fixes bug#AL-4761
parent
e66c945c7b
commit
40d14606ec
2
pom.xml
2
pom.xml
|
@ -4,7 +4,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>br.com.rjconsultores</groupId>
|
<groupId>br.com.rjconsultores</groupId>
|
||||||
<artifactId>ventaboletosadm</artifactId>
|
<artifactId>ventaboletosadm</artifactId>
|
||||||
<version>1.147.0</version>
|
<version>1.147.1</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -6,6 +6,7 @@ package com.rjconsultores.ventaboletos.relatorios.impl;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -34,6 +35,7 @@ public class RelatorioFormaPagamentoAgenciaNovo extends RelatorioDemandas {
|
||||||
|
|
||||||
StringBuilder sql = new StringBuilder();
|
StringBuilder sql = new StringBuilder();
|
||||||
sql.append(" SELECT " );
|
sql.append(" SELECT " );
|
||||||
|
sql.append(" c.caja_id AS cajaID, " );
|
||||||
sql.append(" c.fechorventa AS data, " );
|
sql.append(" c.fechorventa AS data, " );
|
||||||
sql.append(" c.numfoliosistema AS bilhete, " );
|
sql.append(" c.numfoliosistema AS bilhete, " );
|
||||||
sql.append(" bpe.NBP AS bpe, " );
|
sql.append(" bpe.NBP AS bpe, " );
|
||||||
|
@ -102,57 +104,95 @@ public class RelatorioFormaPagamentoAgenciaNovo extends RelatorioDemandas {
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultSet rset = stmt.executeQuery();
|
ResultSet rset = stmt.executeQuery();
|
||||||
|
String cajaID = StringUtils.EMPTY;
|
||||||
|
|
||||||
while (rset.next()) {
|
while (rset.next()) {
|
||||||
Map<String, Object> dataResult = new HashMap<String, Object>();
|
Map<String, Object> dataResult = new HashMap<>();
|
||||||
|
|
||||||
String motivoCancelamento = StringUtils.isNotBlank(rset.getString("motivo")) ? rset.getString("motivo") : StringUtils.EMPTY;
|
String motivoCancelamento = getValueOrEmpty(rset, "motivo");
|
||||||
String indStatus = StringUtils.isNotBlank(rset.getString("status")) ? rset.getString("status") : StringUtils.EMPTY;
|
String indStatus = getValueOrEmpty(rset, "status");
|
||||||
String bpe = StringUtils.isNotBlank(rset.getString("bpe")) ? rset.getString("bpe") : StringUtils.EMPTY;
|
String bpe = getValueOrEmpty(rset, "bpe");
|
||||||
|
|
||||||
Boolean isCancelamento = "1".equals(rset.getString("indcancelacion"));
|
Boolean isCancelamento = "1".equals(rset.getString("indcancelacion"));
|
||||||
BigDecimal tarifa = rset.getBigDecimal("tarifa");
|
String formaPagamento = getValueOrEmpty(rset, "forma_pagamento");
|
||||||
BigDecimal pedagio = rset.getBigDecimal("PEDAGIO");
|
String formaPagamentoOriginal = getValueOrEmpty(rset, "forma_pago_original");
|
||||||
BigDecimal seguro = rset.getBigDecimal("SEGURO");
|
Boolean isFormaPagamentoIguais = formaPagamento.equals(formaPagamentoOriginal);
|
||||||
BigDecimal seguroOPC = rset.getBigDecimal("seg_opcional");
|
|
||||||
BigDecimal taxa = rset.getBigDecimal("taxa");
|
|
||||||
BigDecimal valor = rset.getBigDecimal("valor");
|
|
||||||
String formaPagamento = StringUtils.isEmpty(rset.getString("forma_pagamento")) ? StringUtils.EMPTY : rset.getString("forma_pagamento");
|
|
||||||
String formaPagamentoOriginal = StringUtils.isEmpty(rset.getString("forma_pago_original")) ? StringUtils.EMPTY : rset.getString("forma_pago_original");
|
|
||||||
Boolean isFormaPagamentoIguais = formaPagamento.equals(formaPagamentoOriginal);
|
|
||||||
|
|
||||||
dataResult.put("DATA", rset.getDate("data"));
|
Boolean isCajaIDRepetido = cajaID.equals(rset.getString("cajaID"));
|
||||||
dataResult.put("BILHETE", rset.getString("bilhete"));
|
cajaID = isCajaIDRepetido ? cajaID : rset.getString("cajaID");
|
||||||
dataResult.put("ORIGEM", rset.getString("ORIGEM"));
|
|
||||||
dataResult.put("DESTINO", rset.getString("DESTINO"));
|
|
||||||
dataResult.put("AGENCIA", rset.getString("agencia"));
|
|
||||||
dataResult.put("NUMERO_BPE", bpe);
|
|
||||||
dataResult.put("STATUS", indStatus);
|
|
||||||
dataResult.put("MOTIVO_CANCELAMENTO", motivoCancelamento);
|
|
||||||
|
|
||||||
if(isCancelamento) {
|
BigDecimal tarifa = getBigDecimal(isCajaIDRepetido, rset, "tarifa");
|
||||||
dataResult.put("FORMA_PAGAMENTO", formaPagamentoOriginal);
|
BigDecimal pedagio = getBigDecimal(isCajaIDRepetido, rset, "PEDAGIO");
|
||||||
dataResult.put("TARIFA", tarifa.compareTo(BigDecimal.ZERO) == 0 ? tarifa : tarifa.negate());
|
BigDecimal seguro = getBigDecimal(isCajaIDRepetido, rset, "SEGURO");
|
||||||
dataResult.put("PEDAGIO", pedagio.compareTo(BigDecimal.ZERO) == 0 ? pedagio : pedagio.negate());
|
BigDecimal seguroOPC = getBigDecimal(isCajaIDRepetido, rset, "seg_opcional");
|
||||||
dataResult.put("SEGURO", seguro.compareTo(BigDecimal.ZERO) == 0 ? seguro : seguro.negate());
|
BigDecimal taxa = getBigDecimal(isCajaIDRepetido, rset, "taxa");
|
||||||
dataResult.put("SEG_OPCIONAL", seguroOPC.compareTo(BigDecimal.ZERO) == 0 ? seguroOPC : seguroOPC.negate());
|
BigDecimal valor = rset.getBigDecimal("valor");
|
||||||
dataResult.put("TAXA", taxa.compareTo(BigDecimal.ZERO) == 0 ? taxa : taxa.negate());
|
|
||||||
dataResult.put("VALOR", valor.compareTo(BigDecimal.ZERO) == 0 ? valor : valor.negate());
|
|
||||||
} else if (isFormaPagamentoIguais){
|
|
||||||
dataResult.put("FORMA_PAGAMENTO", formaPagamento);
|
|
||||||
dataResult.put("TARIFA", tarifa);
|
|
||||||
dataResult.put("PEDAGIO", pedagio);
|
|
||||||
dataResult.put("SEGURO", seguro);
|
|
||||||
dataResult.put("SEG_OPCIONAL", seguroOPC);
|
|
||||||
dataResult.put("TAXA", taxa);
|
|
||||||
dataResult.put("VALOR", valor);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.dados.add(dataResult);
|
popularData(dataResult, rset, bpe, indStatus, motivoCancelamento);
|
||||||
|
|
||||||
|
boolean isReplicado = processarTransacao(dataResult, isCancelamento, tarifa, pedagio, seguro, seguroOPC, taxa, valor, formaPagamento, formaPagamentoOriginal, isFormaPagamentoIguais);
|
||||||
|
|
||||||
|
if (!isReplicado) {
|
||||||
|
this.dados.add(dataResult);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.resultSet = rset;
|
this.resultSet = rset;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getValueOrEmpty(ResultSet rset, String columnName) throws SQLException {
|
||||||
|
return StringUtils.defaultString(rset.getString(columnName), StringUtils.EMPTY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BigDecimal getBigDecimal(Boolean isCajaIDRepetido, ResultSet rset, String columnName) throws SQLException {
|
||||||
|
return isCajaIDRepetido ? BigDecimal.ZERO : rset.getBigDecimal(columnName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void popularData(Map<String, Object> dataResult, ResultSet rset, String bpe, String indStatus, String motivoCancelamento) throws SQLException {
|
||||||
|
dataResult.put("DATA", rset.getDate("data"));
|
||||||
|
dataResult.put("BILHETE", rset.getString("bilhete"));
|
||||||
|
dataResult.put("ORIGEM", rset.getString("ORIGEM"));
|
||||||
|
dataResult.put("DESTINO", rset.getString("DESTINO"));
|
||||||
|
dataResult.put("AGENCIA", rset.getString("agencia"));
|
||||||
|
dataResult.put("NUMERO_BPE", bpe);
|
||||||
|
dataResult.put("STATUS", indStatus);
|
||||||
|
dataResult.put("MOTIVO_CANCELAMENTO", motivoCancelamento);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean processarTransacao(Map<String, Object> dataResult, Boolean isCancelamento, BigDecimal tarifa, BigDecimal pedagio, BigDecimal seguro, BigDecimal seguroOPC, BigDecimal taxa, BigDecimal valor, String formaPagamento, String formaPagamentoOriginal, Boolean isFormaPagamentoIguais) {
|
||||||
|
if (isCancelamento) {
|
||||||
|
transacaoNegativa(dataResult, tarifa, pedagio, seguro, seguroOPC, taxa, valor, formaPagamentoOriginal);
|
||||||
|
return false;
|
||||||
|
} else if (isFormaPagamentoIguais) {
|
||||||
|
transacaoNormal(dataResult, tarifa, pedagio, seguro, seguroOPC, taxa, valor, formaPagamento);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void transacaoNegativa(Map<String, Object> dataResult, BigDecimal tarifa, BigDecimal pedagio, BigDecimal seguro, BigDecimal seguroOPC, BigDecimal taxa, BigDecimal valor, String formaPagamentoOriginal) {
|
||||||
|
dataResult.put("FORMA_PAGAMENTO", formaPagamentoOriginal);
|
||||||
|
dataResult.put("TARIFA", tarifa.negate());
|
||||||
|
dataResult.put("PEDAGIO", pedagio.negate());
|
||||||
|
dataResult.put("SEGURO", seguro.negate());
|
||||||
|
dataResult.put("SEG_OPCIONAL", seguroOPC.negate());
|
||||||
|
dataResult.put("TAXA", taxa.negate());
|
||||||
|
dataResult.put("VALOR", valor.negate());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void transacaoNormal(Map<String, Object> dataResult, BigDecimal tarifa, BigDecimal pedagio, BigDecimal seguro, BigDecimal seguroOPC, BigDecimal taxa, BigDecimal valor, String formaPagamento) {
|
||||||
|
dataResult.put("FORMA_PAGAMENTO", formaPagamento);
|
||||||
|
dataResult.put("TARIFA", tarifa);
|
||||||
|
dataResult.put("PEDAGIO", pedagio);
|
||||||
|
dataResult.put("SEGURO", seguro);
|
||||||
|
dataResult.put("SEG_OPCIONAL", seguroOPC);
|
||||||
|
dataResult.put("TAXA", taxa);
|
||||||
|
dataResult.put("VALOR", valor);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue