fix: 견적→수주 변환 시 레거시 데이터 개소 분배 보완

- formula_source 없는 레거시 견적에서 sort_order 기반 개소 분배 로직 추가
- resolveLocationMapping/resolveLocationIndex 실패 시 index÷itemsPerLocation 폴백
- 기존 formula_source 매칭 로직은 그대로 유지

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-22 03:04:42 +09:00
parent 5a3d6c2243
commit b00fa0502a

View File

@@ -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);