2022-02-01 05:40:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models\Product;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2023-05-05 05:48:24 +00:00
|
|
|
use Illuminate\Support\Arr;
|
2022-02-01 05:40:46 +00:00
|
|
|
|
|
|
|
use App\Models\Product;
|
|
|
|
use App\Traits\{OrderServiceOptions,SiteID};
|
|
|
|
|
|
|
|
abstract class Type extends Model
|
|
|
|
{
|
|
|
|
use SiteID,OrderServiceOptions;
|
|
|
|
|
|
|
|
/* RELATIONS */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The product that sells this type
|
|
|
|
*
|
2023-03-15 04:34:28 +00:00
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
|
2022-02-01 05:40:46 +00:00
|
|
|
*/
|
2023-05-04 12:17:42 +00:00
|
|
|
final public function products()
|
2022-02-01 05:40:46 +00:00
|
|
|
{
|
2023-03-15 04:34:28 +00:00
|
|
|
return $this->morphMany(Product::class, null,'model','model_id');
|
2022-02-01 05:40:46 +00:00
|
|
|
}
|
2022-06-12 01:21:20 +00:00
|
|
|
|
2023-05-04 00:02:25 +00:00
|
|
|
/**
|
|
|
|
* The offering supplied with this product
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
|
|
*/
|
2023-05-04 12:17:42 +00:00
|
|
|
final public function supplied()
|
2023-05-04 00:02:25 +00:00
|
|
|
{
|
|
|
|
return $this->hasOne(static::SupplierModel,'id','supplier_item_id');
|
|
|
|
}
|
|
|
|
|
2023-05-05 05:48:24 +00:00
|
|
|
/* ATTRIBUTES */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The product contract term is the highest of our defined contract_term (in Products/*) vs the suppliers
|
|
|
|
* contract term (defined in Supplier/*).
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getContractTermAttribute(): int
|
|
|
|
{
|
|
|
|
return max(Arr::get($this->attributes,'contract_term',0),$this->supplied->contract_term);
|
|
|
|
}
|
|
|
|
|
2023-05-04 12:17:42 +00:00
|
|
|
/* METHODs */
|
|
|
|
|
2023-05-05 05:48:24 +00:00
|
|
|
final public function normalizeBillingInterval(): int
|
2023-05-04 12:17:42 +00:00
|
|
|
{
|
|
|
|
return static::DefaultBill;
|
|
|
|
}
|
2022-02-01 05:40:46 +00:00
|
|
|
}
|