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

@@ -1,48 +0,0 @@
<?php
namespace App\Models;
use App\Models\Service\AdslTraffic;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
/**
* @deprecated
*/
class AdslSupplier extends Model
{
protected $table = 'ab_adsl_supplier';
protected $dates = [
'stats_lastupdate',
];
public $timestamps = FALSE;
/** SCOPES */
/**
* Only query active categories
*/
public function scopeActive($query)
{
return $query->where('active',TRUE);
}
/** METHODS **/
/**
* Return the traffic records, that were not matched to a service.
*
* @param Carbon $date
* @return Collection
*/
public function trafficMismatch(Carbon $date): Collection
{
return AdslTraffic::where('date',$date->format('Y-m-d'))
->where('supplier_id',$this->id)
->whereNULL('ab_service_adsl_id')
->get();
}
}

View File

@@ -22,7 +22,7 @@ final class Broadband extends Type implements ProductItem
'options.address'=>[
'request'=>'options.address',
'key'=>'service_address',
'validation'=>'required|string:10|unique:ab_service__adsl,service_address',
'validation'=>'required|string:10|unique:service_broadband,service_address',
'validation_message'=>'Address is a required field.',
],
'options.notes'=>[

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

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
@@ -62,7 +63,8 @@ class Supplier extends Model
// EG: Crazy Domains, "domains" and "hosting".
public function detail()
{
return $this->hasOne(SupplierDetail::class);
return $this->hasOne(SupplierDetail::class)
->withoutGlobalScope(\App\Models\Scopes\SiteScope::class);
}
/* METHODS */
@@ -103,4 +105,18 @@ class Supplier extends Model
return $result;
}
/**
* Return the traffic records, that were not matched to a service.
*
* @param Carbon $date
* @return \Illuminate\Database\Eloquent\Collection
*/
public function trafficMismatch(Carbon $date): Collection
{
return Usage\Broadband::where('date',$date->format('Y-m-d'))
->where('supplier_id',$this->id)
->whereNULL('service_item_id')
->get();
}
}

View File

@@ -1,23 +1,29 @@
<?php
namespace App\Models\Service;
namespace App\Models\Usage;
use Illuminate\Database\Eloquent\Model;
use Leenooks\Carbon;
class AdslTraffic extends Model
use App\Models\Service\Broadband as ServiceBroadband;
class Broadband extends Model
{
protected $table = 'ab_service__adsl_traffic';
public $timestamps = FALSE;
protected $dates = ['date'];
public $dateFormat = 'U';
protected $table = 'usage_broadband';
public $timestamps = FALSE;
private $traffic_end = 14;
/* RELATIONS */
public function broadband()
{
return $this->belongsTo(Adsl::class);
return $this->belongsTo(ServiceBroadband::class);
}
/* ATTRIBUTES */
public function getTotalAttribute() {
return $this->up_peak+$this->down_peak+$this->up_offpeak+$this->down_offpeak;
}