public SalesReport(List <MLFSIncome> income, List <MLFSSale> sales, List <MLFSDebtorAdjustment> adjustments, List <MLFSBudget> budgets, MLFSAdvisor advisor, MLFSReportingPeriod period) { List <MLFSIncome> relevantIncome = income.Where(x => x.AdvisorId == advisor.Id && x.ReportingPeriodId == period.Id).ToList(); List <MLFSDebtorAdjustment> relevantAdjustments = adjustments.Where(x => x.ReportingPeriodId == period.Id && x.Debtor.AdvisorId == advisor.Id).ToList(); Organisation = advisor.Department; Period = period.Description; PeriodId = period.Id; decimal q = period.ReportOrder / 3; Quarter = period.Quarter; Advisor = advisor.Fullname; AdvisorId = advisor.Id; MLFSBudget budget = budgets.Where(x => x.AdvisorId == advisor.Id && x.ReportingPeriodId == period.Id).FirstOrDefault(); if (budget != null) { Budget = budget.Budget; } else { Budget = 0; } New_Business = sales.Where(x => x.AdvisorId == advisor.Id).Distinct().Sum(y => y.NetAmount); Renewals = relevantIncome.Where(x => !x.IsNewBusiness && !x.IsClawBack).Distinct().Sum(y => y.Amount); Unallocated = relevantIncome.Where(x => x.IsNewBusiness && !x.IsClawBack && x.MLFSDebtorAdjustment == null).Distinct().Sum(y => y.Amount); Clawback = relevantIncome.Where(x => x.IsClawBack).Distinct().Sum(y => y.Amount); NotTakenUp = relevantAdjustments.Where(x => x.NotTakenUp).Distinct().Sum(y => y.Amount); Adjustment = relevantIncome.Where(x => x.IsAdjustment).Distinct().Sum(y => y.Amount); Debtors_Adjustment = relevantAdjustments.Where(x => x.ReceiptId == null && !x.NotTakenUp && !x.IsVariance).Distinct().Sum(y => y.Amount); Debtors_Variance = relevantAdjustments.Where(x => x.IsVariance).Distinct().Sum(y => y.Amount); Total = New_Business + Adjustment + Renewals + Unallocated + Clawback + NotTakenUp + Debtors_Adjustment + Debtors_Variance; }
public void Delete(int budgetId) { MLFSBudget budget = _context.MLFSBudgets.Find(budgetId); _context.Entry(budget).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; _context.SaveChanges(); }
public async Task <IActionResult> Update(int?advisorId, int?reportingPeriodId, string value) { if (reportingPeriodId == null) { return(NotFound()); } if (advisorId == null) { return(NotFound()); } if (decimal.TryParse(value, out decimal budget)) { MLFSReportingPeriod period = await _periodData.GetPeriodById((int)reportingPeriodId); if (period == null) { return(NotFound()); } List <MLFSBudget> budgets = await _budgetData.GetBudgets(period); MLFSBudget b = budgets.Where(x => x.AdvisorId == advisorId).FirstOrDefault(); if (b == null) { b = new MLFSBudget() { AdvisorId = (int)advisorId, Budget = budget, ReportingPeriodId = period.Id }; _budgetData.Insert(b); } else { b.Budget = budget; _budgetData.Update(b); } return(Ok()); } else { return(NotFound()); } }
private List <MLFSReportingPeriod> MockEntries() { List <MLFSReportingPeriod> periods = new List <MLFSReportingPeriod>(); for (int i = 1; i < 4; i++) { MLFSReportingPeriod period = new MLFSReportingPeriod(i, 2020) { Id = i }; periods.Add(period); } MLFSAdvisor advisor = new MLFSAdvisor() { Id = 1, FirstName = "Geoff", LastName = "Smith" }; List <MLFSIncome> income = new List <MLFSIncome>(); MLFSIncome inc = new MLFSIncome() { Id = 1, IOReference = "123456", Advisor = advisor, AdvisorId = advisor.Id, Organisation = "FPP", ReportingPeriodId = periods[0].Id, ReportingPeriod = periods[0], RelevantDate = DateTime.Now, ClientOnBoardDate = DateTime.Now.AddMonths(-2), ClientId = "234", Amount = 100, PlanNumber = "9876" }; income.Add(inc); MLFSIncome inc2 = new MLFSIncome() { Id = 2, IOReference = "1234567", Advisor = advisor, AdvisorId = advisor.Id, Organisation = "MLFS", ReportingPeriodId = periods[0].Id, ReportingPeriod = periods[0], RelevantDate = DateTime.Now, ClientOnBoardDate = DateTime.Now.AddMonths(-2), ClientId = "345", Amount = 100, PlanNumber = "9877" }; income.Add(inc2); List <MLFSBudget> budgets = new List <MLFSBudget>(); MLFSBudget budget = new MLFSBudget() { Id = 9, Advisor = advisor, AdvisorId = advisor.Id, Budget = (decimal)20000, ReportingPeriodId = periods[0].Id, ReportingPeriod = periods[0] }; budgets.Add(budget); periods[0].Receipts = income; periods[0].Budgets = budgets; return(periods); }
public void Update(MLFSBudget budget) { _context.Entry(budget).State = EntityState.Modified; _context.SaveChanges(); }
public void Insert(MLFSBudget budget) { _context.MLFSBudgets.Add(budget); _context.SaveChanges(); }
public async Task <MLFSBudget> GetById(string id) { MLFSBudget budget = await _context.MLFSBudgets.FindAsync(id); return(budget); }