feat(재고): stock_transactions 입출고 거래 이력 테이블 추가
- stock_transactions 마이그레이션 생성 (type, qty, balance_qty, reference) - StockTransaction 모델 (IN/OUT/RESERVE/RELEASE 타입, 사유 상수) - StockService 5개 메서드에 거래 이력 기록 추가 - increaseFromReceiving → IN - decreaseFIFO → OUT (LOT별) - reserve → RESERVE (LOT별) - releaseReservation → RELEASE (LOT별) - decreaseForShipment → OUT (LOT별) - Stock 모델에 transactions() 관계 추가 - 기존 audit_logs 기록은 유지 (감사 로그와 거래 이력 목적 분리) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* 재고 입출고 거래 이력 테이블
|
||||
*
|
||||
* 모든 재고 변동을 스택으로 쌓아 이력 관리합니다.
|
||||
* audit_logs와 별개로 재고 전용 거래 이력을 제공합니다.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('stock_transactions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
|
||||
|
||||
// 재고 참조
|
||||
$table->unsignedBigInteger('stock_id')->comment('재고 ID');
|
||||
$table->unsignedBigInteger('stock_lot_id')->nullable()->comment('LOT ID (입고/출고 시)');
|
||||
|
||||
// 거래 유형
|
||||
$table->string('type', 20)->comment('거래유형: IN(입고), OUT(출고), RESERVE(예약), RELEASE(예약해제)');
|
||||
|
||||
// 수량
|
||||
$table->decimal('qty', 15, 3)->comment('변동 수량 (양수: 증가, 음수: 감소)');
|
||||
$table->decimal('balance_qty', 15, 3)->comment('거래 후 재고 잔량');
|
||||
|
||||
// 참조 정보 (다형성)
|
||||
$table->string('reference_type', 50)->nullable()->comment('참조 유형: receiving, work_order, shipment, order');
|
||||
$table->unsignedBigInteger('reference_id')->nullable()->comment('참조 ID');
|
||||
|
||||
// 상세 정보
|
||||
$table->string('lot_no', 50)->nullable()->comment('LOT번호');
|
||||
$table->string('reason', 50)->nullable()->comment('사유: receiving, work_order_input, shipment, order_confirm, order_cancel');
|
||||
$table->string('remark', 500)->nullable()->comment('비고');
|
||||
|
||||
// 품목 스냅샷 (조회 성능용)
|
||||
$table->string('item_code', 50)->comment('품목코드');
|
||||
$table->string('item_name', 200)->comment('품목명');
|
||||
|
||||
// 감사 정보
|
||||
$table->unsignedBigInteger('created_by')->nullable()->comment('생성자');
|
||||
$table->timestamp('created_at')->useCurrent()->comment('생성일시');
|
||||
|
||||
// 인덱스
|
||||
$table->index('tenant_id');
|
||||
$table->index('stock_id');
|
||||
$table->index('stock_lot_id');
|
||||
$table->index('type');
|
||||
$table->index('reference_type');
|
||||
$table->index(['stock_id', 'created_at']);
|
||||
$table->index(['tenant_id', 'item_code']);
|
||||
$table->index(['tenant_id', 'type', 'created_at']);
|
||||
$table->index(['reference_type', 'reference_id']);
|
||||
|
||||
// 외래키
|
||||
$table->foreign('stock_id')->references('id')->on('stocks')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('stock_transactions');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user