2020-05-28 05:08:13 +00:00
|
|
|
<?php
|
|
|
|
|
2022-04-20 06:24:58 +00:00
|
|
|
namespace App\Models\Usage;
|
2020-05-28 05:08:13 +00:00
|
|
|
|
2022-04-22 01:47:46 +00:00
|
|
|
use Carbon\Carbon;
|
2020-05-28 05:08:13 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
2022-04-20 06:24:58 +00:00
|
|
|
use App\Models\Service\Broadband as ServiceBroadband;
|
|
|
|
|
|
|
|
class Broadband extends Model
|
2020-05-28 05:08:13 +00:00
|
|
|
{
|
2024-07-04 05:03:11 +00:00
|
|
|
protected $casts = [
|
|
|
|
'date'=>'datetime:Y-m-d',
|
|
|
|
];
|
|
|
|
|
2022-04-20 06:24:58 +00:00
|
|
|
protected $table = 'usage_broadband';
|
|
|
|
public $timestamps = FALSE;
|
|
|
|
|
2021-03-12 10:08:40 +00:00
|
|
|
private $traffic_end = 14;
|
2020-05-28 05:08:13 +00:00
|
|
|
|
2022-04-20 06:24:58 +00:00
|
|
|
/* RELATIONS */
|
|
|
|
|
2020-05-28 05:08:13 +00:00
|
|
|
public function broadband()
|
|
|
|
{
|
2022-04-20 06:24:58 +00:00
|
|
|
return $this->belongsTo(ServiceBroadband::class);
|
2020-05-28 05:08:13 +00:00
|
|
|
}
|
2021-03-12 10:08:40 +00:00
|
|
|
|
2022-04-20 06:24:58 +00:00
|
|
|
/* ATTRIBUTES */
|
|
|
|
|
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) {
|
2021-03-12 10:50:42 +00:00
|
|
|
// If we are the last day of the month, we'll temporarily take 3 days since Jan 31 and addMonth() results in March.
|
2021-03-12 11:59:19 +00:00
|
|
|
if ($this->date->addMonth()->day != $this->date->day)
|
2021-03-12 10:50:42 +00:00
|
|
|
$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
|
|
|
}
|