zwei/loan-calculator 包
贷款计算器, 生成还款和回款计划, 支持任意精度的数字
支持还款方式
还款方式 | 是否支持 |
---|---|
等额本金 | 支持 |
等额本息 | 支持 |
每月还息到期还本 | 支持 |
一次性还本付息 | 支持 |
安装前准备
php5.4以上版本 bcmath扩展 http://php.net/manual/zh/book.bc.php 创建composer.json文件,并写入以下内容:
{ "require": { "zwei/loan-calculator": "dev-master" } }
执行composer install
计算器
使用示例(use)
例如项目目录在"E:webphp7test" 创建index.php,并加入以下内容
<?php include_once 'vendor/autoload.php'; use ZweiLoanCalculatorCalculatorEqualTotalPaymentCalculator; use ZweiLoanCalculatorCalculatorEqualPrincipalPaymentCalculator; use ZweiLoanCalculatorCalculatorMonthlyInterestPaymentCalculator; use ZweiLoanCalculatorCalculatorOncePayPrincipalInterestPaymentCalculator; use ZweiLoanCalculatorPaymentCalculatorFactory; $principal = 50000;// 本金 $yearInterestRate = "0.10";// 年利率10% $months = 12;// 借款12个月 $time = strtotime("2018-03-20 10:05");// 借款时间 $decimalDigits = 2;// 保留小数点后3位,默认保留2位 // 等额本金计算器 $obj = PaymentCalculatorFactory::getPaymentCalculatorObj(PaymentCalculatorFactory::TYPE_EQUAL_PRINCIPAL, $principal, $yearInterestRate, $month, 0); $lists = $obj->getPlanLists(); print_r($lists); // 等额本息计算器 $obj = PaymentCalculatorFactory::getPaymentCalculatorObj(PaymentCalculatorFactory::TYPE_EQUAL_TOTAL_PAYMENT, $principal, $yearInterestRate, $month, 0); $lists = $obj->getPlanLists(); print_r($lists); // 每月还息到期还本还款方式计算器 $obj = PaymentCalculatorFactory::getPaymentCalculatorObj(PaymentCalculatorFactory::TYPE_MONTHLY_INTEREST, $principal, $yearInterestRate, $month, 0); $lists = $obj->getPlanLists(); print_r($lists); // 一次性还本付息还款方式计算器 $obj = PaymentCalculatorFactory::getPaymentCalculatorObj(PaymentCalculatorFactory::TYPE_ONCE_PAY_PRINCIPAL_INTEREST, $principal, $yearInterestRate, $month, 0); $lists = $obj->getPlanLists(); print_r($lists); // 等额本金计算器 $obj = new EqualPrincipalPaymentCalculator($principal, $yearInterestRate, $months, $time, $decimalDigits); $planLists = $obj->getPlanLists();// 获取还款计划 // 等额本息计算器 $obj = new EqualTotalPaymentCalculator($principal, $yearInterestRate, $months, $time, $decimalDigits); $planLists = $obj->getPlanLists();// 获取还款计划 // 每月还息到期还本还款方式计算器 $obj = new MonthlyInterestPaymentCalculator($principal, $yearInterestRate, $months, $time, $decimalDigits); $planLists = $obj->getPlanLists();// 获取还款计划 // 一次性还本付息还款方式计算器 $obj = new OncePayPrincipalInterestPaymentCalculator($principal, $yearInterestRate, $months, $time, $decimalDigits); $planLists = $obj->getPlanLists();// 获取还款计划
单元测试使用
--bootstrap引导测试: phpunit --bootstrap ./Tests/TestInit.php ./Tests/--bootstrap 在测试前先运行一个 "bootstrap" PHP 文件
D:phpStudyphpphp-7.1.13-ntsphp.exe D:phpStudyphpphp-5.6.27-ntscomposer.phar update
D:phpStudyphpphp-7.1.13-ntsphp.exe vendorphpunitphpunitphpunit --bootstrap tests/TestInit.php tests/
版权声明:
1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。