예제 #1
0
        /*
         * helper method step 2
         */
        private List <Disbursement> GenerateDisbursementsWithUnfullfilled(List <Disbursement> targetDisbursementsList,
                                                                          DateTime collectionDate)
        {
            var unfufilledDisbursementDetails = _disbursementRepo.GetUnfulfilledDisbursementDetails().ToList();

            foreach (var ufdDetail in unfufilledDisbursementDetails)
            {
                //refactor the remaining qty from unfulfilled details into the new disbursement details
                var unfulfilledDetail         = new DisbursementDetail(ufdDetail);
                var isDisbursementForSameDept = false;
                foreach (var d in targetDisbursementsList)
                {
                    if (d.DeptCode == ufdDetail.Disbursement.DeptCode)
                    {
                        unfulfilledDetail.Stationery = ufdDetail.Stationery;
                        //depends on itemNum, add qty or add as new detail
                        d.Add(unfulfilledDetail);
                        isDisbursementForSameDept = true;
                        break;
                    }
                }

                if (isDisbursementForSameDept)
                {
                    continue;
                }

                //if not for same dept, construct a new disbursement
                var disbursement = new Disbursement(ufdDetail.Disbursement, collectionDate);
                disbursement.Add(unfulfilledDetail);
                targetDisbursementsList.Add(disbursement);
            }

            //since the remaining qty (if any) has been factored into the new disbursement details' requested qty
            //mark processed unfulfilled disbursements fulfilled, and their detail lists' requested qty to be updated to tally status

            foreach (var detail in unfufilledDisbursementDetails)
            {
                detail.RequestedQty = detail.ActualQty;
                _disbursementRepo.UpdateDisbursementDetail(detail);
            }

            var unfulfilledDisList = _disbursementRepo.GetUnfulfilledDisbursements().ToList();

            foreach (var unfd in unfulfilledDisList)
            {
                unfd.Status = DisbursementStatus.Fulfilled;
                _disbursementRepo.Update(unfd);
            }

            return(targetDisbursementsList);
        }