66 lines
1.6 KiB
PHP
66 lines
1.6 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Models\Supplier;
|
||
|
|
||
|
use Illuminate\Database\Eloquent\Model;
|
||
|
use Illuminate\Support\Arr;
|
||
|
use Leenooks\Traits\ScopeActive;
|
||
|
|
||
|
use App\Models\{Invoice,Supplier,SupplierDetail,Tax};
|
||
|
use App\Traits\{ProductDetails,SiteID};
|
||
|
|
||
|
abstract class Type extends Model
|
||
|
{
|
||
|
use SiteID,ScopeActive,ProductDetails;
|
||
|
|
||
|
/* RELATIONS */
|
||
|
|
||
|
public function supplier_detail()
|
||
|
{
|
||
|
return $this->belongsTo(SupplierDetail::class);
|
||
|
}
|
||
|
|
||
|
/* ATTRIBUTES */
|
||
|
|
||
|
public function getBaseCostTaxableAttribute(): float
|
||
|
{
|
||
|
return Tax::tax_calc($this->attributes['base_cost'],config('site')->taxes);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 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(static::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);
|
||
|
}
|
||
|
}
|