2026-01-06 16:17:12 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Models\Product;
|
|
|
|
|
use App\Models\Vendor;
|
|
|
|
|
use App\Models\PurchaseOrder;
|
|
|
|
|
use App\Models\Warehouse;
|
|
|
|
|
use App\Models\Inventory;
|
|
|
|
|
use Inertia\Inertia;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
|
|
class DashboardController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2026-01-15 13:56:11 +08:00
|
|
|
$centralDomains = config('tenancy.central_domains', []);
|
|
|
|
|
|
|
|
|
|
if (in_array(request()->getHost(), $centralDomains)) {
|
|
|
|
|
return redirect()->route('landlord.dashboard');
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-06 16:17:12 +08:00
|
|
|
$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
|
|
|
|
|
'pendingOrdersCount' => PurchaseOrder::where('status', 'pending')->count(),
|
|
|
|
|
'lowStockCount' => Inventory::whereColumn('quantity', '<=', 'safety_stock')->count(),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return Inertia::render('Dashboard', [
|
|
|
|
|
'stats' => $stats,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|