public bool DeleteReliefRequisitionDetail(ReliefRequisitionDetail reliefRequisitionDetail)
 {
     if (reliefRequisitionDetail == null) return false;
     _unitOfWork.ReliefRequisitionDetailRepository.Delete(reliefRequisitionDetail);
     _unitOfWork.Save();
     return true;
 }
        public static ReliefRequisitionDetailViewModel BindReliefRequisitionDetailViewModel(ReliefRequisitionDetail reliefRequisitionDetail, decimal RationAmount)
        {
            decimal? contingencyValue = 0;
            // Calculate contingency of the saved value is Null
            if (reliefRequisitionDetail != null && reliefRequisitionDetail.ReliefRequisition.RegionalRequestID != null)
            {
                if (reliefRequisitionDetail.ReliefRequisition.RegionalRequest.Contingency)
                    contingencyValue = (reliefRequisitionDetail.Amount.ToPreferedWeightUnit()*(decimal) 0.05);
            }

            return new ReliefRequisitionDetailViewModel()
            {
                Zone = reliefRequisitionDetail.ReliefRequisition.AdminUnit1.Name,
                Woreda = reliefRequisitionDetail.FDP.AdminUnit.Name,
                FDP = reliefRequisitionDetail.FDP.Name,
                Donor = reliefRequisitionDetail.DonorID.HasValue ? reliefRequisitionDetail.Donor.Name : "-",
                Commodity = reliefRequisitionDetail.Commodity.Name,
                BenficiaryNo = reliefRequisitionDetail.BenficiaryNo,
                Amount =reliefRequisitionDetail.Amount.ToPreferedWeightUnit(),
                RequisitionID = reliefRequisitionDetail.RequisitionID,
                RequisitionDetailID = reliefRequisitionDetail.RequisitionDetailID,
                CommodityID = reliefRequisitionDetail.CommodityID,
                FDPID = reliefRequisitionDetail.FDPID,
                DonorID = reliefRequisitionDetail.DonorID,
                RationAmount =RationAmount,
                Contingency = contingencyValue,
                IsContengency = reliefRequisitionDetail.ReliefRequisition.RegionalRequestID.HasValue && reliefRequisitionDetail.ReliefRequisition.RegionalRequest.Contingency,
                Total = (decimal) (reliefRequisitionDetail.Amount.ToPreferedWeightUnit() - contingencyValue)
                //_GetCommodityRation(reliefRequisitionDetail.RequisitionID,reliefRequisitionDetail.CommodityID);
               // GetCommodityRation(reliefRequisitionDetail.RequisitionID,reliefRequisitionDetail.CommodityID)

            };
        }
Esempio n. 3
0
        public static ReliefRequisitionDetailViewModel BindReliefRequisitionDetailViewModel(ReliefRequisitionDetail reliefRequisitionDetail, decimal RationAmount)
        {
            return new ReliefRequisitionDetailViewModel()
            {
                Zone = reliefRequisitionDetail.ReliefRequisition.AdminUnit1.Name,
                Woreda = reliefRequisitionDetail.FDP.AdminUnit.Name,
                FDP = reliefRequisitionDetail.FDP.Name,
                Donor = reliefRequisitionDetail.DonorID.HasValue ? reliefRequisitionDetail.Donor.Name : "-",
                Commodity = reliefRequisitionDetail.Commodity.Name,
                BenficiaryNo = reliefRequisitionDetail.BenficiaryNo,
                Amount =reliefRequisitionDetail.Amount,
                RequisitionID = reliefRequisitionDetail.RequisitionID,
                RequisitionDetailID = reliefRequisitionDetail.RequisitionDetailID,
                CommodityID = reliefRequisitionDetail.CommodityID,
                FDPID = reliefRequisitionDetail.FDPID,
                DonorID = reliefRequisitionDetail.DonorID,
                RationAmount =RationAmount,
                Contingency = (reliefRequisitionDetail.Amount * (decimal)0.05)
                //_GetCommodityRation(reliefRequisitionDetail.RequisitionID,reliefRequisitionDetail.CommodityID);
               // GetCommodityRation(reliefRequisitionDetail.RequisitionID,reliefRequisitionDetail.CommodityID)

            };
        }
        public ReliefRequisition GenerateRequisition(RegionalRequest regionalRequest, List<RegionalRequestDetail> regionalRequestDetails, int commodityId, int zoneId)
        {
            var relifRequisition = new ReliefRequisition()
            {
                //TODO:Please Include Regional Request ID in Requisition
                RegionalRequestID = regionalRequest.RegionalRequestID,
                Round = regionalRequest.Round,
                Month = regionalRequest.Month,
                ProgramID = regionalRequest.ProgramId,
                CommodityID = commodityId,
                RequestedDate = DateTime.Today

                //TODO:Please find another way how to specify Requistion No
                ,
                RequisitionNo = Guid.NewGuid().ToString(),
                RegionID = regionalRequest.RegionID,
                ZoneID = zoneId,
                Status = (int)ReliefRequisitionStatus.Draft,
                //RequestedBy =itm.RequestedBy,
                //ApprovedBy=itm.ApprovedBy,
                //ApprovedDate=itm.ApprovedDate,

            };

            foreach (var regionalRequestDetail in regionalRequestDetails)
            {
                var relifRequistionDetail = new ReliefRequisitionDetail();
                var commodity = regionalRequestDetail.RequestDetailCommodities.First(t => t.CommodityID == commodityId);
                relifRequistionDetail.DonorID = regionalRequest.DonorID;
                relifRequistionDetail.FDPID = regionalRequestDetail.Fdpid;
                relifRequistionDetail.BenficiaryNo = regionalRequestDetail.Beneficiaries;
                relifRequistionDetail.CommodityID = commodity.CommodityID;
                relifRequistionDetail.Amount = commodity.Amount;
                relifRequisition.ReliefRequisitionDetails.Add(relifRequistionDetail);
            }
            return relifRequisition;
        }
Esempio n. 5
0
        public ActionResult Allocation_Destroy([DataSourceRequest] DataSourceRequest request,
                                                  ReliefRequisitionDetail reliefRequisitionDetail)
        {
            if (reliefRequisitionDetail != null)
            {
                _reliefRequisitionDetailService.DeleteById(reliefRequisitionDetail.RequisitionDetailID);
            }

            return Json(ModelState.ToDataSourceResult());
        }
 public bool EditReliefRequisitionDetail(ReliefRequisitionDetail reliefRequisitionDetail)
 {
     _unitOfWork.ReliefRequisitionDetailRepository.Edit(reliefRequisitionDetail);
     _unitOfWork.Save();
     return true;
 }
 public ActionResult Edit(ReliefRequisition reliefrequisition,FormCollection collection)
 {
     if (ModelState.IsValid)
     {
         var requisition = _reliefRequisitionService.FindById(reliefrequisition.RequisitionID);
         if (requisition.ReliefRequisitionDetails.Count > 0)
         {
             foreach (var oldRequisitionDetail in requisition.ReliefRequisitionDetails)
             {
                 var commodityAmount = (decimal)0.00;
                 if (reliefrequisition.RationID != null)
                 {
                     var detail = oldRequisitionDetail;
                     var ration = _rationDetailService.FindBy(t => t.RationID == (int)reliefrequisition.RationID && t.CommodityID == detail.CommodityID).FirstOrDefault();
                     if (ration != null) commodityAmount = ration.Amount/1000;
                 }
                 var newRequisitionDetail = new ReliefRequisitionDetail()
                                             {
                                                 RequisitionID = oldRequisitionDetail.RequisitionID,
                                                 RequisitionDetailID = oldRequisitionDetail.RequisitionDetailID,
                                                 CommodityID = oldRequisitionDetail.CommodityID,
                                                 BenficiaryNo = oldRequisitionDetail.BenficiaryNo,
                                                 Amount = oldRequisitionDetail.BenficiaryNo * commodityAmount,
                                                 FDPID = oldRequisitionDetail.FDPID,
                                                 DonorID = oldRequisitionDetail.DonorID,
                                                 Contingency = oldRequisitionDetail.Contingency
                                             };
                 //oldRequisitionDetail.Amount = oldRequisitionDetail.BenficiaryNo*commodityAmount;
                 _reliefRequisitionDetailService.DeleteById(oldRequisitionDetail.RequisitionDetailID);
                 _reliefRequisitionDetailService.AddReliefRequisitionDetail(newRequisitionDetail);
             }
         }
         requisition.RationID = reliefrequisition.RationID;
         requisition.RequisitionNo = reliefrequisition.RequisitionNo;
         requisition.RequestedDate = reliefrequisition.RequestedDate;
         _reliefRequisitionService.EditReliefRequisition(requisition);
         return RedirectToAction("Index", "ReliefRequisition");
     }
     return View(reliefrequisition);
 }
Esempio n. 8
0
        public bool CreateRequisitonForTransfer(Transfer transfer)
        {
            if (transfer != null)
               {
               var fdp = _unitOfWork.FDPRepository.FindBy(m => m.HubID == transfer.DestinationHubID).FirstOrDefault();
               if (fdp != null)
               {
                   List<LedgerService.AvailableShippingCodes> availableSINumbers=new List<LedgerService.AvailableShippingCodes>();
                   var relifRequisition = new ReliefRequisition()
                       {

                           //RegionalRequestID = regionalRequest.RegionalRequestID,
                           //Round = regionalRequest.Round,
                           Month = transfer.CreatedDate.Month,
                           ProgramID = transfer.ProgramID,
                           CommodityID = transfer.CommodityID,
                           RequestedDate = transfer.CreatedDate,
                           //RationID = regionalRequest.RationID

                           RequisitionNo = Guid.NewGuid().ToString(),
                           RegionID = fdp.AdminUnit.AdminUnit2.AdminUnit2.AdminUnitID,
                           ZoneID = fdp.AdminUnit.AdminUnit2.AdminUnitID,
                           Status = (int) ReliefRequisitionStatus.Draft,

                       };
                   _unitOfWork.ReliefRequisitionRepository.Add(relifRequisition);

                   var relifRequistionDetail = new ReliefRequisitionDetail();

                   relifRequistionDetail.DonorID = 1;

                   relifRequistionDetail.FDPID = fdp.FDPID;

                   relifRequistionDetail.BenficiaryNo = 0; //since there is no need of benficiaryNo on transfer
                   relifRequistionDetail.CommodityID = transfer.CommodityID;
                   relifRequistionDetail.Amount = transfer.Quantity;
                   relifRequisition.ReliefRequisitionDetails.Add(relifRequistionDetail);

                   // save hub allocation
                   var hubAllocation = new HubAllocation
                       {
                           AllocatedBy = 1,
                           RequisitionID = relifRequisition.RequisitionID,
                           AllocationDate = transfer.CreatedDate,
                           ReferenceNo = "001",
                           HubID = transfer.SourceHubID
                       };
                   _unitOfWork.HubAllocationRepository.Add(hubAllocation);
                   //relifRequisition.RequisitionNo = String.Format("REQ-{0}", relifRequisition.RequisitionID);
                   relifRequisition.RequisitionNo = transfer.ReferenceNumber;
                   relifRequisition.Status = (int)ReliefRequisitionStatus.HubAssigned;
                   if(transfer.Commodity.ParentID==null)
                   {
                       availableSINumbers = GetFreeSICodesByCommodity(transfer.SourceHubID, transfer.CommodityID);
                   }
                   else
                   {
                       availableSINumbers = GetFreeSICodesByCommodityChild(transfer.SourceHubID, transfer.CommodityID);
                   }

                   var siNumberExist = availableSINumbers.Any(availableShippingCode => availableShippingCode.siCodeId == transfer.ShippingInstructionID);

                   if (!siNumberExist)
                   {
                       return false;
                   }
                   _unitOfWork.Save();

                   SIPCAllocation allocation = new SIPCAllocation
                   {
                       Code = transfer.ShippingInstructionID,
                       AllocatedAmount = transfer.Quantity,
                       AllocationType = "SI",
                       RequisitionDetailID = relifRequistionDetail.RequisitionDetailID
                   };
                   _unitOfWork.SIPCAllocationRepository.Add(allocation);

                   relifRequisition.Status = (int) ReliefRequisitionStatus.ProjectCodeAssigned;
                   relifRequisition.RequisitionNo = String.Format("REQ-{0}", relifRequisition.RequisitionID);
                   _unitOfWork.Save();
                   if (!PostSIAllocation(relifRequisition.RequisitionID,transfer.CommoditySourceID))
                   {
                       return false;
                   }
                   return true;

               }
               }
               return false;
        }