Cleanup usage of Leenooks\Carbon, change ServiceType to be consistent with Products/ Suppliers/

This commit is contained in:
Deon George
2022-04-22 11:47:46 +10:00
parent 8ed9e38290
commit a16277d9bb
19 changed files with 65 additions and 64 deletions

View File

@@ -2,21 +2,20 @@
namespace App\Models\Service;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Leenooks\Carbon;
use App\Interfaces\ServiceUsage;
use App\Models\Base\ServiceType;
use App\Models\Supplier\Broadband as SupplierBroadband;
use App\Models\Supplier\Type;
use App\Models\Supplier\Type as SupplierType;
use App\Models\Usage\Broadband as UsageBroadband;
/**
* Class Broadband (Service)
* Services that are Internet Broadband
*/
class Broadband extends ServiceType implements ServiceUsage
class Broadband extends Type implements ServiceUsage
{
private const LOGKEY = 'MSB';
@@ -105,9 +104,9 @@ class Broadband extends ServiceType implements ServiceUsage
/**
* Return the suppliers offering that this service is providing
*
* @return Type
* @return SupplierType
*/
public function supplied(): Type
public function supplied(): SupplierType
{
return $this->provided_adsl_plan_id
? SupplierBroadband::findOrFail($this->provided_adsl_plan_id)

View File

@@ -2,15 +2,14 @@
namespace App\Models\Service;
use App\Models\Base\ServiceType;
use App\Traits\ServiceDomains;
use App\Models\DomainRegistrar;
use App\Traits\ServiceDomains;
/**
* Class Domain (Service)
* Services that are managed Domain Names
*/
class Domain extends ServiceType
class Domain extends Type
{
use ServiceDomains;

View File

@@ -2,14 +2,13 @@
namespace App\Models\Service;
use App\Models\Base\ServiceType;
use App\Traits\ServiceDomains;
/**
* Class Email (Service)
* Services that are Email Hosting
*/
class Email extends ServiceType
class Email extends Type
{
use ServiceDomains;

View File

@@ -2,10 +2,8 @@
namespace App\Models\Service;
use App\Models\Base\ServiceType;
// @todo Document how this is used.
class Generic extends ServiceType
class Generic extends Type
{
protected $table = 'service__generic';
public $timestamps = FALSE;

View File

@@ -2,15 +2,14 @@
namespace App\Models\Service;
use App\Models\Base\ServiceType;
use App\Traits\ServiceDomains;
use App\Models\HostServer;
use App\Traits\ServiceDomains;
/**
* Class Host (Service)
* Services that are Web Hosting
*/
class Host extends ServiceType
class Host extends Type
{
use ServiceDomains;

View File

@@ -2,13 +2,11 @@
namespace App\Models\Service;
use App\Models\Base\ServiceType;
/**
* Class Phone (Service)
* Services that are Voice Telephony
*/
class Phone extends ServiceType
class Phone extends Type
{
protected $dates = [
'connect_at',

View File

@@ -2,16 +2,14 @@
namespace App\Models\Service;
use Illuminate\Support\Arr;
use Carbon\Carbon;
use App\Models\Base\ServiceType;
use Illuminate\Support\Arr;
/**
* Class SSL (Service)
* Services that are provide an SSL Certificate
*/
class SSL extends ServiceType
class SSL extends Type
{
protected $table = 'service_ssl';

View File

@@ -0,0 +1,99 @@
<?php
namespace App\Models\Service;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use App\Interfaces\ServiceItem;
use App\Models\{Account,Service};
use App\Models\Supplier\Type as SupplierType;
use App\Traits\{ScopeServiceActive,ScopeServiceUserAuthorised};
abstract class Type extends Model implements ServiceItem
{
use ScopeServiceActive,ScopeServiceUserAuthorised;
protected $dates = [
'expire_at',
];
public $timestamps = FALSE;
/* RELATIONS */
/**
* Account this service belongs to
* @return \Illuminate\Database\Eloquent\Relations\HasOneThrough
*/
public function account()
{
return $this->hasOneThrough(Account::class,Service::class);
}
/**
* @NOTE: The service_id column could be discarded, if the id column=service_id
* @return \Illuminate\Database\Eloquent\Relations\MorphOne
*/
public function service()
{
return $this->morphOne(Service::class,'type','model','id','service_id');
}
/* SCOPES */
/**
* Search for a record
*
* @param $query
* @param string $term
* @return mixed
*/
public function scopeSearch($query,string $term)
{
return $query
->with(['service'])
->join('services','services.id','=',$this->getTable().'.service_id')
->Where('services.id','like','%'.$term.'%');
}
/* INTERFACE */
public function getContractTermAttribute(): int
{
return $this->service->offering->contract_term;
}
public function getServiceExpireAttribute(): ?Carbon
{
return $this->expire_at ?: $this->service->invoice_next_at;
}
public function hasExpired(): bool
{
return (! $this->inContract()) && ($this->service->invoice_next_at && $this->service->invoice_next_at->isPast());
}
public function inContract(): bool
{
return $this->expire_at && $this->expire_at->isFuture();
}
/* ATTRIBUTES */
public function getTypeAttribute()
{
return strtolower((new \ReflectionClass($this))->getShortName());
}
/* METHODS */
/**
* The supplier's service that we provide
*
* @return SupplierType
*/
public function supplied(): SupplierType
{
return $this->service->product->type->supplied;
}
}