52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
<?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,
|
||
]);
|
||
}
|
||
}
|