我继续使用我的previous question。
现在我需要每个月设置价格值的贷款。
价格值来自totalLoan * 5%
示例:
总贷款= 4,000,000
IDR格式
每月总贷款= 4
兴趣= 5%
所以我们得到IDR 4,200,000
现在我需要在第一个月设置利息5%
帐单。
要这样:
28-Apr-2019 - 1,200,000
28-May-2019 - 1,000,000
28-Jun-2019 - 1,000,000
28-Jul-2019 - 1,000,000
到目前为止,如下所示的PHP:
$totalLoan = "4000000";
$interest= "5"; //<-- 5%
$loan = 4;
$fixedDateEveryMonth = 28;
$start = new DateTime(date('Y-m-') . $fixedDateEveryMonth);
for($i = 1; $i <= $loan; $i++)
{
$start->add(new DateInterval("P1M"));
$dateLoan = $start->format('Y-m-d');
echo $dateLoan." = ".$priceLoan; //<-- assume
}
该怎么做?
答案 0 :(得分:1)
$totalLoan = "4000000";
$interest= "5"; //<-- 5%
$loan = 4;
$fixedDateEveryMonth = 28;
$start = new DateTime(date('Y-m-') . $fixedDateEveryMonth);
$everyMonthPriceLoan = $totalLoan/$loan;
for($i = 1; $i <= $loan; $i++)
{
$start->add(new DateInterval("P1M"));
$dateLoan = $start->format('Y-m-d');
$priceLoan = $everyMonthPriceLoan + ($totalLoan/100*$interest);
echo $dateLoan." = ".$priceLoan; //<-- assume
$interest = 0;
}
答案 1 :(得分:1)
您可以尝试一下。它以总贷款除以贷款期数来计算贷款分期付款,然后将总利息(总贷款*利息/ 100)添加到第一批中;第一次付款后重置分期付款价值:
$totalLoan = "4000000";
$interest= "5"; //<-- 5%
$loan = 4;
$instalment = $totalLoan / $loan;
$priceLoan = $instalment + $totalLoan * $interest / 100;
$fixedDateEveryMonth = 28;
$start = new DateTime(date('Y-m-') . $fixedDateEveryMonth);
for ($i = 1; $i <= $loan; $i++) {
$start->add(new DateInterval("P1M"));
$dateLoan = $start->format('Y-m-d');
echo "$dateLoan - " . number_format($priceLoan, 0) . "\n";
$priceLoan = $instalment;
}
输出:
28-Apr-2019 - 1,200,000
28-May-2019 - 1,000,000
28-Jun-2019 - 1,000,000
28-Jul-2019 - 1,000,000