987 lines
46 KiB
Java
987 lines
46 KiB
Java
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||
|
||
import java.math.BigDecimal;
|
||
import java.text.ParseException;
|
||
import java.util.ArrayList;
|
||
import java.util.Arrays;
|
||
import java.util.Calendar;
|
||
import java.util.Collection;
|
||
import java.util.Collections;
|
||
import java.util.Date;
|
||
import java.util.HashMap;
|
||
import java.util.HashSet;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.Map.Entry;
|
||
import java.util.Set;
|
||
import java.util.TreeSet;
|
||
|
||
import org.apache.commons.lang.StringUtils;
|
||
import org.apache.log4j.Logger;
|
||
import org.hibernate.Hibernate;
|
||
import org.hibernate.HibernateException;
|
||
import org.hibernate.Query;
|
||
import org.hibernate.SessionFactory;
|
||
import org.hibernate.transform.Transformers;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.beans.factory.annotation.Qualifier;
|
||
import org.springframework.stereotype.Repository;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
|
||
import com.rjconsultores.ventaboletos.constantes.Constantes;
|
||
import com.rjconsultores.ventaboletos.dao.ConferenciaComissaoDAO;
|
||
import com.rjconsultores.ventaboletos.dao.ContaCorrenteAgenciaDAO;
|
||
import com.rjconsultores.ventaboletos.entidad.Conferencia;
|
||
import com.rjconsultores.ventaboletos.entidad.ContaCorrentePtoVta;
|
||
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
||
import com.rjconsultores.ventaboletos.entidad.LogConferencia;
|
||
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
|
||
import com.rjconsultores.ventaboletos.enums.comissao.StatusLogConferencia;
|
||
import com.rjconsultores.ventaboletos.exception.BusinessException;
|
||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||
import com.rjconsultores.ventaboletos.vo.comissao.BoletoComissao;
|
||
import com.rjconsultores.ventaboletos.vo.comissao.ConferenciaComissaoVO;
|
||
import com.rjconsultores.ventaboletos.vo.comissao.DiaConferenciaComissaoVO;
|
||
import com.rjconsultores.ventaboletos.vo.comissao.EventosFinanceirosVO;
|
||
import com.rjconsultores.ventaboletos.vo.comissao.FormapagoVO;
|
||
import com.rjconsultores.ventaboletos.vo.comissao.LogConferenciaVO;
|
||
import com.rjconsultores.ventaboletos.vo.comissao.OcdVO;
|
||
|
||
@Repository("conferenciaComissaoDAO")
|
||
public class ConferenciaComissaoHibernateDAO extends GenericHibernateDAO<Conferencia, Long> implements ConferenciaComissaoDAO {
|
||
|
||
private static Logger log = Logger.getLogger(ConferenciaComissaoHibernateDAO.class);
|
||
|
||
@Autowired
|
||
private ContaCorrenteAgenciaDAO contaCorrenteAgenciaDAO;
|
||
|
||
@Autowired
|
||
public ConferenciaComissaoHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||
setSessionFactory(factory);
|
||
}
|
||
|
||
@Override
|
||
public List<ConferenciaComissaoVO> carregarConferenciaComissao(String competencia, Empresa empresa, PuntoVenta puntoVenta) throws BusinessException {
|
||
try {
|
||
List<ConferenciaComissaoVO> lsConferencias = new ArrayList<ConferenciaComissaoVO>();
|
||
|
||
carregarPuntoVentas(lsConferencias, competencia, empresa, puntoVenta);
|
||
carregarConferenciasRegistradas(lsConferencias, competencia, empresa, puntoVenta);
|
||
carregarMovimentoVendas(lsConferencias, competencia, empresa, puntoVenta);
|
||
carregarDiasSemMovimento(lsConferencias, competencia, empresa, puntoVenta);
|
||
|
||
Collections.sort(lsConferencias);
|
||
|
||
return lsConferencias;
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@SuppressWarnings({ "unchecked", "deprecation" })
|
||
private void carregarPuntoVentas(List<ConferenciaComissaoVO> lsConferencias, String competencia, Empresa empresa, PuntoVenta puntoVenta) throws BusinessException {
|
||
try {
|
||
|
||
if(puntoVenta != null && puntoVenta.getPuntoventaId() > -1) {
|
||
Set<Integer> diasSemMovimentos = DateUtil.carregarDiasCompetencia(competencia);
|
||
ConferenciaComissaoVO conferenciaComissao = new ConferenciaComissaoVO();
|
||
conferenciaComissao.setPuntoventaId(puntoVenta.getPuntoventaId());
|
||
conferenciaComissao.setNombpuntoventa(puntoVenta.getNombpuntoventa());
|
||
conferenciaComissao.setNumPuntoVenta(puntoVenta.getNumPuntoVenta());
|
||
conferenciaComissao.setCompetencia(competencia);
|
||
conferenciaComissao.setDiasSemMovimentos(diasSemMovimentos);
|
||
lsConferencias.add(conferenciaComissao);
|
||
return;
|
||
}
|
||
|
||
Map<String, Object> parametros = new HashMap<String, Object>();
|
||
StringBuilder sQuery = new StringBuilder("SELECT PV.PUNTOVENTA_ID AS \"puntoventaId\", PV.NUMPUNTOVENTA as \"numPuntoVenta\", PV.NOMBPUNTOVENTA as \"nombpuntoventa\" ");
|
||
sQuery.append("FROM PUNTO_VENTA PV ")
|
||
.append("JOIN PTOVTA_EMPRESA PTE ON PTE.PUNTOVENTA_ID = PV.PUNTOVENTA_ID ")
|
||
.append("WHERE PV.ACTIVO = 1 ");
|
||
|
||
if(empresa != null) {
|
||
sQuery.append("AND PTE.EMPRESA_ID = :empresaId ");
|
||
parametros.put("empresaId", empresa.getEmpresaId());
|
||
}
|
||
|
||
sQuery.append("ORDER BY PV.NOMBPUNTOVENTA ");
|
||
|
||
log.info(sQuery.toString());
|
||
Query qr = getSession().createSQLQuery(sQuery.toString())
|
||
.addScalar("puntoventaId", Hibernate.INTEGER)
|
||
.addScalar("numPuntoVenta", Hibernate.STRING)
|
||
.addScalar("nombpuntoventa", Hibernate.STRING)
|
||
.setResultTransformer(Transformers.aliasToBean(ConferenciaComissaoVO.class));
|
||
setParametros(qr, parametros);
|
||
|
||
processarQueryConferenciaComissao(qr.list(), lsConferencias, competencia);
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@SuppressWarnings("unchecked")
|
||
private void carregarConferenciasRegistradas(List<ConferenciaComissaoVO> lsConferencias, String competencia, Empresa empresa, PuntoVenta puntoVenta) throws BusinessException {
|
||
try {
|
||
Map<String, Object> parametros = carregarParametros(competencia, empresa, puntoVenta);
|
||
StringBuilder sQuery = new StringBuilder("SELECT co FROM Conferencia co ");
|
||
sQuery.append("JOIN co.empresa em ")
|
||
.append("JOIN co.puntoVenta pv ")
|
||
.append("WHERE co.activo = 1 ")
|
||
.append("AND co.datamovimento BETWEEN :dataInicial AND :dataFinal ");
|
||
|
||
if(parametros.containsKey("empresaId")) {
|
||
sQuery.append("AND em.empresaId = :empresaId ");
|
||
}
|
||
|
||
if(parametros.containsKey("puntoventaId")) {
|
||
sQuery.append("AND pv.puntoventaId = :puntoventaId ");
|
||
}
|
||
|
||
log.info(sQuery.toString());
|
||
Query qr = getSession().createQuery(sQuery.toString());
|
||
setParametros(qr, parametros);
|
||
processarQueryConferencia(qr.list(), lsConferencias, competencia);
|
||
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@SuppressWarnings("rawtypes")
|
||
private void setParametros(Query qr, Map<String, Object> parametros) {
|
||
for (Entry<String, Object> parametro : parametros.entrySet()) {
|
||
if(parametro.getValue() instanceof Collection) {
|
||
qr.setParameterList(parametro.getKey(), (Collection) parametro.getValue());
|
||
} else if(parametro.getValue() instanceof List) {
|
||
qr.setParameterList(parametro.getKey(), (List) parametro.getValue());
|
||
} else {
|
||
qr.setParameter(parametro.getKey(), parametro.getValue());
|
||
}
|
||
}
|
||
}
|
||
|
||
@SuppressWarnings({ "unchecked", "deprecation" })
|
||
private void carregarMovimentoVendas(List<ConferenciaComissaoVO> lsConferencias, String competencia, Empresa empresa, PuntoVenta puntoVenta) throws BusinessException {
|
||
try {
|
||
Map<String, Object> parametros = carregarParametros(competencia, empresa, puntoVenta);
|
||
StringBuilder sQuery = new StringBuilder("SELECT PV.PUNTOVENTA_ID AS \"puntoventaId\", PV.NUMPUNTOVENTA as \"numPuntoVenta\", PV.NOMBPUNTOVENTA as \"nombpuntoventa\", TO_DATE(B.FECHORVENTA, 'DD/MM/YY') as \"datamovimento\" ");
|
||
sQuery.append("FROM BOLETO B ")
|
||
.append("INNER JOIN PUNTO_VENTA PV ON B.PUNTOVENTA_ID = PV.PUNTOVENTA_ID ")
|
||
.append("WHERE PV.ACTIVO = 1 ")
|
||
.append("AND B.FECHORVENTA BETWEEN :dataInicial AND :dataFinal ")
|
||
.append("AND B.TIPOVENTA_ID IN (:tipoVenta) ")
|
||
.append("AND ( ")
|
||
.append(" (B.INDSTATUSBOLETO = 'V' AND (B.MOTIVOCANCELACION_ID IS NULL OR B.MOTIVOCANCELACION_ID IN (:motivocancelacionId))) ")
|
||
.append(" OR ")
|
||
.append(" (B.INDSTATUSBOLETO = 'C' AND B.MOTIVOCANCELACION_ID IN (:motivocancelacionId)) ")
|
||
.append(" ) ");
|
||
|
||
parametros.put("tipoVenta", Arrays.asList(Constantes.TPV_BOLETO_REMOTO,Constantes.TPV_MANUAL,Constantes.TPV_DIRECTO_NORMAL));
|
||
parametros.put("motivocancelacionId", Arrays.asList(Constantes.MVO_CANCEL_CANCELACION,Constantes.MVO_CANCEL_DEVOLUCAO));
|
||
|
||
if(parametros.containsKey("empresaId")) {
|
||
sQuery.append("AND B.EMPRESACORRIDA_ID = :empresaId ");
|
||
}
|
||
|
||
if(parametros.containsKey("puntoventaId")) {
|
||
sQuery.append("AND PV.PUNTOVENTA_ID = :puntoventaId ");
|
||
}
|
||
|
||
log.info(sQuery.toString());
|
||
|
||
Query qr = getSession().createSQLQuery(sQuery.toString())
|
||
.addScalar("puntoventaId", Hibernate.INTEGER)
|
||
.addScalar("numPuntoVenta", Hibernate.STRING)
|
||
.addScalar("nombpuntoventa", Hibernate.STRING)
|
||
.addScalar("datamovimento", Hibernate.DATE)
|
||
.setResultTransformer(Transformers.aliasToBean(ConferenciaComissaoVO.class));
|
||
setParametros(qr, parametros);
|
||
|
||
processarQueryConferenciaComissao(qr.list(), lsConferencias, competencia);
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Carrega a {@link ConferenciaComissaoVO} a partir de uma consulta com sql nativo, transformando o resultado em uma cole<6C><65>o de {@link ConferenciaComissaoVO}
|
||
* @param lsQuery
|
||
* @param lsConferencias
|
||
* @param competencia
|
||
* @param corPadrao
|
||
* @throws ParseException
|
||
*/
|
||
private void processarQueryConferenciaComissao(List<ConferenciaComissaoVO> lsQuery, List<ConferenciaComissaoVO> lsConferencias, String competencia) throws ParseException {
|
||
Set<Integer> diasSemMovimentos = DateUtil.carregarDiasCompetencia(competencia);
|
||
|
||
for (ConferenciaComissaoVO conferenciaComissaoMovimentoDiario : lsQuery) {
|
||
ConferenciaComissaoVO conferenciaComissao = new ConferenciaComissaoVO();
|
||
conferenciaComissao.setCompetencia(competencia);
|
||
conferenciaComissao.setPuntoventaId(conferenciaComissaoMovimentoDiario.getPuntoventaId());
|
||
conferenciaComissao.setNumPuntoVenta(conferenciaComissaoMovimentoDiario.getNumPuntoVenta());
|
||
conferenciaComissao.setNombpuntoventa(conferenciaComissaoMovimentoDiario.getNombpuntoventa());
|
||
conferenciaComissao.setDiasSemMovimentos(new TreeSet<Integer>(diasSemMovimentos));
|
||
|
||
if(lsConferencias.contains(conferenciaComissao)) {
|
||
conferenciaComissao = lsConferencias.get(lsConferencias.indexOf(conferenciaComissao));
|
||
}
|
||
|
||
if(conferenciaComissaoMovimentoDiario.getDatamovimento() != null) {
|
||
Integer dia = Integer.valueOf(DateUtil.getStringDate(conferenciaComissaoMovimentoDiario.getDatamovimento(), "dd"));
|
||
if(conferenciaComissao.getDiasSemMovimentos().contains(dia)) {
|
||
|
||
DiaConferenciaComissaoVO diaConferenciaComissao = new DiaConferenciaComissaoVO();
|
||
diaConferenciaComissao.setDia(dia);
|
||
diaConferenciaComissao.setData(DateUtil.getDateFromString(dia + "/" + competencia, "dd/MM/yyyy"));
|
||
|
||
if(conferenciaComissao.getDias() == null) {
|
||
conferenciaComissao.setDias(new ArrayList<DiaConferenciaComissaoVO>());
|
||
}
|
||
|
||
conferenciaComissao.getDias().add(diaConferenciaComissao);
|
||
conferenciaComissao.getDiasSemMovimentos().remove(diaConferenciaComissao.getDia());
|
||
}
|
||
}
|
||
|
||
if(!lsConferencias.contains(conferenciaComissao)) {
|
||
lsConferencias.add(conferenciaComissao);
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Carrega a {@link ConferenciaComissaoVO} a partir dos registros da tabela {@link Conferencia}
|
||
* @param lsQuery
|
||
* @param lsConferencias
|
||
* @param competencia
|
||
* @throws ParseException
|
||
*/
|
||
private void processarQueryConferencia(List<Conferencia> lsQuery, List<ConferenciaComissaoVO> lsConferencias, String competencia) throws ParseException {
|
||
Set<Integer> diasSemMovimentos = DateUtil.carregarDiasCompetencia(competencia);
|
||
|
||
for (Conferencia conferencia : lsQuery) {
|
||
ConferenciaComissaoVO conferenciaComissao = new ConferenciaComissaoVO();
|
||
conferenciaComissao.setCompetencia(competencia);
|
||
conferenciaComissao.setPuntoventaId(conferencia.getPuntoVenta().getPuntoventaId());
|
||
conferenciaComissao.setNumPuntoVenta(conferencia.getPuntoVenta().getNumPuntoVenta());
|
||
conferenciaComissao.setNombpuntoventa(conferencia.getPuntoVenta().getNombpuntoventa());
|
||
conferenciaComissao.setDiasSemMovimentos(new TreeSet<Integer>(diasSemMovimentos));
|
||
|
||
if(lsConferencias.contains(conferenciaComissao)) {
|
||
conferenciaComissao = lsConferencias.get(lsConferencias.indexOf(conferenciaComissao));
|
||
}
|
||
|
||
if(conferencia.getDatamovimento() != null) {
|
||
Integer dia = Integer.valueOf(DateUtil.getStringDate(conferencia.getDatamovimento(), "dd"));
|
||
if(conferenciaComissao.getDiasSemMovimentos().contains(dia)) {
|
||
|
||
DiaConferenciaComissaoVO diaConferenciaComissao = new DiaConferenciaComissaoVO();
|
||
diaConferenciaComissao.setConferenciaId(conferencia.getConferenciaId());
|
||
diaConferenciaComissao.setDia(dia);
|
||
diaConferenciaComissao.setData(DateUtil.getDateFromString(dia + "/" + competencia, "dd/MM/yyyy"));
|
||
diaConferenciaComissao.setIndboletogerado(conferencia.getIndboletogerado());
|
||
diaConferenciaComissao.setIndconferido(conferencia.getIndconferido());
|
||
diaConferenciaComissao.setIndmaloterecebido(conferencia.getIndmaloterecebido());
|
||
diaConferenciaComissao.setIndpendencia(conferencia.getIndpendencia());
|
||
diaConferenciaComissao.setIndsemmovimento(conferencia.getIndsemmovimento());
|
||
|
||
if(conferenciaComissao.getDias() == null) {
|
||
conferenciaComissao.setDias(new ArrayList<DiaConferenciaComissaoVO>());
|
||
}
|
||
|
||
conferenciaComissao.getDias().add(diaConferenciaComissao);
|
||
conferenciaComissao.getDiasSemMovimentos().remove(diaConferenciaComissao.getDia());
|
||
}
|
||
}
|
||
|
||
if(!lsConferencias.contains(conferenciaComissao)) {
|
||
lsConferencias.add(conferenciaComissao);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void carregarDiasSemMovimento(List<ConferenciaComissaoVO> lsConferencias, String competencia, Empresa empresa, PuntoVenta puntoVenta) throws ParseException {
|
||
for (ConferenciaComissaoVO conferenciaComissao : lsConferencias) {
|
||
for (Integer diaSemMovimento : conferenciaComissao.getDiasSemMovimentos()) {
|
||
DiaConferenciaComissaoVO diaConferenciaComissao = new DiaConferenciaComissaoVO();
|
||
diaConferenciaComissao.setDia(diaSemMovimento);
|
||
diaConferenciaComissao.setData(DateUtil.getDateFromString(diaSemMovimento + "/" + competencia, "dd/MM/yyyy"));
|
||
diaConferenciaComissao.setIndsemmovimento(true);
|
||
|
||
if(conferenciaComissao.getDias() == null) {
|
||
conferenciaComissao.setDias(new ArrayList<DiaConferenciaComissaoVO>());
|
||
}
|
||
conferenciaComissao.getDias().add(diaConferenciaComissao);
|
||
}
|
||
conferenciaComissao.getDiasSemMovimentos().clear();
|
||
}
|
||
}
|
||
|
||
private Map<String, Object> carregarParametros(String competencia, Empresa empresa, PuntoVenta puntoVenta) throws ParseException {
|
||
Map<String, Object> parametros = new HashMap<String, Object>();
|
||
if(empresa != null) {
|
||
parametros.put("empresaId", empresa.getEmpresaId());
|
||
}
|
||
if(puntoVenta != null) {
|
||
parametros.put("puntoventaId", puntoVenta.getPuntoventaId());
|
||
}
|
||
|
||
if(StringUtils.isNotBlank(competencia)) {
|
||
String[] vetCompetencia = competencia.split("/");
|
||
Calendar cal = Calendar.getInstance();
|
||
cal.set(Calendar.MONTH, Integer.valueOf(vetCompetencia[0]) - 1);
|
||
cal.set(Calendar.YEAR, Integer.valueOf(vetCompetencia[1]));
|
||
|
||
parametros.put("dataInicial", DateUtil.getDateFromString(cal.getActualMinimum(Calendar.DAY_OF_MONTH) + "/" + competencia, "dd/MM/yyyy"));
|
||
parametros.put("dataFinal", DateUtil.getDateFromString(cal.getActualMaximum(Calendar.DAY_OF_MONTH) + "/" + competencia, "dd/MM/yyyy"));
|
||
}
|
||
|
||
return parametros;
|
||
}
|
||
|
||
@Override
|
||
@Transactional
|
||
public Conferencia confirmarChegadaMalote(Conferencia conferencia) throws BusinessException {
|
||
try {
|
||
conferencia.setIndmaloterecebido(Boolean.TRUE);
|
||
if(!isBilhetesSemConferencia(conferencia) && !isEventosFinanceirosSemConferencia(conferencia)) {
|
||
return encerrarMovimentoDiario(conferencia);
|
||
}
|
||
return suscribirOrActualizacion(conferencia);
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
@Transactional
|
||
public Conferencia suscribirOrActualizacion(Conferencia entidad) {
|
||
if(entidad.getConferenciaId() == null) {
|
||
return suscribir(entidad);
|
||
} else {
|
||
return actualizacion(entidad);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
@Transactional
|
||
public Conferencia encerrarMovimentoDiario(Conferencia conferencia) throws BusinessException {
|
||
try {
|
||
conferencia.setIndconferido(Boolean.TRUE);
|
||
conferencia.setIndpendencia(isMovimentoDiarioPendencia(conferencia));
|
||
conferencia.setIndboletogerado(isMovimentoDiarioBoletoGerado(conferencia));
|
||
|
||
gerarLancamentoContaCorrente(conferencia);
|
||
return suscribirOrActualizacion(conferencia);
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
@Transactional
|
||
public Conferencia reabrirMovimentoDiario(Conferencia conferencia) throws BusinessException {
|
||
try {
|
||
conferencia.setIndconferido(Boolean.FALSE);
|
||
return suscribirOrActualizacion(conferencia);
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
private boolean isMovimentoDiarioBoletoGerado(Conferencia conferencia) throws BusinessException {
|
||
try {
|
||
Map<String, Object> parametros = carregarParametros(null, conferencia.getEmpresa(), conferencia.getPuntoVenta());
|
||
StringBuilder sQuery = new StringBuilder();
|
||
sQuery.append("SELECT FECHAMENTOCNTCORRENTE_ID ")
|
||
.append("FROM FECHAMENTO_CNTCORRENTE ")
|
||
.append("WHERE ACTIVO = 1 ")
|
||
.append("AND :datamovimento BETWEEN FECINIFECHAMENTO AND FECFINFECHAMENTO ");
|
||
|
||
parametros.put("datamovimento", conferencia.getDatamovimento());
|
||
|
||
if(parametros.containsKey("empresaId")) {
|
||
sQuery.append("AND EMPRESA_ID = :empresaId ");
|
||
}
|
||
|
||
if(parametros.containsKey("puntoventaId")) {
|
||
sQuery.append("AND PUNTOVENTA_ID = :puntoventaId ");
|
||
}
|
||
|
||
log.info(sQuery.toString());
|
||
|
||
Query qr = getSession().createSQLQuery(sQuery.toString());
|
||
setParametros(qr, parametros);
|
||
|
||
return !qr.list().isEmpty();
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
private boolean isMovimentoDiarioPendencia(Conferencia conferencia) {
|
||
Query qr = getSession().createQuery("SELECT COUNT(log) FROM LogConferencia log WHERE log.activo = 1 AND log.conferencia.conferenciaId = :conferenciaId AND log.status = :status");
|
||
qr.setParameter("conferenciaId", conferencia.getConferenciaId());
|
||
qr.setParameter("status", StatusLogConferencia.PENDENCIA);
|
||
return !qr.list().isEmpty() && ((Long)qr.list().get(0)) > 0;
|
||
}
|
||
|
||
@Override
|
||
@SuppressWarnings({ "unchecked", "deprecation" })
|
||
public List<EventosFinanceirosVO> carregarEventosFinanceiros(Conferencia conferencia) throws BusinessException {
|
||
try {
|
||
Map<String, Object> parametros = carregarParametros(null, conferencia.getEmpresa(), conferencia.getPuntoVenta());
|
||
StringBuilder sQuery = new StringBuilder();
|
||
sQuery.append("SELECT EE.EVENTOEXTRA_ID AS \"eventoextraId\", EE.NUMDOCUMENTO AS \"numdocumento\", ")
|
||
.append("EE.IMPINGRESO AS \"impingreso\", TEE.DESCTIPOEVENTO AS \"desctipoevento\", EE.DESCINFO AS \"descinfo\", ")
|
||
.append("LOG.STATUS AS \"status\", FP.FORMAPAGO_ID AS \"formapagoId\", FP.DESCPAGO AS \"descpago\", ")
|
||
.append("TEE.INDTIPO AS \"indtipo\", U.NOMBUSUARIO AS \"nombusuario\", LOG.LOGCONFERENCIA_ID AS \"logconferenciaId\", ")
|
||
.append("COMFP.COMEMPFORMAPAGO_ID AS \"comempformapagoId\", COMTEE.COMEMPTIPOEVENTOEXTRA_ID AS \"comemptipoeventoextraId\" ")
|
||
.append("FROM EVENTO_EXTRA EE ")
|
||
.append("JOIN TIPO_EVENTO_EXTRA TEE ON EE.TIPOEVENTOEXTRA_ID = TEE.TIPOEVENTOEXTRA_ID ")
|
||
.append("INNER JOIN USUARIO U ON EE.USUARIO_ID = U.USUARIO_ID ")
|
||
.append("LEFT JOIN LOG_CONFERENCIA LOG ON LOG.EVENTOEXTRA_ID = EE.EVENTOEXTRA_ID ")
|
||
.append("LEFT JOIN FORMA_PAGO FP ON FP.FORMAPAGO_ID = EE.FORMAPAGO_ID ")
|
||
.append("LEFT JOIN COM_EMP_FORMAPAGO COMFP ON COMFP.FORMAPAGO_ID = FP.FORMAPAGO_ID AND COMFP.EMPRESA_ID = EE.EMPRESA_ID ")
|
||
.append("LEFT JOIN COM_EMP_TIPOEVENTOEXTRA COMTEE ON COMTEE.TIPOEVENTOEXTRA_ID = TEE.TIPOEVENTOEXTRA_ID AND COMTEE.EMPRESA_ID = EE.EMPRESA_ID ")
|
||
.append("WHERE EE.ACTIVO = 1 ")
|
||
.append("AND TO_DATE(EE.FECHORINGRESO,'DD/MM/YY') = :datamovimento ");
|
||
|
||
parametros.put("datamovimento", conferencia.getDatamovimento());
|
||
|
||
if(parametros.containsKey("empresaId")) {
|
||
sQuery.append("AND EE.EMPRESA_ID = :empresaId ");
|
||
}
|
||
|
||
if(parametros.containsKey("puntoventaId")) {
|
||
sQuery.append("AND EE.PUNTOVENTA_ID = :puntoventaId ");
|
||
}
|
||
|
||
sQuery.append("ORDER BY TEE.DESCTIPOEVENTO ");
|
||
|
||
log.info(sQuery.toString());
|
||
|
||
Query qr = getSession().createSQLQuery(sQuery.toString())
|
||
.addScalar("eventoextraId", Hibernate.LONG)
|
||
.addScalar("numdocumento", Hibernate.STRING)
|
||
.addScalar("impingreso", Hibernate.BIG_DECIMAL)
|
||
.addScalar("desctipoevento", Hibernate.STRING)
|
||
.addScalar("descinfo", Hibernate.STRING)
|
||
.addScalar("status", Hibernate.INTEGER)
|
||
.addScalar("formapagoId", Hibernate.INTEGER)
|
||
.addScalar("descpago", Hibernate.STRING)
|
||
.addScalar("comempformapagoId", Hibernate.INTEGER)
|
||
.addScalar("comemptipoeventoextraId", Hibernate.INTEGER)
|
||
.addScalar("indtipo", Hibernate.STRING)
|
||
.addScalar("nombusuario", Hibernate.STRING)
|
||
.addScalar("logconferenciaId", Hibernate.LONG)
|
||
.setResultTransformer(Transformers.aliasToBean(EventosFinanceirosVO.class));
|
||
setParametros(qr, parametros);
|
||
|
||
return qr.list();
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||
public List<LogConferenciaVO> carregarLogConferencia(Conferencia conferencia) throws BusinessException {
|
||
try {
|
||
if(conferencia != null && conferencia.getConferenciaId() != null) {
|
||
StringBuilder sQuery = new StringBuilder();
|
||
sQuery.append("SELECT LOG.LOGCONFERENCIA_ID AS \"logconferenciaId\", LOG.OBSERVACAO AS \"observacao\", LOG.PRECO AS \"preco\", ")
|
||
.append("LOG.STATUS AS \"status\", B.NUMFOLIOSISTEMA AS \"numfoliosistema\", LOG.TIPO AS \"tipo\", ")
|
||
.append("O.NUMOPERACION AS \"numoperacion\", TEE.DESCTIPOEVENTO AS \"desctipoevento\", U.NOMBUSUARIO AS \"nombusuario\", ")
|
||
.append("LOG.FECMODIF AS \"fecmodif\", B.BOLETO_ID AS \"boletoId\", O.OCD_ID AS \"ocdId\", EE.EVENTOEXTRA_ID AS \"eventoextraId\" ")
|
||
.append("FROM LOG_CONFERENCIA LOG ")
|
||
.append("LEFT JOIN BOLETO B ON B.BOLETO_ID = LOG.BOLETO_ID ")
|
||
.append("LEFT JOIN EVENTO_EXTRA EE ON EE.EVENTOEXTRA_ID = LOG.EVENTOEXTRA_ID ")
|
||
.append("LEFT JOIN TIPO_EVENTO_EXTRA TEE ON TEE.TIPOEVENTOEXTRA_ID = EE.TIPOEVENTOEXTRA_ID ")
|
||
.append("LEFT JOIN OCD O ON O.OCD_ID = LOG.OCD_ID ")
|
||
.append("JOIN USUARIO U ON U.USUARIO_ID = LOG.USUARIO_ID ")
|
||
.append("WHERE LOG.ACTIVO = 1 ")
|
||
.append("AND LOG.CONFERENCIA_ID = :conferenciaId ");
|
||
|
||
Query qr = getSession().createSQLQuery(sQuery.toString())
|
||
.addScalar("logconferenciaId", Hibernate.LONG)
|
||
.addScalar("observacao", Hibernate.STRING)
|
||
.addScalar("preco", Hibernate.BIG_DECIMAL)
|
||
.addScalar("status", Hibernate.INTEGER)
|
||
.addScalar("numfoliosistema", Hibernate.STRING)
|
||
.addScalar("tipo", Hibernate.INTEGER)
|
||
.addScalar("numoperacion", Hibernate.STRING)
|
||
.addScalar("desctipoevento", Hibernate.STRING)
|
||
.addScalar("nombusuario", Hibernate.STRING)
|
||
.addScalar("fecmodif", Hibernate.TIMESTAMP)
|
||
.addScalar("boletoId", Hibernate.LONG)
|
||
.addScalar("ocdId", Hibernate.LONG)
|
||
.addScalar("eventoextraId", Hibernate.LONG)
|
||
.setResultTransformer(Transformers.aliasToBean(LogConferenciaVO.class));
|
||
qr.setParameter("conferenciaId", conferencia.getConferenciaId());
|
||
|
||
return qr.list();
|
||
}
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
|
||
return new ArrayList<LogConferenciaVO>();
|
||
}
|
||
|
||
@Override
|
||
@Transactional
|
||
public LogConferencia suscribirLogConferencia(LogConferencia logConferencia) throws BusinessException {
|
||
try {
|
||
if(logConferencia.getConferencia().getConferenciaId() == null) {
|
||
logConferencia.setConferencia(confirmarChegadaMalote(logConferencia.getConferencia()));
|
||
}
|
||
|
||
getSession().save(logConferencia);
|
||
return logConferencia;
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
@Transactional
|
||
public void borrarLogConferencia(LogConferencia logConferencia) throws BusinessException {
|
||
try {
|
||
if(logConferencia.getContaCorrentePtoVta() != null) {
|
||
ContaCorrentePtoVta contaCorrentePtoVta = logConferencia.getContaCorrentePtoVta();
|
||
contaCorrentePtoVta.setActivo(Boolean.FALSE);
|
||
contaCorrentePtoVta.setFecmodif(logConferencia.getFecmodif());
|
||
contaCorrentePtoVta.setUsuario(logConferencia.getUsuario());
|
||
|
||
contaCorrenteAgenciaDAO.actualizacion(contaCorrentePtoVta);
|
||
}
|
||
getSession().merge(logConferencia);
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public LogConferencia obtenerLogConferenciaID(Long logconferenciaId) {
|
||
try {
|
||
return (LogConferencia) this.getHibernateTemplate().get(LogConferencia.class.getName(), logconferenciaId);
|
||
} catch (final HibernateException ex) {
|
||
throw convertHibernateAccessException(ex);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
@SuppressWarnings({ "unchecked", "deprecation" })
|
||
public List<BoletoComissao> carregarBilhetesComissao(Conferencia conferencia) throws BusinessException {
|
||
try {
|
||
Map<String, Object> 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\", ")
|
||
.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("FROM BOLETO B ")
|
||
.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 ")
|
||
.append("LEFT JOIN CATEGORIA CAT ON CAT.CATEGORIA_ID = B.CATEGORIA_ID ")
|
||
.append("LEFT JOIN LOG_CONFERENCIA LOG ON LOG.BOLETO_ID = B.BOLETO_ID AND LOG.ACTIVO = 1 ")
|
||
.append("LEFT JOIN MOTIVO_CANCELACION MC ON MC.MOTIVOCANCELACION_ID = B.MOTIVOCANCELACION_ID ")
|
||
.append("INNER JOIN BOLETO_FORMAPAGO BF ON BF.BOLETO_ID = B.BOLETO_ID ")
|
||
.append("INNER JOIN FORMA_PAGO FP ON FP.FORMAPAGO_ID = BF.FORMAPAGO_ID ")
|
||
.append("INNER JOIN USUARIO U ON B.USUARIO_ID = U.USUARIO_ID ")
|
||
.append("LEFT JOIN COM_EMP_FORMAPAGO COMFP ON COMFP.FORMAPAGO_ID = FP.FORMAPAGO_ID AND COMFP.EMPRESA_ID = B.EMPRESACORRIDA_ID ")
|
||
.append("LEFT JOIN COM_EMP_CATEGORIA COMCAT ON COMCAT.CATEGORIA_ID = B.CATEGORIA_ID AND COMCAT.EMPRESA_ID = B.EMPRESACORRIDA_ID ")
|
||
.append("WHERE B.ACTIVO = 1 ")
|
||
.append("AND TO_DATE(B.FECHORVENTA,'DD/MM/YY') = :datamovimento ")
|
||
.append("AND ((B.INDSTATUSBOLETO = 'V' AND (B.MOTIVOCANCELACION_ID IS NULL OR B.MOTIVOCANCELACION_ID IN (:motivocancelacionId))) ")
|
||
.append(" OR ")
|
||
.append(" (B.INDSTATUSBOLETO = 'C' AND B.MOTIVOCANCELACION_ID IN (:motivocancelacionId))")
|
||
.append(" )");
|
||
|
||
parametros.put("datamovimento", conferencia.getDatamovimento());
|
||
parametros.put("motivocancelacionId", Arrays.asList(Constantes.MVO_CANCEL_CANCELACION, Constantes.MVO_CANCEL_DEVOLUCAO));
|
||
|
||
if(parametros.containsKey("empresaId")) {
|
||
sQuery.append("AND B.EMPRESACORRIDA_ID = :empresaId ");
|
||
}
|
||
|
||
if(parametros.containsKey("puntoventaId")) {
|
||
sQuery.append("AND B.PUNTOVENTA_ID = :puntoventaId ");
|
||
}
|
||
|
||
if(StringUtils.isNotBlank(conferencia.getNumfoliosistema())) {
|
||
sQuery.append("AND B.NUMFOLIOSISTEMA = :numfoliosistema ");
|
||
parametros.put("numfoliosistema", conferencia.getNumfoliosistema());
|
||
}
|
||
|
||
/*parametros.put("tipoVenta", Arrays.asList(Constantes.TPV_BOLETO_REMOTO,Constantes.TPV_MANUAL,Constantes.TPV_DIRECTO_NORMAL));
|
||
|
||
if(BoletoStatusComissao.BOLETOS.equals(boletoStatusComissao)) {
|
||
sQuery.append("AND B.TIPOVENTA_ID NOT IN (:tipoVenta) ")
|
||
.append("AND B.INDSTATUSBOLETO IN ('V','C') ");
|
||
parametros.put("tipoVenta", Arrays.asList(Constantes.TPV_BOLETO_REMOTO,Constantes.TPV_MANUAL));
|
||
}
|
||
|
||
if(BoletoStatusComissao.BOLETO_MANUAL.equals(boletoStatusComissao)) {
|
||
sQuery.append("AND B.TIPOVENTA_ID = :tipoVenta ");
|
||
parametros.put("tipoVenta", Constantes.TPV_MANUAL);
|
||
}
|
||
|
||
if(BoletoStatusComissao.BOLETO_CANCELADO.equals(boletoStatusComissao) || BoletoStatusComissao.BOLETO_DEVOLVIDO.equals(boletoStatusComissao)) {
|
||
sQuery.append("AND B.TIPOVENTA_ID = :tipoVenta ")
|
||
.append("AND B.INDSTATUSBOLETO = 'C' ")
|
||
.append("AND B.MOTIVOCANCELACION_ID = :motivocancelacionId ");
|
||
parametros.put("motivocancelacionId", BoletoStatusComissao.BOLETO_CANCELADO.equals(boletoStatusComissao) ? Constantes.MVO_CANCEL_CANCELACION : Constantes.MVO_CANCEL_DEVOLUCAO);
|
||
parametros.put("tipoVenta", Constantes.TPV_DIRECTO_NORMAL);
|
||
}
|
||
|
||
if(BoletoStatusComissao.GAP.equals(boletoStatusComissao)) {
|
||
sQuery.append("AND B.TIPOVENTA_ID = :tipoVenta ")
|
||
.append("AND B.INDSTATUSBOLETO = 'V' ")
|
||
.append("AND B.MOTIVOCANCELACION_ID IS NULL ");
|
||
parametros.put("tipoVenta", Constantes.TPV_BOLETO_REMOTO);
|
||
}
|
||
|
||
if(BoletoStatusComissao.GAP_CANCELADO.equals(boletoStatusComissao) || BoletoStatusComissao.GAP_DEVOLVIDO.equals(boletoStatusComissao)) {
|
||
sQuery.append("AND B.TIPOVENTA_ID = :tipoVenta ")
|
||
.append("AND B.INDSTATUSBOLETO = 'C' ")
|
||
.append("AND B.MOTIVOCANCELACION_ID = :motivocancelacionId ");
|
||
parametros.put("motivocancelacionId", BoletoStatusComissao.GAP_CANCELADO.equals(boletoStatusComissao) ? Constantes.MVO_CANCEL_CANCELACION : Constantes.MVO_CANCEL_DEVOLUCAO);
|
||
parametros.put("tipoVenta", Constantes.TPV_BOLETO_REMOTO);
|
||
}*/
|
||
|
||
log.info(sQuery.toString());
|
||
|
||
Query qr = getSession().createSQLQuery(sQuery.toString())
|
||
.addScalar("boletoId", Hibernate.LONG)
|
||
.addScalar("numAsiento", Hibernate.STRING)
|
||
.addScalar("numAsientoVinculado", Hibernate.STRING)
|
||
.addScalar("numFolioSistema", Hibernate.STRING)
|
||
.addScalar("numSeriePreimpresa", Hibernate.STRING)
|
||
.addScalar("numFolioPreImpreso", Hibernate.STRING)
|
||
.addScalar("uf", Hibernate.STRING)
|
||
.addScalar("desccategoria", Hibernate.STRING)
|
||
.addScalar("valorpagado", Hibernate.BIG_DECIMAL)
|
||
.addScalar("seguroOutros", Hibernate.BIG_DECIMAL)
|
||
.addScalar("pedagio", Hibernate.BIG_DECIMAL)
|
||
.addScalar("seguro", Hibernate.BIG_DECIMAL)
|
||
.addScalar("embarque", Hibernate.BIG_DECIMAL)
|
||
.addScalar("tipoVenta", Hibernate.INTEGER)
|
||
.addScalar("indstatusboleto", Hibernate.STRING)
|
||
.addScalar("status", Hibernate.INTEGER)
|
||
.addScalar("formapagoId", Hibernate.INTEGER)
|
||
.addScalar("descpago", Hibernate.STRING)
|
||
.addScalar("logconferenciaId", Hibernate.LONG)
|
||
.addScalar("descmotivocancelacion", Hibernate.STRING)
|
||
.addScalar("nombusuario", Hibernate.STRING)
|
||
.addScalar("motivoCancelacionId", Hibernate.INTEGER)
|
||
.addScalar("importeFp", Hibernate.BIG_DECIMAL)
|
||
.addScalar("comempformapagoId", Hibernate.INTEGER)
|
||
.addScalar("comempcategoriaId", Hibernate.INTEGER)
|
||
.setResultTransformer(Transformers.aliasToBean(BoletoComissao.class));
|
||
setParametros(qr, parametros);
|
||
|
||
List<BoletoComissao> lsBoletoComissao = new ArrayList<BoletoComissao>();
|
||
List<BoletoComissao> auxLsBoletoComissao = qr.list();
|
||
for (BoletoComissao boletoComissao : auxLsBoletoComissao) {
|
||
if(boletoComissao.getFormapagos() == null) {
|
||
boletoComissao.setFormapagos(new HashSet<FormapagoVO>());
|
||
}
|
||
|
||
if(lsBoletoComissao.contains(boletoComissao)) {
|
||
BoletoComissao aux = lsBoletoComissao.get(lsBoletoComissao.indexOf(boletoComissao));
|
||
aux.getFormapagos().add(new FormapagoVO(boletoComissao.getFormapagoId(), boletoComissao.getDescpago(), boletoComissao.getIndconferenciafisicacomissao(), boletoComissao.getImporteFp()));
|
||
lsBoletoComissao.set(lsBoletoComissao.indexOf(boletoComissao), aux);
|
||
} else {
|
||
boletoComissao.getFormapagos().add(new FormapagoVO(boletoComissao.getFormapagoId(), boletoComissao.getDescpago(), boletoComissao.getIndconferenciafisicacomissao(), boletoComissao.getImporteFp()));
|
||
lsBoletoComissao.add(boletoComissao);
|
||
}
|
||
}
|
||
|
||
return lsBoletoComissao;
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
@SuppressWarnings({ "unchecked", "deprecation" })
|
||
public List<OcdVO> carregarOcds(Conferencia conferencia) throws BusinessException {
|
||
try {
|
||
Map<String, Object> parametros = carregarParametros(null, conferencia.getEmpresa(), conferencia.getPuntoVenta());
|
||
|
||
StringBuilder sQuery = new StringBuilder();
|
||
sQuery.append("SELECT DISTINCT O.OCD_ID AS \"ocdId\", O.NUMOPERACION AS \"numoperacion\", O.FECINC AS \"fecinc\", O.FECPAGAR AS \"fecpagar\", O.FECPAGO AS \"fecpago\", ")
|
||
.append("O.INDPAGO AS \"indpago\", O.VALOR_PAGAR AS \"valorPagar\", O.PENALIZACION AS \"penalizacion\", LOG.STATUS AS \"status\", U.NOMBUSUARIO AS \"nombusuario\", LOG.LOGCONFERENCIA_ID AS \"logconferenciaId\" ")
|
||
.append("FROM OCD O ")
|
||
.append("LEFT JOIN BOLETO B ON B.BOLETO_ID = O.BOLETO_ID ")
|
||
.append("LEFT JOIN LOG_CONFERENCIA LOG ON LOG.OCD_ID = O.OCD_ID ")
|
||
.append("INNER JOIN USUARIO U ON O.USUARIO_ID = U.USUARIO_ID ")
|
||
.append("WHERE O.ACTIVO = 1 ")
|
||
.append("AND TO_DATE(O.FECINC,'DD/MM/YY') = :datamovimento ");
|
||
|
||
parametros.put("datamovimento", conferencia.getDatamovimento());
|
||
|
||
if(parametros.containsKey("empresaId")) {
|
||
sQuery.append("AND B.EMPRESACORRIDA_ID = :empresaId ");
|
||
}
|
||
|
||
if(parametros.containsKey("puntoventaId")) {
|
||
sQuery.append("AND O.PUNTOVENTA_ID = :puntoventaId ");
|
||
}
|
||
|
||
log.info(sQuery.toString());
|
||
|
||
Query qr = getSession().createSQLQuery(sQuery.toString())
|
||
.addScalar("ocdId", Hibernate.LONG)
|
||
.addScalar("numoperacion", Hibernate.STRING)
|
||
.addScalar("fecinc", Hibernate.DATE)
|
||
.addScalar("fecpagar", Hibernate.DATE)
|
||
.addScalar("fecpago", Hibernate.DATE)
|
||
.addScalar("indpago", Hibernate.BOOLEAN)
|
||
.addScalar("valorPagar", Hibernate.BIG_DECIMAL)
|
||
.addScalar("penalizacion", Hibernate.BIG_DECIMAL)
|
||
.addScalar("status", Hibernate.INTEGER)
|
||
.addScalar("nombusuario", Hibernate.STRING)
|
||
.addScalar("logconferenciaId", Hibernate.STRING)
|
||
.setResultTransformer(Transformers.aliasToBean(OcdVO.class));
|
||
setParametros(qr, parametros);
|
||
|
||
return qr.list();
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public Conferencia obtenerConferenciaDataMovimento(Date datamovimento, Integer puntoventaId, Integer empresaId) throws BusinessException {
|
||
try {
|
||
StringBuilder sQuery = new StringBuilder();
|
||
sQuery.append("SELECT co ")
|
||
.append("FROM Conferencia co ")
|
||
.append("WHERE co.activo = 1 ")
|
||
.append("AND co.datamovimento = :datamovimento ")
|
||
.append("AND co.empresa.empresaId = :empresaId ")
|
||
.append("AND co.puntoVenta.puntoventaId = :puntoventaId ");
|
||
|
||
log.info(sQuery.toString());
|
||
Query qr = getSession().createQuery(sQuery.toString());
|
||
qr.setParameter("datamovimento", datamovimento);
|
||
qr.setParameter("empresaId", empresaId);
|
||
qr.setParameter("puntoventaId", puntoventaId);
|
||
qr.setMaxResults(1);
|
||
return (Conferencia) qr.uniqueResult();
|
||
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@Transactional
|
||
private void gerarLancamentoContaCorrente(Conferencia conferencia) throws BusinessException {
|
||
try {
|
||
Calendar cal = Calendar.getInstance();
|
||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
||
|
||
List<LogConferencia> lsLogConferencia = carregarLogConferencia(conferencia.getConferenciaId());
|
||
String sDataMovimento = DateUtil.getStringDate(conferencia.getDatamovimento(), "dd/MM/yyyy");
|
||
String descOperacion = "CONFERENCIA MOVIMENTO DIA - " + sDataMovimento;
|
||
|
||
for (LogConferencia logConferencia : lsLogConferencia) {
|
||
if(logConferencia.getStatus().equals(StatusLogConferencia.CONFERIDO) ||
|
||
(logConferencia.getContaCorrentePtoVta() != null &&
|
||
logConferencia.getContaCorrentePtoVta().getActivo() != null &&
|
||
logConferencia.getContaCorrentePtoVta().getActivo())) {
|
||
continue;
|
||
}
|
||
|
||
ContaCorrentePtoVta contaCorrentePtoVta = contaCorrenteAgenciaDAO.gravarContaCorrente(conferencia.getPuntoVenta().getPuntoventaId(),
|
||
descOperacion, cal.getTime(), conferencia.getUsuarioId(),
|
||
logConferencia.isIndcredito() ? Constantes.TIPO_OPERACION_CC_PAGO : Constantes.TIPO_OPERACION_CC_LQ,
|
||
conferencia.getEmpresa().getEmpresaId(),
|
||
Constantes.TURNO_AUTOMATICO, BigDecimal.ZERO,
|
||
BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO,
|
||
BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO,
|
||
BigDecimal.ZERO, logConferencia.getPreco(), false,
|
||
BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO);
|
||
|
||
logConferencia.setContaCorrentePtoVta(contaCorrentePtoVta);
|
||
suscribirLogConferencia(logConferencia);
|
||
}
|
||
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
@SuppressWarnings("unchecked")
|
||
public List<LogConferencia> carregarLogConferencia(Long conferenciaId) throws BusinessException {
|
||
try {
|
||
StringBuilder sQuery = new StringBuilder();
|
||
sQuery.append("SELECT log ")
|
||
.append("FROM LogConferencia log ")
|
||
.append("WHERE log.activo = 1 ")
|
||
.append("AND log.conferencia.conferenciaId = :conferenciaId ");
|
||
Query qr = getSession().createQuery(sQuery.toString());
|
||
qr.setParameter("conferenciaId", conferenciaId);
|
||
return qr.list();
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
@SuppressWarnings("deprecation")
|
||
public boolean isBilhetesSemConferencia(Conferencia conferencia) throws BusinessException {
|
||
try {
|
||
Map<String, Object> parametros = carregarParametros(null, conferencia.getEmpresa(), conferencia.getPuntoVenta());
|
||
|
||
StringBuilder sQuery = new StringBuilder();
|
||
sQuery.append("SELECT B.BOLETO_ID AS \"boletoId\" ")
|
||
.append("FROM BOLETO B ")
|
||
.append("LEFT JOIN LOG_CONFERENCIA LOG ON LOG.BOLETO_ID = B.BOLETO_ID AND LOG.ACTIVO = 1 ")
|
||
.append("INNER JOIN CATEGORIA CAT ON CAT.CATEGORIA_ID = B.CATEGORIA_ID ")
|
||
.append("LEFT JOIN COM_EMP_CATEGORIA COMCAT ON COMCAT.CATEGORIA_ID = B.CATEGORIA_ID AND COMCAT.EMPRESA_ID = B.EMPRESACORRIDA_ID ")
|
||
.append("INNER JOIN BOLETO_FORMAPAGO BF ON BF.BOLETO_ID = B.BOLETO_ID ")
|
||
.append("INNER JOIN FORMA_PAGO FP ON FP.FORMAPAGO_ID = BF.FORMAPAGO_ID ")
|
||
.append("LEFT JOIN COM_EMP_FORMAPAGO COMFP ON COMFP.FORMAPAGO_ID = FP.FORMAPAGO_ID AND COMFP.EMPRESA_ID = B.EMPRESACORRIDA_ID ")
|
||
.append("WHERE B.ACTIVO = 1 ")
|
||
.append("AND LOG.LOGCONFERENCIA_ID IS NULL ")
|
||
.append("AND (COMFP.COMEMPFORMAPAGO_ID IS NOT NULL OR COMCAT.COMEMPCATEGORIA_ID IS NOT NULL) ")
|
||
.append("AND TO_DATE(B.FECHORVENTA,'DD/MM/YY') = :datamovimento ")
|
||
.append("AND B.TIPOVENTA_ID IN (:tipoVenta) ")
|
||
.append("AND ( ")
|
||
.append(" (B.INDSTATUSBOLETO = 'V' AND B.MOTIVOCANCELACION_ID IS NULL) ")
|
||
.append(" OR ")
|
||
.append(" (B.INDSTATUSBOLETO = 'C' AND B.MOTIVOCANCELACION_ID IN (:motivocancelacionId)) ")
|
||
.append(" ) ");
|
||
|
||
parametros.put("datamovimento", conferencia.getDatamovimento());
|
||
parametros.put("tipoVenta", Arrays.asList(Constantes.TPV_BOLETO_REMOTO,Constantes.TPV_MANUAL,Constantes.TPV_DIRECTO_NORMAL));
|
||
parametros.put("motivocancelacionId", Arrays.asList(Constantes.MVO_CANCEL_CANCELACION,Constantes.MVO_CANCEL_DEVOLUCAO));
|
||
|
||
if(parametros.containsKey("empresaId")) {
|
||
sQuery.append("AND B.EMPRESACORRIDA_ID = :empresaId ");
|
||
}
|
||
|
||
if(parametros.containsKey("puntoventaId")) {
|
||
sQuery.append("AND B.PUNTOVENTA_ID = :puntoventaId ");
|
||
}
|
||
|
||
log.info(sQuery.toString());
|
||
|
||
Query qr = getSession().createSQLQuery(sQuery.toString())
|
||
.addScalar("boletoId", Hibernate.LONG)
|
||
.setResultTransformer(Transformers.aliasToBean(BoletoComissao.class));
|
||
setParametros(qr, parametros);
|
||
|
||
return !qr.list().isEmpty();
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
@SuppressWarnings("deprecation")
|
||
public boolean isEventosFinanceirosSemConferencia(Conferencia conferencia) throws BusinessException {
|
||
try {
|
||
Map<String, Object> parametros = carregarParametros(null, conferencia.getEmpresa(), conferencia.getPuntoVenta());
|
||
StringBuilder sQuery = new StringBuilder();
|
||
sQuery.append("SELECT EE.EVENTOEXTRA_ID AS \"eventoextraId\" ")
|
||
.append("FROM EVENTO_EXTRA EE ")
|
||
.append("JOIN TIPO_EVENTO_EXTRA TEE ON EE.TIPOEVENTOEXTRA_ID = TEE.TIPOEVENTOEXTRA_ID ")
|
||
.append("LEFT JOIN COM_EMP_TIPOEVENTOEXTRA COMTEE ON COMTEE.TIPOEVENTOEXTRA_ID = TEE.TIPOEVENTOEXTRA_ID AND COMTEE.EMPRESA_ID = EE.EMPRESA_ID ")
|
||
.append("LEFT JOIN LOG_CONFERENCIA LOG ON LOG.EVENTOEXTRA_ID = EE.EVENTOEXTRA_ID AND LOG.ACTIVO = 1 ")
|
||
.append("LEFT JOIN FORMA_PAGO FP ON FP.FORMAPAGO_ID = EE.FORMAPAGO_ID ")
|
||
.append("LEFT JOIN COM_EMP_FORMAPAGO COMFP ON COMFP.FORMAPAGO_ID = FP.FORMAPAGO_ID AND COMFP.EMPRESA_ID = EE.EMPRESA_ID ")
|
||
.append("WHERE EE.ACTIVO = 1 ")
|
||
.append("AND LOG.LOGCONFERENCIA_ID IS NULL ")
|
||
.append("AND (COMTEE.COMEMPTIPOEVENTOEXTRA_ID IS NOT NULL OR COMFP.COMEMPFORMAPAGO_ID IS NOT NULL) ")
|
||
.append("AND TO_DATE(EE.FECHORINGRESO,'DD/MM/YY') = :datamovimento ");
|
||
|
||
parametros.put("datamovimento", conferencia.getDatamovimento());
|
||
|
||
if(parametros.containsKey("empresaId")) {
|
||
sQuery.append("AND EE.EMPRESA_ID = :empresaId ");
|
||
}
|
||
|
||
if(parametros.containsKey("puntoventaId")) {
|
||
sQuery.append("AND EE.PUNTOVENTA_ID = :puntoventaId ");
|
||
}
|
||
|
||
log.info(sQuery.toString());
|
||
|
||
Query qr = getSession().createSQLQuery(sQuery.toString())
|
||
.addScalar("eventoextraId", Hibernate.LONG)
|
||
.setResultTransformer(Transformers.aliasToBean(EventosFinanceirosVO.class));
|
||
setParametros(qr, parametros);
|
||
|
||
return !qr.list().isEmpty();
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public BigDecimal carregarTotalFechamentoContaCorrente(Conferencia conferencia) throws BusinessException {
|
||
try {
|
||
Map<String, Object> parametros = carregarParametros(null, conferencia.getEmpresa(), conferencia.getPuntoVenta());
|
||
|
||
StringBuilder sQuery = new StringBuilder();
|
||
sQuery.append("SELECT SUM(TOTAL) AS TOTAL ")
|
||
.append("FROM FECHAMENTO_CNTCORRENTE ")
|
||
.append("WHERE ACTIVO = 1 ")
|
||
.append("AND :datamovimento BETWEEN FECINIFECHAMENTO AND FECFINFECHAMENTO ");
|
||
|
||
parametros.put("datamovimento", conferencia.getDatamovimento());
|
||
|
||
if(parametros.containsKey("empresaId")) {
|
||
sQuery.append("AND EMPRESA_ID = :empresaId ");
|
||
}
|
||
|
||
if(parametros.containsKey("puntoventaId")) {
|
||
sQuery.append("AND PUNTOVENTA_ID = :puntoventaId ");
|
||
}
|
||
|
||
log.info(sQuery.toString());
|
||
|
||
Query qr = getSession().createSQLQuery(sQuery.toString());
|
||
setParametros(qr, parametros);
|
||
return (BigDecimal) qr.uniqueResult();
|
||
} catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
}
|