From d4125dc4ad6ba4a941df3faf55509a207f99ac22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Sat, 7 Feb 2026 04:55:22 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[=EA=B2=AC=EC=A0=81=EA=B4=80=EB=A6=AC]?= =?UTF-8?q?=20=EA=B2=AC=EC=A0=81-=EC=88=98=EC=A3=BC=20=EC=97=AD=EB=B0=A9?= =?UTF-8?q?=ED=96=A5=20=EC=B0=B8=EC=A1=B0=20=EB=B3=B4=EC=A0=95=20=EB=B0=8F?= =?UTF-8?q?=20=EC=9E=90=EB=8F=99=20=EB=8F=99=EA=B8=B0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - QuoteService::show() - order_id가 null인 경우 Order.quote_id 역방향 탐색으로 연결된 수주 자동 보정 - QuoteService::update() - 역방향 참조 포함하여 syncFromQuote() 동기화 트리거 확장 - 수주에서 견적 수정 시 기존 수주에 자동 반영 + "수주 보기" 버튼 정상 표시 Co-Authored-By: Claude Opus 4.6 --- app/Services/Quote/QuoteService.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index 495ee33..021b3f1 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -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(), ]); }