osb/app/Models/Service/AdslTraffic.php

44 lines
1.3 KiB
PHP
Raw Normal View History

2020-05-28 05:08:13 +00:00
<?php
namespace App\Models\Service;
use Illuminate\Database\Eloquent\Model;
2021-03-12 10:08:40 +00:00
use Leenooks\Carbon;
2020-05-28 05:08:13 +00:00
class AdslTraffic extends Model
{
protected $table = 'ab_service__adsl_traffic';
public $timestamps = FALSE;
protected $dates = ['date'];
public $dateFormat = 'U';
2021-03-12 10:08:40 +00:00
private $traffic_end = 14;
2020-05-28 05:08:13 +00:00
public function broadband()
{
return $this->belongsTo(Adsl::class);
}
2021-03-12 10:08:40 +00:00
public function getTotalAttribute() {
return $this->up_peak+$this->down_peak+$this->up_offpeak+$this->down_offpeak;
}
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->addMonth()->day != $this->date->day)
$this->date=$this->date->subDays(3);
2021-03-12 10:08:40 +00:00
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);
}
}
public function getTrafficMonthStartAttribute() {
if ($this->date->day > $this->traffic_end) {
return Carbon::createFromFormat('Y-m-d',$this->date->format('Y-m-').($this->traffic_end+1));
} else {
return Carbon::createFromFormat('Y-m-d',$this->date->subMonth()->format('Y-m-').($this->traffic_end+1));
}
}
2020-05-28 05:08:13 +00:00
}