Files
sam-api/app/Models/Items/ItemDetail.php
kent 80281e65b7 feat: Items 테이블 통합 마이그레이션 Phase 0-5 구현
## 주요 변경사항
- Phase 0: 비표준 item_type 데이터 정규화 마이그레이션
- Phase 1.1: items 테이블 생성 (products + materials 통합)
- Phase 1.2: item_details 테이블 생성 (1:1 확장 필드)
- Phase 1.3: 데이터 이관 + item_id_mappings 테이블 생성
- Phase 3: item_pages.source_table 업데이트
- Phase 5: 참조 테이블 마이그레이션 (product_components, orders 등)

## 신규 파일
- app/Models/Items/Item.php - 통합 아이템 모델
- app/Models/Items/ItemDetail.php - 1:1 확장 필드 모델
- app/Services/ItemService.php - 통합 서비스 클래스

## 수정 파일
- ItemPage.php - items 테이블 지원 추가

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 15:41:30 +09:00

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';
}
}