public MBCategory GetMasterBudgetTotals(CountryProgramme cp) { try { List <MBCategory> mbcList = GenerateMasterBudget(cp.Currency, cp); MBCategory mbc = new MBCategory(); mbc.TotalBudget = 0; mbc.TotalCommitted = mbc.TotalPosted = mbc.RemainingBalance = mbc.CostProjection = 0; foreach (MBCategory mbCat in mbcList) { mbc.TotalBudget += mbCat.TotalBudget; mbc.TotalCommitted += mbCat.TotalCommitted; mbc.TotalPosted += mbCat.TotalPosted; mbc.RemainingBalance += mbCat.RemainingBalance; mbc.CostProjection += mbCat.CostProjection; } mbc.PercentageSpent = (float?)(mbc.TotalPosted / mbc.TotalBudget) * 100; mbc.Surplus = mbc.RemainingBalance - mbc.CostProjection; return(mbc); } catch (Exception ex) { return(null); } }
public void LoadSessionData(CountryProgramme countryProg, Staff currentStaff) { //if (SessionData.CurrentSession.GoodsReceivedNoteList == null) SessionData.CurrentSession.GoodsReceivedNoteList = gRNService.GetGRNs(countryProg.Id); //if (SessionData.CurrentSession.WarehouseList == null) SessionData.CurrentSession.WarehouseList = wareHouseService.GetAllWareHouse(countryProg.Id); //if (SessionData.CurrentSession.InventoryList == null) SessionData.CurrentSession.InventoryList = inventoryService.GetInventory(countryProg.Id); //if (SessionData.CurrentSession.AssetList == null) SessionData.CurrentSession.AssetList = inventoryService.GetAssets(countryProg.Id); }
public AdminBaseController(IUserContext userContext) { this.userContext = userContext; if (userContext.CurrentUser != null) { countryProg = userContext.CurrentUser.Staff.CountrySubOffice.CountryProgramme; currentUser = userContext.CurrentUser; mbCurrency = countryProg.Currency; currentStaff = currentUser.Staff; ViewBag.LoggedInUser = currentStaff.Person.FirstName + " " + currentStaff.Person.OtherNames; ViewBag.CountryProgramme = countryProg.ProgrammeName; ViewBag.CountryProg = countryProg.ShortName; } }
public MasterBudgetCategory GetMasterBudgetCategoryByNumber(string number, CountryProgramme cp) { try { using (var context = new SCMSEntities()) { return(context.MasterBudgetCategories.FirstOrDefault(m => m.Number == number && m.CountryProgrammeId == cp.Id)); } } catch (Exception ex) { return(null); } }
public List <ProjectDonor> GetProjectDonors(CountryProgramme prog) { try { using (var context = SCMSEntities.Define()) { return(context.ProjectDonors.Where(p => p.Project.CountryProgrammeId == prog.Id).ToList()); } } catch (Exception ex) { return(new List <ProjectDonor>()); } }
/// <summary> /// /// </summary> /// <param name="id"></param> /// <returns></returns> public bool DeleteCountryProgramme(Guid id) { bool isDeleted = false; using (var dbContext = new SCMSEntities()) { CountryProgramme countryProg = dbContext.CountryProgrammes.Single(c => c.Id.Equals(id)); dbContext.CountryProgrammes.Remove(countryProg); if (dbContext.SaveChanges() > 0) { isDeleted = true; } } return(isDeleted); }
public List <MasterBudgetCategory> GetMasterBudgetCategories(CountryProgramme cp) { try { using (var context = new SCMSEntities()) { var mbcList = context.MasterBudgetCategories.Include("GeneralLedgers").Where(mb => mb.CountryProgrammeId == cp.Id).ToList(); mbcList = SCMS.Utils.BudgetLineSorter.SortMBCategory(mbcList); return(mbcList); } } catch (Exception ex) { return(new List <MasterBudgetCategory>()); } }
/// <summary> /// /// </summary> /// <param name="countryProg"></param> /// <returns></returns> public bool EditCountryProgramme(CountryProgramme countryProg) { bool isSaved = false; using (var context = new SCMSEntities()) { context.CountryProgrammes.Attach(countryProg); ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(countryProg, System.Data.EntityState.Modified); if (context.SaveChanges() > 0) { isSaved = true; } } return(isSaved); }
public List <GeneralLedger> GetMasterBudgetGLs(CountryProgramme cp) { try { using (var context = new SCMSEntities()) { var glList = context.GeneralLedgers.Include("MasterBudgetCategory").Where(mb => mb.MasterBudgetCategory.CountryProgrammeId == cp.Id).ToList(); glList = SCMS.Utils.BudgetLineSorter.SortGLMBCategory(glList); return(glList); } } catch (Exception ex) { return(new List <GeneralLedger>()); } }
public List <MasterBudgetCategory> GetMBCListNotProjected(CountryProgramme cp) { try { using (var context = new SCMSEntities()) { var mbcList = context.MasterBudgetCategories.Where(m => m.CountryProgrammeId == cp.Id && m.AnnualCostProjections.Count == 0).ToList(); mbcList = SCMS.Utils.BudgetLineSorter.SortMBCategory(mbcList); return(mbcList); } } catch (Exception ex) { return(new List <MasterBudgetCategory>()); } }
public string GenerateUniquNumber(CountryProgramme cp) { string code = "PO/DRC/" + cp.Country.ShortName + "/"; string refNumber = ""; long count = 1; using (var dbContext = new SCMSEntities()) { var total = dbContext.PurchaseOrders.Where(p => p.CountryProgrammeId == cp.Id && p.IsSubmitted == true).Count(); //Model.PurchaseOrder m = dbContext.PurchaseOrders.OrderByDescending(p => p.RecordCount).FirstOrDefault(); //if (m != null) // count = m.RecordCount + 1; count = total; Model.PurchaseOrder m = null; do { count++; if (count < 100000) { if (count < 10) { refNumber = code + "0000" + count; } if (count < 100 & count >= 10) { refNumber = code + "000" + count; } if (count < 1000 & count >= 100) { refNumber = code + "00" + count; } if (count < 10000 & count >= 1000) { refNumber = code + "0" + count; } if (count < 100000 && count >= 10000) { refNumber = code + count; } } m = dbContext.PurchaseOrders.FirstOrDefault(p => p.RefNumber == refNumber); } while (m != null); return(refNumber); } }
public List<ProjectDonor> GetExpiredProjectDonors(CountryProgramme cp) { List<ProjectDonor> projects = new List<ProjectDonor>(); using (var context = new SCMSEntities()) { projects = context.ProjectDonors.Where(c => c.Project.CountryProgrammeId == cp.Id && c.EndDate < DateTime.Today).OrderBy(c => c.Project.Name).ToList<ProjectDonor>(); //dot the related entities 'coz they will be accessed in the view foreach (ProjectDonor pd in projects) { Project p = pd.Project; Donor d = pd.Donor; Currency c = pd.Currency; Person person = pd.Staff.Person; List<BudgetCategory> bcs = pd.BudgetCategories.ToList(); } } return projects; }
/// <summary> /// /// </summary> /// <param name="countryProg"></param> /// <returns></returns> public bool AddCountryProgramme(CountryProgramme countryProg) { bool isSaved = false; if (countryProg.Id.Equals(Guid.Empty)) { countryProg.Id = Guid.NewGuid(); } using (var dbContext = new SCMSEntities()) { dbContext.CountryProgrammes.Add(countryProg); if (dbContext.SaveChanges() > 0) { isSaved = true; } } return(isSaved); }
public string GenerateUniquNumber(CountryProgramme cp) { string code = "OR/DRC/" + cp.Country.ShortName + "/"; string refNumber = ""; long count = 1; using (var dbContext = new SCMSEntities()) { var total = SessionData.CurrentSession.OrderRequestList.Where(p => p.IsSubmitted).Count(); count = total; Model.OrderRequest m = null; do { count++; if (count < 100000) { if (count < 10) { refNumber = code + "0000" + count; } if (count < 100 && count >= 10) { refNumber = code + "000" + count; } if (count < 1000 && count >= 100) { refNumber = code + "00" + count; } if (count < 10000 && count >= 1000) { refNumber = code + "0" + count; } if (count < 100000 && count >= 10000) { refNumber = code + count; } } m = SessionData.CurrentSession.OrderRequestList.FirstOrDefault(p => p.RefNumber == refNumber); } while (m != null); return(refNumber); } }
public string GenerateUniquNumber(CountryProgramme cp) { string code = "RFP/DRC/" + cp.Country.ShortName + "/"; string refNumber = ""; long count = 1; using (var dbContext = new SCMSEntities()) { var total = dbContext.PaymentRequests.Where(p => p.CountryProgrammeId == cp.Id && p.IsSubmitted == true).Count(); count = total; Model.PaymentRequest m = null; do { count++; if (count < 100000) { if (count < 10) { refNumber = code + "0000" + count; } if (count < 100 & count >= 10) { refNumber = code + "000" + count; } if (count < 1000 & count >= 100) { refNumber = code + "00" + count; } if (count < 10000 & count >= 1000) { refNumber = code + "0" + count; } if (count < 100000 && count >= 10000) { refNumber = code + count; } } m = dbContext.PaymentRequests.FirstOrDefault(p => p.RefNumber == refNumber); } while (m != null); return(refNumber); } }
public List <AnnualCostProjection> GetMBProjections(CountryProgramme cp) { try { using (var context = new SCMSEntities()) { var acpList = context.AnnualCostProjections.Where(a => a.CountryProgrammeId == cp.Id).ToList(); foreach (var acp in acpList) { var curr = acp.Currency; var mb = acp.MasterBudgetCategory; } return(acpList); } } catch (Exception ex) { return(new List <AnnualCostProjection>()); } }
public List <MBCategory> GenerateMasterBudget(Currency currency, CountryProgramme cp) { List <MBCategory> mbCategories = new List <MBCategory>(); MBCategory mbc; List <MasterBudgetProject> mbpList; try { List <ProjectDonor> projectDonors = projectService.GetCurrentProjectDonors(cp); List <MasterBudgetCategory> budgetCategories = GetMasterBudgetCategories(cp); foreach (MasterBudgetCategory budgetCategory in budgetCategories) { mbpList = InitMasterBudgetProjects(budgetCategory, projectDonors, currency); if (mbpList.Count > 0) { mbc = new MBCategory(); mbc.EntityBudgetCategory = budgetCategory; mbc.TotalBudget = mbpList[0].TotalBudget; mbc.TotalCommitted = mbpList[0].TotalCommitted; mbc.TotalPosted = mbpList[0].TotalPosted; for (int i = 1; i < mbpList.Count; i++) { mbc.TotalBudget += mbpList[i].TotalBudget; mbc.TotalCommitted += mbpList[i].TotalCommitted; mbc.TotalPosted += mbpList[i].TotalPosted; } mbc.RemainingBalance = mbc.TotalBudget - mbc.TotalCommitted - mbc.TotalPosted; mbc.PercentageSpent = (float?)(mbc.TotalPosted / mbc.TotalBudget) * 100; mbc.CostProjection = GetMBCategoryProjection(mbc.EntityBudgetCategory.Id, cp.Id, currency); mbc.Surplus = mbc.RemainingBalance - mbc.CostProjection; mbc.Projects = mbpList; mbCategories.Add(mbc); } } } catch (Exception ex) { } return(mbCategories); }
public string GenerateUniquNumber(CountryProgramme cp) { string code = "WRO/DRC/" + cp.Country.ShortName + "/"; string refNumber = ""; long count = 1; var total = SessionData.CurrentSession.ReleaseOrderList.Where(p => p.IsSubmitted == true).Count(); count = total; Model.WarehouseRelease m = null; do { count++; if (count < 100000) { if (count < 10) { refNumber = code + "0000" + count; } if (count < 100 && count >= 10) { refNumber = code + "000" + count; } if (count < 1000 && count >= 100) { refNumber = code + "00" + count; } if (count < 10000 && count >= 1000) { refNumber = code + "0" + count; } if (count < 100000 && count >= 10000) { refNumber = code + count; } } m = SessionData.CurrentSession.ReleaseOrderList.FirstOrDefault(p => p.RefNumber == refNumber); } while (m != null); return(refNumber); }
/// <summary> /// This is used mainly for ViewBudget. It calculates the numbers (totals) for each category /// </summary> /// <param name="category"></param> /// <param name="budgetLines"></param> private static void AddCategoryLinesWithNumbers(IExchangeRateService exchangeRateService, Models.Category category, List <ProjectBudget> budgetLines, Currency displayCurrency, CountryProgramme countryProg) { List <Models.BudgetLine> bsl = new List <Models.BudgetLine>(); Models.BudgetLine subLine; decimal budgetAmount; decimal? committed, posted; budgetAmount = 0; committed = posted = 0; foreach (ProjectBudget item in budgetLines) { subLine = new Models.BudgetLine(); subLine.EntityBudgetLine = item; subLine.SubLineId = item.Id; subLine.BudgetCategoryId = category.EntityBudgetCategory.Id.ToString(); subLine.BudgetCategoryNumber = category.EntityBudgetCategory.Number; subLine.TotalBudget = (decimal)exchangeRateService.GetForeignCurrencyValue(displayCurrency, item.BudgetCategory.ProjectDonor.Currency, item.TotalBudget, countryProg.Id); subLine.TotalCommitted = (decimal)exchangeRateService.GetForeignCurrencyValue(displayCurrency, item.BudgetCategory.ProjectDonor.Currency, item.TotalCommitted, countryProg.Id); subLine.TotalPosted = (decimal)exchangeRateService.GetForeignCurrencyValue(displayCurrency, item.BudgetCategory.ProjectDonor.Currency, item.TotalPosted, countryProg.Id); subLine.RemainingBalance = subLine.TotalBudget - (subLine.TotalCommitted + subLine.TotalPosted); //Sum up for category budgetAmount += subLine.TotalBudget; committed += subLine.TotalCommitted; posted += subLine.TotalPosted; bsl.Add(subLine); } category.BudgetLines = bsl; category.TotalBudget = budgetAmount; category.TotalCommitted = committed; category.TotalPosted = posted; category.RemainingBalance = budgetAmount - (committed + posted); }
public ActionResult Summary(Guid currencyId, Guid countryProgrammeId) { Dictionary <String, String> data = new Dictionary <string, string>(); Currency currency = currencyService.GetCurrency(currencyId); data.Add("{CURRENCY}", currency.Name); CountryProgramme cp = countryProgrammeSvc.GetCountryProgrammeById(countryProgrammeId); List <MBCategory> mbcList = mbService.GenerateMasterBudget(currency, cp); this.ComputeTotals(mbcList); decimal totalCommitted = 0; if (mbcList[mbcList.Count - 1].TotalCommitted.HasValue) { totalCommitted = (decimal)mbcList[mbcList.Count - 1].TotalCommitted; } decimal totalPosted = 0; if (mbcList[mbcList.Count - 1].TotalPosted.HasValue) { totalPosted = (decimal)mbcList[mbcList.Count - 1].TotalPosted; } decimal remBal = 0; if (mbcList[mbcList.Count - 1].RemainingBalance.HasValue) { remBal = (decimal)mbcList[mbcList.Count - 1].RemainingBalance; } float pctSpent = 0; if (mbcList[mbcList.Count - 1].PercentageSpent.HasValue) { pctSpent = (float)mbcList[mbcList.Count - 1].PercentageSpent; } decimal costP = 0; if (mbcList[mbcList.Count - 1].CostProjection.HasValue) { costP = (decimal)mbcList[mbcList.Count - 1].CostProjection; } decimal surplus = 0; string style = " style='color:red;' "; if (mbcList[mbcList.Count - 1].Surplus.HasValue) { surplus = (decimal)mbcList[mbcList.Count - 1].Surplus; } if (surplus > 0) { style = ""; } data.Add("{TOTAL_BUDGET}", mbcList[mbcList.Count - 1].TotalBudget.ToString("###,###.00")); data.Add("{TOTAL_COMMITTED}", totalCommitted.ToString("###,###.00")); data.Add("{TOTAL_POSTED}", totalPosted.ToString("###,###.00")); data.Add("{REMAINING_FUNDS}", remBal.ToString("###,###.00")); data.Add("{%_ACTUAL_SPENT}", pctSpent.ToString("0.00")); data.Add("{FUNDS_AVAILABLE}", remBal.ToString("###,###.00")); data.Add("{EXPENDITURE_PROJECTION}", costP.ToString("###,###.00")); data.Add("{SHORTFALL_SURPLUS}", "<span" + style + ">" + surplus.ToString("###,###.00") + "</span>"); string tbody = ""; for (int i = 0; i < mbcList.Count - 1; i++) { tbody += "<tr><td>"; tbody += mbcList[i].EntityBudgetCategory.Description + "</td><td>"; tbody += mbcList[i].Projects[0].EntityProjectDonor.ProjectNumber + "</td><td>"; tbody += mbcList[i].Projects[0].EntityProjectDonor.Donor.ShortName + "</td><td>"; tbody += mbcList[i].Projects[0].TotalBudget.ToString("###,###.00") + "</td><td>"; tbody += ND2S(mbcList[i].Projects[0].TotalCommitted) + "</td><td>"; tbody += ND2S(mbcList[i].Projects[0].TotalPosted) + "</td><td>"; tbody += ND2S(mbcList[i].Projects[0].RemainingBalance) + "</td><td>"; tbody += FD2S(mbcList[i].Projects[0].PercentageSpent) + "</td><td>"; tbody += ND2S(mbcList[i].CostProjection) + "</td><td>"; tbody += "</tr>"; } data.Add("{DETAIL}", tbody); List <String> options = new List <string>(); options.Add(" --orientation Landscape "); Byte[] output = WkHtml2Pdf.CreateReport(data, "master-budget.html", options); return(File(output, "application/pdf", "Project_Bu=dget_" + DateTime.Now.FormatDDMMMYYYYHHmm())); }
public ActionResult Detail(Guid currencyId, Guid countryProgrammeId) { Dictionary <String, String> data = new Dictionary <string, string>(); Currency currency = currencyService.GetCurrency(currencyId); data.Add("{CURRENCY}", currency.Name); CountryProgramme cp = countryProgrammeSvc.GetCountryProgrammeById(countryProgrammeId); List <MBCategory> mbcList = mbService.GenerateMasterBudget(currency, cp); this.ComputeTotals(mbcList); decimal totalCommitted = 0; if (mbcList[mbcList.Count - 1].TotalCommitted.HasValue) { totalCommitted = (decimal)mbcList[mbcList.Count - 1].TotalCommitted; } decimal totalPosted = 0; if (mbcList[mbcList.Count - 1].TotalPosted.HasValue) { totalPosted = (decimal)mbcList[mbcList.Count - 1].TotalPosted; } decimal remBal = 0; if (mbcList[mbcList.Count - 1].RemainingBalance.HasValue) { remBal = (decimal)mbcList[mbcList.Count - 1].RemainingBalance; } float pctSpent = 0; if (mbcList[mbcList.Count - 1].PercentageSpent.HasValue) { pctSpent = (float)mbcList[mbcList.Count - 1].PercentageSpent; } decimal costP = 0; if (mbcList[mbcList.Count - 1].CostProjection.HasValue) { costP = (decimal)mbcList[mbcList.Count - 1].CostProjection; } decimal surplus = 0; string style = " style='color:red;' "; if (mbcList[mbcList.Count - 1].Surplus.HasValue) { surplus = (decimal)mbcList[mbcList.Count - 1].Surplus; } if (surplus > 0) { style = ""; } data.Add("{TOTAL_BUDGET}", mbcList[mbcList.Count - 1].TotalBudget.ToString("###,0.00")); data.Add("{TOTAL_COMMITTED}", totalCommitted.ToString("###,0.00")); data.Add("{TOTAL_POSTED}", totalPosted.ToString("###,0.00")); data.Add("{REMAINING_FUNDS}", remBal.ToString("###,0.00")); data.Add("{%_ACTUAL_SPENT}", pctSpent.ToString("0.00")); data.Add("{FUNDS_AVAILABLE}", remBal.ToString("###,0.00")); data.Add("{EXPENDITURE_PROJECTION}", costP.ToString("###,0.00")); data.Add("{SHORTFALL_SURPLUS}", "<span" + style + ">" + surplus.ToString("###,0.00") + "</span>"); string tbody = ""; for (int i = 0; i < mbcList.Count - 1; i++) { int pCount = mbcList[i].Projects.Count; int rowSpan = 1 + pCount; tbody += "<tr><td style='vertical-align:middle;' rowspan='" + rowSpan + "'><h4>"; tbody += mbcList[i].EntityBudgetCategory.Description + "</h4></td></tr>"; for (int k = 0; k < pCount; k++) { tbody += "<tr><td class='central'>"; tbody += mbcList[i].Projects[k].EntityProjectDonor.ProjectNumber + "</td><td>"; tbody += mbcList[i].Projects[k].EntityProjectDonor.Donor.ShortName + "</td><td class='east'>"; tbody += mbcList[i].Projects[k].TotalBudget.ToString("###,0.00") + "</td><td class='east'>"; tbody += ND2S(mbcList[i].Projects[k].TotalCommitted) + "</td><td class='east'>"; tbody += ND2S(mbcList[i].Projects[k].TotalPosted) + "</td><td class='east'>"; tbody += ND2S(mbcList[i].Projects[k].RemainingBalance) + "</td><td class='east'>"; tbody += FD2S(mbcList[i].Projects[k].PercentageSpent); if (k == 0) { tbody += "</td><td class='east' style='vertical-align:middle;' rowspan='" + rowSpan + "'><b>"; tbody += WrapMinus(ND2S(mbcList[i].RemainingBalance)) + "</b></td>"; tbody += "<td class='east' style='vertical-align:middle;' rowspan='" + rowSpan + "'><b>"; tbody += WrapMinus(ND2S(mbcList[i].CostProjection)) + "</b></td>"; tbody += "<td class='east' style='vertical-align:middle;' rowspan='" + rowSpan + "'><b>"; tbody += WrapMinus(ND2S(mbcList[i].Surplus)) + "</b></td></tr>"; } else { tbody += "</td></tr>"; } } tbody += "<tr><td colspan='3'><h4 class='central'>"; tbody += mbcList[i].EntityBudgetCategory.Description + "</h4></td><td class='east'><b>"; tbody += mbcList[i].TotalBudget.ToString("###,0.00") + "</b></td><td class='east'><b>"; tbody += ND2S(mbcList[i].TotalCommitted) + "</b></td><td class='east'><b>"; tbody += ND2S(mbcList[i].TotalPosted) + "</b></td><td class='east'><b>"; tbody += WrapMinus(ND2S(mbcList[i].RemainingBalance)) + "</b></td><td class='east'><b>"; tbody += FD2S(mbcList[i].PercentageSpent) + "</b></td>"; tbody += "</tr>"; tbody += "<tr><td colspan='11'> </td></tr>"; } data.Add("{DETAIL}", tbody); data.Add("{GENERATED}", DateTime.Now.ToString("f")); List <String> options = new List <string>(); options.Add(" --orientation Landscape "); Byte[] output = WkHtml2Pdf.CreateReport(data, "master-budget.html", options); return(File(output, "application/pdf")); }
public static List <Models.Category> PrepareBudgetModel(IBudgetService budgetService, IExchangeRateService exchangeRateService, ICurrencyService currencyService, CountryProgramme countryProg, ProjectDonor pd, Currency displayCurrency) { List <Model.BudgetCategory> bcList = budgetService.GetBudgetCategories(pd); List <Model.ProjectBudget> budgetLines; List <Models.Category> categories = new List <Models.Category>(); Models.Category category; int i = 0; foreach (Model.BudgetCategory bc in bcList) { budgetLines = budgetService.GetProjectBLByCategory(pd, bc); if (budgetLines.Count > 0) { category = new Models.Category(); category.EntityBudgetCategory = bc; category.Id = bc.Id.ToString(); if (i == 0) { category.ProjectDonorId = (Guid)bc.ProjectDonorId; category.Currencies = new SelectList(currencyService.GetCurrencies(countryProg.Id), "Id", "ShortName", displayCurrency.Id); category.CurrencyId = displayCurrency.Id; } AddCategoryLinesWithNumbers(exchangeRateService, category, budgetLines, displayCurrency, countryProg); categories.Add(category); } } if (categories.Count > 0) { ComputeTotals(categories); } return(categories); }