- 在 RoleController 中新增 procurement_analysis 權限群組名稱 - 在 Procurement 模組中新增採購統計分析路由 - 在 PermissionSeeder 中新增 procurement_analysis.view 權限並分配給角色 - 在側邊欄「報表與分析」分組中新增「採購統計分析」項目 - 優化 API 文件視圖中的表格外觀樣式
46 lines
1.6 KiB
PHP
46 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Procurement\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Modules\Procurement\Services\ProcurementAnalysisService;
|
|
use App\Modules\Procurement\Models\Vendor;
|
|
use App\Modules\Inventory\Contracts\InventoryServiceInterface;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
|
|
class ProcurementAnalysisController extends Controller
|
|
{
|
|
public function __construct(
|
|
protected ProcurementAnalysisService $analysisService,
|
|
protected InventoryServiceInterface $inventoryService,
|
|
) {}
|
|
|
|
public function index(Request $request)
|
|
{
|
|
$filters = $request->only([
|
|
'date_from', 'date_to', 'vendor_id', 'warehouse_id',
|
|
]);
|
|
|
|
// 取得各面向數據
|
|
$kpis = $this->analysisService->getKPIs($filters);
|
|
$deliveryAnalysis = $this->analysisService->getDeliveryAnalysis($filters);
|
|
$quantityAnalysis = $this->analysisService->getQuantityAnalysis($filters);
|
|
$priceTrendAnalysis = $this->analysisService->getPriceTrendAnalysis($filters);
|
|
|
|
// 取得篩選器選項(跨模組透過 Service 取得倉庫)
|
|
$warehouses = $this->inventoryService->getAllWarehouses();
|
|
$vendors = Vendor::select('id', 'name', 'code')->orderBy('name')->get();
|
|
|
|
return Inertia::render('Procurement/Analysis/Index', [
|
|
'kpis' => $kpis,
|
|
'deliveryAnalysis' => $deliveryAnalysis,
|
|
'quantityAnalysis' => $quantityAnalysis,
|
|
'priceTrendAnalysis' => $priceTrendAnalysis,
|
|
'vendors' => $vendors,
|
|
'warehouses' => $warehouses,
|
|
'filters' => $filters,
|
|
]);
|
|
}
|
|
}
|