Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 摊销脚本_Php - Fatal编程技术网

Php 摊销脚本

Php 摊销脚本,php,Php,我正在尝试创建一个摊销计算器来计算本金递减 $x=1; $starting_pmt=26; $ending_pmt=36; $i=0.0010316264327892; $p=410000; $pmt=916.84; $num\u pmt=$end\u pmt-$start\u pmt; 回声“; 回显“PMT Num”; 呼应“平衡”; 呼应“原则”; 呼应“TTL原则”; 呼应“兴趣”; 回应“付款”; 回声“; 启动时 每次付款的余额和两个值之间支付的总本金。我还想计算每次付款支付的利息

我正在尝试创建一个摊销计算器来计算本金递减

$x=1;
$starting_pmt=26;
$ending_pmt=36;
$i=0.0010316264327892;
$p=410000;
$pmt=916.84;
$num\u pmt=$end\u pmt-$start\u pmt;
回声“;
回显“PMT Num”;
呼应“平衡”;
呼应“原则”;
呼应“TTL原则”;
呼应“兴趣”;
回应“付款”;
回声“;
启动时
每次付款的余额和两个值之间支付的总本金。我还想计算每次付款支付的利息以及两个值之间支付的累计利息

这就是我的开始

我不知道如何让循环在每次迭代中进行计算…………我一直在使用我的原始代码,我越来越接近。我无法让循环计算已支付本金和利息的累计总额

<?php
$starting_pmt = 1;

$ending_pmt = 10;

$i = 0.0010316264327892;

$p = 410000;
$pmt = 916.84;

$num_pmts = $ending_pmt - $starting_pmt;

while($x < $num_pmts) {

    echo "<tr>";
    echo "<td>$x</td>";
    echo "<td>".$p - ($p*$i)."</td>";
    echo "<td></td>";
    echo "<td></td>";
    echo "<tr>";

    $x++;

这里有一种制作摊销脚本的方法,你需要传回你想要的利率、付款日期和所有好东西。然后我返回一个包含每个月所有值的关联数组

public static function amortizeLoan($principal, $rate, $term, $extra_days, $payment_date){
    $payment = self::getPayment($principal,($rate*100),$term,$extra_days);

    $MonthlyInterestRate = $rate / 12;
    $Multiplier = 1 + $MonthlyInterestRate;
    $TermRate = 1;
    for($x=0;$x<$term;$x++){
        $TermRate = $TermRate * $Multiplier;
    }
    $Days = $extra_days - 30;
    $oddDayInt = $Days > 0 ? round($principal * ($rate / 365.25) * $Days,2) : 0;

    $amortization = [];
    $total_interest = 0;
    $total_principal = 0;
    $remaining_principal = $principal;
    $compareDay = date('d', strtotime($payment_date));



    for($x=0;$x<$term;$x++){
        $this_int_paid = round((($rate)/12) * $remaining_principal,2);
        if($x==0){$this_int_paid += $oddDayInt;}
        $this_princ_paid = round($payment - $this_int_paid,2);
        $this_rem_princ = round($remaining_principal - $this_princ_paid,2);
        if($x == ($term-1)){
            if($this_rem_princ < 0){
                $this_princ_paid-=abs($this_rem_princ);
                $payment=round($this_int_paid+$this_princ_paid,2);
            }else{
                $this_princ_paid+=$this_rem_princ;
                $payment=round($this_int_paid+$this_princ_paid,2);
            }
        }
        $remaining_principal -= $this_princ_paid;
        $total_interest += $this_int_paid;
        $total_principal += $this_princ_paid;

        // *** If month days < payment date, payment date falls on the last day of that month.***
        $nextMonth = strtotime("last day of next month", strtotime($payment_date));
        $lastDayNextMonth = date('d', $nextMonth);

        if ($compareDay >= $lastDayNextMonth) {
            $payment_date_time = $x ? $nextMonth : strtotime($payment_date);
        } else {
            $payment_date_time = $x ? strtotime("+1 month", strtotime($payment_date)) : strtotime($payment_date);
        }

        if ($lastDayNextMonth > date('d', strtotime($payment_date)) && date('t', strtotime($payment_date)) < $compareDay) {
            $date = date('Y-m-d', $nextMonth);
            $newDate = date_create($date);
            $newDate->format('Y-m-d');
            $finalDate = date_date_set(
                $newDate,
                date_format($newDate, 'Y'),
                date_format($newDate, 'm'),
                $compareDay
            );
            $formatedDate = $finalDate->format('m/d/y');

            $payment_date_time = strtotime($formatedDate);
        }
        $payment_date = gmdate("Y-m-d", $payment_date_time);

        $amortization[] = [
            "payment"=>($x+1),
            "amount"=>$payment,
            "principal"=>$this_princ_paid,
            "interest"=>$this_int_paid,
            "total_principal"=>$total_principal,
            "total_interest"=>$total_interest,
            "remaining_balance"=>round($remaining_principal,2),
            "payment_date"=>$payment_date
        ];
    }
    return $amortization;
}
public静态函数摊销贷款($本金、$rate、$term、$extra_天数、$payment_日期){
$payment=self::getPayment($primary,($rate*100),$term,$extra_天);
$MonthlyInterestate=$rate/12;
$Multiplier=1+MonthlyInterestate美元;
$TermRate=1;
对于($x=0;$x 0?轮($principal*($rate/365.25)*$Days,2):0;
美元摊销=[];
$total_利息=0;
$total_principal=0;
$剩余本金=$本金;
$compareDay=日期('d',标准时间('payment_date));
对于($x=0;$x=$lastDayNextMonth){
$payment\u date\u time=$x?$nextMonth:strottime($payment\u date);
}否则{
$payment_date_time=$x?strotime(“+1个月”,strotime($payment_date)):strotime($payment_date);
}
如果($lastDayNextMonth>date('d',strotime('payment_date))&&date('t',strotime('payment_date))<$compareDay){
$date=日期('Y-m-d',$nextMonth);
$newDate=date\u创建($date);
$newDate->format('Y-m-d');
$finalDate=日期\日期集(
$newDate,
日期格式($newDate,'Y'),
日期格式($newDate,'m'),
$compareDay
);
$formattedate=$finalDate->format('m/d/y');
$payment\u date\u time=strottime($formateDate);
}
$payment\u date=gmdate(“Y-m-d”,$payment\u date\u time);
美元摊销[]=[
“付款”=>($x+1),
“金额”=>$payment,
“委托人”=>$this\u princ\u已付,
“利息”=>$已支付的利息,
“总本金”=>总本金,
“总利息”=>$总利息,
“剩余余额”=>四舍五入($剩余本金,2),
“付款日期”=>美元付款日期
];
}
返回美元摊销;
}

“我不知道如何让循环进行计算”不是一个非常具体的问题。您可能想改写它,也许可以检查我一直在做这项工作并取得了进展。但我不知道如何获得一行的累计总数。