More works on products
This commit is contained in:
@@ -2,23 +2,14 @@
|
||||
|
||||
namespace App\Models\Supplier;
|
||||
|
||||
use App\Traits\ProductDetails;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Leenooks\Traits\ScopeActive;
|
||||
|
||||
use App\Interfaces\SupplierItem;
|
||||
use App\Models\{Invoice,Supplier,SupplierDetail,Tax};
|
||||
use App\Models\Product\Broadband as ProductBroadband;
|
||||
use App\Traits\SiteID;
|
||||
|
||||
class Broadband extends Model implements SupplierItem
|
||||
class Broadband extends Type implements SupplierItem
|
||||
{
|
||||
use SiteID,ScopeActive,ProductDetails;
|
||||
|
||||
protected $casts = [
|
||||
'offpeak_start' => 'datetime:H:i',
|
||||
'offpeak_end' => 'datetime:H:i',
|
||||
@@ -44,19 +35,9 @@ class Broadband extends Model implements SupplierItem
|
||||
|
||||
/* INTERFACES */
|
||||
|
||||
public function supplier_detail(): BelongsTo
|
||||
public function types()
|
||||
{
|
||||
return $this->belongsTo(SupplierDetail::class);
|
||||
}
|
||||
|
||||
public function types(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(ProductBroadband::class,'supplier_broadband','id','id','id','supplier_broadband_id');
|
||||
}
|
||||
|
||||
public function getBaseCostTaxableAttribute(): float
|
||||
{
|
||||
return Tax::tax_calc($this->attributes['base_cost'],config('site')->taxes);
|
||||
return $this->belongsToMany(ProductBroadband::class,$this->table,'id','id','id',$this->table.'_id');
|
||||
}
|
||||
|
||||
public function getBillingIntervalAttribute(): int
|
||||
@@ -64,48 +45,6 @@ class Broadband extends Model implements SupplierItem
|
||||
return 1; // Monthly
|
||||
}
|
||||
|
||||
/**
|
||||
* This contract term is the highest of
|
||||
* + The defined contract_term
|
||||
* + The default months in a billing interval
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getContractTermAttribute(): int
|
||||
{
|
||||
return max(Invoice::billing_period(self::getBillingIntervalAttribute()),Arr::get($this->attributes,'contract_term'));
|
||||
}
|
||||
|
||||
public function getMinCostAttribute(): float
|
||||
{
|
||||
return $this->attributes['setup_cost']+$this->attributes['base_cost']*Invoice::billing_term($this->getContractTermAttribute(),$this->getBillingIntervalAttribute());
|
||||
}
|
||||
|
||||
public function getMinCostTaxableAttribute(): float
|
||||
{
|
||||
return Tax::tax_calc($this->getMinCostAttribute(),config('site')->taxes);
|
||||
}
|
||||
|
||||
public function getNameAttribute(): string
|
||||
{
|
||||
return $this->product_id ?: 'Supplier PID Unknown';
|
||||
}
|
||||
|
||||
public function getNameLongAttribute(): string
|
||||
{
|
||||
return $this->product_desc ?: 'Supplier NAME Unknown';
|
||||
}
|
||||
|
||||
public function getSetupCostTaxableAttribute(): float
|
||||
{
|
||||
return Tax::tax_calc($this->attributes['setup_cost'],config('site')->taxes);
|
||||
}
|
||||
|
||||
public function getTypeAttribute(): string
|
||||
{
|
||||
return Arr::get(collect(Supplier::offering_types)->firstWhere('class',get_class($this)),'name','Unknown');
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user