예제 #1
0
        private RegionalRequest CretaeRegionalRequest(HRDPSNPPlanInfo hrdpsnpPlanInfo)
        {
            var regionalRequest = new RegionalRequest();

            regionalRequest.Status = (int)RegionalRequestStatus.Draft;
            regionalRequest.RequistionDate = DateTime.Today;
            regionalRequest.Year = hrdpsnpPlanInfo.HRDPSNPPlan.Year;

            regionalRequest.PlanID = hrdpsnpPlanInfo.HRDPSNPPlan.PlanID;

            if (hrdpsnpPlanInfo.HRDPSNPPlan.ProgramID == 2)
            {
                regionalRequest.PlanID = hrdpsnpPlanInfo.HRDPSNPPlan.PSNPPlanID;
            }

            if (hrdpsnpPlanInfo.HRDPSNPPlan.SeasonID.HasValue)
                regionalRequest.Season = hrdpsnpPlanInfo.HRDPSNPPlan.SeasonID.Value;
            regionalRequest.Month = hrdpsnpPlanInfo.HRDPSNPPlan.Month;
            regionalRequest.RegionID = hrdpsnpPlanInfo.HRDPSNPPlan.RegionID;
            regionalRequest.ProgramId = hrdpsnpPlanInfo.HRDPSNPPlan.ProgramID;
            regionalRequest.DonorID = hrdpsnpPlanInfo.HRDPSNPPlan.DonorID;
            regionalRequest.RationID = hrdpsnpPlanInfo.HRDPSNPPlan.RationID.HasValue ? hrdpsnpPlanInfo.HRDPSNPPlan.RationID.Value : _applicationSettingService.getDefaultRation();
            regionalRequest.Round = hrdpsnpPlanInfo.HRDPSNPPlan.Round;
            regionalRequest.RegionalRequestDetails = (from item in hrdpsnpPlanInfo.BeneficiaryInfos
                                                      where item.Selected == false
                                                      select new RegionalRequestDetail()
                                                                 {
                                                                     Beneficiaries = item.Beneficiaries,
                                                                     Fdpid = item.FDPID
                                                                 }).ToList();
            _regionalRequestService.AddRegionalRequest(regionalRequest);

            return regionalRequest;
        }
예제 #2
0
        private RegionalRequest CreateRegionalRequest(HRDPSNPPlanInfo hrdpsnpPlanInfo, FormCollection collection, int planid, int reasonTypeID)
        {
            int regionId = Convert.ToInt32(collection["RegionId"].ToString(CultureInfo.InvariantCulture));
            var programId = 3;

            var regionalRequest = new RegionalRequest
                                      {
                                          Status = (int) RegionalRequestStatus.Draft,
                                          RequistionDate = DateTime.Today,
                                          Year = DateTime.Now.Year,
                                          PlanID = planid,
                                          Season = 1,
                                          Month = DateTime.Now.Month,
                                          RegionID = regionId,
                                          ProgramId = programId,
                                          DonorID = null,
                                          RationID = hrdpsnpPlanInfo.HRDPSNPPlan.RationID.HasValue ? hrdpsnpPlanInfo.HRDPSNPPlan.RationID.Value : _applicationSettingService.getDefaultRation(),
                                          Round = null,
                                          IDPSReasonType = reasonTypeID,
                                          RegionalRequestDetails = (from item in hrdpsnpPlanInfo.BeneficiaryInfos
                                                                    where item.Selected == false
                                                                    select new RegionalRequestDetail()
                                                                               {
                                                                                   Beneficiaries = item.Beneficiaries,
                                                                                   Fdpid = item.FDPID
                                                                               }).ToList()
                                      };

            _regionalRequestService.AddRegionalRequest(regionalRequest);

            return regionalRequest;
        }
예제 #3
0
 public ActionResult RequestFromPlan(HRDPSNPPlanInfo psnphrdPlanInfo)
 {
     RegionalRequest req=CretaeRegionalRequest(psnphrdPlanInfo);
     var model = getRequestDetai(req.RegionalRequestID);
     ViewBag.message = "Request Created";
     return View("Details",model);
 }
예제 #4
0
 /*
 [HttpPost]
 public ActionResult New(HRDPSNPPlan hrdpsnpPlan)
 {
     if (ModelState.IsValid)
     {
         var psnphrdPlanInfo = _regionalRequestService.PlanToRequest(hrdpsnpPlan);
         return View("PreparePlan", psnphrdPlanInfo);
     }
     ViewBag.SeasonID = new SelectList(_commonService.GetSeasons(), "SeasonID", "Name");
     PopulateLookup();
     return View(hrdpsnpPlan);
 }
 */
 public ActionResult PreparePlan(HRDPSNPPlanInfo psnphrdPlanInfo)
 {
     return View(psnphrdPlanInfo);
 }
예제 #5
0
        public HRDPSNPPlanInfo PlanToRequest(HRDPSNPPlan plan)
        {
            //if (CheckDurationOfAssisstance(plan))
            //{
                HRDPSNPPlanInfo result = new HRDPSNPPlanInfo();
                List<BeneficiaryInfo> beneficiaryInfos = new List<BeneficiaryInfo>();
                result.HRDPSNPPlan = plan;
                if (plan.ProgramID == (int)Programs.PSNP)
                {
                    RegionalPSNPPlan psnpplan =
                        _unitOfWork.RegionalPSNPPlanRepository.FindBy(r => r.PlanId == plan.PSNPPlanID).FirstOrDefault();

                    if (psnpplan != null)
                    {
                        //TODO:Uncomment this (if PSNP case team Users change their mind and want to get previous request information instead of planned information)

                        var lastPsnpRequest = _unitOfWork.RegionalRequestRepository.FindBy(r => r.RegionID == plan.RegionID && r.ProgramId == (int)Programs.PSNP && r.PlanID == plan.PSNPPlanID).LastOrDefault();
                        if (lastPsnpRequest != null)
                        {
                            result.HRDPSNPPlan.RationID = psnpplan.RationID;
                            result.HRDPSNPPlan.Contingency = lastPsnpRequest.Contingency;
                            var noOfPsnprequests = _unitOfWork.RegionalRequestRepository.FindBy(r => r.RegionID == plan.RegionID && r.ProgramId == (int)Programs.PSNP && r.PlanID == plan.PSNPPlanID).Count;
                            var psnpApplicationWoredas = (from psnpDetail in psnpplan.RegionalPSNPPlanDetails
                                                          where
                                                              psnpDetail.PlanedWoreda.AdminUnit2.AdminUnit2.AdminUnitID ==
                                                              plan.RegionID
                                                              && psnpDetail.FoodRatio > noOfPsnprequests
                                                          select psnpDetail.PlanedWoredaID).ToList();
                            beneficiaryInfos = LastReliefRequest(lastPsnpRequest, psnpApplicationWoredas);
                        }
                        else
                        {
                            result.HRDPSNPPlan.RationID = psnpplan.RationID;
                            result.HRDPSNPPlan.Contingency =
                                psnpplan.RegionalPSNPPlanDetails.Any(
                                    t => t.StartingMonth == result.HRDPSNPPlan.Month && t.Contingency);
                            beneficiaryInfos = PSNPToRequest(psnpplan, plan.RegionID, plan.Month);
                        }

                    }
                }
                else if (plan.ProgramID == (int)Programs.Releif)
                {
                    HRD hrd = _unitOfWork.HRDRepository.FindBy(r => r.PlanID == plan.PlanID).LastOrDefault();

                    if (hrd != null)
                    {

                        var lastRequest =
                            _unitOfWork.RegionalRequestRepository.FindBy(
                                r => r.RegionID == plan.RegionID && r.ProgramId == (int)Programs.Releif && r.PlanID == plan.PlanID).
                                LastOrDefault();
                        if (lastRequest != null)
                        {
                            result.HRDPSNPPlan.RationID = hrd.RationID;
                            var requests =
                                _unitOfWork.RegionalRequestRepository.FindBy(
                                    r => r.RegionID == plan.RegionID && r.ProgramId == 1 && r.PlanID == plan.PlanID);
                            var numberOfRequestsPerRegion = requests.Count;
                            var applicableWoredas = (from detail in hrd.HRDDetails
                                                     where detail.AdminUnit.AdminUnit2.AdminUnit2.AdminUnitID == plan.RegionID //&& detail.DurationOfAssistance > numberOfRequestsPerRegion
                                                     select detail.WoredaID).ToList();
                            beneficiaryInfos = LastReliefRequest(lastRequest, applicableWoredas);
                            // var lastRequestDetail = LastReliefRequest(lastRequest);

                        }
                        else
                        {
                            result.HRDPSNPPlan.RationID = hrd.RationID;
                            List<HRDDetail> hrddetail =
                                (from woreda in hrd.HRDDetails
                                 where
                                     woreda.AdminUnit.AdminUnit2.AdminUnit2.AdminUnitID == plan.RegionID &&
                                     woreda.DurationOfAssistance > 0
                                 select woreda).ToList();
                            beneficiaryInfos = HRDToRequest(hrddetail);
                        }
                    }
                }
                else
                {
                    //if program is IDPS
                    List<BeneficiaryInfo> benficiaries = new List<BeneficiaryInfo>();
                    List<AdminUnit> woredas = new List<AdminUnit>();
                    var zones =
                        _unitOfWork.AdminUnitRepository.FindBy(
                            w => w.AdminUnitTypeID == 3 && w.ParentID == plan.RegionID);
                    foreach (var zone in zones)
                    {
                        AdminUnit zone1 = zone;
                        woredas.AddRange(_unitOfWork.AdminUnitRepository.FindBy(w => w.ParentID == zone1.AdminUnitID));
                    }
                    //var
                    foreach (var woreda in woredas)
                    {
                        AdminUnit woreda1 = woreda;
                        List<FDP> WoredaFDPs =
                            _unitOfWork.FDPRepository.FindBy(w => w.AdminUnitID == woreda1.AdminUnitID);
                        ICollection<BeneficiaryInfo> woredabeneficiaries =
                            (from FDP fdp in WoredaFDPs
                             select new BeneficiaryInfo { FDPID = fdp.FDPID, FDPName = fdp.Name, Beneficiaries = 0 }).
                                ToList();
                        benficiaries.AddRange(woredabeneficiaries);
                    }

                    //beneficiaryInfos = benficiaries;
                    //beneficiaryInfos = null;
                }
                result.BeneficiaryInfos = beneficiaryInfos;
                return result;
            //}
            //return null;
        }
예제 #6
0
        public HRDPSNPPlanInfo PlanToRequest(HRDPSNPPlan plan)
        {
            if (CheckDurationOfAssisstance(plan))
            {
                HRDPSNPPlanInfo result = new HRDPSNPPlanInfo();
                List<BeneficiaryInfo> beneficiaryInfos = new List<BeneficiaryInfo>();
                result.HRDPSNPPlan = plan;
                if (plan.ProgramID == 2)
                {
                    RegionalPSNPPlan psnpplan =
                        _unitOfWork.RegionalPSNPPlanRepository.FindBy(r=>r.PlanId == plan.PSNPPlanID).FirstOrDefault();

                    if (psnpplan != null)
                    {
                        result.HRDPSNPPlan.RationID = psnpplan.RationID;
                        beneficiaryInfos = PSNPToRequest(psnpplan,plan.RegionID);
                    }
                }
                else if (plan.ProgramID == 1)
                {
                    HRD hrd = _unitOfWork.HRDRepository.FindBy(r => r.PlanID == plan.PlanID).LastOrDefault();

                    var lastRequest =_unitOfWork.RegionalRequestRepository.FindBy(r => r.RegionID == plan.RegionID && r.ProgramId == 1 && r.PlanID == plan.PlanID).LastOrDefault();

                    if (lastRequest != null)
                    {
                        var requests = _unitOfWork.RegionalRequestRepository.FindBy(r => r.RegionID == plan.RegionID && r.ProgramId == 1 && r.PlanID == plan.PlanID);
                        var numberOfRequestsPerRegion = requests.Count;
                        var applicableWoredas = (from detail in hrd.HRDDetails
                                                 where
                                                     detail.AdminUnit.AdminUnit2.AdminUnit2.AdminUnitID == plan.RegionID &&
                                                     detail.DurationOfAssistance > numberOfRequestsPerRegion
                                                 select detail.WoredaID).ToList();
                        beneficiaryInfos = LastReliefRequest(lastRequest, applicableWoredas);
                       // var lastRequestDetail = LastReliefRequest(lastRequest);

                    }
                    else
                    {
                        result.HRDPSNPPlan.RationID = hrd.RationID;
                        List<HRDDetail> hrddetail =
                            (from woreda in hrd.HRDDetails
                             where woreda.AdminUnit.AdminUnit2.AdminUnit2.AdminUnitID == plan.RegionID && woreda.DurationOfAssistance>0
                             select woreda).ToList();
                        beneficiaryInfos = HRDToRequest(hrddetail);
                    }
                }
                else
                {
                    //if program is IDPS
                    List<BeneficiaryInfo> benficiaries = new List<BeneficiaryInfo>();
                    List<AdminUnit> woredas = new List<AdminUnit>();
                    var zones =
                        _unitOfWork.AdminUnitRepository.FindBy(
                            w => w.AdminUnitTypeID == 3 && w.ParentID == plan.RegionID);
                    foreach (var zone in zones)
                    {
                        AdminUnit zone1 = zone;
                        woredas.AddRange(_unitOfWork.AdminUnitRepository.FindBy(w => w.ParentID == zone1.AdminUnitID));
                    }
                    //var
                    foreach (var woreda in woredas)
                    {
                        AdminUnit woreda1 = woreda;
                        List<FDP> WoredaFDPs =
                            _unitOfWork.FDPRepository.FindBy(w => w.AdminUnitID == woreda1.AdminUnitID);
                        ICollection<BeneficiaryInfo> woredabeneficiaries =
                            (from FDP fdp in WoredaFDPs
                             select new BeneficiaryInfo {FDPID = fdp.FDPID, FDPName = fdp.Name, Beneficiaries = 0}).
                                ToList();
                        benficiaries.AddRange(woredabeneficiaries);
                    }

                    //beneficiaryInfos = benficiaries;
                    //beneficiaryInfos = null;
                }
                result.BeneficiaryInfos = beneficiaryInfos;
                return result;
            }
            return null;
        }