[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:
@@ -254,17 +254,21 @@ class PurchaseOrderController extends Controller
|
||||
$productIds = collect($validated['items'])->pluck('productId')->unique()->toArray();
|
||||
$products = $this->inventoryService->getProductsByIds($productIds)->keyBy('id');
|
||||
|
||||
$itemsToInsert = [];
|
||||
foreach ($validated['items'] as $item) {
|
||||
// 反算單價
|
||||
$unitPrice = $item['quantity'] > 0 ? $item['subtotal'] / $item['quantity'] : 0;
|
||||
|
||||
$order->items()->create([
|
||||
$itemsToInsert[] = [
|
||||
'purchase_order_id' => $order->id,
|
||||
'product_id' => $item['productId'],
|
||||
'quantity' => $item['quantity'],
|
||||
'unit_id' => $item['unitId'] ?? null,
|
||||
'unit_price' => $unitPrice,
|
||||
'subtotal' => $item['subtotal'],
|
||||
]);
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
|
||||
$product = $products->get($item['productId']);
|
||||
$diff['added'][] = [
|
||||
@@ -275,6 +279,7 @@ class PurchaseOrderController extends Controller
|
||||
]
|
||||
];
|
||||
}
|
||||
\App\Modules\Procurement\Models\PurchaseOrderItem::insert($itemsToInsert);
|
||||
|
||||
// 手動發送高品質日誌(包含品項明細)
|
||||
activity()
|
||||
@@ -468,7 +473,8 @@ class PurchaseOrderController extends Controller
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$order = PurchaseOrder::findOrFail($id);
|
||||
// 加上 lockForUpdate() 防止併發修改
|
||||
$order = PurchaseOrder::lockForUpdate()->findOrFail($id);
|
||||
|
||||
$validated = $request->validate([
|
||||
'vendor_id' => 'required|exists:vendors,id',
|
||||
@@ -572,20 +578,23 @@ class PurchaseOrderController extends Controller
|
||||
// 同步項目(原始邏輯)
|
||||
$order->items()->delete();
|
||||
|
||||
$newItemsData = [];
|
||||
$itemsToInsert = [];
|
||||
foreach ($validated['items'] as $item) {
|
||||
// 反算單價
|
||||
$unitPrice = $item['quantity'] > 0 ? $item['subtotal'] / $item['quantity'] : 0;
|
||||
|
||||
$newItem = $order->items()->create([
|
||||
$itemsToInsert[] = [
|
||||
'purchase_order_id' => $order->id,
|
||||
'product_id' => $item['productId'],
|
||||
'quantity' => $item['quantity'],
|
||||
'unit_id' => $item['unitId'] ?? null,
|
||||
'unit_price' => $unitPrice,
|
||||
'subtotal' => $item['subtotal'],
|
||||
]);
|
||||
$newItemsData[] = $newItem;
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
\App\Modules\Procurement\Models\PurchaseOrderItem::insert($itemsToInsert);
|
||||
|
||||
// 3. 計算項目差異
|
||||
$itemDiffs = [
|
||||
|
||||
Reference in New Issue
Block a user