Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new statistics per payment method #124

Merged
merged 3 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions includes/i18n/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
'split_views' => "Aufgeteilte Ansichten",
'category_split' => "Kategorien",
'household_split' => "Haushalt",
'payment_method_split' => "Zahlungsmethode",
// About page
'about_and_credits' => "Informationen und Danksagungen",
'license' => "Lizenz",
Expand Down
1 change: 1 addition & 0 deletions includes/i18n/el.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
'split_views' => "Διαχωρισμένες προβολές",
'category_split' => "Διαχωρισμός κατηγορίας",
'household_split' => "Διαχωρισμός νοικοκυριού",
'payment_method_split' => "Διαχωρισμός τρόπου πληρωμής",
// About page
'about_and_credits' => "Σχετικά και Credits",
'license' => "License",
Expand Down
3 changes: 2 additions & 1 deletion includes/i18n/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"weeks" => "weeks",
"months" => "months",
"years" => "years",
"external_url" => "Visit Externarl URL",
"external_url" => "Visit External URL",
"empty_page" => "Empty Page",
// Subscription form
"add_subscription" => "Add subscription",
Expand Down Expand Up @@ -78,6 +78,7 @@
'split_views' => "Split Views",
'category_split' => "Category Split",
'household_split' => "Household Split",
'payment_method_split' => "Payment Method Split",
// About page
'about_and_credits' => "About and Credits",
'license' => "License",
Expand Down
1 change: 1 addition & 0 deletions includes/i18n/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
'split_views' => "Vistas Divididas",
'category_split' => "División por Categoría",
'household_split' => "División por Hogar",
'payment_method_split' => "División por Método de Pago",
// About page
'about_and_credits' => "Acerca de y Créditos",
'license' => "Licencia",
Expand Down
1 change: 1 addition & 0 deletions includes/i18n/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
'split_views' => "Vues partagées",
'category_split' => "Répartition par catégorie",
'household_split' => "Répartition du ménage",
'payment_method_split' => "Répartition par méthode de paiement",
// Page À propos
'about_and_credits' => "À propos et crédits",
'license' => "Licence",
Expand Down
1 change: 1 addition & 0 deletions includes/i18n/jp.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
'split_views' => "分割表示",
'category_split' => "カテゴリ別",
'household_split' => "世帯別",
'payment_method_split' => "支払い方法別",
// About page
'about_and_credits' => "概要とクレジット",
'license' => "License",
Expand Down
1 change: 1 addition & 0 deletions includes/i18n/pt.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
'split_views' => "Vistas Divididas",
'category_split' => "Por Categoria",
'household_split' => "Por Membro",
'payment_method_split' => "Por Método de Pagamento",
// About page
'about_and_credits' => "Sobre e Créditos",
'license' => "Licença",
Expand Down
1 change: 1 addition & 0 deletions includes/i18n/tr.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
'split_views' => "Bölünmüş Görünümler",
'category_split' => "Kategori Bölümü",
'household_split' => "Hane Bölümü",
'payment_method_split' => "Ödeme Yöntemi Bölümü",
// About page
'about_and_credits' => "Hakkında ve Teşekkürler",
'license' => "Lisans",
Expand Down
1 change: 1 addition & 0 deletions includes/i18n/zh_cn.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
'split_views' => "拆分视图",
'category_split' => "分类视图",
'household_split' => "家庭视图",
'payment_method_split' => "支付方式视图",

// 关于页面
'about_and_credits' => "关于和鸣谢",
Expand Down
1 change: 1 addition & 0 deletions includes/i18n/zh_tw.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
'split_views' => "分割表示",
'category_split' => "類別表示",
'household_split' => "家庭表示",
'payment_method_split' => "付款方式表示",

// 關於頁面
'about_and_credits' => "關於和致謝",
Expand Down
2 changes: 1 addition & 1 deletion scripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function handleFileSelect(event) {
}

function deleteSubscription(id) {
if (confirm("Are you sure you want to delete this subscription?")) {
if (confirm(translate('confirm_delete_subscription'))) {
fetch(`endpoints/subscription/delete.php?id=${id}`, {
method: 'DELETE',
})
Expand Down
1 change: 1 addition & 0 deletions scripts/i18n/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let i18n = {
failed_to_load_subscription: "Fehler beim Laden des Abonnements",
edit_subscription: "Abonnement bearbeiten",
add_subscription: "Abonnement hinzufügen",
confirm_delete_subscription: "Sind Sie sicher, dass Sie dieses Abonnement löschen möchten?",
// Settings
network_response_error: "Netzwerkfehler",
failed_add_member: "Hinzufügen von Mitglied fehlgeschlagen",
Expand Down
1 change: 1 addition & 0 deletions scripts/i18n/el.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let i18n = {
failed_to_load_subscription: "Απέτυχε η φόρτωση της συνδρομής",
edit_subscription: "Επεξεργασία συνδρομής",
add_subscription: "Προσθήκη συνδρομής",
confirm_delete_subscription: "Είστε σίγουρος ότι θέλετε να διαγράψετε αυτή τη συνδρομή;",
// Settings
network_response_error: "Η ανταπόκριση του δικτύου δεν ήταν εντάξει",
failed_add_member: "Αποτυχία προσθήκης μέλους",
Expand Down
1 change: 1 addition & 0 deletions scripts/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let i18n = {
failed_to_load_subscription: "Failed to load subscription",
edit_subscription: "Edit subscription",
add_subscription: "Add subscription",
confirm_delete_subscription: "Are you sure you want to delete this subscription?",
// Settings
network_response_error: "Network response was not ok",
failed_add_member: "Failed to add member",
Expand Down
1 change: 1 addition & 0 deletions scripts/i18n/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let i18n = {
failed_to_load_subscription: "Error al cargar la suscripción",
edit_subscription: "Editar suscripción",
add_subscription: "Añadir suscripción",
confirm_delete_subscription: "¿Estás seguro de que quieres eliminar esta suscripción?",
// Settings
network_response_error: "Error en la respuesta de la red",
failed_add_member: "Error al añadir miembro",
Expand Down
1 change: 1 addition & 0 deletions scripts/i18n/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let i18n = {
failed_to_load_subscription: "Impossible de charger l'abonnement",
edit_subscription: "Modifier l'abonnement",
add_subscription: "Ajouter un abonnement",
confirm_delete_subscription: "Êtes-vous sûr de vouloir supprimer cet abonnement ?",
// Paramètres
network_response_error: "La réponse du réseau n'était pas correcte",
failed_add_member: "Échec de l'ajout du membre",
Expand Down
1 change: 1 addition & 0 deletions scripts/i18n/jp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let i18n = {
failed_to_load_subscription: "定期購入の読み込みに失敗しました",
edit_subscription: "定期購入の編集",
add_subscription: "定期購入の追加",
confirm_delete_subscription: "この定期購入を削除してもよろしいですか?",
// Settings
network_response_error: "ネットワークの応答異常",
failed_add_member: "世帯員の追加に失敗",
Expand Down
1 change: 1 addition & 0 deletions scripts/i18n/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let i18n = {
'failed_to_load_subscription': 'Falha ao carregar a subscrição',
'edit_subscription': 'Editar subscrição',
'add_subscription': 'Adicionar subscrição',
'confirm_delete_subscription': 'Tem a certeza de que deseja eliminar esta subscrição?',
// Settings
'network_response_error': 'Erro de resposta de rede',
'failed_add_member': 'Falha ao adicionar membro',
Expand Down
1 change: 1 addition & 0 deletions scripts/i18n/tr.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let i18n = {
failed_to_load_subscription: "Abonelik yüklenemedi",
edit_subscription: "Aboneliği Düzenle",
add_subscription: "Abonelik Ekle",
confirm_delete_subscription: "Bu aboneliği silmek istediğinizden emin misiniz?",
// Ayarlar
network_response_error: "Ağ yanıtı kabul edilmedi",
failed_add_member: "Üye eklenemedi",
Expand Down
1 change: 1 addition & 0 deletions scripts/i18n/zh_cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let i18n = {
'failed_to_load_subscription': "加载订阅失败",
'edit_subscription': "编辑订阅",
'add_subscription': "添加订阅",
'confirm_delete_subscription': "您确定要删除此订阅吗?",
// Settings
'network_response_error': "网络响应不正常",
'failed_add_member': '添加成员失败',
Expand Down
1 change: 1 addition & 0 deletions scripts/i18n/zh_tw.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let i18n = {
'failed_to_load_subscription': "讀取訂閱失敗",
'edit_subscription': "編輯訂閱",
'add_subscription': "新增訂閱",
'confirm_delete_subscription': "您確定要刪除此訂閱嗎?",
// Settings
'network_response_error': "網路無回應",
'failed_add_member': '新增成員失敗',
Expand Down
8 changes: 7 additions & 1 deletion scripts/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ function loadGraph(container, dataPoints, currency, run) {
datasets: [{
data: dataPoints.map(point => point.y),
}],
labels: dataPoints.map(point => `${point.label} (${new Intl.NumberFormat(navigator.language, { style: 'currency', currency }).format(point.y)})`),
labels: dataPoints.map(point => {
if (currency) {
return `${point.label} (${new Intl.NumberFormat(navigator.language, { style: 'currency', currency }).format(point.y)})`;
} else {
return `${point.label} (${new Intl.NumberFormat(navigator.language).format(point.y)})`;
}
}),
},
options: {
animation: {
Expand Down
39 changes: 38 additions & 1 deletion stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ function getPriceConverted($price, $currency, $database) {
$categoryCost[$categoryId]['name'] = $row['name'];
}

// Get payment methods
$categories = array();
$query = "SELECT * FROM payment_methods WHERE enabled = 1";
$result = $db->query($query);
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$paymentMethodId = $row['id'];
$paymentMethodCount[$paymentMethodId] = $row;
$paymentMethodCount[$paymentMethodId]['count'] = 0;
$paymentMethodCount[$paymentMethodId]['name'] = $row['name'];
}

// Get code of main currency to display on statistics
$query = "SELECT c.code
FROM currencies c
Expand All @@ -84,7 +95,7 @@ function getPriceConverted($price, $currency, $database) {
$amountDueThisMonth = 0;
$totalCostPerMonth = 0;

$query = "SELECT name, price, frequency, cycle, currency_id, next_payment, payer_user_id, category_id FROM subscriptions";
$query = "SELECT name, price, frequency, cycle, currency_id, next_payment, payer_user_id, category_id, payment_method_id FROM subscriptions";
$result = $db->query($query);
if ($result) {
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
Expand All @@ -100,11 +111,13 @@ function getPriceConverted($price, $currency, $database) {
$next_payment = $subscription['next_payment'];
$payerId = $subscription['payer_user_id'];
$categoryId = $subscription['category_id'];
$paymentMethodId = $subscription['payment_method_id'];
$originalSubscriptionPrice = getPriceConverted($price, $currency, $db);
$price = getPricePerMonth($cycle, $frequency, $originalSubscriptionPrice);
$totalCostPerMonth += $price;
$memberCost[$payerId]['cost'] += $price;
$categoryCost[$categoryId]['cost'] += $price;
$paymentMethodCount[$paymentMethodId]['count'] += 1;
if ($price > $mostExpensiveSubscription) {
$mostExpensiveSubscription = $price;
}
Expand Down Expand Up @@ -207,6 +220,18 @@ function getPriceConverted($price, $currency, $database) {

$showMemberCostGraph = count($memberDataPoints) > 1;

$paymentMethodDataPoints = [];
foreach ($paymentMethodCount as $paymentMethod) {
if ($paymentMethod['count'] != 0) {
$paymentMethodDataPoints[] = [
"label" => $paymentMethod['name'],
"y" => $paymentMethod["count"],
];
}
}

$showPaymentMethodCountGraph = count($paymentMethodDataPoints) > 1;

if ($showMemberCostGraph) {
?>
<section class="graph">
Expand All @@ -231,6 +256,17 @@ function getPriceConverted($price, $currency, $database) {
<?php
}

if ($showPaymentMethodCountGraph) {
?>
<section class="graph">
<header>
<?= translate('payment_method_split', $i18n) ?>
</header>
<canvas id="paymentMethidSplitChart" style="height: 370px; width: 100%;"></canvas>
</section>
<?php
}

?>
</div>
</section>
Expand All @@ -242,6 +278,7 @@ function getPriceConverted($price, $currency, $database) {
window.onload = function() {
loadGraph("categorySplitChart", <?php echo json_encode($categoryDataPoints, JSON_NUMERIC_CHECK); ?>, "<?= $code ?>", <?= $showCategoryCostGraph ?>);
loadGraph("memberSplitChart", <?php echo json_encode($memberDataPoints, JSON_NUMERIC_CHECK); ?>, "<?= $code ?>", <?= $showMemberCostGraph ?>);
loadGraph("paymentMethidSplitChart", <?php echo json_encode($paymentMethodDataPoints, JSON_NUMERIC_CHECK); ?>, "", <?= $showPaymentMethodCountGraph ?>);
}
</script>
<?php
Expand Down