kelasId = $kelasId; } public function collection() { return DetailKelas::with('siswa.Sekolah')->where('kelas_id', $this->kelasId)->get(); } public function headings(): array { return ["No", "Nama Anak", "Orang Tua", "No HP Orangtua", "Kelas", "Sekolah", "Status", "Tgl. Daftar"]; } // Mapping supaya nomor urut otomatis public function map($detailKelas): array { static $no = 1; $noHp = $detailKelas->siswa?->no_hp_orangtua; return [ $no++, // No Str::title($detailKelas->siswa?->nama_anak ?? '-'), Str::title($detailKelas->siswa?->nama_orangtua ?? '-'), $noHp ? "+62" . $noHp : 'No Hp Belum Diisi', $detailKelas->siswa?->kelas ?? '-', $detailKelas->siswa?->Sekolah?->nama_sekolah ?? ($detailKelas->siswa?->asal_sekolah ?? '-'), $detailKelas->status_siswa ?? '-', Carbon::parse($detailKelas->created_at)->locale('id')->translatedFormat('d M Y'), ]; } public function columnFormats(): array { return [ 'D' => NumberFormat::FORMAT_TEXT, ]; } public function bindValue(Cell $cell, $value) { if (is_string($value) && str_starts_with($value, '+')) { $cell->setValueExplicit($value, DataType::TYPE_STRING); return true; } return parent::bindValue($cell, $value); } public function startCell(): string { return 'A6'; } public function registerEvents(): array { $kelasData = Kelas::with('guru')->find($this->kelasId); return [ AfterSheet::class => function(AfterSheet $event) use ($kelasData) { $sheet = $event->sheet; // Header utama $sheet->mergeCells('A1:H1'); $sheet->mergeCells('A2:H2'); $sheet->mergeCells('A3:H3'); $sheet->mergeCells('A4:H4'); $sheet->mergeCells('A5:H5'); $sheet->setCellValue( 'A2', strtoupper(($kelasData ? $kelasData->nama_kelas : '')) ); if ($kelasData) { $sheet->setCellValue( 'A3', "{$kelasData->jenis_kelas} | {$kelasData->status}" ); $sheet->setCellValue( 'A4', $kelasData->Guru->nama ? "Kordinator Kelas " . $kelasData->Guru->nama : '-' ); } $sheet->getStyle('A2')->applyFromArray([ 'font' => ['bold' => true, 'size' => 16], 'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER], ]); $sheet->getStyle('A3:A4')->applyFromArray([ 'font' => ['italic' => true, 'size' => 11], 'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER], ]); $sheet->getStyle('A6:H6')->applyFromArray([ 'font' => ['bold' => true], 'fill' => [ 'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'startColor' => ['rgb' => 'EFEFEF'], ], 'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER], ]); $lastRow = $sheet->getHighestRow(); $sheet->getStyle("A6:H{$lastRow}")->applyFromArray([ 'borders' => [ 'allBorders' => [ 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, 'color' => ['rgb' => '000000'], ], ], ]); // $sheet->mergeCells("A" . ($lastRow+1) . ":C" . ($lastRow+1)); $sheet->setCellValue("G" . ($lastRow+1), "Total"); $sheet->setCellValue("H" . ($lastRow+1), $lastRow - 6); $sheet->getStyle("G" . ($lastRow+1) . ":H" . ($lastRow+1))->applyFromArray([ 'font' => ['bold' => true], 'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT], 'borders' => [ 'allBorders' => [ 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, 'color' => ['rgb' => '000000'], ], ], ]); $sheet->getStyle("G" . ($lastRow+1))->applyFromArray([ 'fill' => [ 'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'startColor' => ['rgb' => 'EFEFEF'], ], ]); $lastRow = $sheet->getHighestRow(); $sheet->getStyle("A7:A{$lastRow}") ->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); $sheet->getStyle("D7:D{$lastRow}") ->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); $sheet->getStyle("E7:E{$lastRow}") ->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); $sheet->getStyle("F7:F{$lastRow}") ->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); $sheet->getStyle("G7:G{$lastRow}") ->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); $sheet->getStyle("H7:H{$lastRow}") ->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); $sheet->getColumnDimension('A')->setWidth(5); $sheet->getColumnDimension('B')->setWidth(32); $sheet->getColumnDimension('C')->setWidth(32); $sheet->getColumnDimension('D')->setWidth(25); $sheet->getColumnDimension('E')->setWidth(8); $sheet->getColumnDimension('F')->setWidth(32); $sheet->getColumnDimension('G')->setWidth(19); $sheet->getColumnDimension('H')->setWidth(19); } ]; } public function title(): string { $kelas = Kelas::find($this->kelasId); return $kelas ? $kelas->nama_kelas : 'Kelas'; } }