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); } } }
public EMovimientoDetalle MovimientoDetalle_Update(EMovimientoDetalle item, ref ETransactionResult _transResult) { EMovimientoDetalle itemUpdated = null; _transResult = new ETransactionResult(); SqlTransaction transaction = null; try { using (SqlConnection sqlCon = new SqlConnection(conn)) { sqlCon.Open(); using (SqlCommand sqlCmd = new SqlCommand()) { transaction = sqlCon.BeginTransaction("UpdateTransaction"); sqlCmd.Transaction = transaction; sqlCmd.Connection = sqlCon; sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.CommandText = "D_PR_MovimientoDetalle_Update"; sqlCmd.Parameters.AddWithValue("@idDetalle", item.idDetalle); sqlCmd.Parameters.AddWithValue("@idMovimiento", item.idMovimiento); sqlCmd.Parameters.AddWithValue("@idProducto", item.idProducto); sqlCmd.Parameters.AddWithValue("@cantidad", item.cantidad); sqlCmd.Parameters.AddWithValue("@tipoAfectacion", item.tipoAfectacion); using (var reader = sqlCmd.ExecuteReader()) { while (reader.Read()) { itemUpdated = new EMovimientoDetalle(); itemUpdated.idDetalle = (int)reader["idDetalle"]; itemUpdated.idMovimiento = (int)reader["idMovimiento"]; itemUpdated.idProducto = (int)reader["idProducto"]; itemUpdated.cantidad = (decimal)reader["cantidad"]; itemUpdated.tipoAfectacion = (string)reader["tipoAfectacion"]; } } transaction.Commit(); _transResult.message = "OK"; _transResult.result = 0; } } } catch (Exception ex) { _transResult.message = ex.Message; _transResult.result = 1; try { transaction.Rollback(); } catch (Exception rollBackEx) { _transResult.rollbackMessage = rollBackEx.Message; _transResult.result = 1; } } return(itemUpdated); }
public List <EMovimientoDetalle> MovimientoDetalle_GetAll(ref ETransactionResult _transResult) { var list = new List <EMovimientoDetalle>(); _transResult = new ETransactionResult(); SqlTransaction transaction = null; try { using (SqlConnection sqlCon = new SqlConnection(conn)) { sqlCon.Open(); using (SqlCommand sqlCmd = new SqlCommand()) { transaction = sqlCon.BeginTransaction("SelectAllTranstaction"); sqlCmd.Transaction = transaction; sqlCmd.Connection = sqlCon; sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.CommandText = "D_PR_MovimientoDetalle_SelectAll"; using (var reader = sqlCmd.ExecuteReader()) while (reader.Read()) { var item = new EMovimientoDetalle(); item.idDetalle = (int)reader["idDetalle"]; item.idMovimiento = (int)reader["idMovimiento"]; item.idProducto = (int)reader["idProducto"]; item.cantidad = (decimal)reader["cantidad"]; item.tipoAfectacion = (string)reader["tipoAfectacion"]; list.Add(item); } transaction.Commit(); _transResult.message = "OK"; _transResult.result = 0; } } } catch (Exception ex) { _transResult.message = ex.Message; _transResult.result = 1; try { transaction.Rollback(); } catch (Exception rollBackEx) { _transResult.rollbackMessage = rollBackEx.Message; _transResult.result = 1; } } return(list); }
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 MovimientoDetalle_Delete(EMovimientoDetalle item, ref ETransactionResult _transResult) { _transResult = new ETransactionResult(); SqlTransaction transaction = null; try { using (SqlConnection sqlCon = new SqlConnection(conn)) { sqlCon.Open(); using (SqlCommand sqlCmd = new SqlCommand()) { transaction = sqlCon.BeginTransaction("DeleteTransaction"); sqlCmd.Transaction = transaction; sqlCmd.Connection = sqlCon; sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.CommandText = "D_PR_MovimientoDetalle_Delete"; sqlCmd.Parameters.AddWithValue("@idDetalle", item.idDetalle); sqlCmd.ExecuteNonQuery(); transaction.Commit(); _transResult.message = "OK"; _transResult.result = 0; } } } catch (Exception ex) { _transResult.message = ex.Message; _transResult.result = 1; try { transaction.Rollback(); } catch (Exception rollBackEx) { _transResult.rollbackMessage = rollBackEx.Message; _transResult.result = 1; } } }
private void setMovimiento(Eproductos item) { 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 = usuario; mov.observacion = ""; totalCantidad = item.cantidad; idDetalle = (int)getIdMovimientoDet(); detalle.idDetalle = idDetalle; detalle.idMovimiento = mov.idMovimiento; detalle.tipoAfectacion = (totalCantidad < 0 ? "S" : "E"); detalle.idProducto = item.idProducto; detalle.cantidad = Math.Abs(totalCantidad); _movimiento.Insert(mov, ref result); if (result.result == 0) { _movimientoDetalle.Insert(detalle, ref result); if (result.result != 0) { Log.Error("Error al insertar detalle movimiento: " + result.message); } } else { Log.Error("Error al insertar movimiento: " + result.message); } }
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); }