<?php
function calcPayment($creditSum,
$percent,
$servicePayment,
$monthlyPayment,
$openPayment){
$paymentTotal = 0;
for($month = 1; $creditSum !=0; $month++){
$creditSum = $creditSum * $percent + $servicePayment - $monthlyPayment;
if ($creditSum <= 0) {
$paymentTotal = $paymentTotal + $monthlyPayment - abs($creditSum); $paymentTotal = round($paymentTotal, 2); $creditSum = 0;
} else {
$paymentTotal = $paymentTotal + $monthlyPayment;
}
}
$paymentTotal = $paymentTotal + $openPayment;
return $paymentTotal;
}
$creditSum = 39999;
$payout = 5000;
$homoCreditTotal = round(calcPayment
($creditSum, 1.04, 500, $payout, 0),2); $softbankTotal = round(calcPayment
($creditSum, 1.03, 1000, $payout, 0),2); $strawberryBankTotal = round(calcPayment
($creditSum, 1.02, 0, $payout, 7777),2);
echo "homoCredit: {$homoCreditTotal} руб.\n";
echo "softbank: {$softbankTotal} руб.\n";
echo "strawberryBank: {$strawberryBankTotal} руб.\n";
$bankOffer = ['homoCredit' => $homoCreditTotal, 'softbank' => $softbankTotal, 'strawberryBank' => $strawberryBankTotal];
echo "\nНаиболее выгодное предложение от {$bank[0]}\n";
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7CgpmdW5jdGlvbiBjYWxjUGF5bWVudCgkY3JlZGl0U3VtLCAKCQkJCQkgJHBlcmNlbnQsIAoJCQkJCSAkc2VydmljZVBheW1lbnQsIAoJCQkJCSAkbW9udGhseVBheW1lbnQsIAoJCQkJCSAkb3BlblBheW1lbnQpewoJJHBheW1lbnRUb3RhbCA9IDA7Cglmb3IoJG1vbnRoID0gMTsgJGNyZWRpdFN1bSAhPTA7ICRtb250aCsrKXsKCQkkY3JlZGl0U3VtID0gJGNyZWRpdFN1bSAqICRwZXJjZW50ICsgJHNlcnZpY2VQYXltZW50IC0gJG1vbnRobHlQYXltZW50OwoJCWlmICgkY3JlZGl0U3VtIDw9IDApIHsKCQkJJHBheW1lbnRUb3RhbCA9ICRwYXltZW50VG90YWwgKyAkbW9udGhseVBheW1lbnQ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