sementara
This commit is contained in:
128
app/Exports/ReferensiLinkExport.php
Normal file
128
app/Exports/ReferensiLinkExport.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Exports;
|
||||
|
||||
use Modules\Lpj\app\Models\ReferensiLink;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
|
||||
class ReferensiLinkExport implements FromQuery, WithHeadings, WithMapping, WithStyles, ShouldAutoSize, WithColumnFormatting
|
||||
{
|
||||
protected $filters;
|
||||
|
||||
public function __construct($filters = [])
|
||||
{
|
||||
$this->filters = $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query data yang akan diexport
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
$query = ReferensiLink::with(['createdBy', 'updatedBy'])
|
||||
->select('referensi_link.*');
|
||||
|
||||
// Apply filters
|
||||
if (isset($this->filters['kategori']) && !empty($this->filters['kategori'])) {
|
||||
$query->where('kategori', $this->filters['kategori']);
|
||||
}
|
||||
|
||||
if (isset($this->filters['status']) && $this->filters['status'] !== '') {
|
||||
$query->where('is_active', $this->filters['status']);
|
||||
}
|
||||
|
||||
if (isset($this->filters['search']) && !empty($this->filters['search'])) {
|
||||
$query->search($this->filters['search']);
|
||||
}
|
||||
|
||||
return $query->ordered();
|
||||
}
|
||||
|
||||
/**
|
||||
* Header kolom
|
||||
*/
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'No',
|
||||
'Nama',
|
||||
'Link',
|
||||
'Kategori',
|
||||
'Deskripsi',
|
||||
'Status Aktif',
|
||||
'Urutan',
|
||||
'Dibuat Oleh',
|
||||
'Diupdate Oleh',
|
||||
'Tanggal Dibuat',
|
||||
'Tanggal Diupdate',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapping data untuk setiap baris
|
||||
*/
|
||||
public function map($referensiLink): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
$rowNumber++;
|
||||
|
||||
return [
|
||||
$rowNumber,
|
||||
$referensiLink->name,
|
||||
$referensiLink->link,
|
||||
$referensiLink->kategori ?? '-',
|
||||
$referensiLink->deskripsi ?? '-',
|
||||
$referensiLink->is_active ? 'Aktif' : 'Tidak Aktif',
|
||||
$referensiLink->urutan,
|
||||
$referensiLink->createdBy ? $referensiLink->createdBy->name : '-',
|
||||
$referensiLink->updatedBy ? $referensiLink->updatedBy->name : '-',
|
||||
$referensiLink->created_at->format('d-m-Y H:i:s'),
|
||||
$referensiLink->updated_at->format('d-m-Y H:i:s'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Styling untuk worksheet
|
||||
*/
|
||||
public function styles(Worksheet $sheet)
|
||||
{
|
||||
return [
|
||||
// Header styling
|
||||
1 => [
|
||||
'font' => ['bold' => true, 'size' => 12],
|
||||
'fill' => ['fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'startColor' => ['rgb' => 'E2EFDA']],
|
||||
'alignment' => ['horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER],
|
||||
],
|
||||
// Alternating row colors
|
||||
'A2:K1000' => [
|
||||
'fill' => ['fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'startColor' => ['rgb' => 'F8F9FA']],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Format kolom
|
||||
*/
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'F' => NumberFormat::FORMAT_DATE_DDMMYYYY, // Tanggal dibuat
|
||||
'G' => NumberFormat::FORMAT_DATE_DDMMYYYY, // Tanggal diupdate
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom title untuk sheet
|
||||
*/
|
||||
public function title(): string
|
||||
{
|
||||
return 'Referensi Link';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user