public ServicioTimbradoMovil() { XmlConfigurator.Configure(); try { this._val = new ValidadorCFDi32(); } catch (Exception ee) { ServicioTimbradoMovil.Logger.Error(ee); } }
public CertificadorService() { XmlConfigurator.Configure(); try { this.val = new ValidadorCFDi32(); } catch (Exception ee) { CertificadorService.Logger.Error(ee); } }
public static string TimbraCfdiString(string comprobante, empresa emp) { ValidadorCFDi32 val = new ValidadorCFDi32(); string result = null; ServicioLocal.Business.TimbreFiscalDigital timbre = null; string acuseSat = ""; string hash = null; XElement element = XElement.Parse(comprobante); Comprobante comp = TimbradoUtils.DesSerializar(element); Dictionary <int, string> dict = val.ProcesarCadena(comp.Emisor.Rfc, comprobante, ref result, ref timbre, ref acuseSat, ref hash); string result2; 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, emp, 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 { TimbradoUtils.Logger.Error("Error al abrir el comprobante:" + comprobante); result2 = "Error al abrir el comprobante"; } } return(result2); }