public GastosHidrocarburos DesSerializarGH(XElement element, ref string erroGH) { GastosHidrocarburos result; try { IEnumerable <XElement> ine = element.Elements(this._ns + "Complemento"); if (ine != null) { ine = ine.Elements(this._ns39 + "GastosHidrocarburos"); if (ine != null) { using (IEnumerator <XElement> enumerator = ine.GetEnumerator()) { if (enumerator.MoveNext()) { XElement e = enumerator.Current; XmlSerializer ser = new XmlSerializer(typeof(GastosHidrocarburos)); string xml = e.ToString(); StringReader reader = new StringReader(xml); GastosHidrocarburos comLXMLComprobante = (GastosHidrocarburos)ser.Deserialize(reader); result = comLXMLComprobante; return(result); } } } } } catch (Exception ex) { erroGH = ex.InnerException.Message; result = null; return(result); } result = null; return(result); }
public string ProcesarGastosHidrocarburos(GastosHidrocarburos gh, string version, string TipoComprobante) { string result; try { if (version != "3.3") { result = "GCEH101 - El atributo Version no tiene un valor válido."; } else if (TipoComprobante != "E") { result = "GCEH102 - El atributo TipoDeComprobante no cumple con el valor permitido."; } else { foreach (GastosHidrocarburosErogacion en in gh.Erogacion) { if (en.DocumentoRelacionado != null) { foreach (GastosHidrocarburosErogacionDocumentoRelacionado d in en.DocumentoRelacionado) { if (!string.IsNullOrEmpty(d.FolioFiscalVinculado)) { if (d.OrigenErogacion.ToString() != "Nacional") { result = "GCEH103 - El atributo FolioFiscalVinculado no se debe registrar cuando el atributo OrigenErogacion es Extranjero."; return(result); } if (string.IsNullOrEmpty(d.RFCProveedor)) { result = "GCEH105 - El atributo RFCProveedor debe registrarse por que existe el atributo FolioFiscalVinculado."; return(result); } if (!d.MontoTotalIVASpecified) { result = "GCEH107 - El atributo MontoTotalIVA debe registrarse por que existe el atributo FolioFiscalVinculado."; return(result); } } else { if (!string.IsNullOrEmpty(d.RFCProveedor)) { result = "GCEH104 - El atributo RFCProveedor no se debe registrar por que no existe el atributo FolioFiscalVinculado."; return(result); } if (d.MontoTotalIVASpecified) { result = "GCEH106 - El atributo MontoTotalIVA no se debe registrar por que no existe el atributo FolioFiscalVinculado."; return(result); } } if (!string.IsNullOrEmpty(d.NumeroPedimentoVinculado)) { if (d.OrigenErogacion.ToString() == "Nacional") { result = "GCEH108 - El atributo NumeroPedimentoVinculado no se debe registrar cuando el atributo OrigenErogacion es Nacional."; return(result); } if (!d.ClavePedimentoVinculadoSpecified) { result = "GCEH110 - El atributo ClavePedimentoVinculado debe registrarse por que existe el atributo NumeroPedimentoVinculado."; return(result); } if (!d.ClavePagoPedimentoVinculadoSpecified) { result = "GCEH112 - El atributo ClavePagoPedimento debe registrarse por que existe el atributo NumeroPedimentoVinculado."; return(result); } if (!d.MontoIVAPedimentoSpecified) { result = "GCEH114 - El atributo MontoIVAPedimento debe registrarse por que existe el atributo NumeroPedimentoVinculado."; return(result); } } else { if (d.ClavePedimentoVinculadoSpecified) { result = "GCEH109 - El atributo ClavePedimentoVinculado no se debe registrar por que no existe el atributo NumeroPedimentoVinculado."; return(result); } if (d.ClavePagoPedimentoVinculadoSpecified) { result = "GCEH111 - El atributo ClavePagoPedimento no se debe registrar por que no existe el atributo NumeroPedimentoVinculado."; return(result); } if (d.MontoIVAPedimentoSpecified) { result = "GCEH113 - El atributo MontoIVAPedimento no se debe registrar por que no existe el atributo NumeroPedimentoVinculado."; return(result); } } if (!string.IsNullOrEmpty(d.FolioFiscalVinculado) && !d.FechaFolioFiscalVinculadoSpecified) { result = "GCEH132 - El atributo FechaFolioFiscalVinculado debe registrarse por que existe el atributo FolioFiscalVinculado."; return(result); } int Mes = d.FechaFolioFiscalVinculado.Month; int Mes2 = Mes - 1; if (Mes2 == 0) { Mes2 = 12; } string strinMes = d.Mes.ToString().Replace("Item", ""); int M = (int)Convert.ToInt16(strinMes); if (M != Mes && M != Mes2) { result = "GCEH115 - El valor del atributo Mes no corresponde al mes registrado en el atributo FechaFolioFiscalVinculado, o al de un mes anterior de calendario respecto a dicho atributo."; return(result); } if (d.NumeroPedimentoVinculado != null) { string sa = this.validarNumeroPedimento(d.NumeroPedimentoVinculado, "GCEH133"); if (sa != "OK") { result = sa; return(result); } } } } if (en.Porcentaje <= 0m) { result = "GCEH116 - El valor del atributo Porcentaje no es mayor a 0."; return(result); } if (en.Actividades != null) { foreach (GastosHidrocarburosErogacionActividades a in en.Actividades) { if (a.SubActividades == null || a.SubActividades.Count == 0) { if (a.ActividadRelacionadaSpecified) { result = "GCEH117 - El atributo ActividadRelacionada no se debe registrar por que no existen los atributos SubActividadRelacionada y TareaRelacionada."; return(result); } } foreach (GastosHidrocarburosErogacionActividadesSubActividades s in a.SubActividades) { if (s.SubActividadRelacionadaSpecified && s.Tareas.Count > 0 && !a.ActividadRelacionadaSpecified) { result = "GCEH118 - El atributo ActividadRelacionada debe registrarse por que existen los atributos SubActividadRelacionada y TareaRelacionada."; return(result); } if (!a.ActividadRelacionadaSpecified && s.Tareas.Count == 0 && s.SubActividadRelacionadaSpecified) { result = "GCEH119 - El atributo SubActividadRelacionada no se debe registrar por que no existen los atributos ActividadRelacionada y TareaRelacionada."; return(result); } if (a.ActividadRelacionadaSpecified && s.Tareas.Count > 0 && !s.SubActividadRelacionadaSpecified) { result = "GCEH120 - El atributo SubActividadRelacionada debe registrarse por que existen los atributos ActividadRelacionada y TareaRelacionada."; return(result); } if (!a.ActividadRelacionadaSpecified && !s.SubActividadRelacionadaSpecified && s.Tareas.Count != 0) { result = "GCEH121 - El atributo TareaRelacionada no se debe registrar por que no existen los atributos ActividadRelacionada y SubActividadRelacionada."; return(result); } if (a.ActividadRelacionadaSpecified && s.SubActividadRelacionadaSpecified && s.Tareas.Count == 0) { result = "GCEH122 - El atributo TareaRelacionada no se debe registrar por que no existen los atributos ActividadRelacionada y SubActividadRelacionada."; return(result); } Actividades myTipoActividad; Enum.TryParse <Actividades>("Item" + a.ActividadRelacionada.ToString(), out myTipoActividad); if (myTipoActividad.ToString() != "Item" + a.ActividadRelacionada.ToString()) { result = "GCEH123 - El valor del atributo ActividadRelacionada no contiene una clave del catálogo catCEH:Actividad."; return(result); } OperacionesCatalogos o322 = new OperacionesCatalogos(); CatalogosSAT.SubActividad usoSubActividad = o322.Consultar_SubActividad(s.SubActividadRelacionada.ToString()); if (Convert.ToInt16(usoSubActividad.c_Actividad) != Convert.ToInt16(a.ActividadRelacionada.ToString())) { result = "GCEH124 - El valor del atributo SubActividadRelacionada no contiene una clave del catálogo catCEH:SubActividad donde la columna c_Actividad sea igual a la clave registrada en el atributo ActividadRelacionada."; return(result); } foreach (GastosHidrocarburosErogacionActividadesSubActividadesTareas t in s.Tareas) { if (t.TareaRelacionadaSpecified) { OperacionesCatalogos o323 = new OperacionesCatalogos(); CatalogosSAT.Tareas usoTarea = o323.Consultar_Tarea(t.TareaRelacionada.ToString()); if (Convert.ToInt16(usoTarea.c_SubActividad) != Convert.ToInt16(s.SubActividadRelacionada.ToString().Replace("Item", "")) || Convert.ToInt16(usoTarea.c_Actividad) != Convert.ToInt16(a.ActividadRelacionada.ToString())) { result = "GCEH125 - El valor del atributo TareaRelacionada no contiene una clave del catálogo catCEH:Tarea donde la columna c_Subactividad sea igual a la clave registrada en el atributo SubActividadRelacionada y la columna c_Actividad sea igual a la clave registrada en el atributo ActividadRelacionada."; return(result); } } } } } } if (en.CentroCostos != null) { foreach (GastosHidrocarburosErogacionCentroCostos c in en.CentroCostos) { if (c.Yacimientos.Count == 0) { if (!string.IsNullOrEmpty(c.Campo)) { result = "GCEH126 - El atributo Campo no se debe registrar por que no existen los atributos Yacimiento y Pozo."; return(result); } } foreach (GastosHidrocarburosErogacionCentroCostosYacimientos y in c.Yacimientos) { if (y.Pozos.Count == 0 && string.IsNullOrEmpty(y.Yacimiento) && !string.IsNullOrEmpty(c.Campo)) { result = "GCEH126 - El atributo Campo no se debe registrar por que no existen los atributos Yacimiento y Pozo."; return(result); } if (y.Pozos.Count <GastosHidrocarburosErogacionCentroCostosYacimientosPozos>() > 0 && !string.IsNullOrEmpty(y.Yacimiento) && string.IsNullOrEmpty(c.Campo)) { result = "GCEH127 - El atributo Campo debe registrarse por que existen los atributos Yacimiento y Pozo."; return(result); } if (y.Pozos.Count == 0 && string.IsNullOrEmpty(c.Campo) && !string.IsNullOrEmpty(y.Yacimiento)) { result = "GCEH128 - El atributo Yacimiento no se debe registrar por que no existen los atributos Campo y Pozo."; return(result); } if (y.Pozos.Count != 0 && !string.IsNullOrEmpty(c.Campo) && string.IsNullOrEmpty(y.Yacimiento)) { result = "GCEH129 - El atributo Yacimiento debe registrarse por que existen los atributos Campo y Pozo."; return(result); } if (string.IsNullOrEmpty(y.Yacimiento) && string.IsNullOrEmpty(c.Campo) && y.Pozos.Count != 0) { result = "GCEH130 - El atributo Pozo no se debe registrar por que no existen los atributos Campo y Yacimiento."; return(result); } if (!string.IsNullOrEmpty(y.Yacimiento) && !string.IsNullOrEmpty(c.Campo) && y.Pozos.Count == 0) { result = "GCEH131 - El atributo Pozo debe registrarse por que existen los atributos Campo y Yacimiento."; return(result); } } } } } result = "0"; } } catch (Exception ex) { result = "GCEH999 - Error no clasificado " + ex.Message; } return(result); }
public string ValidaTimbraCfdi(string comprobante) { string result; try { XElement element = XElement.Load(new StringReader(comprobante)); ServicioLocal.Business.Comprobante comp = this.DesSerializar(element); if (comprobante.Contains("<ieeh:IngresosHidrocarburos")) { string erroIH = ""; IngresosHidrocarburos I = this.DesSerializarIH(element, ref erroIH); ValidarIngresoHidrocarburos VI = new ValidarIngresoHidrocarburos(); erroIH = VI.ProcesarIngresoHidrocarburos(I, comp.Version, comp.TipoDeComprobante, comp.Total); if (erroIH != "0") { result = erroIH; return(result); } } if (comprobante.Contains("<gceh:GastosHidrocarburos")) { string erroGH = ""; GastosHidrocarburos I2 = this.DesSerializarGH(element, ref erroGH); ValidarGastosHidrocarburos VI2 = new ValidarGastosHidrocarburos(); erroGH = VI2.ProcesarGastosHidrocarburos(I2, comp.Version, comp.TipoDeComprobante); if (erroGH != "0") { result = erroGH; return(result); } } ImpuestosLocales IL = null; if (comprobante.Contains("<implocal:ImpuestosLocales")) { IL = this.DesSerializarImpuestosLocales(element); } bool pago10 = comprobante.Contains("pago10:Pagos"); if (pago10) { } bool ComerExt = comprobante.Contains("cce11:ComercioExterior"); ValidarCFDI33 valida = new ValidarCFDI33(); string errorCFDI33 = valida.ProcesarCFDI33(comp, comprobante, pago10, ComerExt, IL); if (errorCFDI33 != "0") { CertificadorService.Logger.Error("Error al abrir el comprobante: " + errorCFDI33); result = errorCFDI33; } else { result = "OK"; } } catch (Exception ex) { CertificadorService.Logger.Error(ex); result = "Error al abrir el comprobante"; } return(result); }
/// <summary> /// Timbra un comprobante /// </summary> /// <param name="comprobante">Documento para validar y timbrar</param> /// <returns>Una cadena con el timbre fiscal digital (TFD)</returns> public string TimbraCfdi(string comprobante, string userName, string password, string LLave, string aplicacion) { string result2; try { if (string.IsNullOrEmpty(userName)) { return("Nombre de usuario o contraseña incorrecta"); } CertificadorService.Logger.Debug(userName); if (aplicacion == "CON") { var Licencia = ValidarLicencia(LLave); if (Licencia == false) { return("Licencia no valida"); } } MembershipUser x = NtLinkLogin.ValidateUser(userName, password); if (x == null) { throw new FaultException("Nombre de usuario o contraseña incorrecta"); } XElement element = XElement.Load(new StringReader(comprobante)); ServicioLocal.Business.Comprobante comp = this.DesSerializar(element); empresa empres = new empresa(); if (comp.Emisor != null && comp.Emisor.Rfc != null) { string vemp = ValidarUsuario(comp.Emisor.Rfc, x, ref empres); if (vemp != "OK") { return(vemp); } } else { return("Error: Los datos del emisor incompletos"); } //------------------------- if (comprobante.Contains("<ieeh:IngresosHidrocarburos")) { string erroIH = ""; IngresosHidrocarburos I = this.DesSerializarIH(element, ref erroIH); ValidarIngresoHidrocarburos VI = new ValidarIngresoHidrocarburos(); erroIH = VI.ProcesarIngresoHidrocarburos(I, comp.Version, comp.TipoDeComprobante, comp.Total); if (erroIH != "0") { result2 = erroIH; return(result2); } } if (comprobante.Contains("<gceh:GastosHidrocarburos")) { string erroGH = ""; GastosHidrocarburos I2 = this.DesSerializarGH(element, ref erroGH); ValidarGastosHidrocarburos VI2 = new ValidarGastosHidrocarburos(); erroGH = VI2.ProcesarGastosHidrocarburos(I2, comp.Version, comp.TipoDeComprobante); if (erroGH != "0") { result2 = erroGH; return(result2); } } ImpuestosLocales IL = null; if (comprobante.Contains("<implocal:ImpuestosLocales")) { IL = this.DesSerializarImpuestosLocales(element); } bool pago10 = comprobante.Contains("pago10:Pagos"); if (comp.TipoDeComprobante == "P" && !pago10) { result2 = "CFDI no contiene el complemento PAGO"; return(result2); } if (pago10) { ServicioLocal.Business.Pagoo.Comprobante pagoDatos = this.DesSerializarP(element); ServicioLocal.Business.Complemento.Pagos pagoss = this.DesSerializarPagos(element); ValidarPago VP = new ValidarPago(); string ErrorPagos = VP.ProcesarPago(comp, pagoss, pagoDatos); if (ErrorPagos != "0") { result2 = ErrorPagos; return(result2); } } bool ComerExt = comprobante.Contains("cce11:ComercioExterior"); ValidarCFDI33 valida = new ValidarCFDI33(); string errorCFDI33 = valida.ProcesarCFDI33(comp, comprobante, pago10, ComerExt, IL); if (errorCFDI33 != "0") { CertificadorService.Logger.Error("Error al abrir el comprobante: " + errorCFDI33); return(errorCFDI33); } bool nomin12 = comprobante.Contains("nomina12:Nomina"); List <Nomina> nom = new List <Nomina>(); if (nomin12) { string erroresNom = null; var nomx = this.DesSerializarNomina12(element, ref erroresNom); nom.Add(nomx); if (erroresNom != null) { result2 = erroresNom; return(result2); } } NtLinkSistema nls = new NtLinkSistema(); string result = null; TimbreFiscalDigital timbre = null; string acuseSat = ""; string hash = null; string erroresNomina = "0"; if (ComerExt && erroresNomina == "0") { string erroresComer = null; ValidarComercioExterior val = new ValidarComercioExterior(); ComercioExterior Comer = this.DesSerializarComercioExterior(element, ref erroresComer); if (erroresComer != null) { result2 = erroresComer; return(result2); } erroresNomina = val.ProcesarComercioExterior(Comer, comp); } if (nomin12 && erroresNomina == "0") { erroresNomina = this.val.ProcesarNomina(nom, comp); if (erroresNomina != "0") { return(erroresNomina); } } Dictionary <int, string> dict = this.val.ProcesarCadena(comp.Emisor.Rfc, comprobante, ref result, ref timbre, ref acuseSat, ref hash); if (timbre != null && timbre.SelloSAT != null && dict.Count == 0) { SerializadorTimbres sert = new SerializadorTimbres(); if (ConfigurationManager.AppSettings["Pruebas"] == "true") { timbre.SelloSAT = "Inválido, Ambiente de pruebas"; } string res = sert.GetTimbreXml(timbre); string cfdiTimbrado = result; if (ConfigurationManager.AppSettings["EnvioSat"] == "false") { if (!TimbradoUtils.GuardaFactura(comp.Fecha, comp.Emisor.Rfc, comp.Receptor.Rfc, timbre.UUID, cfdiTimbrado, hash, empres, true, false)) { throw new Exception("Error al abrir el comprobante"); } } result2 = res; } else { if (timbre != null && timbre.SelloSAT == null && dict.Count == 0) { XElement el = XElement.Parse(result); XElement complemento = el.Elements(Constantes.CFDVersionNamespace + "Complemento").FirstOrDefault <XElement>(); if (complemento != null) { XElement t = complemento.Elements(Constantes.CFDTimbreFiscalVersionNamespace + "TimbreFiscalDigital").FirstOrDefault <XElement>(); if (t != null) { SidetecStringWriter sw = new SidetecStringWriter(Encoding.UTF8); t.Save(sw, SaveOptions.DisableFormatting); result2 = sw.ToString(); return(result2); } } } if (dict.Count > 0) { StringBuilder res2 = new StringBuilder(); foreach (KeyValuePair <int, string> d in dict) { res2.AppendLine(d.Key.ToString() + " - " + d.Value.ToString()); } result2 = res2.ToString(); } else { CertificadorService.Logger.Error("Error al abrir el comprobante: " + comprobante); result2 = "Error al abrir el comprobante"; } } } catch (Exception ex) { CertificadorService.Logger.Error(ex); result2 = "Error al abrir el comprobante: " + ex.Message; } return(result2); }
public string TimbraCfdi(string userName, string password, string comprobante) { string erroresNomina = "0"; if (!this.ValidCredentials(userName, password)) { throw new UnauthorizedAccessException("Invalid Ntlink internal user and password combination"); } string result2; try { XElement element = XElement.Load(new StringReader(comprobante)); ServicioLocal.Business.Comprobante comp = this.DesSerializar(element); if (comprobante.Contains("<ieeh:IngresosHidrocarburos")) { string erroIH = ""; IngresosHidrocarburos I = this.DesSerializarIH(element, ref erroIH); ValidarIngresoHidrocarburos VI = new ValidarIngresoHidrocarburos(); erroIH = VI.ProcesarIngresoHidrocarburos(I, comp.Version, comp.TipoDeComprobante, comp.Total); if (erroIH != "0") { result2 = erroIH; return(result2); } } if (comprobante.Contains("<gceh:GastosHidrocarburos")) { string erroGH = ""; GastosHidrocarburos I2 = this.DesSerializarGH(element, ref erroGH); ValidarGastosHidrocarburos VI2 = new ValidarGastosHidrocarburos(); erroGH = VI2.ProcesarGastosHidrocarburos(I2, comp.Version, comp.TipoDeComprobante); if (erroGH != "0") { result2 = erroGH; return(result2); } } ImpuestosLocales IL = null; if (comprobante.Contains("<implocal:ImpuestosLocales")) { IL = this.DesSerializarImpuestosLocales(element); } bool pago10 = comprobante.Contains("pago10:Pagos"); if (pago10) { ServicioLocal.Business.Pagoo.Comprobante pagoDatos = this.DesSerializarP(element); ServicioLocal.Business.Complemento.Pagos pagoss = this.DesSerializarPagos(element); ValidarPago VP = new ValidarPago(); string ErrorPagos = VP.ProcesarPago(comp, pagoss, pagoDatos); if (ErrorPagos != "0") { result2 = ErrorPagos; return(result2); } } if (comprobante.Contains("<ine:INE ")) { string erroINE = ""; INE I3 = this.DesSerializarINE(element, ref erroINE); ValidarINE VI3 = new ValidarINE(); erroINE = VI3.ProcesarINE(I3); if (erroINE != "0") { result2 = erroINE; return(result2); } } bool ComerExt = comprobante.Contains("cce11:ComercioExterior"); ValidarCFDI33 valida = new ValidarCFDI33(); string errorCFDI33 = valida.ProcesarCFDI33(comp, comprobante, pago10, ComerExt, IL); if (errorCFDI33 != "0") { CertificadorApps.Logger.Error("Error al abrir el comprobante: " + errorCFDI33); result2 = errorCFDI33; } else { if (comprobante.Contains("<ecc12:EstadoDeCuentaCombustible")) { string erroECC = ""; EstadoDeCuentaCombustible E = this.DesSerializarECC(element, ref erroECC); ValidarECC VE = new ValidarECC(); erroECC = VE.ProcesarECC(E, comp.TipoDeComprobante, comp.Version); if (erroECC != "0") { result2 = erroECC; return(result2); } } if (comp.Emisor != null && comp.Emisor.Rfc != null) { empresa empresa = TimbradoUtils.ValidarUsuarioSinSaldo(comp.Emisor.Rfc); if (empresa == null) { CertificadorApps.Logger.Info(comp.Emisor.Rfc + " No encontrado"); result2 = "300 - El usuario con el que se quiere conectar es inválido"; } else { string result = null; TimbreFiscalDigital timbre = null; string acuseSat = ""; string hash = null; bool nomin12 = comprobante.Contains("nomina12:Nomina"); List <Nomina> nom = new List <Nomina>(); if (nomin12) { string erroresNom = null; var nomx = this.DesSerializarNomina12(element, ref erroresNom); nom.Add(nomx); if (erroresNom != null) { result2 = erroresNom; return(result2); } } if (ComerExt && erroresNomina == "0") { string erroresComer = null; ValidarComercioExterior val = new ValidarComercioExterior(); ComercioExterior Comer = this.DesSerializarComercioExterior(element, ref erroresComer); if (erroresComer != null) { CertificadorApps.Logger.Error("Error al abrir el comprobante: " + erroresComer); result2 = erroresComer; return(result2); } erroresNomina = val.ProcesarComercioExterior(Comer, comp); } if (nomin12 && erroresNomina == "0") { erroresNomina = this._val.ProcesarNomina(nom, comp); } if (erroresNomina == "0") { Dictionary <int, string> dict = this._val.ProcesarCadena(comp.Emisor.Rfc, comprobante, ref result, ref timbre, ref acuseSat, ref hash); if (timbre != null && timbre.SelloSAT != null && dict.Count == 0) { if (!string.IsNullOrEmpty(comp.Confirmacion)) { using (NtLinkLocalServiceEntities db = new NtLinkLocalServiceEntities()) { ConfirmacionTimbreWs33 C = db.ConfirmacionTimbreWs33.FirstOrDefault((ConfirmacionTimbreWs33 p) => p.Folio == comp.Folio && p.RfcEmisor == comp.Emisor.Rfc && p.RfcReceptor == comp.Receptor.Rfc); C.procesado = new bool?(true); db.ConfirmacionTimbreWs33.ApplyCurrentValues(C); db.SaveChanges(); } } SerializadorTimbres sert = new SerializadorTimbres(); if (ConfigurationManager.AppSettings["Pruebas"] == "true") { timbre.SelloSAT = "Inválido, Ambiente de pruebas"; } string res = sert.GetTimbreXml(timbre); string cfdiTimbrado = result; if (ConfigurationManager.AppSettings["EnvioSat"] == "false") { if (!TimbradoUtils.GuardaFactura(comp.Fecha, comp.Emisor.Rfc, comp.Receptor.Rfc, timbre.UUID, cfdiTimbrado, hash, empresa, false, false)) { throw new Exception("Error al abrir el comprobante"); } } result2 = res; } else { if (timbre != null && timbre.SelloSAT == null && dict.Count == 0) { XElement el = XElement.Parse(result); XElement complemento = el.Elements(Constantes.CFDVersionNamespace + "Complemento").FirstOrDefault <XElement>(); if (complemento != null) { XElement t = complemento.Elements(Constantes.CFDTimbreFiscalVersionNamespace + "TimbreFiscalDigital").FirstOrDefault <XElement>(); if (t != null) { SidetecStringWriter sw = new SidetecStringWriter(Encoding.UTF8); t.Save(sw, SaveOptions.DisableFormatting); result2 = sw.ToString(); return(result2); } } } if (dict.Count > 0) { StringBuilder res2 = new StringBuilder(); foreach (KeyValuePair <int, string> d in dict) { res2.AppendLine(d.Key.ToString() + " - " + d.Value.ToString()); } result2 = res2.ToString(); } else { CertificadorApps.Logger.Error("Error al abrir el comprobante: " + comprobante); result2 = "Error al abrir el comprobante"; } } } else { CertificadorApps.Logger.Error("Error al abrir el comprobante: " + erroresNomina); result2 = erroresNomina; } } } else { CertificadorApps.Logger.Error("Error al abrir el comprobante: " + comprobante); result2 = "Error al abrir el comprobante"; } } } catch (Exception ex) { CertificadorApps.Logger.Error(ex); result2 = "Error al abrir el comprobante"; } return(result2); }