131 lines
3.3 KiB
PHP
131 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use Illuminate\Support\Collection;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
|
use Maatwebsite\Excel\Concerns\WithStyles;
|
|
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
|
|
class DataPelangganBycawDetailExport implements
|
|
FromCollection,
|
|
WithHeadings,
|
|
WithMapping,
|
|
WithStyles,
|
|
WithCustomStartCell
|
|
{
|
|
protected $pelanggan;
|
|
protected $year;
|
|
protected $no = 0;
|
|
|
|
public function __construct($pelanggan, $year)
|
|
{
|
|
$this->pelanggan = collect($pelanggan);
|
|
$this->year = $year;
|
|
}
|
|
|
|
/**
|
|
* Data source
|
|
*/
|
|
public function collection(): Collection
|
|
{
|
|
return $this->pelanggan;
|
|
}
|
|
|
|
/**
|
|
* Start data from row 5 (sebab ada tajuk)
|
|
*/
|
|
public function startCell(): string
|
|
{
|
|
return 'A5';
|
|
}
|
|
|
|
/**
|
|
* Header column
|
|
*/
|
|
public function headings(): array
|
|
{
|
|
return [
|
|
'No',
|
|
'Cawangan',
|
|
'No.Pelanggan',
|
|
'Umur',
|
|
'Jantina',
|
|
'Pekerjaan',
|
|
'Lokasi',
|
|
'Tempoh Pajakan',
|
|
'Tarikh Mula',
|
|
'Tarikh Tamat',
|
|
'Hari Sejak Transaksi Terakhir',
|
|
'Bil Transaksi',
|
|
'Bil Outstanding',
|
|
'Bil Tebus',
|
|
'Jumlah Pinjaman (RM)',
|
|
'Jumlah Ujrah (RM)',
|
|
'Tujuan Gadaian',
|
|
'Status Aktif',
|
|
'Cara Bayaran',
|
|
'Tarikh Lelong',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Map setiap row
|
|
*/
|
|
public function map($row): array
|
|
{
|
|
return [
|
|
++$this->no,
|
|
$row['cawangan'],
|
|
$row['nopelanggan'],
|
|
$row['umur'],
|
|
$row['jantina'],
|
|
$row['pekerjaan'],
|
|
$row['daerah'],
|
|
$row['tempoh_pajakan'],
|
|
$row['tarikh_mula'],
|
|
$row['tarikh_tamat'],
|
|
$row['hari_sejak_transaksi'],
|
|
$row['bil_transaksi'],
|
|
$row['bil_outstanding'],
|
|
$row['bil_tebus'],
|
|
number_format($row['jumlah_pinjaman'], 2),
|
|
number_format($row['jumlah_ujrah'], 2),
|
|
$row['tujuan_gadai'],
|
|
$row['status_aktif'],
|
|
$row['cara_bayaran'],
|
|
$row['tarikh_lelong'] ?? '-',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Styling Excel
|
|
*/
|
|
public function styles(Worksheet $sheet)
|
|
{
|
|
// Tajuk utama
|
|
$sheet->mergeCells('A1:R1');
|
|
$sheet->setCellValue('A1', 'LAPORAN DATA PELANGGAN MENGIKUT CAWANGAN');
|
|
$sheet->getStyle('A1')->getFont()->setBold(true)->setSize(14);
|
|
$sheet->getStyle('A1')->getAlignment()->setHorizontal('center');
|
|
|
|
// Tahun
|
|
$sheet->mergeCells('A2:R2');
|
|
$sheet->setCellValue('A2', 'TAHUN : ' . $this->year);
|
|
$sheet->getStyle('A2')->getFont()->setBold(true);
|
|
$sheet->getStyle('A2')->getAlignment()->setHorizontal('center');
|
|
|
|
// Header table
|
|
$sheet->getStyle('A5:R5')->getFont()->setBold(true);
|
|
$sheet->getStyle('A5:R5')->getAlignment()->setHorizontal('center');
|
|
|
|
// Auto width
|
|
foreach (range('A', 'R') as $col) {
|
|
$sheet->getColumnDimension($col)->setAutoSize(true);
|
|
}
|
|
}
|
|
}
|