Ejemplo n.º 1
0
        public static DetallesVenta leerDetalleVentaUna(int id) // buscar
        {
            DetallesVenta p       = new DetallesVenta();
            MySqlCommand  comando = new MySqlCommand(String.Format("call DbuscarId('{0}')", id), ConectorMySQL.Conectar());

            try
            {
                MySqlDataReader leer1 = comando.ExecuteReader();

                while (leer1.Read())
                {
                    p.ID_Detalle  = leer1.GetInt32(0);
                    p.Cantidad    = leer1.GetInt32(1);
                    p.Descripcion = leer1.GetString(2);
                    p.Precio      = leer1.GetDouble(3);
                    p.Importe     = leer1.GetDouble(4);
                    p.ID_Producto = leer1.GetInt32(5);
                    p.ID_Venta    = leer1.GetInt32(6);
                }
                return(p);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                ConectorMySQL.Desconectar();
            }
        }
Ejemplo n.º 2
0
        public static List <DetallesVenta> leerPordescripcion(string descripcion) // buscar
        {
            List <DetallesVenta> listaBuscar = new List <DetallesVenta>();
            MySqlCommand         comando     = new MySqlCommand(String.Format("call DbuscarDescrip('{0}')", descripcion), ConectorMySQL.Conectar());

            try
            {
                MySqlDataReader leer1 = comando.ExecuteReader();

                while (leer1.Read())
                {
                    DetallesVenta d = new DetallesVenta();
                    d.ID_Detalle  = leer1.GetInt32(0);
                    d.Cantidad    = leer1.GetInt32(1);
                    d.Descripcion = leer1.GetString(2);
                    d.Precio      = leer1.GetDouble(3);
                    d.Importe     = leer1.GetDouble(4);
                    listaBuscar.Add(d);
                }
                return(listaBuscar);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                ConectorMySQL.Desconectar();
            }
        }
Ejemplo n.º 3
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            Ventas totalventa = new Ventas();

            if (cantidadTextBox.Text.Equals("0") || precioVentaTextBox.Text.Equals("0") || idProductoVComboBox.SelectedValue == null || totalProductoTextBox.Text.Equals("0"))
            {
                MessageBox.Show("Debe Ingresar todos los campos");
            }
            else
            {
                detalles = (DetallesVenta)detallesVentaBindingSource1.Current;
                if (cDetalles.verificarIngredientes(detalles) == true)
                {
                    listaDetalles.Add(detalles);
                    totalventa                     = (Ventas)ventasBindingSource.Current;
                    totalventa.TotalPagar          = totalventa.TotalPagar + detalles.totalProducto;
                    ventasBindingSource.DataSource = totalventa;

                    detallesVentaBindingSource1.EndEdit();
                    detallesVentaBindingSource1.AddNew();

                    detallesVentaBindingSource.DataSource = listaDetalles;
                    detallesVentaBindingSource.ResetBindings(true);
                    detallesVentaDataGridView.ClearSelection();
                }
                else
                {
                    MessageBox.Show("Ingredientes Insuficientes en el Almacen");
                }
            }
        }
Ejemplo n.º 4
0
        public static List <DetallesVenta> leerTodo() // mostrar
        {
            List <DetallesVenta> lista   = new List <DetallesVenta>();
            MySqlCommand         comando = new MySqlCommand(String.Format("call verDetalleVenta()"), ConectorMySQL.Conectar());

            try
            {
                MySqlDataReader leer = comando.ExecuteReader();
                while (leer.Read())
                {
                    DetallesVenta d = new DetallesVenta();
                    d.ID_Detalle  = leer.GetInt32(0);
                    d.Cantidad    = leer.GetInt32(1);
                    d.Descripcion = leer.GetString(2);
                    d.Precio      = leer.GetDouble(3);
                    d.Importe     = leer.GetDouble(4);
                    d.ID_Venta    = leer.GetInt32(5);

                    lista.Add(d);
                }
                return(lista);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                ConectorMySQL.Desconectar();
            }
        }
Ejemplo n.º 5
0
        private void botonHacerVenta_Click(object sender, EventArgs e)
        {
            if (labelSubtotal.Text != "00.00")
            {
                DetallesVenta detalle = new DetallesVenta();
                Venta         agregar = new Venta();

                foreach (DataGridViewRow row in tablaHacerVentas.Rows)
                {
                    detalle.ID_Producto = Convert.ToInt32(row.Cells["idProducto"].Value);
                    detalle.Cantidad    = Convert.ToInt32(row.Cells["Column1"].Value);
                    detalle.Descripcion = Convert.ToString(row.Cells["Column2"].Value);
                    detalle.Precio      = Convert.ToDouble(row.Cells["Column3"].Value);
                    detalle.Importe     = Convert.ToDouble(row.Cells["Column4"].Value);

                    Clases_DAO.DetalleVentaDAO.CrearDetalleTemporal(detalle.ID_Producto, detalle.Cantidad, detalle.Importe,
                                                                    detalle.Descripcion, detalle.Precio);
                }

                agregar.Subtotal = Convert.ToDouble(labelSubtotal.Text);
                agregar.IVA      = Convert.ToDouble(labelIVA.Text);
                agregar.Total    = Convert.ToDouble(labelTotal.Text);
                DateTime myDateTime       = DateTime.Now;
                string   sqlFormattedDate = myDateTime.ToString("yyyy-MM-dd HH:mm:ss");
                agregar.Efecha = sqlFormattedDate;

                int retorno = Clases_DAO.VentasDAO.crear(agregar);

                if (retorno > 0)
                {
                    MessageBox.Show("Agregado con éxito");
                    this.Close();
                    Clases_DAO.FuncionesGenerales.abrirFormInPanel(new VentanaBase(), Form1.panelContenedor);
                    Form1.botonInventario.BackColor = Color.LimeGreen;
                    Form1.botonVentas.BackColor     = Color.LimeGreen;
                    Form1.botonUsuarios.BackColor   = Color.LimeGreen;
                    Form1.button1.BackColor         = Color.DimGray;
                    Form1.iconoCerrar.BackColor     = Color.LimeGreen;
                    btnCancelarVenta.Visible        = false;

                    Form1.botonInventario.Enabled = true;
                    Form1.botonVentas.Enabled     = true;
                    Form1.botonUsuarios.Enabled   = true;
                    Form1.button1.Enabled         = true;
                    Form1.iconoCerrar.Enabled     = true;
                }
                else
                {
                    MessageBox.Show("Error");
                }
            }
            else
            {
                MessageBox.Show("Agrega mínimo un producto para poder registrar la venta");
            }
        }
Ejemplo n.º 6
0
        public void EliminarDetalleVenta(DetallesVenta dv)
        {
            IDbConnection     cn          = Conexion.Conexion.Conectar();
            DynamicParameters paramentros = new DynamicParameters();

            paramentros.Add("@id", dv.idDetalleVenta, DbType.Int32);
            cn.Open();
            cn.Execute("sp_EliminarDetalleVenta", paramentros, commandType: CommandType.StoredProcedure);
            cn.Close();
        }
Ejemplo n.º 7
0
        public void Eliminar(DetallesVenta detallesVenta)
        {
            string            consulta   = "Delete from DetallesVenta where IdDetalleVenta=@id";
            DynamicParameters parametros = new DynamicParameters();

            parametros.Add("@id", detallesVenta.IdDetalleVenta, DbType.Int32);
            cn.Open();
            cn.Execute(consulta, parametros, commandType: CommandType.Text);
            cn.Close();
        }
Ejemplo n.º 8
0
 private void cantidadTextBox_TextChanged(object sender, EventArgs e)
 {
     if (cantidadTextBox.Text != "" && precioVentaTextBox.Text != "")
     {
         int   cantidad = Convert.ToInt32(cantidadTextBox.Text);
         float precio   = float.Parse(precioVentaTextBox.Text);
         detalles = (DetallesVenta)detallesVentaBindingSource1.Current;
         detalles.totalProducto = (precio * cantidad);
         detallesVentaBindingSource1.DataSource = detalles;
     }
 }
Ejemplo n.º 9
0
        public DetallesVenta ObtenerUno(int id)
        {
            string            consulta      = "SELECT * FROM DetallesVenta where IdDetalleVenta=@id";
            DynamicParameters parametros    = new DynamicParameters();
            DetallesVenta     detallesVenta = new DetallesVenta();

            parametros.Add("@id", id, DbType.Int32);
            cn.Open();
            detallesVenta = cn.QuerySingle <DetallesVenta>(consulta, parametros);
            cn.Close();

            return(detallesVenta);
        }
Ejemplo n.º 10
0
        internal void guardarCompra(Ventas V)
        {
            DetallesVenta detalles = new DetallesVenta();

            mVenta.guardarVenta(V);
            for (int i = 0; i < V.detalles.Count; i++)
            {
                detalles         = V.detalles[i];
                detalles.idVenta = retornoId();
                CDetalles.guardarDetallesCompra(detalles);
            }
            mVenta.procesarVenta(retornoId());
        }
Ejemplo n.º 11
0
        public void RegistrarDetalleVenta(DetallesVenta dv)
        {
            IDbConnection     cn          = Conexion.Conexion.Conectar();
            DynamicParameters paramentros = new DynamicParameters();

            paramentros.Add("@idVenta", dv.idVenta, DbType.Int32);
            paramentros.Add("@idInventario", dv.idInventario, DbType.Int32);
            paramentros.Add("@cantidad", dv.cantidad, DbType.Int32);
            paramentros.Add("@precio", dv.precio, DbType.Double);
            paramentros.Add("@total", dv.total, DbType.Double);
            cn.Open();
            cn.Execute("sp_InsertarDetalleVenta", paramentros, commandType: CommandType.StoredProcedure);
            cn.Close();
        }
Ejemplo n.º 12
0
        internal void guardarDetallesVenta(DetallesVenta DV)
        {
            IDbConnection     con        = Conexion.Conexion.Conectar();
            String            consulta   = "sp_nuevoDetalleV";
            DynamicParameters parametros = new DynamicParameters();

            parametros.Add("@idProductoV", DV.idProductoV, DbType.Int32);
            parametros.Add("@precioVenta", DV.precioventa, DbType.Decimal);
            parametros.Add("@cantidad", DV.cantidad, DbType.Int32);
            parametros.Add("@idVenta", DV.idVenta, DbType.Int32);
            con.Open();
            con.Execute(consulta, parametros, commandType: CommandType.StoredProcedure);
            con.Close();
        }
Ejemplo n.º 13
0
        public void Insertar(DetallesVenta detallesVenta)
        {
            string            consulta   = "insert into DetallesVenta values (@IdDetalleInventario_FK,@Cantidad,@IdPresentacion_FK,@IdVenta_FK,@DecuentoAplicado,@PrecioVenta)";
            DynamicParameters parametros = new DynamicParameters();

            parametros.Add("@IdDetalleInventario_FK", detallesVenta.IdDetalleInventario_FK, DbType.Int32);
            parametros.Add("@Cantidad", detallesVenta.Cantidad, DbType.Int32);
            parametros.Add("@IdPresentacion_FK", detallesVenta.IdPresentacion_FK, DbType.Int32);
            parametros.Add("@IdVenta_FK", detallesVenta.IdVenta_FK, DbType.Int32);
            parametros.Add("@DecuentoAplicado", detallesVenta.DecuentoAplicado, DbType.Decimal);
            parametros.Add("@PrecioVenta", detallesVenta.PrecioVenta, DbType.Decimal);
            cn.Open();
            cn.Execute(consulta, parametros, commandType: CommandType.Text);
            cn.Close();
        }
Ejemplo n.º 14
0
        public void Actualizar(DetallesVenta detallesVenta)
        {
            string            consulta   = "Update DetallesVenta set IdDetalleInventario_FK=@IdDetalleInventario_FK,Cantidad=@Cantidad,IdPresentacion_FK=@IdPresentacion_FK,IdVenta_FK=@IdVenta_FK,DecuentoAplicado=@DecuentoAplicado,PrecioVenta=@PrecioVenta where IdDetalleVenta=@id";
            DynamicParameters parametros = new DynamicParameters();

            parametros.Add("@IdDetalleInventario_FK", detallesVenta.IdDetalleInventario_FK, DbType.Int32);
            parametros.Add("@Cantidad", detallesVenta.Cantidad, DbType.Int32);
            parametros.Add("@IdPresentacion_FK", detallesVenta.IdPresentacion_FK, DbType.Int32);
            parametros.Add("@IdVenta_FK", detallesVenta.IdVenta_FK, DbType.Int32);
            parametros.Add("@DecuentoAplicado", detallesVenta.DecuentoAplicado, DbType.Decimal);
            parametros.Add("@PrecioVenta", detallesVenta.PrecioVenta, DbType.Decimal);
            parametros.Add("@id", detallesVenta.IdDetalleVenta, DbType.Int32);
            cn.Open();
            cn.Execute(consulta, parametros, commandType: CommandType.Text);
            cn.Close();
        }
Ejemplo n.º 15
0
        public bool verificarIngredientes(DetallesVenta DV)
        {
            bool     verificar = true;
            MAlmacen mAlmacen  = new MAlmacen();
            MRecetas mRecetas  = new MRecetas();
            Recetas  recetas   = new Recetas();
            Almacen  almacen   = new Almacen();

            if (mRecetas.Listado(DV.idProductoV).Count > 0)
            {
                for (int i = 0; i < mRecetas.Listado(DV.idProductoV).Count; i++)
                {
                    recetas = mRecetas.Listado(DV.idProductoV)[i];
                    for (int I = 0; I < mAlmacen.Listado().Count; I++)
                    {
                        almacen = mAlmacen.Listado()[I];
                        if (almacen.idProductoC == recetas.idProductoC)
                        {
                            if (almacen.cantidadDisponible < (DV.cantidad / recetas.cantidadEstimada))
                            {
                                verificar = false;
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                        else if (almacen.idProductoC != recetas.idProductoC && I == mAlmacen.Listado().Count() - 1)
                        {
                            verificar = false;
                        }
                    }
                    if (verificar == false)
                    {
                        break;
                    }
                }
            }
            else
            {
                verificar = false;
            }
            return(verificar);
        }
Ejemplo n.º 16
0
        public int Insertar(Venta venta, List <ProductoPOS> detalles)
        {
            string            consulta   = "insert into Ventas values (@Fecha,@IdCliente_FK,@IdEmpleado_FK,@TipoDocumento,@Correlativo,@IdCorrelativo_FK,@Total,@Efectivo,@Cambio)";
            DynamicParameters parametros = new DynamicParameters();
            int idventa;

            parametros.Add("@Fecha", venta.Fecha, DbType.DateTime);
            parametros.Add("@IdCliente_FK", venta.IdCliente_FK, DbType.Int32);
            parametros.Add("@IdEmpleado_FK", venta.IdEmpleado_FK, DbType.Int32);
            parametros.Add("@TipoDocumento", venta.TipoDocumento, DbType.Int32);
            parametros.Add("@Correlativo", venta.Correlativo, DbType.Int64);
            parametros.Add("@IdCorrelativo_FK", venta.IdCorrelativo_FK, DbType.Int32);
            parametros.Add("@Total", venta.Total, DbType.Decimal);
            parametros.Add("@Efectivo", venta.Efectivo, DbType.Decimal);
            parametros.Add("@Cambio", venta.Cambio, DbType.Decimal);
            cn.Open();
            cn.Execute(consulta, parametros, commandType: CommandType.Text);
            idventa = cn.QuerySingle <int>("Select max(IdVenta) id from ventas", commandType: CommandType.Text);
            cn.Close();

            CCorrelativo correlativo = new CCorrelativo();

            correlativo.ActualizarCorrelativo(venta.IdCorrelativo_FK);

            CDetallesVenta      detalle    = new CDetallesVenta();
            CDetallesInventario inventario = new CDetallesInventario();

            foreach (ProductoPOS p in detalles)
            {
                DetallesVenta det = new DetallesVenta();
                det.Cantidad = p.Cantidad;
                det.IdDetalleInventario_FK = p.IdDetalleInventario;
                det.IdVenta_FK             = idventa;
                det.PrecioVenta            = p.Precio;

                detalle.Insertar(det);

                inventario.disminuirExistencias(det.IdDetalleInventario_FK, det.Cantidad.Value);
            }
            return(idventa);
        }
Ejemplo n.º 17
0
        public static int ActualizarVenta(DetallesVenta detalle, Producto producto, int cantidad)
        {
            int retorno = 0;

            MySqlCommand comando = new MySqlCommand(String.Format(" call ActualizarVenta('{0}','{1}','{2}')",
                                                                  detalle.ID_Venta, producto.Precio, cantidad), ConectorMySQL.Conectar());

            try
            {
                comando.ExecuteNonQuery();
            }
            catch (Exception)
            {
                MessageBox.Show("Error, venta no actualizada");
            }
            finally
            {
                ConectorMySQL.Desconectar();
            }

            return(retorno);
        }
Ejemplo n.º 18
0
        private void btnComprar_Click(object sender, EventArgs e)
        {
            if (dtvDetallesVenta.Rows.Count == 0)
            {
                MessageBox.Show("¡Aún no hay nada en el carrito!", "Carrito Vacío", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                DialogResult result = MessageBox.Show("¿Desea agregar algo más antes de comprar?", "Validación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.No)
                {
                    using (RestauranteBDEntities1 bd = new RestauranteBDEntities1())
                    {
                        Model.Ventas venta = new Model.Ventas();

                        String nombre = lblUsuario.Text;

                        venta.fechadeVenta    = DateTime.Now;
                        venta.totalPagar      = Convert.ToDecimal(lblTotalAPagar.Text);
                        venta.nombredeUsuario = nombre.ToString();
                        venta.estado          = "Enviada";
                        venta.NumMesa         = Convert.ToInt32(txtNMesa.Text);

                        bd.Ventas.Add(venta);
                        bd.SaveChanges();

                        DetallesVenta detallesV = new DetallesVenta();
                        for (int i = 0; i < dtvDetallesVenta.RowCount; i++)
                        {
                            String idProdV    = dtvDetallesVenta.Rows[i].Cells[0].Value.ToString();
                            int    idProdConv = Convert.ToInt32(idProdV);

                            String cantidad    = dtvDetallesVenta.Rows[i].Cells[3].Value.ToString();
                            int    cantiConver = Convert.ToInt32(cantidad);

                            String precio     = dtvDetallesVenta.Rows[i].Cells[2].Value.ToString();
                            Double precioConv = Convert.ToDouble(precio);

                            String  total     = dtvDetallesVenta.Rows[i].Cells[4].Value.ToString();
                            Decimal totalConv = Convert.ToDecimal(total);

                            var listaReceta = from recetas in bd.Recetas
                                              where recetas.idProductoV == idProdConv
                                              select recetas;
                            foreach (var iterar in listaReceta)
                            {
                                Recetas recetas  = new Recetas();
                                Almacen almaceen = new Almacen();
                                recetas = iterar;
                                int idR = Int32.Parse(recetas.idProductoC.ToString());
                                almaceen = bd.Almacen.Where(VerificarID => VerificarID.idProductoC == idR).First();
                                double cantidadRestada = (Convert.ToDouble(cantiConver) / Convert.ToDouble(recetas.cantidadProdIngrediente));
                                almaceen.cantidadDisponible = almaceen.cantidadDisponible - cantidadRestada;
                            }

                            detallesV.idVenta       = Convert.ToInt32(lblCodigo.Text);
                            detallesV.idProductoV   = idProdConv;
                            detallesV.cantidad      = cantiConver;
                            detallesV.precioCompra  = precioConv;
                            detallesV.totalProducto = totalConv;

                            bd.DetallesVenta.Add(detallesV);
                            bd.SaveChanges();
                        }

                        MessageBox.Show("¡Venta Enviada con éxito!", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        dtvDetallesVenta.Rows.Clear();
                        txtNMesa.Enabled = true;
                    }

                    RetornoId();
                }
            }
        }
        private void btnIngresar_Click(object sender, EventArgs e)
        {
            DetallesVenta detalle = new DetallesVenta();
            int           stockSuma = 0, stockResta = 0;

            cantidad = Convert.ToInt32(txtCantidadEliminar.Text);
            int idVenta   = Convert.ToInt32(FormModificarVentas.tabladetalle.CurrentRow.Cells[5].Value);
            int idDetalle = Convert.ToInt32(FormModificarVentas.tabladetalle.CurrentRow.Cells[0].Value);

            detalle  = Clases_DAO.DetalleVentaDAO.leerDetalleVentaUna(idDetalle);
            producto = Clases_DAO.ProductosDAO.obtenerproducto(detalle.ID_Producto);

            if (cantidad <= detalle.Cantidad)
            {
                stockResta = detalle.Cantidad - cantidad;
                stockSuma  = producto.Stock + cantidad;

                if (cantidad < detalle.Cantidad)
                {
                    int eliminado = Clases_DAO.VentasDAO.ActualizarStock(detalle.ID_Producto, stockSuma);
                    Clases_DAO.DetalleVentaDAO.ActualizarStockDetalle(detalle.ID_Detalle, stockResta, producto.Precio);

                    Clases_DAO.VentasDAO.ActualizarVenta(detalle, producto, cantidad);
                    if (eliminado > 0)
                    {
                        MessageBox.Show("El Producto fue eliminado con éxito");
                        FormModificarVentas.tabladetalle.DataSource = Clases_DAO.DetalleVentaDAO.leerDetalleVenta(idVenta);
                        MainMenuVentas.tablaVentas.DataSource       = Clases_DAO.VentasDAO.leerTodo();
                    }
                    else
                    {
                        MessageBox.Show("Error");
                    }
                }
                else
                {
                    int eliminado = Clases_DAO.VentasDAO.ActualizarStock(detalle.ID_Producto, stockSuma);
                    Clases_DAO.VentasDAO.ActualizarVenta(detalle, producto, cantidad);
                    if (eliminado > 0)
                    {
                        MessageBox.Show("El Producto fue eliminado con éxito");
                        Clases_DAO.DetalleVentaDAO.eliminarDetalleVenta(detalle.ID_Detalle);
                        FormModificarVentas.tabladetalle.DataSource = Clases_DAO.DetalleVentaDAO.leerDetalleVenta(idVenta);
                        MainMenuVentas.tablaVentas.DataSource       = Clases_DAO.VentasDAO.leerTodo();
                        if (Clases_DAO.VentasDAO.VentaEnCeros(idVenta))
                        {
                            Clases_DAO.VentasDAO.eliminar(idVenta);
                        }
                        MainMenuVentas.tablaVentas.DataSource = Clases_DAO.VentasDAO.leerTodo();
                    }
                    else
                    {
                        MessageBox.Show("Error");
                    }
                }
            }
            else
            {
                MessageBox.Show("No se existe esa cantidad del producto en la venta");
            }
            this.Dispose();
        }
        //[ValidateAntiForgeryToken]
        public ActionResult AlmostThere(VentasViewModel ventasViewModel, int?asd = null)
        {
            asd = 1;
            var cookie = Request.Cookies["your-cart-id"];

            if (cookie == null)
            {
                throw new ArgumentNullException("Cart cookie cannot be null!!");
            }

            var cartId = Guid.Parse(cookie?.Value);

            var details = db.DetallesVentaTMPs.Where(pdt => pdt.CartId == cartId).ToList();

            ventasViewModel.DetallesVentas2 = details;

            if (ModelState.IsValid)
            {
                if (details.Count > 0)
                {
                    using (var transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            var sale = new Venta()
                            {
                                NombreCliente   = ventasViewModel.NombreCliente,
                                ApellidoCliente = ventasViewModel.ApellidoCliente,
                                LocalidadId     = ventasViewModel.LocalidadId,
                                Direccion       = ventasViewModel.Direccion,
                                Comentarios     = ventasViewModel.Comentarios,
                                Telefono        = ventasViewModel.Telefono,
                                Correo          = ventasViewModel.Correo,
                                Fecha           = ventasViewModel.Fecha,
                                Estado          = "Pendiente",
                            };

                            db.Ventas.Add(sale);
                            db.SaveChanges();

                            foreach (var item in ventasViewModel.DetallesVentas2)
                            {
                                var producto = db.Productos.Find(item.ProductoId);

                                var saleDetail = new DetallesVenta()
                                {
                                    Descripcion = producto.Descripcion,

                                    Cantidad   = item.Cantidad,
                                    ProductoId = item.ProductoId,
                                    ColorId    = item.ColorId,
                                    VentaId    = sale.VentaId,
                                };
                                if (User.IsInRole("Admin"))
                                {
                                    saleDetail.Precio = producto.PrecioMay;
                                }
                                else
                                {
                                    saleDetail.Precio = producto.PrecioMin;
                                }
                                db.DetallesVentas.Add(saleDetail);

                                var productostock = db.Inventarios.FirstOrDefault(i => i.ProductoId == item.ProductoId && i.ColorId == item.ColorId);
                                productostock.Stock          -= item.Cantidad;
                                db.Entry(productostock).State = EntityState.Modified;
                                db.DetallesVentaTMPs.Remove(item);
                            }


                            ViewBag.LocalidadId = new SelectList(db.Localidads, "LocalidadId", "Name", ventasViewModel.LocalidadId);
                            db.SaveChanges();

                            transaction.Commit();
                            return(RedirectToAction("compraRealizada"));
                        }
                        catch (Exception ex)
                        {
                            transaction.Rollback();
                            ModelState.AddModelError(String.Empty, ex.Message);
                            return(View(ventasViewModel));
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError(String.Empty, "No hay productos agregados.");
                    return(View(ventasViewModel));
                }
            }
            ViewBag.LocalidadId = new SelectList(db.Localidads, "LocalidadId", "Name");
            return(View(ventasViewModel));
        }
Ejemplo n.º 21
0
 public void Actualizar(DetallesVenta detallesVenta)
 {
     mDetallesVenta.Actualizar(detallesVenta);
 }
Ejemplo n.º 22
0
 internal void guardarDetallesCompra(DetallesVenta DV)
 {
     mDetalles.guardarDetallesVenta(DV);
 }
Ejemplo n.º 23
0
 //*********************************************************
 public void Insertar(DetallesVenta detallesVenta)
 {
     mDetallesVenta.Insertar(detallesVenta);
 }
Ejemplo n.º 24
0
 public void RegistrarDetalleVenta(DetallesVenta dv)
 {
     mDetallesVenta.RegistrarDetalleVenta(dv);
 }
Ejemplo n.º 25
0
 public void Eliminar(DetallesVenta detallesVenta)
 {
     mDetallesVenta.Eliminar(detallesVenta);
 }
Ejemplo n.º 26
0
 public void EliminarDetalleVenta(DetallesVenta dv)
 {
     mDetallesVenta.EliminarDetalleVenta(dv);
 }