Пример #1
0
        public JsonResult ObtenVentas(String fFechaInicial, String fFechaFinal)
        {
            String filtro = String.Empty;

            if (string.IsNullOrEmpty(fFechaInicial))
            {
                if (Fechas.Count() != 0)
                {
                    fFechaInicial = Fechas.Min(x => x).ToString("yyyy-MM-dd");
                }
                else
                {
                    fFechaInicial = DateTime.Now.ToString("yyyy-MM-dd");
                }
            }
            DateTime DFechaInicial = Convert.ToDateTime(fFechaInicial).AddHours(00).AddMinutes(00).AddSeconds(00);

            if (String.IsNullOrEmpty(fFechaFinal))
            {
                fFechaFinal = DateTime.Now.ToString("yyyy-MM-dd");
            }
            DateTime DFechaFinal = Convert.ToDateTime(fFechaFinal).AddHours(23).AddMinutes(59).AddSeconds(59);

            filtro  = String.Format("FechaDeOperacion >= DateTime({0},{1},{2},{3},{4},{5})", DFechaInicial.Year, DFechaInicial.Month, DFechaInicial.Day, DFechaInicial.Hour, DFechaInicial.Minute, DFechaInicial.Second);
            filtro += String.Format("&& FechaDeOperacion <= DateTime({0},{1},{2},{3},{4},{5})", DFechaFinal.Year, DFechaFinal.Month, DFechaFinal.Day, DFechaFinal.Hour, DFechaFinal.Minute, DFechaFinal.Second);
            var VentasTotales = (from q in ClsVentasTotales.getList(filtro)
                                 select new
            {
                q.FolioDeOperacion,
                FechaDeOperacion = q.FechaDeOperacion.ToString("yyyy-MM-dd hh:mm:ss tt"),
                q.NombreDeUsuario,
                q.ImporteEntregado,
                q.ImporteCambio,
                q.ImporteNeto,
                q.TextoDeEstatus
            }).OrderBy(x => x.FechaDeOperacion);

            return(Json(new { data = VentasTotales }, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
 public ActionResult Index()
 {
     if (!ValidaSesion())
     {
         return(RedirectToAction("LoginOut", "Account"));
     }
     if (!ValidaFuncionalidad(NumeroDePantalla, (byte)ClsEnumerables.Funcionalidades.ACCESO))
     {
         return(RedirectToAction("Index", "Home"));
     }
     Fechas = (from q in ClsVentasTotales.getList() select q.FechaDeOperacion).ToList();
     if (Fechas.Count() != 0)
     {
         ViewBag.FechaInicialLimite = Fechas.Min(x => x).ToString("yyyy-MM-dd");
         ViewBag.MuestraBotones     = true;
     }
     else
     {
         ViewBag.FechaInicialLimite = DateTime.Now.ToString("yyyy-MM-dd");
         ViewBag.MuestraBotones     = false;
     }
     return(View());
 }
Пример #3
0
        public ClsAdicional.ClsResultado GeneraTicket(short FolioDeVenta)
        {
            ClsAdicional.ClsResultado Resultado = new ClsAdicional.ClsResultado(true, String.Empty);
            try
            {
                List <ClsParametros> ParametrosTicket = (from q in ClsParametros.getList() where q.CveTipo == 2 select q).ToList();
                var lista = (from q in ClsVentasTotales.getList() join v in ClsVentas.getList() on q.FolioDeOperacion equals v.FolioDeOperacion where q.FolioDeOperacion == FolioDeVenta select new { q, v }).ToList();

                List <Object> Producto = new List <Object>();
                foreach (var vproducto in lista)
                {
                    Producto.Add(new { vproducto.v.NombreDeProducto, vproducto.v.PrecioUnitario, vproducto.v.CantidadDeProducto, vproducto.v.ImporteDeProducto });
                }

                Object TicketObj = new
                {
                    FolioDeVenta     = FolioDeVenta,
                    Empresa          = (from q in ParametrosTicket where q.NombreDeParametro == "Empresa" select q.ValorDeParametro).FirstOrDefault(),
                    Dir              = (from q in ParametrosTicket where q.NombreDeParametro == "Direccion" select q.ValorDeParametro).FirstOrDefault(),
                    Tel              = (from q in ParametrosTicket where q.NombreDeParametro == "Telefono" select q.ValorDeParametro).FirstOrDefault(),
                    Atiende          = String.Format("{0} {1} {2}", MoSesion.NombreDePersona, MoSesion.ApellidoPaterno, MoSesion.ApellidoMaterno).ToUpper().Trim(),
                    Fecha            = String.Format("Fecha: {0} Hora: {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString()),
                    ImporteTotal     = lista.FirstOrDefault().q.ImporteNeto,
                    ImporteEntregado = lista.FirstOrDefault().q.ImporteEntregado,
                    Cambio           = lista.FirstOrDefault().q.ImporteCambio,
                    TextoFinal       = (from q in ParametrosTicket where q.NombreDeParametro == "TextoFinal" select q.ValorDeParametro).FirstOrDefault(),
                    ListaProducto    = Producto
                };
                //ClsTicket Ticket = new ClsTicket();
                //Ticket.TextoCentro(String.Format("Empresa {0}", (from q in ParametrosTicket where q.NombreDeParametro == "Empresa" select q.ValorDeParametro).FirstOrDefault()));
                //ClsTicket.LineasCaracter("*");
                //Ticket.TextoCentro(String.Format("Dir: {0}", (from q in ParametrosTicket where q.NombreDeParametro == "Direccion" select q.ValorDeParametro).FirstOrDefault()));
                //Ticket.TextoCentro(String.Format("Tel: {0}", (from q in ParametrosTicket where q.NombreDeParametro == "Telefono" select q.ValorDeParametro).FirstOrDefault()));
                //Ticket.TextoIzquierda(String.Empty);
                //Ticket.TextoCentro("Ticket de Venta");
                //Ticket.TextoIzquierda(String.Format("Fecha: {0} Hora: {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString()));
                //Ticket.TextoIzquierda("Le Atendio: " + String.Format("{0} {1} {2}", MoSesion.NombreDePersona, MoSesion.ApellidoPaterno, MoSesion.ApellidoMaterno).ToUpper());
                //Ticket.TextoIzquierda(String.Empty);
                //ClsTicket.LineasCaracter("*");
                //ClsTicket.EncabezadoVenta();
                //ClsTicket.LineasCaracter("*");
                //foreach (var vproducto in lista)
                //{
                //    Ticket.AgregaArticulo(vproducto.v.NombreDeProducto, vproducto.v.PrecioUnitario, vproducto.v.CantidadDeProducto, vproducto.v.ImporteDeProducto);
                //}
                //ClsTicket.LineasCaracter("*");
                //Ticket.AgregaTotales("Total:", lista.FirstOrDefault().q.ImporteNeto);
                //Ticket.TextoIzquierda(String.Empty);
                //Ticket.AgregaTotales("Efectivo Entregado:", lista.FirstOrDefault().q.ImporteEntregado);
                //Ticket.AgregaTotales("Efectivo Devuelto:", lista.FirstOrDefault().q.ImporteCambio);
                //Ticket.TextoIzquierda(String.Empty);
                //ClsTicket.LineasCaracter("*");
                //Ticket.TextoCentro((from q in ParametrosTicket where q.NombreDeParametro == "TextoFinal" select q.ValorDeParametro).FirstOrDefault());
                //ClsTicket.LineasCaracter("*");

                //Ticket.NombreDeTicket = String.Format("Ticket{0}{1}.txt", lista.FirstOrDefault().q.FolioDeOperacion, DateTime.Now.ToString("yyyyMMdd"));
                //Ticket.RutaDeTicket = System.Web.HttpContext.Current.Server.MapPath(ClsConfiguracion.Tickets);

                //Ticket.ImprimirTiket("POS-58", ref Resultado);
                //if (!Resultado.Resultado)
                //{
                //    ClsBitacora.GeneraBitacora(1, 1, "ImprimirTiket", Resultado.Mensaje);
                //}
                // Ticket.RegresaTextoTicket();
                Resultado.Adicional = TicketObj;
            }
            catch (Exception e)
            {
                ClsBitacora.GeneraBitacora((new ClsVentasTotales()).NumeroDePantallaKuup, 1, "GeneraTicket", String.Format(Recursos.Textos.Bitacora_TextoDeError, e.GetType().ToString(), e.Message.Trim(), e.GetHashCode().ToString()));
            }

            return(Resultado);
        }
Пример #4
0
        public ClsAdicional.ClsResultado RegistroDeVenta(decimal ImporteEntregado, decimal ImporteCambio, String ObjetoVenta)
        {
            ClsAdicional.ClsResultado Resultado     = new ClsAdicional.ClsResultado(true, "Registro de Venta Correcto");
            List <Object>             AvisaCantidad = new List <Object>();
            String Filtro = String.Empty;

            if (!String.IsNullOrEmpty(ObjetoVenta))
            {
                List <ClsVentas> RegistrosDeVentas = ClsAdicional.Deserializar <List <ClsVentas> >(ObjetoVenta);
                if (RegistrosDeVentas == null)
                {
                    RegistrosDeVentas = new List <ClsVentas>();
                }
                using (DBKuupEntities db = new DBKuupEntities())
                {
                    using (var Transaccion = db.Database.BeginTransaction())
                    {
                        try
                        {
                            ClsSequence      Sequence      = new ClsSequence(db.Database);
                            ClsVentasTotales VentasTotales = new ClsVentasTotales();
                            VentasTotales.db = db;
                            VentasTotales.FolioDeOperacion   = Sequence.SQ_FolioVenta();
                            VentasTotales.FechaDeOperacion   = DateTime.Now;
                            VentasTotales.NumeroDeUsuario    = MoSesion.NumeroDeUsuario;
                            VentasTotales.NombreDeCliente    = String.Empty;
                            VentasTotales.CveAplicaDescuento = 2;
                            VentasTotales.CveDeEstatus       = (byte)ClsEnumerables.CveDeEstatusVentas.VENDIDA;
                            VentasTotales.ImporteBruto       = (from q in RegistrosDeVentas select q.ImporteDeProducto).Sum();
                            VentasTotales.ImporteNeto        = VentasTotales.ImporteBruto;
                            VentasTotales.ImporteEntregado   = ImporteEntregado;
                            VentasTotales.ImporteCambio      = ImporteCambio;
                            if (VentasTotales.Insert())
                            {
                                var Productos = ClsProductos.getList(listaProductos: (from q in RegistrosDeVentas select q.NumeroDeProducto).ToList());
                                foreach (var Ventas in RegistrosDeVentas)
                                {
                                    if (Resultado.Resultado)
                                    {
                                        Ventas.db = db;
                                        Ventas.FolioDeOperacion = VentasTotales.FolioDeOperacion;
                                        var Producto = (from q in Productos where q.NumeroDeProducto == Ventas.NumeroDeProducto select q).FirstOrDefault();
                                        if (Ventas.CantidadDeProducto <= Producto.CantidadDeProductoTotal)
                                        {
                                            if (Ventas.Insert())
                                            {
                                                if (Producto != null)
                                                {
                                                    var Cantidad = Producto.CantidadDeProductoTotal - Ventas.CantidadDeProducto;
                                                    if (Cantidad >= 0)
                                                    {
                                                        Producto.db = db;
                                                        Producto.CantidadDeProductoTotal = (short)(Producto.CantidadDeProductoTotal - Ventas.CantidadDeProducto);
                                                        if (!Producto.Update())
                                                        {
                                                            Resultado.Resultado = false;
                                                            Resultado.Mensaje   = "No fue posible actualizar los titulos disponibles";
                                                            break;
                                                        }
                                                        if (Producto.CveAviso == 1)
                                                        {
                                                            if (Cantidad <= Producto.CantidadMinima)
                                                            {
                                                                //AvisaCantidad.Add(String.Format("El producto {0} esta proximo a terminarce Cantidad Actual {1}", Producto.NombreDeProducto, Producto.CantidadDeProductoTotal));
                                                                AvisaCantidad.Add(String.Format("{0}-x mensaje en bitacora", (new ClsVentasTotales()).NumeroDePantallaKuup.ToString().PadLeft(3, '0') + "1".PadLeft(3, '0')));
                                                                ClsBitacora.GeneraBitacora(1, 1, String.Format("RegistroDeVenta-{0}", (new ClsVentasTotales()).NumeroDePantallaKuup.ToString().PadLeft(3, '0') + "1".PadLeft(3, '0')), String.Format("El producto {0} esta proximo a terminarce Cantidad Actual {1}", Producto.NombreDeProducto, Producto.CantidadDeProductoTotal));
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        Resultado.Resultado = false;
                                                        //Resultado.Mensaje = "Ocurrió un problema al realizar la venta, debido a que no existen productos con la cantidad necesaria para hacer la venta";
                                                        Resultado.Mensaje = String.Format("{0}-x mensaje en bitacora", (new ClsVentasTotales()).NumeroDePantallaKuup.ToString().PadLeft(3, '0'), "2".PadLeft(3, '0'));
                                                        //AvisaCantidad.Add(String.Format("El producto {0} no cuenta con la cantidad a vender Cantidad Actual: {1} Cantidad a Vender: {2}", Producto.NombreDeProducto, Producto.CantidadDeProductoTotal, Ventas.CantidadDeProducto));
                                                        AvisaCantidad.Add(String.Format("{0}-x mensaje en bitacora", (new ClsVentasTotales()).NumeroDePantallaKuup.ToString().PadLeft(3, '0') + "2".PadLeft(3, '0')));
                                                        ClsBitacora.GeneraBitacora(1, 1, String.Format("RegistroDeVenta-{0}", (new ClsVentasTotales()).NumeroDePantallaKuup.ToString().PadLeft(3, '0') + "2".PadLeft(3, '0')), String.Format("El producto {0} no cuenta con la cantidad a vender Cantidad Actual: {1} Cantidad a Vender: {2}", Producto.NombreDeProducto, Producto.CantidadDeProductoTotal, Ventas.CantidadDeProducto));
                                                        break;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                Resultado.Resultado = false;
                                                Resultado.Mensaje   = "No fue posible cargar el detalle de la Venta";
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            Resultado.Resultado = false;
                                            //Resultado.Mensaje = "Ocurrió un problema al realizar la venta, debido a que no existen productos con la cantidad necesaria para hacer la venta";
                                            Resultado.Mensaje = String.Format("{0}-x mensaje en bitacora", (new ClsVentasTotales()).NumeroDePantallaKuup.ToString().PadLeft(3, '0') + "3".PadLeft(3, '0'));
                                            //AvisaCantidad.Add(String.Format("El producto {0} no cuenta con la cantidad a vender Cantidad Actual: {1} Cantidad a Vender: {2}", Producto.NombreDeProducto, Producto.CantidadDeProductoTotal, Ventas.CantidadDeProducto));
                                            AvisaCantidad.Add(String.Format("{0}-x mensaje en bitacora", (new ClsVentasTotales()).NumeroDePantallaKuup.ToString().PadLeft(3, '0') + "3".PadLeft(3, '0')));
                                            ClsBitacora.GeneraBitacora(1, 1, String.Format("RegistroDeVenta-{0}", (new ClsVentasTotales()).NumeroDePantallaKuup.ToString().PadLeft(3, '0') + "3".PadLeft(3, '0')), String.Format("El producto {0} no cuenta con la cantidad a vender Cantidad Actual: {1} Cantidad a Vender: {2}", Producto.NombreDeProducto, Producto.CantidadDeProductoTotal, Ventas.CantidadDeProducto));
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Resultado.Resultado = false;
                                Resultado.Mensaje   = "No fue posible realizar la Venta";
                            }
                            String Mensaje = String.Empty;
                            if (AvisaCantidad.Count() != 0)
                            {
                                Mensaje = String.Join("</ br>", AvisaCantidad);
                            }
                            if (Resultado.Resultado)
                            {
                                Transaccion.Commit();
                                ClsAdicional.ClsResultado RTicket = GeneraTicket(VentasTotales.FolioDeOperacion);
                                Resultado.Adicional = new { MensajeAviso = Mensaje, Ticket = RTicket.Adicional };
                            }
                            else
                            {
                                Object Ticket = null;
                                Transaccion.Rollback();
                                Resultado.Adicional = new { MensajeAviso = Mensaje, Ticket };
                            }
                        }
                        catch (Exception e)
                        {
                            Object Ticket = null;
                            Transaccion.Rollback();
                            Resultado.Adicional = new { MensajeAviso = String.Empty, Ticket };
                            Resultado.Resultado = false;
                            Resultado.Mensaje   = Recursos.Textos.Bitacora_TextoTryCatchGenerico;
                            ClsBitacora.GeneraBitacora(1, 1, "RegistroDeVenta", String.Format(Recursos.Textos.Bitacora_TextoDeError, e.GetType().ToString(), e.Message.Trim(), e.GetHashCode().ToString()));
                        }
                    }
                }
            }
            return(Resultado);
        }