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.
This commit is contained in:
58
app/Exports/CustomerExport.php
Normal file
58
app/Exports/CustomerExport.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user