[FIX] 修復所有 E2E 模組測試的標題定位器以及將測試帳號還原為 admin 權限
All checks were successful
ERP-Deploy-Demo / deploy-demo (push) Successful in 55s
All checks were successful
ERP-Deploy-Demo / deploy-demo (push) Successful in 55s
This commit is contained in:
@@ -53,15 +53,22 @@ class StoreRequisitionService
|
||||
// 靜默建立以抑制自動日誌
|
||||
$requisition->saveQuietly();
|
||||
|
||||
$itemsToInsert = [];
|
||||
$productIds = collect($items)->pluck('product_id')->unique()->toArray();
|
||||
$products = \App\Modules\Inventory\Models\Product::whereIn('id', $productIds)->get()->keyBy('id');
|
||||
|
||||
$diff = ['added' => [], 'removed' => [], 'updated' => []];
|
||||
foreach ($items as $item) {
|
||||
$requisition->items()->create([
|
||||
$itemsToInsert[] = [
|
||||
'store_requisition_id' => $requisition->id,
|
||||
'product_id' => $item['product_id'],
|
||||
'requested_qty' => $item['requested_qty'],
|
||||
'remark' => $item['remark'] ?? null,
|
||||
]);
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
|
||||
$product = \App\Modules\Inventory\Models\Product::find($item['product_id']);
|
||||
$product = $products->get($item['product_id']);
|
||||
$diff['added'][] = [
|
||||
'product_name' => $product?->name ?? '未知商品',
|
||||
'new' => [
|
||||
@@ -70,6 +77,7 @@ class StoreRequisitionService
|
||||
]
|
||||
];
|
||||
}
|
||||
StoreRequisitionItem::insert($itemsToInsert);
|
||||
|
||||
// 如果需直接提交,觸發通知
|
||||
if ($submitImmediately) {
|
||||
@@ -179,13 +187,18 @@ class StoreRequisitionService
|
||||
|
||||
// 儲存實際變動
|
||||
$requisition->items()->delete();
|
||||
$itemsToInsert = [];
|
||||
foreach ($items as $item) {
|
||||
$requisition->items()->create([
|
||||
$itemsToInsert[] = [
|
||||
'store_requisition_id' => $requisition->id,
|
||||
'product_id' => $item['product_id'],
|
||||
'requested_qty' => $item['requested_qty'],
|
||||
'remark' => $item['remark'] ?? null,
|
||||
]);
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
StoreRequisitionItem::insert($itemsToInsert);
|
||||
|
||||
// 檢查是否有任何變動 (主表或明細)
|
||||
$isDirty = $requisition->isDirty();
|
||||
@@ -314,6 +327,7 @@ class StoreRequisitionService
|
||||
$supplyWarehouseId = $requisition->supply_warehouse_id;
|
||||
$totalAvailable = \App\Modules\Inventory\Models\Inventory::where('warehouse_id', $supplyWarehouseId)
|
||||
->where('product_id', $reqItem->product_id)
|
||||
->lockForUpdate() // 補上鎖定
|
||||
->selectRaw('SUM(quantity - reserved_quantity) as available')
|
||||
->value('available') ?? 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user