osb/app/Models/Supplier/Type.php

90 lines
1.8 KiB
PHP
Raw Normal View History

2022-02-01 05:40:46 +00:00
<?php
namespace App\Models\Supplier;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Leenooks\Traits\ScopeActive;
2023-05-05 05:48:24 +00:00
use App\Models\{Invoice,SupplierDetail};
2023-05-05 12:05:42 +00:00
use App\Traits\SiteID;
2022-02-01 05:40:46 +00:00
abstract class Type extends Model
{
2023-05-05 12:05:42 +00:00
use SiteID,ScopeActive;
2022-02-01 05:40:46 +00:00
/* RELATIONS */
2023-05-05 05:48:24 +00:00
/**
* The offering supplied with this product
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
final public function products()
{
return $this->hasMany(static::ProductModel,'supplier_item_id','id');
}
final public function supplier_detail()
2022-02-01 05:40:46 +00:00
{
return $this->belongsTo(SupplierDetail::class);
}
/* ATTRIBUTES */
2023-05-05 05:48:24 +00:00
public function getBaseCostAttribute(?float $val): float
2022-02-01 05:40:46 +00:00
{
2023-05-05 05:48:24 +00:00
return $val ?: 0;
2022-02-01 05:40:46 +00:00
}
/**
* This will return the category of the product (eg: domain, hosting, etc) which is the basis for all
* other logic of these types.
*
* @return string
*/
final public function getCategoryAttribute(): string
{
return strtolower((new \ReflectionClass($this))->getShortName());
}
/**
* Return a friendly name for this product, used for display
*
* @return string
*/
final public function getCategoryNameAttribute(): string
{
return static::category_name;
}
2023-05-05 12:05:42 +00:00
final public function getContractTermAttribute(?int $val): int
2022-02-01 05:40:46 +00:00
{
2023-05-05 12:05:42 +00:00
return $val ?: 1;
2022-02-01 05:40:46 +00:00
}
public function getMinCostAttribute(): float
{
2023-05-05 12:05:42 +00:00
return $this->setup_cost+$this->base_cost*$this->contract_term;
2022-02-01 05:40:46 +00:00
}
public function getNameAttribute(): string
{
return $this->product_id ?: 'Supplier PID Unknown';
}
public function getNameLongAttribute(): string
{
return $this->product_desc ?: 'Supplier NAME Unknown';
}
2023-05-05 05:48:24 +00:00
public function getSetupCostAttribute(?float $val): float
2022-02-01 05:40:46 +00:00
{
2023-05-05 05:48:24 +00:00
return $val ?: 0;
2022-02-01 05:40:46 +00:00
}
2023-05-05 00:32:04 +00:00
public function getSupplierAttribute(): Model
{
return $this->supplier_detail->supplier;
}
2022-02-01 05:40:46 +00:00
}