You can install the package via composer:
composer require apxcde/loan-amortizationuse Apxcde\LoanAmortization\LoanAmortization;
$loanAmount = 200000;
$termMonths = 60;
$annualInterestRate = 12;
$loanData = [
'loan_amount' => $loanAmount,
'interest' => $annualInterestRate,
'term_months' => $termMonths,
'starting_date' => new \DateTime('2024-01-01'),
'remaining_months' => $termMonths, // Set to $termMonths for new loan, or less if partially paid
];
$loan = new LoanAmortization($loanData);
// Get all results (summary and schedule)
$results = $loan->getResults();
// Access summary
echo "Monthly Payment: $" . number_format($results['summary']['monthly_repayment'], 2) . "\n";
echo "Total Interest: $" . number_format($results['summary']['total_interest'], 2) . "\n";
echo "Total Payment: $" . number_format($results['summary']['total_pay'], 2) . "\n";
// Access payment schedule
foreach ($results['schedule'] as $payment) {
[$status, $details] = $payment;
echo sprintf(
"%s - Date: %s, Payment: $%.2f, Principal: $%.2f, Interest: $%.2f, Balance: $%.2f\n",
strtoupper($status),
$details['date'],
$details['payment'],
$details['principal'],
$details['interest'],
$details['balance']
);
}If a loan has already been partially paid:
$loanData = [
'loan_amount' => 200000,
'interest' => 12,
'term_months' => 60,
'starting_date' => new \DateTime('2024-01-01'),
'remaining_months' => 36, // 24 months already paid, 36 remaining
];
$loan = new LoanAmortization($loanData);
$results = $loan->getResults();
// The schedule will show 24 months as 'paid' and 36 as 'not_paid'composer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.