Example #1
0
        public JsonResult SearchReporteInsumo(string FechaDesde, string FechaHasta, string Centro, string Medicamento)
        {
            OrderReporteInsumoViewModel order = new OrderReporteInsumoViewModel();

            order = ArmarConsultaReporte(FechaDesde, FechaHasta, Centro, Medicamento);


            return(Json(order, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        private OrderReporteInsumoViewModel ArmarConsultaReporte(string FechaDesde, string FechaHasta, string Centro, string Medicamento)
        {
            int     CentroId         = 0;
            int     MedicamentoId    = 0;
            int     totalSolicitados = 0;
            int     totalEntregados  = 0;
            Usuario usuario          = db.Usuarios.Find(SessionHelper.GetUser());

            if (!String.IsNullOrEmpty(Centro))
            {
                CentroId = Convert.ToInt32(Centro);
            }

            if (!String.IsNullOrEmpty(Medicamento))
            {
                MedicamentoId = Convert.ToInt32(Medicamento);
            }


            OrderReporteInsumoViewModel order = new OrderReporteInsumoViewModel();

            order.Detalle = new List <OrderReporteInsumoDetalleViewModel>();
            DateTime?dtFechaDesde = null;
            DateTime?dtFechaHasta = null;

            if (!String.IsNullOrEmpty(FechaDesde))
            {
                dtFechaDesde = Convert.ToDateTime(FechaDesde);
            }

            if (!String.IsNullOrEmpty(FechaHasta))
            {
                dtFechaHasta = Convert.ToDateTime(FechaHasta).AddDays(1).AddTicks(-1);
            }

            List <OrderProduct> listaProducts = new List <OrderProduct>();

            try
            {
                if (!usuario.Rol.IsAdmin)
                {
                    listaProducts = db.OrderProducts.Where(x => x.Order.CenterId == usuario.CenterId && x.Order.StatusId == (int)StatusOrder.Entregado).Include(x => x.Order.Center).Include(x => x.Product).ToList();
                }
                else
                {
                    listaProducts = db.OrderProducts.Where(x => x.Order.StatusId == (int)StatusOrder.Entregado).Include(o => o.Order.Center).Include(x => x.Product).ToList();
                }

                var lista = listaProducts
                            .Where(x => !string.IsNullOrEmpty(Centro) ? (x.Order.CenterId == CentroId && x.Order.Center.Descripcion != null) : true)
                            .Where(x => !string.IsNullOrEmpty(Medicamento) ? (x.ProductId == MedicamentoId && x.Product.Descripcion != null) : true)
                            .Where(x => !string.IsNullOrEmpty(FechaDesde) ? (x.Order.InitialDate >= dtFechaDesde && x.Order.InitialDate != null) : true)
                            .Where(x => !string.IsNullOrEmpty(FechaHasta) ? (x.Order.InitialDate <= dtFechaHasta && x.Order.InitialDate != null) : true)
                            .OrderByDescending(x => x.Id);
                ;

                foreach (var item in lista)
                {
                    OrderReporteInsumoDetalleViewModel detail = new OrderReporteInsumoDetalleViewModel
                    {
                        Product           = item.Product.Descripcion,
                        Date              = item.Order.InitialDate.ToString("dd/MM/yyyy"),
                        Center            = item.Order.Center.Descripcion,
                        NroPedido         = item.Order.NroPedido,
                        Quantity          = item.Quantity,
                        QuantityDelivered = item.QuantityDelivered
                    };

                    totalSolicitados += item.Quantity;
                    totalEntregados  += item.QuantityDelivered;


                    order.Detalle.Add(detail);
                }

                order.TotalEntregados  = totalEntregados;
                order.TotalSolicitados = totalSolicitados;
            }
            catch (Exception e)
            {
                throw;
            }


            return(order);
        }