Esempio n. 1
0
        public ActionResult SaveDisbursement(int[] IdItemRetrieved)
        {
            // Assume ClerkID
            int IdStoreClerk = (int)Session["IdEmployee"];

            // Get Department that seleceted same collection point as store clerk
            List <string> DClerk = _disbursementDAO.ReturnStoreClerkCP(IdStoreClerk);

            if (IdItemRetrieved.Any())
            {
                // Get IdDisbursementItem from Selecte Retrieved Item
                List <int> IdDisbursementItem = _disbursementItemDAO.GetIdByItemRetrieved(DClerk, IdItemRetrieved);
                // update disbursementitem and set status to "prepared"
                // return IdDisbursement with at lease one items have been set as "prepared"
                List <int> IdDisbursement = _disbursementItemDAO.UpdateDisbursementItem(IdDisbursementItem);
                // update disbursement and set status to "prepared"
                _disbursementDAO.UpdateDisbursement(IdDisbursement);
                // update item stock unit and available unit
                _itemDAO.UpdateItem(IdDisbursementItem);

                // update stockrecord
                _stockRecordDAO.UpdateStockRecord(IdStoreClerk, IdDisbursementItem);

                // check if stock unit is less reorder level
                bool IsLowerThanReorderLevel = _itemDAO.CheckIfLowerThanReorderLevel(IdItemRetrieved);

                if (IsLowerThanReorderLevel)
                {
                    // @Shutong: raise alert to all stockclerks, their ID are 1,2,3
                    Employee        storeclerk1 = new Employee();
                    Employee        storeclerk2 = new Employee();
                    Employee        storeclerk3 = new Employee();
                    List <Employee> clerks      = _employeeDAO.FindAllClerk();
                    if (clerks.Count >= 3)
                    {
                        storeclerk1 = clerks[0];
                        storeclerk2 = clerks[1];
                        storeclerk3 = clerks[2];
                    }

                    var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                    hub.Clients.All.receiveNotification(1);
                    hub.Clients.All.receiveNotification(2);
                    hub.Clients.All.receiveNotification(3);
                    EmailClass emailClass = new EmailClass();
                    string     message    = "The stock levels of some items are running low!";
                    _notificationChannelDAO.CreateNotificationsToGroup("Clerk", IdStoreClerk, message);
                    emailClass.SendTo(storeclerk1.Email, "SSIS System Email", message);
                    emailClass.SendTo(storeclerk2.Email, "SSIS System Email", message);
                    emailClass.SendTo(storeclerk3.Email, "SSIS System Email", message);
                }
            }
            else
            {
                return(RedirectToAction("FormRetrieve", "StoreClerk"));
            }
            return(RedirectToAction("FormRetrieve", "StoreClerk"));
        }
        public ActionResult EditDisbursementList()
        {
            string             deptId   = "";
            List <ItemRequest> new_list = new List <ItemRequest>();

            DisbursementDAO disbursementDAO = new DisbursementDAO();



            foreach (string key in Request.Form.AllKeys)
            {
                if (Convert.ToString(key) == "deptId")
                {
                    deptId = Convert.ToString(Request[key]);
                }
                else
                {
                    ItemRequest item = new ItemRequest();
                    item.ItemId    = Convert.ToString(key);
                    item.ActualQty = Convert.ToInt32(Request[key]);
                    new_list.Add(item);
                }
            }
            List <ItemRequest> old_list = disbursementDAO.GetDisburseItemsForRep(deptId);
            List <ItemRequest> list     = new List <ItemRequest>();

            foreach (var item in new_list)
            {
                foreach (var row in old_list)
                {
                    if (item.ItemId == row.ItemId)
                    {
                        if (row.ActualQty - item.ActualQty != 0)
                        {
                            item.ActualQty = row.ActualQty - item.ActualQty;
                            list.Add(item);
                        }
                    }
                }
            }
            int clerkId = (int)Session["userid"];

            disbursementDAO.UpdateDisbursement(deptId, clerkId, list);
            return(RedirectToAction("ViewDisbursementList", "StoreClerk"));
        }