Files
old-new-wiaas/backend/app/plugins/wiaas/includes/pricing/wiaas-pricing-functions.php
Almira Krdzic e53b243d96 product details
2018-09-12 16:42:21 +02:00

51 lines
1.9 KiB
PHP

<?php
/**
* Copy of Excel's PMT function.
* Credit: http://thoughts-of-laszlo.blogspot.nl/2012/08/complete-formula-behind-excels-pmt.html
*
* @param double $interest The interest rate for the loan.
* @param int $num_of_payments The total number of payments for the loan in months.
* @param double $PV The present value, or the total amount that a series of future payments is worth now;
* Also known as the principal.
* @param double $FV The future value, or a cash balance you want to attain after the last payment is made.
* If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
* @param int $Type Optional, defaults to 0. The number 0 (zero) or 1 and indicates when payments are due.
* 0 = At the end of period
* 1 = At the beginning of the period
*
* @return float
*/
function wiaas_PMT($interest, $num_of_payments, $PV, $FV = 0.00, $Type = 0){
/*$interest = $interest / 12;
$xp=pow((1+$interest),$num_of_payments);
return
($PV* $interest*$xp/($xp-1)+$interest/($xp-1)*$FV)*
($Type==0 ? 1 : 1/($interest+1));*/
$rates = [
24 => 4.282,
30 => 3.451,
36 => 2.896,
42 => 2.500,
48 => 2.223,
54 => 2.025,
60 => 1.834
];
$interest = isset($rates[$num_of_payments]) ? $rates[$num_of_payments] : 10;
return round($PV * ($interest / 100));
}
function wiaas_get_recurrent_price_mortage($principal_amount, $pay_period, $margin, $interest_rate) {
$new_principal_amount = $principal_amount - $margin;
$interest_rate = $interest_rate / 100;
$fixed_mortage = wiaas_PMT($interest_rate, $pay_period, $new_principal_amount);
return round($fixed_mortage, 2);
}
function wiaas_get_price_margin($fixed_price, $principal_amount, $total_cost) {
$total_gain = $fixed_price + $principal_amount;
return $total_gain - $total_cost;
}