コード例 #1
0
ファイル: FacturaXml.cs プロジェクト: moisesiq/aupaga
        public static ResAcc <TimbreXml> LeerXmlTimbrado(string sXmlFactura)
        {
            var Res = new ResAcc <TimbreXml>();

            XmlDocument oXml = new XmlDocument();

            oXml.LoadXml(sXmlFactura);
            var oTfds = oXml.GetElementsByTagName("tfd:TimbreFiscalDigital");

            if (oTfds.Count <= 0)
            {
                Res.Mensaje = "El Xml no contiene la información de timbrado.";
                return(Res);
            }
            try
            {
                var oTimbreXml = new TimbreXml();
                var oTfd       = oTfds[0];
                oTimbreXml.FolioFiscal        = oTfd.Attributes["UUID"].Value;
                oTimbreXml.SelloSat           = oTfd.Attributes["selloSAT"].Value;
                oTimbreXml.CertificadoSat     = oTfd.Attributes["noCertificadoSAT"].Value;
                oTimbreXml.FechaCertificacion = Convert.ToDateTime(oTfd.Attributes["FechaTimbrado"].Value);

                // Se genera la cadena original del timbre fiscal
                var oFacturaComps = oXml.GetElementsByTagName("cfdi:Comprobante");
                if (oFacturaComps.Count <= 0)
                {
                    Res.Mensaje = "El Xml no contiene la información del comprobante o está mal formado.";
                    return(Res);
                }
                var    oFacturaComp  = oFacturaComps[0];
                string sVersion      = oFacturaComp.Attributes["version"].Value;
                string sSelloFactura = oFacturaComp.Attributes["sello"].Value;
                oTimbreXml.CadenaOriginal = FacturaXml.GenerarCadenaOriginalTimbre(sVersion, sSelloFactura, oTimbreXml);

                Res.Respuesta = oTimbreXml;
            }
            catch (Exception e)
            {
                Res.Mensaje = e.Message;
                return(Res);
            }

            Res.Exito = true;
            return(Res);
        }
コード例 #2
0
        public ResAcc <string> GenerarFactura()
        {
            // Se genera el Xml
            var ResXml = FacturaXml.GenerarXml(this);

            if (ResXml.Error)
            {
                return(new ResAcc <string>(false, ResXml.Mensaje));
            }
            // Se llenan algunos datos generados

            /* this.NumeroDeCertificado = ResXml.Respuesta.NumeroDeCertificado;
             * this.Certificado = ResXml.Respuesta.Certificado;
             * this.Sello = ResXml.Respuesta.Sello;
             * this.XmlFactura = ResXml.Respuesta.XmlFactura;
             */

            var Res = new ResAcc <string>(true);

            Res.Respuesta = this.XmlFactura;
            return(Res);
        }
コード例 #3
0
 public ResAcc <TimbreXml> DatosFacturaTimbrada(string sXmlFactura)
 {
     return(FacturaXml.LeerXmlTimbrado(sXmlFactura));
 }
コード例 #4
0
ファイル: FacturaXml.cs プロジェクト: moisesiq/aupaga
        public static ResAcc <FacturaElectronica> GenerarXml(FacturaElectronica oFactura)
        {
            // Se genera el xml con los datos de la factura
            var    ResProcs    = FacturaXml.GenerarXmlDeObjeto(oFactura);
            string sFacturaXml = ResProcs.Respuesta;

            // Se transforma al Xml requerido por el Sat v3.2
            ResProcs = FacturaXml.TransformarXml(sFacturaXml, Properties.Resources.Cfdi3_2);
            if (ResProcs.Error)
            {
                return(new ResAcc <FacturaElectronica>(false, ResProcs.Mensaje));
            }
            string sCfdiXml = ResProcs.Respuesta;

            // Se valida el Xml generado
            ResProcs = FacturaXml.ValidarXml(sCfdiXml, Properties.Resources.cfdv32);
            if (ResProcs.Error)
            {
                return(new ResAcc <FacturaElectronica>(false, ResProcs.Mensaje));
            }

            // Se genera la cadena original
            ResProcs = FacturaXml.TransformarXml(sCfdiXml, Properties.Resources.cadenaoriginal_3_2);
            if (ResProcs.Error)
            {
                return(new ResAcc <FacturaElectronica>(false, ResProcs.Mensaje));
            }
            string sCadenaOriginal = System.Web.HttpUtility.HtmlDecode(ResProcs.Respuesta);

            // Se genera la cadena del sello digital
            var Seguridad = new FacturaSeguridad();

            ResProcs = Seguridad.GenerarSelloDigital(oFactura.Configuracion.RutaArchivoKey, oFactura.Configuracion.ContraseniaArchivoKey, sCadenaOriginal);
            if (ResProcs.Error)
            {
                return(new ResAcc <FacturaElectronica>(false, ResProcs.Mensaje));
            }
            string sSelloDigital = ResProcs.Respuesta;

            // Se agregan los nuevos datos al xml a generar
            var         oCertificado = Seguridad.DatosCertificado(oFactura.Configuracion.RutaCertificado);
            XmlDocument oXml         = new XmlDocument();

            oXml.LoadXml(sCfdiXml);
            oXml.DocumentElement.Attributes["noCertificado"].Value = oCertificado["NumeroDeSerie"];
            oXml.DocumentElement.Attributes["certificado"].Value   = oCertificado["ContenidoBase64"];
            oXml.DocumentElement.Attributes["sello"].Value         = sSelloDigital;
            // Se guarda el xml con los cambios
            var oTexto  = new StringWriterMod(Encoding.UTF8);
            var oEscXml = XmlWriter.Create(oTexto, FacturaXml.ConfigXml);

            oXml.Save(oEscXml);
            ResProcs.Exito     = true;
            ResProcs.Respuesta = oTexto.ToString();

            oFactura.NumeroDeCertificado = oCertificado["NumeroDeSerie"];
            oFactura.Certificado         = oCertificado["ContenidoBase64"];
            oFactura.Sello      = sSelloDigital;
            oFactura.XmlFactura = ResProcs.Respuesta;

            return(new ResAcc <FacturaElectronica>(true, oFactura));
        }