2025-12-30 15:03:19 +08:00
|
|
|
<?php
|
|
|
|
|
|
2026-01-26 10:37:47 +08:00
|
|
|
namespace App\Modules\Inventory\Models;
|
2025-12-30 15:03:19 +08:00
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-01-26 14:59:24 +08:00
|
|
|
use App\Modules\Core\Models\User; // 跨模組核心依賴
|
2025-12-30 15:03:19 +08:00
|
|
|
|
|
|
|
|
class InventoryTransaction extends Model
|
|
|
|
|
{
|
|
|
|
|
/** @use HasFactory<\Database\Factories\InventoryTransactionFactory> */
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'inventory_id',
|
|
|
|
|
'type',
|
|
|
|
|
'quantity',
|
2026-01-26 17:27:34 +08:00
|
|
|
'unit_cost',
|
2025-12-30 15:03:19 +08:00
|
|
|
'balance_before',
|
|
|
|
|
'balance_after',
|
|
|
|
|
'reason',
|
|
|
|
|
'reference_type',
|
|
|
|
|
'reference_id',
|
|
|
|
|
'user_id',
|
|
|
|
|
'actual_time',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'actual_time' => 'datetime',
|
2026-01-26 17:27:34 +08:00
|
|
|
'unit_cost' => 'decimal:4',
|
2025-12-30 15:03:19 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function inventory(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Inventory::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function reference(): \Illuminate\Database\Eloquent\Relations\MorphTo
|
|
|
|
|
{
|
|
|
|
|
return $this->morphTo();
|
|
|
|
|
}
|
|
|
|
|
}
|