Move some product product\supplier and product\type::class methods into __get(), no functional changes
This commit is contained in:
parent
72b11172c8
commit
251aefa947
@ -54,6 +54,7 @@ use App\Traits\ProviderRef;
|
|||||||
*
|
*
|
||||||
* + setup_cost : Charge by supplier to setup this product
|
* + setup_cost : Charge by supplier to setup this product
|
||||||
*
|
*
|
||||||
|
* + supplied : Suppliers product supplied
|
||||||
* + supplier : Supplier for this offering
|
* + supplier : Supplier for this offering
|
||||||
*
|
*
|
||||||
* Attributes for product types (type - Product/*)
|
* Attributes for product types (type - Product/*)
|
||||||
@ -110,6 +111,9 @@ class Product extends Model
|
|||||||
|
|
||||||
'setup_cost' => $this->supplied->setup_cost ?: 0,
|
'setup_cost' => $this->supplied->setup_cost ?: 0,
|
||||||
|
|
||||||
|
'supplied' => $this->type->supplied,
|
||||||
|
'supplier' => $this->supplied->supplier,
|
||||||
|
|
||||||
default => parent::__get($key),
|
default => parent::__get($key),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -189,28 +193,6 @@ class Product extends Model
|
|||||||
return $this->morphTo(null,'model','model_id');
|
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 */
|
/* METHODS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,12 +5,11 @@ namespace App\Models\Product;
|
|||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Leenooks\Traits\ScopeActive;
|
use Leenooks\Traits\ScopeActive;
|
||||||
|
|
||||||
use App\Interfaces\ProductItem;
|
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Service\Broadband as ServiceBroadband;
|
use App\Models\Service\Broadband as ServiceBroadband;
|
||||||
use App\Models\Supplier\Broadband as SupplierBroadband;
|
use App\Models\Supplier\Broadband as SupplierBroadband;
|
||||||
|
|
||||||
final class Broadband extends Type implements ProductItem
|
final class Broadband extends Type
|
||||||
{
|
{
|
||||||
use ScopeActive;
|
use ScopeActive;
|
||||||
|
|
||||||
|
@ -4,12 +4,11 @@ namespace App\Models\Product;
|
|||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
use App\Interfaces\ProductItem;
|
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Service\Domain as ServiceDomain;
|
use App\Models\Service\Domain as ServiceDomain;
|
||||||
use App\Models\Supplier\Domain as SupplierDomain;
|
use App\Models\Supplier\Domain as SupplierDomain;
|
||||||
|
|
||||||
final class Domain extends Type implements ProductItem
|
final class Domain extends Type
|
||||||
{
|
{
|
||||||
protected $table = 'product_domain';
|
protected $table = 'product_domain';
|
||||||
|
|
||||||
|
@ -4,12 +4,11 @@ namespace App\Models\Product;
|
|||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
use App\Interfaces\ProductItem;
|
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Service\Email as ServiceEmail;
|
use App\Models\Service\Email as ServiceEmail;
|
||||||
use App\Models\Supplier\Email as SupplierEmail;
|
use App\Models\Supplier\Email as SupplierEmail;
|
||||||
|
|
||||||
final class Email extends Type implements ProductItem
|
final class Email extends Type
|
||||||
{
|
{
|
||||||
protected $table = 'product_email';
|
protected $table = 'product_email';
|
||||||
|
|
||||||
|
@ -4,12 +4,11 @@ namespace App\Models\Product;
|
|||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
use App\Interfaces\ProductItem;
|
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Service\Generic as ServiceGeneric;
|
use App\Models\Service\Generic as ServiceGeneric;
|
||||||
use App\Models\Supplier\Generic as SupplierGeneric;
|
use App\Models\Supplier\Generic as SupplierGeneric;
|
||||||
|
|
||||||
final class Generic extends Type implements ProductItem
|
final class Generic extends Type
|
||||||
{
|
{
|
||||||
protected $table = 'product_generic';
|
protected $table = 'product_generic';
|
||||||
|
|
||||||
|
@ -4,12 +4,11 @@ namespace App\Models\Product;
|
|||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
use App\Interfaces\ProductItem;
|
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Service\Host as ServiceHost;
|
use App\Models\Service\Host as ServiceHost;
|
||||||
use App\Models\Supplier\Host as SupplierHost;
|
use App\Models\Supplier\Host as SupplierHost;
|
||||||
|
|
||||||
final class Host extends Type implements ProductItem
|
final class Host extends Type
|
||||||
{
|
{
|
||||||
protected $table = 'product_host';
|
protected $table = 'product_host';
|
||||||
|
|
||||||
|
@ -4,12 +4,11 @@ namespace App\Models\Product;
|
|||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
use App\Interfaces\ProductItem;
|
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Service\Phone as ServicePhone;
|
use App\Models\Service\Phone as ServicePhone;
|
||||||
use App\Models\Supplier\Phone as SupplierPhone;
|
use App\Models\Supplier\Phone as SupplierPhone;
|
||||||
|
|
||||||
final class Phone extends Type implements ProductItem
|
final class Phone extends Type
|
||||||
{
|
{
|
||||||
protected $table = 'product_phone';
|
protected $table = 'product_phone';
|
||||||
|
|
||||||
|
@ -4,12 +4,11 @@ namespace App\Models\Product;
|
|||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
use App\Interfaces\ProductItem;
|
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Service\SSL as ServiceSSL;
|
use App\Models\Service\SSL as ServiceSSL;
|
||||||
use App\Models\Supplier\SSL as SupplierSSL;
|
use App\Models\Supplier\SSL as SupplierSSL;
|
||||||
|
|
||||||
final class SSL extends Type implements ProductItem
|
final class SSL extends Type
|
||||||
{
|
{
|
||||||
protected $table = 'product_ssl';
|
protected $table = 'product_ssl';
|
||||||
|
|
||||||
|
@ -3,15 +3,31 @@
|
|||||||
namespace App\Models\Product;
|
namespace App\Models\Product;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Arr;
|
|
||||||
|
|
||||||
|
use App\Interfaces\ProductItem;
|
||||||
use App\Models\Product;
|
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;
|
use SiteID,OrderServiceOptions;
|
||||||
|
|
||||||
|
public function __get($key): mixed
|
||||||
|
{
|
||||||
|
return match ($key) {
|
||||||
|
'billing_interval' => static::DefaultBill,
|
||||||
|
|
||||||
|
default => parent::__get($key),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/* RELATIONS */
|
/* RELATIONS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,24 +52,15 @@ abstract class Type extends Model
|
|||||||
|
|
||||||
/* ATTRIBUTES */
|
/* 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
|
* The product contract term is the highest of our defined contract_term (in Products/*) vs the suppliers
|
||||||
* contract term (defined in Supplier/*).
|
* contract term (defined in Supplier/*).
|
||||||
*
|
*
|
||||||
|
* @param int $val
|
||||||
* @return int
|
* @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);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,11 +16,13 @@ final class Domain extends Type
|
|||||||
// The model of the product that is supplied by this model
|
// The model of the product that is supplied by this model
|
||||||
const ProductModel = ProductDomain::class;
|
const ProductModel = ProductDomain::class;
|
||||||
|
|
||||||
/* INTERFACES */
|
public function __get($key): mixed
|
||||||
|
|
||||||
public function getNameAttribute(): string
|
|
||||||
{
|
{
|
||||||
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 */
|
/* STATIC */
|
||||||
|
@ -3,11 +3,10 @@
|
|||||||
namespace App\Models\Supplier;
|
namespace App\Models\Supplier;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Support\Arr;
|
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Leenooks\Traits\ScopeActive;
|
use Leenooks\Traits\ScopeActive;
|
||||||
|
|
||||||
use App\Models\{Invoice, Supplier, SupplierDetail};
|
use App\Models\{Supplier,SupplierDetail};
|
||||||
use App\Traits\SiteID;
|
use App\Traits\SiteID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,6 +30,12 @@ abstract class Type extends Model
|
|||||||
'category_lc' => strtolower($this->category),
|
'category_lc' => strtolower($this->category),
|
||||||
'category_name' => static::category_name ?: $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),
|
default => parent::__get($key),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -59,31 +64,11 @@ abstract class Type extends Model
|
|||||||
return $val ?: 1;
|
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
|
public function getSetupCostAttribute(?float $val): float
|
||||||
{
|
{
|
||||||
return $val ?: 0;
|
return $val ?: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSupplierAttribute(): Model
|
|
||||||
{
|
|
||||||
return $this->supplier_detail->supplier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function validation(): array
|
public function validation(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user