feat: new statistics per payment method (#124)
* feat: new statistics per payment method * fix: fix typo on english language file * fix: use translation text for deleting subscriptions
This commit is contained in:
@@ -60,6 +60,17 @@ while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$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
|
||||
@@ -84,7 +95,7 @@ $mostExpensiveSubscription = 0;
|
||||
$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)) {
|
||||
@@ -100,11 +111,13 @@ if ($result) {
|
||||
$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;
|
||||
}
|
||||
@@ -207,6 +220,18 @@ if ($result) {
|
||||
|
||||
$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">
|
||||
@@ -231,6 +256,17 @@ if ($result) {
|
||||
<?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>
|
||||
@@ -242,6 +278,7 @@ if ($result) {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user