fix: [receiving] 원자재로트번호 생성 로직 개선

- rand() 기반 → DB 시퀀스 기반으로 변경 (중복 방지)
- 5130 레거시 방식 차용: YYMMDD-NN (일별 시퀀스, 01부터)
- 테넌트별 격리 적용
This commit is contained in:
김보곤
2026-03-17 19:45:08 +09:00
parent e83d0e90ff
commit ecfe389420

View File

@@ -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);
}
/**