Skip to content

Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.

feat: only show filters that are actually used

Miguel Ribeirof007adf9658e
diff --git a/includes/getdbkeys.php b/includes/getdbkeys.php
index 2130024..ac7dd20 100644
--- a/includes/getdbkeys.php
+++ b/includes/getdbkeys.php
@@ -18,16 +18,18 @@
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$memberId = $row['id'];
$members[$memberId] = $row;
+ $members[$memberId]['count'] = 0;
}
$payment_methods = array();
- $query = $db->prepare("SELECT * FROM payment_methods WHERE enabled=:enabled AND user_id = :userId");
+ $query = $db->prepare("SELECT * FROM payment_methods WHERE enabled=:enabled AND user_id = :userId ORDER BY `order` ASC");
$query->bindValue(':enabled', 1, SQLITE3_INTEGER);
$query->bindValue(':userId', $userId, SQLITE3_INTEGER);
$result = $query->execute();
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$payment_methodId = $row['id'];
$payment_methods[$payment_methodId] = $row;
+ $payment_methods[$payment_methodId]['count'] = 0;
}
$categories = array();
@@ -38,6 +40,7 @@
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$categoryId = $row['id'];
$categories[$categoryId] = $row;
+ $categories[$categoryId]['count'] = 0;
}
$cycles = array();
diff --git a/includes/version.php b/includes/version.php
index 0d3cc93..c9232b0 100644
--- a/includes/version.php
+++ b/includes/version.php
@@ -1,3 +1,3 @@
<?php
-$version = "v2.33.1";
+$version = "v2.34.0";
?>
\ No newline at end of file
diff --git a/index.php b/index.php
index a72ea39..6dbe320 100644
--- a/index.php
+++ b/index.php
@@ -121,6 +121,15 @@ if ($result) {
}
}
+foreach ($subscriptions as $subscription) {
+ $memberId = $subscription['payer_user_id'];
+ $members[$memberId]['count']++;
+ $categoryId = $subscription['category_id'];
+ $categories[$categoryId]['count']++;
+ $paymentMethodId = $subscription['payment_method_id'];
+ $payment_methods[$paymentMethodId]['count']++;
+}
+
$headerClass = count($subscriptions) > 0 ? "main-actions" : "main-actions hidden";
?>
<style>
@@ -137,7 +146,11 @@ $headerClass = count($subscriptions) > 0 ? "main-actions" : "main-actions hidden
if (version_compare($version, $latestVersion) == -1) {
?>
<div class="update-banner">
- <?= translate('new_version_available', $i18n) ?>: <span><?= $latestVersion ?></span>
+ <?= translate('new_version_available', $i18n) ?>:
+ <span><a href="https://github.com/ellite/Wallos/releases/tag/<?= htmlspecialchars($latestVersion) ?>"
+ target="_blank">
+ <?= htmlspecialchars($latestVersion) ?>
+ </a></span>
</div>
<?php
}
@@ -180,6 +193,9 @@ $headerClass = count($subscriptions) > 0 ? "main-actions" : "main-actions hidden
<div class="filtermenu-submenu-content" id="filter-member">
<?php
foreach ($members as $member) {
+ if ($member['count'] == 0) {
+ continue;
+ }
$selectedClass = '';
if (isset($_GET['member'])) {
$memberIds = explode(',', $_GET['member']);
@@ -206,6 +222,9 @@ $headerClass = count($subscriptions) > 0 ? "main-actions" : "main-actions hidden
<div class="filtermenu-submenu-content" id="filter-category">
<?php
foreach ($categories as $category) {
+ if ($category['count'] == 0) {
+ continue;
+ }
if ($category['name'] == "No category") {
$category['name'] = translate("no_category", $i18n);
}
@@ -236,6 +255,9 @@ $headerClass = count($subscriptions) > 0 ? "main-actions" : "main-actions hidden
<div class="filtermenu-submenu-content" id="filter-payment">
<?php
foreach ($payment_methods as $payment) {
+ if ($payment['count'] == 0) {
+ continue;
+ }
$selectedClass = '';
if (isset($_GET['payment'])) {
$paymentIds = explode(',', $_GET['payment']);
@@ -564,10 +586,10 @@ $headerClass = count($subscriptions) > 0 ? "main-actions" : "main-actions hidden
</div>
<?php
- $orderedSubscriptions = $subscriptions;
- usort($orderedSubscriptions, function ($a, $b) {
- return strnatcmp(strtolower($a['name']), strtolower($b['name']));
- });
+ $orderedSubscriptions = $subscriptions;
+ usort($orderedSubscriptions, function ($a, $b) {
+ return strnatcmp(strtolower($a['name']), strtolower($b['name']));
+ });
?>
<div class="form-group hide" id="replacement_subscritpion">
diff --git a/stats.php b/stats.php
index 02ea0b9..0051005 100644
--- a/stats.php
+++ b/stats.php
@@ -45,6 +45,7 @@ $result = $stmt->execute();
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$memberId = $row['id'];
$members[$memberId] = $row;
+ $members[$memberId]['count'] = 0;
$memberCost[$memberId]['cost'] = 0;
$memberCost[$memberId]['name'] = $row['name'];
}
@@ -58,21 +59,23 @@ $result = $stmt->execute();
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$categoryId = $row['id'];
$categories[$categoryId] = $row;
+ $categories[$categoryId]['count'] = 0;
$categoryCost[$categoryId]['cost'] = 0;
$categoryCost[$categoryId]['name'] = $row['name'];
}
// Get payment methods
-$paymentMethodCount = array();
+$paymentMethods = array();
$query = "SELECT * FROM payment_methods WHERE user_id = :userId AND enabled = 1";
$stmt = $db->prepare($query);
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
$result = $stmt->execute();
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$paymentMethodId = $row['id'];
- $paymentMethodCount[$paymentMethodId] = $row;
- $paymentMethodCount[$paymentMethodId]['count'] = 0;
- $paymentMethodCount[$paymentMethodId]['name'] = $row['name'];
+ $paymentMethods[$paymentMethodId] = $row;
+ $paymentMethods[$paymentMethodId]['count'] = 0;
+ $paymentMethodsCount[$paymentMethodId]['count'] = 0;
+ $paymentMethodsCount[$paymentMethodId]['name'] = $row['name'];
}
// Get code of main currency to display on statistics
@@ -116,7 +119,7 @@ if (isset($_GET['category'])) {
if (isset($_GET['payment'])) {
$conditions[] = "payment_method_id = :payment";
$params[':payment'] = $_GET['payment'];
- $statsSubtitleParts[] = $paymentMethodCount[$_GET['payment']]['name'];
+ $statsSubtitleParts[] = $paymentMethodsCount[$_GET['payment']]['name'];
}
$conditions[] = "user_id = :userId";
@@ -155,8 +158,11 @@ if ($result) {
}
$next_payment = $subscription['next_payment'];
$payerId = $subscription['payer_user_id'];
+ $members[$payerId]['count'] += 1;
$categoryId = $subscription['category_id'];
+ $categories[$categoryId]['count'] += 1;
$paymentMethodId = $subscription['payment_method_id'];
+ $paymentMethods[$paymentMethodId]['count'] += 1;
$inactive = $subscription['inactive'];
$replacementSubscriptionId = $subscription['replacement_subscription_id'];
$originalSubscriptionPrice = getPriceConverted($price, $currency, $db, $userId);
@@ -167,7 +173,7 @@ if ($result) {
$totalCostPerMonth += $price;
$memberCost[$payerId]['cost'] += $price;
$categoryCost[$categoryId]['cost'] += $price;
- $paymentMethodCount[$paymentMethodId]['count'] += 1;
+ $paymentMethodsCount[$paymentMethodId]['count'] += 1;
if ($price > $mostExpensiveSubscription['price']) {
$mostExpensiveSubscription['price'] = $price;
$mostExpensiveSubscription['name'] = $name;
@@ -289,6 +295,9 @@ if ($usesMultipleCurrencies) {
<div class="filtermenu-submenu-content" id="filter-member">
<?php
foreach ($members as $member) {
+ if ($member['count'] == 0) {
+ continue;
+ }
$selectedClass = '';
if (isset($_GET['member']) && $_GET['member'] == $member['id']) {
$selectedClass = 'selected';
@@ -306,12 +315,17 @@ if ($usesMultipleCurrencies) {
?>
<?php
if (count($categories) > 1) {
+ // sort categories by order
+ usort($categories, function ($a, $b) {
+ return $a['order'] - $b['order'];
+ });
?>
<div class="filtermenu-submenu">
<div class="filter-title" onClick="toggleSubMenu('category')"><?= translate("category", $i18n) ?></div>
<div class="filtermenu-submenu-content" id="filter-category">
<?php
foreach ($categories as $category) {
+ if ($category['count'] > 0) {
if ($category['name'] == "No category") {
$category['name'] = translate("no_category", $i18n);
}
@@ -324,6 +338,7 @@ if ($usesMultipleCurrencies) {
<?= $category['name'] ?>
</div>
<?php
+ }
}
?>
</div>
@@ -332,13 +347,20 @@ if ($usesMultipleCurrencies) {
}
?>
<?php
- if (count($paymentMethodCount) > 1) {
+ if (count($paymentMethods) > 1) {
+
+ usort($paymentMethods, function ($a, $b) {
+ return $a['order'] <=> $b['order'];
+ });
?>
<div class="filtermenu-submenu">
<div class="filter-title" onClick="toggleSubMenu('payment')"><?= translate("payment_method", $i18n) ?></div>
<div class="filtermenu-submenu-content" id="filter-payment">
<?php
- foreach ($paymentMethodCount as $payment) {
+ foreach ($paymentMethods as $payment) {
+ if ($payment['count'] == 0) {
+ continue;
+ }
$selectedClass = '';
if (isset($_GET['payment']) && $_GET['payment'] == $payment['id']) {
$selectedClass = 'selected';
@@ -488,7 +510,7 @@ if ($usesMultipleCurrencies) {
$showMemberCostGraph = count($memberDataPoints) > 1;
$paymentMethodDataPoints = [];
- foreach ($paymentMethodCount as $paymentMethod) {
+ foreach ($paymentMethodsCount as $paymentMethod) {
if ($paymentMethod['count'] != 0) {
$paymentMethodDataPoints[] = [
"label" => $paymentMethod['name'],
@@ -497,8 +519,8 @@ if ($usesMultipleCurrencies) {
}
}
- $showPaymentMethodCountGraph = count($paymentMethodDataPoints) > 1;
- if ($showCategoryCostGraph || $showMemberCostGraph || $showPaymentMethodCountGraph) {
+ $showpaymentMethodsGraph = count($paymentMethodDataPoints) > 1;
+ if ($showCategoryCostGraph || $showMemberCostGraph || $showpaymentMethodsGraph) {
?>
<h2><?= translate('split_views', $i18n) ?></h2>
<div class="graphs">
@@ -527,7 +549,7 @@ if ($usesMultipleCurrencies) {
<?php
}
- if ($showPaymentMethodCountGraph) {
+ if ($showpaymentMethodsGraph) {
?>
<section class="graph">
<header>
@@ -546,14 +568,14 @@ if ($usesMultipleCurrencies) {
</section>
<?php
-if ($showCategoryCostGraph || $showMemberCostGraph || $showPaymentMethodCountGraph) {
+if ($showCategoryCostGraph || $showMemberCostGraph || $showpaymentMethodsGraph) {
?>
<script src="scripts/libs/chart.js"></script>
<script type="text/javascript">
window.onload = function () {
loadGraph("categorySplitChart", <?php echo json_encode($categoryDataPoints, JSON_NUMERIC_CHECK); ?>, "<?= $code ?>", <?= $showCategoryCostGraph ?>);
loadGraph("memberSplitChart", <?php echo json_encode($memberDataPoints, JSON_NUMERIC_CHECK); ?>, "<?= $code ?>", <?= $showMemberCostGraph ?>);
- loadGraph("paymentMethidSplitChart", <?php echo json_encode($paymentMethodDataPoints, JSON_NUMERIC_CHECK); ?>, "", <?= $showPaymentMethodCountGraph ?>);
+ loadGraph("paymentMethidSplitChart", <?php echo json_encode($paymentMethodDataPoints, JSON_NUMERIC_CHECK); ?>, "", <?= $showpaymentMethodsGraph ?>);
}
</script>
<?php
diff --git a/styles/dark-theme.css b/styles/dark-theme.css
index e8b1e45..c97d1ee 100644
--- a/styles/dark-theme.css
+++ b/styles/dark-theme.css
@@ -239,6 +239,10 @@ input {
color: #FFF;
}
+.update-banner>span>a {
+ color: #FFF;
+}
+
.totp-qrcode-container {
padding: 14px;
border: 1px solid #DDD;
diff --git a/styles/styles.css b/styles/styles.css
index d4d4cdd..db153ad 100644
--- a/styles/styles.css
+++ b/styles/styles.css
@@ -2504,6 +2504,11 @@ input[type="radio"]:checked+label::after {
font-weight: 500;
}
+.update-banner>span>a {
+ color: #222;
+ text-decoration: underline;
+}
+
.demo-banner {
padding: 15px 20px;
background-color: rgba(var(--error-color-rgb), 0.2);