diff --git a/endpoints/subscriptions/get.php b/endpoints/subscriptions/get.php index cb58505..1f57a5b 100644 --- a/endpoints/subscriptions/get.php +++ b/endpoints/subscriptions/get.php @@ -16,7 +16,7 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) { $sort = "next_payment"; - $sql = "SELECT * FROM subscriptions ORDER BY next_payment ASC"; + $sql = "SELECT * FROM subscriptions ORDER BY next_payment ASC, inactive ASC"; if (isset($_COOKIE['sortOrder']) && $_COOKIE['sortOrder'] != "") { $sort = $_COOKIE['sortOrder']; $allowedSortCriteria = ['name', 'id', 'next_payment', 'price', 'payer_user_id', 'category_id', 'payment_method_id']; @@ -25,7 +25,7 @@ $order = "DESC"; } if (in_array($sort, $allowedSortCriteria)) { - $sql = "SELECT * FROM subscriptions ORDER BY $sort $order"; + $sql = "SELECT * FROM subscriptions ORDER BY $sort $order, inactive ASC"; } } diff --git a/includes/i18n/de.php b/includes/i18n/de.php index f58720d..419dbea 100644 --- a/includes/i18n/de.php +++ b/includes/i18n/de.php @@ -77,6 +77,7 @@ $i18n = [ 'average_monthly' => "Durchschnittliche monatliche Kosten", 'most_expensive' => "Kosten des teuersten Abonnements", 'amount_due' => "Diesen Monat fällige Summe", + 'monthly_savings' => "Monatliche Ersparnisse (bei inaktiven Abonnements)", 'split_views' => "Aufgeteilte Ansichten", 'category_split' => "Kategorien", 'household_split' => "Haushalt", diff --git a/includes/i18n/el.php b/includes/i18n/el.php index 1c8b377..cd75e42 100644 --- a/includes/i18n/el.php +++ b/includes/i18n/el.php @@ -77,6 +77,7 @@ $i18n = [ 'average_monthly' => "Μέσο μηνιαίο κόστος συνδρομής", 'most_expensive' => "Πιο ακριβό κόστος συνδρομής", 'amount_due' => "Ποσό που οφείλεται αυτόν τον μήνα", + 'monthly_savings' => "Μηνιαίες εξοικονομήσεις (σε ανενεργές συνδρομές)", 'split_views' => "Διαχωρισμένες προβολές", 'category_split' => "Διαχωρισμός κατηγορίας", 'household_split' => "Διαχωρισμός νοικοκυριού", diff --git a/includes/i18n/en.php b/includes/i18n/en.php index bd65215..f3d6e2e 100644 --- a/includes/i18n/en.php +++ b/includes/i18n/en.php @@ -77,6 +77,7 @@ $i18n = [ 'average_monthly' => "Average Monthly Subscription Cost", 'most_expensive' => "Most Expensive Subscription Cost", 'amount_due' => "Amount due this month", + 'monthly_savings' => "Monthly Savings (on inactive subscriptions)", 'split_views' => "Split Views", 'category_split' => "Category Split", 'household_split' => "Household Split", diff --git a/includes/i18n/es.php b/includes/i18n/es.php index 15b325d..62d2877 100644 --- a/includes/i18n/es.php +++ b/includes/i18n/es.php @@ -77,6 +77,7 @@ $i18n = [ 'average_monthly' => "Costo Promedio Mensual de Suscripción", 'most_expensive' => "Costo de Suscripción Más Caro", 'amount_due' => "Monto a pagar este mes", + 'monthly_savings' => "Ahorro Mensual (en suscripciones inactivas)", 'split_views' => "Vistas Divididas", 'category_split' => "División por Categoría", 'household_split' => "División por Hogar", diff --git a/includes/i18n/fr.php b/includes/i18n/fr.php index 0d36ab8..6f832d9 100644 --- a/includes/i18n/fr.php +++ b/includes/i18n/fr.php @@ -77,6 +77,7 @@ $i18n = [ 'average_monthly' => "Coût moyen mensuel de l'abonnement", 'most_expensive' => "Coût d'abonnement le plus élevé", 'amount_due' => "Montant dû ce mois-ci", + 'monthly_savings' => "Économies mensuelles (sur les abonnements inactifs)", 'split_views' => "Vues partagées", 'category_split' => "Répartition par catégorie", 'household_split' => "Répartition du ménage", diff --git a/includes/i18n/jp.php b/includes/i18n/jp.php index ca00915..70eb54e 100644 --- a/includes/i18n/jp.php +++ b/includes/i18n/jp.php @@ -77,6 +77,7 @@ $i18n = [ 'average_monthly' => "月額平均費用", 'most_expensive' => "最も高額な定期購入費用", 'amount_due' => "今月の支払額", + 'monthly_savings' => "月間節約 (非アクティブな定期購入)", 'split_views' => "分割表示", 'category_split' => "カテゴリ別", 'household_split' => "世帯別", diff --git a/includes/i18n/pt.php b/includes/i18n/pt.php index c28a133..896e1a2 100644 --- a/includes/i18n/pt.php +++ b/includes/i18n/pt.php @@ -77,6 +77,7 @@ $i18n = [ 'average_monthly' => "Custo Mensal Médio das Subscrições", 'most_expensive' => "Custo da Subscrição Mais Cara", 'amount_due' => "Quantia em dívida este mês", + 'monthly_savings' => "Poupança Mensal (em subscrições inactivas)", 'split_views' => "Vistas Divididas", 'category_split' => "Por Categoria", 'household_split' => "Por Membro", diff --git a/includes/i18n/tr.php b/includes/i18n/tr.php index 90be24b..2fa03e1 100644 --- a/includes/i18n/tr.php +++ b/includes/i18n/tr.php @@ -77,6 +77,7 @@ $i18n = [ 'average_monthly' => "Ortalama Aylık Abonelik Maliyeti", 'most_expensive' => "En Pahalı Abonelik Maliyeti", 'amount_due' => "Bu ay ödenecek miktar", + 'monthly_savings' => "Aylık Tasarruf (aktif olmayan aboneliklerde)", 'split_views' => "Bölünmüş Görünümler", 'category_split' => "Kategori Bölümü", 'household_split' => "Hane Bölümü", diff --git a/includes/i18n/zh_cn.php b/includes/i18n/zh_cn.php index bdf621b..3cd309e 100644 --- a/includes/i18n/zh_cn.php +++ b/includes/i18n/zh_cn.php @@ -82,6 +82,7 @@ $i18n = [ 'average_monthly' => "平均每月订阅费用", 'most_expensive' => "最昂贵订阅费用", 'amount_due' => "本月应付金额", + 'monthly_savings' => "每月节省", 'split_views' => "拆分视图", 'category_split' => "分类视图", 'household_split' => "家庭视图", diff --git a/includes/i18n/zh_tw.php b/includes/i18n/zh_tw.php index b41c61e..845a8e6 100644 --- a/includes/i18n/zh_tw.php +++ b/includes/i18n/zh_tw.php @@ -82,6 +82,7 @@ $i18n = [ 'average_monthly' => "平均每月訂閱費用", 'most_expensive' => "最高的訂閱費用", 'amount_due' => "本月應付金額", + 'monthly_savings' => "每月節省", 'split_views' => "分割表示", 'category_split' => "類別表示", 'household_split' => "家庭表示", diff --git a/includes/version.php b/includes/version.php index d21392f..3bf0b00 100644 --- a/includes/version.php +++ b/includes/version.php @@ -1,3 +1,3 @@ \ No newline at end of file diff --git a/index.php b/index.php index 224fc88..766a05b 100644 --- a/index.php +++ b/index.php @@ -5,7 +5,7 @@ include_once 'includes/list_subscriptions.php'; $sort = "next_payment"; - $sql = "SELECT * FROM subscriptions ORDER BY next_payment ASC"; + $sql = "SELECT * FROM subscriptions ORDER BY next_payment ASC, inactive ASC"; if (isset($_COOKIE['sortOrder']) && $_COOKIE['sortOrder'] != "") { $sort = $_COOKIE['sortOrder']; $allowedSortCriteria = ['name', 'id', 'next_payment', 'price', 'payer_user_id', 'category_id', 'payment_method_id']; @@ -14,7 +14,7 @@ $order = "DESC"; } if (in_array($sort, $allowedSortCriteria)) { - $sql = "SELECT * FROM subscriptions ORDER BY $sort $order"; + $sql = "SELECT * FROM subscriptions ORDER BY $sort $order, inactive ASC"; } } diff --git a/stats.php b/stats.php index c5c1441..3a90c5c 100644 --- a/stats.php +++ b/stats.php @@ -81,21 +81,15 @@ $result = $stmt->execute(); $row = $result->fetchArray(SQLITE3_ASSOC); $code = $row['code']; - -// Calculate active subscriptions -$query = "SELECT COUNT(*) AS active_subscriptions FROM subscriptions WHERE inactive = 0"; -$stmt = $db->prepare($query); -$stmt->bindParam(':criteria', $criteria, SQLITE3_INTEGER); -$result = $stmt->execute(); -$row = $result->fetchArray(SQLITE3_ASSOC); -$activeSubscriptions = $row['active_subscriptions']; - +$activeSubscriptions = 0; +$inactiveSubscriptions = 0; // Calculate total monthly price $mostExpensiveSubscription = 0; $amountDueThisMonth = 0; $totalCostPerMonth = 0; +$totalSavingsPerMonth = 0; -$query = "SELECT name, price, frequency, cycle, currency_id, next_payment, payer_user_id, category_id, payment_method_id FROM subscriptions WHERE inactive = 0"; +$query = "SELECT name, price, frequency, cycle, currency_id, next_payment, payer_user_id, category_id, payment_method_id, inactive FROM subscriptions"; $result = $db->query($query); if ($result) { while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -112,34 +106,42 @@ if ($result) { $payerId = $subscription['payer_user_id']; $categoryId = $subscription['category_id']; $paymentMethodId = $subscription['payment_method_id']; + $inactive = $subscription['inactive']; $originalSubscriptionPrice = getPriceConverted($price, $currency, $db); $price = getPricePerMonth($cycle, $frequency, $originalSubscriptionPrice); - $totalCostPerMonth += $price; - $memberCost[$payerId]['cost'] += $price; - $categoryCost[$categoryId]['cost'] += $price; - $paymentMethodCount[$paymentMethodId]['count'] += 1; - if ($price > $mostExpensiveSubscription) { - $mostExpensiveSubscription = $price; - } - // Calculate ammount due this month - $nextPaymentDate = DateTime::createFromFormat('Y-m-d', trim($next_payment)); - $tomorrow = new DateTime('tomorrow'); - $endOfMonth = new DateTime('last day of this month'); - - if ($nextPaymentDate >= $tomorrow && $nextPaymentDate <= $endOfMonth) { - $timesToPay = 1; - $daysInMonth = $endOfMonth->diff($tomorrow)->days + 1; - $daysRemaining = $endOfMonth->diff($nextPaymentDate)->days + 1; - if ($cycle == 1) { - $timesToPay = $daysRemaining / $frequency; - } - if ($cycle == 2) { - $weeksInMonth = ceil($daysInMonth / 7); - $weeksRemaining = ceil($daysRemaining / 7); - $timesToPay = $weeksRemaining / $frequency; - } - $amountDueThisMonth += $originalSubscriptionPrice * $timesToPay; + if ($inactive == 0) { + $activeSubscriptions++; + $totalCostPerMonth += $price; + $memberCost[$payerId]['cost'] += $price; + $categoryCost[$categoryId]['cost'] += $price; + $paymentMethodCount[$paymentMethodId]['count'] += 1; + if ($price > $mostExpensiveSubscription) { + $mostExpensiveSubscription = $price; + } + + // Calculate ammount due this month + $nextPaymentDate = DateTime::createFromFormat('Y-m-d', trim($next_payment)); + $tomorrow = new DateTime('tomorrow'); + $endOfMonth = new DateTime('last day of this month'); + + if ($nextPaymentDate >= $tomorrow && $nextPaymentDate <= $endOfMonth) { + $timesToPay = 1; + $daysInMonth = $endOfMonth->diff($tomorrow)->days + 1; + $daysRemaining = $endOfMonth->diff($nextPaymentDate)->days + 1; + if ($cycle == 1) { + $timesToPay = $daysRemaining / $frequency; + } + if ($cycle == 2) { + $weeksInMonth = ceil($daysInMonth / 7); + $weeksRemaining = ceil($daysRemaining / 7); + $timesToPay = $weeksRemaining / $frequency; + } + $amountDueThisMonth += $originalSubscriptionPrice * $timesToPay; + } + } else { + $inactiveSubscriptions++; + $totalSavingsPerMonth += $price; } } @@ -185,6 +187,20 @@ $numberOfElements = 6;
0) { + $numberOfElements = 8; + ?> +
+ +
+
+
+ +
+
+