Subversion Repositories Integrator Subversion

Rev

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