Update and fix broadband traffic
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
<?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'];
|
||||
public $dateFormat = 'U';
|
||||
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) {
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
}
|
@@ -10,6 +10,7 @@ use App\Interfaces\ServiceUsage;
|
||||
use App\Models\Base\ServiceType;
|
||||
use App\Models\Supplier\Broadband as SupplierBroadband;
|
||||
use App\Models\Supplier\Type;
|
||||
use App\Models\Usage\Broadband as UsageBroadband;
|
||||
|
||||
/**
|
||||
* Class Broadband (Service)
|
||||
@@ -65,17 +66,15 @@ class Broadband extends ServiceType implements ServiceUsage
|
||||
return $this->service_number ?: ($this->service_address ?: '-');
|
||||
}
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
/**
|
||||
* The accounts that this user manages
|
||||
* The usage information for broadband
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function traffic()
|
||||
{
|
||||
// @todo Need to include site_id in this relation
|
||||
return $this->hasMany(AdslTraffic::class,'ab_service_adsl_id');
|
||||
return $this->hasMany(UsageBroadband::class,'service_item_id')
|
||||
->where('site_id',$this->site_id);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
@@ -128,8 +127,6 @@ class Broadband extends ServiceType implements ServiceUsage
|
||||
if (! $maxdate)
|
||||
return collect();
|
||||
|
||||
Log::debug(sprintf('%s:Getting Usage data for [%d] days from [%s]',self::LOGKEY,$days,$maxdate->date->format('Y-m-d')),['m'=>__METHOD__]);
|
||||
|
||||
return $this->traffic()
|
||||
->where('date','<=',$maxdate->date->format('Y-m-d'))
|
||||
->where('date','>=',$maxdate->date->subDays($days)->format('Y-m-d'))
|
||||
@@ -139,9 +136,9 @@ class Broadband extends ServiceType implements ServiceUsage
|
||||
/**
|
||||
* Find the last date any traffic was recorded for a service
|
||||
*
|
||||
* @return AdslTraffic|null
|
||||
* @return UsageBroadband|null
|
||||
*/
|
||||
private function usage_last_date(): ?AdslTraffic
|
||||
private function usage_last_date(): ?UsageBroadband
|
||||
{
|
||||
return $this->traffic
|
||||
->sortBy('date')
|
||||
|
Reference in New Issue
Block a user