Example #1
0
        public static List <AlmacenInventarioLoteInfo> ObtenerLotesDelProducto(int formulaId)
        {
            var seguridad = HttpContext.Current.Session["Seguridad"] as SeguridadInfo;
            List <AlmacenInventarioLoteInfo> listaLotes = null;

            if (seguridad != null)
            {
                var         formulaPl   = new FormulaPL();
                FormulaInfo formulaInfo = formulaPl.ObtenerPorID(formulaId);

                if (formulaInfo.Descripcion.Trim() != "F1")
                {
                    var almaceninventariolotepl = new AlmacenInventarioLotePL();
                    listaLotes = almaceninventariolotepl.ObtenerListadoLotesPorOrganizacionTipoAlmacenProducto(
                        new ParametrosOrganizacionTipoAlmacenProductoActivo
                    {
                        Activo         = 1,
                        OrganizacionId = seguridad.Usuario.Organizacion.OrganizacionID,
                        ProductoId     = formulaInfo.Producto.ProductoId,
                        TipoAlmacenId  = (int)TipoAlmacenEnum.MateriasPrimas,
                        UsuarioId      = seguridad.Usuario.UsuarioID
                    });
                }
            }

            return(listaLotes);
        }
        public static AlmacenInventarioLoteInfo ObtenerCantidadPiezas(int idInventarioLote)
        {
            AlmacenInventarioLoteInfo lote = null;

            try
            {
                SeguridadInfo seguridad = HttpContext.Current.Session["Seguridad"] as SeguridadInfo;

                if (seguridad != null)
                {
                    var almacenPl = new AlmacenInventarioLotePL();

                    lote = almacenPl.ObtenerAlmacenInventarioLotePorId(idInventarioLote);
                }
                else
                {
                    throw new ExcepcionServicio("SesionExpirada");
                }
            }
            catch (ExcepcionServicio ex)
            {
                Logger.Error(ex);
                throw new ExcepcionServicio(ex.Message);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new Exception(ex.Message);
            }

            return(lote);
        }
Example #3
0
        public static AlmacenInventarioLoteInfo ObtenerExistenciaInventario(int almacenInventarioLoteId)
        {
            var seguridad = HttpContext.Current.Session["Seguridad"] as SeguridadInfo;
            AlmacenInventarioLoteInfo almacenInventarioLoteInfo = null;
            var almaceninventariolotepl = new AlmacenInventarioLotePL();

            if (seguridad != null)
            {
                almacenInventarioLoteInfo = almaceninventariolotepl.ObtenerAlmacenInventarioLotePorId(almacenInventarioLoteId);
            }

            return(almacenInventarioLoteInfo);
        }
        /// <summary>
        /// Validar lote en uso
        /// </summary>
        /// <returns></returns>
        private bool ValidarLoteEnUso()
        {
            decimal cantidadProgramadaAux = 0;
            var     datosLote             = new AlmacenInventarioLoteInfo
            {
                ProductoId     = producto.ProductoId,
                OrganizacionId = pedido.Organizacion.OrganizacionID,
                TipoAlmacenId  = (int)TipoAlmacenEnum.MateriasPrimas,
                Activo         = EstatusEnum.Activo
            };
            var almacenInventarioLotePL = new AlmacenInventarioLotePL();
            IList <AlmacenInventarioLoteInfo> resultado = almacenInventarioLotePL.ObtenerLotesUso(datosLote);

            if (resultado != null)
            {
                if (Convert.ToInt32(skAyudaLote.Clave) == resultado[0].Lote || Autorizado)
                {
                    Autorizado = false;
                    return(true);
                }
                if (Convert.ToInt32(skAyudaLote.Clave) == resultado[1].Lote)
                {
                    var pedidoPL           = new PedidosPL();
                    int cantidadProgramada =
                        pedidoPL.ObtenerPedidosProgramadosPorLoteCantidadProgramada(resultado[0].Lote);
                    if (detallePedido.ProgramacionMateriaPrima != null)
                    {
                        foreach (
                            var programacionMateriaPrimaInfo in
                            detallePedido.ProgramacionMateriaPrima.Where(
                                programacionMateriaPrimaInfo =>
                                programacionMateriaPrimaInfo.InventarioLoteOrigen.Lote == resultado[0].Lote))
                        {
                            cantidadProgramadaAux = programacionMateriaPrimaInfo.CantidadProgramada;
                        }
                    }
                    if ((resultado[0].Cantidad - (cantidadProgramada + cantidadProgramadaAux)) == 0)
                    {
                        return(true);
                    }
                }
                loteEnUso = resultado[0].Lote;
            }
            SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                              string.Format(Properties.Resources.SolicitudProgramacionMateriaPrima_RequiereAutorizacion,
                                            skAyudaLote.Clave), MessageBoxButton.OK,
                              MessageImage.Warning);
            SolicitarAutorizacionLoteUso();
            return(false);
        }
        /// <summary>
        /// Existe solicitud autorizada para folio seleccionado
        /// </summary>
        private void ExisteSolicitudAutorizada()
        {
            bool loteProgramacion        = false;
            var  solicitudAutorizacionPl = new SolicitudAutorizacionPL();
            var  autorizacionInfo        = new AutorizacionMateriaPrimaInfo
            {
                OrganizacionID     = organizacionID,
                TipoAutorizacionID = TipoAutorizacionEnum.UsoLote.GetHashCode(),
                Folio     = pedido.FolioPedido,
                EstatusID = Estatus.AMPAutoriz.GetHashCode()
            };
            AutorizacionMateriaPrimaInfo resultado =
                solicitudAutorizacionPl.ObtenerDatosSolicitudAutorizada(autorizacionInfo);

            if (resultado != null)
            {
                if (detallePedido.ProgramacionMateriaPrima != null && detallePedido.ProgramacionMateriaPrima.Count > 0)
                {
                    loteProgramacion =
                        detallePedido.ProgramacionMateriaPrima.Any(
                            programacionMateriaPrimaInfo =>
                            programacionMateriaPrimaInfo.InventarioLoteOrigen.Lote == resultado.Lote);
                }
                if (!loteProgramacion)
                {
                    skAyudaLote.Clave          = resultado.Lote.ToString(CultureInfo.InvariantCulture);
                    skAyudaLote.Descripcion    = resultado.Lote.ToString(CultureInfo.InvariantCulture);
                    txtCantidadProgramada.Text = Convert.ToString(resultado.CantidadProgramada);
                    var almacenInventarioLoteInfo = new AlmacenInventarioLoteInfo
                    {
                        ProductoId     = producto.ProductoId,
                        OrganizacionId = pedido.Organizacion.OrganizacionID,
                        TipoAlmacenId  = (int)TipoAlmacenEnum.MateriasPrimas,
                        Activo         = EstatusEnum.Activo,
                        Lote           = resultado.Lote
                    };
                    var almacenInventarioLotePL             = new AlmacenInventarioLotePL();
                    AlmacenInventarioLoteInfo resultadoInfo =
                        almacenInventarioLotePL.ObtenerAlmacenInventarioLotePorFolio(almacenInventarioLoteInfo);
                    almacenInventarioLote                = resultadoInfo;
                    almacenInventarioLote.ProductoId     = almacenInventarioLoteInfo.ProductoId;
                    almacenInventarioLote.OrganizacionId = almacenInventarioLoteInfo.OrganizacionId;
                    almacenInventarioLote.TipoAlmacenId  = almacenInventarioLoteInfo.TipoAlmacenId;
                    almacenInventarioLote.Activo         = almacenInventarioLoteInfo.Activo;
                    almacenInventarioLote.Lote           = almacenInventarioLoteInfo.Lote;
                    skAyudaLote.Info = resultadoInfo;
                }
            }
        }
        public static List <AlmacenInventarioLoteInfo> ObtenerLotes(int idProducto, int idAlmacen)
        {
            List <AlmacenInventarioLoteInfo> listaLotes = null;

            try
            {
                SeguridadInfo seguridad = HttpContext.Current.Session["Seguridad"] as SeguridadInfo;

                if (seguridad != null)
                {
                    var almacenPl = new AlmacenInventarioLotePL();

                    AlmacenInfo almacen = new AlmacenInfo()
                    {
                        AlmacenID = idAlmacen
                    };
                    ProductoInfo producto = new ProductoInfo()
                    {
                        ProductoId = idProducto
                    };

                    listaLotes = almacenPl.ObtenerPorAlmacenProducto(almacen, producto);
                }
                else
                {
                    throw new ExcepcionServicio("SesionExpirada");
                }
            }
            catch (ExcepcionServicio ex)
            {
                Logger.Error(ex);
                throw new ExcepcionServicio(ex.Message);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new Exception(ex.Message);
            }

            return(listaLotes);
        }
Example #7
0
        public static IList <AlmacenInventarioLoteInfo> ObtenerLotes(FiltroAyudaLotes filtroLote)
        {
            IList <AlmacenInventarioLoteInfo> listaAlmacenInventarioLote = null;

            try
            {
                var seguridad = HttpContext.Current.Session["Seguridad"] as SeguridadInfo;
                if (seguridad != null)
                {
                    var almacenPL = new AlmacenPL();
                    List <AlmacenInfo> almacenesOrganizacion  = almacenPL.ObtenerAlmacenesPorOrganizacion(seguridad.Usuario.Organizacion.OrganizacionID);
                    AlmacenInfo        almacenPlantaAlimentos =
                        almacenesOrganizacion.FirstOrDefault(
                            alm => alm.TipoAlmacenID == TipoAlmacenEnum.PlantaDeAlimentos.GetHashCode());
                    if (almacenPlantaAlimentos != null)
                    {
                        filtroLote.AlmacenID = almacenPlantaAlimentos.AlmacenID;
                    }
                    filtroLote.OrganizacionID = seguridad.Usuario.Organizacion.OrganizacionID;

                    var almacenInventarioLotePL = new AlmacenInventarioLotePL();

                    listaAlmacenInventarioLote =
                        almacenInventarioLotePL.ObtenerAlmacenInventarioLotePorLote(filtroLote);

                    return(listaAlmacenInventarioLote);
                }
            }
            catch (ExcepcionDesconocida ex)
            {
                Logger.Error(ex);
                throw;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            return(listaAlmacenInventarioLote);
        }
Example #8
0
        private void CargarArchivoImportar()
        {
            try
            {
                var almacenPL               = new AlmacenPL();
                var almacenInventarioPL     = new AlmacenInventarioPL();
                var almacenInventarioLotePL = new AlmacenInventarioLotePL();
                var productoPL              = new ProductoPL();

                List <AlmacenInfo> almacenesOrganizacion =
                    almacenPL.ObtenerAlmacenesPorOrganizacion(Contexto.Organizacion.OrganizacionID);

                List <ProductoInfo> productos = productoPL.ObtenerPorEstados(EstatusEnum.Activo);


                if (almacenesOrganizacion == null)
                {
                    SkMessageBox.Show(System.Windows.Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                      Properties.Resources.CargaMPPA_SinAlmacenes, MessageBoxButton.OK,
                                      MessageImage.Warning);
                    return;
                }

                IList <AlmacenInventarioInfo> almacenesInventario =
                    almacenInventarioPL.ObtenerPorAlmacenXML(almacenesOrganizacion) ?? new List <AlmacenInventarioInfo>();

                IList <AlmacenInventarioLoteInfo> almacenesInventarioLote =
                    almacenInventarioLotePL.ObtenerLotesPorAlmacenInventarioXML(almacenesInventario.ToList()) ??
                    new List <AlmacenInventarioLoteInfo>();


                var archivoCarga = new FileInfo(Contexto.Ruta);
                // Open and read the XlSX file.
                using (var excel = new ExcelPackage(archivoCarga))
                {
                    ExcelWorkbook libro = excel.Workbook;
                    if (libro == null || libro.Worksheets.Count == 0)
                    {
                        SkMessageBox.Show(System.Windows.Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.CargaMPPA_ArchivoSinDatos, MessageBoxButton.OK, MessageImage.Warning);
                        return;
                    }
                    // Get the first worksheet
                    ExcelWorksheet hojaExcel = libro.Worksheets.First();

                    if (!hojaExcel.Name.ToUpper().Equals(Properties.Resources.CargaMPPA_NombreHoja.ToUpper(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        SkMessageBox.Show(System.Windows.Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.CargaMPPA_NombreIncorrectoHoja, MessageBoxButton.OK, MessageImage.Warning);
                        return;
                    }

                    if (!ValidarEncabezado(hojaExcel))
                    {
                        return;
                    }
                    for (int renglon = RenglonEncabezados + 1; renglon <= hojaExcel.Dimension.End.Row; renglon++)
                    {
                        var carga = new CargaMPPAModel();

                        object columnaVacia = hojaExcel.Cells[renglon, 1].Value;
                        if (columnaVacia == null || string.IsNullOrWhiteSpace(columnaVacia.ToString()))
                        {
                            continue;
                        }

                        #region AsignarPropiedades
                        var propiedades = carga.GetType().GetProperties();
                        foreach (var propInfo in propiedades)
                        {
                            dynamic customAttributes = carga.GetType().GetProperty(propInfo.Name).GetCustomAttributes(typeof(AtributoCargaMPPA), true);
                            if (customAttributes.Length > 0)
                            {
                                for (var indexAtributos = 0; indexAtributos < customAttributes.Length; indexAtributos++)
                                {
                                    var      atributos    = (AtributoCargaMPPA)customAttributes[indexAtributos];
                                    int      celdaArchivo = atributos.Celda;
                                    TypeCode tipoDato     = atributos.TipoDato;
                                    bool     aceptaVacio  = atributos.AceptaVacio;

                                    object dato = hojaExcel.Cells[renglon, celdaArchivo].Value;

                                    switch (tipoDato)
                                    {
                                    case TypeCode.Int32:
                                        int valorInt;
                                        int.TryParse(dato == null ? "" : dato.ToString(), out valorInt);
                                        if (valorInt == 0)
                                        {
                                            if (aceptaVacio)
                                            {
                                                propInfo.SetValue(carga, 0, null);
                                            }
                                            else
                                            {
                                                carga.MensajeAlerta =
                                                    string.Format(Properties.Resources.CargaMPPA_ErrorColumna,
                                                                  renglon, propInfo.Name);
                                                break;
                                            }
                                        }
                                        propInfo.SetValue(carga, valorInt, null);

                                        break;

                                    case TypeCode.Decimal:
                                        decimal valorDecimal;
                                        decimal.TryParse(dato == null ? "" : dato.ToString(), out valorDecimal);
                                        if (valorDecimal == 0)
                                        {
                                            if (aceptaVacio)
                                            {
                                                propInfo.SetValue(carga, 0, null);
                                            }
                                            else
                                            {
                                                carga.MensajeAlerta =
                                                    string.Format(Properties.Resources.CargaMPPA_ErrorColumna,
                                                                  renglon, propInfo.Name);
                                                break;
                                            }
                                        }
                                        propInfo.SetValue(carga, valorDecimal, null);

                                        break;

                                    case TypeCode.DateTime:
                                        DateTime valorFecha;
                                        DateTime.TryParse(dato == null ? "" : dato.ToString(), out valorFecha);
                                        if (valorFecha == DateTime.MinValue)
                                        {
                                            if (aceptaVacio)
                                            {
                                                propInfo.SetValue(carga, DateTime.MinValue, null);
                                            }
                                            else
                                            {
                                                carga.MensajeAlerta =
                                                    string.Format(Properties.Resources.CargaMPPA_ErrorColumna,
                                                                  renglon, propInfo.Name);
                                                break;
                                            }
                                        }
                                        propInfo.SetValue(carga, valorFecha, null);

                                        break;

                                    default:
                                        propInfo.SetValue(carga, null, null);
                                        break;
                                    }
                                }
                            }
                        }
                        #endregion AsignarPropiedades
                        #region Validaciones

                        AlmacenInfo           almacenCarga      = almacenesOrganizacion.FirstOrDefault(alm => alm.AlmacenID == carga.AlmacenID);
                        ProductoInfo          producto          = productos.FirstOrDefault(pro => pro.ProductoId == carga.ProductoID);
                        AlmacenInventarioInfo almacenInventario =
                            almacenesInventario.FirstOrDefault(
                                ai => ai.AlmacenID == carga.AlmacenID && ai.ProductoID == carga.ProductoID);

                        if (almacenCarga == null)
                        {
                            carga.MensajeAlerta = string.Format(Properties.Resources.CargaMPPA_NoExisteAlmacen,
                                                                carga.AlmacenID, renglon);
                        }
                        carga.Almacen = almacenCarga;
                        if (producto == null)
                        {
                            carga.MensajeAlerta = string.Format(Properties.Resources.CargaMPPA_NoExisteProducto,
                                                                carga.ProductoID, renglon);
                        }
                        carga.Producto = producto;
                        if (almacenInventario != null && almacenInventario.Cantidad > 0)
                        {
                            carga.MensajeAlerta = string.Format(Properties.Resources.CargaMPPA_ExisteInventario,
                                                                carga.ProductoID, carga.AlmacenID, renglon);
                        }
                        carga.AlmacenInventario = almacenInventario;

                        if (carga.AlmacenInventario != null && carga.AlmacenInventario.AlmacenInventarioID > 0)
                        {
                            List <AlmacenInventarioLoteInfo> lotesInventario =
                                almacenesInventarioLote.Where(
                                    ail =>
                                    ail.AlmacenInventario.AlmacenInventarioID ==
                                    carga.AlmacenInventario.AlmacenInventarioID).ToList();

                            if (lotesInventario.Any())
                            {
                                AlmacenInventarioLoteInfo lote =
                                    lotesInventario.FirstOrDefault(ail => ail.Lote == carga.Lote);

                                if (lote != null)
                                {
                                    carga.MensajeAlerta = string.Format(Properties.Resources.CargaMPPA_ExisteLote,
                                                                        carga.Lote, carga.AlmacenID, renglon);
                                }
                            }
                        }
                        CargaMPPAModel cargaRepetida =
                            listaInventariosValidos.FirstOrDefault(car => car.ProductoID == carga.ProductoID &&
                                                                   car.AlmacenID == carga.AlmacenID &&
                                                                   car.Lote == carga.Lote);

                        if (cargaRepetida != null)
                        {
                            carga.MensajeAlerta = string.Format(Properties.Resources.CargaMPPA_ExisteRenglonRepetido, renglon);
                        }


                        if (!string.IsNullOrWhiteSpace(carga.MensajeAlerta))
                        {
                            listaInventariosInvalidos.Add(carga);
                        }
                        else
                        {
                            listaInventariosValidos.Add(carga);
                        }
                        #endregion Validaciones
                    }
                }
                if (listaInventariosInvalidos.Any())
                {
                    gridDatos.ItemsSource = listaInventariosInvalidos;
                    btnGuardar.IsEnabled  = false;
                    SkMessageBox.Show(System.Windows.Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                      string.Format(Properties.Resources.CargaMPPA_RegistroProblemas, listaInventariosInvalidos.Count),
                                      MessageBoxButton.OK,
                                      MessageImage.Warning);
                    return;
                }

                if (listaInventariosValidos.Any())
                {
                    SkMessageBox.Show(System.Windows.Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                      string.Format(Properties.Resources.CargaMPPA_RegistroSinProblemas, listaInventariosValidos.Count),
                                      MessageBoxButton.OK,
                                      MessageImage.Correct);
                }

                btnGuardar.IsEnabled = true;
            }
            catch (Exception ex)
            {
                SkMessageBox.Show(System.Windows.Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.CargaMPPA_ErrorValidar, MessageBoxButton.OK, MessageImage.Error);
                Logger.Error(ex);
            }
        }
Example #9
0
        /// <summary>
        /// Valida si el stock actual no cubre el envio que se intenta registrar
        /// </summary>
        /// <returns>Regresa True si la canidad de envio excede el inventario actual</returns>
        private bool ValidarSalidaExcede(out string error)
        {
            AlmacenInventarioPL   almacenInventarioPL   = new AlmacenInventarioPL();
            AlmacenInventarioInfo inventarioActualizado = almacenInventarioPL.ObtenerPorAlmacenIdProductoId(EnvioAlimento.AlmacenInventario);

            if (EnvioAlimento.Producto.ManejaLote)
            {
                AlmacenInventarioLotePL   inventarioLotePL = new AlmacenInventarioLotePL();
                AlmacenInventarioLoteInfo loteActual       = inventarioLotePL.ObtenerAlmacenInventarioLotePorId(EnvioAlimento.AlmacenInventario.ListaAlmacenInventarioLote.FirstOrDefault().AlmacenInventarioLoteId);

                if (loteActual.Cantidad == 0)
                {
                    error = Properties.Resources.EnvioAlimento_MsgProductoSinInventario;
                    LimpiarProducto();
                    this.EnvioAlimento.Producto = new ProductoInfo {
                        ProductoId = 0, SubfamiliaId = (int)this.cmbSubFamilia.SelectedValue
                    };
                    cmbAlmacen.ItemsSource = new List <AlmacenInfo>();
                    this.skAyudaProducto.LimpiarCampos();
                    cmbAlmacen.IsEnabled = false;
                    this.skAyudaProducto.LimpiarCampos();
                    this.skAyudaProducto.txtClave.Focus();

                    txtCantidadEnvio.Text      = string.Empty;
                    txtPrecioPromedio.Text     = string.Empty;
                    txtCantidadInventario.Text = string.Empty;
                    return(true);
                }

                if ((loteActual.Cantidad - decimal.Parse(txtCantidadEnvio.Text)) < 0)
                {
                    error = Properties.Resources.EnvioAlimento_MsgCantidadInventarioNegativo;
                    LimpiarProducto();
                    txtCantidadEnvio.Text      = string.Empty;
                    txtPrecioPromedio.Text     = string.Empty;
                    txtCantidadInventario.Text = string.Empty;
                    return(true);
                }
                error = string.Empty;
                return(false);
            }
            else
            {
                if (inventarioActualizado.Cantidad == 0)
                {
                    error = Properties.Resources.EnvioAlimento_MsgProductoSinInventario;
                    LimpiarProducto();
                    this.skAyudaProducto.LimpiarCampos();
                    this.skAyudaProducto.txtClave.Focus();

                    txtCantidadEnvio.Text      = string.Empty;
                    txtPrecioPromedio.Text     = string.Empty;
                    txtCantidadInventario.Text = string.Empty;
                    return(true);
                }

                if (((inventarioActualizado.Cantidad - decimal.Parse(txtCantidadEnvio.Text.Trim())) < 0))
                {
                    error = Properties.Resources.EnvioAlimento_MsgCantidadInventarioNegativo;
                    LimpiarProducto();
                    txtCantidadEnvio.Text      = string.Empty;
                    txtPrecioPromedio.Text     = string.Empty;
                    txtCantidadInventario.Text = string.Empty;
                    return(true);
                }
                else
                {
                    error = string.Empty;
                    return(false);
                }
            }
        }
Example #10
0
        /// <summary>
        /// Valida el lote ingresado
        /// </summary>
        private void ValidarLote()
        {
            try
            {
                if (txtLote.Text == string.Empty)
                {
                    Contexto.AlmacenInventarioLote = null;
                    return;
                }

                var loteId = int.Parse(txtLote.Text);

                var lotePl = new AlmacenInventarioLotePL();

                //Validar producto seleccionado
                //if (productoSeleccionado == null || productoSeleccionado.ProductoId == 0)
                if (Contexto.Producto == null || Contexto.Producto.ProductoId == 0)
                {
                    SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                      Properties.Resources.ReporteAuxiliarInventarioMateriaPrima_MsgSelecioneProducto, MessageBoxButton.OK,
                                      MessageImage.Warning);
                    skAyudaProducto.Focus();
                    txtLote.Text = string.Empty;
                    return;
                }

                //Validar almacen seleccionado
                //if (almacenSeleccionado == null || almacenSeleccionado.AlmacenID == 0)
                if (Contexto.Almacen == null || Contexto.Almacen.AlmacenID == 0)
                {
                    SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                      Properties.Resources.ReporteAuxiliarInventarioMateriaPrima_MsgSelecioneAlmacen, MessageBoxButton.OK,
                                      MessageImage.Warning);
                    skAyudaAlmacen.Focus();
                    txtLote.Text = string.Empty;
                    return;
                }

                var lotein = new AlmacenInventarioLoteInfo
                {
                    Lote = loteId,
                    //Activo = EstatusEnum.Activo,
                    OrganizacionId    = Contexto.Almacen.Organizacion.OrganizacionID,
                    ProductoId        = Contexto.Producto.ProductoId,
                    TipoAlmacenId     = Contexto.Almacen.TipoAlmacen.TipoAlmacenID,
                    AlmacenInventario = new AlmacenInventarioInfo
                    {
                        AlmacenID = Contexto.Almacen.AlmacenID
                    }
                };

                var loteObtenido = lotePl.ObtenerAlmacenInventarioLotePorFolioLote(lotein);

                if (loteObtenido != null && Contexto.Producto != null)
                {
                    if (loteObtenido.AlmacenInventario.AlmacenID != Contexto.Almacen.AlmacenID)
                    {
                        SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                          Properties.Resources.ReporteAuxiliarInventarioMateriaPrima_LoteNoExiste, MessageBoxButton.OK,
                                          MessageImage.Warning);
                        txtLote.Text = string.Empty;
                        txtLote.Focus();
                    }
                    else
                    {
                        Contexto.AlmacenInventarioLote = loteObtenido;
                    }
                }
                else
                {
                    SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                      Properties.Resources.ReporteAuxiliarInventarioMateriaPrima_LoteNoExiste, MessageBoxButton.OK,
                                      MessageImage.Warning);
                    txtLote.Text = string.Empty;
                    txtLote.Focus();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                  Properties.Resources.ReporteAuxiliarInventarioMateriaPrima_FalloValidarLote, MessageBoxButton.OK,
                                  MessageImage.Warning);
                txtLote.Text = string.Empty;
                txtLote.Focus();
            }
        }
        /// <summary>
        /// Crear un nuevo lote en AlamcenInventarioLote
        /// </summary>
        private void CrearNuevoLote()
        {
            try
            {
                AlmacenInventarioLoteInfo almacenInventarioLote = null;

                int usuarioId = AuxConfiguracion.ObtenerUsuarioLogueado();
                var almacenInventarioLotePl = new AlmacenInventarioLotePL();
                var almacenInventarioPl     = new AlmacenInventarioPL();

                var almacenInventario = new AlmacenInventarioInfo
                {
                    AlmacenID  = Contexto.AlmacenDestino.AlmacenID,
                    ProductoID = Contexto.ProductoDestino.ProductoId
                };

                almacenInventario = almacenInventarioPl.ObtenerPorAlmacenIdProductoId(almacenInventario);

                // Si el producto no se encuentra en el almacen inventario, lo insertamos
                if (almacenInventario == null)
                {
                    almacenInventario = new AlmacenInventarioInfo
                    {
                        AlmacenInventarioID =
                            almacenInventarioPl.Crear(new AlmacenInventarioInfo
                        {
                            AlmacenID         = Contexto.AlmacenDestino.AlmacenID,
                            ProductoID        = Contexto.ProductoDestino.ProductoId,
                            UsuarioCreacionID = usuarioId
                        }),
                        AlmacenID = Contexto.AlmacenDestino.AlmacenID
                    };
                }

                int loteIdCreado = almacenInventarioLotePl.Crear(new AlmacenInventarioLoteInfo
                {
                    AlmacenInventarioLoteId = 0,
                    AlmacenInventario       =
                        new AlmacenInventarioInfo {
                        AlmacenInventarioID = almacenInventario.AlmacenInventarioID
                    },
                    Cantidad          = 0,
                    PrecioPromedio    = 0,
                    Piezas            = 0,
                    Importe           = 0,
                    Activo            = EstatusEnum.Activo,
                    UsuarioCreacionId = usuarioId,
                }, new AlmacenInventarioInfo
                {
                    AlmacenID  = almacenInventario.AlmacenID,
                    ProductoID = Contexto.ProductoDestino.ProductoId
                });

                almacenInventarioLote = almacenInventarioLotePl.ObtenerAlmacenInventarioLotePorId(loteIdCreado);


                Contexto.LoteMpDestino         = almacenInventarioLote;
                skAyudaLoteMPDestino.IsEnabled = false;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                  Properties.Resources.TraspasoMPPAMED_ErrorCrearLote, MessageBoxButton.OK,
                                  MessageImage.Error);
            }
        }
        public static RespuestaInventarioLoteInfo ObtenerLotePorTipoAlmacen(ParametroRecepcionMateriaPrimaLote parametroLoteMateriaPrima)
        {
            try
            {
                RespuestaInventarioLoteInfo listadoLotes = null;
                var almacenInventarioLotePl = new AlmacenInventarioLotePL();
                var seguridad = HttpContext.Current.Session["Seguridad"] as SeguridadInfo;
                int organizacionId = 0, tipoAlmacen = 0;

                if (seguridad != null)
                {
                    organizacionId = seguridad.Usuario.Organizacion.OrganizacionID;
                }

                switch (parametroLoteMateriaPrima.TipoAlmacen)
                {
                case "rbLoteAlmacen":
                    tipoAlmacen = (int)TipoAlmacenEnum.MateriasPrimas;
                    break;

                case "rbLoteProceso":
                    tipoAlmacen = (int)TipoAlmacenEnum.PlantaDeAlimentos;
                    break;

                case "rbBodegaExterna":
                    tipoAlmacen = (int)TipoAlmacenEnum.BodegaExterna;
                    break;
                }

                var almacenInventarioLote = almacenInventarioLotePl
                                            .ObtenerListadoLotesPorOrganizacionTipoAlmacenProducto(
                    new ParametrosOrganizacionTipoAlmacenProductoActivo
                {
                    OrganizacionId = organizacionId,
                    ProductoId     = parametroLoteMateriaPrima.ProductoId,
                    TipoAlmacenId  = tipoAlmacen
                });

                if (almacenInventarioLote != null)
                {
                    foreach (var almacenInventario in almacenInventarioLote.Where(almacen => almacen.Lote == parametroLoteMateriaPrima.Lote))
                    {
                        var almacenPl = new AlmacenPL();
                        var almacen   = almacenPl.ObtenerPorID(almacenInventario.AlmacenInventario.AlmacenID);

                        listadoLotes = new RespuestaInventarioLoteInfo
                        {
                            AlmacenInventarioLoteId = almacenInventario.AlmacenInventarioLoteId,
                            AlmacenId     = almacenInventario.AlmacenInventario.AlmacenID,
                            CodigoAlmacen = almacen.CodigoAlmacen,
                            Lote          = almacenInventario.Lote,
                            Cantidad      = almacenInventario.Cantidad
                        };
                    }
                }
                return(listadoLotes);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new SystemException(ex.Message);
            }
        }
        public static AlmacenInventarioLoteInfo ObtenerNuevoLoteMateriaPrima(int productoId, string tipoalmacen)
        {
            try
            {
                var seguridad = HttpContext.Current.Session["Seguridad"] as SeguridadInfo;
                int organizacionId = 0, usuarioId = 0, tipoAlmacen = 0;

                AlmacenInventarioLoteInfo almacenInventarioLote = null;

                if (seguridad != null)
                {
                    organizacionId = seguridad.Usuario.Organizacion.OrganizacionID;
                    usuarioId      = seguridad.Usuario.UsuarioID;
                }

                switch (tipoalmacen)
                {
                case "rbLoteAlmacen":
                    tipoAlmacen = (int)TipoAlmacenEnum.MateriasPrimas;
                    break;

                case "rbLoteProceso":
                    tipoAlmacen = (int)TipoAlmacenEnum.PlantaDeAlimentos;
                    break;

                case "rbBodegaExterna":
                    tipoAlmacen = (int)TipoAlmacenEnum.BodegaExterna;
                    break;
                }

                var almacenInventarioLotePl = new AlmacenInventarioLotePL();
                var almacenPl               = new AlmacenPL();
                var almacenInventarioPl     = new AlmacenInventarioPL();

                var almacenInventario =
                    almacenPl.ObtenerAlmacenInventarioPorOrganizacionTipoAlmacen(new ParametrosOrganizacionTipoAlmacenProductoActivo
                {
                    OrganizacionId = organizacionId,
                    TipoAlmacenId  = tipoAlmacen,
                    Activo         = (int)EstatusEnum.Activo,
                    ProductoId     = productoId
                });

                // Si el producto no se encuentra en el almacen inventario, lo insertamos
                if (almacenInventario == null)
                {
                    var listaAlmacenOrganizacion = almacenPl.ObtenerAlmacenPorOrganizacion(organizacionId);
                    if (listaAlmacenOrganizacion != null)
                    {
                        // Obtenemos el almacen y validamos que sea del mismo tipo Almacen
                        foreach (AlmacenInfo almacenInfo in listaAlmacenOrganizacion)
                        {
                            // Aqui se valida que el almacen sea del tipo seleccionado en pantalla
                            if (almacenInfo.TipoAlmacen.TipoAlmacenID == tipoAlmacen)
                            {
                                almacenInventario = new AlmacenInventarioInfo
                                {
                                    AlmacenInventarioID =
                                        almacenInventarioPl.Crear(new AlmacenInventarioInfo
                                    {
                                        AlmacenID         = almacenInfo.AlmacenID,
                                        ProductoID        = productoId,
                                        UsuarioCreacionID = usuarioId
                                    }),
                                    AlmacenID = almacenInfo.AlmacenID
                                };
                                break;
                            }
                        }
                    }
                }

                if (almacenInventario != null)
                {
                    int loteIdCreado = almacenInventarioLotePl.Crear(new AlmacenInventarioLoteInfo
                    {
                        AlmacenInventarioLoteId = 0,
                        AlmacenInventario       =
                            new AlmacenInventarioInfo {
                            AlmacenInventarioID = almacenInventario.AlmacenInventarioID
                        },
                        Cantidad          = 0,
                        PrecioPromedio    = 0,
                        Piezas            = 0,
                        Importe           = 0,
                        Activo            = EstatusEnum.Activo,
                        UsuarioCreacionId = usuarioId,
                    }, new AlmacenInventarioInfo
                    {
                        AlmacenID  = almacenInventario.AlmacenID,
                        ProductoID = productoId
                    });

                    almacenInventarioLote = almacenInventarioLotePl.ObtenerAlmacenInventarioLotePorId(loteIdCreado);
                }

                return(almacenInventarioLote);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new SystemException(ex.Message);
            }
        }