From 74d851ea7a7647af1ea0f37612f6df959724be00 Mon Sep 17 00:00:00 2001 From: ellite Date: Sun, 12 Nov 2023 11:07:17 +0100 Subject: [PATCH] Fix rounding and conversion issues on statistics --- endpoints/subscriptions/get.php | 2 +- includes/list_subscriptions.php | 13 +++++++++++-- index.php | 2 +- stats.php | 4 ++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/endpoints/subscriptions/get.php b/endpoints/subscriptions/get.php index 84c2a9234..605866cdf 100644 --- a/endpoints/subscriptions/get.php +++ b/endpoints/subscriptions/get.php @@ -51,7 +51,7 @@ $print[$id]['payment_method_name'] = $payment_methods[$paymentMethodId]['name']; $print[$id]['category_id'] = $subscription['category_id']; $print[$id]['payer_user_id'] = $subscription['payer_user_id']; - $print[$id]['price'] = $subscription['price']; + $print[$id]['price'] = floatval($subscription['price']); if (isset($_COOKIE['convertCurrency']) && $_COOKIE['convertCurrency'] === 'true' && $currencyId != $mainCurrencyId) { $print[$id]['price'] = getPriceConverted($print[$id]['price'], $currencyId, $db); diff --git a/includes/list_subscriptions.php b/includes/list_subscriptions.php index bdeb4230c..a4b4e347d 100644 --- a/includes/list_subscriptions.php +++ b/includes/list_subscriptions.php @@ -50,11 +50,11 @@ function getPriceConverted($price, $currency, $database) { return $price; } else { $fromRate = $exchangeRate['rate']; - return number_format($price / $fromRate, 2); + return $price / $fromRate; } } - function printSubscriptons($subscriptions, $sort, $categories) { + function printSubscriptons($subscriptions, $sort, $categories, $members) { if ($sort === "price") { usort($subscriptions, function($a, $b) { return $a['price'] < $b['price'] ? 1 : -1; @@ -62,6 +62,7 @@ function printSubscriptons($subscriptions, $sort, $categories) { } $currentCategory = 0; + $currentPayerUserId = 0; foreach ($subscriptions as $subscription) { if ($sort == "category_id" && $subscription['category_id'] != $currentCategory) { ?> @@ -71,6 +72,14 @@ function printSubscriptons($subscriptions, $sort, $categories) { +
+ +
+
diff --git a/index.php b/index.php index 305ccbd47..e66f542eb 100644 --- a/index.php +++ b/index.php @@ -79,7 +79,7 @@ $print[$id]['payment_method_name'] = $payment_methods[$paymentMethodId]['name']; $print[$id]['category_id'] = $subscription['category_id']; $print[$id]['payer_user_id'] = $subscription['payer_user_id']; - $print[$id]['price'] = $subscription['price']; + $print[$id]['price'] = floatval($subscription['price']); if (isset($_COOKIE['convertCurrency']) && $_COOKIE['convertCurrency'] === 'true' && $currencyId != $mainCurrencyId) { $print[$id]['price'] = getPriceConverted($print[$id]['price'], $currencyId, $db); diff --git a/stats.php b/stats.php index 495295038..30ffd8bd0 100644 --- a/stats.php +++ b/stats.php @@ -38,7 +38,7 @@ function getPriceConverted($price, $currency, $database) { return $price; } else { $fromRate = $exchangeRate['rate']; - return number_format($price * $fromRate, 2, ".", ""); + return $price / $fromRate; } } @@ -173,7 +173,7 @@ function getPriceConverted($price, $currency, $database) {
Most Expensive Subscription Cost
- +
Amount due this month