feat(tatib): ekspor PDF surat peringatan — unduh PDF per surat (F4 resmi via dompdf) + rekap daftar SP (A4 landscape: ringkasan status, tabel rinci, ttd); tombol Ekspor PDF di /sp-letters & Unduh PDF di detail
This commit is contained in:
@@ -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).
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user