diff options
author | RaindropsSys <contact@minteck.org> | 2023-05-14 14:02:50 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-05-14 14:02:50 +0200 |
commit | a98bafed63f9322d54422861521c0c3c5d110d9a (patch) | |
tree | ca86cd09fd85055f8eb1ccfef10d8ed24c447145 /pages/api/money/accounts.php | |
parent | 926714a89d3dcc2976228b9f0039a34b1e18f5e6 (diff) | |
download | pluralconnect-a98bafed63f9322d54422861521c0c3c5d110d9a.tar.gz pluralconnect-a98bafed63f9322d54422861521c0c3c5d110d9a.tar.bz2 pluralconnect-a98bafed63f9322d54422861521c0c3c5d110d9a.zip |
Updated 7 files and added 4 files (automated)
Diffstat (limited to 'pages/api/money/accounts.php')
-rw-r--r-- | pages/api/money/accounts.php | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/pages/api/money/accounts.php b/pages/api/money/accounts.php new file mode 100644 index 0000000..22d8c77 --- /dev/null +++ b/pages/api/money/accounts.php @@ -0,0 +1,96 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $_PROFILE; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc"; +if (!$isLoggedIn) header("Location: /-/login") and die(); +header("Content-Type: application/json"); + +$accounts = array_map(function ($i) { + $name = substr($i, 0, -5); + $data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/money/" . $i), true); + $data["_name"] = $name; + return $data; +}, array_values(array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/money"), function ($i) { return !str_starts_with($i, "."); }))); +$rate = (float)trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/exchange.txt")); +$obj = [ + "total" => 0, + "exchange_rate" => $rate, + "users" => [ + "cloudburst" => [ + "total" => 0, + "accounts" => [] + ], + "raindrops" => [ + "total" => 0, + "accounts" => [] + ] + ] +]; + +$allAccounts = array_reduce(array_map(function ($i) { + return calculateFullAmount($i, true, true); +}, $accounts), function ($a, $b) { + return $a + $b; +}); +$obj["total"] = [ + "gbp" => round($allAccounts, 2), + "eur" => round($allAccounts * (1 / $rate), 2) +]; + +/* ------------------- */ + +$allAccounts = array_reduce(array_map(function ($i) { + return calculateFullAmount($i, true, true); +}, array_values(array_filter($accounts, function ($i) { return $i["owner"] === "cloudburst"; }))), function ($a, $b) { + return $a + $b; +}); + +$obj["users"]["cloudburst"]["total"] = $allAccounts; + +foreach ($accounts as $index => $account) { + if ($account["owner"] === "cloudburst") { + $acc = []; + + $acc["id"] = $account["_name"]; + $acc["name"] = $account["name"]; + $acc["currency"] = $account["currency"]; + $acc["default"] = $account["default"]; + $acc["total"] = round(calculateFullAmount($account, true), 2); + $acc["interests"] = $account["interests"]; + $acc["max"] = $account["max"]; + $acc["used_percentage"] = isset($account["max"]) ? (calculateFullAmount($account, true) / $account["max"]) * 100 : null; + + $obj["users"]["cloudburst"]["accounts"][] = $acc; + } +} +/* ------------------- */ + +$allAccounts = array_reduce(array_map(function ($i) { + return calculateFullAmount($i, true, true); +}, array_values(array_filter($accounts, function ($i) { return $i["owner"] === "raindrops"; }))), function ($a, $b) { + return $a + $b; +}); + +$obj["users"]["raindrops"]["total"] = $allAccounts; + +foreach ($accounts as $index => $account) { + if ($account["owner"] === "raindrops") { + $acc = []; + + $acc["id"] = $account["_name"]; + $acc["name"] = $account["name"]; + $acc["currency"] = $account["currency"]; + $acc["default"] = $account["default"]; + $acc["total"] = round(calculateFullAmount($account, true), 2); + $acc["interests"] = $account["interests"]; + $acc["max"] = $account["max"]; + $acc["used_percentage"] = isset($account["max"]) ? (calculateFullAmount($account, true) / $account["max"]) * 100 : null; + $acc["transactions"] = null; + + $obj["users"]["raindrops"]["accounts"][] = $acc; + } +} + +/* ------------------- */ + +die(json_encode($obj, JSON_PRETTY_PRINT));
\ No newline at end of file |