From b00fa0502a06c577c9a85affedcd2ea5126eb5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Sun, 22 Feb 2026 03:04:42 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B2=AC=EC=A0=81=E2=86=92=EC=88=98?= =?UTF-8?q?=EC=A3=BC=20=EB=B3=80=ED=99=98=20=EC=8B=9C=20=EB=A0=88=EA=B1=B0?= =?UTF-8?q?=EC=8B=9C=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EA=B0=9C=EC=86=8C=20?= =?UTF-8?q?=EB=B6=84=EB=B0=B0=20=EB=B3=B4=EC=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - formula_source 없는 레거시 견적에서 sort_order 기반 개소 분배 로직 추가 - resolveLocationMapping/resolveLocationIndex 실패 시 index÷itemsPerLocation 폴백 - 기존 formula_source 매칭 로직은 그대로 유지 Co-Authored-By: Claude Opus 4.6 --- app/Services/Quote/QuoteService.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index cc71695..34e05e0 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -689,11 +689,23 @@ public function convertToOrder(int $id): Quote } // 수주 상세 품목 생성 (노드 연결 포함) + // formula_source 없는 레거시 데이터용: sort_order 기반 분배 준비 + $locationCount = count($productItems); + $hasFormulaSource = $quote->items->contains(fn ($item) => ! empty($item->formula_source)); + $itemsPerLocation = (! $hasFormulaSource && $locationCount > 1) + ? intdiv($quote->items->count(), $locationCount) + : 0; + $serialIndex = 1; - foreach ($quote->items as $quoteItem) { + foreach ($quote->items as $index => $quoteItem) { $productMapping = $this->resolveLocationMapping($quoteItem, $productItems); $locIdx = $this->resolveLocationIndex($quoteItem, $productItems); + // sort_order 기반 분배 (formula_source/note 매칭 모두 실패 시) + if ($locIdx === 0 && $itemsPerLocation > 0) { + $locIdx = min(intdiv($index, $itemsPerLocation), $locationCount - 1); + } + $productMapping['order_node_id'] = isset($nodeMap[$locIdx]) ? $nodeMap[$locIdx]->id : null; $orderItem = OrderItem::createFromQuoteItem($quoteItem, $order->id, $serialIndex, $productMapping);