feat: 테넌트별 채번 규칙 시스템 구현

- numbering_rules 테이블: JSON 패턴 기반 채번 규칙 저장 (tenant별)
- numbering_sequences 테이블: MySQL UPSERT 기반 atomic 시퀀스 관리
- NumberingService: generate/preview/nextSequence 핵심 서비스
- QuoteNumberService: NumberingService 우선, 폴백 QT{YYYYMMDD}{NNNN}
- OrderService: NumberingService 우선 (pair_code 지원), 폴백 ORD{YYYYMMDD}{NNNN}
- StoreOrderRequest: pair_code 필드 추가
- NumberingRuleSeeder: tenant_id=287 견적(KD-PR)/수주(KD-{pairCode}) 규칙

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-07 09:50:52 +09:00
parent 6318474b6f
commit 78851ec04a
9 changed files with 475 additions and 44 deletions

View File

@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('numbering_rules', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
$table->string('document_type', 50)->comment('문서유형: quote, order, sale, work_order, material_receipt');
$table->string('rule_name', 100)->nullable()->comment('규칙명 (관리용)');
$table->json('pattern')->comment('패턴 정의 (세그먼트 배열)');
$table->string('reset_period', 20)->default('daily')->comment('시퀀스 리셋 주기: daily, monthly, yearly, never');
$table->integer('sequence_padding')->default(2)->comment('시퀀스 자릿수');
$table->boolean('is_active')->default(true);
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
$table->timestamps();
$table->unique(['tenant_id', 'document_type'], 'uq_tenant_doctype');
$table->index('tenant_id', 'idx_numbering_rules_tenant');
});
}
public function down(): void
{
Schema::dropIfExists('numbering_rules');
}
};

View File

@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('numbering_sequences', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
$table->string('document_type', 50)->comment('문서유형');
$table->string('scope_key', 100)->default('')->comment('범위 키 (카테고리/모델별 구분)');
$table->string('period_key', 20)->comment('기간 키: 260207(daily), 202602(monthly), 2026(yearly)');
$table->unsignedInteger('last_sequence')->default(0)->comment('마지막 시퀀스 번호');
$table->timestamps();
$table->unique(
['tenant_id', 'document_type', 'scope_key', 'period_key'],
'uq_numbering_sequence'
);
});
}
public function down(): void
{
Schema::dropIfExists('numbering_sequences');
}
};

View File

@@ -0,0 +1,58 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class NumberingRuleSeeder extends Seeder
{
public function run(): void
{
$tenantId = 287;
// 견적번호 규칙: KD-PR-{YYMMDD}-{NN}
DB::table('numbering_rules')->updateOrInsert(
['tenant_id' => $tenantId, 'document_type' => 'quote'],
[
'rule_name' => '5130 견적번호',
'pattern' => json_encode([
['type' => 'static', 'value' => 'KD'],
['type' => 'separator', 'value' => '-'],
['type' => 'static', 'value' => 'PR'],
['type' => 'separator', 'value' => '-'],
['type' => 'date', 'format' => 'ymd'],
['type' => 'separator', 'value' => '-'],
['type' => 'sequence'],
]),
'reset_period' => 'daily',
'sequence_padding' => 2,
'is_active' => true,
'created_at' => now(),
'updated_at' => now(),
]
);
// 수주 로트번호 규칙: KD-{pairCode}-{YYMMDD}-{NN}
DB::table('numbering_rules')->updateOrInsert(
['tenant_id' => $tenantId, 'document_type' => 'order'],
[
'rule_name' => '5130 수주 로트번호',
'pattern' => json_encode([
['type' => 'static', 'value' => 'KD'],
['type' => 'separator', 'value' => '-'],
['type' => 'param', 'key' => 'pair_code', 'default' => 'SS'],
['type' => 'separator', 'value' => '-'],
['type' => 'date', 'format' => 'ymd'],
['type' => 'separator', 'value' => '-'],
['type' => 'sequence'],
]),
'reset_period' => 'daily',
'sequence_padding' => 2,
'is_active' => true,
'created_at' => now(),
'updated_at' => now(),
]
);
}
}