Skip to content

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

V2 37 0 (#624)

Miguel Ribeiro17aa34e1d826
diff --git a/calendar.php b/calendar.php
index b54388b..66ec259 100644
--- a/calendar.php
+++ b/calendar.php
@@ -1,6 +1,23 @@
<?php
require_once 'includes/header.php';
+function getPriceConverted($price, $currency, $database, $userId)
+{
+ $query = "SELECT rate FROM currencies WHERE id = :currency AND user_id = :userId";
+ $stmt = $database->prepare($query);
+ $stmt->bindParam(':currency', $currency, SQLITE3_INTEGER);
+ $stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
+ $result = $stmt->execute();
+
+ $exchangeRate = $result->fetchArray(SQLITE3_ASSOC);
+ if ($exchangeRate === false) {
+ return $price;
+ } else {
+ $fromRate = $exchangeRate['rate'];
+ return $price / $fromRate;
+ }
+}
+
$currentMonth = date('m');
$currentYear = date('Y');
$sameAsCurrent = false;
@@ -30,6 +47,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['month']) && isset($_GET
$sameAsCurrent = true;
}
+$currenciesInUse = [];
+$numberOfSubscriptionsToPayThisMonth = 0;
+$totalCostThisMonth = 0;
+$amountDueThisMonth = 0;
+
$query = "SELECT * FROM subscriptions WHERE user_id = :user_id AND inactive = 0";
$stmt = $db->prepare($query);
$stmt->bindValue(':user_id', $userId, SQLITE3_INTEGER);
@@ -37,12 +59,50 @@ $result = $stmt->execute();
$subscriptions = [];
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$subscriptions[] = $row;
+ $currenciesInUse[] = $row['currency_id'];
}
+$currenciesInUse = array_unique($currenciesInUse);
+$usesMultipleCurrencies = count($currenciesInUse) > 1;
+
+$showCantConverErrorMessage = false;
+if ($usesMultipleCurrencies) {
+ $query = "SELECT api_key FROM fixer WHERE user_id = :userId";
+ $stmt = $db->prepare($query);
+ $stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
+ $result = $stmt->execute();
+ if ($result->fetchArray(SQLITE3_ASSOC) === false) {
+ $showCantConverErrorMessage = true;
+ }
+}
+
+// Get code of main currency to display on statistics
+$query = "SELECT c.code
+ FROM currencies c
+ INNER JOIN user u ON c.id = u.main_currency
+ WHERE u.id = :userId";
+$stmt = $db->prepare($query);
+$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
+$result = $stmt->execute();
+$row = $result->fetchArray(SQLITE3_ASSOC);
+$code = $row['code'];
+
$yearsToLoad = $calendarYear - $currentYear + 1;
?>
<section class="contain">
+ <?php
+ if ($showCantConverErrorMessage) {
+ ?>
+ <div class="error-box">
+ <div class="error-message">
+ <i class="fa-solid fa-exclamation-circle"></i>
+ <?= translate('cant_convert_currency', $i18n) ?>
+ </div>
+ </div>
+ <?php
+ }
+ ?>
<div class="split-header">
<h2>Calendar</h2>
<div class="calendar-nav">
@@ -78,6 +138,7 @@ $yearsToLoad = $calendarYear - $currentYear + 1;
$today = $todayYear . '-' . $todayMonth . '-' . $todayDay;
$today = strtotime($today);
?>
+
<div class="calendar">
<div class="calendar-header">
<div class="calendar-cell"><?= translate('mon', $i18n) ?></div>
@@ -115,9 +176,9 @@ $yearsToLoad = $calendarYear - $currentYear + 1;
$nextPaymentDate = strtotime($subscription['next_payment']);
$cycle = $subscription['cycle']; // Integer from 1 to 4
$frequency = $subscription['frequency'];
-
+
$endDate = strtotime("+" . $yearsToLoad . " years", $nextPaymentDate);
-
+
// Determine the strtotime increment string based on cycle
switch ($cycle) {
case 1: // Days
@@ -142,12 +203,17 @@ $yearsToLoad = $calendarYear - $currentYear + 1;
// Find the first payment date of the month by moving backwards
$startDate = $nextPaymentDate;
while ($startDate > $startOfMonth) {
- $startDate = strtotime("-" . $incrementString, $startDate);
+ $startDate = strtotime("-" . $incrementString, $startDate);
}
-
+
for ($date = $startDate; $date <= $endDate; $date = strtotime($incrementString, $date)) {
if (date('Y-m', $date) == $calendarYear . '-' . str_pad($calendarMonth, 2, '0', STR_PAD_LEFT)) {
if (date('d', $date) == $day) {
+ $totalCostThisMonth += getPriceConverted($subscription['price'], $subscription['currency_id'], $db, $userId);
+ $numberOfSubscriptionsToPayThisMonth++;
+ if ($date > $today) {
+ $amountDueThisMonth += getPriceConverted($subscription['price'], $subscription['currency_id'], $db, $userId);
+ }
?>
<div class="calendar-subscription-title" onClick="openSubscriptionModal(<?= $subscription['id'] ?>)">
<?= htmlspecialchars($subscription['name']) ?>
@@ -210,12 +276,17 @@ $yearsToLoad = $calendarYear - $currentYear + 1;
// Find the first payment date of the month by moving backwards
$startDate = $nextPaymentDate;
while ($startDate > $startOfMonth) {
- $startDate = strtotime("-" . $incrementString, $startDate);
+ $startDate = strtotime("-" . $incrementString, $startDate);
}
for ($date = $startDate; $date <= $endDate; $date = strtotime($incrementString, $date)) {
if (date('Y-m', $date) == $calendarYear . '-' . str_pad($calendarMonth, 2, '0', STR_PAD_LEFT)) {
if (date('d', $date) == $day) {
+ $totalCostThisMonth += getPriceConverted($subscription['price'], $subscription['currency_id'], $db, $userId);
+ $numberOfSubscriptionsToPayThisMonth++;
+ if ($date > $today) {
+ $amountDueThisMonth += getPriceConverted($subscription['price'], $subscription['currency_id'], $db, $userId);
+ }
?>
<div class="calendar-subscription-title" onClick="openSubscriptionModal(<?= $subscription['id'] ?>)">
<?= $subscription['name'] ?>
@@ -247,6 +318,28 @@ $yearsToLoad = $calendarYear - $currentYear + 1;
</div>
</div>
</div>
+
+ <div class="calendar-monthly-stats">
+ <div class="calendar-monthly-stats-header">
+ <h3><?= translate("stats", $i18n) ?></h3>
+ </div>
+ <div class="statistics">
+ <div class="statistic">
+ <span>
+ <?= $numberOfSubscriptionsToPayThisMonth ?></span>
+ <div class="title"><?= translate("active_subscriptions", $i18n) ?></div>
+ </div>
+ <div class="statistic">
+ <span><?= CurrencyFormatter::format($totalCostThisMonth, $code) ?></span>
+ <div class="title">Total cost</div>
+ </div>
+ <div class="statistic">
+ <span><?= CurrencyFormatter::format($amountDueThisMonth, $code) ?></span>
+ <div class="title"><?= translate("amount_due", $i18n) ?></div>
+ </div>
+ </div>
+ </div>
+
</section>
<div id="subscriptionModal" class="subscription-modal">
diff --git a/endpoints/cronjobs/sendnotifications.php b/endpoints/cronjobs/sendnotifications.php
index f063f65..aa76020 100644
--- a/endpoints/cronjobs/sendnotifications.php
+++ b/endpoints/cronjobs/sendnotifications.php
@@ -20,6 +20,16 @@ $query = "SELECT id, username FROM user";
$stmt = $db->prepare($query);
$usersToNotify = $stmt->execute();
+function getDaysText($days) {
+ if ($days == 0) {
+ return "Today";
+ } elseif ($days == 1) {
+ return "Tomorrow";
+ } else {
+ return "In " . $days . " days";
+ }
+}
+
while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {
$userId = $userToNotify['id'];
if (php_sapi_name() !== 'cli') {
@@ -213,8 +223,16 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {
$daysToCompare = $days;
}
$nextPaymentDate = new DateTime($rowSubscription['next_payment']);
- $difference = $currentDate->diff($nextPaymentDate)->days + 1;
+
+ $difference = $currentDate->diff($nextPaymentDate)->days;
+ if ($nextPaymentDate > $currentDate) {
+ $difference += 1;
+ }
+
if ($difference === $daysToCompare) {
+ echo "Next payment date: " . $nextPaymentDate->format('Y-m-d') . "<br />";
+ echo "Current date: " . $currentDate->format('Y-m-d') . "<br />";
+ echo "Difference: " . $difference . "<br />";
$notify[$rowSubscription['payer_user_id']][$i]['name'] = $rowSubscription['name'];
$notify[$rowSubscription['payer_user_id']][$i]['price'] = $rowSubscription['price'] . $currencies[$rowSubscription['currency_id']]['symbol'];
$notify[$rowSubscription['payer_user_id']][$i]['currency'] = $currencies[$rowSubscription['currency_id']]['name'];
@@ -244,7 +262,7 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {
$message = "The following subscriptions are up for renewal:\n";
foreach ($perUser as $subscription) {
- $dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
+ $dayText = getDaysText($subscription['days']);
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
}
@@ -313,7 +331,7 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {
}
foreach ($perUser as $subscription) {
- $dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
+ $dayText = getDaysText($subscription['days']);
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
}
@@ -366,7 +384,7 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {
}
foreach ($perUser as $subscription) {
- $dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
+ $dayText = getDaysText($subscription['days']);
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
}
@@ -420,7 +438,7 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {
}
foreach ($perUser as $subscription) {
- $dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
+ $dayText = getDaysText($subscription['days']);
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
}
@@ -469,7 +487,7 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {
}
foreach ($perUser as $subscription) {
- $dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
+ $dayText = getDaysText($subscription['days']);
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
}
@@ -511,7 +529,7 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {
}
foreach ($perUser as $subscription) {
- $dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
+ $dayText = getDaysText($subscription['days']);
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
}
diff --git a/includes/i18n/de.php b/includes/i18n/de.php
index 18aace2..8f243eb 100644
--- a/includes/i18n/de.php
+++ b/includes/i18n/de.php
@@ -364,6 +364,7 @@ $i18n = [
"month-10" => "Oktober",
"month-11" => "November",
"month-12" => "Dezember",
+ "total_cost" => "Gesamtkosten",
// TOTP Page
"insert_totp_code" => "Bitte geben Sie den TOTP-Code ein",
diff --git a/includes/i18n/el.php b/includes/i18n/el.php
index bd2890a..fd40334 100644
--- a/includes/i18n/el.php
+++ b/includes/i18n/el.php
@@ -364,6 +364,7 @@ $i18n = [
"month-10" => "Οκτώβριος",
"month-11" => "Νοέμβριος",
"month-12" => "Δεκέμβριος",
+ "total_cost" => "Συνολικό κόστος",
// TOTP Page
"insert_totp_code" => "Εισάγετε τον κωδικό TOTP",
diff --git a/includes/i18n/en.php b/includes/i18n/en.php
index a218182..6cefaff 100644
--- a/includes/i18n/en.php
+++ b/includes/i18n/en.php
@@ -365,6 +365,7 @@ $i18n = [
"month-10" => "October",
"month-11" => "November",
"month-12" => "December",
+ "total_cost" => "Total Cost",
// TOTP Page
"insert_totp_code" => "Insert TOTP code",
diff --git a/includes/i18n/es.php b/includes/i18n/es.php
index 37da71b..ede2b40 100644
--- a/includes/i18n/es.php
+++ b/includes/i18n/es.php
@@ -364,6 +364,7 @@ $i18n = [
"month-10" => "Octubre",
"month-11" => "Noviembre",
"month-12" => "Diciembre",
+ "total_cost" => "Costo Total",
// TOTP Page
"insert_totp_code" => "Introduce el código TOTP",
diff --git a/includes/i18n/fr.php b/includes/i18n/fr.php
index 6aadfbd..5da586e 100644
--- a/includes/i18n/fr.php
+++ b/includes/i18n/fr.php
@@ -364,6 +364,7 @@ $i18n = [
"month-10" => "Octobre",
"month-11" => "Novembre",
"month-12" => "Décembre",
+ "total_cost" => "Coût total",
// TOTP Page
"insert_totp_code" => "Veuillez insérer le code TOTP",
diff --git a/includes/i18n/it.php b/includes/i18n/it.php
index 92e9510..a35731a 100644
--- a/includes/i18n/it.php
+++ b/includes/i18n/it.php
@@ -384,6 +384,7 @@ $i18n = [
"month-10" => "Ottobre",
"month-11" => "Novembre",
"month-12" => "Dicembre",
+ "total_cost" => "Costo totale",
// TOTP Page
"insert_totp_code" => "Inserisci il codice TOTP",
diff --git a/includes/i18n/jp.php b/includes/i18n/jp.php
index 574c005..003bfcc 100644
--- a/includes/i18n/jp.php
+++ b/includes/i18n/jp.php
@@ -357,6 +357,7 @@ $i18n = [
"month-10" => "10月",
"month-11" => "11月",
"month-12" => "12月",
+ "total_cost" => "合計費用",
// TOTP Page
"insert_totp_code" => "TOTPコードを入力してください",
diff --git a/includes/i18n/ko.php b/includes/i18n/ko.php
index 3a882a9..29cebd3 100644
--- a/includes/i18n/ko.php
+++ b/includes/i18n/ko.php
@@ -364,6 +364,7 @@ $i18n = [
"month-10" => "10월",
"month-11" => "11월",
"month-12" => "12월",
+ "total_cost" => "총 비용",
// TOTP Page
"insert_totp_code" => "2단계 인증 코드를 입력하세요",
diff --git a/includes/i18n/pl.php b/includes/i18n/pl.php
index 4ccf451..26bd40b 100644
--- a/includes/i18n/pl.php
+++ b/includes/i18n/pl.php
@@ -364,6 +364,7 @@ $i18n = [
"month-10" => "Październik",
"month-11" => "Listopad",
"month-12" => "Grudzień",
+ "total_cost" => "Całkowity koszt",
// TOTP Page
"insert_totp_code" => "Wprowadź kod TOTP",
diff --git a/includes/i18n/pt.php b/includes/i18n/pt.php
index f493695..2d6b658 100644
--- a/includes/i18n/pt.php
+++ b/includes/i18n/pt.php
@@ -364,6 +364,7 @@ $i18n = [
"month-10" => "Outubro",
"month-11" => "Novembro",
"month-12" => "Dezembro",
+ "total_cost" => "Custo Total",
// TOTP Page
"insert_totp_code" => "Insira o código TOTP",
diff --git a/includes/i18n/pt_br.php b/includes/i18n/pt_br.php
index 06399fc..0bac791 100644
--- a/includes/i18n/pt_br.php
+++ b/includes/i18n/pt_br.php
@@ -364,6 +364,7 @@ $i18n = [
"month-10" => "Outubro",
"month-11" => "Novembro",
"month-12" => "Dezembro",
+ "total_cost" => "Custo total",
// TOTP Page
"insert_totp_code" => "Insira o código TOTP",
diff --git a/includes/i18n/ru.php b/includes/i18n/ru.php
index 1603a01..3c792b1 100644
--- a/includes/i18n/ru.php
+++ b/includes/i18n/ru.php
@@ -364,6 +364,7 @@ $i18n = [
"month-10" => "Октябрь",
"month-11" => "Ноябрь",
"month-12" => "Декабрь",
+ "total_cost" => "Общая стоимость",
// TOTP Page
"insert_totp_code" => "Введите код TOTP",
diff --git a/includes/i18n/sl.php b/includes/i18n/sl.php
index 2bbba40..eaf4cd3 100644
--- a/includes/i18n/sl.php
+++ b/includes/i18n/sl.php
@@ -357,6 +357,7 @@ $i18n = [
"month-10" => "Oktober",
"month-11" => "November",
"month-12" => "December",
+ "total_cost" => "Skupni stroški",
// TOTP Page
"insert_totp_code" => "Vnesite kodo TOTP",
diff --git a/includes/i18n/sr.php b/includes/i18n/sr.php
index b589b5f..d03c5bc 100644
--- a/includes/i18n/sr.php
+++ b/includes/i18n/sr.php
@@ -364,6 +364,7 @@ $i18n = [
"month-10" => "Октобар",
"month-11" => "Новембар",
"month-12" => "Децембар",
+ "total_cost" => "Укупан трошак",
// TOTP Page
"insert_totp_code" => "Унесите ТОТП код",
diff --git a/includes/i18n/sr_lat.php b/includes/i18n/sr_lat.php
index 3b1da0c..66bc650 100644
--- a/includes/i18n/sr_lat.php
+++ b/includes/i18n/sr_lat.php
@@ -364,6 +364,7 @@ $i18n = [
"month-10" => "Oktobar",
"month-11" => "Novembar",
"month-12" => "Decembar",
+ "total_cost" => "Ukupan trošak",
// TOTP Page
"insert_totp_code" => "Unesite TOTP kod",
diff --git a/includes/i18n/tr.php b/includes/i18n/tr.php
index 50e93e7..f8dc9bc 100644
--- a/includes/i18n/tr.php
+++ b/includes/i18n/tr.php
@@ -364,6 +364,7 @@ $i18n = [
"month-10" => "Ekim",
"month-11" => "Kasım",
"month-12" => "Aralık",
+ "total_cost" => "Toplam Maliyet",
// TOTP Page
"insert_totp_code" => "Lütfen TOTP kodunuzu girin",
diff --git a/includes/i18n/vi.php b/includes/i18n/vi.php
index ee8e72a..8e7c983 100644
--- a/includes/i18n/vi.php
+++ b/includes/i18n/vi.php
@@ -365,6 +365,7 @@ $i18n = [
"month-10" => "Tháng Mười",
"month-11" => "Tháng Mười Một",
"month-12" => "Tháng Mười Hai",
+ "total_cost" => "Tổng chi phí",
// TOTP Page
"insert_totp_code" => "Nhập mã TOTP",
];
diff --git a/includes/i18n/zh_cn.php b/includes/i18n/zh_cn.php
index d747ab7..d3dd630 100644
--- a/includes/i18n/zh_cn.php
+++ b/includes/i18n/zh_cn.php
@@ -384,6 +384,7 @@ $i18n = [
"month-10" => "十月",
"month-11" => "十一月",
"month-12" => "十二月",
+ "total_cost" => "总费用",
// TOTP Page
"insert_totp_code" => "请输入 TOTP 代码",
diff --git a/includes/i18n/zh_tw.php b/includes/i18n/zh_tw.php
index 87652b0..8ab6eae 100644
--- a/includes/i18n/zh_tw.php
+++ b/includes/i18n/zh_tw.php
@@ -364,6 +364,7 @@ $i18n = [
"month-10" => "十月",
"month-11" => "十一月",
"month-12" => "十二月",
+ "total_cost" => "總費用",
// TOTP Page
"insert_totp_code" => "請輸入 TOTP 驗證碼",
diff --git a/includes/version.php b/includes/version.php
index 706b744..4a3f01e 100644
--- a/includes/version.php
+++ b/includes/version.php
@@ -1,3 +1,3 @@
<?php
-$version = "v2.36.2";
+$version = "v2.37.0;
?>
\ No newline at end of file