first commit
This commit is contained in:
54
app/Http/Controllers/Reports/AnalysisController.php
Normal file
54
app/Http/Controllers/Reports/AnalysisController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user