Exemple #1
0
        public ActionResult ConfirmarVenta(VentasAgregarPagoViewModel apVM)
        {
            if (apVM.ClienteID == 0)
            {
                apVM.ClienteID = 1;
            }
            apVM.Items = (List <VentaItem>)System.Web.HttpContext.Current.Session["ListaItemsVentaActual"];

            bool bandera = _ventasServicios.Add(apVM.MapearVenta());
            var  msj     = "";

            if (bandera)
            {
                msj = "Venta agregada correctamente!";
                var venta = _ventasServicios.GetOne(apVM.Pagos.FirstOrDefault().VentaID);
                _stockArticuloSucursalServicios.DescontarStock(venta);
                _stockMovimientosServicios.AgregarMovimientoVentas(venta.VentaItem, sucID, usr.Id);
                ViewBag.Informacion = "Venta generada correctamente!";
                return(View("PrintVenta", venta));
                //apVM = new VentasAgregarPagoViewModel();
            }
            else
            {
                ViewBag.Error = "No se pudo agregar la venta. Vuelva a intentarlo.";
                return(View("AgregarPago", apVM));
            }
            //return RedirectToAction("Agregar", new { mensaje = msj });
        }
Exemple #2
0
        public ActionResult AgregarPago(VentasAgregarPagoViewModel apVM)
        {
            apVM.FormasDePago = null;
            apVM.FormasDePago = new SelectList(_formasDePagoServicios.GetAll(), "Id", "Nombre", 1);
            if (apVM.FormaDePagoID != 0)
            {
                apVM.Items = (List <VentaItem>)System.Web.HttpContext.Current.Session["ListaItemsVentaActual"];
                var formaDePago = _formasDePagoServicios.GetOne(apVM.FormaDePagoID);
                if (apVM.Pagos.Any(a => a.FormaDePagoID == formaDePago.Id))
                {
                    ViewBag.Error = "La forma de pago ya está agregada.";
                    return(View(apVM));
                }

                Pago pago = new Pago();
                pago.FormaDePago   = _formasDePagoServicios.GetOne(formaDePago.Id);
                pago.FormaDePagoID = pago.FormaDePago.Id;
                apVM.Pagos.Add(pago);

                if (apVM.Pagos.Count == 1)
                {
                    apVM.Pagos.First().Monto = apVM.Total;
                }
            }
            else
            {
                Pago pago = new Pago();
                pago.FormaDePago   = _formasDePagoServicios.GetOne(1);
                pago.FormaDePagoID = pago.FormaDePago.Id;
                apVM.Pagos.Add(pago);
                if (apVM.Pagos.Count == 1)
                {
                    apVM.Pagos.First().Monto = apVM.Total;
                }
                //Agregao la forma de pago Devolución
                if (System.Web.HttpContext.Current.Session["SaldoAFavor"] != null)
                {
                    decimal SaldoAFavor = decimal.Parse(System.Web.HttpContext.Current.Session["SaldoAFavor"].ToString());

                    Pago pagoDev = new Pago();
                    pagoDev.FormaDePago   = _formasDePagoServicios.GetOne(4);
                    pagoDev.FormaDePagoID = pagoDev.FormaDePago.Id;
                    apVM.Pagos.Add(pagoDev);

                    apVM.Pagos[0].Monto = apVM.Total - SaldoAFavor;
                    apVM.Pagos[1].Monto = SaldoAFavor;
                }
                System.Web.HttpContext.Current.Session["ListaItemsVentaActual"] = apVM.Items;
            }

            return(View(apVM));
        }
Exemple #3
0
        public ActionResult EliminarFormaPago(VentasAgregarPagoViewModel apVM)
        {
            apVM.FormasDePago = new SelectList(_formasDePagoServicios.GetAll(), "Id", "Nombre", 1);
            if (apVM.FormaDePagoID != 0)
            {
                apVM.Items = (List <VentaItem>)System.Web.HttpContext.Current.Session["ListaItemsVentaActual"];
                Pago pago = new Pago();
                ModelState.Clear();
                pago = apVM.Pagos.Where(a => a.FormaDePagoID == apVM.FormaPagoIDEliminar).FirstOrDefault();
                apVM.Pagos.Remove(pago);

                if (apVM.Pagos.Count == 1)
                {
                    apVM.Pagos.First().Monto = apVM.Total;
                }

                ViewBag.Informacion = "Forma de pago eliminada correctamente!";
            }


            return(View("AgregarPago", apVM));
        }