Rev 369 | Rev 414 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 353 | 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.controller.consultademanda.NotaFiscalConsultaPorDemanda; |
||
| 11 | import br.com.ec.core.generic.GenericService; |
||
| 12 | import br.com.ec.domain.dto.consulta.ParametrosConsultaNotaFiscal; |
||
| 13 | import br.com.ec.domain.model.NotaFiscal; |
||
| 413 | espaco | 14 | import br.com.ec.domain.model.Venda; |
| 353 | espaco | 15 | import br.com.ec.domain.model.nfe.TipoNotaFiscal; |
| 16 | import br.com.ec.domain.service.NotaFiscalService; |
||
| 17 | import br.com.ec.web.exception.VerificadorLancamentoException; |
||
| 18 | import br.com.ec.web.exception.VerificadorLancamentoException.CommandBean; |
||
| 19 | import br.com.ec.web.generic.AbstractBean; |
||
| 20 | import br.com.ec.web.message.LancadorMensagem; |
||
| 21 | import br.com.ec.web.util.TipoOperacao; |
||
| 22 | |||
| 23 | @Named |
||
| 24 | @Scope("view") |
||
| 25 | public class NotaFiscalBean extends AbstractBean<NotaFiscal> implements Serializable { |
||
| 26 | |||
| 27 | private static final long serialVersionUID = 1L; |
||
| 28 | |||
| 29 | private NotaFiscalService notaFiscalService; |
||
| 30 | |||
| 31 | private ParametrosConsultaNotaFiscal parametrosConsultaNotaFiscal; |
||
| 32 | private NotaFiscalConsultaPorDemanda lazy; |
||
| 33 | |||
| 34 | private Long sequencialVendaParaVinculo; |
||
| 35 | |||
| 36 | @Inject |
||
| 37 | public NotaFiscalBean(NotaFiscalConsultaPorDemanda lazy, NotaFiscalService notaFiscalService) { |
||
| 38 | this.lazy = lazy; |
||
| 39 | this.notaFiscalService = notaFiscalService; |
||
| 40 | } |
||
| 41 | |||
| 42 | @Override |
||
| 43 | public void preCarregamento() { |
||
| 44 | parametrosConsultaNotaFiscal = new ParametrosConsultaNotaFiscal(); |
||
| 45 | prepararConsultaDemanda(); |
||
| 46 | limparEntidade(); |
||
| 47 | } |
||
| 48 | |||
| 49 | @Override |
||
| 50 | public void limparEntidade() { |
||
| 51 | setEntidade(new NotaFiscal()); |
||
| 52 | } |
||
| 53 | |||
| 54 | @Override |
||
| 55 | public GenericService<NotaFiscal> getService() { |
||
| 56 | return notaFiscalService; |
||
| 57 | } |
||
| 58 | |||
| 59 | @Override |
||
| 60 | public NotaFiscal getEntidade() { |
||
| 61 | return entidade; |
||
| 62 | } |
||
| 63 | |||
| 64 | @Override |
||
| 65 | public void preConsultar() { |
||
| 66 | setTipoOperacao(TipoOperacao.CONSULTAR); |
||
| 67 | } |
||
| 68 | |||
| 69 | @Override |
||
| 70 | public NotaFiscal getId() { |
||
| 71 | return getEntidade(); |
||
| 72 | } |
||
| 73 | |||
| 74 | public ParametrosConsultaNotaFiscal getParametrosConsultaNotaFiscal() { |
||
| 75 | return parametrosConsultaNotaFiscal; |
||
| 76 | } |
||
| 77 | public void setParametrosConsultaNotaFiscal(ParametrosConsultaNotaFiscal parametrosConsultaNotaFiscal) { |
||
| 78 | this.parametrosConsultaNotaFiscal = parametrosConsultaNotaFiscal; |
||
| 79 | } |
||
| 80 | |||
| 81 | public NotaFiscalConsultaPorDemanda getLazy() { |
||
| 82 | return lazy; |
||
| 83 | } |
||
| 84 | public void setLazy(NotaFiscalConsultaPorDemanda lazy) { |
||
| 85 | this.lazy = lazy; |
||
| 86 | } |
||
| 87 | public void prepararConsultaDemanda() { |
||
| 88 | lazy.setarParametrosConsulta(getParametrosConsultaNotaFiscal()); |
||
| 89 | } |
||
| 90 | |||
| 91 | public TipoNotaFiscal[] getTiposNotaFiscal() { |
||
| 92 | return TipoNotaFiscal.values(); |
||
| 93 | } |
||
| 94 | |||
| 95 | public Long getSequencialVendaParaVinculo() { |
||
| 96 | return sequencialVendaParaVinculo; |
||
| 97 | } |
||
| 98 | public void setSequencialVendaParaVinculo(Long sequencialVendaParaVinculo) { |
||
| 99 | this.sequencialVendaParaVinculo = sequencialVendaParaVinculo; |
||
| 100 | } |
||
| 101 | |||
| 102 | /**************************************************/ |
||
| 103 | |||
| 104 | public void desvincularVenda() { |
||
| 105 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 106 | public void execute() { |
||
| 413 | espaco | 107 | notaFiscalService.desvincularVenda(getEntidade().getSequencial()); |
| 108 | getEntidade().setVenda(null); |
||
| 353 | espaco | 109 | LancadorMensagem.lancarSucesso("VENDA DESVINCULADA COM SUCESSO"); |
| 110 | } |
||
| 111 | }); |
||
| 112 | } |
||
| 113 | |||
| 114 | public void vincularVenda() { |
||
| 115 | new VerificadorLancamentoException().tratarIhRelancarExcecaoSemLimparEntidade(new CommandBean() { |
||
| 116 | public void execute() { |
||
| 413 | espaco | 117 | Venda vendaVinculada = notaFiscalService.vincularVenda(getEntidade().getSequencial(), getSequencialVendaParaVinculo()); |
| 118 | getEntidade().setVenda(vendaVinculada); |
||
| 353 | espaco | 119 | LancadorMensagem.lancarSucesso("VENDA VINCULADA COM SUCESSO"); |
| 120 | } |
||
| 121 | }); |
||
| 122 | } |
||
| 123 | |||
| 413 | espaco | 124 | /* |
| 125 | private StreamedContent chart; |
||
| 126 | public StreamedContent getChart() { |
||
| 127 | return chart; |
||
| 128 | } |
||
| 129 | private PieDataset createDataset() { |
||
| 130 | DefaultPieDataset dataset = new DefaultPieDataset(); |
||
| 131 | dataset.setValue("New York", new Double(45.0)); |
||
| 132 | dataset.setValue("London", new Double(15.0)); |
||
| 133 | dataset.setValue("Paris", new Double(25.2)); |
||
| 134 | dataset.setValue("Berlin", new Double(14.8)); |
||
| 135 | return dataset; |
||
| 136 | } |
||
| 137 | |||
| 138 | private StreamedContent escala; |
||
| 139 | public StreamedContent getEscala() { |
||
| 140 | return escala; |
||
| 141 | } |
||
| 142 | |||
| 143 | private StreamedContent escalaPdf; |
||
| 144 | public StreamedContent getEscalaPdf() { |
||
| 145 | return escalaPdf; |
||
| 146 | } |
||
| 147 | public String generateRandomIdForNotCaching() { |
||
| 148 | return java.util.UUID.randomUUID().toString(); |
||
| 149 | } |
||
| 150 | |||
| 151 | private void criarImagens() { |
||
| 152 | try { |
||
| 153 | InputStream arquivoPdf = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/imagens/escala-202310.pdf"); |
||
| 154 | byte[] bytePdf = ArquivoUtil.retornarBytesPassandoInputStream(arquivoPdf); |
||
| 155 | ByteArrayOutputStream osPdf = new ByteArrayOutputStream(); |
||
| 156 | PdfReader reader = new PdfReader(bytePdf); |
||
| 157 | escalaPdf = DefaultStreamedContent.builder() |
||
| 158 | .contentType("application/pdf") |
||
| 159 | .name("escala-202310.pdf") |
||
| 160 | .stream(() -> { |
||
| 161 | try { |
||
| 162 | return ArquivoUtil.gerarInputStreamDeArquivo(bytePdf); |
||
| 163 | } catch (IOException e1) { |
||
| 164 | e1.printStackTrace(); |
||
| 165 | } |
||
| 166 | return arquivoPdf; |
||
| 167 | }) |
||
| 168 | .build(); |
||
| 169 | |||
| 170 | |||
| 171 | InputStream arquivo = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/imagens/escala-202310.png"); |
||
| 172 | BufferedImage imagem = ImageIO.read(arquivo); |
||
| 173 | ByteArrayOutputStream os = new ByteArrayOutputStream(); |
||
| 174 | ImageIO.write(imagem, "png", os); |
||
| 175 | escala = DefaultStreamedContent.builder() |
||
| 176 | .contentType("image/png") |
||
| 177 | .stream(() -> new ByteArrayInputStream(os.toByteArray())) |
||
| 178 | .build(); |
||
| 179 | |||
| 180 | |||
| 181 | chart = DefaultStreamedContent.builder() |
||
| 182 | .contentType("image/png") |
||
| 183 | .stream(() -> { |
||
| 184 | try { |
||
| 185 | JFreeChart jfreechart = ChartFactory.createPieChart("Cities", createDataset(), true, true, false); |
||
| 186 | File chartFile = new File("dynamichart"); |
||
| 187 | ChartUtilities.saveChartAsPNG(chartFile, jfreechart, 375, 300); |
||
| 188 | return new FileInputStream(chartFile); |
||
| 189 | } |
||
| 190 | catch (Exception e) { |
||
| 191 | e.printStackTrace(); |
||
| 192 | return null; |
||
| 193 | } |
||
| 194 | }) |
||
| 195 | .build(); |
||
| 196 | } catch (IOException e1) { |
||
| 197 | // TODO Auto-generated catch block |
||
| 198 | e1.printStackTrace(); |
||
| 199 | } |
||
| 200 | } |
||
| 201 | */ |
||
| 353 | espaco | 202 | } |