fix(WEB): 수주 상태변경 API 응답에 공통 relations 로딩 적용
- loadDetailRelations() 공통 메서드 추가 (show()와 동일한 relations 보장) - store/update/updateStatus/createFromQuote/revert 등 11곳 일괄 적용 - 수주확정/되돌리기 시 제품내용이 기타부품으로 매핑되던 문제 해결 - 원인: updateStatus 등에서 quote relation 미로딩 → products 빈 배열 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,19 @@ public function __construct(
|
||||
private NumberingService $numberingService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 상세 조회용 공통 relations (show와 동일한 구조 보장)
|
||||
*/
|
||||
private function loadDetailRelations(Order $order): Order
|
||||
{
|
||||
return $order->load([
|
||||
'client:id,name,contact_person,phone,email,manager_name',
|
||||
'items' => fn ($q) => $q->orderBy('sort_order'),
|
||||
'rootNodes' => fn ($q) => $q->withRecursiveChildren(),
|
||||
'quote:id,quote_number,site_name,calculation_inputs',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 목록 조회 (검색/필터링/페이징)
|
||||
*/
|
||||
@@ -131,20 +144,13 @@ public function show(int $id)
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
$order = Order::where('tenant_id', $tenantId)
|
||||
->with([
|
||||
'client:id,name,contact_person,phone,email,manager_name',
|
||||
'items' => fn ($q) => $q->orderBy('sort_order'),
|
||||
'rootNodes' => fn ($q) => $q->withRecursiveChildren(),
|
||||
'quote:id,quote_number,site_name,calculation_inputs',
|
||||
])
|
||||
->find($id);
|
||||
$order = Order::where('tenant_id', $tenantId)->find($id);
|
||||
|
||||
if (! $order) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
}
|
||||
|
||||
return $order;
|
||||
return $this->loadDetailRelations($order);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,7 +266,7 @@ public function store(array $data)
|
||||
$order->refresh();
|
||||
$order->recalculateTotals()->save();
|
||||
|
||||
return $order->load(['client:id,name', 'items']);
|
||||
return $this->loadDetailRelations($order);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -326,7 +332,7 @@ public function update(int $id, array $data)
|
||||
$order->recalculateTotals()->save();
|
||||
}
|
||||
|
||||
return $order->load(['client:id,name', 'items']);
|
||||
return $this->loadDetailRelations($order);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -549,7 +555,7 @@ public function updateStatus(int $id, string $status)
|
||||
$order->updated_by = $userId;
|
||||
$order->save();
|
||||
|
||||
$result = $order->load(['client:id,name', 'items']);
|
||||
$result = $this->loadDetailRelations($order);
|
||||
|
||||
// 매출이 생성된 경우 응답에 포함
|
||||
if ($createdSale) {
|
||||
@@ -853,7 +859,7 @@ public function createFromQuote(int $quoteId, array $data = [])
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
|
||||
return $order->load(['client:id,name', 'items', 'quote:id,quote_number']);
|
||||
return $this->loadDetailRelations($order);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1065,7 +1071,7 @@ public function syncFromQuote(Quote $quote, int $revision): ?Order
|
||||
'created_by' => $userId,
|
||||
]);
|
||||
|
||||
return $order->load(['client:id,name', 'items', 'quote:id,quote_number']);
|
||||
return $this->loadDetailRelations($order);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1342,7 +1348,7 @@ public function createProductionOrder(int $orderId, array $data)
|
||||
return [
|
||||
'work_orders' => $workOrders,
|
||||
'work_order' => $workOrders[0] ?? null, // 하위 호환성
|
||||
'order' => $order->load(['client:id,name', 'items']),
|
||||
'order' => $this->loadDetailRelations($order),
|
||||
];
|
||||
});
|
||||
}
|
||||
@@ -1474,7 +1480,7 @@ public function revertOrderConfirmation(int $orderId): array
|
||||
$order->save();
|
||||
|
||||
return [
|
||||
'order' => $order->load(['client:id,name', 'items']),
|
||||
'order' => $this->loadDetailRelations($order),
|
||||
'previous_status' => $previousStatus,
|
||||
'deleted_sale_id' => $deletedSaleId,
|
||||
];
|
||||
@@ -1624,7 +1630,7 @@ private function revertProductionOrderForce(Order $order, int $tenantId, int $us
|
||||
$order->save();
|
||||
|
||||
return [
|
||||
'order' => $order->load(['client:id,name', 'items']),
|
||||
'order' => $this->loadDetailRelations($order),
|
||||
'deleted_counts' => $deletedCounts,
|
||||
'previous_status' => $previousStatus,
|
||||
];
|
||||
@@ -1695,7 +1701,7 @@ private function revertProductionOrderCancel(Order $order, int $tenantId, int $u
|
||||
$order->save();
|
||||
|
||||
return [
|
||||
'order' => $order->load(['client:id,name', 'items']),
|
||||
'order' => $this->loadDetailRelations($order),
|
||||
'cancelled_count' => $cancelledCount,
|
||||
'skipped_count' => count($skippedIds),
|
||||
'skipped_ids' => $skippedIds,
|
||||
|
||||
Reference in New Issue
Block a user