// GET: MLFSSales public async Task <IActionResult> Index(int?periodId, string split = "", int?advisorId = null) { MLFSReportingPeriod period; decimal large = (decimal)500.00; if (periodId == null) { period = await _periodData.GetCurrent(); } else { period = await _periodData.GetPeriodById((int)periodId); } if (period == null) { return(NotFound()); } List <MLFSIncome> income = await _incomeData.GetIncome(period, advisorId); income = income.Distinct().ToList(); if (split.ToLower() == "unallocated") { income = income.Where(x => x.MLFSDebtorAdjustment == null && x.IsNewBusiness && !x.IsClawBack).ToList(); } else if (split.ToLower() == "allocated") { income = income.Where(x => x.MLFSDebtorAdjustment != null && x.IsNewBusiness && !x.IsClawBack).ToList(); } else if (split.ToLower() == "initial") { income = income.Where(x => x.IsNewBusiness && !x.IsClawBack).ToList(); } else if (split.ToLower() == "recurring") { income = income.Where(x => !x.IsNewBusiness && !x.IsClawBack).ToList(); } else if (split.ToLower() == "adjustment") { income = income.Where(x => x.IsAdjustment && !x.IsClawBack).ToList(); } else if (split.ToLower() == "clawback") { income = income.Where(x => x.IsClawBack).ToList(); } else if (split.ToLower() == "large") { income = income.Where(x => x.Amount > large).ToList(); } return(View(income)); }
public async Task <IActionResult> CheckForMatches() { MLFSReportingPeriod period = await _periodData.GetCurrent(); List <MLFSSale> debtors = await _debtorData.GetDebtors(period); List <MLFSIncome> income = await _incomeData.GetIncome(); income = income.Where(x => x.MLFSDebtorAdjustment == null && x.IncomeType.Contains("Initial")).ToList(); List <MLFSDebtorAdjustment> adjs = MLFSSale.CheckForReceipts(debtors, income); _adjustmentData.InsertList(adjs); return(RedirectToAction("Index")); }
public async Task <IActionResult> UpdateData(int?periodId, int?saleId = null) { List <MLFSSale> sales = new List <MLFSSale>(); if (saleId == null) { if (periodId == null) { return(NotFound()); } MLFSReportingPeriod period = await _periodData.GetPeriodById((int)periodId); if (period == null) { return(NotFound()); } sales = await _salesData.GetSales(period); } else { MLFSSale soleSale = await _salesData.GetSaleById((int)saleId); sales.Add(soleSale); } for (int i = 0; i < sales.Count; i++) { MLFSSale sale = sales[i]; //only interested in clients which haven't been updated already or where we are forcing a particular line //if (saleId != null || (sale.EstimatedOtherIncome == 0)) //{ Console.WriteLine("Client: " + sale.ClientId + ":" + sale.Client + ":" + i.ToString()); MLFSClient client = await _clientData.GetClient(sale.ClientId); List <MLFSIncome> income = await _incomeData.GetIncome(client); sale.AddClientData(client, income); _salesData.Update(sale); //} } return(Ok()); }
public async Task <IActionResult> SalesReport(int?periodId, string entity = "advisor") { MLFSReportingPeriod period; List <SalesReport> report = new List <SalesReport>(); //get period if (periodId == null) { return(NotFound()); } period = await _periodData.GetPeriodById((int)periodId); if (period == null) { return(NotFound()); } //get advsiors List <MLFSAdvisor> advisors = await _advisorData.GetAdvisors(); List <MLFSIncome> income = await _incomeData.GetIncome(period); List <MLFSSale> sales = await _salesData.GetSales(period); List <MLFSDebtorAdjustment> adjs = await _adjustmentData.GetAdjustments(period); List <MLFSBudget> budgets = await _budgetData.GetBudgets(period); if (entity.ToLower() == "advisor") { foreach (MLFSAdvisor adv in advisors) { SalesReport line = new SalesReport(income, sales, adjs, budgets, adv, period); report.Add(line); } } if (entity.ToLower() == "organisation") { report = report.GroupBy(x => x.Organisation).Select(y => new ViewModels.SalesReport() { Period = y.FirstOrDefault().Period, PeriodId = y.FirstOrDefault().PeriodId, Advisor = y.Key, AdvisorId = 0, Organisation = y.Key, Budget = y.Sum(z => z.Budget), New_Business = y.Sum(z => z.New_Business), Renewals = y.Sum(z => z.Renewals), Unallocated = y.Sum(z => z.Unallocated), Clawback = y.Sum(z => z.Clawback), NotTakenUp = y.Sum(z => z.NotTakenUp), Adjustment = y.Sum(z => z.Adjustment), Debtors_Variance = y.Sum(z => z.Debtors_Variance), Debtors_Adjustment = y.Sum(z => z.Debtors_Adjustment), Total = y.Sum(z => z.Total) }).ToList(); } else if (entity.ToLower() == "campaign") { report = ViewModels.SalesReport.CreateByCampaign(income, period); } return(PartialView("_SalesReport", report.OrderBy(x => x.Advisor))); }