Example #1
0
        protected void Unnamed_Click(object sender, EventArgs e)
        {
            venta aux     = new venta();
            venta nueva   = new venta();
            int   bandera = 0;

            carro = (Carrito)Session[Session.SessionID + "articulo"];
            foreach (var item in carro.producto)
            {
                nueva.fechaventa = DateTime.Now.Date;
                nueva.producto   = item;
                nueva.Total      = Convert.ToDecimal(Session[Session.SessionID + "Total"]);
                if (bandera == 0)
                {
                    negocio1.AgregarVenta(nueva);
                    bandera++;
                }
                lista    = negocio1.listarTipo();
                aux      = lista[lista.Count - 1];
                nueva.Id = aux.Id;
                negocio1.AgregarVentaxProducto(nueva);
            }
            Usuario usua = new Usuario();

            usua = (Usuario)Session[Session.SessionID + "Usuario"];
            negocio1.AgregarVentaxUsuario(nueva, usua.Id);
            Response.Redirect("Listado.aspx");
        }
Example #2
0
 public venta ModificarVenta(venta oVenta)
 {
     try
     {
         using (BDSoftComputacionEntities bd = new BDSoftComputacionEntities())
         {
             oVenta.estado = null;
             if (oVenta.entregado == 0)
             {
                 oVenta.idEstado = 9;
             }
             else
             {
                 if (oVenta.entregado > 0 && oVenta.entregado < oVenta.costoTotal)
                 {
                     oVenta.idEstado = 10;
                 }
                 else
                 {
                     oVenta.idEstado = 11;
                 }
             }
             bd.Entry(oVenta).State = System.Data.Entity.EntityState.Modified;
             bd.SaveChanges();
             return(oVenta);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public async Task <IActionResult> Putventa(int id, venta venta)
        {
            if (id != venta.idVenta)
            {
                return(BadRequest());
            }

            _context.Entry(venta).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ventaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <venta> > Postarticulo(venta venta)
        {
            _context.venta.Add(venta);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("Get", new { id = venta.idVenta }, venta));
        }
 public ActionResult NuevaVenta(string nombreProducto = "", int idEstado = 0, int idCategoria = 0, int idSubCategoria = 0, int idProducto = 0)
 {
     try
     {
         usuario oUsuario = (usuario)Session["Usuario"];
         if (oUsuario == null)
         {
             Session.Clear();
             return(RedirectToAction("Index", "Home"));
         }
         if (Session["venta"] == null)
         {
             Session["venta"] = new venta();
         }
         srvEstado       sEstado      = new srvEstado();
         srvProducto     sProducto    = new srvProducto();
         srvCategoria    sCategoria   = new srvCategoria();
         List <producto> lstProductos = sProducto.ObtenerProductos(nombreProducto, idCategoria, idSubCategoria, idEstado, idProducto);
         Session["lstProducto"] = lstProductos;
         ViewBag.lstCategorias  = sCategoria.ObtenerCategorias();
         ViewBag.lstEstados     = sEstado.ObtenerEstados("PRODUCTO");
         ViewBag.filtros        = Convert.ToString(nombreProducto + ";" + idCategoria + ";" + idSubCategoria + ";" + idEstado);
         ProductoController ProductoController = new ProductoController();
         ViewBag.ValorUSD = ProductoController.GetValorUsd();
         PagedList <producto> model = new PagedList <producto>(lstProductos.ToList(), 1, 6);
         return(View(model));
     }
     catch (Exception)
     {
         return(RedirectToAction("Error", "Error", new { stError = "Se produjo un error al intentar obtener los datos del servidor." }));
     }
 }
        public ActionResult VistaVenta(int idVenta)
        {
            try
            {
                usuario oUsuario = (usuario)Session["Usuario"];
                if (oUsuario == null)
                {
                    Session.Clear();
                    return(RedirectToAction("Index", "Home"));
                }

                srvVenta      sVenta   = new srvVenta();
                srvMetodoPago sMetodoP = new srvMetodoPago();
                venta         oVenta   = sVenta.ObtenerVenta(idVenta);
                ViewBag.metodosPago  = sMetodoP.ObtenerMetodosPago();
                ViewBag.detallesPago = sVenta.ObtenerDetallesPagoDeVenta(idVenta);
                if (oVenta.idCliente == 0 || oVenta.idCliente == null)
                {
                    oVenta.idCliente        = 0;
                    oVenta.cliente          = new cliente();
                    oVenta.cliente.nombre   = "CONSUMIDOR ";
                    oVenta.cliente.apellido = "FINAL";
                }
                return(View(oVenta));
            }
            catch (Exception)
            {
                return(RedirectToAction("Error", "Error", new { stError = "Se produjo un error al intentar obtener los datos del servidor." }));
            }
        }
        public PartialViewResult _CarritoVenta(int idProducto, string precio, string cantidad)
        {
            decimal precioD   = Convert.ToDecimal(precio);
            int     cantidadI = Convert.ToInt32(cantidad);

            try
            {
                venta oVenta = new venta();
                if (Session["venta"] == null)
                {
                    Session["venta"] = new venta();
                }
                else
                {
                    //Session["venta"] = Session["venta"];
                    oVenta = (venta)Session["venta"];
                }
                srvVenta sVenta = new srvVenta();
                oVenta           = sVenta.agregarDetalle(oVenta, idProducto, precioD, cantidadI);
                Session["venta"] = oVenta;
                return(PartialView());
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public ActionResult GenerarVenta()
        {
            try
            {
                Session["lstProducto"] = null;
                usuario oUsuario = (usuario)Session["Usuario"];
                if (oUsuario == null)
                {
                    Session.Clear();
                    return(RedirectToAction("Index", "Home"));
                }
                venta oVenta = (venta)Session["venta"];

                oVenta.cliente   = null;
                oVenta.idUsuario = oUsuario.idUsuario;
                oVenta.entregado = 0;
                oVenta.idEstado  = 9;
                srvVenta sVenta = new srvVenta();
                if (oVenta.detalleVenta.Count == 0)
                {
                    return(RedirectToAction("Error", "Error", new { stError = "Se produjo un error al intentar obtener los datos del servidor." }));
                }
                if (oVenta.idCliente == 0)
                {
                    oVenta.idCliente = null;
                }
                oVenta           = sVenta.guardarVenta(oVenta);
                Session["venta"] = null;
                return(RedirectToAction("VistaVenta", new { idVenta = oVenta.idVenta }));
            }
            catch (Exception)
            {
                return(RedirectToAction("Error", "Error", new { stError = "Se produjo un error al intentar obtener los datos del servidor." }));
            }
        }
 public ActionResult DeleteConfirmed(int id)
 {
     venta venta = db.ventas.Find(id);
     db.ventas.Remove(venta);
     db.SaveChanges();
     return RedirectToAction("Index");
 }
Example #10
0
        public void setInfo(string id)
        {
            DataTable data = new venta().Detalle(id);

            if (data != null)
            {
                editar.Visible = true;
                DataRow r = data.Rows[0];

                txtCodigoVenta.Text = r["ID"].ToString();
                getCliente(r["ClienteID"].ToString());
                txtFechaVenta.Text          = r["FechaVenta"].ToString();
                txtTipoPago.Text            = new listadoItems().tipoPagoVenta()[int.Parse(r["TipoPago"].ToString())];
                ventaCredito.Checked        = (int.Parse(r["TipoVenta"].ToString()) == 1) ? true : false;
                txtSubtotal.Text            = r["SubTotal"].ToString();
                txtImpuesto.Text            = r["Impuesto"].ToString();
                txtTotal.Text               = r["Total"].ToString();
                labelFechaModificacion.Text = r["FechaModificacion"].ToString();
                listarDetalle();
            }
            else
            {
                new popup("Error al mostrar detalle", popup.AlertType.error);
            }
        }
 private void validate()
 {
     if (this.db.existventa(int.Parse(this.txtfirst.Text.Trim())))
     {
         this.xventa = this.db.getventa(int.Parse(this.txtfirst.Text.Trim()));
         if (this.xventa.status == statusVenta.ACTIVA)
         {
             this.panelfirst.Visible       = false;
             this.label2.Visible           = true;
             this.txtnumerodeventa.Visible = true;
             this.panel1.Visible           = true;
             this.btncancelarventa.Visible = true;
             this.Height = this.heightlast;
             this.CenterToScreen();
             this.initcommit();
         }
         else
         {
             genericDefinitions.error("Esta venta ya ha sido cancelada", "Seguridad");
             this.txtfirst.Text = "";
             this.txtfirst.Focus();
         }
     }
     else
     {
         genericDefinitions.error("Venta invalida", "Seguridad");
         this.txtfirst.Text = "";
         this.txtfirst.Focus();
     }
 }
Example #12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try {
                int idVenta = int.Parse(Request.QueryString["id"]);

                venta miventa = new venta(idVenta);
                txtFecha.Text = miventa.fecha.ToShortDateString();
                txtID.Text    = miventa.Id.ToString();

                List <detalleventa> listaDetalles = new detalleventa().GetAlldetalleventa();
                List <detalleventa> misDetalles   = new List <detalleventa>();

                foreach (detalleventa dv in listaDetalles)
                {
                    if (dv.idVenta == idVenta)
                    {
                        misDetalles.Add(dv);
                    }
                }

                grdDetalles.DataSource = misDetalles;
                grdDetalles.DataBind();
            } catch (Exception ex) {
                btnRegresar_Click(null, null);
            }
        }
Example #13
0
        public async Task <IActionResult> Putventa(int id, venta venta)
        {
            if (id != venta.idventa)
            {
                return(BadRequest());
            }

            //MI ENTIDAD YA TIENE LAS PROPIEDADDES O INFO QUE VOY A GUARDAR EN MY DB
            _context.Entry(venta).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ventaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(NoContent());
        }
Example #14
0
        // PUT api/Sales/5
        public IHttpActionResult Putventa(int id, venta venta)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != venta.id_venta)
            {
                return(BadRequest());
            }

            db.Entry(venta).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ventaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #15
0
        public List <venta> listarTipo()
        {
            List <venta> Listadotipo = new List <venta>();
            venta        aux;
            AccesoDatos  datos = new AccesoDatos();

            try
            {
                datos.setearSP("spListarVenta");
                datos.ejecutarLector();
                while (datos.lector.Read())
                {
                    aux    = new venta();
                    aux.Id = datos.lector.GetInt32(0);
                    aux.producto.Cantidad = datos.lector.GetInt32(1);
                    aux.Envios            = datos.lector.GetBoolean(2);
                    aux.fechaventa        = datos.lector.GetDateTime(3);
                    aux.Total             = datos.lector.GetDecimal(4);
                    Listadotipo.Add(aux);
                }

                return(Listadotipo);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                datos.cerrarConexion();
            }
        }
Example #16
0
        public List <venta> listarVentaXProductos()
        {
            List <venta> Listadotipo = new List <venta>();
            venta        aux;
            AccesoDatos  datos = new AccesoDatos();

            try
            {
                datos.setearSP("spListarVentaXProductos");
                datos.ejecutarLector();
                while (datos.lector.Read())
                {
                    aux                  = new venta();
                    aux.Id               = datos.lector.GetInt32(0);
                    aux.producto.id      = datos.lector.GetInt32(1);
                    aux.Total            = datos.lector.GetInt32(2);
                    aux.usuario.Id       = datos.lector.GetInt32(3);
                    aux.usuario.Nombre   = (string)datos.lector["Nombreusu"];
                    aux.usuario.Id       = datos.lector.GetInt32(5);
                    aux.usuario.Apellido = (string)datos.lector["Apellidousu"];
                    Listadotipo.Add(aux);
                }

                return(Listadotipo);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                datos.cerrarConexion();
            }
        }
Example #17
0
        public async Task <ActionResult <venta> > PostVenta(venta venta)
        {
            _context.Ventas.Add(venta);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetVenta", new { id = venta.idventa }, venta));
        }
Example #18
0
        //Logica para finalizar la compra del cliente
        public ActionResult FinalizaCompra()
        {
            List <CarritoItem> compras = (List <CarritoItem>)Session["carrito"];

            if (compras != null && compras.Count > 0)
            {
                venta nuevaVenta = new venta();
                nuevaVenta.fecha             = DateTime.Now;
                nuevaVenta.ApplicationUserId = User.Identity.GetUserId();
                nuevaVenta.total             = compras.Sum(x => x.Producto.precio * x.Cantidad);

                nuevaVenta.ventadetalle = (from producto in compras
                                           select new ventadetalle
                {
                    productosId = producto.Producto.Id,
                    nombre = producto.Producto.nombre,
                    cantidad = producto.Cantidad,
                    precio = producto.Producto.precio,
                    subtotal = producto.Cantidad * producto.Producto.precio
                }).ToList();

                db.venta.Add(nuevaVenta);
                db.SaveChanges();
                Session["carrito"] = new List <CarritoItem>();
            }

            return(View());
        }
Example #19
0
        public async Task <IActionResult> PutVenta(int id, venta venta)
        {
            if (id != venta.idventa)
            {
                return(BadRequest());                           // si es diferente no da un badrequest
            }
            _context.Entry(venta).State = EntityState.Modified; /*indicar al dbcontexr con el entity que lo que hay en venta
                                                                 *    vamos a realizar una modificacion , las entidad ya tiene las propiedades
                                                                 *      o informacion que vamos a guardar*/

            /*el manejo de erro try nos evitará  tener problemas a evitar que si hay error que la api no falle*/
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)//esto lo que hara un rollback a la operacion que se esta realizando
            {
                if (!VentaExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;// por si desconocemos el error
                }
            }
            return(NoContent());
        }
Example #20
0
        public venta agregarDetalle(venta oVenta, int idProducto, decimal precio, int cantidad)
        {
            try
            {
                detalleVenta oDetalle  = new detalleVenta();
                srvProducto  sProducto = new srvProducto();
                using (BDSoftComputacionEntities bd = new BDSoftComputacionEntities())
                {
                    if (oVenta.detalleVenta.Where(x => x.idProducto == idProducto).Count() == 1)
                    {
                        oVenta.detalleVenta.Where(x => x.idProducto == idProducto).FirstOrDefault().cantidad = oVenta.detalleVenta.Where(x => x.idProducto == idProducto).FirstOrDefault().cantidad + cantidad;
                        int cantidadExistente = oVenta.detalleVenta.Where(x => x.idProducto == idProducto).FirstOrDefault().cantidad;
                        oVenta.detalleVenta.Where(x => x.idProducto == idProducto).FirstOrDefault().costoGrupal = Convert.ToDecimal(precio * cantidadExistente);
                    }
                    else
                    {
                        oDetalle.idProducto = idProducto;
                        oDetalle.producto   = sProducto.ObtenerProducto(idProducto);
                        string nombre = oDetalle.producto.nombre;
                        oDetalle.costoIndividual = Convert.ToDecimal(precio);
                        oDetalle.costoGrupal     = Convert.ToDecimal(precio * cantidad);
                        oDetalle.cantidad        = cantidad;
                        oVenta.detalleVenta.Add(oDetalle);
                    }


                    return(oVenta);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #21
0
 public venta ObtenerVenta(int idVenta)
 {
     try
     {
         using (BDSoftComputacionEntities bd = new BDSoftComputacionEntities())
         {
             venta  oVenta = bd.venta.Where(x => x.idVenta == idVenta).FirstOrDefault();
             string temp   = "";
             if (oVenta.idCliente != 0 && oVenta.idCliente != null)
             {
                 temp = oVenta.cliente.apellido;
             }
             temp = oVenta.estado.nombre;
             temp = oVenta.usuario.nombre;
             foreach (detalleVenta oDetalle  in oVenta.detalleVenta)
             {
                 temp = oDetalle.producto.nombre;
                 temp = oDetalle.producto.subcategoria.nombre;
                 temp = oDetalle.producto.categoria.nombre;
             }
             return(oVenta);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        void NuevaVenta()
        {
            if (autoCliente.SelectedItem == null)
            {
                MessageBox.Show("Selecciona un cliente");
            }else
            {
                dynamic cl = autoCliente.SelectedItem;
                int idc = cl.id_cliente;
                venta v = new venta
                {
                    cliente_id = idc,
                    fecha_hora = DateTime.Now,
                    usuario_id = idus,
                    total = 0
                };
                BaseDatos.GetBaseDatos().ventas.Add(v);
                BaseDatos.GetBaseDatos().SaveChanges();
                idv = v.id_venta;
                autoProducto.IsEnabled = true;
                txtCantidad.IsEnabled = true;
                btnAgregar.IsEnabled = true;
                btnFinalizar.IsEnabled = true;
                autoCliente.IsEnabled = false;
                btnNuevaVenta.IsEnabled = false;
            }

            
        }
Example #23
0
        public void cargarLista()
        {
            venta        c = new venta();
            List <venta> listaCategorias = c.GetAllventa();

            grdVentas.DataSource = listaCategorias;
            grdVentas.DataBind();
        }
Example #24
0
        protected void Page_Load(object sender, EventArgs e)
        {
            venta        c           = new venta();
            List <venta> listaVentas = c.GetAllventa();

            grdVentas.DataSource = listaVentas;
            grdVentas.DataBind();
        }
        public ActionResult Delete(venta venta)
        {
            var _ventaBL = new VentaBL();

            _ventaBL.EliminarVenta(venta);

            return(RedirectToAction("Index"));
        }
Example #26
0
        public HomeUserControl()
        {
            InitializeComponent();
            _productoVendidoManager = Tools.Tools.FactoryManager.ProductVendidoManager();
            _productoManager        = Tools.Tools.FactoryManager.ProductoManager();
            _ventaManager           = Tools.Tools.FactoryManager.VentaManager();

            List <VentasDeProductosModel> productos = new List <VentasDeProductosModel>();
            int i = 1;

            foreach (var item in _productoManager.ObtenerTodo)
            {
                productos.Add(new VentasDeProductosModel()
                {
                    Id       = i++,
                    Producto = item.Nombre,
                    Cantidad = _productoVendidoManager.TotalDeProductosVendidos(item.IdProducto),
                });
            }

            Grafica(productos);

            i = 1;
            List <VentasPorMesModel> ventas         = new List <VentasPorMesModel>();
            List <venta>             todasLasVentas = _ventaManager.ObtenerTodo.ToList();
            venta primeraVenta = todasLasVentas.OrderBy(v => v.FechaHora).First();
            venta ultimaVenta  = todasLasVentas.OrderByDescending(v => v.FechaHora).First();
            int   anio         = primeraVenta.FechaHora.Year;
            int   mes          = primeraVenta.FechaHora.Month;

            List <VentaCompletaModel> ventasCompletas = _ventaManager.VentasEnIntervalo(primeraVenta.FechaHora, ultimaVenta.FechaHora).ToList();

            while (anio <= ultimaVenta.FechaHora.Year)
            {
                while (mes <= 12)
                {
                    if (anio == ultimaVenta.FechaHora.Year && mes > ultimaVenta.FechaHora.Month)
                    {
                        break;
                    }
                    ventas.Add(new VentasPorMesModel()
                    {
                        Id       = i++,
                        Anio     = anio,
                        Mes      = mes,
                        Cantidad = ventasCompletas.Where(v => v.Venta.FechaHora.Year == anio && v.Venta.FechaHora.Month == mes).Sum(x => x.TotalDeVenta),
                    });
                    mes++;
                    if (mes == 13)
                    {
                        mes = 1;
                        break;
                    }
                }
                anio++;
            }
            Grafica(ventas);
        }
Example #27
0
        private void dgvDatos_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            venta datos = new venta();

            datos.fecha = DateTime.Now;
            int idauto = int.Parse(this.dgvDatos.Rows[e.RowIndex].Cells[0].Value.ToString());

            clsventa.Venta(idauto, frmMainSistema.SessionActiva.usuario.idusuario, idcomprador, datos);
        }
        void GuardarCabecera()
        {
            venta v = new venta();

            v.Fecha        = DateTime.Parse(dtpFecha.Value.ToString());
            v.Cod_Cliente  = int.Parse(txtCodCliente.Text);
            v.Cod_Empleado = int.Parse(cboEmpleado.Text);
            v.Guardar();
        }
Example #29
0
 public ActionResult Edit([Bind(Include = "idventa,idcliente,tipo_comprobante,serie_comprobante,num_comprobante,fecha_hora,impuesto,total_venta,estado")] venta venta)
 {
     if (ModelState.IsValid)
     {
         db.Entry(venta).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(venta));
 }
        public ActionResult Edit(venta venta, HttpPostedFileBase imagen)
        {
            //if (imagen != null)
            //{
            //    venta.UrlImagen = GuardarImagen(imagen);
            //}
            _ventaBL.GuardarVenta(venta);

            return(RedirectToAction("Index"));
        }
        public bool guardarVenta(venta miVenta)
        {
            OleDbConnection cnn = new OleDbConnection(_rutaBD);

            try
            {
                cnn.Open();

                string comandoInsert = "'" + miVenta.idCliente + "', '" + miVenta.idArtículo + "', '" + miVenta.Cantidad + "', '" + miVenta.Precio + "', '" + miVenta.Fecha + "', '" + miVenta.Hora + "'";

                OleDbCommand cmd = new OleDbCommand("INSERT INTO Clientes (idCliente, monto, fecha) VALUES (" + comandoInsert + ")", cnn);

                cmd.ExecuteNonQuery();

                cnn.Close();

                return true;
            }
            catch
            {
                return false;
            }
        }
 public bool modificarVenta(venta venta_a_modificar)
 {
     throw new System.NotImplementedException();
 }
 public bool eliminarVenta(venta venta_a_eliminar)
 {
     OleDbConnection cnn = new OleDbConnection(_rutaBD);
     try
     {
         string cadenaSQL = "Delete from Ventas where Id=" + venta_a_eliminar.id;
         OleDbCommand cmd = new OleDbCommand(cadenaSQL, cnn);
         cmd.ExecuteNonQuery();
         return true;
     }
     catch
     {
         return false;
     }
 }