Move some service::class methods into __get(), no functional changes
This commit is contained in:
parent
98d18c00a3
commit
2b06eca080
@ -257,7 +257,7 @@ class Account extends Model implements IDs
|
||||
{
|
||||
$svs = $this
|
||||
->services_active
|
||||
->filter(fn($item)=>$item->isBilled() && $item->invoice_next)
|
||||
->filter(fn($item)=>$item->is_billed && $item->invoice_next)
|
||||
->sortBy(fn($item)=>(string)$item->invoice_next);
|
||||
|
||||
// Collect all the invoice items for our active services
|
||||
@ -280,7 +280,7 @@ class Account extends Model implements IDs
|
||||
->flatten();
|
||||
|
||||
// Add any account charges (charges with no active service)
|
||||
foreach ($this->charges->filter(function($item) { return $item->unprocessed && ((! $this->service_id) || (! $item->service->isBilled())); }) as $oo) {
|
||||
foreach ($this->charges->filter(function($item) { return $item->unprocessed && ((! $this->service_id) || (! $item->service->is_billed)); }) as $oo) {
|
||||
$ii = new InvoiceItem;
|
||||
|
||||
$ii->active = TRUE;
|
||||
|
@ -29,6 +29,11 @@ use App\Traits\{ScopeAccountUserAuthorised,ScopeServiceActive,SiteID};
|
||||
* - Type, what service we are providing, made up of a product we supply - in the DB these are service/*
|
||||
*
|
||||
* Attributes for services:
|
||||
* + is_billed : Does this service generate an invoice
|
||||
* + is_charge_overridden : Has the price been overridden
|
||||
* + is_cost_overridden : Has the cost been overridden
|
||||
*
|
||||
* Attributes for services (OLD):
|
||||
* + additional_cost : Pending additional charges for this service (excluding setup) //@todo check all these are still valid
|
||||
* + billing_charge : Charge for this service each invoice period
|
||||
* + billing_interval : The period that this service is billed for by default
|
||||
@ -44,8 +49,6 @@ use App\Traits\{ScopeAccountUserAuthorised,ScopeServiceActive,SiteID};
|
||||
* + supplied : The model of the supplier's product used for this service.
|
||||
*
|
||||
* Methods:
|
||||
* + isChargeOverridden : Has the price been overridden?
|
||||
* + isCostOverridden : Has the cost been overridden?
|
||||
* + isPending : Is this a pending active service
|
||||
*
|
||||
* @package App\Models
|
||||
@ -268,6 +271,16 @@ class Service extends Model implements IDs
|
||||
],
|
||||
];
|
||||
|
||||
public function __get($key): mixed
|
||||
{
|
||||
return match ($key) {
|
||||
'is_billed' => (! ($this->external_billing || $this->suspend_billing || ($this->price === 0))),
|
||||
'is_charge_overridden' => (! is_null($this->price)),
|
||||
'is_cost_overridden' => (! is_null($this->cost)),
|
||||
default => parent::__get($key),
|
||||
};
|
||||
}
|
||||
|
||||
/* STATIC */
|
||||
|
||||
/**
|
||||
@ -295,7 +308,7 @@ class Service extends Model implements IDs
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLIDattribute(): string
|
||||
public function getLIDAttribute(): string
|
||||
{
|
||||
return sprintf('%05s',$this->id);
|
||||
}
|
||||
@ -464,37 +477,6 @@ class Service extends Model implements IDs
|
||||
|
||||
/* SCOPES */
|
||||
|
||||
/**
|
||||
* Only query active categories
|
||||
* @deprecated use ScopeServiceActive
|
||||
*/
|
||||
public function scopeActive($query)
|
||||
{
|
||||
throw new \Exception('deprecated');
|
||||
return $query->where(
|
||||
fn($query)=>
|
||||
$query->where($this->getTable().'.active',TRUE)
|
||||
->orWhereNotIn('order_status',self::INACTIVE_STATUS)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find inactive services.
|
||||
*
|
||||
* @param $query
|
||||
* @return mixed
|
||||
* @deprecated use ScopeServiceInactive
|
||||
*/
|
||||
public function scopeInactive($query)
|
||||
{
|
||||
dd('deprecated');
|
||||
return $query->where(
|
||||
fn($query)=>
|
||||
$query->where($this->getTable().'.active',FALSE)
|
||||
->orWhereIn('order_status',self::INACTIVE_STATUS)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a record
|
||||
*
|
||||
@ -1107,31 +1089,6 @@ class Service extends Model implements IDs
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do we bill for this service
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isBilled(): bool
|
||||
{
|
||||
return ! ($this->external_billing || $this->suspend_billing || ($this->price === 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Has the price for this service been overridden
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isChargeOverridden(): bool
|
||||
{
|
||||
return ! is_null($this->price);
|
||||
}
|
||||
|
||||
public function isCostOverridden(): bool
|
||||
{
|
||||
return ! is_null($this->cost);
|
||||
}
|
||||
|
||||
public function isContract(): bool
|
||||
{
|
||||
return $this->getContractEndAttribute() && $this->getContractEndAttribute()->greaterThan(Carbon::now());
|
||||
@ -1163,7 +1120,7 @@ class Service extends Model implements IDs
|
||||
*/
|
||||
public function next_invoice_items(Carbon $billdate=NULL): Collection
|
||||
{
|
||||
if ($this->wasCancelled() || (! $this->isBilled()))
|
||||
if ($this->wasCancelled() || (! $this->is_billed))
|
||||
return collect();
|
||||
|
||||
$o = collect();
|
||||
|
@ -45,7 +45,7 @@
|
||||
<td>{{ $oo->service_expire ? $oo->service_expire->format('Y-m-d') : '-' }}</td>
|
||||
<td>{{ $oo->registrar->name }}</td>
|
||||
<td>{{ $oo->registrar_ns }}</td>
|
||||
<td>@if ($oo->service->isBilled()) {{ $oo->service->invoice_next->format('Y-m-d') }}@else - @endif</td>
|
||||
<td>@if ($oo->service->is_billed) {{ $oo->service->invoice_next->format('Y-m-d') }}@else - @endif</td>
|
||||
<td>@if (! $oo->service->external_billing)${{ number_format($oo->service->next_invoice_items()->sum('total'),2) }}@else - @endif</td>
|
||||
<td>{{ $oo->service->billing_interval_string }}</td>
|
||||
</tr>
|
||||
|
@ -49,7 +49,7 @@
|
||||
<td>{{ $oo->admin_url }}</td>
|
||||
<td>@if($oo->admin_user){{ $oo->admin_user }}/{{ $oo->admin_pass }}@else @endif</td>
|
||||
<td class="text-right">{{ number_format($oo->accounts ?: 0) }}</td>
|
||||
<td>@if ($oo->service->isBilled()) {{ $oo->service->invoice_next->format('Y-m-d') }} @else - @endif</td>
|
||||
<td>@if ($oo->service->is_billed) {{ $oo->service->invoice_next->format('Y-m-d') }} @else - @endif</td>
|
||||
<td>@if (! $oo->service->external_billing)${{ number_format($oo->service->next_invoice_items()->sum('total'),2) }}@else - @endif</td>
|
||||
<td>{{ $oo->service->billing_interval_string }}</td>
|
||||
</tr>
|
||||
|
@ -43,7 +43,7 @@
|
||||
<td>{{ $oo->service->name }}</td>
|
||||
<td>{{ $oo->service_expire ? $oo->service_expire->format('Y-m-d') : '-' }}</td>
|
||||
<td>{{ $oo->service->product->supplier->name }}</td>
|
||||
<td>@if ($oo->service->isBilled()) {{ $oo->service->invoice_next->format('Y-m-d') }}@else - @endif</td>
|
||||
<td>@if ($oo->service->is_billed) {{ $oo->service->invoice_next->format('Y-m-d') }}@else - @endif</td>
|
||||
<td>@if (! $oo->service->external_billing)${{ number_format($oo->service->next_invoice_items()->sum('total'),2) }}@else - @endif</td>
|
||||
<td>{{ $oo->service->billing_interval_string }}</td>
|
||||
</tr>
|
||||
|
@ -47,7 +47,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Amount</th>
|
||||
@if($o->isChargeOverridden())
|
||||
@if($o->is_charge_overridden)
|
||||
<td>@if($o->billing_charge < $o->charge_orig)<del>${{ number_format($o->charge_orig,2) }}</del> @endif${{ number_format($o->billing_charge,2) }}</td>
|
||||
@else
|
||||
<td>${{ number_format($o->billing_charge,2) }}</td>
|
||||
|
@ -67,11 +67,11 @@
|
||||
|
||||
<tr>
|
||||
<th>Billing Price</th>
|
||||
<td @if($o->isChargeOverridden())class="text-danger"@endif>${{ number_format($b=$o->billing_charge,2) }}</td>
|
||||
<td @if($o->isCostOverridden())class="text-danger"@endif>${{ number_format($a=$o->billing_cost,2) }}</td>
|
||||
<td @class(['text-danger'=>$o->is_charge_overridden])>${{ number_format($b=$o->billing_charge,2) }}</td>
|
||||
<td @class(['text-danger'=>$o->is_cost_overridden])>${{ number_format($a=$o->billing_cost,2) }}</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@if($p->exists)
|
||||
<td @if($o->isChargeOverridden())class="text-danger"@endif>${{ number_format($b=$o->account->taxed($p->base_charge),2) }}</td>
|
||||
<td @if($o->is_charge_overridden)class="text-danger"@endif>${{ number_format($b=$o->account->taxed($p->base_charge),2) }}</td>
|
||||
<td>${{ number_format($a=$o->account->taxed($p->base_cost),2) }}</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@endif
|
||||
@ -79,15 +79,15 @@
|
||||
|
||||
<tr>
|
||||
<th>Monthly Price</th>
|
||||
<td @if($x=$o->isChargeOverridden()) class="text-danger" @endif>
|
||||
@if($x)
|
||||
<td @class(['text-danger'=>$o->is_charge_overridden])>
|
||||
@if($o->is_charge_overridden)
|
||||
<abbr title="${{ number_format($b=$o->account->taxed($c->base_charge)*Invoice::billing_change($o->billing_interval,Invoice::BILL_MONTHLY),2) }}">${{ number_format($b=$o->billing_charge_normalised,2) }}
|
||||
@else
|
||||
${{ number_format($b=$o->billing_charge_normalised,2) }}
|
||||
@endif
|
||||
</td>
|
||||
<td @if($x=$o->isCostOverridden()) class="text-danger" @endif>
|
||||
@if($x)
|
||||
<td @class(['text-danger'=>$o->is_cost_overridden])>
|
||||
@if($o->is_cost_overridden)
|
||||
<abbr title="${{ number_format($a=$o->account->taxed($c->base_cost)*Invoice::billing_change($o->billing_interval,Invoice::BILL_MONTHLY),2) }}">${{ number_format($b=$o->billing_cost_normalised,2) }}
|
||||
@else
|
||||
${{ number_format($a=$o->billing_cost_normalised,2) }}
|
||||
@ -95,7 +95,7 @@
|
||||
</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@if($p->exists)
|
||||
<td @if($x=$o->isChargeOverridden()) class="text-danger" @endif>${{ number_format($b=$o->account->taxed($p->base_charge)*Invoice::billing_change($o->billing_interval,Invoice::BILL_MONTHLY),2) }}</td>
|
||||
<td @if($o->is_charge_overridden) class="text-danger" @endif>${{ number_format($b=$o->account->taxed($p->base_charge)*Invoice::billing_change($o->billing_interval,Invoice::BILL_MONTHLY),2) }}</td>
|
||||
<td>${{ number_format($a=$o->account->taxed($p->base_cost)*Invoice::billing_change($o->billing_interval,Invoice::BILL_MONTHLY),2) }}</td>
|
||||
<td>{!! markup($a,$b) !!}</td>
|
||||
@endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user