Rev 577 | Rev 693 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 577 | Rev 681 | ||
|---|---|---|---|
| Line 169... | Line 169... | ||
| 169 | return parcelaRepository.consultarParcelasDaVenda(sequencialVenda); |
169 | return parcelaRepository.consultarParcelasDaVenda(sequencialVenda); |
| 170 | }
|
170 | }
|
| 171 | 171 | ||
| 172 | @Override |
172 | @Override |
| 173 | public Conta gerarParcelas(VendaFormaPagamento vendaFormaPagamento, Conta conta) { |
173 | public Conta gerarParcelas(VendaFormaPagamento vendaFormaPagamento, Conta conta) { |
| 174 | Taxa taxa = consultarTaxa(vendaFormaPagamento); |
- | |
| 175 | Double valorParcelaCalculado = calcularValorParcela(taxa, vendaFormaPagamento.getValorPagamento()); |
- | |
| 176 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDebito()) {return criarParcelaDebito(valorParcelaCalculado, taxa, vendaFormaPagamento, conta);} |
- | |
| 177 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhCredito()) {return criarParcelaCredito(valorParcelaCalculado, taxa, vendaFormaPagamento, conta);} |
- | |
| 178 | return conta; |
- | |
| - | 174 | try { |
|
| - | 175 | Taxa taxa = consultarTaxa(vendaFormaPagamento); |
|
| - | 176 | Double valorParcelaCalculado = calcularValorParcela(taxa, vendaFormaPagamento.getValorPagamento()); |
|
| - | 177 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDebito()) {return criarParcelaDebito(valorParcelaCalculado, taxa, vendaFormaPagamento, conta);} |
|
| - | 178 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhCredito()) {return criarParcelaCredito(valorParcelaCalculado, taxa, vendaFormaPagamento, conta);} |
|
| - | 179 | return conta; |
|
| - | 180 | } catch (Exception e) { |
|
| - | 181 | throw new NegocioException(e.getMessage()); |
|
| - | 182 | }
|
|
| 179 | }
|
183 | }
|
| 180 | 184 | ||
| 181 | private Conta criarParcelaDebito(Double valorParcelaCalculado, Taxa taxa, VendaFormaPagamento vendaFormaPagamento, Conta conta) { |
185 | private Conta criarParcelaDebito(Double valorParcelaCalculado, Taxa taxa, VendaFormaPagamento vendaFormaPagamento, Conta conta) { |
| 182 | Date dataDebito = vendaFormaPagamento.getVenda().getDataVenda(); |
186 | Date dataDebito = vendaFormaPagamento.getVenda().getDataVenda(); |
| 183 | if (taxa.getQuantidadeDiasPrimeiraParcela() > 0) { |
187 | if (taxa.getQuantidadeDiasPrimeiraParcela() > 0) { |
| Line 232... | Line 236... | ||
| 232 | return contaAReceber; |
236 | return contaAReceber; |
| 233 | }
|
237 | }
|
| 234 | 238 | ||
| 235 | @Override |
239 | @Override |
| 236 | public Conta gerarParcelasDaVenda(Venda venda, Conta conta) { |
240 | public Conta gerarParcelasDaVenda(Venda venda, Conta conta) { |
| 237 | if (VerificadorUtil.naoEstaNulo(conta) && VerificadorUtil.naoEstaNulo(venda)) { |
- | |
| 238 | conta = cadastrarContaCasoNaoTenhaSidoCadastrada(conta); |
- | |
| 239 | List<VendaFormaPagamento> listaVendaFormaPagamento = new ArrayList<VendaFormaPagamento>(); |
- | |
| 240 | listaVendaFormaPagamento.addAll(vendaFormaPagamentoService.consultarLancamentosDaVenda(venda)); |
- | |
| 241 | for (VendaFormaPagamento vendaFormaPagamento : listaVendaFormaPagamento) { |
- | |
| 242 | Taxa taxa = consultarTaxa(vendaFormaPagamento); |
- | |
| 243 | Double valorParcelaCalculado = calcularValorParcela(taxa, vendaFormaPagamento.getValorPagamento()); |
- | |
| 244 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDinheiro()) {criarParcelaDinheiro(vendaFormaPagamento, conta);} |
- | |
| 245 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDebito()) {criarParcelaDebito(valorParcelaCalculado, taxa, vendaFormaPagamento, conta);} |
- | |
| 246 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhCredito()) {criarParcelaCredito(valorParcelaCalculado, taxa, vendaFormaPagamento, conta);} |
- | |
| - | 241 | try { |
|
| - | 242 | if (VerificadorUtil.naoEstaNulo(conta) && VerificadorUtil.naoEstaNulo(venda)) { |
|
| - | 243 | conta = cadastrarContaCasoNaoTenhaSidoCadastrada(conta); |
|
| - | 244 | List<VendaFormaPagamento> listaVendaFormaPagamento = new ArrayList<VendaFormaPagamento>(); |
|
| - | 245 | listaVendaFormaPagamento.addAll(vendaFormaPagamentoService.consultarLancamentosDaVenda(venda)); |
|
| - | 246 | for (VendaFormaPagamento vendaFormaPagamento : listaVendaFormaPagamento) { |
|
| - | 247 | Taxa taxa = consultarTaxa(vendaFormaPagamento); |
|
| - | 248 | Double valorParcelaCalculado = calcularValorParcela(taxa, vendaFormaPagamento.getValorPagamento()); |
|
| - | 249 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDinheiro()) {criarParcelaDinheiro(vendaFormaPagamento, conta);} |
|
| - | 250 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDebito()) {criarParcelaDebito(valorParcelaCalculado, taxa, vendaFormaPagamento, conta);} |
|
| - | 251 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhCredito()) {criarParcelaCredito(valorParcelaCalculado, taxa, vendaFormaPagamento, conta);} |
|
| - | 252 | }
|
|
| - | 253 | return conta; |
|
| 247 | }
|
254 | }
|
| 248 | return conta; |
- | |
| - | 255 | throw new NegocioException("NENHUMA PARCELA FOI CRIADA"); |
|
| - | 256 | } catch (Exception e) { |
|
| - | 257 | throw new NegocioException(e.getMessage()); |
|
| 249 | }
|
258 | }
|
| 250 | throw new NegocioException("NENHUMA PARCELA FOI CRIADA"); |
- | |
| 251 | }
|
259 | }
|
| 252 | 260 | ||
| 253 | @Override |
261 | @Override |
| 254 | public Conta gerarParcelasDinheiroDaVenda(Venda venda, Conta contaAReceber) { |
262 | public Conta gerarParcelasDinheiroDaVenda(Venda venda, Conta contaAReceber) { |
| 255 | if (VerificadorUtil.naoEstaNulo(contaAReceber) && VerificadorUtil.naoEstaNulo(venda)) { |
263 | if (VerificadorUtil.naoEstaNulo(contaAReceber) && VerificadorUtil.naoEstaNulo(venda)) { |
| Line 295... | Line 303... | ||
| 295 | cadastrarParcelas(vendaFormaPagamento, new ContaBancaria(ContaBancaria.getContaCaixa()), vendaFormaPagamento.getVenda().getDataVenda(), vendaFormaPagamento.getValorPagamento(), contaAReceber, "VALOR"); |
303 | cadastrarParcelas(vendaFormaPagamento, new ContaBancaria(ContaBancaria.getContaCaixa()), vendaFormaPagamento.getVenda().getDataVenda(), vendaFormaPagamento.getValorPagamento(), contaAReceber, "VALOR"); |
| 296 | return contaAReceber; |
304 | return contaAReceber; |
| 297 | }
|
305 | }
|
| 298 | 306 | ||
| 299 | private Taxa consultarTaxa(VendaFormaPagamento vendaFormaPagamento) { |
307 | private Taxa consultarTaxa(VendaFormaPagamento vendaFormaPagamento) { |
| 300 | Taxa taxa = new Taxa(); |
- | |
| 301 | taxa.setEmpresaAdquirente(vendaFormaPagamento.getEmpresaAdquirenteDaMaquinetaDaVenda()); |
- | |
| 302 | taxa.setFormaPagamento(vendaFormaPagamento.getFormaPagamento()); |
- | |
| 303 | taxa.setBandeiraCartao(vendaFormaPagamento.getBandeiraCartao()); |
- | |
| 304 | taxa = taxaService.consultarTaxa(taxa); |
- | |
| 305 | if (VerificadorUtil.estaNulo(taxa)) { |
- | |
| 306 | taxa = new Taxa(); |
- | |
| - | 308 | try { |
|
| - | 309 | Taxa taxa = new Taxa(); |
|
| 307 | taxa.setEmpresaAdquirente(vendaFormaPagamento.getEmpresaAdquirenteDaMaquinetaDaVenda()); |
310 | taxa.setEmpresaAdquirente(vendaFormaPagamento.getEmpresaAdquirenteDaMaquinetaDaVenda()); |
| 308 | taxa.setFormaPagamento(vendaFormaPagamento.getFormaPagamento()); |
311 | taxa.setFormaPagamento(vendaFormaPagamento.getFormaPagamento()); |
| - | 312 | taxa.setBandeiraCartao(vendaFormaPagamento.getBandeiraCartao()); |
|
| 309 | taxa = taxaService.consultarTaxa(taxa); |
313 | taxa = taxaService.consultarTaxa(taxa); |
| - | 314 | if (VerificadorUtil.estaNulo(taxa)) { |
|
| - | 315 | taxa = new Taxa(); |
|
| - | 316 | taxa.setEmpresaAdquirente(vendaFormaPagamento.getEmpresaAdquirenteDaMaquinetaDaVenda()); |
|
| - | 317 | taxa.setFormaPagamento(vendaFormaPagamento.getFormaPagamento()); |
|
| - | 318 | taxa = taxaService.consultarTaxa(taxa); |
|
| - | 319 | }
|
|
| - | 320 | if (VerificadorUtil.estaNulo(taxa)) { |
|
| - | 321 | taxa = new Taxa(); |
|
| - | 322 | taxa.setContaBancaria(new ContaBancaria(new Long(1))); |
|
| - | 323 | }
|
|
| - | 324 | return taxa; |
|
| - | 325 | } catch (Exception e) { |
|
| - | 326 | throw new NegocioException(e.getMessage()); |
|
| 310 | }
|
327 | }
|
| 311 | if (VerificadorUtil.estaNulo(taxa)) { |
- | |
| 312 | taxa = new Taxa(); |
- | |
| 313 | taxa.setContaBancaria(new ContaBancaria(new Long(1))); |
- | |
| 314 | }
|
- | |
| 315 | return taxa; |
- | |
| 316 | }
|
328 | }
|
| 317 | 329 | ||
| 318 | private Double calcularValorParcela(Taxa taxa, Double valorPagamento) { |
330 | private Double calcularValorParcela(Taxa taxa, Double valorPagamento) { |
| 319 | Double valorParcelaCalculado = new Double(0.0); |
331 | Double valorParcelaCalculado = new Double(0.0); |
| 320 | if (VerificadorUtil.naoEstaNulo(taxa)) { |
332 | if (VerificadorUtil.naoEstaNulo(taxa)) { |