<?php
function creditCount($creditBalance, $monthlyPayment, $percent, $servicePayment, $additionalPayment = 0){
if ($additionalPayment>0) {
$creditBalance += $additionalPayment;
}
$paymentTotal = 0; /* Сколько всего отдал банку анон */
/* Посчитаем расходы 20 раз на 20 месяцев вперед */
for ($month = 1; $month <= 20; $month++) {
$creditBalance = ( $creditBalance * $percent ) + $servicePayment;
$payment = min($creditBalance, 5000); $creditBalance -= $payment;
$paymentTotal += $payment;
/* Если баланс отрицательный — хватит считать */
if ($creditBalance <= 0) {
break;
}
}
return $paymentTotal;
};
$homecredit = creditCount(40000, 5000, 1.04, 500);
$softbank = creditCount(40000, 5000, 1.03, 1000);
$strawberry = creditCount(40000, 5000, 1.02, 0, 7777);
echo 'homecredit: ' . $homecredit . "\n";
echo 'softbank: ' . $softbank . "\n";
echo 'strawberry: ' . $strawberry . "\n";
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKbWJfaW50ZXJuYWxfZW5jb2RpbmcoJ3V0Zi04Jyk7CgpmdW5jdGlvbiBjcmVkaXRDb3VudCgkY3JlZGl0QmFsYW5jZSwgJG1vbnRobHlQYXltZW50LCAkcGVyY2VudCwgJHNlcnZpY2VQYXltZW50LCAkYWRkaXRpb25hbFBheW1lbnQgPSAwKXsKCWlmICgkYWRkaXRpb25hbFBheW1lbnQ+MCkgewoJCSRjcmVkaXRCYWxhbmNlICs9ICRhZGRpdGlvbmFsUGF5bWVudDsKCX0KCSRwYXltZW50VG90YWwgPSAwOyAvKiDQodC60L7Qu9GM0LrQviDQstGB0LXQs9C+INC+0YLQtNCw0Lsg0LHQsNC90LrRgyDQsNC90L7QvSAqLwoJCgkvKiDQn9C+0YHRh9C40YLQsNC10Lwg0YDQsNGB0YXQvtC00YsgMjAg0YDQsNC3INC90LAgMjAg0LzQtdGB0Y/RhtC10LIg0LLQv9C10YDQtdC0ICovIAoJZm9yICgkbW9udGggPSAxOyAkbW9udGggPD0gMjA7ICRtb250aCsrKSB7IAoJCSRjcmVkaXRCYW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