feat(sp-letters): generate PDF resmi SP (DomPDF, F4, kop+tanda tangan) saat surat dibuat — wali bisa lihat/unduh via SiMURID (file_url di API)
This commit is contained in:
@@ -119,6 +119,12 @@ class ViolationService
|
|||||||
'status' => 'draft',
|
'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)
|
// Notifikasi + FCM push ke wali murid (SP baru)
|
||||||
$this->notifyParentsOfSp($letter);
|
$this->notifyParentsOfSp($letter);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Support;
|
||||||
|
|
||||||
|
use App\Models\Setting;
|
||||||
|
use App\Models\SpLetter;
|
||||||
|
use Barryvdh\DomPDF\Facade\Pdf;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generator PDF surat peringatan resmi (kop surat + tanda tangan).
|
||||||
|
* Dipakai saat SP dibuat agar wali murid bisa melihat/unduh lewat SiMURID.
|
||||||
|
*/
|
||||||
|
class SpLetterPdf
|
||||||
|
{
|
||||||
|
public static function generate(SpLetter $spLetter): ?string
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$spLetter->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,9 +40,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="kop-logo">
|
<td class="kop-logo">
|
||||||
@if (! empty($school['kop_logo']) && file_exists(public_path('storage/'.$school['kop_logo'])))
|
@if (! empty($school['kop_logo']) && file_exists(public_path('storage/'.$school['kop_logo'])))
|
||||||
<img src="{{ asset('storage/'.$school['kop_logo']) }}" alt="logo">
|
<img src="{{ isset($forPdf) && $forPdf ? public_path('storage/'.$school['kop_logo']) : asset('storage/'.$school['kop_logo']) }}" alt="logo">
|
||||||
@elseif (! empty($school['logo']) && file_exists(public_path('storage/'.$school['logo'])))
|
@elseif (! empty($school['logo']) && file_exists(public_path('storage/'.$school['logo'])))
|
||||||
<img src="{{ asset('storage/'.$school['logo']) }}" alt="logo">
|
<img src="{{ isset($forPdf) && $forPdf ? public_path('storage/'.$school['logo']) : asset('storage/'.$school['logo']) }}" alt="logo">
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
<td class="kop-text">
|
<td class="kop-text">
|
||||||
@@ -130,8 +130,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
@if (! isset($forPdf) || ! $forPdf)
|
||||||
window.onload = function() { window.print(); };
|
<script>
|
||||||
</script>
|
window.onload = function() { window.print(); };
|
||||||
|
</script>
|
||||||
|
@endif
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user