From ecfe389420fb027ea77c85b21555983b5ff7687e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Tue, 17 Mar 2026 19:45:08 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[receiving]=20=EC=9B=90=EC=9E=90?= =?UTF-8?q?=EC=9E=AC=EB=A1=9C=ED=8A=B8=EB=B2=88=ED=98=B8=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - rand() 기반 → DB 시퀀스 기반으로 변경 (중복 방지) - 5130 레거시 방식 차용: YYMMDD-NN (일별 시퀀스, 01부터) - 테넌트별 격리 적용 --- app/Services/ReceivingService.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/app/Services/ReceivingService.php b/app/Services/ReceivingService.php index 2b2c78ca..4948f23b 100644 --- a/app/Services/ReceivingService.php +++ b/app/Services/ReceivingService.php @@ -427,16 +427,29 @@ private function generateReceivingNumber(int $tenantId): string /** * LOT번호 자동 생성 + * + * 5130 레거시 차용: YYMMDD-NN (일별 시퀀스, 01부터 시작) + * 개선: 파일 기반 → DB 기반 (테넌트별 격리, 동시성 안전) */ private function generateLotNo(): string { - $now = now(); - $year = $now->format('y'); - $month = $now->format('m'); - $day = $now->format('d'); - $seq = str_pad(rand(1, 99), 2, '0', STR_PAD_LEFT); + $tenantId = $this->tenantId(); + $prefix = now()->format('ymd'); // 예: 260317 - return "{$year}{$month}{$day}-{$seq}"; + $lastReceiving = Receiving::query() + ->where('tenant_id', $tenantId) + ->where('lot_no', 'like', $prefix.'-%') + ->orderBy('lot_no', 'desc') + ->first(['lot_no']); + + if ($lastReceiving) { + $lastSeq = (int) substr($lastReceiving->lot_no, -2); + $newSeq = $lastSeq + 1; + } else { + $newSeq = 1; + } + + return $prefix.'-'.str_pad($newSeq, 2, '0', STR_PAD_LEFT); } /**