diff --git a/app/Services/ItemService.php b/app/Services/ItemService.php index 28393f9..4c6a64a 100644 --- a/app/Services/ItemService.php +++ b/app/Services/ItemService.php @@ -431,6 +431,9 @@ public function index(array $params): LengthAwarePaginator unset($arr['code']); } + // has_bom 계산 필드 추가 (BOM이 있는 품목 필터링에 사용) + $arr['has_bom'] = ! empty($arr['bom']) && is_array($arr['bom']) && count($arr['bom']) > 0; + return $arr; }) ); diff --git a/app/Services/Quote/FormulaEvaluatorService.php b/app/Services/Quote/FormulaEvaluatorService.php index d479b59..95d8836 100644 --- a/app/Services/Quote/FormulaEvaluatorService.php +++ b/app/Services/Quote/FormulaEvaluatorService.php @@ -748,9 +748,12 @@ public function calculateBomWithDebug( ]; } - // Step 8: 공정별 그룹화 + // Step 8: 공정별 그룹화 및 items에 process_group 추가 $groupedItems = $this->groupItemsByProcess($calculatedItems, $tenantId); + // items에 process_group 필드 추가 (프론트엔드에서 분류에 사용) + $calculatedItems = $this->addProcessGroupToItems($calculatedItems, $groupedItems); + // Step 9: 소계 계산 $subtotals = []; foreach ($groupedItems as $processType => $group) { @@ -915,6 +918,38 @@ public function groupItemsByProcess(array $items, ?int $tenantId = null): array return $grouped; } + /** + * items 배열에 process_group 필드 추가 + * + * groupedItems에서 각 아이템의 소속 그룹을 찾아 process_group 필드를 추가합니다. + * 프론트엔드에서 탭별 분류에 사용됩니다. + */ + private function addProcessGroupToItems(array $items, array $groupedItems): array + { + // 각 그룹의 아이템 코드 → 그룹명 매핑 생성 + $itemCodeToGroup = []; + foreach ($groupedItems as $groupKey => $group) { + if (! isset($group['items']) || ! is_array($group['items'])) { + continue; + } + foreach ($group['items'] as $groupItem) { + $itemCodeToGroup[$groupItem['item_code']] = [ + 'key' => $groupKey, + 'name' => $group['name'] ?? $groupKey, + ]; + } + } + + // items 배열에 process_group 추가 + return array_map(function ($item) use ($itemCodeToGroup) { + $groupInfo = $itemCodeToGroup[$item['item_code']] ?? ['key' => 'other', 'name' => '기타']; + $item['process_group'] = $groupInfo['name']; + $item['process_group_key'] = $groupInfo['key']; + + return $item; + }, $items); + } + // ========================================================================= // 품목 조회 메서드 // =========================================================================