Optimising product category and category names

This commit is contained in:
Deon George
2022-06-12 11:21:20 +10:00
parent 360c1e46a1
commit cc94426902
36 changed files with 269 additions and 156 deletions

View File

@@ -20,6 +20,7 @@ use Leenooks\Carbon as LeenooksCarbon;
use App\Interfaces\IDs;
use App\Traits\ScopeServiceUserAuthorised;
use App\Traits\SiteID;
/**
* Class Service
@@ -50,7 +51,7 @@ use App\Traits\ScopeServiceUserAuthorised;
*/
class Service extends Model implements IDs
{
use HasFactory,ScopeServiceUserAuthorised;
use HasFactory,ScopeServiceUserAuthorised,SiteID;
protected $casts = [
'order_info'=>AsCollection::class,
@@ -472,25 +473,6 @@ class Service extends Model implements IDs
return number_format($this->getBillingChargeAttribute()/Arr::get(Invoice::billing_periods,$this->recur_schedule.'.interval',1),2);
}
/**
* Return the type of service is provided. eg: Broadband, Phone.
*
* @return string
*/
public function getCategoryAttribute(): string
{
switch ($x=$this->type->getTypeAttribute()) {
case 'ssl':
$type = 'SSL';
break;
default:
$type = ucfirst($x);
}
return $type;
}
/**
* The date the contract ends
*
@@ -707,16 +689,9 @@ class Service extends Model implements IDs
*/
public function getInvoiceToAttribute(): ?LeenooksCarbon
{
$result = ($x=$this->invoice_items->filter(function($item) { return $item->item_type === 0;}))->count()
return ($x=$this->invoice_items->filter(function($item) { return $item->item_type === 0;}))->count()
? $x->last()->stop_at
: NULL;
// For SSL Certificates, the invoice_to date is the expiry date of the Cert
// @todo can we use the expire_at attribute?
if (is_null($result) AND $this->type AND $this->type->type == 'ssl' AND $this->type->expire_at)
return $this->type->expire_at;
return $result;
}
/**