Subversion Repositories Integrator Subversion

Rev

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