diff --git a/app/Models/Product.php b/app/Models/Product.php index c971069..4af1008 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -54,6 +54,7 @@ use App\Traits\ProviderRef; * * + setup_cost : Charge by supplier to setup this product * + * + supplied : Suppliers product supplied * + supplier : Supplier for this offering * * Attributes for product types (type - Product/*) @@ -110,6 +111,9 @@ class Product extends Model 'setup_cost' => $this->supplied->setup_cost ?: 0, + 'supplied' => $this->type->supplied, + 'supplier' => $this->supplied->supplier, + default => parent::__get($key), }; } @@ -189,28 +193,6 @@ class Product extends Model return $this->morphTo(null,'model','model_id'); } - /* ATTRIBUTES */ - - /** - * Suppliers product - * - * @return Model - */ - public function getSuppliedAttribute(): Model - { - return $this->type->supplied; - } - - /** - * Suppliers of this product - * - * @return Model|null - */ - public function getSupplierAttribute(): ?Model - { - return $this->supplied->supplier; - } - /* METHODS */ /** diff --git a/app/Models/Product/Broadband.php b/app/Models/Product/Broadband.php index 1d1e416..b25b187 100644 --- a/app/Models/Product/Broadband.php +++ b/app/Models/Product/Broadband.php @@ -5,12 +5,11 @@ namespace App\Models\Product; use Illuminate\Support\Collection; use Leenooks\Traits\ScopeActive; -use App\Interfaces\ProductItem; use App\Models\Invoice; use App\Models\Service\Broadband as ServiceBroadband; use App\Models\Supplier\Broadband as SupplierBroadband; -final class Broadband extends Type implements ProductItem +final class Broadband extends Type { use ScopeActive; diff --git a/app/Models/Product/Domain.php b/app/Models/Product/Domain.php index 4efa2b1..1361e49 100644 --- a/app/Models/Product/Domain.php +++ b/app/Models/Product/Domain.php @@ -4,12 +4,11 @@ namespace App\Models\Product; use Illuminate\Support\Collection; -use App\Interfaces\ProductItem; use App\Models\Invoice; use App\Models\Service\Domain as ServiceDomain; use App\Models\Supplier\Domain as SupplierDomain; -final class Domain extends Type implements ProductItem +final class Domain extends Type { protected $table = 'product_domain'; diff --git a/app/Models/Product/Email.php b/app/Models/Product/Email.php index 8725f71..be7c8ad 100644 --- a/app/Models/Product/Email.php +++ b/app/Models/Product/Email.php @@ -4,12 +4,11 @@ namespace App\Models\Product; use Illuminate\Support\Collection; -use App\Interfaces\ProductItem; use App\Models\Invoice; use App\Models\Service\Email as ServiceEmail; use App\Models\Supplier\Email as SupplierEmail; -final class Email extends Type implements ProductItem +final class Email extends Type { protected $table = 'product_email'; diff --git a/app/Models/Product/Generic.php b/app/Models/Product/Generic.php index 40bc912..5db8a39 100644 --- a/app/Models/Product/Generic.php +++ b/app/Models/Product/Generic.php @@ -4,12 +4,11 @@ namespace App\Models\Product; use Illuminate\Support\Collection; -use App\Interfaces\ProductItem; use App\Models\Invoice; use App\Models\Service\Generic as ServiceGeneric; use App\Models\Supplier\Generic as SupplierGeneric; -final class Generic extends Type implements ProductItem +final class Generic extends Type { protected $table = 'product_generic'; diff --git a/app/Models/Product/Host.php b/app/Models/Product/Host.php index 87bb873..c5dad53 100644 --- a/app/Models/Product/Host.php +++ b/app/Models/Product/Host.php @@ -4,12 +4,11 @@ namespace App\Models\Product; use Illuminate\Support\Collection; -use App\Interfaces\ProductItem; use App\Models\Invoice; use App\Models\Service\Host as ServiceHost; use App\Models\Supplier\Host as SupplierHost; -final class Host extends Type implements ProductItem +final class Host extends Type { protected $table = 'product_host'; diff --git a/app/Models/Product/Phone.php b/app/Models/Product/Phone.php index f4a57dd..8112fc2 100644 --- a/app/Models/Product/Phone.php +++ b/app/Models/Product/Phone.php @@ -4,12 +4,11 @@ namespace App\Models\Product; use Illuminate\Support\Collection; -use App\Interfaces\ProductItem; use App\Models\Invoice; use App\Models\Service\Phone as ServicePhone; use App\Models\Supplier\Phone as SupplierPhone; -final class Phone extends Type implements ProductItem +final class Phone extends Type { protected $table = 'product_phone'; diff --git a/app/Models/Product/SSL.php b/app/Models/Product/SSL.php index 773357f..97baef7 100644 --- a/app/Models/Product/SSL.php +++ b/app/Models/Product/SSL.php @@ -4,12 +4,11 @@ namespace App\Models\Product; use Illuminate\Support\Collection; -use App\Interfaces\ProductItem; use App\Models\Invoice; use App\Models\Service\SSL as ServiceSSL; use App\Models\Supplier\SSL as SupplierSSL; -final class SSL extends Type implements ProductItem +final class SSL extends Type { protected $table = 'product_ssl'; diff --git a/app/Models/Product/Type.php b/app/Models/Product/Type.php index e390164..06fcdee 100644 --- a/app/Models/Product/Type.php +++ b/app/Models/Product/Type.php @@ -3,15 +3,31 @@ namespace App\Models\Product; use Illuminate\Database\Eloquent\Model; -use Illuminate\Support\Arr; +use App\Interfaces\ProductItem; use App\Models\Product; -use App\Traits\{OrderServiceOptions,ProductDetails,SiteID}; +use App\Traits\{OrderServiceOptions,SiteID}; -abstract class Type extends Model +/** + * Class Supplier\Type + * + * Attributes for supplier types: + * + billing_interval : The Billing interval that the supplier normally uses for this offering + */ + +abstract class Type extends Model implements ProductItem { use SiteID,OrderServiceOptions; + public function __get($key): mixed + { + return match ($key) { + 'billing_interval' => static::DefaultBill, + + default => parent::__get($key), + }; + } + /* RELATIONS */ /** @@ -36,24 +52,15 @@ abstract class Type extends Model /* ATTRIBUTES */ - /** - * The Billing interval that the supplier normally uses for this offering - * - * @return int - */ - public function getBillingIntervalAttribute(): int - { - return static::DefaultBill; - } - /** * The product contract term is the highest of our defined contract_term (in Products/*) vs the suppliers * contract term (defined in Supplier/*). * + * @param int $val * @return int */ - public function getContractTermAttribute(): int + public function getContractTermAttribute(int $val): int { - return max(Arr::get($this->attributes,'contract_term',0),$this->supplied->contract_term); + return max($val,$this->supplied->contract_term); } } \ No newline at end of file diff --git a/app/Models/Supplier/Domain.php b/app/Models/Supplier/Domain.php index 36c70b4..d2796f9 100644 --- a/app/Models/Supplier/Domain.php +++ b/app/Models/Supplier/Domain.php @@ -16,11 +16,13 @@ final class Domain extends Type // The model of the product that is supplied by this model const ProductModel = ProductDomain::class; - /* INTERFACES */ - - public function getNameAttribute(): string + public function __get($key): mixed { - return sprintf('%s: %s',$this->product_id,$this->tld->name); + return match ($key) { + 'name' => sprintf('%s: %s',$this->product_id,$this->tld->name), + + default => parent::__get($key), + }; } /* STATIC */ diff --git a/app/Models/Supplier/Type.php b/app/Models/Supplier/Type.php index 203651c..53f8957 100644 --- a/app/Models/Supplier/Type.php +++ b/app/Models/Supplier/Type.php @@ -3,11 +3,10 @@ namespace App\Models\Supplier; use Illuminate\Database\Eloquent\Model; -use Illuminate\Support\Arr; use Illuminate\Validation\Rule; use Leenooks\Traits\ScopeActive; -use App\Models\{Invoice, Supplier, SupplierDetail}; +use App\Models\{Supplier,SupplierDetail}; use App\Traits\SiteID; /** @@ -31,6 +30,12 @@ abstract class Type extends Model 'category_lc' => strtolower($this->category), 'category_name' => static::category_name ?: $this->category, + 'min_cost' => $this->setup_cost+$this->base_cost*$this->contract_term, + 'name' => $this->product_id ?: 'Supplier PID Unknown', + 'name_long' => $this->product_desc ?: 'Supplier NAME Unknown', + + 'supplier' => $this->supplier_detail->supplier, + default => parent::__get($key), }; } @@ -59,31 +64,11 @@ abstract class Type extends Model return $val ?: 1; } - public function getMinCostAttribute(): float - { - return $this->setup_cost+$this->base_cost*$this->contract_term; - } - - public function getNameAttribute(): string - { - return $this->product_id ?: 'Supplier PID Unknown'; - } - - public function getNameLongAttribute(): string - { - return $this->product_desc ?: 'Supplier NAME Unknown'; - } - public function getSetupCostAttribute(?float $val): float { return $val ?: 0; } - public function getSupplierAttribute(): Model - { - return $this->supplier_detail->supplier; - } - public function validation(): array { return [