fix: clients 테이블 ENUM→VARCHAR 정규화 및 common_codes 연동

- client_type, bad_debt_progress 컬럼을 ENUM에서 VARCHAR로 변경
- 기존 한글값을 common_codes의 code값으로 데이터 마이그레이션
- FormRequest에 prepareForValidation() 추가로 프론트 호환성 유지
  - 한글 입력 시 자동으로 code 변환 (매입 → PURCHASE)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-21 16:05:54 +09:00
parent f1827450bd
commit 756d08be09
3 changed files with 184 additions and 0 deletions

View File

@@ -12,6 +12,43 @@ public function authorize(): bool
return true;
}
protected function prepareForValidation(): void
{
$this->convertCommonCodeNameToCode('client_type');
$this->convertCommonCodeNameToCode('bad_debt_progress');
}
/**
* common_codes의 name을 code로 변환
*/
private function convertCommonCodeNameToCode(string $field): void
{
$value = $this->input($field);
if (! $value) {
return;
}
// 이미 code인지 확인
$existsAsCode = \DB::table('common_codes')
->where('code_group', $field)
->where('code', $value)
->exists();
if ($existsAsCode) {
return;
}
// name으로 code 조회
$code = \DB::table('common_codes')
->where('code_group', $field)
->where('name', $value)
->value('code');
if ($code) {
$this->merge([$field => $code]);
}
}
public function rules(): array
{
return [

View File

@@ -12,6 +12,43 @@ public function authorize(): bool
return true;
}
protected function prepareForValidation(): void
{
$this->convertCommonCodeNameToCode('client_type');
$this->convertCommonCodeNameToCode('bad_debt_progress');
}
/**
* common_codes의 name을 code로 변환
*/
private function convertCommonCodeNameToCode(string $field): void
{
$value = $this->input($field);
if (! $value) {
return;
}
// 이미 code인지 확인
$existsAsCode = \DB::table('common_codes')
->where('code_group', $field)
->where('code', $value)
->exists();
if ($existsAsCode) {
return;
}
// name으로 code 조회
$code = \DB::table('common_codes')
->where('code_group', $field)
->where('name', $value)
->value('code');
if ($code) {
$this->merge([$field => $code]);
}
}
public function rules(): array
{
return [