From f2da990771eef897dd77d904d7892bcfa13bcdf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Mon, 26 Jan 2026 16:12:45 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B2=AC=EC=A0=81=20V2=20BOM=20?= =?UTF-8?q?=EA=B3=84=EC=82=B0=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ItemService.php: has_bom 계산 필드 추가 (BOM 필터링용) - FormulaEvaluatorService.php: process_group 필드 추가 (공정별 그룹핑) 관련: 견적 V2 자동 견적 산출 4가지 오류 수정 Co-Authored-By: Claude Opus 4.5 --- app/Services/ItemService.php | 3 ++ .../Quote/FormulaEvaluatorService.php | 37 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) 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); + } + // ========================================================================= // 품목 조회 메서드 // =========================================================================