예제 #1
0
        /// <summary>
        /// Cargar el grid
        /// </summary>
        public void CargarGrid()
        {
            var almacenId = (int)cboAlmacenes.SelectedValue;
            var almacenPl = new AlmacenPL();
            AlmacenMovimientoInfo almacenMovimientoInfo = new AlmacenMovimientoInfo
            {
                AlmacenID        = almacenId,
                TipoMovimientoID = (int)TipoMovimiento.InventarioFisico,
                Status           = (int)EstatusInventario.Pendiente
            };

            IList <AlmacenMovimientoInfo> resultadoGrid = almacenPl.ObtenerListaAlmacenMovimiento(almacenMovimientoInfo, (int)EstatusEnum.Activo);

            if (resultadoGrid.Count > 0)
            {
                gridDatos.ItemsSource = resultadoGrid;
                btnDetalle.IsEnabled  = true;
            }
            else
            {
                SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                  Properties.Resources.AutorizarAjuste_NoMovimientosDiferencia,
                                  MessageBoxButton.OK, MessageImage.Warning);
                LimpiarCaptura();
            }
        }
예제 #2
0
 /// <summary>
 /// Metodo que llena combo almacenes y extablecer almacen
 /// </summary>
 private void CargarCboAlmacenes()
 {
     try
     {
         var almacenPl        = new AlmacenPL();
         var listaAlmacenInfo = almacenPl.ObtenerAlmacenPorOrganizacion(organizacionID);
         if (listaAlmacenInfo == null)
         {
             return;
         }
         var almacenes = new AlmacenInfo {
             Descripcion = Properties.Resources.AjusteDeInventario_Seleccione, AlmacenID = 0
         };
         listaAlmacenInfo.Insert(0, almacenes);
         CboAlmacenes.ItemsSource   = listaAlmacenInfo;
         CboAlmacenes.SelectedValue = almacenID;
     }
     catch (ExcepcionGenerica ex)
     {
         Logger.Error(ex);
         throw;
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
예제 #3
0
        public static AlmacenInventarioInfo ObtenerExistenciaInventarioFormula(int formulaId)
        {
            var seguridad = HttpContext.Current.Session["Seguridad"] as SeguridadInfo;

            AlmacenInventarioInfo almacenInventarioInfo = null;

            //var almaceninventarioPl = new AlmacenInventarioPL();

            if (seguridad != null)
            {
                FormulaInfo formula   = new FormulaInfo();
                FormulaPL   formulaPl = new FormulaPL();
                formula = formulaPl.ObtenerPorID(formulaId);
                //AlmacenInfo almacenInfo = new AlmacenInfo();
                AlmacenPL almacenPl = new AlmacenPL();
                almacenInventarioInfo = almacenPl.ObtenerAlmacenInventarioPorOrganizacionTipoAlmacen(new ParametrosOrganizacionTipoAlmacenProductoActivo()
                {
                    Activo         = 1,
                    OrganizacionId = seguridad.Usuario.OrganizacionID,
                    ProductoId     = formula.Producto.ProductoId,
                    TipoAlmacenId  = (int)TipoAlmacenEnum.PlantaDeAlimentos
                });
            }

            return(almacenInventarioInfo);
        }
예제 #4
0
 /// <summary>
 /// Cargar el combo almacenes
 /// </summary>
 private void CargarCboAlmacenes()
 {
     try
     {
         AlmacenPL almacenPl = new AlmacenPL();
         listaAlmacenInfo = almacenPl.ObtenerAlmacenPorOrganizacion(organizacionId);
         if (listaAlmacenInfo != null)
         {
             var almacenes = new AlmacenInfo {
                 Descripcion = "Seleccione", AlmacenID = 0
             };
             listaAlmacenInfo.Insert(0, almacenes);
             cboAlmacenes.ItemsSource   = listaAlmacenInfo;
             cboAlmacenes.SelectedValue = 0;
         }
         else
         {
             SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                               Properties.Resources.CierreDiaInventario_NoAlmacenesOrganizacionUsuario,
                               MessageBoxButton.OK, MessageImage.Warning);
             LimpiarCaptura();
             cboAlmacenes.IsEnabled = false;
         }
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
예제 #5
0
 /// <summary>
 /// Carga los productos del grid.
 /// </summary>
 private void CargarGridProductos()
 {
     try
     {
         var almacenPl = new AlmacenPL();
         var almacenId = (int)CboAlmacenes.SelectedValue;
         datosGrid = almacenPl.ObtenerProductosAlamcen(almacenId, organizacionId);
         if (datosGrid != null)
         {
             datosGrid = FiltrarProductosAlmacen(datosGrid);
             gridProductosInventario.ItemsSource = datosGrid;
             txtObservaciones.IsEnabled          = true;
             btnGuardar.IsEnabled = true;
         }
         else
         {
             SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                               Properties.Resources.CierreDiaInventario_NoAlmacenesNoProductos,
                               MessageBoxButton.OK, MessageImage.Warning);
             LimpiarCaptura();
             DesahabilitarControles(false);
             CboAlmacenes.Focus();
             btnGuardar.IsEnabled = false;
         }
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
예제 #6
0
        /// <summary>
        /// Consulta el almacen general de la organizacion del usuario logueado
        /// </summary>
        private void ConsultaAlmacenGeneral()
        {
            try
            {
                var almacenPl    = new AlmacenPL();
                var listaAlmacen = almacenPl.ObtenerAlmacenPorTiposAlmacen(new List <TipoAlmacenEnum>()
                {
                    TipoAlmacenEnum.GeneralGanadera
                }, new OrganizacionInfo()
                {
                    OrganizacionID = organizacionId
                });

                if (listaAlmacen != null && listaAlmacen.Count > 0)
                {
                    txtAlmacenGeneral.Text     = listaAlmacen[0].AlmacenID.ToString();
                    txtDescripcionAlmacen.Text = listaAlmacen[0].Descripcion;
                }
                else
                {
                    BloquearPantalla();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
예제 #7
0
        /// <summary>
        /// Metodo que se invoca cuando la ayuda de seleccion de destino se des-selecciona
        /// </summary>
        /// <param name="sender">Objeto que invoco el evento</param>
        /// <param name="e">Parametros del evento</param>
        private void skAyudaDestino_LostFocus(object sender, RoutedEventArgs e)
        {
            OrganizacionInfo organizacionDestino = EnvioAlimento.Destino;

            if (organizacionDestino.OrganizacionID == 0)
            {
                organizacionDestino = (OrganizacionInfo)skAyudaDestino.DataContext;
                organizacionDestino.ListaTiposOrganizacion = this._tiposOrganizacionDestino;
            }
            if (organizacionDestino.OrganizacionID != 0 && organizacionDestino.TipoOrganizacion != null && (organizacionDestino.TipoOrganizacion.TipoOrganizacionID == TipoOrganizacion.Corporativo.GetHashCode() ||
                                                                                                            organizacionDestino.TipoOrganizacion.TipoOrganizacionID == TipoOrganizacion.Ganadera.GetHashCode()))
            {
                SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.EnvioDeAlimento_MsgErrorTipoOrganizacion, MessageBoxButton.OK, MessageImage.Warning);
                skAyudaDestino.LimpiarCampos();
                return;
            }

            //validar si la organizacion destino tiene un almacen
            if (organizacionDestino != null & organizacionDestino.OrganizacionID != 0)
            {
                AlmacenPL almacenPL = new AlmacenPL();

                List <AlmacenInfo> almacenes = almacenPL.ObtenerAlmacenesPorOrganizacion(organizacionDestino.OrganizacionID);
                if (almacenes == null)
                {
                    SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.EnvioAlimento_MsgDestinoNoTieneAlmacen, MessageBoxButton.OK, MessageImage.Stop);
                    skAyudaDestino.LimpiarCampos();
                    skAyudaDestino.txtClave.Focus();
                    return;
                }
            }
            this.cmbSubFamilia.Focus();
        }
예제 #8
0
        /// <summary>
        /// Método para guardar los valores del contexto
        /// </summary>
        private void Guardar()
        {
            bool guardar = ValidaGuardar();

            if (guardar)
            {
                try
                {
                    var almacenPL = new AlmacenPL();
                    almacenPL.Guardar(Contexto);
                    SkMessageBox.Show(this, Properties.Resources.GuardadoConExito, MessageBoxButton.OK, MessageImage.Correct);
                    if (Contexto.AlmacenID != 0)
                    {
                        confirmaSalir = false;
                        Close();
                    }
                    else
                    {
                        InicializaContexto();
                    }
                }
                catch (ExcepcionGenerica)
                {
                    SkMessageBox.Show(this, Properties.Resources.Almacen_ErrorGuardar, MessageBoxButton.OK, MessageImage.Error);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                    SkMessageBox.Show(this, Properties.Resources.Almacen_ErrorGuardar, MessageBoxButton.OK, MessageImage.Error);
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Llena datos seccion ajuste de inventario e historial
        /// </summary>
        private void LlenarDatosAlmacenMovimiento()
        {
            var usuarioPL             = new UsuarioPL();
            var almacenMovimientoInfo = new AlmacenMovimientoInfo
            {
                AlmacenID           = almacenID,
                FolioMovimiento     = folioMovimiento,
                AlmacenMovimientoID = almacenMovimientoID
            };
            var almacenPL         = new AlmacenPL();
            var almacenMovimiento = almacenPL.ObtenerAlmacenMovimiento(almacenMovimientoInfo);

            if (almacenMovimiento == null)
            {
                return;
            }
            //Informacion almacen
            txtFolioInventarioFisico.Text = Convert.ToString(almacenMovimiento.FolioMovimiento);

            var tipoMovimiento = new TipoMovimientoPL();
            var resultado      = tipoMovimiento.ObtenerPorID(almacenMovimiento.TipoMovimientoID);

            if (resultado != null)
            {
                txtTipoMovimiento.Text = resultado.Descripcion;
            }

            //Fecha actual
            var fechaActual = DateTime.Now;

            txtFecha.Text = fechaActual.ToString("dd'/'MM'/'yyyy' 'hh':'mm  tt", CultureInfo.InvariantCulture);
            //Obtener descripcion de estatus
            var ajusteDeInventarioPL = new AjusteDeInventarioPL();
            var estatusInfo          = ajusteDeInventarioPL.ObtenerEstatusInfo(almacenMovimiento);

            if (estatusInfo != null)
            {
                txtEstado.Text = estatusInfo.Descripcion;
            }

            //Usuarios creacion y modificacion
            var usuario = usuarioPL.ObtenerPorID(almacenMovimiento.UsuarioCreacionID);

            if (usuario != null)
            {
                txtCreadoPor.Text = usuario.Nombre;
            }

            txtModificadoPor.Text       = nombreUsuario;
            txtUltimaActualizacion.Text = fechaActual.ToString("dd'/'MM'/'yyyy' 'hh':'mm  tt", CultureInfo.InvariantCulture);

            //Fecha creacion y modificacion
            //var fechaVal = new DateTime(1492, 10, 12);
            var fechaCreacion = almacenMovimiento.FechaCreacion;

            txtFechaCreacion.Text = fechaCreacion.ToString("dd'/'MM'/'yyyy' 'hh':'mm  tt", CultureInfo.InvariantCulture);
        }
예제 #10
0
        public static IList <AlmacenInventarioInfo> ObtenerProductosPorAlmacen(int idAlmacen)
        {
            IList <AlmacenInventarioInfo> listaAlmacenInventario = null;

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

                if (seguridad != null)
                {
                    var almacenInventarioPl = new AlmacenInventarioPL();
                    var almacenPl           = new AlmacenPL();

                    AlmacenInfo almacen = almacenPl.ObtenerPorID(idAlmacen);

                    OrganizacionInfo organizacion = seguridad.Usuario.Organizacion;

                    listaAlmacenInventario = almacenInventarioPl.ObtienePorAlmacenIdLlenaProductoInfo(almacen);

                    if (listaAlmacenInventario != null && listaAlmacenInventario.Count > 0)
                    {
                        listaAlmacenInventario = (from productos in listaAlmacenInventario
                                                  where productos.Producto != null
                                                  orderby productos.Producto.Descripcion
                                                  select productos).ToList();

                        if (almacen.TipoAlmacen.TipoAlmacenID == (int)TipoAlmacenEnum.PlantaDeAlimentos)
                        {
                            listaAlmacenInventario = (from productos in listaAlmacenInventario
                                                      where productos.Producto.SubFamilia.SubFamiliaID != (int)SubFamiliasEnum.AlimentoFormulado
                                                      orderby productos.Producto.Descripcion
                                                      select productos).ToList();
                        }
                    }
                }
                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(listaAlmacenInventario);
        }
예제 #11
0
        private void ValidarExistenciaProductosAlmacen()
        {
            int  productoID       = Contexto.ProductoId;
            var  almacenPL        = new AlmacenPL();
            bool tieneExistencias = almacenPL.ValidarExistenciasProductoEnAlmacen(productoID);

            if (tieneExistencias)
            {
                SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.ProductoEdicion_MsgProductosAlmacen, MessageBoxButton.OK,
                                  MessageImage.Warning);
                BloquearDesbloquearModificacion(false);
            }
        }
        /// <summary>
        /// Obtiene el almacén general que tenga configurado
        /// el usuario.
        /// </summary>
        private static AlmacenInfo ObtenerAlmacenGenerarl(int organizacionId)
        {
            var                 almacenDaL  = new AlmacenPL();
            AlmacenInfo         almacenInfo = null;
            IList <AlmacenInfo> almacenes   = almacenDaL.ObtenerAlmacenPorOrganizacion(organizacionId);

            if (almacenes != null && almacenes.Count > 0)
            {
                almacenInfo = almacenes.FirstOrDefault(a => a.TipoAlmacenID == (int)TipoAlmacenEnum.GeneralGanadera &&
                                                       a.Activo == EstatusEnum.Activo);
            }
            return(almacenInfo);
        }
예제 #13
0
        public void AlmacenListas()
        {
            var         pl = new AlmacenPL();
            AlmacenInfo info;

            try
            {
                info = pl.ObtenerPorID(1);
            }
            catch (Exception)
            {
                info = null;
            }
            Assert.AreNotEqual(info, null);
        }
예제 #14
0
 public static List <AlmacenesCierreDiaInventarioPAModel> ObtenerAlmacenes()
 {
     try
     {
         var seguridad = (SeguridadInfo)ObtenerSeguridad();
         var almacenPL = new AlmacenPL();
         List <AlmacenesCierreDiaInventarioPAModel> listaAlmacen =
             almacenPL.ObtenerAlmacenesOrganizacion(seguridad.Usuario.Organizacion.OrganizacionID);
         List <AlmacenesCierreDiaInventarioPAModel> listaFiltrada =
             listaAlmacen.Where(tipo => AlmacenesValidos.Contains(tipo.TipoAlmacenID)).ToList();
         return(listaFiltrada);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw;
     }
 }
예제 #15
0
        /// <summary>
        /// Obtiene la lista para mostrar en el grid
        /// </summary>
        private void ObtenerListaAlmacenUsuario(int inicio, int limite)
        {
            try
            {
                if (ucPaginacion.ContextoAnterior != null)
                {
                    bool contextosIguales = ucPaginacion.CompararObjetos(Contexto, ucPaginacion.ContextoAnterior);
                    if (!contextosIguales)
                    {
                        ucPaginacion.Inicio = 1;
                        inicio = 1;
                    }
                }

                //var almacenUsuarioBL = new AlmacenUsuarioBL();
                var almacenPL = new AlmacenPL();
                AlmacenUsuarioInfo filtros = ObtenerFiltros();
                var pagina = new PaginacionInfo {
                    Inicio = inicio, Limite = limite
                };
                ResultadoInfo <AlmacenInfo> resultadoInfo = almacenPL.ObtenerPorPagina(pagina, filtros.Almacen);
                if (resultadoInfo != null && resultadoInfo.Lista != null &&
                    resultadoInfo.Lista.Count > 0)
                {
                    gridDatos.ItemsSource       = resultadoInfo.Lista;
                    ucPaginacion.TotalRegistros = resultadoInfo.TotalRegistros;
                }
                else
                {
                    ucPaginacion.TotalRegistros = 0;
                    ucPaginacion.AsignarValoresIniciales();
                    gridDatos.ItemsSource = new List <AlmacenUsuario>();
                }
            }
            catch (ExcepcionGenerica)
            {
                SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.AlmacenUsuario_ErrorBuscar, MessageBoxButton.OK, MessageImage.Error);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal], Properties.Resources.AlmacenUsuario_ErrorBuscar, MessageBoxButton.OK, MessageImage.Error);
            }
        }
 public static List <ProduccionFormulaInfo> ResumenDeProduccion()
 {
     //List<ProduccionFormulaInfo> ProduccionFormulaLista = new List<ProduccionFormulaInfo>();
     //ProduccionFormulaLista = HttpContext.Current.Session["lista"] as List<ProduccionFormulaInfo>;
     if (ListaGlobal != null)
     {
         var almacenPl = new AlmacenPL();
         var almacenes = almacenPl.ObtenerAlmacenPorTiposAlmacen(new List <TipoAlmacenEnum>()
         {
             TipoAlmacenEnum.PlantaDeAlimentos
         }, new OrganizacionInfo
         {
             OrganizacionID = ListaGlobal[0].Organizacion.OrganizacionID
         });
         ListaGlobal[0].Almacen = almacenes.FirstOrDefault();
         var produccionFormulaPl = new ProduccionFormulaPL();
         ListaGlobal = produccionFormulaPl.ResumenProduccionFormulaLista(ListaGlobal);
     }
     return(ListaGlobal);
 }
예제 #17
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);
        }
예제 #18
0
        public static List <AlmacenInfo> ObtenerAlmacenes()
        {
            List <AlmacenInfo> listaAlmacen = null;

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

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

                    List <TipoAlmacenEnum> tiposAlmacen = new List <TipoAlmacenEnum>();
                    tiposAlmacen.Add(TipoAlmacenEnum.MateriasPrimas);
                    tiposAlmacen.Add(TipoAlmacenEnum.BodegaDeTerceros);
                    tiposAlmacen.Add(TipoAlmacenEnum.PlantaDeAlimentos);
                    tiposAlmacen.Add(TipoAlmacenEnum.BodegaExterna);

                    OrganizacionInfo organizacion = seguridad.Usuario.Organizacion;

                    listaAlmacen = almacenPl.ObtenerAlmacenPorTiposAlmacen(tiposAlmacen, organizacion);
                }
                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(listaAlmacen);
        }
예제 #19
0
        /// <summary>
        /// Cargar Campos
        /// </summary>
        private void CargarCampos()
        {
            var almacenPl            = new AlmacenPL();
            var almacenId            = (int)CboAlmacenes.SelectedValue;
            var cierreInventarioInfo = new AlmacenCierreDiaInventarioInfo
            {
                Almacen = new AlmacenInfo()
                {
                    AlmacenID = almacenId
                },
                OrganizacionId = organizacionId,
                TipoMovimiento = (int)TipoMovimiento.InventarioFisico
            };
            var resultadoAlmacenes = almacenPl.ObtenerDatosAlmacenInventario(cierreInventarioInfo);

            if (resultadoAlmacenes != null)
            {
                txtFolio.Text         = (resultadoAlmacenes.FolioAlmacen).ToString(CultureInfo.InvariantCulture);
                txtEstatus.Text       = EstatusInventario.Nuevo.ToString();
                dtpFecha.SelectedDate = DateTime.Now;
            }
        }
예제 #20
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);
            }
        }
        private void CargarCboAlmacenes()
        {
            AlmacenPL almacenPl = new AlmacenPL();

            listaAlmacenInfo = almacenPl.ObtenerAlmacenPorUsuario(usuarioID, organizacionId);
        }
        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);
            }
        }
예제 #23
0
        /// <summary>
        /// Metodo que valida los datos para guardar
        /// </summary>
        /// <returns></returns>
        private bool ValidaGuardar()
        {
            bool   resultado = true;
            string mensaje   = string.Empty;

            try
            {
                if (string.IsNullOrWhiteSpace(txtAlmacenID.Text))
                {
                    resultado = false;
                    mensaje   = Properties.Resources.AlmacenEdicion_MsgAlmacenIDRequerida;
                    txtAlmacenID.Focus();
                }
                else if (string.IsNullOrWhiteSpace(Contexto.Descripcion))
                {
                    resultado = false;
                    mensaje   = Properties.Resources.AlmacenEdicion_MsgDescripcionRequerida;
                    txtDescripcion.Focus();
                }
                else if (string.IsNullOrWhiteSpace(Contexto.CodigoAlmacen))
                {
                    resultado = false;
                    mensaje   = Properties.Resources.AlmacenEdicion_MsgCodigoAlmacenRequerida;
                    txtCodigoAlmacen.Focus();
                }
                else if (Contexto.Organizacion == null || Contexto.Organizacion.OrganizacionID == 0)
                {
                    resultado = false;
                    mensaje   = Properties.Resources.AlmacenEdicion_MsgOrganizacionIDRequerida;
                    skAyudaOrganizacion.AsignarFoco();
                }

                else if (Contexto.TipoAlmacen.TipoAlmacenID == 0)
                {
                    resultado = false;
                    mensaje   = Properties.Resources.AlmacenEdicion_MsgTipoAlmacenIDRequerida;
                    cmbTipoAlmacen.Focus();
                }
                else if (validaProveedor && (Contexto.Proveedor == null || Contexto.Proveedor.ProveedorID == 0))
                {
                    resultado = false;
                    mensaje   = Properties.Resources.AlmacenEdicion_MsgProveedorRequerido;
                    skAyudaProveedor.AsignarFoco();
                }
                else if (cmbActivo.SelectedItem == null)
                {
                    resultado = false;
                    mensaje   = Properties.Resources.AlmacenEdicion_MsgActivoRequerida;
                    cmbActivo.Focus();
                }
                else if (validaProveedor)
                {
                    if (Contexto.AlmacenID == 0 && Contexto.Proveedor != null && Contexto.Proveedor.ProveedorID > 0)
                    {
                        var proveedorAlmacenPL   = new ProveedorAlmacenPL();
                        var proveedorAlmacenInfo = new ProveedorAlmacenInfo
                        {
                            Proveedor = Contexto.Proveedor,
                            Almacen   = new AlmacenInfo
                            {
                                TipoAlmacenID = Contexto.TipoAlmacen.TipoAlmacenID
                            },
                            Activo = EstatusEnum.Activo
                        };
                        ProveedorAlmacenInfo proveedorAlmacen =
                            proveedorAlmacenPL.ObtenerPorProveedorTipoAlmacen(proveedorAlmacenInfo);
                        if (proveedorAlmacen != null)
                        {
                            resultado = false;
                            mensaje   = Properties.Resources.AlmacenEdicion_MsgProveedorAlmacenExistente;
                            skAyudaProveedor.AsignarFoco();
                        }
                    }
                }
                else
                {
                    int    almacenId   = Extensor.ValorEntero(txtAlmacenID.Text);
                    string descripcion = txtDescripcion.Text;

                    var         almacenPL = new AlmacenPL();
                    AlmacenInfo almacen   = almacenPL.ObtenerPorDescripcion(descripcion);

                    if (almacen == null)
                    {
                        return(true);
                    }

                    if (almacen.TipoAlmacen.TipoAlmacenID != Contexto.TipoAlmacen.TipoAlmacenID && almacen.Organizacion.OrganizacionID == Contexto.Organizacion.OrganizacionID)
                    {
                        bool tieneProductos = almacenPL.ValidarProductosEnAlmacen(almacen);
                        if (tieneProductos)
                        {
                            mensaje   = Properties.Resources.AlmacenEdicion_MsgTipoAlmacenCambio;
                            resultado = false;
                        }
                    }

                    if ((almacenId == 0 || almacenId != almacen.AlmacenID) && almacen.Organizacion.OrganizacionID == Contexto.Organizacion.OrganizacionID)
                    {
                        resultado = false;
                        mensaje   = string.Format(
                            Properties.Resources.AlmacenEdicion_MsgDescripcionExistente, almacen.AlmacenID);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
            }

            if (!string.IsNullOrWhiteSpace(mensaje))
            {
                SkMessageBox.Show(this, mensaje, MessageBoxButton.OK, MessageImage.Warning);
            }
            return(resultado);
        }
        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);
            }
        }