Skip to content

Commit

Permalink
feat: only show filters that are actually used
Browse files Browse the repository at this point in the history
feat: link version update banner to github release
fix: filters for categories and payment method respect order from settings
  • Loading branch information
ellite authored Oct 31, 2024
1 parent f1845b9 commit f007adf
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 21 deletions.
5 changes: 4 additions & 1 deletion includes/getdbkeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -38,6 +40,7 @@
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$categoryId = $row['id'];
$categories[$categoryId] = $row;
$categories[$categoryId]['count'] = 0;
}

$cycles = array();
Expand Down
2 changes: 1 addition & 1 deletion includes/version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php
$version = "v2.33.1";
$version = "v2.34.0";
?>
32 changes: 27 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@
}
}

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>
Expand All @@ -137,7 +146,11 @@
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
}
Expand Down Expand Up @@ -180,6 +193,9 @@
<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']);
Expand All @@ -206,6 +222,9 @@
<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);
}
Expand Down Expand Up @@ -236,6 +255,9 @@
<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']);
Expand Down Expand Up @@ -564,10 +586,10 @@
</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">
Expand Down
50 changes: 36 additions & 14 deletions stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function getPriceConverted($price, $currency, $database, $userId)
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'];
}
Expand All @@ -58,21 +59,23 @@ function getPriceConverted($price, $currency, $database, $userId)
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
Expand Down Expand Up @@ -116,7 +119,7 @@ function getPriceConverted($price, $currency, $database, $userId)
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";
Expand Down Expand Up @@ -155,8 +158,11 @@ function getPriceConverted($price, $currency, $database, $userId)
}
$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);
Expand All @@ -167,7 +173,7 @@ function getPriceConverted($price, $currency, $database, $userId)
$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;
Expand Down Expand Up @@ -289,6 +295,9 @@ function getPriceConverted($price, $currency, $database, $userId)
<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';
Expand All @@ -306,12 +315,17 @@ function getPriceConverted($price, $currency, $database, $userId)
?>
<?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);
}
Expand All @@ -324,6 +338,7 @@ function getPriceConverted($price, $currency, $database, $userId)
<?= $category['name'] ?>
</div>
<?php
}
}
?>
</div>
Expand All @@ -332,13 +347,20 @@ function getPriceConverted($price, $currency, $database, $userId)
}
?>
<?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';
Expand Down Expand Up @@ -488,7 +510,7 @@ function getPriceConverted($price, $currency, $database, $userId)
$showMemberCostGraph = count($memberDataPoints) > 1;

$paymentMethodDataPoints = [];
foreach ($paymentMethodCount as $paymentMethod) {
foreach ($paymentMethodsCount as $paymentMethod) {
if ($paymentMethod['count'] != 0) {
$paymentMethodDataPoints[] = [
"label" => $paymentMethod['name'],
Expand All @@ -497,8 +519,8 @@ function getPriceConverted($price, $currency, $database, $userId)
}
}

$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">
Expand Down Expand Up @@ -527,7 +549,7 @@ function getPriceConverted($price, $currency, $database, $userId)
<?php
}

if ($showPaymentMethodCountGraph) {
if ($showpaymentMethodsGraph) {
?>
<section class="graph">
<header>
Expand All @@ -546,14 +568,14 @@ function getPriceConverted($price, $currency, $database, $userId)

</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
Expand Down
4 changes: 4 additions & 0 deletions styles/dark-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ input {
color: #FFF;
}

.update-banner>span>a {
color: #FFF;
}

.totp-qrcode-container {
padding: 14px;
border: 1px solid #DDD;
Expand Down
5 changes: 5 additions & 0 deletions styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f007adf

Please sign in to comment.