Пример #1
0
        public TIMBRADO FacturarProductivo(string ArchivoXML, string UsuarioProfact, string Folio)
        {
            //Ubicación del servicio de pruebas
            //http://www.timbracfdipruebas.mx/ServicioIntegracionPruebas/Timbrado.asmx
            //Parámetro usuarioIntegrador
            //string usuarioIntegrador = "mvpNUXmQfK8=";
            //Parámetro comprobante a timbrar en base64
            string comprobanteBase64 = Convert.ToBase64String(System.IO.File.ReadAllBytes(ArchivoXML));

            ServiceReferenceProductivo.TimbradoSoapClient soapClient = new ServiceReferenceProductivo.TimbradoSoapClient();
            ServiceReferenceProductivo.ArrayOfAnyType     resultados = soapClient.TimbraCFDI(UsuarioProfact, comprobanteBase64, Folio);
            //Tipo de excepcion
            TIMBRADO tbr = new TIMBRADO()
            {
                TipoExcepcion = resultados[0].ToString(),
                //Numero de error
                NumeroError = resultados[1].ToString(),
                //Descripcion del resultado
                Descripcion = resultados[2].ToString(),
                //Xml timbrado
                Xml = resultados[3].ToString(),
                //Codigo bidimensional
                CodigoBidimensional = (byte[])(resultados[4]),
                //Cadena timbre
                CadenaTimbre = resultados[5].ToString()
            };

            return(tbr);
        }
Пример #2
0
        public object CrearNotaDeVenta(List <VENTA> Ventas, string Rfc, string FormaDePago, string DatosDePago)
        {
            CONFIGURACIONES configuracion  = new CONFIGURACIONES();
            CONSULTAS       sql            = new CONSULTAS();
            CONEXION        C              = new CONEXION();
            string          sentencia      = string.Empty;
            int             idnotadeventa  = int.Parse(C.EjecutarEscalar(sql.AGREGAR_NOTA_DE_VENTA()).ToString());
            TIMBRADO        timbradoactual = null;

            foreach (var venta in Ventas)
            {
                C.EjecutarSentencia(sql.AGREGAR_VENTAS(idnotadeventa, venta.Codigo, venta.Cantidad, venta.Unidad, venta.Descripcion, venta.Precio, venta.P_IEPS, venta.P_IVA, venta.P_ISH));
            }
            if (!string.IsNullOrEmpty(Rfc))
            {
                sentencia = sql.OBTENER_CLIENTE_POR_RFC(Rfc);
                DataTable dt  = C.EjecutarConsulta(sentencia);
                var       res = dt.AsEnumerable()
                                .Select(x => new
                {
                    RFC                  = x.Field <string>("RFC"),
                    RAZON_SOCIAL         = x.Field <string>("RAZON_SOCIAL"),
                    CALLE                = x.Field <string>("CALLE"),
                    NUMERO_INTERIOR      = x.Field <string>("NUMERO_INTERIOR"),
                    NUMERO_EXTERIOR      = x.Field <string>("NUMERO_EXTERIOR"),
                    COLONIA              = x.Field <string>("COLONIA"),
                    DELEGACION_MUNICIPIO = x.Field <string>("DELEGACION_MUNICIPIO"),
                    LOCALIDAD            = x.Field <string>("LOCALIDAD"),
                    ESTADO               = x.Field <string>("ESTADO"),
                    PAIS                 = x.Field <string>("PAIS"),
                    CODIGO_POSTAL        = x.Field <string>("CODIGO_POSTAL"),
                    CORREO_ELECTRONICO   = x.Field <string>("CORREO_ELECTRONICO")
                }).ToList();
                if (res.Count > 0)
                {
                    VALORACION_DE_TIMBRES t = new VALORACION_DE_TIMBRES();
                    Random mirandom         = new Random();
                    timbradoactual = t.TimbrarVenta(Ventas, idnotadeventa, configuracion.Consumidor, "Pago en una sola exhibicion", FormaDePago, res[0].RFC, res[0].RAZON_SOCIAL, res[0].CALLE, res[0].NUMERO_EXTERIOR,
                                                    res[0].NUMERO_INTERIOR, res[0].COLONIA, res[0].DELEGACION_MUNICIPIO, res[0].ESTADO, res[0].PAIS, res[0].CODIGO_POSTAL);
                    int idfactura = (int)(C.EjecutarEscalar(sql.AGREGAR_FACTURA("", FormaDePago, Ventas.Select(x => (double)x.Importe).Sum(), idnotadeventa, Rfc,
                                                                                timbradoactual.Folio.ToString(), res[0].RAZON_SOCIAL, "MXN", Ventas.Select(x => x.Importe + (x.Importe * x.P_IEPS) + (x.Importe * x.P_ISH) + (x.Importe * x.P_IVA)).Sum(),
                                                                                FormaDePago)));
                    //Nullable<int> creados = C.EjecutarSentencia(sql.AGREGAR_FACTURACION(IdNotaDeVenta, idfactura));
                    C.EjecutarSentencia(sql.ACTUALIZAR_fACTURA(idfactura, timbradoactual.Descripcion));
                    GENERACION_DE_REPORTES gr = new GENERACION_DE_REPORTES();
                    System.IO.FileInfo     fi = new System.IO.FileInfo(timbradoactual.RutaDeArchivo);
                    System.IO.File.WriteAllText(fi.FullName.Replace(fi.Extension, "_SAT.xml"), timbradoactual.Xml);
                    System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
                    xmlDoc.LoadXml(timbradoactual.Xml);
                    gr.GenerarFactura(fi.Name.Replace(fi.Extension, string.Empty), Ventas, res[0].RFC, res[0].RAZON_SOCIAL,
                                      string.Format("CALLE {0}, # EXTERIOR {1}, #INTERIOR {2}, COLONIA {3}", res[0].CALLE, res[0].NUMERO_EXTERIOR, res[0].NUMERO_INTERIOR, res[0].COLONIA),
                                      res[0].DELEGACION_MUNICIPIO, res[0].CODIGO_POSTAL, xmlDoc.ChildNodes[1].Attributes["folio"].Value,
                                      xmlDoc.ChildNodes[1].ChildNodes[4].ChildNodes[0].Attributes["UUID"].Value, xmlDoc.ChildNodes[1].ChildNodes[4].ChildNodes[0].Attributes["FechaTimbrado"].Value,
                                      xmlDoc.ChildNodes[1].Attributes["sello"].Value, xmlDoc.ChildNodes[1].ChildNodes[4].ChildNodes[0].Attributes["selloCFD"].Value,
                                      xmlDoc.ChildNodes[1].ChildNodes[4].ChildNodes[0].Attributes["noCertificadoSAT"].Value, "CODIGO RQ");
                    if (!string.IsNullOrEmpty(res[0].CORREO_ELECTRONICO))
                    {
                        NOTIFIACIONES nt = new NOTIFIACIONES();
                        nt.NotificacionPorCorreo(res[0].CORREO_ELECTRONICO, new List <string>()
                        {
                            fi.FullName.Replace(fi.Extension, "_SAT.xml"),
                            fi.FullName.Replace(fi.Extension, "_SAT.pdf")
                        });
                    }
                }
            }
            return(new
            {
                ID_NOTA_DE_VENTA = idnotadeventa,
                ERROR = (timbradoactual == null ? false : (timbradoactual.NumeroError == "0" ? false : true)),
                RESULTADO = (timbradoactual == null ? "" : timbradoactual.Descripcion)
            });
        }