Start work on updating services

This commit is contained in:
Deon George
2022-04-19 17:07:39 +10:00
parent ebf08ea414
commit 621a132e35
63 changed files with 1038 additions and 612 deletions

View File

@@ -6,24 +6,64 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Leenooks\Carbon;
use App\Interfaces\{ServiceItem,ServiceUsage};
use App\Interfaces\ServiceUsage;
use App\Models\Base\ServiceType;
use App\Models\Supplier\Broadband as SupplierBroadband;
use App\Traits\NextKey;
use App\Models\Supplier\Type;
class Broadband extends ServiceType implements ServiceItem,ServiceUsage
/**
* Class Broadband (Service)
* Services that are Internet Broadband
*/
class Broadband extends ServiceType implements ServiceUsage
{
private const LOGKEY = 'MSA';
use NextKey;
const RECORD_ID = 'service__adsl';
private const LOGKEY = 'MSB';
protected $dates = [
'service_connect_date',
'service_contract_date'
'connect_at',
'expire_at',
];
public $dateFormat = 'U';
protected $table = 'ab_service__adsl';
protected $table = 'service_broadband';
/* ABSTRACT */
/**
* Search for a record
*
* @param $query
* @param string $term
* @return mixed
*/
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.'%');
}
/* INTERFACES */
/**
* Return the service address
*
* @return string
*/
public function getServiceDescriptionAttribute(): string
{
return strtoupper($this->service_address) ?: '-';
}
/**
* Return the service number
*
* @return string
*/
public function getServiceNameAttribute(): string
{
return $this->service_number ?: ($this->service_address ?: '-');
}
/* RELATIONS */
@@ -38,79 +78,37 @@ class Broadband extends ServiceType implements ServiceItem,ServiceUsage
return $this->hasMany(AdslTraffic::class,'ab_service_adsl_id');
}
/* 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 */
/**
* @deprecated use $o->service_name;
* @return mixed|string
*/
/* ATTRIBUTES */
public function getNameAttribute()
{
abort(500,'deprecated - use $o->service_name');
return $this->service_number ?: $this->service_address;
}
/**
* Return the service address
* The type of technology used to provide this Internet Service
*
* @return string
* @param $value
* @return null|string
*/
public function getServiceDescriptionAttribute(): string
public function getTechnologyAttribute($value): ?string
{
return strtoupper($this->service_address) ?: 'NO Service Address';
}
public function getServiceExpireAttribute(): \Carbon\Carbon
{
// TODO: Implement getServiceExpireAttribute() method.
}
/**
* Return the service number
*
* @return string
*/
public function getServiceNameAttribute(): string
{
return $this->service_number ?: $this->service_address;
return $value ?: $this->supplied()->technology;
}
/* METHODS */
/**
* Is this service currently in a contract
*
* @return bool
*/
public function inContract(): bool
{
return $this->service_contract_date AND $this->service_contract_date->addMonths($this->contract_term)->isFuture();
}
/**
* Return the suppliers offering that this service is providing
*
* @return SupplierBroadband
* @return Type
*/
public function supplied(): SupplierBroadband
public function supplied(): Type
{
return $this->provided_adsl_plan_id
? SupplierBroadband::findOrFail($this->provided_adsl_plan_id)
@@ -184,4 +182,4 @@ class Broadband extends ServiceType implements ServiceItem,ServiceUsage
return $result;
}
}
}

View File

@@ -2,97 +2,25 @@
namespace App\Models\Service;
use Carbon\Carbon;
use App\Models\Base\ServiceType;
use App\Models\{Account,DomainRegistrar,DomainTld,Service};
use App\Interfaces\ServiceItem;
use App\Traits\{NextKey,ScopeServiceActive,ScopeServiceUserAuthorised};
use App\Traits\ServiceDomains;
use App\Models\DomainRegistrar;
/**
* Class Domain (Service)
* Services that domain names
*
* Attributes for services:
* + service_description : Description as shown in a Service Context
* + service_expire : The date the service expires
* + service_name : Name as shown in a Service Context
*
* @package App\Models\Service
* Services that are managed Domain Names
*/
class Domain extends ServiceType implements ServiceItem
class Domain extends ServiceType
{
use ScopeServiceActive,ScopeServiceUserAuthorised;
use ServiceDomains;
protected $dates = [
'domain_expire',
];
public $dateFormat = 'U';
protected $table = 'service_domains';
protected $table = 'service_domain';
protected $with = ['tld'];
/* INTERFACES */
public function getServiceDescriptionAttribute(): string
{
// N/A
return 'Domain Name';
}
public function getServiceExpireAttribute(): Carbon
{
return $this->domain_expire;
}
/**
* The name of the domain with its TLD
*
* @return string
*/
public function getServiceNameAttribute(): string
{
return strtoupper(sprintf('%s.%s',$this->domain_name,$this->tld->name));
}
public function inContract(): bool
{
return $this->domain_expire->isFuture();
}
/* RELATIONS */
public function account()
{
return $this->hasOneThrough(Account::class,Service::class);
}
public function registrar()
{
return $this->belongsTo(DomainRegistrar::class,'domain_registrar_id');
}
public function tld()
{
return $this->belongsTo(DomainTld::class,'domain_tld_id');
}
/* SCOPES */
/**
* Search for a record
*
* @param $query
* @param string $term
* @return mixed
*/
public function scopeSearch($query,string $term)
{
// If we have a period in the name, we'll ignore everything after it.
$term = strstr($term,'.',TRUE) ?: $term;
// Build our where clause
return parent::scopeSearch($query,$term)
->orwhere('domain_name','like','%'.$term.'%');
}
/* ATTRIBUTES */
}

View File

@@ -2,64 +2,17 @@
namespace App\Models\Service;
use Carbon\Carbon;
use App\Models\Base\ServiceType;
use App\Models\{Account, DomainRegistrar, DomainTld, Service, TLD};
use App\Interfaces\ServiceItem;
use App\Traits\{NextKey,ScopeServiceActive,ScopeServiceUserAuthorised};
use App\Traits\ServiceDomains;
/**
* Class Email (Service)
* Services that email hostings
*
* Attributes for services:
* + service_description : Description as shown in a Service Context
* + service_expire : The date the service expires
* + service_name : Name as shown in a Service Context
*
* @package App\Models\Service
* Services that are Email Hosting
*/
class Email extends ServiceType implements ServiceItem
class Email extends ServiceType
{
use ScopeServiceActive,ScopeServiceUserAuthorised;
use ServiceDomains;
protected $dates = ['expire_at'];
protected $table = 'service_emails';
/* INTERFACES */
public function getServiceDescriptionAttribute(): string
{
// N/A
return 'Email Hosting';
}
public function getServiceExpireAttribute(): Carbon
{
return $this->expire_at ?: $this->service->next_invoice;
}
/**
* The name of the domain with its TLD
*
* @return string
* // @todo
*/
public function getServiceNameAttribute(): string
{
return strtoupper(sprintf('%s.%s',$this->domain_name,$this->tld->name));
}
public function inContract(): bool
{
return $this->expire_at && $this->expire_at->isFuture();
}
/* RELATIONS */
public function tld()
{
return $this->belongsTo(TLD::class);
}
protected $table = 'service_email';
protected $with = ['tld'];
}

View File

@@ -4,8 +4,21 @@ namespace App\Models\Service;
use App\Models\Base\ServiceType;
// @todo Document how this is used.
class Generic extends ServiceType
{
protected $table = 'service__generic';
public $timestamps = FALSE;
/* INTERFACE */
public function getServiceDescriptionAttribute(): string
{
return 'Generic';
}
public function getServiceNameAttribute(): string
{
return 'Generic';
}
}

View File

@@ -2,55 +2,25 @@
namespace App\Models\Service;
use Carbon\Carbon;
use App\Interfaces\ServiceItem;
use App\Models\Base\ServiceType;
use App\Models\DomainTld;
use App\Traits\ServiceDomains;
use App\Models\HostServer;
use App\Traits\NextKey;
use App\Traits\{ScopeServiceActive,ScopeServiceUserAuthorised};
class Host extends ServiceType implements ServiceItem
/**
* Class Host (Service)
* Services that are Web Hosting
*/
class Host extends ServiceType
{
use ScopeServiceActive,ScopeServiceUserAuthorised;
use NextKey;
const RECORD_ID = 'service__hosting';
use ServiceDomains;
protected $dates = [
'host_expire',
];
public $dateFormat = 'U';
protected $table = 'ab_service__hosting';
protected $table = 'service_host';
protected $with = ['tld'];
/* RELATIONS */
public function provider()
{
return $this->belongsTo(HostServer::class,'host_server_id');
}
public function tld()
{
return $this->belongsTo(DomainTld::class,'domain_tld_id');
}
public function getServiceDescriptionAttribute(): string
{
// N/A
return 'Hosting';
}
public function getServiceExpireAttribute(): Carbon
{
return $this->host_expire;
}
public function getServiceNameAttribute(): string
{
return sprintf('%s.%s',strtoupper($this->domain_name),strtoupper($this->tld->name));
}
public function inContract(): bool
{
return $this->host_expire->isFuture();
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace App\Models\Service;
use App\Models\Base\ServiceType;
/**
* Class Phone (Service)
* Services that are Voice Telephony
*/
class Phone extends ServiceType
{
protected $dates = [
'connect_at',
'expire_at',
];
protected $table = 'service_phone';
/* ABSTRACT */
/**
* Search for a record
*
* @param $query
* @param string $term
* @return mixed
*/
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.'%');
}
/* INTERFACES */
/**
* Return the service address
*
* @return string
*/
public function getServiceDescriptionAttribute(): string
{
return strtoupper($this->service_address) ?: '-';
}
/**
* Return the service number
*
* @return string
*/
public function getServiceNameAttribute(): string
{
return $this->service_number ?: ($this->service_address ?: '-');
}
/* ATTRIBUTES */
/**
* The type of technology used to provide this Internet Service
*
* @param $value
* @return null|string
*/
public function getTechnologyAttribute($value): ?string
{
return $value ?: $this->supplied()->technology;
}
}

View File

@@ -5,19 +5,20 @@ namespace App\Models\Service;
use Illuminate\Support\Arr;
use Carbon\Carbon;
use App\Interfaces\ServiceItem;
use App\Models\Base\ServiceType;
use App\Traits\NextKey;
class SSL extends ServiceType implements ServiceItem
/**
* Class SSL (Service)
* Services that are provide an SSL Certificate
*/
class SSL extends ServiceType
{
use NextKey;
const RECORD_ID = 'service__ssl';
protected $table = 'service_ssl';
protected $table = 'ab_service__ssl';
protected $crt_parse = NULL;
protected $public_key = NULL;
protected $crt_parse = NULL;
/* STATIC */
public static function boot()
{
@@ -33,11 +34,27 @@ class SSL extends ServiceType implements ServiceItem
});
}
public function getValidToAttribute()
/* ABSTRACT */
/**
* Search for a record
*
* @param $query
* @param string $term
* @return mixed
*/
public function scopeSearch($query,string $term)
{
return $this->cert ? Carbon::createFromTimestamp($this->crt_parse->get('validTo_time_t')) : NULL;
// @todo
}
/* INTERFACES */
/**
* Return the Cert DN
*
* @return string
*/
public function getServiceDescriptionAttribute(): string
{
if ($this->cert)
@@ -58,11 +75,19 @@ class SSL extends ServiceType implements ServiceItem
}
}
public function getServiceExpireAttribute(): Carbon
/**
* Return the Certificate Expiry Date
*/
public function getServiceExpireAttribute(): ?Carbon
{
// TODO: Implement getServiceExpireAttribute() method.
return $this->cert ? Carbon::createFromTimestamp($this->crt_parse->get('validTo_time_t')) : NULL;
}
/**
* Return the Cert Name
*
* @return string
*/
public function getServiceNameAttribute(): string
{
return $this->cert
@@ -70,9 +95,24 @@ class SSL extends ServiceType implements ServiceItem
: Arr::get(openssl_csr_get_subject($this->csr),'CN','');
}
/**
* Certificates have no contract and can be cancelled anytime.
*
* @return bool
*/
public function inContract(): bool
{
// N/A
return FALSE;
}
/* METHODS */
/**
* @return Carbon|null
* @deprecated use getServiceExpireAttribute()
*/
public function getValidToAttribute()
{
abort(500,'use getServiceExpireAttribute');
}
}

View File

@@ -1,72 +0,0 @@
<?php
namespace App\Models\Service;
use App\Interfaces\ServiceItem;
use App\Models\Base\ServiceType;
use App\Traits\NextKey;
use Carbon\Carbon;
class Voip extends ServiceType implements ServiceItem
{
use NextKey;
const RECORD_ID = 'service__adsl';
protected $dates = [
'service_connect_date',
'service_contract_date',
];
public $dateFormat = 'U';
protected $table = 'ab_service__voip';
/* 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.'%');
}
/* ATTRIBUTES */
/**
* Return the service address
*
* @return string
*/
public function getServiceDescriptionAttribute(): string
{
return $this->service_address ?: 'VOIP';
}
public function getServiceExpireAttribute(): Carbon
{
// TODO: Implement getServiceExpireAttribute() method.
}
/**
* Return the service number
*
* @return string
*/
public function getServiceNameAttribute(): string
{
return $this->service_number ?: ($this->service_address ?: 'Unknown');
}
/* METHODS */
public function inContract(): bool
{
return $this->service_contract_date AND $this->service_contract_date->addMonths($this->contract_term)->isFuture();
}
}