168 lines
5.3 KiB
PHP
168 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\WithTitle;
|
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
|
use Maatwebsite\Excel\Concerns\WithStyles;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
|
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
|
|
|
class SAExport implements FromCollection, WithHeadings, WithTitle, WithMapping, WithStyles, WithCustomStartCell, WithColumnFormatting
|
|
{
|
|
protected $stokaudit;
|
|
protected $jenisLaporan; // ✅ Define the missing property
|
|
|
|
public function __construct($stokaudit, $jenisLaporan = 'LAPORAN') // ✅ Allow a custom report title
|
|
{
|
|
$this->stokaudit = $stokaudit;
|
|
$this->jenisLaporan = strtoupper($jenisLaporan); // ✅ Convert to uppercase for consistency
|
|
}
|
|
|
|
public function collection()
|
|
{
|
|
$data = collect($this->stokaudit);
|
|
|
|
// ✅ Compute Totals
|
|
$totals = [
|
|
'norujukan' => 'TOTAL KESELURUHAN', // Label for total row
|
|
'tempoh' => '',
|
|
'nokp' => '',
|
|
'berat' => $data->sum('berat'),
|
|
'nilaimarhun' => $data->sum('nilaimarhun'),
|
|
'marhun' => '',
|
|
'pinjaman' => $data->sum('pinjaman'),
|
|
'bakipjm' => $data->sum('bakipjm'),
|
|
'kadarupah' => '',
|
|
'tempohbayar' => '',
|
|
'tunggakan' => $data->sum('tunggakan'),
|
|
'tunggakanujrah' => $data->sum('tunggakanujrah'),
|
|
'tunggakanonepercent' => $data->sum('tunggakanonepercent'),
|
|
'lelong_tawarruq' => '',
|
|
];
|
|
|
|
// ✅ Append Total Row to the Data Collection
|
|
$data->push($totals);
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
public function headings(): array
|
|
{
|
|
return [
|
|
['LAPORAN STOK AUDIT'], // ✅ Ensure proper title format
|
|
[
|
|
'Bil', 'Norujukan', 'JBG', 'No. KP', 'Berat',
|
|
'Nilai Marhun (RM)', 'Marhun', 'Pembiayaan Asal (RM)', 'Baki Pembiayaan (RM)',
|
|
'Kadar Keuntungan', 'Tempoh Belum Bayar', 'Keuntungan Belum Bayar (RM)',
|
|
'Lain-Lain Caj (RM)', 'Keuntungan 1% (RM)', 'Lanjutan'
|
|
]
|
|
];
|
|
}
|
|
|
|
|
|
public function startCell(): string
|
|
{
|
|
return 'A2';
|
|
}
|
|
|
|
public function map($row): array
|
|
{
|
|
static $counter = 1;
|
|
|
|
if ($row['norujukan'] === 'TOTAL KESELURUHAN') {
|
|
return [
|
|
'', // Empty for numbering
|
|
'JUMLAH',
|
|
'', '',
|
|
$row['berat'], // Raw number
|
|
$row['nilaimarhun'], // Raw number
|
|
'',
|
|
$row['pinjaman'], // Raw number
|
|
$row['bakipjm'], // Raw number
|
|
'',
|
|
'',
|
|
$row['tunggakan'], // Raw number
|
|
$row['tunggakanujrah'], // Raw number
|
|
$row['tunggakanonepercent'], // Raw number
|
|
'',
|
|
];
|
|
}
|
|
return [
|
|
$counter++, // Bil
|
|
$row['norujukan'],
|
|
$row['tempoh'],
|
|
$row['nokp'],
|
|
$row['berat'], // Raw number
|
|
$row['nilaimarhun'], // Raw number
|
|
$row['marhun'],
|
|
$row['pinjaman'], // Raw number
|
|
$row['bakipjm'], // Raw number
|
|
$row['kadarupah'], // Raw number
|
|
$row['tempoh'] - $row['tempohbayar'], // Raw number
|
|
$row['tunggakan'], // Raw number
|
|
$row['tunggakanujrah'], // Raw number
|
|
$row['tunggakanonepercent'], // Raw number
|
|
$row['lelong_tawarruq'],
|
|
];
|
|
}
|
|
|
|
|
|
|
|
|
|
public function title(): string
|
|
{
|
|
return $this->jenisLaporan; // ✅ Now correctly uses the class property
|
|
}
|
|
|
|
public function styles(Worksheet $sheet)
|
|
{
|
|
|
|
// ✅ Merge and Style Title Row
|
|
$sheet->mergeCells('A1:O1');
|
|
$sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16);
|
|
$sheet->getStyle('A1')->getAlignment()->setHorizontal('center');
|
|
|
|
// ✅ Bold Headers
|
|
$sheet->getStyle('A2:O2')->getFont()->setBold(true)->setSize(12);
|
|
|
|
// ✅ Bold Last Row (Total Row)
|
|
$lastRow = $sheet->getHighestRow(); // Get last row number
|
|
$sheet->getStyle("A{$lastRow}:O{$lastRow}")->getFont()->setBold(true)->setSize(12);
|
|
$sheet->getStyle("A{$lastRow}:O{$lastRow}")->getAlignment()->setHorizontal('right'); // Align text properly
|
|
|
|
return [];
|
|
}
|
|
|
|
public function columnWidths(): array
|
|
{
|
|
return [
|
|
'A' => 5,
|
|
'B' => 25,
|
|
'C' => 5,
|
|
'D' => 18,
|
|
'E' => 10,
|
|
'F' => 10,
|
|
'G' => 10,
|
|
];
|
|
}
|
|
|
|
public function columnFormats(): array
|
|
{
|
|
return [
|
|
'E' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
|
'F' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
|
'H' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
|
'I' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
|
'L' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
|
'M' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
|
'N' => NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1,
|
|
];
|
|
}
|
|
}
|