Files
star-erp/app/Modules/Inventory/Models/InventoryTransaction.php

45 lines
1.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Modules\Inventory\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class InventoryTransaction extends Model
{
/** @use HasFactory<\Database\Factories\InventoryTransactionFactory> */
use HasFactory;
protected $fillable = [
'inventory_id',
'type',
'quantity',
'unit_cost',
'balance_before',
'balance_after',
'reason',
'reference_type',
'reference_id',
'user_id',
'actual_time',
];
protected $casts = [
// actual_time 不做時區轉換,保留原始字串格式(台北時間)
// 原因:資料庫儲存的是台北時間,但 MySQL 時區為 UTC
// 若使用 datetime castLaravel 會誤當作 UTC 再轉回台北時間,造成偏移
'unit_cost' => 'decimal:4',
];
public function inventory(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Inventory::class);
}
public function reference(): \Illuminate\Database\Eloquent\Relations\MorphTo
{
return $this->morphTo();
}
}