76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use App\Models\HasilSaw;
|
|
use App\Models\PeriodeSeleksi;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
use Maatwebsite\Excel\Concerns\WithTitle;
|
|
use Maatwebsite\Excel\Concerns\WithStyles;
|
|
use Maatwebsite\Excel\Concerns\WithColumnWidths;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
|
|
class HasilSawExport implements FromCollection, WithHeadings, WithTitle, WithStyles, WithColumnWidths
|
|
{
|
|
protected $periode;
|
|
|
|
public function __construct(PeriodeSeleksi $periode)
|
|
{
|
|
$this->periode = $periode;
|
|
}
|
|
|
|
public function collection()
|
|
{
|
|
return HasilSaw::with('warga')
|
|
->where('periode_id', $this->periode->id)
|
|
->orderBy('ranking')
|
|
->get()
|
|
->map(fn ($h) => [
|
|
'Ranking' => $h->ranking,
|
|
'Nama' => $h->warga->nama ?? '-',
|
|
'NIK' => $h->warga->nik ?? '-',
|
|
'Dusun' => $h->warga->dusun ?? '-',
|
|
'RW' => $h->warga->rw ?? '-',
|
|
'Skor Akhir' => number_format($h->skor_akhir, 6),
|
|
'Status' => ucfirst($h->status),
|
|
]);
|
|
}
|
|
|
|
public function headings(): array
|
|
{
|
|
return ['Ranking', 'Nama Warga', 'NIK', 'Dusun', 'RW', 'Skor Akhir', 'Status'];
|
|
}
|
|
|
|
public function title(): string
|
|
{
|
|
return 'Hasil SAW';
|
|
}
|
|
|
|
public function styles(Worksheet $sheet): array
|
|
{
|
|
return [
|
|
1 => [
|
|
'font' => ['bold' => true, 'color' => ['argb' => 'FFFFFFFF']],
|
|
'fill' => ['fillType' => Fill::FILL_SOLID, 'startColor' => ['argb' => 'FF198754']],
|
|
'alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER],
|
|
],
|
|
];
|
|
}
|
|
|
|
public function columnWidths(): array
|
|
{
|
|
return [
|
|
'A' => 10,
|
|
'B' => 28,
|
|
'C' => 20,
|
|
'D' => 16,
|
|
'E' => 8,
|
|
'F' => 16,
|
|
'G' => 16,
|
|
];
|
|
}
|
|
}
|