public String adicionarEntregasTemp(int idempleado, DateTime fecha, int idBodega, DataTable tablaConfigurados, String[] datos)
        {
            int     NumerosEntregas = 0;
            Decimal idDocumento     = 0;
            Decimal idOrdenEntrega  = 0;

            Brainsbits.LLB.almacen.documento_temp _documento = new almacen.documento_temp(Empresa, Usuario);
            Inventario_temp _inventario = new Inventario_temp(Empresa, Usuario);
            Conexion        _dato       = new LDA.Conexion(Empresa);

            _dato.IniciarTransaccion();

            #region validaciones
            idDocumento = _documento.AdicionarAlmDocumentosTemp(idempleado, "ENTREGA", "", fecha, Convert.ToDateTime("01/01/1900"), 0, "CONFIGURADO", "", _dato);

            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
            {
                foreach (DataRow filaConf in tablaConfigurados.Rows)
                {
                    int       idproducto   = Convert.ToInt32(filaConf["ID_PRODUCTO"]);
                    int       cantidad     = Convert.ToInt32(filaConf["CANTIDAD"]);
                    int       idlote       = Convert.ToInt32(filaConf["ID_LOTE"]);
                    lote      _lote        = new lote(Empresa, Usuario);
                    DataTable tablalo      = _lote.ObtenerAlmLotePorId(idlote);
                    DataRow   filalo       = tablalo.Rows[0];
                    Decimal   costo        = Convert.ToInt32(filalo["COSTO"]);
                    String    talla        = filaConf["TALLA"].ToString();
                    Decimal   idinventario = 0;

                    idinventario = _inventario.AdicionarAlmInventarioTemp(Convert.ToInt32(idDocumento), idproducto, idBodega, idlote, 0, talla, cantidad, costo, fecha, "SALIDA", _dato);

                    if (idinventario == 0)
                    {
                        _dato.DeshacerTransaccion();
                        MensajeError += "El registro de inventario no fue posible crearlo por: " + _inventario.MensajeError + " Valide con el Administrador";
                    }
                    else
                    {
                        NumerosEntregas++;
                    }
                }
            }
            if (NumerosEntregas == tablaConfigurados.Rows.Count)
            {
                _dato.AceptarTransaccion();
            }
            else
            {
                _dato.DeshacerTransaccion();
                NumerosEntregas = 0;
            }
            #endregion

            if (NumerosEntregas <= 0)
            {
                return("");
            }
            return(idDocumento.ToString());
        }
        public String adicionarEntregasTemp(int idempleado, DateTime fecha, int idBodega, DataTable tablaConfigurados, String[] datos)
        {
            int NumerosEntregas = 0;
            Decimal idDocumento = 0;
            Decimal idOrdenEntrega = 0;

            Brainsbits.LLB.almacen.documento_temp _documento = new almacen.documento_temp(Empresa, Usuario);
            Inventario_temp _inventario = new Inventario_temp(Empresa, Usuario);
            Conexion _dato = new LDA.Conexion(Empresa);
            _dato.IniciarTransaccion();

            #region validaciones
            idDocumento = _documento.AdicionarAlmDocumentosTemp(idempleado, "ENTREGA", "", fecha, Convert.ToDateTime("01/01/1900"), 0, "CONFIGURADO", "", _dato);

            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
            {
                foreach (DataRow filaConf in tablaConfigurados.Rows)
                {
                    int idproducto = Convert.ToInt32(filaConf["ID_PRODUCTO"]);
                    int cantidad = Convert.ToInt32(filaConf["CANTIDAD"]);
                    int idlote = Convert.ToInt32(filaConf["ID_LOTE"]);
                    lote _lote = new lote(Empresa, Usuario);
                    DataTable tablalo = _lote.ObtenerAlmLotePorId(idlote);
                    DataRow filalo = tablalo.Rows[0];
                    Decimal costo = Convert.ToInt32(filalo["COSTO"]);
                    String talla = filaConf["TALLA"].ToString();
                    Decimal idinventario = 0;

                    idinventario = _inventario.AdicionarAlmInventarioTemp(Convert.ToInt32(idDocumento), idproducto, idBodega, idlote, 0, talla, cantidad, costo, fecha, "SALIDA", _dato);

                    if (idinventario == 0)
                    {
                        _dato.DeshacerTransaccion();
                        MensajeError += "El registro de inventario no fue posible crearlo por: " + _inventario.MensajeError + " Valide con el Administrador";
                    }
                    else
                    {
                        NumerosEntregas++;
                    }
                }
            }
            if (NumerosEntregas == tablaConfigurados.Rows.Count)
            {
                _dato.AceptarTransaccion();
            }
            else
            {
                _dato.DeshacerTransaccion();
                NumerosEntregas = 0;
            }
            #endregion

            if (NumerosEntregas <= 0) return "";
            return idDocumento.ToString();
        }
        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 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();
        }