refactor: remove column definitions from multiple Excel export classes for simplification and maintainability
This commit is contained in:
parent
a996fd6de2
commit
874808733b
@ -7,7 +7,6 @@
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use pxlrbt\FilamentExcel\Columns\Column;
|
||||
use pxlrbt\FilamentExcel\Exports\ExcelExport;
|
||||
|
||||
class ContentRecapExcelExport extends ExcelExport implements WithEvents, WithStyles
|
||||
@ -17,33 +16,7 @@ public function setUp()
|
||||
$this->withFilename(fn ($resource) => $resource::getModelLabel().'-'.date('Y-m-d'));
|
||||
|
||||
$this->fromTable()
|
||||
->except(['index'])
|
||||
->withColumns([
|
||||
Column::make('title')
|
||||
->heading('Judul Konten'),
|
||||
|
||||
Column::make('type')
|
||||
->heading('Tipe')
|
||||
->formatStateUsing(fn ($state) => $state?->getLabel()),
|
||||
|
||||
Column::make('channel')
|
||||
->heading('Kanal')
|
||||
->formatStateUsing(fn ($state) => $state->getLabel()),
|
||||
|
||||
Column::make('social_media')
|
||||
->heading('Media Sosial')
|
||||
->formatStateUsing(fn ($state) => $state?->getLabel()),
|
||||
|
||||
Column::make('classification.name')
|
||||
->heading('Klasifikasi'),
|
||||
|
||||
Column::make('link')
|
||||
->heading('Tautan (URL)'),
|
||||
|
||||
Column::make('posting_date')
|
||||
->heading('Tanggal Posting')
|
||||
->formatStateUsing(fn ($state) => $state?->translatedFormat('l, d F Y')),
|
||||
]);
|
||||
->except(['index']);
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
@ -73,7 +46,7 @@ public function registerEvents(): array
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
$lastColumn = 'G'; // A-G
|
||||
$lastColumn = $sheet->getHighestColumn();
|
||||
|
||||
$sheet->mergeCells("A1:{$lastColumn}1");
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use pxlrbt\FilamentExcel\Columns\Column;
|
||||
use pxlrbt\FilamentExcel\Exports\ExcelExport;
|
||||
|
||||
class CooperationExcelExport extends ExcelExport implements WithEvents, WithStyles
|
||||
@ -16,37 +15,8 @@ public function setUp()
|
||||
{
|
||||
$this->withFilename(fn ($resource) => $resource::getModelLabel().'-'.date('Y-m-d'));
|
||||
|
||||
$this->withColumns([
|
||||
Column::make('title')
|
||||
->heading('Judul Kerja Sama'),
|
||||
|
||||
Column::make('partnerMedia.name')
|
||||
->heading('Media')
|
||||
->getStateUsing(fn ($record) => $record->partnerMedia->pluck('name')->join(', ')),
|
||||
|
||||
Column::make('initial_submission_date')
|
||||
->heading('Tgl Pengajuan Awal')
|
||||
->formatStateUsing(fn ($state) => $state?->translatedFormat('l, d F Y')),
|
||||
|
||||
Column::make('final_submission_date')
|
||||
->heading('Tgl Pengajuan Akhir')
|
||||
->formatStateUsing(fn ($state) => $state?->translatedFormat('l, d F Y')),
|
||||
|
||||
Column::make('status')
|
||||
->heading('Status')
|
||||
->formatStateUsing(fn ($state) => $state?->getLabel()),
|
||||
|
||||
Column::make('payment_amount')
|
||||
->heading('Jumlah Pembayaran')
|
||||
->formatStateUsing(fn ($state) => 'Rp '.number_format($state, 0, ',', '.')),
|
||||
|
||||
Column::make('payment_date')
|
||||
->heading('Tanggal Pembayaran')
|
||||
->formatStateUsing(fn ($state) => $state?->translatedFormat('l, d F Y')),
|
||||
|
||||
Column::make('description')
|
||||
->heading('Deskripsi'),
|
||||
]);
|
||||
$this->fromTable()
|
||||
->except(['index']);
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
@ -76,7 +46,7 @@ public function registerEvents(): array
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
$lastColumn = 'H'; // A-H
|
||||
$lastColumn = $sheet->getHighestColumn();
|
||||
|
||||
$sheet->mergeCells("A1:{$lastColumn}1");
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use pxlrbt\FilamentExcel\Columns\Column;
|
||||
use pxlrbt\FilamentExcel\Exports\ExcelExport;
|
||||
|
||||
class IssueManagementExcelExport extends ExcelExport implements WithEvents, WithStyles
|
||||
@ -17,38 +16,7 @@ public function setUp()
|
||||
$this->withFilename(fn ($resource) => $resource::getModelLabel().'-'.date('Y-m-d'));
|
||||
|
||||
$this->fromTable()
|
||||
->except(['index'])
|
||||
->withColumns([
|
||||
Column::make('mediaMonitoring.title')
|
||||
->heading('Judul Berita'),
|
||||
|
||||
Column::make('issue')
|
||||
->heading('Sentimen Isu')
|
||||
->formatStateUsing(fn ($state) => $state?->getLabel()),
|
||||
|
||||
Column::make('response')
|
||||
->heading('Respon Pemerintah')
|
||||
->formatStateUsing(fn ($state) => $state?->getLabel()),
|
||||
|
||||
Column::make('location.name')
|
||||
->heading('Lokus'),
|
||||
|
||||
Column::make('subLocation.name')
|
||||
->heading('Sublokus'),
|
||||
|
||||
Column::make('classification.name')
|
||||
->heading('Klasifikasi'),
|
||||
|
||||
Column::make('subClassification.name')
|
||||
->heading('Subklasifikasi'),
|
||||
|
||||
Column::make('description')
|
||||
->heading('Keterangan Isu'),
|
||||
|
||||
Column::make('mediaMonitoring.release_date')
|
||||
->heading('Tanggal Rilis')
|
||||
->formatStateUsing(fn ($state) => $state?->translatedFormat('l, d F Y')),
|
||||
]);
|
||||
->except(['index']);
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
@ -78,7 +46,7 @@ public function registerEvents(): array
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
$lastColumn = 'I'; // A-I
|
||||
$lastColumn = $sheet->getHighestColumn();
|
||||
|
||||
$sheet->mergeCells("A1:{$lastColumn}1");
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use pxlrbt\FilamentExcel\Columns\Column;
|
||||
use pxlrbt\FilamentExcel\Exports\ExcelExport;
|
||||
|
||||
class MediaMonitoringExcelExport extends ExcelExport implements WithEvents, WithStyles
|
||||
@ -17,45 +16,7 @@ public function setUp()
|
||||
$this->withFilename(fn ($resource) => $resource::getModelLabel().'-'.date('Y-m-d'));
|
||||
|
||||
$this->fromTable()
|
||||
->except(['index'])
|
||||
->withColumns([
|
||||
Column::make('code')
|
||||
->heading('Kode'),
|
||||
|
||||
Column::make('media_name')
|
||||
->heading('Nama Media'),
|
||||
|
||||
Column::make('title')
|
||||
->heading('Judul Berita'),
|
||||
|
||||
Column::make('channel')
|
||||
->heading('Kanal')
|
||||
->formatStateUsing(fn ($state) => $state->getLabel() ?? $state),
|
||||
|
||||
Column::make('writter')
|
||||
->heading('Penulis'),
|
||||
|
||||
Column::make('link')
|
||||
->heading('Tautan (URL)'),
|
||||
|
||||
Column::make('influencer')
|
||||
->heading('Influencer'),
|
||||
|
||||
Column::make('keyword')
|
||||
->heading('Kata Kunci'),
|
||||
|
||||
Column::make('themes')
|
||||
->heading('Tema')
|
||||
->getStateUsing(fn ($record) => $record->themes->pluck('name')->join(', ')),
|
||||
|
||||
Column::make('release_date')
|
||||
->heading('Tanggal Rilis')
|
||||
->formatStateUsing(fn ($state) => $state?->translatedFormat('l, d F Y')),
|
||||
|
||||
Column::make('issue_management_status')
|
||||
->heading('Status Isu')
|
||||
->getStateUsing(fn ($record) => $record->issueManagement ? 'Sudah Input' : 'Belum Input'),
|
||||
]);
|
||||
->except(['index']);
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
@ -85,7 +46,7 @@ public function registerEvents(): array
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
$lastColumn = 'K'; // Based on column count (A-K)
|
||||
$lastColumn = $sheet->getHighestColumn();
|
||||
|
||||
$sheet->mergeCells("A1:{$lastColumn}1");
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user