Rev 309 | Rev 352 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 309 | Rev 317 | ||
|---|---|---|---|
| Line 170... | Line 170... | ||
| 170 | 170 | ||
| 171 | @Override |
171 | @Override |
| 172 | public Conta gerarParcelas(VendaFormaPagamento vendaFormaPagamento, Conta conta) { |
172 | public Conta gerarParcelas(VendaFormaPagamento vendaFormaPagamento, Conta conta) { |
| 173 | Taxa taxa = consultarTaxa(vendaFormaPagamento); |
173 | Taxa taxa = consultarTaxa(vendaFormaPagamento); |
| 174 | Double valorParcelaCalculado = calcularValorParcela(taxa, vendaFormaPagamento.getValorPagamento()); |
174 | Double valorParcelaCalculado = calcularValorParcela(taxa, vendaFormaPagamento.getValorPagamento()); |
| 175 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDebito()) {return criarParcelaDebito(valorParcelaCalculado, taxa.getContaBancaria(), vendaFormaPagamento, conta);} |
- | |
| 176 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhCredito()) {return criarParcelaCredito(valorParcelaCalculado, taxa.getContaBancaria(), vendaFormaPagamento, conta);} |
- | |
| 177 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhPagseguro()) {return criarParcelaPagseguro(valorParcelaCalculado, taxa.getContaBancaria(), vendaFormaPagamento, conta);} |
- | |
| - | 175 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDebito()) {return criarParcelaDebito(valorParcelaCalculado, taxa, vendaFormaPagamento, conta);} |
|
| - | 176 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhCredito()) {return criarParcelaCredito(valorParcelaCalculado, taxa, vendaFormaPagamento, conta);} |
|
| 178 | return conta; |
177 | return conta; |
| 179 | }
|
178 | }
|
| 180 | 179 | ||
| 181 | private Conta criarParcelaDebito(Double valorParcelaCalculado, ContaBancaria contaBancaria, VendaFormaPagamento vendaFormaPagamento, Conta conta) { |
- | |
| 182 | Date dataDebito = DataUtils.acrescentarDiasResultadoDiaUtil(vendaFormaPagamento.getVenda().getDataVenda(), 1); |
- | |
| 183 | cadastrarParcelas(vendaFormaPagamento, contaBancaria, dataDebito, valorParcelaCalculado, conta, "DÉBITO"); |
- | |
| - | 180 | private Conta criarParcelaDebito(Double valorParcelaCalculado, Taxa taxa, VendaFormaPagamento vendaFormaPagamento, Conta conta) { |
|
| - | 181 | Date dataDebito = vendaFormaPagamento.getVenda().getDataVenda(); |
|
| - | 182 | if (taxa.getQuantidadeDiasPrimeiraParcela() > 0) { |
|
| - | 183 | dataDebito = DataUtils.acrescentarDiasResultadoDiaUtil(dataDebito, taxa.getQuantidadeDiasPrimeiraParcela()); |
|
| - | 184 | }
|
|
| - | 185 | cadastrarParcelas(vendaFormaPagamento, taxa.getContaBancaria(), dataDebito, valorParcelaCalculado, conta, taxa.getFormaPagamento().getDescricao()); |
|
| 184 | return conta; |
186 | return conta; |
| 185 | }
|
187 | }
|
| 186 | 188 | ||
| 187 | private Conta criarParcelaCredito(Double valorParcelaCalculado, ContaBancaria contaBancaria, VendaFormaPagamento vendaFormaPagamento, Conta contaAReceber) { |
- | |
| 188 | Integer quantidadeVezes = 0; |
- | |
| 189 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh1x()) {quantidadeVezes = 1;} |
- | |
| 190 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh2x()) {quantidadeVezes = 2;} |
- | |
| 191 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh3x()) {quantidadeVezes = 3;} |
- | |
| 192 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh4x()) {quantidadeVezes = 4;} |
- | |
| 193 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh5x()) {quantidadeVezes = 5;} |
- | |
| 194 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh6x()) {quantidadeVezes = 6;} |
- | |
| 195 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh7x()) {quantidadeVezes = 7;} |
- | |
| 196 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh8x()) {quantidadeVezes = 8;} |
- | |
| 197 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh9x()) {quantidadeVezes = 9;} |
- | |
| 198 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh10x()) {quantidadeVezes = 10;} |
- | |
| 199 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh11x()) {quantidadeVezes = 11;} |
- | |
| 200 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh12x()) {quantidadeVezes = 12;} |
- | |
| 201 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh13x()) {quantidadeVezes = 13;} |
- | |
| 202 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh14x()) {quantidadeVezes = 14;} |
- | |
| 203 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh15x()) {quantidadeVezes = 15;} |
- | |
| 204 | Date dataParcela = vendaFormaPagamento.getVenda().getDataVenda(); |
- | |
| 205 | Date dataInicial = vendaFormaPagamento.getVenda().getDataVenda(); |
- | |
| 206 | for (int i = 1; i <= quantidadeVezes; i++) { |
- | |
| 207 | if (i == 1) { |
- | |
| 208 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh1x()) { |
- | |
| 209 | dataParcela = DataUtils.acrescentarDias(dataParcela, 2); |
- | |
| - | 189 | private Conta criarParcelaCredito(Double valorParcelaCalculado, Taxa taxa, VendaFormaPagamento vendaFormaPagamento, Conta contaAReceber) { |
|
| - | 190 | if (taxa.getReceberParcelado()) { |
|
| - | 191 | Integer quantidadeVezes = 0; |
|
| - | 192 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh1x()) {quantidadeVezes = 1;} |
|
| - | 193 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh2x()) {quantidadeVezes = 2;} |
|
| - | 194 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh3x()) {quantidadeVezes = 3;} |
|
| - | 195 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh4x()) {quantidadeVezes = 4;} |
|
| - | 196 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh5x()) {quantidadeVezes = 5;} |
|
| - | 197 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh6x()) {quantidadeVezes = 6;} |
|
| - | 198 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh7x()) {quantidadeVezes = 7;} |
|
| - | 199 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh8x()) {quantidadeVezes = 8;} |
|
| - | 200 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh9x()) {quantidadeVezes = 9;} |
|
| - | 201 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh10x()) {quantidadeVezes = 10;} |
|
| - | 202 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh11x()) {quantidadeVezes = 11;} |
|
| - | 203 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh12x()) {quantidadeVezes = 12;} |
|
| - | 204 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh13x()) {quantidadeVezes = 13;} |
|
| - | 205 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh14x()) {quantidadeVezes = 14;} |
|
| - | 206 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh15x()) {quantidadeVezes = 15;} |
|
| - | 207 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh16x()) {quantidadeVezes = 16;} |
|
| - | 208 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh17x()) {quantidadeVezes = 17;} |
|
| - | 209 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEh18x()) {quantidadeVezes = 18;} |
|
| - | 210 | Date dataParcela = vendaFormaPagamento.getVenda().getDataVenda(); |
|
| - | 211 | Date dataInicial = vendaFormaPagamento.getVenda().getDataVenda(); |
|
| - | 212 | for (int i = 1; i <= quantidadeVezes; i++) { |
|
| - | 213 | if (i == 1) { |
|
| - | 214 | dataParcela = DataUtils.acrescentarDias(dataParcela, taxa.getQuantidadeDiasPrimeiraParcela()); |
|
| 210 | } else { |
215 | } else { |
| 211 | dataParcela = DataUtils.acrescentarDias(dataParcela, 31); |
- | |
| - | 216 | dataParcela = DataUtils.acrescentarDias(dataInicial, i * 30); |
|
| 212 | }
|
217 | }
|
| 213 | } else { |
- | |
| 214 | dataParcela = DataUtils.acrescentarDias(dataInicial, i * 30); |
- | |
| - | 218 | dataParcela = DataUtils.acrescentarDiasResultadoDiaUtil(dataParcela, 0); |
|
| - | 219 | cadastrarParcelas(vendaFormaPagamento, taxa.getContaBancaria(), dataParcela, valorParcelaCalculado / quantidadeVezes, contaAReceber, "CRÉDITO " + i + "/" + quantidadeVezes); |
|
| - | 220 | }
|
|
| - | 221 | } else { |
|
| - | 222 | Date dataParcela = vendaFormaPagamento.getVenda().getDataVenda(); |
|
| - | 223 | if (taxa.getQuantidadeDiasPrimeiraParcela() > 0) { |
|
| - | 224 | dataParcela = DataUtils.acrescentarDias(dataParcela, taxa.getQuantidadeDiasPrimeiraParcela()); |
|
| - | 225 | dataParcela = DataUtils.acrescentarDiasResultadoDiaUtil(dataParcela, 0); |
|
| 215 | }
|
226 | }
|
| 216 | dataParcela = DataUtils.acrescentarDiasResultadoDiaUtil(dataParcela, 0); |
- | |
| 217 | cadastrarParcelas(vendaFormaPagamento, contaBancaria, dataParcela, valorParcelaCalculado / quantidadeVezes, contaAReceber, "CRÉDITO " + i + "/" + quantidadeVezes); |
- | |
| - | 227 | cadastrarParcelas(vendaFormaPagamento, taxa.getContaBancaria(), dataParcela, valorParcelaCalculado, contaAReceber, "CRÉDITO 1/1"); |
|
| 218 | }
|
228 | }
|
| 219 | return contaAReceber; |
229 | return contaAReceber; |
| 220 | }
|
230 | }
|
| 221 | 231 | ||
| 222 | @Override |
232 | @Override |
| Line 227... | Line 237... | ||
| 227 | listaVendaFormaPagamento.addAll(vendaFormaPagamentoService.consultarLancamentosDaVenda(venda)); |
237 | listaVendaFormaPagamento.addAll(vendaFormaPagamentoService.consultarLancamentosDaVenda(venda)); |
| 228 | for (VendaFormaPagamento vendaFormaPagamento : listaVendaFormaPagamento) { |
238 | for (VendaFormaPagamento vendaFormaPagamento : listaVendaFormaPagamento) { |
| 229 | Taxa taxa = consultarTaxa(vendaFormaPagamento); |
239 | Taxa taxa = consultarTaxa(vendaFormaPagamento); |
| 230 | Double valorParcelaCalculado = calcularValorParcela(taxa, vendaFormaPagamento.getValorPagamento()); |
240 | Double valorParcelaCalculado = calcularValorParcela(taxa, vendaFormaPagamento.getValorPagamento()); |
| 231 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDinheiro()) {criarParcelaDinheiro(vendaFormaPagamento, conta);} |
241 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDinheiro()) {criarParcelaDinheiro(vendaFormaPagamento, conta);} |
| 232 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDebito()) {criarParcelaDebito(valorParcelaCalculado, taxa.getContaBancaria(), vendaFormaPagamento, conta);} |
- | |
| 233 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhCredito()) {criarParcelaCredito(valorParcelaCalculado, taxa.getContaBancaria(), vendaFormaPagamento, conta);} |
- | |
| 234 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhPagseguro()) {criarParcelaPagseguro(valorParcelaCalculado, taxa.getContaBancaria(), vendaFormaPagamento, conta);} |
- | |
| - | 242 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDebito()) {criarParcelaDebito(valorParcelaCalculado, taxa, vendaFormaPagamento, conta);} |
|
| - | 243 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhCredito()) {criarParcelaCredito(valorParcelaCalculado, taxa, vendaFormaPagamento, conta);} |
|
| 235 | }
|
244 | }
|
| 236 | return conta; |
245 | return conta; |
| 237 | }
|
246 | }
|
| 238 | throw new NegocioException("NENHUMA PARCELA FOI CRIADA"); |
247 | throw new NegocioException("NENHUMA PARCELA FOI CRIADA"); |
| 239 | }
|
248 | }
|
| Line 244... | Line 253... | ||
| 244 | contaAReceber = cadastrarContaCasoNaoTenhaSidoCadastrada(contaAReceber); |
253 | contaAReceber = cadastrarContaCasoNaoTenhaSidoCadastrada(contaAReceber); |
| 245 | List<VendaFormaPagamento> listaVendaFormaPagamento = new ArrayList<VendaFormaPagamento>(); |
254 | List<VendaFormaPagamento> listaVendaFormaPagamento = new ArrayList<VendaFormaPagamento>(); |
| 246 | listaVendaFormaPagamento.addAll(vendaFormaPagamentoService.consultarLancamentosDaVenda(venda)); |
255 | listaVendaFormaPagamento.addAll(vendaFormaPagamentoService.consultarLancamentosDaVenda(venda)); |
| 247 | for (VendaFormaPagamento vendaFormaPagamento : listaVendaFormaPagamento) { |
256 | for (VendaFormaPagamento vendaFormaPagamento : listaVendaFormaPagamento) { |
| 248 | Taxa taxa = consultarTaxa(vendaFormaPagamento); |
257 | Taxa taxa = consultarTaxa(vendaFormaPagamento); |
| 249 | Double valorParcelaCalculado = calcularValorParcela(taxa, vendaFormaPagamento.getValorPagamento()); |
- | |
| 250 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDinheiro()) {criarParcelaDinheiro(vendaFormaPagamento, contaAReceber);} |
258 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDinheiro()) {criarParcelaDinheiro(vendaFormaPagamento, contaAReceber);} |
| 251 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhPagseguro()) {criarParcelaPagseguro(valorParcelaCalculado, taxa.getContaBancaria(), vendaFormaPagamento, contaAReceber);} |
- | |
| 252 | }
|
259 | }
|
| 253 | return contaAReceber; |
260 | return contaAReceber; |
| 254 | }
|
261 | }
|
| 255 | throw new NegocioException("NENHUMA PARCELA FOI CRIADA"); |
262 | throw new NegocioException("NENHUMA PARCELA FOI CRIADA"); |
| 256 | }
|
263 | }
|
| Line 262... | Line 269... | ||
| 262 | List<VendaFormaPagamento> listaVendaFormaPagamento = new ArrayList<VendaFormaPagamento>(); |
269 | List<VendaFormaPagamento> listaVendaFormaPagamento = new ArrayList<VendaFormaPagamento>(); |
| 263 | listaVendaFormaPagamento.addAll(vendaFormaPagamentoService.consultarLancamentosDaVenda(venda)); |
270 | listaVendaFormaPagamento.addAll(vendaFormaPagamentoService.consultarLancamentosDaVenda(venda)); |
| 264 | for (VendaFormaPagamento vendaFormaPagamento : listaVendaFormaPagamento) { |
271 | for (VendaFormaPagamento vendaFormaPagamento : listaVendaFormaPagamento) { |
| 265 | Taxa taxa = consultarTaxa(vendaFormaPagamento); |
272 | Taxa taxa = consultarTaxa(vendaFormaPagamento); |
| 266 | Double valorParcelaCalculado = calcularValorParcela(taxa, vendaFormaPagamento.getValorPagamento()); |
273 | Double valorParcelaCalculado = calcularValorParcela(taxa, vendaFormaPagamento.getValorPagamento()); |
| 267 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDebito()) {criarParcelaDebito(valorParcelaCalculado, taxa.getContaBancaria(), vendaFormaPagamento, conta);} |
- | |
| 268 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhCredito()) {criarParcelaCredito(valorParcelaCalculado, taxa.getContaBancaria(), vendaFormaPagamento, conta);} |
- | |
| - | 274 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhDebito()) {criarParcelaDebito(valorParcelaCalculado, taxa, vendaFormaPagamento, conta);} |
|
| - | 275 | if (vendaFormaPagamento.getFormaPagamento().formaPagamentoEhCredito()) {criarParcelaCredito(valorParcelaCalculado, taxa, vendaFormaPagamento, conta);} |
|
| 269 | }
|
276 | }
|
| 270 | return conta; |
277 | return conta; |
| 271 | }
|
278 | }
|
| 272 | throw new NegocioException("NENHUMA PARCELA FOI CRIADA"); |
279 | throw new NegocioException("NENHUMA PARCELA FOI CRIADA"); |
| 273 | }
|
280 | }
|
| Line 281... | Line 288... | ||
| 281 | return conta; |
288 | return conta; |
| 282 | }
|
289 | }
|
| 283 | 290 | ||
| 284 | private Conta criarParcelaDinheiro(VendaFormaPagamento vendaFormaPagamento, Conta contaAReceber) { |
291 | private Conta criarParcelaDinheiro(VendaFormaPagamento vendaFormaPagamento, Conta contaAReceber) { |
| 285 | cadastrarParcelas(vendaFormaPagamento, new ContaBancaria(ContaBancaria.getContaCaixa()), vendaFormaPagamento.getVenda().getDataVenda(), vendaFormaPagamento.getValorPagamento(), contaAReceber, "VALOR"); |
292 | cadastrarParcelas(vendaFormaPagamento, new ContaBancaria(ContaBancaria.getContaCaixa()), vendaFormaPagamento.getVenda().getDataVenda(), vendaFormaPagamento.getValorPagamento(), contaAReceber, "VALOR"); |
| 286 | return contaAReceber; |
- | |
| 287 | }
|
- | |
| 288 | - | ||
| 289 | private Conta criarParcelaPagseguro(Double valorParcelaCalculado, ContaBancaria contaBancaria, VendaFormaPagamento vendaFormaPagamento, Conta contaAReceber) { |
- | |
| 290 | cadastrarParcelas(vendaFormaPagamento, contaBancaria, vendaFormaPagamento.getVenda().getDataVenda(), valorParcelaCalculado, contaAReceber, "PAGSEGURO"); |
- | |
| 291 | return contaAReceber; |
293 | return contaAReceber; |
| 292 | }
|
294 | }
|
| 293 | 295 | ||
| 294 | private Taxa consultarTaxa(VendaFormaPagamento vendaFormaPagamento) { |
296 | private Taxa consultarTaxa(VendaFormaPagamento vendaFormaPagamento) { |
| 295 | Taxa taxa = new Taxa(); |
297 | Taxa taxa = new Taxa(); |
| Line 325... | Line 327... | ||
| 325 | private Double descontarTaxa(Double valorPagamento, Double taxa) { |
327 | private Double descontarTaxa(Double valorPagamento, Double taxa) { |
| 326 | return new Double (new DecimalFormat("#.##").format(valorPagamento - (valorPagamento * taxa / 100)).replace(",", ".")); |
328 | return new Double (new DecimalFormat("#.##").format(valorPagamento - (valorPagamento * taxa / 100)).replace(",", ".")); |
| 327 | }
|
329 | }
|
| 328 | 330 | ||
| 329 | private void cadastrarParcelas(VendaFormaPagamento vendaFormaPagamento, ContaBancaria contaBancaria, Date dataVencimento, Double valorPagamento, Conta conta, String observacao) { |
331 | private void cadastrarParcelas(VendaFormaPagamento vendaFormaPagamento, ContaBancaria contaBancaria, Date dataVencimento, Double valorPagamento, Conta conta, String observacao) { |
| 330 | Parcela parcela = new Parcela(conta, contaBancaria, vendaFormaPagamento.getVenda().getDataVenda(), dataVencimento, null, valorPagamento, observacao + " DA VENDA: " + vendaFormaPagamento.getVenda().getSequencial(), vendaFormaPagamento.getFormaPagamento(), true); |
- | |
| - | 332 | Parcela parcela = new Parcela(conta, contaBancaria, vendaFormaPagamento.getVenda().getDataVenda(), dataVencimento, null, valorPagamento, observacao + " DA VENDA: " + vendaFormaPagamento.getVenda().getSequencial() + " (" + vendaFormaPagamento.getDescricaoDaBandeiraCartao() + ")", vendaFormaPagamento.getFormaPagamento(), true); |
|
| 331 | this.cadastrar(parcela); |
333 | this.cadastrar(parcela); |
| 332 | }
|
334 | }
|
| 333 | 335 | ||
| 334 | @Override |
336 | @Override |
| 335 | public Boolean verificarPossuiParcelaAberta(Venda venda) { |
337 | public Boolean verificarPossuiParcelaAberta(Venda venda) { |