Ejemplo n.º 1
0
        public RetrievalFormPayload generateRetrievalFormFromDisbursementDuty(int disDutyId)
        {
            List <DisbursementDetail> disbursementDetails = context.DisbursementDetails
                                                            .Where(d => d.Disbursement.DisbursementDutyID == disDutyId)
                                                            .ToList();

            List <string> itemIds = disbursementDetails
                                    .Select(d => d.RequisitionDetail.ItemID)
                                    .Distinct()
                                    .ToList();

            List <Item> items = context.Items.Where(i => itemIds.Contains(i.ItemID)).ToList();

            List <RetrievalItemPayload> retrievalItems = new List <RetrievalItemPayload>();

            RetrievalItemPayload retrievalItem;

            foreach (Item item in items)
            {
                retrievalItem               = new RetrievalItemPayload();
                retrievalItem.ItemID        = item.ItemID;
                retrievalItem.QtyToRetrieve = disbursementDetails
                                              .Where(d => d.RequisitionDetail.ItemID == item.ItemID)
                                              .Sum(d => d.Quantity);
                retrievalItem.QtyInStock    = stockManagementService.getStockCountOfItem(item.ItemID);
                retrievalItem.ItemName      = item.ItemName;
                retrievalItem.UnitOfMeasure = item.UnitOfMeasure;
                retrievalItems.Add(retrievalItem);
            }

            RetrievalFormPayload retrievalFormPayload = new RetrievalFormPayload();

            retrievalFormPayload.disDutyId             = disDutyId;
            retrievalFormPayload.retrievalItemPayloads = retrievalItems;
            return(retrievalFormPayload);
        }
Ejemplo n.º 2
0
        public RetrievalFormPayload generateNewRetrievalForm(string empId)
        {
            // Get list of items to retrieve
            List <RequisitionDetail> requisitionDetails = context.RequisitionDetails
                                                          .Where(rd => rd.Requisition.ApprovalStatusID == 3)                                             // approved requisitions
                                                          .Where(rd => (rd.Requisition.RetrievalStatusID == 1 || rd.Requisition.RetrievalStatusID == 3)) // incomplete requisitions
                                                          .ToList();

            List <string> itemIds         = requisitionDetails.Select(rd => rd.ItemID).Distinct().ToList();
            List <Item>   itemsToRetrieve = context.Items.Where(i => itemIds.Contains(i.ItemID)).ToList();

            List <RetrievalItemPayload> retrievalItems = new List <RetrievalItemPayload>();

            foreach (Item item in itemsToRetrieve)
            {
                RetrievalItemPayload retrievalItem = new RetrievalItemPayload();
                retrievalItem.ItemID     = item.ItemID;
                retrievalItem.QtyInStock = stockManagementService.getStockCountOfItem(item.ItemID);
                int qtyRequested = requisitionDetails
                                   .Where(rd => rd.ItemID == item.ItemID)
                                   .Select(rd => rd.Quantity)
                                   .Sum();
                int qtyCollected = requisitionDetails
                                   .Where(rd => rd.ItemID == item.ItemID)
                                   .Select(rd => (int)rd.DisbursementDetails.Select(dd => dd.CollectedQty).Sum())
                                   .Sum();
                retrievalItem.ItemName      = item.ItemName;
                retrievalItem.UnitOfMeasure = item.UnitOfMeasure;
                retrievalItem.QtyToRetrieve = qtyRequested - qtyCollected;
                retrievalItems.Add(retrievalItem);
            }

            int disDutyId = 0;

            if (retrievalItems.Count > 0)
            {
                // Change status of requsitions to retrieveing so that they won't be
                // doubly selected for retrieval

                List <Requisition> requisitions = context.Requisitions
                                                  .Where(r => r.ApprovalStatusID == 3)
                                                  .Where(r => r.RetrievalStatusID == 1 || r.RetrievalStatusID == 3)
                                                  .ToList();

                requisitions.ForEach(r => r.RetrievalStatusID = 2);
                context.SaveChanges();

                // Assign duty to employee
                disDutyId = addDisbursementDuty(empId);

                foreach (Requisition req in requisitions)
                {
                    // Record requisitions into disbursements
                    int disId = addDisbursementFromRequisition(req.RequisitionID, disDutyId);
                    // Record requisition details into disbursement details
                    req.RequisitionDetails.ToList().ForEach(r => addDisbursementDetailFromRequsitionDetail(r.RequisitionDetailsID, disId, r.Quantity));
                }
            }

            RetrievalFormPayload retrievalFormPayload = new RetrievalFormPayload();

            retrievalFormPayload.disDutyId             = disDutyId;
            retrievalFormPayload.retrievalItemPayloads = retrievalItems;
            return(retrievalFormPayload);
        }