whereBelongsTo($current_team) ->orderByDesc('year') ->orderByDesc('month') ->get(); return Inertia::render('reports/periods/Index', [ 'periods' => $periods->map(fn (ReportPeriod $period) => [ 'id' => $period->id, 'year' => $period->year, 'month' => $period->month, 'label' => $period->label(), 'status' => $period->status->value, 'statusLabel' => $period->status->label(), 'isEditable' => $period->isEditable(), 'updatedAt' => $period->updated_at?->toIso8601String(), ])->values(), 'months' => collect(range(1, 12))->map(fn (int $month) => [ 'value' => $month, 'label' => (new ReportPeriod([ 'month' => $month, 'year' => now()->year, 'status' => ReportPeriodStatus::Draft, ]))->label(), ])->all(), 'years' => collect(range((int) now()->year - 1, (int) now()->year + 2))->values()->all(), ]); } /** * Store a newly created report period. */ public function store(StoreReportPeriodRequest $request, Team $current_team): RedirectResponse { ReportPeriod::create([ ...$request->validated(), 'team_id' => $current_team->id, 'status' => ReportPeriodStatus::Draft, ]); return to_route('reports.periods.index', $current_team); } /** * Approve the given report period. */ public function approve(Team $current_team, ReportPeriod $report_period): RedirectResponse { abort_unless($report_period->team?->is($current_team), 404); $report_period->update([ 'status' => ReportPeriodStatus::Approved, ]); return to_route('reports.periods.index', $current_team); } }