PHP code example of zwei / loan-calculator

1. Go to this page and download the library: Download zwei/loan-calculator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zwei / loan-calculator example snippets



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();// 获取还款计划