From 7eb5825d4108364382b5ee04bfbb19d86e50b044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Sun, 22 Feb 2026 03:50:24 +0900 Subject: [PATCH] =?UTF-8?q?fix(WEB):=20=EC=9E=85=EA=B3=A0=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20=EC=A0=80=EC=9E=A5=20=EC=98=A4=EB=A5=98=203?= =?UTF-8?q?=EA=B1=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FormRequest에 manufacturer, material_no 규칙 추가 (validated()에서 누락 방지) - store() 시 lot_no 자동 생성 (generateLotNo() 폴백) - getOrCreateStock()에서 item_code 기반 2차 검색 추가 (unique key 충돌 방지) - 동일 item_code, 다른 item_id인 Stock 존재 시 item_id 업데이트 - SoftDeletes 복원 로직 포함 Co-Authored-By: Claude Opus 4.6 --- .../V1/Receiving/StoreReceivingRequest.php | 2 ++ .../V1/Receiving/UpdateReceivingRequest.php | 2 ++ app/Services/ReceivingService.php | 2 +- app/Services/StockService.php | 31 ++++++++++++++++--- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/app/Http/Requests/V1/Receiving/StoreReceivingRequest.php b/app/Http/Requests/V1/Receiving/StoreReceivingRequest.php index 56594ee..56904de 100644 --- a/app/Http/Requests/V1/Receiving/StoreReceivingRequest.php +++ b/app/Http/Requests/V1/Receiving/StoreReceivingRequest.php @@ -29,6 +29,8 @@ public function rules(): array 'lot_no' => ['nullable', 'string', 'max:50'], 'status' => ['nullable', 'string', 'in:order_completed,shipping,inspection_pending,receiving_pending'], 'remark' => ['nullable', 'string', 'max:1000'], + 'manufacturer' => ['nullable', 'string', 'max:100'], + 'material_no' => ['nullable', 'string', 'max:50'], ]; } diff --git a/app/Http/Requests/V1/Receiving/UpdateReceivingRequest.php b/app/Http/Requests/V1/Receiving/UpdateReceivingRequest.php index 61e2de9..4273062 100644 --- a/app/Http/Requests/V1/Receiving/UpdateReceivingRequest.php +++ b/app/Http/Requests/V1/Receiving/UpdateReceivingRequest.php @@ -31,6 +31,8 @@ public function rules(): array 'inspection_status' => ['nullable', 'string', 'max:10'], 'inspection_date' => ['nullable', 'date'], 'inspection_result' => ['nullable', 'string', 'max:20'], + 'manufacturer' => ['nullable', 'string', 'max:100'], + 'material_no' => ['nullable', 'string', 'max:50'], ]; } diff --git a/app/Services/ReceivingService.php b/app/Services/ReceivingService.php index ed005c6..6ecf6ff 100644 --- a/app/Services/ReceivingService.php +++ b/app/Services/ReceivingService.php @@ -199,7 +199,7 @@ public function store(array $data): Receiving $receiving->due_date = $data['due_date'] ?? null; $receiving->receiving_qty = $data['receiving_qty'] ?? null; $receiving->receiving_date = $data['receiving_date'] ?? null; - $receiving->lot_no = $data['lot_no'] ?? null; + $receiving->lot_no = $data['lot_no'] ?? $this->generateLotNo(); $receiving->status = $data['status'] ?? 'receiving_pending'; $receiving->remark = $data['remark'] ?? null; diff --git a/app/Services/StockService.php b/app/Services/StockService.php index e3569cf..d980a30 100644 --- a/app/Services/StockService.php +++ b/app/Services/StockService.php @@ -525,18 +525,41 @@ public function getOrCreateStock(int $itemId, ?Receiving $receiving = null): Sto $tenantId = $this->tenantId(); $userId = $this->apiUserId(); - $stock = Stock::where('tenant_id', $tenantId) + $item = Item::where('tenant_id', $tenantId) + ->findOrFail($itemId); + + // 1차: item_id로 조회 (SoftDeletes 포함) + $stock = Stock::withTrashed() + ->where('tenant_id', $tenantId) ->where('item_id', $itemId) ->first(); + // 2차: item_code로 조회 (unique key 기준, item_id가 다를 수 있음) + if (! $stock) { + $stock = Stock::withTrashed() + ->where('tenant_id', $tenantId) + ->where('item_code', $item->code) + ->first(); + + // item_id가 변경된 경우 업데이트 + if ($stock && $stock->item_id !== $itemId) { + $stock->item_id = $itemId; + } + } + if ($stock) { + if ($stock->trashed()) { + $stock->restore(); + $stock->status = 'out'; + } + $stock->item_name = $item->name; + $stock->updated_by = $userId; + $stock->save(); + return $stock; } // Stock이 없으면 새로 생성 - $item = Item::where('tenant_id', $tenantId) - ->findOrFail($itemId); - $stock = new Stock; $stock->tenant_id = $tenantId; $stock->item_id = $itemId;