55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Reports;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\ReportPeriod;
|
|
use App\Models\Team;
|
|
use App\Services\Reports\AnalysisReportService;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class AnalysisController extends Controller
|
|
{
|
|
/**
|
|
* Display the analysis page.
|
|
*/
|
|
public function index(Request $request, Team $current_team, AnalysisReportService $analysisReportService): Response
|
|
{
|
|
$periods = ReportPeriod::query()
|
|
->whereBelongsTo($current_team)
|
|
->orderByDesc('year')
|
|
->orderByDesc('month')
|
|
->get();
|
|
|
|
/** @var ReportPeriod|null $selectedPeriod */
|
|
$selectedPeriod = $periods->firstWhere('id', $request->integer('period', $periods->first()?->id));
|
|
|
|
$analysis = $selectedPeriod
|
|
? $analysisReportService->build($current_team, $selectedPeriod->year, $selectedPeriod->month)
|
|
: [
|
|
'period' => null,
|
|
'columns' => [],
|
|
'rows' => [],
|
|
'meta' => [
|
|
'status' => null,
|
|
'statusLabel' => null,
|
|
'updatedAt' => null,
|
|
'canEditSources' => false,
|
|
],
|
|
];
|
|
|
|
return Inertia::render('reports/analysis/Index', [
|
|
'periods' => $periods->map(fn (ReportPeriod $period) => [
|
|
'id' => $period->id,
|
|
'label' => $period->label(),
|
|
'status' => $period->status->value,
|
|
'statusLabel' => $period->status->label(),
|
|
])->values(),
|
|
'selectedPeriodId' => $selectedPeriod?->id,
|
|
...$analysis,
|
|
]);
|
|
}
|
|
}
|