Skip to content

Commit

Permalink
Merge pull request #158 from gsteel/daily-interest-amount
Browse files Browse the repository at this point in the history
Add the daily interest amount to the response
  • Loading branch information
gsteel authored Aug 17, 2023
2 parents 8c3a8b8 + 8fa1288 commit 65ae15a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/App/Calculator/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ private function __construct(
public float $interestRate,
public int $recoveryFee,
public int $interestPayable,
public int $dailyAmount,
public int $daysOverdue,
public DateTimeImmutable $referenceDate,
) {
Expand All @@ -24,6 +25,7 @@ public static function new(
float $interestRate,
Money $recoveryFee,
Money $interestPayable,
Money $dailyAmount,
int $daysOverdue,
DateTimeImmutable $referenceDate,
): self {
Expand All @@ -32,6 +34,7 @@ public static function new(
$interestRate,
(int) $recoveryFee->getAmount(),
(int) $interestPayable->getAmount(),
(int) $dailyAmount->getAmount(),
$daysOverdue,
$referenceDate,
);
Expand All @@ -47,6 +50,11 @@ public function interestPayable(): Money
return new Money($this->interestPayable, $this->request->currency());
}

public function dailyAmount(): Money
{
return new Money($this->dailyAmount, $this->request->currency());
}

public function totalPayable(): Money
{
return $this->request->amount()->add(
Expand Down
4 changes: 2 additions & 2 deletions src/App/Calculator/StandardCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function calculate(Request $request): Calculation
if ($dueDate >= $request->now) {
$zero = new Money(0, $this->expectedCurrency);

return Calculation::new($request, 0.0, $zero, $zero, 0, $referenceDate);
return Calculation::new($request, 0.0, $zero, $zero, $zero, 0, $referenceDate);
}

$baseRate = $this->rateHistory->findChangeOnOrPreceding($referenceDate);
Expand All @@ -52,7 +52,7 @@ public function calculate(Request $request): Calculation
$dailyAmount = $request->amount()->multiply((string) ($dailyRate / 100));
$interestAmount = $dailyAmount->multiply($days);

return Calculation::new($request, $interestRate, $recovery, $interestAmount, $days, $referenceDate);
return Calculation::new($request, $interestRate, $recovery, $interestAmount, $dailyAmount, $days, $referenceDate);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/App/Middleware/CalculationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private function result(Calculation $result): ResponseInterface
'recoveryFee' => $formatter->format($result->recoveryFee()),
'interestPayable' => $formatter->format($result->interestPayable()),
'totalPayable' => $formatter->format($result->totalPayable()),
'dailyAmount' => $formatter->format($result->dailyAmount()),
'interestRate' => $result->interestRate,
'daysOverdue' => $result->daysOverdue,
'originalAmount' => $formatter->format($result->request->amount()),
Expand Down
1 change: 1 addition & 0 deletions templates/pages/home.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ $initialDate = new DateTimeImmutable('-30 days');
<em>(The statutory rate of 8.0% + The Bank of England base rate as at <span
class="result-referenceDate"></span>)</em></li>
<li>Interest Amount Payable: £<span class="result-interestPayable"></span></li>
<li>Daily Interest Amount: £<span class="result-dailyAmount"></span></li>
<li>Recovery Fee: £<span class="result-recoveryFee"></span>
<em>(According to the legislation)</em></li>
<li>Total now due: £<span class="result-totalPayable"></span>
Expand Down

0 comments on commit 65ae15a

Please sign in to comment.