diff options
Diffstat (limited to 'pages/api/money/account.php')
-rw-r--r-- | pages/api/money/account.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/pages/api/money/account.php b/pages/api/money/account.php new file mode 100644 index 0000000..6620733 --- /dev/null +++ b/pages/api/money/account.php @@ -0,0 +1,62 @@ +<?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 = []; + +if (!isset($_GET["id"])) { + die(json_encode($obj, JSON_PRETTY_PRINT)); +} + +foreach ($accounts as $account) { + if ($account["_name"] === $_GET["id"]) { + $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"] = []; + + foreach ($account["transactions"] as $index => $transaction) { + $member = getMemberWithoutSystem($transaction["author"]) ?? getMemberWithoutSystem("zdtsg"); + $trans = [ + "id" => $index, + "author" => [ + "avatar" => getAsset($member["_system"], $member["id"]), + "name" => $member["display_name"] ?? $member["name"] + ], + "type" => $transaction["amount"] < 0 ? "REMOVE" : "ADD", + "amount" => round(abs($transaction["amount"]), 2), + "date" => [ + "ts" => strtotime($transaction["date"]), + "iso" => date('c', strtotime($transaction["date"])), + "relative" => timeAgo($transaction["date"]) + ], + "description" => (isset($transaction["description"]) && trim($transaction["description"]) !== "") ? trim($transaction["description"]) : null + ]; + + $acc["transactions"][] = $trans; + } + + $obj = $acc; + } +} + +/* ------------------- */ + +die(json_encode($obj, JSON_PRETTY_PRINT));
\ No newline at end of file |