diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioMovimentosAtraso.java b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioMovimentosAtraso.java new file mode 100644 index 000000000..043e6ad4c --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioMovimentosAtraso.java @@ -0,0 +1,236 @@ +package com.rjconsultores.ventaboletos.relatorios.impl; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +import com.rjconsultores.ventaboletos.relatorios.utilitarios.DataSource; +import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio; +import com.rjconsultores.ventaboletos.utilerias.DateUtil; +import com.rjconsultores.ventaboletos.vo.comissao.MovimentosAtrasoVO; +import com.rjconsultores.ventaboletos.vo.comissao.MovimentosAtrasoVO.SituacaoDiaMovimento; +import com.rjconsultores.ventaboletos.web.utilerias.NamedParameterStatement; + +import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; + +public class RelatorioMovimentosAtraso extends Relatorio { + + private static Logger log = Logger.getLogger(RelatorioMovimentosAtraso.class); + private Integer empresaId; + private Integer puntoventaId; + private Date dataInicial; + private Date dataFinal; + private String competencia; + + public RelatorioMovimentosAtraso(Map parametros, Connection conexao) throws Exception { + super(parametros, conexao); + + this.setCustomDataSource(new DataSource(this) { + @Override + public void initDados() throws Exception { + Connection conexao = this.relatorio.getConexao(); + definirFiltros(this.relatorio.getParametros()); + List lsDadosRelatorio = processarRelatorio(conexao); + setLsDadosRelatorio(lsDadosRelatorio); + } + }); + } + + private List processarRelatorio(Connection conexao) throws ParseException { + List lsDadosRelatorio = iniciarDados(conexao); + ResultSet rset = null; + NamedParameterStatement stmt = null; + try { + StringBuilder sQuery = new StringBuilder(); + sQuery.append("SELECT DISTINCT PV.PUNTOVENTA_ID, CO.DATAMOVIMENTO ") + .append("FROM CONFERENCIA CO ") + .append("JOIN PUNTO_VENTA PV ON PV.PUNTOVENTA_ID = CO.PUNTOVENTA_ID ") + .append("WHERE CO.ACTIVO = 1 ") + .append("AND CO.DATAMOVIMENTO BETWEEN :dataInicial AND :dataFinal ") + .append("AND CO.INDMALOTERECEBIDO = 1 "); + + if(empresaId != null) { + sQuery.append("AND CO.EMPRESA_ID = :empresaId "); + } + + if(puntoventaId != null) { + sQuery.append("AND CO.PUNTOVENTA_ID = :puntoventaId "); + } + + sQuery.append("ORDER BY PV.PUNTOVENTA_ID, CO.DATAMOVIMENTO"); + + log.info(sQuery.toString()); + + stmt = new NamedParameterStatement(conexao, sQuery.toString()); + if(empresaId != null) { + stmt.setInt("empresaId", empresaId); + } + + if(puntoventaId != null) { + stmt.setInt("puntoventaId", puntoventaId); + } + stmt.setDate("dataInicial", new java.sql.Date(dataInicial.getTime())); + stmt.setDate("dataFinal", new java.sql.Date(dataFinal.getTime())); + + rset = stmt.executeQuery(); + + while (rset.next()) { + MovimentosAtrasoVO movimentosAtraso = new MovimentosAtrasoVO(rset.getInt("PUNTOVENTA_ID"),DateUtil.normalizar(rset.getDate("DATAMOVIMENTO"))); + if(lsDadosRelatorio.contains(movimentosAtraso)) { + movimentosAtraso = lsDadosRelatorio.get(lsDadosRelatorio.indexOf(movimentosAtraso)); + movimentosAtraso.setSituacao(SituacaoDiaMovimento.ENTREGUE); + } + } + + Collections.sort(lsDadosRelatorio); + return lsDadosRelatorio; + } catch (Exception e) { + log.error(e.getMessage(), e); + } finally { + try { + if(rset != null) { + rset.close(); + } + if(stmt != null) { + stmt.close(); + } + } catch (SQLException e) { + log.error(e.getMessage(), e); + } + } + return null; + } + + private List iniciarDados(Connection conexao) { + ResultSet rset = null; + NamedParameterStatement stmt = null; + try { + List lsMovimentosAtrasoVOs = new ArrayList(); + + StringBuilder sQuery = new StringBuilder(); + sQuery.append("SELECT DISTINCT PV.PUNTOVENTA_ID, PV.NUMPUNTOVENTA, PV.NOMBPUNTOVENTA, NVL(FP.DIASEMTRANSITO,0) AS DIASEMTRANSITO ") + .append("FROM PUNTO_VENTA PV ") + .append("INNER JOIN PTOVTA_EMPRESA PTE ON PTE.PUNTOVENTA_ID = PV.PUNTOVENTA_ID ") + .append("LEFT JOIN FECHAMENTO_PARAMPTOVTA FP ON FP.EMPRESA_ID = PTE.EMPRESA_ID AND PV.PUNTOVENTA_ID = FP.PUNTOVENTA_ID AND FP.ACTIVO = 1 ") + .append("WHERE PV.ACTIVO = 1 "); + + if(empresaId != null) { + sQuery.append("AND PTE.EMPRESA_ID = :empresaId "); + } + + if(puntoventaId != null) { + sQuery.append("AND PV.PUNTOVENTA_ID = :puntoventaId "); + } + + sQuery.append("ORDER BY PV.NOMBPUNTOVENTA "); + + log.info(sQuery.toString()); + + stmt = new NamedParameterStatement(conexao, sQuery.toString()); + if(empresaId != null) { + stmt.setInt("empresaId", empresaId); + } + + if(puntoventaId != null) { + stmt.setInt("puntoventaId", puntoventaId); + } + + rset = stmt.executeQuery(); + while (rset.next()) { + MovimentosAtrasoVO movimentosAtrasoVO = new MovimentosAtrasoVO(); + movimentosAtrasoVO.setPuntoventaId(rset.getInt("PUNTOVENTA_ID")); + movimentosAtrasoVO.setNumPuntoVenta(rset.getString("NUMPUNTOVENTA")); + movimentosAtrasoVO.setNombpuntoventa(rset.getString("NOMBPUNTOVENTA")); + movimentosAtrasoVO.setCompetencia(competencia); + movimentosAtrasoVO.setDiasemtransito(rset.getInt("DIASEMTRANSITO")); + lsMovimentosAtrasoVOs.addAll(carregarDiasMovimento(movimentosAtrasoVO)); + } + + return lsMovimentosAtrasoVOs; + } catch (Exception e) { + log.error(e.getMessage(), e); + } finally { + try { + if(rset != null) { + rset.close(); + } + if(stmt != null) { + stmt.close(); + } + } catch (SQLException e) { + log.error(e.getMessage(), e); + } + } + return null; + } + + private List carregarDiasMovimento(MovimentosAtrasoVO movimentosAtrasoBase) throws ParseException { + Set diasCompetencia = DateUtil.carregarDiasCompetencia(movimentosAtrasoBase.getCompetencia()); + List lsMovimentos = new ArrayList(); + Date dataAtual = new Date(); + for (Integer dia : diasCompetencia) { + MovimentosAtrasoVO movimentosAtraso = new MovimentosAtrasoVO(movimentosAtrasoBase.getPuntoventaId(), movimentosAtrasoBase.getNombpuntoventa(), + movimentosAtrasoBase.getNumPuntoVenta(), movimentosAtrasoBase.getCompetencia(), + movimentosAtrasoBase.getDiasemtransito(), + DateUtil.getDateFromString(dia + "/" + movimentosAtrasoBase.getCompetencia(), "dd/MM/yyyy"), + SituacaoDiaMovimento.AGUARDANDO); + + if(movimentosAtraso.getDiasemtransito() != null && movimentosAtraso.getDiasemtransito() > 0) { + if(DateUtil.getElapsedDias(dataAtual, movimentosAtraso.getDataMovimento()) > movimentosAtraso.getDiasemtransito()) { + movimentosAtraso.setSituacao(SituacaoDiaMovimento.ATRASADO); + } + } + + lsMovimentos.add(movimentosAtraso); + } + return lsMovimentos; + } + + public void setLsDadosRelatorio(List lsDadosRelatorio) { + this.setCollectionDataSource(new JRBeanCollectionDataSource(lsDadosRelatorio)); + } + + @Override + protected void processaParametros() throws Exception { + } + + private void definirFiltros(Map parametros) throws ParseException { + Integer puntoventaId = (Integer) parametros.get("puntoventaId"); + Integer empresaId = (Integer) parametros.get("empresaId"); + String competencia = (String) parametros.get("competencia"); + + if(StringUtils.isNotBlank(competencia)) { + this.competencia = competencia; + } + + if(empresaId != null) { + this.empresaId = empresaId; + } + if(puntoventaId != null) { + this.puntoventaId = puntoventaId; + } + + 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])); + + this.dataInicial = DateUtil.getDateFromString(cal.getActualMinimum(Calendar.DAY_OF_MONTH) + "/" + competencia, "dd/MM/yyyy"); + this.dataFinal = DateUtil.getDateFromString(cal.getActualMaximum(Calendar.DAY_OF_MONTH) + "/" + competencia, "dd/MM/yyyy"); + } + + } + +} diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioMovimentosAtraso_es.properties b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioMovimentosAtraso_es.properties new file mode 100644 index 000000000..8c48ccc75 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioMovimentosAtraso_es.properties @@ -0,0 +1,19 @@ +#geral +msg.noData=Não foi possivel obter dados com os parâmetros informados. + +#Labels cabeçalho +cabecalho.nome=Relatório Movimentos em Atraso +cabecalho.relatorio=Relatório: +cabecalho.periodo=Período: +cabecalho.periodoA=à +cabecalho.dataHora=Data/Hora: +cabecalho.impressorPor=Impressor por: +cabecalho.pagina=Página +cabecalho.de=de +cabecalho.filtros=Filtros: +label.empresa=Empresa: +cabecalho.usuario=Usuário: +label.empresa=Empresa: +label.legenda=Legenda +label.puntoventa=Punto Venta: +label.competencia=Competencia: \ No newline at end of file diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioMovimentosAtraso_pt_BR.properties b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioMovimentosAtraso_pt_BR.properties new file mode 100644 index 000000000..bbc8831e0 --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/internacionalizacao/RelatorioMovimentosAtraso_pt_BR.properties @@ -0,0 +1,19 @@ +#geral +msg.noData=Não foi possivel obter dados com os parâmetros informados. + +#Labels cabeçalho +cabecalho.nome=Relatório Movimentos em Atraso +cabecalho.relatorio=Relatório: +cabecalho.periodo=Período: +cabecalho.periodoA=à +cabecalho.dataHora=Data/Hora: +cabecalho.impressorPor=Impressor por: +cabecalho.pagina=Página +cabecalho.de=de +cabecalho.filtros=Filtros: +label.empresa=Empresa: +cabecalho.usuario=Usuário: +label.empresa=Empresa: +label.legenda=Legenda +label.puntoventa=Ponto de Venda: +label.competencia=Competência: \ No newline at end of file diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioMovimentosAtraso.jasper b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioMovimentosAtraso.jasper new file mode 100644 index 000000000..f01b8d340 Binary files /dev/null and b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioMovimentosAtraso.jasper differ diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioMovimentosAtraso.jrxml b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioMovimentosAtraso.jrxml new file mode 100644 index 000000000..1f748717b --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioMovimentosAtraso.jrxml @@ -0,0 +1,247 @@ + + + + + +