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