diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarPuntoVentaController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarPuntoVentaController.java index 95137c70e..88542272f 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarPuntoVentaController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/catalogos/EditarPuntoVentaController.java @@ -4,6 +4,14 @@ */ package com.rjconsultores.ventaboletos.web.gui.controladores.catalogos; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; import java.io.IOException; import java.math.BigDecimal; import java.sql.Connection; @@ -14,7 +22,10 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; +import javax.activation.MimetypesFileTypeMap; import javax.sql.DataSource; import org.apache.commons.collections.CollectionUtils; @@ -42,6 +53,7 @@ import org.zkoss.zul.Combobox; import org.zkoss.zul.Comboitem; import org.zkoss.zul.Datebox; import org.zkoss.zul.Doublebox; +import org.zkoss.zul.Filedownload; import org.zkoss.zul.Image; import org.zkoss.zul.Intbox; import org.zkoss.zul.Messagebox; @@ -213,6 +225,7 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer { private List lsEmpresaComissao; private List lsEstoque; private List lsPtovtaComissao; + private List lsLogFiles; private Radio radDatosTarjetaSi; private Radio radDatosTarjetaNo; private Radio radAprobacionAutorizado; @@ -257,8 +270,10 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer { private Combobox cmbEmpresas; private Combobox cmbCategorias; private Combobox cmbEmpresaFechamentoParamptovta; + private Combobox cmbLogFiles; private Button btnSalvarFormaPago; private Button btnApagar; + private Button btnShowLog; private Doublebox txtCargosExtras; private MyTextbox txtNome; private MyTextbox txtNumFax; @@ -318,11 +333,15 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer { private Textbox logResult; private boolean integracionTotvs; + private String logFileSelected; + public static final int INTERVALO_FECHAMENTO_SEMANAL = 7; public static final int INTERVALO_FECHAMENTO_DECENDIAL = 10; public static final int INTERVALO_FECHAMENTO_QUINZENAL = 15; public static final int INTERVALO_FECHAMENTO_MENSAL = 30; - + + private static final int TAMANHO_BUFFER = 4096; // 4kb + @Autowired private DataSource dataSource; @@ -342,6 +361,17 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer { ; } + private List getLogFiles(){ + List files = new ArrayList(); + File logDir = new File(System.getProperty("jboss.server.log.dir")); + for (String str : logDir.list()){ + if (str.contains("ws") && !str.contains("zip")){ + files.add(str); + } + } + return files; + } + @Override public void doAfterCompose(Component comp) throws Exception { @@ -358,7 +388,8 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer { lsFormaPago = formaPagoService.obtenerTodos(); lsTipoPuntoVenta = tipoPuntoVentaService.obtenerTodosExceto(TipoPuntoVenta.TODOS); lsUsuarioBancario = usuarioBancarioService.obtenerTodos(); - + lsLogFiles = getLogFiles(); + popularCombobox(cmbTipoConta, cmbPessoa, cmbForm, cmbLote, cmbPosicao, cmbReceita, cmbEmpresas, cmbCategorias); ptovtaEmpresasBloqueadasList.setItemRenderer(new RenderEmpresaBloquear()); @@ -665,6 +696,45 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer { txtNome.focus(); } + public void onClick$btnDownload(Event event) { + String fileName = System.getProperty("jboss.server.log.dir") + "\\" + cmbLogFiles.getSelectedItem().getValue().toString(); + String fileZip = System.getProperty("jboss.server.log.dir") + "\\" + cmbLogFiles.getSelectedItem().getValue().toString().replace("log", "zip"); + FileInputStream inputStream; + try { + excluirArquivosZip(); + compactarArquivo(fileZip, fileName); + File file = new File(fileZip); + if (file.exists()) { + inputStream = new FileInputStream(file); + Filedownload.save(inputStream, new MimetypesFileTypeMap().getContentType(file), file.getName()); + } + file.delete(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private String readFile(String fileName) throws IOException { + BufferedReader br = new BufferedReader(new FileReader(fileName)); + try { + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + + while (line != null) { + sb.append(line); + sb.append("\n"); + line = br.readLine(); + } + return sb.toString(); + } finally { + br.close(); + } + } + @Transactional public boolean validaFuncionTipoBoletoBloqueado() { List listClavesPermisos = new ArrayList(); @@ -2349,6 +2419,15 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer { this.txtRazonSocial = txtRazonSocial; } + + public String getLogFileSelected() { + return logFileSelected; + } + + public void setLogFileSelected(String logFileSelected) { + this.logFileSelected = logFileSelected; + } + public void onChange$cmbPuntoVentaPadre(Event ev) throws InterruptedException { if (puntoVenta.getPuntoventaId() != null) { List lsPuntosSubordinados = puntoVentaService.buscarPuntoVentaSubordinados(puntoVenta); @@ -2544,4 +2623,57 @@ public class EditarPuntoVentaController extends MyGenericForwardComposer { public void setIntegracionTotvs(boolean integracionTotvs) { this.integracionTotvs = integracionTotvs; } + + public List getLsLogFiles() { + return lsLogFiles; + } + + public void setLsLogFiles(List lsLogFiles) { + this.lsLogFiles = lsLogFiles; + } + + public Button getBtnShowLog() { + return btnShowLog; + } + + public void setBtnShowLog(Button btnShowLog) { + this.btnShowLog = btnShowLog; + } + + 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) { + throw new IOException(e.getMessage()); + } + } + + private void excluirArquivosZip(){ + File pasta = new File(System.getProperty("jboss.server.log.dir")); + File[] arquivos = pasta.listFiles(); + + for(File arquivo : arquivos) { + if(arquivo.getName().endsWith("zip")) { + arquivo.delete(); + } + } + } } diff --git a/web/WEB-INF/i3-label_es_MX.label b/web/WEB-INF/i3-label_es_MX.label index 7bb159533..692ac41f6 100644 --- a/web/WEB-INF/i3-label_es_MX.label +++ b/web/WEB-INF/i3-label_es_MX.label @@ -906,6 +906,8 @@ editarPuntoVentaController.lbCheckCredito.value=CC editarPuntoVentaController.lbCheckDebito.value=CD editarPuntoVentaController.lbCheckTF.value=TF editarPuntoVentaController.lbCheckBoletos.value=BOL +editarPuntoVentaController.lbFileLog.value=Arquivos Log +editarPuntoVentaController.btnDownload.tooltiptext=Download # Fechamento Conta Corrente Agencia editarPuntoVentaController.puntoventa.label = Agencia diff --git a/web/WEB-INF/i3-label_pt_BR.label b/web/WEB-INF/i3-label_pt_BR.label index f2363cc8b..fbd0600bc 100644 --- a/web/WEB-INF/i3-label_pt_BR.label +++ b/web/WEB-INF/i3-label_pt_BR.label @@ -943,6 +943,8 @@ editarPuntoVentaController.lbCheckCredito.value=CC editarPuntoVentaController.lbCheckDebito.value=CD editarPuntoVentaController.lbCheckTF.value=TF editarPuntoVentaController.lbCheckBoletos.value=BOL +editarPuntoVentaController.lbFileLog.value=Arquivos Log +editarPuntoVentaController.btnDownload.tooltiptext=Download # Fechamento Conta Corrente Agencia editarPuntoVentaController.puntoventa.label = Agencia diff --git a/web/gui/catalogos/editarPuntoVenta.zul b/web/gui/catalogos/editarPuntoVenta.zul index beb0e3631..2c904e63f 100644 --- a/web/gui/catalogos/editarPuntoVenta.zul +++ b/web/gui/catalogos/editarPuntoVenta.zul @@ -1336,7 +1336,7 @@ - + @@ -1393,8 +1393,21 @@ height="20" image="/gui/img/icon-active.gif" width="35px" tooltiptext="${c:l('busquedaEmpresaController.btnIntegracao.tooltiptext')}" /> + +