diff --git a/stats.php b/stats.php index 722115a..46e4db0 100644 --- a/stats.php +++ b/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 $query = "SELECT c.symbol FROM currencies c @@ -61,7 +72,7 @@ $activeSubscriptions = $row['active_subscriptions']; $mostExpensiveSubscription = 0; $amountDueThisMonth = 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); if ($result) { while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -75,12 +86,19 @@ if ($result) { $cycle = $subscription['cycle']; $currency = $subscription['currency_id']; $next_payment = $subscription['next_payment']; + $payerId = $subscription['payer_user_id']; $originalSubscriptionPrice = getPriceConverted($price, $currency, $db); $price = getPricePerMonth($cycle, $frequency, $originalSubscriptionPrice); $totalCostPerMonth += $price; + $memberCost[$payerId]['cost'] += $price; if ($price > $mostExpensiveSubscription) { $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, ".", ""); if ((int)$totalCostPerMonth == $totalCostPerMonth) { $totalCostPerMonth = (int)$totalCostPerMonth; @@ -125,10 +143,7 @@ if ($result) { $averageSubscriptionCost = 0; } } - -// Calculate cost per household member - - + ?>
@@ -156,6 +171,23 @@ if ($result) {
Amount due this month
+ +
+ +
's monthly costs
+
+ +
+
span {