From fca47d4d32d60b7bc6e16a7511a92660a975fa2c Mon Sep 17 00:00:00 2001 From: ellite Date: Sun, 12 Nov 2023 00:21:37 +0100 Subject: [PATCH] Fix roundings on the stats --- stats.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/stats.php b/stats.php index 46e4db0..f755dea 100644 --- a/stats.php +++ b/stats.php @@ -4,19 +4,26 @@ function getPricePerMonth($cycle, $frequency, $price) { switch ($cycle) { case 1: + echo "1"; $numberOfPaymentsPerMonth = (30 / $frequency); return $price * $numberOfPaymentsPerMonth; break; case 2: + echo "2"; $numberOfPaymentsPerMonth = (4.35 / $frequency); return $price * $numberOfPaymentsPerMonth; break; case 3: + echo "3"; $numberOfPaymentsPerMonth = (1 / $frequency); return $price * $numberOfPaymentsPerMonth; break; case 4: - $numberOfPaymentsPerMonth = (0.083 / $frequency); + if ($frequency === 1) { + return $price / 12; + break; + } + $numberOfPaymentsPerMonth = (0.0833310 / $frequency); return $price * $numberOfPaymentsPerMonth; break; } @@ -99,10 +106,6 @@ if ($result) { 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; - } $nextPaymentDate = DateTime::createFromFormat('Y-m-d', trim($next_payment)); $tomorrow = new DateTime('tomorrow'); @@ -138,6 +141,11 @@ if ($result) { if ((int)$averageSubscriptionCost == $averageSubscriptionCost) { $averageSubscriptionCost = (int)$averageSubscriptionCost; } + + $totalCostPerMonth = number_format($totalCostPerMonth, 2, ".", ""); + if ((int)$totalCostPerMonth == $totalCostPerMonth) { + $totalCostPerMonth = (int)$totalCostPerMonth; + } } else { $totalCostPerYear = 0; $averageSubscriptionCost = 0;