114 lines
3.1 KiB
PHP
114 lines
3.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models\Items;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 품목 상세 정보 모델
|
||
|
|
*
|
||
|
|
* items 테이블의 확장 필드 (1:1 관계)
|
||
|
|
* - Products 전용 필드 (is_sellable, is_purchasable 등)
|
||
|
|
* - Materials 전용 필드 (is_inspection 등)
|
||
|
|
*/
|
||
|
|
class ItemDetail extends Model
|
||
|
|
{
|
||
|
|
protected $fillable = [
|
||
|
|
'item_id',
|
||
|
|
// Products 전용
|
||
|
|
'is_sellable',
|
||
|
|
'is_purchasable',
|
||
|
|
'is_producible',
|
||
|
|
'safety_stock',
|
||
|
|
'lead_time',
|
||
|
|
'is_variable_size',
|
||
|
|
'product_category',
|
||
|
|
'part_type',
|
||
|
|
// 파일 필드 (Products)
|
||
|
|
'bending_diagram',
|
||
|
|
'bending_details',
|
||
|
|
'specification_file',
|
||
|
|
'specification_file_name',
|
||
|
|
'certification_file',
|
||
|
|
'certification_file_name',
|
||
|
|
'certification_number',
|
||
|
|
'certification_start_date',
|
||
|
|
'certification_end_date',
|
||
|
|
// Materials 전용
|
||
|
|
'is_inspection',
|
||
|
|
'item_name',
|
||
|
|
'specification',
|
||
|
|
'search_tag',
|
||
|
|
'remarks',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'is_sellable' => 'boolean',
|
||
|
|
'is_purchasable' => 'boolean',
|
||
|
|
'is_producible' => 'boolean',
|
||
|
|
'is_variable_size' => 'boolean',
|
||
|
|
'bending_details' => 'array',
|
||
|
|
'certification_start_date' => 'date',
|
||
|
|
'certification_end_date' => 'date',
|
||
|
|
];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 품목 (부모)
|
||
|
|
*/
|
||
|
|
public function item()
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Item::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
// ──────────────────────────────────────────────────────────────
|
||
|
|
// Products 전용 헬퍼
|
||
|
|
// ──────────────────────────────────────────────────────────────
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 판매 가능 여부
|
||
|
|
*/
|
||
|
|
public function isSellable(): bool
|
||
|
|
{
|
||
|
|
return $this->is_sellable ?? false;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 구매 가능 여부
|
||
|
|
*/
|
||
|
|
public function isPurchasable(): bool
|
||
|
|
{
|
||
|
|
return $this->is_purchasable ?? false;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 생산 가능 여부
|
||
|
|
*/
|
||
|
|
public function isProducible(): bool
|
||
|
|
{
|
||
|
|
return $this->is_producible ?? false;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 인증서 유효 여부
|
||
|
|
*/
|
||
|
|
public function isCertificationValid(): bool
|
||
|
|
{
|
||
|
|
if (! $this->certification_end_date) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
return $this->certification_end_date->isFuture();
|
||
|
|
}
|
||
|
|
|
||
|
|
// ──────────────────────────────────────────────────────────────
|
||
|
|
// Materials 전용 헬퍼
|
||
|
|
// ──────────────────────────────────────────────────────────────
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 검사 필요 여부
|
||
|
|
*/
|
||
|
|
public function requiresInspection(): bool
|
||
|
|
{
|
||
|
|
return $this->is_inspection === 'Y';
|
||
|
|
}
|
||
|
|
}
|