More Product Model optimisation
This commit is contained in:
@@ -41,11 +41,8 @@ use App\Traits\{ProductDetails,SiteID};
|
||||
* + billing_interval : Default Billing Interval
|
||||
* + billing_interval_string: Default Billing Interval in human-readable form
|
||||
* + setup_charge : Charge to setup this product
|
||||
* + setup_charge_taxable : Charge to setup this product including taxes
|
||||
* + base_charge : Default billing amount
|
||||
* + base_charge_taxable : Default billing amount including taxes
|
||||
* + min_charge : Minimum charge taking into account billing interval and setup charges
|
||||
* + min_charge_taxable : Minimum charge taking into account billing interval and setup charges including taxes
|
||||
*
|
||||
* Attributes for product types (type - Product/*)
|
||||
* + name : Short Name for our Product
|
||||
@@ -65,7 +62,6 @@ use App\Traits\{ProductDetails,SiteID};
|
||||
* ]
|
||||
* ]
|
||||
*
|
||||
* @todo doesnt appear that price_type is used - but could be used to have different offering types billed differently
|
||||
* @package App\Models
|
||||
*/
|
||||
class Product extends Model implements IDs
|
||||
@@ -170,20 +166,6 @@ class Product extends Model implements IDs
|
||||
return $this->_charge('base',$timeperiod,$go);
|
||||
}
|
||||
|
||||
/**
|
||||
* The amount we invoice each time period for this service, including taxes
|
||||
*
|
||||
* @param int|null $timeperiod
|
||||
* @param Group|null $go
|
||||
* @param Collection|NULL $taxes
|
||||
* @return float
|
||||
* @deprecated move to account::tax_calc
|
||||
*/
|
||||
public function getBaseChargeTaxableAttribute(int $timeperiod=NULL,Group $go=NULL,Collection $taxes=NULL): float
|
||||
{
|
||||
return Tax::tax_calc($this->getBaseChargeAttribute($timeperiod,$go),$taxes ?: config('site')->taxes);
|
||||
}
|
||||
|
||||
/**
|
||||
* The base cost of this product at the appropriate billing interval
|
||||
*
|
||||
@@ -191,19 +173,7 @@ class Product extends Model implements IDs
|
||||
*/
|
||||
public function getBaseCostAttribute(): float
|
||||
{
|
||||
return $this->supplied->base_cost*Invoice::billing_change($this->supplied->billing_interval,$this->billing_interval) ?: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The base cost of this product at the appropriate billing interval including taxes
|
||||
*
|
||||
* @param Collection|NULL $taxes
|
||||
* @return float
|
||||
* @deprecated move to account::tax_calc
|
||||
*/
|
||||
public function getBaseCostTaxableAttribute(Collection $taxes=NULL): float
|
||||
{
|
||||
return Tax::tax_calc($this->getBaseCostAttribute(),$taxes ?: config('site')->taxes);;
|
||||
return $this->supplied->base_cost*Invoice::billing_change($this->type->normalizeBillingInterval(),$this->billing_interval) ?: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -214,7 +184,7 @@ class Product extends Model implements IDs
|
||||
*/
|
||||
public function getBillingIntervalAttribute(): int
|
||||
{
|
||||
return max($this->price_recur_default,$this->supplied->billing_interval);
|
||||
return max($this->price_recur_default,$this->type->normalizeBillingInterval());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,20 +242,6 @@ class Product extends Model implements IDs
|
||||
return $this->getSetupChargeAttribute($timeperiod,$go)+$this->getBaseChargeAttribute($timeperiod,$go)*Invoice::billing_term($this->type->contract_term,$this->getBillingIntervalAttribute());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum cost of this product with taxes
|
||||
*
|
||||
* @param int|null $timeperiod
|
||||
* @param Group|null $go
|
||||
* @param Collection|NULL $taxes
|
||||
* @return float
|
||||
* @deprecated move to account::tax_calc
|
||||
*/
|
||||
public function getMinChargeTaxableAttribute(int $timeperiod=NULL,Group $go=NULL,Collection $taxes=NULL): float
|
||||
{
|
||||
return Tax::tax_calc($this->getMinChargeAttribute($timeperiod,$go),$taxes ?: config('site')->taxes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Our products short descriptive name
|
||||
*
|
||||
@@ -348,20 +304,6 @@ class Product extends Model implements IDs
|
||||
return $this->_charge('setup',$timeperiod,$go);
|
||||
}
|
||||
|
||||
/**
|
||||
* The charge to setup this service including taxes
|
||||
*
|
||||
* @param int|null $timeperiod
|
||||
* @param Group|null $go
|
||||
* @param Collection|null $taxes
|
||||
* @return float
|
||||
* @deprecated move to account::tax_calc
|
||||
*/
|
||||
public function getSetupChargeTaxableAttribute(int $timeperiod=NULL,Group $go=NULL,Collection $taxes=NULL): float
|
||||
{
|
||||
return Tax::tax_calc($this->getSetupChargeAttribute($timeperiod,$go),$taxes ?: config('site')->taxes);
|
||||
}
|
||||
|
||||
/**
|
||||
* The cost to setup this service
|
||||
*
|
||||
@@ -372,18 +314,6 @@ class Product extends Model implements IDs
|
||||
return $this->supplied->setup_cost ?: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The charge to setup this service
|
||||
*
|
||||
* @param Collection|null $taxes
|
||||
* @return float
|
||||
* @deprecated move to account::tax_calc
|
||||
*/
|
||||
public function getSetupCostTaxableAttribute(Collection $taxes=NULL): float
|
||||
{
|
||||
return Tax::tax_calc($this->getSetupCostAttribute(),$taxes ?: config('site')->taxes);;
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
/**
|
||||
@@ -457,11 +387,10 @@ class Product extends Model implements IDs
|
||||
*
|
||||
* @note: By definition products are normalised, as their cost price is based on the default billing interval
|
||||
* @return float
|
||||
* @todo Move tax calculations out
|
||||
*/
|
||||
public function cost_normalized(): float
|
||||
{
|
||||
return number_format(Tax::tax_calc($this->supplied->base_cost,config('site')->taxes),2);
|
||||
return number_format(config('site')->taxed($this->supplied->base_cost),2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user