Files
siakad/resources/views/dosen/presensi.blade.php
2026-10-24 11:45:32 +07:00

151 lines
8.9 KiB
PHP

@php
$tabUrl = fn (string $t): string => route('dosen.presensi', ['kelas' => $kelas['id'], 'pertemuan' => $nomor, 'tab' => $t]);
$kelasOpsi = $daftar->mapWithKeys(fn (array $k): array => [$k['id'] => $k['label']])->all();
$pertemuanOpsi = $pertemuan->mapWithKeys(fn (array $t): array => [$t['nomor'] => 'Pertemuan '.$t['nomor'].' ('.\App\Support\Prototype\DosenData::tanggal($t['tanggal']).')'])->all();
$rendah = $rekap->filter(fn (array $r): bool => $r['persen'] < $batas);
@endphp
<x-layouts.app title="Presensi">
<x-ui.page-header title="Presensi" description="Catat kehadiran mahasiswa pada setiap pertemuan dan pantau rekap kehadirannya." />
<div class="stack">
<x-glass.panel padding="sm">
<form method="GET" action="{{ route('dosen.presensi') }}" class="filter-bar" x-data x-on:change="$el.requestSubmit()" role="search" aria-label="Pilih kelas dan pertemuan">
<input type="hidden" name="tab" value="{{ $tab }}">
<x-form.select name="kelas" label="Kelas" :options="$kelasOpsi" :value="$kelas['id']" id="pilih-kelas" />
<x-form.select name="pertemuan" label="Pertemuan" :options="$pertemuanOpsi" :value="$nomor" id="pilih-pertemuan" />
</form>
</x-glass.panel>
<x-ui.tabs label="Bagian presensi">
<x-ui.tab :href="$tabUrl('isi')" :active="$tab === 'isi'">Isi presensi</x-ui.tab>
<x-ui.tab :href="$tabUrl('rekap')" :active="$tab === 'rekap'">Rekap kehadiran</x-ui.tab>
</x-ui.tabs>
@if ($tab === 'isi')
<form
method="POST"
action="{{ route('dosen.presensi.store') }}"
class="stack"
novalidate
x-data="{
status: @js($status),
setAll(v) { for (const k in this.status) this.status[k] = v; },
count(v) { return Object.values(this.status).filter((s) => s === v).length; },
}"
>
@csrf
<input type="hidden" name="kelas" value="{{ $kelas['id'] }}">
<input type="hidden" name="pertemuan" value="{{ $nomor }}">
@if ($errors->any())
<x-ui.alert tone="danger" title="Presensi belum dapat dikirim">Periksa kembali status kehadiran setiap mahasiswa.</x-ui.alert>
@endif
<x-glass.panel padding="none">
<div class="flex flex-wrap items-center justify-between gap-3 p-4">
<div class="grid gap-1">
<h2 class="text-title">{{ $kelas['matkul'] }} ({{ $kelas['kelas'] }}), pertemuan {{ $nomor }}</h2>
<span class="text-sm text-muted">
{{ \App\Support\Prototype\DosenData::tanggal($info['tanggal'], 'dddd, D MMMM YYYY') }}{{ $info['materi'] ? ', '.$info['materi'] : '' }}
</span>
</div>
<x-ui.button variant="secondary" size="sm" icon="check-circle" x-on:click="setAll('hadir')">Semua hadir</x-ui.button>
</div>
<x-ui.table label="Presensi peserta kelas">
<table class="table">
<thead>
<tr>
<th scope="col">NIM</th>
<th scope="col">Nama</th>
<th scope="col">Kehadiran</th>
</tr>
</thead>
<tbody>
@foreach ($peserta as $p)
<tr>
<td class="table__title">{{ $p['nim'] }}</td>
<td>{{ $p['nama'] }}</td>
<td>
<fieldset class="flex flex-wrap gap-4">
<legend class="visually-hidden">Kehadiran {{ $p['nama'] }}</legend>
@foreach ($opsi as $value => $label)
<label class="check" for="p-{{ $p['nim'] }}-{{ $value }}">
<input
type="radio"
class="check__input"
id="p-{{ $p['nim'] }}-{{ $value }}"
name="status[{{ $p['nim'] }}]"
value="{{ $value }}"
x-model="status['{{ $p['nim'] }}']"
@checked(($status[$p['nim']] ?? 'hadir') === $value)
>
<span>{{ $label }}</span>
</label>
@endforeach
</fieldset>
@error('status.'.$p['nim'])
<span class="field__help field__help--error" role="alert">{{ $message }}</span>
@enderror
</td>
</tr>
@endforeach
</tbody>
</table>
</x-ui.table>
<div class="flex flex-wrap items-center gap-2 p-4">
<x-ui.badge tone="success"><span x-text="count('hadir')">{{ collect($status)->filter(fn ($s) => $s === 'hadir')->count() }}</span> hadir</x-ui.badge>
<x-ui.badge tone="gold"><span x-text="count('izin')">{{ collect($status)->filter(fn ($s) => $s === 'izin')->count() }}</span> izin</x-ui.badge>
<x-ui.badge tone="accent"><span x-text="count('sakit')">{{ collect($status)->filter(fn ($s) => $s === 'sakit')->count() }}</span> sakit</x-ui.badge>
<x-ui.badge tone="danger"><span x-text="count('alpa')">{{ collect($status)->filter(fn ($s) => $s === 'alpa')->count() }}</span> alpa</x-ui.badge>
</div>
</x-glass.panel>
<x-form.actions>
<x-ui.button type="submit" icon="check">Simpan presensi</x-ui.button>
<x-ui.button variant="secondary" :href="route('dosen.kelas.show', $kelas['id'])">Lihat kelas</x-ui.button>
</x-form.actions>
</form>
@else
@if ($rendah->isNotEmpty())
<x-ui.alert tone="warning" title="Kehadiran di bawah batas">
{{ $rendah->count() }} mahasiswa memiliki kehadiran kurang dari {{ $batas }}% dan berisiko tidak dapat mengikuti ujian akhir.
</x-ui.alert>
@endif
<x-glass.panel padding="none">
<x-ui.table label="Rekap kehadiran peserta">
<table class="table">
<thead>
<tr>
<th scope="col">NIM</th>
<th scope="col">Nama</th>
<th scope="col" class="num">Hadir</th>
<th scope="col">Persentase</th>
<th scope="col">Keterangan</th>
</tr>
</thead>
<tbody>
@foreach ($rekap as $r)
<tr>
<td class="table__title">{{ $r['nim'] }}</td>
<td>{{ $r['nama'] }}</td>
<td class="num">{{ $r['hadir'] }} / {{ $r['total'] }}</td>
<td style="min-width: 10rem">
<x-ui.meter :value="$r['persen']" :max="100" :label="'Kehadiran '.$r['nama']" :value-text="$r['persen'].'%'" :tone="$r['persen'] >= $batas ? 'success' : 'danger'" />
</td>
<td>
<x-ui.badge :tone="$r['persen'] >= $batas ? 'success' : 'danger'">{{ $r['persen'] >= $batas ? 'Memenuhi syarat' : 'Di bawah '.$batas.'%' }}</x-ui.badge>
</td>
</tr>
@endforeach
</tbody>
</table>
</x-ui.table>
</x-glass.panel>
@endif
</div>
</x-layouts.app>