Ejemplo n.º 1
0
        public static List <WCFRetieve> GetAllPossibleRetrievalsForUser(string currentUser)
        {
            List <WCFRetieve> wcfList = new List <WCFRetieve>();

            using (SSISEntities context = new SSISEntities())
            {
                //Move all from allocated to retrieving automatically
                var allocated = FacadeFactory.getAllocatedService(context).getAllAllocated();
                if (allocated.Count > 0)
                {
                    foreach (var allocModel in allocated)
                    {
                        List <string> items = allocModel.Items.Select(s => s.Key.ItemCode).ToList();

                        FacadeFactory.getRequestMovementService(context).moveFromAllocatedToRetrieving(allocModel.RequestId, items, currentUser);
                    }
                }

                context.SaveChanges();

                var retrieving = FacadeFactory.getRetrievalService(context).getAllRetrievingByClerk(currentUser);

                var itemGroups = retrieving.SelectMany(sm =>
                                                       sm.Items
                                                       .Select(s => new { s.Key.ItemCode, s.Key.Description, Quantity = s.Value, sm.Department.dept_code, sm.RequestId, sm.Department.name })
                                                       ).GroupBy(k => k.ItemCode, v => v).ToList();


                foreach (var itemGroup in itemGroups)
                {
                    int itemQty = itemGroup.Select(s => s.Quantity).Aggregate((a, b) => a + b);
                    //List<int> reqIds = itemGroup.Select(s => s.RequestId).ToList();
                    WCFRetieve wcfItem = new WCFRetieve();

                    wcfItem.ItemDes  = itemGroup.First().Description;
                    wcfItem.TotalQty = itemQty.ToString();
                    wcfItem.ItemCode = itemGroup.Key;

                    wcfList.Add(wcfItem);
                }
            }

            return(wcfList);
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!User.Identity.IsAuthenticated)
            //{
            //    Response.Redirect("~/login.aspx?return=/Views/StoreClerk/DEMO_MakeRetrievalForm.aspx");
            //}

            if (IsPostBack)
            {
                return;
            }

            panelNoItems.Visible = false;
            panelNormal.Visible  = false;
            using (SSISEntities context = new SSISEntities())
            {
                //lblDebug.Text += User.Identity.Name;

                var allocated = FacadeFactory.getAllocatedService(context).getAllAllocated();
                if (allocated.Count == 0)
                {
                    panelNoItems.Visible = true;
                    return;
                }


                panelNormal.Visible = true;

                //var items = allocated.SelectMany(sm =>
                //    sm.Items.Select(s => new { s.Key.ItemCode, s.Key.Description, s.Value, sm.Department.dept_code, sm.RequestId, sm.Department.name })
                //).OrderBy(o => o.name)
                //.OrderBy(o => o.ItemCode)
                //.ToList();//.GroupBy(k => k.ItemCode, v => new { v.dept_code, v.RequestId });

                var itemGroups = allocated.SelectMany(sm =>
                                                      sm.Items
                                                      //.Where(w => w.Value > 0)
                                                      .Select(s => new { s.Key.ItemCode, s.Key.Description, s.Value, sm.Department.dept_code, sm.RequestId, sm.Department.name })
                                                      ).GroupBy(k => k.ItemCode, v => v).ToList();

                List <RetrievalFormViewModel> list = new List <RetrievalFormViewModel>();

                foreach (var itemGroup in itemGroups)
                {
                    var deptGroups = itemGroup.GroupBy(k => k.dept_code, v => v);
                    foreach (var deptGroup in deptGroups)
                    {
                        int        deptQty = deptGroup.Select(s => s.Value).Aggregate((a, b) => a + b);
                        List <int> reqIds  = deptGroup.Select(s => s.RequestId).ToList();

                        RetrievalFormViewModel model = new RetrievalFormViewModel();
                        model.ItemCode        = itemGroup.Key;
                        model.ItemDescription = itemGroup.First().Description;
                        model.DeptCode        = deptGroup.Key;
                        model.DeptName        = deptGroup.First().name;
                        model.Quantity        = deptQty;
                        model.RequestIds      = reqIds;
                        model.Include         = true;

                        list.Add(model);
                    }
                }

                Session[SESSION_ALLOC_LIST] = list;

                _refreshGrid(list);
            }
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            string currentUser = User.Identity.Name;

            SSISEntities context = new SSISEntities();

            string fullName = "";

            fullName = context.Dept_Registry.Find(currentUser).fullname;

            lblFullName.Text = "Welcome, " + fullName;

            /* Emp side Dash */
            FillPage();

            /* Items to retrieve */
            #region Items to retrieve
            /* Items for retrieving */
            var allocated = FacadeFactory.getAllocatedService(context).getAllAllocated();

            bool anyAllocated = false;

            if (allocated != null)
            {
                anyAllocated = allocated.Count > 0;

                var allocatedItems = allocated.SelectMany(sm =>
                                                          sm.Items
                                                          .Select(s => new { s.Key.ItemCode, s.Key.Description, Quantity = s.Value
                                                                                                                           //, sm.Department.dept_code, sm.RequestId, sm.Department.name
                                                                  })
                                                          )
                                     .GroupBy(k => k.ItemCode, v => v)
                                     .Select(s => s.Aggregate((a, b) => {
                    int Quantity = a.Quantity + b.Quantity;
                    return(new { a.ItemCode, a.Description, Quantity });
                })
                                             )
                                     .ToList();
                gridViewToRetrieve_FromWarehouse.DataSource = allocatedItems.Take(3);
                gridViewToRetrieve_FromWarehouse.DataBind();

                lblNumToRetrieve.Text = string.Format("({0} in total)", allocatedItems.Count);
            }


            /* Items to confirm */
            var toConfirm = FacadeFactory.getRetrievalService(context).getAllRetrievingByClerk(currentUser);

            bool anyRetrievingToConfirm = toConfirm.Count > 0;

            var toConfirmItems = toConfirm.SelectMany(sm =>
                                                      sm.Items
                                                      .Select(s => new { s.Key.ItemCode, s.Key.Description, Quantity = s.Value })
                                                      )
                                 .GroupBy(k => k.ItemCode, v => v)
                                 .Select(s => s.Aggregate((a, b) => {
                int Quantity = a.Quantity + b.Quantity;
                return(new { a.ItemCode, a.Description, Quantity });
            })
                                         )
                                 .ToList();

            gridViewToRetrieve_ToConfirm.DataSource = toConfirmItems.Take(3);
            gridViewToRetrieve_ToConfirm.DataBind();

            /* Display toggling */
            panelToRetrieve_Empty.Visible         = true;
            panelToRetrieve_FromWarehouse.Visible = true;
            panelToRetrieve_ToConfirm.Visible     = true;

            if (anyAllocated)
            {
                panelToRetrieve.CssClass      = "panel panel-info";
                panelToRetrieve_Empty.Visible = false;
            }
            else
            {
                panelToRetrieve_FromWarehouse.Visible = false;
            }

            if (anyRetrievingToConfirm)
            {
                panelToRetrieve.CssClass      = "panel panel-info";
                panelToRetrieve_Empty.Visible = false;
                lblNumToConfirm.Text          = string.Format("({0} in total)", toConfirmItems.Count);
            }
            else
            {
                panelToRetrieve_ToConfirm.Visible = false;
            }
            #endregion

            /* Disbursements */
            #region Disbursements
            /* To disburse to collection points */
            var toBeDisbursed = FacadeFactory.getDisbursementService(context).getAllPossibleDisbursements();

            bool anyToBeDisbursed = toBeDisbursed.Count > 0;

            var collectionPtIds = toBeDisbursed.SelectMany(sm =>
                                                           sm.Items
                                                           .Select(s => new { s.Key.ItemCode, s.Key.Description, s.Value, sm.Department.dept_code, sm.RequestId, sm.Department.name, sm.CollectionPtId })
                                                           )
                                  .GroupBy(k => k.CollectionPtId)
                                  .Select(s => s.Key)
                                  .ToList();

            List <Collection_Point> collectionPts = context.Collection_Point.Where(w => w.deleted != "Y" && collectionPtIds.Contains(w.collection_pt_id)).ToList();

            gridViewToDisburse_ToCollectionPt.DataSource = collectionPts.Take(3);
            gridViewToDisburse_ToCollectionPt.DataBind();

            /* To sign-off */
            DisbursementModelCollection disbursingList = FacadeFactory.getDisbursementService(context).getAllThatCanBeSignedOff(currentUser);

            bool anyToBeSignedOff = disbursingList.Count > 0;

            var toBeSignedOff = disbursingList
                                .Select(sm => sm.Department.name)
                                .Distinct()
                                .Select(s => new { DepartmentName = s })
                                .ToList();

            gridViewToDisburse_ToConfirm.DataSource = toBeSignedOff.Take(3);
            gridViewToDisburse_ToConfirm.DataBind();

            /* Display toggling */
            panelToDisburse_Empty.Visible          = true;
            panelToDisburse_ToCollectionPt.Visible = true;
            panelToDisburse_ToConfirm.Visible      = true;

            if (anyToBeDisbursed)
            {
                panelToDisburse.CssClass      = "panel panel-success";
                panelToDisburse_Empty.Visible = false;
                lblNumToDisburse.Text         = string.Format("({0} in total)", collectionPts.Count);
            }
            else
            {
                panelToDisburse_ToCollectionPt.Visible = false;
            }

            if (anyToBeSignedOff)
            {
                panelToDisburse.CssClass      = "panel panel-success";
                panelToDisburse_Empty.Visible = false;
                lblNumToSignOff.Text          = string.Format("({0} in total)", toBeSignedOff.Count);
            }
            else
            {
                panelToDisburse_ToConfirm.Visible = false;
            }
            #endregion

            /* Low Stocks */
            #region Low Stocks
            List <Stock_Inventory> stocks    = context.Stock_Inventory.ToList();
            List <ItemModel>       lowStocks = new List <ItemModel>();

            foreach (var stock in stocks)
            {
                ItemModel im = new ItemModel(stock);
                if (im.AvailableQuantity < im.ReorderLevel)
                {
                    lowStocks.Add(im);
                }
            }

            gridViewLowStocks.DataSource = lowStocks.OrderBy(o => o.AvailableQuantity).Take(5);
            gridViewLowStocks.DataBind();

            if (lowStocks.Count > 0)
            {
                panelLowStocksEmpty.Visible          = false;
                panelLowStocksNormal.Visible         = true;
                panelLowStocksBtn.Visible            = true;
                panelLowStocks.CssClass              = "panel panel-warning";
                gridViewLowStocks.HeaderRow.CssClass = "warning";
                lblNumLowStock.Text = string.Format("({0} in total)", lowStocks.Count);
            }
            else
            {
                panelLowStocksEmpty.Visible  = true;
                panelLowStocksNormal.Visible = false;
                panelLowStocksBtn.Visible    = false;
            }
            #endregion

            context.Dispose();
        }