public PaymentSchedule GeneratePaymentSchedule(PaymentData order) { var sched = new PaymentSchedule(); sched.CreditBalance = order.CreditAmount; sched.GiftCardBalance = order.GiftCardAmount; sched.UpfrontDue = order.UpfrontTotal; //Default in case rate is 0% var payment = (double)order.FinancedTotal / order.Terms; if (order.APR > 0) { var rate = (double)order.APR / 1200; payment = rate * (double)order.FinancedTotal / (1 - Math.Pow((1 + rate), (order.Terms * -1))); } var roundPayment = Math.Round(payment, 2); //Always round up! if (roundPayment < payment) roundPayment += .01; sched.MonthlyPayment = (Decimal)roundPayment; var totalDue = payment * order.Terms; var totalPayments = sched.MonthlyPayment * order.Terms; var finalAdjustment = (decimal)totalDue - totalPayments; sched.FinalPayment = sched.MonthlyPayment + Math.Round(finalAdjustment, 2); return sched; }
public void Should_be_able_to_determine_a_payment_schedule() { var paydata = new PaymentData { APR = 7.8M, FinancedTotal = 225000M, Terms = 360, GiftCardAmount = 0M, CreditAmount = 0M, UpfrontTotal = 25000M }; var expectedAmountDue = 25000M; var expectedPayment = 1619.71M; var expectedFinal = 1619.22M; var expectedGift = 0M; var expectedCredit = 0M; var schedule = DefaultContext.FinanceTask.GeneratePaymentSchedule(paydata); Assert.AreEqual(expectedAmountDue, schedule.UpfrontDue); Assert.AreEqual(expectedPayment, schedule.MonthlyPayment); Assert.AreEqual(expectedFinal, schedule.FinalPayment); Assert.AreEqual(expectedGift, schedule.GiftCardBalance); Assert.AreEqual(expectedCredit, schedule.CreditBalance); }
public PaymentData CombineLineData(PaymentData order) { var curorder = order; curorder.UpfrontTotal = curorder.Parts.Sum(x => x.UpfrontAmount); curorder.FinancedTotal = curorder.Parts.Sum(x => x.FinancedAmount); return curorder; }
public void BeforeScenario() { var order = new PaymentData(); var schedule = new PaymentSchedule(); ScenarioContext.Current.Set(order); ScenarioContext.Current.Set(schedule); ScenarioContext.Current.Set(_payTasks); }
public JsonResult CalcPaymentSchedule(PaymentData data) { var schedule = _pay.CalculatePaymentSchedule(data); var result = new { AmountDue = String.Format("{0:C}",schedule.UpfrontDue), Payment = String.Format("{0:C}",schedule.MonthlyPayment), Final = String.Format("{0:C}",schedule.FinalPayment), Gift =String.Format("{0:C}",schedule.GiftCardBalance), Credit = String.Format("{0:C}",schedule.CreditBalance), }; return Json(result, JsonRequestBehavior.AllowGet); }
public PaymentData ApplyGiftCertificate(PaymentData order) { var curorder = order; decimal applyAmount; applyAmount = Math.Min(curorder.GiftCardAmount, curorder.UpfrontTotal); curorder.UpfrontTotal -= applyAmount; curorder.GiftCardAmount -= applyAmount; applyAmount = Math.Min(curorder.GiftCardAmount, curorder.FinancedTotal); curorder.FinancedTotal -= applyAmount; curorder.GiftCardAmount -= applyAmount; return curorder; }
public PaymentData ApplyCredit(PaymentData order) { var curorder = order; decimal applyAmount; applyAmount = Math.Min(curorder.CreditAmount, curorder.UpfrontTotal); curorder.UpfrontTotal -= applyAmount; curorder.CreditAmount -= applyAmount; applyAmount = Math.Min(curorder.CreditAmount, curorder.FinancedTotal); curorder.FinancedTotal -= applyAmount; curorder.CreditAmount -= applyAmount; return curorder; }
public void BeforeLargeOrderScenario() { var order = new PaymentData(); var schedule = new PaymentSchedule(); var parts = new List<PartData> { new PartData {PartName = "Flexible whisker sensors", UnitPrice = 100M, UpfrontPercent = 0M, DiscountPercent = .1M, Quantity = 100}, new PartData {PartName = "Assorted Gears and Bearings", UnitPrice = 50M, UpfrontPercent = 0M, DiscountPercent = 0M, Quantity = 100}, new PartData {PartName = "Mountable Halogen Floodlights", UnitPrice = 100M, UpfrontPercent = .1M, DiscountPercent = .05M, Quantity = 50} }; order.Parts = parts.ToArray(); ScenarioContext.Current.Set(order); ScenarioContext.Current.Set(schedule); ScenarioContext.Current.Set(_payTasks); }
public PaymentSchedule CalculatePaymentSchedule(PaymentData data) { var order = data; for(int i = 0; i < order.Parts.Count(); i++) { var part = data.Parts[i]; part = _finance.LoadLineData(part); part = _finance.CalculateLineTotals(part); order.Parts[i] = part; } order = _finance.CombineLineData(order); order = _finance.ApplyGiftCertificate(order); order = _finance.ApplyCredit(order); var schedule = _finance.GeneratePaymentSchedule(order); return schedule; }
public void Should_apply_remainder_gift_certificates_to_financed_amount() { var paydat = new PaymentData() { FinancedTotal = 1000, UpfrontTotal = 500, GiftCardAmount = 700, }; paydat = DefaultContext.FinanceTask.ApplyGiftCertificate(paydat); var expectedFinanced = 800; // 800 or 300 var expectedUpfront = 0; //0 or 500 var expectedGift = 0; Assert.AreEqual(expectedGift, paydat.GiftCardAmount); Assert.AreEqual(expectedUpfront, paydat.UpfrontTotal); Assert.AreEqual(expectedFinanced, paydat.FinancedTotal); }
public void Should_apply_credit_to_down_payment() { var paydat = new PaymentData() { FinancedTotal = 1000, UpfrontTotal = 500, CreditAmount = 100, }; paydat = DefaultContext.FinanceTask.ApplyCredit(paydat); var expectedFinanced = 1000; var expectedUpfront = 400; var expectedCredit = 0; Assert.AreEqual(expectedCredit, paydat.CreditAmount); Assert.AreEqual(expectedUpfront, paydat.UpfrontTotal); Assert.AreEqual(expectedFinanced, paydat.FinancedTotal); }
public void Should_be_able_to_return_remaining_credits() { var paydata = new PaymentData { APR = 10M, FinancedTotal = 0, Terms = 12, GiftCardAmount = 100M, CreditAmount = 200M }; var expectedAmountDue = 0M; var expectedPayment = 0M; var expectedFinal = 0M; var expectedGift = 100M; var expectedCredit = 200M; var schedule = DefaultContext.FinanceTask.GeneratePaymentSchedule(paydata); Assert.AreEqual(expectedAmountDue, schedule.UpfrontDue); Assert.AreEqual(expectedPayment, schedule.MonthlyPayment); Assert.AreEqual(expectedFinal, schedule.FinalPayment); Assert.AreEqual(expectedGift, schedule.GiftCardBalance); Assert.AreEqual(expectedCredit, schedule.CreditBalance); }
public void Should_retain_remaining_gift_certificate() { var paydat = new PaymentData() { FinancedTotal = 1000, UpfrontTotal = 500, GiftCardAmount = 2100, }; paydat = DefaultContext.FinanceTask.ApplyGiftCertificate(paydat); var expectedFinanced = 0; var expectedUpfront = 0; //0 or 500 var expectedGift = 600; //600 or 1100 Assert.AreEqual(expectedGift, paydat.GiftCardAmount); Assert.AreEqual(expectedUpfront, paydat.UpfrontTotal); Assert.AreEqual(expectedFinanced, paydat.FinancedTotal); }
public void Should_combine_all_parts_into_summary_data() { var paydat = new PaymentData(); paydat.Parts = new PartData[3]; paydat.Parts[0] = DefaultContext.FinanceTask.CalculateLineTotals(new PartData { DiscountPercent = .25M, Quantity = 3, UnitPrice = 150, UpfrontPercent = 0M }); paydat.Parts[1] = DefaultContext.FinanceTask.CalculateLineTotals(new PartData { DiscountPercent = 0M, Quantity = 2, UnitPrice = 125, UpfrontPercent = .1M }); paydat.Parts[2] = DefaultContext.FinanceTask.CalculateLineTotals(new PartData { DiscountPercent = .10M, Quantity = 4, UnitPrice = 210, UpfrontPercent = .15M }); var expectedUpfront = 138.4M; var expectedFinanced = 1205.1M; paydat = DefaultContext.FinanceTask.CombineLineData(paydat); Assert.AreEqual(expectedFinanced, paydat.FinancedTotal); Assert.AreEqual(expectedUpfront, paydat.UpfrontTotal); }