Update and fix broadband traffic
This commit is contained in:
50
app/Models/Usage/Broadband.php
Normal file
50
app/Models/Usage/Broadband.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Usage;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Leenooks\Carbon;
|
||||
|
||||
use App\Models\Service\Broadband as ServiceBroadband;
|
||||
|
||||
class Broadband extends Model
|
||||
{
|
||||
protected $dates = ['date'];
|
||||
protected $table = 'usage_broadband';
|
||||
public $timestamps = FALSE;
|
||||
|
||||
private $traffic_end = 14;
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function broadband()
|
||||
{
|
||||
return $this->belongsTo(ServiceBroadband::class);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
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);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user