diff --git a/src/com/rjconsultores/ventaboletos/dao/CajaDAO.java b/src/com/rjconsultores/ventaboletos/dao/CajaDAO.java index c857cb945..93e73c4c0 100644 --- a/src/com/rjconsultores/ventaboletos/dao/CajaDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/CajaDAO.java @@ -5,6 +5,9 @@ import java.util.List; import java.util.Map; import com.rjconsultores.ventaboletos.entidad.Caja; +import com.rjconsultores.ventaboletos.entidad.Marca; +import com.rjconsultores.ventaboletos.entidad.PuntoVenta; +import com.rjconsultores.ventaboletos.exception.BusinessException; import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaBoletoException; import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaBoletoFormapagoException; import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaCajaException; @@ -16,15 +19,17 @@ import com.rjconsultores.ventaboletos.vo.caja.VendaEmbarcadaVO; public interface CajaDAO { public List buscarCajaFecha(boolean yaCerrado, Date fechaDesde, Date fechaHasta); - + public List buscarCajaCerrado(Date fecha, String cveusuario, String turnoid); - + List buscarUsuarioCerrado(Date fecha); - + public void gerarVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws VendaEmbarcadaBoletoException, VendaEmbarcadaBoletoFormapagoException, VendaEmbarcadaCajaException, VendaEmbarcadaCajaFormapagoException; - + public List buscarDetalleCaja(Date fechaDesde, Date fechaHasta, Boolean sembilhetesPacote); - + Map> buscarCajaYTarjeta(String... numoperacion); - + + public Integer atualizaCajasIntegracaoTotvs(Marca marca, Date dataIncial, Date dataFinal, PuntoVenta puntoVenta) throws BusinessException; + } diff --git a/src/com/rjconsultores/ventaboletos/dao/MarcaDAO.java b/src/com/rjconsultores/ventaboletos/dao/MarcaDAO.java index 1a1cfe2b4..ffabe72ea 100644 --- a/src/com/rjconsultores/ventaboletos/dao/MarcaDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/MarcaDAO.java @@ -16,12 +16,14 @@ import com.rjconsultores.ventaboletos.entidad.Usuario; */ public interface MarcaDAO extends GenericDAO { - public List buscarPorNome(String nomeMarca); + public List buscarPorNome(String nomeMarca); + + public List buscarTodosExceto(Usuario usuario, Integer... idMarca); + + public List buscarDescricaoIdMarca(); + + public List buscarMarcaPorEmpresa(List empresa); + + public Marca buscarMarcaPorEmpresa(Empresa empresa); - public List buscarTodosExceto(Usuario usuario,Integer... idMarca); - - public List buscarDescricaoIdMarca(); - - public List buscarMarcaPorEmpresa(List empresa); - } \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/dao/PuntoVentaDAO.java b/src/com/rjconsultores/ventaboletos/dao/PuntoVentaDAO.java index 561541f9a..304b141fe 100644 --- a/src/com/rjconsultores/ventaboletos/dao/PuntoVentaDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/PuntoVentaDAO.java @@ -19,7 +19,6 @@ import com.rjconsultores.ventaboletos.entidad.PuntoVentaVO; */ public interface PuntoVentaDAO extends GenericDAO { - public List buscaLike(String strEstacion, boolean sinTodos); public List busca(String nomPuntoVenta, String numPuntoVenta); @@ -27,16 +26,18 @@ public interface PuntoVentaDAO extends GenericDAO { public List buscaPuntoVenta(String numPuntoVenta); public List buscaPuntoVentaParada(Parada parada); - + public List buscaPuntoVentaEmpresaSemECF(Empresa empresa); public List buscarPuntoVentaSubordinados(PuntoVenta puntoVenta); - + public List buscarPuntosVentaMovimentacionBilhetes(List empresas); - + public List buscarPuntoVentaPorTipoEstoque(PtovtaTipoEstoque tipoEstoque); - + public List quantidadeECFPorPuntoVenta(Conferencia conferencia); - + public List buscarPuntoVentaPtoVtaComissao(List empresas); -} + + public List buscaPuntoVentaEmpresa(Empresa empresa); +} diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/CajaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/CajaHibernateDAO.java index ad247c790..97eaff220 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/CajaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/CajaHibernateDAO.java @@ -2,7 +2,6 @@ package com.rjconsultores.ventaboletos.dao.hibernate; import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -28,8 +27,10 @@ import org.springframework.transaction.annotation.Transactional; import com.rjconsultores.ventaboletos.dao.CajaDAO; import com.rjconsultores.ventaboletos.dao.sqlbuilder.SQLBuilder; -import com.rjconsultores.ventaboletos.enums.TipoFormapago; import com.rjconsultores.ventaboletos.entidad.Caja; +import com.rjconsultores.ventaboletos.entidad.Marca; +import com.rjconsultores.ventaboletos.entidad.PuntoVenta; +import com.rjconsultores.ventaboletos.enums.TipoFormapago; import com.rjconsultores.ventaboletos.exception.BusinessException; import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaBoletoException; import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaBoletoFormapagoException; @@ -50,12 +51,12 @@ import com.rjconsultores.ventaboletos.vo.caja.VendaEmbarcadaVO; @Repository("cajaDAO") public class CajaHibernateDAO extends GenericHibernateDAO implements CajaDAO { - + private static Logger log = org.slf4j.LoggerFactory.getLogger(CajaHibernateDAO.class); - + @Autowired private SQLBuilder sqlBuilder; - + @Autowired public CajaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { setSessionFactory(factory); @@ -117,11 +118,12 @@ public class CajaHibernateDAO extends GenericHibernateDAO implemen return list; } + @Override public List buscarDetalleCaja(Date fechaDesde, Date fechaHasta, Boolean sembilhetesPacote) { - + String sqlBuscarCajaFecha = sqlBuilder.getSQLBuscarDatosCaja(fechaDesde, fechaHasta, sembilhetesPacote); - + SQLQuery sql = getSession().createSQLQuery(sqlBuscarCajaFecha) .addScalar("cajaId", LongType.INSTANCE) .addScalar("numAsiento", StringType.INSTANCE) @@ -184,102 +186,102 @@ public class CajaHibernateDAO extends GenericHibernateDAO implemen .addScalar("descconvenio", StringType.INSTANCE) .addScalar("cveconvenio", StringType.INSTANCE) .addScalar("descsecretaria", StringType.INSTANCE); - + sql.setResultTransformer(new AliasToBeanResultTransformer(CajaDetalleVO.class)); - + @SuppressWarnings("unchecked") - List lsBusca = (List)sql.list(); - + List lsBusca = sql.list(); + List lsResultado = new ArrayList(); - + for (CajaDetalleVO cd : lsBusca) { - + int indexOf = lsResultado.indexOf(cd); - + CajaDetalleVO cajaDetalleVO = null; - - if (indexOf != -1){ + + if (indexOf != -1) { cajaDetalleVO = lsResultado.get(indexOf); - }else{ + } else { cajaDetalleVO = cd; } - - if (cajaDetalleVO.getFormaspagamento() == null){ + + if (cajaDetalleVO.getFormaspagamento() == null) { cajaDetalleVO.setFormaspagamento(new ArrayList()); } - if(!cd.getDescPago().equalsIgnoreCase("TROCA DE PASSAGEM")){ - PagamentoVO pagamentoVO = new PagamentoVO(); - pagamentoVO.setFormapagamento(cd.getDescPago()); - pagamentoVO.setMoeda("R$"); - pagamentoVO.setValor(cd.getVlrFormaPago()); - pagamentoVO.setIdentificacaoEmpresa(cd.getCvesecretaria()); - pagamentoVO.setRazaoSocial(cd.getDescsecretaria()); - - - if(cd.getNotacreditovendapacoteId() != null) { - NotaCreditoVendaPacoteVO notacredito = new NotaCreditoVendaPacoteVO(); - notacredito.setVouchernotacredito(cd.getNotacreditovendapacoteId().toString()); - pagamentoVO.setNotacredito(notacredito); - } - - if(cd.getOcdId() != null) { - NotaCreditoVendaPacoteVO notacredito = new NotaCreditoVendaPacoteVO(); - notacredito.setVouchernotacredito(OcdUtil.generaLocalizadorOCD(cd.getNumoperacionOcd(), cd.getOcdId())); - pagamentoVO.setNotacredito(notacredito); - } + if (!cd.getDescPago().equalsIgnoreCase("TROCA DE PASSAGEM")) { + PagamentoVO pagamentoVO = new PagamentoVO(); + pagamentoVO.setFormapagamento(cd.getDescPago()); + pagamentoVO.setMoeda("R$"); + pagamentoVO.setValor(cd.getVlrFormaPago()); + pagamentoVO.setIdentificacaoEmpresa(cd.getCvesecretaria()); + pagamentoVO.setRazaoSocial(cd.getDescsecretaria()); - if (StringUtils.isNotBlank(cd.getNumAutorizacion())){ - PagamentoCartaoVO cartao = new PagamentoCartaoVO(); - cartao.setNumautorizacao(cd.getNumAutorizacion()); - cartao.setBandeira(cd.getTipotarjeta()); - cartao.setDatapagamento(cd.getFecoperacion()); - cartao.setNumcartao(cd.getNumtarjeta()); - cartao.setParcelas(cd.getCantparcelas()); - cartao.setTitular(cd.getNombtitular()); - cartao.setOperadoracartao(cd.getOperadoracartao()); - - pagamentoVO.setCartao(cartao); + if (cd.getNotacreditovendapacoteId() != null) { + NotaCreditoVendaPacoteVO notacredito = new NotaCreditoVendaPacoteVO(); + notacredito.setVouchernotacredito(cd.getNotacreditovendapacoteId().toString()); + pagamentoVO.setNotacredito(notacredito); + } + + if (cd.getOcdId() != null) { + NotaCreditoVendaPacoteVO notacredito = new NotaCreditoVendaPacoteVO(); + notacredito.setVouchernotacredito(OcdUtil.generaLocalizadorOCD(cd.getNumoperacionOcd(), cd.getOcdId())); + pagamentoVO.setNotacredito(notacredito); + } + + if (StringUtils.isNotBlank(cd.getNumAutorizacion())) { + PagamentoCartaoVO cartao = new PagamentoCartaoVO(); + cartao.setNumautorizacao(cd.getNumAutorizacion()); + cartao.setBandeira(cd.getTipotarjeta()); + cartao.setDatapagamento(cd.getFecoperacion()); + cartao.setNumcartao(cd.getNumtarjeta()); + cartao.setParcelas(cd.getCantparcelas()); + cartao.setTitular(cd.getNombtitular()); + cartao.setOperadoracartao(cd.getOperadoracartao()); + + pagamentoVO.setCartao(cartao); + } + + cajaDetalleVO.getFormaspagamento().add(pagamentoVO); + + if (pagamentoVO.getDadosBancarios() == null) { + pagamentoVO.setDadosBancarios(new ArrayList()); + } + + if (isPagamentoDeposito(TipoFormapago.getTipoFormapagoByValor(cd.getTipoPago()))) { + pagamentoVO.getDadosBancarios().addAll(carregarDadosDeposito(cd.getCajaId(), cd.getFormaPagoId())); + } + + if (pagamentoVO.getDadosBancarios().isEmpty()) { + pagamentoVO.setDadosBancarios(null); + } } - - cajaDetalleVO.getFormaspagamento().add(pagamentoVO); - - if(pagamentoVO.getDadosBancarios() == null) { - pagamentoVO.setDadosBancarios(new ArrayList()); - } - - if(isPagamentoDeposito(TipoFormapago.getTipoFormapagoByValor(cd.getTipoPago()))) { - pagamentoVO.getDadosBancarios().addAll(carregarDadosDeposito(cd.getCajaId(), cd.getFormaPagoId())); - } - - if(pagamentoVO.getDadosBancarios().isEmpty()) { - pagamentoVO.setDadosBancarios(null); - } - } - if (indexOf == -1){ + if (indexOf == -1) { lsResultado.add(cajaDetalleVO); } } - + List filtrados = new ArrayList(); - for(CajaDetalleVO c : lsResultado){ - if(c.getFormaspagamento() != null && !c.getFormaspagamento().isEmpty() && !existeApenasFpReserva(c)){ + for (CajaDetalleVO c : lsResultado) { + if (c.getFormaspagamento() != null && !c.getFormaspagamento().isEmpty() && !existeApenasFpReserva(c)) { filtrados.add(c); } } - + return filtrados; } - - private Boolean existeApenasFpReserva(CajaDetalleVO c){ - if(c.getFormaspagamento().size() == 1 - && c.getFormaspagamento().get(0).getFormapagamento().equals("RESERVA")){ + + private Boolean existeApenasFpReserva(CajaDetalleVO c) { + if (c.getFormaspagamento().size() == 1 + && c.getFormaspagamento().get(0).getFormapagamento().equals("RESERVA")) { return true; } - + return false; } + @Override public List buscarCajaCerrado(Date fecha, String cveusuario, String turnoid) { return buscarCajaCerrado(fecha, cveusuario, turnoid, false); } @@ -351,7 +353,7 @@ public class CajaHibernateDAO extends GenericHibernateDAO implemen .addScalar("precio", BigDecimalType.INSTANCE) .addScalar("tipoEvento", StringType.INSTANCE); sql.setResultTransformer(new AliasToBeanResultTransformer(ReceitaDespesaVO.class)); - u.setDiversos((List) sql.list()); + u.setDiversos(sql.list()); } return usuarios; } catch (Exception e) { @@ -362,80 +364,80 @@ public class CajaHibernateDAO extends GenericHibernateDAO implemen } @Override - @Transactional(rollbackFor={BusinessException.class,VendaEmbarcadaBoletoException.class,VendaEmbarcadaBoletoFormapagoException.class,VendaEmbarcadaCajaException.class,VendaEmbarcadaCajaFormapagoException.class}) + @Transactional(rollbackFor = { BusinessException.class, VendaEmbarcadaBoletoException.class, VendaEmbarcadaBoletoFormapagoException.class, VendaEmbarcadaCajaException.class, VendaEmbarcadaCajaFormapagoException.class }) public void gerarVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws VendaEmbarcadaBoletoException, VendaEmbarcadaBoletoFormapagoException, VendaEmbarcadaCajaException, VendaEmbarcadaCajaFormapagoException { inserirBoletoVendaEmbarcada(vendaEmbarcada); inserirBoletoFormaPagoVendaEmbarcada(vendaEmbarcada); inserirCajaVendaEmbarcada(vendaEmbarcada); inserirCajaFormaPagoVendaEmbarcada(vendaEmbarcada); } - - private void inserirCajaVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws VendaEmbarcadaCajaException{ - + + private void inserirCajaVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws VendaEmbarcadaCajaException { + try { - + SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLInserirCajaVendaEmbarcada()); - + vendaEmbarcada.setCajaId(obterIdCaja().longValue()); - + query.setLong("cajaId", vendaEmbarcada.getCajaId()); query.setString("numAsiento", vendaEmbarcada.getNumAsiento()); query.setInteger("categoriaId", vendaEmbarcada.getCategoriaId()); query.setInteger("claseServicioId", vendaEmbarcada.getClaseServicioId()); - query.setInteger("marcaId",vendaEmbarcada.getMarcaId()); - query.setInteger("origemId",vendaEmbarcada.getOrigemId()); - query.setInteger("destinoId",vendaEmbarcada.getDestinoId()); - query.setInteger("corridaId",vendaEmbarcada.getCorridaId()); - query.setDate("fecCorrida",vendaEmbarcada.getFecCorrida()); - query.setBigDecimal("precioBase",vendaEmbarcada.getPrecio()); - query.setBigDecimal("precioPagado",vendaEmbarcada.getPrecio()); - query.setInteger("tipoVentaId",vendaEmbarcada.getTipoVentaId()); - query.setDate("fechorViaje",vendaEmbarcada.getFechorViaje()); - query.setDate("fechorVenta",vendaEmbarcada.getFechorVenta()); - query.setInteger("puntoVentaId",vendaEmbarcada.getPuntoVentaId()); - query.setString("numOperacion",vendaEmbarcada.getNumOperacion()); - query.setBigInteger("empresaPuntoVentaId",vendaEmbarcada.getEmpresaId()); - query.setBigInteger("empresaCorridaId",vendaEmbarcada.getEmpresaId()); - query.setInteger("estacionId",vendaEmbarcada.getEstacionId()); - query.setInteger("usuarioId",vendaEmbarcada.getUsuarioId()); - query.setBigDecimal("importeTaxaEmbarque",vendaEmbarcada.getImporteTaxaEmbarque()); - query.setBigDecimal("importePedagio",vendaEmbarcada.getImportePedagio()); - query.setBigDecimal("importeOutros",vendaEmbarcada.getImporteOutros()); - query.setBigDecimal("importeSeguro",vendaEmbarcada.getImporteSeguro()); + query.setInteger("marcaId", vendaEmbarcada.getMarcaId()); + query.setInteger("origemId", vendaEmbarcada.getOrigemId()); + query.setInteger("destinoId", vendaEmbarcada.getDestinoId()); + query.setInteger("corridaId", vendaEmbarcada.getCorridaId()); + query.setDate("fecCorrida", vendaEmbarcada.getFecCorrida()); + query.setBigDecimal("precioBase", vendaEmbarcada.getPrecio()); + query.setBigDecimal("precioPagado", vendaEmbarcada.getPrecio()); + query.setInteger("tipoVentaId", vendaEmbarcada.getTipoVentaId()); + query.setDate("fechorViaje", vendaEmbarcada.getFechorViaje()); + query.setDate("fechorVenta", vendaEmbarcada.getFechorVenta()); + query.setInteger("puntoVentaId", vendaEmbarcada.getPuntoVentaId()); + query.setString("numOperacion", vendaEmbarcada.getNumOperacion()); + query.setBigInteger("empresaPuntoVentaId", vendaEmbarcada.getEmpresaId()); + query.setBigInteger("empresaCorridaId", vendaEmbarcada.getEmpresaId()); + query.setInteger("estacionId", vendaEmbarcada.getEstacionId()); + query.setInteger("usuarioId", vendaEmbarcada.getUsuarioId()); + query.setBigDecimal("importeTaxaEmbarque", vendaEmbarcada.getImporteTaxaEmbarque()); + query.setBigDecimal("importePedagio", vendaEmbarcada.getImportePedagio()); + query.setBigDecimal("importeOutros", vendaEmbarcada.getImporteOutros()); + query.setBigDecimal("importeSeguro", vendaEmbarcada.getImporteSeguro()); query.setDate("fecCreacion", vendaEmbarcada.getFechorVenta()); query.setInteger("rutaId", vendaEmbarcada.getRutaId()); query.setTimestamp("fecModIf", vendaEmbarcada.getFecModIf()); query.setString("numFolioPreimpresso", vendaEmbarcada.getNumFolioPreimpresso()); query.setString("serieImpFiscal", vendaEmbarcada.getSerieImpFiscal()); - + if (query.executeUpdate() != 1) { throw new VendaEmbarcadaCajaException("Erro ao gerar caixa venda embarcada"); } - + } catch (VendaEmbarcadaCajaException e) { throw e; } catch (Exception e) { log.error(e.getMessage(), e); throw new VendaEmbarcadaCajaException(e.getMessage(), e); } - + } - + private void inserirCajaFormaPagoVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws VendaEmbarcadaCajaFormapagoException { try { SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLInserirCajaFormaPagoVendaEmbarcada()); - + query.setInteger("formaPagoId", vendaEmbarcada.getFormaPagoId()); query.setLong("cajaId", vendaEmbarcada.getCajaId()); query.setBigDecimal("importe", vendaEmbarcada.getPrecio()); query.setInteger("usuarioId", vendaEmbarcada.getUsuarioId()); query.setLong("cajaFormaPagoId", obterIdCajaFormaPago().longValue()); query.setTimestamp("fecModIf", vendaEmbarcada.getFecModIf()); - + if (query.executeUpdate() != 1) { throw new VendaEmbarcadaCajaFormapagoException("Erro ao gerar forma de pagamento do caixa venda embarcada"); } - + } catch (VendaEmbarcadaCajaFormapagoException e) { throw e; } catch (Exception e) { @@ -443,19 +445,19 @@ public class CajaHibernateDAO extends GenericHibernateDAO implemen throw new VendaEmbarcadaCajaFormapagoException(e.getMessage(), e); } } - + private void inserirBoletoVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws VendaEmbarcadaBoletoException { try { - + SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLInserirBoletoVendaEmbarcada()); - + vendaEmbarcada.setBoletoId(obterIdBoleto().longValue()); vendaEmbarcada.setNumOperacion(obterNumOperacion().toString()); - + query.setBigInteger("empresaCorridaId", vendaEmbarcada.getEmpresaId()); query.setInteger("destinoId", vendaEmbarcada.getDestinoId()); - query.setInteger("tipoVentaId",vendaEmbarcada.getTipoVentaId()); - query.setInteger("categoriaId",vendaEmbarcada.getCategoriaId()); + query.setInteger("tipoVentaId", vendaEmbarcada.getTipoVentaId()); + query.setInteger("categoriaId", vendaEmbarcada.getCategoriaId()); query.setInteger("corridaId", vendaEmbarcada.getCorridaId()); query.setInteger("claseServicioId", vendaEmbarcada.getClaseServicioId()); query.setDate("fecCorrida", vendaEmbarcada.getFecCorrida()); @@ -466,9 +468,9 @@ public class CajaHibernateDAO extends GenericHibernateDAO implemen query.setString("numAsiento", vendaEmbarcada.getNumAsiento()); query.setBigDecimal("precioPagado", vendaEmbarcada.getPrecio()); query.setDate("fechorViaje", vendaEmbarcada.getFechorViaje()); - query.setDate("fechorVenta", vendaEmbarcada.getFechorVenta()); + query.setDate("fechorVenta", vendaEmbarcada.getFechorVenta()); query.setString("numOperacion", vendaEmbarcada.getNumOperacion()); - query.setInteger("usuarioId",vendaEmbarcada.getUsuarioId()); + query.setInteger("usuarioId", vendaEmbarcada.getUsuarioId()); query.setBigDecimal("precioBase", vendaEmbarcada.getPrecio()); query.setInteger("estacionId", vendaEmbarcada.getEstacionId()); query.setBigDecimal("importeTaxaEmbarque", vendaEmbarcada.getImporteTaxaEmbarque()); @@ -481,11 +483,11 @@ public class CajaHibernateDAO extends GenericHibernateDAO implemen query.setBigDecimal("precioPricing", vendaEmbarcada.getPrecio()); query.setString("numFolioPreimpresso", vendaEmbarcada.getNumFolioPreimpresso()); query.setString("serieImpFiscal", vendaEmbarcada.getSerieImpFiscal()); - + if (query.executeUpdate() != 1) { throw new VendaEmbarcadaBoletoException("Erro ao gerar boleto venda embarcada"); } - + } catch (VendaEmbarcadaBoletoException e) { throw e; } catch (Exception e) { @@ -493,23 +495,23 @@ public class CajaHibernateDAO extends GenericHibernateDAO implemen throw new VendaEmbarcadaBoletoException(e.getMessage(), e); } } - - private void inserirBoletoFormaPagoVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws VendaEmbarcadaBoletoFormapagoException{ + + private void inserirBoletoFormaPagoVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws VendaEmbarcadaBoletoFormapagoException { try { - + SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLInserirBoletoFormaPagoVendaEmbarcada()); - + query.setInteger("formaPagoId", vendaEmbarcada.getFormaPagoId()); query.setLong("boletoId", vendaEmbarcada.getBoletoId()); query.setBigDecimal("importe", vendaEmbarcada.getPrecio()); query.setTimestamp("fecModIf", vendaEmbarcada.getFecModIf()); query.setInteger("usuarioId", vendaEmbarcada.getUsuarioId()); query.setBigDecimal("boletoFormaPagoId", obterIdBoletoFormaPago()); - + if (query.executeUpdate() != 1) { throw new VendaEmbarcadaBoletoFormapagoException("Erro ao gerar forma de pagamento do boleto venda embarcada"); } - + } catch (VendaEmbarcadaBoletoFormapagoException e) { throw e; } catch (Exception e) { @@ -517,90 +519,90 @@ public class CajaHibernateDAO extends GenericHibernateDAO implemen throw new VendaEmbarcadaBoletoFormapagoException(e.getMessage(), e); } } - - private BigDecimal obterIdBoletoFormaPago(){ + + private BigDecimal obterIdBoletoFormaPago() { SQLQuery sql = getSession().createSQLQuery(sqlBuilder.getSQLObterSequenceBoletoFormaPago()); - - return gerarChave((BigDecimal)sql.uniqueResult()); + + return gerarChave((BigDecimal) sql.uniqueResult()); } - - private BigDecimal obterIdCajaFormaPago(){ + + private BigDecimal obterIdCajaFormaPago() { SQLQuery sql = getSession().createSQLQuery(sqlBuilder.getSQLObterSequenceCajaFormaPago()); - - return gerarChave((BigDecimal)sql.uniqueResult()); + + return gerarChave((BigDecimal) sql.uniqueResult()); } - - private BigDecimal obterIdBoleto(){ + + private BigDecimal obterIdBoleto() { SQLQuery sql = getSession().createSQLQuery(sqlBuilder.getSQLObterSequenceCajaFormaPago()); - - return gerarChave((BigDecimal)sql.uniqueResult()); + + return gerarChave((BigDecimal) sql.uniqueResult()); } - - private BigDecimal obterIdCaja(){ + + private BigDecimal obterIdCaja() { SQLQuery sql = getSession().createSQLQuery(sqlBuilder.getSQLObterSequenceCaja()); - - return gerarChave((BigDecimal)sql.uniqueResult()); + + return gerarChave((BigDecimal) sql.uniqueResult()); } - - private BigDecimal obterNumOperacion(){ + + private BigDecimal obterNumOperacion() { SQLQuery sql = getSession().createSQLQuery(sqlBuilder.getSQLObterSequenciaNumOperacion()); - - return gerarChave((BigDecimal)sql.uniqueResult()); + + return gerarChave((BigDecimal) sql.uniqueResult()); } - - private BigDecimal gerarChave(BigDecimal seq){ + + private BigDecimal gerarChave(BigDecimal seq) { Integer tamChave = 13; - + String chave = "1"; - + --tamChave; - - while ((seq.toString().length() + chave.length()) <= (tamChave)){ + + while ((seq.toString().length() + chave.length()) <= (tamChave)) { chave += "0"; } - + return new BigDecimal(chave += seq); } - + @SuppressWarnings("unchecked") private List carregarDadosDeposito(Long cajaId, Integer formapagoId) { StringBuilder sQuery = new StringBuilder(); sQuery.append("SELECT CDDP.IDENTIFICACAO_DEPOSITO, CDDP.IMPORTE, CDDP.FECDEPOSITO ") - .append("FROM CAJA_DET_DEPOSITO_PAGO CDDP ") - .append("JOIN CAJA_FORMAPAGO CFP ON CFP.CAJAFORMAPAGO_ID = CDDP.CAJAFORMAPAGO_ID ") - .append("WHERE CDDP.ACTIVO = 1 ") - .append("AND CFP.CAJA_ID = :cajaId ") - .append("AND CFP.FORMAPAGO_ID = :formapagoId "); - + .append("FROM CAJA_DET_DEPOSITO_PAGO CDDP ") + .append("JOIN CAJA_FORMAPAGO CFP ON CFP.CAJAFORMAPAGO_ID = CDDP.CAJAFORMAPAGO_ID ") + .append("WHERE CDDP.ACTIVO = 1 ") + .append("AND CFP.CAJA_ID = :cajaId ") + .append("AND CFP.FORMAPAGO_ID = :formapagoId "); + SQLQuery query = getSession().createSQLQuery(sQuery.toString()) - .addScalar("IDENTIFICACAO_DEPOSITO", StringType.INSTANCE) - .addScalar("IMPORTE", BigDecimalType.INSTANCE) - .addScalar("FECDEPOSITO", DateType.INSTANCE); - + .addScalar("IDENTIFICACAO_DEPOSITO", StringType.INSTANCE) + .addScalar("IMPORTE", BigDecimalType.INSTANCE) + .addScalar("FECDEPOSITO", DateType.INSTANCE); + query.setResultTransformer(new DatosDadosBancarioResultTransformer()); query.setParameter("cajaId", cajaId); query.setParameter("formapagoId", formapagoId); - + return query.list(); } - + private boolean isPagamentoDeposito(TipoFormapago tipoFormapago) { return TipoFormapago.DEPOSITO.equals(tipoFormapago); } - + @SuppressWarnings("unchecked") @Override public Map> buscarCajaYTarjeta(String... numoperacionList) { - + String queryString = "SELECT DISTINCT c FROM Caja c " + "LEFT JOIN FETCH c.cajaFormaPago cfp " + "LEFT JOIN FETCH cfp.cajaDetPago cdp " + "LEFT JOIN FETCH cdp.cajaTarjetas ct " + "WHERE c.numoperacion IN(:numoperacion) "; - + Query query = getSession().createQuery(queryString); query.setParameterList("numoperacion", numoperacionList); - + List cajaList = query.list(); HashMap> result = new HashMap>(); for (Caja caja : cajaList) { @@ -612,9 +614,33 @@ public class CajaHibernateDAO extends GenericHibernateDAO implemen } cajaListTemp.add(caja); } - + return result; - + } - + + @Override + @Transactional(rollbackFor = { BusinessException.class }) + public Integer atualizaCajasIntegracaoTotvs(Marca marca, Date dataIncial, Date dataFinal, PuntoVenta puntoVenta) throws BusinessException { + + // update caja set integradototvs = 0 where PUNTOVENTA_ID = 269 and FECHORVENTA >= '30/03/2018' and FECHORVENTA <= '01/04/2018'; + StringBuilder sb = new StringBuilder(); + sb.append(" update caja set integradototvs = 0 "); + sb.append(" where FECHORVENTA >= :fechorInicial "); + sb.append(" and FECHORVENTA <= :fechorFinal "); + sb.append(" and PUNTOVENTA_ID = :puntoVentaId "); + if (marca != null) { + sb.append(" and MARCA_ID = :marcaId "); + } + SQLQuery query = getSession().createSQLQuery(sb.toString()); + if (marca != null) { + query.setInteger("marcaId", marca.getMarcaId()); + } + query.setInteger("puntoVentaId", puntoVenta.getPuntoventaId()); + query.setTimestamp("fechorInicial", dataIncial); + query.setTimestamp("fechorFinal", dataFinal); + Integer result = query.executeUpdate(); + return result; + } + } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/MarcaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/MarcaHibernateDAO.java index 431ecd274..13cb7cbac 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/MarcaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/MarcaHibernateDAO.java @@ -49,6 +49,7 @@ public class MarcaHibernateDAO extends GenericHibernateDAO } + @Override public List buscarPorNome(String nomeMarca) { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); @@ -57,6 +58,7 @@ public class MarcaHibernateDAO extends GenericHibernateDAO return c.list(); } + @Override public List buscarTodosExceto(Usuario usuario, Integer... idMarca) { String hql = " select new com.rjconsultores.ventaboletos.entidad.Marca(marca.marcaId, marca.descmarca) from Marca marca, UsuarioEmpresa ue" + " where marca.empresa = ue.empresa and ue.usuarioLog = :usuarioId "; @@ -78,6 +80,7 @@ public class MarcaHibernateDAO extends GenericHibernateDAO return lsMarca; } + @Override public List buscarMarcaPorEmpresa(List empresa) { if ((empresa == null) || (empresa.isEmpty())) { return Collections.emptyList(); @@ -98,4 +101,16 @@ public class MarcaHibernateDAO extends GenericHibernateDAO return c.list(); } + @Override + public Marca buscarMarcaPorEmpresa(Empresa empresa) { + Criteria c = makeCriteria(); + c.add(Restrictions.eq("activo", true)); + c.add(Restrictions.eq("empresa", empresa)); + List marcas = c.list(); + if (marcas != null && !marcas.isEmpty()) { + return marcas.get(0); + } + return null; + } + } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/PuntoVentaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/PuntoVentaHibernateDAO.java index 1dfad3372..457625811 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/PuntoVentaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/PuntoVentaHibernateDAO.java @@ -61,6 +61,7 @@ public class PuntoVentaHibernateDAO extends GenericHibernateDAO buscaLike(String strEstacion, boolean sinTodos) { Criteria c = getSession().createCriteria(getPersistentClass()); @@ -85,6 +86,7 @@ public class PuntoVentaHibernateDAO extends GenericHibernateDAO busca(String nomPuntoVenta, String numPuntoVenta) { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); @@ -95,6 +97,7 @@ public class PuntoVentaHibernateDAO extends GenericHibernateDAO buscaPuntoVenta(String numPuntoVenta) { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); @@ -103,6 +106,16 @@ public class PuntoVentaHibernateDAO extends GenericHibernateDAO buscaPuntoVentaEmpresa(Empresa empresa) { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.add(Restrictions.eq("empresa", empresa)); + + return c.list(); + } + + @Override public List buscaPuntoVentaParada(Parada parada) { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); @@ -112,6 +125,7 @@ public class PuntoVentaHibernateDAO extends GenericHibernateDAO buscaPuntoVentaEmpresaSemECF(Empresa empresa) { StringBuilder sb = new StringBuilder(); sb.append(" select "); @@ -188,6 +202,7 @@ public class PuntoVentaHibernateDAO extends GenericHibernateDAO buscarPuntoVentaPorTipoEstoque(PtovtaTipoEstoque tipoEstoque) { Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("ptovtaTipoEstoque", tipoEstoque)); @@ -261,8 +276,8 @@ public class PuntoVentaHibernateDAO extends GenericHibernateDAO buscarPuntoVentaPtoVtaComissao(List empresas) { StringBuilder sQuery = new StringBuilder("SELECT DISTINCT pv.PUNTOVENTA_ID, pv.NOMBPUNTOVENTA, pv.ACTIVO "); sQuery.append("FROM PTOVTA_COMISSAO ptovta ") - .append("JOIN PUNTO_VENTA pv ON pv.puntoventa_id = ptovta.puntoventa_id ") - .append("JOIN EMPRESA em ON em.empresa_id = ptovta.empresa_id ") - .append("WHERE ptovta.activo = 1 ") - .append("AND pv.activo = 1 ") - .append("AND em.activo = 1 ") - .append("AND em.empresa_id in (:empresas)"); - + .append("JOIN PUNTO_VENTA pv ON pv.puntoventa_id = ptovta.puntoventa_id ") + .append("JOIN EMPRESA em ON em.empresa_id = ptovta.empresa_id ") + .append("WHERE ptovta.activo = 1 ") + .append("AND pv.activo = 1 ") + .append("AND em.activo = 1 ") + .append("AND em.empresa_id in (:empresas)"); + Query qr = getSession().createSQLQuery(sQuery.toString()) - .addScalar("PUNTOVENTA_ID", IntegerType.INSTANCE) - .addScalar("NOMBPUNTOVENTA", StringType.INSTANCE) - .addScalar("ACTIVO", BooleanType.INSTANCE) - .setResultTransformer(new DatosPuntoVentaResultTransformer()); - + .addScalar("PUNTOVENTA_ID", IntegerType.INSTANCE) + .addScalar("NOMBPUNTOVENTA", StringType.INSTANCE) + .addScalar("ACTIVO", BooleanType.INSTANCE) + .setResultTransformer(new DatosPuntoVentaResultTransformer()); + qr.setParameterList("empresas", empresas); return qr.list(); diff --git a/src/com/rjconsultores/ventaboletos/entidad/IntegracaoTotvs.java b/src/com/rjconsultores/ventaboletos/entidad/IntegracaoTotvs.java new file mode 100644 index 000000000..711f5a181 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/entidad/IntegracaoTotvs.java @@ -0,0 +1,5 @@ +package com.rjconsultores.ventaboletos.entidad; + +public class IntegracaoTotvs { + +} diff --git a/src/com/rjconsultores/ventaboletos/service/IntegracaoTotvsService.java b/src/com/rjconsultores/ventaboletos/service/IntegracaoTotvsService.java new file mode 100644 index 000000000..4403f781b --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/IntegracaoTotvsService.java @@ -0,0 +1,15 @@ +package com.rjconsultores.ventaboletos.service; + +import java.util.Date; +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.Empresa; +import com.rjconsultores.ventaboletos.entidad.PuntoVenta; +import com.rjconsultores.ventaboletos.exception.BusinessException; + +public interface IntegracaoTotvsService { + public Integer atualizaStstausBilhetesIntegrar(Empresa empresa, Date dataIncial, Date dataFinal, PuntoVenta puntoVenta) throws BusinessException; + + public List buscaPuntoVentaEmpresa(Empresa empresa) throws Exception; + +} \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/service/impl/ConferenciaComissaoServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/ConferenciaComissaoServiceImpl.java index f930885af..cf30bacf2 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/ConferenciaComissaoServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/ConferenciaComissaoServiceImpl.java @@ -11,7 +11,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -64,7 +64,7 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic private static Logger log = Logger.getLogger(ConferenciaComissaoService.class); @Autowired - private ConferenciaComissaoDAO conferenciaComissaoDAO; + private ConferenciaComissaoDAO conferenciaComissaoDAO; @Autowired private EmpresaDAO empresaDAO; @@ -114,16 +114,16 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic public List carregarConferenciaComissao(String competencia, Empresa empresa, PuntoVenta puntoVenta, Date dataMovimento) throws BusinessException { return conferenciaComissaoDAO.carregarConferenciaComissao(competencia, empresa, puntoVenta, dataMovimento); } - + @Override public List carregarConferenciaComissao(Date dataInicial, Date dataFinal, Empresa empresa, PuntoVenta puntoVenta, Date dataMovimento) throws BusinessException { return conferenciaComissaoDAO.carregarConferenciaComissao(dataInicial, dataFinal, empresa, puntoVenta, dataMovimento); } - + @Override public Conferencia confirmarChegadaMalote(Conferencia conferencia) throws BusinessException { conferencia.setDatamalote(new Date()); - if(conferencia.getUsuarioId()==null || conferencia.getUsuarioId() < 1){ + if (conferencia.getUsuarioId() == null || conferencia.getUsuarioId() < 1) { conferencia.setUsuarioMaloteId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); } return conferenciaComissaoDAO.confirmarChegadaMalote(conferencia); @@ -139,8 +139,8 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic @Override public Conferencia encerrarMovimentoDiario(Conferencia conferencia) throws BusinessException { - if(conferencia.getUsuarioId()==null || conferencia.getUsuarioId() < 1){ - conferencia.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + if (conferencia.getUsuarioId() == null || conferencia.getUsuarioId() < 1) { + conferencia.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); } conferencia.setFecmodif(Calendar.getInstance().getTime()); return conferenciaComissaoDAO.encerrarMovimentoDiario(conferencia); @@ -170,29 +170,29 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic public LogConferencia obtenerLogConferenciaID(Long logconferenciaId) { return conferenciaComissaoDAO.obtenerLogConferenciaID(logconferenciaId); } - + @Override public List carregarBilhetesComissao(List boletoComissaos, List conferencias, BoletoStatusComissao boletoStatusComissao, boolean carregarDadosFaltantes) throws BusinessException { List retorno = new ArrayList(); Boolean retornar = false; - + for (Conferencia c : conferencias) { - - if(retornar){ + + if (retornar) { return retorno; } if (boletoComissaos == null || boletoComissaos.isEmpty()) { boletoComissaos = conferenciaComissaoDAO.carregarBilhetesComissao(c, false, false); } - - if(boletoStatusComissao == null){ + + if (boletoStatusComissao == null) { retorno.addAll(boletoComissaos); boletoComissaos = null; continue; } - + Empresa empresa = empresaDAO.obtenerID(c.getEmpresa().getEmpresaId()); ComEmpConferencia comEmpConferencia = null; if (empresa.getComEmpConferencias() != null && !empresa.getComEmpConferencias().isEmpty()) { @@ -229,7 +229,6 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic return retorno; } - @Override public List carregarBilhetesComissao(List boletoComissaos, Conferencia conferencia, BoletoStatusComissao boletoStatusComissao, boolean carregarDadosFaltantes) throws BusinessException { @@ -295,11 +294,11 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic Set boletos = new HashSet(); for (BoletoComissao boletoComissao : boletoComissaos) { if (boletoComissao.isAbaBilheteVendido() || carregarDadosFaltantes) { - + if (comEmpConferencia != null) { boletoComissao.setExigeConferenciaAba(comEmpConferencia.getIndbilhetevendido()); } - if(boletoComissao.isQuitacaoOCD()){ + if (boletoComissao.isQuitacaoOCD()) { continue; } boletos.add(boletoComissao); @@ -425,7 +424,7 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic public boolean isEventosFinanceirosSemConferencia(List lsEventosFinanceiros) throws BusinessException { for (EventosFinanceirosVO eventosFinanceiros : lsEventosFinanceiros) { if ((eventosFinanceiros.isExigeConferencia() || eventosFinanceiros.getExigeConferenciaAba()) && - (!eventosFinanceiros.isConferido() && eventosFinanceiros.getLogconferenciaId() == null)) { + (!eventosFinanceiros.isConferido() && eventosFinanceiros.getLogconferenciaId() == null)) { return true; } } @@ -442,13 +441,13 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic BigDecimal total = BigDecimal.ZERO; if (lsBoletoComissao != null) { for (BoletoComissao boletoComissao : lsBoletoComissao) { - if(boletoComissao.isNotSomarBilhete()) { + if (boletoComissao.isNotSomarBilhete()) { continue; } - + if ((lStatusBilhete == null || lStatusBilhete.contains(boletoComissao.getIndstatusboletoEnum())) && - !boletoComissao.isVendaBilheteConfirmaAberto(boletoComissao.getTipoVenta())) { - //log.info(boletoComissao.toString()); + !boletoComissao.isVendaBilheteConfirmaAberto(boletoComissao.getTipoVenta())) { + // log.info(boletoComissao.toString()); total = total.add(boletoComissao.getTotal()); } } @@ -463,7 +462,7 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic BigDecimal totalOcd = BigDecimal.ZERO; if (lsBoletoComissao != null) { for (BoletoComissao boletoComissao : lsBoletoComissao) { - if(boletoComissao.isNotSomarBilhete()) { + if (boletoComissao.isNotSomarBilhete()) { continue; } if (boletoComissao.isOcd()) { @@ -487,7 +486,7 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic BigDecimal total = BigDecimal.ZERO; if (lsEventosFinanceiros != null) { for (EventosFinanceirosVO eventosFinanceiros : lsEventosFinanceiros) { - /*total = total.add(eventosFinanceiros.getImpingreso());*/ + /* total = total.add(eventosFinanceiros.getImpingreso()); */ if (eventosFinanceiros.isCredito()) { total = MoneyHelper.somar(total, eventosFinanceiros.getImpingreso()); } else if (eventosFinanceiros.isDebito()) { @@ -536,33 +535,34 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic /** * Calcula o total de deposito + * * @param resumoComissao - * @param boletoComissaos - * @param lsEventosFinanceiros + * @param boletoComissaos + * @param lsEventosFinanceiros * @return */ private void carregarTotalDeposito(ResumoComissao resumoComissao, List boletoComissaos, List lsEventosFinanceiros) { List formaspagosDeposito = new ArrayList(Arrays.asList(Constantes.FORMA_PAGO_DINHEIRO.intValue(), - Constantes.FORMA_PAGO_TROCA_PASSAGEM.intValue())); - + Constantes.FORMA_PAGO_TROCA_PASSAGEM.intValue())); + BigDecimal totalDeposito = BigDecimal.ZERO; - + for (BoletoComissao boletoComissao : boletoComissaos) { if (!boletoComissao.isNotSomarBilhete()) { for (FormapagoVO formapago : boletoComissao.getFormapagos()) { - if(formaspagosDeposito.contains(formapago.getFormapagoId())) { - //subtraindo as quitacoes de ocd - if(boletoComissao.isMotivocancelacionQuitacaoOcd()) { + if (formaspagosDeposito.contains(formapago.getFormapagoId())) { + // subtraindo as quitacoes de ocd + if (boletoComissao.isMotivocancelacionQuitacaoOcd()) { totalDeposito = MoneyHelper.subtrair(totalDeposito, formapago.getImporte()); - //somando as vendas - } else if(boletoComissao.isAbaBilheteVendido() || boletoComissao.isAbaGapVendido() || boletoComissao.isAbaBilheteManual()) { + // somando as vendas + } else if (boletoComissao.isAbaBilheteVendido() || boletoComissao.isAbaGapVendido() || boletoComissao.isAbaBilheteManual()) { totalDeposito = MoneyHelper.somar(totalDeposito, formapago.getImporte()); - //subtraindo os cancelamentos - } else if(boletoComissao.isAbaBilheteCancelado() || boletoComissao.isAbaGapCancelado()) { + // subtraindo os cancelamentos + } else if (boletoComissao.isAbaBilheteCancelado() || boletoComissao.isAbaGapCancelado()) { totalDeposito = MoneyHelper.subtrair(totalDeposito, formapago.getImporte()); - //subtraindo as trocas e devolucoes - } else if(boletoComissao.isAbaBilheteDevolvido() || boletoComissao.isAbaGapDevolvido()) { - if(boletoComissao.isMotivocancelacionTrocado() || boletoComissao.isMotivocancelacionDevolvido()) { + // subtraindo as trocas e devolucoes + } else if (boletoComissao.isAbaBilheteDevolvido() || boletoComissao.isAbaGapDevolvido()) { + if (boletoComissao.isMotivocancelacionTrocado() || boletoComissao.isMotivocancelacionDevolvido()) { totalDeposito = MoneyHelper.subtrair(totalDeposito, formapago.getImporte()); } } @@ -570,10 +570,10 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic } } } - - //calculando os movimentos financeiros + + // calculando os movimentos financeiros for (EventosFinanceirosVO eventosFinanceiros : lsEventosFinanceiros) { - if(formaspagosDeposito.contains(eventosFinanceiros.getFormapagoId())) { + if (formaspagosDeposito.contains(eventosFinanceiros.getFormapagoId())) { if (eventosFinanceiros.isCredito()) { totalDeposito = MoneyHelper.somar(totalDeposito, eventosFinanceiros.getImpingreso()); } else if (eventosFinanceiros.isDebito()) { @@ -581,15 +581,16 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic } } } - + resumoComissao.setValorDeposito(totalDeposito); - + } /** * 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
+ * (-) Abas: Bilhetes Cancelados, Bilhetes Devolvidos, Gap Cancelados, Gap Devolvidos
+ * * @param resumoComissao * @param boletoComissaos * @param lsEventosFinanceiros @@ -607,25 +608,25 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic totalFormapagos.add(formapago); } - //subtraindo as quitacoes de ocd - if(boletoComissao.isMotivocancelacionQuitacaoOcd()) { + // subtraindo as quitacoes de ocd + if (boletoComissao.isMotivocancelacionQuitacaoOcd()) { formapago.subtract(formapagoBoleto.getImporte()); - //somando as vendas + // somando as vendas } else if (boletoComissao.isAbaBilheteVendido() || boletoComissao.isAbaGapVendido() || boletoComissao.isAbaBilheteManual()) { formapago.add(formapagoBoleto.getImporte()); - //subtraindo os cancelamentos + // subtraindo os cancelamentos } else if (boletoComissao.isAbaBilheteCancelado() || boletoComissao.isAbaGapCancelado()) { formapago.subtract(formapagoBoleto.getImporte()); - //subtraindo as trocas e devolucoes - } else if(boletoComissao.isAbaBilheteDevolvido() || boletoComissao.isAbaGapDevolvido()) { - if(boletoComissao.isMotivocancelacionTrocado() || boletoComissao.isMotivocancelacionDevolvido() || boletoComissao.isMotivocancelacionQuitacaoOcd()) { + // subtraindo as trocas e devolucoes + } else if (boletoComissao.isAbaBilheteDevolvido() || boletoComissao.isAbaGapDevolvido()) { + if (boletoComissao.isMotivocancelacionTrocado() || boletoComissao.isMotivocancelacionDevolvido() || boletoComissao.isMotivocancelacionQuitacaoOcd()) { formapago.subtract(formapagoBoleto.getImporte()); } } } } } - + for (EventosFinanceirosVO eventosFinanceiros : lsEventosFinanceiros) { FormapagoVO formapagoEventoFinanceiro = new FormapagoVO(eventosFinanceiros.getFormapagoId(), eventosFinanceiros.getDescpago(), null, BigDecimal.ZERO); if (totalFormapagos.contains(formapagoEventoFinanceiro)) { @@ -640,7 +641,7 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic formapagoEventoFinanceiro.subtract(eventosFinanceiros.getImpingreso().abs()); } } - + resumoComissao.setTotalFormapago(totalFormapagos); } @@ -775,12 +776,13 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic } } + @Override @Transactional(readOnly = true, propagation = Propagation.SUPPORTS) public void generacionAutomaticaConferencia() { - List lsPuntoVenta; - List lsConferenciaComissao; - Conferencia conferencia; - // Perocorrer todas as empresas cadastradas + List lsPuntoVenta; + List lsConferenciaComissao; + Conferencia conferencia; + // Perocorrer todas as empresas cadastradas List lsEmpresa = empresaService.obtenerTodos(); for (Empresa empresa : lsEmpresa) { lsPuntoVenta = puntoVentaService.buscaPuntoVentaEmpresaSemECF(empresa); @@ -789,11 +791,11 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic PuntoVenta puntoVenta = new PuntoVenta(puntoVentaVO.getPuntoventaId(), puntoVentaVO.getNombpuntoventa()); // Busca o Movimento para o dia de ontem, caso não exista aborta para este ponto de venda lsConferenciaComissao = carregarConferenciaComissao(null, empresa, puntoVenta, DateUtil.getYesterdayDate()); - if ((CollectionUtils.isEmpty(lsConferenciaComissao)) || (!CollectionUtils.isEmpty(lsConferenciaComissao.get(0).getDias()) && lsConferenciaComissao.get(0).getDias().size() < 1)) { + if ((CollectionUtils.isEmpty(lsConferenciaComissao)) || (!CollectionUtils.isEmpty(lsConferenciaComissao.get(0).getDias()) && lsConferenciaComissao.get(0).getDias().size() < 1)) { log.info("Não há conferência para o Ponto de Venda " + puntoVentaVO.getNombpuntoventa() + " da empresa " + empresa.getNombempresa() + " no dia " + DateUtil.getYesterdayDateString()); continue; } - + // Confirma chegada do malote conferencia = obtenerConferenciaDataMovimento(DateUtil.getYesterdayDate(), puntoVentaVO.getPuntoventaId(), empresa.getEmpresaId()); if (conferencia == null) { @@ -802,24 +804,23 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic conferencia.setFecmodif(new Date()); conferencia.setUsuarioId(1); conferencia.setEmpresa(empresa); - conferencia.setPuntoVenta(new PuntoVenta( puntoVentaVO.getPuntoventaId())); + conferencia.setPuntoVenta(new PuntoVenta(puntoVentaVO.getPuntoventaId())); conferencia.setDatamovimento(DateUtil.getYesterdayDate()); - } - else{ - //Se existe a conferência com status conferido para esta empresa e ponto de venda no dia de ontem, aborta. - if(Boolean.TRUE == conferencia.getIndconferido()){ + } else { + // Se existe a conferência com status conferido para esta empresa e ponto de venda no dia de ontem, aborta. + if (Boolean.TRUE == conferencia.getIndconferido()) { log.info("Já existe conferência com status conferido para o Ponto de Venda " + puntoVentaVO.getNombpuntoventa() + " da empresa " + empresa.getNombempresa() + " no dia " + DateUtil.getYesterdayDateString()); continue; } } - - //Valida se existe alguma pendência que impede o fechamento. - if(!validaConferencia(conferencia)){ + + // Valida se existe alguma pendência que impede o fechamento. + if (!validaConferencia(conferencia)) { log.info("Não há bilhetes para conferir ou será necessário realizar Conferência Manual para o Ponto de Venda " + puntoVentaVO.getNombpuntoventa() + " da empresa " + empresa.getNombempresa() + " no dia " + DateUtil.getYesterdayDateString()); continue; } - - //Confirma chegada do malote + + // Confirma chegada do malote conferencia = confirmarChegadaMalote(conferencia); log.info("Realizado confirmação de chegada do malote para o Ponto de Venda " + puntoVentaVO.getNombpuntoventa() + " da empresa " + empresa.getNombempresa() + " no dia " + DateUtil.getYesterdayDateString()); @@ -834,47 +835,47 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic } } - private boolean validaConferencia(Conferencia conferencia ) { + private boolean validaConferencia(Conferencia conferencia) { try { - + List boletosComissaos = carregarBilhetesComissao(null, conferencia, null, false); - if(boletosComissaos ==null || CollectionUtils.isEmpty(boletosComissaos)){ + if (boletosComissaos == null || CollectionUtils.isEmpty(boletosComissaos)) { return false; } - if(!validaBilhetesManual(boletosComissaos, conferencia)){ + if (!validaBilhetesManual(boletosComissaos, conferencia)) { return false; } - - if(!validaBilhetesVendidos(boletosComissaos, conferencia)){ + + if (!validaBilhetesVendidos(boletosComissaos, conferencia)) { return false; } - - if(!validaBilhetesCancelados(boletosComissaos, conferencia)){ + + if (!validaBilhetesCancelados(boletosComissaos, conferencia)) { return false; } - - if(!validaBilhetesDevolvidos(boletosComissaos, conferencia)){ + + if (!validaBilhetesDevolvidos(boletosComissaos, conferencia)) { return false; } - - if(!validaBilhetesGap(boletosComissaos, conferencia)){ + + if (!validaBilhetesGap(boletosComissaos, conferencia)) { return false; } - - if(!validaBilhetesGapCancelados(boletosComissaos, conferencia)){ + + if (!validaBilhetesGapCancelados(boletosComissaos, conferencia)) { return false; } - - if(!validaBilhetesGapDevolvidos(boletosComissaos, conferencia)){ + + if (!validaBilhetesGapDevolvidos(boletosComissaos, conferencia)) { return false; } - - if(!validaEventosFinanceiros(boletosComissaos, conferencia)){ + + if (!validaEventosFinanceiros(boletosComissaos, conferencia)) { return false; } - - if(!validaOcds(conferencia)){ + + if (!validaOcds(conferencia)) { return false; } return true; @@ -883,80 +884,86 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic return false; } } - - private boolean validaBilhetesManual(List boletosComissaos, Conferencia conferencia ) throws BusinessException { + + private boolean validaBilhetesManual(List boletosComissaos, Conferencia conferencia) throws BusinessException { List lsBilhetesManual = carregarBilhetesComissao(boletosComissaos, conferencia, BoletoStatusComissao.BOLETO_MANUAL, false); - if(!CollectionUtils.isEmpty(lsBilhetesManual) && isBilhetesSemConferencia(lsBilhetesManual)){ + if (!CollectionUtils.isEmpty(lsBilhetesManual) && isBilhetesSemConferencia(lsBilhetesManual)) { return false; - }else{ + } else { return true; } } + private boolean validaBilhetesVendidos(List boletosComissaos, Conferencia conferencia) throws BusinessException { List lsBilhetes = carregarBilhetesComissao(boletosComissaos, conferencia, BoletoStatusComissao.BOLETOS_VENDIDOS, false); - if(!CollectionUtils.isEmpty(lsBilhetes) && isBilhetesSemConferencia(lsBilhetes)){ - + if (!CollectionUtils.isEmpty(lsBilhetes) && isBilhetesSemConferencia(lsBilhetes)) { + return false; - }else{ + } else { return true; } } + private boolean validaBilhetesCancelados(List boletosComissaos, Conferencia conferencia) throws BusinessException { List lsBilhetesCancelados = carregarBilhetesComissao(boletosComissaos, conferencia, BoletoStatusComissao.BOLETO_CANCELADO, false); - if(!CollectionUtils.isEmpty(lsBilhetesCancelados) && isBilhetesSemConferencia(lsBilhetesCancelados)){ + if (!CollectionUtils.isEmpty(lsBilhetesCancelados) && isBilhetesSemConferencia(lsBilhetesCancelados)) { return false; - }else{ + } else { return true; } } + private boolean validaBilhetesDevolvidos(List boletosComissaos, Conferencia conferencia) throws BusinessException { List lsBilhetesDevolvidos = carregarBilhetesComissao(boletosComissaos, conferencia, BoletoStatusComissao.BOLETO_DEVOLVIDO, false); - if(!CollectionUtils.isEmpty(lsBilhetesDevolvidos) && isBilhetesSemConferencia(lsBilhetesDevolvidos)){ + if (!CollectionUtils.isEmpty(lsBilhetesDevolvidos) && isBilhetesSemConferencia(lsBilhetesDevolvidos)) { return false; - }else{ + } else { return true; } } + private boolean validaBilhetesGap(List boletosComissaos, Conferencia conferencia) throws BusinessException { List lsBilhetesGap = carregarBilhetesComissao(boletosComissaos, conferencia, BoletoStatusComissao.GAP_VENDIDOS, false); - if(!CollectionUtils.isEmpty(lsBilhetesGap) && isBilhetesSemConferencia(lsBilhetesGap)){ + if (!CollectionUtils.isEmpty(lsBilhetesGap) && isBilhetesSemConferencia(lsBilhetesGap)) { return false; - }else{ + } else { return true; } } - private boolean validaBilhetesGapCancelados(List boletosComissaos, Conferencia conferencia ) throws BusinessException { + + private boolean validaBilhetesGapCancelados(List boletosComissaos, Conferencia conferencia) throws BusinessException { List lsBilhetesGapCancelados = carregarBilhetesComissao(boletosComissaos, conferencia, BoletoStatusComissao.GAP_CANCELADO, false); - if(!CollectionUtils.isEmpty(lsBilhetesGapCancelados) && isBilhetesSemConferencia(lsBilhetesGapCancelados)){ + if (!CollectionUtils.isEmpty(lsBilhetesGapCancelados) && isBilhetesSemConferencia(lsBilhetesGapCancelados)) { return false; - }else{ - return true; + } else { + return true; } } - + private boolean validaBilhetesGapDevolvidos(List boletosComissaos, Conferencia conferencia) throws BusinessException { List lsBilhetesGapDevolvidos = carregarBilhetesComissao(boletosComissaos, conferencia, BoletoStatusComissao.GAP_DEVOLVIDO, false); - if(!CollectionUtils.isEmpty(lsBilhetesGapDevolvidos) && isBilhetesSemConferencia(lsBilhetesGapDevolvidos)){ - return false; - }else{ - return true; - } - } - - private boolean validaEventosFinanceiros(List boletosComissaos, Conferencia conferencia) throws BusinessException { - ListlsEventosFinanceiros = carregarEventosFinanceiros(conferencia); - if(!CollectionUtils.isEmpty(lsEventosFinanceiros) && isEventosFinanceirosSemConferencia(lsEventosFinanceiros)) { + if (!CollectionUtils.isEmpty(lsBilhetesGapDevolvidos) && isBilhetesSemConferencia(lsBilhetesGapDevolvidos)) { return false; } else { return true; } } + + private boolean validaEventosFinanceiros(List boletosComissaos, Conferencia conferencia) throws BusinessException { + List lsEventosFinanceiros = carregarEventosFinanceiros(conferencia); + if (!CollectionUtils.isEmpty(lsEventosFinanceiros) && isEventosFinanceirosSemConferencia(lsEventosFinanceiros)) { + return false; + } else { + return true; + } + } + private boolean validaOcds(Conferencia conferencia) throws BusinessException { List lsOcds = carregarOcds(conferencia); - if(!CollectionUtils.isEmpty(lsOcds) && isOcdSemConferencia(lsOcds)) { + if (!CollectionUtils.isEmpty(lsOcds) && isOcdSemConferencia(lsOcds)) { return false; } else { - return true; + return true; } } @@ -969,10 +976,10 @@ public class ConferenciaComissaoServiceImpl implements ConferenciaComissaoServic public boolean isConferidoVenta(BoletoComissao boletoComissao) { return conferenciaComissaoDAO.isConferidoVenta(boletoComissao); } - + @Override public void borrarLogConferenciaTransacaoId(Long transacaoId) throws BusinessException { conferenciaComissaoDAO.borrarLogConferenciaTransacaoId(transacaoId); } - + } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/IntegracaoTotvsServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/IntegracaoTotvsServiceImpl.java new file mode 100644 index 000000000..cbc0ae435 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/IntegracaoTotvsServiceImpl.java @@ -0,0 +1,44 @@ +package com.rjconsultores.ventaboletos.service.impl; + +import java.util.Date; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.rjconsultores.ventaboletos.dao.CajaDAO; +import com.rjconsultores.ventaboletos.dao.MarcaDAO; +import com.rjconsultores.ventaboletos.dao.PuntoVentaDAO; +import com.rjconsultores.ventaboletos.entidad.Empresa; +import com.rjconsultores.ventaboletos.entidad.Marca; +import com.rjconsultores.ventaboletos.entidad.PuntoVenta; +import com.rjconsultores.ventaboletos.exception.BusinessException; +import com.rjconsultores.ventaboletos.service.IntegracaoTotvsService; + +@Service("integracaoTotvsService") +public class IntegracaoTotvsServiceImpl implements IntegracaoTotvsService { + + @Autowired + CajaDAO cajaDao; + + @Autowired + PuntoVentaDAO puntoVentaDao; + + @Autowired + MarcaDAO marcaDao; + + @Override + public Integer atualizaStstausBilhetesIntegrar(Empresa empresa, Date dataIncial, Date dataFinal, PuntoVenta puntoVenta) throws BusinessException { + Marca marca = null; + if (empresa != null) { + marca = marcaDao.buscarMarcaPorEmpresa(empresa); + } + return cajaDao.atualizaCajasIntegracaoTotvs(marca, dataIncial, dataFinal, puntoVenta); + } + + @Override + public List buscaPuntoVentaEmpresa(Empresa empresa) { + return puntoVentaDao.buscaPuntoVentaEmpresa(empresa); + + } +}