'integer', 'receipt_date' => 'date', 'qty' => 'decimal:3', 'reserved_qty' => 'decimal:3', 'available_qty' => 'decimal:3', 'stock_id' => 'integer', 'receiving_id' => 'integer', ]; /** * LOT 상태 목록 */ public const STATUSES = [ 'available' => '사용가능', 'reserved' => '예약됨', 'used' => '사용완료', ]; /** * 재고 관계 */ public function stock(): BelongsTo { return $this->belongsTo(Stock::class); } /** * 입고 관계 */ public function receiving(): BelongsTo { return $this->belongsTo(Receiving::class); } /** * 생성자 관계 */ public function creator(): BelongsTo { return $this->belongsTo(\App\Models\Members\User::class, 'created_by'); } /** * 상태 라벨 */ public function getStatusLabelAttribute(): string { return self::STATUSES[$this->status] ?? $this->status; } /** * 경과일 */ public function getDaysElapsedAttribute(): int { return $this->receipt_date->diffInDays(now()); } /** * 가용 수량 업데이트 */ public function updateAvailableQty(): void { $this->available_qty = $this->qty - $this->reserved_qty; if ($this->available_qty <= 0 && $this->qty <= 0) { $this->status = 'used'; } elseif ($this->reserved_qty > 0) { $this->status = 'reserved'; } else { $this->status = 'available'; } $this->save(); } }