Update and fix broadband traffic

This commit is contained in:
Deon George
2022-04-20 16:24:58 +10:00
parent 621a132e35
commit 16b7e0b493
13 changed files with 161 additions and 112 deletions

View File

@@ -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')