where('tenant_id', $tenantId) ->whereIn('code', ['input_variables', 'calculation_variables', 'range_selection']) ->pluck('id', 'code') ->toArray(); if (empty($categories)) { $this->command->error('QuoteFormulaSeeder: 카테고리가 없습니다. QuoteFormulaCategorySeeder를 먼저 실행하세요.'); return; } $formulas = []; // === 1. 입력변수 (input) === $inputVars = [ [ 'variable' => 'PC', 'name' => '제품 카테고리', 'description' => '스크린 또는 철재 선택', 'formula' => null, 'sort_order' => 1, ], [ 'variable' => 'W0', 'name' => '오픈사이즈 폭 (W0)', 'description' => '개구부 실측 폭 (mm)', 'formula' => null, 'sort_order' => 2, ], [ 'variable' => 'H0', 'name' => '오픈사이즈 높이 (H0)', 'description' => '개구부 실측 높이 (mm)', 'formula' => null, 'sort_order' => 3, ], [ 'variable' => 'GT', 'name' => '가이드레일 설치유형', 'description' => '벽면형 또는 측면형', 'formula' => null, 'sort_order' => 4, ], [ 'variable' => 'MP', 'name' => '모터 전원', 'description' => '220V 또는 380V', 'formula' => null, 'sort_order' => 5, ], [ 'variable' => 'CT', 'name' => '연동제어기', 'description' => '단독 또는 연동', 'formula' => null, 'sort_order' => 6, ], [ 'variable' => 'QTY', 'name' => '수량', 'description' => '견적 수량', 'formula' => null, 'sort_order' => 7, ], ]; foreach ($inputVars as $var) { $formulas[] = [ 'tenant_id' => $tenantId, 'category_id' => $categories['input_variables'], 'product_id' => null, 'name' => $var['name'], 'variable' => $var['variable'], 'type' => 'input', 'formula' => $var['formula'], 'output_type' => 'variable', 'description' => $var['description'], 'sort_order' => $var['sort_order'], 'is_active' => true, 'created_by' => 1, 'updated_by' => 1, ]; } // === 2. 계산변수 (calculation) === $calcVars = [ [ 'variable' => 'W1_SCREEN', 'name' => '제작폭 W1 (스크린)', 'description' => '스크린 제작 폭: W0 + 140mm', 'formula' => 'W0 + 140', 'sort_order' => 10, ], [ 'variable' => 'W1_STEEL', 'name' => '제작폭 W1 (철재)', 'description' => '철재 제작 폭: W0 + 110mm', 'formula' => 'W0 + 110', 'sort_order' => 11, ], [ 'variable' => 'H1', 'name' => '제작높이 H1', 'description' => '제작 높이: H0 + 350mm', 'formula' => 'H0 + 350', 'sort_order' => 12, ], [ 'variable' => 'W', 'name' => '제작폭 (W)', 'description' => 'W1의 별칭 (수식에서 사용)', 'formula' => 'IF(PC=="스크린", W0+140, W0+110)', 'sort_order' => 13, ], [ 'variable' => 'H', 'name' => '제작높이 (H)', 'description' => 'H1의 별칭 (수식에서 사용)', 'formula' => 'H0 + 350', 'sort_order' => 14, ], [ 'variable' => 'M', 'name' => '면적 (M)', 'description' => '제작 면적 (㎡): W × H / 1,000,000', 'formula' => 'W * H / 1000000', 'sort_order' => 15, ], [ 'variable' => 'K_SCREEN', 'name' => '중량 K (스크린)', 'description' => '스크린 중량 (kg): M×2 + W0/1000×14.17', 'formula' => 'M * 2 + W0 / 1000 * 14.17', 'sort_order' => 16, ], [ 'variable' => 'K_STEEL', 'name' => '중량 K (철재)', 'description' => '철재 중량 (kg): M × 25', 'formula' => 'M * 25', 'sort_order' => 17, ], [ 'variable' => 'K', 'name' => '중량 (K)', 'description' => '제품별 중량 선택', 'formula' => 'IF(PC=="스크린", M*2+W0/1000*14.17, M*25)', 'sort_order' => 18, ], ]; foreach ($calcVars as $var) { $formulas[] = [ 'tenant_id' => $tenantId, 'category_id' => $categories['calculation_variables'], 'product_id' => null, 'name' => $var['name'], 'variable' => $var['variable'], 'type' => 'calculation', 'formula' => $var['formula'], 'output_type' => 'variable', 'description' => $var['description'], 'sort_order' => $var['sort_order'], 'is_active' => true, 'created_by' => 1, 'updated_by' => 1, ]; } // === 3. 범위선택 (range) === $rangeVars = [ [ 'variable' => 'MOTOR', 'name' => '모터 자동선택', 'description' => '중량(K) 기준 모터 자동 선택', 'formula' => 'K', // 조건 변수 'sort_order' => 20, ], [ 'variable' => 'GUIDE', 'name' => '가이드레일 자동선택', 'description' => '높이(H) 기준 가이드레일 규격 선택', 'formula' => 'H', 'sort_order' => 21, ], [ 'variable' => 'CASE', 'name' => '케이스 자동선택', 'description' => '폭(W) 기준 케이스 규격 선택', 'formula' => 'W', 'sort_order' => 22, ], ]; foreach ($rangeVars as $var) { $formulas[] = [ 'tenant_id' => $tenantId, 'category_id' => $categories['range_selection'], 'product_id' => null, 'name' => $var['name'], 'variable' => $var['variable'], 'type' => 'range', 'formula' => $var['formula'], 'output_type' => 'item', 'description' => $var['description'], 'sort_order' => $var['sort_order'], 'is_active' => true, 'created_by' => 1, 'updated_by' => 1, ]; } // 기존 데이터 삭제 후 삽입 $existingIds = DB::table('quote_formulas') ->where('tenant_id', $tenantId) ->whereIn('category_id', array_values($categories)) ->pluck('id') ->toArray(); if (! empty($existingIds)) { // 연결된 범위/아이템 데이터도 삭제 DB::table('quote_formula_ranges')->whereIn('formula_id', $existingIds)->delete(); DB::table('quote_formula_items')->whereIn('formula_id', $existingIds)->delete(); DB::table('quote_formulas')->whereIn('id', $existingIds)->delete(); } // 새 데이터 삽입 foreach ($formulas as $formula) { DB::table('quote_formulas')->insert(array_merge($formula, [ 'created_at' => now(), 'updated_at' => now(), ])); } $this->command->info('QuoteFormulaSeeder: '.count($formulas).'개 수식 생성 완료'); $this->command->info(' - 입력변수: '.count($inputVars).'개'); $this->command->info(' - 계산변수: '.count($calcVars).'개'); $this->command->info(' - 범위선택: '.count($rangeVars).'개'); } }