Fix determining traffic usage month end

This commit is contained in:
Deon George 2021-03-12 21:50:42 +11:00
parent fee4b5802e
commit 45c93283fb
No known key found for this signature in database
GPG Key ID: 7670E8DC27415254
2 changed files with 5 additions and 1 deletions

View File

@ -159,7 +159,7 @@ class Adsl extends ServiceType implements ServiceItem,ServiceUsage
// If we are before the 15th // If we are before the 15th
if ($start->day < 15) { 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 { } else {
$start = $start->subDays($start->day-15); $start = $start->subDays($start->day-15);
} }

View File

@ -23,6 +23,10 @@ class AdslTraffic extends Model
public function getTrafficMonthEndAttribute() { public function getTrafficMonthEndAttribute() {
if ($this->date->day > $this->traffic_end) { 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); return Carbon::createFromFormat('Y-m-d',$this->date->addMonth()->format('Y-m-').$this->traffic_end);
} else { } else {
return Carbon::createFromFormat('Y-m-d',$this->date->format('Y-m-').$this->traffic_end); return Carbon::createFromFormat('Y-m-d',$this->date->format('Y-m-').$this->traffic_end);