Files
webstatement/app/Exports/CustomerExport.php
Daeng Deni Mardaeni 32750d2d02 feat(customers): tambahkan ekspor data pelanggan ke format Excel
- Menambahkan kelas CustomerExport untuk mengekspor data pelanggan.
- Mengimplementasikan antarmuka FromCollection, WithHeadings, WithMapping, dan WithColumnFormatting.
- Menyediakan pemetaan kolom untuk data pelanggan termasuk ID, kode pelanggan, nama, alamat, kode cabang, tanggal lahir, email, dan tanggal dibuat.
- Mengatur format kolom untuk ID sebagai angka dan tanggal lahir serta email sebagai format tanggal.
2025-02-18 16:36:20 +07:00

59 lines
1.3 KiB
PHP

<?php
namespace Modules\Webstatement\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Modules\Webstatement\Models\Customer;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
class CustomerExport implements WithColumnFormatting, WithHeadings, FromCollection, WithMapping
{
public function collection()
{
return Customer::all();
}
public function map($row)
: array
{
return [
$row->id,
$row->customer_code,
$row->name,
$row->address,
$row->branch_code,
$row->date_of_birth,
$row->email,
$row->created_at
];
}
public function headings()
: array
{
return [
'ID',
'Customer Code',
'Name',
'Address',
'Branch Code',
'Date of Birth',
'Email',
'Created At'
];
}
public function columnFormats()
: array
{
return [
'A' => NumberFormat::FORMAT_NUMBER,
'F' => NumberFormat::FORMAT_DATE_DMYSLASH,
'G' => NumberFormat::FORMAT_DATE_DATETIME
];
}
}