From 45c93283fbf31884abc1fb39d09af0e61dca0a9d Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 12 Mar 2021 21:50:42 +1100 Subject: [PATCH] Fix determining traffic usage month end --- app/Models/Service/Adsl.php | 2 +- app/Models/Service/AdslTraffic.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Models/Service/Adsl.php b/app/Models/Service/Adsl.php index 31a6f23..d56b503 100644 --- a/app/Models/Service/Adsl.php +++ b/app/Models/Service/Adsl.php @@ -159,7 +159,7 @@ class Adsl extends ServiceType implements ServiceItem,ServiceUsage // If we are before the 15th if ($start->day < 15) { - $start = Carbon::createFromFormat('Y-m-d',$start->subMonth->format('Y-m-').'15'); + $start = Carbon::createFromFormat('Y-m-d',$start->subMonth()->format('Y-m-').'15'); } else { $start = $start->subDays($start->day-15); } diff --git a/app/Models/Service/AdslTraffic.php b/app/Models/Service/AdslTraffic.php index 7fc8ba0..016f4c1 100644 --- a/app/Models/Service/AdslTraffic.php +++ b/app/Models/Service/AdslTraffic.php @@ -23,6 +23,10 @@ class AdslTraffic extends Model public function getTrafficMonthEndAttribute() { if ($this->date->day > $this->traffic_end) { + // If we are the last day of the month, we'll temporarily take 3 days since Jan 31 and addMonth() results in March. + if ($this->date->isLastOfMonth()) + $this->date=$this->date->subDays(3); + return Carbon::createFromFormat('Y-m-d',$this->date->addMonth()->format('Y-m-').$this->traffic_end); } else { return Carbon::createFromFormat('Y-m-d',$this->date->format('Y-m-').$this->traffic_end);