public ActionResult processXML(EstadodeCuentaWebModel model) { if ((sesion = SessionDB.start(Request, Response, false, db, SESSION_BEHAVIOR.AJAX)) == null) { return(Content("-1")); } model.IDSIU = sesion.vdata["IDSIU"]; model.Sede = sesion.vdata.ContainsKey("Sede") ? model.Sede = sesion.vdata["Sede"] : ""; model.sesion = sesion; List <string> errores = new List <string>(); List <string> errores_stx = new List <string>(); string str_xml = ""; string msg = ""; if (model.FileNameXML != null) { XmlDocument xmldoc = new XmlDocument(); str_xml = Load(model.FileNameXML); xmldoc.LoadXml(str_xml.ToLower()); XmlNode node; List <XmlNode> listNodes; //node = xmldoc.DocumentElement.SelectSingleNode("/cfdi_Comprobante"); node = SelectFirstNode(xmldoc, "/cfdi:comprobante"); if (node == null) { node = SelectFirstNode(xmldoc, "/comprobante"); } FormatoXML XML = new FormatoXML(model); if (node == null) { // return Content(msg); msg = "xml no cumple con las especificaciones como la etiqueta Comprobante"; errores_stx.Add(msg); // return Content(Notification.Error2(msg)); } else { XML.Fecha = node.Attributes["fecha"]?.InnerText; } //XML.Total = node.Attributes["total"]?.InnerText; node = SelectFirstNode(xmldoc, "/cfdi:comprobante/cfdi:emisor"); if (node == null) { node = SelectFirstNode(xmldoc, "/comprobante/emisor"); } if (node == null) { msg = "xml no cumple con las especificaciones como la etiqueta Emisor"; errores_stx.Add(msg); // return Content(Notification.Error2(msg)); ; } else { XML.RFC_Emisor = node.Attributes["rfc"]?.InnerText; } node = SelectFirstNode(xmldoc, "/cfdi:comprobante/cfdi:receptor"); if (node == null) { node = SelectFirstNode(xmldoc, "/comprobante/receptor"); } if (node == null) { msg = "xml no cumple con las especificaciones como la etiqueta Receptor"; errores_stx.Add(msg); // return Content(Notification.Error2(msg)); } else { XML.RFC_Receptor = node.Attributes["rfc"]?.InnerText; } listNodes = SelectListNode(xmldoc, "/cfdi:comprobante/cfdi:impuestos/cfdi:retenciones/cfdi:retencion"); if (listNodes == null) { listNodes = SelectListNode(xmldoc, "/comprobante/impuestos/retenciones/retencion"); } if (listNodes != null) { foreach (XmlNode item in listNodes) { string importe = item.Attributes["importe"]?.InnerText; switch (item.Attributes["impuesto"]?.InnerText) { case "IVA": XML.IVA_Ret = importe; break; case "ISR": XML.ISR_Ret = importe; break; } } } else { msg = "xml no tiene Impuestos y/o Retenciones"; errores_stx.Add(msg); // return Content(Notification.Error2(msg)); } //XML.IVA_Ret = node.Attributes["IVA"]?.InnerText; //XML.ISR_Ret = node.Attributes["ISR"]?.InnerText; listNodes = SelectListNode(xmldoc, "/cfdi:comprobante/cfdi:conceptos/cfdi:concepto"); if (listNodes == null) { listNodes = SelectListNode(xmldoc, "/comprobante/conceptos/concepto"); } if (listNodes != null) { if (listNodes.Count > 0)//checar el importe es obligatorio { XML.Importe = listNodes[0].Attributes["importe"]?.InnerText; } } else { msg = "xml no tiene Conceptos"; errores_stx.Add(msg); // return Content(Notification.Error2(msg)); } if (errores_stx.Count == 0) { if (model.ValidarXML) { errores = model.validarXML(XML); } } } // Si no hay errores (localmente) ... if (errores_stx.Count == 0) { if (errores.Count == 0) { bool correcto = true; // model.ValidarMySuite = true; if (model.FileNameXML != null && model.ValidarMySuite) { correcto = validarMySuite(str_xml, out msg, model); } // XXXXXXXXXXXXXXXXXXXXXXXXXXXXX // XXXXXXXXXXXXXXXXXXXXXXXXXXXXX // XXXXXXXXXXXXXXXXXXXXXXXXXXXXX //correcto = true; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXX // XXXXXXXXXXXXXXXXXXXXXXXXXXXXX // XXXXXXXXXXXXXXXXXXXXXXXXXXXXX if (correcto) { // Se mueven los archivos organizandolos a una carpeta del mes actual. model.FileNameXML = moveFile(model.FileNameXML); model.FileNamePDF = moveFile(model.FileNamePDF); model.saveXMLyPDF(); return(Content("0")); } } else { msg = string.Join <string>("<br/>\n", errores); } } else { try { msg = string.Join <string>("<br/>\n", errores_stx); model.savelOG(msg, 1); } catch (Exception) { } } //guarda pdf y xml en carperta: Upload/Error_Facturas try { model.FileNameXML = moveFile_Error(model.FileNameXML); model.FileNamePDF = moveFile_Error(model.FileNamePDF); model.savelOG(msg, 0); }catch (Exception) { } // return Content(msg); return(Content(Notification.Error3(msg))); }