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
|
$svs = $this
|
||||||
->services_active
|
->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);
|
->sortBy(fn($item)=>(string)$item->invoice_next);
|
||||||
|
|
||||||
// Collect all the invoice items for our active services
|
// Collect all the invoice items for our active services
|
||||||
@ -280,7 +280,7 @@ class Account extends Model implements IDs
|
|||||||
->flatten();
|
->flatten();
|
||||||
|
|
||||||
// Add any account charges (charges with no active service)
|
// 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 = new InvoiceItem;
|
||||||
|
|
||||||
$ii->active = TRUE;
|
$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/*
|
* - Type, what service we are providing, made up of a product we supply - in the DB these are service/*
|
||||||
*
|
*
|
||||||
* Attributes for services:
|
* 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
|
* + 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_charge : Charge for this service each invoice period
|
||||||
* + billing_interval : The period that this service is billed for by default
|
* + 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.
|
* + supplied : The model of the supplier's product used for this service.
|
||||||
*
|
*
|
||||||
* Methods:
|
* Methods:
|
||||||
* + isChargeOverridden : Has the price been overridden?
|
|
||||||
* + isCostOverridden : Has the cost been overridden?
|
|
||||||
* + isPending : Is this a pending active service
|
* + isPending : Is this a pending active service
|
||||||
*
|
*
|
||||||
* @package App\Models
|
* @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 */
|
/* STATIC */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -295,7 +308,7 @@ class Service extends Model implements IDs
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getLIDattribute(): string
|
public function getLIDAttribute(): string
|
||||||
{
|
{
|
||||||
return sprintf('%05s',$this->id);
|
return sprintf('%05s',$this->id);
|
||||||
}
|
}
|
||||||
@ -464,37 +477,6 @@ class Service extends Model implements IDs
|
|||||||
|
|
||||||
/* SCOPES */
|
/* 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
|
* Search for a record
|
||||||
*
|
*
|
||||||
@ -1107,31 +1089,6 @@ class Service extends Model implements IDs
|
|||||||
return FALSE;
|
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
|
public function isContract(): bool
|
||||||
{
|
{
|
||||||
return $this->getContractEndAttribute() && $this->getContractEndAttribute()->greaterThan(Carbon::now());
|
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
|
public function next_invoice_items(Carbon $billdate=NULL): Collection
|
||||||
{
|
{
|
||||||
if ($this->wasCancelled() || (! $this->isBilled()))
|
if ($this->wasCancelled() || (! $this->is_billed))
|
||||||
return collect();
|
return collect();
|
||||||
|
|
||||||
$o = collect();
|
$o = collect();
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
<td>{{ $oo->service_expire ? $oo->service_expire->format('Y-m-d') : '-' }}</td>
|
<td>{{ $oo->service_expire ? $oo->service_expire->format('Y-m-d') : '-' }}</td>
|
||||||
<td>{{ $oo->registrar->name }}</td>
|
<td>{{ $oo->registrar->name }}</td>
|
||||||
<td>{{ $oo->registrar_ns }}</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>@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>
|
<td>{{ $oo->service->billing_interval_string }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
<td>{{ $oo->admin_url }}</td>
|
<td>{{ $oo->admin_url }}</td>
|
||||||
<td>@if($oo->admin_user){{ $oo->admin_user }}/{{ $oo->admin_pass }}@else @endif</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 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>@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>
|
<td>{{ $oo->service->billing_interval_string }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
<td>{{ $oo->service->name }}</td>
|
<td>{{ $oo->service->name }}</td>
|
||||||
<td>{{ $oo->service_expire ? $oo->service_expire->format('Y-m-d') : '-' }}</td>
|
<td>{{ $oo->service_expire ? $oo->service_expire->format('Y-m-d') : '-' }}</td>
|
||||||
<td>{{ $oo->service->product->supplier->name }}</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>@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>
|
<td>{{ $oo->service->billing_interval_string }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Amount</th>
|
<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>
|
<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
|
@else
|
||||||
<td>${{ number_format($o->billing_charge,2) }}</td>
|
<td>${{ number_format($o->billing_charge,2) }}</td>
|
||||||
|
@ -67,11 +67,11 @@
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>Billing Price</th>
|
<th>Billing Price</th>
|
||||||
<td @if($o->isChargeOverridden())class="text-danger"@endif>${{ number_format($b=$o->billing_charge,2) }}</td>
|
<td @class(['text-danger'=>$o->is_charge_overridden])>${{ 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_cost_overridden])>${{ number_format($a=$o->billing_cost,2) }}</td>
|
||||||
<td>{!! markup($a,$b) !!}</td>
|
<td>{!! markup($a,$b) !!}</td>
|
||||||
@if($p->exists)
|
@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>${{ number_format($a=$o->account->taxed($p->base_cost),2) }}</td>
|
||||||
<td>{!! markup($a,$b) !!}</td>
|
<td>{!! markup($a,$b) !!}</td>
|
||||||
@endif
|
@endif
|
||||||
@ -79,15 +79,15 @@
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>Monthly Price</th>
|
<th>Monthly Price</th>
|
||||||
<td @if($x=$o->isChargeOverridden()) class="text-danger" @endif>
|
<td @class(['text-danger'=>$o->is_charge_overridden])>
|
||||||
@if($x)
|
@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) }}
|
<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
|
@else
|
||||||
${{ number_format($b=$o->billing_charge_normalised,2) }}
|
${{ number_format($b=$o->billing_charge_normalised,2) }}
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
<td @if($x=$o->isCostOverridden()) class="text-danger" @endif>
|
<td @class(['text-danger'=>$o->is_cost_overridden])>
|
||||||
@if($x)
|
@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) }}
|
<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
|
@else
|
||||||
${{ number_format($a=$o->billing_cost_normalised,2) }}
|
${{ number_format($a=$o->billing_cost_normalised,2) }}
|
||||||
@ -95,7 +95,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>{!! markup($a,$b) !!}</td>
|
<td>{!! markup($a,$b) !!}</td>
|
||||||
@if($p->exists)
|
@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>${{ 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>
|
<td>{!! markup($a,$b) !!}</td>
|
||||||
@endif
|
@endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user