public void CalculateFeeLaFullPeriodWithFeeChangeMultipleChgInOnePeriodForCustomDates() { FeeCalculatorService srv = new FeeCalculatorService(); var schedules = getSchedules(40); var invoiceResident = new InvoiceResident(40, "John", schedules); var resident = srv.CalculateFee(invoiceResident, new DateTime(2020, 01, 01), new DateTime(2020, 03, 31)); var feesPerSchedules = resident.GetSchedules(); var amounts = feesPerSchedules.Select(c => c.AmountDue).ToArray(); var totalAmount = amounts.Sum(); // Multiple Fee changes // (40, 1, 1, new DateTime(2019, 01, 01), new DateTime(2020, 01, 10), 600.50M)); // (40, 1, 1, new DateTime(2020, 01, 11), new DateTime(2020, 01, 15), 630.90M)); // (40, 1, 1, new DateTime(2020, 01, 16), new DateTime(2050, 12, 31), 250.50M)); // (40, 99, 2, new DateTime(2019, 01, 01), new DateTime(2020, 01, 10), 150.44M)); // (40, 99, 2, new DateTime(2020, 01, 11), new DateTime(2020, 01, 15), 165.78M)); // (40, 99, 2, new DateTime(2020, 01, 16), new DateTime(2050, 12, 31), 550.58M)); // LA 600.50 CC 150.44 for 10 days // LA 630.90 CC 165.78 for 5 days // LA 250.50 CC 550.58 for 13 days 91 days Assert.AreEqual(10339.26M, totalAmount); }
// CORE function private IEnumerable <InvoiceResident> GetInvoiceResidentData(DateTime startDate, DateTime endDate) { // each resi may have multiple contributors, LA || LA and CC || LA and CC1, CC2 var schedules = this._invoiceDataProvider.GetAllSchedulesForInvoiceDate(startDate, endDate); var residents = this._residentDataProvider .GetResidents() .Where(res => res.ExitDate >= startDate && res.AdmissionDate <= endDate); // create invoiceResident var invResidents = residents.Select(r => { // find their schedules. by LA or CC or LA+CC? var _schedules = schedules.Where(s => s.ResidentId == r.Id); var _invResident = new InvoiceResident(r.Id, $"{r.ForeName} {r.SurName}", _schedules); _invResident.LocalAuthorityId = _schedules.Select(s => s.LocalAuthorityId).FirstOrDefault(); // logger.Info($"Calculate invoice amount {_invResident.Name}"); var residentsWithCalculatedFees = _feeCalculatorService.CalculateFee(_invResident, startDate, endDate); // sum LA total, LA Fee + Supliment Fee(s) // PaymentProviderId = LA=1, CC=2, PV=3 var sumWeekly = residentsWithCalculatedFees.GetSchedules() .Where(s => s.PaymentProviderId == 1).Select(k => k.AmountDue).Sum(); residentsWithCalculatedFees.TotalLaFee = sumWeekly; // get resident weekly fee (LA Fee + CC Fee) var payTypeIds = residentsWithCalculatedFees.GetSchedules().Select(s => s.PaymentTypeId).Distinct(); payTypeIds.ForEach(payId => { if (payId <= 3) // paymentTypeId 1 = La, 2 = CC 3 = Private { var wf = residentsWithCalculatedFees.GetSchedules().Where(s => s.PaymentTypeId == payId).Select(s => s.WeeklyFee).FirstOrDefault(); residentsWithCalculatedFees.ResidentWeeklyFee += wf; } }); // get GrandTotal (all amount dues) residentsWithCalculatedFees.GrandTotal = residentsWithCalculatedFees.GetSchedules() .Select(s => s.AmountDue).Sum(); // order by local auth id residentsWithCalculatedFees.SetSchedules( residentsWithCalculatedFees.GetSchedules().OrderBy(s => s.LocalAuthorityId)); // Added la div names for report purposes residentsWithCalculatedFees.LocalAuthorityName = r.LocalAuthorityName; residentsWithCalculatedFees.CareHomeDivisionId = r.CareHomeDivisionId; residentsWithCalculatedFees.CareHomeDivisionName = r.CareHomeDivisionName; return(residentsWithCalculatedFees); }).ToArray(); var result = invResidents.OrderBy(r => r.Name); return(result); }
public void CalculateFeeLaResidentArrivesMidMonth() { FeeCalculatorService srv = new FeeCalculatorService(); var schedules = getSchedules(21); var invoiceResident = new InvoiceResident(21, "John", schedules); var resident = srv.CalculateFee(invoiceResident, new DateTime(2020, 01, 01), new DateTime(2020, 01, 28)); var feesPerSchedules = resident.GetSchedules(); var amounts = feesPerSchedules.Select(c => c.AmountDue).ToArray(); var totalAmount = amounts.Sum(); // Fee = la= 678.01 // For 8 days: 774.87 Assert.AreEqual(774.87M, totalAmount); }
public void CalculateFeeLaResidentLeavesMidMonth() { FeeCalculatorService srv = new FeeCalculatorService(); var schedules = getSchedules(20); var invoiceResident = new InvoiceResident(20, "John", schedules); var resident = srv.CalculateFee(invoiceResident, new DateTime(2020, 01, 01), new DateTime(2020, 01, 28)); var feesPerSchedules = resident.GetSchedules(); var amounts = feesPerSchedules.Select(c => c.AmountDue).ToArray(); var totalAmount = amounts.Sum(); // Fee = la= 680.10 // For 15 days: 1457.36 Assert.AreEqual(1457.36M, totalAmount); }
public void CalculateFeeLaAndCcFullPeriodNoFeeChange() { FeeCalculatorService srv = new FeeCalculatorService(); var schedules = getSchedules(11); var invoiceResident = new InvoiceResident(11, "John", schedules); var resident = srv.CalculateFee(invoiceResident, new DateTime(2020, 01, 01), new DateTime(2020, 01, 28)); var feesPerSchedules = resident.GetSchedules(); var amounts = feesPerSchedules.Select(c => c.AmountDue).ToArray(); var totalAmount = amounts.Sum(); // Fee = la= 555.75M cc= 245.43M // For 28 days: 555.75+245.43 / 7 * 28 = 3204.72 Assert.AreEqual(3204.72M, totalAmount); }
public void CalculateFeeLaFullPeriodNoFeeChangeForCustomDates() { FeeCalculatorService srv = new FeeCalculatorService(); var schedules = getSchedules(10); var invoiceResident = new InvoiceResident(10, "John", schedules); var resident = srv.CalculateFee(invoiceResident, new DateTime(2020, 01, 01), new DateTime(2020, 03, 31)); // <<--quarter var feesPerSchedules = resident.GetSchedules(); var amounts = feesPerSchedules.Select(c => c.AmountDue).ToArray(); var totalAmount = amounts.Sum(); // Fee = 599.99M // For 91 days: 599.99 / 7 * 91 = 7799.87 Assert.AreEqual(7799.87M, totalAmount); }
public void CalculateFeeLaFullPeriodNoFeeChange() { FeeCalculatorService srv = new FeeCalculatorService(); // get schedules for John var schedules = getSchedules(10); var invoiceResident = new InvoiceResident(10, "John", schedules); var resident = srv.CalculateFee(invoiceResident, new DateTime(2020, 01, 01), new DateTime(2020, 01, 28)); var feesPerSchedules = resident.GetSchedules(); var amounts = feesPerSchedules.Select(c => c.AmountDue).ToArray(); var totalAmount = amounts.Sum(); // Fee = 599.99M // For 28 days: 599.99 / 7 * 28 = 2399.96 Assert.AreEqual(2399.96M, totalAmount); }
public void CalculateFeeLaFullPeriodWithFeeChange() { FeeCalculatorService srv = new FeeCalculatorService(); var schedules = getSchedules(30); var invoiceResident = new InvoiceResident(30, "John", schedules); var resident = srv.CalculateFee(invoiceResident, new DateTime(2020, 01, 01), new DateTime(2020, 01, 28)); var feesPerSchedules = resident.GetSchedules(); var amounts = feesPerSchedules.Select(c => c.AmountDue).ToArray(); var totalAmount = amounts.Sum(); // (30, 1, 1, new DateTime(2019, 01, 01), new DateTime(2020, 01, 15), 630.50M)); // (30, 1, 1, new DateTime(2020, 01, 16), new DateTime(2050, 12, 31), 655.75M)); // For 630.50 for 15 days = 1351.07 // For 655.75 for 13 days = 1217.82 = 2568.89 Assert.AreEqual(2568.89M, totalAmount); }
public void CalculateFeeLaAndCcWithLaMultiplePaymentsAndCcMultiplePayments() { FeeCalculatorService srv = new FeeCalculatorService(); var schedules = getSchedules(50); var invoiceResident = new InvoiceResident(50, "John", schedules); var resident = srv.CalculateFee(invoiceResident, new DateTime(2020, 01, 01), new DateTime(2020, 01, 28)); var feesPerSchedules = resident.GetSchedules(); var amounts = feesPerSchedules.Select(c => c.AmountDue).ToArray(); var totalAmount = amounts.Sum(); // multiple payments categories from la // (50, 1, 1, new DateTime(2019, 01, 01), new DateTime(2050, 12, 31), 499.99M)); // (50, 1, 1, new DateTime(2019, 01, 01), new DateTime(2050, 12, 31), 69.75M)); // (50, 1, 1, new DateTime(2019, 01, 01), new DateTime(2050, 12, 31), 25.55M)); // (50, 99, 2, new DateTime(2019, 01, 01), new DateTime(2050, 12, 31), 125.75M)); // (50, 99, 2, new DateTime(2019, 01, 01), new DateTime(2050, 12, 31), 13.33M)); // For 28 days: all totals = 2937.48 Assert.AreEqual(2937.48M, totalAmount); }