From 5ef1a27a647c4a2550b6b2a744b17f6ad1f57915 Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 22 May 2025 12:01:31 +1000 Subject: [PATCH] Move category/category_name product::class methods into __get(), no functional changes --- app/Console/Commands/ServiceList.php | 4 +- app/Http/Controllers/ServiceController.php | 14 +++---- app/Jobs/ImportCosts.php | 2 +- app/Mail/OrderRequestApprove.php | 8 ++-- app/Models/Product.php | 27 ++---------- app/Models/Supplier.php | 8 ++-- app/Models/Supplier/Type.php | 41 +++++++++---------- .../views/mail/admin/order/approve.blade.php | 2 +- .../views/mail/admin/order/reject.blade.php | 2 +- .../views/mail/admin/service/cancel.blade.php | 2 +- .../views/mail/admin/service/change.blade.php | 2 +- .../adminlte/service/change_pending.blade.php | 2 +- .../adminlte/service/change_request.blade.php | 2 +- .../backend/adminlte/service/home.blade.php | 4 +- .../service/order/provision_plan.blade.php | 2 +- .../adminlte/service/order/sent.blade.php | 2 +- .../service/widget/internal.blade.php | 4 +- .../adminlte/service/widget/update.blade.php | 4 +- .../supplier/product/addedit.blade.php | 4 +- .../supplier/widget/offerings.blade.php | 2 +- .../supplier/widget/products.blade.php | 2 +- .../metronic/order/widget/info.blade.php | 4 +- .../metronic/order/widget/order.blade.php | 4 +- 23 files changed, 63 insertions(+), 85 deletions(-) diff --git a/app/Console/Commands/ServiceList.php b/app/Console/Commands/ServiceList.php index 939e8c2..1ed9693 100644 --- a/app/Console/Commands/ServiceList.php +++ b/app/Console/Commands/ServiceList.php @@ -52,7 +52,7 @@ class ServiceList extends Command if ((! $this->option('inactive')) && (! $o->is_active)) continue; - if ($this->option('type') && ($o->product->getCategoryAttribute() !== $this->option('type'))) + if ($this->option('type') && ($o->product->category_lc !== strtolower($this->option('type')))) continue; $c = $o->invoiced_items @@ -67,7 +67,7 @@ class ServiceList extends Command $this->info(sprintf($header, $o->lid, - $o->product->getCategoryNameAttribute(), + $o->product->category_name, substr($o->product->getNameAttribute(),0,35), substr($o->name_short,0,40), $o->active ? 'active' : 'inactive', diff --git a/app/Http/Controllers/ServiceController.php b/app/Http/Controllers/ServiceController.php index 5b5a31c..77d9236 100644 --- a/app/Http/Controllers/ServiceController.php +++ b/app/Http/Controllers/ServiceController.php @@ -401,10 +401,10 @@ class ServiceController extends Controller $request->post(), collect($o->type->validation()) ->keys() - ->map(fn($item)=>sprintf('%s.%s',$o->product->category,$item)) + ->map(fn($item)=>sprintf('%s.%s',$o->product->category_lc,$item)) ->combine(array_values($o->type->validation())) ->map(fn($item)=>is_string($item) - ? preg_replace('/^exclude_without:/',sprintf('exclude_without:%s.',$o->product->category),$item) + ? preg_replace('/^exclude_without:/',sprintf('exclude_without:%s.',$o->product->category_lc),$item) : $item) ->merge( [ @@ -416,7 +416,7 @@ class ServiceController extends Controller 'price' => 'nullable|numeric|min:0', // Price we charge the client, if we dont charge supplied/price 'cost' => 'nullable|numeric|min:0', // Price we are charged by supplier, if we arent charged supplier/price 'supplierid' => 'nullable|string|min:1', // As used on invoices - $o->product->category => 'array|min:1', + $o->product->category_lc => 'array|min:1', ] ) ->toArray() @@ -432,13 +432,13 @@ class ServiceController extends Controller $validated = collect($validator->validated()); // Store our service type values - $o->type->forceFill($validated->get($o->product->category)); + $o->type->forceFill($validated->get($o->product->category_lc)); // Some special handling - switch ($o->product->category) { + switch ($o->product->category_lc) { case 'broadband': // If pppoe is not set, then we dont need username/password - $o->type->pppoe = ($x=data_get($validated,$o->product->category.'.pppoe',FALSE)); + $o->type->pppoe = ($x=data_get($validated,$o->product->category_lc.'.pppoe',FALSE)); if (! $x) { $o->type->service_username = NULL; @@ -470,7 +470,7 @@ class ServiceController extends Controller else { // For broadband, start_at is connect_at in the type record - switch ($o->product->category) { + switch ($o->product->category_lc) { case 'broadband': $o->start_at = $o->type->connect_at; break; diff --git a/app/Jobs/ImportCosts.php b/app/Jobs/ImportCosts.php index 755c2cd..7cdde56 100644 --- a/app/Jobs/ImportCosts.php +++ b/app/Jobs/ImportCosts.php @@ -131,7 +131,7 @@ class ImportCosts implements ShouldQueue if ($so) { // r[1] = Monthly Charge or Extra Charge,r[2] = "On Plan", r[3] = Plan Info $r = []; - switch ($so->product->category) { + switch ($so->product->category_lc) { case 'broadband': $to = Cost\Broadband::where('site_id',$this->co->site_id) ->where('cost_id',$this->co->id) diff --git a/app/Mail/OrderRequestApprove.php b/app/Mail/OrderRequestApprove.php index 5b59d52..d8a2eb6 100644 --- a/app/Mail/OrderRequestApprove.php +++ b/app/Mail/OrderRequestApprove.php @@ -31,19 +31,17 @@ class OrderRequestApprove extends Mailable /** * Build the message. - * - * @return $this */ public function build() { Config::set('site',$this->so->site); // @todo This is not consistent with Cancel/Change Request - switch ($this->so->product->category) { - case 'broadband': $subject = sprintf('%s: %s',$this->so->product->category,$this->so->type->service_address); + switch ($this->so->product->category_lc) { + case 'broadband': $subject = sprintf('%s: %s',$this->so->product->category_name,$this->so->type->service_address); break; - case 'phone': $subject = sprintf('%s: %s',$this->so->product->category,$this->so->type->service_number); + case 'phone': $subject = sprintf('%s: %s',$this->so->product->category_name,$this->so->type->service_number); break; default: diff --git a/app/Models/Product.php b/app/Models/Product.php index 438b6a6..c68ac03 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -77,6 +77,10 @@ class Product extends Model implements IDs return match ($key) { 'base_cost' => round($this->supplied->base_cost,2)*Invoice::billing_change($this->type->billing_interval,$this->billing_interval) ?: 0, + 'category' => $this->supplied->category, + 'category_lc' => strtolower($this->category), + 'category_name' => $this->supplied->category_name, + default => parent::__get($key), }; } @@ -181,29 +185,6 @@ class Product extends Model implements IDs return max($this->price_recur_default,$this->type->billing_interval); } - /** - * This will return the category of the product (eg: domain, webhosting, etc) which is the basis for all - * other logic of these types. - * - * @return string - */ - public function getCategoryAttribute(): string - { - return strtolower(Str::studly($this->category_name)); - } - - /** - * Return the type of service is provided. eg: Broadband, Phone. - * This will return the category of the product (eg: domain, hosting, etc) which is the basis for all - * other logic of these types. - * - * @return string - */ - public function getCategoryNameAttribute(): string - { - return $this->supplied->category_name; - } - /** * How long must this product be purchased for as a service. * diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index a2a3a03..22a157c 100644 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -49,8 +49,8 @@ class Supplier extends Model if ($so) { // If we have a connections configuration for that supplier, then build the child relationships - if (Arr::get($so->detail->connections,$class->category)) { - $result->put($class->category,(object)[ + if (Arr::get($so->detail->connections,$class->category_lc)) { + $result->put($class->category_lc,(object)[ 'type' => $class->category_name, 'items' => $class->where('supplier_detail_id',$so->detail->id), ]); @@ -63,13 +63,13 @@ class Supplier extends Model $o->where('supplier_detail_id',$so->detail->id); if ($o->count()) - $result->put($class->category,(object)[ + $result->put($class->category_lc,(object)[ 'type' => $class->category_name, 'items' => $class->where('supplier_detail_id',$so->detail->id), ]); } else { - $result->put($class->category_name,$class); + $result->put($class->category_lc,$class); } } diff --git a/app/Models/Supplier/Type.php b/app/Models/Supplier/Type.php index e4d7d81..2be12c1 100644 --- a/app/Models/Supplier/Type.php +++ b/app/Models/Supplier/Type.php @@ -10,10 +10,30 @@ use Leenooks\Traits\ScopeActive; use App\Models\{Invoice, Supplier, SupplierDetail}; use App\Traits\SiteID; +/** + * Class Supplier\Type + * + * Attributes for supplier types: + * + category : This will return the category of the product (eg: domain, hosting, etc), based on the class, which is the basis for all other logic of these types. + * + category_name : A friendly name that can override category + */ + abstract class Type extends Model { use SiteID,ScopeActive; + protected const category_name = NULL; + + public function __get($key): mixed + { + return match ($key) { + 'category' => (new \ReflectionClass($this))->getShortName(), + 'category_name' => static::category_name ?: $this->category, + + default => parent::__get($key), + }; + } + /* RELATIONS */ /** @@ -33,27 +53,6 @@ abstract class Type extends Model /* ATTRIBUTES */ - /** - * This will return the category of the product (eg: domain, hosting, etc) which is the basis for all - * other logic of these types. - * - * @return string - */ - final public function getCategoryAttribute(): string - { - return strtolower((new \ReflectionClass($this))->getShortName()); - } - - /** - * Return a friendly name for this product, used for display - * - * @return string - */ - final public function getCategoryNameAttribute(): string - { - return static::category_name; - } - final public function getContractTermAttribute(?int $val): int { return $val ?: 1; diff --git a/resources/views/mail/admin/order/approve.blade.php b/resources/views/mail/admin/order/approve.blade.php index bf59857..3eda162 100644 --- a/resources/views/mail/admin/order/approve.blade.php +++ b/resources/views/mail/admin/order/approve.blade.php @@ -8,7 +8,7 @@ Please order the following... | Account | {{ $service->account->name }} | | Service ID | {{ $service->sid }} | | Product | {{ $service->product->name }} | -@switch($service->product->category) +@switch($service->product->category_lc) @case('broadband') | Address | {{ $service->type->service_address }} | @break; diff --git a/resources/views/mail/admin/order/reject.blade.php b/resources/views/mail/admin/order/reject.blade.php index b990e50..dbd3ee1 100644 --- a/resources/views/mail/admin/order/reject.blade.php +++ b/resources/views/mail/admin/order/reject.blade.php @@ -7,7 +7,7 @@ | Account | {{ $service->account->name }} | | Service ID | {{ $service->sid }} | | Product | {{ $service->product->name }} | -@switch($service->product->category) +@switch($service->product->category_lc) @case('broadband') | Address | {{ is_object($service->type) ? $service->type->service_address : 'Not Supplied' }} | @break; diff --git a/resources/views/mail/admin/service/cancel.blade.php b/resources/views/mail/admin/service/cancel.blade.php index a18d6e9..a47e311 100644 --- a/resources/views/mail/admin/service/cancel.blade.php +++ b/resources/views/mail/admin/service/cancel.blade.php @@ -9,7 +9,7 @@ Please cancel the following... | Service ID | {{ $service->sid }} | | Cancel Date | {{ $service->stop_at->format('Y-m-d') }} | | Product | {{ $service->product->name }} | -@switch($service->product->category) +@switch($service->product->category_lc) @case('broadband') | Address | {{ $service->type->service_address }} | @break; diff --git a/resources/views/mail/admin/service/change.blade.php b/resources/views/mail/admin/service/change.blade.php index db3aaeb..88007ad 100644 --- a/resources/views/mail/admin/service/change.blade.php +++ b/resources/views/mail/admin/service/change.blade.php @@ -8,7 +8,7 @@ Please change the following... | Account | {{ $service->account->name }} | | Service ID | {{ $service->sid }} | | Product | {{ $service->product->name }} | -@switch($service->product->category) +@switch($service->product->category_lc) @case('broadband') | Address | {{ $service->type->service_address }} | @break; diff --git a/resources/views/theme/backend/adminlte/service/change_pending.blade.php b/resources/views/theme/backend/adminlte/service/change_pending.blade.php index c700ac8..830671c 100644 --- a/resources/views/theme/backend/adminlte/service/change_pending.blade.php +++ b/resources/views/theme/backend/adminlte/service/change_pending.blade.php @@ -42,7 +42,7 @@ + :options="Product::get()->filter(fn($item)=>$item->category_lc === $np->category_lc)->sortBy('name')->sortByDesc('active')->map(fn($item)=>['id'=>$item->id,'active'=>$item->active,'value'=>$item->name])" required/> diff --git a/resources/views/theme/backend/adminlte/service/change_request.blade.php b/resources/views/theme/backend/adminlte/service/change_request.blade.php index 60e0459..c6217c2 100644 --- a/resources/views/theme/backend/adminlte/service/change_request.blade.php +++ b/resources/views/theme/backend/adminlte/service/change_request.blade.php @@ -41,7 +41,7 @@
- @includeIf('theme.backend.adminlte.service.widget.'.$so->product->category.'.change',['o'=>$so->type]) + @includeIf('theme.backend.adminlte.service.widget.'.$so->product->category_lc.'.change',['o'=>$so->type])
diff --git a/resources/views/theme/backend/adminlte/service/home.blade.php b/resources/views/theme/backend/adminlte/service/home.blade.php index eb6d81f..e1e5c0a 100644 --- a/resources/views/theme/backend/adminlte/service/home.blade.php +++ b/resources/views/theme/backend/adminlte/service/home.blade.php @@ -20,7 +20,7 @@
- @includeIf('theme.backend.adminlte.service.widget.'.$o->product->category.'.details',['o'=>$o->type]) + @includeIf('theme.backend.adminlte.service.widget.'.$o->product->category_lc.'.details',['o'=>$o->type]) @include('theme.backend.adminlte.service.widget.information')
@@ -73,7 +73,7 @@ @if($o->product->hasUsage())
! ($x || (session()->has('service_update') || session()->has('charge_add')))]) id="traffic"> @if($o->type->usage(30)->count()) - @include('theme.backend.adminlte.service.widget.'.$o->product->category.'.usagegraph',['o'=>$o->type]) + @include('theme.backend.adminlte.service.widget.'.$o->product->category_lc.'.usagegraph',['o'=>$o->type]) @endif
@endif diff --git a/resources/views/theme/backend/adminlte/service/order/provision_plan.blade.php b/resources/views/theme/backend/adminlte/service/order/provision_plan.blade.php index 79af6e8..dd82e7a 100644 --- a/resources/views/theme/backend/adminlte/service/order/provision_plan.blade.php +++ b/resources/views/theme/backend/adminlte/service/order/provision_plan.blade.php @@ -38,7 +38,7 @@
- @includeIf('theme.backend.adminlte.service.widget.'.$o->product->category.'.order',['o'=>$o->type]) + @includeIf('theme.backend.adminlte.service.widget.'.$o->product->category_lc.'.order',['o'=>$o->type])
diff --git a/resources/views/theme/backend/adminlte/service/order/sent.blade.php b/resources/views/theme/backend/adminlte/service/order/sent.blade.php index f9cabbd..1da3e5a 100644 --- a/resources/views/theme/backend/adminlte/service/order/sent.blade.php +++ b/resources/views/theme/backend/adminlte/service/order/sent.blade.php @@ -38,7 +38,7 @@
- @includeIf('theme.backend.adminlte.service.widget.'.$o->product->category.'.order',['o'=>$o->type]) + @includeIf('theme.backend.adminlte.service.widget.'.$o->product->category_lc.'.order',['o'=>$o->type])
diff --git a/resources/views/theme/backend/adminlte/service/widget/internal.blade.php b/resources/views/theme/backend/adminlte/service/widget/internal.blade.php index c93acb1..c4dc853 100644 --- a/resources/views/theme/backend/adminlte/service/widget/internal.blade.php +++ b/resources/views/theme/backend/adminlte/service/widget/internal.blade.php @@ -34,11 +34,11 @@ Product #{{ $o->product_id }}: {{ $o->product->name }} - #{{ $c->supplied->id }}: {{ $c->supplied->name_long }} + #{{ $c->supplied->id }}: {{ $c->supplied->name_long }} {{ $c->category_name }} @if($p->exists) #{{ $p->id }}: {{ $p->name }} - #{{ $p->supplied->id }}: {{ $p->supplied->name_long }} + #{{ $p->supplied->id }}: {{ $p->supplied->name_long }}   @endif diff --git a/resources/views/theme/backend/adminlte/service/widget/update.blade.php b/resources/views/theme/backend/adminlte/service/widget/update.blade.php index 425da21..e2420b8 100644 --- a/resources/views/theme/backend/adminlte/service/widget/update.blade.php +++ b/resources/views/theme/backend/adminlte/service/widget/update.blade.php @@ -51,7 +51,7 @@ :value="$o->product_id" :options="Product::with(['type.supplied','translate']) ->get() - ->filter(fn($item)=>($item->category === $o->product->category)) + ->filter(fn($item)=>($item->category_lc === $o->product->category_lc)) ->sortBy('name') ->map(fn($item)=>[ 'id'=>$item->id, @@ -65,7 +65,7 @@

- @includeIf('theme.backend.adminlte.service.widget.'.$o->product->category.'.update',['o'=>$o->type]) + @includeIf('theme.backend.adminlte.service.widget.'.$o->product->category_lc.'.update',['o'=>$o->type])
diff --git a/resources/views/theme/backend/adminlte/supplier/product/addedit.blade.php b/resources/views/theme/backend/adminlte/supplier/product/addedit.blade.php index 98ebc1b..795d1dd 100644 --- a/resources/views/theme/backend/adminlte/supplier/product/addedit.blade.php +++ b/resources/views/theme/backend/adminlte/supplier/product/addedit.blade.php @@ -53,7 +53,7 @@ if(isset($spo)) {
- +
@@ -180,7 +180,7 @@ if(isset($spo)) { $(document).ready(function() { @if(isset($oo) && $oo->exists) $('#offering_type').attr('style','pointer-events: none;'); - load_type('{{$oo->category}}',{{$oo->id}}) + load_type('{{$oo->category_lc}}',{{$oo->id}}) @endif $('#offering_type').on('change',function() { diff --git a/resources/views/theme/backend/adminlte/supplier/widget/offerings.blade.php b/resources/views/theme/backend/adminlte/supplier/widget/offerings.blade.php index 4e71e56..410f551 100644 --- a/resources/views/theme/backend/adminlte/supplier/widget/offerings.blade.php +++ b/resources/views/theme/backend/adminlte/supplier/widget/offerings.blade.php @@ -37,7 +37,7 @@ @foreach($xx=$offering->items->with(['products.products.services'])->get() as $oo) - {{ $oo->id }} + {{ $oo->id }} {{ $oo->name }} {{ $oo->name_long }} {{ $oo->active ? 'YES' : 'NO' }} diff --git a/resources/views/theme/backend/adminlte/supplier/widget/products.blade.php b/resources/views/theme/backend/adminlte/supplier/widget/products.blade.php index 55686db..2c6688b 100644 --- a/resources/views/theme/backend/adminlte/supplier/widget/products.blade.php +++ b/resources/views/theme/backend/adminlte/supplier/widget/products.blade.php @@ -40,7 +40,7 @@ @foreach($oo->products->pluck('products')->flatten()->filter() as $po) {{ $po->lid }} - {{ $po->pid }} [{{ $po->supplied->name }}] + {{ $po->pid }} [{{ $po->supplied->name }}] {{ $po->name }} {{ $po->active ? 'YES' : 'NO' }} {{ $po->billing_interval_string }} diff --git a/resources/views/theme/frontend/metronic/order/widget/info.blade.php b/resources/views/theme/frontend/metronic/order/widget/info.blade.php index d75954c..f8bc1e1 100644 --- a/resources/views/theme/frontend/metronic/order/widget/info.blade.php +++ b/resources/views/theme/frontend/metronic/order/widget/info.blade.php @@ -1,9 +1,9 @@ -@if(View::exists('theme.frontend.metronic.order.widget.info.'.$pdo->category)) +@if(View::exists('theme.frontend.metronic.order.widget.info.'.$pdo->category_lc))
{{-- Return Category Requirements --}} - @include('theme.frontend.metronic.order.widget.info.'.$pdo->category) + @include('theme.frontend.metronic.order.widget.info.'.$pdo->category_lc) {{-- Return Supplier Requirements --}} {{-- Return Product Requirements --}} diff --git a/resources/views/theme/frontend/metronic/order/widget/order.blade.php b/resources/views/theme/frontend/metronic/order/widget/order.blade.php index 64d0a7f..b0d7c81 100644 --- a/resources/views/theme/frontend/metronic/order/widget/order.blade.php +++ b/resources/views/theme/frontend/metronic/order/widget/order.blade.php @@ -1,5 +1,5 @@ -@if(View::exists('theme.frontend.metronic.order.widget.order.'.$pdo->category)) +@if(View::exists('theme.frontend.metronic.order.widget.order.'.$pdo->category_lc))

Order Configuration

@@ -7,7 +7,7 @@
{{-- Return Category Requirements --}} - @include('theme.frontend.metronic.order.widget.order.'.$pdo->category) + @include('theme.frontend.metronic.order.widget.order.'.$pdo->category_lc) {{-- Return Supplier Requirements --}} {{-- Return Product Requirements --}}