From 151e540b7760719358d29ff345c67b519bddb728 Mon Sep 17 00:00:00 2001 From: wilian Date: Wed, 23 Mar 2016 13:32:42 +0000 Subject: [PATCH] fixes bug #7265 git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@54170 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../ventaboletos/constantes/Constantes.java | 3 + .../ConferenciaComissaoHibernateDAO.java | 66 +++------ .../enums/comissao/BoletoStatusComissao.java | 2 + .../service/ConferenciaComissaoService.java | 3 + .../impl/ConferenciaComissaoServiceImpl.java | 140 +++++++++++++++--- .../vo/comissao/BoletoComissao.java | 58 +++++++- 6 files changed, 198 insertions(+), 74 deletions(-) diff --git a/src/com/rjconsultores/ventaboletos/constantes/Constantes.java b/src/com/rjconsultores/ventaboletos/constantes/Constantes.java index bec4d129f..a611c9850 100644 --- a/src/com/rjconsultores/ventaboletos/constantes/Constantes.java +++ b/src/com/rjconsultores/ventaboletos/constantes/Constantes.java @@ -7,6 +7,7 @@ import java.util.List; public class Constantes { + public static final Long FORMA_PAGO_DINHEIRO = new Long(1); public static final Long FORMA_PAGO_RESERVA = new Long(94); public static final Long FORMA_PAGO_NOTA_CREDITO = new Long(93); public static final Long FORMA_PAGO_CREDITO = new Long(2); @@ -14,6 +15,7 @@ public class Constantes { public static final Long MVO_CANCEL_CANCELACION = new Long(31); public static final Long MVO_CANCEL_DEVOLUCAO = new Long(32); + public static final Long MVO_CANCEL_TROCA = new Long(10); public static Long TPV_DIRECTO_NORMAL = new Long(1); public static Long TPV_MANUAL = new Long(3); @@ -40,5 +42,6 @@ public class Constantes { public static String CLAVE_ENCERRAR_MOVIMENTODIARIO = "COM.RJCONSULTORES.ADMINISTRACION.GUI.COMISSAO.MENU.CONFERENCIACOMISSAO.ENCERRARMOVIMENTODIARIO"; public static final String UTF_8 = "UTF-8"; + } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/ConferenciaComissaoHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/ConferenciaComissaoHibernateDAO.java index 1e9de7f31..96f596b50 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/ConferenciaComissaoHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/ConferenciaComissaoHibernateDAO.java @@ -176,12 +176,15 @@ public class ConferenciaComissaoHibernateDAO extends GenericHibernateDAO parametros = carregarParametros(null, conferencia.getEmpresa(), conferencia.getPuntoVenta()); StringBuilder sQuery = new StringBuilder(); - sQuery.append("SELECT B.BOLETO_ID AS \"boletoId\", B.NUMASIENTO AS \"numAsiento\", B.NUMASIENTOVINCULADO AS \"numAsientoVinculado\", B.NUMFOLIOSISTEMA AS \"numFolioSistema\", B.NUMSERIEPREIMPRESA AS \"numSeriePreimpresa\", ") + sQuery.append("SELECT B.BOLETO_ID AS \"boletoId\", B.NUMASIENTO AS \"numAsiento\", B.NUMASIENTOVINCULADO AS \"numAsientoVinculado\", ") + .append("B.NUMOPERACION AS \"numoperacion\", B.NUMFOLIOSISTEMA AS \"numFolioSistema\", B.NUMSERIEPREIMPRESA AS \"numSeriePreimpresa\", ") .append("B.NUMFOLIOPREIMPRESO AS \"numFolioPreImpreso\", EST.CVEESTADO AS \"uf\", CAT.DESCCATEGORIA AS \"desccategoria\", ") .append("NVL(B.PRECIOPAGADO,0) AS \"valorpagado\", NVL(B.IMPORTEOUTROS,0) AS \"seguroOutros\", ") .append("NVL(B.IMPORTEPEDAGIO,0) AS \"pedagio\", NVL(B.IMPORTESEGURO,0) AS \"seguro\", NVL(B.IMPORTETAXAEMBARQUE,0) AS \"embarque\", ") .append("B.TIPOVENTA_ID AS \"tipoVenta\", B.INDSTATUSBOLETO AS \"indstatusboleto\", LOG.STATUS AS \"status\", ") .append("FP.FORMAPAGO_ID AS \"formapagoId\", FP.DESCPAGO AS \"descpago\", LOG.LOGCONFERENCIA_ID AS \"logconferenciaId\", ") .append("MC.DESCMOTIVO AS \"descmotivocancelacion\", U.NOMBUSUARIO AS \"nombusuario\", B.MOTIVOCANCELACION_ID AS \"motivocancelacionId\", ") - .append("BF.IMPORTE AS \"importeFp\", COMFP.COMEMPFORMAPAGO_ID AS \"comempformapagoId\", COMCAT.COMEMPCATEGORIA_ID AS \"comempcategoriaId\" ") + .append("BF.IMPORTE AS \"importeFp\", COMFP.COMEMPFORMAPAGO_ID AS \"comempformapagoId\", COMCAT.COMEMPCATEGORIA_ID AS \"comempcategoriaId\", ") + .append("BO1.TIPOVENTA_ID \"tipoVentaOriginal1\", BO2.TIPOVENTA_ID \"tipoVentaOriginal2\", OCD.OCD_ID \"ocdId\" ") .append("FROM BOLETO B ") + .append("LEFT JOIN BOLETO BO1 ON BO1.BOLETO_ID = B.BOLETOORIGINAL_ID ") + .append("LEFT JOIN BOLETO BO2 ON BO2.BOLETO_ID = BO1.BOLETOORIGINAL_ID ") + .append("LEFT JOIN OCD OCD ON B.BOLETOORIGINAL_ID = OCD.BOLETO_ID ") .append("LEFT JOIN PARADA ORI ON ORI.PARADA_ID = B.ORIGEN_ID ") .append("LEFT JOIN CIUDAD CID ON CID.CIUDAD_ID = ORI.PARADA_ID ") .append("LEFT JOIN ESTADO EST ON EST.ESTADO_ID = CID.ESTADO_ID ") @@ -614,12 +622,15 @@ public class ConferenciaComissaoHibernateDAO extends GenericHibernateDAO totalizarBoletoComissaoDevolvidosTrocaOcd(List lsBoletoComissao) throws BusinessException; + } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/ConferenciaComissaoServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/ConferenciaComissaoServiceImpl.java index 6fd8ecfe4..139057c16 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/ConferenciaComissaoServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/ConferenciaComissaoServiceImpl.java @@ -4,7 +4,9 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -171,9 +173,7 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic private List carregarBilhetesVendidos(List boletoComissaos) { List boletos = new ArrayList(); for (BoletoComissao boletoComissao : boletoComissaos) { - if(IndStatusBoleto.V.getShortValue().equalsIgnoreCase(boletoComissao.getIndstatusboleto()) && - Constantes.TPV_BOLETO_REMOTO.intValue() != boletoComissao.getTipoVenta() && - Constantes.TPV_MANUAL.intValue() != boletoComissao.getTipoVenta()) { + if(isBilhetesNormalVendido(boletoComissao)) { boletos.add(boletoComissao); } } @@ -183,8 +183,7 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic private List carregarBilhetesManuais(List boletoComissaos) { List boletos = new ArrayList(); for (BoletoComissao boletoComissao : boletoComissaos) { - if(IndStatusBoleto.V.getShortValue().equalsIgnoreCase(boletoComissao.getIndstatusboleto()) && - Constantes.TPV_MANUAL.intValue() == boletoComissao.getTipoVenta()) { + if(isBilhetesManualVendido(boletoComissao)) { boletos.add(boletoComissao); } } @@ -194,10 +193,7 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic private List carregarBilhetesCancelados(List boletoComissaos) { List boletos = new ArrayList(); for (BoletoComissao boletoComissao : boletoComissaos) { - if(IndStatusBoleto.C.getShortValue().equalsIgnoreCase(boletoComissao.getIndstatusboleto()) && - Constantes.MVO_CANCEL_CANCELACION.intValue() == boletoComissao.getMotivoCancelacionId() && - Constantes.TPV_BOLETO_REMOTO.intValue() != boletoComissao.getTipoVenta() && - Constantes.TPV_MANUAL.intValue() != boletoComissao.getTipoVenta()) { + if(isBilhetesNormalCancelado(boletoComissao)) { boletos.add(boletoComissao); } } @@ -207,10 +203,7 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic private List carregarBilhetesDevolvidos(List boletoComissaos) { List boletos = new ArrayList(); for (BoletoComissao boletoComissao : boletoComissaos) { - if(IndStatusBoleto.C.getShortValue().equalsIgnoreCase(boletoComissao.getIndstatusboleto()) && - Constantes.MVO_CANCEL_DEVOLUCAO.intValue() == boletoComissao.getMotivoCancelacionId() && - Constantes.TPV_BOLETO_REMOTO.intValue() != boletoComissao.getTipoVenta() && - Constantes.TPV_MANUAL.intValue() != boletoComissao.getTipoVenta()) { + if(isBilhetesNormalDevolvido(boletoComissao) || isBilhetesNormalTrocado(boletoComissao)) { boletos.add(boletoComissao); } } @@ -220,8 +213,7 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic private List carregarBilhetesGapsVendidos(List boletoComissaos) { List boletos = new ArrayList(); for (BoletoComissao boletoComissao : boletoComissaos) { - if(IndStatusBoleto.V.getShortValue().equalsIgnoreCase(boletoComissao.getIndstatusboleto()) && - Constantes.TPV_BOLETO_REMOTO.intValue() == boletoComissao.getTipoVenta()) { + if(isBilhetesGapVendido(boletoComissao)) { boletos.add(boletoComissao); } } @@ -231,9 +223,7 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic private List carregarBilhetesGapCancelados(List boletoComissaos) { List boletos = new ArrayList(); for (BoletoComissao boletoComissao : boletoComissaos) { - if(IndStatusBoleto.C.getShortValue().equalsIgnoreCase(boletoComissao.getIndstatusboleto()) && - Constantes.MVO_CANCEL_CANCELACION.intValue() == boletoComissao.getMotivoCancelacionId() && - Constantes.TPV_BOLETO_REMOTO.intValue() == boletoComissao.getTipoVenta()) { + if(isBilhetesGapCancelado(boletoComissao)) { boletos.add(boletoComissao); } } @@ -243,9 +233,7 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic private List carregarBilhetesGapDevolvidos(List boletoComissaos) { List boletos = new ArrayList(); for (BoletoComissao boletoComissao : boletoComissaos) { - if(IndStatusBoleto.C.getShortValue().equalsIgnoreCase(boletoComissao.getIndstatusboleto()) && - Constantes.MVO_CANCEL_DEVOLUCAO.intValue() == boletoComissao.getMotivoCancelacionId() && - Constantes.TPV_BOLETO_REMOTO.intValue() == boletoComissao.getTipoVenta()) { + if(isBilhetesGapDevolvido(boletoComissao)) { boletos.add(boletoComissao); } } @@ -289,6 +277,29 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic } return total; } + + @Override + public Map totalizarBoletoComissaoDevolvidosTrocaOcd(List lsBoletoComissao) throws BusinessException { + BigDecimal totalDevolvidos = BigDecimal.ZERO; + BigDecimal totalTroca = BigDecimal.ZERO; + BigDecimal totalOcd = BigDecimal.ZERO; + if(lsBoletoComissao != null) { + for (BoletoComissao boletoComissao : lsBoletoComissao) { + if(boletoComissao.getOcdId() != null) { + totalOcd = totalOcd.add(boletoComissao.getTotal()); + } else if(boletoComissao.getIndstatusboleto().equals(IndStatusBoleto.C.getShortValue())) { + totalDevolvidos = totalOcd.add(boletoComissao.getTotal()); + } else if(boletoComissao.getIndstatusboleto().equals(IndStatusBoleto.T.getShortValue())) { + totalTroca = totalOcd.add(boletoComissao.getTotal()); + } + } + } + Map maps = new HashMap(); + maps.put(BoletoStatusComissao.BOLETO_DEVOLVIDO, totalDevolvidos); + maps.put(BoletoStatusComissao.BOLETO_DEVOLVIDO_OCD, totalOcd); + maps.put(BoletoStatusComissao.BOLETO_DEVOLVIDO_TROCADO, totalTroca); + return maps; + } @Override public BigDecimal totalizarEventosFinanceiros(List lsEventosFinanceiros) throws BusinessException { @@ -310,7 +321,6 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic if(lsOcd != null) { for (OcdVO ocd : lsOcd) { total.setValorPagar(total.getValorPagar().add(ocd.getValorPagar())); - total.setPenalizacion(total.getPenalizacion().add(ocd.getPenalizacion())); } } return total; @@ -327,18 +337,49 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic resumoComissao.setTotalReceitas(totalCreditosEventoFinanceiros); resumoComissao.setTotalDespesas(totalDebitosEventoFinanceiros); resumoComissao.setTotalOcd(totalOcd); - resumoComissao.setValorDeposito(conferenciaComissaoDAO.carregarTotalFechamentoContaCorrente(conferencia)); carregarTotalFormapago(resumoComissao, boletoComissaos, lsEventosFinanceiros); + + BigDecimal totalFormapagoDinheiro = getFormapagoDinheiro(resumoComissao); + totalFormapagoDinheiro = totalFormapagoDinheiro.subtract(carregarTotalDevolvidosDinhero(boletoComissaos)); + totalFormapagoDinheiro = totalFormapagoDinheiro.subtract(totalOcd.getValorPagar()); + + resumoComissao.setValorDeposito(totalFormapagoDinheiro); return resumoComissao; } + private BigDecimal carregarTotalDevolvidosDinhero(List boletoComissaos) { + BigDecimal totalDevolvidoDinheiro = BigDecimal.ZERO; + for (BoletoComissao boletoComissao : boletoComissaos) { + if(boletoComissao.getIndstatusboleto().equals(IndStatusBoleto.C.getShortValue()) && + boletoComissao.getMotivoCancelacionId() == Constantes.MVO_CANCEL_DEVOLUCAO.intValue()) { + for (FormapagoVO formapago : boletoComissao.getFormapagos()) { + if(formapago.getFormapagoId() == Constantes.FORMA_PAGO_DINHEIRO.intValue()) { + totalDevolvidoDinheiro = totalDevolvidoDinheiro.add(formapago.getImporte()); + } + } + } + } + return totalDevolvidoDinheiro; + } + + private BigDecimal getFormapagoDinheiro(ResumoComissao resumoComissao) { + for (FormapagoVO formapago : resumoComissao.getTotalFormapago()) { + if(formapago.getFormapagoId() == Constantes.FORMA_PAGO_DINHEIRO.intValue()) { + return formapago.getImporte(); + } + } + return BigDecimal.ZERO; + } + private void carregarTotalFormapago(ResumoComissao resumoComissao, List boletoComissaos, List lsEventosFinanceiros) { List totalFormapagos = new ArrayList(); for (BoletoComissao boletoComissao : boletoComissaos) { if(boletoComissao.getIndstatusboleto().equals(IndStatusBoleto.V.getShortValue()) && - boletoComissao.getMotivoCancelacionId() == null) { + (boletoComissao.getMotivoCancelacionId() == null || + boletoComissao.getMotivoCancelacionId() != Constantes.MVO_CANCEL_CANCELACION.intValue() || + boletoComissao.getMotivoCancelacionId() != Constantes.MVO_CANCEL_DEVOLUCAO.intValue())) { for (FormapagoVO formapagoBoleto : boletoComissao.getFormapagos()) { FormapagoVO formapago; if(totalFormapagos.contains(formapagoBoleto)) { @@ -446,4 +487,55 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic return conferenciaComissaoDAO.isConferenciaCompetenciaEncerrada(competencia, empresa, puntoVenta); } + public boolean isBilhetesManualVendido(BoletoComissao boletoComissao) { + return boletoComissao.getTipoVenta() == Constantes.TPV_MANUAL.intValue() && + boletoComissao.getIndstatusboleto().equals(IndStatusBoleto.V.getShortValue()); + } + + public boolean isBilhetesNormalVendido(BoletoComissao boletoComissao) { + return boletoComissao.getTipoVenta() == Constantes.TPV_DIRECTO_NORMAL.intValue() && + boletoComissao.getIndstatusboleto().equals(IndStatusBoleto.V.getShortValue()); + } + + public boolean isBilhetesNormalCancelado(BoletoComissao boletoComissao) { + return boletoComissao.getTipoVenta() == Constantes.TPV_DIRECTO_NORMAL.intValue() && + boletoComissao.getIndstatusboleto().equals(IndStatusBoleto.C.getShortValue()) && + boletoComissao.getMotivoCancelacionId() == Constantes.MVO_CANCEL_CANCELACION.intValue(); + } + + public boolean isBilhetesNormalDevolvido(BoletoComissao boletoComissao) { + return (boletoComissao.getTipoVenta() == Constantes.TPV_DIRECTO_NORMAL.intValue() || boletoComissao.getTipoVentaOriginal() == Constantes.TPV_DIRECTO_NORMAL.intValue()) && + boletoComissao.getIndstatusboleto().equals(IndStatusBoleto.C.getShortValue()) && + boletoComissao.getMotivoCancelacionId() == Constantes.MVO_CANCEL_DEVOLUCAO.intValue(); + } + + public boolean isBilhetesNormalTrocado(BoletoComissao boletoComissao) { + return boletoComissao.getTipoVenta() == Constantes.TPV_TRANSFERENCIAS.intValue() && + boletoComissao.getTipoVentaOriginal() == Constantes.TPV_DIRECTO_NORMAL.intValue() && + boletoComissao.getIndstatusboleto().equals(IndStatusBoleto.T.getShortValue()); + } + + public boolean isBilhetesGapVendido(BoletoComissao boletoComissao) { + return boletoComissao.getTipoVenta() == Constantes.TPV_BOLETO_REMOTO.intValue() && + boletoComissao.getIndstatusboleto().equals(IndStatusBoleto.V.getShortValue()); + } + + public boolean isBilhetesGapCancelado(BoletoComissao boletoComissao) { + return boletoComissao.getTipoVenta() == Constantes.TPV_BOLETO_REMOTO.intValue() && + boletoComissao.getIndstatusboleto().equals(IndStatusBoleto.C.getShortValue()) && + boletoComissao.getMotivoCancelacionId() == Constantes.MVO_CANCEL_CANCELACION.intValue(); + } + + public boolean isBilhetesGapDevolvido(BoletoComissao boletoComissao) { + return boletoComissao.getTipoVenta() == Constantes.TPV_BOLETO_REMOTO.intValue() && + boletoComissao.getIndstatusboleto().equals(IndStatusBoleto.C.getShortValue()) && + boletoComissao.getMotivoCancelacionId() == Constantes.MVO_CANCEL_DEVOLUCAO.intValue(); + } + + public boolean isBilhetesGapTrocado(BoletoComissao boletoComissao) { + return boletoComissao.getTipoVenta() == Constantes.TPV_TRANSFERENCIAS.intValue() && + boletoComissao.getTipoVentaOriginal() == Constantes.TPV_BOLETO_REMOTO.intValue() && + boletoComissao.getIndstatusboleto().equals(IndStatusBoleto.T.getShortValue()); + } + } diff --git a/src/com/rjconsultores/ventaboletos/vo/comissao/BoletoComissao.java b/src/com/rjconsultores/ventaboletos/vo/comissao/BoletoComissao.java index d1a8216fc..08c6930a5 100644 --- a/src/com/rjconsultores/ventaboletos/vo/comissao/BoletoComissao.java +++ b/src/com/rjconsultores/ventaboletos/vo/comissao/BoletoComissao.java @@ -35,6 +35,10 @@ public class BoletoComissao { private String uf; private String desccategoria; private Integer status; + private String numoperacion; + private Integer tipoVentaOriginal1; + private Integer tipoVentaOriginal2; + private Integer ocdId; private Integer estadoId; private Integer formapagoId; @@ -265,8 +269,6 @@ public class BoletoComissao { return true; if (obj == null) return false; - if (getClass() != obj.getClass()) - return false; BoletoComissao other = (BoletoComissao) obj; if (boletoId == null) { if (other.boletoId != null) @@ -356,12 +358,16 @@ public class BoletoComissao { } public String getSituacaoBilhete() { - if(StringUtils.isNotBlank(getDescmotivocancelacion())) { - return getDescmotivocancelacion(); - } else { - IndStatusBoleto indStatusBoleto = IndStatusBoleto.getIndStatusBoleto(getIndstatusboleto()); - return indStatusBoleto != null ? indStatusBoleto.getValue() : ""; - } + if(getOcdId() != null) { + return "OCD"; + } else if(!getIndstatusboleto().equalsIgnoreCase(IndStatusBoleto.V.getShortValue()) && + !getIndstatusboleto().equalsIgnoreCase(IndStatusBoleto.T.getShortValue())&& + StringUtils.isNotBlank(getDescmotivocancelacion())) { + return getDescmotivocancelacion(); + } else { + IndStatusBoleto indStatusBoleto = IndStatusBoleto.getIndStatusBoleto(getIndstatusboleto()); + return indStatusBoleto != null ? indStatusBoleto.getValue() : ""; + } } public String getNombusuario() { @@ -416,4 +422,40 @@ public class BoletoComissao { this.logconferenciaId = logconferenciaId; } + public String getNumoperacion() { + return numoperacion; + } + + public void setNumoperacion(String numoperacion) { + this.numoperacion = numoperacion; + } + + public Integer getTipoVentaOriginal() { + return tipoVentaOriginal2 != null ? tipoVentaOriginal2 : tipoVentaOriginal1; + } + + public Integer getTipoVentaOriginal1() { + return tipoVentaOriginal1; + } + + public void setTipoVentaOriginal1(Integer tipoVentaOriginal1) { + this.tipoVentaOriginal1 = tipoVentaOriginal1; + } + + public Integer getTipoVentaOriginal2() { + return tipoVentaOriginal2; + } + + public void setTipoVentaOriginal2(Integer tipoVentaOriginal2) { + this.tipoVentaOriginal2 = tipoVentaOriginal2; + } + + public Integer getOcdId() { + return ocdId; + } + + public void setOcdId(Integer ocdId) { + this.ocdId = ocdId; + } + } \ No newline at end of file