Skip to content

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

feat: cancellation in dashboard & general statistics (#1207)

gwprestone38403d920ed
diff --git a/endpoints/cronjobs/sendcancellationnotifications.php b/endpoints/cronjobs/sendcancellationnotifications.php
index dd07cb7..64ab37e 100644
--- a/endpoints/cronjobs/sendcancellationnotifications.php
+++ b/endpoints/cronjobs/sendcancellationnotifications.php
@@ -178,11 +178,14 @@ while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {
$currentDate = new DateTime('now');
$currentDate = $currentDate->format('Y-m-d');
- $query = "SELECT * FROM subscriptions WHERE user_id = :user_id AND inactive = :inactive AND cancellation_date = :cancellationDate ORDER BY payer_user_id ASC";
+ // One-time purchases have no recurring commitment to cancel, and the
+ // subscription form clears their cancellation date, so never notify for them.
+ $query = "SELECT * FROM subscriptions WHERE user_id = :user_id AND inactive = :inactive AND cancellation_date = :cancellationDate AND cycle != :oneTimeCycle ORDER BY payer_user_id ASC";
$stmt = $db->prepare($query);
$stmt->bindValue(':user_id', $userId, SQLITE3_INTEGER);
$stmt->bindValue(':inactive', 0, SQLITE3_INTEGER);
$stmt->bindValue(':cancellationDate', $currentDate, SQLITE3_TEXT);
+ $stmt->bindValue(':oneTimeCycle', 5, SQLITE3_INTEGER);
$resultSubscriptions = $stmt->execute();
$notify = [];
diff --git a/endpoints/subscriptions/get.php b/endpoints/subscriptions/get.php
index d14be44..6d4d7cb 100644
--- a/endpoints/subscriptions/get.php
+++ b/endpoints/subscriptions/get.php
@@ -104,9 +104,11 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
if ($type === 'reminder') {
$notifConditions[] = "notify = 1";
} elseif ($type === 'cancellation') {
- $notifConditions[] = "(cancellation_date IS NOT NULL AND cancellation_date != '')";
+ // One-time purchases are never treated as cancellable, matching the
+ // dashboard, statistics page and cancellation notification cron.
+ $notifConditions[] = "(cancellation_date IS NOT NULL AND cancellation_date != '' AND cycle != 5)";
} elseif ($type === 'none') {
- $notifConditions[] = "(notify = 0 AND (cancellation_date IS NULL OR cancellation_date = ''))";
+ $notifConditions[] = "(notify = 0 AND (cancellation_date IS NULL OR cancellation_date = '' OR cycle = 5))";
}
}
if (!empty($notifConditions)) {
diff --git a/includes/i18n/ar.php b/includes/i18n/ar.php
index 6fb9569..fabb6f4 100644
--- a/includes/i18n/ar.php
+++ b/includes/i18n/ar.php
@@ -50,6 +50,7 @@ $i18n = [
// لوحة التحكم
"hello" => "مرحبًا",
"upcoming_payments" => "المدفوعات القادمة",
+ "upcoming_cancellations" => "الإلغاءات القادمة",
"upcoming_payments_to_show" => "المدفوعات القادمة المعروضة",
"no_upcoming_payments" => "ليس لديك أي مدفوعات قادمة",
"overdue_renewals" => "التجديدات المتأخرة",
@@ -145,6 +146,8 @@ $i18n = [
"amount_over_budget" => "مقدار تجاوز الميزانية",
"monthly_savings" => "التوفير الشهري (من الاشتراكات المعطلة)",
"yearly_savings" => "التوفير السنوي (من الاشتراكات المعطلة)",
+ "potential_monthly_savings" => "التوفير الشهري المحتمل",
+ "potential_yearly_savings" => "التوفير السنوي المحتمل",
"split_views" => "طرق توزيع البيانات",
"category_split" => "التوزيع حسب التصنيف",
"household_split" => "التوزيع حسب أفراد الأسرة",
diff --git a/includes/i18n/az.php b/includes/i18n/az.php
index 816939b..aa0226f 100644
--- a/includes/i18n/az.php
+++ b/includes/i18n/az.php
@@ -50,6 +50,7 @@ $i18n = [
// Dashboard
"hello" => "Salam",
"upcoming_payments" => "Yaxınlaşan ödənişlər",
+ "upcoming_cancellations" => "Yaxınlaşan ləğvetmələr",
"upcoming_payments_to_show" => "Göstəriləcək yaxınlaşan ödənişlər",
"no_upcoming_payments" => "Yaxınlaşan ödənişiniz yoxdur",
"overdue_renewals" => "Vaxtı keçmiş yenilənmələr",
@@ -145,6 +146,8 @@ $i18n = [
"amount_over_budget" => "Büdcədən artıq məbləğ",
"monthly_savings" => "Aylıq qənaət (deaktiv abunələr üzrə)",
"yearly_savings" => "İllik qənaət (deaktiv abunələr üzrə)",
+ "potential_monthly_savings" => "Potensial aylıq qənaət",
+ "potential_yearly_savings" => "Potensial illik qənaət",
"split_views" => "Bölgü görünüşləri",
"category_split" => "Kateqoriya üzrə bölgü",
"household_split" => "Ev təsərrüfatı üzrə bölgü",
diff --git a/includes/i18n/ca.php b/includes/i18n/ca.php
index 9d02349..2a64127 100644
--- a/includes/i18n/ca.php
+++ b/includes/i18n/ca.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Hola",
"upcoming_payments" => "Pròxims Pagaments",
+ "upcoming_cancellations" => "Pròximes Cancel·lacions",
"upcoming_payments_to_show" => "Pròxims pagaments a mostrar",
"no_upcoming_payments" => "No tens pròxims pagaments",
"overdue_renewals" => "Renovacions Endarrerides",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Import per sobre del pressupost",
"monthly_savings" => "Estalvi Mensual (en subscripcions no actives)",
"yearly_savings" => "Estalvi Anual (en subscripcions no actives)",
+ "potential_monthly_savings" => "Estalvi Mensual Potencial",
+ "potential_yearly_savings" => "Estalvi Anual Potencial",
"split_views" => "Vistes Dividides",
"category_split" => "Divisió per Categoria",
"household_split" => "Divisió per Membres Familiars",
diff --git a/includes/i18n/cs.php b/includes/i18n/cs.php
index c0522b9..719d5c4 100644
--- a/includes/i18n/cs.php
+++ b/includes/i18n/cs.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Ahoj",
"upcoming_payments" => "Plánované platby",
+ "upcoming_cancellations" => "Plánovaná zrušení",
"upcoming_payments_to_show" => "Zobrazené plánované platby",
"no_upcoming_payments" => "Žádné plánované platby",
"overdue_renewals" => "Zpožděná obnovení",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Částka nad rozpočet",
"monthly_savings" => "Měsíční úspory (na neaktivních předplatných)",
"yearly_savings" => "Roční úspory (na neaktivních předplatných)",
+ "potential_monthly_savings" => "Potenciální měsíční úspora",
+ "potential_yearly_savings" => "Potenciální roční úspora",
"split_views" => "Zobrazení rozdělení",
"category_split" => "Rozdělení kategorií",
"household_split" => "Rozdělení domácnosti",
diff --git a/includes/i18n/da.php b/includes/i18n/da.php
index 7b29119..a6d9f1d 100644
--- a/includes/i18n/da.php
+++ b/includes/i18n/da.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Hej",
"upcoming_payments" => "Kommende betalinger",
+ "upcoming_cancellations" => "Kommende annulleringer",
"upcoming_payments_to_show" => "Kommende betalinger, der vises",
"no_upcoming_payments" => "Du har ingen kommende betalinger",
"overdue_renewals" => "Forsinkede fornyelser",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Beløb over budget",
"monthly_savings" => "Månedlige besparelser (på inaktive abonnementer)",
"yearly_savings" => "Årlige besparelser (på inaktive abonnementer)",
+ "potential_monthly_savings" => "Potentiel månedlig besparelse",
+ "potential_yearly_savings" => "Potentiel årlig besparelse",
"split_views" => "Opdelte visninger",
"category_split" => "Kategoriopdeling",
"household_split" => "Husstandsopdeling",
diff --git a/includes/i18n/de.php b/includes/i18n/de.php
index 2385f07..df9900b 100644
--- a/includes/i18n/de.php
+++ b/includes/i18n/de.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Hallo",
"upcoming_payments" => "Bevorstehende Zahlungen",
+ "upcoming_cancellations" => "Bevorstehende Kündigungen",
"upcoming_payments_to_show" => "Anzuzeigende bevorstehende Zahlungen",
"no_upcoming_payments" => "Sie haben keine bevorstehenden Zahlungen",
"overdue_renewals" => "Überfällige Verlängerungen",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Überzogenes Budget",
"monthly_savings" => "Monatliche Ersparnisse (bei inaktiven Abonnements)",
"yearly_savings" => "Jährliche Ersparnisse (bei inaktiven Abonnements)",
+ "potential_monthly_savings" => "Mögliche monatliche Einsparung",
+ "potential_yearly_savings" => "Mögliche jährliche Einsparung",
"split_views" => "Aufgeteilte Ansichten",
"category_split" => "Kategorien",
"household_split" => "Haushalt",
diff --git a/includes/i18n/el.php b/includes/i18n/el.php
index b0a10b0..0c71a55 100644
--- a/includes/i18n/el.php
+++ b/includes/i18n/el.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Γειά σου",
"upcoming_payments" => "Επερχόμενες Πληρωμές",
+ "upcoming_cancellations" => "Επερχόμενες Ακυρώσεις",
"upcoming_payments_to_show" => "Επερχόμενες πληρωμές προς εμφάνιση",
"no_upcoming_payments" => "Δεν έχετε καμία επερχόμενη πληρωμή",
"overdue_renewals" => "Καθυστερημένες Ανανεώσεις",
@@ -141,6 +142,8 @@ $i18n = [
"amount_over_budget" => "Ποσό πάνω από τον προϋπολογισμό",
"monthly_savings" => "Μηνιαίες εξοικονομήσεις (σε ανενεργές συνδρομές)",
"yearly_savings" => "Ετήσιες εξοικονομήσεις (σε ανενεργές συνδρομές)",
+ "potential_monthly_savings" => "Πιθανή Μηνιαία Εξοικονόμηση",
+ "potential_yearly_savings" => "Πιθανή Ετήσια Εξοικονόμηση",
"split_views" => "Διαχωρισμένες προβολές",
"category_split" => "Διαχωρισμός κατηγορίας",
"household_split" => "Διαχωρισμός νοικοκυριού",
diff --git a/includes/i18n/en.php b/includes/i18n/en.php
index 06b5a99..c79ce74 100644
--- a/includes/i18n/en.php
+++ b/includes/i18n/en.php
@@ -50,6 +50,7 @@ $i18n = [
// Dashboard
"hello" => "Hello",
"upcoming_payments" => "Upcoming Payments",
+ "upcoming_cancellations" => "Upcoming Cancellations",
"upcoming_payments_to_show" => "Upcoming payments to show",
"no_upcoming_payments" => "You don't have any upcoming payments",
"overdue_renewals" => "Overdue Renewals",
@@ -145,6 +146,8 @@ $i18n = [
"amount_over_budget" => "Amount over budget",
"monthly_savings" => "Monthly Savings (on inactive subscriptions)",
"yearly_savings" => "Yearly Savings (on inactive subscriptions)",
+ "potential_monthly_savings" => "Potential Monthly Savings",
+ "potential_yearly_savings" => "Potential Yearly Savings",
"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 10217b7..a2ead4d 100644
--- a/includes/i18n/es.php
+++ b/includes/i18n/es.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Hola",
"upcoming_payments" => "Próximos Pagos",
+ "upcoming_cancellations" => "Próximas Cancelaciones",
"upcoming_payments_to_show" => "Próximos pagos a mostrar",
"no_upcoming_payments" => "No tienes pagos próximos",
"overdue_renewals" => "Renovaciones Atrasadas",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Monto sobre el presupuesto",
"monthly_savings" => "Ahorro Mensual (en suscripciones inactivas)",
"yearly_savings" => "Ahorro Anual (en suscripciones inactivas)",
+ "potential_monthly_savings" => "Ahorro Mensual Potencial",
+ "potential_yearly_savings" => "Ahorro Anual Potencial",
"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 7de5d64..2bb1d9e 100644
--- a/includes/i18n/fr.php
+++ b/includes/i18n/fr.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Bonjour",
"upcoming_payments" => "Paiements à venir",
+ "upcoming_cancellations" => "Annulations à venir",
"upcoming_payments_to_show" => "Paiements à venir à afficher",
"no_upcoming_payments" => "Vous n'avez aucun paiement à venir",
"overdue_renewals" => "Renouvellements en retard",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Montant dépassant le budget",
"monthly_savings" => "Économies mensuelles (sur les abonnements inactifs)",
"yearly_savings" => "Économies annuelles (sur les abonnements inactifs)",
+ "potential_monthly_savings" => "Économies mensuelles potentielles",
+ "potential_yearly_savings" => "Économies annuelles potentielles",
"split_views" => "Vues partagées",
"category_split" => "Répartition par catégorie",
"household_split" => "Répartition du ménage",
diff --git a/includes/i18n/hu.php b/includes/i18n/hu.php
index 2464494..3051822 100644
--- a/includes/i18n/hu.php
+++ b/includes/i18n/hu.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Üdvözlöm",
"upcoming_payments" => "Közelgő fizetések",
+ "upcoming_cancellations" => "Közelgő lemondások",
"upcoming_payments_to_show" => "Megjelenítendő közelgő fizetések",
"no_upcoming_payments" => "Nincsenek közelgő fizetései",
"overdue_renewals" => "Lejárt megújítások",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Költségvetés feletti összeg",
"monthly_savings" => "Havi megtakarítások (inaktív előfizetéseken)",
"yearly_savings" => "Éves megtakarítások (inaktív előfizetéseken)",
+ "potential_monthly_savings" => "Lehetséges havi megtakarítás",
+ "potential_yearly_savings" => "Lehetséges éves megtakarítás",
"split_views" => "Osztott nézetek",
"category_split" => "Kategória szerinti megoszlás",
"household_split" => "Háztartás szerinti megoszlás",
diff --git a/includes/i18n/id.php b/includes/i18n/id.php
index a5279bb..ac4992c 100644
--- a/includes/i18n/id.php
+++ b/includes/i18n/id.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Halo",
"upcoming_payments" => "Pembayaran Mendatang",
+ "upcoming_cancellations" => "Pembatalan Mendatang",
"upcoming_payments_to_show" => "Pembayaran mendatang yang ditampilkan",
"no_upcoming_payments" => "Anda tidak memiliki pembayaran mendatang",
"overdue_renewals" => "Perpanjangan Terlambat",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Jumlah melebihi anggaran",
"monthly_savings" => "Penghematan Bulanan (pada langganan tidak aktif)",
"yearly_savings" => "Penghematan Tahunan (pada langganan tidak aktif)",
+ "potential_monthly_savings" => "Potensi Penghematan Bulanan",
+ "potential_yearly_savings" => "Potensi Penghematan Tahunan",
"split_views" => "Tampilan Terpisah",
"category_split" => "Pemisahan Kategori",
"household_split" => "Pemisahan Rumah Tangga",
diff --git a/includes/i18n/it.php b/includes/i18n/it.php
index bd5474a..8c1e602 100644
--- a/includes/i18n/it.php
+++ b/includes/i18n/it.php
@@ -52,6 +52,7 @@ $i18n = [
// Dashboard
"hello" => "Ciao",
"upcoming_payments" => "Pagamenti in arrivo",
+ "upcoming_cancellations" => "Cancellazioni in arrivo",
"upcoming_payments_to_show" => "Pagamenti in arrivo da mostrare",
"no_upcoming_payments" => "Non hai pagamenti in arrivo",
"overdue_renewals" => "Rinnovi scaduti",
@@ -148,6 +149,8 @@ $i18n = [
"amount_over_budget" => 'Importo oltre il budget',
"monthly_savings" => 'Risparmi mensili (su abbonamenti inattivi)',
"yearly_savings" => 'Risparmi annuali (su abbonamenti inattivi)',
+ "potential_monthly_savings" => "Risparmio mensile potenziale",
+ "potential_yearly_savings" => "Risparmio annuale potenziale",
"split_views" => 'Visualizzazioni con grafici',
"category_split" => 'Suddivisione per categoria',
"household_split" => 'Suddivisione per nucleo familiare',
diff --git a/includes/i18n/ja.php b/includes/i18n/ja.php
index f167c98..7326aed 100644
--- a/includes/i18n/ja.php
+++ b/includes/i18n/ja.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "こんにちは",
"upcoming_payments" => "今後の支払い",
+ "upcoming_cancellations" => "今後のキャンセル",
"upcoming_payments_to_show" => "表示する今後の支払い",
"no_upcoming_payments" => "今後の支払いはありません",
"overdue_renewals" => "期限切れの更新",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "予算オーバー",
"monthly_savings" => "月間節約 (非アクティブな定期購入)",
"yearly_savings" => "年間節約 (非アクティブな定期購入)",
+ "potential_monthly_savings" => "想定される月間節約額",
+ "potential_yearly_savings" => "想定される年間節約額",
"split_views" => "分割表示",
"category_split" => "カテゴリ別",
"household_split" => "世帯別",
diff --git a/includes/i18n/ko.php b/includes/i18n/ko.php
index 4ef3e56..8d8b77e 100644
--- a/includes/i18n/ko.php
+++ b/includes/i18n/ko.php
@@ -50,6 +50,7 @@ $i18n = [
// Dashboard
"hello" => "안녕하세요!",
"upcoming_payments" => "결제 예정",
+ "upcoming_cancellations" => "취소 예정",
"upcoming_payments_to_show" => "표시할 예정된 결제",
"no_upcoming_payments" => "예정된 결제가 없습니다.",
"overdue_renewals" => "갱신 필요",
@@ -145,6 +146,8 @@ $i18n = [
"amount_over_budget" => "초과된 예산",
"monthly_savings" => "월간 절약액",
"yearly_savings" => "연간 절약액",
+ "potential_monthly_savings" => "예상 월 절감액",
+ "potential_yearly_savings" => "예상 연 절감액",
"split_views" => "스플릿 뷰",
"category_split" => "카테고리별 분포",
"household_split" => "가구 구성별 분포",
diff --git a/includes/i18n/nl.php b/includes/i18n/nl.php
index 7bfe70e..2e4056b 100644
--- a/includes/i18n/nl.php
+++ b/includes/i18n/nl.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Hallo",
"upcoming_payments" => "Aankomende Betalingen",
+ "upcoming_cancellations" => "Aankomende Annuleringen",
"upcoming_payments_to_show" => "Weer te geven aankomende betalingen",
"no_upcoming_payments" => "Je hebt geen aankomende betalingen",
"overdue_renewals" => "Verlopen Verlengen",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Bedrag over budget",
"monthly_savings" => "Maandelijkse besparingen (op inactieve abonnementen)",
"yearly_savings" => "Jaarlijkse besparingen (op inactieve abonnementen)",
+ "potential_monthly_savings" => "Potentiële Maandelijkse Besparing",
+ "potential_yearly_savings" => "Potentiële Jaarlijkse Besparing",
"split_views" => "Verdelingen",
"category_split" => "Categorieverdeling",
"household_split" => "Huishoudenverdeling",
diff --git a/includes/i18n/pl.php b/includes/i18n/pl.php
index 1d91681..7533790 100644
--- a/includes/i18n/pl.php
+++ b/includes/i18n/pl.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Cześć",
"upcoming_payments" => "Nadchodzące płatności",
+ "upcoming_cancellations" => "Nadchodzące anulowania",
"upcoming_payments_to_show" => "Wyświetlane nadchodzące płatności",
"no_upcoming_payments" => "Nie masz żadnych nadchodzących płatności",
"overdue_renewals" => "Zaległe odnowienia",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Kwota przekraczająca budżet",
"monthly_savings" => "Miesięczne oszczędności (w przypadku nieaktywnych subskrypcji)",
"yearly_savings" => "Roczne oszczędności (w przypadku nieaktywnych subskrypcji)",
+ "potential_monthly_savings" => "Potencjalne oszczędności miesięczne",
+ "potential_yearly_savings" => "Potencjalne oszczędności roczne",
"split_views" => "Podziel widoki",
"category_split" => "Podział kategorii",
"household_split" => "Podział gospodarstwa domowego",
diff --git a/includes/i18n/pt.php b/includes/i18n/pt.php
index d99d2d2..e9067e6 100644
--- a/includes/i18n/pt.php
+++ b/includes/i18n/pt.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Olá",
"upcoming_payments" => "Próximos Pagamentos",
+ "upcoming_cancellations" => "Próximos Cancelamentos",
"upcoming_payments_to_show" => "Próximos pagamentos a mostrar",
"no_upcoming_payments" => "Você não tem pagamentos agendados",
"overdue_renewals" => "Renovações Atrasadas",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Quantia acima do orçamento",
"monthly_savings" => "Poupança Mensal (em subscrições inactivas)",
"yearly_savings" => "Poupança Anual (em subscrições inactivas)",
+ "potential_monthly_savings" => "Poupança Mensal Potencial",
+ "potential_yearly_savings" => "Poupança Anual Potencial",
"split_views" => "Vistas Divididas",
"category_split" => "Por Categoria",
"household_split" => "Por Membro",
diff --git a/includes/i18n/pt_br.php b/includes/i18n/pt_br.php
index 20a7aff..270d7f8 100644
--- a/includes/i18n/pt_br.php
+++ b/includes/i18n/pt_br.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Olá",
"upcoming_payments" => "Pagamentos Futuros",
+ "upcoming_cancellations" => "Cancelamentos Futuros",
"upcoming_payments_to_show" => "Pagamentos futuros a exibir",
"no_upcoming_payments" => "Você não tem pagamentos futuros",
"overdue_renewals" => "Renovações Atrasadas",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Valor acima do orçamento",
"monthly_savings" => "Economia mensal (em assinaturas inativas)",
"yearly_savings" => "Economia anual (em assinaturas inativas)",
+ "potential_monthly_savings" => "Economia Mensal Potencial",
+ "potential_yearly_savings" => "Economia Anual Potencial",
"split_views" => "Visualizações",
"category_split" => "Por categoria",
"household_split" => "Por membro",
diff --git a/includes/i18n/ro.php b/includes/i18n/ro.php
index b207fac..2a28861 100644
--- a/includes/i18n/ro.php
+++ b/includes/i18n/ro.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Salut",
"upcoming_payments" => "Plăți scadente",
+ "upcoming_cancellations" => "Anulări viitoare",
"upcoming_payments_to_show" => "Plăți scadente de afișat",
"no_upcoming_payments" => "Nu există plăți scadente",
"overdue_renewals" => "Reînnoiri scadente",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Suma peste buget",
"monthly_savings" => "Economii lunare (abonamente inactive)",
"yearly_savings" => "Economii anuale (abonamente inactive)",
+ "potential_monthly_savings" => "Economii lunare potențiale",
+ "potential_yearly_savings" => "Economii anuale potențiale",
"split_views" => "Vizualizare împărțită",
"category_split" => "După categorii",
"household_split" => "După membrii familiei",
diff --git a/includes/i18n/ru.php b/includes/i18n/ru.php
index c832449..77c81ff 100644
--- a/includes/i18n/ru.php
+++ b/includes/i18n/ru.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Привет",
"upcoming_payments" => "Предстоящие платежи",
+ "upcoming_cancellations" => "Предстоящие отмены",
"upcoming_payments_to_show" => "Отображаемые предстоящие платежи",
"no_upcoming_payments" => "У вас нет предстоящих платежей",
"overdue_renewals" => "Просроченные продления",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Сумма превышения бюджета",
"monthly_savings" => "Ежемесячная экономия (при неактивных подписках)",
"yearly_savings" => "Годовая экономия (при неактивных подписках)",
+ "potential_monthly_savings" => "Потенциальная экономия в месяц",
+ "potential_yearly_savings" => "Потенциальная экономия в год",
"split_views" => "Подробная статистика",
"category_split" => "По категориям",
"household_split" => "По членам семьи",
diff --git a/includes/i18n/sl.php b/includes/i18n/sl.php
index 697bed8..bc03ecc 100644
--- a/includes/i18n/sl.php
+++ b/includes/i18n/sl.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Pozdravljen",
"upcoming_payments" => "Prihajajoča plačila",
+ "upcoming_cancellations" => "Prihajajoči preklici",
"upcoming_payments_to_show" => "Prikazana prihajajoča plačila",
"no_upcoming_payments" => "Nimate prihodnjih plačil",
"overdue_renewals" => "Zapadla podaljšanja",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Znesek nad proračunom",
"monthly_savings" => "Mesečni prihranek (pri neaktivnih naročninah)",
"yearly_savings" => "Letni prihranki (pri neaktivnih naročninah)",
+ "potential_monthly_savings" => "Možni mesečni prihranek",
+ "potential_yearly_savings" => "Možni letni prihranek",
"split_views" => "Razdeljeni pogledi",
"category_split" => "Razdelitev kategorije",
"household_split" => "Razdelitev gospodinjstva",
diff --git a/includes/i18n/sr.php b/includes/i18n/sr.php
index a5b8811..53e4a9d 100644
--- a/includes/i18n/sr.php
+++ b/includes/i18n/sr.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Здраво",
"upcoming_payments" => "Предстојећа плаћања",
+ "upcoming_cancellations" => "Предстојећа отказивања",
"upcoming_payments_to_show" => "Приказана предстојећа плаћања",
"no_upcoming_payments" => "Немате предстојећих плаћања",
"overdue_renewals" => "Засадне обнове",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Износ преко буџета",
"monthly_savings" => "Месечне уштеде (на неактивним претплатама)",
"yearly_savings" => "Годишње уштеде (на неактивним претплатама)",
+ "potential_monthly_savings" => "Могућа месечна уштеда",
+ "potential_yearly_savings" => "Могућа годишња уштеда",
"split_views" => "Подељени прикази",
"category_split" => "Подела по категоријама",
"household_split" => "Подела по домаћинству",
diff --git a/includes/i18n/sr_lat.php b/includes/i18n/sr_lat.php
index 863cbee..d0a965c 100644
--- a/includes/i18n/sr_lat.php
+++ b/includes/i18n/sr_lat.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Zdravo",
"upcoming_payments" => "Predstojeće uplate",
+ "upcoming_cancellations" => "Predstojeća otkazivanja",
"upcoming_payments_to_show" => "Prikazane predstojeće uplate",
"no_upcoming_payments" => "Nemate predstojećih uplata",
"overdue_renewals" => "Zakasne obnove",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Iznos preko budžeta",
"monthly_savings" => "Mesečne uštede (na neaktivnim pretplatama)",
"yearly_savings" => "Godišnje uštede (na neaktivnim pretplatama)",
+ "potential_monthly_savings" => "Moguća mesečna ušteda",
+ "potential_yearly_savings" => "Moguća godišnja ušteda",
"split_views" => "Podeljene statistike",
"category_split" => "Podela po kategorijama",
"household_split" => "Podela po domaćinstvima",
diff --git a/includes/i18n/tr.php b/includes/i18n/tr.php
index 5d77138..efd41f8 100644
--- a/includes/i18n/tr.php
+++ b/includes/i18n/tr.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Merhaba",
"upcoming_payments" => "Yaklaşan Ödemeler",
+ "upcoming_cancellations" => "Yaklaşan İptaller",
"upcoming_payments_to_show" => "Gösterilecek yaklaşan ödemeler",
"no_upcoming_payments" => "Yaklaşan ödemeniz yok",
"overdue_renewals" => "Gecikmiş Yenilemeler",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Bütçe Aşımı",
"monthly_savings" => "Aylık Tasarruf (aktif olmayan aboneliklerde)",
"yearly_savings" => "Yıllık Tasarruf (aktif olmayan aboneliklerde)",
+ "potential_monthly_savings" => "Potansiyel Aylık Tasarruf",
+ "potential_yearly_savings" => "Potansiyel Yıllık Tasarruf",
"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/uk.php b/includes/i18n/uk.php
index a180e12..c0883ec 100644
--- a/includes/i18n/uk.php
+++ b/includes/i18n/uk.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Привіт",
"upcoming_payments" => "Предстоять платежі",
+ "upcoming_cancellations" => "Предстоящі скасування",
"upcoming_payments_to_show" => "Показувані майбутні платежі",
"no_upcoming_payments" => "У вас немає предстоять платежів",
"overdue_renewals" => "Прострочені поновлення",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Сума перевищення бюджету",
"monthly_savings" => "Щомісячна економія (при неактивних підписках)",
"yearly_savings" => "Річна економія (при неактивних підписках)",
+ "potential_monthly_savings" => "Потенційна щомісячна економія",
+ "potential_yearly_savings" => "Потенційна щорічна економія",
"split_views" => "Детальна статистика",
"category_split" => "За категоріями",
"household_split" => "За членами сім'ї",
diff --git a/includes/i18n/vi.php b/includes/i18n/vi.php
index 381a844..16fa582 100644
--- a/includes/i18n/vi.php
+++ b/includes/i18n/vi.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "Xin chào",
"upcoming_payments" => "Các khoản thanh toán sắp tới",
+ "upcoming_cancellations" => "Hủy bỏ sắp tới",
"upcoming_payments_to_show" => "Các khoản thanh toán sắp tới cần hiển thị",
"no_upcoming_payments" => "Bạn không có khoản thanh toán nào sắp tới",
"overdue_renewals" => "Gia hạn quá hạn",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "Số tiền vượt ngân sách",
"monthly_savings" => "Tiết kiệm hàng tháng (trên các đăng ký không hoạt động)",
"yearly_savings" => "Tiết kiệm hàng năm (trên các đăng ký không hoạt động)",
+ "potential_monthly_savings" => "Tiết kiệm hàng tháng tiềm năng",
+ "potential_yearly_savings" => "Tiết kiệm hàng năm tiềm năng",
"split_views" => "Chia tách lượt xem",
"category_split" => "Phân chia theo danh mục",
"household_split" => "Phân chia theo hộ gia đình",
diff --git a/includes/i18n/zh_cn.php b/includes/i18n/zh_cn.php
index ad0769f..df86745 100644
--- a/includes/i18n/zh_cn.php
+++ b/includes/i18n/zh_cn.php
@@ -51,6 +51,7 @@ $i18n = [
// Dashboard
"hello" => "你好",
"upcoming_payments" => "即将到期的付款",
+ "upcoming_cancellations" => "即将取消",
"upcoming_payments_to_show" => "要显示的即将到期付款",
"no_upcoming_payments" => "您没有任何即将到期的付款",
"overdue_renewals" => "逾期续订",
@@ -149,6 +150,8 @@ $i18n = [
"amount_over_budget" => "超出预算金额",
"monthly_savings" => "每月节省",
"yearly_savings" => "每年节省",
+ "potential_monthly_savings" => "预计每月可省",
+ "potential_yearly_savings" => "预计每年可省",
"split_views" => "拆分视图",
"category_split" => "分类视图",
"household_split" => "家庭视图",
diff --git a/includes/i18n/zh_tw.php b/includes/i18n/zh_tw.php
index b3354e5..009bcb4 100644
--- a/includes/i18n/zh_tw.php
+++ b/includes/i18n/zh_tw.php
@@ -48,6 +48,7 @@ $i18n = [
// Dashboard
"hello" => "你好",
"upcoming_payments" => "即將到期的付款",
+ "upcoming_cancellations" => "即將取消",
"upcoming_payments_to_show" => "要顯示的即將到期付款",
"no_upcoming_payments" => "您沒有任何即將到期的付款",
"overdue_renewals" => "逾期續訂",
@@ -143,6 +144,8 @@ $i18n = [
"amount_over_budget" => "預算超支",
"monthly_savings" => "每月節省金額(已停用的訂閱)",
"yearly_savings" => "每年節省金額(已停用的訂閱)",
+ "potential_monthly_savings" => "預計每月可省",
+ "potential_yearly_savings" => "預計每年可省",
"split_views" => "分類檢視",
"category_split" => "分類分析",
"household_split" => "家庭成員分析",
diff --git a/includes/upcoming_cancellations.php b/includes/upcoming_cancellations.php
new file mode 100644
index 0000000..e037e8b
--- /dev/null
+++ b/includes/upcoming_cancellations.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * Fetch the subscriptions whose cancellation reminder is still ahead of us.
+ *
+ * One-time purchases are excluded: they have no recurring commitment to cancel,
+ * and the subscription form clears their cancellation date. The cancellation
+ * notification cron applies the same rule.
+ *
+ * @param SQLite3 $db
+ * @param int $userId
+ * @return array
+ */
+function get_upcoming_cancellations($db, $userId)
+{
+ $stmt = $db->prepare("SELECT id, logo, logo_text_color, logo_variant, name, price, currency_id, cycle, frequency, cancellation_date
+ FROM subscriptions
+ WHERE user_id = :userId
+ AND inactive = 0
+ AND cancellation_date IS NOT NULL
+ AND cancellation_date != ''
+ AND cancellation_date >= date('now')
+ AND cycle != 5
+ ORDER BY cancellation_date ASC");
+ $stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
+ $result = $stmt->execute();
+
+ $subscriptions = [];
+ while ($result && ($row = $result->fetchArray(SQLITE3_ASSOC))) {
+ $subscriptions[] = $row;
+ }
+
+ return $subscriptions;
+}
+
+/**
+ * Total monthly cost, in the user's main currency, of everything currently
+ * flagged for cancellation — what the user would stop spending by cancelling.
+ *
+ * Expects getPricePerMonth() and getPriceConverted() from stats_calculations.php.
+ *
+ * @param array $cancellations rows from get_upcoming_cancellations()
+ * @param SQLite3 $db
+ * @param int $userId
+ * @return float
+ */
+function get_upcoming_cancellations_monthly_value($cancellations, $db, $userId)
+{
+ $total = 0;
+
+ foreach ($cancellations as $subscription) {
+ $perMonth = getPricePerMonth($subscription['cycle'], $subscription['frequency'], $subscription['price']);
+ $total += getPriceConverted($perMonth, $subscription['currency_id'], $db, $userId);
+ }
+
+ return $total;
+}
diff --git a/index.php b/index.php
index 6f2db63..99f43b7 100644
--- a/index.php
+++ b/index.php
@@ -4,6 +4,7 @@ require_once 'includes/header.php';
require_once 'includes/getdbkeys.php';
require_once 'includes/logo_theme_variant.php';
require_once 'includes/upcoming_payments.php';
+require_once 'includes/upcoming_cancellations.php';
function formatPrice($price, $currencyCode, $currencies)
{
@@ -90,6 +91,11 @@ while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
}
$hasOverdueSubscriptions = !empty($overdueSubscriptions);
+// Fetch the subscriptions whose cancellation reminder is still ahead (shared with
+// the statistics page, so both stay in step).
+$upcomingCancellations = get_upcoming_cancellations($db, $userId);
+$hasUpcomingCancellations = !empty($upcomingCancellations);
+
require_once 'includes/stats_calculations.php';
// Get AI Recommendations for user
@@ -222,6 +228,45 @@ while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
</div>
</div>
+ <?php if ($hasUpcomingCancellations) { ?>
+ <div class="cancellation-subscriptions">
+ <h2><?= translate('upcoming_cancellations', $i18n) ?></h2>
+ <div class="dashboard-subscriptions-container">
+ <div class="dashboard-subscriptions-list">
+ <?php
+ foreach ($upcomingCancellations as $subscription) {
+ $subscriptionName = htmlspecialchars($subscription['name']);
+ $subscriptionPrice = $subscription['price'];
+ $subscriptionCurrency = $subscription['currency_id'];
+ $subscriptionDisplayCancellationDate = formatDate($subscription['cancellation_date'], $lang);
+ $subscriptionDisplayPrice = formatPrice($subscriptionPrice, $currencies[$subscriptionCurrency]['code'], $currencies);
+
+ ?>
+ <div class="subscription-item" onClick="showSubscriptionDetails(event, <?= $subscription['id'] ?>)" data-id="<?= $subscription['id'] ?>">
+ <?php
+ if (empty($subscription['logo'])) {
+ ?>
+ <p class="subscription-item-title"><?= $subscriptionName ?></p>
+ <?php
+ } else {
+ $subscriptionLogoSrc = "images/uploads/logos/" . $subscription['logo'];
+ $subscriptionLogoVariantSrc = !empty($subscription['logo_variant']) ? "images/uploads/logos/" . $subscription['logo_variant'] : null;
+ echo renderThemedLogoImg($subscriptionLogoSrc, $subscriptionLogoVariantSrc, $subscription['logo_text_color'] ?? null, 'subscription-item-logo', 'alt="' . $subscriptionName . ' logo" title="' . $subscriptionName . '"');
+ }
+ ?>
+ <div class="subscription-item-info">
+ <p class="subscription-item-date"> <?= $subscriptionDisplayCancellationDate ?></p>
+ <p class="subscription-item-price"> <?= $subscriptionDisplayPrice ?></p>
+ </div>
+ </div>
+ <?php
+ }
+ ?>
+ </div>
+ </div>
+ </div>
+ <?php } ?>
+
<?php if (!empty($aiRecommendations)) { ?>
<div class="ai-recommendations">
<h2><?= translate('ai_recommendations', $i18n) ?></h2>
diff --git a/stats.php b/stats.php
index ae44091..c81ad74 100644
--- a/stats.php
+++ b/stats.php
@@ -16,6 +16,12 @@ $code = $row['code'];
require_once 'includes/stats_calculations.php';
require_once 'includes/stats_extra_calculations.php';
+require_once 'includes/upcoming_cancellations.php';
+
+// Subscriptions flagged for cancellation, and what cancelling them would stop costing.
+$upcomingCancellations = get_upcoming_cancellations($db, $userId);
+$upcomingCancellationsCount = count($upcomingCancellations);
+$potentialMonthlySavings = get_upcoming_cancellations_monthly_value($upcomingCancellations, $db, $userId);
?>
<section class="contain">
@@ -618,6 +624,34 @@ require_once 'includes/stats_extra_calculations.php';
<?php
}
+ if ($upcomingCancellationsCount > 0) {
+ ?>
+ <section class="stats-section">
+ <h2><?= translate('upcoming_cancellations', $i18n) ?></h2>
+ <div class="statistics">
+ <div class="statistic">
+ <span><?= $upcomingCancellationsCount ?></span>
+ <div class="title"><?= translate('subscriptions', $i18n) ?></div>
+ </div>
+ <?php
+ if ($potentialMonthlySavings > 0) {
+ ?>
+ <div class="statistic">
+ <span><?= CurrencyFormatter::format($potentialMonthlySavings, $code) ?></span>
+ <div class="title"><?= translate('potential_monthly_savings', $i18n) ?></div>
+ </div>
+ <div class="statistic">
+ <span><?= CurrencyFormatter::format($potentialMonthlySavings * 12, $code) ?></span>
+ <div class="title"><?= translate('potential_yearly_savings', $i18n) ?></div>
+ </div>
+ <?php
+ }
+ ?>
+ </div>
+ </section>
+ <?php
+ }
+
if ($inactiveSubscriptions > 0) {
?>
<section class="stats-section">
diff --git a/tests/cases/cancellation_notifications_test.php b/tests/cases/cancellation_notifications_test.php
new file mode 100644
index 0000000..e08d9d0
--- /dev/null
+++ b/tests/cases/cancellation_notifications_test.php
@@ -0,0 +1,166 @@
+<?php
+/*
+ The cancellation notification cron must never notify for one-time purchases:
+ they have no recurring commitment to cancel, and the subscription form clears
+ their cancellation date.
+
+ The cron's query is inline (the file requires PHPMailer and the notification
+ providers, so it cannot be included here), so the test reads the statement out
+ of the file and runs that — asserting against the real SQL, not a copy of it.
+*/
+
+/**
+ * Returns the subscription SELECT the cancellation cron runs.
+ *
+ * @return string
+ */
+function cancellation_cron_query()
+{
+ $source = file_get_contents(WALLOS_ROOT . '/endpoints/cronjobs/sendcancellationnotifications.php');
+
+ if (!preg_match('/\$query = "(SELECT \* FROM subscriptions WHERE[^"]+)";/', $source, $matches)) {
+ return '';
+ }
+
+ return $matches[1];
+}
+
+/**
+ * Runs the cron's query for one user and returns the subscription names it picks.
+ *
+ * @param SQLite3 $db
+ * @param int $userId
+ * @return array
+ */
+function cancellation_cron_names($db, $userId)
+{
+ $stmt = $db->prepare(cancellation_cron_query());
+ $stmt->bindValue(':user_id', $userId, SQLITE3_INTEGER);
+ $stmt->bindValue(':inactive', 0, SQLITE3_INTEGER);
+ $stmt->bindValue(':cancellationDate', date('Y-m-d'), SQLITE3_TEXT);
+ $stmt->bindValue(':oneTimeCycle', 5, SQLITE3_INTEGER);
+
+ $names = [];
+ $result = $stmt->execute();
+ while ($result && $row = $result->fetchArray(SQLITE3_ASSOC)) {
+ $names[] = $row['name'];
+ }
+ sort($names);
+
+ return $names;
+}
+
+wallos_test('the cancellation cron query was found in the cron', function () {
+ assert_contains('cancellation_date', cancellation_cron_query(),
+ 'the cron still selects subscriptions by cancellation date');
+});
+
+wallos_test('the cancellation cron skips one-time purchases due today', function () {
+ $db = wallos_test_open_database();
+ wallos_test_create_user($db, 1, 'alice');
+
+ $today = date('Y-m-d');
+ $rows = [
+ ['Netflix', 3, 0, $today], // recurring, due today -> notify
+ ['Udemy Course', 5, 0, $today], // one-time, due today -> never notify
+ ['PureGym', 3, 1, $today], // inactive -> no notify
+ ['Spotify', 3, 0, date('Y-m-d', strtotime('+3 days'))], // not due yet
+ ];
+
+ $stmt = $db->prepare('INSERT INTO subscriptions (user_id, name, price, currency_id, next_payment, cycle, frequency, inactive, cancellation_date)
+ VALUES (1, :name, 9.99, :currencyId, :nextPayment, :cycle, 1, :inactive, :cancellationDate)');
+ foreach ($rows as [$name, $cycle, $inactive, $cancellationDate]) {
+ $stmt->bindValue(':name', $name, SQLITE3_TEXT);
+ $stmt->bindValue(':currencyId', wallos_test_currency_id(1, 0), SQLITE3_INTEGER);
+ $stmt->bindValue(':nextPayment', date('Y-m-d', strtotime('+5 days')), SQLITE3_TEXT);
+ $stmt->bindValue(':cycle', $cycle, SQLITE3_INTEGER);
+ $stmt->bindValue(':inactive', $inactive, SQLITE3_INTEGER);
+ $stmt->bindValue(':cancellationDate', $cancellationDate, SQLITE3_TEXT);
+ $stmt->execute();
+ }
+
+ assert_same(['Netflix'], cancellation_cron_names($db, 1),
+ 'only the recurring subscription due today is notified');
+
+ $db->close();
+});
+
+wallos_test('the shared helper skips one-time purchases and the other exclusions', function () {
+ require_once WALLOS_ROOT . '/includes/upcoming_cancellations.php';
+
+ $db = wallos_test_open_database();
+ wallos_test_create_user($db, 1, 'alice');
+
+ $rows = [
+ // name, cycle, inactive, cancellation_date
+ ['Netflix', 3, 0, date('Y-m-d', strtotime('+3 days'))], // shown
+ ['Spotify', 3, 0, date('Y-m-d', strtotime('+12 days'))], // shown
+ ['Udemy Course', 5, 0, date('Y-m-d', strtotime('+1 day'))], // one-time
+ ['PureGym', 3, 1, date('Y-m-d', strtotime('+4 days'))], // inactive
+ ['Audible', 3, 0, date('Y-m-d', strtotime('-2 days'))], // already passed
+ ['Duolingo', 3, 0, ''], // empty string
+ ['iCloud+', 3, 0, null], // never set
+ ];
+
+ $stmt = $db->prepare('INSERT INTO subscriptions (user_id, name, price, currency_id, next_payment, cycle, frequency, inactive, cancellation_date)
+ VALUES (1, :name, 10.00, :currencyId, :nextPayment, :cycle, 1, :inactive, :cancellationDate)');
+ foreach ($rows as [$name, $cycle, $inactive, $cancellationDate]) {
+ $stmt->bindValue(':name', $name, SQLITE3_TEXT);
+ $stmt->bindValue(':currencyId', wallos_test_currency_id(1, 0), SQLITE3_INTEGER);
+ $stmt->bindValue(':nextPayment', date('Y-m-d', strtotime('+5 days')), SQLITE3_TEXT);
+ $stmt->bindValue(':cycle', $cycle, SQLITE3_INTEGER);
+ $stmt->bindValue(':inactive', $inactive, SQLITE3_INTEGER);
+ $stmt->bindValue(':cancellationDate', $cancellationDate, $cancellationDate === null ? SQLITE3_NULL : SQLITE3_TEXT);
+ $stmt->execute();
+ }
+
+ $names = array_map(fn($row) => $row['name'], get_upcoming_cancellations($db, 1));
+
+ assert_same(['Netflix', 'Spotify'], $names,
+ 'only active, recurring subscriptions with a future cancellation date are listed, soonest first');
+
+ $db->close();
+});
+
+wallos_test('the dashboard and the statistics page both read the shared helper', function () {
+ foreach (['index.php', 'stats.php'] as $page) {
+ $source = file_get_contents(WALLOS_ROOT . '/' . $page);
+
+ assert_contains('get_upcoming_cancellations(', $source,
+ $page . ' calls the shared helper');
+ assert_not_contains('cancellation_date >= date', $source,
+ $page . ' does not carry its own copy of the query');
+ }
+});
+
+wallos_test('the potential-savings total normalizes each cycle and converts each currency', function () {
+ require_once WALLOS_ROOT . '/includes/upcoming_cancellations.php';
+
+ // stats_calculations.php supplies these in the app, but including it runs a
+ // page's worth of queries. Stubbing them keeps this focused on the summing
+ // logic: every row must be normalized to a month AND converted, then added.
+ if (!function_exists('getPricePerMonth')) {
+ function getPricePerMonth($cycle, $frequency, $price)
+ {
+ return $cycle == 4 ? $price / (12 * $frequency) : $price / $frequency;
+ }
+ }
+ if (!function_exists('getPriceConverted')) {
+ // a distinctive factor, so a row that skipped conversion is visible
+ function getPriceConverted($price, $currency, $database, $userId)
+ {
+ return $price * 2;
+ }
+ }
+
+ $rows = [
+ ['price' => 10.00, 'cycle' => 3, 'frequency' => 1, 'currency_id' => 1], // 10/mo
+ ['price' => 120.00, 'cycle' => 4, 'frequency' => 1, 'currency_id' => 2], // 10/mo
+ ];
+
+ assert_same(40.0, get_upcoming_cancellations_monthly_value($rows, null, 1),
+ 'both rows are normalized to a month, converted, and summed');
+
+ assert_same(0, get_upcoming_cancellations_monthly_value([], null, 1),
+ 'nothing flagged means nothing to save');
+});
diff --git a/tests/cases/subscription_index_test.php b/tests/cases/subscription_index_test.php
index e0317b9..32bf058 100644
--- a/tests/cases/subscription_index_test.php
+++ b/tests/cases/subscription_index_test.php
@@ -50,6 +50,7 @@ wallos_test('the queries Wallos runs use an index instead of scanning', function
'active subscriptions' => "SELECT * FROM subscriptions WHERE user_id = 1 AND inactive = 0",
'notification cron' => "SELECT * FROM subscriptions WHERE user_id = 1 AND notify = 1 AND inactive = 0",
'calendar range' => "SELECT * FROM subscriptions WHERE user_id = 1 AND inactive = 0 AND next_payment BETWEEN '2026-08-01' AND '2026-08-31'",
+ 'dashboard cancellations' => "SELECT * FROM subscriptions WHERE user_id = 1 AND inactive = 0 AND cancellation_date IS NOT NULL AND cancellation_date != '' AND cancellation_date >= date('now') AND cycle != 5 ORDER BY cancellation_date ASC",
];
foreach ($cases as $label => $sql) {
diff --git a/tests/cases/subscriptions_notification_filter_test.php b/tests/cases/subscriptions_notification_filter_test.php
new file mode 100644
index 0000000..b3b6425
--- /dev/null
+++ b/tests/cases/subscriptions_notification_filter_test.php
@@ -0,0 +1,94 @@
+<?php
+/*
+ The subscription list's "notifications" filter must never file a one-time
+ purchase under "cancellation": one-time purchases have no recurring
+ commitment to cancel, matching the dashboard, statistics page and
+ cancellation notification cron (see cancellation_notifications_test.php).
+
+ endpoints/subscriptions/get.php requires connect_endpoint.php and a live
+ session, so it can't be included here. As with the cron test, this reads
+ the two SQL fragments out of the source file and runs them against a
+ seeded database, asserting against the real conditions rather than a copy
+ that could silently drift.
+*/
+
+/**
+ * Returns the SQL condition endpoints/subscriptions/get.php builds for one
+ * notification filter type ('cancellation' or 'none').
+ *
+ * @param string $type
+ * @return string
+ */
+function notification_filter_condition($type)
+{
+ $source = file_get_contents(WALLOS_ROOT . '/endpoints/subscriptions/get.php');
+
+ if (!preg_match('/\$type === \'' . $type . '\'\) \{\s*(?:\/\/[^\n]*\n\s*)*\$notifConditions\[\] = "([^"]+)";/', $source, $matches)) {
+ return '';
+ }
+
+ return $matches[1];
+}
+
+/**
+ * Runs one notification filter condition for a user and returns the
+ * subscription names it matches.
+ *
+ * @param SQLite3 $db
+ * @param int $userId
+ * @param string $type
+ * @return array
+ */
+function notification_filter_names($db, $userId, $type)
+{
+ $condition = notification_filter_condition($type);
+ $stmt = $db->prepare("SELECT name FROM subscriptions WHERE user_id = :userId AND ($condition) ORDER BY name ASC");
+ $stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
+
+ $names = [];
+ $result = $stmt->execute();
+ while ($result && $row = $result->fetchArray(SQLITE3_ASSOC)) {
+ $names[] = $row['name'];
+ }
+
+ return $names;
+}
+
+wallos_test('the notification filter conditions were found in the endpoint', function () {
+ assert_contains('cancellation_date', notification_filter_condition('cancellation'),
+ 'the cancellation condition still filters by cancellation date');
+ assert_contains('cancellation_date', notification_filter_condition('none'),
+ 'the none condition still checks for a cancellation date');
+});
+
+wallos_test('the cancellation filter excludes one-time purchases', function () {
+ $db = wallos_test_open_database();
+ wallos_test_create_user($db, 1, 'alice');
+
+ $rows = [
+ // name, cycle, notify, cancellation_date
+ ['Netflix', 3, 0, date('Y-m-d', strtotime('+10 days'))], // recurring, flagged -> cancellation
+ ['Udemy Course', 5, 0, date('Y-m-d', strtotime('+10 days'))], // one-time, flagged -> none, not cancellation
+ ['Spotify', 3, 1, null], // reminder only
+ ['iCloud+', 3, 0, null], // nothing set -> none
+ ];
+
+ $stmt = $db->prepare('INSERT INTO subscriptions (user_id, name, price, currency_id, next_payment, cycle, frequency, inactive, notify, cancellation_date)
+ VALUES (1, :name, 9.99, :currencyId, :nextPayment, :cycle, 1, 0, :notify, :cancellationDate)');
+ foreach ($rows as [$name, $cycle, $notify, $cancellationDate]) {
+ $stmt->bindValue(':name', $name, SQLITE3_TEXT);
+ $stmt->bindValue(':currencyId', wallos_test_currency_id(1, 0), SQLITE3_INTEGER);
+ $stmt->bindValue(':nextPayment', date('Y-m-d', strtotime('+5 days')), SQLITE3_TEXT);
+ $stmt->bindValue(':cycle', $cycle, SQLITE3_INTEGER);
+ $stmt->bindValue(':notify', $notify, SQLITE3_INTEGER);
+ $stmt->bindValue(':cancellationDate', $cancellationDate, $cancellationDate === null ? SQLITE3_NULL : SQLITE3_TEXT);
+ $stmt->execute();
+ }
+
+ assert_same(['Netflix'], notification_filter_names($db, 1, 'cancellation'),
+ 'only the recurring, flagged subscription is filed under cancellation');
+ assert_same(['Udemy Course', 'iCloud+'], notification_filter_names($db, 1, 'none'),
+ 'the one-time purchase falls back to "none" instead of "cancellation"');
+
+ $db->close();
+});