コード例 #1
0
        public int guardarKardex(kardex K)
        {
            db.kardex.Add(K);
            db.SaveChanges();

            int id = Convert.ToInt16(db.kardex.Max(p => p.id));
            return id;
        }
コード例 #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();

                    int p = Convert.ToInt16(producto);
                    //Guardo Lote
                    int Lote = CAI.guardarLote(p, 1);

                    kardex K = new kardex();
                    K.cantidad_producto = DV.cantidad_producto;
                    K.fecha = DateTime.Today;
                    K.precio_u = DV.precio_u;
                    K.LOTE_id = Lote;
                    K.SUCURSAL_id = Convert.ToInt16(Session["Sucursal_id"]);
                    K.total_producto = DV.total;
                    K.MOVIMIENTO_id = 2;

                    int kar = CAI.guardarKardex(K);

                    CAI.guardarInventario(Convert.ToInt16(producto), kar);

                    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");
            }
        }
コード例 #3
0
        public ActionResult Create(M_D_Compra MDC)
        {
            //Obteniendo el valor del Master
            int Maestro = Convert.ToInt16(Session["M_C"]);
            int TIPOCOMPRA = MDC.TipoCompra;
            float totalMaster = 0;
            //recorriendo Arrays
            for (int i = 0; i < MDC.Cant.Count(); i++)
            {
                //Obtener Valores de la clase
                string cantidad = MDC.Cant[i];
                string producto = MDC.id[i];
                string costo = MDC.cost[i];
                if (cantidad != "" && costo !="")
                {
                    d_compra DC = new d_compra();
                    DC.M_COMPRA_id = Maestro;
                    DC.PRODUCTO_id = Convert.ToInt16(producto);
                    DC.cantidad_producto = Convert.ToInt16(cantidad);
                    DC.costo_unitario = float.Parse(costo);
                    DC.total = DC.cantidad_producto * DC.costo_unitario;

                    db.d_compra.Add(DC);
                    db.SaveChanges();

                    int p = Convert.ToInt16(producto);
                    //Guardo Lote
                    int Lote = CAI.guardarLote(p, 1);

                    kardex K = new kardex();
                    K.cantidad_producto = DC.cantidad_producto;
                    K.fecha = DateTime.Today;
                    K.precio_u = DC.costo_unitario;
                    K.LOTE_id = Lote;
                    K.SUCURSAL_id = Convert.ToInt16(Session["Sucursal_id"]);
                    K.total_producto = DC.total;
                    K.MOVIMIENTO_id = 1;

                    int kar = CAI.guardarKardex(K);
                    CAI.guardarInventario(Convert.ToInt16(producto),kar);

                    totalMaster = totalMaster + DC.total;
                }
            }

            m_compra MC = db.m_compra.Where(p => p.id == Maestro).Select(p => p).Single();
            MC.TIPO_COMPRA_id = TIPOCOMPRA;
            MC.total_compra = totalMaster;
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
            //Si es Nota de Credito
            if (MC.TIPO_COMPRA_id == 2)
            {
                return RedirectToAction("Create", "NotaCreditoVenta");
            }
            else
            {
                Session["M_C"] = null;
                return RedirectToAction("Index");
            }
        }