From 98a84f3aa735f31b08e807c8a4f0549742cbd1b0 Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Tue, 16 May 2023 22:17:15 +0200 Subject: Updated 8 files (automated) --- pages/money.inc | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 121 insertions(+), 3 deletions(-) (limited to 'pages/money.inc') diff --git a/pages/money.inc b/pages/money.inc index 4d93398..1338a3a 100644 --- a/pages/money.inc +++ b/pages/money.inc @@ -100,6 +100,76 @@ if ((isset($_GET["create"]) || isset($_GET["delete"])) && isset($parts[2])) { $rate = (float)trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/exchange.txt")); require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; +$transactionMonths = []; + +foreach ($accounts as $account) { + array_push($transactionMonths, ...array_map(function ($i) { return date('Y-m', strtotime($i["date"])); }, array_filter($account["transactions"], function ($i) { return !isset($i["initial"]) || !$i["initial"]; }))); +} + +$months = [ + ...[ + "2022-12", "2022-11", "2022-10", "2022-09", + "2022-08", "2022-07", "2022-06" + ], + ...array_values(array_filter(array_unique(array_reduce($transactionMonths, function ($a, $b) { + return [...$a, $b]; + }, [])), function ($i) { + return $i !== date('Y-m'); + })) +]; + +$monthlyCloudburst = []; +$monthlyRaindrops = []; + +$bits = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/bits.json"), true); +$projects = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/projects.json"), true); + +foreach ($bits["cloudburst"] as $month => $value) { + $monthlyCloudburst[$month] = $value; +} + +foreach ($bits["raindrops"] as $month => $value) { + $monthlyRaindrops[$month] = $value; +} + +foreach ($months as $month) { + $gainedCloudburst = $monthlyCloudburst[$month] ?? 0; + $gainedRaindrops = $monthlyRaindrops[$month] ?? 0; + + foreach ($accounts as $account) { + foreach ($account["transactions"] as $transaction) { + if (isset($transaction["initial"]) && $transaction["initial"]) continue; + if (date('Y-m', strtotime($transaction["date"])) !== $month) continue; + + if ($account["owner"] === "raindrops") { + $gainedRaindrops += $transaction["amount"]; + } else { + $gainedCloudburst += $transaction["amount"]; + } + } + } + + $monthlyCloudburst[$month] = $gainedCloudburst; + $monthlyRaindrops[$month] = $gainedRaindrops; +} + +uksort($monthlyCloudburst, function ($k1, $k2) { + return strtotime($k2) - strtotime($k1); +}); + +uksort($monthlyRaindrops, function ($k1, $k2) { + return strtotime($k2) - strtotime($k1); +}); + +function getMonthlyEarnings(): array { + global $monthlyRaindrops; + global $monthlyCloudburst; + + return [ + "cloudburst" => array_sum(array_values($monthlyCloudburst)) / count($monthlyCloudburst), + "raindrops" => array_sum(array_values($monthlyRaindrops)) / count($monthlyRaindrops) + ]; +} ?> @@ -267,7 +337,21 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; return $a + $b; }); - ?>£) + ?>£, earning £/month) +
+
+ Show monthly earnings + + + $value): ?> + + + + + +
:">£
+
+
$account): if ($account["owner"] === "cloudburst"): ?> "> @@ -385,7 +469,21 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; return $a + $b; }); - ?>€) + ?>€, earning €/month) +
+
+ Show monthly earnings + + + $value): ?> + + + + + +
:">€
+
+
$account): if ($account["owner"] === "raindrops"): ?> "> @@ -423,6 +521,26 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc';

">€ $minimumRaindrops): ?> (%) $minimumRaindrops ? "over" : "under" ?> the minimum

+ +
+
+ " style="width: 100%;"> +
+
+
+

+
+
%">
+
+ 0): $months = ceil($missing / getMonthlyEarnings()["raindrops"]); ?> +
Costs € · Missing € · Can afford it in (in month 1 ? "s" : "" ?>)
+
You can afford it now, this will take you to the minimum.
+
You can afford it now, this will take you € above the minimum.
+
+
+
+ +
Add new transaction
$transaction): $member = getMemberWithoutSystem($transaction["author"]) ?? getMemberWithoutSystem("zdtsg"); ?> -
" style="border-radius: 999px; width: 32px; height: 32px; margin-right: 10px;">
 "> :
+
" style="border-radius: 999px; width: 32px; height: 32px; margin-right: 10px;">
 "> : Initial amount
-- cgit