More Product Model optimisation

This commit is contained in:
2023-05-05 15:48:24 +10:00
parent 96f799f535
commit 820ff2be00
37 changed files with 161 additions and 592 deletions

View File

@@ -118,31 +118,6 @@ final class Broadband extends Type implements ProductItem
return $result;
}
/**
* The product contract term is the highest of
* + This defined contract_term
* + The suppliers contract_term
*
* @return int
*/
public function getContractTermAttribute(): int
{
return max($this->attributes['contract_term'],$this->supplied->getContractTermAttribute());
}
public function getCostAttribute(): float
{
abort(500,'deprecated');
// @todo Tax shouldnt be hard coded
return ($this->supplied->base_cost+$this->allowance_cost())*1.1;
}
public function getSupplierAttribute()
{
abort(500,'deprecated');
return $this->getRelationValue('supplier');
}
public function hasUsage(): bool
{
return TRUE;

View File

@@ -51,22 +51,6 @@ final class Domain extends Type implements ProductItem
return '';
}
public function getContractTermAttribute(): int
{
return 12;
}
public function getCostAttribute(): float
{
// N/A
return 0;
}
public function getSupplierAttribute()
{
return '';
}
public function hasUsage(): bool
{
return FALSE;

View File

@@ -35,22 +35,6 @@ final class Email extends Type implements ProductItem
return '';
}
public function getContractTermAttribute(): int
{
return 12;
}
public function getCostAttribute(): float
{
// N/A
return 0;
}
public function getSupplierAttribute()
{
return '';
}
public function hasUsage(): bool
{
return FALSE;

View File

@@ -23,16 +23,6 @@ final class Generic extends Type implements ProductItem
/* INTERFACES */
public function getContractTermAttribute(): int
{
return 0;
}
public function hasUsage(): bool
{
return FALSE;
}
public function allowance(): Collection
{
// TODO: Implement allowance() method.
@@ -43,13 +33,8 @@ final class Generic extends Type implements ProductItem
// TODO: Implement allowance_string() method.
}
public function getCostAttribute(): float
public function hasUsage(): bool
{
// TODO: Implement getCostAttribute() method.
return FALSE;
}
public function getSupplierAttribute()
{
// TODO: Implement getSupplierAttribute() method.
}
}
}

View File

@@ -23,16 +23,6 @@ final class Host extends Type implements ProductItem
/* INTERFACES */
public function getContractTermAttribute(): int
{
return 12;
}
public function hasUsage(): bool
{
return FALSE;
}
public function allowance(): Collection
{
// TODO: Implement allowance() method.
@@ -44,14 +34,8 @@ final class Host extends Type implements ProductItem
return '';
}
public function getCostAttribute(): float
public function hasUsage(): bool
{
// TODO: Implement getCostAttribute() method.
return 0;
}
public function getSupplierAttribute()
{
// TODO: Implement getSupplierAttribute() method.
return FALSE;
}
}

View File

@@ -50,17 +50,6 @@ final class Phone extends Type implements ProductItem
/* INTERFACES */
public function getContractTermAttribute(): int
{
// @todo Get this from the DB
return 12;
}
public function hasUsage(): bool
{
return FALSE;
}
public function allowance(): Collection
{
// TODO: Implement allowance() method.
@@ -71,13 +60,8 @@ final class Phone extends Type implements ProductItem
return "(TBA)";
}
public function getCostAttribute(): float
public function hasUsage(): bool
{
// TODO: Implement getCostAttribute() method.
}
public function getSupplierAttribute()
{
// TODO: Implement getSupplierAttribute() method.
return FALSE;
}
}

View File

@@ -35,26 +35,6 @@ final class SSL extends Type implements ProductItem
return '';
}
public function getContractTermAttribute(): int
{
return 12;
}
public function getCostAttribute(): float
{
// N/A
return 0;
}
public function getSupplierAttribute()
{
abort(500,'deprecated');
$o = new \stdClass();
$o->name = 'Internal';
return $o;
}
public function hasUsage(): bool
{
return FALSE;

View File

@@ -3,14 +3,11 @@
namespace App\Models\Product;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use App\Models\Product;
use App\Traits\{OrderServiceOptions,SiteID};
/**
* @todo These tables have a base_cost/setup_cost/contract_term columns - how is that different to the supplier_tables?
* @todo Ensure our terminology is consistent - we have a "cost", we "charge" clients, and we have a "price" which is not official charges nor a cost.
*/
abstract class Type extends Model
{
use SiteID,OrderServiceOptions;
@@ -37,9 +34,22 @@ abstract class Type extends Model
return $this->hasOne(static::SupplierModel,'id','supplier_item_id');
}
/* ATTRIBUTES */
/**
* The product contract term is the highest of our defined contract_term (in Products/*) vs the suppliers
* contract term (defined in Supplier/*).
*
* @return int
*/
public function getContractTermAttribute(): int
{
return max(Arr::get($this->attributes,'contract_term',0),$this->supplied->contract_term);
}
/* METHODs */
final function normalizeBillingInterval(): int
final public function normalizeBillingInterval(): int
{
return static::DefaultBill;
}