'킬로그램', 'value' => 'kg'], ['label' => '개', 'value' => 'EA'], ['label' => '미터', 'value' => 'm'], ['label' => '밀리미터', 'value' => 'mm'], ['label' => '리터', 'value' => 'L'], ['label' => '박스', 'value' => 'BOX'], ]; foreach ($units as $unit) { UnitOption::create([ 'tenant_id' => $tenantId, 'label' => $unit['label'], 'value' => $unit['value'], 'created_by' => $userId, ]); } // 2. 섹션 템플릿 $templates = [ ['title' => '기본 정보', 'type' => 'fields', 'description' => '제품 기본 정보 입력용 템플릿', 'is_default' => true], ['title' => '치수 정보', 'type' => 'fields', 'description' => '제품 치수 정보 입력용 템플릿', 'is_default' => false], ['title' => 'BOM 구성', 'type' => 'bom', 'description' => 'BOM 항목 관리용 템플릿', 'is_default' => true], ]; foreach ($templates as $template) { SectionTemplate::create([ 'tenant_id' => $tenantId, 'title' => $template['title'], 'type' => $template['type'], 'description' => $template['description'], 'is_default' => $template['is_default'], 'created_by' => $userId, ]); } // 3. 마스터 필드 (독립 엔티티로 생성) $masterFields = [ ['field_name' => '제품명', 'field_type' => 'textbox', 'category' => '기본정보', 'is_common' => true], ['field_name' => '제품코드', 'field_type' => 'textbox', 'category' => '기본정보', 'is_common' => true], ['field_name' => '규격', 'field_type' => 'textbox', 'category' => '기본정보', 'is_common' => true], ['field_name' => '수량', 'field_type' => 'number', 'category' => '재고정보', 'is_common' => true], ['field_name' => '단위', 'field_type' => 'dropdown', 'category' => '재고정보', 'is_common' => true, 'options' => [ ['label' => 'kg', 'value' => 'kg'], ['label' => 'EA', 'value' => 'EA'], ['label' => 'm', 'value' => 'm'], ]], ['field_name' => '길이', 'field_type' => 'number', 'category' => '치수정보', 'is_common' => false, 'properties' => ['unit' => 'mm', 'precision' => 2]], ['field_name' => '폭', 'field_type' => 'number', 'category' => '치수정보', 'is_common' => false, 'properties' => ['unit' => 'mm', 'precision' => 2]], ['field_name' => '높이', 'field_type' => 'number', 'category' => '치수정보', 'is_common' => false, 'properties' => ['unit' => 'mm', 'precision' => 2]], ]; foreach ($masterFields as $field) { ItemField::create([ 'tenant_id' => $tenantId, 'group_id' => $groupId, 'field_name' => $field['field_name'], 'field_type' => $field['field_type'], 'order_no' => 0, 'is_required' => false, 'category' => $field['category'], 'is_common' => $field['is_common'], 'options' => $field['options'] ?? null, 'properties' => $field['properties'] ?? null, 'created_by' => $userId, ]); } // 4. 품목 페이지 (5개 유형) $pages = [ ['page_name' => '완제품 관리', 'item_type' => 'FG', 'absolute_path' => '/FG/완제품 관리'], ['page_name' => '반제품 관리', 'item_type' => 'PT', 'absolute_path' => '/PT/반제품 관리'], ['page_name' => '부자재 관리', 'item_type' => 'SM', 'absolute_path' => '/SM/부자재 관리'], ['page_name' => '원자재 관리', 'item_type' => 'RM', 'absolute_path' => '/RM/원자재 관리'], ['page_name' => '소모품 관리', 'item_type' => 'CS', 'absolute_path' => '/CS/소모품 관리'], ]; foreach ($pages as $index => $page) { // 페이지 생성 (독립 엔티티) $itemPage = ItemPage::create([ 'tenant_id' => $tenantId, 'group_id' => $groupId, 'page_name' => $page['page_name'], 'item_type' => $page['item_type'], 'absolute_path' => $page['absolute_path'], 'is_active' => true, 'created_by' => $userId, ]); // 기본 정보 섹션 생성 (독립 엔티티) $section1 = ItemSection::create([ 'tenant_id' => $tenantId, 'group_id' => $groupId, 'title' => '기본 정보', 'type' => 'fields', 'order_no' => 0, 'created_by' => $userId, ]); // 페이지-섹션 관계 생성 (entity_relationships) // link(tenantId, parentType, parentId, childType, childId, orderNo, metadata, groupId) EntityRelationship::link( $tenantId, EntityRelationship::TYPE_PAGE, $itemPage->id, EntityRelationship::TYPE_SECTION, $section1->id, 0, // order_no null, // metadata $groupId ); // 필드 생성 및 섹션에 연결 $fieldData = [ ['field_name' => '제품명', 'is_required' => true, 'placeholder' => '제품명을 입력하세요'], ['field_name' => '제품코드', 'is_required' => true, 'placeholder' => '제품코드를 입력하세요'], ['field_name' => '규격', 'is_required' => false, 'placeholder' => '규격을 입력하세요'], ]; foreach ($fieldData as $orderNo => $fd) { $field = ItemField::create([ 'tenant_id' => $tenantId, 'group_id' => $groupId, 'field_name' => $fd['field_name'], 'field_type' => 'textbox', 'order_no' => $orderNo, 'is_required' => $fd['is_required'], 'placeholder' => $fd['placeholder'], 'created_by' => $userId, ]); // 섹션-필드 관계 생성 (entity_relationships) EntityRelationship::link( $tenantId, EntityRelationship::TYPE_SECTION, $section1->id, EntityRelationship::TYPE_FIELD, $field->id, $orderNo, null, $groupId ); } // BOM 섹션 (완제품, 반제품만) if (in_array($page['item_type'], ['FG', 'PT'])) { // BOM 섹션 생성 (독립 엔티티) $section2 = ItemSection::create([ 'tenant_id' => $tenantId, 'group_id' => $groupId, 'title' => 'BOM 구성', 'type' => 'bom', 'order_no' => 1, 'created_by' => $userId, ]); // 페이지-섹션 관계 생성 EntityRelationship::link( $tenantId, EntityRelationship::TYPE_PAGE, $itemPage->id, EntityRelationship::TYPE_SECTION, $section2->id, 1, // order_no null, $groupId ); // BOM 항목 생성 (독립 엔티티) $bomItem = ItemBomItem::create([ 'tenant_id' => $tenantId, 'group_id' => $groupId, 'item_code' => 'MAT-001', 'item_name' => '철판', 'quantity' => 10.5, 'unit' => 'kg', 'unit_price' => 5000.00, 'total_price' => 52500.00, 'spec' => '두께 2mm, 스테인리스', 'note' => '샘플 BOM 항목', 'created_by' => $userId, ]); // 섹션-BOM 관계 생성 EntityRelationship::link( $tenantId, EntityRelationship::TYPE_SECTION, $section2->id, EntityRelationship::TYPE_BOM, $bomItem->id, 0, null, $groupId ); } } // 5. 커스텀 탭 $tabs = [ ['label' => '전체', 'icon' => 'all', 'is_default' => true, 'order_no' => 0], ['label' => '완제품', 'icon' => 'product', 'is_default' => false, 'order_no' => 1], ['label' => '원자재', 'icon' => 'material', 'is_default' => false, 'order_no' => 2], ]; foreach ($tabs as $tab) { $customTab = CustomTab::create([ 'tenant_id' => $tenantId, 'label' => $tab['label'], 'icon' => $tab['icon'], 'is_default' => $tab['is_default'], 'order_no' => $tab['order_no'], 'created_by' => $userId, ]); // 탭별 컬럼 설정 TabColumn::create([ 'tenant_id' => $tenantId, 'tab_id' => $customTab->id, 'columns' => [ ['key' => 'name', 'label' => '품목명', 'visible' => true, 'order' => 0], ['key' => 'code', 'label' => '품목코드', 'visible' => true, 'order' => 1], ['key' => 'type', 'label' => '유형', 'visible' => true, 'order' => 2], ['key' => 'price', 'label' => '가격', 'visible' => false, 'order' => 3], ], 'created_by' => $userId, ]); } echo "✅ ItemMaster 시드 데이터 생성 완료!\n"; echo ' - 단위 옵션: '.count($units)."개\n"; echo ' - 섹션 템플릿: '.count($templates)."개\n"; echo ' - 마스터 필드: '.count($masterFields)."개\n"; echo ' - 품목 페이지: '.count($pages)."개\n"; echo ' - 커스텀 탭: '.count($tabs)."개\n"; } }