Files
star-erp/app/Modules/Core/Controllers/DashboardController.php
sky121113 0e51992cb4
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 1m1s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped
refactor(modular): 完成第二階段儀表板解耦與模型清理
2026-01-27 08:59:45 +08:00

52 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Modules\Core\Controllers;
use App\Http\Controllers\Controller;
use App\Modules\Inventory\Contracts\InventoryServiceInterface;
use App\Modules\Procurement\Contracts\ProcurementServiceInterface;
use Inertia\Inertia;
use Illuminate\Http\Request;
class DashboardController extends Controller
{
protected $inventoryService;
protected $procurementService;
public function __construct(
InventoryServiceInterface $inventoryService,
ProcurementServiceInterface $procurementService
) {
$this->inventoryService = $inventoryService;
$this->procurementService = $procurementService;
}
public function index()
{
$centralDomains = config('tenancy.central_domains', []);
$demoPort = config('tenancy.demo_tenant_port');
if ((!$demoPort || request()->getPort() != $demoPort) && in_array(request()->getHost(), $centralDomains)) {
return redirect()->route('landlord.dashboard');
}
$invStats = $this->inventoryService->getDashboardStats();
$procStats = $this->procurementService->getDashboardStats();
$stats = [
'productsCount' => $invStats['productsCount'],
'vendorsCount' => $procStats['vendorsCount'],
'purchaseOrdersCount' => $procStats['purchaseOrdersCount'],
'warehousesCount' => $invStats['warehousesCount'],
'totalInventoryValue' => $invStats['totalInventoryQuantity'], // 原本前端命名是 totalInventoryValue 但實作是 Quantity暫且保留欄位名以不破壞前端
'pendingOrdersCount' => $procStats['pendingOrdersCount'],
'lowStockCount' => $invStats['lowStockCount'],
];
return Inertia::render('Dashboard', [
'stats' => $stats,
]);
}
}