authorize('time.approve-others'); } /** * @return list */ #[Computed] public function pending(): array { return app(TimeEntryQueries::class)->pendingWeeks($this->personFilter === '' ? null : (int) $this->personFilter); } /** * @return list */ #[Computed] public function approved(): array { $since = CarbonImmutable::instance(app(Clock::class)->today())->startOfWeek()->subWeeks(7)->toDateString(); $weeks = app(TimeEntryQueries::class)->approvedWeeks($since); return $this->personFilter === '' ? $weeks : array_values(array_filter($weeks, fn (ApprovalWeek $week): bool => $week->userId === (int) $this->personFilter)); } /** * @return list */ #[Computed] public function people(): array { return app(UserAccountQueries::class)->activeUserOptions(); } public function approve(int $userId, string $monday, ApproveWeek $approveWeek): void { $this->authorize('time.approve-others'); $week = collect($this->pending)->first(fn (ApprovalWeek $week): bool => $week->userId === $userId && $week->monday === $monday); if ($week === null) { return; } $approveWeek->execute($userId, $monday, (int) auth()->id()); unset($this->pending, $this->approved); $this->statusMessage = __('time.approval.approved_for', ['name' => $week->userName, 'week' => $this->weekLabel($monday)]); $this->js("document.getElementById('pending-heading')?.focus()"); } /** * @return list */ public function pendingHeaders(): array { return [ ['index' => 'person', 'label' => __('time.approvals.person'), 'sortable' => false], ['index' => 'week', 'label' => __('time.approvals.week'), 'sortable' => false], ['index' => 'hours', 'label' => __('time.approvals.hours'), 'sortable' => false, 'align' => 'right'], ['index' => 'actions', 'label' => __('time.approvals.actions'), 'sortable' => false], ]; } /** * @return list */ public function approvedHeaders(): array { return [ ['index' => 'person', 'label' => __('time.approvals.person'), 'sortable' => false], ['index' => 'week', 'label' => __('time.approvals.week'), 'sortable' => false], ['index' => 'hours', 'label' => __('time.approvals.hours'), 'sortable' => false, 'align' => 'right'], ['index' => 'approver', 'label' => __('time.approvals.approver'), 'sortable' => false], ['index' => 'actions', 'label' => __('time.approvals.actions'), 'sortable' => false], ]; } public function weekLabel(string $monday): string { $start = CarbonImmutable::parse($monday); return __('time.week_heading', ['number' => $start->isoWeek(), 'from' => $start->format('j.n.'), 'to' => $start->addDays(6)->format('j.n.Y')]); } public function hours(int $quarters): string { return WorkedHours::formatQuarters($quarters); } public function weekUrl(ApprovalWeek $week): string { return route('time.week', ['kayttaja' => $week->userId, 'viikko' => $week->monday]); } public function render(): mixed { return $this->view()->title(__('time.approvals.title')); } }; ?>
{{ __('time.approvals.title') }}

{{ __('time.approvals.intro') }}

{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}} @foreach ($this->people as $person) @endforeach

{{ $statusMessage }}

{{ __('time.approvals.pending') }}

@if ($this->pending === []) {{ __('time.approvals.none_pending') }} @else @interact('column_person', $week) {{ $week->userName }} @endinteract @interact('column_week', $week) {{ $this->weekLabel($week->monday) }} @endinteract @interact('column_hours', $week) {{ $this->hours($week->quarters) }} @endinteract @interact('column_actions', $week)
@endinteract
@endif

{{ __('time.approvals.approved') }}

@if ($this->approved === []) {{ __('time.approvals.none_approved') }} @else @interact('column_person', $week) {{ $week->userName }} @endinteract @interact('column_week', $week) {{ $this->weekLabel($week->monday) }} @endinteract @interact('column_hours', $week) {{ $this->hours($week->quarters) }} @endinteract @interact('column_approver', $week) @if ($week->approval !== null) {{ __('time.approvals.approver_value', ['name' => $week->approval->approverName, 'date' => \Carbon\CarbonImmutable::parse($week->approval->approvedAt)->format('j.n.Y H:i')]) }} @endif @endinteract @interact('column_actions', $week) @endinteract @endif