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> IncomeOnly(Upload upload) { if (upload.ReportingPeriodId == null) { return(NotFound()); } MLFSReportingPeriod period = await _periodData.GetPeriodById((int)upload.ReportingPeriodId); if (period == null) { return(NotFound()); } upload.ReportingPeriod = period; upload.ReportingPeriodId = period.Id; if (upload.Files == null || upload.Files.Count != 4) { return(NotFound()); } List <MLFSAdvisor> advisors = await _advisorData.GetAdvisors(); DataTable incomeTable = new DataTable(); foreach (IFormFile file in upload.Files) { if (file.Length > 0) { string newFilePath = Path.GetTempFileName(); using (var fileStream = new FileStream(newFilePath, FileMode.Create)) { await file.CopyToAsync(fileStream); } if (file.FileName.Contains("AdviserMonthlyFCI")) { incomeTable = Tools.ConvertCSVToDataTable(newFilePath); } } } upload.Income = MLFSIncome.CreateFromDataTable(incomeTable, advisors, period); await _incomeData.InsertList(upload.Income); List <MLFSDebtorAdjustment> adjs = MLFSSale.CheckForReceipts(upload.Sales, upload.Income); _adjustmentData.InsertList(adjs); ViewBag.Result = "Uploaded Successfully"; return(RedirectToAction("Index")); }
public async Task <IActionResult> Index(Upload upload) { if (upload.ReportingPeriodId == null) { return(NotFound()); } MLFSReportingPeriod period = await _periodData.GetPeriodById((int)upload.ReportingPeriodId); if (period == null) { return(NotFound()); } upload.ReportingPeriod = period; upload.ReportingPeriodId = period.Id; if (upload.Files == null || upload.Files.Count != 4) { return(NotFound()); } List <MLFSAdvisor> advisors = await _advisorData.GetAdvisors(); string response = await upload.CreateEntities(advisors); if (response != "Success") { return(NotFound()); } await _salesData.InsertList(upload.Sales); await _incomeData.InsertList(upload.Income); List <MLFSDebtorAdjustment> adjs = MLFSSale.CheckForReceipts(upload.Sales, upload.Income); _adjustmentData.InsertList(adjs); ViewBag.Result = "Uploaded Successfully"; return(RedirectToAction("Index")); }
public async Task <ActionResult> PostMonthlyData(IFormFile salesCSV, IFormFile planCSV, IFormFile fciCSV, string periodId) { //check we have a valid period if (periodId == null || !int.TryParse(periodId, out int pId)) { return(BadRequest()); } //Get the period we are using MLFSReportingPeriod period = await _periodData.GetPeriodById(pId); if (period == null) { return(BadRequest()); } //convert our csvs into datatables string newSalesFilePath = Path.GetTempFileName(); string newPlanFilePath = Path.GetTempFileName(); string newFCIFilePath = Path.GetTempFileName(); if (salesCSV.Length > 0) { using (var fileStream = new FileStream(newSalesFilePath, FileMode.Create)) { await salesCSV.CopyToAsync(fileStream); } } else { return(NotFound()); } if (planCSV.Length > 0) { using (var fileStream = new FileStream(newPlanFilePath, FileMode.Create)) { await planCSV.CopyToAsync(fileStream); } } else { return(NotFound()); } if (fciCSV.Length > 0) { using (var fileStream = new FileStream(newFCIFilePath, FileMode.Create)) { await fciCSV.CopyToAsync(fileStream); } } else { return(NotFound()); } DataTable feeDt = Tools.ConvertCSVToDataTable(newSalesFilePath); DataTable planDt = Tools.ConvertCSVToDataTable(newPlanFilePath); DataTable fciDt = Tools.ConvertCSVToDataTable(newFCIFilePath); //load data to database and get response await _salesData.UploadSalesForPeriod(period, feeDt, planDt); List <MLFSIncome> receipts = await _incomeData.UploadIncomeForPeriod(period, fciDt); await _incomeData.UpdateClientOnboardDate(period); //Allocate Receipts List <MLFSSale> debtors = await _salesData.GetDebtors(); List <MLFSDebtorAdjustment> adjs = MLFSSale.CheckForReceipts(debtors, receipts.Where(x => x.IncomeType.Contains("Initial")).ToList()); _adjData.InsertList(adjs); return(Ok()); }
public void CheckForReceiptsTest() { //arrange List <MLFSReportingPeriod> periods = new List <MLFSReportingPeriod>(); for (int i = 1; i < 4; i++) { MLFSReportingPeriod period = new MLFSReportingPeriod(i, 2020) { Id = i }; periods.Add(period); } List <MLFSSale> debtors = new List <MLFSSale>(); MLFSSale sale = new MLFSSale() { Id = 1, ReportingPeriodId = periods[0].Id, ReportingPeriod = periods[0], Investment = 100, NetAmount = 4, OnGoingPercentage = (decimal)0.005, RelevantDate = DateTime.Parse("01/02/2020") }; debtors.Add(sale); MLFSSale sale2 = new MLFSSale() { Id = 1, IOReference = "1234567", ReportingPeriodId = periods[1].Id, ReportingPeriod = periods[1], Investment = 1000, NetAmount = 100, OnGoingPercentage = (decimal)0.005, RelevantDate = DateTime.Parse("01/02/2020") }; debtors.Add(sale2); List <MLFSIncome> income = new List <MLFSIncome>(); MLFSIncome inc = new MLFSIncome() { Id = 1, IOReference = "123456", ReportingPeriodId = periods[2].Id, ReportingPeriod = periods[2], RelevantDate = DateTime.Now, ClientId = "234", Amount = 100, PlanNumber = "9876" }; income.Add(inc); MLFSIncome inc2 = new MLFSIncome() { Id = 2, IOReference = "1234567", ReportingPeriodId = periods[2].Id, ReportingPeriod = periods[2], RelevantDate = DateTime.Now, ClientId = "345", Amount = 90, PlanNumber = "9877" }; income.Add(inc2); //act List <MLFSDebtorAdjustment> adjs = MLFSSale.CheckForReceipts(debtors, income); //assert Assert.AreEqual(1, adjs.Count, "Incorrect number of adjustments created"); Assert.AreEqual((decimal)10, sale2.Outstanding, "Amount outstanding to sale2 not reflected"); }