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;
}
$querySubscriptions = "SELECT * FROM subscriptions WHERE notify = 1";
$querySubscriptions = "SELECT * FROM subscriptions WHERE notify = 1 AND inactive = 0";
$resultSubscriptions = $db->query($querySubscriptions);
$notify = []; $i = 0;

View File

@ -13,7 +13,7 @@
$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->bindValue(':currentDate', $currentDate->format('Y-m-d'));
$result = $stmt->execute();

View File

@ -151,6 +151,7 @@
$logoUrl = validate($_POST['logo-url']);
$logo = "";
$notify = isset($_POST['notifications']) ? true : false;
$inactive = isset($_POST['inactive']) ? true : false;
if($logoUrl !== "") {
$logo = getLogoFromUrl($logoUrl, '../../images/uploads/logos/', $name);
@ -162,15 +163,15 @@
if (!$isEdit) {
$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,
:paymentMethodId, :payerUserId, :categoryId, :notify, :url)";
:paymentMethodId, :payerUserId, :categoryId, :notify, :inactive, :url)";
} else {
$id = $_POST['id'];
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 {
$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(':categoryId', $categoryId, SQLITE3_INTEGER);
$stmt->bindParam(':notify', $notify, SQLITE3_INTEGER);
$stmt->bindParam(':inactive', $inactive, SQLITE3_INTEGER);
$stmt->bindParam(':url', $url, SQLITE3_TEXT);
if ($stmt->execute()) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -36,6 +36,7 @@ $i18n = [
'last_added' => "创建时间",
'price' => "价格",
'next_payment' => "下次支付时间",
'inactive' => "禁用订阅",
'member' => "成员",
'category' => "分类",
'payment_method' => "支付方式",
@ -75,6 +76,7 @@ $i18n = [
// 统计页面
'general_statistics' => "总体统计",
'active_subscriptions' => "活跃订阅",
'inactive_subscriptions' => "非活动订阅",
'monthly_cost' => "月费用",
'yearly_cost' => "年费用",
'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;
$currentPayerUserId = 0;
$currentPaymentMethodId = 0;
@ -98,7 +105,7 @@
$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">
<span class="logo"><img src="<?= $subscription['logo'] ?>"></span>
<span class="name"><?= $subscription['name'] ?></span>

View File

@ -87,6 +87,7 @@
$print[$id]['category_id'] = $subscription['category_id'];
$print[$id]['payer_user_id'] = $subscription['payer_user_id'];
$print[$id]['price'] = floatval($subscription['price']);
$print[$id]['inactive'] = $subscription['inactive'];
$print[$id]['url'] = $subscription['url'];
$print[$id]['notes'] = $subscription['notes'];
@ -194,6 +195,11 @@
</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">
<label for="payment_method"><?= translate('payment_method', $i18n) ?></label>
<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;
const notes = document.querySelector("#notes");
notes.value = subscription.notes;
const inactive = document.querySelector("#inactive");
inactive.checked = subscription.inactive;
const url = document.querySelector("#url");
url.value = subscription.url;

View File

@ -83,19 +83,27 @@ $code = $row['code'];
// 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->bindParam(':criteria', $criteria, SQLITE3_INTEGER);
$result = $stmt->execute();
$row = $result->fetchArray(SQLITE3_ASSOC);
$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
$mostExpensiveSubscription = 0;
$amountDueThisMonth = 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);
if ($result) {
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
@ -163,6 +171,15 @@ if ($result) {
<span><?= $activeSubscriptions ?></span>
<div class="title"><?= translate('active_subscriptions', $i18n) ?></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">
<span><?= CurrencyFormatter::format($totalCostPerMonth, $code) ?></span>
<div class="title"><?= translate('monthly_cost', $i18n) ?></div>

View File

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