From 3a40db944493fab604b592560d20cf52a01c04f3 Mon Sep 17 00:00:00 2001 From: kent Date: Mon, 12 Jan 2026 16:14:09 +0900 Subject: [PATCH] =?UTF-8?q?fix(order):=20=EC=88=98=EC=A3=BC=20API=20500=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - show(): clients 테이블 컬럼명 수정 (business_no,representative → contact_person) - store/update/createFromQuote(): order_items에 tenant_id, serial_no 필드 추가 - index(): quote eager loading 추가 Co-Authored-By: Claude Opus 4.5 --- app/Services/OrderService.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/Services/OrderService.php b/app/Services/OrderService.php index 274c9b0..80aa562 100644 --- a/app/Services/OrderService.php +++ b/app/Services/OrderService.php @@ -29,7 +29,7 @@ public function index(array $params) $query = Order::query() ->where('tenant_id', $tenantId) - ->with(['client:id,name', 'items']); + ->with(['client:id,name', 'items', 'quote:id,quote_number']); // 검색어 (수주번호, 현장명, 거래처명) if ($q !== '') { @@ -108,7 +108,7 @@ public function show(int $id) $order = Order::where('tenant_id', $tenantId) ->with([ - 'client:id,name,business_no,representative,phone,email', + 'client:id,name,contact_person,phone,email', 'items' => fn ($q) => $q->orderBy('sort_order'), 'quote:id,quote_number,site_name', ]) @@ -147,6 +147,8 @@ public function store(array $data) // 품목 저장 foreach ($items as $index => $item) { + $item['tenant_id'] = $tenantId; + $item['serial_no'] = $index + 1; // 1부터 시작하는 순번 $item['sort_order'] = $index; $this->calculateItemAmounts($item); $order->items()->create($item); @@ -178,7 +180,7 @@ public function update(int $id, array $data) throw new BadRequestHttpException(__('error.order.cannot_update_completed')); } - return DB::transaction(function () use ($order, $data, $userId) { + return DB::transaction(function () use ($order, $data, $tenantId, $userId) { $data['updated_by'] = $userId; $items = $data['items'] ?? null; @@ -190,6 +192,8 @@ public function update(int $id, array $data) if ($items !== null) { $order->items()->delete(); foreach ($items as $index => $item) { + $item['tenant_id'] = $tenantId; + $item['serial_no'] = $index + 1; // 1부터 시작하는 순번 $item['sort_order'] = $index; $this->calculateItemAmounts($item); $order->items()->create($item); @@ -370,6 +374,8 @@ public function createFromQuote(int $quoteId, array $data = []) // 견적 품목을 수주 품목으로 변환 foreach ($quote->items as $index => $quoteItem) { $order->items()->create([ + 'tenant_id' => $tenantId, + 'serial_no' => $index + 1, // 1부터 시작하는 순번 'item_id' => $quoteItem->item_id, 'item_name' => $quoteItem->item_name, 'specification' => $quoteItem->specification,