public Decimal guardarCierreInventario(DateTime FECHA_INICIO, DateTime FECHA_FIN) { Decimal idCierre = 0; Decimal idDetalle = 0; int idCierreActivo = 0; DataTable tablaCierres = new DataTable(); Boolean correcto = true; bool ejecuta; Conexion _dates = new Conexion(Empresa); _dates.IniciarTransaccion(); try { if (FECHA_INICIO < FECHA_FIN) { MensajeError = null; tablaCierres = ObtenerInvCierreTodos(_dates); if (MensajeError != null) { correcto = false; ejecuta = false; _dates.DeshacerTransaccion(); } else { if (tablaCierres.Rows.Count == 0) { if (FECHA_FIN <= System.DateTime.Today) { ejecuta = true; } else { ejecuta = false; correcto = false; _dates.DeshacerTransaccion(); MensajeError += "La fecha final no debe ser mayor a la fecha de hoy. Valide por favor"; } } else { DataRow filaCierres = tablaCierres.Rows[0]; DateTime FECHA_CORTE = Convert.ToDateTime(filaCierres["FECHA_CORTE"].ToString()); idCierreActivo = Convert.ToInt32(filaCierres["ID_CIERRE"].ToString()); if (FECHA_INICIO > FECHA_CORTE) { if (FECHA_FIN <= System.DateTime.Today) { ejecuta = true; } else { ejecuta = false; correcto = false; _dates.DeshacerTransaccion(); MensajeError += "La fecha final no debe ser mayor a la fecha de hoy. Valide por favor"; } } else { MensajeError = "ADVERTENCIA: La fecha de inicio está contenida en el último cierre. Valide por favor."; ejecuta = false; correcto = false; _dates.DeshacerTransaccion(); } } } } else { MensajeError += "La fecha de fin debe ser mayor que la fecha de inicio. Valide por favor."; correcto = false; ejecuta = false; _dates.DeshacerTransaccion(); } if (ejecuta) { Inventario _inventario = new Inventario(Empresa, Usuario); DataTable tablaInventario = _inventario.ObtenerAlmInventarioPorPeriodo(FECHA_INICIO, FECHA_FIN, _dates); if (_inventario.MensajeError != null) { ejecuta = false; correcto = false; MensajeError = _inventario.MensajeError; _dates.DeshacerTransaccion(); } else { DataTable tablaCierre = new DataTable(); tablaCierre.Columns.Add("ID_PRODUCTO", typeof(Decimal)); tablaCierre.Columns.Add("ID_BODEGA", typeof(Decimal)); tablaCierre.Columns.Add("TALLA", typeof(String)); tablaCierre.Columns.Add("CANTIDAD", typeof(Int32)); tablaCierre.Columns.Add("COSTO", typeof(Decimal)); if (idCierreActivo != 0) { DataTable tablaDetalles = ObtenerInvDetalleCierrePorIdCierre(idCierreActivo, _dates); foreach (DataRow filac in tablaDetalles.Rows) { DataRow filan = tablaCierre.NewRow(); filan["ID_PRODUCTO"] = Convert.ToDecimal(filac["ID_PRODUCTO"]); filan["ID_BODEGA"] = Convert.ToDecimal(filac["ID_BODEGA"]); filan["TALLA"] = filac["TALLA"]; filan["CANTIDAD"] = Convert.ToInt32(filac["CANTIDAD_INVENTARIO"]); filan["COSTO"] = Convert.ToDecimal(filac["COSTO_PROMEDIO"]); tablaCierre.Rows.Add(filan); } } DataRow filam; usuario _usuario = new usuario(Empresa); DataTable tablaUsuario = _usuario.ObtenerUsuarioPorUsuLog(Usuario, _dates); if (_usuario.MensajeError != null) { ejecuta = false; correcto = false; MensajeError = _usuario.MensajeError; _dates.DeshacerTransaccion(); } else { DataRow filaUsuario = tablaUsuario.Rows[0]; /* * ES MUY IMPORTANTE ESTO, * EN LA UTLIMA REUNION SE DECLARO QUE EL BOTON DE CIERRE FISICO NO SERVIA * POR LO TANTO AUTOMATICAMENTE EL ACREAR EL CIERRE DE UNA LO DEJAMOS EN ESTADO 'ACTIVO', * ANTES SE GUARDABA EN ESTADO 'ABIERTO' */ idCierre = AdicionarInvCierre(Convert.ToInt32(filaUsuario["ID_USUARIO"]), System.DateTime.Today, FECHA_FIN, FECHA_INICIO, "", "ACTIVO", _dates); if (idCierre != 0) { foreach (DataRow fila in tablaInventario.Rows) { if (tablaCierre.Rows.Count <= 0) { filam = tablaCierre.NewRow(); filam["ID_PRODUCTO"] = fila["ID_PRODUCTO"]; filam["ID_BODEGA"] = fila["ID_BODEGA"]; filam["TALLA"] = fila["TALLA"]; if (fila["MOVIMIENTO"].Equals("ENTRADA")) { filam["CANTIDAD"] = Convert.ToInt32(fila["CANTIDAD"]); filam["COSTO"] = Convert.ToDecimal(fila["COSTO"]); } else if (fila["MOVIMIENTO"].Equals("SALIDA")) { filam["CANTIDAD"] = -Convert.ToInt32(fila["CANTIDAD"]); filam["COSTO"] = 1; } tablaCierre.Rows.Add(filam); } else { DataRow[] filasCoinciden = tablaCierre.Select("ID_PRODUCTO = '" + fila["ID_PRODUCTO"].ToString() + "' AND ID_BODEGA = '" + fila["ID_BODEGA"].ToString() + "' AND TALLA = '" + fila["TALLA"].ToString() + "' AND COSTO = '" + fila["COSTO"].ToString() + "'"); if (filasCoinciden.Length <= 0) { filam = tablaCierre.NewRow(); filam["ID_PRODUCTO"] = fila["ID_PRODUCTO"]; filam["ID_BODEGA"] = fila["ID_BODEGA"]; filam["TALLA"] = fila["TALLA"]; if (fila["MOVIMIENTO"].Equals("ENTRADA")) { filam["CANTIDAD"] = Convert.ToInt32(fila["CANTIDAD"]); filam["COSTO"] = Convert.ToDecimal(fila["COSTO"]); } else if (fila["MOVIMIENTO"].Equals("SALIDA")) { filam["CANTIDAD"] = -Convert.ToInt32(fila["CANTIDAD"]); filam["COSTO"] = 1; } tablaCierre.Rows.Add(filam); } else { DataRow filaCoincide = filasCoinciden[0]; Decimal costoN = 0; Int32 cantidadN = 0; Decimal CostoA = 0; Int32 cantidadA = 0; if (!(String.IsNullOrEmpty(fila["CANTIDAD"].ToString()))) { cantidadN = Convert.ToInt32(fila["CANTIDAD"]); } if (!(String.IsNullOrEmpty(fila["COSTO"].ToString()))) { costoN = Convert.ToDecimal(fila["COSTO"]); } if (!(String.IsNullOrEmpty(filaCoincide["CANTIDAD"].ToString()))) { cantidadA = Convert.ToInt32(filaCoincide["CANTIDAD"]); } if (!(String.IsNullOrEmpty(filaCoincide["COSTO"].ToString()))) { CostoA = Convert.ToDecimal(filaCoincide["COSTO"]); } if (fila["MOVIMIENTO"].Equals("ENTRADA")) { filaCoincide["CANTIDAD"] = cantidadA + cantidadN; if (cantidadA < 0) { cantidadA = cantidadA * (-1); } if (cantidadN < 0) { cantidadN = cantidadN * (-1); } filaCoincide["COSTO"] = (((cantidadA * CostoA) + (cantidadN * costoN)) / (cantidadA + cantidadN)); } else if (fila["MOVIMIENTO"].Equals("SALIDA")) { filaCoincide["CANTIDAD"] = cantidadA - cantidadN; } } } } if (correcto == true) { int x = 0; if (tablaCierre.Rows.Count != 0) { foreach (DataRow filax in tablaCierre.Rows) { Decimal costo = 0; if (!(String.IsNullOrEmpty(filax["COSTO"].ToString()))) { costo = Convert.ToDecimal(filax["COSTO"]); } /* * ACA TAMBIEN ES IMPORTANTE ACLARAR * QUE DESPUES DE LA ULTIMA REUNION EL BOTON DE CIERRE FISICO SE DEBIA QUITAR * ENTONCES LOS DETALLES DEL CIERRE DE UNA VEZ SE DEJAN EN ESTADO 'COMPLETADO' * ADEMAS EL VALOR DE LA CANTIDAD FISICA SE DEJA IGUAL QUE LA CANTIDAD INVENTARIO * ANTES SE CREABA EL REGISTRO EN ESTADO 'ABIERTO' Y LA CANTIDAD FISICA EN CERO * PARA QUE DESPUES POR CIERRE FISICO SE VALIDARA DICHA CANTIDAD * */ idDetalle = AdicionarInvDetalleCierre(Convert.ToInt32(idCierre), Convert.ToInt32(filax["ID_PRODUCTO"]), Convert.ToInt32(filax["CANTIDAD"]), Convert.ToInt32(filax["CANTIDAD"]), Convert.ToInt32(filax["ID_BODEGA"]), filax["TALLA"].ToString(), costo, "COMPLETADO", _dates); if (idDetalle != 0) { x++; } else { _dates.DeshacerTransaccion(); correcto = false; ejecuta = false; idCierre = 0; break; } } } else { MensajeError += "No hay detalles en el cierre."; idCierre = 0; correcto = false; ejecuta = false; _dates.DeshacerTransaccion(); } } } else { _dates.DeshacerTransaccion(); correcto = false; ejecuta = false; idCierre = 0; } } } } if (correcto == true) { _dates.AceptarTransaccion(); } } catch (Exception ex) { MensajeError = ex.Message; correcto = false; ejecuta = false; _dates.DeshacerTransaccion(); } finally { _dates.Desconectar(); } if (correcto == true) { return idCierre; } else { return 0; } }
public Decimal guardarDevolucion(List<int> ID_LOTE, int ID_BODEGA, int ID_EMPLEADO, List<int> ID_DOCUMENTO, List<int> ID_INVENTARIO, List<int> ID_PRODUCTO, List<int> cantidad, List<String> Estado, List<String> motivo, List<Decimal> ID_DETALLE_ENTREGAS, List<EquipoEntrega> listaEquiposDevueltos) { Decimal idDocumento = 0; Decimal idInventario = 0; Decimal idLote = 0; DateTime fecha = System.DateTime.Today; documento _doc = new documento(Empresa, Usuario); Inventario _inventario = new Inventario(Empresa, Usuario); Conexion _dato = new Conexion(Empresa); lote _lote = new lote(Empresa, Usuario); int cuenta = 0; Boolean correcto = true; _dato.IniciarTransaccion(); try { idDocumento = _doc.AdicionarAlmDocumentos(ID_EMPLEADO, 0, "DEVOLUCION", "", "", fecha, new DateTime(), 0, 0, 0, "", "", _dato, 0, null); if (idDocumento == 0) { correcto = false; MensajeError = _doc.MensajeError; _dato.DeshacerTransaccion(); } else { for (int i = 0; i < ID_PRODUCTO.Count; i++) { _lote.MensajeError = null; DataTable tablalote = _lote.ObtenerAlmLotePorId(ID_LOTE[i], _dato); if (_lote.MensajeError != null) { correcto = false; _dato.DeshacerTransaccion(); MensajeError = _lote.MensajeError; break; } else { DataRow filalote = tablalote.Rows[0]; String activoLote = "S"; if (Estado[i] != "BUENO") { activoLote = "N"; } idLote = _lote.AdicionarAlmLote(ID_DOCUMENTO[i], ID_PRODUCTO[i], Convert.ToInt32(filalote["ID_BODEGA"]), Convert.ToDateTime(DateTime.Now.ToShortDateString()), cantidad[i], 0, Convert.ToDecimal(filalote["COSTO"]), filalote["TALLA"].ToString().Trim(), activoLote, _dato, filalote["REEMBOLSO"].ToString()); if (idLote == 0) { correcto = false; MensajeError = _lote.MensajeError; _dato.DeshacerTransaccion(); break; } else { _inventario.MensajeError = null; idInventario = _inventario.AdicionarAlmInventario(Convert.ToInt32(idDocumento), ID_PRODUCTO[i], Convert.ToInt32(filalote["ID_BODEGA"]), cantidad[i], Convert.ToDecimal(filalote["COSTO"]), Convert.ToDateTime(DateTime.Now.ToShortDateString()), "ENTRADA", _dato, Convert.ToInt32(idLote), filalote["TALLA"].ToString(), 0, ID_DETALLE_ENTREGAS[i], motivo[i], filalote["REEMBOLSO"].ToString()); if (idInventario <= 0) { correcto = false; MensajeError = _inventario.MensajeError; _dato.DeshacerTransaccion(); break; } else { cuenta++; } } } } if (correcto == true) { foreach (EquipoEntrega equipo in listaEquiposDevueltos) { _lote.MensajeError = null; DataTable tablalote = _lote.ObtenerAlmLotePorId(Convert.ToInt32(equipo.ID_LOTE), _dato); if (_lote.MensajeError != null) { correcto = false; _dato.DeshacerTransaccion(); MensajeError = _lote.MensajeError; break; } else { DataRow filalote = tablalote.Rows[0]; String activoLote = "S"; if (equipo.ESTADO_DEV != "BUENO") { activoLote = "N"; } idLote = _lote.AdicionarAlmLote(Convert.ToInt32(equipo.ID_DOCUMENTO), Convert.ToInt32(equipo.ID_PRODUCTO), Convert.ToInt32(filalote["ID_BODEGA"]), Convert.ToDateTime(DateTime.Now.ToShortDateString()), 1, 0, Convert.ToDecimal(filalote["COSTO"]), filalote["TALLA"].ToString().Trim(), activoLote, _dato, filalote["REEMBOLSO"].ToString()); if (idLote == 0) { correcto = false; MensajeError = _lote.MensajeError; _dato.DeshacerTransaccion(); break; } else { _inventario.MensajeError = null; idInventario = _inventario.AdicionarAlmInventario(Convert.ToInt32(idDocumento), Convert.ToInt32(equipo.ID_PRODUCTO), Convert.ToInt32(filalote["ID_BODEGA"]), 1, Convert.ToDecimal(filalote["COSTO"]), Convert.ToDateTime(DateTime.Now.ToShortDateString()), "ENTRADA", _dato, Convert.ToInt32(idLote), filalote["TALLA"].ToString(), Convert.ToInt32(equipo.ID_EQUIPO), equipo.ID_DETALLE_ENTREGAS, equipo.DETALLE_DEV, filalote["REEMBOLSO"].ToString()); if (idInventario <= 0) { correcto = false; MensajeError = _inventario.MensajeError; _dato.DeshacerTransaccion(); break; } else { Entrega _entrega = new Entrega(Empresa, Usuario); if (_entrega.ActualizarAlmEquiposEntregaDevolucion(equipo.ID_EQUIPO_ENTREGA, equipo.ID_EQUIPO, idLote, idDocumento, equipo.ESTADO_DEV, equipo.DETALLE_DEV, _dato) == false) { correcto = false; MensajeError = _entrega.MensajeError; _dato.DeshacerTransaccion(); break; } else { cuenta++; } } } } } } if (correcto == true) { if (cuenta != (ID_PRODUCTO.Count + listaEquiposDevueltos.Count)) { correcto = false; _dato.DeshacerTransaccion(); MensajeError = "Ocurrio un error inesperado, el numero de productos y equipos procesados no corresponde."; } } } if (correcto == true) { _dato.AceptarTransaccion(); } } catch (Exception ex) { _dato.DeshacerTransaccion(); MensajeError = ex.Message; correcto = false; } finally { _dato.Desconectar(); } if (correcto == true) { return idDocumento; } else { return 0; } }
public String adicionarEntregas(int idempleado, DateTime fecha, int idBodega, DataTable tablaConfigurados, DataTable tablalotes, String[] datos, String faltantes) { int NumerosEntregas = 0; Decimal idDocumento = 0; Decimal idOrdenEntrega = 0; AsignacionServiciosComplementarios _OrdenEntrega = new AsignacionServiciosComplementarios(Empresa, Usuario); Brainsbits.LLB.almacen.documento _documento = new almacen.documento(Empresa, Usuario); Inventario _inventario = new Inventario(Empresa, Usuario); Conexion _dato = new LDA.Conexion(Empresa); _dato.IniciarTransaccion(); #region validaciones foreach (DataRow filaConf in tablaConfigurados.Rows) { foreach (DataRow filaLote in tablalotes.Rows) { if (filaConf["ID_PRODUCTO"].Equals(filaLote["ID_PRODUCTO"]) & filaConf["TALLA"].Equals(filaLote["TALLA"]) & Convert.ToInt32(filaConf["CANTIDAD_A_ENTREGAR"]) > Convert.ToInt32(filaLote["CANTIDAD_CONFIGURADA"])) { MensajeError += "La cantidad que se desea entregar es superior a la cantidad que se debe entregar. Valide por favor"; } else { idDocumento = _documento.AdicionarAlmDocumentos(idempleado, 0, "ENTREGA", "", "", fecha, new DateTime(), 0, 0, 0, "", "", _dato, 0, null); if (idDocumento == 0) { _dato.DeshacerTransaccion(); MensajeError += "ADVERTENCIA: No fue posible crear el documento, por la siguiente razón \n" + _documento.MensajeError + " \ncomuniquese con el administrador"; } else { idOrdenEntrega = _OrdenEntrega.AdicionarAsignacionServiciosComplementarios(Convert.ToInt32(idDocumento), idempleado, fecha, "", _dato); if (idOrdenEntrega == 0) { _dato.DeshacerTransaccion(); MensajeError += "ADVERTENCIA: No fue posible crear el documento de Orden de Entrega, por la siguiente razón \n" + _OrdenEntrega.MensajeError + " \ncomuniquese con el administrador"; } else { if (filaConf["ID_PRODUCTO"].Equals(filaLote["ID_PRODUCTO"]) & filaConf["TALLA"].Equals(filaLote["TALLA"]) & Convert.ToInt32(filaConf["CANTIDAD_A_ENTREGAR"]) <= Convert.ToInt32(filaLote["CONTENIDO_LOTE"])) { int idproducto = Convert.ToInt32(filaConf["ID_PRODUCTO"]); int cantidad = Convert.ToInt32(filaConf["CANTIDAD_A_ENTREGAR"]); int idlote = Convert.ToInt32(filaLote["ID_LOTE"]); lote _lote = new lote(Empresa, Usuario); DataTable tablalo = _lote.ObtenerAlmLotePorId(idlote, _dato); DataRow filalo = tablalo.Rows[0]; Decimal costo = Convert.ToInt32(filalo["COSTO"]); String talla = filaConf["TALLA"].ToString(); Decimal idinventario = 0; Decimal idEntrega = 0; idinventario = _inventario.AdicionarAlmInventario(Convert.ToInt32(idDocumento), idproducto, idBodega, cantidad, costo, fecha, "SALIDA", _dato, idlote, talla, 0, 0, null, filalo["REEMBOLSO"].ToString()); if (idinventario == 0) { _dato.DeshacerTransaccion(); MensajeError += "El registro de inventario no fue posible crearlo por: " + _inventario.MensajeError + " Valide con el Administrador"; } else { idEntrega = AdicionarConRegEntregasServiciosComplementarios(Convert.ToInt32(idOrdenEntrega), idproducto, fecha, talla, cantidad, cantidad, "COMPLETA", costo, 0, 0, 0, "N", "", _dato); if (idEntrega == 0) { _dato.DeshacerTransaccion(); MensajeError += "El registro de inventario no fue posible crearlo por: " + MensajeError + " Valide con el Administrador"; } else { NumerosEntregas++; break; } } } else { } } } } } } if (NumerosEntregas == tablaConfigurados.Rows.Count) { if (faltantes.Equals("")) { if (_OrdenEntrega.ActualizarAsignacionServiciosComplementarios(Convert.ToInt32(idOrdenEntrega), Convert.ToInt32(idDocumento), idempleado, fecha, "COMPLETO", _dato)) { if (_documento.ActualizarAlmDocumento(Convert.ToInt32(idDocumento), idempleado, 0, "ENTREGA", "", "" + idOrdenEntrega.ToString(), fecha, Convert.ToDateTime("01/01/1900"), 0, 0, 0, "COMPLETO", "", 0, _dato)) { _dato.AceptarTransaccion(); } else { _dato.DeshacerTransaccion(); MensajeError += "No fue posible actualizar el documento por: " + _documento.MensajeError; } } else { _dato.DeshacerTransaccion(); MensajeError += "No fue posible actualizar la orden de entrega por: " + _OrdenEntrega.MensajeError; } } else { if (_OrdenEntrega.ActualizarAsignacionServiciosComplementarios(Convert.ToInt32(idOrdenEntrega), Convert.ToInt32(idDocumento), idempleado, fecha, "INCOMPLETO", _dato)) { if (_documento.ActualizarAlmDocumento(Convert.ToInt32(idDocumento), idempleado, 0, "ENTREGA", "", "" + idOrdenEntrega.ToString(), fecha, Convert.ToDateTime("01/01/1900"), 0, 0, 0, "INCOMPLETO", faltantes, 0, _dato)) { _dato.AceptarTransaccion(); } else { _dato.DeshacerTransaccion(); MensajeError += "No fue posible actualizar el documento por: " + _documento.MensajeError; } } else { _dato.DeshacerTransaccion(); MensajeError += "No fue posible actualizar la orden de entrega por: " + _OrdenEntrega.MensajeError; } } } else { NumerosEntregas = 0; } #endregion if (NumerosEntregas <= 0) return ""; return idOrdenEntrega.ToString(); }
public Decimal AdicionarEntregaProductos(Decimal id_empleado, List<Entrega> listaProductosEntrega, List<Equipo> listaEquiposEntrega) { Conexion conexion = new Conexion(Empresa); conexion.IniciarTransaccion(); Boolean correcto = true; Decimal id_documento_entrega = 0; try { documento _documento = new documento(Empresa, Usuario); id_documento_entrega = _documento.AdicionarAlmDocumentos(Convert.ToInt32(id_empleado), 0, TiposDeDocumento.ENTREGA.ToString(), null, null, DateTime.Now, new DateTime(), 0, 0, 0, EstadosDocumento.COMPLETO.ToString(), null, conexion, 0, null); if (id_documento_entrega <= 0) { conexion.DeshacerTransaccion(); correcto = false; MensajeError = _documento.MensajeError; id_documento_entrega = 0; } else { lote _lote = new lote(Empresa, Usuario); Inventario _inventario = new Inventario(Empresa, Usuario); Dictionary<Decimal, Decimal> listaIndices = new Dictionary<Decimal, Decimal>(); foreach (Entrega productoEntrega in listaProductosEntrega) { DataTable tablaLote = _lote.ObtenerAlmLotePorId(Convert.ToInt32(productoEntrega.ID_LOTE), conexion); DataRow filaLote = tablaLote.Rows[0]; Decimal ID_BODEGA = Convert.ToDecimal(filaLote["ID_BODEGA"]); Decimal COSTO_UNIDAD = Convert.ToDecimal(filaLote["COSTO"]); Decimal COSTO_TOTAL = (COSTO_UNIDAD * productoEntrega.CANTIDAD); Decimal ID_INVENTARIO = _inventario.AdicionarAlmInventario(Convert.ToInt32(id_documento_entrega), Convert.ToInt32(productoEntrega.ID_PRODUCTO), Convert.ToInt32(ID_BODEGA), productoEntrega.CANTIDAD, Convert.ToDecimal(filaLote["COSTO"]), DateTime.Now, TiposMovimientos.SALIDA.ToString(), conexion, Convert.ToInt32(productoEntrega.ID_LOTE), productoEntrega.TALLA, 0, 0, null, filaLote["REEMBOLSO"].ToString()); if (ID_INVENTARIO <= 0) { conexion.DeshacerTransaccion(); correcto = false; MensajeError = _inventario.MensajeError; id_documento_entrega = 0; break; } else { if (_lote.ActualizarCantidadesInventario(productoEntrega.ID_LOTE, productoEntrega.CANTIDAD, TiposMovimientos.SALIDA.ToString(), conexion) == false) { conexion.DeshacerTransaccion(); correcto = false; MensajeError = _inventario.MensajeError; id_documento_entrega = 0; break; } else { Decimal ID_ASIGNACION_SC = 0; if (productoEntrega.ID_ASIGNACION_SC == 0) { if (listaIndices.ContainsKey(productoEntrega.ID_INDEX) == true) { ID_ASIGNACION_SC = listaIndices[productoEntrega.ID_INDEX]; } else { ID_ASIGNACION_SC = AdicionarEscAsignacionSC(id_empleado, productoEntrega.ID_PRODUCTO, productoEntrega.CANTIDAD_TOTAL, 0, productoEntrega.FECHA_PROYECTADA_ENTREGA, productoEntrega.TIPO_ENTREGA, EstadosAsignacionSC.ABIERTA.ToString(), conexion); if (ID_ASIGNACION_SC <= 0) { conexion.DeshacerTransaccion(); correcto = false; id_documento_entrega = 0; break; } else { listaIndices.Add(productoEntrega.ID_INDEX, ID_ASIGNACION_SC); } } } else { ID_ASIGNACION_SC = productoEntrega.ID_ASIGNACION_SC; } Decimal ID_DETALLE_ASIGNACION = AdicionarEscDetalleContenidoAsignacion(ID_ASIGNACION_SC, id_documento_entrega, productoEntrega.CANTIDAD, productoEntrega.TALLA, COSTO_UNIDAD, COSTO_TOTAL, productoEntrega.ID_LOTE, conexion, ID_INVENTARIO); if (ID_DETALLE_ASIGNACION <= 0) { conexion.DeshacerTransaccion(); correcto = false; id_documento_entrega = 0; break; } else { if (ActualizarCantidadesAsignacion(ID_ASIGNACION_SC, productoEntrega.CANTIDAD, conexion) == false) { conexion.DeshacerTransaccion(); correcto = false; id_documento_entrega = 0; break; } } } } } listaIndices = new Dictionary<Decimal, Decimal>(); foreach (Equipo equipo in listaEquiposEntrega) { DataTable tablaLote = _lote.ObtenerAlmLotePorId(Convert.ToInt32(equipo.ID_LOTE), conexion); DataRow filaLote = tablaLote.Rows[0]; Decimal ID_BODEGA = Convert.ToDecimal(filaLote["ID_BODEGA"]); Decimal COSTO_UNIDAD = Convert.ToDecimal(filaLote["COSTO"]); Decimal ID_INVENTARIO = _inventario.AdicionarAlmInventario(Convert.ToInt32(id_documento_entrega), Convert.ToInt32(equipo.ID_PRODUCTO), Convert.ToInt32(ID_BODEGA), 1, Convert.ToDecimal(filaLote["COSTO"]), DateTime.Now, TiposMovimientos.SALIDA.ToString(), conexion, Convert.ToInt32(equipo.ID_LOTE), filaLote["TALLA"].ToString(), Convert.ToInt32(equipo.ID_EQUIPO), 0, null, filaLote["REEMBOLSO"].ToString()); if (ID_INVENTARIO <= 0) { conexion.DeshacerTransaccion(); correcto = false; MensajeError = _inventario.MensajeError; id_documento_entrega = 0; break; } else { if (_lote.ActualizarCantidadesInventario(equipo.ID_LOTE, 1, TiposMovimientos.SALIDA.ToString(), conexion) == false) { conexion.DeshacerTransaccion(); correcto = false; MensajeError = _inventario.MensajeError; id_documento_entrega = 0; break; } else { Decimal ID_ASIGNACION_SC = 0; if (equipo.ID_ASIGNACION_SC == 0) { if (listaIndices.ContainsKey(equipo.ID_INDEX) == true) { ID_ASIGNACION_SC = listaIndices[equipo.ID_INDEX]; } else { ID_ASIGNACION_SC = AdicionarEscAsignacionSC(id_empleado, equipo.ID_PRODUCTO, equipo.CANTIDAD_TOTAL, 0, equipo.FECHA_PROYECTADA_ENTREGA, equipo.TIPO_ENTREGA, EstadosAsignacionSC.ABIERTA.ToString(), conexion); if (ID_ASIGNACION_SC <= 0) { conexion.DeshacerTransaccion(); correcto = false; id_documento_entrega = 0; break; } else { listaIndices.Add(equipo.ID_INDEX, ID_ASIGNACION_SC); } } } else { ID_ASIGNACION_SC = equipo.ID_ASIGNACION_SC; } Decimal ID_DETALLE_ASIGNACION = AdicionarEscDetalleContenidoAsignacion(ID_ASIGNACION_SC, id_documento_entrega, 1, filaLote["TALLA"].ToString(), Convert.ToDecimal(filaLote["COSTO"]), Convert.ToDecimal(filaLote["COSTO"]), equipo.ID_LOTE, conexion, ID_INVENTARIO); if (ID_DETALLE_ASIGNACION <= 0) { conexion.DeshacerTransaccion(); correcto = false; id_documento_entrega = 0; break; } else { if (ActualizarCantidadesAsignacion(ID_ASIGNACION_SC, 1, conexion) == false) { conexion.DeshacerTransaccion(); correcto = false; id_documento_entrega = 0; break; } else { Decimal ID_EQUIPO_ENTREGA = AdicionarAlmEquiposEntrega(equipo.ID_EQUIPO, ID_DETALLE_ASIGNACION, DateTime.Now, conexion); if (ID_EQUIPO_ENTREGA <= 0) { conexion.DeshacerTransaccion(); correcto = false; id_documento_entrega = 0; break; } else { if (ActualizarDisponibilidadDeEquipo(equipo.ID_EQUIPO, "N", conexion) == false) { conexion.DeshacerTransaccion(); correcto = false; id_documento_entrega = 0; break; } } } } } } } } if (correcto == true) { conexion.AceptarTransaccion(); } } catch (Exception ex) { conexion.DeshacerTransaccion(); correcto = false; id_documento_entrega = 0; MensajeError = ex.Message; } finally { conexion.Desconectar(); } return id_documento_entrega; }
public Decimal AdicionarDatosFactura(Int32 ID_EMPLEADO, Int32 DOCUMENTO_ORIGEN, String TIPO_DOC, String ORIGEN, String NUMERO_DOCUMENTO, DateTime FECHA_DOCUMENTO, DateTime FECHA_VENCE, Int32 ID_BODEGA_DESTINO, Decimal VALOR, String ESTADO, String OBSERVACION_JUSTIFICACION, Int32 ID_PROVEEDOR, List<documento> listaDetalleFactura) { Decimal ID_DOCUMENTO = 0; Decimal ID_LOTE = 0; Decimal ID_INVENTARIO = 0; Decimal ID_DESCARGUE = 0; Boolean verificador = true; List<Decimal> listaDeOrdenesParaDescargadas = new List<Decimal>(); Conexion conexion = new Conexion(Empresa); conexion.IniciarTransaccion(); try { ID_DOCUMENTO = AdicionarAlmDocumentosParaFactura(ID_EMPLEADO, DOCUMENTO_ORIGEN, TIPO_DOC, ORIGEN, NUMERO_DOCUMENTO, FECHA_DOCUMENTO, FECHA_VENCE, ID_BODEGA_DESTINO, VALOR, ESTADO, OBSERVACION_JUSTIFICACION, conexion, ID_PROVEEDOR); if (ID_DOCUMENTO == 0) { conexion.DeshacerTransaccion(); MensajeError = MensajeError; verificador = false; } else { lote _lote = new lote(Empresa, Usuario); Inventario _inventario = new Inventario(Empresa, Usuario); crtDescargueFactura _crtDescargueFactura = new crtDescargueFactura(Empresa, Usuario); foreach (documento detalleFactura in listaDetalleFactura) { ID_LOTE = _lote.AdicionarAlmLote(Convert.ToInt32(ID_DOCUMENTO), Convert.ToInt32(detalleFactura.ID_PRODUCTO), Convert.ToInt32(detalleFactura.ID_BODEGA), FECHA_DOCUMENTO, detalleFactura.CANTIDAD, 0, detalleFactura.VALOR_UNIDAD, detalleFactura.TALLA, "S", conexion, detalleFactura.REEMBOLSO); if (ID_LOTE == 0) { conexion.DeshacerTransaccion(); MensajeError = "ERROR: Ingresando el lote: " + _lote.MensajeError; verificador = false; break; } else { ID_INVENTARIO = _inventario.AdicionarAlmInventario(Convert.ToInt32(ID_DOCUMENTO), Convert.ToInt32(detalleFactura.ID_PRODUCTO), Convert.ToInt32(detalleFactura.ID_BODEGA), detalleFactura.CANTIDAD, detalleFactura.VALOR_UNIDAD, FECHA_DOCUMENTO, "ENTRADA", conexion, Convert.ToInt32(ID_LOTE), detalleFactura.TALLA, 0, 0, null, detalleFactura.REEMBOLSO); if (ID_INVENTARIO == 0) { conexion.DeshacerTransaccion(); MensajeError = "ERROR: Ingresando el inventario: " + _inventario.MensajeError; verificador = false; break; } else { ID_DESCARGUE = _crtDescargueFactura.AdicionarAlmCrtDescargueInventario(ID_DOCUMENTO, detalleFactura.ID_ORDEN, detalleFactura.ID_PRODUCTO, detalleFactura.ID_DETALLE, detalleFactura.ID_BODEGA, ID_LOTE, detalleFactura.REFERENCIA_PRODUCTO, detalleFactura.TALLA, detalleFactura.CANTIDAD, conexion, detalleFactura.REEMBOLSO); if (ID_DESCARGUE == 0) { conexion.DeshacerTransaccion(); MensajeError = "ERROR: Ingresando el descargue de inventario: " + _crtDescargueFactura.MensajeError; verificador = false; break; } } } if (listaDeOrdenesParaDescargadas.Contains(detalleFactura.ID_ORDEN) == false) { listaDeOrdenesParaDescargadas.Add(detalleFactura.ID_ORDEN); } } } if (verificador == true) { ordenCompra _ordenCompra = new ordenCompra(Empresa, Usuario); DataTable tablaDetalleOrden; Int32 CANTIDAD_TOTAL_PRODUCTOS = 0; Int32 CANTIDAD_TOTAL_DESCARGADA = 0; foreach (Decimal orden in listaDeOrdenesParaDescargadas) { CANTIDAD_TOTAL_PRODUCTOS = 0; CANTIDAD_TOTAL_DESCARGADA = 0; tablaDetalleOrden = _ordenCompra.ObtenerDetallesOrdenCompraPorIdOrdenConCantidadDescargada(orden, conexion); foreach (DataRow filaTabla in tablaDetalleOrden.Rows) { try { CANTIDAD_TOTAL_PRODUCTOS += Convert.ToInt32(filaTabla["CANTIDAD"]); CANTIDAD_TOTAL_DESCARGADA += Convert.ToInt32(filaTabla["CANTIDAD_DESCARGADA"]); } catch (Exception ex) { MensajeError = "ERROR: Al intentar calcular estado de descarga de la orden de compra " + orden.ToString() + ". " + ex.Message; conexion.DeshacerTransaccion(); verificador = false; break; } } if (verificador == true) { if ((CANTIDAD_TOTAL_PRODUCTOS - CANTIDAD_TOTAL_DESCARGADA) <= 0) { if (_ordenCompra.ActualizarestadoOrdenCompra(orden, tabla.VAR_ESTADO_ORDEN_COMPRA_FINALIZADA, null) == false) { MensajeError = _ordenCompra.MensajeError; conexion.DeshacerTransaccion(); verificador = false; break; } } else { if (_ordenCompra.ActualizarestadoOrdenCompra(orden, tabla.VAR_ESTADO_ORDEN_COMPRA_ADJUNTADO_FACTURA, null) == false) { MensajeError = _ordenCompra.MensajeError; conexion.DeshacerTransaccion(); verificador = false; break; } } } else { break; } } if (verificador == true) { conexion.AceptarTransaccion(); } } } catch (Exception ex) { conexion.DeshacerTransaccion(); MensajeError = ex.Message; verificador = false; } finally { conexion.Desconectar(); } if (verificador == true) { return ID_DOCUMENTO; } else { return 0; } }