Rev 387 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 1 | package br.com.ec.domain.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | import java.util.Date; |
||
| 5 | |||
| 6 | import javax.persistence.Column; |
||
| 7 | import javax.persistence.Entity; |
||
| 8 | import javax.persistence.GeneratedValue; |
||
| 9 | import javax.persistence.GenerationType; |
||
| 10 | import javax.persistence.Id; |
||
| 11 | import javax.persistence.JoinColumn; |
||
| 12 | import javax.persistence.ManyToOne; |
||
| 13 | import javax.persistence.SequenceGenerator; |
||
| 14 | import javax.persistence.Table; |
||
| 15 | import javax.persistence.Transient; |
||
| 16 | import javax.validation.constraints.NotNull; |
||
| 17 | import javax.validation.constraints.Size; |
||
| 18 | |||
| 19 | import org.hibernate.annotations.ForeignKey; |
||
| 20 | |||
| 195 | espaco | 21 | import br.com.ec.core.generic.identidade.Identidade; |
| 22 | import br.com.ec.core.interfaces.Alterar; |
||
| 23 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 24 | import br.com.ec.core.util.DataUtils; |
||
| 25 | import br.com.ec.core.util.StringUtil; |
||
| 26 | import br.com.ec.core.util.VerificadorUtil; |
||
| 106 | espaco | 27 | |
| 28 | @Entity |
||
| 29 | @Table(name="sec_parcela", schema="sc_sec") |
||
| 30 | public class Parcela implements Serializable, Identidade, Cloneable { |
||
| 31 | |||
| 32 | private static final long serialVersionUID = 1L; |
||
| 33 | |||
| 34 | private Long sequencial; |
||
| 35 | private Conta conta; |
||
| 36 | private ContaBancaria contaBancaria; |
||
| 304 | espaco | 37 | private FormaPagamento formaPagamento; |
| 106 | espaco | 38 | private Date dataEmissao; |
| 39 | private Date dataVencimento; |
||
| 40 | private Date dataPagamento; |
||
| 41 | private Double valor; |
||
| 42 | private String observacao; |
||
| 43 | private Boolean indicadorOficial; |
||
| 44 | private Boolean indicadorAtivo; |
||
| 387 | espaco | 45 | private Boolean indicadorConciliado = false; |
| 577 | blopes | 46 | private Boolean indicadorNegociacao = false; |
| 106 | espaco | 47 | |
| 48 | private Boolean possuiLancamento = false; |
||
| 49 | |||
| 50 | public Parcela() {} |
||
| 51 | |||
| 52 | public Parcela(Conta conta, ContaBancaria contaBancaria, Date dataEmissao, |
||
| 309 | espaco | 53 | Date dataVencimento, Date dataPagamento, Double valor, String observacao, |
| 54 | FormaPagamento formaPagamento, Boolean indicadorAtivo) { |
||
| 106 | espaco | 55 | this.conta = conta; |
| 56 | this.contaBancaria = contaBancaria; |
||
| 57 | this.dataEmissao = dataEmissao; |
||
| 58 | this.dataVencimento = dataVencimento; |
||
| 59 | this.dataPagamento = dataPagamento; |
||
| 60 | this.valor = valor; |
||
| 61 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
||
| 309 | espaco | 62 | this.formaPagamento = formaPagamento; |
| 106 | espaco | 63 | this.indicadorAtivo = indicadorAtivo; |
| 64 | } |
||
| 65 | |||
| 66 | @Override |
||
| 67 | @Transient |
||
| 68 | public Object getId() { |
||
| 69 | return this.getSequencial(); |
||
| 70 | } |
||
| 71 | @Override |
||
| 72 | public void setId(Object id) { |
||
| 73 | this.sequencial = (Long) id; |
||
| 74 | } |
||
| 75 | |||
| 76 | @Id |
||
| 77 | @SequenceGenerator(name = "sq_parcela") |
||
| 78 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 79 | @Column(name="seq_parcela", nullable=false) |
||
| 80 | public Long getSequencial() { |
||
| 81 | return sequencial; |
||
| 82 | } |
||
| 83 | public void setSequencial(Long sequencial) { |
||
| 84 | this.sequencial = sequencial; |
||
| 85 | } |
||
| 86 | |||
| 87 | @ManyToOne |
||
| 88 | @ForeignKey(name="fk_parcela_conta") |
||
| 89 | @JoinColumn(name="seq_conta") |
||
| 90 | public Conta getConta() { |
||
| 91 | return conta; |
||
| 92 | } |
||
| 93 | public void setConta(Conta conta) { |
||
| 94 | this.conta = conta; |
||
| 95 | } |
||
| 96 | |||
| 97 | @ManyToOne |
||
| 98 | @ForeignKey(name="fk_parcela_contabancaria") |
||
| 99 | @JoinColumn(name="cod_conta_bancaria") |
||
| 100 | public ContaBancaria getContaBancaria() { |
||
| 101 | return contaBancaria; |
||
| 102 | } |
||
| 103 | public void setContaBancaria(ContaBancaria contaBancaria) { |
||
| 104 | this.contaBancaria = contaBancaria; |
||
| 105 | } |
||
| 106 | |||
| 304 | espaco | 107 | @ManyToOne |
| 108 | @ForeignKey(name="fk_parcela_formapagamento") |
||
| 109 | @JoinColumn(name="cod_formapagament") |
||
| 110 | public FormaPagamento getFormaPagamento() { |
||
| 111 | return formaPagamento; |
||
| 112 | } |
||
| 113 | public void setFormaPagamento(FormaPagamento formaPagamento) { |
||
| 114 | this.formaPagamento = formaPagamento; |
||
| 115 | } |
||
| 116 | |||
| 106 | espaco | 117 | @Column(name="dth_emissao", nullable=false) |
| 118 | public Date getDataEmissao() { |
||
| 119 | return dataEmissao; |
||
| 120 | } |
||
| 121 | public void setDataEmissao(Date dataEmissao) { |
||
| 122 | this.dataEmissao = dataEmissao; |
||
| 123 | } |
||
| 124 | |||
| 125 | @Column(name="dat_vencimento", nullable=true) |
||
| 126 | public Date getDataVencimento() { |
||
| 127 | return dataVencimento; |
||
| 128 | } |
||
| 129 | public void setDataVencimento(Date dataVencimento) { |
||
| 130 | this.dataVencimento = dataVencimento; |
||
| 131 | } |
||
| 132 | |||
| 133 | @Column(name="dat_pagamento", nullable=true) |
||
| 134 | public Date getDataPagamento() { |
||
| 135 | return dataPagamento; |
||
| 136 | } |
||
| 137 | public void setDataPagamento(Date dataPagamento) { |
||
| 138 | this.dataPagamento = dataPagamento; |
||
| 139 | } |
||
| 140 | |||
| 141 | @Column(name="val_valor", nullable=true) |
||
| 142 | @NotNull(message = "Parâmetro obrigatório não preenchido: Valor da parcela", groups = {Cadastrar.class, Alterar.class}) |
||
| 143 | public Double getValor() { |
||
| 144 | return valor; |
||
| 145 | } |
||
| 146 | public void setValor(Double valor) { |
||
| 147 | this.valor = valor; |
||
| 148 | } |
||
| 149 | |||
| 150 | @Column(name="dsc_observacao") |
||
| 151 | @Size(max = 400, message = "Limite de caracteres ultrapassado: Observação") |
||
| 152 | public String getObservacao() { |
||
| 153 | return observacao; |
||
| 154 | } |
||
| 155 | public void setObservacao(String observacao) { |
||
| 156 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
||
| 157 | } |
||
| 158 | |||
| 159 | @Column(name="ind_oficial") |
||
| 160 | public Boolean getIndicadorOficial() { |
||
| 161 | return indicadorOficial; |
||
| 162 | } |
||
| 163 | public void setIndicadorOficial(Boolean indicadorOficial) { |
||
| 164 | this.indicadorOficial = indicadorOficial; |
||
| 165 | } |
||
| 309 | espaco | 166 | |
| 106 | espaco | 167 | @Column(name="ind_ativo", nullable=false) |
| 168 | public Boolean getIndicadorAtivo() { |
||
| 169 | return indicadorAtivo; |
||
| 170 | } |
||
| 171 | public void setIndicadorAtivo(Boolean indicadorAtivo) { |
||
| 172 | this.indicadorAtivo = indicadorAtivo; |
||
| 173 | } |
||
| 174 | |||
| 387 | espaco | 175 | @Column(name="ind_conciliado", nullable=false) |
| 176 | public Boolean getIndicadorConciliado() { |
||
| 177 | return indicadorConciliado; |
||
| 178 | } |
||
| 179 | public void setIndicadorConciliado(Boolean indicadorConciliado) { |
||
| 180 | this.indicadorConciliado = indicadorConciliado; |
||
| 181 | } |
||
| 182 | |||
| 577 | blopes | 183 | @Column(name="ind_negociacao", nullable=false) |
| 184 | public Boolean getIndicadorNegociacao() { |
||
| 185 | return indicadorNegociacao; |
||
| 186 | } |
||
| 187 | public void setIndicadorNegociacao(Boolean indicadorNegociacao) { |
||
| 188 | this.indicadorNegociacao = indicadorNegociacao; |
||
| 189 | } |
||
| 190 | |||
| 106 | espaco | 191 | @Transient |
| 192 | public Boolean getPossuiLancamento() { |
||
| 193 | return possuiLancamento; |
||
| 194 | } |
||
| 195 | public void setPossuiLancamento(Boolean possuiLancamento) { |
||
| 196 | this.possuiLancamento = possuiLancamento; |
||
| 197 | } |
||
| 198 | |||
| 199 | @Override |
||
| 200 | public int hashCode() { |
||
| 201 | final int prime = 31; |
||
| 202 | int result = 1; |
||
| 203 | result = prime * result |
||
| 204 | + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 205 | return result; |
||
| 206 | } |
||
| 207 | |||
| 208 | @Override |
||
| 209 | public boolean equals(Object obj) { |
||
| 210 | if (this == obj) |
||
| 211 | return true; |
||
| 212 | if (obj == null) |
||
| 213 | return false; |
||
| 214 | if (getClass() != obj.getClass()) |
||
| 215 | return false; |
||
| 216 | Parcela other = (Parcela) obj; |
||
| 217 | if (sequencial == null) { |
||
| 218 | if (other.sequencial != null) |
||
| 219 | return false; |
||
| 220 | } else if (!sequencial.equals(other.sequencial)) |
||
| 221 | return false; |
||
| 222 | return true; |
||
| 223 | } |
||
| 224 | |||
| 225 | @Transient |
||
| 226 | public Boolean parcelaAVencerAlemDeTresDias() { |
||
| 227 | return DataUtils.calcularDiferenceEmDiasEntreDuasDatas(getDataVencimento(), DataUtils.getDataAtual()) > 3 ? true : false; |
||
| 228 | } |
||
| 229 | |||
| 230 | @Transient |
||
| 231 | public Boolean parcelaAVencerAteTresDias() { |
||
| 232 | return DataUtils.calcularDiferenceEmDiasEntreDuasDatas(getDataVencimento(), DataUtils.getDataAtual()) < 3 && |
||
| 233 | DataUtils.calcularDiferenceEmDiasEntreDuasDatas(getDataVencimento(), DataUtils.getDataAtual()) >= 0? true : false; |
||
| 234 | } |
||
| 235 | |||
| 236 | @Transient |
||
| 237 | public Boolean parcelaVencida() { |
||
| 238 | if (VerificadorUtil.naoEstaNulo(getDataVencimento())) { |
||
| 239 | Date dataVerificar = DataUtils.acrescentarDias(DataUtils.getDataAtual(), -1); |
||
| 240 | return getDataVencimento().before(DataUtils.getDataComHorarioMaximo(dataVerificar)); |
||
| 241 | } |
||
| 242 | return false; |
||
| 243 | } |
||
| 244 | |||
| 245 | @Transient |
||
| 246 | public Boolean parcelaAhReceber() { |
||
| 247 | return VerificadorUtil.naoEstaNulo(getConta())? getConta().ehContaAReceber() : false; |
||
| 248 | } |
||
| 249 | |||
| 250 | @Transient |
||
| 251 | public Boolean parcelaAhPagar() { |
||
| 252 | return VerificadorUtil.naoEstaNulo(getConta())? getConta().ehContaAPagar() : false; |
||
| 253 | } |
||
| 254 | |||
| 255 | @Transient |
||
| 256 | public String corParcela() { |
||
| 257 | return parcelaAhPagar()? "red" : "green"; |
||
| 258 | } |
||
| 259 | |||
| 260 | @Transient |
||
| 261 | public String descricaoDaLoja() { |
||
| 262 | return VerificadorUtil.naoEstaNulo(getConta())? VerificadorUtil.naoEstaNulo(getConta().getLoja())? getConta().getLoja().getDescricao() : "" : ""; |
||
| 263 | } |
||
| 264 | |||
| 265 | @Transient |
||
| 266 | public Boolean formaDePagamentoEhDebito() { |
||
| 267 | return VerificadorUtil.naoEstaNulo(getConta())? getConta().formaDePagamentoEhDebito() : false; |
||
| 268 | } |
||
| 269 | |||
| 270 | @Transient |
||
| 271 | public Boolean formaDePagamentoEhCredito() { |
||
| 272 | return VerificadorUtil.naoEstaNulo(getConta())? getConta().formaDePagamentoEhCredito() : false; |
||
| 273 | } |
||
| 274 | |||
| 275 | @Transient |
||
| 276 | public String getDescricaoDaCategoria() { |
||
| 277 | return VerificadorUtil.naoEstaNulo(getConta())? VerificadorUtil.naoEstaNulo(getConta().getCategoria())? getConta().getCategoria().getDescricao(): null: null; |
||
| 278 | } |
||
| 279 | |||
| 280 | @Transient |
||
| 281 | public String getTipoDaCategoria() { |
||
| 282 | return VerificadorUtil.naoEstaNulo(getConta())? VerificadorUtil.naoEstaNulo(getConta().getCategoria())? "(" + getConta().getCategoria().getTipo() + ")": null: null; |
||
| 283 | } |
||
| 284 | |||
| 285 | @Override |
||
| 286 | public Parcela clone() throws CloneNotSupportedException { |
||
| 287 | return (Parcela) super.clone(); |
||
| 288 | } |
||
| 289 | |||
| 290 | } |