private void saveProducto(Eproductos item, ref ETransactionResult res) { Daproductos db = new Daproductos(); db.productos_Insert(item, ref res); if (res.result == 0) { EMovimiento mov = new EMovimiento(); EMovimientoDetalle detalle = new EMovimientoDetalle(); ETransactionResult result = new ETransactionResult(); int idDetalle = 0; decimal totalCantidad = 0; mov.fecha = DateTime.Now; mov.idMovimiento = (int)getIdMovimiento(); mov.idTipoMovimiento = "EPT"; mov.usuario = "admin"; totalCantidad = item.cantidad; idDetalle = (int)getIdMovimientoDet(); detalle.idDetalle = idDetalle; detalle.idMovimiento = mov.idMovimiento; detalle.tipoAfectacion = "E"; detalle.idProducto = item.idProducto; detalle.cantidad = totalCantidad; _movimiento.Movimiento_Insert(mov, ref result); if (result.result == 0) { _movimientoDetalle.MovimientoDetalle_Insert(detalle, ref result); } } }
private void rollbackVenta(List <Eproductos> productos, int idTicket, int idMovimiento) { ETransactionResult result = new ETransactionResult(); Daticket daTicket = new Daticket(); Daproductos daProductos = new Daproductos(); daTicket.ticket_RollBack(idTicket, idMovimiento, ref result); foreach (Eproductos item in productos) { daProductos.productos_Update(item, ref result); } }
public void CancelaVenta(Eticket ticket, ref ETransactionResult result) { List <EdetalleTicket> det = new List <EdetalleTicket>(); DadetalleTicket db = new DadetalleTicket(); Daticket dbTicket = new Daticket(); Daproductos _prod = new Daproductos(); det = db.detalleTicket_GetByIdTicket(ticket, ref result); EMovimiento mov = new EMovimiento(); List <EMovimientoDetalle> movdet = new List <EMovimientoDetalle>(); int idDetalle = 0; mov.fecha = DateTime.Now; mov.idMovimiento = (int)getIdMovimiento(); mov.idTipoMovimiento = "DEV"; mov.observacion = ""; mov.usuario = ticket.usuario; idDetalle = (int)getIdMovimientoDetalle(); foreach (EdetalleTicket item in det) { EMovimientoDetalle detalle = new EMovimientoDetalle(); detalle.idDetalle = idDetalle; detalle.idMovimiento = mov.idMovimiento; detalle.tipoAfectacion = "E"; detalle.idProducto = item.idProducto; detalle.cantidad = item.cantidad; idDetalle += 1; movdet.Add(detalle); } saveMovimiento(mov, ref result); saveDetalleMov(movdet, ref result); dbTicket.ticket_Update(ticket, ref result); }
public void Update(object obj, ref ETransactionResult result) { Daproductos daLista = new Daproductos(); daLista.productos_Update((Eproductos)obj, ref result); }
public object Insert(object obj, ref ETransactionResult result) { Daproductos daLista = new Daproductos(); return((Eproductos)daLista.productos_Insert((Eproductos)obj, ref result)); }
public List <object> GetAll(ref ETransactionResult result) { Daproductos daLista = new Daproductos(); return(daLista.productos_GetAll(ref result).ToList <object>()); }
public bool SetVenta(List <ETicketVenta> venta, string usr, ref ETransactionResult result) { bool res = true; EMovimiento mov = new EMovimiento(); Daproductos _prod = new Daproductos(); List <EMovimientoDetalle> movdet = new List <EMovimientoDetalle>(); int idDetalle = 0; mov.fecha = DateTime.Now; mov.idMovimiento = (int)getIdMovimiento(); mov.idTipoMovimiento = "VTA"; mov.observacion = ""; mov.usuario = usr; idDetalle = (int)getIdMovimientoDetalle(); foreach (ETicketVenta det in venta) { EMovimientoDetalle detalle = new EMovimientoDetalle(); detalle.idDetalle = idDetalle; detalle.idMovimiento = mov.idMovimiento; detalle.tipoAfectacion = "S"; detalle.idProducto = det.Producto; detalle.cantidad = det.Cantidad; idDetalle += 1; movdet.Add(detalle); } var prods = _prod.productos_GetAll(ref result).Cast <Eproductos>().ToList(); var invInsuficiente = movdet.Join(prods, _mov => _mov.idProducto, _prods => _prods.idProducto, (_mov, _prods) => new { Cantidad = _prods.cantidad - _mov.cantidad }).Where( x => x.Cantidad < 0).ToList().Count; if (invInsuficiente > 0) { result.result = -1; result.message = "No se puede vender mas producto que el existente."; return(false); } Eticket ticket = new Eticket(); List <EdetalleTicket> detTic = new List <EdetalleTicket>(); ticket.idTicket = (int)getIdTicket(); ticket.usuario = usr; ticket.fecha = DateTime.Now; ticket.total = venta.Sum(p => p.Total); ticket.observacion = ""; ticket.cancelado = false; idDetalle = (int)getIdTicketDet(); foreach (ETicketVenta det in venta) { EdetalleTicket detalle = new EdetalleTicket(); detalle.idDetalle = idDetalle; detalle.idTicket = ticket.idTicket; detalle.fecha = DateTime.Now; detalle.idProducto = det.Producto; detalle.cantidad = det.Cantidad; detalle.precio = det.Precio; detalle.total = det.Total; idDetalle += 1; detTic.Add(detalle); } var _productos = _prod.productos_GetAll(ref result); _productos = _productos.Join(movdet, x => x.idProducto, y => y.idProducto, (x, y) => x).ToList(); if (saveTicket(ticket, ref result)) { if (saveDetalleTicket(detTic, ref result)) { if (saveMovimiento(mov, ref result)) { if (!saveDetalleMov(movdet, ref result)) { rollbackVenta(_productos, ticket.idTicket, mov.idMovimiento); } else { res = true; } } else { rollbackVenta(_productos, ticket.idTicket, mov.idMovimiento); } } else { rollbackVenta(_productos, ticket.idTicket, mov.idMovimiento); } } else { rollbackVenta(_productos, ticket.idTicket, mov.idMovimiento); } return(res); }
public void SetProductos(string directorio, ref ETransactionResult res) { res = new ETransactionResult(); List <Eproductos> prods = new List <Eproductos>(); try { using (var reader = new StreamReader(directorio)) using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) { prods = csv.GetRecords <Eproductos>().ToList(); } Daproductos db = new Daproductos(); var prod = db.productos_GetAll(ref res).Cast <Eproductos>().ToList(); int maxId = 0; if (prod.Count != 0) { maxId = prod.Select(x => x.idProducto).Max(); } int codigoProducto = maxId + 1; bool bandera = false; StringBuilder mensaje = new StringBuilder(); foreach (Eproductos item in prods) { item.idProducto = codigoProducto; codigoProducto++; } foreach (Eproductos item in prods) { res = new ETransactionResult(); saveProducto(item, ref res); if (res.result == 1) { bandera = true; mensaje.Append("\n No se pudo guardar el producto " + item.descripcion + " :" + res.message); } } res = new ETransactionResult(); if (!string.IsNullOrEmpty(mensaje.ToString())) { res.result = 1; res.message = mensaje.ToString(); } } catch (Exception ex) { res.result = 1; res.message = ex.Message; } }