From ba3c10ac13f9b0d1650930c194d939a53b542f05 Mon Sep 17 00:00:00 2001 From: sky121113 Date: Thu, 5 Feb 2026 13:18:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(warehouse):=20=E5=BA=AB=E5=AD=98=E7=B5=B1?= =?UTF-8?q?=E8=A8=88=E5=8D=A1=E7=89=87=E5=8A=A0=E5=85=A5=E7=B8=BD=E9=87=91?= =?UTF-8?q?=E9=A1=8D=E9=A1=AF=E7=A4=BA=20(=E5=8F=AF=E7=94=A8/=E5=B8=B3?= =?UTF-8?q?=E9=9D=A2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/WarehouseController.php | 28 ++++++++++++++++--- resources/js/Pages/Warehouse/Index.tsx | 28 +++++++++++++++---- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/app/Modules/Inventory/Controllers/WarehouseController.php b/app/Modules/Inventory/Controllers/WarehouseController.php index 658cf2a..aca2356 100644 --- a/app/Modules/Inventory/Controllers/WarehouseController.php +++ b/app/Modules/Inventory/Controllers/WarehouseController.php @@ -30,8 +30,9 @@ class WarehouseController extends Controller } $warehouses = $query->withSum('inventories as book_stock', 'quantity') // 帳面庫存 = 所有庫存總和 + ->withSum('inventories as book_amount', 'total_value') // 帳面金額 ->withSum(['inventories as available_stock' => function ($query) { - // 可用庫存 = 庫存 > 0 且 品質正常 且 (未過期 或 無效期) 且 倉庫類型不為瑕疵倉 + // 可用庫存條件 $query->where('quantity', '>', 0) ->where('quality_status', 'normal') ->whereHas('warehouse', function ($q) { @@ -42,6 +43,18 @@ class WarehouseController extends Controller ->orWhere('expiry_date', '>=', now()); }); }], 'quantity') + ->withSum(['inventories as available_amount' => function ($query) { + // 可用金額條件 (與可用庫存一致) + $query->where('quantity', '>', 0) + ->where('quality_status', 'normal') + ->whereHas('warehouse', function ($q) { + $q->where('type', '!=', \App\Enums\WarehouseType::QUARANTINE); + }) + ->where(function ($q) { + $q->whereNull('expiry_date') + ->orWhere('expiry_date', '>=', now()); + }); + }], 'total_value') ->addSelect(['low_stock_count' => function ($query) { $query->selectRaw('count(*)') ->from('warehouse_product_safety_stocks as ss') @@ -52,9 +65,6 @@ class WarehouseController extends Controller ->paginate($perPage) ->withQueryString(); - // 移除原本對 is_sellable 的手動修正邏輯,現在由 type 自動過濾 - - // 計算全域總計 (不分頁) $totals = [ 'available_stock' => \App\Modules\Inventory\Models\Inventory::where('quantity', '>', 0) @@ -66,7 +76,17 @@ class WarehouseController extends Controller $q->whereNull('expiry_date') ->orWhere('expiry_date', '>=', now()); })->sum('quantity'), + 'available_amount' => \App\Modules\Inventory\Models\Inventory::where('quantity', '>', 0) + ->where('quality_status', 'normal') + ->whereHas('warehouse', function ($q) { + $q->where('type', '!=', \App\Enums\WarehouseType::QUARANTINE); + }) + ->where(function ($q) { + $q->whereNull('expiry_date') + ->orWhere('expiry_date', '>=', now()); + })->sum('total_value'), 'book_stock' => \App\Modules\Inventory\Models\Inventory::sum('quantity'), + 'book_amount' => \App\Modules\Inventory\Models\Inventory::sum('total_value'), ]; return Inertia::render('Warehouse/Index', [ diff --git a/resources/js/Pages/Warehouse/Index.tsx b/resources/js/Pages/Warehouse/Index.tsx index b88aec0..9d95676 100644 --- a/resources/js/Pages/Warehouse/Index.tsx +++ b/resources/js/Pages/Warehouse/Index.tsx @@ -34,7 +34,9 @@ interface PageProps { }; totals: { available_stock: number; + available_amount: number; book_stock: number; + book_amount: number; }; filters: { search?: string; @@ -169,9 +171,16 @@ export default function WarehouseIndex({ warehouses, totals, filters }: PageProp
可用庫存總計 - - {totals.available_stock.toLocaleString()} - +
+ + {totals.available_stock.toLocaleString()} + + + + ( 總額:${totals.available_amount?.toLocaleString()} ) + + +
@@ -180,9 +189,16 @@ export default function WarehouseIndex({ warehouses, totals, filters }: PageProp
帳面庫存總計 - - {totals.book_stock.toLocaleString()} - +
+ + {totals.book_stock.toLocaleString()} + + + + ( 總額:${totals.book_amount?.toLocaleString()} ) + + +