2017 © Pedro Peláez
 

library loan-calculator

The loan calculator package.

image

zwei/loan-calculator

The loan calculator package.

  • Tuesday, July 3, 2018
  • by smilehaha
  • Repository
  • 1 Watchers
  • 1 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 13 % Grown

The README.md

zwei/loan-calculator 包

贷款计算器, 生成还款和回款计划, 支持任意精度的数字, (*1)

支持还款方式

还款方式 是否支持
等额本金 支持
等额本息 支持
每月还息到期还本 支持
一次性还本付息 支持

安装前准备

  1. php5.4以上版本
  2. bcmath扩展 http://php.net/manual/zh/book.bc.php
  3. 创建composer.json文件,并写入以下内容:
{
  "require": {
    "zwei/loan-calculator": "dev-master"
  }
}
  1. 执行composer install

计算器, (*2)

使用示例(use)

  1. 例如项目目录在"E:\web\php7\test"
  2. 创建index.php,并加入以下内容
<?php
include_once 'vendor/autoload.php';

use Zwei\LoanCalculator\Calculator\EqualTotalPaymentCalculator;
use Zwei\LoanCalculator\Calculator\EqualPrincipalPaymentCalculator;
use Zwei\LoanCalculator\Calculator\MonthlyInterestPaymentCalculator;
use Zwei\LoanCalculator\Calculator\OncePayPrincipalInterestPaymentCalculator;
use \Zwei\LoanCalculator\PaymentCalculatorFactory;

$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 在测试前先运行一个 "bootstrap" PHP 文件 * --bootstrap引导测试: phpunit --bootstrap ./Tests/TestInit.php ./Tests/, (*3)

D:\phpStudy\php\php-7.1.13-nts\php.exe D:\phpStudy\php\php-5.6.27-nts\composer.phar update, (*4)

D:\phpStudy\php\php-7.1.13-nts\php.exe vendor\phpunit\phpunit\phpunit --bootstrap tests/TestInit.php tests/, (*5)

The Versions

03/07 2018

dev-master

9999999-dev https://github.com/qq1060656096/loan-calculator

The loan calculator package.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Zhao Wei Jie

23/04 2018

v1.0.2

1.0.2.0 https://github.com/qq1060656096/loan-calculator

The loan calculator package.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Zhao Wei Jie

23/04 2018

dev-develop

dev-develop https://github.com/qq1060656096/loan-calculator

The loan calculator package.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Zhao Wei Jie

26/03 2018

v1.0.1

1.0.1.0 https://github.com/qq1060656096/loan-calculator

The loan calculator package.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Zhao Wei Jie

26/03 2018

v1.0.0

1.0.0.0 https://github.com/qq1060656096/loan-calculator

The loan calculator package.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Zhao Wei Jie