Ejemplo n.º 1
0
        public FacturaDB_ToMensajeReceptor Convertir(Factura_Resolucion facturaResolucion)
        {
            MensajeReceptor documento = new MensajeReceptor()
            {
                DetalleMensaje            = facturaResolucion.DetalleResolucion,
                FechaEmisionDoc           = facturaResolucion.Fecha_Documento,
                Mensaje                   = EnumUtils.SetTypeString <MensajeReceptorMensaje>(facturaResolucion.Resolucion.ToString()),
                TotalFactura              = facturaResolucion.TotalComprobante,
                Clave                     = facturaResolucion.Clave,
                NumeroCedulaEmisor        = facturaResolucion.Emisor_Identificacion_Numero.PadLeft(12).Replace(" ", "0"),
                NumeroCedulaReceptor      = Contribuyente.Identificacion_Numero.PadLeft(12).Replace(" ", "0"),
                NumeroConsecutivoReceptor = facturaResolucion.NumeroConsecutivo
            };

            if (facturaResolucion.TotalImpuesto.HasValue)
            {
                documento.MontoTotalImpuestoSpecified = true;
                documento.MontoTotalImpuesto          = facturaResolucion.TotalImpuesto.Value;
            }


            requestData = new FacturaRequest()
            {
                clave  = facturaResolucion.Clave,
                emisor = new FacturaClient()
                {
                    numeroIdentificacion = Contribuyente.Identificacion_Numero,
                    tipoIdentificacion   = EnumUtils.SetTypeString <FacturaElectronica_V_4_3.IdentificacionTypeTipo>(Contribuyente.Identificacion_Tipo).ToString()
                },
                fecha = facturaResolucion.Fecha_Documento.ToString("yyyy-MM-ddTHH:mm:ss"),
            };

            DocumentoElectronico = documento;
            return(this);
        }
Ejemplo n.º 2
0
        public MensajeReceptor CrearEstructuraMensajeReceptor(DataMensajeReceptor value)
        {
            MensajeReceptor MensajeReceptor = new MensajeReceptor
            {
                Clave = value.Clave,                                                                                             //CLAVE DEL DOCUMENTO AL CUAL SE ASOCIA ESTE MESAJE
                NumeroCedulaEmisor          = value.NumeroCedulaEmisor,
                FechaEmisionDoc             = value.FechaEmisionDoc,                                                             // FECHA Y HORA DE LA EMISION DE ESTA RESPUESTA
                Mensaje                     = (MensajeReceptorMensaje)Enum.Parse(typeof(MensajeReceptorMensaje), value.Mensaje), //Item1(aceptado),Item2(aceptado parcialmente) y Item3(rechazado)
                DetalleMensaje              = value.DetalleMensaje,                                                              //80 CARACTERES MAXIMOS
                MontoTotalImpuesto          = value.MontoTotalImpuesto.ToString(EngineData.decimalFormat5, CultureInfo.InvariantCulture),
                MontoTotalImpuestoSpecified = EngineDocumento.InsertFieldBoolCantidad(value.MontoTotalImpuesto),
                TotalFactura                = value.TotalFactura.ToString(EngineData.decimalFormat5, CultureInfo.InvariantCulture),
                NumeroCedulaReceptor        = value.NumeroCedulaReceptor,
                NumeroConsecutivoReceptor   = value.NumeroConsecutivoReceptor,
            };

            return(MensajeReceptor);
        }
        public XmlDocument CrearDocumentoXmlReceptor(DataMensajeReceptor objDataMensajeReceptor)
        {
            XmlDocument    documentoXml   = new XmlDocument();
            XmlDeclaration xmlDeclaracion = documentoXml.CreateXmlDeclaration("1.0", "UTF-8", null);
            XmlElement     root           = documentoXml.DocumentElement;

            documentoXml.InsertBefore(xmlDeclaracion, root);
            CreadorMensajeReceptor XmlMensaje      = new CreadorMensajeReceptor();
            MensajeReceptor        MensajeReceptor = new MensajeReceptor();

            MensajeReceptor = XmlMensaje.CrearEstructuraMensajeReceptor(objDataMensajeReceptor);
            var navMensajeReceptor = documentoXml.CreateNavigator();

            using (writer = navMensajeReceptor.AppendChild())
            {
                var serializer = new XmlSerializer(typeof(MensajeReceptor));
                serializer.Serialize(writer, MensajeReceptor);
            }
            return(documentoXml);
        }
Ejemplo n.º 4
0
        protected async void btnEnviar_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(this.txtNumConsecutivoReceptor.Text))
                {
                    this.alertMessages.Attributes["class"] = "alert alert-danger";
                    this.alertMessages.InnerText           = "Número de consecutivo requerido";
                    return;
                }

                Thread.CurrentThread.CurrentCulture = Utilidades.getCulture();

                MensajeReceptor dato = new MensajeReceptor();
                dato.clave           = this.txtClave.Text;
                dato.fechaEmisionDoc = txtFechaEmisor.Text;

                dato.numeroCedulaEmisor   = this.txtNumCedEmisor.Text;
                dato.numeroCedulaReceptor = this.txtNumCedReceptor.Text;

                dato.mensajeDetalle            = this.txtDetalleMensaje.Text;
                dato.mensaje                   = int.Parse(this.cmbMensaje.Value.ToString());
                dato.numeroConsecutivoReceptor = this.txtNumConsecutivoReceptor.Text;

                dato.montoTotalImpuesto = decimal.Parse(this.txtMontoTotalImpuesto.Text);
                dato.montoTotalFactura  = decimal.Parse(this.txtTotalFactura.Text);

                EmisorReceptorIMEC elEmisor = (EmisorReceptorIMEC)Session["elEmisor"];
                string             xml      = EncodeXML.XMLUtils.getXMLFromObject(dato);
                //string xmlSigned = FirmaXML.getXMLFirmadoWeb(xml, elEmisor.llaveCriptografica, elEmisor.claveLlaveCriptografica);

                //Habilitar solo cuando funcione el servicio
                string responsePost = await Services.enviarMensajeReceptor(xml, elEmisor, Session["receptor.tipoIdentificacion"].ToString());

                if (responsePost.Equals("Success"))
                {
                    this.alertMessages.Attributes["class"] = "alert alert-info";
                    this.alertMessages.InnerText           = "Los datos fueron enviados correctamente!!!";

                    using (var conexion = new DataModelFE())
                    {
                        elEmisor.consecutivo          += 1;
                        conexion.Entry(elEmisor).State = EntityState.Modified;
                        conexion.SaveChanges();
                        Session["elEmisor"] = elEmisor;
                    }

                    string correo = Session["receptor.CorreoElectronico"].ToString();
                    if (!string.IsNullOrWhiteSpace(correo))
                    {
                        string nombre = Session["receptor.Nombre"].ToString();

                        Utilidades.sendMail(Session["emisor"].ToString(), correo,
                                            string.Format("{0} - {1}", dato.clave.Substring(21, 20), nombre),
                                            Utilidades.mensageGenerico(), "Factura Electrónica", xml, dato.clave.Substring(21, 20), dato.clave, null);
                    }
                }
                else
                {
                    this.alertMessages.Attributes["class"] = "alert alert-danger";
                    this.alertMessages.InnerText           = String.Format("Factura #{0} con errores.", dato.clave);
                }

                this.guardarDocumentoReceptor();
                this.alertMessages.Attributes["class"] = "alert alert-info";
                this.alertMessages.InnerText           = "Los datos se guardaron correctamente!!!";
                //Limpiar la página
                //this.CleanControl(this.Controls);
                Response.Redirect("~/Pages/Facturacion/FrmCargarXMLReceptor.aspx");
            }
            catch (Exception ex)
            {
                this.alertMessages.Attributes["class"] = "alert alert-danger";
                this.alertMessages.InnerText           = Utilidades.validarExepcionSQL(ex);
            }
        }