Added usage graph (ADSL), improved logging for usage collection (ADSL)
This commit is contained in:
@@ -2,16 +2,19 @@
|
||||
|
||||
namespace App\Models\Service;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
use App\Interfaces\ServiceItem;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Interfaces\{ServiceItem,ServiceUsage};
|
||||
use App\Models\AdslSupplierPlan;
|
||||
use App\Models\Base\ServiceType;
|
||||
use App\Models\Service;
|
||||
use App\Traits\NextKey;
|
||||
|
||||
class Adsl extends ServiceType implements ServiceItem
|
||||
class Adsl extends ServiceType implements ServiceItem,ServiceUsage
|
||||
{
|
||||
private const LOGKEY = 'MSA';
|
||||
|
||||
use NextKey;
|
||||
const RECORD_ID = 'service__adsl';
|
||||
|
||||
@@ -30,6 +33,7 @@ class Adsl extends ServiceType implements ServiceItem
|
||||
*/
|
||||
public function traffic()
|
||||
{
|
||||
// @todo Need to include site_id in this relation
|
||||
return $this->hasMany(AdslTraffic::class,'ab_service_adsl_id');
|
||||
}
|
||||
|
||||
@@ -91,4 +95,24 @@ class Adsl extends ServiceType implements ServiceItem
|
||||
{
|
||||
return $this->service_contract_date AND $this->service_contract_date->addMonths($this->contract_term)->isFuture();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return service usage data
|
||||
*
|
||||
* @param int $days
|
||||
* @return Collection
|
||||
*/
|
||||
public function usage(int $days=31): Collection
|
||||
{
|
||||
$maxdate = self::traffic()
|
||||
->select(DB::raw('max(date) as max'))
|
||||
->pluck('max')->pop();
|
||||
|
||||
Log::debug(sprintf('%s:Getting Usage data for [%d] days from [%s]',self::LOGKEY,$days,$maxdate),['m'=>__METHOD__]);
|
||||
|
||||
return $this->traffic()
|
||||
->where('date','<=',$maxdate)
|
||||
->where('date','>=',DB::raw(sprintf('date_sub(\'%s\',INTERVAL %s DAY)',$maxdate,$days)))
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ class AdslTraffic extends Model
|
||||
{
|
||||
protected $table = 'ab_service__adsl_traffic';
|
||||
public $timestamps = FALSE;
|
||||
protected $dates = ['date'];
|
||||
|
||||
public function broadband()
|
||||
{
|
||||
|
Reference in New Issue
Block a user