-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.php
47 lines (34 loc) · 1.28 KB
/
calc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
if (
!isset($_POST)
|| !isset($_POST['date'])
|| !isset($_POST['depositeAmount'])
|| !isset($_POST['years'])
|| !isset($_POST['isReplenishment'])
|| !isset($_POST['depositReplenishmentAmount'])
) die("Ошибка входных данных");
extract($_POST);
$bankPercent = 0.1;
$summ = $depositeAmount;
$replenishment = $isReplenishment == "true" ? $depositReplenishmentAmount : 0;
$currentDate = strtotime($date); // <-- timestamp value
for ($i = 0; $i < $years; $i++) {
for ($j = 0; $j < 12; $j++) {
$lastSumm = $summ;
$currentDate += 60 * 60 * 24 * date("t", $currentDate);
$summ = CapitalizationOfInterestInTheMonth($bankPercent, $currentDate, $lastSumm, $replenishment);
}
}
function CapitalizationOfInterestInTheMonth($percent, $currentDate, $lastMonthSumm, $replenishment)
{
$daysInMonth = date("t", $currentDate);
$daysInYear = date('L', $currentDate) ? 366 : 365;
$currentMonthSumm = $lastMonthSumm + ($lastMonthSumm + $replenishment) * $daysInMonth * ($percent / $daysInYear);
// $currentMonthSumm = $lastMonthSumm + $replenishment + $lastMonthSumm * $daysInMonth * ($percent / $daysInYear);
return $currentMonthSumm;
}
$result = [
"success" => round($summ, 2)
];
echo json_encode($result);
die();