/// <summary> /// GerarXml /// </summary> /// <param name="NFe"></param> public void GerarXml(NFe NFe, string folderDestino) { doc = new XmlDocument(); XmlDeclaration node = doc.CreateXmlDeclaration("1.0", "UTF-8", ""); doc.InsertBefore(node, doc.DocumentElement); /// /// NFe /// XmlNode xmlInf = doc.CreateElement("NFe"); //if (NFe.ide.cUF != 29) //Bahia //{ // XmlAttribute xmlVersion = doc.CreateAttribute("xmlns:xsi"); // xmlVersion.Value = "http://www.w3.org/2001/XMLSchema-instance"; // xmlInf.Attributes.Append(xmlVersion); //} XmlAttribute xmlVersion1 = doc.CreateAttribute("xmlns"); xmlVersion1.Value = NFeStrConstants.NAME_SPACE_NFE;// !string.IsNullOrEmpty(Propriedade.nsURI_nfe) ? Propriedade.nsURI_nfe : "http://www.portalfiscal.inf.br/nfe"; xmlInf.Attributes.Append(xmlVersion1); doc.AppendChild(xmlInf); string cChave = NFe.ide.cUF.ToString() + NFe.ide.dEmi.Year.ToString("0000").Substring(2) + NFe.ide.dEmi.Month.ToString("00"); //data AAMM if (NFe.infNFe.Versao >= 3) cChave = NFe.ide.cUF.ToString() + NFe.ide.dhEmi.Substring(2, 2) + NFe.ide.dhEmi.Substring(5, 2); //data AAMM Int64 iTmp = Convert.ToInt64("0" + NFe.emit.CNPJ + NFe.emit.CPF); cChave += iTmp.ToString("00000000000000"); cChave += Convert.ToInt32(NFe.ide.mod).ToString("00"); if (NFe.ide.cNF == 0) { /// /// gera codigo aleatorio /// NFe.ide.cNF = this.GerarCodigoNumerico(NFe.ide.nNF); } string ccChave = cChave + NFe.ide.serie.ToString("000") + NFe.ide.nNF.ToString("000000000") + ((int)NFe.ide.tpEmis).ToString("0") + NFe.ide.cNF.ToString("00000000"); if (NFe.ide.cDV == 0) { /// /// calcula digito verificador /// NFe.ide.cDV = this.GerarDigito(ccChave); } else { int ccDV = this.GerarDigito(ccChave); if (NFe.ide.cDV != ccDV) throw new Exception(string.Format("Digito verificador informado, [{0}] é diferente do calculado, [{1}]", NFe.ide.cDV, ccDV)); } cChave += NFe.ide.serie.ToString("000") + NFe.ide.nNF.ToString("000000000") + ((int)NFe.ide.tpEmis).ToString("0") + NFe.ide.cNF.ToString("00000000") + NFe.ide.cDV.ToString("0"); NFe.infNFe.ID = cChave; /// /// infNFe /// if (NFe.infNFe.Versao == 0) NFe.infNFe.Versao = Convert.ToDecimal(versoes.VersaoXMLNFe.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); nDecimaisPerc = (double)NFe.infNFe.Versao >= 3.10 ? TpcnTipoCampo.tcDec4 : TpcnTipoCampo.tcDec2; XmlElement infNfe = doc.CreateElement("infNFe"); XmlAttribute infNfeAttr1 = doc.CreateAttribute(TpcnResources.versao.ToString()); infNfeAttr1.Value = NFe.infNFe.Versao.ToString("0.00").Replace(",", "."); infNfe.Attributes.Append(infNfeAttr1); XmlAttribute infNfeAttrId = doc.CreateAttribute(TpcnResources.Id.ToString()); infNfeAttrId.Value = "NFe" + NFe.infNFe.ID; infNfe.Attributes.Append(infNfeAttrId); xmlInf.AppendChild(infNfe); this.convertToOem = true; infNfe.AppendChild(GerarIde(NFe)); infNfe.AppendChild(GerarEmit(NFe)); GerarAvulsa(NFe, infNfe); XmlNode nodeDest = GerarDest(NFe); if (nodeDest != null && nodeDest.HasChildNodes) ///danasa 6/2014 infNfe.AppendChild(nodeDest); ///somente grava o nó "dest" se exibir GerarRetirada(NFe, infNfe); GerarEntrega(NFe, infNfe); GerarautXML(NFe, infNfe); GerarDet(NFe, infNfe); GerarTotal(NFe, infNfe); GerarTransp(NFe.Transp, infNfe); GerarCobr(NFe.Cobr, infNfe); if (NFe.infNFe.Versao >= 3 && NFe.ide.mod == TpcnMod.modNFCe) GerarPag(NFe, infNfe); GerarInfAdic(NFe.InfAdic, infNfe); GerarExporta(NFe, NFe.exporta, infNfe); GerarCompra(NFe.compra, infNfe); GerarCana(NFe.cana, infNfe); this.cFileName = NFe.infNFe.ID + Propriedade.ExtEnvio.Nfe; if (!string.IsNullOrEmpty(folderDestino)) { if (folderDestino.Substring(folderDestino.Length - 1, 1) == @"\") folderDestino = folderDestino.Substring(0, folderDestino.Length - 1); if (!Directory.Exists(Path.Combine(folderDestino, "Convertidos"))) { /// /// cria uma pasta temporária para armazenar o XML convertido /// System.IO.Directory.CreateDirectory(Path.Combine(folderDestino, "Convertidos")); } string strRetorno = this.cFileName; strRetorno = Path.Combine(folderDestino, "Convertidos"); this.cFileName = Path.Combine(strRetorno, this.cFileName); /// /// salva o XML strRetorno = this.cFileName; doc.Save(@strRetorno); } /// /// retorna o conteudo do XML da nfe XMLString = doc.OuterXml; }
/// <summary> /// GerarDest /// </summary> /// <param name="NFe"></param> /// <returns></returns> private XmlElement GerarDest(NFe NFe) { XmlElement e0 = doc.CreateElement("dest"); nodeCurrent = e0; if (NFe.infNFe.Versao <= 2 || (NFe.infNFe.Versao >= 3 && (!string.IsNullOrEmpty(NFe.dest.CNPJ) || !string.IsNullOrEmpty(NFe.dest.CPF) || !string.IsNullOrEmpty(NFe.dest.idEstrangeiro)))) { if (NFe.infNFe.Versao >= 3 && !string.IsNullOrEmpty(NFe.dest.idEstrangeiro)) { if (NFe.dest.idEstrangeiro.Equals("NAO GERAR TAG")) wCampo("", TpcnTipoCampo.tcStr, TpcnResources.idEstrangeiro, ObOp.Obrigatorio); //E03a else wCampo(NFe.dest.idEstrangeiro, TpcnTipoCampo.tcStr, TpcnResources.idEstrangeiro, ObOp.Opcional); //E03a } else if (NFe.dest.enderDest.cPais != 1058 && NFe.infNFe.Versao <= 2) wCampo("", TpcnTipoCampo.tcStr, TpcnResources.CNPJ); else if (!string.IsNullOrEmpty(NFe.dest.CNPJ)) wCampo(NFe.dest.CNPJ, TpcnTipoCampo.tcStr, TpcnResources.CNPJ); else if (!string.IsNullOrEmpty(NFe.dest.CPF)) wCampo(NFe.dest.CPF, TpcnTipoCampo.tcStr, TpcnResources.CPF); } if (NFe.ide.mod == TpcnMod.modNFe || (NFe.ide.mod == TpcnMod.modNFCe && !string.IsNullOrEmpty(NFe.dest.xNome))) { wCampo(NFe.ide.tpAmb == TipoAmbiente.taProducao ? NFe.dest.xNome : "NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL", TpcnTipoCampo.tcStr, TpcnResources.xNome, (NFe.infNFe.Versao >= 3 && NFe.ide.mod == TpcnMod.modNFCe) ? ObOp.Opcional : ObOp.Obrigatorio); } if (NFe.ide.mod == TpcnMod.modNFe || (NFe.ide.mod == TpcnMod.modNFCe && !string.IsNullOrEmpty(NFe.dest.enderDest.xLgr))) //danasa: 12/2013 { /// /// (**)GerarDestEnderDest(UF); /// XmlElement e1 = doc.CreateElement("enderDest"); e0.AppendChild(e1); nodeCurrent = e1; wCampo(NFe.dest.enderDest.xLgr, TpcnTipoCampo.tcStr, TpcnResources.xLgr); wCampo(NFe.dest.enderDest.nro, TpcnTipoCampo.tcStr, TpcnResources.nro); wCampo(NFe.dest.enderDest.xCpl, TpcnTipoCampo.tcStr, TpcnResources.xCpl, ObOp.Opcional); wCampo(NFe.dest.enderDest.xBairro, TpcnTipoCampo.tcStr, TpcnResources.xBairro); wCampo(NFe.dest.enderDest.cMun, TpcnTipoCampo.tcInt, TpcnResources.cMun, ObOp.Obrigatorio, 7); wCampo(NFe.dest.enderDest.xMun, TpcnTipoCampo.tcStr, TpcnResources.xMun); wCampo(NFe.dest.enderDest.UF, TpcnTipoCampo.tcStr, TpcnResources.UF); wCampo(NFe.dest.enderDest.CEP, TpcnTipoCampo.tcInt, TpcnResources.CEP, ObOp.Opcional, 8); wCampo(NFe.dest.enderDest.cPais, TpcnTipoCampo.tcInt, TpcnResources.cPais, ObOp.Opcional, 4); wCampo(NFe.dest.enderDest.xPais, TpcnTipoCampo.tcStr, TpcnResources.xPais, ObOp.Opcional); wCampo(NFe.dest.enderDest.fone, TpcnTipoCampo.tcStr, TpcnResources.fone, ObOp.Opcional); } /// /// </enderDest"> /// nodeCurrent = e0; if (e0.HasChildNodes) { if ((double)NFe.infNFe.Versao >= 3.10) wCampo((int)NFe.dest.indIEDest, TpcnTipoCampo.tcInt, TpcnResources.indIEDest, ObOp.Obrigatorio); else NFe.dest.indIEDest = TpcnindIEDest.inContribuinte; //força para a versao 2.00 switch (NFe.dest.indIEDest) { case TpcnindIEDest.inContribuinte: case TpcnindIEDest.inNaoContribuinte: { if (!string.IsNullOrEmpty(NFe.dest.IE) || NFe.infNFe.Versao < 3) { if (NFe.dest.enderDest.UF != "EX" || NFe.dest.enderDest.cPais == 1058) { if (string.IsNullOrEmpty(NFe.dest.IE)) { wCampo("", TpcnTipoCampo.tcStr, TpcnResources.IE); } else if (!string.IsNullOrEmpty(NFe.dest.IE) || NFe.ide.mod != TpcnMod.modNFCe) { wCampo(NFe.dest.IE, TpcnTipoCampo.tcStr, TpcnResources.IE); } } else { wCampo("ISENTO", TpcnTipoCampo.tcStr, TpcnResources.IE); } } } break; } wCampo(NFe.dest.ISUF, TpcnTipoCampo.tcStr, TpcnResources.ISUF, ObOp.Opcional); wCampo(NFe.dest.IM, TpcnTipoCampo.tcStr, TpcnResources.IM, ObOp.Opcional); wCampo(NFe.dest.email, TpcnTipoCampo.tcStr, TpcnResources.email, ObOp.Opcional); } return e0; }
/// <summary> /// GerarDetImpostoPIS /// </summary> /// <param name="PIS"></param> /// <param name="nodeImposto"></param> private void GerarDetImpostoPIS(NFe nfe, PIS PIS, XmlElement nodeImposto) { if (!string.IsNullOrEmpty(PIS.CST)) { XmlElement e0 = doc.CreateElement("PIS"); switch (PIS.CST) { case "01": case "02": nodeCurrent = doc.CreateElement("PISAliq"); e0.AppendChild(nodeCurrent); nodeImposto.AppendChild(e0); wCampo(PIS.CST, TpcnTipoCampo.tcStr, TpcnResources.CST); wCampo(PIS.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); wCampo(PIS.pPIS, this.nDecimaisPerc, TpcnResources.pPIS); wCampo(PIS.vPIS, TpcnTipoCampo.tcDec2, TpcnResources.vPIS); break; case "03": nodeCurrent = doc.CreateElement("PISQtde"); e0.AppendChild(nodeCurrent); nodeImposto.AppendChild(e0); wCampo(PIS.CST, TpcnTipoCampo.tcStr, TpcnResources.CST); wCampo(PIS.qBCProd, TpcnTipoCampo.tcDec4, TpcnResources.qBCProd); wCampo(PIS.vAliqProd, TpcnTipoCampo.tcDec4, TpcnResources.vAliqProd); wCampo(PIS.vPIS, TpcnTipoCampo.tcDec2, TpcnResources.vPIS); break; case "04": case "05": case "06": case "07": case "08": case "09": nodeCurrent = doc.CreateElement("PISNT"); e0.AppendChild(nodeCurrent); nodeImposto.AppendChild(e0); wCampo(PIS.CST, TpcnTipoCampo.tcStr, TpcnResources.CST); break; case "49": case "50": case "51": case "52": case "53": case "54": case "55": case "56": case "60": case "61": case "62": case "63": case "64": case "65": case "66": case "67": case "70": case "71": case "72": case "73": case "74": case "75": case "98": case "99": if ((PIS.vBC + PIS.pPIS > 0) && (PIS.qBCProd + PIS.vAliqProd > 0)) { this.cMensagemErro += "PIS: As TAG's <vBC> e <pPIS> não podem ser informadas em conjunto com as TAG <qBCProd> e <vAliqProd>" + Environment.NewLine; } nodeCurrent = doc.CreateElement(TpcnResources.PISOutr.ToString()); e0.AppendChild(nodeCurrent); nodeImposto.AppendChild(e0); wCampo(PIS.CST, TpcnTipoCampo.tcStr, TpcnResources.CST); if (PIS.qBCProd + PIS.vAliqProd > 0) { wCampo(PIS.qBCProd, TpcnTipoCampo.tcDec4, TpcnResources.qBCProd); wCampo(PIS.vAliqProd, TpcnTipoCampo.tcDec4, TpcnResources.vAliqProd); } else { wCampo(PIS.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); wCampo(PIS.pPIS, this.nDecimaisPerc, TpcnResources.pPIS); } wCampo(PIS.vPIS, TpcnTipoCampo.tcDec2, TpcnResources.vPIS); break; } } }
/// <summary> /// Gerarpag /// </summary> /// <param name="nfe"></param> /// <param name="root"></param> void GerarPag(NFe nfe, XmlElement root) { foreach (pag pagItem in nfe.pag) { XmlElement nodePag = doc.CreateElement("pag"); //YA01 nodeCurrent = nodePag; root.AppendChild(nodePag); wCampo((int)pagItem.tPag, TpcnTipoCampo.tcInt, TpcnResources.tPag, ObOp.Obrigatorio, 2); //YA02 wCampo(pagItem.vPag, TpcnTipoCampo.tcDec2, TpcnResources.vPag, ObOp.Obrigatorio); //YA03 if (!string.IsNullOrEmpty(pagItem.CNPJ)) { XmlElement xnodePag = doc.CreateElement("card"); //YA04 nodeCurrent = xnodePag; nodePag.AppendChild(xnodePag); wCampo((int)pagItem.tpIntegra, TpcnTipoCampo.tcInt, TpcnResources.tpIntegra, ObOp.Opcional); wCampo(pagItem.CNPJ, TpcnTipoCampo.tcStr, TpcnResources.CNPJ, ObOp.Obrigatorio); //YA05 wCampo((int)pagItem.tBand, TpcnTipoCampo.tcInt, TpcnResources.tBand, ObOp.Obrigatorio, 2); //YA06 wCampo(pagItem.cAut, TpcnTipoCampo.tcStr, TpcnResources.cAut, ObOp.Obrigatorio); //YA07 } nodeCurrent = nodePag; } }
/// <summary> /// GerarDetImpostoCOFINSST /// </summary> /// <param name="COFINSST"></param> /// <param name="nodeImposto"></param> private void GerarDetImpostoCOFINSST(NFe nfe, COFINSST COFINSST, XmlElement nodeImposto) { if ((COFINSST.vBC > 0) || (COFINSST.pCOFINS > 0) || (COFINSST.qBCProd > 0) || (COFINSST.vAliqProd > 0) || (COFINSST.vCOFINS > 0)) { if ((COFINSST.vBC + COFINSST.pCOFINS > 0) && (COFINSST.qBCProd + COFINSST.vAliqProd > 0)) this.cMensagemErro += "COFINSST: As TAG's <vBC> e <pCOFINS> não podem ser informadas em conjunto com as TAG <qBCProd> e <vAliqProd>" + Environment.NewLine; XmlElement node0 = doc.CreateElement("COFINSST"); nodeCurrent = node0; if (COFINSST.vBC + COFINSST.pCOFINS > 0) { nodeImposto.AppendChild(node0); wCampo(COFINSST.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); wCampo(COFINSST.pCOFINS, this.nDecimaisPerc, TpcnResources.pCOFINS); wCampo(COFINSST.vCOFINS, TpcnTipoCampo.tcDec2, TpcnResources.vCOFINS); } if (COFINSST.qBCProd + COFINSST.vAliqProd > 0) { nodeImposto.AppendChild(node0); wCampo(COFINSST.qBCProd, TpcnTipoCampo.tcDec4, TpcnResources.qBCProd); wCampo(COFINSST.vAliqProd, TpcnTipoCampo.tcDec4, TpcnResources.vAliqProd); wCampo(COFINSST.vCOFINS, TpcnTipoCampo.tcDec2, TpcnResources.vCOFINS); } } }
/// <summary> /// Converter /// </summary> public bool Converter(string cArquivo, string cFolderDestino)//, string cFolderRetorno) { cRetorno.Clear(); if (this.CarregarArquivo(cArquivo)) { this.LinhaLida = 0; foreach (List<string> content in this.xConteudoArquivo.Values) { NFe = null; NFe = new NFe(); bool houveErro = false; foreach (string xContent in content) { houveErro = false; ++this.LinhaLida; try { /// /// processa o TXT /// this.LerRegistro(xContent); } catch(Exception ex) { houveErro = true; this.cMensagemErro += "Layout: " + this.layout.Replace(prefix, "") + Environment.NewLine; this.cMensagemErro += "Linha lida: " + (this.LinhaLida+1).ToString()+ Environment.NewLine+ "Conteudo: " + xContent.Substring(1) + Environment.NewLine + ex.Message + Environment.NewLine; } } if (!houveErro && this.cMensagemErro == "") { NFeW nfew = new NFeW(); try { nfew.cMensagemErro = this.cMensagemErro; /// /// gera o XML da nota /// nfew.GerarXml(NFe, cFolderDestino);//cFolderRetorno); if (nfew.cFileName != "") { /// /// Adiciona o XML na lista de arquivos convertidos /// this.cRetorno.Add(new txtTOxmlClassRetorno(nfew.cFileName, NFe.infNFe.ID, NFe.ide.nNF, NFe.ide.serie)); } } catch (Exception ex) { nfew.cMensagemErro += ex.Message; } this.cMensagemErro = nfew.cMensagemErro; } if (this.cMensagemErro != "") { /// /// exclui os arquivos gerados /// foreach (txtTOxmlClassRetorno txtClass in this.cRetorno) { string dArquivo = txtClass.XMLFileName; if (File.Exists(dArquivo)) { FileInfo fi = new FileInfo(dArquivo); fi.Delete(); } } } } return string.IsNullOrEmpty(this.cMensagemErro); } return false; }
/// <summary> /// GerarAvulsa /// </summary> /// <param name="NFe"></param> /// <param name="root"></param> private void GerarAvulsa(NFe NFe, XmlElement root) { if (!string.IsNullOrEmpty(NFe.avulsa.CNPJ)) { XmlElement ELav = doc.CreateElement("avulsa"); nodeCurrent = ELav; root.AppendChild(ELav); wCampo(NFe.avulsa.CNPJ, TpcnTipoCampo.tcStr, TpcnResources.CNPJ); wCampo(NFe.avulsa.xOrgao, TpcnTipoCampo.tcStr, TpcnResources.xOrgao); wCampo(NFe.avulsa.matr, TpcnTipoCampo.tcStr, TpcnResources.matr); wCampo(NFe.avulsa.xAgente, TpcnTipoCampo.tcStr, TpcnResources.xAgente); wCampo(NFe.avulsa.fone, TpcnTipoCampo.tcStr, TpcnResources.fone); wCampo(NFe.avulsa.UF, TpcnTipoCampo.tcStr, TpcnResources.UF); wCampo(NFe.avulsa.nDAR, TpcnTipoCampo.tcStr, TpcnResources.nDAR); wCampo(NFe.avulsa.dEmi, TpcnTipoCampo.tcDatYYYY_MM_DD, TpcnResources.dEmi); wCampo(NFe.avulsa.vDAR, TpcnTipoCampo.tcDec2, TpcnResources.vDAR); wCampo(NFe.avulsa.repEmi, TpcnTipoCampo.tcStr, TpcnResources.repEmi); wCampo(NFe.avulsa.dPag, TpcnTipoCampo.tcDatYYYY_MM_DD, TpcnResources.dPag, ObOp.Opcional); } }
/// <summary> /// GerarDetImpostoISSQN /// </summary> /// <param name="nfe"></param> /// <param name="imposto"></param> /// <param name="nodeImposto"></param> private void GerarDetImpostoISSQN(NFe nfe, Imposto imposto, XmlElement nodeImposto) { if ((imposto.ISSQN.vBC > 0) || (imposto.ISSQN.vAliq > 0) || (imposto.ISSQN.vISSQN > 0) || (imposto.ISSQN.cMunFG > 0) || (!string.IsNullOrEmpty(imposto.ISSQN.cListServ))) { nodeCurrent = doc.CreateElement("ISSQN"); nodeImposto.AppendChild(nodeCurrent); wCampo(imposto.ISSQN.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); wCampo(imposto.ISSQN.vAliq, nDecimaisPerc, TpcnResources.vAliq); wCampo(imposto.ISSQN.vISSQN, TpcnTipoCampo.tcDec2, TpcnResources.vISSQN); wCampo(imposto.ISSQN.cMunFG, TpcnTipoCampo.tcInt, TpcnResources.cMunFG, ObOp.Obrigatorio, 7); wCampo(imposto.ISSQN.cListServ, TpcnTipoCampo.tcStr, TpcnResources.cListServ); if ((double)nfe.infNFe.Versao >= 3.10) { wCampo(imposto.ISSQN.vDeducao, TpcnTipoCampo.tcDec2, TpcnResources.vDeducao, ObOp.Opcional); wCampo(imposto.ISSQN.vOutro, TpcnTipoCampo.tcDec2, TpcnResources.vOutro, ObOp.Opcional); wCampo(imposto.ISSQN.vDescIncond, TpcnTipoCampo.tcDec2, TpcnResources.vDescIncond, ObOp.Opcional); wCampo(imposto.ISSQN.vDescCond, TpcnTipoCampo.tcDec2, TpcnResources.vDescCond, ObOp.Opcional); wCampo(imposto.ISSQN.vISSRet, TpcnTipoCampo.tcDec2, TpcnResources.vISSRet, ObOp.Opcional); wCampo((int)imposto.ISSQN.indISS, TpcnTipoCampo.tcInt, TpcnResources.indISS); wCampo(imposto.ISSQN.cServico, TpcnTipoCampo.tcStr, TpcnResources.cServico, ObOp.Opcional); wCampo(imposto.ISSQN.cMun, TpcnTipoCampo.tcInt, TpcnResources.cMun, ObOp.Opcional); wCampo(imposto.ISSQN.cPais, TpcnTipoCampo.tcInt, TpcnResources.cPais, ObOp.Opcional); wCampo(imposto.ISSQN.nProcesso, TpcnTipoCampo.tcStr, TpcnResources.nProcesso, ObOp.Opcional); wCampo(imposto.ISSQN.indIncentivo ? 1 : 2, TpcnTipoCampo.tcInt, TpcnResources.indIncentivo, ObOp.Opcional); } else { wCampo(imposto.ISSQN.cSitTrib, TpcnTipoCampo.tcStr, TpcnResources.cSitTrib); } } }
/// <summary> /// GerarautoXML /// </summary> /// <param name="NFe"></param> /// <param name="root"></param> private void GerarautXML(NFe NFe, XmlElement root) { for (int i = 0; i < NFe.autXML.Count; ++i) { nodeCurrent = doc.CreateElement("autXML"); root.AppendChild(nodeCurrent); if (!string.IsNullOrEmpty(NFe.autXML[i].CNPJ)) wCampo(NFe.autXML[i].CNPJ, TpcnTipoCampo.tcStr, TpcnResources.CNPJ); else wCampo(NFe.autXML[i].CPF, TpcnTipoCampo.tcStr, TpcnResources.CPF); } }
/// <summary> /// GerarExporta /// </summary> /// <param name="exporta"></param> /// <param name="root"></param> private void GerarExporta(NFe nfe, Exporta exporta, XmlElement root) { if ((double)nfe.infNFe.Versao >= 3.10) { if (!string.IsNullOrEmpty(exporta.UFSaidaPais) || !string.IsNullOrEmpty(exporta.xLocExporta)) { nodeCurrent = doc.CreateElement("exporta"); root.AppendChild(nodeCurrent); wCampo(exporta.UFSaidaPais, TpcnTipoCampo.tcStr, TpcnResources.UFSaidaPais); wCampo(exporta.xLocExporta, TpcnTipoCampo.tcStr, TpcnResources.xLocExporta); wCampo(exporta.xLocDespacho, TpcnTipoCampo.tcStr, TpcnResources.xLocDespacho, ObOp.Opcional); } } else if (!string.IsNullOrEmpty(exporta.UFEmbarq) || !string.IsNullOrEmpty(exporta.xLocEmbarq)) { nodeCurrent = doc.CreateElement("exporta"); root.AppendChild(nodeCurrent); wCampo(exporta.UFEmbarq, TpcnTipoCampo.tcStr, TpcnResources.UFEmbarq); wCampo(exporta.xLocEmbarq, TpcnTipoCampo.tcStr, TpcnResources.xLocEmbarq); } }
/// <summary> /// GerarEntrega /// </summary> /// <param name="NFe"></param> /// <param name="root"></param> private void GerarEntrega(NFe NFe, XmlElement root) { if (!string.IsNullOrEmpty(NFe.entrega.xLgr)) { XmlElement e0 = doc.CreateElement("entrega"); root.AppendChild(e0); nodeCurrent = e0; if (string.IsNullOrEmpty(NFe.entrega.CNPJ) && string.IsNullOrEmpty(NFe.entrega.CPF)) throw new Exception("CNPJ/CPF inválido no segmento [F]"); if (!string.IsNullOrEmpty(NFe.entrega.CNPJ)) wCampo(NFe.entrega.CNPJ, TpcnTipoCampo.tcStr, TpcnResources.CNPJ); else wCampo(NFe.entrega.CPF, TpcnTipoCampo.tcStr, TpcnResources.CPF); wCampo(NFe.entrega.xLgr, TpcnTipoCampo.tcStr, TpcnResources.xLgr); wCampo(NFe.entrega.nro, TpcnTipoCampo.tcStr, TpcnResources.nro); wCampo(NFe.entrega.xCpl, TpcnTipoCampo.tcStr, TpcnResources.xCpl, ObOp.Opcional); wCampo(NFe.entrega.xBairro, TpcnTipoCampo.tcStr, TpcnResources.xBairro); wCampo(NFe.entrega.cMun, TpcnTipoCampo.tcInt, TpcnResources.cMun, ObOp.Obrigatorio, 7); wCampo(NFe.entrega.xMun, TpcnTipoCampo.tcStr, TpcnResources.xMun); wCampo(NFe.entrega.UF, TpcnTipoCampo.tcStr, TpcnResources.UF); } }
/// <summary> /// GerarEmit /// </summary> /// <param name="NFe"></param> /// <returns></returns> private XmlElement GerarEmit(NFe NFe) { XmlElement ELemit = doc.CreateElement("emit"); nodeCurrent = ELemit; if (string.IsNullOrEmpty(NFe.emit.CNPJ) && string.IsNullOrEmpty(NFe.emit.CPF)) throw new Exception("CNPJ/CPF inválido no segmento [C]"); if (!string.IsNullOrEmpty(NFe.emit.CNPJ)) wCampo(NFe.emit.CNPJ, TpcnTipoCampo.tcStr, TpcnResources.CNPJ); else wCampo(NFe.emit.CPF, TpcnTipoCampo.tcStr, TpcnResources.CPF); wCampo(NFe.emit.xNome, TpcnTipoCampo.tcStr, TpcnResources.xNome); wCampo(NFe.emit.xFant, TpcnTipoCampo.tcStr, TpcnResources.xFant, ObOp.Opcional); /// /// <enderEmit> /// XmlElement el = doc.CreateElement("enderEmit"); nodeCurrent.AppendChild(el); nodeCurrent = el; wCampo(NFe.emit.enderEmit.xLgr, TpcnTipoCampo.tcStr, TpcnResources.xLgr); wCampo(NFe.emit.enderEmit.nro, TpcnTipoCampo.tcStr, TpcnResources.nro); wCampo(NFe.emit.enderEmit.xCpl, TpcnTipoCampo.tcStr, TpcnResources.xCpl, ObOp.Opcional); wCampo(NFe.emit.enderEmit.xBairro, TpcnTipoCampo.tcStr, TpcnResources.xBairro); wCampo(NFe.emit.enderEmit.cMun, TpcnTipoCampo.tcInt, TpcnResources.cMun, ObOp.Obrigatorio, 7); wCampo(NFe.emit.enderEmit.xMun, TpcnTipoCampo.tcStr, TpcnResources.xMun); wCampo(NFe.emit.enderEmit.UF, TpcnTipoCampo.tcStr, TpcnResources.UF); wCampo(NFe.emit.enderEmit.CEP, TpcnTipoCampo.tcInt, TpcnResources.CEP, ObOp.Opcional, 8); wCampo(NFe.emit.enderEmit.cPais, TpcnTipoCampo.tcInt, TpcnResources.cPais, ObOp.Opcional); wCampo(NFe.emit.enderEmit.xPais, TpcnTipoCampo.tcStr, TpcnResources.xPais, ObOp.Opcional); wCampo(NFe.emit.enderEmit.fone, TpcnTipoCampo.tcStr, TpcnResources.fone, ObOp.Opcional); /// /// </enderEmit> /// nodeCurrent = ELemit; wCampo(NFe.emit.IE, TpcnTipoCampo.tcStr, TpcnResources.IE); wCampo(NFe.emit.IEST, TpcnTipoCampo.tcStr, TpcnResources.IEST, ObOp.Opcional); wCampo(NFe.emit.IM, TpcnTipoCampo.tcStr, TpcnResources.IM, ObOp.Opcional); if (NFe.emit.IM.Length > 0) wCampo(NFe.emit.CNAE, TpcnTipoCampo.tcStr, TpcnResources.CNAE, ObOp.Opcional); wCampo(NFe.emit.CRT, TpcnTipoCampo.tcInt, TpcnResources.CRT); return ELemit; }
/// <summary> /// GerarDetImpostoPISST /// </summary> /// <param name="PISST"></param> /// <param name="nodeImposto"></param> private void GerarDetImpostoPISST(NFe nfe, PISST PISST, XmlElement nodeImposto) { if ((PISST.vBC > 0) || (PISST.pPis > 0) || (PISST.qBCProd > 0) || (PISST.vAliqProd > 0) || (PISST.vPIS > 0)) { if ((PISST.vBC + PISST.pPis > 0) && (PISST.qBCProd + PISST.vAliqProd > 0)) this.cMensagemErro += "PISST: As TAG's <vBC> e <pPIS> não podem ser informadas em conjunto com as TAG <qBCProd> e <vAliqProd>)" + Environment.NewLine; if (PISST.vBC + PISST.pPis > 0) { nodeCurrent = doc.CreateElement("PISST"); nodeImposto.AppendChild(nodeCurrent); wCampo(PISST.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); wCampo(PISST.pPis, this.nDecimaisPerc, TpcnResources.pPIS); wCampo(PISST.vPIS, TpcnTipoCampo.tcDec2, TpcnResources.vPIS); } if (PISST.qBCProd + PISST.vAliqProd > 0) { nodeCurrent = doc.CreateElement("PISST"); nodeImposto.AppendChild(nodeCurrent); wCampo(PISST.qBCProd, TpcnTipoCampo.tcDec4, TpcnResources.qBCProd); wCampo(PISST.vAliqProd, TpcnTipoCampo.tcDec4, TpcnResources.vAliqProd); wCampo(PISST.vPIS, TpcnTipoCampo.tcDec2, TpcnResources.vPIS); } } }
/// <summary> /// GerarDet /// </summary> /// <param name="NFe"></param> /// <param name="root"></param> private void GerarDet(NFe NFe, XmlElement root) { if (NFe.det.Count > 990) this.cMensagemErro += "Número máximo de itens excedeu o máximo permitido" + Environment.NewLine; foreach (Det det in NFe.det) { XmlElement rootDet = doc.CreateElement("det"); XmlAttribute xmlItem = doc.CreateAttribute("nItem"); xmlItem.Value = det.Prod.nItem.ToString(); rootDet.Attributes.Append(xmlItem); root.AppendChild(rootDet); /// /// Linha do produto /// XmlElement nodeProd = doc.CreateElement("prod"); rootDet.AppendChild(nodeProd); nodeCurrent = nodeProd; this.convertToOem = (det.Prod.comb.cProdANP > 0 && det.Prod.comb.cProdANP > 0 ? false : true); wCampo(det.Prod.cProd, TpcnTipoCampo.tcStr, TpcnResources.cProd); wCampo(det.Prod.cEAN, TpcnTipoCampo.tcStr, TpcnResources.cEAN); wCampo(det.Prod.xProd, TpcnTipoCampo.tcStr, TpcnResources.xProd); this.convertToOem = true; wCampo(det.Prod.NCM, TpcnTipoCampo.tcStr, TpcnResources.NCM); wCampo(det.Prod.NVE, TpcnTipoCampo.tcStr, TpcnResources.NVE, ObOp.Opcional); wCampo(det.Prod.CEST, TpcnTipoCampo.tcInt, TpcnResources.CEST, ObOp.Opcional); wCampo(det.Prod.EXTIPI, TpcnTipoCampo.tcStr, TpcnResources.EXTIPI, ObOp.Opcional); wCampo(det.Prod.CFOP, TpcnTipoCampo.tcStr, TpcnResources.CFOP); wCampo(det.Prod.uCom, TpcnTipoCampo.tcStr, TpcnResources.uCom); wCampo(det.Prod.qCom, TpcnTipoCampo.tcDec4, TpcnResources.qCom); wCampo(det.Prod.vUnCom, det.Prod.vUnCom_Tipo, TpcnResources.vUnCom); wCampo(det.Prod.vProd, TpcnTipoCampo.tcDec2, TpcnResources.vProd); wCampo(det.Prod.cEANTrib, TpcnTipoCampo.tcStr, TpcnResources.cEANTrib); wCampo(det.Prod.uTrib, TpcnTipoCampo.tcStr, TpcnResources.uTrib); wCampo(det.Prod.qTrib, TpcnTipoCampo.tcDec4, TpcnResources.qTrib); wCampo(det.Prod.vUnTrib, det.Prod.vUnTrib_Tipo, TpcnResources.vUnTrib); wCampo(det.Prod.vFrete, TpcnTipoCampo.tcDec2, TpcnResources.vFrete, ObOp.Opcional); wCampo(det.Prod.vSeg, TpcnTipoCampo.tcDec2, TpcnResources.vSeg, ObOp.Opcional); wCampo(det.Prod.vDesc, TpcnTipoCampo.tcDec2, TpcnResources.vDesc, ObOp.Opcional); wCampo(det.Prod.vOutro, TpcnTipoCampo.tcDec2, TpcnResources.vOutro, ObOp.Opcional); wCampo(det.Prod.indTot, TpcnTipoCampo.tcInt, TpcnResources.indTot); #region /// DI if (det.Prod.DI.Count > 100) this.cMensagemErro += "Número máximo de itens DI excedeu o máximo permitido" + Environment.NewLine; XmlNode oldNode = nodeCurrent; foreach (DI di in det.Prod.DI) { XmlElement nodeDI = doc.CreateElement("DI"); nodeProd.AppendChild(nodeDI); nodeCurrent = nodeDI; wCampo(di.nDI, TpcnTipoCampo.tcStr, TpcnResources.nDI); wCampo(di.dDI, TpcnTipoCampo.tcDatYYYY_MM_DD, TpcnResources.dDI); wCampo(di.xLocDesemb, TpcnTipoCampo.tcStr, TpcnResources.xLocDesemb); wCampo(di.UFDesemb, TpcnTipoCampo.tcStr, TpcnResources.UFDesemb); wCampo(di.dDesemb, TpcnTipoCampo.tcDatYYYY_MM_DD, TpcnResources.dDesemb); if (NFe.infNFe.Versao >= 3) { wCampo((int)di.tpViaTransp, TpcnTipoCampo.tcInt, TpcnResources.tpViaTransp, ObOp.Opcional); wCampo(di.vAFRMM, TpcnTipoCampo.tcDec2, TpcnResources.vAFRMM, di.tpViaTransp == TpcnTipoViaTransp.tvMaritima ? ObOp.Obrigatorio : ObOp.Opcional); wCampo((int)di.tpIntermedio, TpcnTipoCampo.tcInt, TpcnResources.tpIntermedio, ObOp.Opcional); wCampo(di.CNPJ, TpcnTipoCampo.tcStr, TpcnResources.CNPJ, ObOp.Opcional); wCampo(di.UFTerceiro, TpcnTipoCampo.tcStr, TpcnResources.UFTerceiro, ObOp.Opcional); } wCampo(di.cExportador, TpcnTipoCampo.tcStr, TpcnResources.cExportador); // //GerarDetProdDIadi // if (di.adi.Count > 100) this.cMensagemErro += "Número máximo de itens DI->ADI excedeu o máximo permitido" + Environment.NewLine; if (di.adi.Count == 0) this.cMensagemErro += "Número minimo de itens DI->ADI não permitido" + Environment.NewLine; foreach (Adi adi in di.adi) { XmlElement e1 = doc.CreateElement("adi"); nodeDI.AppendChild(e1); nodeCurrent = e1; wCampo(adi.nAdicao, TpcnTipoCampo.tcInt, TpcnResources.nAdicao); wCampo(adi.nSeqAdi, TpcnTipoCampo.tcInt, TpcnResources.nSeqAdic); wCampo(adi.cFabricante, TpcnTipoCampo.tcStr, TpcnResources.cFabricante); wCampo(adi.vDescDI, TpcnTipoCampo.tcDec2, TpcnResources.vDescDI, ObOp.Opcional); wCampo(adi.nDraw, TpcnTipoCampo.tcStr, TpcnResources.nDraw, ObOp.Opcional); } } nodeCurrent = oldNode; #endregion wCampo(det.Prod.xPed, TpcnTipoCampo.tcStr, TpcnResources.xPed, ObOp.Opcional); wCampo(det.Prod.nItemPed, TpcnTipoCampo.tcInt, TpcnResources.nItemPed, ObOp.Opcional); #region -- GerarDetProddetExport if (det.Prod.detExport.Count > 500) this.cMensagemErro += "Número máximo de itens em 'prod->detExport' excedeu o máximo permitido" + Environment.NewLine; foreach (detExport detx in det.Prod.detExport) { XmlElement nodeDI = doc.CreateElement("detExport"); nodeProd.AppendChild(nodeDI); nodeCurrent = nodeDI; wCampo(detx.nDraw, TpcnTipoCampo.tcStr, TpcnResources.nDraw); if (!string.IsNullOrEmpty(detx.exportInd.nRE)) { XmlElement nodeDI2 = doc.CreateElement("exportInd"); nodeDI.AppendChild(nodeDI2); nodeCurrent = nodeDI2; wCampo(detx.exportInd.nRE, TpcnTipoCampo.tcStr, TpcnResources.nRE, ObOp.Obrigatorio); wCampo(detx.exportInd.chNFe, TpcnTipoCampo.tcStr, TpcnResources.chNFe, ObOp.Obrigatorio); wCampo(detx.exportInd.qExport, TpcnTipoCampo.tcDec4, TpcnResources.qExport, ObOp.Opcional); } } nodeCurrent = oldNode; #endregion wCampo(det.Prod.nFCI, TpcnTipoCampo.tcStr, TpcnResources.nFCI, ObOp.Opcional); #region /// veiculos if (!string.IsNullOrEmpty(det.Prod.veicProd.chassi)) { oldNode = nodeCurrent; XmlElement nodeVeic = doc.CreateElement("veicProd"); nodeProd.AppendChild(nodeVeic); nodeCurrent = nodeVeic; wCampo(det.Prod.veicProd.tpOp, TpcnTipoCampo.tcStr, TpcnResources.tpOp); wCampo(det.Prod.veicProd.chassi, TpcnTipoCampo.tcStr, TpcnResources.chassi); wCampo(det.Prod.veicProd.cCor, TpcnTipoCampo.tcStr, TpcnResources.cCor); wCampo(det.Prod.veicProd.xCor, TpcnTipoCampo.tcStr, TpcnResources.xCor); wCampo(det.Prod.veicProd.pot, TpcnTipoCampo.tcStr, TpcnResources.pot); wCampo(det.Prod.veicProd.cilin, TpcnTipoCampo.tcStr, TpcnResources.cilin); wCampo(det.Prod.veicProd.pesoL, TpcnTipoCampo.tcStr, TpcnResources.pesoL); wCampo(det.Prod.veicProd.pesoB, TpcnTipoCampo.tcStr, TpcnResources.pesoB); wCampo(det.Prod.veicProd.nSerie, TpcnTipoCampo.tcStr, TpcnResources.nSerie); wCampo(det.Prod.veicProd.tpComb, TpcnTipoCampo.tcStr, TpcnResources.tpComb); wCampo(det.Prod.veicProd.nMotor, TpcnTipoCampo.tcStr, TpcnResources.nMotor); wCampo(det.Prod.veicProd.CMT, TpcnTipoCampo.tcStr, TpcnResources.CMT); wCampo(det.Prod.veicProd.dist, TpcnTipoCampo.tcStr, TpcnResources.dist); wCampo(det.Prod.veicProd.anoMod, TpcnTipoCampo.tcInt, TpcnResources.anoMod, ObOp.Obrigatorio, 4); wCampo(det.Prod.veicProd.anoFab, TpcnTipoCampo.tcInt, TpcnResources.anoFab, ObOp.Obrigatorio, 4); wCampo(det.Prod.veicProd.tpPint, TpcnTipoCampo.tcStr, TpcnResources.tpPint); wCampo(det.Prod.veicProd.tpVeic, TpcnTipoCampo.tcInt, TpcnResources.tpVeic); wCampo(det.Prod.veicProd.espVeic, TpcnTipoCampo.tcInt, TpcnResources.espVeic); wCampo(det.Prod.veicProd.VIN, TpcnTipoCampo.tcStr, TpcnResources.VIN); wCampo(det.Prod.veicProd.condVeic, TpcnTipoCampo.tcStr, TpcnResources.condVeic); wCampo(det.Prod.veicProd.cMod, TpcnTipoCampo.tcStr, TpcnResources.cMod); wCampo(det.Prod.veicProd.cCorDENATRAN, TpcnTipoCampo.tcInt, TpcnResources.cCorDENATRAN, ObOp.Obrigatorio, 2); wCampo(det.Prod.veicProd.lota, TpcnTipoCampo.tcInt, TpcnResources.lota); wCampo(det.Prod.veicProd.tpRest, TpcnTipoCampo.tcInt, TpcnResources.tpRest); nodeCurrent = oldNode; } #endregion #region /// medicamentos if (det.Prod.med.Count > 500) this.cMensagemErro += "Número máximo de itens em 'med' excedeu o máximo permitido" + Environment.NewLine; foreach (Med med in det.Prod.med) { XmlElement e0 = doc.CreateElement("med"); nodeProd.AppendChild(e0); nodeCurrent = e0; wCampo(med.nLote, TpcnTipoCampo.tcStr, TpcnResources.nLote); wCampo(med.qLote, TpcnTipoCampo.tcDec3, TpcnResources.qLote); wCampo(med.dFab, TpcnTipoCampo.tcDatYYYY_MM_DD, TpcnResources.dFab); wCampo(med.dVal, TpcnTipoCampo.tcDatYYYY_MM_DD, TpcnResources.dVal); wCampo(med.vPMC, TpcnTipoCampo.tcDec2, TpcnResources.vPMC); } #endregion #region /// armamento if (det.Prod.arma.Count > 500) this.cMensagemErro += "Número máximo de itens em 'arma' excedeu o máximo permitido" + Environment.NewLine; foreach (Arma arma in det.Prod.arma) { XmlElement nodeArma = doc.CreateElement("arma"); nodeProd.AppendChild(nodeArma); nodeCurrent = nodeArma; wCampo(arma.tpArma, TpcnTipoCampo.tcInt, TpcnResources.tpArma); wCampo(arma.nSerie, TpcnTipoCampo.tcInt, TpcnResources.nSerie); wCampo(arma.nCano, TpcnTipoCampo.tcInt, TpcnResources.nCano); wCampo(arma.descr, TpcnTipoCampo.tcStr, TpcnResources.descr); } #endregion #region /// combustiveis if (det.Prod.comb.cProdANP > 0) { XmlElement e0 = doc.CreateElement("comb"); nodeProd.AppendChild(e0); nodeCurrent = e0; wCampo(det.Prod.comb.cProdANP, TpcnTipoCampo.tcInt, TpcnResources.cProdANP); wCampo(det.Prod.comb.pMixGN, TpcnTipoCampo.tcDec4, TpcnResources.pMixGN, ObOp.Opcional); if (!string.IsNullOrEmpty(det.Prod.comb.CODIF)) wCampo(det.Prod.comb.CODIF, TpcnTipoCampo.tcStr, TpcnResources.CODIF); if (det.Prod.comb.qTemp > 0) wCampo(det.Prod.comb.qTemp, TpcnTipoCampo.tcDec4, TpcnResources.qTemp); wCampo(det.Prod.comb.UFCons, TpcnTipoCampo.tcStr, TpcnResources.UFCons); if ((det.Prod.comb.CIDE.qBCprod > 0) || (det.Prod.comb.CIDE.vAliqProd > 0) || (det.Prod.comb.CIDE.vCIDE > 0)) { XmlElement e1 = doc.CreateElement("CIDE"); e0.AppendChild(e1); nodeCurrent = e1; wCampo(det.Prod.comb.CIDE.qBCprod, TpcnTipoCampo.tcDec4, TpcnResources.qBCProd); wCampo(det.Prod.comb.CIDE.vAliqProd, TpcnTipoCampo.tcDec4, TpcnResources.vAliqProd); wCampo(det.Prod.comb.CIDE.vCIDE, TpcnTipoCampo.tcDec2, TpcnResources.vCIDE); nodeCurrent = e0; } if (det.Prod.comb.encerrante.nBico > 0 && det.Prod.comb.encerrante.nTanque > 0 && !string.IsNullOrEmpty(det.Prod.comb.encerrante.vEncIni) && !string.IsNullOrEmpty(det.Prod.comb.encerrante.vEncFin)) { XmlElement e1 = doc.CreateElement("encerrante"); e0.AppendChild(e1); nodeCurrent = e1; wCampo((int)det.Prod.comb.encerrante.nBico, TpcnTipoCampo.tcInt, TpcnResources.nBico); wCampo((int)det.Prod.comb.encerrante.nBomba, TpcnTipoCampo.tcInt, TpcnResources.nBomba, ObOp.Opcional); wCampo((int)det.Prod.comb.encerrante.nTanque, TpcnTipoCampo.tcInt, TpcnResources.nTanque); wCampo(det.Prod.comb.encerrante.vEncIni, TpcnTipoCampo.tcStr, TpcnResources.vEncIni); wCampo(det.Prod.comb.encerrante.vEncFin, TpcnTipoCampo.tcStr, TpcnResources.vEncFin); nodeCurrent = e0; } } #endregion wCampo(det.Prod.nRECOPI, TpcnTipoCampo.tcStr, TpcnResources.nRECOPI, ObOp.Opcional); GerarDetImposto(NFe, det.Imposto, rootDet); GerarDetDevol(det.impostoDevol, rootDet); nodeCurrent = rootDet; wCampo(det.infAdProd, TpcnTipoCampo.tcStr, TpcnResources.infAdProd, ObOp.Opcional); } }
/// <summary> /// GerarInfNFe /// </summary> /// <param name="Nfe"></param> /// <returns></returns> private XmlElement GerarIde(NFe Nfe) { XmlElement ELide = doc.CreateElement("ide"); nodeCurrent = ELide; wCampo(Nfe.ide.cUF, TpcnTipoCampo.tcInt, TpcnResources.cUF, ObOp.Obrigatorio, 0); wCampo(Nfe.ide.cNF, TpcnTipoCampo.tcInt, TpcnResources.cNF, ObOp.Obrigatorio, 8); wCampo(Nfe.ide.natOp, TpcnTipoCampo.tcStr, TpcnResources.natOp, ObOp.Obrigatorio, 0); wCampo((int)Nfe.ide.indPag, TpcnTipoCampo.tcInt, TpcnResources.indPag, ObOp.Obrigatorio, 0); wCampo((int)Nfe.ide.mod, TpcnTipoCampo.tcInt, TpcnResources.mod, ObOp.Obrigatorio, 0); wCampo(Nfe.ide.serie, TpcnTipoCampo.tcInt, TpcnResources.serie, ObOp.Obrigatorio, 0); wCampo(Nfe.ide.nNF, TpcnTipoCampo.tcInt, TpcnResources.nNF, ObOp.Obrigatorio, 0); if (Nfe.infNFe.Versao >= 3) { wCampo(Nfe.ide.dhEmi, TpcnTipoCampo.tcStr, TpcnResources.dhEmi, ObOp.Obrigatorio); if (Nfe.ide.mod == TpcnMod.modNFe) wCampo(Nfe.ide.dhSaiEnt, TpcnTipoCampo.tcStr, TpcnResources.dhSaiEnt, ObOp.Opcional); } else { wCampo(Nfe.ide.dEmi, TpcnTipoCampo.tcDatYYYY_MM_DD, TpcnResources.dEmi, ObOp.Obrigatorio, 0); wCampo(Nfe.ide.dSaiEnt, TpcnTipoCampo.tcDatYYYY_MM_DD, TpcnResources.dSaiEnt, ObOp.Opcional, 0); wCampo(Nfe.ide.hSaiEnt, TpcnTipoCampo.tcHor, TpcnResources.hSaiEnt, ObOp.Opcional, 0); } wCampo((int)Nfe.ide.tpNF, TpcnTipoCampo.tcInt, TpcnResources.tpNF, ObOp.Obrigatorio, 0); if (Nfe.infNFe.Versao >= 3) wCampo((Nfe.ide.mod == TpcnMod.modNFe ? (int)Nfe.ide.idDest : (int)TpcnDestinoOperacao.doInterna), TpcnTipoCampo.tcInt, TpcnResources.idDest, ObOp.Obrigatorio); //B11a wCampo(Nfe.ide.cMunFG, TpcnTipoCampo.tcInt, TpcnResources.cMunFG, ObOp.Obrigatorio, 0); if (Nfe.infNFe.Versao < 3) this.GerarIdeNFref(Nfe, ELide); nodeCurrent = ELide; wCampo((int)Nfe.ide.tpImp, TpcnTipoCampo.tcInt, TpcnResources.tpImp, (Nfe.infNFe.Versao >= 3 ? ObOp.Opcional : ObOp.Obrigatorio)); wCampo((int)Nfe.ide.tpEmis, TpcnTipoCampo.tcInt, TpcnResources.tpEmis, ObOp.Obrigatorio); wCampo(Nfe.ide.cDV, TpcnTipoCampo.tcInt, TpcnResources.cDV, ObOp.Obrigatorio); wCampo((int)Nfe.ide.tpAmb, TpcnTipoCampo.tcInt, TpcnResources.tpAmb, ObOp.Obrigatorio); wCampo((int)Nfe.ide.finNFe, TpcnTipoCampo.tcInt, TpcnResources.finNFe, ObOp.Obrigatorio); if (Nfe.infNFe.Versao >= 3) { wCampo((int)Nfe.ide.indFinal, TpcnTipoCampo.tcInt, TpcnResources.indFinal, ObOp.Obrigatorio);//B25a wCampo((int)Nfe.ide.indPres, TpcnTipoCampo.tcInt, TpcnResources.indPres, ObOp.Obrigatorio);//B25b } wCampo(Nfe.ide.procEmi, TpcnTipoCampo.tcInt, TpcnResources.procEmi, ObOp.Obrigatorio); wCampo(Nfe.ide.verProc, TpcnTipoCampo.tcStr, TpcnResources.verProc, ObOp.Obrigatorio); wCampo(Nfe.ide.dhCont, TpcnTipoCampo.tcStr, TpcnResources.dhCont, ObOp.Opcional); wCampo(Nfe.ide.xJust, TpcnTipoCampo.tcStr, TpcnResources.xJust, ObOp.Opcional); if (Nfe.infNFe.Versao >= 3) this.GerarIdeNFref(Nfe, ELide); return ELide; }
/// <summary> /// GerarDetImposto /// </summary> /// <param name="nfe"></param> /// <param name="imposto"></param> /// <param name="root"></param> private void GerarDetImposto(NFe nfe, Imposto imposto, XmlElement root) { XmlElement nodeImposto = doc.CreateElement("imposto"); root.AppendChild(nodeImposto); nodeCurrent = nodeImposto; wCampo(imposto.vTotTrib, TpcnTipoCampo.tcDec2, TpcnResources.vTotTrib, ObOp.Opcional); if ((double)nfe.infNFe.Versao < 3.10) { if (!string.IsNullOrEmpty(imposto.ISSQN.cSitTrib)) { GerarDetImpostoISSQN(nfe, imposto, nodeImposto); } else { GerarDetImpostoICMS(nfe, imposto, nodeImposto); GerarDetImpostoIPI(nfe, imposto.IPI, nodeImposto); if (nfe.det[0].Prod.DI.Count > 0) GerarDetImpostoII(imposto.II, nodeImposto); } } else { GerarDetImpostoICMS(nfe, imposto, nodeImposto); GerarDetImpostoIPI(nfe, imposto.IPI, nodeImposto); if (nfe.det[0].Prod.DI.Count > 0) GerarDetImpostoII(imposto.II, nodeImposto); GerarDetImpostoISSQN(nfe, imposto, nodeImposto); } GerarDetImpostoPIS(nfe, imposto.PIS, nodeImposto); GerarDetImpostoPISST(nfe, imposto.PISST, nodeImposto); GerarDetImpostoCOFINS(nfe, imposto.COFINS, nodeImposto); GerarDetImpostoCOFINSST(nfe, imposto.COFINSST, nodeImposto); }
/// <summary> /// GerarIdeNFref /// </summary> /// <param name="Nfe"></param> /// <param name="ELide"></param> void GerarIdeNFref(NFe Nfe, XmlElement ELide) { // Gera TAGs referentes a NFe referência foreach (NFref refNFe in Nfe.ide.NFref) { if (!string.IsNullOrEmpty(refNFe.refNFe)) { XmlElement ep = doc.CreateElement(TpcnResources.NFref.ToString()); XmlElement el = doc.CreateElement(TpcnResources.refNFe.ToString()); el.InnerText = refNFe.refNFe; ep.AppendChild(el); ELide.AppendChild(ep); } } // Gera TAGs se NÃO for uma NFe referência foreach (NFref refNFe in Nfe.ide.NFref) { if (refNFe.refNF != null) { if (refNFe.refNF.nNF > 0) { XmlElement ep = doc.CreateElement(TpcnResources.NFref.ToString()); XmlElement el = doc.CreateElement("refNF"); ep.AppendChild(el); ELide.AppendChild(ep); nodeCurrent = el; wCampo(refNFe.refNF.cUF, TpcnTipoCampo.tcInt, TpcnResources.cUF, ObOp.Obrigatorio, 2); wCampo(refNFe.refNF.AAMM, TpcnTipoCampo.tcStr, TpcnResources.AAMM, ObOp.Obrigatorio, 0); wCampo(refNFe.refNF.CNPJ, TpcnTipoCampo.tcStr, TpcnResources.CNPJ, ObOp.Obrigatorio, 0); wCampo(refNFe.refNF.mod, TpcnTipoCampo.tcStr, TpcnResources.mod, ObOp.Obrigatorio, 2); wCampo(refNFe.refNF.serie, TpcnTipoCampo.tcInt, TpcnResources.serie, ObOp.Obrigatorio, 0); wCampo(refNFe.refNF.nNF, TpcnTipoCampo.tcInt, TpcnResources.nNF, ObOp.Obrigatorio, 0); } } } foreach (NFref refNFe in Nfe.ide.NFref) { if (refNFe.refNFP != null) { if (refNFe.refNFP.nNF > 0) { XmlElement ep = doc.CreateElement(TpcnResources.NFref.ToString()); XmlElement el = doc.CreateElement("refNFP"); ep.AppendChild(el); ELide.AppendChild(ep); nodeCurrent = el; wCampo(refNFe.refNFP.cUF, TpcnTipoCampo.tcInt, TpcnResources.cUF, ObOp.Obrigatorio, 2); wCampo(refNFe.refNFP.AAMM, TpcnTipoCampo.tcStr, TpcnResources.AAMM, ObOp.Obrigatorio, 0); if (!string.IsNullOrEmpty(refNFe.refNFP.CNPJ)) wCampo(refNFe.refNFP.CNPJ, TpcnTipoCampo.tcStr, TpcnResources.CNPJ, ObOp.Obrigatorio, 0); else if (!string.IsNullOrEmpty(refNFe.refNFP.CPF)) wCampo(refNFe.refNFP.CPF, TpcnTipoCampo.tcStr, TpcnResources.CPF, ObOp.Obrigatorio, 0); wCampo(refNFe.refNFP.IE, TpcnTipoCampo.tcStr, TpcnResources.IE, ObOp.Opcional, 0); wCampo(refNFe.refNFP.mod, TpcnTipoCampo.tcStr, TpcnResources.mod, ObOp.Obrigatorio, 2); wCampo(refNFe.refNFP.serie, TpcnTipoCampo.tcInt, TpcnResources.serie, ObOp.Obrigatorio, 0); wCampo(refNFe.refNFP.nNF, TpcnTipoCampo.tcInt, TpcnResources.nNF, ObOp.Obrigatorio, 0); } } } foreach (NFref refNFe in Nfe.ide.NFref) { if (!string.IsNullOrEmpty(refNFe.refCTe)) { if (refNFe.refCTe.Substring(0, 2) != "00") { XmlElement ep = doc.CreateElement(TpcnResources.NFref.ToString()); XmlElement el = doc.CreateElement(TpcnResources.refCTe.ToString()); el.InnerText = refNFe.refCTe; ep.AppendChild(el); ELide.AppendChild(ep); } } } foreach (NFref refNFe in Nfe.ide.NFref) { if (refNFe.refECF != null) { if (refNFe.refECF.nCOO > 0) { XmlElement ep = doc.CreateElement(TpcnResources.NFref.ToString()); XmlElement el = doc.CreateElement("refECF"); ep.AppendChild(el); ELide.AppendChild(ep); nodeCurrent = el; wCampo(refNFe.refECF.mod, TpcnTipoCampo.tcStr, TpcnResources.mod, ObOp.Obrigatorio); wCampo(refNFe.refECF.nECF, TpcnTipoCampo.tcInt, TpcnResources.nECF, ObOp.Obrigatorio, 3); wCampo(refNFe.refECF.nCOO, TpcnTipoCampo.tcInt, TpcnResources.nCOO, ObOp.Obrigatorio); } } } }
/// <summary> /// GerarDetImpostoCOFINS /// </summary> /// <param name="COFINS"></param> /// <param name="nodeImposto"></param> private void GerarDetImpostoCOFINS(NFe nfe, COFINS COFINS, XmlElement nodeImposto) { if (!string.IsNullOrEmpty(COFINS.CST)) { XmlElement node0 = doc.CreateElement("COFINS"); switch (COFINS.CST) { case "01": case "02": { nodeCurrent = doc.CreateElement("COFINSAliq"); node0.AppendChild(nodeCurrent); nodeImposto.AppendChild(node0); wCampo(COFINS.CST, TpcnTipoCampo.tcStr, TpcnResources.CST); wCampo(COFINS.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); wCampo(COFINS.pCOFINS, this.nDecimaisPerc, TpcnResources.pCOFINS); wCampo(COFINS.vCOFINS, TpcnTipoCampo.tcDec2, TpcnResources.vCOFINS); } break; case "03": { nodeCurrent = doc.CreateElement("COFINSQtde"); node0.AppendChild(nodeCurrent); nodeImposto.AppendChild(node0); wCampo(COFINS.CST, TpcnTipoCampo.tcStr, TpcnResources.CST); wCampo(COFINS.qBCProd, TpcnTipoCampo.tcDec4, TpcnResources.qBCProd); wCampo(COFINS.vAliqProd, TpcnTipoCampo.tcDec4, TpcnResources.vAliqProd); wCampo(COFINS.vCOFINS, TpcnTipoCampo.tcDec2, TpcnResources.vCOFINS); } break; case "04": case "05": case "06": case "07": case "08": case "09": { nodeCurrent = doc.CreateElement("COFINSNT"); node0.AppendChild(nodeCurrent); nodeImposto.AppendChild(node0); wCampo(COFINS.CST, TpcnTipoCampo.tcStr, TpcnResources.CST); } break; case "49": case "50": case "51": case "52": case "53": case "54": case "55": case "56": case "60": case "61": case "62": case "63": case "64": case "65": case "66": case "67": case "70": case "71": case "72": case "73": case "74": case "75": case "98": case "99": { if ((COFINS.vBC + COFINS.pCOFINS > 0) && (COFINS.qBCProd + COFINS.vAliqProd > 0)) this.cMensagemErro += "COFINSOutr: As TAG's <vBC> e <pCOFINS> não podem ser informadas em conjunto com as TAG <qBCProd> e <vAliqProd>" + Environment.NewLine; nodeCurrent = doc.CreateElement("COFINSOutr"); node0.AppendChild(nodeCurrent); nodeImposto.AppendChild(node0); wCampo(COFINS.CST, TpcnTipoCampo.tcStr, TpcnResources.CST); if (COFINS.qBCProd + COFINS.vAliqProd > 0) { wCampo(COFINS.qBCProd, TpcnTipoCampo.tcDec4, TpcnResources.qBCProd); wCampo(COFINS.vAliqProd, TpcnTipoCampo.tcDec4, TpcnResources.vAliqProd); } else { wCampo(COFINS.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); wCampo(COFINS.pCOFINS, this.nDecimaisPerc, TpcnResources.pCOFINS); } wCampo(COFINS.vCOFINS, TpcnTipoCampo.tcDec2, TpcnResources.vCOFINS); } break; } } }
/// <summary> /// GerarRetirada /// </summary> /// <param name="NFe"></param> /// <param name="root"></param> private void GerarRetirada(NFe NFe, XmlElement root) { if (!string.IsNullOrEmpty(NFe.retirada.xLgr)) { XmlElement el = doc.CreateElement("retirada"); root.AppendChild(el); nodeCurrent = el; if (!string.IsNullOrEmpty(NFe.retirada.CNPJ)) wCampo(NFe.retirada.CNPJ, TpcnTipoCampo.tcStr, TpcnResources.CNPJ); else wCampo(NFe.retirada.CPF, TpcnTipoCampo.tcStr, TpcnResources.CPF); wCampo(NFe.retirada.xLgr, TpcnTipoCampo.tcStr, TpcnResources.xLgr); wCampo(NFe.retirada.nro, TpcnTipoCampo.tcStr, TpcnResources.nro); wCampo(NFe.retirada.xCpl, TpcnTipoCampo.tcStr, TpcnResources.xCpl, ObOp.Opcional); wCampo(NFe.retirada.xBairro, TpcnTipoCampo.tcStr, TpcnResources.xBairro); wCampo(NFe.retirada.cMun, TpcnTipoCampo.tcInt, TpcnResources.cMun, ObOp.Obrigatorio, 7); wCampo(NFe.retirada.xMun, TpcnTipoCampo.tcStr, TpcnResources.xMun); wCampo(NFe.retirada.UF, TpcnTipoCampo.tcStr, TpcnResources.UF); } }
/// <summary> /// GerarDetImpostoICMS /// </summary> /// <param name="nfe"></param> /// <param name="imposto"></param> /// <param name="nodeImposto"></param> private void GerarDetImpostoICMS(NFe nfe, Imposto imposto, XmlElement nodeImposto) { if (!string.IsNullOrEmpty(imposto.ICMS.CST)) { if (imposto.ICMS.ICMSst == 1) { XmlElement e0 = doc.CreateElement(TpcnResources.ICMS.ToString()); nodeCurrent = doc.CreateElement("ICMSST"); e0.AppendChild(nodeCurrent); nodeImposto.AppendChild(e0); wCampo(imposto.ICMS.orig, TpcnTipoCampo.tcInt, TpcnResources.orig); wCampo(imposto.ICMS.CST, TpcnTipoCampo.tcStr, TpcnResources.CST); wCampo(imposto.ICMS.vBCSTRet, TpcnTipoCampo.tcDec2, TpcnResources.vBCSTRet); wCampo(imposto.ICMS.vICMSSTRet, TpcnTipoCampo.tcDec2, TpcnResources.vICMSSTRet); wCampo(imposto.ICMS.vBCSTDest, TpcnTipoCampo.tcDec2, TpcnResources.vBCSTDest); wCampo(imposto.ICMS.vICMSSTDest, TpcnTipoCampo.tcDec2, TpcnResources.vICMSSTDest); } else { XmlElement e0 = doc.CreateElement(TpcnResources.ICMS.ToString()); if (imposto.ICMS.ICMSPart10 == 1 || imposto.ICMS.ICMSPart90 == 1) nodeCurrent = doc.CreateElement("ICMSPart"); else nodeCurrent = doc.CreateElement(TpcnResources.ICMS.ToString() + (imposto.ICMS.CST == "41" || imposto.ICMS.CST == "50" ? "40" : imposto.ICMS.CST)); e0.AppendChild(nodeCurrent); nodeImposto.AppendChild(e0); wCampo(imposto.ICMS.orig, TpcnTipoCampo.tcInt, TpcnResources.orig); wCampo(imposto.ICMS.CST, TpcnTipoCampo.tcStr, TpcnResources.CST); switch (imposto.ICMS.CST) { case "00": wCampo(imposto.ICMS.modBC, TpcnTipoCampo.tcInt, TpcnResources.modBC); wCampo(imposto.ICMS.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); wCampo(imposto.ICMS.pICMS, this.nDecimaisPerc, TpcnResources.pICMS); wCampo(imposto.ICMS.vICMS, TpcnTipoCampo.tcDec2, TpcnResources.vICMS); break; case "10": wCampo(imposto.ICMS.modBC, TpcnTipoCampo.tcInt, TpcnResources.modBC); if (imposto.ICMS.ICMSPart10 == 1) wCampo(imposto.ICMS.pRedBC, TpcnTipoCampo.tcDec2, TpcnResources.pRedBC, ObOp.Opcional); wCampo(imposto.ICMS.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); wCampo(imposto.ICMS.pICMS, this.nDecimaisPerc, TpcnResources.pICMS); wCampo(imposto.ICMS.vICMS, TpcnTipoCampo.tcDec2, TpcnResources.vICMS); wCampo(imposto.ICMS.modBCST, TpcnTipoCampo.tcInt, TpcnResources.modBCST); wCampo(imposto.ICMS.pMVAST, this.nDecimaisPerc, TpcnResources.pMVAST, ObOp.Opcional); wCampo(imposto.ICMS.pRedBCST, this.nDecimaisPerc, TpcnResources.pRedBCST, ObOp.Opcional); wCampo(imposto.ICMS.vBCST, TpcnTipoCampo.tcDec2, TpcnResources.vBCST); wCampo(imposto.ICMS.pICMSST, this.nDecimaisPerc, TpcnResources.pICMSST); wCampo(imposto.ICMS.vICMSST, TpcnTipoCampo.tcDec2, TpcnResources.vICMSST); if (imposto.ICMS.ICMSPart10 == 1) { wCampo(imposto.ICMS.pBCOp, this.nDecimaisPerc, TpcnResources.pBCOp); wCampo(imposto.ICMS.UFST, TpcnTipoCampo.tcStr, TpcnResources.UFST); } break; case "20": wCampo(imposto.ICMS.modBC, TpcnTipoCampo.tcInt, TpcnResources.modBC); wCampo(imposto.ICMS.pRedBC, this.nDecimaisPerc, TpcnResources.pRedBC); wCampo(imposto.ICMS.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); wCampo(imposto.ICMS.pICMS, this.nDecimaisPerc, TpcnResources.pICMS); wCampo(imposto.ICMS.vICMS, TpcnTipoCampo.tcDec2, TpcnResources.vICMS); if ((double)nfe.infNFe.Versao >= 3.10 && imposto.ICMS.vICMSDeson > 0) { wCampo(imposto.ICMS.vICMSDeson, TpcnTipoCampo.tcDec2, TpcnResources.vICMSDeson); wCampo(imposto.ICMS.motDesICMS, TpcnTipoCampo.tcInt, TpcnResources.motDesICMS); } break; case "30": wCampo(imposto.ICMS.modBCST, TpcnTipoCampo.tcInt, TpcnResources.modBCST); wCampo(imposto.ICMS.pMVAST, this.nDecimaisPerc, TpcnResources.pMVAST, ObOp.Opcional); wCampo(imposto.ICMS.pRedBCST, this.nDecimaisPerc, TpcnResources.pRedBCST, ObOp.Opcional); wCampo(imposto.ICMS.vBCST, TpcnTipoCampo.tcDec2, TpcnResources.vBCST); wCampo(imposto.ICMS.pICMSST, this.nDecimaisPerc, TpcnResources.pICMSST); wCampo(imposto.ICMS.vICMSST, TpcnTipoCampo.tcDec2, TpcnResources.vICMSST); if ((double)nfe.infNFe.Versao >= 3.10 && imposto.ICMS.vICMSDeson > 0) { wCampo(imposto.ICMS.vICMSDeson, TpcnTipoCampo.tcDec2, TpcnResources.vICMSDeson); wCampo(imposto.ICMS.motDesICMS, TpcnTipoCampo.tcInt, TpcnResources.motDesICMS); } break; case "40": case "41": case "50": if ((double)nfe.infNFe.Versao >= 3.10) { if (imposto.ICMS.vICMSDeson > 0) { wCampo(imposto.ICMS.vICMSDeson, TpcnTipoCampo.tcDec2, TpcnResources.vICMSDeson); wCampo(imposto.ICMS.motDesICMS, TpcnTipoCampo.tcInt, TpcnResources.motDesICMS); } } else { wCampo(imposto.ICMS.vICMS, TpcnTipoCampo.tcDec2, TpcnResources.vICMS, ObOp.Opcional); if (imposto.ICMS.vICMS > 0) wCampo(imposto.ICMS.motDesICMS, TpcnTipoCampo.tcInt, TpcnResources.motDesICMS, ObOp.Opcional); } break; case "51": //Esse bloco fica a critério de cada UF a obrigação das informações, conforme o manual { var obop = ObOp.Opcional; if ((double)nfe.infNFe.Versao >= 3.10) { if (imposto.ICMS.pRedBC > 0 || imposto.ICMS.vBC > 0 || imposto.ICMS.vICMSOp > 0 || imposto.ICMS.pDif > 0 || imposto.ICMS.vICMSDif > 0 || imposto.ICMS.vICMS > 0) obop = ObOp.Obrigatorio; } wCampo(imposto.ICMS.modBC, TpcnTipoCampo.tcInt, TpcnResources.modBC, ObOp.Opcional); wCampo(imposto.ICMS.pRedBC, this.nDecimaisPerc, TpcnResources.pRedBC, obop); wCampo(imposto.ICMS.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC, obop); wCampo(imposto.ICMS.pICMS, this.nDecimaisPerc, TpcnResources.pICMS, obop); if ((double)nfe.infNFe.Versao >= 3.10) { wCampo(imposto.ICMS.vICMSOp, TpcnTipoCampo.tcDec2, TpcnResources.vICMSOp, obop); wCampo(imposto.ICMS.pDif, this.nDecimaisPerc, TpcnResources.pDif, obop); wCampo(imposto.ICMS.vICMSDif, TpcnTipoCampo.tcDec2, TpcnResources.vICMSDif, obop); } wCampo(imposto.ICMS.vICMS, TpcnTipoCampo.tcDec2, TpcnResources.vICMS, obop); } break; case "60": if ((double)nfe.infNFe.Versao >= 2.0) { if (imposto.ICMS.vBCSTRet > 0 || imposto.ICMS.vICMSSTRet > 0) { wCampo(imposto.ICMS.vBCSTRet, TpcnTipoCampo.tcDec2, TpcnResources.vBCSTRet); wCampo(imposto.ICMS.vICMSSTRet, TpcnTipoCampo.tcDec2, TpcnResources.vICMSSTRet); } } else { wCampo(imposto.ICMS.vBCST, TpcnTipoCampo.tcDec2, TpcnResources.vBCST); wCampo(imposto.ICMS.pICMSST, this.nDecimaisPerc, TpcnResources.pICMSST); } break; case "70": wCampo(imposto.ICMS.modBC, TpcnTipoCampo.tcInt, TpcnResources.modBC); wCampo(imposto.ICMS.pRedBC, this.nDecimaisPerc, TpcnResources.pRedBC); wCampo(imposto.ICMS.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); wCampo(imposto.ICMS.pICMS, this.nDecimaisPerc, TpcnResources.pICMS); wCampo(imposto.ICMS.vICMS, TpcnTipoCampo.tcDec2, TpcnResources.vICMS); wCampo(imposto.ICMS.modBCST, TpcnTipoCampo.tcInt, TpcnResources.modBCST); wCampo(imposto.ICMS.pMVAST, this.nDecimaisPerc, TpcnResources.pMVAST, ObOp.Opcional); wCampo(imposto.ICMS.pRedBCST, this.nDecimaisPerc, TpcnResources.pRedBCST, ObOp.Opcional); wCampo(imposto.ICMS.vBCST, TpcnTipoCampo.tcDec2, TpcnResources.vBCST); wCampo(imposto.ICMS.pICMSST, this.nDecimaisPerc, TpcnResources.pICMSST); wCampo(imposto.ICMS.vICMSST, TpcnTipoCampo.tcDec2, TpcnResources.vICMSST); if ((double)nfe.infNFe.Versao >= 3.10 && imposto.ICMS.vICMSDeson > 0) { wCampo(imposto.ICMS.vICMSDeson, TpcnTipoCampo.tcDec2, TpcnResources.vICMSDeson); wCampo(imposto.ICMS.motDesICMS, TpcnTipoCampo.tcInt, TpcnResources.motDesICMS); } break; case "90": wCampo(imposto.ICMS.modBC, TpcnTipoCampo.tcInt, TpcnResources.modBC); wCampo(imposto.ICMS.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); if (imposto.ICMS.ICMSPart90 == 1) wCampo(imposto.ICMS.pRedBC, this.nDecimaisPerc, TpcnResources.pRedBC, ObOp.Opcional); wCampo(imposto.ICMS.pICMS, this.nDecimaisPerc, TpcnResources.pICMS); wCampo(imposto.ICMS.vICMS, TpcnTipoCampo.tcDec2, TpcnResources.vICMS); if (imposto.ICMS.vBCST > 0 || imposto.ICMS.vICMSST > 0) { wCampo(imposto.ICMS.modBCST, TpcnTipoCampo.tcInt, TpcnResources.modBCST); wCampo(imposto.ICMS.pMVAST, this.nDecimaisPerc, TpcnResources.pMVAST, ObOp.Opcional); wCampo(imposto.ICMS.pRedBCST, this.nDecimaisPerc, TpcnResources.pRedBCST, ObOp.Opcional); wCampo(imposto.ICMS.vBCST, TpcnTipoCampo.tcDec2, TpcnResources.vBCST); wCampo(imposto.ICMS.pICMSST, this.nDecimaisPerc, TpcnResources.pICMSST); wCampo(imposto.ICMS.vICMSST, TpcnTipoCampo.tcDec2, TpcnResources.vICMSST); } if (imposto.ICMS.ICMSPart90 == 1) { wCampo(imposto.ICMS.pBCOp, this.nDecimaisPerc, TpcnResources.pBCOp); wCampo(imposto.ICMS.UFST, TpcnTipoCampo.tcStr, TpcnResources.UFST); } else if ((double)nfe.infNFe.Versao >= 3.10 && imposto.ICMS.vICMSDeson > 0) { wCampo(imposto.ICMS.vICMSDeson, TpcnTipoCampo.tcDec2, TpcnResources.vICMSDeson); wCampo(imposto.ICMS.motDesICMS, TpcnTipoCampo.tcInt, TpcnResources.motDesICMS); } break; } if (imposto.ICMS.ICMSPart10 == 1 || imposto.ICMS.ICMSPart90 == 1 && (double)nfe.infNFe.Versao >= 3.10) { if (imposto.ICMS.ICMSUFDest.vBCUFDest > 0 || imposto.ICMS.ICMSUFDest.pICMSUFDest > 0 || imposto.ICMS.ICMSUFDest.pICMSInter > 0 || imposto.ICMS.ICMSUFDest.pICMSInterPart > 0 || imposto.ICMS.ICMSUFDest.vICMSUFDest > 0 || imposto.ICMS.ICMSUFDest.vICMSUFRemet > 0) { var x_nodeCurrent = nodeCurrent; XmlElement ee0 = doc.CreateElement(TpcnResources.ICMSUFDest.ToString()); nodeCurrent.AppendChild(ee0); wCampo(imposto.ICMS.ICMSUFDest.vBCUFDest, TpcnTipoCampo.tcDec2, TpcnResources.vBCUFDest); wCampo(imposto.ICMS.ICMSUFDest.pICMSUFDest, TpcnTipoCampo.tcDec4, TpcnResources.pICMSUFDest); wCampo(imposto.ICMS.ICMSUFDest.pICMSInter, TpcnTipoCampo.tcDec4, TpcnResources.pICMSInter); wCampo(imposto.ICMS.ICMSUFDest.pICMSInterPart, TpcnTipoCampo.tcDec4, TpcnResources.pICMSInterPart); wCampo(imposto.ICMS.ICMSUFDest.vICMSUFDest, TpcnTipoCampo.tcDec2, TpcnResources.vICMSUFDest); wCampo(imposto.ICMS.ICMSUFDest.vICMSUFRemet, TpcnTipoCampo.tcDec2, TpcnResources.vICMSUFRemet); nodeCurrent = x_nodeCurrent; } } } } if (imposto.ICMS.CSOSN > 100) { XmlElement e0 = doc.CreateElement(TpcnResources.ICMS.ToString()); switch (imposto.ICMS.CSOSN) { case 101: nodeCurrent = doc.CreateElement("ICMSSN101"); break; case 102: case 103: case 300: case 400: nodeCurrent = doc.CreateElement("ICMSSN102"); break; case 201: nodeCurrent = doc.CreateElement("ICMSSN201"); break; case 202: case 203: nodeCurrent = doc.CreateElement("ICMSSN202"); break; case 500: nodeCurrent = doc.CreateElement("ICMSSN500"); break; case 900: nodeCurrent = doc.CreateElement("ICMSSN900"); break; } e0.AppendChild(nodeCurrent); nodeImposto.AppendChild(e0); wCampo(imposto.ICMS.orig, TpcnTipoCampo.tcInt, TpcnResources.orig); wCampo(imposto.ICMS.CSOSN, TpcnTipoCampo.tcInt, TpcnResources.CSOSN); switch (imposto.ICMS.CSOSN) { case 101: wCampo(imposto.ICMS.pCredSN, TpcnTipoCampo.tcDec2, TpcnResources.pCredSN); wCampo(imposto.ICMS.vCredICMSSN, TpcnTipoCampo.tcDec2, TpcnResources.vCredICMSSN); break; case 201: wCampo(imposto.ICMS.modBCST, TpcnTipoCampo.tcInt, TpcnResources.modBCST); wCampo(imposto.ICMS.pMVAST, this.nDecimaisPerc, TpcnResources.pMVAST, ObOp.Opcional); wCampo(imposto.ICMS.pRedBCST, this.nDecimaisPerc, TpcnResources.pRedBCST, ObOp.Opcional); wCampo(imposto.ICMS.vBCST, TpcnTipoCampo.tcDec2, TpcnResources.vBCST); wCampo(imposto.ICMS.pICMSST, this.nDecimaisPerc, TpcnResources.pICMSST); wCampo(imposto.ICMS.vICMSST, TpcnTipoCampo.tcDec2, TpcnResources.vICMSST); wCampo(imposto.ICMS.pCredSN, this.nDecimaisPerc, TpcnResources.pCredSN); wCampo(imposto.ICMS.vCredICMSSN, TpcnTipoCampo.tcDec2, TpcnResources.vCredICMSSN); break; case 202: case 203: wCampo(imposto.ICMS.modBCST, TpcnTipoCampo.tcInt, TpcnResources.modBCST); wCampo(imposto.ICMS.pMVAST, this.nDecimaisPerc, TpcnResources.pMVAST, ObOp.Opcional); wCampo(imposto.ICMS.pRedBCST, this.nDecimaisPerc, TpcnResources.pRedBCST, ObOp.Opcional); wCampo(imposto.ICMS.vBCST, TpcnTipoCampo.tcDec2, TpcnResources.vBCST); wCampo(imposto.ICMS.pICMSST, this.nDecimaisPerc, TpcnResources.pICMSST); wCampo(imposto.ICMS.vICMSST, TpcnTipoCampo.tcDec2, TpcnResources.vICMSST); break; case 500: //wCampo(imposto.ICMS.modBCST, TpcnTipoCampo.tcInt, TpcnResources.modBCST, false); wCampo(imposto.ICMS.vBCSTRet, TpcnTipoCampo.tcDec2, TpcnResources.vBCSTRet); wCampo(imposto.ICMS.vICMSSTRet, TpcnTipoCampo.tcDec2, TpcnResources.vICMSSTRet); break; case 900: wCampo(imposto.ICMS.modBC, TpcnTipoCampo.tcInt, TpcnResources.modBC); wCampo(imposto.ICMS.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); wCampo(imposto.ICMS.pRedBC, this.nDecimaisPerc, TpcnResources.pRedBC, ObOp.Opcional); wCampo(imposto.ICMS.pICMS, this.nDecimaisPerc, TpcnResources.pICMS); wCampo(imposto.ICMS.vICMS, TpcnTipoCampo.tcDec2, TpcnResources.vICMS); wCampo(imposto.ICMS.modBCST, TpcnTipoCampo.tcInt, TpcnResources.modBCST); wCampo(imposto.ICMS.pMVAST, this.nDecimaisPerc, TpcnResources.pMVAST, ObOp.Opcional); wCampo(imposto.ICMS.pRedBCST, this.nDecimaisPerc, TpcnResources.pRedBCST, ObOp.Opcional); wCampo(imposto.ICMS.vBCST, TpcnTipoCampo.tcDec2, TpcnResources.vBCST); wCampo(imposto.ICMS.pICMSST, this.nDecimaisPerc, TpcnResources.pICMSST); wCampo(imposto.ICMS.vICMSST, TpcnTipoCampo.tcDec2, TpcnResources.vICMSST); wCampo(imposto.ICMS.pCredSN, this.nDecimaisPerc, TpcnResources.pCredSN); wCampo(imposto.ICMS.vCredICMSSN, TpcnTipoCampo.tcDec2, TpcnResources.vCredICMSSN); break; } } }
/// <summary> /// GerarTotal /// </summary> /// <param name="NFe"></param> /// <param name="root"></param> private void GerarTotal(NFe NFe, XmlElement root) { XmlElement nodeTotal = doc.CreateElement("total"); root.AppendChild(nodeTotal); #region --ICMSTot nodeCurrent = doc.CreateElement("ICMSTot"); nodeTotal.AppendChild(nodeCurrent); wCampo(NFe.Total.ICMSTot.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); wCampo(NFe.Total.ICMSTot.vICMS, TpcnTipoCampo.tcDec2, TpcnResources.vICMS); if ((double)NFe.infNFe.Versao >= 3.10) { wCampo(NFe.Total.ICMSTot.vICMSDeson, TpcnTipoCampo.tcDec2, TpcnResources.vICMSDeson); wCampo(NFe.Total.ICMSTot.vICMSUFDest, TpcnTipoCampo.tcDec2, TpcnResources.vICMSUFDest, ObOp.Opcional); wCampo(NFe.Total.ICMSTot.vICMSUFRemet, TpcnTipoCampo.tcDec2, TpcnResources.vICMSUFRemet, ObOp.Opcional); } wCampo(NFe.Total.ICMSTot.vBCST, TpcnTipoCampo.tcDec2, TpcnResources.vBCST); wCampo(NFe.Total.ICMSTot.vST, TpcnTipoCampo.tcDec2, TpcnResources.vST); wCampo(NFe.Total.ICMSTot.vProd, TpcnTipoCampo.tcDec2, TpcnResources.vProd); wCampo(NFe.Total.ICMSTot.vFrete, TpcnTipoCampo.tcDec2, TpcnResources.vFrete); wCampo(NFe.Total.ICMSTot.vSeg, TpcnTipoCampo.tcDec2, TpcnResources.vSeg); wCampo(NFe.Total.ICMSTot.vDesc, TpcnTipoCampo.tcDec2, TpcnResources.vDesc); wCampo(NFe.Total.ICMSTot.vII, TpcnTipoCampo.tcDec2, TpcnResources.vII); wCampo(NFe.Total.ICMSTot.vIPI, TpcnTipoCampo.tcDec2, TpcnResources.vIPI); wCampo(NFe.Total.ICMSTot.vPIS, TpcnTipoCampo.tcDec2, TpcnResources.vPIS); wCampo(NFe.Total.ICMSTot.vCOFINS, TpcnTipoCampo.tcDec2, TpcnResources.vCOFINS); wCampo(NFe.Total.ICMSTot.vOutro, TpcnTipoCampo.tcDec2, TpcnResources.vOutro); wCampo(NFe.Total.ICMSTot.vNF, TpcnTipoCampo.tcDec2, TpcnResources.vNF); wCampo(NFe.Total.ICMSTot.vTotTrib, TpcnTipoCampo.tcDec2, TpcnResources.vTotTrib, ObOp.Opcional); #endregion #region --ISSQNtot if ((NFe.Total.ISSQNtot.vServ > 0) || (NFe.Total.ISSQNtot.vBC > 0) || (NFe.Total.ISSQNtot.vISS > 0) || (NFe.Total.ISSQNtot.vPIS > 0) || (NFe.Total.ISSQNtot.vCOFINS > 0)) { nodeCurrent = doc.CreateElement("ISSQNtot"); nodeTotal.AppendChild(nodeCurrent); wCampo(NFe.Total.ISSQNtot.vServ, TpcnTipoCampo.tcDec2, TpcnResources.vServ, ObOp.Opcional); wCampo(NFe.Total.ISSQNtot.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC, ObOp.Opcional); wCampo(NFe.Total.ISSQNtot.vISS, TpcnTipoCampo.tcDec2, TpcnResources.vISS, ObOp.Opcional); wCampo(NFe.Total.ISSQNtot.vPIS, TpcnTipoCampo.tcDec2, TpcnResources.vPIS, ObOp.Opcional); wCampo(NFe.Total.ISSQNtot.vCOFINS, TpcnTipoCampo.tcDec2, TpcnResources.vCOFINS, ObOp.Opcional); if ((double)NFe.infNFe.Versao >= 3.10) { wCampo(NFe.Total.ISSQNtot.dCompet, TpcnTipoCampo.tcDatYYYY_MM_DD, TpcnResources.dCompet, ObOp.Opcional); wCampo(NFe.Total.ISSQNtot.vDeducao, TpcnTipoCampo.tcDec2, TpcnResources.vDeducao, ObOp.Opcional); //wCampo(NFe.Total.ISSQNtot.vINSS, TpcnTipoCampo.tcDec2, TpcnResources.vINSS, ObOp.Opcional); //wCampo(NFe.Total.ISSQNtot.vIR, TpcnTipoCampo.tcDec2, TpcnResources.vIR, ObOp.Opcional); //wCampo(NFe.Total.ISSQNtot.vCSLL, TpcnTipoCampo.tcDec2, TpcnResources.vCSLL, ObOp.Opcional); wCampo(NFe.Total.ISSQNtot.vOutro, TpcnTipoCampo.tcDec2, TpcnResources.vOutro, ObOp.Opcional); wCampo(NFe.Total.ISSQNtot.vDescIncond, TpcnTipoCampo.tcDec2, TpcnResources.vDescIncond, ObOp.Opcional); wCampo(NFe.Total.ISSQNtot.vDescCond, TpcnTipoCampo.tcDec2, TpcnResources.vDescCond, ObOp.Opcional); wCampo(NFe.Total.ISSQNtot.vISSRet, TpcnTipoCampo.tcDec2, TpcnResources.vISSRet, ObOp.Opcional); //wCampo(NFe.Total.ISSQNtot.indISSRet ? "1":"2", TpcnTipoCampo.tcStr, TpcnResources.indISSRet); //wCampo((int)NFe.Total.ISSQNtot.indISS, TpcnTipoCampo.tcInt, TpcnResources.indISS); //wCampo(NFe.Total.ISSQNtot.cServico, TpcnTipoCampo.tcStr, TpcnResources.cServico, ObOp.Opcional); //wCampo(NFe.Total.ISSQNtot.cMun, TpcnTipoCampo.tcInt, TpcnResources.cMun, ObOp.Opcional); //wCampo(NFe.Total.ISSQNtot.cPais, TpcnTipoCampo.tcInt, TpcnResources.cPais, ObOp.Opcional); //wCampo(NFe.Total.ISSQNtot.nProcesso, TpcnTipoCampo.tcStr, TpcnResources.nProcesso, ObOp.Opcional); //wCampo(NFe.Total.ISSQNtot.vISSRet, TpcnTipoCampo.tcDec2, TpcnResources.vISSRet, ObOp.Opcional); wCampo((int)NFe.Total.ISSQNtot.cRegTrib, TpcnTipoCampo.tcInt, TpcnResources.cRegTrib, ObOp.Opcional); //wCampo(NFe.Total.ISSQNtot.indIncentivo ? 1:2 , TpcnTipoCampo.tcInt, TpcnResources.indIncentivo); } } #endregion #region --retTrib if ((NFe.Total.retTrib.vRetPIS > 0) || (NFe.Total.retTrib.vRetCOFINS > 0) || (NFe.Total.retTrib.vRetCSLL > 0) || (NFe.Total.retTrib.vBCIRRF > 0) || (NFe.Total.retTrib.vIRRF > 0) || (NFe.Total.retTrib.vBCRetPrev > 0) || (NFe.Total.retTrib.vRetPrev > 0)) { nodeCurrent = doc.CreateElement("retTrib"); nodeTotal.AppendChild(nodeCurrent); wCampo(NFe.Total.retTrib.vRetPIS, TpcnTipoCampo.tcDec2, TpcnResources.vRetPIS, ObOp.Opcional); wCampo(NFe.Total.retTrib.vRetCOFINS, TpcnTipoCampo.tcDec2, TpcnResources.vRetCOFINS, ObOp.Opcional); wCampo(NFe.Total.retTrib.vRetCSLL, TpcnTipoCampo.tcDec2, TpcnResources.vRetCSLL, ObOp.Opcional); wCampo(NFe.Total.retTrib.vBCIRRF, TpcnTipoCampo.tcDec2, TpcnResources.vBCIRRF, ObOp.Opcional); wCampo(NFe.Total.retTrib.vIRRF, TpcnTipoCampo.tcDec2, TpcnResources.vIRRF, ObOp.Opcional); wCampo(NFe.Total.retTrib.vBCRetPrev, TpcnTipoCampo.tcDec2, TpcnResources.vBCRetPrev, ObOp.Opcional); wCampo(NFe.Total.retTrib.vRetPrev, TpcnTipoCampo.tcDec2, TpcnResources.vRetPrev, ObOp.Opcional); } #endregion }
public nfeRead() { nfe = new NFe(); }
/// <summary> /// GerarDetImpostoIPI /// </summary> /// <param name="IPI"></param> /// <param name="nodeImposto"></param> private bool GerarDetImpostoIPI(NFe nfe, IPI IPI, XmlElement nodeImposto) { if (!string.IsNullOrEmpty(IPI.CST)) { bool CST00495099; // variavel CST00495099 usada para Ignorar Tag <IPI> // se GerarTagIPIparaNaoTributado = False e CST00495099 = False CST00495099 = (IPI.CST == "00" || IPI.CST == "49" || IPI.CST == "50" || IPI.CST == "99"); XmlElement e0 = doc.CreateElement("IPI"); nodeImposto.AppendChild(e0); nodeCurrent = e0; wCampo(IPI.clEnq, TpcnTipoCampo.tcStr, TpcnResources.clEnq, ObOp.Opcional); wCampo(IPI.CNPJProd, TpcnTipoCampo.tcStr, TpcnResources.CNPJProd, ObOp.Opcional); wCampo(IPI.cSelo, TpcnTipoCampo.tcStr, TpcnResources.cSelo, ObOp.Opcional); wCampo(IPI.qSelo, TpcnTipoCampo.tcInt, TpcnResources.qSelo, ObOp.Opcional); if (IPI.cEnq.Trim() == "") IPI.cEnq = "999"; wCampo(IPI.cEnq, TpcnTipoCampo.tcStr, TpcnResources.cEnq); if (CST00495099) { if ((IPI.vBC + IPI.pIPI > 0) && (IPI.qUnid + IPI.vUnid > 0)) this.cMensagemErro += "IPITrib: As TAG's <vBC> e <pIPI> não podem ser informadas em conjunto com as TAG <qUnid> e <vUnid>" + Environment.NewLine; nodeCurrent = doc.CreateElement("IPITrib"); e0.AppendChild(nodeCurrent); wCampo(IPI.CST, TpcnTipoCampo.tcStr, TpcnResources.CST); if (IPI.qUnid + IPI.vUnid > 0) { wCampo(IPI.qUnid, TpcnTipoCampo.tcDec4, TpcnResources.qUnid); wCampo(IPI.vUnid, TpcnTipoCampo.tcDec4, TpcnResources.vUnid); } else { wCampo(IPI.vBC, TpcnTipoCampo.tcDec2, TpcnResources.vBC); wCampo(IPI.pIPI, this.nDecimaisPerc, TpcnResources.pIPI); } wCampo(IPI.vIPI, TpcnTipoCampo.tcDec2, TpcnResources.vIPI); } else //(* Quando CST/IPI for 01,02,03,04,51,52,53,54 ou 55 *) { nodeCurrent = doc.CreateElement("IPINT"); e0.AppendChild(nodeCurrent); wCampo(IPI.CST, TpcnTipoCampo.tcStr, TpcnResources.CST); } return true; } return false; }