public List <LineaVenta> listarProductosmasVendidos() { LineaVenta pr = null; List <LineaVenta> list = new List <LineaVenta>(); using (ProyectoEntities db = new ProyectoEntities()) { var query = (from p in db.LineaVenta group p by p.ProductoLV into g orderby g.Count() descending select new { idproducto = g.Key, cantidadventas = g.Count() }); if (query != null) { foreach (var r in query) { pr = new LineaVenta(); pr.ProductoLV = r.idproducto; pr.Cantidad = r.cantidadventas; list.Add(pr); } } } return(list); }
public void registrar(LineaVenta t) { t.IdLineaVenta = IdContador; IdContador++; todasLasLineasVenta.Add(t); }
public ActionResult DeleteConfirmed(int id) { LineaVenta lineaVenta = db.LineaVentas.Find(id); db.LineaVentas.Remove(lineaVenta); db.SaveChanges(); return(RedirectToAction("Index")); }
//Cuando clickamos a un producto para añadirlo a lineaventa private void producto_click(object sender, RoutedEventArgs e) { var aux = e.OriginalSource; if (aux.GetType() == typeof(Button)) { Button b = (Button)aux; String[] btname = b.Name.Split('_'); int cx = Convert.ToInt32(btname[1].Trim()); productoTPV = unit.RepositorioProducto.ObtenerUno(c => c.ProductoId == cx); if (productoTPV.Stock < 1) { MessageBox.Show("El producto no tiene stock", "ERROR", MessageBoxButton.OK, MessageBoxImage.Stop); } else { if (venta == null) { venta = new Venta(); //Empleado usuario = unit.RepositorioEmpleado.ObtenerUno(c => c.Nombre.Equals(user)); //venta.EmpleadoId = usuario.UsuarioId; //clientetpv = unit.RepositorioCliente.ObtenerUno(c => c.Nombre.Equals(cb_clientetpv.Text)); //venta.ClienteId = Convert.ToInt32(clientetpv.ClienteId); //venta.Fecha = DateTime.Now; } if (listalineaventas.Where(c => c.ProductoId.Equals(productoTPV.ProductoId)).FirstOrDefault() == null) { // la venta no tiene actualmente ese producto, se añade como linea lineaventa = new LineaVenta(); lineaventa.ProductoId = productoTPV.ProductoId; lineaventa.Cantidad = 1; lineaventa.VentaId = venta.VentaId; lineaventa.Productos = productoTPV; lineaventa.Ventas = venta; lineaventa.CalcularPrecio(); //venta.LineaVentas.Add(lineaventa); productoTPV.Stock--; unit.RepositorioProducto.Actualizar(productoTPV); listalineaventas.Add(lineaventa); } else { // la venta ya contiene ese producto, se incrementa la cantidad en la linea lineaventa = listalineaventas.Where(c => c.ProductoId.Equals(productoTPV.ProductoId)).FirstOrDefault(); lineaventa.Cantidad++; lineaventa.CalcularPrecio(); productoTPV.Stock--; unit.RepositorioProducto.Actualizar(productoTPV); } dg_TPV.ItemsSource = ""; dg_TPV.ItemsSource = listalineaventas; } } }
void ReducirCant(LineaVenta l, double precioF) { l.cantidad--; if (l.cantidad < 1) { carro.Remove(l); } l.precioTotal = (Convert.ToDouble(l.precioTotal) - Convert.ToDouble(precioF)).ToString(); Refrescar(); }
public void actualizar(LineaVenta t) { for (int i = 0; i < todasLasLineasVenta.Count; i++) { if (todasLasLineasVenta.ElementAt(i).IdLineaVenta == t.IdLineaVenta) { todasLasLineasVenta[i] = t; } } }
//clickar en datagrid elimina objeto private void dg_TPV_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { lineaventa = (LineaVenta)dg_TPV.SelectedItem; } catch (Exception) { } }
private Venta parse(List <Object> unRegistro) { int idVenta = (int)unRegistro.ElementAt(0); DateTime fechaVenta = DateTime.Parse(unRegistro.ElementAt(1).ToString()); double iva = Convert.ToDouble(unRegistro.ElementAt(2)); double importeTotal = Convert.ToDouble(unRegistro.ElementAt(3)); int idCliente = (int)unRegistro.ElementAt(4); int idEmpleado = (int)unRegistro.ElementAt(5); int idPedido = (int)unRegistro.ElementAt(6); Venta nuevaVenta = new Venta(); nuevaVenta.IdVenta = idVenta; nuevaVenta.fechaDeVenta = fechaVenta; nuevaVenta.iva = iva; IClienteDAO clienteDao = new ClienteDaoImpl(); nuevaVenta.agregarCliente(clienteDao.leerPorId(idCliente)); IEmpleadoDAO emleadoDao = new EmpleadoDaoImpl(); nuevaVenta.agregarEmpleado(emleadoDao.leerPorId(idEmpleado)); IPedidoDao pedidoDao = new PedidoDaoImpl(); Pedido pedidoRegistrado = pedidoDao.leerPorId(idPedido); nuevaVenta.pedido = pedidoRegistrado; nuevaVenta.materialesNecesarios = pedidoRegistrado.ListaDeMateriales; nuevaVenta.costosExtras = pedidoRegistrado.costosExtras; IProductoDao productoDao = new ProductoDaoImpl(); //agregar lineas de venta foreach (LineaPedido lineaPedido in pedidoRegistrado.lineasDePedido) { int idLineaVenta = 1; int cantidadVenta = lineaPedido.cantidad; Producto producto = productoDao.leerPorId(lineaPedido.producto.IdProducto); LineaVenta lineaVenta = new LineaVenta(cantidadVenta, producto); nuevaVenta.lineasDeVenta.Add(lineaVenta); } //agregar listaMateriales nuevaVenta.materialesNecesarios = pedidoRegistrado.ListaDeMateriales; //agregar listaCostos nuevaVenta.costosExtras = pedidoRegistrado.costosExtras; return(nuevaVenta); }
public ActionResult Edit([Bind(Include = "idLineaVenta,idVenta,idProducto,cantidad,subtotal,precio")] LineaVenta lineaVenta) { if (ModelState.IsValid) { db.Entry(lineaVenta).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idProducto = new SelectList(db.Productoes, "idProducto", "descripcion", lineaVenta.idProducto); ViewBag.idVenta = new SelectList(db.Ventas, "idVenta", "idVenta", lineaVenta.idVenta); return(View(lineaVenta)); }
// GET: LineaVentas/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LineaVenta lineaVenta = db.LineaVentas.Find(id); if (lineaVenta == null) { return(HttpNotFound()); } return(View(lineaVenta)); }
// GET: LineaVentas/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LineaVenta lineaVenta = db.LineaVentas.Find(id); if (lineaVenta == null) { return(HttpNotFound()); } ViewBag.idProducto = new SelectList(db.Productoes, "idProducto", "descripcion", lineaVenta.idProducto); ViewBag.idVenta = new SelectList(db.Ventas, "idVenta", "idVenta", lineaVenta.idVenta); return(View(lineaVenta)); }
//Realizar Pedido private void bt_realizarpedido_tpv_Click(object sender, RoutedEventArgs e) { venta.Fecha = DateTime.Now; venta.EmpleadoId = user.UsuarioId; venta.Empleados = user; clientetpv = unit.RepositorioCliente.ObtenerUno(c => c.Nombre.Equals(cb_clientetpv.Text)); venta.ClienteId = clientetpv.ClienteId; venta.Clientes = clientetpv; venta.LineaVentas = listalineaventas; unit.RepositorioVenta.Crear(venta); CrearFactura(venta); dg_TPV.ItemsSource = ""; venta = new Venta(); lineaventa = new LineaVenta(); listalineaventas = new List <LineaVenta>(); dg_productos.ItemsSource = unit.RepositorioProducto.ObtenerTodo(); }
protected void btnAdd_Click(object sender, EventArgs e) { List <LineaVenta> carrito = new List <LineaVenta>(); LineaVenta nuevaLineaVenta = new LineaVenta(); LineaVenta antiguaLineaVenta = null; Session["state"] = "modified"; try { nuevaLineaVenta.ProductId = int.Parse(this.tbxProduct.Text); nuevaLineaVenta.Quantity = int.Parse(this.tbxQuantity.Text); if (!(Session["myCart"] == null)) { carrito = (List <LineaVenta>)Session["myCart"]; } foreach (LineaVenta lineaVenta in carrito) { if (nuevaLineaVenta.ProductId == lineaVenta.ProductId) { nuevaLineaVenta.Quantity += lineaVenta.Quantity; antiguaLineaVenta = lineaVenta; } } if (nuevaLineaVenta.Quantity < ProductLogic.GetProducto(nuevaLineaVenta.ProductId).UnitsInStock) { if (antiguaLineaVenta != null) { carrito.Remove(antiguaLineaVenta); } carrito.Add(nuevaLineaVenta); Session["myCart"] = carrito; } else { Session["state"] = "inputError"; } Response.Redirect("~/Catalog.aspx"); } catch (FormatException) { Session["state"] = "inputError"; Response.Redirect("/Catalog.aspx"); } }
public void AnadirLineaVenta(Venta pVenta, Articulo pArticulo, int pCantidad)// la venta parametro es a la que se le añade la linea de venta que sera creada con el articulo y la cantidad; por tanto el articulo debe ser comprobado que existe antes de añadirlo. { bool esta = false; foreach (LineaVenta l in pVenta.Lineas) { if (l.Articulo.Equals(pArticulo)) { esta = true; l.Cantidad = l.Cantidad + pCantidad; } } if (!esta) { LineaVenta nLinea = new LineaVenta(pArticulo, pCantidad); pVenta.Lineas.Add(nLinea); } }
//Cancelar Pedido private void bt_cancelarpedido_tpv_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("¿Desea cancelar la venta?", "Cancelar", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { foreach (var item in listalineaventas) { Producto productoaux = item.Productos; productoaux.Stock += item.Cantidad; unit.RepositorioProducto.Actualizar(productoaux); } venta = new Venta(); lineaventa = new LineaVenta(); listalineaventas.Clear(); productoTPV = new Producto(); dg_TPV.ItemsSource = ""; } else { MessageBox.Show("Cancelada eliminacion"); } }
void Load_LineaVenta(string NombreProducto) { lv = new LineaVenta(); lv.Producto = u.ProductoRepository.Get().FirstOrDefault(c => c.Nombre.Equals(NombreProducto)); if (unidades != null) { lv.Unidades = Convert.ToInt32(unidades); } else { unidades = 1.ToString(); lv.Unidades = Convert.ToInt32(unidades); } tv.LineaVenta.Add(lv); total += u.ProductoRepository.Get().FirstOrDefault(c => c.Nombre.Equals(NombreProducto)).Precio *lv.Unidades; txtblock_Total.Text = total.ToString(); unidades = 1.ToString(); txtblock_unidades.Text = unidades.ToString(); RefrescarDatagridLineaVenta(); unidades = null; }
protected void btnBorrar_Click(object sender, EventArgs e) { LineaVenta lineaVentaEliminada = new LineaVenta(); try { int idLinea = int.Parse(tbxLineaVenta.Text.Replace("PageContent_", "")); List <LineaVenta> carrito = (List <LineaVenta>)Session["myCart"]; foreach (LineaVenta lineaVenta in carrito) { if (lineaVenta.ProductId == idLinea) { lineaVentaEliminada = lineaVenta; } } carrito.Remove(lineaVentaEliminada); if (carrito.Count == 0) { Session["myCart"] = null; } else { Session["myCart"] = carrito; } Response.Redirect("~/Cart.aspx"); } catch (NullReferenceException) { Session["state"] = "deleteError"; } catch (FormatException) { Session["state"] = "deleteError"; } finally { Response.Redirect("~/Cart.aspx"); } }
private List <LineaVenta> listarLineaVenta(int id) { LineaVenta pr = null; List <LineaVenta> list = new List <LineaVenta>(); using (ProyectoEntities db = new ProyectoEntities()) { var query = (from p in db.LineaVenta where p.IdV == id select new { ProductoLFC = p.ProductoLV, IdFacturaCompra = p.IdV, CantidadLFC = p.CantidadLV, ImporteLFC = p.ImporteLV, }).ToList(); if (query != null) { foreach (var r in query) { pr = new LineaVenta(); pr.ProductoLV = r.ProductoLFC; pr.IdV = r.IdFacturaCompra; pr.CantidadLV = r.CantidadLFC; pr.ImporteLV = r.ImporteLFC; list.Add(pr); } } } return(list); }
private void ProdBtn_Click(object sender, RoutedEventArgs e) {//Añadir producto al carro //Console.WriteLine("Tooltip: " + (sender as Button).ToolTip.ToString()); Producto p = new Producto(); LineaVenta lv = new LineaVenta(); double descontado = new double(); double precioF = new double(); bool añadido = false; string prod = (sender as Button).ToolTip.ToString(); p = MainWindow.u.ProductosRepository.Single(c => c.nombre.ToUpper() == prod); descontado = p.precio * p.descuento; descontado = descontado / 100; precioF = p.precio - descontado; foreach (LineaVenta l in carro) { if (l.ProductoID == p.ProductoID) {//Si el producto ya ha sido añadido sólo le añade uno a la cantidad, y aumenta el precio total AumentarCant(l, precioF); añadido = true; } } if (!añadido) {//item no está, hay que añadirlo lv.ProductoID = p.ProductoID; lv.Producto = p; lv.Venta = v; lv.cantidad = 1; lv.precioTotal = precioF.ToString(); carro.Add(lv); } Refrescar(); }
private UpdatePuntacion GenerarUpdatePuntoPendiente(int dniDelCliente, Venta venta, LineaVenta detalleDeVenta, string vendedor) { return(new UpdatePuntacion { idventa = detalleDeVenta.IdVenta, idnlinea = detalleDeVenta.IdNLinea, cantidad = detalleDeVenta.Cantidad, precio = (decimal)detalleDeVenta.ImporteNeto, tipoPago = detalleDeVenta.TipoLinea, dni = dniDelCliente.ToString(), trabajador = vendedor, receta = detalleDeVenta.TipoAportacion, dtoLinea = (float)(detalleDeVenta.DescuentoLinea ?? 0), dtoVenta = (float)(detalleDeVenta.DescuentoOpera ?? 0) }); }
//private double CalcularPuntos(string tarjetaDelCliente, string tipoFamilia, double importe, string articuloDescripcion, int articuloCantidad) //{ // var puntos = importe * // (double)(_fisiotes.Familias.GetPuntosByFamiliaTipoVerificado(tipoFamilia)); // var soloPuntosConTarjeta = _fisiotes.Configuraciones.GetByCampo(FIELD_SOLO_PUNTOS_CON_TARJETA); // if (soloPuntosConTarjeta.ToLower() == "si" && string.IsNullOrWhiteSpace(tarjetaDelCliente)) // puntos = 0; // var canjeoPuntos = _fisiotes.Configuraciones.GetByCampo(FIELD_CANJEO_PUNTOS); // if (canjeoPuntos.ToLower() != "si" && articuloDescripcion.Contains("FIDELIZACION")) // puntos = Math.Abs(articuloCantidad) * -1; // return puntos; //} private InsertPuntuacion GenerarPuntoPendienteCargadoPorDefault(int dniDelCliente, Venta venta, LineaVenta detalleDeVenta, Articulo articulo, string vendedor) { var puntos = 0d; var cargado = "si"; var familia = FAMILIA_DEFAULT; var superFamilia = FAMILIA_DEFAULT; var codLaboratorio = string.Empty; var pvp = 0f; var puc = 0f; if (articulo != null) { familia = _farmatic.Familias.GetById(articulo.XFam_IdFamilia)?.Descripcion; if (string.IsNullOrEmpty(familia)) { familia = FAMILIA_DEFAULT; } superFamilia = !familia.Equals(FAMILIA_DEFAULT) ? _farmatic.Familias.GetSuperFamiliaDescripcionByFamilia(familia) ?? FAMILIA_DEFAULT : familia; pvp = (float)articulo.Pvp; puc = (float)articulo.Puc; codLaboratorio = articulo.Laboratorio.Strip() ?? string.Empty; } var redencion = _farmatic.Ventas .GetOneOrDefaultLineaRedencionByKey(detalleDeVenta.IdVenta, detalleDeVenta.IdNLinea)?.Redencion ?? 0; var codigoBarra = _farmatic.Sinonimos .GetOneOrDefaultByArticulo(detalleDeVenta.Codigo)?.Sinonimo.Strip() ?? COD_BARRAS_DEFAULT; var proveedor = _farmatic.Proveedores.GetOneOrDefaultByCodigoNacional(detalleDeVenta.Codigo)?.FIS_NOMBRE.Strip() ?? string.Empty; var laboratorio = Generator.GetNombreLaboratorioFromLocalOrDefault(_farmatic, _consejo, codLaboratorio, LABORATORIO_DEAFULT).Strip(); return(new InsertPuntuacion { idventa = detalleDeVenta.IdVenta, idnlinea = detalleDeVenta.IdNLinea, cod_barras = codigoBarra, cod_nacional = detalleDeVenta.Codigo.Strip(), descripcion = detalleDeVenta.Descripcion.Strip(), familia = familia.Strip(), superFamilia = superFamilia.Strip(), cantidad = detalleDeVenta.Cantidad, precio = (decimal)detalleDeVenta.ImporteNeto, tipoPago = detalleDeVenta.TipoLinea, fecha = venta.FechaHora.ToDateInteger(), dni = dniDelCliente.ToString(), cargado = cargado, puesto = venta.Maquina, trabajador = vendedor, cod_laboratorio = codLaboratorio, laboratorio = laboratorio, proveedor = proveedor, receta = detalleDeVenta.TipoAportacion, fechaVenta = venta.FechaHora, pvp = pvp, puc = puc, puntos = (float)puntos, dtoLinea = (float)(detalleDeVenta.DescuentoLinea ?? 0), dtoVenta = (float)(detalleDeVenta.DescuentoOpera ?? 0), redencion = (float)redencion, recetaPendiente = detalleDeVenta.RecetaPendiente, actualizado = 1 }); }
void AumentarCant(LineaVenta l, double precioF) { l.cantidad++; l.precioTotal = (Convert.ToDouble(l.precioTotal) + Convert.ToDouble(precioF)).ToString(); Refrescar(); }
private bool HayDiferencias(int dni, string vendedor, PuntosPendientes remoto, LineaVenta local) { return (local.Cantidad != remoto.cantidad || dni != remoto.dni.ToIntegerOrDefault() || Math.Round(local.ImporteNeto, 2) != (double)Math.Round(remoto.precio, 2) || Math.Round(local.DescuentoLinea.GetValueOrDefault(), 2) != Math.Round(remoto.dtoLinea.GetValueOrDefault(), 2) || Math.Round(local.DescuentoOpera.GetValueOrDefault(), 2) != Math.Round(remoto.dtoVenta.GetValueOrDefault(), 2) || vendedor.Trim().ToUpper() != remoto.trabajador.Trim().ToUpper() || local.TipoAportacion.Trim().ToUpper() != remoto.receta.Trim().ToUpper()); }
private PuntosPendientes GenerarPuntoPendiente(string puntosDeSisfarma, string cargarPuntos, int dni, string tarjetaDelCliente, double descuentoVenta, Venta venta, LineaVenta linea, string vendedor, FarmaticService farmatic, ConsejoService consejo) { var redencion = (farmatic.Ventas.GetOneOrDefaultLineaRedencionByKey(venta.IdVenta, linea.IdNLinea)? .Redencion) ?? 0; var articulo = farmatic.Articulos.GetOneOrDefaultById(linea.Codigo); var pp = new PuntosPendientes(); pp.idventa = venta.IdVenta; pp.idnlinea = linea.IdNLinea; pp.puntos = 0; pp.puesto = venta.Maquina; pp.tipoPago = linea.TipoLinea; pp.fechaVenta = venta.FechaHora; if (string.IsNullOrEmpty(venta.XClie_IdCliente.Strip()?.Trim()) || string.IsNullOrWhiteSpace(venta.XClie_IdCliente.Strip())) { pp.dni = "0"; } else { pp.dni = venta.XClie_IdCliente.Strip(); } pp.trabajador = vendedor; pp.fecha = Convert.ToInt32(venta.FechaHora.ToString("yyyyMMdd")); pp.recetaPendiente = linea.RecetaPendiente; pp.receta = linea.TipoAportacion; pp.redencion = Convert.ToSingle(redencion); pp.cod_nacional = linea.Codigo; pp.cod_barras = GetCodidoBarrasFromLocalOrDefault(farmatic, linea.Codigo); pp.descripcion = linea.Descripcion.Strip(); pp.pvp = Convert.ToSingle(linea.PVP); pp.dtoVenta = Convert.ToSingle(descuentoVenta); pp.dtoLinea = Convert.ToSingle(linea.DescuentoLinea ?? 0d); pp.precio = Convert.ToDecimal(linea.ImporteNeto); pp.cantidad = linea.Cantidad; pp.cargado = cargarPuntos.ToLower().Equals("si") ? "no" : "si"; if (articulo == null) { pp.laboratorio = "<Sin Laboratorio>"; pp.cod_laboratorio = string.Empty; pp.familia = FAMILIA_DEFAULT; pp.superFamilia = FAMILIA_DEFAULT; pp.proveedor = string.Empty; pp.puc = 0; } else { pp.cod_laboratorio = articulo.Laboratorio.Strip() ?? string.Empty; pp.laboratorio = GetNombreLaboratorioFromLocalOrDefault(farmatic, consejo, pp.cod_laboratorio, "<Sin Laboratorio>"); pp.puc = Convert.ToSingle(articulo.Puc); pp.familia = GetFamiliaFromLocalOrDefault(farmatic, articulo.XFam_IdFamilia, "<Sin Clasificar>"); pp.superFamilia = !pp.familia.Equals("<Sin Clasificar>") ? GetSuperFamiliaFromLocalOrDefault(farmatic, pp.familia, "<Sin Clasificar>").Strip() : pp.familia.Strip(); pp.familia = pp.familia.Strip(); pp.proveedor = GetProveedorFromLocalOrDefault(farmatic, articulo.IdArticu).Strip(); } //var sonpuntosdesisfarma = puntosdesisfarma.tolower().equals("si"); //var fechadeventa = venta.fechahora.date; //var cargado = cargarpuntos.tolower().equals("si"); //if (dni != 0 && // sonpuntosdesisfarma && !cargado && // !string.isnullorwhitespace(_fechadepuntos) && // _fechadepuntos.tolower() != "no" && // fechadeventa >= _fechadepuntos.todatetimeordefault("yyyymmdd")) //{ // var tipofamilia = pp.familia != familia_default ? pp.familia : pp.superfamilia; // var importe = linea.importeneto; // var articulodescripcion = articulo?.descripcion ?? string.empty; // var articulocantidad = linea.cantidad; // pp.puntos = (float)calcularpuntos(tarjetadelcliente, tipofamilia, importe, articulodescripcion, articulocantidad); //} //else if (dni != 0 && _fechadepuntos.tolower() != "no") // pp.cargado = "no"; return(pp); }