生產工單BOM以及批號完善
This commit is contained in:
@@ -7,8 +7,10 @@ use App\Models\Vendor;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\Warehouse;
|
||||
use App\Models\Inventory;
|
||||
use App\Models\WarehouseProductSafetyStock;
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
@@ -21,15 +23,25 @@ class DashboardController extends Controller
|
||||
return redirect()->route('landlord.dashboard');
|
||||
}
|
||||
|
||||
// 計算低庫存數量:各商品在各倉庫的總量 < 安全庫存
|
||||
$lowStockCount = DB::table('warehouse_product_safety_stocks as ss')
|
||||
->join(DB::raw('(SELECT warehouse_id, product_id, SUM(quantity) as total_qty FROM inventories WHERE deleted_at IS NULL GROUP BY warehouse_id, product_id) as inv'),
|
||||
function ($join) {
|
||||
$join->on('ss.warehouse_id', '=', 'inv.warehouse_id')
|
||||
->on('ss.product_id', '=', 'inv.product_id');
|
||||
})
|
||||
->whereRaw('inv.total_qty <= ss.safety_stock')
|
||||
->count();
|
||||
|
||||
$stats = [
|
||||
'productsCount' => Product::count(),
|
||||
'vendorsCount' => Vendor::count(),
|
||||
'purchaseOrdersCount' => PurchaseOrder::count(),
|
||||
'warehousesCount' => Warehouse::count(),
|
||||
'totalInventoryValue' => Inventory::join('products', 'inventories.product_id', '=', 'products.id')
|
||||
->sum('inventories.quantity'), // Simplified, maybe just sum quantities for now
|
||||
->sum('inventories.quantity'),
|
||||
'pendingOrdersCount' => PurchaseOrder::where('status', 'pending')->count(),
|
||||
'lowStockCount' => Inventory::whereColumn('quantity', '<=', 'safety_stock')->count(),
|
||||
'lowStockCount' => $lowStockCount,
|
||||
];
|
||||
|
||||
return Inertia::render('Dashboard', [
|
||||
|
||||
Reference in New Issue
Block a user