valdevir 2019-02-13 20:14:55 +00:00
parent 2898b19aca
commit 8508f782ef
2 changed files with 312 additions and 203 deletions

View File

@ -18,99 +18,116 @@ import com.rjconsultores.integracaoreceitadespesa.entidades.DespesaReceita;
import com.rjconsultores.integracaoreceitadespesa.entidades.Empresa;
import com.rjconsultores.integracaoreceitadespesa.entidades.PuntoVenta;
public class Totalbus {
private static final Logger log = Logger.getLogger(Totalbus.class);
private static final int DAYS_AGO = -1;
private Connection conn;
private List<PuntoVenta> pontosVenda = new ArrayList<PuntoVenta>();
private List<Empresa> empresas = new ArrayList<Empresa>();
private DecimalFormat df = new DecimalFormat("#0.00");
public Totalbus(Connection con){
public Totalbus(Connection con) {
this.conn = con;
loadEmpresas();
loadPuntosVenta();
}
public List<String> getDespesasReceitas(Integer puntoventaId, Integer empresaId,Date fechaParam, boolean incluiTipoPagamentoTurismoBGM){
public List<String> getDespesasReceitas(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) {
log.debug("gerando depósitos...");
List<DespesaReceita> despesasReceitas = getDepositos(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM);
log.debug("gerando despesas...");
despesasReceitas.addAll(getDespesas(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM));
log.debug("gerando despesas cartão...");
despesasReceitas.addAll(getDespesaCartaoDebCred(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM));
log.debug("gerando receitas...");
despesasReceitas.addAll(getReceitas(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM));
List<String> rows = new ArrayList<String>();
for (DespesaReceita item : despesasReceitas){
item.preencheLinha(rows);
}
return rows;
despesasReceitas.addAll(getDespesas(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM));
log.debug("gerando despesas cartão...");
despesasReceitas.addAll(getDespesaCartaoDebCred(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM));
log.debug("gerando receitas...");
despesasReceitas.addAll(getReceitas(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM));
List<String> rows = new ArrayList<String>();
for (DespesaReceita item : despesasReceitas) {
item.preencheLinha(rows);
}
return rows;
}
private void loadPuntosVenta(){
private void loadPuntosVenta() {
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
pstmt = getConnection().prepareStatement("Select puntoventa_id, nombpuntoventa from punto_venta order by nombpuntoventa");
try {
pstmt = getConnection().prepareStatement("Select puntoventa_id, nombpuntoventa from punto_venta order by nombpuntoventa");
rs = pstmt.executeQuery();
while (rs.next()){
while (rs.next()) {
PuntoVenta puntoVenta = new PuntoVenta();
puntoVenta.codigo = rs.getInt(1);
puntoVenta.nombpuntoventa = rs.getString(2);
pontosVenda.add(puntoVenta);
}
} catch (Exception e){
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
try { rs.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try { pstmt.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try {
rs.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
try {
pstmt.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
}
}
private void loadEmpresas(){
private void loadEmpresas() {
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
pstmt = getConnection().prepareStatement("Select empresa_id, nombempresa from empresa order by nombempresa");
try {
pstmt = getConnection().prepareStatement("Select empresa_id, nombempresa from empresa order by nombempresa");
rs = pstmt.executeQuery();
while (rs.next()){
while (rs.next()) {
Empresa empresa = new Empresa();
empresa.codigo = rs.getInt(1);
empresa.nombempresa = rs.getString(2);
empresas.add(empresa);
}
} catch (Exception e){
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
try { rs.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try { pstmt.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try {
rs.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
try {
pstmt.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
}
}
public Connection getConnection(){
public Connection getConnection() {
return this.conn;
}
public List<DespesaReceita> getDespesaCartaoDebCred(final Integer puntoVentaId, final Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) {
List<DespesaReceita> despesas = new ArrayList<DespesaReceita>();
StringBuilder sb = new StringBuilder();
sb.append(" select ");
sb.append(" select ");
sb.append(" cd.feccorte AS fechorvta, ");
sb.append(" e.empresa_id AS empresa, ");
sb.append(" pv.puntoventa_id AS puntoventaId, ");
sb.append(" sum(cdp.importe) AS valor, ");
sb.append(" case when cdp.formapago_id = 2 then 802 else 803 end as contacontabil, ");
sb.append(" pv.numpuntoventa AS numpuntoventa, ev.tipoeventoextra_id ");
sb.append(" pv.numpuntoventa AS numpuntoventa, ");
sb.append(" ev.tipoeventoextra_id, ");
sb.append(" cdp.formapago_id as formapagoId ");
sb.append(" from ");
sb.append(" caja_diversos cd ");
sb.append(" left join evento_extra ev on ev.eventoextra_id = cd.eventoextra_id ");
@ -130,30 +147,30 @@ public class Totalbus {
sb.append(" e.empresa_id, ");
sb.append(" pv.puntoventa_id, ");
sb.append(" case when cdp.formapago_id = 2 then 802 else 803 end, ");
sb.append(" pv.numpuntoventa, ev.tipoeventoextra_id ");
sb.append(" pv.numpuntoventa, ev.tipoeventoextra_id, ");
sb.append(" cdp.formapago_id ");
PreparedStatement stmt = null;
ResultSet rs = null;
Date fecha = fechaParam;
if(fechaParam== null){
if (fechaParam == null) {
fecha = getData();
}
try{
try {
stmt = getConnection().prepareStatement(sb.toString());
stmt.setDate(1, new java.sql.Date(fecha.getTime()));
stmt.setDate(1, new java.sql.Date(fecha.getTime()));
rs = stmt.executeQuery();
while (rs.next()){
while (rs.next()) {
DespesaReceita despesa = new DespesaReceita();
despesa.setCodigoEmpresa(rs.getInt(2));
despesa.setCodigoReceitaDespesa(rs.getString(5));
despesa.setDataLancamento(rs.getDate(1));
despesa.setDataMovimento(rs.getDate(1));
despesa.setLocalArrecadacao(rs.getString(6));
if (rs.getBigDecimal(4).signum() == -1){
despesa.setLocalArrecadacao(rs.getString(6));
if (rs.getBigDecimal(4).signum() == -1) {
despesa.setIdentificadorReceitaDespesa("R");
despesa.setValorLancamento(df.format(rs.getBigDecimal(4).multiply(new BigDecimal(-1))));
} else {
@ -163,13 +180,22 @@ public class Totalbus {
if (incluiTipoPagamentoTurismoBGM) {
despesa.setTipoPagamentoTurismo(rs.getString("tipoeventoextra_id"));
}
despesa.setFormaPagamentoId(rs.getString("formapagoId"));
despesas.add(despesa);
}
} catch (Exception e){
log.error(e.toString(),e);
} catch (Exception e) {
log.error(e.toString(), e);
} finally {
try { rs.close(); } catch (Exception ignore) { log.error("", ignore); }
try { stmt.close(); } catch (Exception ignore) { log.error("", ignore); }
try {
rs.close();
} catch (Exception ignore) {
log.error("", ignore);
}
try {
stmt.close();
} catch (Exception ignore) {
log.error("", ignore);
}
}
return despesas;
}
@ -179,7 +205,7 @@ public class Totalbus {
sb.append(filtroSQL + valor);
}
}
public List<DespesaReceita> getReceitas(final Integer puntoVentaId, final Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) {
List<DespesaReceita> despesas = new ArrayList<DespesaReceita>();
StringBuilder sb = new StringBuilder();
@ -190,7 +216,9 @@ public class Totalbus {
sb.append(" sum(cdp.importe) AS valor, ");
sb.append(" tee.contacontabil AS contacontabil, ");
sb.append(" pv.numpuntoventa AS numpuntoventa, ");
sb.append(" ev.descinfo as descinfo, ev.tipoeventoextra_id ");
sb.append(" ev.descinfo as descinfo, ");
sb.append(" ev.tipoeventoextra_id, ");
sb.append(" cdp.formapago_id as formapagoId ");
sb.append(" from ");
sb.append(" caja_diversos cd ");
sb.append(" left join evento_extra ev on ev.eventoextra_id = cd.eventoextra_id ");
@ -208,62 +236,74 @@ public class Totalbus {
sb.append(" group by cd.feccorte, ");
sb.append(" e.empresa_id, pv.puntoventa_id, ");
sb.append(" tee.contacontabil, pv.numpuntoventa, ");
sb.append(" ev.descinfo, ev.tipoeventoextra_id ");
sb.append(" ev.descinfo, ev.tipoeventoextra_id, ");
sb.append(" cdp.formapago_id ");
PreparedStatement stmt = null;
ResultSet rs = null;
Date fecha = fechaParam;
if(fechaParam== null){
if (fechaParam == null) {
fecha = getData();
}
try{
try {
stmt = getConnection().prepareStatement(sb.toString());
stmt.setDate(1, new java.sql.Date(fecha.getTime()));
stmt.setDate(1, new java.sql.Date(fecha.getTime()));
rs = stmt.executeQuery();
while (rs.next()){
while (rs.next()) {
DespesaReceita receita = new DespesaReceita();
receita.setCodigoEmpresa(rs.getInt(2));
receita.setCodigoReceitaDespesa(rs.getString(5));
receita.setDataLancamento(rs.getDate(1));
receita.setDataMovimento(rs.getDate(1));
receita.setLocalArrecadacao(rs.getString(6));
if (rs.getBigDecimal(4).signum() == -1){
if (rs.getBigDecimal(4).signum() == -1) {
receita.setIdentificadorReceitaDespesa("D");
receita.setValorLancamento(df.format(rs.getBigDecimal(4).multiply(new BigDecimal(-1))));
} else {
receita.setIdentificadorReceitaDespesa("R");
receita.setValorLancamento(df.format(rs.getBigDecimal(4)));
}
}
receita.setDescricaoDetalhada(rs.getString(7));
if (incluiTipoPagamentoTurismoBGM) {
receita.setTipoPagamentoTurismo(rs.getString("tipoeventoextra_id"));
}
receita.setFormaPagamentoId(rs.getString("formapagoId"));
despesas.add(receita);
}
} catch (Exception e){
log.error(e.getMessage(),e);
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
try { rs.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try { stmt.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try {
rs.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
try {
stmt.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
}
return despesas;
}
public List<DespesaReceita> getDespesas(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM){
public List<DespesaReceita> getDespesas(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) {
List<DespesaReceita> despesas = new ArrayList<DespesaReceita>();
StringBuilder sb = new StringBuilder();
sb.append(" select ");
sb.append(" cd.feccorte as feccorte, ");
sb.append(" e.empresa_id as empresa_id, ");
sb.append(" pv.numpuntoventa as numpuntoventa, ");
sb.append(" cdp.importe as valor, ");
sb.append(" tee.contacontabil as contacontabil, ");
sb.append(" ev.descinfo as descinfo, ev.tipoeventoextra_id ");
sb.append(" from ");
sb.append(" caja_diversos cd ");
sb.append(" cd.feccorte as feccorte, ");
sb.append(" e.empresa_id as empresa_id, ");
sb.append(" pv.numpuntoventa as numpuntoventa, ");
sb.append(" cdp.importe as valor, ");
sb.append(" tee.contacontabil as contacontabil, ");
sb.append(" ev.descinfo as descinfo, ");
sb.append(" ev.tipoeventoextra_id, ");
sb.append(" cdp.formapago_id as formapagoId ");
sb.append(" from ");
sb.append(" caja_diversos cd ");
sb.append(" left join evento_extra ev on ev.eventoextra_id = cd.eventoextra_id ");
sb.append(" left join empresa e on e.empresa_id = ev.empresa_id ");
sb.append(" left join punto_venta pv on pv.puntoventa_id = cd.puntoventa_id ");
@ -278,21 +318,21 @@ public class Totalbus {
sb.append(" and cd.activo = 1 ");
sb.append(" and not exists (select ee.EVENTOEXTRA_ID from evento_extra ee where ev.EVENTOEXTRA_ID = ee.EVENTOEXTRACANC_ID) ");
sb.append(" and ev.EVENTOEXTRACANC_ID is null ");
Date fecha = fechaParam;
if(fechaParam== null){
if (fechaParam == null) {
fecha = getData();
}
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
try {
pstmt = getConnection().prepareStatement(sb.toString());
pstmt.setDate(1, new java.sql.Date(fecha.getTime()));
pstmt.setDate(1, new java.sql.Date(fecha.getTime()));
rs = pstmt.executeQuery();
while (rs.next()){
while (rs.next()) {
DespesaReceita despesa = new DespesaReceita();
despesa.setCodigoEmpresa(rs.getInt(2));
despesa.setCodigoReceitaDespesa(rs.getString(5));
@ -305,65 +345,84 @@ public class Totalbus {
if (incluiTipoPagamentoTurismoBGM) {
despesa.setTipoPagamentoTurismo(rs.getString("tipoeventoextra_id"));
}
despesa.setFormaPagamentoId(rs.getString("formapagoId"));
despesas.add(despesa);
}
} catch (Exception e){
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
try { rs.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try { pstmt.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try {
rs.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
try {
pstmt.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
}
return despesas;
}
public List<DespesaReceita> getDepositos(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM){
public List<DespesaReceita> getDepositos(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) {
List<DespesaReceita> depositos = new ArrayList<DespesaReceita>();
StringBuilder strFechamentos = new StringBuilder();
strFechamentos.append("Select distinct sum(fd.valor_pago), fdep.numdeposito, fdep.fecha_deposito, fc.empresa_id, ");
strFechamentos.append(" pv.numpuntoventa, ec.numagencia, ec.numconta, if.CODIGO, ec.numintegracion, fdep.feccreacion ");
strFechamentos.append(" from fechamento_deposito fdep ");
strFechamentos.append(" join fechamento_cct_deposito fd on fd.fechamentodeposito_id = fdep.fechamentodeposito_id ");
strFechamentos.append(" join fechamento_cntcorrente fc on fc.fechamentocntcorrente_id = fd.fechamentocntcorrente_id ");
strFechamentos.append(" inner join PUNTO_VENTA pv on PV.PUNTOVENTA_ID = FC.PUNTOVENTA_ID ");
strFechamentos.append(" join empresa_contabancaria ec on ec.EMPRESACONTABANCARIA_ID = fdep.EMPRESACONTABANCARIA_ID ");
strFechamentos.append(" join INSTI_FINANCEIRA if on if.INSTIFINANCEIRA_ID = EC.INSTIFINANCEIRA_ID ");
strFechamentos.append(" join EMPRESA e on e.empresa_id = fc.empresa_id ");
strFechamentos.append(" join fechamento_cct_deposito fd on fd.fechamentodeposito_id = fdep.fechamentodeposito_id ");
strFechamentos.append(" join fechamento_cntcorrente fc on fc.fechamentocntcorrente_id = fd.fechamentocntcorrente_id ");
strFechamentos.append(" inner join PUNTO_VENTA pv on PV.PUNTOVENTA_ID = FC.PUNTOVENTA_ID ");
strFechamentos.append(" join empresa_contabancaria ec on ec.EMPRESACONTABANCARIA_ID = fdep.EMPRESACONTABANCARIA_ID ");
strFechamentos.append(" join INSTI_FINANCEIRA if on if.INSTIFINANCEIRA_ID = EC.INSTIFINANCEIRA_ID ");
strFechamentos.append(" join EMPRESA e on e.empresa_id = fc.empresa_id ");
strFechamentos.append(" where trunc(fdep.feccreacion) = :fecha and fd.activo = 1 and fc.activo = 1 and fdep.activo = 1 ");
adicionaFiltroQuery(puntoventaId, strFechamentos, " and fc.puntoventa_id = ", puntoventaId != null && !puntoventaId.equals(-1));
adicionaFiltroQuery(empresaId, strFechamentos, " and fc.empresa_id = ", empresaId != null);
strFechamentos.append(" group by fdep.numdeposito, fdep.feccreacion, fdep.fecha_deposito, fc.empresa_id, pv.numpuntoventa, ec.numagencia, ec.numconta, if.CODIGO, ec.numintegracion ");
Date fecha = fechaParam;
if(fechaParam == null){
if (fechaParam == null) {
fecha = getData();
}
PreparedStatement pstmtFechamentos = null;
ResultSet rsFechamentos = null;
BigDecimal soma = BigDecimal.ZERO;
try{
try {
pstmtFechamentos = getConnection().prepareStatement(strFechamentos.toString());
pstmtFechamentos.setDate(1, new java.sql.Date(fecha.getTime()));
rsFechamentos = pstmtFechamentos.executeQuery();
while (rsFechamentos.next()){
while (rsFechamentos.next()) {
Integer empId = null;
String banco = "" ;
String banco = "";
String agencia = "";
String contaCorrente = "";
String numDep = " Dep: " + rsFechamentos.getString(2);
String codRecDesp = null;
String numpuntoventa = rsFechamentos.getString(5);
if (empId == null ){ empId = rsFechamentos.getInt(4); }
if (banco.isEmpty()){banco = "Bco: " + StringUtils.leftPad(rsFechamentos.getString(8), 3, "0");}
if (agencia.isEmpty()){ agencia = " Ag: " + rsFechamentos.getString(6); }
if (contaCorrente.isEmpty()){ contaCorrente = " C/C: " + rsFechamentos.getString(7); }
if (codRecDesp == null){ codRecDesp = rsFechamentos.getString(9); }
if (empId == null) {
empId = rsFechamentos.getInt(4);
}
if (banco.isEmpty()) {
banco = "Bco: " + StringUtils.leftPad(rsFechamentos.getString(8), 3, "0");
}
if (agencia.isEmpty()) {
agencia = " Ag: " + rsFechamentos.getString(6);
}
if (contaCorrente.isEmpty()) {
contaCorrente = " C/C: " + rsFechamentos.getString(7);
}
if (codRecDesp == null) {
codRecDesp = rsFechamentos.getString(9);
}
DespesaReceita deposito = new DespesaReceita();
deposito.setCodigoEmpresa(empId);
deposito.setDataLancamento(rsFechamentos.getDate(10));
@ -373,101 +432,127 @@ public class Totalbus {
deposito.setIdentificadorReceitaDespesa("D");
deposito.setCodigoReceitaDespesa(codRecDesp);
deposito.setDescricaoDetalhada(banco + agencia + contaCorrente + numDep);
depositos.add(deposito);
soma = soma.add(rsFechamentos.getBigDecimal(1));
}
log.debug("Total depósitos: " + soma);
} catch (Exception e){
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
try { pstmtFechamentos.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try { rsFechamentos.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try {
pstmtFechamentos.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
try {
rsFechamentos.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
}
return depositos;
}
public Integer getCodigoReceitaDespesaGlobus(){
public Integer getCodigoReceitaDespesaGlobus() {
StringBuilder sb = new StringBuilder();
sb.append("Select valorconstante from constante where nombconstante = 'CODIGO_RECEITA_DESPESA_GLOBUS' ");
PreparedStatement pstmt = null;
ResultSet rs = null;
Integer result = null;
try{
try {
pstmt = getConnection().prepareStatement(sb.toString());
rs = pstmt.executeQuery();
if (rs.next()){
if (rs.next()) {
result = rs.getInt(1);
}
} catch (Exception e){
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
try { rs.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try { pstmt.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try {
rs.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
try {
pstmt.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
}
return result;
}
public Boolean isConstanteBloqueioMenorQueData(Integer empresaId, Date data){
public Boolean isConstanteBloqueioMenorQueData(Integer empresaId, Date data) {
StringBuilder sb = new StringBuilder();
sb.append("Select valorconstante from constante where nombconstante = 'DATA_LIMITE_EDICAO_DEPOSITO_" + empresaId + "'");
PreparedStatement pstmt = null;
ResultSet rs = null;
Boolean result = null;
try{
try {
pstmt = getConnection().prepareStatement(sb.toString());
rs = pstmt.executeQuery();
if (rs.next()){
if (rs.next()) {
Date rsDate = new SimpleDateFormat("dd/MM/yyyy").parse(rs.getString(1));
result = !rsDate.after(data);
} else { // se não existir a constante, retorno true para que ela seja criada na função updateDataBloqueio
result = true;
}
} catch (Exception e){
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
try { rs.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try { pstmt.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try {
rs.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
try {
pstmt.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
}
return result;
}
public void updateDataBloqueio(Integer empresaId, Date data){
public void updateDataBloqueio(Integer empresaId, Date data) {
StringBuilder sb = new StringBuilder();
PreparedStatement pstmt = null;
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
try{
if (!getConnection().
prepareStatement("Select valorconstante from constante where nombconstante = 'DATA_LIMITE_EDICAO_DEPOSITO_" + empresaId + "'").
executeQuery().next()){
sb.append("insert into constante values (constante_seq.nextval, 'DATA_LIMITE_EDICAO_DEPOSITO_" + empresaId + "', 'DATA_LIMITE_EDICAO_DEPOSITO_" + empresaId + "',1,"+
try {
if (!getConnection().prepareStatement("Select valorconstante from constante where nombconstante = 'DATA_LIMITE_EDICAO_DEPOSITO_" + empresaId + "'").executeQuery().next()) {
sb.append("insert into constante values (constante_seq.nextval, 'DATA_LIMITE_EDICAO_DEPOSITO_" + empresaId + "', 'DATA_LIMITE_EDICAO_DEPOSITO_" + empresaId + "',1," +
"'" + sdf.format(data) + "', 1, 1, :datamodif, 1)");
pstmt = getConnection().prepareStatement(sb.toString());
pstmt = getConnection().prepareStatement(sb.toString());
pstmt.setDate(1, new java.sql.Date(new Date().getTime()));
} else {
sb.append("update constante set valorconstante = :valor where nombconstante = 'DATA_LIMITE_EDICAO_DEPOSITO_" + empresaId + "'");
pstmt = getConnection().prepareStatement(sb.toString());
pstmt.setString(1, sdf.format(data));
}
}
pstmt.executeUpdate();
} catch (Exception e){
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
try { pstmt.close(); } catch (Exception ignore) { log.error(ignore.getMessage(), ignore); }
try {
pstmt.close();
} catch (Exception ignore) {
log.error(ignore.getMessage(), ignore);
}
}
}
private Date getData(){
private Date getData() {
Calendar cal = Calendar.getInstance();
cal.set(2015, 10, 13);
cal.setTime(new Date());
cal.add(Calendar.DAY_OF_MONTH, DAYS_AGO);
return cal.getTime();
cal.setTime(new Date());
cal.add(Calendar.DAY_OF_MONTH, DAYS_AGO);
return cal.getTime();
}
public List<PuntoVenta> getPontosVenda() {
return pontosVenda;
}
@ -482,5 +567,5 @@ public class Totalbus {
public void setEmpresas(List<Empresa> empresas) {
this.empresas = empresas;
}
}
}

View File

@ -8,44 +8,60 @@ import org.apache.commons.lang.StringUtils;
public class DespesaReceita {
private String dataLancamento; // DD/MM/YYYY
private String codigoEmpresa; // 011 003 Numérico
private final String codigoFilial = "001"; // 014 003 Numérico
private String localArrecadação; // 017 005 Alfanumérico
private final String numeroDaGuia = " "; // 022 025 Alfanumérico
private String dataMovimento; // 047 010 Alfanumérico
private final String usuarioGlobus = "TOTALBUS ";// 057 015 Alfanumérico
private final String turno = "01";// 072 002 Numérico
private String codigoReceitaDespesa;// 074 010 Numérico CONSTANTE CODIGO_RECEITA_DESPESA_GLOBUS
private String identificadorReceitaDespesa;// 084 001 Alfanumérico
private String valorLancamento;// 085 013 Numérico
private final String numeroContratoTurismo = "0000000000";// 098 010 Numérico
private final String numeroReciboTurismo = " ";// 108 010 Alfanumérico
private final String formaPagamentoTurismo = "00";// 118 002 Numérico
private String tipoPagamentoTurismo = "00";// 120 002 Numérico
private String descricaoDetalhada = " ";// 122 100 Alfanumérico
private final String documentoVenda = "000000";// 222 6 Numérico
private final String tipoDocumentoVenda = " ";// 228 1 Alfanumérico
private final String numerodocumentoCPG = "0000000000";// 229 10 Numérico
private final String finalLinha = "*";// 239 1 Alfanumérico
private String codigoEmpresa; // 011 003 Numérico
private final String codigoFilial = "001"; // 014 003 Numérico
private String localArrecadação; // 017 005 Alfanumérico
private final String numeroDaGuia = " "; // 022 025 Alfanumérico
private String dataMovimento; // 047 010 Alfanumérico
private final String usuarioGlobus = "TOTALBUS ";// 057 015 Alfanumérico
private final String turno = "01";// 072 002 Numérico
private String codigoReceitaDespesa;// 074 010 Numérico CONSTANTE CODIGO_RECEITA_DESPESA_GLOBUS
private String identificadorReceitaDespesa;// 084 001 Alfanumérico
private String valorLancamento;// 085 013 Numérico
private final String numeroContratoTurismo = "0000000000";// 098 010 Numérico
private final String numeroReciboTurismo = " ";// 108 010 Alfanumérico
private final String formaPagamentoTurismo = "00";// 118 002 Numérico
private String tipoPagamentoTurismo = "00";// 120 002 Numérico
private String descricaoDetalhada = " ";// 122 100 Alfanumérico
private final String documentoVenda = "000000";// 222 6 Numérico
private final String tipoDocumentoVenda = " ";// 228 1 Alfanumérico
private final String numerodocumentoCPG = "0000000000";// 229 10 Numérico
private final String finalLinha = "*";// 239 1 Alfanumérico
private String formaPagamentoId = "";// 240 Numérico
private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
public DespesaReceita(){
public DespesaReceita() {
}
public void preencheLinha(List<String> rows){
rows.add(dataLancamento + codigoEmpresa + codigoFilial +
localArrecadação.toUpperCase() +
numeroDaGuia + dataMovimento + usuarioGlobus +
turno + codigoReceitaDespesa +
identificadorReceitaDespesa.toUpperCase() + valorLancamento +
numeroContratoTurismo + numeroReciboTurismo +
getFormaPagamentoTurismo() + getTipoPagamentoTurismo() +
descricaoDetalhada + documentoVenda + tipoDocumentoVenda +
numerodocumentoCPG + finalLinha + System.getProperty("line.separator"));
public void preencheLinha(List<String> rows) {
StringBuilder sb = new StringBuilder();
sb.append(dataLancamento);
sb.append(codigoEmpresa);
sb.append(codigoFilial);
sb.append(localArrecadação.toUpperCase());
sb.append(numeroDaGuia);
sb.append(dataMovimento);
sb.append(usuarioGlobus);
sb.append(turno);
sb.append(codigoReceitaDespesa);
sb.append(identificadorReceitaDespesa.toUpperCase());
sb.append(valorLancamento);
sb.append(numeroContratoTurismo);
sb.append(numeroReciboTurismo);
sb.append(getFormaPagamentoTurismo());
sb.append(getTipoPagamentoTurismo());
sb.append(descricaoDetalhada);
sb.append(documentoVenda);
sb.append(tipoDocumentoVenda);
sb.append(numerodocumentoCPG);
sb.append(formaPagamentoId);
sb.append(finalLinha);
sb.append(System.getProperty("line.separator"));
rows.add(sb.toString());
}
public void setDataLancamento(Date dataLancamento) {
this.dataLancamento = sdf.format(dataLancamento);
}
@ -57,19 +73,19 @@ public class DespesaReceita {
public void setLocalArrecadacao(Integer localArrecadacao) {
this.localArrecadação = StringUtils.rightPad(localArrecadacao.toString(), 5, " ");
}
public void setLocalArrecadacao(String localArrecadacao) {
this.localArrecadação = StringUtils.rightPad(localArrecadacao, 5, " ");
}
public void setDataMovimento(Date dataMovimento) {
public void setDataMovimento(Date dataMovimento) {
this.dataMovimento = sdf.format(dataMovimento);
}
public void setCodigoReceitaDespesa(String codigoReceitaDespesa) {
this.codigoReceitaDespesa = StringUtils.leftPad(codigoReceitaDespesa != null ? codigoReceitaDespesa : "0", 10, "0");
}
public void setIdentificadorReceitaDespesa(String identificadorReceitaDespesa) {
this.identificadorReceitaDespesa = identificadorReceitaDespesa.toUpperCase();
}
@ -78,10 +94,10 @@ public class DespesaReceita {
this.valorLancamento = StringUtils.leftPad(valorLancamento.replace(",", "").replace(".", ""), 13, "0");
}
public void setDescricaoDetalhada(String desc){
public void setDescricaoDetalhada(String desc) {
this.descricaoDetalhada = StringUtils.rightPad(desc != null ? truncStr(desc, 100) : "", 100, " ");
}
public String getFormaPagamentoTurismo() {
return formaPagamentoTurismo;
}
@ -94,11 +110,19 @@ public class DespesaReceita {
this.tipoPagamentoTurismo = StringUtils.leftPad(tipoPagamentoTurismo, 2, "0");
}
private String truncStr(String str, int size){
if (str.length() > size){
return str.substring(0, size -1);
}
public String getFormaPagamentoId() {
return formaPagamentoId;
}
public void setFormaPagamentoId(String formaPagamentoId) {
this.formaPagamentoId = formaPagamentoId;
}
private String truncStr(String str, int size) {
if (str.length() > size) {
return str.substring(0, size - 1);
}
return str;
}
}