예제 #1
0
        public ActionResult FormRetrieve(int[] idCPs, string StartDate, string EndDate)
        {
            // Assume ClerkID
            int IdStoreClerk = (int)Session["IdEmployee"];

            //Huang Yuzhe : changing collection points function
            if (idCPs != null)
            {
                foreach (int id in idCPs)
                {
                    int tempClerkId = _employeeDAO.FindClerkIdByCPId(id);
                    if (tempClerkId == IdStoreClerk)
                    {
                        continue;
                    }
                    else
                    {
                        List <int> CPIdOfTempClerkId = _collectionpointDAO.FindByClerkId(tempClerkId);
                        List <int> CPIdOfClerkId     = _collectionpointDAO.FindByClerkId(IdStoreClerk);
                        for (int i = 0; i < CPIdOfClerkId.Count; i++)
                        {
                            bool noNeedChange = false;
                            foreach (int id2 in idCPs)
                            {
                                if (CPIdOfClerkId[i] == id2)
                                {
                                    noNeedChange = true;
                                }
                            }
                            if (noNeedChange == false)
                            {
                                //swap the collection point between two clerks
                                int temp = CPIdOfClerkId[i];
                                CPIdOfClerkId[i] = id;
                                CPIdOfTempClerkId[CPIdOfTempClerkId.IndexOf(id)] = temp;
                                _collectionpointDAO.ChangeCPTo(IdStoreClerk, CPIdOfClerkId);
                                _collectionpointDAO.ChangeCPTo(tempClerkId, CPIdOfTempClerkId);
                                break;
                            }
                        }
                    }
                }
            }
            List <int> CPs = _collectionpointDAO.FindByClerkId(IdStoreClerk);

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

            if (StartDate.Equals("") || EndDate.Equals(""))
            {
                return(RedirectToAction("FormRetrieve", "StoreClerk"));
            }
            DateTime SDate = DateTime.ParseExact(StartDate, "dd-MM-yyyy",
                                                 System.Globalization.CultureInfo.InvariantCulture);
            DateTime EDate = DateTime.ParseExact(EndDate, "dd-MM-yyyy",
                                                 System.Globalization.CultureInfo.InvariantCulture).AddDays(1);

            // Search and retrieve Requisition & Requisition Item
            List <Retrieval> RetrievalItem = _requisitionDAO
                                             .RetrieveRequisition(DClerk, SDate, EDate);
            // Check if the the RetrievalForm has been created
            // return retrieval item that have not created to disbursement and disbursementitem
            List <Retrieval> NewRetrievalItem = _disbursementDAO.CheckRetrievalFormExist(RetrievalItem, SDate);

            // New Retrieval Item is null when all IdRequisition is disbursed
            if (NewRetrievalItem.Any())
            {
                // Create Disbursement and set status to "preparing"
                List <int> IdDisbursement = _disbursementDAO.CreateDisbursement(NewRetrievalItem);
                // Create DisbursementItem and set status to "preparing"
                List <int> IdDisbursementItem = _disbursementItemDAO
                                                .CreateDisbursementItem(IdDisbursement, NewRetrievalItem);

                // Distribute stock item based on approved date given stockunit less than sum of requested unit
                _disbursementItemDAO.DisbursementItemByPriority(NewRetrievalItem);

                // Search Disbursement with status set as "preparing"
                DateTime         Today         = DateTime.Now;
                List <Retrieval> RetrievalForm = _disbursementDAO.RetrievePreparingItem(DClerk, Today, SDate);
                ViewData["RetrievalForm"]    = RetrievalForm;
                ViewData["NoDisbursement"]   = false;
                ViewData["NoNewRequisition"] = false;
                ViewBag.Today   = EndDate;
                ViewBag.LastThu = StartDate;
            }
            else
            {
                ViewData["NoDisbursement"]   = true;
                ViewData["NoNewRequisition"] = true;
                ViewBag.Today   = EndDate;
                ViewBag.LastThu = StartDate;
            }
            ViewBag.LastThu = StartDate;
            ViewBag.Today   = EndDate;
            return(View());
        }