diff --git a/app/Http/Controllers/StudentReportController.php b/app/Http/Controllers/StudentReportController.php index 018b07f..dc6de0d 100644 --- a/app/Http/Controllers/StudentReportController.php +++ b/app/Http/Controllers/StudentReportController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Models\Student; +use Barryvdh\DomPDF\Facade\Pdf; use Illuminate\Http\RedirectResponse; use App\Models\SpLetter; use App\Models\SpThreshold; @@ -112,6 +113,51 @@ class StudentReportController extends Controller )); } + /** + * Kartu pelanggaran siswa (PDF). + */ + public function pdf(Student $student) + { + abort_unless(auth()->user()->canViewStudent($student), 403); + + $student->load([ + 'violations' => fn ($q) => $q->with(['violationType.category', 'recorder']) + ->whereNull('deleted_at') + ->latest('violation_date'), + 'spLetters.spThreshold', + ]); + + $totalPoints = $student->total_points; + $violations = $student->violations; + $spThresholds = SpThreshold::where('is_active', true)->orderBy('min_points')->get(); + + $currentSpLevel = null; + $nextSpThreshold = null; + foreach ($spThresholds as $threshold) { + if ($totalPoints >= $threshold->min_points) { + $currentSpLevel = $threshold; + } elseif (! $nextSpThreshold) { + $nextSpThreshold = $threshold; + } + } + + $school = [ + 'name' => \App\Models\Setting::getValue('school_name', 'SMKN 1 WONOREJO'), + 'address' => \App\Models\Setting::getValue('school_address', ''), + ]; + + $ketuaTim = \App\Models\User::where('role', 'ketua_tim') + ->where('is_active', true) + ->first(); + + $pdf = Pdf::loadView('students.pdf-card', compact( + 'student', 'totalPoints', 'violations', + 'currentSpLevel', 'nextSpThreshold', 'school', 'ketuaTim' + ))->setPaper('a4'); + + return $pdf->stream('kartu-pelanggaran-'.str_replace(' ', '-', $student->full_name).'.pdf'); + } + public function update(Request $request, Student $student): RedirectResponse { abort_unless(auth()->user()->canViewStudent($student), 403); diff --git a/resources/views/sp-letters/index.blade.php b/resources/views/sp-letters/index.blade.php index 7e987db..3e542d7 100644 --- a/resources/views/sp-letters/index.blade.php +++ b/resources/views/sp-letters/index.blade.php @@ -26,7 +26,12 @@ @forelse($letters as $sp) {{ $sp->letter_number }} - {{ $sp->student->full_name ?? '-' }} + +
{{ $sp->student->full_name ?? '-' }}
+
+ NISN: {{ $sp->student->nisn ?? '-' }} ยท {{ $sp->student->class_name ?? '-' }} +
+ {{ $sp->spThreshold->name ?? '-' }} diff --git a/resources/views/students/_riwayat.blade.php b/resources/views/students/_riwayat.blade.php new file mode 100644 index 0000000..d2605a7 --- /dev/null +++ b/resources/views/students/_riwayat.blade.php @@ -0,0 +1,32 @@ +
{{ $title }}
+@if($items->isEmpty()) +
Tidak ada catatan {{ strtolower($title) }}.
+@else + + + + + + + + + + + + @foreach($items as $i => $v) + + + + + + + + @endforeach + +
NoTanggalJenis PelanggaranPoinSanksi
{{ $i + 1 }}{{ \Carbon\Carbon::parse($v->violation_date)->locale('id')->translatedFormat('l, d/m/Y') }} + {{ $v->violationType?->name ?? 'โ€”' }} + @if($v->description) +
{{ $v->description }}
+ @endif +
+{{ $v->points }}{{ $v->sanction ?? 'โ€”' }}
+@endif diff --git a/resources/views/students/index.blade.php b/resources/views/students/index.blade.php index 96d4606..932e18e 100644 --- a/resources/views/students/index.blade.php +++ b/resources/views/students/index.blade.php @@ -173,11 +173,18 @@ {{-- Aksi --}} - - - Detail - +
+ + + PDF + + + + Detail + +
@empty diff --git a/resources/views/students/pdf-card.blade.php b/resources/views/students/pdf-card.blade.php new file mode 100644 index 0000000..b52d1a3 --- /dev/null +++ b/resources/views/students/pdf-card.blade.php @@ -0,0 +1,264 @@ + + + + + Kartu Pelanggaran {{ $student->full_name }} + + + +
+ +
+
{{ strtoupper($school['name']) }}
+
{{ $school['address'] }}
+
+ +
KARTU PELANGGARAN SISWA
+ +
Identitas Siswa
+ + + + + + + + + + + + + + + + + + + +
Nama Lengkap: {{ strtoupper($student->full_name) }}NIS: {{ $student->student_number ?? '-' }}
NISN: {{ $student->nisn ?? '-' }}Kelas: {{ $student->class_name ?? '-' }}
Jurusan: {{ $student->department_name ?? $student->department_code ?? '-' }}Tahun Akademik: {{ $student->academic_year_name ?? '-' }}
+ +
Rekap Poin Pelanggaran
+ + + + + + +
+
{{ $totalPoints }}
+
Total Poin
+
+
{{ $violations->count() }}x
+
Jumlah Pelanggaran
+
+ @if($currentSpLevel) + {{ $currentSpLevel->name }} +
Level SP
+ @else +
Aman
+
Belum Ada SP
+ @endif +
+ +
Riwayat Pelanggaran
+ @if($violations->isEmpty()) +
Siswa tidak memiliki catatan pelanggaran.
+ @else + @php + $tlMembolos = $violations->filter(fn ($v) => str_contains(strtolower($v->violationType?->name ?? ''), 'terlambat') || str_contains(strtolower($v->violationType?->name ?? ''), 'membolos'))->values(); + $lainnya = $violations->filter(fn ($v) => ! str_contains(strtolower($v->violationType?->name ?? ''), 'terlambat') && ! str_contains(strtolower($v->violationType?->name ?? ''), 'membolos'))->values(); + @endphp + @if($tlMembolos->isNotEmpty()) + @include('students._riwayat', ['title' => 'Terlambat & Membolos', 'items' => $tlMembolos]) + @endif + @if($lainnya->isNotEmpty()) + @include('students._riwayat', ['title' => 'Pelanggaran Lainnya', 'items' => $lainnya]) + @endif + @endif + + @if($nextSpThreshold) +
+ * Poin menuju SP berikutnya ({{ $nextSpThreshold->name }}) : {{ $nextSpThreshold->min_points - $totalPoints }} poin lagi. +
+ @endif + +
+
Wonorejo, {{ \Carbon\Carbon::now()->locale('id')->translatedFormat('d F Y') }}
+
Mengetahui,
+
Ketua Tatib SMKN 1 Wonorejo
+

+
{{ strtoupper($ketuaTim?->name ?? ' ') }}
+
{{ $ketuaTim?->username ?? '' }}
+
+ + + +
+ + diff --git a/resources/views/students/show.blade.php b/resources/views/students/show.blade.php index 5602ca2..59abaee 100644 --- a/resources/views/students/show.blade.php +++ b/resources/views/students/show.blade.php @@ -370,7 +370,7 @@ {{ strtoupper(substr($p->user->name ?? '?', 0, 1)) }} - {{ $p->user->name }} + {{ $p->user?->name ?? 'โ€”' }} @if($p->role) {{ $p->role }} @endif diff --git a/routes/web.php b/routes/web.php index 1ce7db5..4092907 100644 --- a/routes/web.php +++ b/routes/web.php @@ -78,6 +78,7 @@ Route::middleware('auth')->group(function () { Route::middleware('permission:view-students')->group(function () { Route::get('/students', [StudentReportController::class, 'index'])->name('students.index'); Route::get('/students/{student}', [StudentReportController::class, 'show'])->name('students.show'); + Route::get('/students/{student}/pdf', [StudentReportController::class, 'pdf'])->name('students.pdf'); Route::put('/students/{student}', [StudentReportController::class, 'update'])->name('students.update'); });