Rev 259 | Rev 282 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 259 | Rev 274 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | package br.com.ec.domain.service.impl; |
1 | package br.com.ec.domain.service.impl; |
| 2 | 2 | ||
| 3 | import org.springframework.beans.factory.annotation.Autowired; |
3 | import org.springframework.beans.factory.annotation.Autowired; |
| 4 | import org.springframework.stereotype.Service; |
4 | import org.springframework.stereotype.Service; |
| 5 | 5 | ||
| 6 | import br.com.ec.core.exception.NegocioException; |
- | |
| 7 | import br.com.ec.core.generic.AbstractService; |
6 | import br.com.ec.core.generic.AbstractService; |
| 8 | import br.com.ec.core.generic.GenericRepository; |
7 | import br.com.ec.core.generic.GenericRepository; |
| 9 | import br.com.ec.core.util.VerificadorUtil; |
- | |
| 10 | import br.com.ec.core.validador.Validador; |
8 | import br.com.ec.core.validador.Validador; |
| 11 | import br.com.ec.domain.model.Conta; |
- | |
| 12 | import br.com.ec.domain.model.Parcela; |
9 | import br.com.ec.domain.model.Parcela; |
| 13 | import br.com.ec.domain.service.ParcelaService; |
10 | import br.com.ec.domain.service.ParcelaService; |
| 14 | import br.com.ec.repository.ParcelaRepository; |
11 | import br.com.ec.repository.ParcelaRepository; |
| 15 | 12 | ||
| 16 | @Service |
13 | @Service |
| 17 | public class ParcelaServiceImpl extends AbstractService<Parcela> implements ParcelaService { |
14 | public class ParcelaServiceImpl extends AbstractService<Parcela> implements ParcelaService { |
| 18 | - | ||
| - | 15 | ||
| 19 | private ParcelaRepository parcelaRepository; |
16 | private ParcelaRepository parcelaRepository; |
| 20 | /*
|
- | |
| - | 17 | /*
|
|
| 21 | private TaxaService taxaService;
|
18 | private TaxaService taxaService;
|
| 22 | private ContaService contaService;
|
19 | private ContaService contaService;
|
| 23 | private CategoriaService categoriaService;
|
20 | private CategoriaService categoriaService;
|
| 24 | private ContaFormaPagamentoService contaFormaPagamentoService;
|
21 | private ContaFormaPagamentoService contaFormaPagamentoService;
|
| 25 | private VendaFormaPagamentoService vendaFormaPagamentoService;
|
22 | private VendaFormaPagamentoService vendaFormaPagamentoService;
|
| 26 | private VigenciaService vigenciaService;
|
- | |
| 27 | */
|
- | |
| - | 23 | private VigenciaService vigenciaService;*/
|
|
| - | 24 | ||
| 28 | @Autowired |
25 | @Autowired |
| 29 | public ParcelaServiceImpl(Validador validador, ParcelaRepository parcelaRepository/*, TaxaService taxaService, |
26 | public ParcelaServiceImpl(Validador validador, ParcelaRepository parcelaRepository/*, TaxaService taxaService, |
| 30 | ContaService contaService, CategoriaService categoriaService, ContaFormaPagamentoService contaFormaPagamentoService,
|
27 | ContaService contaService, CategoriaService categoriaService, ContaFormaPagamentoService contaFormaPagamentoService,
|
| 31 | VendaFormaPagamentoService vendaFormaPagamentoService, VigenciaService vigenciaService*/) { |
28 | VendaFormaPagamentoService vendaFormaPagamentoService, VigenciaService vigenciaService*/) { |
| 32 | super(validador); |
29 | super(validador); |
| Line 43... | Line 40... | ||
| 43 | 40 | ||
| 44 | @Override |
41 | @Override |
| 45 | protected GenericRepository<Parcela> getRepository() { |
42 | protected GenericRepository<Parcela> getRepository() { |
| 46 | return this.parcelaRepository; |
43 | return this.parcelaRepository; |
| 47 | }
|
44 | }
|
| 48 | - | ||
| 49 | /************************************/
|
- | |
| 50 | - | ||
| 51 | - | ||
| 52 | - | ||
| 53 | /*
|
45 | /*
|
| 54 | @Override
|
46 | @Override
|
| 55 | protected void regrasNegocioCadastrar(Parcela parcela) {
|
47 | protected void regrasNegocioCadastrar(Parcela parcela) {
|
| 56 | verificarParcela(parcela);
|
48 | verificarParcela(parcela);
|
| 57 | }
|
49 | }
|
| Line 59... | Line 51... | ||
| 59 | @Override
|
51 | @Override
|
| 60 | protected void regrasNegocioAlterar(Parcela parcela) {
|
52 | protected void regrasNegocioAlterar(Parcela parcela) {
|
| 61 | verificarParcela(parcela);
|
53 | verificarParcela(parcela);
|
| 62 | }
|
54 | }
|
| 63 | 55 | ||
| - | 56 |
|
|
| 64 | private void verificarParcela(Parcela parcela) {
|
57 | private void verificarParcela(Parcela parcela) {
|
| 65 | if (VerificadorUtil.estaNulo(parcela.getDataVencimento()) && VerificadorUtil.estaNulo(parcela.getDataPagamento())) {
|
58 | if (VerificadorUtil.estaNulo(parcela.getDataVencimento()) && VerificadorUtil.estaNulo(parcela.getDataPagamento())) {
|
| 66 | throw new NegocioException("INFORME A DATA DE VENCIMENTO OU A DATA DE PAGAMENTO");
|
59 | throw new NegocioException("INFORME A DATA DE VENCIMENTO OU A DATA DE PAGAMENTO");
|
| 67 | }
|
60 | }
|
| - | 61 | //TODO: VERIFICAR CADASTRO
|
|
| 68 | cadastrarContaCasoNaoTenhaSidoCadastrada(parcela.getConta());
|
62 | cadastrarContaCasoNaoTenhaSidoCadastrada(parcela.getConta());
|
| 69 | }
|
- | |
| 70 |
|
- | |
| 71 | private Conta cadastrarContaCasoNaoTenhaSidoCadastrada(Conta conta) {
|
- | |
| 72 | if (VerificadorUtil.naoEstaNulo(conta)) {
|
- | |
| 73 | if (VerificadorUtil.estaNulo(conta.getSequencial())) {
|
- | |
| 74 | contaService.cadastrar(conta);
|
- | |
| 75 | }
|
- | |
| 76 | }
|
- | |
| 77 | return conta;
|
- | |
| - | 63 | // cadastrarContaCasoNaoTenhaSidoCadastrada(parcela.getConta(), TipoConta.CONTA_A_PAGAR.getValor());
|
|
| - | 64 | // cadastrarContaCasoNaoTenhaSidoCadastrada(parcela.getConta(), TipoConta.CONTA_A_RECEBER.getValor());
|
|
| 78 | }
|
65 | }
|
| 79 |
|
66 |
|
| 80 | @Override
|
67 | @Override
|
| 81 | public void cancelarParcela(Parcela parcela) {
|
68 | public void cancelarParcela(Parcela parcela) {
|
| 82 | parcela.setIndicadorAtivo(false);
|
69 | parcela.setIndicadorAtivo(false);
|
| Line 183... | Line 170... | ||
| 183 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh8x()) {quantidadeVezes = 8;}
|
170 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh8x()) {quantidadeVezes = 8;}
|
| 184 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh9x()) {quantidadeVezes = 9;}
|
171 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh9x()) {quantidadeVezes = 9;}
|
| 185 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh10x()) {quantidadeVezes = 10;}
|
172 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh10x()) {quantidadeVezes = 10;}
|
| 186 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh11x()) {quantidadeVezes = 11;}
|
173 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh11x()) {quantidadeVezes = 11;}
|
| 187 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh12x()) {quantidadeVezes = 12;}
|
174 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh12x()) {quantidadeVezes = 12;}
|
| - | 175 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh13x()) {quantidadeVezes = 13;}
|
|
| - | 176 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh14x()) {quantidadeVezes = 14;}
|
|
| - | 177 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh15x()) {quantidadeVezes = 15;}
|
|
| 188 | Date dataParcela = vendaFormaPagamento.getVenda().getDataVenda();
|
178 | Date dataParcela = vendaFormaPagamento.getVenda().getDataVenda();
|
| 189 | Date dataInicial = vendaFormaPagamento.getVenda().getDataVenda();
|
179 | Date dataInicial = vendaFormaPagamento.getVenda().getDataVenda();
|
| 190 | for (int i = 1; i <= quantidadeVezes; i++) {
|
180 | for (int i = 1; i <= quantidadeVezes; i++) {
|
| 191 | if (i == 1) {
|
181 | if (i == 1) {
|
| 192 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh1x()) {
|
182 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh1x()) {
|
| Line 252... | Line 242... | ||
| 252 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhCredito()) {criarParcelaCredito(valorParcelaCalculado, taxa.getContaBancaria(), vendaFormaPagamento, conta);}
|
242 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhCredito()) {criarParcelaCredito(valorParcelaCalculado, taxa.getContaBancaria(), vendaFormaPagamento, conta);}
|
| 253 | }
|
243 | }
|
| 254 | return conta;
|
244 | return conta;
|
| 255 | }
|
245 | }
|
| 256 | throw new NegocioException("NENHUMA PARCELA FOI CRIADA");
|
246 | throw new NegocioException("NENHUMA PARCELA FOI CRIADA");
|
| - | 247 | }
|
|
| - | 248 |
|
|
| - | 249 | private Conta cadastrarContaCasoNaoTenhaSidoCadastrada(Conta conta) {
|
|
| - | 250 | if (VerificadorUtil.naoEstaNulo(conta)) {
|
|
| - | 251 | if (VerificadorUtil.estaNulo(conta.getSequencial())) {
|
|
| - | 252 | contaService.cadastrar(conta);
|
|
| - | 253 | }
|
|
| - | 254 | }
|
|
| - | 255 | return conta;
|
|
| 257 | }
|
256 | }
|
| 258 |
|
257 |
|
| 259 | private Conta criarParcelaDinheiro(VendaFormaPagamento vendaFormaPagamento, Conta contaAReceber) {
|
258 | private Conta criarParcelaDinheiro(VendaFormaPagamento vendaFormaPagamento, Conta contaAReceber) {
|
| 260 | cadastrarParcelas(vendaFormaPagamento, new ContaBancaria(ContaBancaria.getContaCaixa()), vendaFormaPagamento.getVenda().getDataVenda(), vendaFormaPagamento.getValorPagamento(), contaAReceber, "VALOR");
|
259 | cadastrarParcelas(vendaFormaPagamento, new ContaBancaria(ContaBancaria.getContaCaixa()), vendaFormaPagamento.getVenda().getDataVenda(), vendaFormaPagamento.getValorPagamento(), contaAReceber, "VALOR");
|
| 261 | return contaAReceber;
|
260 | return contaAReceber;
|