Add household members monthly cost to stats
This commit is contained in:
parent
fb24b6779d
commit
1e8d0d05da
42
stats.php
42
stats.php
@ -38,6 +38,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get household members
|
||||||
|
$members = array();
|
||||||
|
$query = "SELECT * FROM household";
|
||||||
|
$result = $db->query($query);
|
||||||
|
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||||
|
$memberId = $row['id'];
|
||||||
|
$members[$memberId] = $row;
|
||||||
|
$memberCost[$memberId]['cost'] = 0;
|
||||||
|
$memberCost[$memberId]['name'] = $row['name'];
|
||||||
|
}
|
||||||
|
|
||||||
// Get symbol of main currency to display on statistics
|
// Get symbol of main currency to display on statistics
|
||||||
$query = "SELECT c.symbol
|
$query = "SELECT c.symbol
|
||||||
FROM currencies c
|
FROM currencies c
|
||||||
@ -61,7 +72,7 @@ $activeSubscriptions = $row['active_subscriptions'];
|
|||||||
$mostExpensiveSubscription = 0;
|
$mostExpensiveSubscription = 0;
|
||||||
$amountDueThisMonth = 0;
|
$amountDueThisMonth = 0;
|
||||||
$totalCostPerMonth = 0;
|
$totalCostPerMonth = 0;
|
||||||
$query = "SELECT name, price, frequency, cycle, currency_id, next_payment FROM subscriptions";
|
$query = "SELECT name, price, frequency, cycle, currency_id, next_payment, payer_user_id FROM subscriptions";
|
||||||
$result = $db->query($query);
|
$result = $db->query($query);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||||
@ -75,12 +86,19 @@ if ($result) {
|
|||||||
$cycle = $subscription['cycle'];
|
$cycle = $subscription['cycle'];
|
||||||
$currency = $subscription['currency_id'];
|
$currency = $subscription['currency_id'];
|
||||||
$next_payment = $subscription['next_payment'];
|
$next_payment = $subscription['next_payment'];
|
||||||
|
$payerId = $subscription['payer_user_id'];
|
||||||
$originalSubscriptionPrice = getPriceConverted($price, $currency, $db);
|
$originalSubscriptionPrice = getPriceConverted($price, $currency, $db);
|
||||||
$price = getPricePerMonth($cycle, $frequency, $originalSubscriptionPrice);
|
$price = getPricePerMonth($cycle, $frequency, $originalSubscriptionPrice);
|
||||||
$totalCostPerMonth += $price;
|
$totalCostPerMonth += $price;
|
||||||
|
$memberCost[$payerId]['cost'] += $price;
|
||||||
if ($price > $mostExpensiveSubscription) {
|
if ($price > $mostExpensiveSubscription) {
|
||||||
$mostExpensiveSubscription = $price;
|
$mostExpensiveSubscription = $price;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$memberCost[$payerId]['cost'] = number_format($memberCost[$payerId]['cost'], 2, ".", "");
|
||||||
|
if ((int)$memberCost[$payerId]['cost'] == $memberCost[$payerId]['cost']) {
|
||||||
|
$memberCost[$payerId]['cost'] = (int)$memberCost[$payerId]['cost'];
|
||||||
|
}
|
||||||
$totalCostPerMonth = number_format($totalCostPerMonth, 2, ".", "");
|
$totalCostPerMonth = number_format($totalCostPerMonth, 2, ".", "");
|
||||||
if ((int)$totalCostPerMonth == $totalCostPerMonth) {
|
if ((int)$totalCostPerMonth == $totalCostPerMonth) {
|
||||||
$totalCostPerMonth = (int)$totalCostPerMonth;
|
$totalCostPerMonth = (int)$totalCostPerMonth;
|
||||||
@ -125,10 +143,7 @@ if ($result) {
|
|||||||
$averageSubscriptionCost = 0;
|
$averageSubscriptionCost = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate cost per household member
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<section class="contain">
|
<section class="contain">
|
||||||
<div class="statistics">
|
<div class="statistics">
|
||||||
@ -156,6 +171,23 @@ if ($result) {
|
|||||||
<span><?= $amountDueThisMonth ?><?= $symbol ?></span>
|
<span><?= $amountDueThisMonth ?><?= $symbol ?></span>
|
||||||
<div class="title">Amount due this month</div>
|
<div class="title">Amount due this month</div>
|
||||||
</div>
|
</div>
|
||||||
|
<?php
|
||||||
|
$numberOfElements = 6;
|
||||||
|
foreach($memberCost as $member) {
|
||||||
|
?>
|
||||||
|
<div class="statistic">
|
||||||
|
<span><?= $member['cost'] ?><?= $symbol ?></span>
|
||||||
|
<div class="title"><?= $member['name'] ?>'s monthly costs</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
$numberOfElements++;
|
||||||
|
}
|
||||||
|
if (($numberOfElements + 1) % 3 == 0) {
|
||||||
|
?>
|
||||||
|
<div class="statistic empty"><div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<?php
|
<?php
|
||||||
|
|||||||
@ -1049,13 +1049,22 @@ input[type="checkbox"] {
|
|||||||
flex-basis: 31%;
|
flex-basis: 31%;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.statistic.empty {
|
||||||
|
background-color: transparent;
|
||||||
|
border: none;
|
||||||
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.statistic {
|
.statistic {
|
||||||
flex-basis: 100%;
|
flex-basis: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.statistic.empty {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.statistic > span {
|
.statistic > span {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user