Skip to content

Commit

Permalink
make rescheduled payments due in full
Browse files Browse the repository at this point in the history
  • Loading branch information
simontreanor committed Oct 7, 2024
1 parent c93b5c5 commit 9763cbc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
13 changes: 8 additions & 5 deletions src/Amortisation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,14 @@ module Amortisation =
if si.BalanceStatus = ClosedBalance || si.BalanceStatus = RefundDue then
0L<Cent>
else
match ap.ScheduledPayment.Total with
| 0L<Cent> -> 0L<Cent>
| amount when extraPaymentsBalance > 0L<Cent> -> amount - extraPaymentsBalance
| amount -> Cent.min (si.PrincipalBalance + si.FeesBalance + roundedInterestPortion) amount
|> Cent.max 0L<Cent>
match ap.ScheduledPayment.Original, ap.ScheduledPayment.Rescheduled with
| _, ValueSome rp -> rp.Value // always make rescheduled payment value due in full
| ValueSome op, _ when op.Value = 0L<Cent> -> 0L<Cent> // nothing due to pay
| ValueSome op, _ when extraPaymentsBalance > 0L<Cent> -> op.Value - extraPaymentsBalance // reduce the payment due if early/extra payments have been made
| ValueSome op, _ -> op.Value // payment due in full
| ValueNone, ValueNone -> 0L<Cent> // nothing due to pay
|> Cent.min (si.PrincipalBalance + si.FeesBalance + roundedInterestPortion) // payment due should never exceed settlement figure
|> Cent.max 0L<Cent> // payment due should never be negative
|> fun p ->
match sp.Calculation.MinimumPayment with
| NoMinimumPayment -> p
Expand Down
2 changes: 1 addition & 1 deletion tests/ActualPaymentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ module ActualPaymentTests =
Advances = [||]
ScheduledPayment = ScheduledPayment.Quick (ValueSome 491_53L<Cent>) ValueNone
Window = 5
PaymentDue = 457_65L<Cent>
PaymentDue = 432_07L<Cent>
ActualPayments = [| { ActualPaymentStatus = ActualPaymentStatus.Confirmed 500_00L<Cent>; Metadata = Map.empty } |]
GeneratedPayment = ValueNone
NetEffect = 500_00L<Cent>
Expand Down
28 changes: 14 additions & 14 deletions tests/EdgeCaseTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -660,25 +660,25 @@ module EdgeCaseTests =
Window = 4
PaymentDue = 0L<Cent>
ActualPayments = [||]
GeneratedPayment = ValueSome 138_65L<Cent>
NetEffect = 138_65L<Cent>
GeneratedPayment = ValueSome 83_74L<Cent>
NetEffect = 83_74L<Cent>
PaymentStatus = Generated
BalanceStatus = ClosedBalance
OriginalSimpleInterest = 0L<Cent>
ContractualInterest = 0m<Cent>
SimpleInterest = 5_63.072m<Cent>
NewInterest = 5_63.072m<Cent>
SimpleInterest = 4_32.256m<Cent>
NewInterest = 4_32.256m<Cent>
NewCharges = [||]
PrincipalPortion = 87_98L<Cent>
PrincipalPortion = 67_54L<Cent>
FeesPortion = 0L<Cent>
InterestPortion = 50_67L<Cent>
InterestPortion = 16_20L<Cent>
ChargesPortion = 0L<Cent>
FeesRefund = 0L<Cent>
PrincipalBalance = 0L<Cent>
FeesBalance = 0L<Cent>
InterestBalance = 0m<Cent>
ChargesBalance = 0L<Cent>
SettlementFigure = 138_65L<Cent>
SettlementFigure = 83_74L<Cent>
FeesRefundIfSettled = 0L<Cent>
})
actual |> should equal expected
Expand Down Expand Up @@ -744,25 +744,25 @@ module EdgeCaseTests =
Window = 4
PaymentDue = 0L<Cent>
ActualPayments = [||]
GeneratedPayment = ValueSome 68_68L<Cent>
NetEffect = 68_68L<Cent>
GeneratedPayment = ValueSome 10_19L<Cent>
NetEffect = 10_19L<Cent>
PaymentStatus = Generated
BalanceStatus = ClosedBalance
OriginalSimpleInterest = 0L<Cent>
ContractualInterest = 0m<Cent>
SimpleInterest = 2_78.912m<Cent>
NewInterest = 2_78.912m<Cent>
SimpleInterest = 52.608m<Cent>
NewInterest = 52.608m<Cent>
NewCharges = [||]
PrincipalPortion = 43_58L<Cent>
PrincipalPortion = 8_22L<Cent>
FeesPortion = 0L<Cent>
InterestPortion = 25_10L<Cent>
InterestPortion = 1_97L<Cent>
ChargesPortion = 0L<Cent>
FeesRefund = 0L<Cent>
PrincipalBalance = 0L<Cent>
FeesBalance = 0L<Cent>
InterestBalance = 0m<Cent>
ChargesBalance = 0L<Cent>
SettlementFigure = 68_68L<Cent>
SettlementFigure = 10_19L<Cent>
FeesRefundIfSettled = 0L<Cent>
})
actual |> should equal expected
Expand Down
4 changes: 2 additions & 2 deletions tests/QuoteTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ module QuoteTests =
Advances = [||]
ScheduledPayment = ScheduledPayment.Quick (ValueSome 491_53L<Cent>) ValueNone
Window = 5
PaymentDue = 457_65L<Cent>
PaymentDue = 432_07L<Cent>
ActualPayments = [||]
GeneratedPayment = ValueSome 432_07L<Cent>
NetEffect = 432_07L<Cent>
Expand Down Expand Up @@ -1592,7 +1592,7 @@ module QuoteTests =
Advances = [||]
ScheduledPayment = ScheduledPayment.Quick (ValueSome 491_53L<Cent>) ValueNone
Window = 5
PaymentDue = 457_65L<Cent>
PaymentDue = 432_07L<Cent>
ActualPayments = [| { ActualPaymentStatus = ActualPaymentStatus.Confirmed 500_00L<Cent>; Metadata = Map.empty } |]
GeneratedPayment = ValueSome -67_93L<Cent>
NetEffect = 432_07L<Cent>
Expand Down

0 comments on commit 9763cbc

Please sign in to comment.