From 0b80c378ed2ce1cd9ca231cb840171a0d2b04a37 Mon Sep 17 00:00:00 2001 From: leonardo Date: Wed, 23 Dec 2015 18:17:01 +0000 Subject: [PATCH] fixes bug #6938 git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@51519 d1611594-4594-4d17-8e1d-87c2c4800839 --- .checkstyle | 7 + .classpath | 4 +- .project | 1 + ...pse.jst.j2ee.ejb.annotations.xdoclet.prefs | 5 + .../org.eclipse.ltk.core.refactoring.prefs | 2 + .settings/org.eclipse.wst.common.component | 3 + .../org.eclipse.wst.ws.service.policy.prefs | 2 + .../RelatorioArquivoBGMController.java | 210 ++++++++++++++++++ .../ItemMenuRelatorioArquivoBGM.java | 86 +------ web/WEB-INF/i3-label_es_MX.label | 9 +- web/WEB-INF/i3-label_pt_BR.label | 8 +- .../relatorios/filtroRelatorioArquivoBGM.zul | 56 +++++ 12 files changed, 306 insertions(+), 87 deletions(-) create mode 100644 .checkstyle create mode 100644 .settings/org.eclipse.jst.j2ee.ejb.annotations.xdoclet.prefs create mode 100644 .settings/org.eclipse.ltk.core.refactoring.prefs create mode 100644 .settings/org.eclipse.wst.ws.service.policy.prefs create mode 100644 src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioArquivoBGMController.java create mode 100644 web/gui/relatorios/filtroRelatorioArquivoBGM.zul diff --git a/.checkstyle b/.checkstyle new file mode 100644 index 000000000..75246d341 --- /dev/null +++ b/.checkstyle @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.classpath b/.classpath index 35231eeb6..230c9871f 100644 --- a/.classpath +++ b/.classpath @@ -84,6 +84,7 @@ + @@ -103,9 +104,6 @@ - - - diff --git a/.project b/.project index 0c2f258f0..2abc9b24e 100644 --- a/.project +++ b/.project @@ -7,6 +7,7 @@ LibreriasAdmVenta CustomAdmVenta WSTotvs + IntegracaoReceitaDespesa diff --git a/.settings/org.eclipse.jst.j2ee.ejb.annotations.xdoclet.prefs b/.settings/org.eclipse.jst.j2ee.ejb.annotations.xdoclet.prefs new file mode 100644 index 000000000..af099af2a --- /dev/null +++ b/.settings/org.eclipse.jst.j2ee.ejb.annotations.xdoclet.prefs @@ -0,0 +1,5 @@ +XDOCLETBUILDERACTIVE=true +XDOCLETHOME= +XDOCLETUSEGLOBAL=true +XDOCLETVERSION=1.2.1 +eclipse.preferences.version=1 diff --git a/.settings/org.eclipse.ltk.core.refactoring.prefs b/.settings/org.eclipse.ltk.core.refactoring.prefs new file mode 100644 index 000000000..cfcd1d3c2 --- /dev/null +++ b/.settings/org.eclipse.ltk.core.refactoring.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index ca7baf1d7..0be854b3e 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -12,6 +12,9 @@ uses + + uses + diff --git a/.settings/org.eclipse.wst.ws.service.policy.prefs b/.settings/org.eclipse.wst.ws.service.policy.prefs new file mode 100644 index 000000000..6da2f3d07 --- /dev/null +++ b/.settings/org.eclipse.wst.ws.service.policy.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.wst.ws.service.policy.projectEnabled=false diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioArquivoBGMController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioArquivoBGMController.java new file mode 100644 index 000000000..f2e17215d --- /dev/null +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioArquivoBGMController.java @@ -0,0 +1,210 @@ +package com.rjconsultores.ventaboletos.web.gui.controladores.relatorios; + +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.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import javax.activation.MimetypesFileTypeMap; +import javax.sql.DataSource; + +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Controller; +import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.event.Event; +import org.zkoss.zul.Datebox; +import org.zkoss.zul.Filedownload; + +import com.rjconsultores.integracaoreceitadespesa.Arquivo; +import com.rjconsultores.integracaoreceitadespesa.dao.Totalbus; +import com.rjconsultores.ventaboletos.entidad.Empresa; +import com.rjconsultores.ventaboletos.entidad.PuntoVenta; +import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEmpresa; +import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxParada; +import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer; + +@Controller("relatorioArquivoBGMController") +@Scope("prototype") +public class RelatorioArquivoBGMController extends MyGenericForwardComposer { + + private static final long serialVersionUID = 1L; + private static Logger log = Logger.getLogger(RelatorioArquivoBGMController.class); + private static final int TAMANHO_BUFFER = 4096; // 4kb + + private MyComboboxEmpresa cmbEmpresa; + private MyComboboxParada cmbPuntoVenta; + private Datebox datInicial; + private Datebox datFinal; + + @Autowired + private DataSource dataSource; + + @Override + public void doAfterCompose(Component comp) throws Exception { + super.doAfterCompose(comp); + + } + + public void onClick$btnExecutarRelatorio(Event ev) throws Exception { + executarRelatorio(); + } + + /** + * @throws Exception + * + */ + private void executarRelatorio() throws Exception { + excluirArquivosZip(); + List files = new ArrayList(); + Calendar cal = Calendar.getInstance(); + // Seta primeiro dia da itera玢o + cal.setTime(datInicial.getValue()); + Calendar calFinal = Calendar.getInstance(); + calFinal.setTime(datFinal.getValue()); + // seta dia e m阺 finais para limite da itera玢o + int diaFinal = calFinal.get(Calendar.DAY_OF_MONTH); + int mesFinal = calFinal.get(Calendar.MONTH); + while (cal.get(Calendar.DAY_OF_MONTH) <= diaFinal && cal.get(Calendar.MONTH) <= mesFinal) { + String fileName = System.getProperty("jboss.server.log.dir") + "/BGM-" + cal.get(Calendar.YEAR) + "" + (cal.get(Calendar.MONTH) + 1) + "" + cal.get(Calendar.DAY_OF_MONTH) + ".txt"; + File file = new File(fileName); + + Totalbus totalbus = new Totalbus(dataSource.getConnection()); + + Arquivo.GravaArquivo(file.getAbsolutePath(), totalbus.getDespesasReceitas( + cmbPuntoVenta.getSelectedItem() == null ? null : ((PuntoVenta)cmbPuntoVenta.getSelectedItem().getValue()).getPuntoventaId(), + cmbPuntoVenta.getSelectedItem() == null ? null : ((Empresa)cmbPuntoVenta.getSelectedItem().getValue()).getEmpresaId(), + cal.getTime())); + // adiciona um dia para itera玢o + cal.add(Calendar.DAY_OF_MONTH, 1); + files.add(file); + } + + + String fileZip = System.getProperty("jboss.server.log.dir") + "\\ArquivosBGM.zip"; + FileInputStream inputStream; + + compactarArquivos(files, fileZip); + File filez = new File(fileZip); + if (filez.exists()) { + inputStream = new FileInputStream(filez); + Filedownload.save(inputStream, new MimetypesFileTypeMap().getContentType(filez), filez.getName()); + } + filez.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) { + throw new IOException(e.getMessage()); + } + } + + private void compactarArquivos(List arquivosEOuPastas, String arquivoDeSaida){ + System.out.println(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) { + e.printStackTrace(); + } + } + + 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(); + } + } + } + + public MyComboboxEmpresa getCmbEmpresa() { + return cmbEmpresa; + } + + public void setCmbEmpresa(MyComboboxEmpresa cmbEmpresa) { + this.cmbEmpresa = cmbEmpresa; + } + + public MyComboboxParada getCmbPuntoVenta() { + return cmbPuntoVenta; + } + + public void setCmbPuntoVenta(MyComboboxParada cmbPuntoVenta) { + this.cmbPuntoVenta = cmbPuntoVenta; + } + + public Datebox getDatInicial() { + return datInicial; + } + + public void setDatInicial(Datebox datInicial) { + this.datInicial = datInicial; + } + + public Datebox getDatFinal() { + return datFinal; + } + + public void setDatFinal(Datebox datFinal) { + this.datFinal = datFinal; + } + + +} diff --git a/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/relatorios/ItemMenuRelatorioArquivoBGM.java b/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/relatorios/ItemMenuRelatorioArquivoBGM.java index 7a57ab6f8..dfcb0b021 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/relatorios/ItemMenuRelatorioArquivoBGM.java +++ b/src/java/com/rjconsultores/ventaboletos/web/utilerias/menu/item/relatorios/ItemMenuRelatorioArquivoBGM.java @@ -1,27 +1,11 @@ package com.rjconsultores.ventaboletos.web.utilerias.menu.item.relatorios; -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.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; +import org.zkoss.util.resource.Labels; -import javax.activation.MimetypesFileTypeMap; -import javax.sql.DataSource; - -import org.zkoss.zul.Filedownload; - -import com.rjconsultores.integracaoreceitadespesa.Arquivo; -import com.rjconsultores.integracaoreceitadespesa.dao.Totalbus; +import com.rjconsultores.ventaboletos.web.utilerias.PantallaUtileria; import com.rjconsultores.ventaboletos.web.utilerias.menu.DefaultItemMenuSistema; -import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext; public class ItemMenuRelatorioArquivoBGM extends DefaultItemMenuSistema { - - private static final int TAMANHO_BUFFER = 4096; // 4kb public ItemMenuRelatorioArquivoBGM() { super("indexController.mniRelatorioArquivoBGM.label"); @@ -34,69 +18,7 @@ public class ItemMenuRelatorioArquivoBGM extends DefaultItemMenuSistema { @Override public void ejecutar() { - DataSource ds = null; - try { - ds = (DataSource) AppContext.getApplicationContext().getBean("dataSource"); - Totalbus totalbus = new Totalbus(ds.getConnection()); - String fileName = System.getProperty("jboss.server.log.dir") + "/arquivobgm.txt"; - String fileZip = System.getProperty("jboss.server.log.dir") + "/arquivobgm.zip"; - FileInputStream inputStream; - Arquivo.GravaArquivo(fileName, totalbus.getDespesasReceitas(null, null)); - - 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 (Exception e) { - e.printStackTrace(); - } finally { - try { - ds.getConnection().close(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - - 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(); - } - } + PantallaUtileria.openWindow("/gui/relatorios/filtroRelatorioArquivoBGM.zul", + Labels.getLabel("indexController.mniRelatorioArquivoBGM.label"), getArgs() ,desktop); } } diff --git a/web/WEB-INF/i3-label_es_MX.label b/web/WEB-INF/i3-label_es_MX.label index be2cfe8b2..735a8600a 100644 --- a/web/WEB-INF/i3-label_es_MX.label +++ b/web/WEB-INF/i3-label_es_MX.label @@ -6030,4 +6030,11 @@ editarConexionController.labelConexaoFixa = Conexi贸n Fijo editarConexionController.MSG.conexaoFixa1 = Informe la conexi贸n fijo del primero paso de la conexi贸n. editarConexionController.MSG.conexaoFixa2 = Informe la conexi贸n fijo del segundo paso de la conexi贸n. editarConexionController.MSG.conexaoFixa3 = Informe la conexi贸n fijo del tercero paso de la conexi贸n. -editarConexionController.MSG.conexaoFixa4 = Informe la conexi贸n fijo del cuarto paso de la conexi贸n. \ No newline at end of file +editarConexionController.MSG.conexaoFixa4 = Informe la conexi贸n fijo del cuarto paso de la conexi贸n. + + +# Relatorio Arquivo BGM +relatorioArquivoBGMController.lbDataIni.value = Data Inicial +relatorioArquivoBGMController.lbDataFin.value = Data Final +relatorioArquivoBGMController.lbEmpresa.value = Empresa +relatorioArquivoBGMController.lbPuntoVenta.value = Ag锚ncia diff --git a/web/WEB-INF/i3-label_pt_BR.label b/web/WEB-INF/i3-label_pt_BR.label index bf2b202d3..7a2c7cd79 100644 --- a/web/WEB-INF/i3-label_pt_BR.label +++ b/web/WEB-INF/i3-label_pt_BR.label @@ -6175,4 +6175,10 @@ relatorioObservacaoEventosFinanceirosController.btnCerrar.tooltiptext = Fechar relatorioObservacaoEventosFinanceirosController.lbDataIni.value = Data Inicio relatorioObservacaoEventosFinanceirosController.lbDataFin.value = Data Final relatorioObservacaoEventosFinanceirosController.lbEmpresa.value = Empresa -relatorioObservacaoEventosFinanceirosController.lbPuntoVenta.value = Punto venta \ No newline at end of file +relatorioObservacaoEventosFinanceirosController.lbPuntoVenta.value = Punto venta + +# Relatorio Arquivo BGM +relatorioArquivoBGMController.lbDataIni.value = Data Inicial +relatorioArquivoBGMController.lbDataFin.value = Data Final +relatorioArquivoBGMController.lbEmpresa.value = Empresa +relatorioArquivoBGMController.lbPuntoVenta.value = Ag锚ncia diff --git a/web/gui/relatorios/filtroRelatorioArquivoBGM.zul b/web/gui/relatorios/filtroRelatorioArquivoBGM.zul new file mode 100644 index 000000000..280bf03d9 --- /dev/null +++ b/web/gui/relatorios/filtroRelatorioArquivoBGM.zul @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +