feat(API): 견적-주문 연동 필드 및 마이그레이션 추가
- Order, OrderItem 모델에 견적 연동 필드 추가 - Quote 모델에 order_id 관계 추가 - QuoteService 개선 - 관련 마이그레이션 파일 추가 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 수주 상세(order_items)에 금액 및 품목 정보 필드 추가
|
||||
* - 견적 → 수주 전환 시 품목별 금액 정보 저장
|
||||
* - 생산/출하/정산 플로우에서 품목별 추적 가능
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('order_items', function (Blueprint $table) {
|
||||
// 품목 정보 (quote_items와 동일 구조)
|
||||
$table->string('item_code', 50)->nullable()->after('item_id')->comment('품목코드');
|
||||
$table->string('item_name', 200)->nullable()->after('item_code')->comment('품명');
|
||||
$table->string('specification', 100)->nullable()->after('item_name')->comment('규격');
|
||||
$table->string('unit', 20)->default('EA')->after('specification')->comment('단위');
|
||||
|
||||
// 금액 정보
|
||||
$table->decimal('unit_price', 15, 2)->default(0)->after('quantity')->comment('단가');
|
||||
$table->decimal('supply_amount', 15, 2)->default(0)->after('unit_price')->comment('공급가액');
|
||||
$table->decimal('tax_amount', 15, 2)->default(0)->after('supply_amount')->comment('세액');
|
||||
$table->decimal('total_amount', 15, 2)->default(0)->after('tax_amount')->comment('금액 (공급가액 + 세액)');
|
||||
|
||||
// 할인 정보
|
||||
$table->decimal('discount_rate', 5, 2)->default(0)->after('total_amount')->comment('할인율 (%)');
|
||||
$table->decimal('discount_amount', 15, 2)->default(0)->after('discount_rate')->comment('할인금액');
|
||||
|
||||
// 추가 정보
|
||||
$table->text('note')->nullable()->after('remarks')->comment('비고');
|
||||
$table->unsignedInteger('sort_order')->default(0)->after('note')->comment('정렬순서');
|
||||
|
||||
// 견적 연결 (추적용)
|
||||
$table->unsignedBigInteger('quote_id')->nullable()->after('order_id')->comment('원본 견적 ID');
|
||||
$table->unsignedBigInteger('quote_item_id')->nullable()->after('quote_id')->comment('원본 견적 품목 ID');
|
||||
|
||||
// 인덱스
|
||||
$table->index('item_code', 'idx_order_items_item_code');
|
||||
$table->index('quote_id', 'idx_order_items_quote_id');
|
||||
$table->index('sort_order', 'idx_order_items_sort_order');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('order_items', function (Blueprint $table) {
|
||||
// 인덱스 삭제
|
||||
$table->dropIndex('idx_order_items_item_code');
|
||||
$table->dropIndex('idx_order_items_quote_id');
|
||||
$table->dropIndex('idx_order_items_sort_order');
|
||||
|
||||
// 컬럼 삭제
|
||||
$table->dropColumn([
|
||||
'item_code',
|
||||
'item_name',
|
||||
'specification',
|
||||
'unit',
|
||||
'unit_price',
|
||||
'supply_amount',
|
||||
'tax_amount',
|
||||
'total_amount',
|
||||
'discount_rate',
|
||||
'discount_amount',
|
||||
'note',
|
||||
'sort_order',
|
||||
'quote_id',
|
||||
'quote_item_id',
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* 수주(orders)에 견적 연결 및 금액 필드 추가
|
||||
* - 견적 → 수주 전환 시 견적 정보 및 금액 저장
|
||||
* - 수주 기반 생산/출하 플로우 지원
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('orders', function (Blueprint $table) {
|
||||
// 견적 연결 (추적용)
|
||||
$table->unsignedBigInteger('quote_id')->nullable()->after('tenant_id')->comment('원본 견적 ID');
|
||||
|
||||
// 거래처 정보 (비정규화 - 조회 성능)
|
||||
$table->string('client_name', 200)->nullable()->after('client_id')->comment('거래처명');
|
||||
|
||||
// 금액 정보 (합계)
|
||||
$table->decimal('supply_amount', 15, 2)->default(0)->after('quantity')->comment('공급가액 합계');
|
||||
$table->decimal('tax_amount', 15, 2)->default(0)->after('supply_amount')->comment('세액 합계');
|
||||
$table->decimal('total_amount', 15, 2)->default(0)->after('tax_amount')->comment('총액 (공급가액 + 세액)');
|
||||
|
||||
// 할인 정보
|
||||
$table->decimal('discount_rate', 5, 2)->default(0)->after('total_amount')->comment('할인율 (%)');
|
||||
$table->decimal('discount_amount', 15, 2)->default(0)->after('discount_rate')->comment('할인금액');
|
||||
|
||||
// 추가 정보
|
||||
$table->text('remarks')->nullable()->after('memo')->comment('비고');
|
||||
$table->text('note')->nullable()->after('remarks')->comment('내부 메모');
|
||||
|
||||
// 인덱스
|
||||
$table->index('quote_id', 'idx_orders_quote_id');
|
||||
$table->index('client_name', 'idx_orders_client_name');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('orders', function (Blueprint $table) {
|
||||
// 인덱스 삭제
|
||||
$table->dropIndex('idx_orders_quote_id');
|
||||
$table->dropIndex('idx_orders_client_name');
|
||||
|
||||
// 컬럼 삭제
|
||||
$table->dropColumn([
|
||||
'quote_id',
|
||||
'client_name',
|
||||
'supply_amount',
|
||||
'tax_amount',
|
||||
'total_amount',
|
||||
'discount_rate',
|
||||
'discount_amount',
|
||||
'remarks',
|
||||
'note',
|
||||
]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
{
|
||||
/**
|
||||
* 견적(quotes)에 수주 연결 필드 추가
|
||||
* - 견적 → 수주 전환 시 생성된 수주 ID 저장
|
||||
* - 전환된 견적 추적용
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('quotes', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('order_id')->nullable()->after('tenant_id')->comment('전환된 수주 ID');
|
||||
|
||||
$table->index('order_id', 'idx_quotes_order_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('quotes', function (Blueprint $table) {
|
||||
$table->dropIndex('idx_quotes_order_id');
|
||||
$table->dropColumn('order_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user