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)
| No | +Tanggal | +Jenis Pelanggaran | +Poin | +Sanksi | +
|---|---|---|---|---|
| {{ $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 ?? 'โ' }} | +
| 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 ?? '-' }} | +
|
+ {{ $totalPoints }}
+ Total Poin
+ |
+
+ {{ $violations->count() }}x
+ Jumlah Pelanggaran
+ |
+
+ @if($currentSpLevel)
+ {{ $currentSpLevel->name }}
+ Level SP
+ @else
+ Aman
+ Belum Ada SP
+ @endif
+ |
+