Blame |
Last modification |
View Log
| Download
| RSS feed
package br.com.ec.controller;
import java.io.Serializable;
import javax.inject.Inject;
import javax.inject.Named;
import org.springframework.context.annotation.Scope;
import br.com.ec.domain.service.EmissorRelatorioService;
@Named
@Scope
("view")
public class EmissorRelatorioBean
implements Serializable {
private static final long serialVersionUID = 1L
;
private EmissorRelatorioService emissorRelatorioService
;
@Inject
public EmissorRelatorioBean
(EmissorRelatorioService emissorRelatorioService
) {
this.
emissorRelatorioService = emissorRelatorioService
;
}
/*
public TipoRelatorioSistema[] getTiposRelatorioSistema() {
return TipoRelatorioSistema.values();
}
public StreamedContent emitirNfce() {
return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() {
@Override
public StreamedContent execute() {
FiltroDanfe filtro = new FiltroDanfe();
NotaFiscal nfce = new NotaFiscal();
// Pessoa pessoa = new Pessoa();
// pessoa.setNome("ESPAÇO CASE EPP");
// nfce.setEmitente(pessoa);
List<CompraProduto> listaCompraProduto = new ArrayList<CompraProduto>();
// CompraProduto item = new CompraProduto();
// Produto produto = new Produto();
// produto.setCodigo("12345");
// produto.setDescricao("TESTE");
// item.setProduto(produto);
// listaCompraProduto.add(item);
// nfce.setListaCompraProduto(listaCompraProduto);
//
// filtro.setNotaFiscal(nfce);
JasperPrint relatorio = emissorRelatorioService.emitirComprovante(filtro);
return RelatorioUtils.gerarPdf(relatorio, "NFCE");
}
});
}
public StreamedContent emitirNfceEmPdf(final Venda venda) {
return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() {
@Override
public StreamedContent execute() {
System.out.println("Emitir nota fiscal...");
//NotaFiscal notaFiscalEmitida...
FiltroDanfe filtro = new FiltroDanfe();
filtro.setNotaFiscal(preencherNotaFiscal(venda, true));
JasperPrint relatorio = emissorRelatorioService.emitirComprovante(filtro);
return RelatorioUtils.gerarPdf(relatorio, "NFCE");
}
});
}
public StreamedContent emitirCupomEmPdf(final Venda venda) {
return new VerificadorLancamentoException().verificarLancamentoException(new CommandRelatorioStreamedContent() {
@Override
public StreamedContent execute() {
FiltroCupom filtro = new FiltroCupom();
filtro.setNotaFiscal(preencherNotaFiscal(venda, false));
JasperPrint relatorio = emissorRelatorioService.emitirComprovante(filtro);
return RelatorioUtils.gerarPdf(relatorio, "CUPOM");
}
});
}
*/
/************************************************************************/
/*
private NotaFiscalDTO preencherNotaFiscal(Venda venda, boolean notaFiscal) {
NotaFiscalDTO nfce = new NotaFiscalDTO();
nfce.setPessoaJuridica(pessoaService.detalharPessoa(venda.getPessoaJuridicaDaLoja()));
nfce.setEnderecoEmitente(new ArrayList<Endereco>(nfce.getPessoaJuridica().getEnderecos()).get(0));
nfce.preencherItens(venda.getLancamentosValidos());
nfce.preencherPagamentos(venda.getVendaFormaPagamentos());
if (notaFiscal) {
// PREENCHER COM DADOS DA NOTA FISCAL EMITIDA
// Número: 1 Série: 1 Emissão: 25/03/2018 16:28:40
// Protocolo de Autorização: 327180000056573 25/03/2018 16:28:42
// 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
nfce.setNumero("1");
nfce.setSerie("1");
nfce.setDataHoraEmissao("25/03/2018 16:28:40");
nfce.setChave("2718 0321 4948 2100 0100 6500 1000 0000 0110 0000 0011");
nfce.setProtocoloAutorizacao("327180000056573 25/03/2018 16:28:42");
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");
nfce.setCpfCnpjConsumidor("062.569.544-59");
}
return nfce;
}
public void visualizarPdf(Venda venda) {
FiltroCupom filtro = new FiltroCupom();
filtro.setNotaFiscal(preencherNotaFiscal(venda, false));
JasperPrint relatorio = emissorRelatorioService.emitirComprovante(filtro);
byte[] bytePdf = null;
try {
bytePdf = JasperExportManager.exportReportToPdf(relatorio);
} catch (JRException e1) {
e1.printStackTrace();
}
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();
response.reset();
response.setContentType("application/pdf");
response.setContentLength(bytePdf.length);
response.setHeader("Content-disposition", "inline; filename=arquivo.pdf");
try {
response.getOutputStream().write(bytePdf);
response.getOutputStream().flush();
response.getOutputStream().close();
fc.responseComplete();
} catch (IOException e) {
e.printStackTrace();
}
}
public void visualizarCupomParaImpressao(Venda venda) {
FiltroCupom filtro = new FiltroCupom();
filtro.setNotaFiscal(preencherNotaFiscal(venda, false));
JasperPrint relatorio = emissorRelatorioService.emitirComprovante(filtro);
byte[] imageBytes = null;
try {
BufferedImage bufferedImage = (BufferedImage) JasperPrintManager.printPageToImage(relatorio, 0, 2.0f);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufferedImage,"png", baos );
imageBytes = baos.toByteArray();
} catch (Exception e1) {
e1.printStackTrace();
}
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();
response.reset();
response.setContentType("image/png");
response.setContentLength(imageBytes.length);
response.setHeader("Content-disposition", "inline; filename=cupom.png");
try {
response.getOutputStream().write(imageBytes);
response.getOutputStream().flush();
response.getOutputStream().close();
fc.responseComplete();
} catch (IOException e) {
e.printStackTrace();
}
}
*/
}