// GET: Facturas/Create
        public ActionResult Create()
        {
            ViewBag.cliente       = new SelectList(db.Clientes, "id", "nombrePersona");
            ViewBag.estadoFactura = new SelectList(db.estadoFacturas, "id", "nombreEstado");
            ViewBag.vendedor      = new SelectList(db.Usuarios, "id", "nombrePersona");
            ViewBag.fechaI        = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss");
            if (Session["FacturaI"] == null)
            {
                ViewBag.totalI = 0;
                FacturaView fv = new FacturaView();
                fv.factEncab        = new Factura();
                fv.Titulos          = new FacturaDetalle();
                fv.factList         = new List <FacturaDetalle>();
                Session["FacturaI"] = fv;
                return(View(fv));
            }
            decimal c  = 0;
            var     ff = Session["FacturaI"] as FacturaView;

            foreach (var item in ff.factList)
            {
                c += decimal.Parse(item.precio.ToString());
            }
            ViewBag.totalI = c;
            return(View(Session["FacturaI"] as FacturaView));
        }
Exemple #2
0
 public _00044_FormaPago(FacturaView factura)
     : this() // Ctor vacio
 {
     _factura       = factura;
     _vieneDeVentas = true;
     CargarDatos(_factura);
 }
        public _00050_Venta(
            IClienteServicio clienteServicio,
            IPuestoTrabajoServicio puestoTrabajoServicio,
            IListaPrecioServicio listaPrecioServicio,
            IConfiguracionServicio configuracionServicio,
            IEmpleadoServicio empleadoServicio,
            IContadorServicio contadorServicio,
            IArticuloServicio articuloServicio,
            IFacturaServicio facturaServicio)
        {
            InitializeComponent();
            this.DoubleBuffered = true;

            // -------------------------------------------- Servicios

            _clienteServicio       = clienteServicio;
            _puestoTrabajoServicio = puestoTrabajoServicio;
            _listaPrecioServicio   = listaPrecioServicio;
            _configuracionServicio = configuracionServicio;
            _empleadoServicio      = empleadoServicio;
            _contadorServicio      = contadorServicio;
            _articuloServicio      = articuloServicio;
            _facturaServicio       = facturaServicio;

            //----------------------------------------------

            dgvGrilla.AutoSizeRowsMode      = DataGridViewAutoSizeRowsMode.None;
            dgvGrilla.AllowUserToResizeRows = false;

            txtCodigo.KeyPress += delegate(object sender, KeyPressEventArgs args)
            {
                NoInyeccion(sender, args);
                NoLetras(sender, args);
            };

            // ----------------------------- Asignacion de Variables Privadas

            _clienteSeleccionado  = null;
            _vendedorSeleccionado = null;
            _articuloSeleccionado = null;
            _itemSeleccionado     = null;

            _permiteAgregarPorCantidad            = false;
            _articuloConPrecioAlternativo         = false;
            _autorizaPermisoListaPrecio           = false;
            _ingresoPorCodigoBascula              = false;
            _cambiarCantidadConErrorPorValidacion = false;

            _factura = new FacturaView();

            _configuracion = _configuracionServicio.Obtener();

            if (_configuracion == null)
            {
                MessageBox.Show("Antes de comenzar por favor cargue la configuracion del Sistema");
                Close();
            }
            // ----------------------------- Eventos
        }
Exemple #4
0
 private void LimpiarParaNuevaFactura()
 {
     _factura = new FacturaView();
     CargarCabecera();
     CargarCuerpo();
     CargarPie();
     LimpiarParaNuevoItem();
 }
Exemple #5
0
        public ActionResult NuevaFactura()
        {
            FacturaView facturaview = new FacturaView();

            facturaview.Clientes  = new ClienteFactura();
            facturaview.Productos = new List <ProductoFactura>();
            return(View(facturaview));
        }
        private void CargarDatos(FacturaView factura)
        {
            txtTotalAbonar.Text    = factura.TotalStr;
            nudMontoEfectivo.Value = factura.Total;

            nudMontoCheque.Value  = 0;
            nudMontoCtaCte.Value  = 0;
            nudMontoTarjeta.Value = 0;
            txtApellido.Text      = factura.Cliente.ApyNom;
            txtDni.Text           = factura.Cliente.Dni;
            txtTelefono.Text      = factura.Cliente.Telefono;
            txtDireccion.Text     = factura.Cliente.Direccion;
        }
Exemple #7
0
        public _00050_Venta(IClienteServicio clienteServicio,
                            IPuestoTrabajoServicio puestoTrabajoServicio,
                            IListaPrecioServicio listaPrecioServicio,
                            IConfiguracionServicio configuracionServicio,
                            IEmpleadoServicio empleadoServicio,
                            IContadorServicio contadorServicio,
                            IArticuloServicio articuloServicio)
        {
            InitializeComponent();

            this.DoubleBuffered = true;

            // ================================  Servicios   ================================= //

            _clienteServicio       = clienteServicio;
            _puestoTrabajoServicio = puestoTrabajoServicio;
            _listaPrecioServicio   = listaPrecioServicio;
            _configuracionServicio = configuracionServicio;
            _empleadoServicio      = empleadoServicio;
            _contadorServicio      = contadorServicio;
            _articuloServicio      = articuloServicio;

            // =============================================================================== //

            dgvGrilla.AutoSizeRowsMode      = DataGridViewAutoSizeRowsMode.None;
            dgvGrilla.AllowUserToResizeRows = false;

            // =================  Asignacion de Variables Privadas   ========================= //
            _clienteSeleccionado  = null;
            _vendedorSeleccionado = null;
            _articuloSeleccionado = null;
            _itemseleccionado     = null;

            _permiteAgregarPorCantidad    = false;
            _articuloConPrecioAlternativo = false;
            _autorizaPermisoListaPrecio   = false;
            _ingresoPorCodigoBascula      = false;

            _factura = new FacturaView();

            _configuracion = _configuracionServicio.Obtener();

            if (_configuracion == null)
            {
                MessageBox.Show("Antes de comenzar por favor cargue la configuracion del Sistema");
                Close();
            }
        }
        public ActionResult CancelarFact()
        {
            ViewBag.cliente       = new SelectList(db.Clientes, "id", "nombrePersona");
            ViewBag.estadoFactura = new SelectList(db.estadoFacturas, "id", "nombreEstado");
            ViewBag.vendedor      = new SelectList(db.Usuarios, "id", "nombrePersona");
            ViewBag.fechaI        = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss");
            ViewBag.totalI        = 0;
            FacturaView fv = new FacturaView();

            fv.factEncab        = new Factura();
            fv.Titulos          = new FacturaDetalle();
            fv.factList         = new List <FacturaDetalle>();
            Session["FacturaI"] = fv;
            Session["ProductI"] = new List <Inventario>();
            return(RedirectToAction("Create"));
        }
Exemple #9
0
        // GET: Facturas
        public ActionResult NuevaFactura()
        {
            var facturaView = new FacturaView();

            facturaView.Cliente    = new Cliente();
            facturaView.Productos  = new List <ProductoFactura>();
            Session["facturaView"] = facturaView;
            //Crear una lista para ordernarla y armar el ViewBag.Cliente
            var lista = db.Clientes.ToList();

            lista.Add(new Cliente {
                Id = 0, Nombre = "[Seleccione el Cliente]"
            });
            lista           = lista.OrderBy(c => c.Nombre).ToList();
            ViewBag.Cliente = new SelectList(lista, "Id", "Nombre");
            return(View(facturaView));
        }
Exemple #10
0
        private void CargarDatos(FacturaView factura)
        {
            txtTotalAbonar.Text    = factura.TotalStr;
            nudMontoEfectivo.Value = factura.Total;

            nudMontoCheque.Value = 0;
            txtNumeroCheque.Clear();
            dtpFechaVencimientoCheque.Value = DateTime.Now;

            nudMontoCtaCte.Value = 0;
            txtApellido.Text     = factura.Cliente.ApyNom;
            txtDni.Text          = factura.Cliente.Dni;
            txtTelefono.Text     = factura.Cliente.Telefono;
            txtDireccion.Text    = factura.Cliente.Direccion;

            nudMontoTarjeta.Value = 0;
            txtNumeroTarjeta.Clear();
            txtCuponPago.Clear();
            nudCantidadCuotas.Value = 1;
        }
        public ActionResult NuevaFactura()
        {
            var facturaView = new FacturaView();

            facturaView.Cliente    = new Cliente();
            facturaView.Product    = new List <ProductFactura>();
            Session["FacturaView"] = facturaView;

            var listp = db.Plans.ToList();

            listp.Add(new Plan {
                PlanId = 0, descripcion = "[Seleccione un tipo de Plan...]"
            });
            listp          = listp.OrderBy(p => p.descripcion).ToList();
            ViewBag.PlanId = new SelectList(listp, "PlanId", "descripcion");

            ClientesViewModel clientes = new ClientesViewModel();
            var list = from r in db.Clientes
                       join e in db.Plans on r.PlanId.ToString() equals e.PlanId.ToString()
                       join s in db.Sucursals on r.SucursalId.ToString() equals s.SucursalId.ToString()
                       // where ((r.ClienteId == clienteid || clienteid == null) && (e.SucursalId == sucursalid || sucursalid == null))
                       select new ClientesViewModel()
            {
                Nombre    = r.ClienteCodigo + "--" + s.Nombre + "--" + r.Nombre,
                ClienteId = r.ClienteId,
            };


            var lista = list.ToList();

            lista.Add((new ClientesViewModel {
                ClienteId = 0, Nombre = "[Seleccione un Cliente...]"
            }));
            ViewBag.ClienteId = new SelectList(lista, "ClienteId", "Nombre", 0);


            return(View(facturaView));
        }
        private void CargarDatos(FacturaView factura)
        {
            txtTotalAbonar.Text    = factura.TotalStr;
            nudMontoEfectivo.Value = factura.Total;
            nudMontoCheque.Value   = 0;
            txtNumeroCheque.Clear();
            dtpFechaVencimientoCheque.Value = DateTime.Now;
            nudMontoCtaCte.Value            = 0;
            txtApellido.Text  = factura.Cliente.ApyNom;
            txtDni.Text       = factura.Cliente.Dni;
            txtTelefono.Text  = factura.Cliente.Telefono;
            txtDireccion.Text = factura.Cliente.Direccion;

            txtMontoAdeudado.Text = factura.Cliente.Dni != Aplicacion.Constantes.Cliente.ConsumidorFinal
                ? _cuentaCorrienteServicio.ObtenerDeudaCliente(factura.Cliente.Id).ToString("C")
                :  0.ToString("C");


            nudMontoTarjeta.Value = 0;
            txtNumeroTarjeta.Clear();
            txtCuponPago.Clear();
            nudCantidadCuotas.Value = 1;
        }
 public FacturaViewModel(FacturaView facturaView)
 {
     this.Instancia = this;
     Mensajes       = facturaView;
 }
        public ActionResult NuevaFactura(FacturaView facturaView, string dtDetalles)
        {
            //CultureInfo DoTime = CultureInfo.CreateSpecificCulture("es-DO");
            //var hoy = Convert.ToString();
            var ukTimeZone = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
            // DateTime Today = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, ukTimeZone);
            //var DoTime = TimeZoneInfo.FindSystemTimeZoneById("SA Western Standard Time");
            //var Today = ukTime.AddMinutes(-240);
            //DateTime Today = DateTime.Now;

            var            info            = TimeZoneInfo.FindSystemTimeZoneById("SA Western Standard Time");
            DateTimeOffset localServerTime = DateTimeOffset.Now;
            DateTimeOffset istambulTime    = TimeZoneInfo.ConvertTime(localServerTime, info);
            var            Today           = istambulTime.DateTime;

            if (ModelState.IsValid)
            {
                using (var db = new ApplicationDbContext())
                {
                    try
                    {
                        if (!string.IsNullOrWhiteSpace(dtDetalles))
                        {
                            var idDetalle = 0;

                            List <DetalleFactura> jarray = JsonConvert.DeserializeObject <List <DetalleFactura> >(dtDetalles);
                            int            idHeader      = String.IsNullOrEmpty(db.Facturas.Max(u => (int?)u.FacturaId).ToString()) ? 1 : db.Facturas.Max(u => (int?)u.FacturaId).Value + 1;
                            DetalleFactura datosDetalle  = new DetalleFactura();


                            var cabecera = new Facturas()
                            {
                                FacturaId    = idHeader,
                                ClienteId    = facturaView.ClienteId2,
                                FechaFactura = Today,
                                FacEstatus   = 1,
                                UserName     = User.Identity.Name
                            };
                            db.Facturas.Add(cabecera);


                            foreach (var item in jarray)
                            {
                                idDetalle++;
                                datosDetalle = new DetalleFactura()
                                {
                                    cantidad         = 1,
                                    descripcion      = item.descripcion,
                                    productoId       = item.productoId,
                                    precio           = item.precio,
                                    DetalleFacturaId = idDetalle,
                                    FacturaId        = idHeader
                                };
                                db.DetalleFacturas.Add(datosDetalle);
                            }

                            //db.SaveChanges();
                        }
                        else
                        {
                            TempData.Add("Error", "Debe la factura");
                        }
                    }
                    catch (Exception e)
                    {
                        TempData.Add("Error", e.Message);
                        return(RedirectToAction("NuevaFactura"));
                    }

                    HttpBrowserCapabilitiesBase Navegador = Request.Browser;
                    string SistemaOperativo = "Android"; /// El fin de esto es para que imprima el cuadre de una vez -----



                    if (SistemaOperativo.Contains("Win"))
                    {
                        return(RedirectToAction("ReporteFactura"));
                    }
                    else
                    {
                        return(RedirectToAction("Conduce80MM"));
                    }
                }
            }
            return(RedirectToAction("NuevaFactura"));
        }
Exemple #15
0
        public ActionResult NuevaFactura(FacturaView facturaView)
        {
            facturaView = (FacturaView)Session["facturaView"];
            var ClienteId = int.Parse(Request["Id"]);

            if (ClienteId == 0)
            {
                ViewBag.Cliente = new SelectList(db.Clientes.ToList(), "Id", "Nombre");
                ViewBag.Error   = "Debe seleccionar un Cliente";
            }


            if (facturaView.Productos.Count == 0)
            {
                ViewBag.Error = "Factura en blanco";
            }
            var Cliente = db.Clientes.Find(ClienteId);

            if (Cliente == null)
            {
                ViewBag.Cliente = new SelectList(db.Clientes.ToList(), "Id", "Nombre");
                ViewBag.Error   = "Este Cliente NO existe";
            }

            var facturaId = 0;

            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    var factura = new Factura
                    {
                        ClienteId = ClienteId,
                        Fecha     = DateTime.Now,
                    };
                    db.Facturas.Add(factura);
                    db.SaveChanges();

                    facturaId = db.Facturas.ToList().Select(f => f.Id).Max();

                    var detalleId = db.Detalles.ToList().Select(d => d.Id).Max();
                    foreach (var item in facturaView.Productos)
                    {
                        var detalle = new Detalle
                        {
                            Id         = detalleId,
                            ProductoId = item.Id,
                            //Descripcion = item.Descripcion,
                            Cantidad  = item.Cantidad,
                            Precio    = item.Precio,
                            FacturaId = facturaId
                        };
                        var producto = db.Productos.Where(x => x.Id == item.Id);

                        db.Detalles.Add(detalle);
                        db.SaveChanges();
                    }
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    ViewBag.Error = "No se pudo guardar la Factura";
                    var listaClientes = db.Clientes.ToList();
                    listaClientes.Add(new Cliente {
                        Id = 0, Nombre = "Seleccione un Cliente"
                    });
                    listaClientes   = listaClientes.OrderBy(x => x.Nombre).ToList();
                    ViewBag.Cliente = new SelectList(listaClientes, "Id", "Nombre");
                    return(View(facturaView));
                }
            }
            ViewBag.Mensaje = string.Format("La orden ID: {0} se guardo con exito", facturaId);
            ViewBag.Cliente = new SelectList(db.Clientes.ToList(), "Id", "Nombre");

            //Armo la lista que le voy a pasar
            facturaView            = new FacturaView();
            facturaView.Cliente    = new Cliente();
            facturaView.Productos  = new List <ProductoFactura>();
            Session["facturaView"] = facturaView;
            return(View(facturaView));
        }
        public ActionResult Create(FacturaView fvv)
        {
            decimal c  = 0;
            var     ff = Session["FacturaI"] as FacturaView;

            fvv.factList = ff.factList;
            foreach (var item in ff.factList)
            {
                c += decimal.Parse(item.precio.ToString());
            }
            Factura insF     = fvv.factEncab;
            var     clientes = db.Clientes.ToList();

            foreach (var item in clientes)
            {
                if (item.nit.Equals(insF.nitFactura))
                {
                    insF.cliente       = item.id;
                    insF.nombreFactura = item.nombrePersona + " " + item.apellidoPersona;
                    break;
                }
            }
            insF.estadoFactura = db.estadoFacturas.ToList().First().id;
            insF.vendedor      = int.Parse(Session["UserID"].ToString());
            insF.totalFactura  = c;
            insF.fechaFactura  = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
            db.Factura.Add(insF);
            db.SaveChanges();
            insF = db.Factura.ToList().Last();
            foreach (var item in fvv.factList)
            {
                DetalleFactura df = new DetalleFactura();
                df.codigoFactura    = insF.id;
                df.codigoInventario = item.codigoInventario;
                df.precio           = item.precio;
                db.DetalleFactura.Add(df);
                db.SaveChanges();
            }
            InOut io = new InOut();

            io.descripcion   = "Salida por factura generada";
            io.fechaInOut    = insF.fechaFactura;
            io.tipoInOut     = 2;
            io.cantidadInOut = fvv.factList.Count;
            int eje = int.Parse(Session["UserID"].ToString());
            int ub  = int.Parse((from q in db.EmployeeBodega
                                 where q.idUsuario == eje
                                 select q).ToList().First().idBodega.ToString());

            io.ubicacionInOut = ub;
            db.InOut.Add(io);
            db.SaveChanges();
            io = db.InOut.ToList().Last();
            List <DetalleInOutP> dip = new List <DetalleInOutP>();

            foreach (var item in fvv.factList)
            {
                bool creador = true;
                int  proc    = int.Parse((from q in db.Inventario
                                          where q.id == item.codigoInventario
                                          select q).ToList().First().codigoProducto.ToString());
                foreach (var item1 in dip)
                {
                    if (item1.codigoProducto == proc)
                    {
                        item1.cantidadP++;
                        creador = false;
                    }
                }
                if (creador)
                {
                    DetalleInOutP dop = new DetalleInOutP();
                    dop.inoutType      = false;
                    dop.codigoProducto = proc;
                    dop.cantidadP      = 1;
                    dop.coidgoInOut    = io.id;
                    dip.Add(dop);
                }
            }
            foreach (var item in dip)
            {
                db.DetalleInOutP.Add(item);
                db.SaveChanges();
                var ite = db.DetalleInOutP.ToList().Last();
                foreach (var item1 in fvv.factList)
                {
                    int proc = int.Parse((from q in db.Inventario
                                          where q.id == item1.codigoInventario
                                          select q).ToList().First().codigoProducto.ToString());
                    if (proc == ite.codigoProducto)
                    {
                        DetalleInOut dit = new DetalleInOut();
                        dit.coidgoInOut    = ite.id;
                        dit.codigoProducto = item1.codigoInventario;
                        dit.cantidad       = 1;
                        db.DetalleInOut.Add(dit);
                        db.SaveChanges();
                    }
                }
            }
            foreach (var item in fvv.factList)
            {
                db.inveVendido(item.codigoInventario);
            }
            ViewBag.cliente       = new SelectList(db.Clientes, "id", "nombrePersona");
            ViewBag.estadoFactura = new SelectList(db.estadoFacturas, "id", "nombreEstado");
            ViewBag.vendedor      = new SelectList(db.Usuarios, "id", "nombrePersona");
            ViewBag.fechaI        = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss");
            ViewBag.totalI        = 0;
            FacturaView fv = new FacturaView();

            fv.factEncab        = new Factura();
            fv.Titulos          = new FacturaDetalle();
            fv.factList         = new List <FacturaDetalle>();
            Session["FacturaI"] = fv;
            Session["ProductI"] = new List <Inventario>();
            return(RedirectToAction("Create"));
        }
Exemple #17
0
        public ActionResult Facturacion()
        {
            var  Tbuscar         = Request["Cod_Tbuscar"];
            var  buscar          = Request["CBuscar"];
            var  factura         = new List <factura>();
            var  Blist           = new List <Buscar>();
            var  mesas           = db.Mesas.ToList();
            var  mesasEstado     = new List <MesasOcupadas>();
            var  mesasllegada    = new List <MesasOcupadas>();
            var  DMC             = new List <DetalleMesasCliente>();
            var  facturacionView = new FacturaView();
            bool busquedad       = false;
            int  x = Convert.ToInt32(Tbuscar);

            try
            {
                Blist.Add(new Buscar {
                    Cbuscar = 0, Tbuscar = "TIPO DE BUSQUEDA... "
                });
                Blist.Add(new Buscar {
                    Cbuscar = 1, Tbuscar = "MESA"
                });
                Blist.Add(new Buscar {
                    Cbuscar = 2, Tbuscar = "CLIENTE"
                });
                ViewBag.Cod_Tbuscar = new SelectList(Blist.OrderBy(m => m.Cbuscar).ToList(), "Cbuscar", "Tbuscar");
                foreach (var item in mesas)
                {
                    var mesasOcupada = db.MesasOcupadas.Where(t => t.Cod_Mesa == item.Cod_Mesa).ToList();
                    var mesasFecha   = mesasOcupada.Where(t => t.Fecha_MesasO == fecha).ToList();
                    if (mesasFecha.Count() == 0)
                    {
                        var mesasHora = mesasFecha.Where(t => (hora >= t.HoraIngreso_MesasO) && (t.HoraSalida_MesasO >= hora)).ToList();
                        mesasEstado = mesasHora.Where(t => t.Estado_MesasO == true).ToList();
                    }
                    else
                    {
                        if (mesasFecha.FirstOrDefault().Llegada_MesasO == true)
                        {
                            var mesasHora = mesasFecha.Where(t => (hora >= t.HoraIngreso_MesasO)).ToList();
                            mesasEstado = mesasHora.Where(t => t.Estado_MesasO == true).ToList();
                        }
                        else
                        {
                            var mesasHora = mesasFecha.Where(t => (hora >= t.HoraIngreso_MesasO) && (t.HoraSalida_MesasO >= hora)).ToList();
                            mesasEstado = mesasHora.Where(t => t.Estado_MesasO == true).ToList();
                        }
                    }
                    if (mesasEstado.Count() == 0)
                    {
                        var f = new factura
                        {
                            Estado      = item.Estado_Mesa,
                            Numero_Mesa = item.Numero_Mesa,
                            Cod_Mesa    = item.Cod_Mesa,
                            Ocupada     = false,
                        };
                        factura.Add(f);
                    }
                    else if (mesasEstado.Count() > 0)
                    {
                        decimal R = 0;
                        int     i = 0, idMesaO;
                        idMesaO = mesasEstado.FirstOrDefault().Cod_MesasO;
                        DMC     = db.DetalleMesasCliente.Where(t => t.Cod_MesasO == idMesaO).ToList();
                        string[] Tipo = DMC.FirstOrDefault().NConfirmacion_DMC.Split(new char[] { '-' });
                        foreach (var item1 in DMC)
                        {
                            Menu M = db.Menus.Find(item1.Cod_Menu);
                            R = R + (M.Valor_Menu * item1.Cantidad_DMC);
                            if (item1.PedidoM == true)
                            {
                                i++;
                            }
                        }
                        if (x != 0 && buscar != "")
                        {
                            if (x == 1)
                            {
                                long M = 0;
                                bool B = long.TryParse(Convert.ToString(buscar), out M);
                                if (B == true)
                                {
                                    if (item.Cod_Mesa == M)
                                    {
                                        busquedad        = true;
                                        ViewBag.busqueda = true;
                                    }
                                }
                                else
                                {
                                    ModelState.AddModelError(string.Empty, "Por favor ingrese un numero de mesa");
                                    ViewBag.Error = true;
                                }
                            }
                            else
                            {
                                string[] Cnombre   = DMC.FirstOrDefault().Cliente.Nombres_Cli.ToLower().Split(new char[] { ' ' });
                                string[] Capellido = DMC.FirstOrDefault().Cliente.Apellidos_Cli.ToLower().Split(new char[] { ' ' });
                                string[] s         = buscar.Split(new char[] { ' ' });
                                for (int y = 0; y < s.Length; y++)
                                {
                                    if (Cnombre.Count() > 1 && Capellido.Count() > 1)
                                    {
                                        if (Cnombre[0].Contains(s[y].ToLower()) || Capellido[0].Contains(s[y].ToLower()) ||
                                            Cnombre[1].Contains(s[y].ToLower()) || Capellido[1].Contains(s[y].ToLower()))
                                        {
                                            busquedad        = true;
                                            ViewBag.busqueda = true;
                                        }
                                    }
                                    else if (Cnombre.Count() == 1 && Capellido.Count() > 1)
                                    {
                                        if (Cnombre[0].Contains(s[y].ToLower()) || Capellido[0].Contains(s[y].ToLower()) || Capellido[1].Contains(s[y].ToLower()))
                                        {
                                            busquedad        = true;
                                            ViewBag.busqueda = true;
                                        }
                                    }
                                    else if (Cnombre.Count() > 1 && Capellido.Count() == 1)
                                    {
                                        if (Cnombre[0].Contains(s[y].ToLower()) || Capellido[0].Contains(s[y].ToLower()) || Cnombre[1].Contains(s[y].ToLower()))
                                        {
                                            busquedad        = true;
                                            ViewBag.busqueda = true;
                                        }
                                    }
                                    else
                                    {
                                        if (Cnombre[0].Contains(s[y].ToLower()) || Capellido[0].Contains(s[y].ToLower()))
                                        {
                                            busquedad        = true;
                                            ViewBag.busqueda = true;
                                        }
                                    }
                                }
                            }
                        }
                        else if (x == 0)
                        {
                            ModelState.AddModelError(string.Empty, "Selecciona el tipo de busquedad");
                            ViewBag.Error = true;
                        }
                        else if (buscar == "")
                        {
                            if (ModelState.IsValid)
                            {
                                ModelState.AddModelError(string.Empty, "Ingresa el numero de mesa o nombre del cliente");
                                ViewBag.Error = true;
                            }
                        }
                        var f = new factura
                        {
                            Estado        = item.Estado_Mesa,
                            Llegada       = mesasEstado.FirstOrDefault().Llegada_MesasO,
                            Numero_Mesa   = item.Numero_Mesa,
                            Cod_Mesa      = item.Cod_Mesa,
                            Ocupada       = true,
                            Cod_MesasO    = mesasEstado.FirstOrDefault().Cod_MesasO,
                            NConfirmacion = mesasEstado.FirstOrDefault().Reservada,
                            ValorTotal    = R,
                            CMenu         = i,
                            Cod_Cli       = DMC.FirstOrDefault().Cod_Cli,
                            TipoFactura   = Tipo[0],
                            Busquedad     = busquedad
                        };
                        factura.Add(f);
                        busquedad = false;
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, string.Format("Ha ocurrido un error al mostrar la vista <br/>" + ex.Message));
                facturacionView.factura = factura;
                return(View(facturacionView));
            }
            int c = 0, ca = factura.Count();

            foreach (var item in factura)
            {
                if (item.Busquedad == false && x == 2)
                {
                    c++;
                }
            }
            if (c == ca)
            {
                ModelState.AddModelError(string.Empty, "El cliente no ha reservado");
                ViewBag.Error = true;
            }
            facturacionView.factura = factura;
            return(View(facturacionView));
        }
Exemple #18
0
        public ActionResult Facturacion(bool?E, string NF, int?IdM)
        {
            var factura         = new List <factura>();
            var Blist           = new List <Buscar>();
            var mesas           = db.Mesas.ToList();
            var mesasEstado     = new List <MesasOcupadas>();
            var mesasllegada    = new List <MesasOcupadas>();
            var DMC             = new List <DetalleMesasCliente>();
            var facturacionView = new FacturaView();

            try
            {
                Blist.Add(new Buscar {
                    Cbuscar = 0, Tbuscar = "TIPO DE BUSQUEDA... "
                });
                Blist.Add(new Buscar {
                    Cbuscar = 1, Tbuscar = "MESA"
                });
                Blist.Add(new Buscar {
                    Cbuscar = 2, Tbuscar = "CLIENTE"
                });
                ViewBag.Cod_Tbuscar = new SelectList(Blist.OrderBy(m => m.Cbuscar).ToList(), "Cbuscar", "Tbuscar");
                if (E == true)
                {
                    int i = 0;
                    mesasllegada = db.MesasOcupadas.Where(t => t.Fecha_MesasO == fecha).ToList();
                    mesasllegada = mesasllegada.Where(t => t.Reservada == NF).ToList();
                    foreach (var item in mesasllegada)
                    {
                        if (item.Cod_MesasO == IdM)
                        {
                            i++;
                        }
                        var x = db.MesasOcupadas.Find(item.Cod_MesasO);
                        x.Llegada_MesasO  = true;
                        db.Entry(x).State = EntityState.Modified;
                    }
                    if (i != 0)
                    {
                        db.SaveChanges();
                    }
                }
                foreach (var item in mesas)
                {
                    var mesasOcupada = db.MesasOcupadas.Where(t => t.Cod_Mesa == item.Cod_Mesa).ToList();
                    var mesasFecha   = mesasOcupada.Where(t => t.Fecha_MesasO == fecha).ToList();
                    if (mesasFecha.Count() == 0)
                    {
                        var mesasHora = mesasFecha.Where(t => (hora >= t.HoraIngreso_MesasO) && (t.HoraSalida_MesasO >= hora)).ToList();
                        mesasEstado = mesasHora.Where(t => t.Estado_MesasO == true).ToList();
                    }
                    else
                    {
                        if (mesasFecha.FirstOrDefault().Llegada_MesasO == true)
                        {
                            var mesasHora = mesasFecha.Where(t => (hora >= t.HoraIngreso_MesasO)).ToList();
                            mesasEstado = mesasHora.Where(t => t.Estado_MesasO == true).ToList();
                        }
                        else
                        {
                            var mesasHora = mesasFecha.Where(t => (hora >= t.HoraIngreso_MesasO) && (t.HoraSalida_MesasO >= hora)).ToList();
                            mesasEstado = mesasHora.Where(t => t.Estado_MesasO == true).ToList();
                        }
                    }
                    if (mesasEstado.Count() == 0)
                    {
                        var f = new factura
                        {
                            Estado      = item.Estado_Mesa,
                            Numero_Mesa = item.Numero_Mesa,
                            Cod_Mesa    = item.Cod_Mesa,
                            Ocupada     = false,
                        };
                        factura.Add(f);
                    }
                    else if (mesasEstado.Count() > 0)
                    {
                        decimal R = 0;
                        int     i = 0, idMesaO;
                        idMesaO = mesasEstado.FirstOrDefault().Cod_MesasO;
                        DMC     = db.DetalleMesasCliente.Where(t => t.Cod_MesasO == idMesaO).ToList();
                        string[] Tipo = DMC.FirstOrDefault().NConfirmacion_DMC.Split(new char[] { '-' });
                        foreach (var item1 in DMC)
                        {
                            Menu M = db.Menus.Find(item1.Cod_Menu);
                            R = R + (M.Valor_Menu * item1.Cantidad_DMC);
                            if (item1.PedidoM == true)
                            {
                                i++;
                            }
                        }

                        var f = new factura
                        {
                            Estado        = item.Estado_Mesa,
                            Llegada       = mesasEstado.FirstOrDefault().Llegada_MesasO,
                            Numero_Mesa   = item.Numero_Mesa,
                            Cod_Mesa      = item.Cod_Mesa,
                            Ocupada       = true,
                            Cod_MesasO    = mesasEstado.FirstOrDefault().Cod_MesasO,
                            NConfirmacion = mesasEstado.FirstOrDefault().Reservada,
                            ValorTotal    = R,
                            CMenu         = i,
                            Cod_Cli       = DMC.FirstOrDefault().Cod_Cli,
                            TipoFactura   = Tipo[0]
                        };
                        factura.Add(f);
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, string.Format("Ha Ocurrido un Error al mostrar la vista <br/>" + ex.Message));
                facturacionView.factura = factura;
                return(View(facturacionView));
            }
            facturacionView.factura = factura;
            return(View(facturacionView));
        }