39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Service;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Leenooks\Carbon;
|
|
|
|
class AdslTraffic extends Model
|
|
{
|
|
protected $table = 'ab_service__adsl_traffic';
|
|
public $timestamps = FALSE;
|
|
protected $dates = ['date'];
|
|
private $traffic_end = 14;
|
|
|
|
public function broadband()
|
|
{
|
|
return $this->belongsTo(Adsl::class);
|
|
}
|
|
|
|
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) {
|
|
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));
|
|
}
|
|
}
|
|
} |