From f8a460532f3770a19b4cc23709669e8064e459f7 Mon Sep 17 00:00:00 2001 From: fabiorj Date: Fri, 3 Dec 2021 20:06:39 -0300 Subject: [PATCH] Commit inicial --- .gitignore | 4 + pom.xml | 44 + src/META-INF/MANIFEST.MF | 3 + .../integracaoreceitadespesa/Application.java | 55 + .../integracaoreceitadespesa/Arquivo.java | 35 + .../BGMApplication.java | 267 ++++ .../IntegracaoReceitaDespesaException.java | 13 + .../dao/Totalbus.java | 1145 +++++++++++++++++ .../entidades/DespesaReceita.java | 155 +++ .../entidades/DespesaReceitaComporte.java | 66 + .../entidades/Empresa.java | 11 + .../entidades/PuntoVenta.java | 11 + 12 files changed, 1809 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/META-INF/MANIFEST.MF create mode 100644 src/com/rjconsultores/integracaoreceitadespesa/Application.java create mode 100644 src/com/rjconsultores/integracaoreceitadespesa/Arquivo.java create mode 100644 src/com/rjconsultores/integracaoreceitadespesa/BGMApplication.java create mode 100644 src/com/rjconsultores/integracaoreceitadespesa/IntegracaoReceitaDespesaException.java create mode 100644 src/com/rjconsultores/integracaoreceitadespesa/dao/Totalbus.java create mode 100644 src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceita.java create mode 100644 src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceitaComporte.java create mode 100644 src/com/rjconsultores/integracaoreceitadespesa/entidades/Empresa.java create mode 100644 src/com/rjconsultores/integracaoreceitadespesa/entidades/PuntoVenta.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..4e247eee2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.settings +/target +/.classpath +/.project diff --git a/pom.xml b/pom.xml new file mode 100644 index 000000000..766d63b1b --- /dev/null +++ b/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + br.com.rjconsultores + IntegracaoReceitaDespesa + 0.0.1-SNAPSHOT + + + + log4j + log4j + 1.2.16 + + + commons-lang + commons-lang + 2.0 + + + + + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.3 + + 1.6 + 1.6 + Cp1252 + + + + + \ No newline at end of file diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 000000000..254272e1c --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/src/com/rjconsultores/integracaoreceitadespesa/Application.java b/src/com/rjconsultores/integracaoreceitadespesa/Application.java new file mode 100644 index 000000000..875ee650e --- /dev/null +++ b/src/com/rjconsultores/integracaoreceitadespesa/Application.java @@ -0,0 +1,55 @@ +package com.rjconsultores.integracaoreceitadespesa; + +import java.io.FileInputStream; +import java.io.IOException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.util.Properties; + +import org.apache.log4j.Logger; + +public class Application { + private static Application instance = null; + + private static final Logger log = Logger.getLogger(Application.class); + + private Application(){ + + } + + public Connection getConnection(){ + try { + Properties props = Application.getInstance().getApplicationProperties(); + + String DRIVER = "oracle.jdbc.driver.OracleDriver"; + + Class.forName(DRIVER); + Connection conn = DriverManager.getConnection( + props.getProperty("url"), + props.getProperty("username").trim(), + props.getProperty("password").trim()); + + return conn; + + } catch (Exception e){ + log.error("", e); + return null; + } + } + public static Application getInstance(){ + if (instance == null){ + instance = new Application(); + } + return instance; + } + + public Properties getApplicationProperties(){ + Properties props = new Properties(); + try { + props.load(new FileInputStream("db.properties")); + } catch (IOException e) { + log.error("", e); + } + return props; + } +} diff --git a/src/com/rjconsultores/integracaoreceitadespesa/Arquivo.java b/src/com/rjconsultores/integracaoreceitadespesa/Arquivo.java new file mode 100644 index 000000000..c7c8712a2 --- /dev/null +++ b/src/com/rjconsultores/integracaoreceitadespesa/Arquivo.java @@ -0,0 +1,35 @@ +package com.rjconsultores.integracaoreceitadespesa; + +import java.io.Closeable; +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; + +import org.apache.log4j.Logger; + +public class Arquivo { + private static final Logger log = Logger.getLogger(Arquivo.class); + + public static void GravaArquivo(String filename, List rows){ + try{ + log.debug("gravando arquivo" + filename + "..."); + FileWriter writer = new FileWriter(filename); + for(String str: rows) { + writer.write(str); + } + writer.close(); + } catch (Exception e){ + log.error("", e); + } + } + + public static void close(Closeable c) { + if (c == null) return; + try { + c.close(); + } catch (IOException e) { + log.error(e); + } + } + +} diff --git a/src/com/rjconsultores/integracaoreceitadespesa/BGMApplication.java b/src/com/rjconsultores/integracaoreceitadespesa/BGMApplication.java new file mode 100644 index 000000000..41b3eec14 --- /dev/null +++ b/src/com/rjconsultores/integracaoreceitadespesa/BGMApplication.java @@ -0,0 +1,267 @@ +package com.rjconsultores.integracaoreceitadespesa; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.FileChannel; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Properties; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +import com.rjconsultores.integracaoreceitadespesa.dao.Totalbus; + +public class BGMApplication { + private static BGMApplication instance = null; + + private static final Logger log = Logger.getLogger(BGMApplication.class); + + private static final int TAMANHO_BUFFER = 4096; // 4kb + + private boolean isReceitasDespesasComporte; + + private boolean isCodReceitaFixoBgm; + + private boolean isReceitasDespesasOuroPrata; + + private BGMApplication(){ + + } + + public Connection getConnection(){ + try { + Properties props = BGMApplication.getInstance().getApplicationProperties(); + + String DRIVER = "oracle.jdbc.driver.OracleDriver"; + + Class.forName(DRIVER); + Connection conn = DriverManager.getConnection( + props.getProperty("url"), + props.getProperty("username").trim(), + props.getProperty("password").trim()); + + return conn; + + } catch (Exception e){ + log.error("", e); + return null; + } + } + + public static BGMApplication getInstance(){ + if (instance == null){ + instance = new BGMApplication(); + } + return instance; + } + + public Properties getApplicationProperties(){ + Properties props = new Properties(); + try { + props.load(new FileInputStream("db.properties")); + } catch (IOException e) { + log.error("", e); + } + return props; + } + + public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM, boolean isReceitasDespesasComporte,boolean isCodReceitaFixoBgm, boolean isReceitasDespesasOuroPrata, boolean layoutNovo) throws IllegalArgumentException, IntegracaoReceitaDespesaException{ + this.isCodReceitaFixoBgm = isCodReceitaFixoBgm; + this.isReceitasDespesasOuroPrata = isReceitasDespesasOuroPrata; + return executaExportacao(dataInicio, dataFinal, diretorio, empresaId, puntoVentaId, con, pathGravacaoExternaArquivos, incluiTipoPagamentoTurismoBGM, layoutNovo); + } + + public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM, boolean isReceitasDespesasComporte,boolean isCodReceitaFixoBgm, boolean isReceitasDespesasOuroPrata) throws IllegalArgumentException, IntegracaoReceitaDespesaException{ + this.isCodReceitaFixoBgm = isCodReceitaFixoBgm; + this.isReceitasDespesasOuroPrata = isReceitasDespesasOuroPrata; + return executaExportacao(dataInicio, dataFinal, diretorio, empresaId, puntoVentaId, con, pathGravacaoExternaArquivos, incluiTipoPagamentoTurismoBGM, false); + } + + public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM, boolean isReceitasDespesasComporte, boolean isReceitasDespesasOuroPrata) throws IllegalArgumentException, IntegracaoReceitaDespesaException{ + this.isReceitasDespesasComporte = isReceitasDespesasComporte; + return executaExportacao(dataInicio, dataFinal, diretorio, empresaId, puntoVentaId, con, pathGravacaoExternaArquivos, incluiTipoPagamentoTurismoBGM, false); + } + + public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM, boolean layoutNovo) throws IllegalArgumentException, IntegracaoReceitaDespesaException{ + if (empresaId == null){ + throw new IllegalArgumentException("o parâmetro empesaId é obrigatório!"); + } + if (puntoVentaId == null){ + throw new IllegalArgumentException("o parâmetro puntoVentaId é obrigatório!"); + } + excluirArquivosZip(diretorio); + Totalbus totalbus = new Totalbus(con, isReceitasDespesasComporte, isCodReceitaFixoBgm, isReceitasDespesasOuroPrata, layoutNovo ); + if (totalbus.isConstanteBloqueioMenorQueData(empresaId, dataFinal)){ + totalbus.updateDataBloqueio(empresaId, dataFinal); + } + List files = new ArrayList(); + Calendar cal = Calendar.getInstance(); + // Seta primeiro dia da iteração + cal.setTime(dataInicio); + Calendar calFinal = Calendar.getInstance(); + calFinal.setTime(dataFinal); + + Calendar cf = Calendar.getInstance(); + cf.setTime(dataFinal); + cf.add(Calendar.DATE, 1); + try{ + + while (cal.before(cf)) { + String fileName = diretorio + File.separator + "BGM_" + empresaId + "-" + cal.get(Calendar.YEAR) + + "" + StringUtils.leftPad(Integer.toString(cal.get(Calendar.MONTH) + 1), 2, "0") + "" + + StringUtils.leftPad(Integer.toString(cal.get(Calendar.DAY_OF_MONTH)), 2, "0") + ".txt"; + File file = new File(fileName); + + log.debug("gerando arquivo..."); + Arquivo.GravaArquivo(file.getAbsolutePath(), totalbus.getDespesasReceitas(puntoVentaId, empresaId, cal.getTime(), incluiTipoPagamentoTurismoBGM)); + + this.copiarArquivoExternamente(file, pathGravacaoExternaArquivos); + + // adiciona um dia para iteração + cal.add(Calendar.DAY_OF_MONTH, 1); + files.add(file); + } + + String fileZip = diretorio + File.separator + "ArquivosBGM.zip"; + log.debug("nome arquivo: " + fileZip); + + compactarArquivos(files, fileZip); + return fileZip; + } catch (IntegracaoReceitaDespesaException e){ + throw e; + } catch (Exception e) { + log.error("", e); + return ""; + } finally{ + try { + con.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + private void copiarArquivoExternamente(File arquivoBGM,String pathGravacaoExternaArquivos){ + if (pathGravacaoExternaArquivos == null){ + log.info("Path externo para gravação de arquivos não configurado"); + + return; + } + + if (!pathGravacaoExternaArquivos.endsWith("/")){ + pathGravacaoExternaArquivos = pathGravacaoExternaArquivos +"/"; + } + + File destino = new File(pathGravacaoExternaArquivos + arquivoBGM.getName()); + + try { + this.copyFileUsingChannel(arquivoBGM, destino); + } catch (IOException e) { + log.error(String.format("Erro ao gravar o arquivo %s no diretorio %s", arquivoBGM.getName(),pathGravacaoExternaArquivos) ,e); + } + } + + @SuppressWarnings("resource") + private void copyFileUsingChannel(File source, File dest) throws IOException { + + FileChannel sourceChannel = null; + FileChannel destChannel = null; + try { + sourceChannel = new FileInputStream(source).getChannel(); + destChannel = new FileOutputStream(dest).getChannel(); + destChannel.transferFrom(sourceChannel, 0, sourceChannel.size()); + }finally{ + sourceChannel.close(); + destChannel.close(); + } + } + + private void excluirArquivosZip(String diretorio){ + File pasta = new File(diretorio); + File[] arquivos = pasta.listFiles(); + + for(File arquivo : arquivos) { + if(arquivo.getName().endsWith("zip")) { + arquivo.delete(); + } + } + } + + public static void compactarArquivo(String arqSaida,String arqEntrada) throws IOException{ + int cont; + byte[] dados = new byte[TAMANHO_BUFFER]; + BufferedInputStream origem = null; + FileInputStream streamDeEntrada = null; + FileOutputStream destino = null; + ZipOutputStream saida = null; + ZipEntry entry = null; + try { + destino = new FileOutputStream(new File(arqSaida)); + saida = new ZipOutputStream(new BufferedOutputStream(destino)); + File file = new File(arqEntrada); + streamDeEntrada = new FileInputStream(file); + origem = new BufferedInputStream(streamDeEntrada, TAMANHO_BUFFER); + entry = new ZipEntry(file.getName()); + saida.putNextEntry(entry); + while((cont = origem.read(dados, 0, TAMANHO_BUFFER)) != -1) { + saida.write(dados, 0, cont); + } + origem.close(); + saida.close(); + } catch(IOException e) { + log.error(e.getMessage()); + throw new IOException(e.getMessage()); + } + } + + private void compactarArquivos(List arquivosEOuPastas, String arquivoDeSaida){ + System.out.println(arquivoDeSaida); + log.debug(arquivoDeSaida); + + // Create a buffer for reading the files + byte[] buf = new byte[1024]; + + try { + // Create the ZIP file + ZipOutputStream out = new ZipOutputStream(new FileOutputStream(arquivoDeSaida)); + + // Compress the files + for (File f : arquivosEOuPastas) { + FileInputStream in = new FileInputStream(f.getPath()); + + // Add ZIP entry to output stream. + out.putNextEntry(new ZipEntry(f.getName())); + System.out.println(f.getPath()); + // Transfer bytes from the file to the ZIP file + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + + // Complete the entry + out.closeEntry(); + in.close(); + f.delete(); + } + + // Complete the ZIP file + out.close(); + } catch (IOException e) { + log.error(e.getMessage(),e); + e.printStackTrace(); + } + } + +} diff --git a/src/com/rjconsultores/integracaoreceitadespesa/IntegracaoReceitaDespesaException.java b/src/com/rjconsultores/integracaoreceitadespesa/IntegracaoReceitaDespesaException.java new file mode 100644 index 000000000..c38e2c744 --- /dev/null +++ b/src/com/rjconsultores/integracaoreceitadespesa/IntegracaoReceitaDespesaException.java @@ -0,0 +1,13 @@ +package com.rjconsultores.integracaoreceitadespesa; + +public class IntegracaoReceitaDespesaException extends Exception{ + + /** + * + */ + private static final long serialVersionUID = -5422391379643449955L; + + public IntegracaoReceitaDespesaException(String message) { + super(message); + } +} diff --git a/src/com/rjconsultores/integracaoreceitadespesa/dao/Totalbus.java b/src/com/rjconsultores/integracaoreceitadespesa/dao/Totalbus.java new file mode 100644 index 000000000..53ce3590c --- /dev/null +++ b/src/com/rjconsultores/integracaoreceitadespesa/dao/Totalbus.java @@ -0,0 +1,1145 @@ +package com.rjconsultores.integracaoreceitadespesa.dao; + +import java.math.BigDecimal; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +import com.rjconsultores.integracaoreceitadespesa.IntegracaoReceitaDespesaException; +import com.rjconsultores.integracaoreceitadespesa.entidades.DespesaReceita; +import com.rjconsultores.integracaoreceitadespesa.entidades.DespesaReceitaComporte; +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 pontosVenda = new ArrayList(); + private List empresas = new ArrayList(); + + private Boolean isCodReceitaFixoBgm = false; + + private Boolean isReceitasDespesasComporte = false; + + private Boolean isReceitasDespesasOuroPrata= false; + + private Boolean isLayoutNovo= false; + + private DecimalFormat df = new DecimalFormat("#0.00"); + + public Totalbus(Connection con, Boolean isReceitasDespesasComporte, Boolean isReceitasDespesasOuroPrata) { + this.conn = con; + this.isReceitasDespesasComporte = isReceitasDespesasComporte; + this.isReceitasDespesasOuroPrata = isReceitasDespesasOuroPrata; + loadEmpresas(); + loadPuntosVenta(); + } + + public Totalbus(Connection con, Boolean isReceitasDespesasComporte,Boolean isCodReceitaFixoBgm, Boolean isReceitasDespesasOuroPrata) { + this.conn = con; + this.isReceitasDespesasComporte = isReceitasDespesasComporte; + this.isReceitasDespesasOuroPrata = isReceitasDespesasOuroPrata; + this.isCodReceitaFixoBgm = isCodReceitaFixoBgm; + loadEmpresas(); + loadPuntosVenta(); + } + + public Totalbus(Connection con, Boolean isReceitasDespesasComporte,Boolean isCodReceitaFixoBgm, Boolean isReceitasDespesasOuroPrata, Boolean isLayoutNovo) { + this.conn = con; + this.isReceitasDespesasComporte = isReceitasDespesasComporte; + this.isReceitasDespesasOuroPrata = isReceitasDespesasOuroPrata; + this.isCodReceitaFixoBgm = isCodReceitaFixoBgm; + this.isLayoutNovo = isLayoutNovo; + loadEmpresas(); + loadPuntosVenta(); + } + + public List getDespesasReceitas(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) throws IntegracaoReceitaDespesaException{ + log.debug("gerando depósitos..."); + List despesasReceitas = getDepositos(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM); + log.debug("gerando despesas..."); + despesasReceitas.addAll(getDespesas(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM)); + log.debug("gerando despesas cartão..."); + + if (isReceitasDespesasComporte){ + despesasReceitas.addAll(getDespesaCartaoDebCredComporte(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM)); + log.debug("gerando receitas..."); + despesasReceitas.addAll(getReceitasComporte(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM)); + + }else { + despesasReceitas.addAll(getDespesaCartaoDebCred(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM)); + log.debug("gerando receitas..."); + despesasReceitas.addAll(getReceitas(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM)); + if(isReceitasDespesasOuroPrata) { + getContaCorrenteAgencia(despesasReceitas, puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM); + } + } + + List rows = new ArrayList(); + + if( isLayoutNovo ) { + for (DespesaReceita item : despesasReceitas) { + item.preencheLinhaLayoutNovo(rows); + } + }else { + for (DespesaReceita item : despesasReceitas) { + item.preencheLinha(rows); + } + } + return rows; + } + + private void getContaCorrenteAgencia(List despesasReceitas, Integer puntoVentaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) throws IntegracaoReceitaDespesaException { + despesasReceitas.addAll(buscarFormasPagamentoContaCorrenteAgencia(puntoVentaId, empresaId, fechaParam,incluiTipoPagamentoTurismoBGM)); + despesasReceitas.addAll(buscarComissoesContaCorrenteAgencia(puntoVentaId, empresaId, fechaParam,incluiTipoPagamentoTurismoBGM)); + } + + private Collection buscarFormasPagamentoContaCorrenteAgencia(Integer puntoVentaId, + Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) + throws IntegracaoReceitaDespesaException { + + List despesas = new ArrayList(); + + StringBuilder sb = new StringBuilder(); + + SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy"); + String fechaStr = sf.format(fechaParam); + if (fechaParam == null) { + fechaStr = sf.format(getData()); + } + + + sb.append("SELECT SUM(precioboleto) AS precioBoleto, "); + sb.append("formaPagoId, "); + sb.append("descripcionFormaPago, "); + sb.append("empresa, "); + sb.append("puntoventaId, "); + sb.append("contacontabil, "); + sb.append("numpuntoventa, "); + sb.append("descinfo, "); + sb.append("tipoEventoExtra, "); + sb.append("feccorte AS feccorte "); + sb.append("FROM ("); + sb.append("(SELECT SUM(CASE "); + sb.append(" WHEN c.MOTIVOCANCELACION_ID IS NULL THEN 1 ELSE -1 END * cfp.importe) AS precioBoleto, "); + sb.append("cfp.formapago_id AS formaPagoId, "); + sb.append("fp.DESCPAGO AS descripcionFormaPago, "); + sb.append("e.empresa_id AS empresa, "); + sb.append("ccp.PUNTOVENTA_ID AS puntoventaId, "); + sb.append("tee.contacontabil AS contacontabil, "); + sb.append("pv.numpuntoventa AS numpuntoventa, "); + sb.append("ee.descinfo AS descinfo, "); + sb.append("ee.tipoeventoextra_id AS tipoEventoExtra, "); + sb.append("ccp.feccorte AS feccorte "); + sb.append(" FROM forma_pago fp, caja c "); + sb.append(" left OUTER JOIN motivo_cancelacion mc ON c.motivocancelacion_id = mc.motivocancelacion_id"); + sb.append(" left OUTER JOIN marca m ON c.marca_id = m.marca_id"); + sb.append(" left OUTER JOIN empresa e ON m.empresa_id = e.empresa_id"); + sb.append(" INNER JOIN caja_formapago cfp ON c.caja_id = cfp.caja_id"); + sb.append(" left OUTER JOIN boleto b ON b.boleto_id = c.transacao_id"); + sb.append(" left JOIN evento_extra ee ON b.boleto_id = ee.boleto_id and ee.boleto_id is null "); + sb.append(" left JOIN tipo_evento_extra tee ON tee.tipoeventoextra_id = ee.tipoeventoextra_id"); + sb.append(" left JOIN punto_venta pv ON pv.puntoventa_id = c.puntoventa_id and (cfp.activo = 1) "); + sb.append(" INNER JOIN CONTA_CORRENTE_PTOVTA ccp ON e.EMPRESA_ID = ccp.EMPRESA_ID"); + sb.append(" and ccp.PUNTOVENTA_ID = c.PUNTOVENTA_ID"); + sb.append(" and ccp.FECCORTE = c.FECCORTE"); + sb.append(" and ccp.TURNO_ID = c.turno_id"); + sb.append(" and ccp.ACTIVO = 1"); + sb.append(" and c.USUARIO_ID = ccp.USUARIO_ID"); + sb.append(" WHERE cfp.formapago_id = fp.formapago_id"); + sb.append(" and C.INDSTATUSOPERACION = 'F'"); + sb.append(" and c.INDREIMPRESION = 0"); + sb.append(" and c.tipoventa_id <> 6"); + sb.append(" and c.ACTIVO = 1"); + adicionaFiltroQuery(empresaId, sb, " and ccp.EMPRESA_ID = ", empresaId != null); + adicionaFiltroQuery(puntoVentaId, sb, " and ccp.PUNTOVENTA_ID = ", puntoVentaId != null && !puntoVentaId.equals(-1)); + sb.append(" and ccp.feccorte = TO_DATE('"+fechaStr+" 00:00:00', 'dd/MM/yyyy HH24:mi:ss')and cfp.formapago_id in (2,3) "); + sb.append(" GROUP BY cfp.formapago_id,"); + sb.append(" fp.DESCPAGO,"); + sb.append(" e.empresa_id,"); + sb.append(" ccp.PUNTOVENTA_ID,"); + sb.append(" tee.contacontabil,"); + sb.append(" pv.numpuntoventa,"); + sb.append(" ee.descinfo, ee.tipoeventoextra_id, ccp.FECCORTE )"); + sb.append(" UNION"); + sb.append(" (SELECT SUM(cdp.IMPORTE) AS precioBoleto,"); + sb.append(" cdp.formapago_id AS formaPagoId,"); + sb.append(" fp.DESCPAGO AS descripcionFormaPago,"); + sb.append(" e.empresa_id AS empresa,"); + sb.append(" cd.PUNTOVENTA_ID AS puntoventaId,"); + sb.append(" tee.contacontabil AS contacontabil,"); + sb.append(" pv.numpuntoventa AS numpuntoventa,"); + sb.append(" ee.descinfo AS descinfo,"); + sb.append(" ee.tipoeventoextra_id AS tipoEventoExtra, ccp.feccorte AS feccorte "); + sb.append(" FROM CAJA_DIVERSOS cd"); + sb.append(" JOIN CAJA_DIVERSOS_PAGO cdp ON cdp.CAJADIVERSOS_ID = cd.CAJADIVERSOS_ID"); + sb.append(" INNER JOIN forma_pago fp ON fp.formapago_id = cdp.formapago_id"); + sb.append(" INNER JOIN EVENTO_EXTRA EE ON EE.EVENTOEXTRA_ID = cd.EVENTOEXTRA_ID"); + sb.append(" LEFT OUTER JOIN empresa e ON ee.empresa_id = e.empresa_id"); + sb.append(" LEFT JOIN boleto b ON b.boleto_id = ee.boleto_id"); + sb.append(" LEFT OUTER JOIN evento_extra ee ON b.boleto_id = ee.boleto_id"); + sb.append(" LEFT JOIN tipo_evento_extra tee ON tee.tipoeventoextra_id = ee.tipoeventoextra_id"); + sb.append(" LEFT JOIN punto_venta pv ON pv.puntoventa_id = cd.puntoventa_id "); + sb.append(" INNER JOIN CONTA_CORRENTE_PTOVTA ccp ON e.EMPRESA_ID = ccp.EMPRESA_ID "); + sb.append(" AND ccp.PUNTOVENTA_ID = cd.PUNTOVENTA_ID "); + sb.append("AND ccp.FECCORTE = cd.FECCORTE "); + sb.append(" AND ccp.TURNO_ID = cd.turno_id "); + sb.append(" AND cd.USUARIO_ID = ccp.USUARIO_ID "); + sb.append(" WHERE 1 = 1"); + sb.append(" AND cd.ACTIVO = 1"); + sb.append(" AND ccp.ACTIVO = 1"); + sb.append(" AND (ee.boleto_id IS NULL"); + sb.append(" OR ee.boleto_id = b.boleto_id)"); + adicionaFiltroQuery(empresaId, sb, " and ccp.EMPRESA_ID = ", empresaId != null); + adicionaFiltroQuery(puntoVentaId, sb, " and ccp.PUNTOVENTA_ID = ", puntoVentaId != null && !puntoVentaId.equals(-1)); + sb.append(" AND ccp.feccorte = TO_DATE('"+fechaStr+" 00:00:00', 'dd/MM/yyyy HH24:mi:ss') and ee.tipoeventoextra_id <> 25 and cdp.formapago_id in (2,3) "); + sb.append(" GROUP BY cdp.formapago_id, fp.DESCPAGO,"); + sb.append(" e.empresa_id, cd.PUNTOVENTA_ID, "); + sb.append(" tee.contacontabil,"); + sb.append(" pv.numpuntoventa, ee.descinfo,"); + sb.append(" ee.tipoeventoextra_id, ccp.FECCORTE )) x "); + sb.append("GROUP BY formaPagoId, descripcionFormaPago, empresa, "); + sb.append(" puntoventaId,"); + sb.append(" contacontabil,"); + sb.append(" numpuntoventa,"); + sb.append(" descinfo,"); + sb.append(" tipoEventoExtra,feccorte "); + sb.append("ORDER BY formaPagoId, descripcionFormaPago"); + + + PreparedStatement stmt = null; + ResultSet rs = null; + + try { + stmt = getConnection().prepareStatement(sb.toString()); + rs = stmt.executeQuery(); + + while (rs.next()) { + DespesaReceita receita = new DespesaReceita(); + receita.setCodigoEmpresa(rs.getInt(4)); + receita.setCodigoReceitaDespesa(rs.getString(6)); + receita.setDataLancamento(rs.getDate(10)); + receita.setDataMovimento(rs.getDate(10)); + receita.setLocalArrecadacao(rs.getString(7)); + if (rs.getBigDecimal(1).signum() == 1) { + receita.setIdentificadorReceitaDespesa("D"); + receita.setValorLancamento(df.format(rs.getBigDecimal(1))); + } else { + receita.setIdentificadorReceitaDespesa("R"); + receita.setValorLancamento(df.format(rs.getBigDecimal(1))); + } + + String desc =rs.getString(8); + + desc = this.removerQuebraDeLinha(desc); + + receita.setDescricaoDetalhada(desc); + if (incluiTipoPagamentoTurismoBGM) { + receita.setTipoPagamentoTurismo(rs.getString("tipoEventoExtra")); + } + receita.setFormaPagamentoId(rs.getString("formaPagoId")); + despesas.add(receita); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Receitas"); + } finally { + try { + rs.close(); + } catch (Exception ignore) { + log.error(ignore.getMessage(), ignore); + } + try { + stmt.close(); + } catch (Exception ignore) { + log.error(ignore.getMessage(), ignore); + } + } + return despesas; + } + + private void loadPuntosVenta() { + PreparedStatement pstmt = null; + ResultSet rs = null; + + try { + pstmt = getConnection().prepareStatement("Select puntoventa_id, nombpuntoventa from punto_venta order by nombpuntoventa"); + rs = pstmt.executeQuery(); + while (rs.next()) { + PuntoVenta puntoVenta = new PuntoVenta(); + puntoVenta.codigo = rs.getInt(1); + puntoVenta.nombpuntoventa = rs.getString(2); + pontosVenda.add(puntoVenta); + } + } 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); + } + } + } + + private Collection buscarComissoesContaCorrenteAgencia(Integer puntoVentaId,Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) + throws IntegracaoReceitaDespesaException { + List despesas = new ArrayList(); + + StringBuilder sb = new StringBuilder(); + + SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy"); + String fechaStr = sf.format(fechaParam); + if (fechaParam == null) { + fechaStr = sf.format(getData()); + } + + sb.append("SELECT CASE"); + sb.append(" WHEN E.INDRATEIOCOMISSAOGRUPOLINHA = 1"); + sb.append(" AND OP.TIPOOPERACIONCC_ID = 5"); + sb.append(" AND CCGL.CONTACORRENTEPTOVTAGRLIN_ID IS NOT NULL THEN CCGL.IMPORTE"); + sb.append(" ELSE CC.IMPORTETOTALEFECTIVO"); + sb.append(" END AS precioBoleto ,"); + sb.append(" CASE"); + sb.append(" WHEN OP.INDCREDITO = 1 THEN 'CREDITO'"); + sb.append(" ELSE 'DEBITO'"); + sb.append(" END AS descripcionFormaPago ,"); + sb.append(" CASE"); + sb.append(" WHEN OP.CVETIPO = 'CM' THEN 'COMISSAO' "); + sb.append(" WHEN OP.CVETIPO = 'LQ' THEN 'LQ' "); + sb.append(" END AS descripcionFormaPago,"); + sb.append(" cc.empresa_id, "); + sb.append(" cc.puntoventa_id, "); + sb.append(" pv.numpuntoventa, "); + sb.append(" cc.fechoroperacion "); + sb.append("FROM CONTA_CORRENTE_PTOVTA CC "); + sb.append("LEFT JOIN CONTA_CORRENTE_PTOVTA_GR_LIN CCGL ON CCGL.CONTACORRENTEPTOVTA_ID = CC.CONTACORRENTEPTOVTA_ID "); + sb.append("JOIN TIPO_OPERACION_CC OP ON CC.TIPOOPERACIONCC_ID = OP.TIPOOPERACIONCC_ID "); + sb.append("JOIN PUNTO_VENTA PV ON CC.PUNTOVENTA_ID = PV.PUNTOVENTA_ID "); + sb.append("JOIN EMPRESA E ON CC.EMPRESA_ID = E.EMPRESA_ID "); + sb.append("LEFT JOIN LOG_CONFERENCIA LG ON CC.CONTACORRENTEPTOVTA_ID = LG.CONTACORRENTEPTOVTA_ID "); + sb.append("LEFT JOIN CONFERENCIA_PENDENCIA CP ON CP.CONFERENCIAPENDENCIA_ID = LG.CONFERENCIAPENDENCIA_ID "); + sb.append("WHERE CC.ACTIVO = 1 "); + sb.append(" AND cc.feccorte = TO_DATE('"+fechaStr+" 00:00:00', 'dd/MM/yyyy HH24:mi:ss') "); + adicionaFiltroQuery(empresaId, sb, " and CC.EMPRESA_ID = ", empresaId != null); + adicionaFiltroQuery(puntoVentaId, sb, " and CC.PUNTOVENTA_ID = ", puntoVentaId != null && !puntoVentaId.equals(-1)); + sb.append(" ORDER BY PV.NOMBPUNTOVENTA,"); + sb.append(" E.NOMBEMPRESA,"); + sb.append(" OP.DESCTIPO,"); + sb.append(" OP.CVETIPO "); + + + PreparedStatement stmt = null; + ResultSet rs = null; + + + try { + stmt = getConnection().prepareStatement(sb.toString()); + + rs = stmt.executeQuery(); + + while (rs.next()) { + DespesaReceita receita = new DespesaReceita(); + receita.setCodigoEmpresa(rs.getInt(4)); + receita.setCodigoReceitaDespesa(""); + receita.setDataLancamento(rs.getDate(7)); + receita.setDataMovimento(rs.getDate(7)); + receita.setLocalArrecadacao(rs.getString(6)); + if(rs.getString(3) != null) { + if(rs.getString(3).equalsIgnoreCase("COMISSAO")) { + if (rs.getBigDecimal(1).signum() == 1) { + receita.setIdentificadorReceitaDespesa("D"); + } else { + receita.setIdentificadorReceitaDespesa("R"); + } + }else if(rs.getString(3).equalsIgnoreCase("LQ")) { + if (rs.getBigDecimal(1).signum() == 1) { + receita.setIdentificadorReceitaDespesa("D"); + } else { + receita.setIdentificadorReceitaDespesa("R"); + } + } + } + receita.setValorLancamento(df.format(rs.getBigDecimal(1))); + receita.setDescricaoDetalhada(""); + if (incluiTipoPagamentoTurismoBGM) { + receita.setTipoPagamentoTurismo(rs.getString("tipoeventoextra_id")); + } + receita.setFormaPagamentoId("1"); + despesas.add(receita); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Receitas"); + } finally { + try { + rs.close(); + } catch (Exception ignore) { + log.error(ignore.getMessage(), ignore); + } + try { + stmt.close(); + } catch (Exception ignore) { + log.error(ignore.getMessage(), ignore); + } + } + return despesas; + } + + + + private void loadEmpresas() { + PreparedStatement pstmt = null; + ResultSet rs = null; + + try { + pstmt = getConnection().prepareStatement("Select empresa_id, nombempresa from empresa order by nombempresa"); + rs = pstmt.executeQuery(); + while (rs.next()) { + Empresa empresa = new Empresa(); + empresa.codigo = rs.getInt(1); + empresa.nombempresa = rs.getString(2); + empresas.add(empresa); + } + } 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); + } + } + } + + public Connection getConnection() { + return this.conn; + } + + public List getDespesaCartaoDebCred(final Integer puntoVentaId, final Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) throws IntegracaoReceitaDespesaException{ + List despesas = new ArrayList(); + StringBuilder sb = new StringBuilder(); + 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, "); + + if(isCodReceitaFixoBgm){ + sb.append(" case when cdp.formapago_id = 2 then 802 else 803 end, "); + }else{ + sb.append(" tee.contacontabil AS contacontabil, "); + } + + 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 "); + 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 "); + sb.append(" left join caja_diversos_pago cdp on cdp.cajadiversos_id = cd.cajadiversos_id "); + sb.append(" left join tipo_evento_extra tee on tee.tipoeventoextra_id = ev.tipoeventoextra_id "); + sb.append(" left join ptovta_integra pi on e.empresa_id = pi.empresa_id and pi.puntoventa_id = pv.puntoventa_id "); + sb.append(" where "); + sb.append(" cd.feccorte = ? "); + adicionaFiltroQuery(puntoVentaId, sb, " and cd.puntoventa_id = ", puntoVentaId != null && !puntoVentaId.equals(-1)); + adicionaFiltroQuery(empresaId, sb, " and e.empresa_id = ", empresaId != null); + sb.append(" and cd.activo = 1 "); + sb.append(" and cdp.formapago_id in (2,3) "); + sb.append(" and tee.indtipo = 0 "); + sb.append(" group by "); + sb.append(" cd.feccorte, "); + sb.append(" e.empresa_id, "); + sb.append(" pv.puntoventa_id, "); + + if(isCodReceitaFixoBgm){ + sb.append(" case when cdp.formapago_id = 2 then 802 else 803 end, "); + }else{ + sb.append(" tee.contacontabil, "); + } + + sb.append(" pv.numpuntoventa, ev.tipoeventoextra_id, "); + sb.append(" cdp.formapago_id "); + + PreparedStatement stmt = null; + ResultSet rs = null; + + Date fecha = fechaParam; + if (fechaParam == null) { + fecha = getData(); + } + + try { + stmt = getConnection().prepareStatement(sb.toString()); + stmt.setDate(1, new java.sql.Date(fecha.getTime())); + rs = stmt.executeQuery(); + + 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.setIdentificadorReceitaDespesa("D"); + despesa.setValorLancamento(df.format(rs.getBigDecimal(4).multiply(new BigDecimal(-1)))); + } else { + despesa.setIdentificadorReceitaDespesa("R"); + despesa.setValorLancamento(df.format(rs.getBigDecimal(4))); + } + if (incluiTipoPagamentoTurismoBGM) { + despesa.setTipoPagamentoTurismo(rs.getString("tipoeventoextra_id")); + } + despesa.setFormaPagamentoId(rs.getString("formapagoId")); + despesas.add(despesa); + } + } catch (Exception e) { + log.error(e.toString(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Despesas Cartão Crédito/Débito"); + } finally { + try { + rs.close(); + } catch (Exception ignore) { + log.error("", ignore); + } + try { + stmt.close(); + } catch (Exception ignore) { + log.error("", ignore); + } + } + return despesas; + } + + public List getDespesaCartaoDebCredComporte(final Integer puntoVentaId, final Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) throws IntegracaoReceitaDespesaException{ + List despesas = new ArrayList(); + StringBuilder sb = new StringBuilder(); + 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(" tee.contacontabil AS contacontabil, "); + sb.append(" pv.numpuntoventa AS numpuntoventa, "); + sb.append(" ev.tipoeventoextra_id, "); + sb.append(" cdp.formapago_id as formapagoId, "); + sb.append(" ct.numautorizacion as numautorizacion, "); + sb.append(" pte.numsitef as numeroEstabelecimento "); + 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 "); + sb.append(" left join caja_diversos_pago cdp on cdp.cajadiversos_id = cd.cajadiversos_id "); + sb.append(" left join tipo_evento_extra tee on tee.tipoeventoextra_id = ev.tipoeventoextra_id "); + sb.append(" left join ptovta_integra pi on e.empresa_id = pi.empresa_id and pi.puntoventa_id = pv.puntoventa_id "); + sb.append(" left join caja_tarjeta ct on ct.cajatarjeta_id = cdp.cajatarjeta_id "); + sb.append(" left join ptovta_empresa pte on pte.puntoventa_id = pv.puntoventa_id and pte.empresa_id = e.empresa_id "); + sb.append(" where "); + sb.append(" cd.feccorte = ? "); + adicionaFiltroQuery(puntoVentaId, sb, " and cd.puntoventa_id = ", puntoVentaId != null && !puntoVentaId.equals(-1)); + adicionaFiltroQuery(empresaId, sb, " and e.empresa_id = ", empresaId != null); + sb.append(" and cd.activo = 1 "); + sb.append(" and cdp.formapago_id in (2,3) "); + sb.append(" and tee.indtipo = 0 "); + sb.append(" group by "); + sb.append(" cd.feccorte, "); + sb.append(" e.empresa_id, "); + sb.append(" pv.puntoventa_id, "); + sb.append(" tee.contacontabil, "); + sb.append(" pv.numpuntoventa, ev.tipoeventoextra_id, "); + sb.append(" cdp.formapago_id, "); + sb.append(" ct.numautorizacion, "); + sb.append(" pte.numsitef "); + + PreparedStatement stmt = null; + ResultSet rs = null; + + Date fecha = fechaParam; + if (fechaParam == null) { + fecha = getData(); + } + + try { + stmt = getConnection().prepareStatement(sb.toString()); + stmt.setDate(1, new java.sql.Date(fecha.getTime())); + rs = stmt.executeQuery(); + + while (rs.next()) { + DespesaReceitaComporte despesa = new DespesaReceitaComporte(); + 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.setIdentificadorReceitaDespesa("D"); + despesa.setValorLancamento(df.format(rs.getBigDecimal(4).multiply(new BigDecimal(-1)))); + } else { + despesa.setIdentificadorReceitaDespesa("R"); + despesa.setValorLancamento(df.format(rs.getBigDecimal(4))); + } + if (incluiTipoPagamentoTurismoBGM) { + despesa.setTipoPagamentoTurismo(rs.getString("tipoeventoextra_id")); + } + despesa.setFormaPagamentoId(rs.getString("formapagoId")); + + if( despesa.getFormaPagamentoId().equals("2") || despesa.getFormaPagamentoId().equals("3")) { + despesa.setCodigoAutorizacao(rs.getString("numautorizacion")); + despesa.setNumeroEstabelecimento(rs.getString("numeroEstabelecimento")); + }else { + despesa.setCodigoAutorizacao(""); + despesa.setNumeroEstabelecimento(""); + } + + despesas.add(despesa); + } + } catch (Exception e) { + log.error(e.toString(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Despesas Cartão Crédito/Débito"); + } finally { + try { + rs.close(); + } catch (Exception ignore) { + log.error("", ignore); + } + try { + stmt.close(); + } catch (Exception ignore) { + log.error("", ignore); + } + } + return despesas; + } + + private void adicionaFiltroQuery(final Integer valor, StringBuilder sb, String filtroSQL, Boolean adicionar) { + if (adicionar) { + sb.append(filtroSQL + valor); + } + } + + public List getReceitas(final Integer puntoVentaId, final Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) throws IntegracaoReceitaDespesaException { + List despesas = new ArrayList(); + StringBuilder sb = new StringBuilder(); + 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(" COALESCE(sum(cdp.importe),0) AS valor, "); + sb.append(" tee.contacontabil AS contacontabil, "); + sb.append(" pv.numpuntoventa AS numpuntoventa, "); + sb.append(" ev.descinfo as descinfo, "); + sb.append(" ev.tipoeventoextra_id, "); + sb.append(" COALESCE(cdp.formapago_id,0) 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 "); + sb.append(" left join caja_diversos_pago cdp on cdp.cajadiversos_id = cd.cajadiversos_id "); + sb.append(" left join tipo_evento_extra tee on tee.tipoeventoextra_id = ev.tipoeventoextra_id "); + sb.append(" left join ptovta_integra pi on e.empresa_id = pi.empresa_id and pi.puntoventa_id = pv.puntoventa_id "); + sb.append(" where "); + sb.append(" cd.feccorte = ? "); + adicionaFiltroQuery(puntoVentaId, sb, " and cd.puntoventa_id = ", puntoVentaId != null && !puntoVentaId.equals(-1)); + adicionaFiltroQuery(empresaId, sb, " and e.empresa_id = ", empresaId != null); + sb.append(" and cd.activo = 1 "); + sb.append(" and tee.indtipo = 1 "); + 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(" cdp.formapago_id "); + + PreparedStatement stmt = null; + ResultSet rs = null; + + Date fecha = fechaParam; + if (fechaParam == null) { + fecha = getData(); + } + + try { + stmt = getConnection().prepareStatement(sb.toString()); + stmt.setDate(1, new java.sql.Date(fecha.getTime())); + rs = stmt.executeQuery(); + + 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) { + 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))); + } + + String desc =rs.getString(7); + + desc = this.removerQuebraDeLinha(desc); + + receita.setDescricaoDetalhada(desc); + if (incluiTipoPagamentoTurismoBGM) { + receita.setTipoPagamentoTurismo(rs.getString("tipoeventoextra_id")); + } + receita.setFormaPagamentoId(rs.getString("formapagoId")); + despesas.add(receita); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Receitas"); + } finally { + 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 getReceitasComporte(final Integer puntoVentaId, final Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) throws IntegracaoReceitaDespesaException { + List despesas = new ArrayList(); + StringBuilder sb = new StringBuilder(); + 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(" COALESCE(cdp.importe,0) AS valor, "); + sb.append(" tee.contacontabil AS contacontabil, "); + sb.append(" pv.numpuntoventa AS numpuntoventa, "); + sb.append(" ev.descinfo AS descinfo, "); + sb.append(" ev.tipoeventoextra_id, "); + sb.append(" COALESCE(cdp.formapago_id,0) as formapagoId, "); + sb.append(" ct.numautorizacion AS numautorizacion, "); + sb.append(" pte.numsitef AS numeroestabelecimento, "); + sb.append(" ct.cantparcelas "); + 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 "); + sb.append(" left join caja_diversos_pago cdp on cdp.cajadiversos_id = cd.cajadiversos_id "); + sb.append(" left join tipo_evento_extra tee on tee.tipoeventoextra_id = ev.tipoeventoextra_id "); + sb.append(" left join ptovta_integra pi on e.empresa_id = pi.empresa_id and pi.puntoventa_id = pv.puntoventa_id "); + sb.append(" LEFT JOIN caja_tarjeta ct ON ct.cajatarjeta_id = cdp.cajatarjeta_id "); + sb.append(" LEFT JOIN ptovta_empresa pte ON pte.puntoventa_id = pv.puntoventa_id AND pte.empresa_id = e.empresa_id "); + sb.append(" where "); + sb.append(" cd.feccorte = ? "); + adicionaFiltroQuery(puntoVentaId, sb, " and cd.puntoventa_id = ", puntoVentaId != null && !puntoVentaId.equals(-1)); + adicionaFiltroQuery(empresaId, sb, " and e.empresa_id = ", empresaId != null); + sb.append(" and cd.activo = 1 "); + sb.append(" and tee.indtipo = 1 "); + + PreparedStatement stmt = null; + ResultSet rs = null; + + Date fecha = fechaParam; + if (fechaParam == null) { + fecha = getData(); + } + + try { + stmt = getConnection().prepareStatement(sb.toString()); + stmt.setDate(1, new java.sql.Date(fecha.getTime())); + rs = stmt.executeQuery(); + + while (rs.next()) { + DespesaReceitaComporte receita = new DespesaReceitaComporte(); + 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)); + receita.setCantParcelas(rs.getString(12)); + 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))); + } + + String desc =rs.getString(7); + + desc = this.removerQuebraDeLinha(desc); + + receita.setDescricaoDetalhada(desc); + if (incluiTipoPagamentoTurismoBGM) { + receita.setTipoPagamentoTurismo(rs.getString("tipoeventoextra_id")); + } + receita.setFormaPagamentoId(rs.getString("formapagoId")); + + if( receita.getFormaPagamentoId().equals("2") || receita.getFormaPagamentoId().equals("3")) { + receita.setCodigoAutorizacao(rs.getString("numautorizacion")); + receita.setNumeroEstabelecimento(rs.getString("numeroEstabelecimento")); + }else { + receita.setCodigoAutorizacao(""); + receita.setNumeroEstabelecimento(""); + } + + despesas.add(receita); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Receitas"); + } finally { + 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 getDespesas(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) throws IntegracaoReceitaDespesaException { + List despesas = new ArrayList(); + 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, "); + 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 "); + sb.append(" left join caja_diversos_pago cdp on cdp.cajadiversos_id = cd.cajadiversos_id "); + sb.append(" left join tipo_evento_extra tee on tee.tipoeventoextra_id = ev.tipoeventoextra_id "); + sb.append(" left join ptovta_integra pi on e.empresa_id = pi.empresa_id and pi.puntoventa_id = pv.puntoventa_id "); + sb.append(" where "); + sb.append(" cd.feccorte = ? "); + sb.append(" and tee.indtipo = 0 "); + adicionaFiltroQuery(puntoventaId, sb, " and cd.puntoventa_id = ", puntoventaId != null && !puntoventaId.equals(-1)); + adicionaFiltroQuery(empresaId, sb, " and e.empresa_id = ", empresaId != null); + sb.append(" and cd.activo = 1 "); + sb.append(" AND cdp.formapago_id not IN (2,3) "); + 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) { + fecha = getData(); + } + + PreparedStatement pstmt = null; + ResultSet rs = null; + + try { + pstmt = getConnection().prepareStatement(sb.toString()); + pstmt.setDate(1, new java.sql.Date(fecha.getTime())); + + rs = pstmt.executeQuery(); + 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(3)); + despesa.setValorLancamento(df.format(rs.getBigDecimal(4).doubleValue() * -1)); + despesa.setIdentificadorReceitaDespesa("D"); + String desc =rs.getString(6); + + desc = this.removerQuebraDeLinha(desc); + + despesa.setDescricaoDetalhada(desc); + if (incluiTipoPagamentoTurismoBGM) { + despesa.setTipoPagamentoTurismo(rs.getString("tipoeventoextra_id")); + } + despesa.setFormaPagamentoId(rs.getString("formapagoId")); + despesas.add(despesa); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Despesas"); + } finally { + try { + rs.close(); + } catch (Exception ignore) { + log.error(ignore.getMessage(), ignore); + } + try { + pstmt.close(); + } catch (Exception ignore) { + log.error(ignore.getMessage(), ignore); + } + } + return despesas; + } + + private String removerQuebraDeLinha(String desc) { + if(StringUtils.isBlank(desc)){ + return desc; + } + + desc = desc.replaceAll("\t", " "); + + desc = desc.replaceAll("\n", " "); + + desc = desc.replaceAll("\r", " "); + + return desc; + } + + public List getDepositos(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM) throws IntegracaoReceitaDespesaException { + List depositos = new ArrayList(); + + 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(" 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) { + fecha = getData(); + } + + PreparedStatement pstmtFechamentos = null; + ResultSet rsFechamentos = null; + BigDecimal soma = BigDecimal.ZERO; + try { + pstmtFechamentos = getConnection().prepareStatement(strFechamentos.toString()); + pstmtFechamentos.setDate(1, new java.sql.Date(fecha.getTime())); + + rsFechamentos = pstmtFechamentos.executeQuery(); + + while (rsFechamentos.next()) { + Integer empId = null; + 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); + } + + DespesaReceita deposito = new DespesaReceita(); + deposito.setCodigoEmpresa(empId); + deposito.setDataLancamento(rsFechamentos.getDate(10)); + deposito.setDataMovimento(rsFechamentos.getDate(3)); + deposito.setLocalArrecadacao(numpuntoventa); + deposito.setValorLancamento(df.format(rsFechamentos.getBigDecimal(1))); + 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) { + log.error(e.getMessage(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Depósitos"); + } finally { + 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() { + 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 { + pstmt = getConnection().prepareStatement(sb.toString()); + rs = pstmt.executeQuery(); + if (rs.next()) { + result = rs.getInt(1); + } + } 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); + } + } + return result; + + } + + 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 { + pstmt = getConnection().prepareStatement(sb.toString()); + rs = pstmt.executeQuery(); + 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) { + 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); + } + } + return result; + + } + + 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," + + "'" + sdf.format(data) + "', 1, 1, :datamodif, 1)"); + 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) { + log.error(e.getMessage(), e); + } finally { + try { + pstmt.close(); + } catch (Exception ignore) { + log.error(ignore.getMessage(), ignore); + } + } + } + + 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(); + } + + public List getPontosVenda() { + return pontosVenda; + } + + public void setPontosVenda(List pontosVenda) { + this.pontosVenda = pontosVenda; + } + + public List getEmpresas() { + return empresas; + } + + public void setEmpresas(List empresas) { + this.empresas = empresas; + } + + public void setIsReceitasDespesasComporte(Boolean isReceitasDespesasComporte) { + this.isReceitasDespesasComporte = isReceitasDespesasComporte; + } + public static void amain(String[] args) { + System.out.println(new BigDecimal("0").signum()); + } + +} diff --git a/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceita.java b/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceita.java new file mode 100644 index 000000000..5f77c7553 --- /dev/null +++ b/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceita.java @@ -0,0 +1,155 @@ +package com.rjconsultores.integracaoreceitadespesa.entidades; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +import org.apache.commons.lang.StringUtils; + +public class DespesaReceita { + protected String dataLancamento; // DD/MM/YYYY + protected String codigoEmpresa; // 011 003 Numerico + protected final String codigoFilial = "001"; // 014 003 Numerico + protected String localArrecadacao; // 017 005 Alfanumerico + protected final String numeroDaGuia = " "; // 022 025 Alfanumerico + protected String dataMovimento; // 047 010 Alfanumerico + protected final String usuarioGlobus = "TOTALBUS ";// 057 015 Alfanumerico + protected final String turno = "01";// 072 002 Numerico + protected String codigoReceitaDespesa;// 074 010 Numerico CONSTANTE CODIGO_RECEITA_DESPESA_GLOBUS + protected String identificadorReceitaDespesa;// 084 001 Alfanumerico + protected String valorLancamento;// 085 013 Numerico + protected final String numeroContratoTurismo = "0000000000"; // 098 010 Numerico + protected final String numeroReciboTurismo = " "; // 108 010 Alfanumerico + protected final String formaPagamentoTurismo = " ";// 118 002 Numerico + protected String tipoPagamentoTurismo = " ";// 120 002 Numerico + protected String descricaoDetalhada = "";// 122 80 Alfanumerico + protected final String documentoVenda = "000000";// 202 6 Numerico + protected final String tipoDocumentoVenda = " ";// 208 1 Alfanumerico + protected final String numerodocumentoCPG = "0000000000";// 209 10 Numerico + protected String formaPagamentoId = "0";// 218 Numerico + protected final String finalLinha = "*";// 239 1 Alfanumerico + + + protected SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); + + public DespesaReceita() { + + } + + public void preencheLinha(List rows) { + StringBuilder sb = new StringBuilder(); + sb.append(dataLancamento); + sb.append(codigoEmpresa); + sb.append(codigoFilial); + sb.append(localArrecadacao.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(StringUtils.rightPad("", 10, " ")); + sb.append(numeroReciboTurismo); + sb.append(getFormaPagamentoTurismo()); + sb.append(getTipoPagamentoTurismo()); + sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(descricaoDetalhada) ? truncStr(descricaoDetalhada, 100) : "", 100, " ")); + sb.append(documentoVenda); + sb.append(tipoDocumentoVenda); + sb.append(StringUtils.rightPad("", 9, "0")); + sb.append(formaPagamentoId); + sb.append(finalLinha); + sb.append(System.getProperty("line.separator")); + rows.add(sb.toString()); + } + + public void preencheLinhaLayoutNovo(List rows) { + StringBuilder sb = new StringBuilder(); + sb.append(StringUtils.rightPad(dataLancamento.trim(), 10, " ")); + sb.append(StringUtils.leftPad(codigoEmpresa.trim(), 3, "0")); + sb.append(StringUtils.leftPad(codigoFilial.trim(), 3, "0")); + sb.append(StringUtils.rightPad(localArrecadacao.toUpperCase().trim(), 5, " ")); + sb.append(StringUtils.rightPad(numeroDaGuia.trim(), 25, " ")); + sb.append(StringUtils.rightPad(dataMovimento.trim(), 10, " ")); + sb.append(StringUtils.rightPad(usuarioGlobus.trim(), 15, " ")); + sb.append(StringUtils.leftPad(turno.trim(), 2, "0")); + sb.append(StringUtils.leftPad(codigoReceitaDespesa.trim(), 10, "0")); + sb.append(StringUtils.rightPad(identificadorReceitaDespesa.toUpperCase().trim(), 1, " ")); + sb.append(StringUtils.leftPad(valorLancamento.trim(), 13, "0")); + sb.append(StringUtils.rightPad("", 10, " ")); + sb.append(StringUtils.rightPad(numeroReciboTurismo.trim(), 10, " ")); + sb.append(StringUtils.leftPad(getFormaPagamentoTurismo().trim(), 2, "0")); + sb.append(StringUtils.leftPad(getTipoPagamentoTurismo().trim(), 2, "0")); + sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(descricaoDetalhada) ? truncStr(descricaoDetalhada, 100) : "", 100, " ")); + sb.append(StringUtils.leftPad(documentoVenda.trim(), 6, "0")); + sb.append(StringUtils.rightPad(tipoDocumentoVenda.trim(), 1, " ")); + sb.append(StringUtils.rightPad("", 9, "0")); + sb.append(finalLinha); + sb.append(System.getProperty("line.separator")); + rows.add(sb.toString()); + } + + public void setDataLancamento(Date dataLancamento) { + this.dataLancamento = sdf.format(dataLancamento); + } + + public void setCodigoEmpresa(Integer codigoEmpresa) { + this.codigoEmpresa = StringUtils.leftPad(codigoEmpresa.toString(), 3, "0"); + } + + public void setLocalArrecadacao(Integer localArrecadacao) { + this.localArrecadacao = StringUtils.rightPad(localArrecadacao != null ? truncStr(localArrecadacao.toString(), 5) : "", 5, " "); + } + + public void setLocalArrecadacao(String localArrecadacao) { + this.localArrecadacao = StringUtils.rightPad(localArrecadacao != null ? truncStr(localArrecadacao, 6) : "", 5, ""); + } + + 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(); + } + + public void setValorLancamento(String valorLancamento) { + this.valorLancamento = StringUtils.leftPad(valorLancamento!=null?truncStr(valorLancamento.replace(",", "").replace(".", ""), 100):"", 13, "0"); + } + + public void setDescricaoDetalhada(String desc) { + this.descricaoDetalhada = StringUtils.rightPad(StringUtils.isNotEmpty(desc) ? truncStr(desc, 100) : "", 100, " "); + } + + public String getFormaPagamentoTurismo() { + return formaPagamentoTurismo; + } + + public String getTipoPagamentoTurismo() { + return tipoPagamentoTurismo; + } + + public void setTipoPagamentoTurismo(String tipoPagamentoTurismo) { + this.tipoPagamentoTurismo = StringUtils.leftPad(StringUtils.isNotEmpty(tipoPagamentoTurismo) ? truncStr(tipoPagamentoTurismo, 2):tipoPagamentoTurismo, 2, " "); + } + + public String getFormaPagamentoId() { + return formaPagamentoId; + } + + public void setFormaPagamentoId(String formaPagamentoId) { + this.formaPagamentoId = StringUtils.leftPad(StringUtils.isNotEmpty(formaPagamentoId) ? truncStr(formaPagamentoId.toString(), 2) : "", 1, "0"); + } + + protected String truncStr(String str, int size) { + if (str.length() > size) { + return str.substring(0, size - 1); + } + return str; + } + +} diff --git a/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceitaComporte.java b/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceitaComporte.java new file mode 100644 index 000000000..1fe8fe538 --- /dev/null +++ b/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceitaComporte.java @@ -0,0 +1,66 @@ +package com.rjconsultores.integracaoreceitadespesa.entidades; + +import java.util.List; + +import org.apache.commons.lang.StringUtils; + +public class DespesaReceitaComporte extends DespesaReceita { + + protected String numeroEstabelecimento; + protected String codigoAutorizacao; + protected String cantParcelas = ""; + + @Override + public void preencheLinha(List rows) { + StringBuilder sb = new StringBuilder(); + sb.append(dataLancamento); + sb.append(codigoEmpresa); + sb.append(codigoFilial); + sb.append(localArrecadacao.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(StringUtils.rightPad("", 80, " ")); + sb.append(StringUtils.rightPad(numeroEstabelecimento, 10, "0").substring(0,10)); + sb.append(StringUtils.rightPad(codigoAutorizacao, 6, "0").substring(0,6)); + sb.append(StringUtils.rightPad("", 16, " ")); + sb.append(StringUtils.rightPad("", 3, "0")); + sb.append(StringUtils.leftPad(formaPagamentoId, 2, "0")); + sb.append(cantParcelas); + sb.append(finalLinha); + sb.append(System.getProperty("line.separator")); + rows.add(sb.toString()); + } + + public String getNumeroEstabelecimento() { + return numeroEstabelecimento; + } + + public void setNumeroEstabelecimento(String numeroEstabelecimento) { + this.numeroEstabelecimento = StringUtils.rightPad(numeroEstabelecimento != null ? numeroEstabelecimento : "", 10, " "); + } + + public String getCodigoAutorizacao() { + return codigoAutorizacao; + } + + public void setCodigoAutorizacao(String codigoAutorizacao) { + this.codigoAutorizacao = StringUtils.rightPad(codigoAutorizacao != null ? truncStr(codigoAutorizacao, 22) : "", 22, "0"); + } + + public String getCantParcelas() { + return cantParcelas; + } + + public void setCantParcelas(String cantParcelas) { + this.cantParcelas = StringUtils.isNotEmpty(cantParcelas) ? StringUtils.leftPad(cantParcelas, 4,"0") : " "; + } +} diff --git a/src/com/rjconsultores/integracaoreceitadespesa/entidades/Empresa.java b/src/com/rjconsultores/integracaoreceitadespesa/entidades/Empresa.java new file mode 100644 index 000000000..debc1c81a --- /dev/null +++ b/src/com/rjconsultores/integracaoreceitadespesa/entidades/Empresa.java @@ -0,0 +1,11 @@ +package com.rjconsultores.integracaoreceitadespesa.entidades; + +public class Empresa { + public Integer codigo; + public String nombempresa; + + @Override + public String toString(){ + return nombempresa; + } +} diff --git a/src/com/rjconsultores/integracaoreceitadespesa/entidades/PuntoVenta.java b/src/com/rjconsultores/integracaoreceitadespesa/entidades/PuntoVenta.java new file mode 100644 index 000000000..62d041503 --- /dev/null +++ b/src/com/rjconsultores/integracaoreceitadespesa/entidades/PuntoVenta.java @@ -0,0 +1,11 @@ +package com.rjconsultores.integracaoreceitadespesa.entidades; + +public class PuntoVenta { + public Integer codigo; + public String nombpuntoventa; + + @Override + public String toString(){ + return nombpuntoventa; + } +}