1017 lines
46 KiB
Java
1017 lines
46 KiB
Java
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||
|
||
import java.math.BigDecimal;
|
||
import java.sql.Connection;
|
||
import java.sql.PreparedStatement;
|
||
import java.sql.ResultSet;
|
||
import java.sql.SQLException;
|
||
import java.text.ParseException;
|
||
import java.util.ArrayList;
|
||
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 javax.sql.DataSource;
|
||
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
|
||
private DataSource dataSourceRead;
|
||
|
||
@Autowired
|
||
public ConferenciaComissaoHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
||
setSessionFactory(factory);
|
||
}
|
||
|
||
@Override
|
||
public List<ConferenciaComissaoVO> carregarConferenciaComissao(String competencia,
|
||
Empresa empresa, PuntoVenta puntoVenta) throws BusinessException {
|
||
Connection con = null;
|
||
try {
|
||
con = dataSourceRead.getConnection();
|
||
|
||
List<ConferenciaComissaoVO> lsConferencias = new ArrayList<ConferenciaComissaoVO>();
|
||
|
||
carregarPuntoVentas(lsConferencias, competencia, empresa, puntoVenta);
|
||
carregarConferenciasRegistradas(lsConferencias, competencia, empresa, puntoVenta);
|
||
carregarMovimentoVendas(con, 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);
|
||
}
|
||
finally {
|
||
try {
|
||
if (con != null && !con.isClosed()) {
|
||
con.close();
|
||
}
|
||
}
|
||
catch (SQLException e) {
|
||
log.error(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()
|
||
.append("SELECT PV.PUNTOVENTA_ID AS \"puntoventaId\", ")
|
||
.append("PV.NUMPUNTOVENTA as \"numPuntoVenta\", PV.NOMBPUNTOVENTA as \"nombpuntoventa\" ")
|
||
.append("FROM PUNTO_VENTA PV ")
|
||
.append("JOIN PTOVTA_EMPRESA PTE ON PTE.PUNTOVENTA_ID = PV.PUNTOVENTA_ID AND PTE.ACTIVO = 1 ")
|
||
.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 ");
|
||
|
||
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, null);
|
||
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 ");
|
||
}
|
||
|
||
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());
|
||
}
|
||
}
|
||
}
|
||
|
||
private void carregarMovimentoVendas(Connection con, List<ConferenciaComissaoVO> lsConferencias,
|
||
String competencia, Empresa empresa, PuntoVenta puntoVenta)
|
||
throws BusinessException, SQLException {
|
||
PreparedStatement stmt = null;
|
||
ResultSet rset = null;
|
||
|
||
try {
|
||
Map<String, Object> parametros = carregarParametros(competencia, empresa, puntoVenta, null);
|
||
StringBuilder sQuery = new StringBuilder()
|
||
.append("SELECT PV.PUNTOVENTA_ID AS \"puntoventaId\", PV.NUMPUNTOVENTA as \"numPuntoVenta\", ")
|
||
.append("PV.NOMBPUNTOVENTA as \"nombpuntoventa\", TO_DATE(B.FECHORVENTA, 'DD/MM/YY') as \"datamovimento\" ")
|
||
.append("FROM BOLETO B ")
|
||
.append("INNER JOIN PUNTO_VENTA PV ON B.PUNTOVENTA_ID = PV.PUNTOVENTA_ID ")
|
||
.append("INNER JOIN MARCA M ON B.MARCA_ID = M.MARCA_ID ")
|
||
.append("WHERE PV.ACTIVO = 1 ")
|
||
.append("AND B.FECHORVENTA BETWEEN TO_DATE(?, 'DD/MM/YYYY HH24:MI') AND TO_DATE(?, 'DD/MM/YYYY HH24:MI') ");
|
||
|
||
if (parametros.containsKey("empresaId")) {
|
||
sQuery.append("AND M.EMPRESA_ID = ? ");
|
||
}
|
||
if (parametros.containsKey("puntoventaId")) {
|
||
sQuery.append("AND PV.PUNTOVENTA_ID = ? ");
|
||
}
|
||
|
||
sQuery.append("GROUP BY PV.PUNTOVENTA_ID, PV.NUMPUNTOVENTA, PV.NOMBPUNTOVENTA, TO_DATE(B.FECHORVENTA, 'DD/MM/YY') ");
|
||
|
||
int idxParametro = 1;
|
||
stmt = con.prepareStatement(sQuery.toString());
|
||
stmt.setString(idxParametro++, DateUtil.getStringDate(DateUtil.inicioFecha((Date) parametros.get("dataInicial")), "dd/MM/yyyy HH:mm"));
|
||
stmt.setString(idxParametro++, DateUtil.getStringDate(DateUtil.fimFecha((Date) parametros.get("dataFinal")), "dd/MM/yyyy HH:mm"));
|
||
if (parametros.containsKey("empresaId")) {
|
||
stmt.setInt(idxParametro++, (Integer) parametros.get("empresaId"));
|
||
}
|
||
if (parametros.containsKey("puntoventaId")) {
|
||
stmt.setInt(idxParametro++, (Integer) parametros.get("puntoventaId"));
|
||
}
|
||
|
||
rset = stmt.executeQuery();
|
||
List<ConferenciaComissaoVO> movimentos = new ArrayList<ConferenciaComissaoVO>();
|
||
while (rset.next()) {
|
||
ConferenciaComissaoVO conferenciaComissao = new ConferenciaComissaoVO();
|
||
conferenciaComissao.setPuntoventaId(rset.getInt("puntoventaId"));
|
||
conferenciaComissao.setNumPuntoVenta(rset.getString("numPuntoVenta"));
|
||
conferenciaComissao.setNombpuntoventa(rset.getString("nombpuntoventa"));
|
||
conferenciaComissao.setDatamovimento(rset.getDate("datamovimento"));
|
||
|
||
movimentos.add(conferenciaComissao);
|
||
}
|
||
|
||
processarQueryConferenciaComissao(movimentos, lsConferencias, competencia);
|
||
}
|
||
catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
finally {
|
||
if (rset != null && !rset.isClosed()) {
|
||
rset.close();
|
||
}
|
||
if (stmt != null && !stmt.isClosed()) {
|
||
stmt.close();
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 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, Date datamovimento) throws ParseException {
|
||
Map<String, Object> parametros = new HashMap<String, Object>();
|
||
if (empresa != null) {
|
||
parametros.put("empresaId", empresa.getEmpresaId());
|
||
}
|
||
if (puntoVenta != null && puntoVenta.getPuntoventaId() > -1) {
|
||
parametros.put("puntoventaId", puntoVenta.getPuntoventaId());
|
||
}
|
||
|
||
if (datamovimento != null) {
|
||
parametros.put("dataMovimentoInicial", DateUtil.getStringDate(DateUtil.inicioFecha(datamovimento), "dd/MM/yyyy HH:mm"));
|
||
parametros.put("dataMovimentoFinal", DateUtil.getStringDate(DateUtil.fimFecha(datamovimento), "dd/MM/yyyy HH:mm"));
|
||
}
|
||
|
||
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 + " 00:00:00", "dd/MM/yyyy hh:mm:ss"));
|
||
parametros.put("dataFinal", DateUtil.getDateFromString(
|
||
cal.getActualMaximum(Calendar.DAY_OF_MONTH) + "/" + competencia + " 23:59:59", "dd/MM/yyyy hh:mm:ss"));
|
||
}
|
||
|
||
return parametros;
|
||
}
|
||
|
||
@Override
|
||
@Transactional
|
||
public Conferencia confirmarChegadaMalote(Conferencia conferencia) throws BusinessException {
|
||
try {
|
||
conferencia.setIndmaloterecebido(Boolean.TRUE);
|
||
if (conferencia.isSemPendenciaConferencia()) {
|
||
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(), null);
|
||
StringBuilder sQuery = new StringBuilder()
|
||
.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 ");
|
||
}
|
||
|
||
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(), conferencia.getDatamovimento());
|
||
StringBuilder sQuery = new StringBuilder()
|
||
.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("CEC.INDEVENTOSFINANCEIROS AS \"exigeConferenciaAba\" ")
|
||
.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 COM_EMP_CONFERENCIA CEC ON EE.EMPRESA_ID = CEC.EMPRESA_ID AND CEC.ACTIVO = 1 ")
|
||
.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 AND COMFP.ACTIVO = 1 ")
|
||
.append("LEFT JOIN COM_EMP_TIPOEVENTOEXTRA COMTEE ON COMTEE.TIPOEVENTOEXTRA_ID = TEE.TIPOEVENTOEXTRA_ID AND COMTEE.EMPRESA_ID = EE.EMPRESA_ID AND COMTEE.ACTIVO = 1 ")
|
||
.append("WHERE EE.ACTIVO = 1 ")
|
||
.append("AND EE.FECHORINGRESO BETWEEN TO_DATE(:dataMovimentoInicial, 'DD/MM/YYYY HH24:MI') AND TO_DATE(:dataMovimentoFinal, 'DD/MM/YYYY HH24:MI') ");
|
||
|
||
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 ");
|
||
|
||
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)
|
||
.addScalar("exigeConferenciaAba", Hibernate.BOOLEAN)
|
||
.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()
|
||
.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\", LOG.INDCREDITO AS \"indcredito\", B.BOLETO_ID AS \"boletoId\", O.OCD_ID AS \"ocdId\", EE.EVENTOEXTRA_ID AS \"eventoextraId\", TI.DESCTIPO AS \"desctipoinformativo\", ")
|
||
.append("CP.DESCPENDENCIA AS \"descpendencia\" ")
|
||
.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("LEFT JOIN TIPO_INFORMATIVO TI ON TI.TIPOINFORMATIVO_ID = LOG.TIPOINFORMATIVOCOMISSAO_ID ")
|
||
.append("LEFT JOIN CONFERENCIA_PENDENCIA CP ON CP.CONFERENCIAPENDENCIA_ID = LOG.CONFERENCIAPENDENCIA_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("indcredito", Hibernate.SHORT)
|
||
.addScalar("boletoId", Hibernate.LONG).addScalar("ocdId", Hibernate.LONG)
|
||
.addScalar("eventoextraId", Hibernate.LONG)
|
||
.addScalar("desctipoinformativo", Hibernate.STRING)
|
||
.addScalar("descpendencia", Hibernate.STRING)
|
||
.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(suscribir(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(), conferencia.getDatamovimento());
|
||
|
||
StringBuilder sQuery = new StringBuilder()
|
||
.append("SELECT B.BOLETO_ID AS \"boletoId\", B.NUMASIENTO AS \"numAsiento\", B.NUMASIENTOVINCULADO AS \"numAsientoVinculado\", ")
|
||
.append("B.NUMOPERACION AS \"numoperacion\", B.NUMFOLIOSISTEMA AS \"numFolioSistema\", B.NUMSERIEPREIMPRESA AS \"numSeriePreimpresa\", ")
|
||
.append("B.NUMFOLIOPREIMPRESO AS \"numFolioPreImpreso\", EST.CVEESTADO AS \"uf\", CAT.DESCCATEGORIA AS \"desccategoria\", ")
|
||
.append("NVL(B.PRECIOPAGADO,0) AS \"valorpagado\", NVL(B.IMPORTEOUTROS,0) AS \"seguroOutros\", ")
|
||
.append("NVL(B.IMPORTEPEDAGIO,0) AS \"pedagio\", NVL(B.IMPORTESEGURO,0) AS \"seguro\", NVL(B.IMPORTETAXAEMBARQUE,0) AS \"embarque\", ")
|
||
.append("B.TIPOVENTA_ID AS \"tipoVenta\", B.INDSTATUSBOLETO AS \"indstatusboleto\", LOG.STATUS AS \"status\", ")
|
||
.append("FP.FORMAPAGO_ID AS \"formapagoId\", FP.DESCPAGO AS \"descpago\", LOG.LOGCONFERENCIA_ID AS \"logconferenciaId\", ")
|
||
.append("MC.DESCMOTIVO AS \"descmotivocancelacion\", U.NOMBUSUARIO AS \"nombusuario\", B.MOTIVOCANCELACION_ID AS \"motivocancelacionId\", ")
|
||
.append("BF.IMPORTE AS \"importeFp\", COMFP.COMEMPFORMAPAGO_ID AS \"comempformapagoId\", COMCAT.COMEMPCATEGORIA_ID AS \"comempcategoriaId\", ")
|
||
.append("BO1.TIPOVENTA_ID \"tipoVentaOriginal1\", BO2.TIPOVENTA_ID \"tipoVentaOriginal2\", OCD.OCD_ID \"ocdId\", ")
|
||
.append("B.NOMBPASAJERO AS \"nombpasajero\", E.INDCARBOLETOSDEVOLVIDOSCONF AS \"indcarboletosdevolvidosconf\", ")
|
||
.append("B.FECCORRIDA AS \"feccorrida\", B.CORRIDA_ID \"corridaId\", B.BOLETOORIGINAL_ID AS \"boletoOriginalId\", ")
|
||
.append("BO1.MOTIVOCANCELACION_ID \"motivoCancelacionOriginal1\", BO2.MOTIVOCANCELACION_ID \"motivoCancelacionOriginal2\", ")
|
||
.append("NVL(tarifa.PRECIO,0) + NVL(tarifa.IMPORTEPEDAGIO,0) + NVL(tarifa.IMPORTETAXAEMBARQUE,0) + NVL(tarifa.IMPORTESEGURO,0) + NVL(tarifa.IMPORTEOUTROS,0) AS \"valorTabela\"")
|
||
.append("FROM BOLETO B ")
|
||
.append("LEFT JOIN BOLETO BO1 ON BO1.BOLETO_ID = B.BOLETOORIGINAL_ID ")
|
||
.append("LEFT JOIN BOLETO BO2 ON BO2.BOLETO_ID = BO1.BOLETOORIGINAL_ID ")
|
||
.append("LEFT JOIN OCD OCD ON B.BOLETOORIGINAL_ID = OCD.BOLETO_ID ")
|
||
.append("LEFT JOIN PARADA ORI ON ORI.PARADA_ID = B.ORIGEN_ID ")
|
||
.append("LEFT JOIN CIUDAD CID ON CID.CIUDAD_ID = ORI.PARADA_ID ")
|
||
.append("LEFT JOIN ESTADO EST ON EST.ESTADO_ID = CID.ESTADO_ID ")
|
||
.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("INNER JOIN MARCA M ON B.MARCA_ID = M.MARCA_ID ")
|
||
.append("INNER JOIN EMPRESA E ON E.EMPRESA_ID = M.EMPRESA_ID ")
|
||
.append("LEFT JOIN COM_EMP_FORMAPAGO COMFP ON COMFP.FORMAPAGO_ID = FP.FORMAPAGO_ID AND COMFP.EMPRESA_ID = M.EMPRESA_ID AND COMFP.ACTIVO = 1 ")
|
||
.append("LEFT JOIN COM_EMP_CATEGORIA COMCAT ON COMCAT.CATEGORIA_ID = B.CATEGORIA_ID AND COMCAT.EMPRESA_ID = M.EMPRESA_ID AND COMCAT.ACTIVO = 1 ")
|
||
.append("INNER JOIN TARIFA tarifa ON (tarifa.RUTA_ID = B.RUTA_ID AND tarifa.ORIGEN_ID = B.ORIGEN_ID AND tarifa.DESTINO_ID = B.DESTINO_ID AND tarifa.MARCA_ID = M.MARCA_ID) ")
|
||
.append("INNER JOIN VIGENCIA_TARIFA vigenciaTarifa ON (vigenciaTarifa.VIGENCIATARIFA_ID = tarifa.VIGENCIATARIFA_ID) ")
|
||
.append("WHERE B.ACTIVO = 1 ")
|
||
.append("AND B.FECHORVENTA BETWEEN TO_DATE(:dataMovimentoInicial, 'DD/MM/YYYY HH24:MI') AND TO_DATE(:dataMovimentoFinal, 'DD/MM/YYYY HH24:MI') ")
|
||
.append("AND B.FECHORVENTA BETWEEN vigenciaTarifa.FECINICIOVIGENCIA AND vigenciaTarifa.FECFINVIGENCIA ");
|
||
|
||
|
||
if (parametros.containsKey("empresaId")) {
|
||
sQuery.append("AND M.EMPRESA_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());
|
||
}
|
||
sQuery.append("ORDER BY B.BOLETO_ID ");
|
||
|
||
Query qr = getSession().createSQLQuery(sQuery.toString())
|
||
.addScalar("boletoId", Hibernate.LONG)
|
||
.addScalar("boletoOriginalId", 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("valorTabela", 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("motivoCancelacionOriginal1", Hibernate.INTEGER)
|
||
.addScalar("motivoCancelacionOriginal2", Hibernate.INTEGER)
|
||
.addScalar("importeFp", Hibernate.BIG_DECIMAL)
|
||
.addScalar("comempformapagoId", Hibernate.INTEGER)
|
||
.addScalar("comempcategoriaId", Hibernate.INTEGER)
|
||
.addScalar("numoperacion", Hibernate.STRING)
|
||
.addScalar("tipoVentaOriginal1", Hibernate.INTEGER)
|
||
.addScalar("tipoVentaOriginal2", Hibernate.INTEGER)
|
||
.addScalar("ocdId", Hibernate.INTEGER)
|
||
.addScalar("nombpasajero", Hibernate.STRING)
|
||
.addScalar("indcarboletosdevolvidosconf", Hibernate.BOOLEAN)
|
||
.addScalar("feccorrida", Hibernate.DATE)
|
||
.addScalar("corridaId", 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)) {
|
||
int indice = lsBoletoComissao.indexOf(boletoComissao);
|
||
BoletoComissao aux = lsBoletoComissao.get(indice);
|
||
aux.setComempcategoriaId(boletoComissao.getComempcategoriaId() != null
|
||
? boletoComissao.getComempcategoriaId() : aux.getComempcategoriaId());
|
||
aux.setComempformapagoId(boletoComissao.getComempformapagoId() != null
|
||
? boletoComissao.getComempformapagoId() : aux.getComempformapagoId());
|
||
aux.getFormapagos().add(new FormapagoVO(boletoComissao.getFormapagoId(),
|
||
boletoComissao.getDescpago(),
|
||
boletoComissao.getIndconferenciafisicacomissao(),
|
||
boletoComissao.getImporteFp()));
|
||
lsBoletoComissao.set(indice, 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(), conferencia.getDatamovimento());
|
||
|
||
StringBuilder sQuery = new StringBuilder()
|
||
.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\", (B.PRECIOPAGADO * (O.PENALIZACION / 100)) AS \"penalizacion\", LOG.STATUS AS \"status\", ")
|
||
.append("U.NOMBUSUARIO AS \"nombusuario\", LOG.LOGCONFERENCIA_ID AS \"logconferenciaId\", U.CVEUSUARIO AS \"login\", B.NUMFOLIOSISTEMA AS \"numFolioSistema\", ")
|
||
.append("CEC.INDOCD AS \"exigeConferenciaAba\" ").append("FROM OCD O ")
|
||
.append("INNER JOIN BOLETO B ON B.BOLETO_ID = O.BOLETO_ID ")
|
||
.append("INNER JOIN MARCA M ON B.MARCA_ID = M.MARCA_ID ")
|
||
.append("LEFT JOIN LOG_CONFERENCIA LOG ON LOG.OCD_ID = O.OCD_ID AND LOG.ACTIVO = 1 ")
|
||
.append("INNER JOIN USUARIO U ON O.USUARIOPAGO_ID = U.USUARIO_ID ")
|
||
.append("LEFT JOIN COM_EMP_CONFERENCIA CEC ON CEC.EMPRESA_ID = M.EMPRESA_ID AND CEC.ACTIVO = 1 ")
|
||
.append("INNER JOIN MARCA ON m.MARCA_ID = b.MARCA_ID ")
|
||
.append("WHERE O.ACTIVO = 1 ")
|
||
.append("AND O.FECPAGO BETWEEN TO_DATE(:dataMovimentoInicial, 'DD/MM/YYYY HH24:MI') AND TO_DATE(:dataMovimentoFinal, 'DD/MM/YYYY HH24:MI') ")
|
||
.append("AND O.INDPAGO = 1 ");
|
||
|
||
if (parametros.containsKey("empresaId")) {
|
||
sQuery.append("AND ((B.EMPRESACORRIDA_ID IS NOT NULL AND B.EMPRESACORRIDA_ID = :empresaId) OR(m.EMPRESA_ID = :empresaId)) ");
|
||
}
|
||
if (parametros.containsKey("puntoventaId")) {
|
||
sQuery.append("AND O.PUNTOVENTAPAGO_ID = :puntoventaId ");
|
||
}
|
||
|
||
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.LONG)
|
||
.addScalar("login", Hibernate.STRING)
|
||
.addScalar("numFolioSistema", Hibernate.STRING)
|
||
.addScalar("exigeConferenciaAba", Hibernate.BOOLEAN)
|
||
.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()
|
||
.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 ");
|
||
|
||
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()))
|
||
|| (logConferencia.getPreco() == null
|
||
|| logConferencia.getPreco().doubleValue() == 0d)
|
||
|| logConferencia.isIndcredito().equals((short) 2)) {
|
||
continue;
|
||
}
|
||
|
||
ContaCorrentePtoVta contaCorrentePtoVta = contaCorrenteAgenciaDAO
|
||
.gravarContaCorrente(conferencia.getPuntoVenta().getPuntoventaId(),
|
||
descOperacion, cal.getTime(), conferencia.getUsuarioId(),
|
||
logConferencia.isIndcredito().equals((short)1) ? 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, logConferencia.getPreco());
|
||
|
||
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()
|
||
.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
|
||
public boolean isConferenciaCompetenciaEncerrada(String competencia, Empresa empresa,
|
||
PuntoVenta puntoVenta) throws BusinessException {
|
||
try {
|
||
List<ConferenciaComissaoVO> lsConferencias = new ArrayList<ConferenciaComissaoVO>();
|
||
|
||
carregarConferenciasRegistradas(lsConferencias, competencia, empresa, puntoVenta);
|
||
carregarDiasSemMovimento(lsConferencias, competencia, empresa, puntoVenta);
|
||
|
||
for (ConferenciaComissaoVO conferenciaComissao : lsConferencias) {
|
||
for (DiaConferenciaComissaoVO diaConferenciaComissao : conferenciaComissao.getDias()) {
|
||
if (!diaConferenciaComissao.getIndsemmovimento() && !diaConferenciaComissao.getIndconferido()) {
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public BigDecimal carregarValorDepositoContaCorrente(Integer empresaId, Integer puntoventaId, Date datamovimento) {
|
||
StringBuilder sQuery = new StringBuilder()
|
||
.append("SELECT SUM(importeTotalEfectivo) ").append("FROM ContaCorrentePtoVta cc ")
|
||
.append("WHERE cc.activo = 1 ").append("AND cc.empresa.empresaId = :empresaId ")
|
||
.append("AND cc.puntoVenta.puntoventaId = :puntoventaId ")
|
||
.append("AND cc.fecHorOperacion = :datamovimento ");
|
||
|
||
Query qr = getSession().createQuery(sQuery.toString());
|
||
qr.setParameter("empresaId", empresaId);
|
||
qr.setParameter("puntoventaId", puntoventaId);
|
||
qr.setParameter("datamovimento", datamovimento);
|
||
qr.setMaxResults(1);
|
||
|
||
return (BigDecimal) qr.uniqueResult();
|
||
}
|
||
|
||
@Override
|
||
@SuppressWarnings("unchecked")
|
||
public DiaConferenciaComissaoVO carregarConferenciaRegistrada(Date datamovimento,
|
||
Empresa empresa, PuntoVenta puntoVenta) throws BusinessException {
|
||
try {
|
||
String competencia = DateUtil.getStringDate(datamovimento, "MM/yyyy");
|
||
Map<String, Object> parametros = carregarParametros(competencia, empresa, puntoVenta, null);
|
||
StringBuilder sQuery = new StringBuilder("SELECT co FROM Conferencia co ")
|
||
.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 ");
|
||
}
|
||
|
||
Query qr = getSession().createQuery(sQuery.toString());
|
||
setParametros(qr, parametros);
|
||
qr.setParameter("dataInicial", datamovimento);
|
||
qr.setParameter("dataFinal", datamovimento);
|
||
|
||
List<ConferenciaComissaoVO> lsConferenciaComissao = new ArrayList<ConferenciaComissaoVO>();
|
||
processarQueryConferencia(qr.list(), lsConferenciaComissao, competencia);
|
||
|
||
if (!lsConferenciaComissao.isEmpty()) {
|
||
for (DiaConferenciaComissaoVO diaConferenciaComissao : lsConferenciaComissao
|
||
.iterator().next().getDiasOrdenado()) {
|
||
if (diaConferenciaComissao.getData().equals(datamovimento)) {
|
||
return diaConferenciaComissao;
|
||
}
|
||
}
|
||
}
|
||
|
||
return null;
|
||
}
|
||
catch (Exception e) {
|
||
log.error(e.getMessage(), e);
|
||
throw new BusinessException(e.getMessage(), e);
|
||
}
|
||
}
|
||
}
|