feat(inventory): 販賣機視覺優化、修復匯入日期缺失與倉庫刪除權限錯誤
This commit is contained in:
@@ -31,7 +31,51 @@ class SafetyStockController extends Controller
|
||||
];
|
||||
});
|
||||
|
||||
// 準備現有庫存列表 (用於庫存量對比)
|
||||
// 獲取現有庫存 (用於抓取「已在倉庫中」的商品)
|
||||
$inventoryProductIds = Inventory::where('warehouse_id', $warehouse->id)->pluck('product_id')->unique();
|
||||
|
||||
// 準備安全庫存設定列表 (從資料庫讀取)
|
||||
$existingSettings = WarehouseProductSafetyStock::where('warehouse_id', $warehouse->id)
|
||||
->with(['product.category', 'product.baseUnit'])
|
||||
->get();
|
||||
|
||||
$existingProductIds = $existingSettings->pluck('product_id')->toArray();
|
||||
|
||||
// 找出:有庫存但是「還沒設定過安全庫存」的商品
|
||||
$missingProductIds = $inventoryProductIds->diff($existingProductIds);
|
||||
|
||||
$missingProducts = Product::whereIn('id', $missingProductIds)
|
||||
->with(['category', 'baseUnit'])
|
||||
->get();
|
||||
|
||||
// 合併:已設定的 + 有庫存未設定的 (預設值 0)
|
||||
$safetyStockSettings = $existingSettings->map(function ($setting) {
|
||||
return [
|
||||
'id' => (string) $setting->id,
|
||||
'warehouseId' => (string) $setting->warehouse_id,
|
||||
'productId' => (string) $setting->product_id,
|
||||
'productName' => $setting->product->name,
|
||||
'productType' => $setting->product->category ? $setting->product->category->name : '其他',
|
||||
'safetyStock' => (float) $setting->safety_stock,
|
||||
'unit' => $setting->product->baseUnit?->name ?? '個',
|
||||
'updatedAt' => $setting->updated_at->toIso8601String(),
|
||||
'isNew' => false, // 標記為舊有設定
|
||||
];
|
||||
})->concat($missingProducts->map(function ($product) use ($warehouse) {
|
||||
return [
|
||||
'id' => 'temp_' . $product->id, // 暫時 ID
|
||||
'warehouseId' => (string) $warehouse->id,
|
||||
'productId' => (string) $product->id,
|
||||
'productName' => $product->name,
|
||||
'productType' => $product->category ? $product->category->name : '其他',
|
||||
'safetyStock' => 0, // 預設 0
|
||||
'unit' => $product->baseUnit?->name ?? '個',
|
||||
'updatedAt' => now()->toIso8601String(),
|
||||
'isNew' => true, // 標記為建議新增
|
||||
];
|
||||
}))->values();
|
||||
|
||||
// 原本的 inventories 映射 (供顯示對比)
|
||||
$inventories = Inventory::where('warehouse_id', $warehouse->id)
|
||||
->select('product_id', DB::raw('SUM(quantity) as total_quantity'))
|
||||
->groupBy('product_id')
|
||||
@@ -43,23 +87,6 @@ class SafetyStockController extends Controller
|
||||
];
|
||||
});
|
||||
|
||||
// 準備安全庫存設定列表 (從新表格讀取)
|
||||
$safetyStockSettings = WarehouseProductSafetyStock::where('warehouse_id', $warehouse->id)
|
||||
->with(['product.category', 'product.baseUnit'])
|
||||
->get()
|
||||
->map(function ($setting) {
|
||||
return [
|
||||
'id' => (string) $setting->id,
|
||||
'warehouseId' => (string) $setting->warehouse_id,
|
||||
'productId' => (string) $setting->product_id,
|
||||
'productName' => $setting->product->name,
|
||||
'productType' => $setting->product->category ? $setting->product->category->name : '其他',
|
||||
'safetyStock' => (float) $setting->safety_stock,
|
||||
'unit' => $setting->product->baseUnit?->name ?? '個',
|
||||
'updatedAt' => $setting->updated_at->toIso8601String(),
|
||||
];
|
||||
});
|
||||
|
||||
return Inertia::render('Warehouse/SafetyStockSettings', [
|
||||
'warehouse' => $warehouse,
|
||||
'safetyStockSettings' => $safetyStockSettings,
|
||||
|
||||
Reference in New Issue
Block a user