<?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";
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpmdW5jdGlvbiBjb3VudFRvdGFsUGF5bWVudCAoJGNyZWRpdERlYnQsICRwZXJjZW50LCAkc2VydmljZUZlZSwgJG1vbnRobHlQYXltZW50KSB7CiAgICBmb3IgKCRtb250aHMgPSAyLCAkcGF5bWVudFRvdGFsID0gMDsgJG1vbnRocyA8PSAyMDsgJG1vbnRocyArKykgewogICAgICAgICRjcmVkaXREZWJ0ID0gKCRjcmVkaXREZWJ0ICogJHBlcmNlbnQpICsgJHNlcnZpY2VGZWUgLSAkbW9udGhseVBheW1lbnQ7CiAgICAgICAgJHBheW1lbnRUb3RhbCA9ICRwYXltZW50VG90YWwgKyAkbW9udGhseVBheW1lbnQ7CiAgICBpZiAoJHNlcnZpY2VGZWUgPT0gNzc3NyAmJiAkbW9udGhzID4gMykgewogICAgICAgICRjcmVkaXREZWJ0ID0gJGNyZWRpdERlYnQgLSAkc2VydmljZUZlZTsKfQogICAgaWYgKCgkY3JlZGl0RGVidCAqICRwZXJjZW50KSAr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