<?php
function countTotalPayment ($creditDebt, $percent, $serviceFee, $monthlyPayment) {
for ($months = 2, $paymentTotal = 0; $months <= 20; $months ++) {
$creditDebt = ($creditDebt * $percent) + $serviceFee - $monthlyPayment;
$paymentTotal = $paymentTotal + $monthlyPayment;
if ($serviceFee == 7777 && $months >= 3) {
$creditDebt = $creditDebt - $serviceFee;
}
if (($creditDebt * $percent) + $serviceFee < $monthlyPayment) {
$paymentTotal = $paymentTotal + ($creditDebt * $percent) + $serviceFee;
$months++;
break;
}
}
return $paymentTotal;
}
$creditSum = 40000;
$payout = 5000;
$homoCreditTotal = countTotalPayment ($creditSum, 1.04, 500, $payout);
$softbankTotal = countTotalPayment ($creditSum, 1.03, 1000, $payout);
$strawberryBankTotal = countTotalPayment ($creditSum, 1.02, 7777, $payout);
echo "HomoCredit: {$homoCreditTotal} \n";
echo "Softbank: {$softbankTotal} \n";
echo "StrawberryBank: {$strawberryBankTotal} \n";
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpmdW5jdGlvbiBjb3VudFRvdGFsUGF5bWVudCAoJGNyZWRpdERlYnQsICRwZXJjZW50LCAkc2VydmljZUZlZSwgJG1vbnRobHlQYXltZW50KSB7CiAgICBmb3IgKCRtb250aHMgPSAyLCAkcGF5bWVudFRvdGFsID0gMDsgJG1vbnRocyA8PSAyMDsgJG1vbnRocyArKykgewogICAgICAgICRjcmVkaXREZWJ0ID0gKCRjcmVkaXREZWJ0ICogJHBlcmNlbnQpICsgJHNlcnZpY2VGZWUgLSAkbW9udGhseVBheW1lbnQ7CiAgICAgICAgJHBheW1lbnRUb3RhbCA9ICRwYXltZW50VG90YWwgKyAkbW9udGhseVBheW1lbnQ7CiAgICBpZiAoJHNlcnZpY2VGZWUgPT0gNzc3NyAmJiAkbW9udGhzID49IDMpIHsKICAgICAgICAkY3JlZGl0RGVidCA9ICRjcmVkaXREZWJ0IC0gJHNlcnZpY2VGZWU7Cn0KICAgIGlmICgoJGNyZWRpdERlYnQgKiAkcGV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