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:
114
app/Models/Tenants/StockTransaction.php
Normal file
114
app/Models/Tenants/StockTransaction.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Tenants;
|
||||
|
||||
use App\Traits\BelongsToTenant;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* 재고 입출고 거래 이력
|
||||
*
|
||||
* 모든 재고 변동을 스택으로 기록합니다.
|
||||
* - IN: 입고 (재고 증가)
|
||||
* - OUT: 출고/생산투입 (재고 감소)
|
||||
* - RESERVE: 수주 확정으로 예약
|
||||
* - RELEASE: 수주 취소로 예약 해제
|
||||
*/
|
||||
class StockTransaction extends Model
|
||||
{
|
||||
use BelongsToTenant;
|
||||
|
||||
const UPDATED_AT = null; // updated_at 사용 안함 (이력은 불변)
|
||||
|
||||
// 거래 유형 상수
|
||||
public const TYPE_IN = 'IN';
|
||||
|
||||
public const TYPE_OUT = 'OUT';
|
||||
|
||||
public const TYPE_RESERVE = 'RESERVE';
|
||||
|
||||
public const TYPE_RELEASE = 'RELEASE';
|
||||
|
||||
public const TYPES = [
|
||||
self::TYPE_IN => '입고',
|
||||
self::TYPE_OUT => '출고',
|
||||
self::TYPE_RESERVE => '예약',
|
||||
self::TYPE_RELEASE => '예약해제',
|
||||
];
|
||||
|
||||
// 사유 상수
|
||||
public const REASON_RECEIVING = 'receiving';
|
||||
|
||||
public const REASON_WORK_ORDER_INPUT = 'work_order_input';
|
||||
|
||||
public const REASON_SHIPMENT = 'shipment';
|
||||
|
||||
public const REASON_ORDER_CONFIRM = 'order_confirm';
|
||||
|
||||
public const REASON_ORDER_CANCEL = 'order_cancel';
|
||||
|
||||
public const REASONS = [
|
||||
self::REASON_RECEIVING => '입고',
|
||||
self::REASON_WORK_ORDER_INPUT => '생산투입',
|
||||
self::REASON_SHIPMENT => '출하',
|
||||
self::REASON_ORDER_CONFIRM => '수주확정',
|
||||
self::REASON_ORDER_CANCEL => '수주취소',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'tenant_id',
|
||||
'stock_id',
|
||||
'stock_lot_id',
|
||||
'type',
|
||||
'qty',
|
||||
'balance_qty',
|
||||
'reference_type',
|
||||
'reference_id',
|
||||
'lot_no',
|
||||
'reason',
|
||||
'remark',
|
||||
'item_code',
|
||||
'item_name',
|
||||
'created_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'stock_id' => 'integer',
|
||||
'stock_lot_id' => 'integer',
|
||||
'qty' => 'decimal:3',
|
||||
'balance_qty' => 'decimal:3',
|
||||
'reference_id' => 'integer',
|
||||
'created_by' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
|
||||
// ===== 관계 =====
|
||||
|
||||
public function stock(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Stock::class);
|
||||
}
|
||||
|
||||
public function stockLot(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(StockLot::class);
|
||||
}
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Members\User::class, 'created_by');
|
||||
}
|
||||
|
||||
// ===== Accessors =====
|
||||
|
||||
public function getTypeLabelAttribute(): string
|
||||
{
|
||||
return self::TYPES[$this->type] ?? $this->type;
|
||||
}
|
||||
|
||||
public function getReasonLabelAttribute(): string
|
||||
{
|
||||
return self::REASONS[$this->reason] ?? ($this->reason ?? '-');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user