feat: 수주(Order) ↔ 매출(Sale) 연동 스키마 구현

- sales 테이블: order_id, shipment_id, source_type 컬럼 추가
- orders 테이블: sales_recognition, sale_id 컬럼 추가
- Sale 모델: order(), shipment() 관계 및 createFromOrder/Shipment 팩토리 메서드
- Order 모델: sale(), sales() 관계 및 shouldCreateSaleOnConfirm/Shipment 헬퍼
- 매출 인식 시점: 수주확정 시 / 출하완료 시 / 수동 선택 가능

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-22 17:23:36 +09:00
parent d186a0c111
commit c8d7990313
4 changed files with 224 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* 매출-수주 연동을 위한 컬럼 추가
*
* - order_id: 수주 연결
* - shipment_id: 출하 연결
* - source_type: 매출 생성 시점 (order_confirm/shipment_complete)
*/
return new class extends Migration
{
public function up(): void
{
Schema::table('sales', function (Blueprint $table) {
$table->unsignedBigInteger('order_id')->nullable()->after('tenant_id')->comment('수주 ID');
$table->unsignedBigInteger('shipment_id')->nullable()->after('order_id')->comment('출하 ID');
$table->string('source_type', 30)->nullable()->after('status')->comment('매출 생성 시점: order_confirm/shipment_complete/manual');
// 인덱스
$table->index('order_id', 'idx_sales_order_id');
$table->index('shipment_id', 'idx_sales_shipment_id');
$table->index('source_type', 'idx_sales_source_type');
});
}
public function down(): void
{
Schema::table('sales', function (Blueprint $table) {
$table->dropIndex('idx_sales_order_id');
$table->dropIndex('idx_sales_shipment_id');
$table->dropIndex('idx_sales_source_type');
$table->dropColumn(['order_id', 'shipment_id', 'source_type']);
});
}
};

View File

@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* 수주별 매출 인식 시점 설정 컬럼 추가
*
* - sales_recognition: 매출 생성 시점 설정
* - on_order_confirm: 수주확정 시 매출 생성
* - on_shipment: 출하완료 시 매출 생성 (기본값)
* - manual: 수동 등록
*/
return new class extends Migration
{
public function up(): void
{
Schema::table('orders', function (Blueprint $table) {
$table->string('sales_recognition', 20)->default('on_shipment')->after('options')->comment('매출 인식 시점: on_order_confirm/on_shipment/manual');
$table->unsignedBigInteger('sale_id')->nullable()->after('sales_recognition')->comment('연결된 매출 ID');
// 인덱스
$table->index('sales_recognition', 'idx_orders_sales_recognition');
$table->index('sale_id', 'idx_orders_sale_id');
});
}
public function down(): void
{
Schema::table('orders', function (Blueprint $table) {
$table->dropIndex('idx_orders_sales_recognition');
$table->dropIndex('idx_orders_sale_id');
$table->dropColumn(['sales_recognition', 'sale_id']);
});
}
};