Move base_cost/base_charge product::class methods into __get(), and base_charge(), no functional changes
This commit is contained in:
@@ -34,6 +34,7 @@ use App\Traits\{ProductDetails,ProviderRef};
|
||||
* + lid : Local ID for product (part number)
|
||||
* + sid : System ID for product (part number)
|
||||
* + base_charge : Default billing amount
|
||||
*
|
||||
* + billing_interval : Default Billing Interval
|
||||
* + billing_interval_string: Default Billing Interval in human-readable form
|
||||
* + category : Type of product supplied
|
||||
@@ -62,8 +63,6 @@ use App\Traits\{ProductDetails,ProviderRef};
|
||||
* group => [ pricing/setup ]
|
||||
* ]
|
||||
* ]
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class Product extends Model implements IDs
|
||||
{
|
||||
@@ -73,6 +72,15 @@ class Product extends Model implements IDs
|
||||
'pricing' => CollectionOrNull::class,
|
||||
];
|
||||
|
||||
public function __get($key): mixed
|
||||
{
|
||||
return match ($key) {
|
||||
'base_cost' => round($this->supplied->base_cost,2)*Invoice::billing_change($this->type->billing_interval,$this->billing_interval) ?: 0,
|
||||
|
||||
default => parent::__get($key),
|
||||
};
|
||||
}
|
||||
|
||||
/* STATIC */
|
||||
|
||||
/**
|
||||
@@ -162,28 +170,6 @@ class Product extends Model implements IDs
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
/**
|
||||
* The amount we invoice each time period for this service
|
||||
*
|
||||
* @param int|NULL $timeperiod
|
||||
* @param Group|NULL $go
|
||||
* @return float
|
||||
*/
|
||||
public function getBaseChargeAttribute(int $timeperiod=NULL,Group $go=NULL): float
|
||||
{
|
||||
return $this->_charge('base',$timeperiod,$go);
|
||||
}
|
||||
|
||||
/**
|
||||
* The base cost of this product at the appropriate billing interval
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getBaseCostAttribute(): float
|
||||
{
|
||||
return round($this->supplied->base_cost,2)*Invoice::billing_change($this->type->billing_interval,$this->billing_interval) ?: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Our default billing interval
|
||||
* Its the max of what we define, or what the supplier bills us at
|
||||
@@ -248,7 +234,7 @@ class Product extends Model implements IDs
|
||||
public function getMinChargeAttribute(int $timeperiod=NULL,Group $go=NULL): float
|
||||
{
|
||||
return $this->getSetupChargeAttribute($timeperiod,$go)
|
||||
+ $this->getBaseChargeAttribute($timeperiod,$go)*Invoice::billing_change($this->billing_interval,$this->type->billing_interval)*$this->type->contract_term;
|
||||
+ $this->base_charge($timeperiod,$go)*Invoice::billing_change($this->billing_interval,$this->type->billing_interval)*$this->type->contract_term;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -383,6 +369,18 @@ class Product extends Model implements IDs
|
||||
->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* The amount we invoice each time period for this service
|
||||
*
|
||||
* @param int|NULL $timeperiod
|
||||
* @param Group|NULL $go
|
||||
* @return float
|
||||
*/
|
||||
public function base_charge(?int $timeperiod=NULL,?Group $go=NULL): float
|
||||
{
|
||||
return $this->_charge('base',$timeperiod,$go);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the charge from the pricing table for the specific time period and group
|
||||
*
|
||||
|
Reference in New Issue
Block a user