fix: [견적관리] 견적-수주 역방향 참조 보정 및 자동 동기화
- QuoteService::show() - order_id가 null인 경우 Order.quote_id 역방향 탐색으로 연결된 수주 자동 보정 - QuoteService::update() - 역방향 참조 포함하여 syncFromQuote() 동기화 트리거 확장 - 수주에서 견적 수정 시 기존 수주에 자동 반영 + "수주 보기" 버튼 정상 표시 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -177,6 +177,17 @@ public function show(int $id): Quote
|
||||
throw new NotFoundHttpException(__('error.quote_not_found'));
|
||||
}
|
||||
|
||||
// 역방향 참조 보정: order_id가 null인데 Order.quote_id로 연결된 수주가 있는 경우
|
||||
if (! $quote->order_id) {
|
||||
$linkedOrder = Order::where('quote_id', $quote->id)
|
||||
->where('tenant_id', $tenantId)
|
||||
->first();
|
||||
if ($linkedOrder) {
|
||||
$quote->update(['order_id' => $linkedOrder->id]);
|
||||
$quote->refresh()->load(['items', 'revisions', 'client', 'creator', 'updater', 'finalizer', 'siteBriefing.partner']);
|
||||
}
|
||||
}
|
||||
|
||||
// BOM 자재 데이터 계산 및 추가
|
||||
$bomMaterials = $this->calculateBomMaterials($quote);
|
||||
if (! empty($bomMaterials)) {
|
||||
@@ -444,8 +455,19 @@ public function update(int $id, array $data): Quote
|
||||
|
||||
$quote->refresh()->load(['items', 'revisions', 'client']);
|
||||
|
||||
// 연결된 수주가 있으면 동기화
|
||||
if ($quote->order_id) {
|
||||
// 연결된 수주가 있으면 동기화 (역방향 참조도 포함)
|
||||
$syncOrderId = $quote->order_id;
|
||||
if (! $syncOrderId) {
|
||||
$linkedOrder = Order::where('quote_id', $quote->id)
|
||||
->where('tenant_id', $tenantId)
|
||||
->first();
|
||||
if ($linkedOrder) {
|
||||
$quote->update(['order_id' => $linkedOrder->id]);
|
||||
$quote->refresh()->load(['items', 'revisions', 'client']);
|
||||
$syncOrderId = $linkedOrder->id;
|
||||
}
|
||||
}
|
||||
if ($syncOrderId) {
|
||||
try {
|
||||
$this->orderService->setContext($tenantId, $userId);
|
||||
$this->orderService->syncFromQuote($quote, $quote->current_revision);
|
||||
@@ -453,7 +475,7 @@ public function update(int $id, array $data): Quote
|
||||
// 수주 동기화 실패는 로그만 남기고 견적 수정은 성공 처리
|
||||
Log::warning('Failed to sync order from quote', [
|
||||
'quote_id' => $quote->id,
|
||||
'order_id' => $quote->order_id,
|
||||
'order_id' => $syncOrderId,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user