feat: add over budget warnings on the calendar

fix: force correct timezone on the cronjobs
This commit is contained in:
Miguel Ribeiro
2025-04-18 15:43:51 +02:00
committed by GitHub
parent 384cffd7ff
commit 88eae1002f
33 changed files with 87 additions and 6 deletions

View File

@@ -18,6 +18,14 @@ function getPriceConverted($price, $currency, $database, $userId)
}
}
// Get budget from user table
$query = "SELECT budget FROM user WHERE id = :userId";
$stmt = $db->prepare($query);
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
$result = $stmt->execute();
$row = $result->fetchArray(SQLITE3_ASSOC);
$budget = $row['budget'];
$currentMonth = date('m');
$currentYear = date('Y');
$sameAsCurrent = false;
@@ -133,7 +141,7 @@ $yearsToLoad = $calendarYear - $currentYear + 1;
<?php
}
?>
<span id="month"><?= translate('month-' . $calendarMonth, $i18n) ?> <?= $calendarYear ?></span>
<span id="month" class="month"><?= translate('month-' . $calendarMonth, $i18n) ?> <?= $calendarYear ?></span>
<button class="button tiny" id="next" onclick="nextMonth(<?= $calendarMonth ?>, <?= $calendarYear ?>)"><i
class="fa-solid fa-chevron-right"></i></button>
</div>
@@ -336,6 +344,19 @@ $yearsToLoad = $calendarYear - $currentYear + 1;
</div>
</div>
<?php
if ($totalCostThisMonth > $budget) {
$overBudgetAmount = $totalCostThisMonth - $budget;
$overBudgetAmount = CurrencyFormatter::format($overBudgetAmount, $code);
?>
<div class="over-budget">
<i class="fa-solid fa-exclamation-triangle"></i>
<?= translate('over_budget_warning', $i18n) ?> (<?= $overBudgetAmount ?>)
</div>
<?php
}
?>
<div class="calendar-monthly-stats">
<div class="calendar-monthly-stats-header">
<h3><?= translate("stats", $i18n) ?></h3>

View File

@@ -10,6 +10,8 @@ require __DIR__ . '/../../libs/PHPMailer/PHPMailer.php';
require __DIR__ . '/../../libs/PHPMailer/SMTP.php';
require __DIR__ . '/../../libs/PHPMailer/Exception.php';
require 'settimezone.php';
// Get all user ids
$query = "SELECT id, username FROM user";
$stmt = $db->prepare($query);

View File

@@ -12,6 +12,8 @@ require __DIR__ . '/../../libs/PHPMailer/Exception.php';
require __DIR__ . '/../../includes/currency_formatter.php';
require 'settimezone.php';
if (php_sapi_name() == 'cli') {
$date = new DateTime('now');
echo "\n" . $date->format('Y-m-d') . " " . $date->format('H:i:s') . "<br />\n";

View File

@@ -6,6 +6,8 @@ use PHPMailer\PHPMailer\Exception;
require_once 'validate.php';
require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';
require 'settimezone.php';
$query = "SELECT * FROM admin";
$stmt = $db->prepare($query);
$result = $stmt->execute();

View File

@@ -6,6 +6,8 @@ use PHPMailer\PHPMailer\Exception;
require_once 'validate.php';
require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';
require 'settimezone.php';
$query = "SELECT * FROM admin";
$stmt = $db->prepare($query);
$result = $stmt->execute();

View File

@@ -0,0 +1,7 @@
<?php
$timezone = date_default_timezone_get();
if ($timezone == '') {
$timezone = 'UTC';
}
date_default_timezone_set($timezone);

View File

@@ -2,6 +2,8 @@
require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';
require 'settimezone.php';
if (php_sapi_name() == 'cli') {
$date = new DateTime('now');
echo "\n" . $date->format('Y-m-d') . " " . $date->format('H:i:s') . "<br />\n";

View File

@@ -2,6 +2,8 @@
require_once 'validate.php';
require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';
require 'settimezone.php';
// Get all user ids
if (php_sapi_name() == 'cli') {

View File

@@ -3,10 +3,11 @@
require_once 'validate.php';
require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';
if (php_sapi_name() == 'cli') {
$date = new DateTime('now');
echo "\n" . $date->format('Y-m-d') . " " . $date->format('H:i:s') . "<br />\n";
}
require 'settimezone.php';
$date = new DateTime('now');
echo "\n" . $date->format('Y-m-d') . " " . $date->format('H:i:s') . "<br />\n";
echo $timezone . "<br />\n";
$currentDate = new DateTime();
$currentDateString = $currentDate->format('Y-m-d');

View File

@@ -379,6 +379,7 @@ $i18n = [
"month-12" => "Prosinec",
"total_cost" => "Celkové náklady",
"export_icalendar" => "Exportovat iCalendar",
"over_budget_warning" => "Překročili jste rozpočet",
// TOTP Page
"insert_totp_code" => "Vložte kód TOTP",

View File

@@ -378,6 +378,7 @@ $i18n = [
"month-12" => "Dezember",
"total_cost" => "Gesamtkosten",
"export_icalendar" => "iCalendar exportieren",
"over_budget_warning" => "Sie haben Ihr Budget überschritten",
// TOTP Page
"insert_totp_code" => "Bitte geben Sie den TOTP-Code ein",

View File

@@ -378,6 +378,7 @@ $i18n = [
"month-12" => "Δεκέμβριος",
"total_cost" => "Συνολικό κόστος",
"export_icalendar" => "Εξαγωγή iCalendar",
"over_budget_warning" => "Έχετε ξεπεράσει τον προϋπολογισμό",
// TOTP Page
"insert_totp_code" => "Εισάγετε τον κωδικό TOTP",

View File

@@ -379,6 +379,7 @@ $i18n = [
"month-12" => "December",
"total_cost" => "Total Cost",
"export_icalendar" => "Export iCalendar",
"over_budget_warning" => "You're over budget",
// TOTP Page
"insert_totp_code" => "Insert TOTP code",

View File

@@ -378,6 +378,7 @@ $i18n = [
"month-12" => "Diciembre",
"total_cost" => "Costo Total",
"export_icalendar" => "Exportar iCalendar",
"over_budget_warning" => "Te has pasado del presupuesto",
// TOTP Page
"insert_totp_code" => "Introduce el código TOTP",

View File

@@ -379,6 +379,7 @@ $i18n = [
"month-12" => "Décembre",
"total_cost" => "Coût total",
"export_icalendar" => "Exporter en iCalendar",
"over_budget_warning" => "Vous avez dépassé votre budget",
// TOTP Page
"insert_totp_code" => "Veuillez insérer le code TOTP",

View File

@@ -398,6 +398,7 @@ $i18n = [
"month-12" => "Dicembre",
"total_cost" => "Costo totale",
"export_icalendar" => "Esporta iCal",
"over_budget_warning" => "Avete superato il budget",
// TOTP Page
"insert_totp_code" => "Inserisci il codice TOTP",

View File

@@ -379,6 +379,7 @@ $i18n = [
"month-12" => "12月",
"total_cost" => "合計費用",
"export_icalendar" => "iCalendarをエクスポート",
"over_budget_warning" => "予算オーバーだ",
// TOTP Page
"insert_totp_code" => "TOTPコードを入力してください",

View File

@@ -378,6 +378,7 @@ $i18n = [
"month-12" => "12월",
"total_cost" => "총 비용",
"export_icalendar" => "iCalendar 내보내기",
"over_budget_warning" => "예산이 초과되었습니다",
// TOTP Page
"insert_totp_code" => "2단계 인증 코드를 입력하세요",

View File

@@ -379,6 +379,7 @@ $i18n = [
"month-12" => "December",
"total_cost" => "Totale kosten",
"export_icalendar" => "Exporteer iCalendar",
"over_budget_warning" => "U bent over uw budget",
// TOTP Page
"insert_totp_code" => "Voer TOTP code in",

View File

@@ -378,6 +378,7 @@ $i18n = [
"month-12" => "Grudzień",
"total_cost" => "Całkowity koszt",
"export_icalendar" => "Eksportuj do iCalendar",
"over_budget_warning" => "Przekroczyłeś budżet",
// TOTP Page
"insert_totp_code" => "Wprowadź kod TOTP",

View File

@@ -378,6 +378,7 @@ $i18n = [
"month-12" => "Dezembro",
"total_cost" => "Custo Total",
"export_icalendar" => "Exportar iCalendar",
"over_budget_warning" => "O orçamento foi ultrapassado",
// TOTP Page
"insert_totp_code" => "Insira o código TOTP",

View File

@@ -378,6 +378,7 @@ $i18n = [
"month-12" => "Dezembro",
"total_cost" => "Custo total",
"export_icalendar" => "Exportar iCalendar",
"over_budget_warning" => "Você está acima do orçamento",
// TOTP Page
"insert_totp_code" => "Insira o código TOTP",

View File

@@ -378,6 +378,7 @@ $i18n = [
"month-12" => "Декабрь",
"total_cost" => "Общая стоимость",
"export_icalendar" => "Экспорт в iCalendar",
"over_budget_warning" => "Вы превысили бюджет",
// TOTP Page
"insert_totp_code" => "Введите код TOTP",

View File

@@ -371,6 +371,7 @@ $i18n = [
"month-12" => "December",
"total_cost" => "Skupni stroški",
"export_icalendar" => "Izvozi iCalendar",
"over_budget_warning" => "Presegli ste proračun",
// TOTP Page
"insert_totp_code" => "Vnesite kodo TOTP",

View File

@@ -378,6 +378,7 @@ $i18n = [
"month-12" => "Децембар",
"total_cost" => "Укупан трошак",
"export_icalendar" => "Извоз у iCalendar формат",
"over_budget_warning" => "Прекорачили сте буџет",
// TOTP Page
"insert_totp_code" => "Унесите ТОТП код",

View File

@@ -378,6 +378,7 @@ $i18n = [
"month-12" => "Decembar",
"total_cost" => "Ukupan trošak",
"export_icalendar" => "Izvezi iCalendar",
"over_budget_warning" => "Prekoračili ste budžet",
// TOTP Page
"insert_totp_code" => "Unesite TOTP kod",

View File

@@ -378,6 +378,7 @@ $i18n = [
"month-12" => "Aralık",
"total_cost" => "Toplam Maliyet",
"export_icalendar" => "iCalendar olarak dışa aktar",
"over_budget_warning" => "Bütçenizi aştınız",
// TOTP Page
"insert_totp_code" => "Lütfen TOTP kodunuzu girin",

View File

@@ -378,6 +378,7 @@ $i18n = [
"month-12" => "Грудень",
"total_cost" => "Загальна вартість",
"export_icalendar" => "Експорт у iCalendar",
"over_budget_warning" => "Ви перевищили бюджет",
// TOTP Page
"insert_totp_code" => "Введіть код TOTP",

View File

@@ -379,6 +379,7 @@ $i18n = [
"month-12" => "Tháng Mười Hai",
"total_cost" => "Tổng chi phí",
"export_icalendar" => "Xuất iCalendar",
"over_budget_warning" => "Bạn đang vượt quá ngân sách",
// TOTP Page
"insert_totp_code" => "Nhập mã TOTP",
];

View File

@@ -398,6 +398,7 @@ $i18n = [
"month-12" => "十二月",
"total_cost" => "总费用",
"export_icalendar" => "导出 iCalendar",
"over_budget_warning" => "您超出预算",
// TOTP Page
"insert_totp_code" => "请输入 TOTP 代码",

View File

@@ -379,6 +379,7 @@ $i18n = [
"month-12" => "十二月",
"total_cost" => "總費用",
"export_icalendar" => "匯出 iCalendar",
"over_budget_warning" => "您超出預算",
// TOTP 頁面
"insert_totp_code" => "請輸入 TOTP 驗證碼",

View File

@@ -1,3 +1,3 @@
<?php
$version = "v2.50.1";
$version = "v2.51.0";
?>

View File

@@ -2377,6 +2377,10 @@ button.dark-theme-button i {
font-size: 18px;
}
.calendar-nav .month {
text-align: center;
}
.calendar {
display: flex;
flex-direction: column;
@@ -2477,6 +2481,20 @@ button.dark-theme-button i {
font-weight: 700;
}
.over-budget {
background-color: rgba(var(--error-color-rgb), 0.2);
border: 1px solid var(--error-color);
border-radius: 8px;
padding: 10px;
margin-top: 20px;
text-align: center;
font-size: 16px;
}
.over-budget>i {
color: var(--error-color);
}
.subscription-modal {
max-width: 400px;
}