diff --git a/calendar.php b/calendar.php index b54388b03..66ec25975 100644 --- a/calendar.php +++ b/calendar.php @@ -1,6 +1,23 @@ 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 @@ $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 @@ $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; ?>
+ +
+
+ + +
+
+

Calendar

@@ -78,6 +138,7 @@ class="fa-solid fa-chevron-right"> $today = $todayYear . '-' . $todayMonth . '-' . $todayDay; $today = strtotime($today); ?> +
@@ -115,9 +176,9 @@ class="fa-solid fa-chevron-right"> $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 @@ class="fa-solid fa-chevron-right"> // 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); + } ?>
@@ -210,12 +276,17 @@ class="fa-solid fa-chevron-right"> // 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); + } ?>
@@ -247,6 +318,28 @@ class="fa-solid fa-chevron-right">
+ +
+
+

+
+
+
+ + +
+
+
+ +
Total cost
+
+
+ +
+
+
+
+
diff --git a/includes/i18n/de.php b/includes/i18n/de.php index 18aace26a..8f243ebc0 100644 --- a/includes/i18n/de.php +++ b/includes/i18n/de.php @@ -364,6 +364,7 @@ "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 bd2890a75..fd4033496 100644 --- a/includes/i18n/el.php +++ b/includes/i18n/el.php @@ -364,6 +364,7 @@ "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 a21818220..6cefaffa1 100644 --- a/includes/i18n/en.php +++ b/includes/i18n/en.php @@ -365,6 +365,7 @@ "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 37da71b7e..ede2b4079 100644 --- a/includes/i18n/es.php +++ b/includes/i18n/es.php @@ -364,6 +364,7 @@ "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 6aadfbd6e..5da586e88 100644 --- a/includes/i18n/fr.php +++ b/includes/i18n/fr.php @@ -364,6 +364,7 @@ "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 92e951085..a35731a2c 100644 --- a/includes/i18n/it.php +++ b/includes/i18n/it.php @@ -384,6 +384,7 @@ "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 574c005b7..003bfcc53 100644 --- a/includes/i18n/jp.php +++ b/includes/i18n/jp.php @@ -357,6 +357,7 @@ "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 3a882a92b..29cebd37c 100644 --- a/includes/i18n/ko.php +++ b/includes/i18n/ko.php @@ -364,6 +364,7 @@ "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 4ccf45152..26bd40bc4 100644 --- a/includes/i18n/pl.php +++ b/includes/i18n/pl.php @@ -364,6 +364,7 @@ "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 f49369506..2d6b6589f 100644 --- a/includes/i18n/pt.php +++ b/includes/i18n/pt.php @@ -364,6 +364,7 @@ "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 06399fce3..0bac79125 100644 --- a/includes/i18n/pt_br.php +++ b/includes/i18n/pt_br.php @@ -364,6 +364,7 @@ "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 1603a0155..3c792b1f5 100644 --- a/includes/i18n/ru.php +++ b/includes/i18n/ru.php @@ -364,6 +364,7 @@ "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 2bbba4028..eaf4cd3ee 100644 --- a/includes/i18n/sl.php +++ b/includes/i18n/sl.php @@ -357,6 +357,7 @@ "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 b589b5f69..d03c5bcee 100644 --- a/includes/i18n/sr.php +++ b/includes/i18n/sr.php @@ -364,6 +364,7 @@ "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 3b1da0cda..66bc650b3 100644 --- a/includes/i18n/sr_lat.php +++ b/includes/i18n/sr_lat.php @@ -364,6 +364,7 @@ "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 50e93e74f..f8dc9bc77 100644 --- a/includes/i18n/tr.php +++ b/includes/i18n/tr.php @@ -364,6 +364,7 @@ "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 ee8e72a03..8e7c983b7 100644 --- a/includes/i18n/vi.php +++ b/includes/i18n/vi.php @@ -365,6 +365,7 @@ "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 d747ab748..d3dd63020 100644 --- a/includes/i18n/zh_cn.php +++ b/includes/i18n/zh_cn.php @@ -384,6 +384,7 @@ "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 87652b061..8ab6eaeab 100644 --- a/includes/i18n/zh_tw.php +++ b/includes/i18n/zh_tw.php @@ -364,6 +364,7 @@ "month-10" => "十月", "month-11" => "十一月", "month-12" => "十二月", + "total_cost" => "總費用", // TOTP Page "insert_totp_code" => "請輸入 TOTP 驗證碼",