Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | 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.Table; |
||
| 14 | import javax.persistence.Transient; |
||
| 15 | |||
| 16 | import org.hibernate.annotations.ForeignKey; |
||
| 17 | |||
| 18 | import br.edu.cesmac.core.generic.identidade.Identidade; |
||
| 19 | import br.edu.cesmac.core.util.DataUtils; |
||
| 20 | import br.edu.cesmac.core.util.StringUtil; |
||
| 21 | import br.edu.cesmac.core.util.VerificadorUtil; |
||
| 22 | |||
| 23 | @Entity |
||
| 24 | @Table(name="sec_parcela", schema="sc_sec") |
||
| 25 | public class Parcela implements Serializable, Identidade { |
||
| 26 | |||
| 27 | private static final long serialVersionUID = 1L; |
||
| 28 | |||
| 29 | private Long sequencial; |
||
| 30 | private Conta conta; |
||
| 31 | private ContaBancaria contaBancaria; |
||
| 32 | private Date dataEmissao; |
||
| 33 | private Date dataVencimento; |
||
| 34 | private Date dataPagamento; |
||
| 35 | private Double valor; |
||
| 36 | private String observacao; |
||
| 37 | private Boolean indicadorAtivo; |
||
| 38 | |||
| 39 | public Parcela() {} |
||
| 40 | |||
| 41 | public Parcela(Conta conta, ContaBancaria contaBancaria, Date dataEmissao, |
||
| 42 | Date dataVencimento, Date dataPagamento, Double valor, String observacao, Boolean indicadorAtivo) { |
||
| 43 | this.conta = conta; |
||
| 44 | this.contaBancaria = contaBancaria; |
||
| 45 | this.dataEmissao = dataEmissao; |
||
| 46 | this.dataVencimento = dataVencimento; |
||
| 47 | this.dataPagamento = dataPagamento; |
||
| 48 | this.valor = valor; |
||
| 49 | this.observacao = StringUtil.setarUpperCase(observacao); |
||
| 50 | this.indicadorAtivo = indicadorAtivo; |
||
| 51 | } |
||
| 52 | |||
| 53 | @Override |
||
| 54 | @Transient |
||
| 55 | public Object getId() { |
||
| 56 | return this.getSequencial(); |
||
| 57 | } |
||
| 58 | @Override |
||
| 59 | public void setId(Object id) { |
||
| 60 | this.sequencial = (Long) id; |
||
| 61 | } |
||
| 62 | |||
| 63 | @Id |
||
| 64 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 65 | @Column(name="seq_parcela", nullable=false) |
||
| 66 | public Long getSequencial() { |
||
| 67 | return sequencial; |
||
| 68 | } |
||
| 69 | public void setSequencial(Long sequencial) { |
||
| 70 | this.sequencial = sequencial; |
||
| 71 | } |
||
| 72 | |||
| 73 | @ManyToOne |
||
| 74 | @ForeignKey(name="fk_parcela_conta") |
||
| 75 | @JoinColumn(name="seq_conta") |
||
| 76 | public Conta getConta() { |
||
| 77 | return conta; |
||
| 78 | } |
||
| 79 | public void setConta(Conta conta) { |
||
| 80 | this.conta = conta; |
||
| 81 | } |
||
| 82 | |||
| 83 | @ManyToOne |
||
| 84 | @ForeignKey(name="fk_parcela_contabancaria") |
||
| 85 | @JoinColumn(name="cod_conta_bancaria") |
||
| 86 | public ContaBancaria getContaBancaria() { |
||
| 87 | return contaBancaria; |
||
| 88 | } |
||
| 89 | public void setContaBancaria(ContaBancaria contaBancaria) { |
||
| 90 | this.contaBancaria = contaBancaria; |
||
| 91 | } |
||
| 92 | |||
| 93 | @Column(name="dth_emissao", nullable=false) |
||
| 94 | public Date getDataEmissao() { |
||
| 95 | return dataEmissao; |
||
| 96 | } |
||
| 97 | public void setDataEmissao(Date dataEmissao) { |
||
| 98 | this.dataEmissao = dataEmissao; |
||
| 99 | } |
||
| 100 | |||
| 101 | @Column(name="dat_vencimento", nullable=true) |
||
| 102 | public Date getDataVencimento() { |
||
| 103 | return dataVencimento; |
||
| 104 | } |
||
| 105 | public void setDataVencimento(Date dataVencimento) { |
||
| 106 | this.dataVencimento = dataVencimento; |
||
| 107 | } |
||
| 108 | |||
| 109 | @Column(name="dat_pagamento", nullable=true) |
||
| 110 | public Date getDataPagamento() { |
||
| 111 | return dataPagamento; |
||
| 112 | } |
||
| 113 | public void setDataPagamento(Date dataPagamento) { |
||
| 114 | this.dataPagamento = dataPagamento; |
||
| 115 | } |
||
| 116 | |||
| 117 | @Column(name="val_valor", nullable=true) |
||
| 118 | public Double getValor() { |
||
| 119 | return valor; |
||
| 120 | } |
||
| 121 | public void setValor(Double valor) { |
||
| 122 | this.valor = valor; |
||
| 123 | } |
||
| 124 | |||
| 125 | @Column(name="dsc_observacao") |
||
| 126 | public String getObservacao() { |
||
| 127 | return observacao; |
||
| 128 | } |
||
| 129 | public void setObservacao(String observacao) { |
||
| 130 | this.observacao = StringUtil.setarUpperCase(observacao); |
||
| 131 | } |
||
| 132 | |||
| 133 | @Column(name="ind_ativo", nullable=false) |
||
| 134 | public Boolean getIndicadorAtivo() { |
||
| 135 | return indicadorAtivo; |
||
| 136 | } |
||
| 137 | public void setIndicadorAtivo(Boolean indicadorAtivo) { |
||
| 138 | this.indicadorAtivo = indicadorAtivo; |
||
| 139 | } |
||
| 140 | |||
| 141 | @Override |
||
| 142 | public int hashCode() { |
||
| 143 | final int prime = 31; |
||
| 144 | int result = 1; |
||
| 145 | result = prime * result |
||
| 146 | + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 147 | return result; |
||
| 148 | } |
||
| 149 | |||
| 150 | @Override |
||
| 151 | public boolean equals(Object obj) { |
||
| 152 | if (this == obj) |
||
| 153 | return true; |
||
| 154 | if (obj == null) |
||
| 155 | return false; |
||
| 156 | if (getClass() != obj.getClass()) |
||
| 157 | return false; |
||
| 158 | Parcela other = (Parcela) obj; |
||
| 159 | if (sequencial == null) { |
||
| 160 | if (other.sequencial != null) |
||
| 161 | return false; |
||
| 162 | } else if (!sequencial.equals(other.sequencial)) |
||
| 163 | return false; |
||
| 164 | return true; |
||
| 165 | } |
||
| 166 | |||
| 167 | @Transient |
||
| 168 | public Boolean parcelaAVencerAlemDeTresDias() { |
||
| 169 | return DataUtils.calcularDiferenceEmDiasEntreDuasDatas(getDataVencimento(), DataUtils.getDataAtual()) > 3 ? true : false; |
||
| 170 | } |
||
| 171 | |||
| 172 | @Transient |
||
| 173 | public Boolean parcelaAVencerAteTresDias() { |
||
| 174 | return DataUtils.calcularDiferenceEmDiasEntreDuasDatas(getDataVencimento(), DataUtils.getDataAtual()) < 3 && |
||
| 175 | DataUtils.calcularDiferenceEmDiasEntreDuasDatas(getDataVencimento(), DataUtils.getDataAtual()) >= 0? true : false; |
||
| 176 | } |
||
| 177 | |||
| 178 | @Transient |
||
| 179 | public Boolean parcelaVencida() { |
||
| 180 | if (VerificadorUtil.naoEstaNulo(getDataVencimento())) { |
||
| 181 | Date dataVerificar = DataUtils.acrescentarDias(DataUtils.getDataAtual(), -1); |
||
| 182 | return getDataVencimento().before(DataUtils.getDataComHorarioMaximo(dataVerificar)); |
||
| 183 | } |
||
| 184 | return false; |
||
| 185 | } |
||
| 186 | |||
| 187 | @Transient |
||
| 188 | public Boolean parcelaAhReceber() { |
||
| 189 | return VerificadorUtil.naoEstaNulo(getConta())? getConta().ehContaAReceber() : false; |
||
| 190 | } |
||
| 191 | |||
| 192 | @Transient |
||
| 193 | public Boolean parcelaAhPagar() { |
||
| 194 | return VerificadorUtil.naoEstaNulo(getConta())? getConta().ehContaAPagar() : false; |
||
| 195 | } |
||
| 196 | |||
| 197 | @Transient |
||
| 198 | public String descricaoDaLoja() { |
||
| 199 | return VerificadorUtil.naoEstaNulo(getConta())? VerificadorUtil.naoEstaNulo(getConta().getLoja())? getConta().getLoja().getDescricao() : "" : ""; |
||
| 200 | } |
||
| 201 | |||
| 202 | @Transient |
||
| 203 | public Boolean formaDePagamentoEhDebito() { |
||
| 204 | return VerificadorUtil.naoEstaNulo(getConta())? getConta().formaDePagamentoEhDebito() : false; |
||
| 205 | } |
||
| 206 | |||
| 207 | @Transient |
||
| 208 | public Boolean formaDePagamentoEhCredito() { |
||
| 209 | return VerificadorUtil.naoEstaNulo(getConta())? getConta().formaDePagamentoEhCredito() : false; |
||
| 210 | } |
||
| 211 | |||
| 212 | @Transient |
||
| 213 | public String getDescricaoDaCategoria() { |
||
| 214 | return VerificadorUtil.naoEstaNulo(getConta())? VerificadorUtil.naoEstaNulo(getConta().getCategoria())? getConta().getCategoria().getDescricao(): null: null; |
||
| 215 | } |
||
| 216 | |||
| 217 | @Transient |
||
| 218 | public String getTipoDaCategoria() { |
||
| 219 | return VerificadorUtil.naoEstaNulo(getConta())? VerificadorUtil.naoEstaNulo(getConta().getCategoria())? "(" + getConta().getCategoria().getTipo() + ")": null: null; |
||
| 220 | } |
||
| 221 | |||
| 222 | } |