From 4e75456b16a703fbaf9fff653a912d75d38c82ef Mon Sep 17 00:00:00 2001 From: ellite Date: Sat, 11 Nov 2023 16:51:31 +0100 Subject: [PATCH] Fix statistics calculation for weekly subscriptions --- stats.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/stats.php b/stats.php index 1103cdb..722115a 100644 --- a/stats.php +++ b/stats.php @@ -92,14 +92,14 @@ if ($result) { if ($nextPaymentDate >= $tomorrow && $nextPaymentDate <= $endOfMonth) { $timesToPay = 1; + $daysInMonth = $endOfMonth->diff($tomorrow)->days + 1; + $daysRemaining = $endOfMonth->diff($nextPaymentDate)->days + 1; if ($cycle == 1) { - $daysInMonth = $endOfMonth->diff($tomorrow)->days + 1; - $daysRemaining = $endOfMonth->diff($nextPaymentDate)->days + 1; $timesToPay = $daysRemaining / $frequency; } if ($cycle == 2) { - $weeksInMonth = $endOfMonth->diff($tomorrow)->weeks + 1; - $weeksRemaining = $endOfMonth->diff($nextPaymentDate)->weeks + 1; + $weeksInMonth = ceil($daysInMonth / 7); + $weeksRemaining = ceil($daysRemaining / 7); $timesToPay = $weeksRemaining / $frequency; } $amountDueThisMonth += $originalSubscriptionPrice * $timesToPay; @@ -125,6 +125,9 @@ if ($result) { $averageSubscriptionCost = 0; } } + +// Calculate cost per household member + ?>