From 78ff01d6b175f6f06532dcf8582a878b73b432bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=98=81=EB=B3=B4?= Date: Fri, 20 Mar 2026 17:08:37 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[=EC=83=9D=EC=82=B0=EC=A7=80=EC=8B=9C]?= =?UTF-8?q?=20=EB=B3=B4=EC=A1=B0=EA=B3=B5=EC=A0=95=20=ED=92=88=EB=AA=A9=20?= =?UTF-8?q?=EB=AF=B8=EB=B0=B0=EC=A0=95=20=EB=AC=B8=EC=A0=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 부자재(감기샤프트, 각파이프 등)가 "재고생산"(보조공정) 매핑으로 미배정 생성되던 문제 - 보조공정(is_auxiliary) 및 미매핑(none) 품목을 메인 공정으로 자동 병합 - 메인 공정 중 품목 수가 가장 많은 공정에 배정 --- app/Services/OrderService.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/Services/OrderService.php b/app/Services/OrderService.php index 8eeb1eb4..59870222 100644 --- a/app/Services/OrderService.php +++ b/app/Services/OrderService.php @@ -1533,6 +1533,35 @@ public function createProductionOrder(int $orderId, array $data) } $itemsByProcess[$key]['items'][] = $orderItem; } + + // 보조 공정(재고생산 등) 품목을 메인 공정으로 병합 + $auxiliaryProcessIds = \App\Models\Process::where('tenant_id', $tenantId) + ->where('is_active', true) + ->get() + ->filter(fn ($p) => ! empty($p->options['is_auxiliary'])) + ->pluck('id') + ->all(); + + $auxiliaryKeys = []; + $mainKeys = []; + foreach ($itemsByProcess as $key => $group) { + if ($key === 'none' || in_array($group['process_id'], $auxiliaryProcessIds, true)) { + $auxiliaryKeys[] = $key; + } else { + $mainKeys[] = $key; + } + } + + if (! empty($auxiliaryKeys) && ! empty($mainKeys)) { + // 메인 공정 중 품목 수가 가장 많은 공정에 병합 + $targetKey = collect($mainKeys)->sortByDesc(fn ($k) => count($itemsByProcess[$k]['items']))->first(); + foreach ($auxiliaryKeys as $auxKey) { + foreach ($itemsByProcess[$auxKey]['items'] as $item) { + $itemsByProcess[$targetKey]['items'][] = $item; + } + unset($itemsByProcess[$auxKey]); + } + } } return DB::transaction(function () use ($order, $data, $tenantId, $userId, $itemsByProcess, $nodesBomMap, $isStock) {