From e1d0c2ef44ab6e1d598d59a1c8d19e86c0a6ca5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Sat, 21 Mar 2026 11:22:00 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[bending]=20=EA=B8=B0=EC=B4=88=EC=9E=90?= =?UTF-8?q?=EB=A3=8C=20=EC=BD=94=EB=93=9C=20=ED=95=AD=EC=83=81=20.001?= =?UTF-8?q?=EB=B6=80=ED=84=B0=20=EC=8B=9C=EC=9E=91=20=E2=80=94=20.001?= =?UTF-8?q?=EC=9D=B4=20=EB=8C=80=ED=91=9C(=ED=91=9C=EC=A4=80)=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/BendingItemService.php | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/app/Services/BendingItemService.php b/app/Services/BendingItemService.php index 7b290cfe..5bb6f147 100644 --- a/app/Services/BendingItemService.php +++ b/app/Services/BendingItemService.php @@ -146,40 +146,25 @@ private function buildOptions(array $data): ?array /** * 기초자료 코드 자동 채번 * - * BD-XX : 표준 형상 (재공품 코드 앞 5자리와 동일) - * BD-XX.nnn : 표준 대비 변형 (주문 수정 형상, 최대 999종) + * BD-XX.001 : 대표(표준) 형상 — 재공품 코드(BD-XX-길이)의 기준 + * BD-XX.002~: 표준 대비 변형 (주문 수정 형상, 최대 999종) * - * 첫 등록 → BD-XX (표준), 이후 → BD-XX.001~ (변형) + * 항상 .001부터 시작, .001 = 대표 번호 */ private function generateCode(string $prefix): string { $prefix = strtoupper($prefix); - // BD-XX.nnn 형태 중 가장 큰 순번 조회 - $lastDotCode = BendingItem::withoutGlobalScopes() + $lastCode = BendingItem::withoutGlobalScopes() ->where('code', 'like', "BD-{$prefix}.%") ->orderByRaw('CAST(SUBSTRING(code, ?) AS UNSIGNED) DESC', [strlen("BD-{$prefix}.") + 1]) ->value('code'); - // BD-XX (표준 형상) 존재 여부 - $plainExists = BendingItem::withoutGlobalScopes() - ->where('code', "BD-{$prefix}") - ->exists(); - - if (! $lastDotCode && ! $plainExists) { - // 해당 분류 첫 등록 → BD-XX (표준 형상) - return "BD-{$prefix}"; + $nextSeq = 1; + if ($lastCode && preg_match('/\.(\d+)$/', $lastCode, $m)) { + $nextSeq = (int) $m[1] + 1; } - if ($plainExists && ! $lastDotCode) { - // 표준만 있고 변형 없음 → 변형 001번 부여 - return "BD-{$prefix}.001"; - } - - // 변형이 이미 있음 → 마지막 +1 - preg_match('/\.(\d+)$/', $lastDotCode, $m); - $nextSeq = (int) ($m[1] ?? 0) + 1; - return "BD-{$prefix}.".str_pad($nextSeq, 3, '0', STR_PAD_LEFT); }