apxcde / loan-amortization
PHP composer package for loan amortization
Fund package maintenance!
apxcde
Installs: 54
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 2
pkg:composer/apxcde/loan-amortization
Requires
- php: ^8.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- pestphp/pest: ^2.0
This package is auto-updated.
Last update: 2025-10-17 10:51:52 UTC
README
Installation
You can install the package via composer:
composer require apxcde/loan-amortization
Usage
use 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'] ); }
Example with Partial Payment
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'
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.