//
 // GET: /NotaCreditoVenta/Pagar
 public ActionResult Pagar(long id = 0)
 {
     int rol = Convert.ToInt16(Session["Rol_id"]);
     bool Validacion = SEG.ValidarAcceso(rol, "NotaCreditoVenta", "Pagar");
     if (Validacion)
     {
         nota_credito_venta NCV = db.nota_credito_venta.Where(p => p.id == id).Select(p => p).Single();
         NCV.fecha_pagado = DateTime.Today;
         facturacion FAC = new facturacion();
         FAC.TIPO_FACTURACION_id = 2;
         FAC.M_VENTA_id = Convert.ToInt16(NCV.id);
         db.facturacion.Add(FAC);
         try
         {
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw e;
         }
         return RedirectToAction("Index");
     }
     else
     {
         return RedirectToAction("Error");
     }
 }
Exemplo n.º 2
0
        public ActionResult Create(M_D_Venta MDV)
        {
            //Obteniendo el valor del Master
            int Maestro = Convert.ToInt16(Session["M_V"]);
            int TipoFacturacion = MDV.TipoFacturacion;
            float totalMaster = 0;
            int caja = Convert.ToInt16(Session["Caja_id"]);
            //recorriendo Arrays
            for (int i = 0; i < MDV.Cant.Count(); i++)
            {
                //Obtener Valores de la clase
                string cantidad = MDV.Cant[i];
                string producto = MDV.id[i];
                int producto_id = int.Parse(producto);
                float precio = db.producto.Where(x => x.id == producto_id).Select(x => x.precio_venta_u).Single();
                float total = int.Parse(cantidad) * precio;
                if (cantidad != "")
                {
                    d_venta DV = new d_venta();
                    DV.PRODUCTO_id = int.Parse(producto);
                    DV.cantidad_producto = int.Parse(cantidad);
                    DV.total = total;
                    DV.M_VENTA_id = Maestro;
                    DV.precio_u = precio;

                    db.d_venta.Add(DV);
                    db.SaveChanges();

                    totalMaster = totalMaster + DV.total;
                }
            }

            m_venta MV = db.m_venta.Where(p => p.id == Maestro).Select(p => p).Single();
            MV.total = totalMaster;
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
            if (TipoFacturacion == 1)           //Nota de Credito Venta
            {
                return RedirectToAction("Create", "NotaCreditoVenta");
            }
            else if(TipoFacturacion == 2)       //tiquete
            {
                facturacion F = new facturacion();
                F.TIPO_FACTURACION_id = TipoFacturacion;
                F.M_VENTA_id = MV.id;
                db.facturacion.Add(F);
                db.SaveChanges();

                CIC.Ingreso(caja, totalMaster, Maestro);
                return Redirect("Index");

            }
            else if (TipoFacturacion == 3)       //Consumidor
            {
                CIC.Ingreso(caja, totalMaster, Maestro);
                return RedirectToAction("ConsumidorFinal");
            }
            else if (TipoFacturacion == 4)       //Credito fiscal
            {
                CIC.Ingreso(caja, totalMaster, Maestro);
                return RedirectToAction("CreditoFiscal");
            }
            else
            {
                return RedirectToAction("Index");
            }
        }
        public ActionResult Index(M_PeticionArduino MPA)
        {
            //Validar que haya gasolina del tipo seleccionado
            int est = Convert.ToInt16(MPA.estacion);
            int tipo = Convert.ToInt16(MPA.tipo);
            int cant = Convert.ToInt16(MPA.giro);

            float cantidadActual = db.estacion.Where(p => p.numero == est && p.tipo == tipo).Select(p => p.cantidad).Single();
            if(cantidadActual>float.Parse(MPA.giro))
            {
                //hacerlo
                if (tipo == 4)        //Regular
                {
                    //Arbitrariamente se selecciono grados menores de 90
                    MPA.tipo = "1";
                    float giro = float.Parse(MPA.giro)*10;
                    float movimiento = 90 - giro;
                    MPA.giro = movimiento.ToString();
                    CARD.EnviarPeticion(MPA);
                }
                else if(tipo == 6)    //Disel
                {
                    //Arbitrariamente se selecciono grados mayores de 90
                    MPA.tipo = "2";
                    float giro = float.Parse(MPA.giro)*10;
                    float movimiento = 90 + giro;
                    MPA.giro = movimiento.ToString();
                    CARD.EnviarPeticion(MPA);
                }

                // Actualizando BD
                estacion E = db.estacion.Where(p => p.numero == est && p.tipo == tipo).Single();
                E.cantidad = E.cantidad - cant;
                db.SaveChanges();

                m_venta MV = new m_venta();
                MV.fecha_venta = DateTime.Today;
                MV.EMPLEADO_id = Convert.ToInt16(Session["Empleado_id"]);
                MV.total = 0;

                db.m_venta.Add(MV);
                db.SaveChanges();

                int MASTER = Convert.ToInt16(db.m_venta.Max(x => x.id));

                d_venta DV = new d_venta();
                DV.PRODUCTO_id = tipo;
                DV.cantidad_producto = cant;
                DV.M_VENTA_id = MASTER;
                producto pro = db.producto.Where(p => p.id == tipo).Single();
                DV.precio_u = pro.precio_venta_u;
                DV.total = (DV.precio_u * DV.cantidad_producto);

                db.d_venta.Add(DV);
                db.SaveChanges();

                m_venta MV2 = db.m_venta.Where(p => p.id == MASTER).Select(p => p).Single();
                MV2.total = DV.total;
                db.SaveChanges();

                facturacion F = new facturacion();
                F.TIPO_FACTURACION_id = 2;
                F.M_VENTA_id = MV.id;
                db.facturacion.Add(F);
                db.SaveChanges();

                CIC.Ingreso(Convert.ToInt16(Session["Caja_id"]), MV2.total, MASTER);

                //Redireccionar Exito
                return RedirectToAction("Index");
            }
            else
            {
                //Escribir Error
                string mensaje = "Lo sentimos no hay suficiente combustible de ese tipo en esta estacion";
                return RedirectToAction("Index", new { mensaje });
            }
        }