/// <summary> /// Cria um novo objeto do tipo Imposto. Cada nota Fiscal possui um ou vários produtos. Cada produto possui imposto. /// </summary> /// <param name="pos">Passa a posição do item da lista de produtos na nota fiscal que está sendo lido</param> /// <param name="nfeProc">Um objeto do tipo TNfeProc</param> /// <returns></returns> public Imposto ImpostoNotaFiscal(int pos, TNfeProc nfeProc) { try { // checar se já existe um arquivo resumo nota fiscal salvo no dropbox local string recuperaArquivo = BuscaArquivoTxt(); Imposto imposto = new Imposto(); imposto.NCM = nfeProc.NFe.infNFe.det[pos].prod.NCM; imposto.TipoReceita = nfeProc.NFe.infNFe.ide.natOp; //natureza operação? imposto.AliquotaOrigem = Convert.ToDecimal(buscaAliquotaOrigem); // aliD = "18" -> valor atual da alíquota de destino de sergipe; imposto.AliquotaDestino = Convert.ToDecimal(aliD); if (recuperaArquivo != " " && recuperaArquivo != null) { var tupla = LerArquivoTxt(recuperaArquivo, imposto.NCM, buscaAliquotaOrigem, aliD); string mva = tupla.Item2; if (String.IsNullOrEmpty(mva).Equals(false)) { imposto.DataAtualizacaoMVA = tupla.Item1; imposto.MVA = Convert.ToDecimal(tupla.Item2); } } return(imposto); } catch (Exception ex) { MessageBox.Show(string.Format("Não foi possível criar o objeto Imposto. Erro: {0}", ex.Message), "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
public NotasFiscais NovoObjeto(TNfeProc nfeProc, string arquivo, int posicao) { try { NotasFiscais notasFiscais = new NotasFiscais(); notasFiscais.Numero = nfeProc.NFe.infNFe.ide.nNF; // notasFiscais.Numero = nfeProc.NFe.infNFe.ide.nNF; notasFiscais.NomeFornecedor = nfeProc.NFe.infNFe.emit.xNome; notasFiscais.CnpjFornecedor = RetornaCnpjFornecedor(arquivo, posicao); notasFiscais.DataEmissao = nfeProc.NFe.infNFe.ide.dhEmi; DateTime converterData = Convert.ToDateTime(notasFiscais.DataEmissao); string strDate = converterData.ToString("dd/MM/yyyy"); notasFiscais.DataEmissao = strDate; string valorProdutos = nfeProc.NFe.infNFe.total.ICMSTot.vProd; var vp = valorProdutos.Replace('.', ','); string valorFrete = nfeProc.NFe.infNFe.total.ICMSTot.vFrete; var vf = valorFrete.Replace('.', ','); string valorTotal = nfeProc.NFe.infNFe.total.ICMSTot.vNF; var vt = valorTotal.Replace('.', ','); notasFiscais.ValorProdutos = Math.Round(Convert.ToDecimal(vp), 2); notasFiscais.ValorFrete = Math.Round(Convert.ToDecimal(vf), 2); notasFiscais.ValorTotal = Math.Round(Convert.ToDecimal(vt), 2); return(notasFiscais); } catch (Exception ex) { MessageBox.Show(String.Format("Não foi possível criar o objeto NotasFiscais. Erro: {0}", ex.Message), "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
public long Importar(TNfeProc nfe) { try { string numeroNF = nfe.NFe.infNFe.ide.nNF; string cpf_cnpjFornecedor = nfe.NFe.infNFe.emit.Item; IEnumerable <Entrada> entradas = ObterPorNumeroNotaFiscalFornecedor(numeroNF, cpf_cnpjFornecedor); if (entradas.Count() > 0) { Entrada entrada = entradas.ElementAtOrDefault(0); RecuperarDadosEntrada(nfe, entrada); GerenciadorEntrada.GetInstance().Atualizar(entrada); return(entrada.CodEntrada); } else { Entrada entrada = new Entrada(); RecuperarDadosEntrada(nfe, entrada); long codEntrada = GerenciadorEntrada.GetInstance().Inserir(entrada); return(codEntrada); } } catch (Exception e) { throw new NegocioException("Problema durante a importação dos dados da Entrada da NF-e. Favor contactar administrador.", e); } }
/// <summary> /// Serializes current TNfeProc object into an XML document /// </summary> /// <returns>string XML value</returns> public static string Serialize(TNfeProc nfe, System.Text.Encoding encoding) { System.IO.StreamReader streamReader = null; System.IO.MemoryStream memoryStream = null; try { memoryStream = new System.IO.MemoryStream(); System.Xml.XmlWriterSettings xmlWriterSettings = new System.Xml.XmlWriterSettings(); xmlWriterSettings.Encoding = encoding; System.Xml.XmlWriter xmlWriter = XmlWriter.Create(memoryStream, xmlWriterSettings); Serializer.Serialize(xmlWriter, nfe); memoryStream.Seek(0, System.IO.SeekOrigin.Begin); streamReader = new System.IO.StreamReader(memoryStream); return(streamReader.ReadToEnd()); } finally { if ((streamReader != null)) { streamReader.Dispose(); } if ((memoryStream != null)) { memoryStream.Dispose(); } } }
public void Assinar(ref TNfeProc nota) { if (Certificado == null) { throw new Exception("O Certificado Digital não está Configurado."); } nota.NFe = AssinarNFE(nota.NFe, "infNFe"); }
private void UpdateAdicionais(TNfeProc nota, IList <PostResultItem> adicionais) { var infAdFisco = GetValue(adicionais, "Descrição").Trim(); if (!string.IsNullOrWhiteSpace(infAdFisco)) { nota.NFe.infNFe.infAdic = new TNFeInfNFeInfAdic(); nota.NFe.infNFe.infAdic.infAdFisco = infAdFisco; } }
public TNfeProc LerNFE(string arquivo) { XmlDocument xmldocRetorno = new XmlDocument(); xmldocRetorno.Load(arquivo); XmlNodeReader xmlReaderRetorno = new XmlNodeReader(xmldocRetorno.DocumentElement); XmlSerializer serializer = new XmlSerializer(typeof(TNfeProc)); TNfeProc nfe = (TNfeProc)serializer.Deserialize(xmlReaderRetorno); return(nfe); }
/// <summary> /// Serializes current TNfeProc object into file /// </summary> /// <param name="fileName">full path of outupt xml file</param> /// <param name="exception">output Exception value if failed</param> /// <returns>true if can serialize and save into file; otherwise, false</returns> public virtual bool SaveToFile(string fileName, TNfeProc nfe, System.Text.Encoding encoding, out System.Exception exception) { exception = null; try { SaveToFile(fileName, nfe, encoding); return(true); } catch (System.Exception e) { exception = e; return(false); } }
public static string ToPDF(TNfeProc nota, ConfiguracaoHiperNFe config) { try { var arquivoPDF = nota.NFe.NomeArquivo.Replace(".xml", ".pdf"); var danfe = Print.DANFE(nota, config); danfe.ExportToDisk(ExportFormatType.PortableDocFormat, arquivoPDF); return arquivoPDF; } catch (Exception ex) { throw new Exception("Erro ao gerar o arquivo do DANFE: " + ex.Message); } }
public static string ToPDF(TNfeProc nota, ConfiguracaoHiperNFe config) { try { var arquivoPDF = nota.NFe.NomeArquivo.Replace(".xml", ".pdf"); var danfe = Print.DANFE(nota, config); danfe.ExportToDisk(ExportFormatType.PortableDocFormat, arquivoPDF); return(arquivoPDF); } catch (Exception ex) { throw new Exception("Erro ao gerar o arquivo do DANFE: " + ex.Message); } }
/// <summary> /// Deserializes workflow markup into an TNfeProc object /// </summary> /// <param name="xml">string workflow markup to deserialize</param> /// <param name="obj">Output TNfeProc object</param> /// <param name="exception">output Exception value if deserialize failed</param> /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns> public static bool Deserialize(string xml, out TNfeProc obj, out System.Exception exception) { exception = null; obj = default(TNfeProc); try { obj = Deserialize(xml); return(true); } catch (System.Exception ex) { exception = ex; return(false); } }
private void RecuperarDadosEntrada(TNfeProc nfe, Entrada entrada) { CultureInfo ci = new CultureInfo("en-US"); // usado para connversão dos números do xml entrada.CodEmpresaFrete = ObterInserirEmpresaFrete(nfe.NFe); entrada.CodFornecedor = ObterInserirFornecedor(nfe.NFe); entrada.CodSituacaoPagamentos = SituacaoPagamentos.ABERTA; entrada.CodTipoEntrada = Entrada.TIPO_ENTRADA; entrada.DataEmissao = Convert.ToDateTime(nfe.NFe.infNFe.ide.dhEmi); entrada.DataEntrada = DateTime.Now; entrada.Desconto = Convert.ToDecimal(nfe.NFe.infNFe.total.ICMSTot.vDesc, ci); entrada.FretePagoEmitente = nfe.NFe.infNFe.transp.modFrete == TNFeInfNFeTranspModFrete.Item0; // Frete pago emitente entrada.NumeroNotaFiscal = nfe.NFe.infNFe.ide.nNF; entrada.OutrasDespesas = Convert.ToDecimal(nfe.NFe.infNFe.total.ICMSTot.vOutro, ci); entrada.TotalBaseCalculo = Convert.ToDecimal(nfe.NFe.infNFe.total.ICMSTot.vBC, ci); entrada.TotalBaseSubstituicao = Convert.ToDecimal(nfe.NFe.infNFe.total.ICMSTot.vBCST, ci); entrada.TotalICMS = Convert.ToDecimal(nfe.NFe.infNFe.total.ICMSTot.vICMS, ci); entrada.TotalIPI = Convert.ToDecimal(nfe.NFe.infNFe.total.ICMSTot.vIPI, ci); entrada.TotalNota = Convert.ToDecimal(nfe.NFe.infNFe.total.ICMSTot.vNF, ci); entrada.TotalProdutos = Convert.ToDecimal(nfe.NFe.infNFe.total.ICMSTot.vProd, ci); entrada.Serie = nfe.NFe.infNFe.ide.serie; entrada.Chave = nfe.NFe.infNFe.Id.Substring(3); // retira o inicio nfe // precisa calcular entrada.TotalProdutosST = 0; foreach (TNFeInfNFeDet produto in nfe.NFe.infNFe.det) { for (int i = 0; i < produto.imposto.Items.Length; i++) { if (produto.imposto.Items[i] is TNFeInfNFeDetImpostoICMS) { var icms = ((TNFeInfNFeDetImpostoICMS)produto.imposto.Items[i]).Item; if ((icms is TNFeInfNFeDetImpostoICMSICMS10) || (icms is TNFeInfNFeDetImpostoICMSICMS30) || (icms is TNFeInfNFeDetImpostoICMSICMS60) || (icms is TNFeInfNFeDetImpostoICMSICMS70) || (icms is TNFeInfNFeDetImpostoICMSICMSSN202) || (icms is TNFeInfNFeDetImpostoICMSICMSSN201) || (icms is TNFeInfNFeDetImpostoICMSICMSSN500)) { entrada.TotalProdutosST += Convert.ToDecimal(produto.prod.vProd, ci); } } } } entrada.TotalSubstituicao = Convert.ToDecimal(nfe.NFe.infNFe.total.ICMSTot.vST, ci); entrada.ValorFrete = Convert.ToDecimal(nfe.NFe.infNFe.total.ICMSTot.vFrete, ci); entrada.ValorSeguro = Convert.ToDecimal(nfe.NFe.infNFe.total.ICMSTot.vSeg, ci); }
public virtual void SaveToFile(string fileName, TNfeProc nfe, System.Text.Encoding encoding) { System.IO.StreamWriter streamWriter = null; try { string xmlString = Serialize(nfe, encoding); streamWriter = new System.IO.StreamWriter(fileName, false, Encoding.UTF8); streamWriter.WriteLine(xmlString); streamWriter.Close(); } finally { if ((streamWriter != null)) { streamWriter.Dispose(); } } }
public TNfeProc DesserializarNota(string arquivo) { try { TNfeProc nfe = new TNfeProc(); GerenciadorNfe gerenciadorNfe = new GerenciadorNfe(); nfe = gerenciadorNfe.LerNFE(arquivo); return(nfe); } catch (Exception ex) { MessageBox.Show(String.Format("Não foi possível desserializar nota. Erro: {0}", ex.Message), "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
private void Form1_Load(object sender, EventArgs e) { string path = @"E:\Clientes\Romulus\Loja1\NfeEntrada_Loja1\202005\Xml\"; DirectoryInfo directory = new DirectoryInfo(path); foreach (FileInfo file in directory.GetFiles()) { if (file.Extension.ToUpper() == ".XML") { string content = getStream(file.FullName); TNfeProc tNfe = TNfeProc.GetNfeProc(content); continue; } file.Delete(); } }
internal static string GerarNfeProcXml(TNFe nfe, string urlQrCode, TProtNFe protocolo = null) { var nfeProc = new TNfeProc(); var nFeNamespaceName = "http://www.portalfiscal.inf.br/nfe"; var nfeSerializada = Serialize(nfe, nFeNamespaceName); nfeProc.NFe = (XmlSchemas.NfeAutorizacao.Retorno.NfeProc.TNFe) Deserialize <XmlSchemas.NfeAutorizacao.Retorno.NfeProc.TNFe>(nfeSerializada); if (nfeProc.NFe.infNFeSupl != null) { nfeProc.NFe.infNFeSupl.qrCode = ""; } if (protocolo != null) { var protocoloSerializado = Serialize(protocolo, nFeNamespaceName); nfeProc.protNFe = (XmlSchemas.NfeAutorizacao.Retorno.NfeProc.TProtNFe) Deserialize <XmlSchemas.NfeAutorizacao.Retorno.NfeProc.TProtNFe>(protocoloSerializado); } else { nfeProc.protNFe = new XmlSchemas.NfeAutorizacao.Retorno.NfeProc.TProtNFe(); } nfeProc.versao = "4.00"; var result = Serialize(nfeProc, nFeNamespaceName).Replace("<motDesICMS>1</motDesICMS>", string.Empty); if (nfeProc.NFe.infNFeSupl != null) { result = result.Replace("<qrCode />", "<qrCode>" + urlQrCode + "</qrCode>") .Replace("<NFe>", "<NFe xmlns=\"http://www.portalfiscal.inf.br/nfe\">"); } else { result = result.Replace("<NFe>", "<NFe xmlns=\"http://www.portalfiscal.inf.br/nfe\">"); } return(result); }
private void UpdateTotais(TNfeProc nota, IList <PostResultItem> totais) { nota.NFe.infNFe.total = new TNFeInfNFeTotal(); nota.NFe.infNFe.total.ICMSTot = new TNFeInfNFeTotalICMSTot(); nota.NFe.infNFe.total.ICMSTot.vBC = double.Parse(GetValue(totais, "Base de Cálculo ICMS")).ToString("0.00", enUs); nota.NFe.infNFe.total.ICMSTot.vICMS = double.Parse(GetValue(totais, "Valor do ICMS")).ToString("0.00", enUs); nota.NFe.infNFe.total.ICMSTot.vBCST = double.Parse(GetValue(totais, "Base de Cálculo ICMS ST")).ToString("0.00", enUs); nota.NFe.infNFe.total.ICMSTot.vST = double.Parse(GetValue(totais, "Valor ICMS Substituição")).ToString("0.00", enUs); nota.NFe.infNFe.total.ICMSTot.vProd = double.Parse(GetValue(totais, "Valor Total dos Produtos")).ToString("0.00", enUs); nota.NFe.infNFe.total.ICMSTot.vFrete = double.Parse(GetValue(totais, "Valor do Frete")).ToString("0.00", enUs); nota.NFe.infNFe.total.ICMSTot.vSeg = double.Parse(GetValue(totais, "Valor do Seguro")).ToString("0.00", enUs); nota.NFe.infNFe.total.ICMSTot.vDesc = double.Parse(GetValue(totais, "Valor Total dos Descontos")).ToString("0.00", enUs); nota.NFe.infNFe.total.ICMSTot.vII = double.Parse(GetValue(totais, "Valor Total do II")).ToString("0.00", enUs); nota.NFe.infNFe.total.ICMSTot.vIPI = double.Parse(GetValue(totais, "Valor Total do IPI")).ToString("0.00", enUs); nota.NFe.infNFe.total.ICMSTot.vPIS = double.Parse(GetValue(totais, "Valor do PIS")).ToString("0.00", enUs); nota.NFe.infNFe.total.ICMSTot.vCOFINS = double.Parse(GetValue(totais, "Valor da COFINS")).ToString("0.00", enUs); nota.NFe.infNFe.total.ICMSTot.vOutro = double.Parse(GetValue(totais, "Outras Despesas Acessórias")).ToString("0.00", enUs); nota.NFe.infNFe.total.ICMSTot.vNF = double.Parse(GetValue(totais, "Valor Total da NFe")).ToString("0.00", enUs); nota.NFe.infNFe.total.ISSQNtot = new TNFeInfNFeTotalISSQNtot(); }
private void btnImportarNfe_Click(object sender, EventArgs e) { if (openFileDialogNfe.ShowDialog() == DialogResult.OK) { string nomearquivo = openFileDialogNfe.FileName; TNfeProc nfe = GerenciadorNFe.GetInstance().LerNFE(nomearquivo); if (MessageBox.Show("Deseja importar CABEÇALHO da NF-e?", "Confirmar Importar NF-e", MessageBoxButtons.YesNo) == DialogResult.Yes) { Cursor.Current = Cursors.WaitCursor; long codEntrada = GerenciadorEntrada.GetInstance().Importar(nfe); fornecedorBindingSource.DataSource = GerenciadorPessoa.GetInstance().ObterTodos(); empresaFreteBindingSource.DataSource = GerenciadorPessoa.GetInstance().ObterTodos(); entradaBindingSource.DataSource = GerenciadorEntrada.GetInstance().ObterTodos(); entradaBindingSource.Position = entradaBindingSource.List.IndexOf(new Entrada() { CodEntrada = codEntrada }); Cursor.Current = Cursors.Default; } if (MessageBox.Show("Deseja importar PRODUTOS da NF-e?", "Confirmar Importar NF-e", MessageBoxButtons.YesNo) == DialogResult.Yes) { List <EntradaProduto> listaEntradaProduto = GerenciadorEntradaProduto.GetInstance(null).Importar(nfe); Entrada entrada = (Entrada)entradaBindingSource.Current; if (listaEntradaProduto.Count > 0) { if (entrada.CodEntrada != listaEntradaProduto[0].CodEntrada) { entradaBindingSource.Position = entradaBindingSource.List.IndexOf(new Entrada() { CodEntrada = listaEntradaProduto[0].CodEntrada }); } } entrada = (Entrada)entradaBindingSource.Current; FrmEntradaImportar frmEntradaImportar = new FrmEntradaImportar(entrada, listaEntradaProduto); frmEntradaImportar.ShowDialog(); frmEntradaImportar.Dispose(); codEntradaTextBox_TextChanged(sender, e); } } }
public void Generate(DownloadedHtmlData downloadedData, string directory) { var nota = new TNfeProc(); UpdateDadosNfe(downloadedData.ChaveAcessso, nota, downloadedData.DadosNfe, downloadedData.DadosEmitente, downloadedData.InformacoesAdicionais); UpdateDadosEmitente(nota, downloadedData.DadosEmitente); UpdateDadosDestinatario(nota, downloadedData.DadosDestinatario); UpdateProdutos(nota, downloadedData.Products); UpdateTotais(nota, downloadedData.Totais); UpdateTransporte(nota, downloadedData.DadosTransporte); UpdateAdicionais(nota, downloadedData.InformacoesAdicionais); var xml = Util.Serialize(nota); xml = xml.Replace("protNFe versao=\"2.00\"", "protNFe xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"2.00\""); SaveXml(xml, directory); }
public static TNfeProc GetTNFeProc(string content) { TNfeProc nfeProc = null; try { XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add("NFe", "http://www.portalfiscal.inf.br/nfe"); XmlSerializer serializer = new XmlSerializer(typeof(TNfeProc)); serializer.Serialize(Console.Out, new TNfeProc(), namespaces); System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(new System.IO.StringReader(content)); reader.Read(); nfeProc = (TNfeProc)serializer.Deserialize(reader); reader.Close(); } catch { nfeProc = null; throw; } return(nfeProc); }
public ExtratoImposto ExtratoGrid(TNfeProc nfe, decimal soma) { try { ExtratoImposto extrato = new ExtratoImposto(); extrato.NumeroNota = nfe.NFe.infNFe.ide.nNF; string valorTotalNota = nfe.NFe.infNFe.total.ICMSTot.vNF; if (valorTotalNota != null) { string formatvalorTotalNota = valorTotalNota.Replace(".", ","); extrato.ValorTotalNota = Convert.ToDecimal(formatvalorTotalNota); } extrato.ValorICMSCalculado = Convert.ToDecimal(nfe.NFe.infNFe.total.ICMSTot.vICMS.Replace(".", ",")); extrato.ValorAnalisado = soma; return(extrato); } catch (Exception ex) { MessageBox.Show(string.Format("Não foi possível criar o extrato. Erro: {0}", ex.Message), "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
public string buscarNota(int numPedido) { //Busca o XML try { buscarDadosAcesso(); string nomArquivo = String.Format("{0:0000000000}", numPedido) + ".xml"; FileStream stream = new FileStream(repositorio + nomArquivo.ToUpper(), FileMode.Open); //MemoryStream stream = buscarNotaFTP(numPedido); XmlSerializer desserializador = new XmlSerializer(typeof(TNfeProc)); TNfeProc np = (TNfeProc)desserializador.Deserialize(stream); var serializer = JsonConvert.SerializeObject(np); stream.Close(); stream.Dispose(); return(serializer); } catch (Exception ex) { return(ex.Message); } }
public static ReportDocument CartaCorrecao(TNfeProc nfe, CartaCorrecao.TProcEvento evento, ConfiguracaoHiperNFe config) { var doc = XDocument.Load(evento.NomeArquivo); var dataSet = new DataSet(); dataSet.ReadXml(doc.CreateReader()); var cartaCorrecao = new ImpressaoCartaCorrecao.CartaCorrecao(); cartaCorrecao.Load(Path.Combine(Environment.CurrentDirectory, "CartaCorrecao.rpt"), OpenReportMethod.OpenReportByDefault); var imageds = new ImpressaoCartaCorrecao.ImageDataSet(); imageds.Images.AddImagesRow(Logo.ToBytes(config), Barras.ToArray(evento.retEvento.infEvento.chNFe), config.Site); var row = ((ImpressaoCartaCorrecao.ImageDataSet.CartaCorrecaoRow)(imageds.CartaCorrecao.NewRow())); #region Nota Fiscal Eletrônica row.Modelo = Funcoes.ConvertEnumToString(nfe.NFe.infNFe.ide.mod); row.Serie = nfe.NFe.infNFe.ide.serie; row.Numero = nfe.NFe.infNFe.ide.nNF; row.MesAnoEmissao = nfe.NFe.infNFe.ide.dEmi.Substring(5, 2) + "/" + nfe.NFe.infNFe.ide.dEmi.Substring(2, 2); row.ChaveAcesso = nfe.protNFe.infProt.chNFe; #endregion Nota Fiscal Eletrônica #region Carta de Correção Eletrônica row.Orgao = Funcoes.ConvertEnumToString(evento.evento.infEvento.cOrgao); row.Ambiente = Funcoes.ConvertEnumToString(evento.evento.infEvento.tpAmb); row.DataHoraEvento = evento.evento.infEvento.dhEvento; row.Evento = Funcoes.ConvertEnumToString(evento.evento.infEvento.tpEvento); row.DescricaoEvento = Funcoes.ConvertEnumToString(evento.evento.infEvento.detEvento.descEvento); row.SequenciaEvento = evento.evento.infEvento.nSeqEvento; row.VersaoEvento = Funcoes.ConvertEnumToString(evento.evento.infEvento.verEvento); row.Status = evento.retEvento.infEvento.cStat + " - " + evento.retEvento.infEvento.xMotivo; row.Protocolo = evento.retEvento.infEvento.nProt; row.DataHoraRegistro = evento.retEvento.infEvento.dhRegEvento; #endregion Carta de Correção Eletrônica #region Emitente row.RazaoSocial_Emit = nfe.NFe.infNFe.emit.xNome; row.CNPJCPF_Emit = nfe.NFe.infNFe.emit.Item; row.Endereco_Emit = nfe.NFe.infNFe.emit.enderEmit.xLgr + " " + nfe.NFe.infNFe.emit.enderEmit.nro + " " + nfe.NFe.infNFe.emit.enderEmit.xCpl; row.Bairro_Emit = nfe.NFe.infNFe.emit.enderEmit.xBairro; row.CEP_Emit = nfe.NFe.infNFe.emit.enderEmit.CEP; row.Municipio_Emit = nfe.NFe.infNFe.emit.enderEmit.xMun; row.FoneFax_Emit = nfe.NFe.infNFe.emit.enderEmit.fone; row.Estado_Emit = nfe.NFe.infNFe.emit.enderEmit.UF.ToString(); row.IE_Emit = nfe.NFe.infNFe.emit.IE; #endregion Emitente #region Destinatário / Remetente row.RazaoSocial_Dest = nfe.NFe.infNFe.dest.xNome; row.CNPJCPF_Dest = nfe.NFe.infNFe.dest.Item; row.Endereco_Dest = nfe.NFe.infNFe.dest.enderDest.xLgr + " " + nfe.NFe.infNFe.dest.enderDest.nro + " " + nfe.NFe.infNFe.dest.enderDest.xCpl; row.Bairro_Dest = nfe.NFe.infNFe.dest.enderDest.xBairro; row.CEP_Dest = nfe.NFe.infNFe.dest.enderDest.CEP; row.Municipio_Dest = nfe.NFe.infNFe.dest.enderDest.xMun; row.FoneFax_Dest = nfe.NFe.infNFe.dest.enderDest.fone; row.Estado_Dest = nfe.NFe.infNFe.dest.enderDest.UF.ToString(); row.IE_Dest = nfe.NFe.infNFe.dest.IE; #endregion Destinatário / Remetente row.CondicoesUso = Funcoes.ConvertEnumToString(evento.evento.infEvento.detEvento.xCondUso); row.Correcao = evento.evento.infEvento.detEvento.xCorrecao; imageds.CartaCorrecao.AddCartaCorrecaoRow(row); cartaCorrecao.SetDataSource(dataSet); cartaCorrecao.Database.Tables["Images"].SetDataSource(imageds); return(cartaCorrecao); }
/// <summary> /// Importa os produtos de uma Nfe /// </summary> /// <param name="nfe"></param> public List <EntradaProduto> Importar(TNfeProc nfe) { const string VERSAO2 = "2.00"; const string VERSAO3 = "3.10"; const string VERSAO4 = "4.00"; try { CultureInfo ci = new CultureInfo("en-US"); // usado para connversão dos números do xml string numeroNF = nfe.NFe.infNFe.ide.nNF; string versaoNF = nfe.NFe.infNFe.versao; string cpf_cnpjFornecedor = nfe.NFe.infNFe.emit.Item; IEnumerable <Entrada> entradas = GerenciadorEntrada.GetInstance().ObterPorNumeroNotaFiscalFornecedor(numeroNF, cpf_cnpjFornecedor); if (entradas.Count() == 0) { throw new NegocioException("A entrada não foi encontrada para realizar o cadastro de produtos"); } Entrada entrada = entradas.ElementAtOrDefault(0); List <EntradaProduto> listaProtutos = new List <EntradaProduto>(); foreach (TNFeInfNFeDet produto in nfe.NFe.infNFe.det) { EntradaProduto entradaProduto = new EntradaProduto(); entradaProduto.Cfop = Convert.ToInt32(produto.prod.CFOP); entradaProduto.CodEntrada = entrada.CodEntrada; entradaProduto.CodFornecedor = entrada.CodFornecedor; ProdutoPesquisa produtoPesquisa = null; if (!string.IsNullOrEmpty(produto.prod.cEAN)) { produtoPesquisa = GerenciadorProduto.GetInstance().ObterPorCodigoBarraExato(produto.prod.cEAN).ElementAtOrDefault(0); } entradaProduto.CodProduto = (produtoPesquisa != null) ? produtoPesquisa.CodProduto : 1; entradaProduto.DataEntrada = entrada.DataEntrada; entradaProduto.FornecedorEhFabricante = entrada.FornecedorEhFabricante; if (entrada.ValorFrete > 0) { entradaProduto.Frete = ((entrada.ValorFrete / entrada.TotalProdutos) * 100); } else { entradaProduto.Frete = 0; } entradaProduto.Ncmsh = produto.prod.NCM; entradaProduto.NomeProduto = produto.prod.xProd.Length > 50 ? produto.prod.xProd.Substring(0, 50).ToUpper() : produto.prod.xProd.ToUpper(); entradaProduto.Quantidade = Convert.ToDecimal(produto.prod.qCom, ci); entradaProduto.QuantidadeEmbalagem = (produtoPesquisa == null) ? 1 : produtoPesquisa.QuantidadeEmbalagem; entradaProduto.Simples = (produtoPesquisa == null) ? 8 : produtoPesquisa.Simples; entradaProduto.UnidadeCompra = produto.prod.uCom; entradaProduto.ValorDesconto = Convert.ToDecimal(produto.prod.vDesc, ci); entradaProduto.ValorUnitario = Convert.ToDecimal(produto.prod.vUnCom, ci); entradaProduto.Desconto = Convert.ToDecimal(produto.prod.vDesc, ci) / entradaProduto.ValorTotal * 100; entradaProduto.CodigoBarra = produto.prod.cEAN; entradaProduto.ReferenciaFabricante = produto.prod.cProd; for (int i = 0; i < produto.imposto.Items.Length; i++) { if (produto.imposto.Items[i] is TNFeInfNFeDetImpostoICMS) { var icms = ((TNFeInfNFeDetImpostoICMS)produto.imposto.Items[i]).Item; if (icms is TNFeInfNFeDetImpostoICMSICMS00) { TNFeInfNFeDetImpostoICMSICMS00 icms00 = ((TNFeInfNFeDetImpostoICMSICMS00)icms);; entradaProduto.BaseCalculoICMS = Convert.ToDecimal(icms00.vBC, ci); entradaProduto.BaseCalculoICMSST = 0; entradaProduto.CodCST = icms00.orig.ToString().Substring(4) + icms00.CST.ToString().Substring(4); entradaProduto.CodCSTNFe = icms00.orig.ToString().Substring(4) + icms00.CST.ToString().Substring(4); entradaProduto.Icms = Convert.ToDecimal(icms00.pICMS, ci); entradaProduto.IcmsSubstituto = 0; } else if (icms is TNFeInfNFeDetImpostoICMSICMS10) { TNFeInfNFeDetImpostoICMSICMS10 icms10 = ((TNFeInfNFeDetImpostoICMSICMS10)icms);; entradaProduto.BaseCalculoICMS = Convert.ToDecimal(icms10.vBC, ci); entradaProduto.BaseCalculoICMSST = Convert.ToDecimal(icms10.vBCST, ci); entradaProduto.CodCST = icms10.orig.ToString().Substring(4) + icms10.CST.ToString().Substring(4); entradaProduto.CodCSTNFe = icms10.orig.ToString().Substring(4) + icms10.CST.ToString().Substring(4); entradaProduto.Icms = Convert.ToDecimal(icms10.pICMS, ci); if (entrada.TotalProdutosST > 0) { entradaProduto.IcmsSubstituto = entrada.TotalSubstituicao / entrada.TotalProdutosST * 100; //Convert.ToDecimal(icms10.pICMSST, ci); } } else if (icms is TNFeInfNFeDetImpostoICMSICMS20) { TNFeInfNFeDetImpostoICMSICMS20 icms20 = ((TNFeInfNFeDetImpostoICMSICMS20)icms);; entradaProduto.BaseCalculoICMS = Convert.ToDecimal(icms20.vBC, ci); entradaProduto.BaseCalculoICMSST = 0; entradaProduto.CodCST = icms20.orig.ToString().Substring(4) + icms20.CST.ToString().Substring(4); entradaProduto.CodCSTNFe = icms20.orig.ToString().Substring(4) + icms20.CST.ToString().Substring(4); entradaProduto.Icms = Convert.ToDecimal(icms20.pICMS, ci); entradaProduto.IcmsSubstituto = 0; //Convert.ToDecimal(icms10.pICMSST, ci); } else if (icms is TNFeInfNFeDetImpostoICMSICMS30) { TNFeInfNFeDetImpostoICMSICMS30 icms30 = ((TNFeInfNFeDetImpostoICMSICMS30)icms);; entradaProduto.BaseCalculoICMS = 0; entradaProduto.BaseCalculoICMSST = Convert.ToDecimal(icms30.vBCST, ci); entradaProduto.CodCST = icms30.orig.ToString().Substring(4) + icms30.CST.ToString().Substring(4); entradaProduto.CodCSTNFe = icms30.orig.ToString().Substring(4) + icms30.CST.ToString().Substring(4); entradaProduto.Icms = 0; if (entrada.TotalProdutosST > 0) { entradaProduto.IcmsSubstituto = entrada.TotalSubstituicao / entrada.TotalProdutosST * 100; //Convert.ToDecimal(icms10.pICMSST, ci); } } else if (icms is TNFeInfNFeDetImpostoICMSICMS40) { TNFeInfNFeDetImpostoICMSICMS40 icms40 = ((TNFeInfNFeDetImpostoICMSICMS40)icms);; entradaProduto.BaseCalculoICMS = 0; entradaProduto.BaseCalculoICMSST = 0; entradaProduto.CodCST = icms40.orig.ToString().Substring(4) + icms40.CST.ToString().Substring(4); entradaProduto.CodCSTNFe = icms40.orig.ToString().Substring(4) + icms40.CST.ToString().Substring(4); entradaProduto.Icms = 0; if (entrada.TotalProdutosST > 0) { entradaProduto.IcmsSubstituto = entrada.TotalSubstituicao / entrada.TotalProdutosST * 100; //Convert.ToDecimal(icms10.pICMSST, ci); } } else if (icms is TNFeInfNFeDetImpostoICMSICMS60) { TNFeInfNFeDetImpostoICMSICMS60 icms60 = ((TNFeInfNFeDetImpostoICMSICMS60)icms);; entradaProduto.BaseCalculoICMS = 0; entradaProduto.BaseCalculoICMSST = Convert.ToDecimal(icms60.vBCSTRet, ci); entradaProduto.CodCST = icms60.orig.ToString().Substring(4) + icms60.CST.ToString().Substring(4); entradaProduto.CodCSTNFe = icms60.orig.ToString().Substring(4) + icms60.CST.ToString().Substring(4); entradaProduto.Icms = Convert.ToDecimal(icms60.vICMSSTRet, ci); if (entrada.TotalProdutosST > 0) { entradaProduto.IcmsSubstituto = entrada.TotalSubstituicao / entrada.TotalProdutosST * 100; //Convert.ToDecimal(icms10.pICMSST, ci); } } else if (icms is TNFeInfNFeDetImpostoICMSICMS70) { TNFeInfNFeDetImpostoICMSICMS70 icms70 = ((TNFeInfNFeDetImpostoICMSICMS70)icms);; entradaProduto.BaseCalculoICMS = Convert.ToDecimal(icms70.vBC, ci); entradaProduto.BaseCalculoICMSST = Convert.ToDecimal(icms70.vBCST, ci); entradaProduto.CodCST = icms70.orig.ToString().Substring(4) + icms70.CST.ToString().Substring(4); entradaProduto.CodCSTNFe = icms70.orig.ToString().Substring(4) + icms70.CST.ToString().Substring(4); entradaProduto.Icms = Convert.ToDecimal(icms70.pICMS, ci); if (entrada.TotalProdutosST > 0) { entradaProduto.IcmsSubstituto = entrada.TotalSubstituicao / entrada.TotalProdutosST * 100; //Convert.ToDecimal(icms10.pICMSST, ci); } } else if (icms is TNFeInfNFeDetImpostoICMSICMSSN101) { TNFeInfNFeDetImpostoICMSICMSSN101 icms101 = ((TNFeInfNFeDetImpostoICMSICMSSN101)icms);; entradaProduto.BaseCalculoICMS = 0; entradaProduto.BaseCalculoICMSST = 0; entradaProduto.CodCST = icms101.orig.ToString().Substring(4) + icms101.CSOSN.ToString().Substring(4); entradaProduto.CodCSTNFe = icms101.orig.ToString().Substring(4) + icms101.CSOSN.ToString().Substring(4); entradaProduto.Icms = Convert.ToDecimal(icms101.pCredSN, ci); entradaProduto.IcmsSubstituto = 0; } else if (icms is TNFeInfNFeDetImpostoICMSICMSSN102) { TNFeInfNFeDetImpostoICMSICMSSN102 icms102 = ((TNFeInfNFeDetImpostoICMSICMSSN102)icms);; entradaProduto.BaseCalculoICMS = 0; entradaProduto.BaseCalculoICMSST = 0; entradaProduto.CodCST = icms102.orig.ToString().Substring(4) + icms102.CSOSN.ToString().Substring(4); entradaProduto.CodCSTNFe = icms102.orig.ToString().Substring(4) + icms102.CSOSN.ToString().Substring(4); entradaProduto.Icms = 0; entradaProduto.IcmsSubstituto = 0; } else if (icms is TNFeInfNFeDetImpostoICMSICMSSN900) { TNFeInfNFeDetImpostoICMSICMSSN900 icms900 = ((TNFeInfNFeDetImpostoICMSICMSSN900)icms);; entradaProduto.BaseCalculoICMS = Convert.ToDecimal(icms900.vBC, ci); entradaProduto.BaseCalculoICMSST = Convert.ToDecimal(icms900.vBCST, ci); entradaProduto.CodCST = icms900.orig.ToString().Substring(4) + icms900.CSOSN.ToString().Substring(4); entradaProduto.CodCSTNFe = icms900.orig.ToString().Substring(4) + icms900.CSOSN.ToString().Substring(4); entradaProduto.Icms = Convert.ToDecimal(icms900.pICMS, ci); entradaProduto.IcmsSubstituto = 0; if (entrada.TotalProdutosST > 0) { entradaProduto.IcmsSubstituto = entrada.TotalSubstituicao / entrada.TotalProdutosST * 100; } } else if (icms is TNFeInfNFeDetImpostoICMSICMSSN201) { TNFeInfNFeDetImpostoICMSICMSSN201 icms201 = ((TNFeInfNFeDetImpostoICMSICMSSN201)icms);; entradaProduto.BaseCalculoICMS = 0; entradaProduto.BaseCalculoICMSST = Convert.ToDecimal(icms201.vBCST, ci); entradaProduto.CodCST = icms201.orig.ToString().Substring(4) + icms201.CSOSN.ToString().Substring(4); entradaProduto.CodCSTNFe = icms201.orig.ToString().Substring(4) + icms201.CSOSN.ToString().Substring(4); entradaProduto.Icms = 0; if (entrada.TotalProdutosST > 0) { entradaProduto.IcmsSubstituto = entrada.TotalSubstituicao / entrada.TotalProdutosST * 100; } } else if (icms is TNFeInfNFeDetImpostoICMSICMSSN202) { TNFeInfNFeDetImpostoICMSICMSSN202 icms202 = ((TNFeInfNFeDetImpostoICMSICMSSN202)icms);; entradaProduto.BaseCalculoICMS = 0; entradaProduto.BaseCalculoICMSST = Convert.ToDecimal(icms202.vBCST, ci); entradaProduto.CodCST = icms202.orig.ToString().Substring(4) + icms202.CSOSN.ToString().Substring(4); entradaProduto.CodCSTNFe = icms202.orig.ToString().Substring(4) + icms202.CSOSN.ToString().Substring(4); entradaProduto.Icms = 0; if (entrada.TotalProdutosST > 0) { entradaProduto.IcmsSubstituto = entrada.TotalSubstituicao / entrada.TotalProdutosST * 100; } } else if (icms is TNFeInfNFeDetImpostoICMSICMSSN500) { TNFeInfNFeDetImpostoICMSICMSSN500 icms500 = ((TNFeInfNFeDetImpostoICMSICMSSN500)icms);; entradaProduto.BaseCalculoICMS = 0; entradaProduto.BaseCalculoICMSST = Convert.ToDecimal(icms500.vBCSTRet, ci); entradaProduto.CodCST = icms500.orig.ToString().Substring(4) + icms500.CSOSN.ToString().Substring(4); entradaProduto.CodCSTNFe = icms500.orig.ToString().Substring(4) + icms500.CSOSN.ToString().Substring(4); entradaProduto.Icms = 0; if (entrada.TotalProdutosST > 0) { entradaProduto.IcmsSubstituto = entrada.TotalSubstituicao / entrada.TotalProdutosST * 100; } } else { throw new NegocioException("Existe um imposto ICMS não tratado pela importação. Avise ao administrador."); } } else if (versaoNF.Equals(VERSAO2)) { if (produto.imposto.Items[i] is Dominio.NFE2.TNFeInfNFeDetImpostoIPI) { Dominio.NFE2.TNFeInfNFeDetImpostoIPI impostoIPI = (Dominio.NFE2.TNFeInfNFeDetImpostoIPI)produto.imposto.Items[i]; if (impostoIPI.Item is Dominio.NFE2.TNFeInfNFeDetImpostoIPIIPITrib) { Dominio.NFE2.TNFeInfNFeDetImpostoIPIIPITrib ipiTrib = ((Dominio.NFE2.TNFeInfNFeDetImpostoIPIIPITrib)impostoIPI.Item); entradaProduto.Ipi = Convert.ToDecimal(ipiTrib.vIPI, ci) / entradaProduto.ValorTotal * 100; } } } else if (versaoNF.Equals(VERSAO3) || versaoNF.Equals(VERSAO4)) { if (produto.imposto.Items[i] is TIpi) { TIpi ipi = (TIpi)produto.imposto.Items[i]; if (ipi.Item is TIpiIPITrib) { TIpiIPITrib impostoIPI = (TIpiIPITrib)ipi.Item; entradaProduto.Ipi = Convert.ToDecimal(impostoIPI.vIPI, ci) / entradaProduto.ValorTotal * 100; } else { entradaProduto.Ipi = 0; } } } } Produto produtoCalculo = new Produto() { Desconto = entradaProduto.Desconto, Icms = entradaProduto.Icms, IcmsSubstituto = entradaProduto.IcmsSubstituto, Ipi = entradaProduto.Ipi, Frete = entradaProduto.Frete, Simples = entradaProduto.Simples, UltimoPrecoCompra = (entradaProduto.ValorUnitario / entradaProduto.QuantidadeEmbalagem) }; entradaProduto.PrecoCusto = produtoCalculo.PrecoCusto; if (produtoPesquisa == null) { entradaProduto.LucroPrecoRevenda = 15; entradaProduto.LucroPrecoVendaAtacado = 30; entradaProduto.LucroPrecoVendaVarejo = 35; entradaProduto.QtdProdutoAtacado = 0; } else { entradaProduto.LucroPrecoRevenda = produtoPesquisa.LucroPrecoRevenda; entradaProduto.LucroPrecoVendaAtacado = produtoPesquisa.LucroPrecoVendaAtacado; entradaProduto.LucroPrecoVendaVarejo = produtoPesquisa.LucroPrecoVendaVarejo; entradaProduto.QtdProdutoAtacado = produtoPesquisa.QtdProdutoAtacado; } produtoCalculo.LucroPrecoRevenda = entradaProduto.LucroPrecoRevenda; produtoCalculo.LucroPrecoVendaAtacado = entradaProduto.LucroPrecoVendaAtacado; produtoCalculo.LucroPrecoVendaVarejo = entradaProduto.LucroPrecoVendaVarejo; entradaProduto.PrecoRevendaSugestao = produtoCalculo.PrecoRevendaSugestao; entradaProduto.PrecoVendaAtacadoSugestao = produtoCalculo.PrecoVendaAtacadoSugestao; entradaProduto.PrecoVendaVarejoSugestao = produtoCalculo.PrecoVendaVarejoSugestao; if (produtoPesquisa == null) { entradaProduto.PrecoRevenda = entradaProduto.PrecoRevendaSugestao; entradaProduto.PrecoVendaAtacado = entradaProduto.PrecoVendaAtacadoSugestao; entradaProduto.PrecoVendaVarejo = entradaProduto.PrecoVendaVarejoSugestao; } else { entradaProduto.PrecoRevenda = produtoPesquisa.PrecoRevenda; entradaProduto.PrecoVendaAtacado = produtoPesquisa.PrecoVendaAtacado; entradaProduto.PrecoVendaVarejo = produtoPesquisa.PrecoVendaVarejo; } listaProtutos.Add(entradaProduto); } return(listaProtutos); } catch (Exception e) { throw new NegocioException("Problema durante a importação dos dados dos Produtos da NF-e. Favor contactar administrador.", e); } }
public static ReportDocument DANFE(TNfeProc nota, ConfiguracaoHiperNFe config) { var doc = XDocument.Load(nota.NFe.NomeArquivo); #region Validations foreach (var det in doc.Descendants(Ns + "det")) { var imposto = det.Element(Ns + "imposto"); /*Cria toda a parte do ICMS*/ XmlImpostoCreator.Icms(imposto); XmlImpostoCreator.Ipi(imposto); if (det.Element(Ns + "infAdProd") == null) { det.Add(new XElement(Ns + "infAdProd", "")); } var xElement = det.Element(Ns + "prod"); if (xElement == null || xElement.Element(Ns + "vDesc") != null) continue; var element = det.Element(Ns + "prod"); if (element != null) element.Add(new XElement(Ns + "vDesc", "0.00")); } #endregion Validations var dataSet = new DataSet(); dataSet.ReadXml(doc.CreateReader()); #region Validations if (dataSet.Tables["ide"].Columns["dSaiEnt"] == null) { dataSet.Tables["ide"].Columns.Add("dSaiEnt"); } if (dataSet.Tables["ide"].Columns["hSaiEnt"] == null) { dataSet.Tables["ide"].Columns.Add("hSaiEnt"); } if (dataSet.Tables["emit"].Columns["CPF"] == null) { dataSet.Tables["emit"].Columns.Add("CPF"); } if (dataSet.Tables["emit"].Columns["CNPJ"] == null) { dataSet.Tables["emit"].Columns.Add("CNPJ"); } if (dataSet.Tables["emit"].Columns["IEST"] == null) { dataSet.Tables["emit"].Columns.Add("IEST"); } if (dataSet.Tables["enderEmit"].Columns["xCpl"] == null) { dataSet.Tables["enderEmit"].Columns.Add("xCpl"); } if (dataSet.Tables["enderEmit"].Columns["CEP"] == null) { dataSet.Tables["enderEmit"].Columns.Add("CEP"); } if (dataSet.Tables["enderEmit"].Columns["fone"] == null) { dataSet.Tables["enderEmit"].Columns.Add("fone"); } if (dataSet.Tables["dest"].Columns["CPF"] == null) { dataSet.Tables["dest"].Columns.Add("CPF"); } if (dataSet.Tables["dest"].Columns["CNPJ"] == null) { dataSet.Tables["dest"].Columns.Add("CNPJ"); } if (dataSet.Tables["dest"].Columns["email"] == null) { dataSet.Tables["dest"].Columns.Add("email"); } if (dataSet.Tables["enderDest"].Columns["xCpl"] == null) { dataSet.Tables["enderDest"].Columns.Add("xCpl"); } if (dataSet.Tables["enderDest"].Columns["CEP"] == null) { dataSet.Tables["enderDest"].Columns.Add("CEP"); } if (dataSet.Tables["enderDest"].Columns["fone"] == null) { dataSet.Tables["enderDest"].Columns.Add("fone"); } if (dataSet.Tables["ISSQNTot"] == null) { dataSet.Tables.Add("ISSQNTot"); } if (dataSet.Tables["retTrib"] == null) { dataSet.Tables.Add("retTrib"); } if (dataSet.Tables["transporta"] == null) { dataSet.Tables.Add("transporta"); } if (dataSet.Tables["transporta"].Columns["CPF"] == null) { dataSet.Tables["transporta"].Columns.Add("CPF"); } if (dataSet.Tables["transporta"].Columns["CNPJ"] == null) { dataSet.Tables["transporta"].Columns.Add("CNPJ"); } if (dataSet.Tables["transporta"].Columns["IE"] == null) { dataSet.Tables["transporta"].Columns.Add("IE"); } if (dataSet.Tables["transporta"].Columns["xNome"] == null) { dataSet.Tables["transporta"].Columns.Add("xNome"); } if (dataSet.Tables["transporta"].Columns["xEnder"] == null) { dataSet.Tables["transporta"].Columns.Add("xEnder"); } if (dataSet.Tables["transporta"].Columns["xMun"] == null) { dataSet.Tables["transporta"].Columns.Add("xMun"); } if (dataSet.Tables["transporta"].Columns["UF"] == null) { dataSet.Tables["transporta"].Columns.Add("UF"); } if (dataSet.Tables["veicTransp"] == null) { dataSet.Tables.Add("veicTransp"); } if (dataSet.Tables["veicTransp"].Columns["transp_Id"] == null) { dataSet.Tables["veicTransp"].Columns.Add("transp_Id"); } if (dataSet.Tables["veicTransp"].Columns["RNTC"] == null) { dataSet.Tables["veicTransp"].Columns.Add("RNTC"); } if (dataSet.Tables["veicTransp"].Columns["placa"] == null) { dataSet.Tables["veicTransp"].Columns.Add("placa"); } if (dataSet.Tables["veicTransp"].Columns["UF"] == null) { dataSet.Tables["veicTransp"].Columns.Add("UF"); } if (dataSet.Tables["vol"] == null) { dataSet.Tables.Add("vol"); } if (dataSet.Tables["vol"].Columns["qVol"] == null) { dataSet.Tables["vol"].Columns.Add("qVol"); } if (dataSet.Tables["vol"].Columns["esp"] == null) { dataSet.Tables["vol"].Columns.Add("esp"); } if (dataSet.Tables["vol"].Columns["marca"] == null) { dataSet.Tables["vol"].Columns.Add("marca"); } if (dataSet.Tables["vol"].Columns["nVol"] == null) { dataSet.Tables["vol"].Columns.Add("nVol"); } if (dataSet.Tables["vol"].Columns["pesoL"] == null) { dataSet.Tables["vol"].Columns.Add("pesoL"); } if (dataSet.Tables["vol"].Columns["pesoB"] == null) { dataSet.Tables["vol"].Columns.Add("pesoB"); } if (dataSet.Tables["cobr"] == null) { dataSet.Tables.Add("cobr"); } if (dataSet.Tables["fat"] == null) { dataSet.Tables.Add("fat"); } if (dataSet.Tables["dup"] == null) { dataSet.Tables.Add("dup"); dataSet.Tables["dup"].Columns.Add("nDup"); dataSet.Tables["dup"].Columns.Add("dVenc"); dataSet.Tables["dup"].Columns.Add("vDup"); } if (dataSet.Tables["entrega"] == null) { dataSet.Tables.Add("entrega"); dataSet.Tables["entrega"].Columns.Add("CNPJ"); dataSet.Tables["entrega"].Columns.Add("CPF"); dataSet.Tables["entrega"].Columns.Add("xLog"); dataSet.Tables["entrega"].Columns.Add("nro"); dataSet.Tables["entrega"].Columns.Add("xCpl"); dataSet.Tables["entrega"].Columns.Add("xBairro"); dataSet.Tables["entrega"].Columns.Add("cMun"); dataSet.Tables["entrega"].Columns.Add("xMun"); dataSet.Tables["entrega"].Columns.Add("UF"); } if (dataSet.Tables["infProt"] == null) { dataSet.Tables.Add("infProt"); } if (dataSet.Tables["infProt"].Columns["nProt"] == null) { dataSet.Tables["infProt"].Columns.Add("nProt"); } if (dataSet.Tables["infProt"].Columns["chNFe"] == null) { dataSet.Tables["infProt"].Columns.Add("chNFe"); } if (dataSet.Tables["infProt"].Columns["dhRecbto"] == null) { dataSet.Tables["infProt"].Columns.Add("dhRecbto"); } if (dataSet.Tables["infProt"].Columns["cStat"] == null) { dataSet.Tables["infProt"].Columns.Add("cStat"); } if (dataSet.Tables["infAdic"] == null) { dataSet.Tables.Add("infAdic"); } if (dataSet.Tables["infAdic"].Columns["infCpl"] == null) { dataSet.Tables["infAdic"].Columns.Add("infCpl"); } if (dataSet.Tables["infAdic"].Columns["infAdFisco"] == null) { dataSet.Tables["infAdic"].Columns.Add("infAdFisco"); } if (dataSet.Tables["obsCont"] == null) { dataSet.Tables.Add("obsCont"); } if (dataSet.Tables["obsFisco"] == null) { dataSet.Tables.Add("obsFisco"); } #endregion Validations var danfe = new DANFE.DANFE(); danfe.Load(Path.Combine(Environment.CurrentDirectory, "DANFE.rpt"), OpenReportMethod.OpenReportByDefault); var imageds = new DANFE.ImageDataSet(); imageds.Images.AddImagesRow(Logo.ToBytes(config), Barras.ToArray(nota.NFe.infNFe.Id.Substring(3)), config.Site, config.CasasDecimaisQtd, config.CasasDecimaisValorUnitario); danfe.SetDataSource(dataSet); danfe.Database.Tables["Images"].SetDataSource(imageds); return danfe; }
public static ReportDocument DANFE(TNfeProc nota, ConfiguracaoHiperNFe config) { var doc = XDocument.Load(nota.NFe.NomeArquivo); #region Validations foreach (var det in doc.Descendants(Ns + "det")) { var imposto = det.Element(Ns + "imposto"); /*Cria toda a parte do ICMS*/ XmlImpostoCreator.Icms(imposto); XmlImpostoCreator.Ipi(imposto); if (det.Element(Ns + "infAdProd") == null) { det.Add(new XElement(Ns + "infAdProd", "")); } var xElement = det.Element(Ns + "prod"); if (xElement == null || xElement.Element(Ns + "vDesc") != null) { continue; } var element = det.Element(Ns + "prod"); if (element != null) { element.Add(new XElement(Ns + "vDesc", "0.00")); } } #endregion Validations var dataSet = new DataSet(); dataSet.ReadXml(doc.CreateReader()); #region Validations if (dataSet.Tables["ide"].Columns["dSaiEnt"] == null) { dataSet.Tables["ide"].Columns.Add("dSaiEnt"); } if (dataSet.Tables["ide"].Columns["hSaiEnt"] == null) { dataSet.Tables["ide"].Columns.Add("hSaiEnt"); } if (dataSet.Tables["emit"].Columns["CPF"] == null) { dataSet.Tables["emit"].Columns.Add("CPF"); } if (dataSet.Tables["emit"].Columns["CNPJ"] == null) { dataSet.Tables["emit"].Columns.Add("CNPJ"); } if (dataSet.Tables["emit"].Columns["IEST"] == null) { dataSet.Tables["emit"].Columns.Add("IEST"); } if (dataSet.Tables["enderEmit"].Columns["xCpl"] == null) { dataSet.Tables["enderEmit"].Columns.Add("xCpl"); } if (dataSet.Tables["enderEmit"].Columns["CEP"] == null) { dataSet.Tables["enderEmit"].Columns.Add("CEP"); } if (dataSet.Tables["enderEmit"].Columns["fone"] == null) { dataSet.Tables["enderEmit"].Columns.Add("fone"); } if (dataSet.Tables["dest"].Columns["CPF"] == null) { dataSet.Tables["dest"].Columns.Add("CPF"); } if (dataSet.Tables["dest"].Columns["CNPJ"] == null) { dataSet.Tables["dest"].Columns.Add("CNPJ"); } if (dataSet.Tables["dest"].Columns["email"] == null) { dataSet.Tables["dest"].Columns.Add("email"); } if (dataSet.Tables["enderDest"].Columns["xCpl"] == null) { dataSet.Tables["enderDest"].Columns.Add("xCpl"); } if (dataSet.Tables["enderDest"].Columns["CEP"] == null) { dataSet.Tables["enderDest"].Columns.Add("CEP"); } if (dataSet.Tables["enderDest"].Columns["fone"] == null) { dataSet.Tables["enderDest"].Columns.Add("fone"); } if (dataSet.Tables["ISSQNTot"] == null) { dataSet.Tables.Add("ISSQNTot"); } if (dataSet.Tables["retTrib"] == null) { dataSet.Tables.Add("retTrib"); } if (dataSet.Tables["transporta"] == null) { dataSet.Tables.Add("transporta"); } if (dataSet.Tables["transporta"].Columns["CPF"] == null) { dataSet.Tables["transporta"].Columns.Add("CPF"); } if (dataSet.Tables["transporta"].Columns["CNPJ"] == null) { dataSet.Tables["transporta"].Columns.Add("CNPJ"); } if (dataSet.Tables["transporta"].Columns["IE"] == null) { dataSet.Tables["transporta"].Columns.Add("IE"); } if (dataSet.Tables["transporta"].Columns["xNome"] == null) { dataSet.Tables["transporta"].Columns.Add("xNome"); } if (dataSet.Tables["transporta"].Columns["xEnder"] == null) { dataSet.Tables["transporta"].Columns.Add("xEnder"); } if (dataSet.Tables["transporta"].Columns["xMun"] == null) { dataSet.Tables["transporta"].Columns.Add("xMun"); } if (dataSet.Tables["transporta"].Columns["UF"] == null) { dataSet.Tables["transporta"].Columns.Add("UF"); } if (dataSet.Tables["veicTransp"] == null) { dataSet.Tables.Add("veicTransp"); } if (dataSet.Tables["veicTransp"].Columns["transp_Id"] == null) { dataSet.Tables["veicTransp"].Columns.Add("transp_Id"); } if (dataSet.Tables["veicTransp"].Columns["RNTC"] == null) { dataSet.Tables["veicTransp"].Columns.Add("RNTC"); } if (dataSet.Tables["veicTransp"].Columns["placa"] == null) { dataSet.Tables["veicTransp"].Columns.Add("placa"); } if (dataSet.Tables["veicTransp"].Columns["UF"] == null) { dataSet.Tables["veicTransp"].Columns.Add("UF"); } if (dataSet.Tables["vol"] == null) { dataSet.Tables.Add("vol"); } if (dataSet.Tables["vol"].Columns["qVol"] == null) { dataSet.Tables["vol"].Columns.Add("qVol"); } if (dataSet.Tables["vol"].Columns["esp"] == null) { dataSet.Tables["vol"].Columns.Add("esp"); } if (dataSet.Tables["vol"].Columns["marca"] == null) { dataSet.Tables["vol"].Columns.Add("marca"); } if (dataSet.Tables["vol"].Columns["nVol"] == null) { dataSet.Tables["vol"].Columns.Add("nVol"); } if (dataSet.Tables["vol"].Columns["pesoL"] == null) { dataSet.Tables["vol"].Columns.Add("pesoL"); } if (dataSet.Tables["vol"].Columns["pesoB"] == null) { dataSet.Tables["vol"].Columns.Add("pesoB"); } if (dataSet.Tables["cobr"] == null) { dataSet.Tables.Add("cobr"); } if (dataSet.Tables["fat"] == null) { dataSet.Tables.Add("fat"); } if (dataSet.Tables["dup"] == null) { dataSet.Tables.Add("dup"); dataSet.Tables["dup"].Columns.Add("nDup"); dataSet.Tables["dup"].Columns.Add("dVenc"); dataSet.Tables["dup"].Columns.Add("vDup"); } if (dataSet.Tables["entrega"] == null) { dataSet.Tables.Add("entrega"); dataSet.Tables["entrega"].Columns.Add("CNPJ"); dataSet.Tables["entrega"].Columns.Add("CPF"); dataSet.Tables["entrega"].Columns.Add("xLog"); dataSet.Tables["entrega"].Columns.Add("nro"); dataSet.Tables["entrega"].Columns.Add("xCpl"); dataSet.Tables["entrega"].Columns.Add("xBairro"); dataSet.Tables["entrega"].Columns.Add("cMun"); dataSet.Tables["entrega"].Columns.Add("xMun"); dataSet.Tables["entrega"].Columns.Add("UF"); } if (dataSet.Tables["infProt"] == null) { dataSet.Tables.Add("infProt"); } if (dataSet.Tables["infProt"].Columns["nProt"] == null) { dataSet.Tables["infProt"].Columns.Add("nProt"); } if (dataSet.Tables["infProt"].Columns["chNFe"] == null) { dataSet.Tables["infProt"].Columns.Add("chNFe"); } if (dataSet.Tables["infProt"].Columns["dhRecbto"] == null) { dataSet.Tables["infProt"].Columns.Add("dhRecbto"); } if (dataSet.Tables["infProt"].Columns["cStat"] == null) { dataSet.Tables["infProt"].Columns.Add("cStat"); } if (dataSet.Tables["infAdic"] == null) { dataSet.Tables.Add("infAdic"); } if (dataSet.Tables["infAdic"].Columns["infCpl"] == null) { dataSet.Tables["infAdic"].Columns.Add("infCpl"); } if (dataSet.Tables["infAdic"].Columns["infAdFisco"] == null) { dataSet.Tables["infAdic"].Columns.Add("infAdFisco"); } if (dataSet.Tables["obsCont"] == null) { dataSet.Tables.Add("obsCont"); } if (dataSet.Tables["obsFisco"] == null) { dataSet.Tables.Add("obsFisco"); } #endregion Validations var danfe = new DANFE.DANFE(); danfe.Load(Path.Combine(Environment.CurrentDirectory, "DANFE.rpt"), OpenReportMethod.OpenReportByDefault); var imageds = new DANFE.ImageDataSet(); imageds.Images.AddImagesRow(Logo.ToBytes(config), Barras.ToArray(nota.NFe.infNFe.Id.Substring(3)), config.Site, config.CasasDecimaisQtd, config.CasasDecimaisValorUnitario); danfe.SetDataSource(dataSet); danfe.Database.Tables["Images"].SetDataSource(imageds); return(danfe); }
public static ReportDocument CartaCorrecao(TNfeProc nfe, CartaCorrecao.TProcEvento evento, ConfiguracaoHiperNFe config) { var doc = XDocument.Load(evento.NomeArquivo); var dataSet = new DataSet(); dataSet.ReadXml(doc.CreateReader()); var cartaCorrecao = new ImpressaoCartaCorrecao.CartaCorrecao(); cartaCorrecao.Load(Path.Combine(Environment.CurrentDirectory, "CartaCorrecao.rpt"), OpenReportMethod.OpenReportByDefault); var imageds = new ImpressaoCartaCorrecao.ImageDataSet(); imageds.Images.AddImagesRow(Logo.ToBytes(config), Barras.ToArray(evento.retEvento.infEvento.chNFe), config.Site); var row = ((ImpressaoCartaCorrecao.ImageDataSet.CartaCorrecaoRow)(imageds.CartaCorrecao.NewRow())); #region Nota Fiscal Eletrônica row.Modelo = Funcoes.ConvertEnumToString(nfe.NFe.infNFe.ide.mod); row.Serie = nfe.NFe.infNFe.ide.serie; row.Numero = nfe.NFe.infNFe.ide.nNF; row.MesAnoEmissao = nfe.NFe.infNFe.ide.dEmi.Substring(5, 2) + "/" + nfe.NFe.infNFe.ide.dEmi.Substring(2, 2); row.ChaveAcesso = nfe.protNFe.infProt.chNFe; #endregion Nota Fiscal Eletrônica #region Carta de Correção Eletrônica row.Orgao = Funcoes.ConvertEnumToString(evento.evento.infEvento.cOrgao); row.Ambiente = Funcoes.ConvertEnumToString(evento.evento.infEvento.tpAmb); row.DataHoraEvento = evento.evento.infEvento.dhEvento; row.Evento = Funcoes.ConvertEnumToString(evento.evento.infEvento.tpEvento); row.DescricaoEvento = Funcoes.ConvertEnumToString(evento.evento.infEvento.detEvento.descEvento); row.SequenciaEvento = evento.evento.infEvento.nSeqEvento; row.VersaoEvento = Funcoes.ConvertEnumToString(evento.evento.infEvento.verEvento); row.Status = evento.retEvento.infEvento.cStat + " - " + evento.retEvento.infEvento.xMotivo; row.Protocolo = evento.retEvento.infEvento.nProt; row.DataHoraRegistro = evento.retEvento.infEvento.dhRegEvento; #endregion Carta de Correção Eletrônica #region Emitente row.RazaoSocial_Emit = nfe.NFe.infNFe.emit.xNome; row.CNPJCPF_Emit = nfe.NFe.infNFe.emit.Item; row.Endereco_Emit = nfe.NFe.infNFe.emit.enderEmit.xLgr + " " + nfe.NFe.infNFe.emit.enderEmit.nro + " " + nfe.NFe.infNFe.emit.enderEmit.xCpl; row.Bairro_Emit = nfe.NFe.infNFe.emit.enderEmit.xBairro; row.CEP_Emit = nfe.NFe.infNFe.emit.enderEmit.CEP; row.Municipio_Emit = nfe.NFe.infNFe.emit.enderEmit.xMun; row.FoneFax_Emit = nfe.NFe.infNFe.emit.enderEmit.fone; row.Estado_Emit = nfe.NFe.infNFe.emit.enderEmit.UF.ToString(); row.IE_Emit = nfe.NFe.infNFe.emit.IE; #endregion Emitente #region Destinatário / Remetente row.RazaoSocial_Dest = nfe.NFe.infNFe.dest.xNome; row.CNPJCPF_Dest = nfe.NFe.infNFe.dest.Item; row.Endereco_Dest = nfe.NFe.infNFe.dest.enderDest.xLgr + " " + nfe.NFe.infNFe.dest.enderDest.nro + " " + nfe.NFe.infNFe.dest.enderDest.xCpl; row.Bairro_Dest = nfe.NFe.infNFe.dest.enderDest.xBairro; row.CEP_Dest = nfe.NFe.infNFe.dest.enderDest.CEP; row.Municipio_Dest = nfe.NFe.infNFe.dest.enderDest.xMun; row.FoneFax_Dest = nfe.NFe.infNFe.dest.enderDest.fone; row.Estado_Dest = nfe.NFe.infNFe.dest.enderDest.UF.ToString(); row.IE_Dest = nfe.NFe.infNFe.dest.IE; #endregion Destinatário / Remetente row.CondicoesUso = Funcoes.ConvertEnumToString(evento.evento.infEvento.detEvento.xCondUso); row.Correcao = evento.evento.infEvento.detEvento.xCorrecao; imageds.CartaCorrecao.AddCartaCorrecaoRow(row); cartaCorrecao.SetDataSource(dataSet); cartaCorrecao.Database.Tables["Images"].SetDataSource(imageds); return cartaCorrecao; }
public void SalvarNFe(ref TNfeProc nota) { nota.NFe.NomeArquivo = GetFileNameNFe(nota.NFe.infNFe); nota.NFe.ArquivoXML = SaveXml(nota.Serialize(), nota.NFe.NomeArquivo); }
public CartaCorrecao.TRetEnvEvento CartaCorrecao(TNfeProc nota, string Correcao, X509Certificate2 pCertificado, int numLote, int nSequencia, TAmb ambiente, out ACBr.Net.NFe.CartaCorrecao.TProcEvento procEvento) { string arqPedCorecao = _PastaLog + nota.NFe.infNFe.Id.Substring(3) + "-ped-evento.xml";//-ped-cce.xml ??? string retPedCorrecao = _PastaLog + nota.NFe.infNFe.Id.Substring(3) + "-eve.xml"; C_WebService.ListaUrl listaURL = default(C_WebService.ListaUrl); listaURL = WsUrls.BuscaURL(nota.NFe.infNFe.ide.cUF, ambiente); #region evento CartaCorrecao.TEvento evento = new CartaCorrecao.TEvento(); evento.versao = "1.00"; #region infEvento CartaCorrecao.TEventoInfEvento infEvento = new CartaCorrecao.TEventoInfEvento(); infEvento.tpAmb = ambiente; infEvento.chNFe = nota.NFe.infNFe.Id.Substring(3); infEvento.cOrgao = PegarCodigoOrgaoUF(nota.NFe.infNFe.ide.cUF); infEvento.dhEvento = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzzz"); infEvento.Id = "ID" + "110110" + nota.NFe.infNFe.Id.Substring(3) + nSequencia.ToString("D2"); infEvento.ItemElementName = ACBr.Net.NFe.CartaCorrecao.ItemChoiceTypeCC.CNPJ; infEvento.Item = nota.NFe.infNFe.emit.Item; infEvento.nSeqEvento = nSequencia.ToString(); infEvento.verEvento = ACBr.Net.NFe.CartaCorrecao.TEventoInfEventoVerEvento.Item100; infEvento.tpEvento = ACBr.Net.NFe.CartaCorrecao.TEventoInfEventoTpEvento.Item110110; #region detEvento CartaCorrecao.TEventoInfEventoDetEvento detEvento = new CartaCorrecao.TEventoInfEventoDetEvento(); detEvento.descEvento = ACBr.Net.NFe.CartaCorrecao.TEventoInfEventoDetEventoDescEvento.CartadeCorrecao; detEvento.versao = ACBr.Net.NFe.CartaCorrecao.TEventoInfEventoDetEventoVersao.Item100; detEvento.xCondUso = ACBr.Net.NFe.CartaCorrecao.TEventoInfEventoDetEventoXCondUso.ACartadeCorrecaoedisciplinadapeloparagrafo1oAdoart7odoConvenioSNde15dedezembrode1970epodeserutilizadapararegularizacaodeerroocorridonaemissaodedocumentofiscaldesdequeoerronaoestejarelacionadocomIasvariaveisquedeterminamovalordoimpostotaiscomobasedecalculoaliquotadiferencadeprecoquantidadevalordaoperacaooudaprestacaoIIacorrecaodedadoscadastraisqueimpliquemudancadoremetenteoudodestinatarioIIIadatadeemissaooudesaida; detEvento.xCorrecao = Correcao; #endregion detEvento infEvento.detEvento = detEvento; #endregion infEvento evento.infEvento = infEvento; XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(Funcoes.RemoveNameSpaceFromXml(evento.Serialize())); xmldoc = CertificadoDigital.Assinar(xmldoc, "infEvento", pCertificado); xmldoc.Save(arqPedCorecao); #endregion evento dynamic envEvento = GeraLoteEvento(arqPedCorecao, numLote); try { RecepcaoEvento.nfeCabecMsg cab = new RecepcaoEvento.nfeCabecMsg(); RecepcaoEvento.RecepcaoEvento wsMsg = default(RecepcaoEvento.RecepcaoEvento); // UF E VERSÃO DO CABEÇALHO cab.cUF = PegarCodigoUF(nota.NFe.infNFe.ide.cUF); cab.versaoDados = "1.00"; //CABEÇALHO USADA PARA ENVIO DE LOTE wsMsg = new RecepcaoEvento.RecepcaoEvento(listaURL.UrlRecepcaoEvento); wsMsg.nfeCabecMsgValue = cab; wsMsg.Timeout = 100000; wsMsg.ClientCertificates.Add(pCertificado); wsMsg.SoapVersion = SoapProtocolVersion.Soap12; //RETORNO DA SEFAZ XmlElement strRetorno = wsMsg.nfeRecepcaoEvento(envEvento); XmlDocument xmlRetorno = new XmlDocument(); xmlRetorno.LoadXml(strRetorno.OuterXml); xmlRetorno.Save(retPedCorrecao); ACBr.Net.NFe.CartaCorrecao.TRetEnvEvento retCorrecaoNFe = ACBr.Net.NFe.CartaCorrecao.TRetEnvEvento.LoadFromFile(retPedCorrecao); //saída procEvento = new CartaCorrecao.TProcEvento(); procEvento.evento = ACBr.Net.NFe.CartaCorrecao.TEvento.Deserialize(xmldoc.OuterXml); procEvento.retEvento = retCorrecaoNFe.retEvento[0]; procEvento.versao = "1.00"; return(retCorrecaoNFe); } catch (Exception ex) { throw new System.InvalidOperationException("Erro ao corrigir NFe. Erro: " + ex.Message); } }
public Cancelamento.TRetEnvEvento CancelaNFe(TNfeProc nota, string Justificativa, X509Certificate2 pCertificado, int numLote, int nSequencia, TAmb ambiente, out ACBr.Net.NFe.Cancelamento.TProcEvento procEvento) { XmlElement strRetorno = null; string arqPedCanc = _PastaLog + nota.NFe.infNFe.Id.Substring(3) + "-ped-evento.xml"; string retPedCanc = _PastaLog + nota.NFe.infNFe.Id.Substring(3) + "-eve.xml"; C_WebService.ListaUrl listaURL = default(C_WebService.ListaUrl); listaURL = WsUrls.BuscaURL(nota.NFe.infNFe.ide.cUF, ambiente); #region evento Cancelamento.TEvento evento = new Cancelamento.TEvento(); evento.versao = "1.00"; #region infEvento Cancelamento.TEventoInfEvento infEvento = new Cancelamento.TEventoInfEvento(); infEvento.tpAmb = ambiente; infEvento.chNFe = nota.NFe.infNFe.Id.Substring(3); infEvento.cOrgao = nota.NFe.infNFe.ide.cUF; infEvento.dhEvento = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzzz");// +"-00:00"; infEvento.Id = "ID" + "110111" + nota.NFe.infNFe.Id.Substring(3) + nSequencia.ToString("D2"); infEvento.ItemElementName = Cancelamento.TipoDocumentoCanc.CNPJ; infEvento.Item = nota.NFe.infNFe.emit.Item; infEvento.nSeqEvento = nSequencia.ToString(); infEvento.verEvento = Cancelamento.TEventoInfEventoVerEvento.Item100; infEvento.tpEvento = Cancelamento.TEventoInfEventoTpEvento.Cancelamento; #region detEvento Cancelamento.TEventoInfEventoDetEvento detEvento = new Cancelamento.TEventoInfEventoDetEvento(); detEvento.descEvento = Cancelamento.TEventoInfEventoDetEventoDescEvento.Cancelamento; detEvento.nProt = nota.protNFe.infProt.nProt; detEvento.versao = Cancelamento.TEventoInfEventoDetEventoVersao.Item100; detEvento.xJust = Justificativa; #endregion detEvento infEvento.detEvento = detEvento; #endregion infEvento evento.infEvento = infEvento; XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(Funcoes.RemoveNameSpaceFromXml(evento.Serialize())); xmldoc = CertificadoDigital.Assinar(xmldoc, "infEvento", pCertificado); xmldoc.Save(arqPedCanc); #endregion evento dynamic envEvento = GeraLoteEvento(arqPedCanc, numLote); try { RecepcaoEvento.nfeCabecMsg cab = new RecepcaoEvento.nfeCabecMsg(); RecepcaoEvento.RecepcaoEvento wsMsg = default(RecepcaoEvento.RecepcaoEvento); // UF E VERSÃO DO CABEÇALHO cab.cUF = PegarCodigoUF(nota.NFe.infNFe.ide.cUF); cab.versaoDados = "1.00"; //CABEÇALHO USADA PARA ENVIO DE LOTE wsMsg = new RecepcaoEvento.RecepcaoEvento(listaURL.UrlRecepcaoEvento); wsMsg.nfeCabecMsgValue = cab; wsMsg.Timeout = 100000; wsMsg.ClientCertificates.Add(pCertificado); wsMsg.SoapVersion = SoapProtocolVersion.Soap12; //RETORNO DA SEFAZ strRetorno = wsMsg.nfeRecepcaoEvento(envEvento); XmlDocument xmlRetorno = new XmlDocument(); xmlRetorno.LoadXml(strRetorno.OuterXml); xmlRetorno.Save(retPedCanc); ACBr.Net.NFe.Cancelamento.TRetEnvEvento retCancNFe = ACBr.Net.NFe.Cancelamento.TRetEnvEvento.LoadFromFile(retPedCanc); //saída procEvento = new Cancelamento.TProcEvento(); procEvento.evento = ACBr.Net.NFe.Cancelamento.TEvento.Deserialize(xmldoc.OuterXml); procEvento.retEvento = retCancNFe.retEvento[0]; procEvento.versao = "1.00"; return(retCancNFe); } catch (Exception ex) { throw new System.InvalidOperationException("Erro ao cancelar NFe. Erro: " + ex.Message); } }
public static bool LoadFromFile(string fileName, out TNfeProc obj) { System.Exception exception = null; return(LoadFromFile(fileName, out obj, out exception)); }
public static bool Deserialize(string xml, out TNfeProc obj) { System.Exception exception = null; return(Deserialize(xml, out obj, out exception)); }
public static string Serialize(TNfeProc nfe) { return(Serialize(nfe, Encoding.UTF8)); }