Move some service\type::class methods into __get(), no functional changes
This commit is contained in:
parent
1e496a2863
commit
72b11172c8
@ -6,13 +6,6 @@ use Carbon\Carbon;
|
|||||||
|
|
||||||
interface ServiceItem
|
interface ServiceItem
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Months the service is contracted for.
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getContractTermAttribute(): int;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the Service Description.
|
* Return the Service Description.
|
||||||
*
|
*
|
||||||
@ -20,29 +13,10 @@ interface ServiceItem
|
|||||||
*/
|
*/
|
||||||
public function getServiceDescriptionAttribute(): string;
|
public function getServiceDescriptionAttribute(): string;
|
||||||
|
|
||||||
/**
|
|
||||||
* Date the service expires
|
|
||||||
*/
|
|
||||||
public function getServiceExpireAttribute(): ?Carbon;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the Service Name.
|
* Return the Service Name.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getServiceNameAttribute(): string;
|
public function getServiceNameAttribute(): string;
|
||||||
|
|
||||||
/**
|
|
||||||
* Has this service expired
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function hasExpired(): bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is this service in a contract
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function inContract(): bool;
|
|
||||||
}
|
}
|
@ -44,6 +44,8 @@ class Broadband extends Type implements ServiceUsage
|
|||||||
return $this->service_number ?: ($this->service_address ?: '-');
|
return $this->service_number ?: ($this->service_address ?: '-');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* RELATIONS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The usage information for broadband
|
* The usage information for broadband
|
||||||
*
|
*
|
||||||
|
@ -17,6 +17,15 @@ class SSL extends Type
|
|||||||
protected $public_key = NULL;
|
protected $public_key = NULL;
|
||||||
protected $crt_parse = NULL;
|
protected $crt_parse = NULL;
|
||||||
|
|
||||||
|
public function __get($key): mixed
|
||||||
|
{
|
||||||
|
return match ($key) {
|
||||||
|
'in_contract' => FALSE,
|
||||||
|
|
||||||
|
default => parent::__get($key),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/* STATIC METHODS */
|
/* STATIC METHODS */
|
||||||
|
|
||||||
public static function boot()
|
public static function boot()
|
||||||
@ -82,25 +91,4 @@ class SSL extends Type
|
|||||||
? Arr::get($this->crt_parse,'subject.CN')
|
? Arr::get($this->crt_parse,'subject.CN')
|
||||||
: Arr::get(openssl_csr_get_subject($this->csr),'CN','');
|
: Arr::get(openssl_csr_get_subject($this->csr),'CN','');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Certificates have no contract and can be cancelled anytime.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function inContract(): bool
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* METHODS */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Carbon|null
|
|
||||||
* @deprecated use getServiceExpireAttribute()
|
|
||||||
*/
|
|
||||||
public function getValidToAttribute()
|
|
||||||
{
|
|
||||||
abort(500,'use getServiceExpireAttribute');
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -22,6 +22,17 @@ abstract class Type extends Model implements ServiceItem
|
|||||||
|
|
||||||
public $timestamps = FALSE;
|
public $timestamps = FALSE;
|
||||||
|
|
||||||
|
public function __get($key): mixed
|
||||||
|
{
|
||||||
|
return match ($key) {
|
||||||
|
'contract_term' => $this->service->offering->contract_term,
|
||||||
|
'has_expired' => (! $this->in_contract) && ($this->service->invoice_next && $this->service->invoice_next->isPast()),
|
||||||
|
'in_contract' => $this->expire_at && $this->expire_at->isFuture(),
|
||||||
|
|
||||||
|
default => parent::__get($key),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/* RELATIONS */
|
/* RELATIONS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,11 +61,17 @@ abstract class Type extends Model implements ServiceItem
|
|||||||
->where('site_id',$this->site_id);
|
->where('site_id',$this->site_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* INTERFACE */
|
/* ATTRIBUTES */
|
||||||
|
|
||||||
public function getContractTermAttribute(): int
|
/**
|
||||||
|
* We need to cast some dates to LeenooksCarbon to get access to startOfHalf()/endOfHalf() methods
|
||||||
|
*
|
||||||
|
* @param $value
|
||||||
|
* @return LeenooksCarbon|null
|
||||||
|
*/
|
||||||
|
public function getExpireAtAttribute($value): ?LeenooksCarbon
|
||||||
{
|
{
|
||||||
return $this->service->offering->contract_term;
|
return $value ? LeenooksCarbon::create($value) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getServiceExpireAttribute(): ?LeenooksCarbon
|
public function getServiceExpireAttribute(): ?LeenooksCarbon
|
||||||
@ -62,43 +79,8 @@ abstract class Type extends Model implements ServiceItem
|
|||||||
return $this->expire_at ?: $this->service->invoice_next_at;
|
return $this->expire_at ?: $this->service->invoice_next_at;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasExpired(): bool
|
|
||||||
{
|
|
||||||
return (! $this->inContract())
|
|
||||||
&& ($this->service->invoice_next && $this->service->invoice_next->isPast());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function inContract(): bool
|
|
||||||
{
|
|
||||||
return $this->expire_at
|
|
||||||
&& $this->expire_at->isFuture();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ATTRIBUTES */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We need to cast some dates to LeenooksCarbon to get access to startOfHalf()/endOfHalf() methods
|
|
||||||
*
|
|
||||||
* @param $value
|
|
||||||
* @return LeenooksCarbon
|
|
||||||
*/
|
|
||||||
public function getExpireAtAttribute($value): ?LeenooksCarbon
|
|
||||||
{
|
|
||||||
return $value ? LeenooksCarbon::create($value) : NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* METHODS */
|
/* METHODS */
|
||||||
|
|
||||||
/**
|
|
||||||
* Validation used to accept form input
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function validation(): array
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The supplier's service that we provide
|
* The supplier's service that we provide
|
||||||
*
|
*
|
||||||
@ -119,4 +101,14 @@ abstract class Type extends Model implements ServiceItem
|
|||||||
{
|
{
|
||||||
return collect();
|
return collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validation used to accept form input
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function validation(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($o as $oo)
|
@foreach ($o as $oo)
|
||||||
<tr @if ($oo->hasExpired()) class="table-danger" @endif>
|
<tr @if ($oo->has_expired) class="table-danger" @endif>
|
||||||
<td><a href="{{ url('u/service',[$oo->service_id]) }}">{{ $oo->service->sid }}</td>
|
<td><a href="{{ url('u/service',[$oo->service_id]) }}">{{ $oo->service->sid }}</td>
|
||||||
<td>{{ $oo->service->account->name }}</td>
|
<td>{{ $oo->service->account->name }}</td>
|
||||||
<td>{{ $oo->service->product->name }}</td>
|
<td>{{ $oo->service->product->name }}</td>
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($o as $oo)
|
@foreach ($o as $oo)
|
||||||
<tr @if ($oo->hasExpired()) class="table-danger" @endif>
|
<tr @if ($oo->has_expired) class="table-danger" @endif>
|
||||||
<td><a href="{{ url('u/service',[$oo->service_id]) }}">{{ $oo->service->sid }}</td>
|
<td><a href="{{ url('u/service',[$oo->service_id]) }}">{{ $oo->service->sid }}</td>
|
||||||
<td>{{ $oo->service->account->name }}</td>
|
<td>{{ $oo->service->account->name }}</td>
|
||||||
<td>{{ $oo->service->product->name }}</td>
|
<td>{{ $oo->service->product->name }}</td>
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($o as $oo)
|
@foreach ($o as $oo)
|
||||||
<tr @if ($oo->hasExpired()) class="table-danger" @endif>
|
<tr @if ($oo->has_expired) class="table-danger" @endif>
|
||||||
<td><a href="{{ url('u/service',[$oo->service_id]) }}">{{ $oo->service->sid }}</td>
|
<td><a href="{{ url('u/service',[$oo->service_id]) }}">{{ $oo->service->sid }}</td>
|
||||||
<td>{{ $oo->service->account->name }}</td>
|
<td>{{ $oo->service->account->name }}</td>
|
||||||
<td>{{ $oo->service->product->name }}</td>
|
<td>{{ $oo->service->product->name }}</td>
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
<th>IP6 Address</th>
|
<th>IP6 Address</th>
|
||||||
<td>{{ $o->ip6address ?: '-' }}</td>
|
<td>{{ $o->ip6address ?: '-' }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
@if ($o->inContract())
|
@if ($o->in_contract)
|
||||||
<tr>
|
<tr>
|
||||||
<th>Contract</th>
|
<th>Contract</th>
|
||||||
<td>{{ $o->contract_term }} months</td>
|
<td>{{ $o->contract_term }} months</td>
|
||||||
@ -74,7 +74,7 @@
|
|||||||
@endif
|
@endif
|
||||||
<tr>
|
<tr>
|
||||||
<th>Cancel Notice</th>
|
<th>Cancel Notice</th>
|
||||||
<td>1 month @if($o->inContract())<small>(after {{ $o->service_expire->subMonth()->format('Y-m-d') }})</small>@endif</td>
|
<td>1 month @if($o->in_contract)<small>(after {{ $o->service_expire->subMonth()->format('Y-m-d') }})</small>@endif</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@if(($x=$o->service->changes()->where('service__change.active',TRUE)->where('complete',FALSE)->get()->pop()))
|
@if(($x=$o->service->changes()->where('service__change.active',TRUE)->where('complete',FALSE)->get()->pop()))
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
<td>{{ $o->service_connect_date->format('Y-m-d') }}</td>
|
<td>{{ $o->service_connect_date->format('Y-m-d') }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endif
|
@endif
|
||||||
@if ($o->inContract())
|
@if ($o->in_contract)
|
||||||
<tr>
|
<tr>
|
||||||
<th>Contract Term</th>
|
<th>Contract Term</th>
|
||||||
<td>{{ $o->service->contract_term }} months</td>
|
<td>{{ $o->service->contract_term }} months</td>
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
<td>{{ $o->service_connect_date->format('Y-m-d') }}</td>
|
<td>{{ $o->service_connect_date->format('Y-m-d') }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endif
|
@endif
|
||||||
@if ($o->inContract())
|
@if ($o->in_contract)
|
||||||
<tr>
|
<tr>
|
||||||
<th>Contract Term</th>
|
<th>Contract Term</th>
|
||||||
<td>{{ $o->service->contract_term }} months</td>
|
<td>{{ $o->service->contract_term }} months</td>
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
<td>{{ $o->service->product->type->allowance_string() }} Included Calls</td>
|
<td>{{ $o->service->product->type->allowance_string() }} Included Calls</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endif
|
@endif
|
||||||
@if ($o->inContract())
|
@if ($o->in_contract)
|
||||||
<tr>
|
<tr>
|
||||||
<th>Contract</th>
|
<th>Contract</th>
|
||||||
<td>{{ $o->contract_term }} months</td>
|
<td>{{ $o->contract_term }} months</td>
|
||||||
@ -58,7 +58,7 @@
|
|||||||
@endif
|
@endif
|
||||||
<tr>
|
<tr>
|
||||||
<th>Cancel Notice</th>
|
<th>Cancel Notice</th>
|
||||||
<td>1 month @if($o->inContract())<small>(after {{ $o->service_expire->subMonth()->format('Y-m-d') }})</small>@endif</td>
|
<td>1 month @if($o->in_contract)<small>(after {{ $o->service_expire->subMonth()->format('Y-m-d') }})</small>@endif</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user