fix: 견적 V2 BOM 계산 오류 수정

- ItemService.php: has_bom 계산 필드 추가 (BOM 필터링용)
- FormulaEvaluatorService.php: process_group 필드 추가 (공정별 그룹핑)

관련: 견적 V2 자동 견적 산출 4가지 오류 수정

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-26 16:12:45 +09:00
parent 462f6bd9e3
commit f2da990771
2 changed files with 39 additions and 1 deletions

View File

@@ -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);
}
// =========================================================================
// 품목 조회 메서드
// =========================================================================