
PK 
<?php
namespace App\Exports;
use App\Models\Payroll;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
class EsiExport implements FromCollection, WithHeadings
{
protected int $month;
protected int $year;
public function __construct(int $month, int $year)
{
$this->month = $month;
$this->year = $year;
}
public function collection()
{
return Payroll::with('employee')
->where('month', $this->month)
->where('year', $this->year)
->where('gross', '<=', 21000)
->get()
->map(fn($p) => [
$p->employee->esi_no,
$p->employee->name,
$p->gross,
$p->esi_employee,
$p->esi_employer
]);
}
public function headings(): array
{
return [
'IP Number',
'Employee Name',
'Gross Wages',
'Employee Contribution',
'Employer Contribution'
];
}
}


PK 99