public bool UpdateRegionalPSNPPlan(RegionalPSNPPlan item) { if (item == null) return false; _unitOfWork.RegionalPSNPPlanRepository.Edit(item); _unitOfWork.Save(); return true; }
public RegionalPSNPPlan CreatePsnpPlan(int year,int duration,int ration,int statusID ,int planID, int userId) { var psnp = new RegionalPSNPPlan() { PlanId = planID, Year = year, Duration = duration, RationID = ration, StatusID = statusID, User = userId }; _unitOfWork.RegionalPSNPPlanRepository.Add(psnp); _unitOfWork.Save(); return psnp; }
public ActionResult Create(RegionalPSNPPlan regionalpsnpplan) { //regionalpsnpplan.StatusID = 1; //check if this psnp plan exitsts for this region var exists = _regionalPSNPPlanService.DoesPsnpPlanExistForThisRegion(regionalpsnpplan.PlanId); if (ModelState.IsValid) { if (!exists) { int BP_PSNP = _ApplicationSettingService.getPSNPWorkflow(); if (BP_PSNP != 0) { BusinessProcessState createdstate = new BusinessProcessState { DatePerformed = DateTime.Now, PerformedBy = "System", Comment = "Created workflow for PSNP Plan" }; _regionalPSNPPlanService.AddRegionalPSNPPlan(regionalpsnpplan); _planService.ChangePlanStatus(regionalpsnpplan.PlanId); BusinessProcess bp = _BusinessProcessService.CreateBusinessProcess(BP_PSNP, regionalpsnpplan. RegionalPSNPPlanID, "PSNP", createdstate); regionalpsnpplan.StatusID = bp.BusinessProcessID; _regionalPSNPPlanService.UpdateRegionalPSNPPlan(regionalpsnpplan); return RedirectToAction("Index"); } ViewBag.ErrorMessage1 = "The workflow assosiated with PSNP planning doesnot exist."; ViewBag.ErrorMessage2 = "Please make sure the workflow is created and configured."; } LoadLookups(); ModelState.AddModelError("Errors", "PSNP plan already made for this period."); return View(regionalpsnpplan); } LoadLookups(); return View(regionalpsnpplan); }
public bool AddRegionalPSNPPlan(RegionalPSNPPlan item) { _unitOfWork.RegionalPSNPPlanRepository.Add(item); _unitOfWork.Save(); return true; }
public ActionResult Create(RegionalPSNPPlan regionalpsnpplan) { var planName = regionalpsnpplan.Plan.PlanName; var startDate = regionalpsnpplan.Plan.StartDate; var firstDayOfTheMonth = startDate.AddDays(1 - startDate.Day); var endDate = firstDayOfTheMonth.AddMonths(regionalpsnpplan.Duration).AddDays(-1); UserProfile user = _userProfileService.GetUser(User.Identity.Name); if (ModelState.IsValid) { _regionalPSNPPlanService.AddPsnpPlan(planName, firstDayOfTheMonth, endDate); var plan = _planService.Get(m => m.PlanName == planName,null,"Program").FirstOrDefault(); regionalpsnpplan.Plan = plan; //check if this psnp plan exitsts for this year and Plan var exists = plan != null && _regionalPSNPPlanService.DoesPsnpPlanExistForThisRegion(plan.PlanID, regionalpsnpplan.Year); if (!exists) { int BP_PSNP = _ApplicationSettingService.getPSNPWorkflow(); if (BP_PSNP != 0) { BusinessProcessState createdstate = new BusinessProcessState { DatePerformed = DateTime.Now, PerformedBy = "System", Comment = "Created workflow for PSNP Plan" }; var psnpPlan= _regionalPSNPPlanService.CreatePsnpPlan(regionalpsnpplan.Year,regionalpsnpplan.Duration,regionalpsnpplan.RationID,regionalpsnpplan.StatusID,plan.PlanID,user.UserProfileID); //_planService.ChangePlanStatus(regionalpsnpplan.PlanId); BusinessProcess bp = _BusinessProcessService.CreateBusinessProcess(BP_PSNP, regionalpsnpplan. RegionalPSNPPlanID, "PSNP", createdstate); psnpPlan.StatusID = bp.BusinessProcessID; _regionalPSNPPlanService.UpdateRegionalPSNPPlan(psnpPlan); return RedirectToAction("Index"); } ViewBag.ErrorMessage1 = "The workflow assosiated with PSNP planning doesnot exist."; ViewBag.ErrorMessage2 = "Please make sure the workflow is created and configured."; } LoadLookups(); ModelState.AddModelError("Errors", @"PSNP plan already made for this period and plan Name."); return View(regionalpsnpplan); } LoadLookups(); return View(regionalpsnpplan); }
public void PostPSNP(RegionalPSNPPlan plan) { try { var ration = _rationService.FindBy(r => r.RationID == plan.RationID).FirstOrDefault(); _transactionService.PostPSNPPlan(plan, ration); } catch (Exception ex) { _log.Error("Error in posting psnp:",new Exception(ex.Message)); } }
public ActionResult Edit(RegionalPSNPPlan regionalpsnpplan) { if (ModelState.IsValid) { _regionalPSNPPlanService.UpdateRegionalPSNPPlan(regionalpsnpplan); return RedirectToAction("Index"); } LoadLookups(); return View(regionalpsnpplan); }
public bool UpdatePsnpPlan(int year, int duration, int ration, int statusID, int planID) { var psnp = new RegionalPSNPPlan() { PlanId = planID, Year = year, Duration = duration, RationID = ration, StatusID = statusID }; _unitOfWork.RegionalPSNPPlanRepository.Edit(psnp); _unitOfWork.Save(); return true; }
public void ShouldPostPSNPPlanTransaction() { //Act var regionalPSNPPlan = new RegionalPSNPPlan() { RegionalPSNPPlanID = 1, Year = 2014, Duration = 5, RationID = 1, StatusID = 1, PlanId = 1, RegionalPSNPPlanDetails = new List<RegionalPSNPPlanDetail>() { new RegionalPSNPPlanDetail() { RegionalPSNPPlanDetailID = 1, RegionalPSNPPlanID = 1, PlanedFDPID = 1, BeneficiaryCount = 200, FoodRatio = 3, CashRatio = 3, Item3Ratio = 0, Item4Ratio = 0 } } }; var ration = new Ration() { RationID = 1, CreatedDate = DateTime.Now, IsDefaultRation = true, RefrenceNumber = "Ration-Default", RationDetails = new List<RationDetail>() { new RationDetail() { RationDetailID = 1, RationID =1, CommodityID = 1, Amount = 20, }, new RationDetail() { RationDetailID = 2, RationID =1, CommodityID = 2, Amount = 20, } } }; var result = _accountTransactionService.PostPSNPPlan(regionalPSNPPlan, ration); //Assert Assert.IsInstanceOf<List<Models.Transaction>>(result); }
public List<Models.Transaction> PostPSNPPlan(RegionalPSNPPlan plan, Ration ration) { List<Models.Transaction> entries = new List<Models.Transaction>(); List<int> regionalBenCount = new List<int>(); for (int r = 0; r < plan.Duration; r++) { regionalBenCount.Add(0); } foreach (RegionalPSNPPlanDetail fdp in plan.RegionalPSNPPlanDetails) { for (int r = 0; r < fdp.FoodRatio; r++) { regionalBenCount[r] += (int)fdp.BeneficiaryCount; } } for (int r = 0; r < plan.Duration; r++) { int noben = regionalBenCount[r]; if (noben > 0) { Guid transactionGroupID = Guid.NewGuid(); DateTime transactionDate = DateTime.Now; foreach (RationDetail rd in ration.RationDetails) { decimal amount = rd.Amount * noben; Models.Transaction entry2 = new Models.Transaction { CommodityID = rd.CommodityID, Round = r + 1, ProgramID = TransactionConstants.Constants.PSNP_PROGRAM_ID, QuantityInUnit = amount, UnitID=1, QuantityInMT = amount, LedgerID = Cats.Models.Ledger.Constants.REQUIRMENT_DOCUMENT_PALN, // previously 200 TransactionDate = transactionDate, TransactionGroupID = transactionGroupID, PlanId = plan.PlanId, TransactionID = Guid.NewGuid(), }; Models.Transaction entry1 = new Models.Transaction { CommodityID = rd.CommodityID, Round = r + 1, ProgramID = TransactionConstants.Constants.PSNP_PROGRAM_ID, QuantityInUnit = -amount, UnitID = 1, QuantityInMT = -amount, LedgerID = Cats.Models.Ledger.Constants.REQUIRMENT_DOCUMENT, //previously 100 TransactionDate = transactionDate, TransactionGroupID = transactionGroupID, PlanId = plan.PlanId, TransactionID = Guid.NewGuid(), }; _unitOfWork.TransactionRepository.Add(entry1); _unitOfWork.TransactionRepository.Add(entry2); _unitOfWork.Save(); entries.Add(entry1); entries.Add(entry2); } plan.TransactionGroupID = transactionGroupID; _unitOfWork.RegionalPSNPPlanRepository.Edit(plan); } } return entries; }
public List<Models.Transaction> PostPSNPPlan(RegionalPSNPPlan plan, Ration ration) { List<Models.Transaction> entries = new List<Models.Transaction>(); List<int> regionalBenCount = new List<int>(); for (int r = 0; r < plan.Duration; r++) { regionalBenCount.Add(0); } foreach (RegionalPSNPPlanDetail fdp in plan.RegionalPSNPPlanDetails) { for (int r = 0; r < fdp.FoodRatio; r++) { regionalBenCount[r] += (int)fdp.BeneficiaryCount; } } for (int r = 0; r < plan.Duration; r++) { int noben = regionalBenCount[r]; if (noben > 0) { foreach (RationDetail rd in ration.RationDetails) { decimal amount = rd.Amount * noben; Models.Transaction entry2 = new Models.Transaction { CommodityID = rd.CommodityID, Round = r + 1, ProgramID = 2, QuantityInUnit = -amount, UnitID=1, QuantityInMT = -amount, LedgerID = 200 }; Models.Transaction entry1 = new Models.Transaction { CommodityID = rd.CommodityID, Round = r + 1, ProgramID = 2, QuantityInUnit = amount, UnitID = 1, QuantityInMT = amount, LedgerID = 100 }; entries.Add(entry1); entries.Add(entry2); } } } PostTransaction(entries); return entries; }
private List<BeneficiaryInfo> PSNPToRequest(RegionalPSNPPlan plan, int regionID,int month) { List<BeneficiaryInfo> benficiaries = new List<BeneficiaryInfo>(); foreach (var psnpPlan in plan.RegionalPSNPPlanDetails.Where(m=>m.StartingMonth<=month)) { List<FDP> WoredaFDPs = _unitOfWork.FDPRepository.FindBy(w => w.AdminUnitID == psnpPlan.PlanedWoredaID && w.AdminUnit.AdminUnit2.AdminUnit2.AdminUnitID == regionID); ICollection<BeneficiaryInfo> woredaBeneficiaries = (from FDP fdp in WoredaFDPs select new BeneficiaryInfo { FDPID = fdp.FDPID, FDPName = fdp.Name, Beneficiaries = 0 }) .ToList(); benficiaries.AddRange(woredaBeneficiaries); } return benficiaries; }
private List<BeneficiaryInfo> PSNPToRequest(RegionalPSNPPlan plan,int regionID) { List<BeneficiaryInfo> benficiaries = (from RegionalPSNPPlanDetail pd in plan.RegionalPSNPPlanDetails where pd.PlanedFDP.AdminUnit.AdminUnit2.AdminUnit2.AdminUnitID==regionID select new BeneficiaryInfo {FDPID = pd.PlanedFDP.FDPID, FDPName = pd.PlanedFDP.Name, Beneficiaries = pd.BeneficiaryCount}) .ToList(); return benficiaries; }