feat(tatib): kartu pelanggaran PDF per siswa (tombol PDF di /students, dompdf A4: identitas, rekap poin, riwayat 2 tabel Terlambat&Membolos/Lainnya, ttd Ketua Tim); fix null-safe nama user di riwayat handling; kolom NISN+Kelas di SP Letters
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user