osb/app/Models/Service/Adsl.php

93 lines
1.8 KiB
PHP
Raw Normal View History

2018-05-20 12:53:14 +00:00
<?php
namespace App\Models\Service;
2018-05-20 12:53:14 +00:00
2020-02-05 04:47:24 +00:00
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use App\Interfaces\ServiceItem;
use App\Models\Base\ServiceType;
use App\Models\Service;
use App\Traits\NextKey;
2020-02-05 04:47:24 +00:00
class Adsl extends ServiceType implements ServiceItem
2018-05-20 12:53:14 +00:00
{
use NextKey;
const RECORD_ID = 'service__adsl';
// @todo column service_id can be removed.
2018-05-20 12:53:14 +00:00
protected $table = 'ab_service__adsl';
2020-02-05 04:47:24 +00:00
protected $dates = [
'service_connect_date',
'service_contract_date'
];
/**
* The service this belongs to
*
* @return BelongsTo|MorphOne
*/
public function service()
{
return $this->belongsTo(Service::class);
}
2018-05-20 12:53:14 +00:00
2019-06-29 00:14:12 +00:00
/** SCOPES */
/**
* Search for a record
*
* @param $query
* @param string $term
* @return
*/
public function scopeSearch($query,string $term)
{
// Build our where clause
return parent::scopeSearch($query,$term)
->orwhere('service_number','like','%'.$term.'%')
->orWhere('service_address','like','%'.$term.'%')
->orWhere('ipaddress','like','%'.$term.'%');
}
/** ATTRIBUTES **/
/**
2020-02-05 04:47:24 +00:00
* @deprecated use $o->type()->service_name;
* @return mixed|string
2019-06-29 00:14:12 +00:00
*/
2020-02-05 04:47:24 +00:00
public function getNameAttribute()
2018-11-21 03:37:17 +00:00
{
2020-02-05 04:47:24 +00:00
return $this->service_number ?: $this->service_address;
2018-11-21 03:37:17 +00:00
}
2020-02-05 04:47:24 +00:00
/**
* Return the service address
*
* @return string
*/
public function getServiceDescriptionAttribute(): string
2018-05-20 12:53:14 +00:00
{
2020-02-08 11:51:50 +00:00
return strtoupper($this->service_address) ?: 'NO Service Address';
2020-02-05 04:47:24 +00:00
}
/**
* Return the service number
*
* @return string
*/
public function getServiceNameAttribute(): string
{
return $this->service_number ?: 'NO Service Number';
2018-05-20 12:53:14 +00:00
}
2019-06-29 00:14:12 +00:00
2020-02-05 04:47:24 +00:00
/**
* Is this service currently in a contract
*
* @return bool
*/
public function inContract(): bool
2019-06-29 00:14:12 +00:00
{
2020-02-05 04:47:24 +00:00
return $this->service_contract_date AND $this->service_contract_date->addMonths($this->contract_term)->isFuture();
2019-06-29 00:14:12 +00:00
}
2018-05-20 12:53:14 +00:00
}