Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
414 espaco 1
package br.com.ec.controller;
2
 
3
import java.io.Serializable;
4
 
5
import javax.inject.Inject;
6
import javax.inject.Named;
7
 
8
import org.springframework.context.annotation.Scope;
9
 
10
import br.com.ec.domain.service.EmissorRelatorioService;
11
 
12
@Named
13
@Scope("view")
14
public class EmissorRelatorioBean implements Serializable {
15
 
16
        private static final long serialVersionUID = 1L;
17
 
18
        private EmissorRelatorioService emissorRelatorioService;
19
 
20
        @Inject
21
        public EmissorRelatorioBean(EmissorRelatorioService emissorRelatorioService) {
22
                this.emissorRelatorioService = emissorRelatorioService;
23
        }
24
 
25
        /*
26
        public TipoRelatorioSistema[] getTiposRelatorioSistema() {
27
                return TipoRelatorioSistema.values();
28
        }
29
 
30
        public StreamedContent emitirNfce() {
31
                return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() {
32
                        @Override
33
                        public StreamedContent execute() {
34
                                FiltroDanfe filtro = new FiltroDanfe();
35
 
36
                                NotaFiscal nfce = new NotaFiscal();
37
 
38
//                              Pessoa pessoa = new Pessoa();
39
//                              pessoa.setNome("ESPAÇO CASE EPP");
40
//                              nfce.setEmitente(pessoa);
41
 
42
                                List<CompraProduto> listaCompraProduto = new ArrayList<CompraProduto>();
43
//                              CompraProduto item = new CompraProduto();
44
//                              Produto produto = new Produto();
45
//                              produto.setCodigo("12345");
46
//                              produto.setDescricao("TESTE");
47
//                              item.setProduto(produto);
48
//                              listaCompraProduto.add(item);
49
//                              nfce.setListaCompraProduto(listaCompraProduto);
50
//                             
51
//                              filtro.setNotaFiscal(nfce);
52
                                JasperPrint relatorio = emissorRelatorioService.emitirComprovante(filtro);
53
                                return RelatorioUtils.gerarPdf(relatorio, "NFCE");
54
                        }
55
                });
56
        }
57
 
58
        public StreamedContent emitirNfceEmPdf(final Venda venda) {
59
                return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() {
60
                        @Override
61
                        public StreamedContent execute() {
62
                                System.out.println("Emitir nota fiscal...");
63
                                //NotaFiscal notaFiscalEmitida...
64
 
65
                                FiltroDanfe filtro = new FiltroDanfe();
66
                                filtro.setNotaFiscal(preencherNotaFiscal(venda, true));
67
                                JasperPrint relatorio = emissorRelatorioService.emitirComprovante(filtro);
68
                                return RelatorioUtils.gerarPdf(relatorio, "NFCE");
69
                        }
70
                });
71
        }
72
 
73
        public StreamedContent emitirCupomEmPdf(final Venda venda) {
74
                return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() {
75
                        @Override
76
                        public StreamedContent execute() {
77
                                FiltroCupom filtro = new FiltroCupom();
78
                                filtro.setNotaFiscal(preencherNotaFiscal(venda, false));
79
                                JasperPrint relatorio = emissorRelatorioService.emitirComprovante(filtro);
80
                                return RelatorioUtils.gerarPdf(relatorio, "CUPOM");
81
                        }
82
                });
83
        }
84
        */
85
        /************************************************************************/
86
        /*
87
        private NotaFiscalDTO preencherNotaFiscal(Venda venda, boolean notaFiscal) {
88
                NotaFiscalDTO nfce = new NotaFiscalDTO();
89
                nfce.setPessoaJuridica(pessoaService.detalharPessoa(venda.getPessoaJuridicaDaLoja()));
90
                nfce.setEnderecoEmitente(new ArrayList<Endereco>(nfce.getPessoaJuridica().getEnderecos()).get(0));
91
                nfce.preencherItens(venda.getLancamentosValidos());
92
                nfce.preencherPagamentos(venda.getVendaFormaPagamentos());
93
 
94
                if (notaFiscal) {
95
                        // PREENCHER COM DADOS DA NOTA FISCAL EMITIDA
96
        //              Número: 1 Série: 1 Emissão: 25/03/2018 16:28:40
97
        //              Protocolo de Autorização: 327180000056573   25/03/2018 16:28:42
98
        //              http://nfce.sefaz.al.gov.br/QRCode/consultarNFCe.jsp?chNFe=27180321494821000100650010000000011000000011&nVersao=100&tpAmb=2&cDest=06256954459&dhEmi=323031382d30332d32355431363a32383a34302d30333a3030&vNF=11.50&vICMS=0.00&digVal=4e35376b3876386a4d3931483269386843546f4a767443354d41453d&cIdToken=000002&cHashQRCode=A0FC7AB12F30E66649C3FFFB275323FCD2AA0AD7
99
                        nfce.setNumero("1");
100
                        nfce.setSerie("1");
101
                        nfce.setDataHoraEmissao("25/03/2018 16:28:40");
102
                        nfce.setChave("2718 0321 4948 2100 0100 6500 1000 0000 0110 0000 0011");
103
                        nfce.setProtocoloAutorizacao("327180000056573   25/03/2018 16:28:42");
104
                        nfce.setCaminhoQrCode("http://nfce.sefaz.al.gov.br/QRCode/consultarNFCe.jsp?chNFe=27180321494821000100650010000000011000000011&nVersao=100&tpAmb=2&cDest=06256954459&dhEmi=323031382d30332d32355431363a32383a34302d30333a3030&vNF=11.50&vICMS=0.00&digVal=4e35376b3876386a4d3931483269386843546f4a767443354d41453d&cIdToken=000002&cHashQRCode=A0FC7AB12F30E66649C3FFFB275323FCD2AA0AD7");
105
                        nfce.setCpfCnpjConsumidor("062.569.544-59");
106
                }
107
                return nfce;
108
        }
109
 
110
        public void visualizarPdf(Venda venda) {
111
                FiltroCupom filtro = new FiltroCupom();
112
                filtro.setNotaFiscal(preencherNotaFiscal(venda, false));
113
                JasperPrint relatorio = emissorRelatorioService.emitirComprovante(filtro);
114
                byte[] bytePdf = null;
115
                try {
116
                        bytePdf = JasperExportManager.exportReportToPdf(relatorio);
117
                } catch (JRException e1) {
118
                        e1.printStackTrace();
119
                }
120
 
121
                FacesContext fc = FacesContext.getCurrentInstance();
122
            HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();
123
            response.reset();
124
            response.setContentType("application/pdf");
125
            response.setContentLength(bytePdf.length);
126
            response.setHeader("Content-disposition", "inline; filename=arquivo.pdf");
127
            try {
128
                response.getOutputStream().write(bytePdf);
129
                response.getOutputStream().flush();
130
                response.getOutputStream().close();
131
                fc.responseComplete();
132
             } catch (IOException e) {
133
                 e.printStackTrace();
134
             }
135
        }
136
 
137
        public void visualizarCupomParaImpressao(Venda venda) {
138
                FiltroCupom filtro = new FiltroCupom();
139
                filtro.setNotaFiscal(preencherNotaFiscal(venda, false));
140
                JasperPrint relatorio = emissorRelatorioService.emitirComprovante(filtro);
141
 
142
                byte[] imageBytes = null;
143
                try {
144
                        BufferedImage bufferedImage = (BufferedImage) JasperPrintManager.printPageToImage(relatorio, 0, 2.0f);
145
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
146
                ImageIO.write(bufferedImage,"png", baos );
147
                imageBytes = baos.toByteArray();
148
                } catch (Exception e1) {
149
                        e1.printStackTrace();
150
                }
151
 
152
                FacesContext fc = FacesContext.getCurrentInstance();
153
            HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();
154
            response.reset();
155
            response.setContentType("image/png");
156
            response.setContentLength(imageBytes.length);
157
            response.setHeader("Content-disposition", "inline; filename=cupom.png");
158
            try {
159
                response.getOutputStream().write(imageBytes);
160
                response.getOutputStream().flush();
161
                response.getOutputStream().close();
162
                fc.responseComplete();
163
             } catch (IOException e) {
164
                 e.printStackTrace();
165
             }
166
        }
167
        */
168
}