2026-01-06 16:17:12 +08:00
|
|
|
<?php
|
|
|
|
|
|
2026-01-26 10:37:47 +08:00
|
|
|
namespace App\Modules\Core\Controllers;
|
2026-01-06 16:17:12 +08:00
|
|
|
|
2026-01-26 10:37:47 +08:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
|
2026-01-27 08:59:45 +08:00
|
|
|
use App\Modules\Inventory\Contracts\InventoryServiceInterface;
|
|
|
|
|
use App\Modules\Procurement\Contracts\ProcurementServiceInterface;
|
2026-01-06 16:17:12 +08:00
|
|
|
use Inertia\Inertia;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
|
|
class DashboardController extends Controller
|
|
|
|
|
{
|
2026-01-27 08:59:45 +08:00
|
|
|
protected $inventoryService;
|
|
|
|
|
protected $procurementService;
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
InventoryServiceInterface $inventoryService,
|
|
|
|
|
ProcurementServiceInterface $procurementService
|
|
|
|
|
) {
|
|
|
|
|
$this->inventoryService = $inventoryService;
|
|
|
|
|
$this->procurementService = $procurementService;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-06 16:17:12 +08:00
|
|
|
public function index()
|
|
|
|
|
{
|
2026-01-15 13:56:11 +08:00
|
|
|
$centralDomains = config('tenancy.central_domains', []);
|
|
|
|
|
|
2026-01-16 09:28:29 +08:00
|
|
|
$demoPort = config('tenancy.demo_tenant_port');
|
|
|
|
|
if ((!$demoPort || request()->getPort() != $demoPort) && in_array(request()->getHost(), $centralDomains)) {
|
2026-01-15 13:56:11 +08:00
|
|
|
return redirect()->route('landlord.dashboard');
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-27 08:59:45 +08:00
|
|
|
$invStats = $this->inventoryService->getDashboardStats();
|
2026-01-06 16:17:12 +08:00
|
|
|
|
|
|
|
|
return Inertia::render('Dashboard', [
|
2026-02-10 10:47:31 +08:00
|
|
|
'stats' => [
|
|
|
|
|
'totalItems' => $invStats['productsCount'],
|
|
|
|
|
'lowStockCount' => $invStats['lowStockCount'],
|
|
|
|
|
'negativeCount' => $invStats['negativeCount'] ?? 0,
|
|
|
|
|
'expiringCount' => $invStats['expiringCount'] ?? 0,
|
|
|
|
|
],
|
|
|
|
|
'abnormalItems' => $invStats['abnormalItems'] ?? [],
|
2026-01-06 16:17:12 +08:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-10 10:47:31 +08:00
|
|
|
|