diff --git a/app/Http/Controllers/SpLetterController.php b/app/Http/Controllers/SpLetterController.php index a47124a..06bb5aa 100644 --- a/app/Http/Controllers/SpLetterController.php +++ b/app/Http/Controllers/SpLetterController.php @@ -6,6 +6,7 @@ use App\Models\SpLetter; use App\Models\Setting; use Barryvdh\DomPDF\Facade\Pdf; use Illuminate\Http\Request; +use Illuminate\Support\Str; use Illuminate\View\View; class SpLetterController extends Controller @@ -39,10 +40,56 @@ class SpLetterController extends Controller $spLetter->update(['printed_at' => now(), 'status' => 'printed']); - // For now, return an HTML print view + // HTML print view (untuk cetak langsung dari browser) return view('sp-letters.print', compact('spLetter', 'school')); } + /** + * Unduh PDF surat peringatan (format F4 resmi). + */ + public function pdf(SpLetter $spLetter) + { + abort_unless(auth()->user()->canViewStudent($spLetter->student_id), 403); + + $spLetter->load(['student', 'spThreshold', 'generator']); + $school = $this->schoolSettings(); + $forPdf = true; + + $spLetter->update(['printed_at' => now(), 'status' => 'printed']); + + $pdf = Pdf::loadView('sp-letters.print', compact('spLetter', 'school', 'forPdf')) + ->setPaper([0, 0, 595.28, 935.43], 'portrait'); // F4 (210×330 mm) + + $filename = 'SP-'.Str::slug(str_replace(['/', '\\'], '-', $spLetter->letter_number)).'.pdf'; + + return $pdf->download($filename); + } + + /** + * Ekspor PDF rekap seluruh surat peringatan (daftar, A4 landscape). + */ + public function exportPdf() + { + $letters = SpLetter::with(['student', 'spThreshold', 'generator']) + ->when(auth()->user()->isScopedWaliKelas(), fn ($q) => $q->whereHas('student', fn ($qq) => $qq->whereIn('class_id', auth()->user()->homeroomClassIds()))) + ->latest() + ->get(); + + $summary = [ + 'total' => $letters->count(), + 'total_poin' => $letters->sum('total_points_at_time'), + 'siswa' => $letters->pluck('student_id')->unique()->count(), + 'per_status' => $letters->groupBy('status')->map->count(), + ]; + + $school = $this->schoolSettings(); + + $pdf = Pdf::loadView('sp-letters.export-pdf', compact('letters', 'summary', 'school')) + ->setPaper('a4', 'landscape'); + + return $pdf->download('rekap-surat-peringatan-'.now()->format('Ymd-His').'.pdf'); + } + /** * Data sekolah untuk kop surat (format resmi). */ diff --git a/resources/views/sp-letters/export-pdf.blade.php b/resources/views/sp-letters/export-pdf.blade.php new file mode 100644 index 0000000..b6038b9 --- /dev/null +++ b/resources/views/sp-letters/export-pdf.blade.php @@ -0,0 +1,157 @@ + + +
+ +|
+ @if (! empty($school['kop_logo']) && file_exists(public_path('storage/'.$school['kop_logo'])))
+ |
+
+ {{ $school['government'] }}
+ {{ $school['agency'] }}
+ {{ $school['full_name'] }}
+ {{ $school['address_detail'] }}
+ {{ $school['website_email'] }}
+ {{ $school['postal'] }}
+ |
+
Dicetak {{ now()->locale('id')->isoFormat('dddd, D MMMM YYYY') }}
+| {{ $summary['total'] }}Total Surat | +{{ $summary['total_poin'] }}Total Poin | +{{ $summary['siswa'] }}Siswa Terkena SP | ++ + {{ $summary['per_status']->get('draft', 0) }} / {{ $summary['per_status']->get('printed', 0) }} + + Draft / Tercetak + | ++ + {{ $summary['per_status']->get('signed', 0) }} / {{ $summary['per_status']->get('delivered', 0) }} + + TTD / Diserahkan + | +
| No | +No. Surat | +Tanggal | +NISN | +Nama Siswa | +Kelas | +Jenis SP | +Poin | +Status | +
|---|---|---|---|---|---|---|---|---|
| {{ $i + 1 }} | +{{ $sp->letter_number }} | +{{ $sp->created_at?->format('d/m/Y') }} | +{{ $sp->student?->nisn }} | +{{ $sp->student?->full_name }} | +{{ $sp->student?->class_name }} | +{{ $sp->spThreshold?->name }} | +{{ $sp->total_points_at_time }} | +{{ $label }} | +
| Belum ada surat peringatan | ||||||||
|
+ Petugas / Guru BK
+ ______________________
+ |
+
+ Mengetahui,
+ Kepala {{ $school['name'] }} {{ $school['kepala_sekolah'] }}
+ NIP. {{ $school['kepala_sekolah_nip'] }}
+ |
+
Daftar surat peringatan siswa
+Daftar surat peringatan siswa
+