<?php
function calculateTotalAmount($creditSum, $percent, $commission, $accountPayment, $monthlyPayment) {
$creditSum += $accountPayment; // Это для 3-го банка //
$totalAmount = 0;
while ($creditSum > 0) {
$creditSum = $creditSum * $percent + $commission; //Формула расчета осуществления ежем.выплат
if ($creditSum >= $monthlyPayment) { //Если сумма к. > или = ежем.выплате, то
$creditSum -= $monthlyPayment; // Производится выплата 5к, т.е. из суммы вычитаем 5к
$totalAmount += $monthlyPayment; // Сюда заносится сумма выплат
} else { // В других случаях, когда сумма меньше ежем. платежа, то
$totalAmount += $creditSum; // к общему числу выплат заносится остаток
$creditSum -= $creditSum; // из остатка вычитается сам остаток, доходя до 0, т.е. все выплачено
}
}
return $totalAmount;
}
$creditSum = 39999;
$monthlyPayment = 5000;
$homoCredit = calculateTotalAmount($creditSum, 1.04, 500, 0, $monthlyPayment);
$softBank = calculateTotalAmount($creditSum, 1.03, 1000, 0, $monthlyPayment);
$strawberryBank = calculateTotalAmount($creditSum, 1.02, 0, 7777, $monthlyPayment);
echo "homoCredit: $homoCredit \n";
echo "SoftBank: $softBank \n";
echo "StrawberryBank: $strawberryBank ";
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpmdW5jdGlvbiBjYWxjdWxhdGVUb3RhbEFtb3VudCgkY3JlZGl0U3VtLCAkcGVyY2VudCwgJGNvbW1pc3Npb24sICRhY2NvdW50UGF5bWVudCwgJG1vbnRobHlQYXltZW50KSB7CiAgICAkY3JlZGl0U3VtICs9ICRhY2NvdW50UGF5bWVudDsgLy8g0K3RgtC+INC00LvRjyAzLdCz0L4g0LHQsNC90LrQsCAvLwogICAgJHRvdGFsQW1vdW50ID0gMDsKICAgIHdoaWxlICgkY3JlZGl0U3VtID4gMCkgewogICAgICAgICRjcmVkaXRTdW0gPSAkY3JlZGl0U3VtICogJHBlcmNlbnQgKyAkY29tbWlzc2lvbjsgLy/QpNC+0YDQvNGD0LvQsCDRgNCw0YHRh9C10YLQsCDQvtGB0YPRidC10YHRgtCy0Lv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