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