private void ajustarEntradasYsalidas(int ajuste) { if (AccesoInternet() == false) { MessageBox.Show("No hay internet, intente en un momento"); return; } int stockActual = productoSeleccionadoi.STOCK; if (stockActual != ajuste) { if (stockActual > ajuste) { int diferencia = stockActual - ajuste; osa_gral og = new osa_gral(); osa_indiv oi = new osa_indiv(); og.Id = og.NextID(); og.ID_CLIENTE = 0; og.FECHA = DateTime.Now.Date; oi.Id = oi.NextID(); oi.ID_OSAGRAL = og.Id; oi.ID_PRODUCTO2 = productoSeleccionadoi.Id; oi.QTY2 = diferencia; oi.precioAlmacen = productoSeleccionadoi.PrecioAlmacen; oi.totalItem = oi.precioAlmacen * oi.QTY2; #region LOOP SALIDAS INVETNARIOCOSTOS inventariocostos invCost = new inventariocostos(oi.ID_PRODUCTO2, "Salida"); if (invCost.Id > 0) { if (oi.QTY2 <= invCost.cantidad_actual) { invCost.cantidad_actual -= oi.QTY2; invCost.Update("Id"); } else { int Qty = oi.QTY2; Qty -= invCost.cantidad_actual; invCost.cantidad_actual = 0; invCost.Update("Id"); while (Qty > 0) { inventariocostos invCost2 = new inventariocostos(oi.ID_PRODUCTO2, "Salida2"); if (invCost2.Id > 0) { if (Qty <= invCost2.cantidad_actual) { invCost2.cantidad_actual -= Qty; invCost2.Update("Id"); Qty = 0; } else { Qty -= invCost2.cantidad_actual; invCost2.cantidad_actual = 0; invCost2.Update("Id"); } } else { MessageBox.Show("No hay entradas registradas para esta salida"); Qty = 0; } } } } else { MessageBox.Show("Este producto no tiene Facturas de compra, Favor de ingresarlas antes de Sacar el Producto"); } #endregion LOOP SALIDAS INVETNARIOCOSTOS generalok: og.Id = og.NextID(); og.Insert(); if (og.Error != "") { goto generalok; } individualok: oi.Id = oi.NextID(); oi.ID_OSAGRAL = og.Id; oi.Insert(); if (oi.Error != "") { goto individualok; } } else { int diferencia = ajuste - stockActual; oen_gral og = new oen_gral(); oen_indiv oi = new oen_indiv(); og.Id = og.NextID(); og.ID_PROVEEDOR = 0; og.FECHA = DateTime.Now; oi.Id = oi.NextID(); oi.ID_OENGRAL = og.Id; oi.ID_PRODUCTO = productoSeleccionadoi.Id; oi.QTY = diferencia; generalok: og.Id = og.NextID(); og.Insert(); if (og.Error != "") { goto generalok; } individualok: oi.Id = oi.NextID(); oi.ID_OENGRAL = og.Id; oi.Insert(); if (oi.Error != "") { goto individualok; } } } }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } if (dataGridView1.Rows[e.RowIndex].Cells[1].Value == DBNull.Value) { return; } int rowIndex = e.RowIndex; int item = Convert.ToInt32(dataGridView1.Rows[rowIndex].Cells[0].Value); string catalogo = dataGridView1.Rows[rowIndex].Cells[1].Value.ToString(); osa_indiv i = new osa_indiv(item, osaSeleccionada.Id); productos p = new productos(i.ID_PRODUCTO2); inventariocostos invCost = new inventariocostos(i.ID_PRODUCTO2, true); FormDevolucion d = new FormDevolucion(); d.labelProducto.Text = "OSA no. " + osaSeleccionada.Id + ", ITEM: " + item + ", CATALOGO: " + catalogo; d.textBoxExistencia.Text = i.QTY2.ToString(); d.existencia = i.QTY2; d.stock = p.STOCK; d.ShowDialog(); if (d.DialogResult == DialogResult.OK) { if (d.existencia < i.QTY2) { #region WHILE DEVOLVER A iNVENTARIOCOSTOS if (invCost.Id > 0) { int diferenciaOen = invCost.cantidad_oen - invCost.cantidad_actual; int restaOsa = i.QTY2 - d.existencia; if (restaOsa <= diferenciaOen) { invCost.cantidad_actual += restaOsa; invCost.Update("Id"); } else { int qty = restaOsa; invCost.cantidad_actual += diferenciaOen; invCost.Update("Id"); qty -= diferenciaOen; while (qty > 0) { inventariocostos invCost2 = new inventariocostos(i.ID_PRODUCTO2, true); if (invCost2.Id > 0) { int restaOen = invCost2.cantidad_oen - invCost2.cantidad_actual; if (qty <= restaOen) { invCost2.cantidad_actual += qty; invCost2.Update("Id"); qty = 0; } else { invCost2.cantidad_actual += restaOen; invCost2.Update("Id"); qty -= restaOen; } } else { MessageBox.Show("No hay ordenes de entrada para este producto"); qty = 0; } } } } else { MessageBox.Show("No hay ordenes de entrada para estos productos"); } #endregion WHILE DEVOLVER A INVENTARIOcOSTOS i.QTY2 = d.existencia; p.STOCK = d.stock; i.Update("Id"); p.Update("Id"); MessageBox.Show("Devolucion aplicada"); VerDGV(osaSeleccionada.Id); foreach (DataGridViewRow fila in dataGridView1.Rows) { string cantidad = fila.Cells[2].ToString(); string cat = fila.Cells[1].ToString(); } } } if (osaSeleccionada.idpoliza > 0) { double tot = 0; foreach (DataGridViewRow fila in dataGridView1.Rows) { if (fila.Cells[3].Value != null) { string cantidad = fila.Cells[3].Value.ToString(); catalogo = fila.Cells[1].Value.ToString(); item = Convert.ToInt32(dataGridView1.Rows[fila.Index].Cells[0].Value); i = new osa_indiv(item, osaSeleccionada.Id); p = new productos(i.ID_PRODUCTO2); tot += Convert.ToInt32(cantidad) * p.PrecioAlmacen; } } polizasdb pol = new polizasdb(osaSeleccionada.idpoliza); pol.subtotal = tot; pol.egreso = tot; pol.Update("folio"); } }