Skip to content

Commit

Permalink
Allow to disable notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
sokratis1988 authored Feb 23, 2024
1 parent d2671b0 commit 91e53a4
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 9 deletions.
2 changes: 1 addition & 1 deletion endpoints/cronjobs/sendnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion endpoints/cronjobs/updatenextpayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 6 additions & 4 deletions endpoints/subscription/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ function resizeAndUploadLogo($uploadedFile, $uploadDir, $name) {
$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);
Expand All @@ -162,15 +163,15 @@ function resizeAndUploadLogo($uploadedFile, $uploadDir, $name) {

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";
}
}

Expand All @@ -192,6 +193,7 @@ function resizeAndUploadLogo($uploadedFile, $uploadDir, $name) {
$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()) {
Expand Down
1 change: 1 addition & 0 deletions endpoints/subscription/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions endpoints/subscriptions/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'last_added' => "Zuletzt hinzugefügt",
'price' => "Preis",
'next_payment' => "Nächste Zahlung",
'inactive' => "Deaktiviertes Abonnement",
'member' => "Mitglied",
'category' => "Kategorie",
'payment_method' => "Zahlungsmethode",
Expand Down Expand Up @@ -70,6 +71,7 @@
// 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",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/el.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'last_added' => "Τελευταία προσθήκη",
'price' => "Τιμή",
'next_payment' => "Επόμενη πληρωμή",
'inactive' => "Ανενεργή συνδρομή",
'member' => "Χρήστης",
'category' => "Κατηγορία",
'payment_method' => "Τρόπος πληρωμής",
Expand Down Expand Up @@ -70,6 +71,7 @@
// Statistics page
'general_statistics' => "Γενικές στατιστικές",
'active_subscriptions' => "Ενεργές συνδρομές",
'inactive_subscriptions' => "Ανενεργές συνδρομές",
'monthly_cost' => "Μηνιαίο κόστος",
'yearly_cost' => "Ετήσιο κόστος",
'average_monthly' => "Μέσο μηνιαίο κόστος συνδρομής",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'last_added' => "Last Added",
'price' => "Price",
'next_payment' => "Next Payment",
'inactive' => "Disabled Subscription",
'member' => "Member",
'category' => "Category",
'payment_method' => "Payment Method",
Expand Down Expand Up @@ -70,6 +71,7 @@
// 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",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'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",
Expand Down Expand Up @@ -70,6 +71,7 @@
// 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",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'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",
Expand Down Expand Up @@ -70,6 +71,7 @@
// 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",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/jp.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'last_added' => "最終追加日",
'price' => "金額",
'next_payment' => "次回支払い",
'inactive' => "無効なサブスクリプション",
'member' => "メンバー",
'category' => "カテゴリ",
'payment_method' => "支払い方法",
Expand Down Expand Up @@ -70,6 +71,7 @@
// Statistics page
'general_statistics' => "一般統計",
'active_subscriptions' => "アクティブな定期購入",
'inactive_subscriptions' => "非アクティブなサブスクリプション",
'monthly_cost' => "月間費用",
'yearly_cost' => "年間費用",
'average_monthly' => "月額平均費用",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/pt.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'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",
Expand Down Expand Up @@ -70,6 +71,7 @@
// 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",
Expand Down
2 changes: 2 additions & 0 deletions includes/i18n/zh_cn.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
'last_added' => "创建时间",
'price' => "价格",
'next_payment' => "下次支付时间",
'inactive' => "禁用订阅",
'member' => "成员",
'category' => "分类",
'payment_method' => "支付方式",
Expand Down Expand Up @@ -75,6 +76,7 @@
// 统计页面
'general_statistics' => "总体统计",
'active_subscriptions' => "活跃订阅",
'inactive_subscriptions' => "非活动订阅",
'monthly_cost' => "月费用",
'yearly_cost' => "年费用",
'average_monthly' => "平均每月订阅费用",
Expand Down
9 changes: 8 additions & 1 deletion includes/list_subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ function printSubscriptions($subscriptions, $sort, $categories, $members, $i18n)
});
}

usort($subscriptions, function ($a, $b) {
if ($a['inactive'] == $b['inactive']) {
return 0;
}
return $a['inactive'] ? 1 : -1;
});

$currentCategory = 0;
$currentPayerUserId = 0;
$currentPaymentMethodId = 0;
Expand Down Expand Up @@ -98,7 +105,7 @@ function printSubscriptions($subscriptions, $sort, $categories, $members, $i18n)
$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>
Expand Down
6 changes: 6 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down Expand Up @@ -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">
Expand Down
11 changes: 11 additions & 0 deletions migrations/000008.php
Original file line number Diff line number Diff line change
@@ -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');
}
2 changes: 2 additions & 0 deletions scripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
21 changes: 19 additions & 2 deletions stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,27 @@ function getPriceConverted($price, $currency, $database) {


// 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)) {
Expand Down Expand Up @@ -163,6 +171,15 @@ function getPriceConverted($price, $currency, $database) {
<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>
Expand Down
7 changes: 7 additions & 0 deletions styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 91e53a4

Please sign in to comment.