iamvimukthi/loancalculator
Composer 安装命令:
composer require iamvimukthi/loancalculator
包简介
A simple Laravel package for calculating loans, including EMI, interest, and total payments. Perfect for financial apps with easy integration and customizable options.
README 文档
README
A Laravel package for calculating loan details, including EMI (Equated Monthly Installment), Total Cost, Total Interest, and generating a detailed Payment Schedule. This package is ideal for financial applications requiring loan calculations.
Features
- Calculate EMI, Total Cost, and Total Interest for a loan.
- Generate a Payment Schedule with a month-by-month breakdown of payments.
- Accepts flexible loan terms in both years and months.
- Easy integration with Laravel applications.
Installation
Step 1: Install via Composer
Run the installation command:
composer require iamvimukthi/loancalculator:1.0.0
Step 2: (Optional) Publish Configuration
To publish the configuration file (if required):
php artisan vendor:publish --provider="Iamvimukthi\Loancalculator\LoanCalculatorService"
Usage
1. Calculate Loan Details
Use the calculateLoanDetails method to calculate the EMI, total cost, and total interest for a loan.
use Iamvimukthi\Loancalculator\LoanCalculator;
$loanAmount = 500000; // Principal amount
$annualInterestRate = 5; // Annual interest rate (percentage)
$loanTermYears = 5; // Loan term in years
$loanTermMonths = 6; // Additional months
$loanDetails = LoanCalculator::calculateLoanDetails($loanAmount, $annualInterestRate, $loanTermYears, $loanTermMonths);
echo "Monthly EMI: " . number_format($loanDetails['EMI'], 2) . "\n";
echo "Total Cost of Loan: " . number_format($loanDetails['TotalCost'], 2) . "\n";
echo "Total Interest: " . number_format($loanDetails['TotalInterest'], 2) . "\n";
Output Example:
Monthly EMI: 8,680.78
Total Cost of Loan: 572,931.50
Total Interest: 72,931.50
2. Generate Payment Schedule
Use the generatePaymentSchedule method to create a detailed payment schedule for the loan.
$schedule = LoanCalculator::generatePaymentSchedule($loanAmount, $annualInterestRate, $loanTermYears, $loanTermMonths);
foreach ($schedule as $payment) {
echo "Month-Year: {$payment['MonthYear']}, Principal: " . number_format($payment['PrincipalPayment'], 2) . ", Interest: " . number_format($payment['InterestPayment'], 2) . ", Total: " . number_format($payment['TotalPayment'], 2) . ", Balance: " . number_format($payment['Balance'], 2) . "\n";
}
Output Example:
Month-Year: Dec-2024, Principal: 6,597.45, Interest: 2,083.33, Total: 8,680.78, Balance: 493,402.55
Month-Year: Jan-2025, Principal: 6,624.94, Interest: 2,055.84, Total: 8,680.78, Balance: 486,777.62
...
Methods
calculateLoanDetails($loanAmount, $annualInterestRate, $loanTermYears, $loanTermMonths = 0)
- Description: Calculates EMI, total cost, and total interest for the given loan.
- Parameters:
$loanAmount(float): Principal loan amount.$annualInterestRate(float): Annual interest rate (percentage).$loanTermYears(int): Loan term in years.$loanTermMonths(int): Additional months to add to the loan term (default: 0).
- Returns: Array containing:
'EMI': Monthly installment.'TotalCost': Total loan cost (principal + interest).'TotalInterest': Total interest paid.
generatePaymentSchedule($loanAmount, $annualInterestRate, $loanTermYears, $loanTermMonths = 0)
- Description: Generates a detailed payment schedule for the loan.
- Parameters:
$loanAmount(float): Principal loan amount.$annualInterestRate(float): Annual interest rate (percentage).$loanTermYears(int): Loan term in years.$loanTermMonths(int): Additional months to add to the loan term (default: 0).
- Returns: Array containing:
'MonthYear': Month and year of the payment.'PrincipalPayment': Principal portion of the payment.'InterestPayment': Interest portion of the payment.'TotalPayment': Total payment (EMI).'Balance': Remaining loan balance.
Testing
Run unit tests for the package using PHPUnit to ensure calculations are accurate.
php artisan test
Example test case:
use Iamvimukthi\Loancalculator\LoanCalculator;
class LoanCalculatorTest extends TestCase
{
public function testCalculateLoanDetails()
{
$loanDetails = LoanCalculator::calculateLoanDetails(500000, 5, 5, 6);
$this->assertEquals(9432.26, $loanDetails['EMI']);
$this->assertEquals(566136.45, $loanDetails['TotalCost']);
$this->assertEquals(66136.45, $loanDetails['TotalInterest']);
}
}
License
This package is licensed under the MIT License.
Contributing
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourFeature). - Commit your changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature/YourFeature). - Open a Pull Request.
Contact
For any issues or suggestions, please create an issue on the GitHub Issues page.
iamvimukthi/loancalculator 适用场景与选型建议
iamvimukthi/loancalculator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 12 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 iamvimukthi/loancalculator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 iamvimukthi/loancalculator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-14