public HttpResponseMessage Get()
        {
            InformacionReferencia informacionreferencia = new InformacionReferencia();

            HttpResponseMessage response = Request.CreateResponse <List <Models.InformacionReferencia> >(HttpStatusCode.Created, informacionreferencia.Select_Todo_InformacionReferencia());

            return(response);
        }
        public HttpResponseMessage Get([FromUri] String id)
        {
            InformacionReferencia informacionreferencia = new InformacionReferencia();
            Factura clave = new Factura();

            clave.Clave1 = id;
            informacionreferencia.Clave1 = clave;

            HttpResponseMessage response = Request.CreateResponse <Models.InformacionReferencia>(HttpStatusCode.Created, informacionreferencia.Select_InformacionReferencia());

            return(response);
        }
        public HttpResponseMessage Delete(FormDataCollection form)
        {
            InformacionReferencia informacionreferencia = new InformacionReferencia();

            Factura clave = new Factura();

            clave.Clave1 = form.Get("Clave");
            informacionreferencia.Clave1 = clave;

            string[] respuesta = new string[2];
            respuesta[0] = informacionreferencia.Delete_InformacionReferencia();
            respuesta[1] = form.Get("Clave");

            HttpResponseMessage response = Request.CreateResponse <string[]>(HttpStatusCode.Created, respuesta);

            return(response);
        }
        public HttpResponseMessage Put(FormDataCollection form)
        {
            InformacionReferencia informacionreferencia = new InformacionReferencia();

            informacionreferencia.TipoDoc1      = form.Get("TipoDoc");
            informacionreferencia.Numero1       = form.Get("Numero");
            informacionreferencia.FechaEmision1 = Convert.ToDateTime(form.Get("FechaEmisionReferencia"));
            informacionreferencia.Codigo1       = form.Get("Codigo");
            informacionreferencia.Razon1        = form.Get("Razon");

            Factura clave = new Factura();

            clave.Clave1 = form.Get("Clave");
            informacionreferencia.Clave1 = clave;

            string[] respuesta = new string[2];
            respuesta[0] = informacionreferencia.Insert_InformacionReferencia();
            respuesta[1] = form.Get("Clave");

            HttpResponseMessage response = Request.CreateResponse <string[]>(HttpStatusCode.Created, respuesta);

            return(response);
        }
Ejemplo n.º 5
0
        protected async void btnCrearNota_Click(object sender, EventArgs e)
        {
            try
            {
                Thread.CurrentThread.CurrentCulture = Utilidades.getCulture();


                List <string> cc        = new List <string>();
                Regex         validator = new Regex(@"\s*\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*\s*");

                foreach (var correo in this.txtCorreoReceptor.Tokens)
                {
                    if (validator.IsMatch(correo))
                    {
                        cc.Add(correo);
                    }
                    else
                    {
                        this.alertMessages.Attributes["class"] = "alert alert-danger";
                        this.alertMessages.InnerText           = String.Format("Favor verifique el formato de la dirección {0}", correo);
                        return;
                    }
                }
                cc.RemoveAt(0);


                DetalleServicio detalle = (DetalleServicio)Session["detalleServicio"];
                if (detalle.lineaDetalle.Count == 0)
                {
                    this.alertMessages.Attributes["class"] = "alert alert-danger";
                    this.alertMessages.InnerText           = "Debe agregar almenos una linea de detalle a la factura";
                    return;
                }

                // datos de la factura original
                FacturaElectronica factura = new FacturaElectronica();
                string             clave   = Session["clave"].ToString();
                using (var conexion = new DataModelFE())
                {
                    WSRecepcionPOST datoPost   = conexion.WSRecepcionPOST.Find(clave);
                    string          xmlFactura = datoPost.comprobanteXml;
                    factura = (FacturaElectronica)EncodeXML.XMLUtils.getObjetcFromXML(xmlFactura, typeof(FacturaElectronica));

                    DocumentoElectronico dato = null;
                    if (TipoDocumento.NOTA_CREDITO.Equals(Session["tipoNota"].ToString()))
                    {
                        dato = new NotaCreditoElectronica();
                    }
                    else
                    {
                        dato = new NotaDebitoElectronica();
                    }


                    /* ENCABEZADO */
                    dato.medioPago      = factura.medioPago;
                    dato.plazoCredito   = factura.plazoCredito;
                    dato.condicionVenta = factura.condicionVenta;
                    dato.fechaEmision   = Date.DateTimeNow().ToString("yyyy-MM-ddTHH:mm:ss") + "-06:00";
                    /* DETALLE */
                    dato.detalleServicio = detalle;

                    /* EMISOR */
                    dato.emisor = factura.emisor;


                    /* RECEPTOR */
                    dato.receptor = factura.receptor;


                    /* INFORMACION DE REFERENCIA */
                    InformacionReferencia informacionReferencia = new InformacionReferencia();
                    informacionReferencia.numero        = factura.clave;
                    informacionReferencia.fechaEmision  = factura.fechaEmision;
                    informacionReferencia.codigo        = this.cmbCodigoReferencia.Value.ToString();
                    informacionReferencia.razon         = this.txtRazón.Text;
                    informacionReferencia.tipoDocumento = TipoDocumento.FACTURA_ELECTRONICA;
                    dato.informacionReferencia.Add(informacionReferencia);

                    /* RESUMEN */
                    dato.resumenFactura.tipoCambio   = factura.resumenFactura.tipoCambio;
                    dato.resumenFactura.codigoMoneda = factura.resumenFactura.codigoMoneda;
                    foreach (var item in dato.detalleServicio.lineaDetalle)
                    {
                        if (item.tipoServMerc == null)
                        {
                            Producto producto = conexion.Producto.Where(x => x.codigo == item.codigo.codigo && x.emisor == dato.emisor.identificacion.numero).FirstOrDefault();
                            item.tipoServMerc = producto.tipoServMerc;
                            item.producto     = producto.codigo;
                        }
                    }
                    dato.resumenFactura.calcularResumenFactura(dato.detalleServicio.lineaDetalle);

                    /* VERIFICA VACIOS PARA XML */
                    dato.verificaDatosParaXML();

                    //genera el consecutivo del documento
                    string   sucursal = this.cmbSucursalCaja.Value.ToString().Substring(0, 3);
                    string   caja     = this.cmbSucursalCaja.Value.ToString().Substring(3, 5);
                    object[] key      = new object[] { dato.emisor.identificacion.numero, sucursal, caja, this.cmbTipoDocumento.Value.ToString() };
                    ConsecutivoDocElectronico consecutivo = conexion.ConsecutivoDocElectronico.Find(key);
                    if (consecutivo != null)
                    {
                        dato.clave             = consecutivo.getClave(Date.DateTimeNow().ToString("yyyyMMdd"));
                        dato.numeroConsecutivo = consecutivo.getConsecutivo();

                        consecutivo.consecutivo          += 1;
                        conexion.Entry(consecutivo).State = EntityState.Modified;
                    }
                    else
                    {
                        consecutivo                   = new ConsecutivoDocElectronico();
                        consecutivo.sucursal          = ConsecutivoDocElectronico.DEFAULT_SUCURSAL;
                        consecutivo.caja              = ConsecutivoDocElectronico.DEFAULT_CAJA;
                        consecutivo.digitoVerificador = ConsecutivoDocElectronico.DEFAULT_DIGITO_VERIFICADOR;
                        consecutivo.emisor            = dato.emisor.identificacion.numero;
                        consecutivo.tipoDocumento     = this.cmbTipoDocumento.Value.ToString();
                        consecutivo.consecutivo       = 1;
                        consecutivo.estado            = Estado.ACTIVO.ToString();
                        consecutivo.fechaCreacion     = Date.DateTimeNow();

                        dato.clave             = consecutivo.getClave(Date.DateTimeNow().ToString("yyyyMMdd"));
                        dato.numeroConsecutivo = consecutivo.getConsecutivo();

                        consecutivo.consecutivo += 1;
                        conexion.ConsecutivoDocElectronico.Add(consecutivo);
                    }

                    EmisorReceptorIMEC elEmisor     = (EmisorReceptorIMEC)Session["elEmisor"];
                    string             responsePost = await Services.enviarDocumentoElectronico(false, dato, elEmisor, this.cmbTipoDocumento.Value.ToString(), Session["usuario"].ToString());

                    if (responsePost.Equals("Success"))
                    {
                        this.alertMessages.Attributes["class"] = "alert alert-info";
                        this.alertMessages.InnerText           = String.Format("Documento #{0} enviada.", dato.numeroConsecutivo);

                        if (!string.IsNullOrWhiteSpace(dato.receptor.correoElectronico) || this.txtCorreoReceptor.Tokens.Count > 0)
                        {
                            string xml = EncodeXML.XMLUtils.getXMLFromObject(dato);

                            Utilidades.sendMail(Session["emisor"].ToString(), dato.receptor.correoElectronico,
                                                string.Format("{0} - {1}", dato.numeroConsecutivo, elEmisor.nombre),
                                                Utilidades.mensageGenerico(), "Documento Electrónico", xml, dato.numeroConsecutivo, dato.clave, cc);
                        }
                    }
                    else if (responsePost.Equals("Error"))
                    {
                        this.alertMessages.Attributes["class"] = "alert alert-danger";
                        this.alertMessages.InnerText           = String.Format("Documento #{0} con errores.", dato.numeroConsecutivo);
                        return;
                    }
                    else
                    {
                        this.alertMessages.Attributes["class"] = "alert alert-warning";
                        this.alertMessages.InnerText           = String.Format("Documento #{0} pendiente de envío", dato.numeroConsecutivo);
                    }

                    conexion.SaveChanges();


                    Response.Redirect("~/Pages/Consulta/" + dato.clave);
                }
            }
            catch (Exception ex)
            {
                this.alertMessages.Attributes["class"] = "alert alert-danger";
                this.alertMessages.InnerText           = Utilidades.validarExepcionSQL(ex);
            }
            finally
            {
                //refescar los datos
                this.refreshData();
            }
        }