Rev 309 | Go to most recent revision | 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; |
| 106 | espaco | 46 | |
| 47 | private Boolean possuiLancamento = false; |
||
| 48 | |||
| 49 | public Parcela() {} |
||
| 50 | |||
| 51 | public Parcela(Conta conta, ContaBancaria contaBancaria, Date dataEmissao, |
||
| 309 | espaco | 52 | Date dataVencimento, Date dataPagamento, Double valor, String observacao, |
| 53 | FormaPagamento formaPagamento, Boolean indicadorAtivo) { |
||
| 106 | espaco | 54 | this.conta = conta; |
| 55 | this.contaBancaria = contaBancaria; |
||
| 56 | this.dataEmissao = dataEmissao; |
||
| 57 | this.dataVencimento = dataVencimento; |
||
| 58 | this.dataPagamento = dataPagamento; |
||
| 59 | this.valor = valor; |
||
| 60 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
||
| 309 | espaco | 61 | this.formaPagamento = formaPagamento; |
| 106 | espaco | 62 | this.indicadorAtivo = indicadorAtivo; |
| 63 | } |
||
| 64 | |||
| 65 | @Override |
||
| 66 | @Transient |
||
| 67 | public Object getId() { |
||
| 68 | return this.getSequencial(); |
||
| 69 | } |
||
| 70 | @Override |
||
| 71 | public void setId(Object id) { |
||
| 72 | this.sequencial = (Long) id; |
||
| 73 | } |
||
| 74 | |||
| 75 | @Id |
||
| 76 | @SequenceGenerator(name = "sq_parcela") |
||
| 77 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 78 | @Column(name="seq_parcela", nullable=false) |
||
| 79 | public Long getSequencial() { |
||
| 80 | return sequencial; |
||
| 81 | } |
||
| 82 | public void setSequencial(Long sequencial) { |
||
| 83 | this.sequencial = sequencial; |
||
| 84 | } |
||
| 85 | |||
| 86 | @ManyToOne |
||
| 87 | @ForeignKey(name="fk_parcela_conta") |
||
| 88 | @JoinColumn(name="seq_conta") |
||
| 89 | public Conta getConta() { |
||
| 90 | return conta; |
||
| 91 | } |
||
| 92 | public void setConta(Conta conta) { |
||
| 93 | this.conta = conta; |
||
| 94 | } |
||
| 95 | |||
| 96 | @ManyToOne |
||
| 97 | @ForeignKey(name="fk_parcela_contabancaria") |
||
| 98 | @JoinColumn(name="cod_conta_bancaria") |
||
| 99 | public ContaBancaria getContaBancaria() { |
||
| 100 | return contaBancaria; |
||
| 101 | } |
||
| 102 | public void setContaBancaria(ContaBancaria contaBancaria) { |
||
| 103 | this.contaBancaria = contaBancaria; |
||
| 104 | } |
||
| 105 | |||
| 304 | espaco | 106 | @ManyToOne |
| 107 | @ForeignKey(name="fk_parcela_formapagamento") |
||
| 108 | @JoinColumn(name="cod_formapagament") |
||
| 109 | public FormaPagamento getFormaPagamento() { |
||
| 110 | return formaPagamento; |
||
| 111 | } |
||
| 112 | public void setFormaPagamento(FormaPagamento formaPagamento) { |
||
| 113 | this.formaPagamento = formaPagamento; |
||
| 114 | } |
||
| 115 | |||
| 106 | espaco | 116 | @Column(name="dth_emissao", nullable=false) |
| 117 | public Date getDataEmissao() { |
||
| 118 | return dataEmissao; |
||
| 119 | } |
||
| 120 | public void setDataEmissao(Date dataEmissao) { |
||
| 121 | this.dataEmissao = dataEmissao; |
||
| 122 | } |
||
| 123 | |||
| 124 | @Column(name="dat_vencimento", nullable=true) |
||
| 125 | public Date getDataVencimento() { |
||
| 126 | return dataVencimento; |
||
| 127 | } |
||
| 128 | public void setDataVencimento(Date dataVencimento) { |
||
| 129 | this.dataVencimento = dataVencimento; |
||
| 130 | } |
||
| 131 | |||
| 132 | @Column(name="dat_pagamento", nullable=true) |
||
| 133 | public Date getDataPagamento() { |
||
| 134 | return dataPagamento; |
||
| 135 | } |
||
| 136 | public void setDataPagamento(Date dataPagamento) { |
||
| 137 | this.dataPagamento = dataPagamento; |
||
| 138 | } |
||
| 139 | |||
| 140 | @Column(name="val_valor", nullable=true) |
||
| 141 | @NotNull(message = "Parâmetro obrigatório não preenchido: Valor da parcela", groups = {Cadastrar.class, Alterar.class}) |
||
| 142 | public Double getValor() { |
||
| 143 | return valor; |
||
| 144 | } |
||
| 145 | public void setValor(Double valor) { |
||
| 146 | this.valor = valor; |
||
| 147 | } |
||
| 148 | |||
| 149 | @Column(name="dsc_observacao") |
||
| 150 | @Size(max = 400, message = "Limite de caracteres ultrapassado: Observação") |
||
| 151 | public String getObservacao() { |
||
| 152 | return observacao; |
||
| 153 | } |
||
| 154 | public void setObservacao(String observacao) { |
||
| 155 | this.observacao = StringUtil.setarUpperCaseComTrim(observacao); |
||
| 156 | } |
||
| 157 | |||
| 158 | @Column(name="ind_oficial") |
||
| 159 | public Boolean getIndicadorOficial() { |
||
| 160 | return indicadorOficial; |
||
| 161 | } |
||
| 162 | public void setIndicadorOficial(Boolean indicadorOficial) { |
||
| 163 | this.indicadorOficial = indicadorOficial; |
||
| 164 | } |
||
| 309 | espaco | 165 | |
| 106 | espaco | 166 | @Column(name="ind_ativo", nullable=false) |
| 167 | public Boolean getIndicadorAtivo() { |
||
| 168 | return indicadorAtivo; |
||
| 169 | } |
||
| 170 | public void setIndicadorAtivo(Boolean indicadorAtivo) { |
||
| 171 | this.indicadorAtivo = indicadorAtivo; |
||
| 172 | } |
||
| 173 | |||
| 387 | espaco | 174 | @Column(name="ind_conciliado", nullable=false) |
| 175 | public Boolean getIndicadorConciliado() { |
||
| 176 | return indicadorConciliado; |
||
| 177 | } |
||
| 178 | public void setIndicadorConciliado(Boolean indicadorConciliado) { |
||
| 179 | this.indicadorConciliado = indicadorConciliado; |
||
| 180 | } |
||
| 181 | |||
| 106 | espaco | 182 | @Transient |
| 183 | public Boolean getPossuiLancamento() { |
||
| 184 | return possuiLancamento; |
||
| 185 | } |
||
| 186 | public void setPossuiLancamento(Boolean possuiLancamento) { |
||
| 187 | this.possuiLancamento = possuiLancamento; |
||
| 188 | } |
||
| 189 | |||
| 190 | @Override |
||
| 191 | public int hashCode() { |
||
| 192 | final int prime = 31; |
||
| 193 | int result = 1; |
||
| 194 | result = prime * result |
||
| 195 | + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 196 | return result; |
||
| 197 | } |
||
| 198 | |||
| 199 | @Override |
||
| 200 | public boolean equals(Object obj) { |
||
| 201 | if (this == obj) |
||
| 202 | return true; |
||
| 203 | if (obj == null) |
||
| 204 | return false; |
||
| 205 | if (getClass() != obj.getClass()) |
||
| 206 | return false; |
||
| 207 | Parcela other = (Parcela) obj; |
||
| 208 | if (sequencial == null) { |
||
| 209 | if (other.sequencial != null) |
||
| 210 | return false; |
||
| 211 | } else if (!sequencial.equals(other.sequencial)) |
||
| 212 | return false; |
||
| 213 | return true; |
||
| 214 | } |
||
| 215 | |||
| 216 | @Transient |
||
| 217 | public Boolean parcelaAVencerAlemDeTresDias() { |
||
| 218 | return DataUtils.calcularDiferenceEmDiasEntreDuasDatas(getDataVencimento(), DataUtils.getDataAtual()) > 3 ? true : false; |
||
| 219 | } |
||
| 220 | |||
| 221 | @Transient |
||
| 222 | public Boolean parcelaAVencerAteTresDias() { |
||
| 223 | return DataUtils.calcularDiferenceEmDiasEntreDuasDatas(getDataVencimento(), DataUtils.getDataAtual()) < 3 && |
||
| 224 | DataUtils.calcularDiferenceEmDiasEntreDuasDatas(getDataVencimento(), DataUtils.getDataAtual()) >= 0? true : false; |
||
| 225 | } |
||
| 226 | |||
| 227 | @Transient |
||
| 228 | public Boolean parcelaVencida() { |
||
| 229 | if (VerificadorUtil.naoEstaNulo(getDataVencimento())) { |
||
| 230 | Date dataVerificar = DataUtils.acrescentarDias(DataUtils.getDataAtual(), -1); |
||
| 231 | return getDataVencimento().before(DataUtils.getDataComHorarioMaximo(dataVerificar)); |
||
| 232 | } |
||
| 233 | return false; |
||
| 234 | } |
||
| 235 | |||
| 236 | @Transient |
||
| 237 | public Boolean parcelaAhReceber() { |
||
| 238 | return VerificadorUtil.naoEstaNulo(getConta())? getConta().ehContaAReceber() : false; |
||
| 239 | } |
||
| 240 | |||
| 241 | @Transient |
||
| 242 | public Boolean parcelaAhPagar() { |
||
| 243 | return VerificadorUtil.naoEstaNulo(getConta())? getConta().ehContaAPagar() : false; |
||
| 244 | } |
||
| 245 | |||
| 246 | @Transient |
||
| 247 | public String corParcela() { |
||
| 248 | return parcelaAhPagar()? "red" : "green"; |
||
| 249 | } |
||
| 250 | |||
| 251 | @Transient |
||
| 252 | public String descricaoDaLoja() { |
||
| 253 | return VerificadorUtil.naoEstaNulo(getConta())? VerificadorUtil.naoEstaNulo(getConta().getLoja())? getConta().getLoja().getDescricao() : "" : ""; |
||
| 254 | } |
||
| 255 | |||
| 256 | @Transient |
||
| 257 | public Boolean formaDePagamentoEhDebito() { |
||
| 258 | return VerificadorUtil.naoEstaNulo(getConta())? getConta().formaDePagamentoEhDebito() : false; |
||
| 259 | } |
||
| 260 | |||
| 261 | @Transient |
||
| 262 | public Boolean formaDePagamentoEhCredito() { |
||
| 263 | return VerificadorUtil.naoEstaNulo(getConta())? getConta().formaDePagamentoEhCredito() : false; |
||
| 264 | } |
||
| 265 | |||
| 266 | @Transient |
||
| 267 | public String getDescricaoDaCategoria() { |
||
| 268 | return VerificadorUtil.naoEstaNulo(getConta())? VerificadorUtil.naoEstaNulo(getConta().getCategoria())? getConta().getCategoria().getDescricao(): null: null; |
||
| 269 | } |
||
| 270 | |||
| 271 | @Transient |
||
| 272 | public String getTipoDaCategoria() { |
||
| 273 | return VerificadorUtil.naoEstaNulo(getConta())? VerificadorUtil.naoEstaNulo(getConta().getCategoria())? "(" + getConta().getCategoria().getTipo() + ")": null: null; |
||
| 274 | } |
||
| 275 | |||
| 276 | @Override |
||
| 277 | public Parcela clone() throws CloneNotSupportedException { |
||
| 278 | return (Parcela) super.clone(); |
||
| 279 | } |
||
| 280 | |||
| 281 | } |