diff --git a/IntegracaoReceitaDespesa/.gitignore b/IntegracaoReceitaDespesa/.gitignore new file mode 100644 index 000000000..d052193ef --- /dev/null +++ b/IntegracaoReceitaDespesa/.gitignore @@ -0,0 +1,10 @@ +/.classpath +/.project +/.settings +/target +/settings.xml +/dist +/.factorypath +/*.BASE.xml +/*.LOCAL.xml +/*.REMOTE.xml diff --git a/IntegracaoReceitaDespesa/pom.xml b/IntegracaoReceitaDespesa/pom.xml new file mode 100644 index 000000000..2ed0661eb --- /dev/null +++ b/IntegracaoReceitaDespesa/pom.xml @@ -0,0 +1,47 @@ + + 4.0.0 + br.com.rjconsultores + IntegracaoReceitaDespesa + 1.6.1 + + + + rj-releases + http://52.5.53.15:8081/nexus/content/repositories/releases/ + + + + + UTF-8 + UTF-8 + + + + src + + + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + + + + + org.apache.logging.log4j + log4j-core + 2.17.1 + + + commons-lang + commons-lang + 2.0 + + + + \ No newline at end of file diff --git a/IntegracaoReceitaDespesa/src/META-INF/MANIFEST.MF b/IntegracaoReceitaDespesa/src/META-INF/MANIFEST.MF new file mode 100644 index 000000000..254272e1c --- /dev/null +++ b/IntegracaoReceitaDespesa/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/Application.java b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/Application.java new file mode 100644 index 000000000..4a1ceea6a --- /dev/null +++ b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/Application.java @@ -0,0 +1,57 @@ +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.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + + +public class Application { + private static Application instance = null; + + private static final Logger log = LogManager.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/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/Arquivo.java b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/Arquivo.java new file mode 100644 index 000000000..c78751a3e --- /dev/null +++ b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/Arquivo.java @@ -0,0 +1,37 @@ +package com.rjconsultores.integracaoreceitadespesa; + +import java.io.Closeable; +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + + +public class Arquivo { + private static final Logger log = LogManager.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/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/BGMApplication.java b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/BGMApplication.java new file mode 100644 index 000000000..cabe11e3a --- /dev/null +++ b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/BGMApplication.java @@ -0,0 +1,270 @@ +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.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + + +import com.rjconsultores.integracaoreceitadespesa.dao.Totalbus; + +public class BGMApplication { + private static BGMApplication instance = null; + + private static final Logger log = LogManager.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.isReceitasDespesasComporte = isReceitasDespesasComporte; + 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, layoutNovo)); + + 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/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/IntegracaoReceitaDespesaException.java b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/IntegracaoReceitaDespesaException.java new file mode 100644 index 000000000..c38e2c744 --- /dev/null +++ b/IntegracaoReceitaDespesa/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/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/dao/Totalbus.java b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/dao/Totalbus.java new file mode 100644 index 000000000..78ef4ac70 --- /dev/null +++ b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/dao/Totalbus.java @@ -0,0 +1,1455 @@ +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.logging.log4j.LogManager; +import org.apache.logging.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 = LogManager.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"); + + private int formaPagoCieloLink = 0; + + public Totalbus(Connection con, Boolean isReceitasDespesasComporte, Boolean isReceitasDespesasOuroPrata) { + this.conn = con; + this.isReceitasDespesasComporte = isReceitasDespesasComporte; + this.isReceitasDespesasOuroPrata = isReceitasDespesasOuroPrata; + loadEmpresas(); + loadPuntosVenta(); + buscarFormaPagoCieloLink(); + } + + public Totalbus(Connection con, Boolean isReceitasDespesasComporte,Boolean isCodReceitaFixoBgm, Boolean isReceitasDespesasOuroPrata) { + this.conn = con; + this.isReceitasDespesasComporte = isReceitasDespesasComporte; + this.isReceitasDespesasOuroPrata = isReceitasDespesasOuroPrata; + this.isCodReceitaFixoBgm = isCodReceitaFixoBgm; + loadEmpresas(); + loadPuntosVenta(); + buscarFormaPagoCieloLink(); + } + + 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(); + buscarFormaPagoCieloLink(); + } + + public List getDespesasReceitas(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM, boolean isLayoutNovo) throws IntegracaoReceitaDespesaException{ + List rows = new ArrayList(); + if (isReceitasDespesasComporte){ + log.debug("gerando depositos..."); + List despesasReceitas = getDepositosComporte(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM, isLayoutNovo); + log.debug("gerando despesas..."); + despesasReceitas.addAll(getDespesasComporte(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM, isLayoutNovo)); + log.debug("gerando despesas cartão..."); + despesasReceitas.addAll(getDespesaCartaoDebCredComporte(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM)); + log.debug("gerando receitas..."); + despesasReceitas.addAll(getReceitasComporte(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM)); + + if( isLayoutNovo ) { + for (DespesaReceita item : despesasReceitas) { + item.preencheLinhaLayoutNovo(rows); + } + }else { + for (DespesaReceita item : despesasReceitas) { + item.preencheLinha(rows); + } + } + }else { + log.debug("gerando depositos..."); + List despesasReceitas = getDepositos(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM, isLayoutNovo); + log.debug("gerando despesas..."); + despesasReceitas.addAll(getDespesas(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM, isLayoutNovo)); + log.debug("gerando despesas cartão..."); + despesasReceitas.addAll(getDespesaCartaoDebCred(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM, isLayoutNovo)); + log.debug("gerando receitas..."); + despesasReceitas.addAll(getReceitas(puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM, isLayoutNovo)); + if(isReceitasDespesasOuroPrata) { + getContaCorrenteAgencia(despesasReceitas, puntoventaId, empresaId, fechaParam, incluiTipoPagamentoTurismoBGM); + } + 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("CASE WHEN cfp.formapago_id = 2 THEN 802 ELSE 803 END 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(" CASE WHEN cdp.formapago_id = 2 THEN 802 ELSE 803 END 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(" CASE WHEN OP.INDCREDITO = 1 THEN 802 ELSE 803 END contacontabil "); + 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(rs.getString(8)); + 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, boolean isLayoutNovo) 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")); + + if(isLayoutNovo) { + despesa.setTipoPagamentoTurismo("01"); + despesa.setFormaPagamentoId("03"); + despesa.setTipoDocumentoVenda("P"); + } + + 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(" 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(" b.numfoliosistema,"); + sb.append(" ct.tx_id, "); + sb.append(" b.num_bpe "); + 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(" left join boleto b on (b.boleto_id = ev.boleto_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," +formaPagoCieloLink+ ") "); + sb.append(" and tee.indtipo = 0 "); + + PreparedStatement stmt = null; + ResultSet rs = null; + String formaPagoCieloLinkStr = Integer.toString(formaPagoCieloLink); + + 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)); + if(StringUtils.isNotBlank(rs.getString(5)) && (rs.getString(5).equals("22") || rs.getString(5).equals("8101"))) { + despesa.setNumfoliosistema(rs.getString("num_bpe")); + }else { + despesa.setNumfoliosistema(""); + } + 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.getFormaPagamentoId().equals(formaPagoCieloLinkStr)) { + despesa.setCodigoAutorizacao(rs.getString("numautorizacion")); + despesa.setNumeroEstabelecimento(rs.getString("numeroEstabelecimento")); + }else { + despesa.setCodigoAutorizacao(""); + despesa.setNumeroEstabelecimento(""); + } + despesa.setTxId(rs.getString(12)); + 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, boolean isLayoutNovo) 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(" tee.desctipoevento, "); + sb.append(" fp.tipo_pago "); + 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 forma_pago fp on cdp.formapago_id = fp.formapago_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, tee.desctipoevento,fp.tipo_pago "); + + 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")); + + if(isLayoutNovo) { + if( rs.getString("desctipoevento").matches("EXCESSO.BAGAGEM") ) { + receita.setTipoDocumentoVenda("E"); + }else { + receita.setTipoDocumentoVenda("P"); + } + + receita.setTipoPagamentoTurismo("01"); + receita.setFormaPagamentoId( converteFormaPagamentoLayoutNovo(rs.getString("tipo_pago")) ); + + } + + 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(" case when (b.num_bpe is not null) then LPAD(b.num_bpe, 9,'0') else LPAD(' ',9,0) end as num_bpe, "); + sb.append(" ct.tx_id"); + 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(" LEFT JOIN boleto b on (b.boleto_id = ev.boleto_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; + String formaPagoCieloLinkStr = Integer.toString(formaPagoCieloLink); + 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.setNumfoliosistema(rs.getString(13)); + 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.getFormaPagamentoId().equals(formaPagoCieloLinkStr)) { + receita.setCodigoAutorizacao(rs.getString("numautorizacion")); + receita.setNumeroEstabelecimento(rs.getString("numeroestabelecimento")); + }else { + receita.setCodigoAutorizacao(""); + receita.setNumeroEstabelecimento(""); + } + receita.setTxId(rs.getString(14)); + 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, boolean isLayoutNovo ) 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")); + + if(isLayoutNovo) { + despesa.setTipoPagamentoTurismo("01"); + despesa.setFormaPagamentoId("01"); + despesa.setTipoDocumentoVenda("P"); + } + + 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, boolean isLayoutNovo) 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); + + if(isLayoutNovo) { + deposito.setTipoPagamentoTurismo("01"); + deposito.setFormaPagamentoId("04"); + deposito.setTipoDocumentoVenda("P"); + } + + depositos.add(deposito); + soma = soma.add(rsFechamentos.getBigDecimal(1)); + } + log.debug("Total depositos: " + soma); + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Depositos"); + } 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(); + } + + private String converteFormaPagamentoLayoutNovo(String formaPago) { + //lista de tipos: com.rjconsultores.ventaboletos.enums.TipoFormapago + if(formaPago == null) { + return ""; + } + + Integer converted = new Integer( formaPago); + switch (converted) { + case 0: + return "01"; + case 1: + return "03"; + case 2: + return "03"; + case 3: + return "05"; + case 4: + return "05"; + case 10: + return "02"; + case 11: + return "04"; + default: + return ""; + } + } + + 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()); + } + + + public List getDepositosComporte(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM, boolean isLayoutNovo) 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); + } + + DespesaReceitaComporte deposito = new DespesaReceitaComporte(); + 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); + + if(isLayoutNovo) { + deposito.setTipoPagamentoTurismo("01"); + deposito.setFormaPagamentoId("04"); + deposito.setTipoDocumentoVenda("P"); + } + depositos.add(deposito); + soma = soma.add(rsFechamentos.getBigDecimal(1)); + } + log.debug("Total depositos: " + soma); + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new IntegracaoReceitaDespesaException("Erro ao processar Depositos"); + } 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 List getDespesasComporte(Integer puntoventaId, Integer empresaId, Date fechaParam, boolean incluiTipoPagamentoTurismoBGM, boolean isLayoutNovo ) 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(" case when (b.num_bpe is not null) then LPAD(b.num_bpe, 9,'0') else LPAD(' ',9,0) end as num_bpe "); + 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 boleto b on b.boleto_id = ev.boleto_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()) { + 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(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")); + + if(isLayoutNovo) { + despesa.setTipoPagamentoTurismo("01"); + despesa.setFormaPagamentoId("01"); + despesa.setTipoDocumentoVenda("P"); + } + + despesa.setNumfoliosistema(rs.getString("num_bpe")); + 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 void buscarFormaPagoCieloLink() { + PreparedStatement pstmt = null; + ResultSet rs = null; + + try { + pstmt = getConnection().prepareStatement("Select formapago_id from forma_pago where tipo_carteira_digital = 'CIELO_LINK' and activo = 1"); + rs = pstmt.executeQuery(); + if (rs.getFetchSize() > 0) { + while (rs.next()) { + formaPagoCieloLink = 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); + } + } + } + + + +} diff --git a/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceita.java b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceita.java new file mode 100644 index 000000000..6b3f24de1 --- /dev/null +++ b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceita.java @@ -0,0 +1,223 @@ +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 String tipoDocumentoVenda = " ";// 208 1 Alfanumerico + protected final String numerodocumentoCPG = "0000000000";// 209 10 Numerico + protected String formaPagamentoId = "0";// 218 Numerico + protected String tx_id = " "; + protected String numFolioSistema = " "; + protected final String finalLinha = "*";// 239 1 Alfanumerico + + protected String numeroEstabelecimento = " "; + protected String codigoAutorizacao = " "; + protected String cantParcelas = "0000"; + + + 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 preencheLinhaComporte(List rows) { + StringBuilder sb = new StringBuilder(); + sb.append(StringUtils.rightPad(dataLancamento.trim(), 10, " ")); //10 + sb.append(StringUtils.leftPad(codigoEmpresa.trim(), 3, "0")); //13 + sb.append(StringUtils.leftPad(codigoFilial.trim(), 3, "0")); //16 + sb.append(StringUtils.rightPad(truncStr(localArrecadacao.toUpperCase(), 5), 5, " ")); //21 + sb.append(StringUtils.rightPad(numeroDaGuia.trim(), 25, " ")); //46 + sb.append(StringUtils.rightPad(dataMovimento.trim(), 10, " ")); //56 + sb.append(StringUtils.rightPad(usuarioGlobus.trim(), 15, " ")); //71 + sb.append(StringUtils.leftPad(turno.trim(), 2, "0")); //73 + sb.append(StringUtils.leftPad(codigoReceitaDespesa.trim(), 10, "0")); //83 + sb.append(StringUtils.rightPad(identificadorReceitaDespesa.toUpperCase().trim(), 1, " ")); //84 + sb.append(StringUtils.leftPad(valorLancamento.trim(), 13, "0")); //97 + sb.append(StringUtils.rightPad(numeroContratoTurismo.trim(), 10, "0")); //107 + sb.append(StringUtils.rightPad(numeroReciboTurismo.trim(), 10, "0")); //117 + sb.append(StringUtils.leftPad(getFormaPagamentoId().trim(), 2, "0")); //119 + sb.append(StringUtils.leftPad(getTipoPagamentoTurismo().trim(), 2, "0")); //121 + sb.append(StringUtils.rightPad(descricaoDetalhada.trim(), 80, " ")); //201 + sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(numeroEstabelecimento) ? StringUtils.rightPad(numeroEstabelecimento, 10, "0").substring(0,10) : "", 10, "0"));//211 + sb.append(codigoAutorizacao != null ? StringUtils.rightPad(codigoAutorizacao, 25, "0") : StringUtils.rightPad("", 25, "0")); //236 + sb.append(StringUtils.rightPad(formaPagamentoId.trim(), 2, "0")); //238 + sb.append(StringUtils.leftPad(cantParcelas.trim(), 4, "0")); //242 + sb.append(StringUtils.leftPad(numFolioSistema.trim(), 16, " ")); //258 + sb.append(StringUtils.leftPad(tx_id.trim(), 35, " ")); //293 + 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(truncStr(localArrecadacao.toUpperCase(), 5), 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(getFormaPagamentoId().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("", 10, "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; + } + + public String getTipoDocumentoVenda() { + return tipoDocumentoVenda; + } + + public void setTipoDocumentoVenda(String tipoDocumentoVenda) { + this.tipoDocumentoVenda = tipoDocumentoVenda; + } + + 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/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceitaComporte.java b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceitaComporte.java new file mode 100644 index 000000000..3a8431f52 --- /dev/null +++ b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/entidades/DespesaReceitaComporte.java @@ -0,0 +1,87 @@ +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 = ""; + protected String numfoliosistema = ""; + protected String txId = ""; + + @Override + public void preencheLinha(List rows) { + StringBuilder sb = new StringBuilder(); + sb.append(StringUtils.rightPad(dataLancamento.trim(), 10, " ")); //10 + sb.append(StringUtils.leftPad(codigoEmpresa.trim(), 3, "0")); //13 + sb.append(StringUtils.leftPad(codigoFilial.trim(), 3, "0")); //16 + sb.append(StringUtils.rightPad(truncStr(localArrecadacao.toUpperCase(), 5), 5, " ")); //21 + sb.append(StringUtils.rightPad(numeroDaGuia.trim(), 25, " ")); //46 + sb.append(StringUtils.rightPad(dataMovimento.trim(), 10, " ")); //56 + sb.append(StringUtils.rightPad(usuarioGlobus.trim(), 15, " ")); //71 + sb.append(StringUtils.leftPad(turno.trim(), 2, "0")); //73 + sb.append(StringUtils.leftPad(codigoReceitaDespesa.trim(), 10, "0")); //83 + sb.append(StringUtils.rightPad(identificadorReceitaDespesa.toUpperCase().trim(), 1, "0")); //84 + sb.append(StringUtils.leftPad(valorLancamento.trim(), 13, "0")); //97 + sb.append(StringUtils.leftPad(numeroContratoTurismo.trim(), 10, "0"));//107 + sb.append(StringUtils.leftPad(numeroReciboTurismo.trim(), 10, "0"));//117 + sb.append(StringUtils.leftPad(getFormaPagamentoTurismo().trim(),2,"0"));//119 + sb.append(StringUtils.leftPad(getTipoPagamentoTurismo().trim(), 2, "0"));//121 + sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(descricaoDetalhada) ? truncStr(descricaoDetalhada, 80) : "", 80, " ")); //201 + sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(numeroEstabelecimento) ? StringUtils.rightPad(numeroEstabelecimento, 10, "0").substring(0,10) : "", 10, "0")); //211 + sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(codigoAutorizacao) ? StringUtils.rightPad(codigoAutorizacao, 22, " ").substring(0,22) : "", 22, " "));//237 + sb.append(StringUtils.leftPad("0", 2, "0"));//239 + sb.append(StringUtils.leftPad(" ", 1, " "));//239 + sb.append(StringUtils.leftPad(formaPagamentoId, 2, "0"));//239 + sb.append(StringUtils.isNotEmpty(cantParcelas) ? StringUtils.leftPad(cantParcelas, 4,"0") : "0000");//243 + sb.append(StringUtils.leftPad(numfoliosistema,16, " "));//259 + sb.append(StringUtils.leftPad(txId,35, " "));//294 + 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 = codigoAutorizacao; + } + + public String getCantParcelas() { + return cantParcelas; + } + + public void setCantParcelas(String cantParcelas) { + this.cantParcelas = StringUtils.isNotEmpty(cantParcelas) ? StringUtils.leftPad(cantParcelas, 4,"0") : "0000"; + } + + public String getNumfoliosistema() { + return numfoliosistema; + } + + public void setNumfoliosistema(String numfoliosistema) { + this.numfoliosistema = StringUtils.leftPad(numfoliosistema != null ? numfoliosistema :StringUtils.leftPad(" ", 16) , 16, " "); + } + + public String getTxId() { + return txId; + } + + public void setTxId(String txId) { + this.txId = StringUtils.leftPad(txId != null ? truncStr(txId, 36) : StringUtils.leftPad(" ", 35), 35, " "); + } + +} diff --git a/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/entidades/Empresa.java b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/entidades/Empresa.java new file mode 100644 index 000000000..debc1c81a --- /dev/null +++ b/IntegracaoReceitaDespesa/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/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/entidades/PuntoVenta.java b/IntegracaoReceitaDespesa/src/com/rjconsultores/integracaoreceitadespesa/entidades/PuntoVenta.java new file mode 100644 index 000000000..62d041503 --- /dev/null +++ b/IntegracaoReceitaDespesa/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; + } +}