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