diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioReceitaDiariaAgencia.java b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioReceitaDiariaAgencia.java index e29a993a9..ccf8dc8ea 100644 --- a/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioReceitaDiariaAgencia.java +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/impl/RelatorioReceitaDiariaAgencia.java @@ -37,15 +37,23 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { this.setCustomDataSource(new ArrayDataSource(this) { - protected HashMap> mapDados; + protected HashMap> mapDados; @Override public Object valueCustomFields(String fieldName) throws Exception { if (fieldName.equals("RECEITA_TOTAL")) { - return ((BigDecimal) this.getByName("RECEITA_TARIFA")).add((BigDecimal) this.getByName("RECEITA_SEGURO")).add((BigDecimal) this.getByName("RECEITA_BAGAGEM")).add((BigDecimal) this.getByName("RECEITA_EMBARQUE")).subtract((BigDecimal) this.getByName("TOTAL_DEVOL")); + BigDecimal gap = BigDecimal.ZERO; + if ((Boolean) this.relatorio.getParametros().get("B_CONTEMPLAR_GAP")) { + gap = ((BigDecimal) this.getByName("RECEITA_TARIFA_GAP")).add((BigDecimal) this.getByName("RECEITA_SEGURO_GAP")).add((BigDecimal) this.getByName("RECEITA_EMBARQUE_GAP")).subtract((BigDecimal) this.getByName("TOTAL_DEVOL_GAP")); + } + return ((BigDecimal) this.getByName("RECEITA_TARIFA")).add((BigDecimal) this.getByName("RECEITA_SEGURO")).add((BigDecimal) this.getByName("RECEITA_BAGAGEM")).add((BigDecimal) this.getByName("RECEITA_EMBARQUE")).subtract((BigDecimal) this.getByName("TOTAL_DEVOL")).add(gap); } else if (fieldName.equals("RECEITA_LIQUIDA")) { - return ((BigDecimal) this.getByName("RECEITA_TARIFA")).add((BigDecimal) this.getByName("RECEITA_SEGURO")).add((BigDecimal) this.getByName("RECEITA_BAGAGEM")).add((BigDecimal) this.getByName("RECEITA_EMBARQUE")).subtract((BigDecimal) this.getByName("TOTAL_DEVOL")).subtract((BigDecimal) this.getByName("IMPOSTOS")); + BigDecimal gap = BigDecimal.ZERO; + if ((Boolean) this.relatorio.getParametros().get("B_CONTEMPLAR_GAP")) + gap = ((BigDecimal) this.getByName("RECEITA_TARIFA_GAP")).add((BigDecimal) this.getByName("RECEITA_SEGURO_GAP")).add((BigDecimal) this.getByName("RECEITA_EMBARQUE_GAP")).subtract((BigDecimal) this.getByName("TOTAL_DEVOL_GAP")); + + return ((BigDecimal) this.getByName("RECEITA_TARIFA")).add((BigDecimal) this.getByName("RECEITA_SEGURO")).add((BigDecimal) this.getByName("RECEITA_BAGAGEM")).add((BigDecimal) this.getByName("RECEITA_EMBARQUE")).subtract((BigDecimal) this.getByName("TOTAL_DEVOL")).subtract((BigDecimal) this.getByName("IMPOSTOS")).add(gap); } else if (fieldName.equals("DIFERENCA_COMISSAO")) { return ((BigDecimal) this.getByName("VALOR_COMISSAO")).subtract((BigDecimal) this.getByName("ANTECIPACAO")); @@ -78,14 +86,12 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { for (Estado s : (ArrayList) parametros.get("ESTADO_ID")) { strEstadoList.append("," + s.getEstadoId() + ","); } - stmt.setString("ESTADO_ID", strEstadoList.toString()); stmt.setString("ISESTADOTODOS", "N"); } else { stmt.setNull("ESTADO_ID", java.sql.Types.INTEGER); stmt.setString("ISESTADOTODOS", "S"); - } if (parametros.get("EMPRESA_ID") != null) @@ -115,7 +121,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { // Verifica se existe agência de destino da comissão e atualiza a row se necessario if ((Integer) configComissao.get("PUNTOVENTA_ID") != 0 && !((Integer) configComissao.get("PUNTOVENTA_ID")).equals(this.resultSet.getInt("PUNTOVENTA_ID"))) - rowDestino = this.getRow((Integer) configComissao.get("PUNTOVENTA_ID"), null); + rowDestino = this.getRow((Integer) configComissao.get("PUNTOVENTA_ID"), (Integer) rowOrigem.get("EMPRESA_ID"), null); Integer puntoVentaId = (Integer) rowDestino.get("PUNTOVENTA_ID"); BigDecimal motivoCancelacionId = this.resultSet.getBigDecimal("MOTIVOCANCELACION_ID"); @@ -201,18 +207,20 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { rowDestino.put("NUMPUNTOVENTA", configComissao.get("NUMPUNTOVENTA")); rowDestino.put("NOMBPUNTOVENTA", configComissao.get("NOMBPUNTOVENTA")); rowDestino.put("EMPRESAPUNTOVENTA_ID", rowOrigem.get("EMPRESAPUNTOVENTA_ID")); + rowDestino.put("EMPRESA", rowOrigem.get("EMPRESA")); + rowDestino.put("EMPRESA_ID", rowOrigem.get("EMPRESA_ID")); rowDestino.put("ESTADO_ID", configComissao.get("ESTADO_ID")); rowDestino.put("TIPO_AGENCIA", configComissao.get("TIPO_AGENCIA")); - mapDados.put(puntoVentaId, (HashMap) rowDestino); + mapDados.put(puntoVentaId+"-"+rowOrigem.get("EMPRESA_ID"), (HashMap) rowDestino); } } - protected Map getRow(Integer puntoVentaId, ResultSet rs) throws SQLException { + protected Map getRow(Integer puntoVentaId, Integer empresaId, ResultSet rs) throws SQLException { Map row; - if (mapDados.containsKey(puntoVentaId)) { - row = mapDados.get(puntoVentaId); + if (mapDados.containsKey(puntoVentaId.toString()+"-"+empresaId.toString())) { + row = mapDados.get(puntoVentaId.toString()+"-"+empresaId.toString()); } else { @@ -243,6 +251,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { row.put("CVEESTADO", rs.getString("CVEESTADO")); row.put("NUMPUNTOVENTA", rs.getString("NUMPUNTOVENTA")); row.put("EMPRESA", rs.getString("NOMBEMPRESA")); + row.put("EMPRESA_ID", rs.getString("EMPRESA_ID")); row.put("NOMBPUNTOVENTA", rs.getString("NOMBPUNTOVENTA")); row.put("EMPRESAPUNTOVENTA_ID", rs.getInt("EMPRESAPUNTOVENTA_ID")); row.put("ESTADO_ID", rs.getBigDecimal("ESTADO_ID")); @@ -251,7 +260,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { // Como a receita de bagagem é obtida por agencia, já calcula o valor if (!(Boolean) this.relatorio.getParametros().get("B_EXCLUI_BAGAGEM")) { - BigDecimal receitaBagagem = getValorReceitaBagagem(puntoVentaId); + BigDecimal receitaBagagem = getValorReceitaBagagem(puntoVentaId, empresaId); try { row.put("IMPOSTOS", getValorImposto(rs.getInt("ORIGEM_ESTADO_ID"), puntoVentaId, rs.getString("INTERESTADUAL"), BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, receitaBagagem)); } catch (Exception e) { @@ -272,19 +281,20 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { public void initDados() throws Exception { this.prepareQuery(); - this.mapDados = new HashMap>(); + this.mapDados = new HashMap>(); while (this.resultSet.next()) { Integer puntoVentaId = this.resultSet.getInt("PUNTOVENTA_ID"); + Integer empresaId = this.resultSet.getInt("EMPRESA_ID"); Integer motivoCancelacionId = this.resultSet.getInt("MOTIVOCANCELACION_ID"); Integer tipoVentaId = this.resultSet.getInt("TIPOVENTA_ID"); Integer idEstado = this.resultSet.getInt("ORIGEM_ESTADO_ID"); // Inicializa a row atual - Map row = this.getRow(puntoVentaId, this.resultSet); + Map row = this.getRow(puntoVentaId,empresaId, this.resultSet); - this.mapDados.put((Integer) row.get("PUNTOVENTA_ID"), (HashMap) row); + this.mapDados.put(row.get("PUNTOVENTA_ID")+"-"+empresaId.toString(), (HashMap) row); row.put("TOTAL_BILHETES", ((BigDecimal) row.get("TOTAL_BILHETES")).add(motivoCancelacionId == 0 && !tipoVentaId.equals(18) ? BigDecimal.ONE : BigDecimal.ZERO)); row.put("TOTAL_BILHETES_GAP", ((BigDecimal) row.get("TOTAL_BILHETES_GAP")).add(motivoCancelacionId == 0 && tipoVentaId.equals(18) ? BigDecimal.ONE : BigDecimal.ZERO)); @@ -313,8 +323,8 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { else { // Verificia se a devolução é pra ser contabilizada na agência de destino ou de origem da venda if (((Integer) this.relatorio.getParametros().get("ISDEVOLUCAODESTINO") == 1) || (((Integer) this.relatorio.getParametros().get("ISDEVOLUCAODESTINO")).equals(0) && this.resultSet.getInt("POSSUI_CANC") == 1)) { - row.put("TOTAL_DEVOL", ((BigDecimal) row.get("TOTAL_DEVOL")).add( !tipoVentaId.equals(18) ? this.resultSet.getBigDecimal("PRECIOPAGADO") : BigDecimal.ZERO)); - row.put("TOTAL_DEVOL_GAP", ((BigDecimal) row.get("TOTAL_DEVOL_GAP")).add( tipoVentaId.equals(18) ? this.resultSet.getBigDecimal("PRECIOPAGADO") : BigDecimal.ZERO)); + row.put("TOTAL_DEVOL", ((BigDecimal) row.get("TOTAL_DEVOL")).add(!tipoVentaId.equals(18) ? this.resultSet.getBigDecimal("PRECIOPAGADO") : BigDecimal.ZERO)); + row.put("TOTAL_DEVOL_GAP", ((BigDecimal) row.get("TOTAL_DEVOL_GAP")).add(tipoVentaId.equals(18) ? this.resultSet.getBigDecimal("PRECIOPAGADO") : BigDecimal.ZERO)); } } @@ -469,7 +479,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { return BigDecimal.ZERO; } - public BigDecimal getValorReceitaBagagem(Integer puntoVentaId) throws SQLException { + public BigDecimal getValorReceitaBagagem(Integer puntoVentaId, Integer empresaId) throws SQLException { StringBuilder sql = new StringBuilder(); sql.append(" SELECT nvl(SUM(CASE "); sql.append(" WHEN EE.TIPOEVENTOEXTRA_ID = 1 AND EE.ACTIVO = 1 THEN "); @@ -479,9 +489,11 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { sql.append(" WHERE TRUNC(EE.FECHORINGRESO) BETWEEN :DATA_INICIO AND "); sql.append(" :DATA_FINAL "); sql.append(" AND EE.PUNTOVENTA_ID = :PUNTOVENTA_ID "); + sql.append(" AND EE.EMPRESA_ID = :EMPRESA_ID "); NamedParameterStatement stmt = new NamedParameterStatement(this.getConexao(), sql.toString()); stmt.setInt("PUNTOVENTA_ID", puntoVentaId); + stmt.setInt("EMPRESA_ID", empresaId); stmt.setDate("DATA_INICIO", (java.sql.Date) this.getParametros().get("DATA_INICIO")); stmt.setDate("DATA_FINAL", (java.sql.Date) this.getParametros().get("DATA_FINAL")); @@ -570,9 +582,11 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { sql.append(" AND CJD.PUNTOVENTA_ID = CJ.PUNTOVENTA_ID"); sql.append(" AND ROWNUM = 1) POSSUI_CANC, "); sql.append(" TP.CVEPTOVTA TIPO_AGENCIA, "); - sql.append(" EC.NOMBEMPRESA "); + sql.append(" EC.NOMBEMPRESA, "); + sql.append(" EC.EMPRESA_ID "); sql.append(" FROM CAJA CJ, "); sql.append(" PUNTO_VENTA PV, "); + sql.append(" MARCA MC, "); sql.append(" EMPRESA EM, "); sql.append(" EMPRESA EC, "); sql.append(" PARADA PR, "); @@ -589,7 +603,8 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { sql.append(" :DATA_FINAL "); sql.append(" AND PR.PARADA_ID = PV.PARADA_ID "); sql.append(" AND CJ.EMPRESAPUNTOVENTA_ID = EM.EMPRESA_ID "); - sql.append(" AND CJ.EMPRESACORRIDA_ID = EC.EMPRESA_ID "); + sql.append(" AND CJ.MARCA_ID = MC.MARCA_ID "); + sql.append(" AND MC.EMPRESA_ID = EC.EMPRESA_ID "); sql.append(" AND EM.CIUDAD_ID = CE.CIUDAD_ID "); sql.append(" AND CX.CIUDAD_ID = PR.CIUDAD_ID "); sql.append(" AND CX.ESTADO_ID = ES.ESTADO_ID "); @@ -601,13 +616,13 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio { sql.append(" AND CJ.INDREIMPRESION = 0 "); sql.append(" AND PV.TIPOPTOVTA_ID = NVL(:TIPOPTOVTA_ID, PV.TIPOPTOVTA_ID) "); sql.append(" AND TP.TIPOPTOVTA_ID = PV.TIPOPTOVTA_ID "); - sql.append(" AND CJ.EMPRESACORRIDA_ID = NVL(:EMPRESA_ID, CJ.EMPRESACORRIDA_ID) "); + sql.append(" AND EC.EMPRESA_ID = NVL(:EMPRESA_ID, EC.EMPRESA_ID) "); // sql.append(" AND ES.ESTADO_ID = NVL(:ESTADO_ID, ES.ESTADO_ID) "); sql.append(" AND ((INSTR(:NUMPUNTOVENTA, ',' || TRIM(PV.NUMPUNTOVENTA) || ',') > 0 AND "); sql.append(" :ISNUMPUNTOVENTATODOS = 'N') OR (:ISNUMPUNTOVENTATODOS = 'S')) "); sql.append(" AND ((INSTR(:ESTADO_ID, ',' || TRIM(ES.ESTADO_ID) || ',') > 0 AND "); sql.append(" :ISESTADOTODOS = 'N') OR (:ISESTADOTODOS = 'S')) "); - sql.append(" ORDER BY EC.NOMBEMPRESA "); + sql.append(" ORDER BY EC.NOMBEMPRESA, ES.CVEESTADO "); return sql.toString(); } diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioReceitaDiariaAgencia.jasper b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioReceitaDiariaAgencia.jasper index 80f45826f..441f74367 100644 Binary files a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioReceitaDiariaAgencia.jasper and b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioReceitaDiariaAgencia.jasper differ diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioReceitaDiariaAgencia.jrxml b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioReceitaDiariaAgencia.jrxml index 986d5b2b0..d4282395d 100644 --- a/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioReceitaDiariaAgencia.jrxml +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/templates/RelatorioReceitaDiariaAgencia.jrxml @@ -247,6 +247,7 @@ + diff --git a/src/java/versionADM.info b/src/java/versionADM.info index c152fede6..fa5dba29b 100644 --- a/src/java/versionADM.info +++ b/src/java/versionADM.info @@ -1 +1 @@ -ADM_20130910_1RC229 \ No newline at end of file +ADM_20130910_1RC230 \ No newline at end of file