優化門市叫貨流程:實作庫存預扣機制、鎖定自動產生的調撥單明細、修復自動販賣機貨道數量連動 Bug 及狀態同步問題
All checks were successful
ERP-Deploy-Demo / deploy-demo (push) Successful in 56s

This commit is contained in:
2026-02-25 17:32:28 +08:00
parent e3df090afd
commit 63e4f88a14
8 changed files with 469 additions and 161 deletions

View File

@@ -17,6 +17,7 @@ class Inventory extends Model
'warehouse_id',
'product_id',
'quantity',
'reserved_quantity',
'location',
'unit_cost',
'total_value',
@@ -34,6 +35,8 @@ class Inventory extends Model
protected $casts = [
'arrival_date' => 'date:Y-m-d',
'expiry_date' => 'date:Y-m-d',
'quantity' => 'decimal:4',
'reserved_quantity' => 'decimal:4',
'unit_cost' => 'decimal:4',
'total_value' => 'decimal:4',
];
@@ -109,7 +112,33 @@ class Inventory extends Model
});
}
/**
* 可用庫存(實體庫存 - 預留庫存)
*/
public function getAvailableQuantityAttribute()
{
return max(0, $this->quantity - $this->reserved_quantity);
}
/**
* 增加預留庫存(鎖定)
*/
public function reserveQuantity(float|int $amount)
{
if ($amount <= 0) return;
$this->reserved_quantity += $amount;
$this->save();
}
/**
* 釋放預留庫存(解鎖)
*/
public function releaseReservedQuantity(float|int $amount)
{
if ($amount <= 0) return;
$this->reserved_quantity = max(0, $this->reserved_quantity - $amount);
$this->save();
}
/**
* 產生批號