Allow to disable notifications

This commit is contained in:
Sokratis 2024-02-23 15:29:11 +01:00 committed by GitHub
parent d2671b0276
commit 91e53a48e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 79 additions and 9 deletions

View File

@ -30,7 +30,7 @@
$currencies[$currencyId] = $row; $currencies[$currencyId] = $row;
} }
$querySubscriptions = "SELECT * FROM subscriptions WHERE notify = 1"; $querySubscriptions = "SELECT * FROM subscriptions WHERE notify = 1 AND inactive = 0";
$resultSubscriptions = $db->query($querySubscriptions); $resultSubscriptions = $db->query($querySubscriptions);
$notify = []; $i = 0; $notify = []; $i = 0;

View File

@ -13,7 +13,7 @@
$cycles[$cycleId] = $row; $cycles[$cycleId] = $row;
} }
$query = "SELECT id, next_payment, frequency, cycle FROM subscriptions WHERE next_payment < :currentDate"; $query = "SELECT id, next_payment, frequency, cycle FROM subscriptions WHERE inactive = 0 AND next_payment < :currentDate";
$stmt = $db->prepare($query); $stmt = $db->prepare($query);
$stmt->bindValue(':currentDate', $currentDate->format('Y-m-d')); $stmt->bindValue(':currentDate', $currentDate->format('Y-m-d'));
$result = $stmt->execute(); $result = $stmt->execute();

View File

@ -151,6 +151,7 @@
$logoUrl = validate($_POST['logo-url']); $logoUrl = validate($_POST['logo-url']);
$logo = ""; $logo = "";
$notify = isset($_POST['notifications']) ? true : false; $notify = isset($_POST['notifications']) ? true : false;
$inactive = isset($_POST['inactive']) ? true : false;
if($logoUrl !== "") { if($logoUrl !== "") {
$logo = getLogoFromUrl($logoUrl, '../../images/uploads/logos/', $name); $logo = getLogoFromUrl($logoUrl, '../../images/uploads/logos/', $name);
@ -162,15 +163,15 @@
if (!$isEdit) { if (!$isEdit) {
$sql = "INSERT INTO subscriptions (name, logo, price, currency_id, next_payment, cycle, frequency, notes, $sql = "INSERT INTO subscriptions (name, logo, price, currency_id, next_payment, cycle, frequency, notes,
payment_method_id, payer_user_id, category_id, notify, url) payment_method_id, payer_user_id, category_id, notify, inactive, url)
VALUES (:name, :logo, :price, :currencyId, :nextPayment, :cycle, :frequency, :notes, VALUES (:name, :logo, :price, :currencyId, :nextPayment, :cycle, :frequency, :notes,
:paymentMethodId, :payerUserId, :categoryId, :notify, :url)"; :paymentMethodId, :payerUserId, :categoryId, :notify, :inactive, :url)";
} else { } else {
$id = $_POST['id']; $id = $_POST['id'];
if ($logo != "") { if ($logo != "") {
$sql = "UPDATE subscriptions SET name = :name, logo = :logo, price = :price, currency_id = :currencyId, next_payment = :nextPayment, cycle = :cycle, frequency = :frequency, notes = :notes, payment_method_id = :paymentMethodId, payer_user_id = :payerUserId, category_id = :categoryId, notify = :notify, url = :url WHERE id = :id"; $sql = "UPDATE subscriptions SET name = :name, logo = :logo, price = :price, currency_id = :currencyId, next_payment = :nextPayment, cycle = :cycle, frequency = :frequency, notes = :notes, payment_method_id = :paymentMethodId, payer_user_id = :payerUserId, category_id = :categoryId, notify = :notify, inactive = :inactive, url = :url WHERE id = :id";
} else { } else {
$sql = "UPDATE subscriptions SET name = :name, price = :price, currency_id = :currencyId, next_payment = :nextPayment, cycle = :cycle, frequency = :frequency, notes = :notes, payment_method_id = :paymentMethodId, payer_user_id = :payerUserId, category_id = :categoryId, notify = :notify, url = :url WHERE id = :id"; $sql = "UPDATE subscriptions SET name = :name, price = :price, currency_id = :currencyId, next_payment = :nextPayment, cycle = :cycle, frequency = :frequency, notes = :notes, payment_method_id = :paymentMethodId, payer_user_id = :payerUserId, category_id = :categoryId, notify = :notify, inactive = :inactive, url = :url WHERE id = :id";
} }
} }
@ -192,6 +193,7 @@
$stmt->bindParam(':payerUserId', $payerUserId, SQLITE3_INTEGER); $stmt->bindParam(':payerUserId', $payerUserId, SQLITE3_INTEGER);
$stmt->bindParam(':categoryId', $categoryId, SQLITE3_INTEGER); $stmt->bindParam(':categoryId', $categoryId, SQLITE3_INTEGER);
$stmt->bindParam(':notify', $notify, SQLITE3_INTEGER); $stmt->bindParam(':notify', $notify, SQLITE3_INTEGER);
$stmt->bindParam(':inactive', $inactive, SQLITE3_INTEGER);
$stmt->bindParam(':url', $url, SQLITE3_TEXT); $stmt->bindParam(':url', $url, SQLITE3_TEXT);
if ($stmt->execute()) { if ($stmt->execute()) {

View File

@ -25,6 +25,7 @@
$subscriptionData['payer_user_id'] = $row['payer_user_id']; $subscriptionData['payer_user_id'] = $row['payer_user_id'];
$subscriptionData['category_id'] = $row['category_id']; $subscriptionData['category_id'] = $row['category_id'];
$subscriptionData['notify'] = $row['notify']; $subscriptionData['notify'] = $row['notify'];
$subscriptionData['inactive'] = $row['inactive'];
$subscriptionData['url'] = $row['url']; $subscriptionData['url'] = $row['url'];
$subscriptionJson = json_encode($subscriptionData); $subscriptionJson = json_encode($subscriptionData);

View File

@ -56,6 +56,7 @@
$print[$id]['category_id'] = $subscription['category_id']; $print[$id]['category_id'] = $subscription['category_id'];
$print[$id]['payer_user_id'] = $subscription['payer_user_id']; $print[$id]['payer_user_id'] = $subscription['payer_user_id'];
$print[$id]['price'] = floatval($subscription['price']); $print[$id]['price'] = floatval($subscription['price']);
$print[$id]['inactive'] = $subscription['inactive'];
$print[$id]['url'] = $subscription['url']; $print[$id]['url'] = $subscription['url'];
$print[$id]['notes'] = $subscription['notes']; $print[$id]['notes'] = $subscription['notes'];

View File

@ -33,6 +33,7 @@ $i18n = [
'last_added' => "Zuletzt hinzugefügt", 'last_added' => "Zuletzt hinzugefügt",
'price' => "Preis", 'price' => "Preis",
'next_payment' => "Nächste Zahlung", 'next_payment' => "Nächste Zahlung",
'inactive' => "Deaktiviertes Abonnement",
'member' => "Mitglied", 'member' => "Mitglied",
'category' => "Kategorie", 'category' => "Kategorie",
'payment_method' => "Zahlungsmethode", 'payment_method' => "Zahlungsmethode",
@ -70,6 +71,7 @@ $i18n = [
// Statistics page // Statistics page
'general_statistics' => "Allgemeine Statistiken", 'general_statistics' => "Allgemeine Statistiken",
'active_subscriptions' => "Aktive Abonnements", 'active_subscriptions' => "Aktive Abonnements",
'inactive_subscriptions' => "Inaktive Abonnements",
'monthly_cost' => "Monatliche Kosten", 'monthly_cost' => "Monatliche Kosten",
'yearly_cost' => "Jährliche Kosten", 'yearly_cost' => "Jährliche Kosten",
'average_monthly' => "Durchschnittliche monatliche Kosten", 'average_monthly' => "Durchschnittliche monatliche Kosten",

View File

@ -33,6 +33,7 @@ $i18n = [
'last_added' => "Τελευταία προσθήκη", 'last_added' => "Τελευταία προσθήκη",
'price' => "Τιμή", 'price' => "Τιμή",
'next_payment' => "Επόμενη πληρωμή", 'next_payment' => "Επόμενη πληρωμή",
'inactive' => "Ανενεργή συνδρομή",
'member' => "Χρήστης", 'member' => "Χρήστης",
'category' => "Κατηγορία", 'category' => "Κατηγορία",
'payment_method' => "Τρόπος πληρωμής", 'payment_method' => "Τρόπος πληρωμής",
@ -70,6 +71,7 @@ $i18n = [
// Statistics page // Statistics page
'general_statistics' => "Γενικές στατιστικές", 'general_statistics' => "Γενικές στατιστικές",
'active_subscriptions' => "Ενεργές συνδρομές", 'active_subscriptions' => "Ενεργές συνδρομές",
'inactive_subscriptions' => "Ανενεργές συνδρομές",
'monthly_cost' => "Μηνιαίο κόστος", 'monthly_cost' => "Μηνιαίο κόστος",
'yearly_cost' => "Ετήσιο κόστος", 'yearly_cost' => "Ετήσιο κόστος",
'average_monthly' => "Μέσο μηνιαίο κόστος συνδρομής", 'average_monthly' => "Μέσο μηνιαίο κόστος συνδρομής",

View File

@ -33,6 +33,7 @@ $i18n = [
'last_added' => "Last Added", 'last_added' => "Last Added",
'price' => "Price", 'price' => "Price",
'next_payment' => "Next Payment", 'next_payment' => "Next Payment",
'inactive' => "Disabled Subscription",
'member' => "Member", 'member' => "Member",
'category' => "Category", 'category' => "Category",
'payment_method' => "Payment Method", 'payment_method' => "Payment Method",
@ -70,6 +71,7 @@ $i18n = [
// Statistics page // Statistics page
'general_statistics' => "General Statistics", 'general_statistics' => "General Statistics",
'active_subscriptions' => "Active Subscriptions", 'active_subscriptions' => "Active Subscriptions",
'inactive_subscriptions' => "Inactive Subscriptions",
'monthly_cost' => "Monthly Cost", 'monthly_cost' => "Monthly Cost",
'yearly_cost' => "Yearly Cost", 'yearly_cost' => "Yearly Cost",
'average_monthly' => "Average Monthly Subscription Cost", 'average_monthly' => "Average Monthly Subscription Cost",

View File

@ -33,6 +33,7 @@ $i18n = [
'last_added' => "Última Añadida", 'last_added' => "Última Añadida",
'price' => "Precio", 'price' => "Precio",
'next_payment' => "Próximo Pago", 'next_payment' => "Próximo Pago",
'inactive' => "Suscripción desactivada",
'member' => "Miembro", 'member' => "Miembro",
'category' => "Categoría", 'category' => "Categoría",
'payment_method' => "Método de Pago", 'payment_method' => "Método de Pago",
@ -70,6 +71,7 @@ $i18n = [
// Statistics page // Statistics page
'general_statistics' => "Estadísticas Generales", 'general_statistics' => "Estadísticas Generales",
'active_subscriptions' => "Suscripciones Activas", 'active_subscriptions' => "Suscripciones Activas",
'inactive_subscriptions' => "Suscripciones inactivas",
'monthly_cost' => "Costo Mensual", 'monthly_cost' => "Costo Mensual",
'yearly_cost' => "Costo Anual", 'yearly_cost' => "Costo Anual",
'average_monthly' => "Costo Promedio Mensual de Suscripción", 'average_monthly' => "Costo Promedio Mensual de Suscripción",

View File

@ -33,6 +33,7 @@ $i18n = [
'last_added' => "Dernier ajouté", 'last_added' => "Dernier ajouté",
'price' => "Prix", 'price' => "Prix",
'next_payment' => "Prochain paiement", 'next_payment' => "Prochain paiement",
'inactive' => "Abonnement désactivé",
'member' => "Membre", 'member' => "Membre",
'category' => "Catégorie", 'category' => "Catégorie",
'payment_method' => "Méthode de paiement", 'payment_method' => "Méthode de paiement",
@ -70,6 +71,7 @@ $i18n = [
// Page de statistiques // Page de statistiques
'general_statistics' => "Statistiques générales", 'general_statistics' => "Statistiques générales",
'active_subscriptions' => "Abonnements actifs", 'active_subscriptions' => "Abonnements actifs",
'inactive_subscriptions' => "Abonnements inactifs",
'monthly_cost' => "Coût mensuel", 'monthly_cost' => "Coût mensuel",
'yearly_cost' => "Coût annuel", 'yearly_cost' => "Coût annuel",
'average_monthly' => "Coût moyen mensuel de l'abonnement", 'average_monthly' => "Coût moyen mensuel de l'abonnement",

View File

@ -33,6 +33,7 @@ $i18n = [
'last_added' => "最終追加日", 'last_added' => "最終追加日",
'price' => "金額", 'price' => "金額",
'next_payment' => "次回支払い", 'next_payment' => "次回支払い",
'inactive' => "無効なサブスクリプション",
'member' => "メンバー", 'member' => "メンバー",
'category' => "カテゴリ", 'category' => "カテゴリ",
'payment_method' => "支払い方法", 'payment_method' => "支払い方法",
@ -70,6 +71,7 @@ $i18n = [
// Statistics page // Statistics page
'general_statistics' => "一般統計", 'general_statistics' => "一般統計",
'active_subscriptions' => "アクティブな定期購入", 'active_subscriptions' => "アクティブな定期購入",
'inactive_subscriptions' => "非アクティブなサブスクリプション",
'monthly_cost' => "月間費用", 'monthly_cost' => "月間費用",
'yearly_cost' => "年間費用", 'yearly_cost' => "年間費用",
'average_monthly' => "月額平均費用", 'average_monthly' => "月額平均費用",

View File

@ -33,6 +33,7 @@ $i18n = [
'last_added' => "Última Adicionada", 'last_added' => "Última Adicionada",
'price' => "Preço", 'price' => "Preço",
'next_payment' => "Próximo Pagamento", 'next_payment' => "Próximo Pagamento",
'inactive' => "Subscrição desactivada",
'member' => "Membro", 'member' => "Membro",
'category' => "Categoria", 'category' => "Categoria",
'payment_method' => "Metodo de Pagamento", 'payment_method' => "Metodo de Pagamento",
@ -70,6 +71,7 @@ $i18n = [
// Statistics page // Statistics page
'general_statistics' => "Estatísticas Gerais", 'general_statistics' => "Estatísticas Gerais",
'active_subscriptions' => "Subscrições Activas", 'active_subscriptions' => "Subscrições Activas",
'inactive_subscriptions' => "Subscrições inactivas",
'monthly_cost' => "Custo Mensal", 'monthly_cost' => "Custo Mensal",
'yearly_cost' => "Custo Anual", 'yearly_cost' => "Custo Anual",
'average_monthly' => "Custo Mensal Médio das Subscrições", 'average_monthly' => "Custo Mensal Médio das Subscrições",

View File

@ -36,6 +36,7 @@ $i18n = [
'last_added' => "创建时间", 'last_added' => "创建时间",
'price' => "价格", 'price' => "价格",
'next_payment' => "下次支付时间", 'next_payment' => "下次支付时间",
'inactive' => "禁用订阅",
'member' => "成员", 'member' => "成员",
'category' => "分类", 'category' => "分类",
'payment_method' => "支付方式", 'payment_method' => "支付方式",
@ -75,6 +76,7 @@ $i18n = [
// 统计页面 // 统计页面
'general_statistics' => "总体统计", 'general_statistics' => "总体统计",
'active_subscriptions' => "活跃订阅", 'active_subscriptions' => "活跃订阅",
'inactive_subscriptions' => "非活动订阅",
'monthly_cost' => "月费用", 'monthly_cost' => "月费用",
'yearly_cost' => "年费用", 'yearly_cost' => "年费用",
'average_monthly' => "平均每月订阅费用", 'average_monthly' => "平均每月订阅费用",

View File

@ -63,6 +63,13 @@
}); });
} }
usort($subscriptions, function ($a, $b) {
if ($a['inactive'] == $b['inactive']) {
return 0;
}
return $a['inactive'] ? 1 : -1;
});
$currentCategory = 0; $currentCategory = 0;
$currentPayerUserId = 0; $currentPayerUserId = 0;
$currentPaymentMethodId = 0; $currentPaymentMethodId = 0;
@ -98,7 +105,7 @@
$currentPaymentMethodId = $subscription['payment_method_id']; $currentPaymentMethodId = $subscription['payment_method_id'];
} }
?> ?>
<div class="subscription" onClick="toggleOpenSubscription(<?= $subscription['id'] ?>)" data-id="<?= $subscription['id'] ?>"> <div class="subscription<?= $subscription['inactive'] ? ' inactive' : '' ?>" onClick="toggleOpenSubscription(<?= $subscription['id'] ?>)" data-id="<?= $subscription['id'] ?>">
<div class="subscription-main"> <div class="subscription-main">
<span class="logo"><img src="<?= $subscription['logo'] ?>"></span> <span class="logo"><img src="<?= $subscription['logo'] ?>"></span>
<span class="name"><?= $subscription['name'] ?></span> <span class="name"><?= $subscription['name'] ?></span>

View File

@ -87,6 +87,7 @@
$print[$id]['category_id'] = $subscription['category_id']; $print[$id]['category_id'] = $subscription['category_id'];
$print[$id]['payer_user_id'] = $subscription['payer_user_id']; $print[$id]['payer_user_id'] = $subscription['payer_user_id'];
$print[$id]['price'] = floatval($subscription['price']); $print[$id]['price'] = floatval($subscription['price']);
$print[$id]['inactive'] = $subscription['inactive'];
$print[$id]['url'] = $subscription['url']; $print[$id]['url'] = $subscription['url'];
$print[$id]['notes'] = $subscription['notes']; $print[$id]['notes'] = $subscription['notes'];
@ -194,6 +195,11 @@
</div> </div>
</div> </div>
<div class="form-group-inline">
<input type="checkbox" id="inactive" name="inactive">
<label for="inactive"><?= translate('inactive', $i18n) ?></label>
</div>
<div class="form-group"> <div class="form-group">
<label for="payment_method"><?= translate('payment_method', $i18n) ?></label> <label for="payment_method"><?= translate('payment_method', $i18n) ?></label>
<select id="payment_method" name="payment_method_id"> <select id="payment_method" name="payment_method_id">

11
migrations/000008.php Normal file
View File

@ -0,0 +1,11 @@
<?php
// This migration adds a "activated" column to the subscriptions table and sets all values to true.
/** @noinspection PhpUndefinedVariableInspection */
$columnQuery = $db->query("SELECT * FROM pragma_table_info('subscriptions') WHERE name='inactive'");
$columnRequired = $columnQuery->fetchArray(SQLITE3_ASSOC) === false;
if ($columnRequired) {
$db->exec('ALTER TABLE subscriptions ADD COLUMN inactive BOOLEAN DEFAULT false');
$db->exec('UPDATE subscriptions SET inactive = false');
}

View File

@ -67,6 +67,8 @@ function fillEditFormFields(subscription) {
nextPament.value = subscription.next_payment; nextPament.value = subscription.next_payment;
const notes = document.querySelector("#notes"); const notes = document.querySelector("#notes");
notes.value = subscription.notes; notes.value = subscription.notes;
const inactive = document.querySelector("#inactive");
inactive.checked = subscription.inactive;
const url = document.querySelector("#url"); const url = document.querySelector("#url");
url.value = subscription.url; url.value = subscription.url;

View File

@ -83,19 +83,27 @@ $code = $row['code'];
// Calculate active subscriptions // Calculate active subscriptions
$query = "SELECT COUNT(*) AS active_subscriptions FROM subscriptions"; $query = "SELECT COUNT(*) AS active_subscriptions FROM subscriptions WHERE inactive = 0";
$stmt = $db->prepare($query); $stmt = $db->prepare($query);
$stmt->bindParam(':criteria', $criteria, SQLITE3_INTEGER); $stmt->bindParam(':criteria', $criteria, SQLITE3_INTEGER);
$result = $stmt->execute(); $result = $stmt->execute();
$row = $result->fetchArray(SQLITE3_ASSOC); $row = $result->fetchArray(SQLITE3_ASSOC);
$activeSubscriptions = $row['active_subscriptions']; $activeSubscriptions = $row['active_subscriptions'];
// Calculate inactive subscriptions
$query = "SELECT COUNT(*) AS inactive_subscriptions FROM subscriptions WHERE inactive = 1";
$stmt = $db->prepare($query);
$stmt->bindParam(':inactive', $inactive, SQLITE3_INTEGER);
$result = $stmt->execute();
$row = $result->fetchArray(SQLITE3_ASSOC);
$inactiveSubscriptions = $row['inactive_subscriptions'];
// Calculate total monthly price // Calculate total monthly price
$mostExpensiveSubscription = 0; $mostExpensiveSubscription = 0;
$amountDueThisMonth = 0; $amountDueThisMonth = 0;
$totalCostPerMonth = 0; $totalCostPerMonth = 0;
$query = "SELECT name, price, frequency, cycle, currency_id, next_payment, payer_user_id, category_id, payment_method_id FROM subscriptions"; $query = "SELECT name, price, frequency, cycle, currency_id, next_payment, payer_user_id, category_id, payment_method_id FROM subscriptions WHERE inactive = 0";
$result = $db->query($query); $result = $db->query($query);
if ($result) { if ($result) {
while ($row = $result->fetchArray(SQLITE3_ASSOC)) { while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
@ -163,6 +171,15 @@ if ($result) {
<span><?= $activeSubscriptions ?></span> <span><?= $activeSubscriptions ?></span>
<div class="title"><?= translate('active_subscriptions', $i18n) ?></div> <div class="title"><?= translate('active_subscriptions', $i18n) ?></div>
</div> </div>
<?php if ($inactiveSubscriptions > 0) {
?>
<div class="statistic">
<span><?= $inactiveSubscriptions ?></span>
<div class="title"><?= translate('inactive_subscriptions', $i18n) ?></div>
</div>
<?php
}
?>
<div class="statistic"> <div class="statistic">
<span><?= CurrencyFormatter::format($totalCostPerMonth, $code) ?></span> <span><?= CurrencyFormatter::format($totalCostPerMonth, $code) ?></span>
<div class="title"><?= translate('monthly_cost', $i18n) ?></div> <div class="title"><?= translate('monthly_cost', $i18n) ?></div>

View File

@ -201,6 +201,13 @@ main > .contain {
cursor: pointer; cursor: pointer;
} }
.subscription.inactive {
color: #808080;
text-decoration: line-through;
font-style: italic;
background-color: #F8F8FF;
}
.subscription-main { .subscription-main {
display: flex; display: flex;
flex-direction: row; flex-direction: row;