diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/ConferenciaComissaoHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/ConferenciaComissaoHibernateDAO.java index d2e968d58..f3e051d9c 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/ConferenciaComissaoHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/ConferenciaComissaoHibernateDAO.java @@ -707,9 +707,7 @@ public class ConferenciaComissaoHibernateDAO extends GenericHibernateDAO lsOcd) throws BusinessException; - public BigDecimal totalizarBoletoComissao(List lsBoletoComissao, IndStatusBoleto... statusBilhete) throws BusinessException; + public BigDecimal totalizarBoletoComissao(List lsBoletoComissao, Boolean indreimpression, IndStatusBoleto... statusBilhete) throws BusinessException; public BigDecimal totalizarEventosFinanceiros(List lsEventosFinanceiros) throws BusinessException; diff --git a/src/com/rjconsultores/ventaboletos/service/impl/ConferenciaComissaoServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/ConferenciaComissaoServiceImpl.java index 25973da71..83b52e5d7 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/ConferenciaComissaoServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/ConferenciaComissaoServiceImpl.java @@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.zkoss.util.resource.Labels; +import com.rjconsultores.ventaboletos.constantes.Constantes; import com.rjconsultores.ventaboletos.dao.ConferenciaComissaoDAO; import com.rjconsultores.ventaboletos.dao.EmpresaDAO; import com.rjconsultores.ventaboletos.dao.PuntoVentaDAO; @@ -374,7 +375,7 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic } @Override - public BigDecimal totalizarBoletoComissao(List lsBoletoComissao, IndStatusBoleto... statusBilhete) throws BusinessException { + public BigDecimal totalizarBoletoComissao(List lsBoletoComissao, Boolean indreimpression, IndStatusBoleto... statusBilhete) throws BusinessException { List lStatusBilhete = null; if (statusBilhete != null && statusBilhete.length > 0) { lStatusBilhete = Arrays.asList(statusBilhete); @@ -383,6 +384,10 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic BigDecimal total = BigDecimal.ZERO; if (lsBoletoComissao != null) { for (BoletoComissao boletoComissao : lsBoletoComissao) { + if(indreimpression != null && !indreimpression.equals(boletoComissao.getIndreimpresion())) { + continue; + } + if ((lStatusBilhete == null || lStatusBilhete.contains(boletoComissao.getIndstatusboletoEnum())) && !boletoComissao.isVendaBilheteConfirmaAberto(boletoComissao.getTipoVenta())) { total = total.add(boletoComissao.getTotal()); @@ -399,7 +404,7 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic BigDecimal totalOcd = BigDecimal.ZERO; if (lsBoletoComissao != null) { for (BoletoComissao boletoComissao : lsBoletoComissao) { - if (boletoComissao.isMotivocancelacionGeracaoOcd()) { + if (boletoComissao.isOcd()) { totalOcd = totalOcd.add(boletoComissao.getTotal()); } else if (boletoComissao.isMotivocancelacionDevolvido()) { totalDevolvidos = totalDevolvidos.add(boletoComissao.getTotal()); @@ -453,13 +458,63 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic resumoComissao.setTotalOcd(totalOcd); carregarTotalFormapago(resumoComissao, boletoComissaos, lsEventosFinanceiros); + + subtrairOcdFormapagoDinheiro(totalOcd, resumoComissao); - resumoComissao.setValorDeposito(conferenciaComissaoDAO.carregarValorDepositoContaCorrente(conferencia.getEmpresa().getEmpresaId(), conferencia.getPuntoVenta().getPuntoventaId(), conferencia.getDatamovimento())); + resumoComissao.setValorDeposito(carregarTotalFormapagoDinheiro(resumoComissao)); resumoComissao.setQuantidadeEcf(puntoVentaDAO.quantidadeECFPorPuntoVenta(conferencia.getEmpresa().getEmpresaId(), conferencia.getPuntoVenta().getPuntoventaId())); return resumoComissao; } + /** + * Retorna o valor total de forma pago do tipo DINHEIRO + * @param resumoComissao + * @return + */ + private BigDecimal carregarTotalFormapagoDinheiro(ResumoComissao resumoComissao) { + for (FormapagoVO formapagoVO : resumoComissao.getTotalFormapago()) { + if(formapagoVO.getFormapagoId().equals(Constantes.FORMA_PAGO_DINHEIRO.intValue())) { + return formapagoVO.getImporte(); + } + } + + return BigDecimal.ZERO; + } + + /** + * Subtrai do total de forma pago o total pago das ocds. + * @param totalOcd + * @param resumoComissao + */ + private void subtrairOcdFormapagoDinheiro(OcdVO totalOcd, ResumoComissao resumoComissao) { + FormapagoVO formapagoDinheiro = null; + for (FormapagoVO formapagoVO : resumoComissao.getTotalFormapago()) { + if(formapagoVO.getFormapagoId().equals(Constantes.FORMA_PAGO_DINHEIRO.intValue())) { + formapagoDinheiro = formapagoVO; + break; + } + } + + if(formapagoDinheiro == null) { + formapagoDinheiro = new FormapagoVO(Constantes.FORMA_PAGO_DINHEIRO.intValue(), "DINHEIRO", null, BigDecimal.ZERO); + } + + formapagoDinheiro.subtract(totalOcd.getValorPagar()); + + if(!resumoComissao.getTotalFormapago().contains(formapagoDinheiro)) { + resumoComissao.getTotalFormapago().add(formapagoDinheiro); + } + } + + /** + * Totaliza os valores conforme o forma pago, apenas do bilhetes que geraram registros em caixa + * (+) Abas: Bilhetes Manual, Bilhetes, Gap Venda + * (-) Abas: Bilhetes Cancelados, Bilhetes Devolvidos, Gap Cancelados, Gap Devolvidos + * @param resumoComissao + * @param boletoComissaos + * @param lsEventosFinanceiros + */ private void carregarTotalFormapago(ResumoComissao resumoComissao, List boletoComissaos, List lsEventosFinanceiros) { List totalFormapagos = new ArrayList(); for (BoletoComissao boletoComissao : boletoComissaos) { @@ -473,9 +528,9 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic totalFormapagos.add(formapago); } - if (boletoComissao.isStatusVendido() || boletoComissao.isStatusTroca()) { + if (boletoComissao.isAbaBilheteVendido() || boletoComissao.isAbaGapVendido() || boletoComissao.isAbaBilheteManual()) { formapago.add(formapagoBoleto.getImporte()); - } else if (boletoComissao.isAbaBilheteCancelado() || boletoComissao.isAbaBilheteDevolvido() || boletoComissao.isAbaGapCancelado() || boletoComissao.isAbaGapDevolvido()) { + } else if ((boletoComissao.isAbaBilheteCancelado() || boletoComissao.isAbaBilheteDevolvido() || boletoComissao.isAbaGapCancelado() || boletoComissao.isAbaGapDevolvido())) { formapago.subtract(formapagoBoleto.getImporte()); } } diff --git a/src/com/rjconsultores/ventaboletos/vo/comissao/BoletoComissao.java b/src/com/rjconsultores/ventaboletos/vo/comissao/BoletoComissao.java index 7e1e814fe..290adfe86 100644 --- a/src/com/rjconsultores/ventaboletos/vo/comissao/BoletoComissao.java +++ b/src/com/rjconsultores/ventaboletos/vo/comissao/BoletoComissao.java @@ -75,9 +75,10 @@ public class BoletoComissao { private Integer corridaId; private Boolean indCancelacion; + + private Boolean indreimpresion; private Integer tipoventaAnteriorId; - private Long boletoAnteriorId; public Integer getEmpresaId() { return empresaId; @@ -389,17 +390,25 @@ public class BoletoComissao { public String getSituacaoBilhete() { if (isOcd()) { return "OCD"; - } else if ((isStatusCancelado()) && (isMotivocancelacionDevolvido() || isMotivocancelacionCancelado()) + } + + if(isStatusVendido()) { + return IndStatusBoleto.getIndStatusBoleto(getIndstatusboleto()).getValue(); + } + + if ((isStatusCancelado()) && (isMotivocancelacionDevolvido() || isMotivocancelacionCancelado()) && StringUtils.isNotBlank(getDescmotivocancelacion())) { return getDescmotivocancelacion(); - } else if ((isStatusVendido() || isStatusCancelado()) - && !isMotivocancelacionDevolvido() && !isMotivocancelacionCancelado()) { - if (isStatusCancelado() && isMotivocancelacionTrocado()) { - return "B. VENDIDO TROCADO"; - } else if (isStatusVendido() && isMotivocancelacionTransferido()) { - return "B. VENDIDO TRANSFERIDO"; + } + + if (isStatusCancelado()) { + if (isMotivocancelacionTrocado() || (isMotivocancelacionGeracaoOcd() && isFormapagoTrocaPassagem())) { + return "TROCADO"; + } else if (isMotivocancelacionTransferido()) { + return "TRANSFERIDO"; } - } else if (isStatusTroca()) { + } + if (isStatusTroca()) { if (isVendaBilheteTroca(getTipoVenta()) || isVendaGap(getTipoVenta())) { return "B. DA TROCA"; } else if (isVendaBilheteTransferencia(getTipoVenta()) || isVendaGap(getTipoVenta())) { @@ -413,8 +422,16 @@ public class BoletoComissao { return indStatusBoleto != null ? indStatusBoleto.getValue() : ""; } + public boolean isFormapagoTrocaPassagem() { + boolean fpTrocapassagem = false; + for (FormapagoVO formapagoVO : formapagos) { + fpTrocapassagem = formapagoVO.getFormapagoId().equals(Constantes.FORMA_PAGO_TROCA_PASSAGEM.intValue()); + } + return fpTrocapassagem; + } + public boolean isOcd() { - return getOcdId() != null && isStatusCancelado(); + return getOcdId() != null && isStatusCancelado() && !isFormapagoTrocaPassagem(); } public String getNombusuario() { @@ -742,21 +759,19 @@ public class BoletoComissao { public boolean isTotalizarFormapago() { boolean totalizar = isTotalizarTipovenda(); - if (totalizar) { - totalizar = !isOcd(); - } - + totalizar = !isOcd(); + totalizar = !getIndreimpresion(); return totalizar; } private boolean isTotalizarTipovenda() { - return isAbaBilheteCancelado() || + return isAbaBilheteManual() || + isAbaBilheteVendido() || + isAbaBilheteCancelado() || isAbaBilheteDevolvido() || - isAbaGapCancelado() || - isAbaGapDevolvido() || - isAbaBilheteManual() || isAbaGapVendido() || - isAbaBilheteVendido(); + isAbaGapCancelado() || + isAbaGapDevolvido(); } public String getOrderExigeConferencia() { @@ -786,15 +801,15 @@ public class BoletoComissao { return false; } - if(isMotivocancelacionTransferido()) { - return false; - } - if(isVendaGap(getTipoVenta()) && !isStatusEntregue()) { return false; } - return isStatusVendido() || isStatusEntregue() || isStatusTroca(); + if((isVendaBilheteTransferencia(getTipoVenta())) && isVendaGap(getTipoVentaOriginal())) { + return false; + } + + return isStatusVendido() || isStatusTroca() || isStatusEntregue(); } /** Define bilhete na aba de venda cancelada */ @@ -837,11 +852,11 @@ public class BoletoComissao { return false; } - if(isMotivocancelacionTransferido()) { + if(!isVendaGap(getTipoVenta()) && !isVendaBilheteTransferencia(getTipoVenta())) { return false; } - - if(!isVendaGap(getTipoVenta())) { + + if((isVendaBilheteTransferencia(getTipoVenta())) && !isVendaGap(getTipoVentaOriginal())) { return false; } @@ -905,17 +920,17 @@ public class BoletoComissao { public void setTipoventaAnteriorId(Integer tipoventaAnteriorId) { this.tipoventaAnteriorId = tipoventaAnteriorId; } - - public Long getBoletoAnteriorId() { - return boletoAnteriorId; - } - - public void setBoletoAnteriorId(Long boletoAnteriorId) { - this.boletoAnteriorId = boletoAnteriorId; - } private boolean isNotNumFolioPreImpressoGerado() { return StringUtils.isBlank(getNumFolioPreImpreso()); } + public Boolean getIndreimpresion() { + return indreimpresion; + } + + public void setIndreimpresion(Boolean indreimpresion) { + this.indreimpresion = indreimpresion; + } + } diff --git a/src/com/rjconsultores/ventaboletos/vo/comissao/FormapagoVO.java b/src/com/rjconsultores/ventaboletos/vo/comissao/FormapagoVO.java index c265ad5a9..98a103856 100644 --- a/src/com/rjconsultores/ventaboletos/vo/comissao/FormapagoVO.java +++ b/src/com/rjconsultores/ventaboletos/vo/comissao/FormapagoVO.java @@ -4,6 +4,7 @@ import java.math.BigDecimal; import com.rjconsultores.ventaboletos.utilerias.BigDecimalUtil; import com.rjconsultores.ventaboletos.utilerias.LocaleUtil; +import com.rjconsultores.ventaboletos.utilerias.MoneyHelper; public class FormapagoVO { @@ -89,11 +90,11 @@ public class FormapagoVO { } public void add(BigDecimal importe) { - this.importe = this.importe.add(importe != null ? importe : BigDecimal.ZERO); + this.importe = MoneyHelper.somar(this.importe, (importe != null ? importe : BigDecimal.ZERO)); } public void subtract(BigDecimal importe) { - this.importe = this.importe.subtract(importe != null ? importe : BigDecimal.ZERO); + this.importe = MoneyHelper.subtrair(this.importe,(importe != null ? importe : BigDecimal.ZERO)); } }