From cda9cbec0366151dcf8e838a311c1015f97ed712 Mon Sep 17 00:00:00 2001 From: Novy San87 Date: Fri, 7 Aug 2026 15:06:16 +0700 Subject: [PATCH] =?UTF-8?q?feat(sp-letters):=20generate=20PDF=20resmi=20SP?= =?UTF-8?q?=20(DomPDF,=20F4,=20kop+tanda=20tangan)=20saat=20surat=20dibuat?= =?UTF-8?q?=20=E2=80=94=20wali=20bisa=20lihat/unduh=20via=20SiMURID=20(fil?= =?UTF-8?q?e=5Furl=20di=20API)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/ViolationService.php | 6 +++ app/Support/SpLetterPdf.php | 54 ++++++++++++++++++++++ resources/views/sp-letters/print.blade.php | 12 +++-- 3 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 app/Support/SpLetterPdf.php diff --git a/app/Services/ViolationService.php b/app/Services/ViolationService.php index 3223145..9ff1b35 100644 --- a/app/Services/ViolationService.php +++ b/app/Services/ViolationService.php @@ -119,6 +119,12 @@ class ViolationService 'status' => 'draft', ]); + // Generate PDF resmi (kop surat) agar wali bisa melihat/unduh di SiMURID + $pdfPath = \App\Support\SpLetterPdf::generate($letter); + if ($pdfPath) { + $letter->update(['file_path' => $pdfPath]); + } + // Notifikasi + FCM push ke wali murid (SP baru) $this->notifyParentsOfSp($letter); diff --git a/app/Support/SpLetterPdf.php b/app/Support/SpLetterPdf.php new file mode 100644 index 0000000..32fe4d9 --- /dev/null +++ b/app/Support/SpLetterPdf.php @@ -0,0 +1,54 @@ +load(['student', 'spThreshold', 'generator']); + + $school = [ + 'name' => Setting::getValue('school_name', 'SMK'), + 'address' => Setting::getValue('school_address', ''), + 'phone' => Setting::getValue('school_phone', ''), + 'logo' => Setting::getValue('school_logo', ''), + 'kop_logo' => Setting::getValue('kop_logo', ''), + 'government' => Setting::getValue('school_government', 'PEMERINTAH PROVINSI JAWA TIMUR'), + 'agency' => Setting::getValue('school_agency', 'DINAS PENDIDIKAN'), + 'full_name' => Setting::getValue('school_full_name', Setting::getValue('school_name', 'SMK')), + 'address_detail' => Setting::getValue('school_address_detail', ''), + 'website_email' => Setting::getValue('school_website_email', ''), + 'postal' => Setting::getValue('school_postal', ''), + 'kepala_sekolah' => Setting::getValue('kepala_sekolah_name', ''), + 'kepala_sekolah_nip' => Setting::getValue('kepala_sekolah_nip', ''), + 'place' => Setting::getValue('school_place', 'Wonorejo'), + ]; + + $pdf = Pdf::loadView('sp-letters.print', [ + 'spLetter' => $spLetter, + 'school' => $school, + 'forPdf' => true, + ])->setPaper('folio'); // F4 = 210 x 330 mm + + $path = 'sp-letters/sp-' . $spLetter->id . '.pdf'; + Storage::disk('public')->put($path, $pdf->output()); + + return $path; + } catch (\Throwable $e) { + report($e); + + return null; + } + } +} diff --git a/resources/views/sp-letters/print.blade.php b/resources/views/sp-letters/print.blade.php index e8e9041..1a4ab2a 100644 --- a/resources/views/sp-letters/print.blade.php +++ b/resources/views/sp-letters/print.blade.php @@ -40,9 +40,9 @@ @if (! empty($school['kop_logo']) && file_exists(public_path('storage/'.$school['kop_logo']))) - logo + logo @elseif (! empty($school['logo']) && file_exists(public_path('storage/'.$school['logo']))) - logo + logo @endif @@ -130,8 +130,10 @@ - + @if (! isset($forPdf) || ! $forPdf) + + @endif