Subversion Repositories Integrator Subversion

Rev

Rev 462 | Rev 468 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
259 espaco 1
package br.com.ec.domain.dto;
2
 
3
import java.io.Serializable;
4
 
467 blopes 5
import br.com.ec.core.util.VerificadorUtil;
6
import br.com.ec.domain.model.NotaFiscal;
7
import br.com.ec.web.util.DataUtil;
8
 
259 espaco 9
public class NotaFiscalDTO implements Serializable {
10
 
11
        private static final long serialVersionUID = 1L;
12
 
462 blopes 13
        private Long sequencialNotaFiscal;
14
        private String chave;
15
 
259 espaco 16
        /*
17
        private Venda venda;
18
 
19
        private Pessoa pessoaJuridica;
20
        private Endereco enderecoEmitente;
21
        private List<NfceItemDTO> itens = new ArrayList<NfceItemDTO>();
22
        private List<NfcePagamentoDTO> pagamentos = new ArrayList<NfcePagamentoDTO>();
23
 
24
        private String numero = "";
25
        private String serie = "";
26
        private String dataHoraEmissao = "";
27
        private String protocoloAutorizacao = "";
28
        private String cpfCnpjConsumidor = "";
29
        private String caminhoQrCode = "";
30
        */
31
 
462 blopes 32
        public NotaFiscalDTO() {
33
                setChave("");
34
        }
35
 
467 blopes 36
        public NotaFiscalDTO(NotaFiscal notaFiscal) {
37
                /*
38
                this.setVenda(notaFiscal.getVenda());
39
                this.setNumero("" + notaFiscal.getNumeroNotaFiscal());
40
                this.setSerie(notaFiscal.getSerie());
41
                this.setChave(notaFiscal.getChave());
42
                this.setCaminhoQrCode(notaFiscal.getCaminhoQrcode());
43
//              this.setCpfCnpjConsumidor("NÃO INFORMADO");
44
                if (VerificadorUtil.naoEstaNulo(notaFiscal.getVenda())) {
45
                        if (VerificadorUtil.naoEstaNulo(notaFiscal.getVenda().getCliente())) {
46
                                this.setCpfCnpjConsumidor(notaFiscal.getVenda().getCliente().getCpfCnpj());
47
                        }
48
                }
49
        this.setDataHoraEmissao(DataUtil.retornarDataFormatadaEmFormatoTexto("yyyy-MM-dd HH:mm:ss", notaFiscal.getDataHoraEmissao()));
50
        this.setProtocoloAutorizacao(notaFiscal.getProtocoloAutorizacao());
51
        */
52
        }
53
 
462 blopes 54
        public static String CONSULTA_DTO_SIMPLES = "e.sequencial, e.chave";
55
        public NotaFiscalDTO(Long sequencial, String chave) {
56
                this.sequencialNotaFiscal = sequencial;
57
                this.chave = chave;
58
        }
59
 
60
        public Long getSequencialNotaFiscal() {
61
                return sequencialNotaFiscal;
62
        }
63
        public void setSequencialNotaFiscal(Long sequencialNotaFiscal) {
64
                this.sequencialNotaFiscal = sequencialNotaFiscal;
65
        }
66
 
67
        public String getChave() {
68
                return chave;
69
        }
70
        public void setChave(String chave) {
71
                this.chave = chave;
72
        }
73
 
259 espaco 74
        /*
75
        public NotaFiscalDTO(Venda venda) {
76
                this.venda = venda;
77
                if (VerificadorUtil.naoEstaNulo(venda.getCliente())) {
78
                        this.setCpfCnpjConsumidor(venda.getCliente().getCpfCnpj());
79
                } else {
80
                        this.setCpfCnpjConsumidor("NÃO INFORMADO");
81
                }
82
        }
83
 
84
        public NotaFiscalDTO(TNfeProc nfeProc, Venda vendaCompleta) {
85
                Pessoa pessoaJuridica = new Pessoa();
86
                pessoaJuridica.setCpfCnpj(nfeProc.getNFe().getInfNFe().getEmit().getCNPJ());
87
                this.setPessoaJuridica(pessoaJuridica);
88
 
89
                Endereco enderecoEmitente = new Endereco();
90
                enderecoEmitente.setLogradouro(nfeProc.getNFe().getInfNFe().getEmit().getEnderEmit().getXLgr());
91
                enderecoEmitente.setNumero(nfeProc.getNFe().getInfNFe().getEmit().getEnderEmit().getNro());
92
                enderecoEmitente.setComplemento(nfeProc.getNFe().getInfNFe().getEmit().getEnderEmit().getXCpl());
93
                enderecoEmitente.setBairro(nfeProc.getNFe().getInfNFe().getEmit().getEnderEmit().getXBairro());
94
                enderecoEmitente.setMunicipio(nfeProc.getNFe().getInfNFe().getEmit().getEnderEmit().getXMun());
95
                enderecoEmitente.setUnidadeFederativa(nfeProc.getNFe().getInfNFe().getEmit().getEnderEmit().getUF().name());
96
                this.setEnderecoEmitente(enderecoEmitente);
97
 
98
                List<NfceItemDTO> itens = new ArrayList<NfceItemDTO>();
99
                for (nfce.java.TNFe.InfNFe.Det detalhe : nfeProc.getNFe().getInfNFe().getDet()) {
100
                        NfceItemDTO item = new NfceItemDTO();
101
                        item.setSequencial(new Integer(detalhe.getNItem()));
102
 
103
                        StringBuilder descricaoCompleta = new StringBuilder();
104
                        descricaoCompleta.append(detalhe.getProd().getCProd());
105
                        descricaoCompleta.append(" - ");
106
                        descricaoCompleta.append(detalhe.getProd().getXProd());
107
                        descricaoCompleta.append(" 1 UN X R$");
108
                        descricaoCompleta.append(formatarValor(new Double(detalhe.getProd().getVUnCom())));
109
                        descricaoCompleta.append(" R$");
110
                        descricaoCompleta.append(formatarValor(new Double(detalhe.getProd().getVProd())));
111
                        item.setDescricao(descricaoCompleta.toString());
112
                        item.setQuantidade(new Integer(detalhe.getProd().getQCom().substring(0, detalhe.getProd().getQCom().indexOf("."))));
113
                        item.setValorUnitario(new Double(detalhe.getProd().getVUnCom()));
114
                        itens.add(item);
115
                }
116
                this.setItens(itens);
117
 
118
                // TODO: AINDA PREENCHENDO COM PAGAMENTOS DA VENDA
119
                this.preencherPagamentos(vendaCompleta.getVendaFormaPagamentos());
120
 
121
                this.setNumero(nfeProc.getNFe().getInfNFe().getIde().getNNF());
122
                this.setSerie(nfeProc.getNFe().getInfNFe().getIde().getSerie());
123
                this.setChave(nfeProc.getProtNFe().getInfProt().getChNFe());
124
                this.setCaminhoQrCode(nfeProc.getNFe().getInfNFeSupl().getQrCode());
125
                this.setCpfCnpjConsumidor("NÃO INFORMADO");
126
 
127
                if (VerificadorUtil.naoEstaNulo(nfeProc.getNFe().getInfNFe().getDest())) {
128
                        String cpfCnpjFormatado = "";
129
                        if (VerificadorUtil.naoEstaNuloOuVazio(nfeProc.getNFe().getInfNFe().getDest().getCPF())) {
130
                                cpfCnpjFormatado = StringUtil.formatarCpf(nfeProc.getNFe().getInfNFe().getDest().getCPF());
131
                        } else if (VerificadorUtil.naoEstaNuloOuVazio(nfeProc.getNFe().getInfNFe().getDest().getCNPJ())) {
132
                                cpfCnpjFormatado = StringUtil.formatarCnpj(nfeProc.getNFe().getInfNFe().getDest().getCNPJ());
133
                        }
134
                        this.setCpfCnpjConsumidor(cpfCnpjFormatado);
135
                }
136
                Date data;
137
                try {
138
                        data = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'-03:00'").parse(nfeProc.getNFe().getInfNFe().getIde().getDhEmi());
139
                        this.setDataHoraEmissao(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(data));
140
                } catch (ParseException e) {
141
                        e.printStackTrace();
142
                }
143
        this.setProtocoloAutorizacao(nfeProc.getProtNFe().getInfProt().getNProt());
144
        }
145
 
146
        public Long getSequencialNotaFiscal() {
147
                return sequencialNotaFiscal;
148
        }
149
        public void setSequencialNotaFiscal(Long sequencialNotaFiscal) {
150
                this.sequencialNotaFiscal = sequencialNotaFiscal;
151
        }
152
 
153
        public Venda getVenda() {
154
                return venda;
155
        }
156
        public void setVenda(Venda venda) {
157
                this.venda = venda;
158
        }
159
        public Long getSequencialDaVenda() {
160
                return VerificadorUtil.naoEstaNulo(getVenda())? getVenda().getSequencial() : null;
161
        }
162
 
163
        public Pessoa getPessoaJuridica() {
164
                return pessoaJuridica;
165
        }
166
        public void setPessoaJuridica(Pessoa pessoaJuridica) {
167
                this.pessoaJuridica = pessoaJuridica;
168
        }
169
 
170
        public Endereco getEnderecoEmitente() {
171
                return enderecoEmitente;
172
        }
173
        public void setEnderecoEmitente(Endereco enderecoEmitente) {
174
                this.enderecoEmitente = enderecoEmitente;
175
        }
176
 
177
        public List<NfceItemDTO> getItens() {
178
                return itens;
179
        }
180
        public void setItens(List<NfceItemDTO> itens) {
181
                this.itens = itens;
182
        }
183
 
184
        public List<NfcePagamentoDTO> getPagamentos() {
185
                return pagamentos;
186
        }
187
        public void setPagamentos(List<NfcePagamentoDTO> pagamentos) {
188
                this.pagamentos = pagamentos;
189
        }
190
 
191
        public String getNumero() {
192
                return numero;
193
        }
194
        public void setNumero(String numero) {
195
                this.numero = numero;
196
        }
197
 
198
        public String getSerie() {
199
                return serie;
200
        }
201
        public void setSerie(String serie) {
202
                this.serie = serie;
203
        }
204
 
205
        public String getDataHoraEmissao() {
206
                return dataHoraEmissao;
207
        }
208
        public void setDataHoraEmissao(String dataHoraEmissao) {
209
                this.dataHoraEmissao = dataHoraEmissao;
210
        }
211
 
212
        public String getChave() {
213
                return chave;
214
        }
215
        public void setChave(String chave) {
216
                this.chave = formatarChave(chave);
217
        }
218
 
219
        public String getProtocoloAutorizacao() {
220
                return protocoloAutorizacao;
221
        }
222
        public void setProtocoloAutorizacao(String protocoloAutorizacao) {
223
                this.protocoloAutorizacao = protocoloAutorizacao;
224
        }
225
 
226
        public String getCpfCnpjConsumidor() {
227
                if (VerificadorUtil.estaNulo(cpfCnpjConsumidor)) {
228
                        return "NÃO INFORMADO";
229
                }
230
                return cpfCnpjConsumidor;
231
        }
232
        public void setCpfCnpjConsumidor(String cpfCnpjConsumidor) {
233
                this.cpfCnpjConsumidor = cpfCnpjConsumidor;
234
        }
235
 
236
        public String getCpfCnpjConsumidorFormatado() {
237
                if (VerificadorUtil.estaNulo(cpfCnpjConsumidor)) {
238
                        return "NÃO INFORMADO";
239
                }
240
                return FormatarUtil.retornarCpfCnpjFormatado(StringUtil.retornarApenasNumeros(cpfCnpjConsumidor));
241
        }
242
 
243
        public String getCaminhoQrCode() {
244
                return caminhoQrCode;
245
        }
246
        public void setCaminhoQrCode(String caminhoQrCode) {
247
                this.caminhoQrCode = caminhoQrCode;
248
        }
249
        */
250
        /*******************************************************************/
251
        /*
252
        public String getRazaoSocialDaLoja() {
253
                return VerificadorUtil.naoEstaNulo(getPessoaJuridica())? getPessoaJuridica().getRazaoSocial() : "";
254
        }
255
 
256
        public String getCnpjDaLoja() {
257
                return VerificadorUtil.naoEstaNulo(getPessoaJuridica())? StringUtil.formatarCnpj(getPessoaJuridica().getCpfCnpj()) : "";
258
        }
259
 
260
        public String getCnpjMatrizDaLojaSemAcentos() {
261
                String cnpjMatriz = VerificadorUtil.naoEstaNulo(getPessoaJuridica())? getPessoaJuridica().getCpfCnpj() : "";
262
                return VerificadorUtil.naoEstaNuloOuVazio(cnpjMatriz)? cnpjMatriz.substring(0, 8) : "";
263
        }
264
 
265
        //TODO: ALTERAÇÃO PROVISÓRIA
266
        public String getEnderecoDoEmitente() {
267
                String numero = getEnderecoEmitente().getNumero();
268
                if (numero.equals("2650")) {
269
                        numero = "2990";
270
                }
271
                return getEnderecoEmitente().getLogradouro() + ", " + numero + ", " + getEnderecoEmitente().getComplemento() + ", " +
272
                                getEnderecoEmitente().getBairro() + ", " + getEnderecoEmitente().getMunicipio() + ", " + getEnderecoEmitente().getUnidadeFederativa();
273
        }
274
 
275
        public void preencherItens(List<Lancamento> lancamentos) {
276
                Integer sequencial = 1;
277
                for (Lancamento lancamento : lancamentos) {
278
                        NfceItemDTO item = new NfceItemDTO();
279
                        item.setSequencial(sequencial);
280
                        item.setSequencialProduto(lancamento.getProduto().getSequencial());
281
                        item.setDescricao(montagemDescricaoDoItem(lancamento));
282
                        item.setQuantidade(1);
283
                        item.setValorUnitario(lancamento.getValorVenda());
284
                        getItens().add(item);
285
                        sequencial++;
286
                }
287
        }
288
 
289
        public String montagemDescricaoDoItem(Lancamento lancamento) {
290
                StringBuilder descricaoCompleta = new StringBuilder();
291
                descricaoCompleta.append(lancamento.getProduto().getCodigo());
292
                descricaoCompleta.append(" - ");
293
                descricaoCompleta.append(lancamento.getDescricaoNotaFiscal());
294
                descricaoCompleta.append("  1 UN X ");
295
                descricaoCompleta.append(formatarValor(lancamento.getValorVenda()));
296
                descricaoCompleta.append("  R$");
297
                descricaoCompleta.append(formatarValor(lancamento.getValorVenda() * 1));
298
                return descricaoCompleta.toString();
299
        }
300
 
301
        public void preencherItensComanda(List<Lancamento> lancamentos) {
302
                Integer sequencial = 1;
303
                for (Lancamento lancamento : lancamentos) {
304
                        NfceItemDTO item = new NfceItemDTO();
305
                        item.setSequencial(sequencial);
306
                        item.setSequencialProduto(lancamento.getProduto().getSequencial());
307
                        item.setDescricao(montagemDescricaoDoItemComanda(lancamento));
308
                        item.setQuantidade(1);
309
                        item.setValorUnitario(lancamento.getValorVenda());
310
                        getItens().add(item);
311
                        sequencial++;
312
                }
313
        }
314
 
315
        public String montagemDescricaoDoItemComanda(Lancamento lancamento) {
316
                StringBuilder descricaoCompleta = new StringBuilder();
317
                descricaoCompleta.append(lancamento.getDescricaoComanda());
318
                descricaoCompleta.append("  R$");
319
                descricaoCompleta.append(formatarValor(lancamento.getValorVenda()));
320
                return descricaoCompleta.toString();
321
        }
322
 
323
        public void preencherPagamentos(List<VendaFormaPagamento> pagamentos) {
324
                for (VendaFormaPagamento vendaFormaPagamento : pagamentos) {
325
                        NfcePagamentoDTO pagamento = new NfcePagamentoDTO();
326
                        String formaDePagamento = vendaFormaPagamento.getFormaPagamento().getDescricao();
327
                        if (VerificadorUtil.naoEstaNulo(vendaFormaPagamento.getBandeiraCartao())) {
328
                                formaDePagamento = formaDePagamento + " (" + vendaFormaPagamento.getBandeiraCartao().getDescricao() + ") ";
329
                        }
330
                        pagamento.setFormaDePagamento(formaDePagamento);
331
                        pagamento.setValor(formatarValor(vendaFormaPagamento.getValorPagamento()));
332
                        getPagamentos().add(pagamento);
333
                }
334
        }
335
 
336
        public String getValorTotal() {
337
                Double total = 0.0;
338
                if (!VerificadorUtil.isListaNulaOuVazia(getItens())) {
339
                        for (NfceItemDTO item : getItens()) {
340
                                total = total + item.getValorTotal();
341
                        }
342
                }
343
                return formatarValor(total);
344
        }
345
 
346
        public String formatarChave(String chaveAcessoNF) {
347
                chaveAcessoNF = chaveAcessoNF.replace("NFe", "");
348
                return chaveAcessoNF.substring(0, 4) + " " +
349
                           chaveAcessoNF.substring(4, 8) + " " +
350
                           chaveAcessoNF.substring(8, 12) + " " +
351
                           chaveAcessoNF.substring(12, 16) + " " +
352
                           chaveAcessoNF.substring(16, 20) + " " +
353
                           chaveAcessoNF.substring(20, 24) + " " +
354
                           chaveAcessoNF.substring(24, 28) + " " +
355
                           chaveAcessoNF.substring(28, 32) + " " +
356
                           chaveAcessoNF.substring(32, 36) + " " +
357
                           chaveAcessoNF.substring(36, 40) + " " +
358
                           chaveAcessoNF.substring(40, 44);
359
        }
360
 
361
//      Número: 1 Série: 1 Emissão: 25/03/2018 16:28:40
362
//      Protocolo de Autorização: 327180000056573   25/03/2018 16:28:42
363
//      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
364
        */
365
        /*
366
        public String getNumeroSerieEmissao() {
367
                StringBuilder numeroSerieEmissao = new StringBuilder();
368
                numeroSerieEmissao.append("NÚMERO: ");
369
                numeroSerieEmissao.append(getNumero());
370
                numeroSerieEmissao.append(" SÉRIE: ");
371
                numeroSerieEmissao.append(getSerie());
372
                numeroSerieEmissao.append(" EMISSÃO: ");
373
                numeroSerieEmissao.append(getDataHoraEmissao());
374
                return numeroSerieEmissao.toString();
375
        }
376
 
377
        public String getProtocoloAutorizacaoDataHoraEmissao() {
378
                return "PROTOCOLO DE AUTORIZAÇÃO: " + getProtocoloAutorizacao();
379
        }
380
        */
381
        /*
382
        private String formatarValor(Double valor) {
383
                return String.format("%.2f", valor);
384
        }
385
        */
386
        /*
387
        @Transient
388
        public Double getTotalLancamentos() {
389
                Double total = 0.0;
390
                if (!VerificadorUtil.isListaNulaOuVazia(getListaLancamento())) {
391
                        for (Lancamento lancamento : getListaLancamento()) {
392
                                total = total + lancamento.getValorVenda();
393
                        }
394
                }
395
                return total;  
396
        }
397
 
398
        @Transient
399
        public Double getTotalPago() {
400
                Double total = 0.0;
401
                if (!VerificadorUtil.isListaNulaOuVazia(getListaFormaPagamento())) {
402
                        for (VendaFormaPagamento vendaFormaPagamento : getListaFormaPagamento()) {
403
                                total = total + vendaFormaPagamento.getValorPagamento();
404
                        }
405
                }
406
                return total;  
407
        }
408
        */
409
 
410
}