
PK 
<?php
namespace App\Exports;
use App\Models\Payroll;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
class PayrollExport 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)
->get()
->map(function ($p) {
return [
'Emp Code' => $p->employee->emp_code,
'Name' => $p->employee->name,
'Month' => $p->month,
'Year' => $p->year,
'Gross' => $p->gross,
'PF (EE)' => $p->pf_employee,
'ESI (EE)' => $p->esi_employee,
'PT' => $p->professional_tax,
'TDS' => $p->tds,
'Deductions' => $p->deductions,
'Net Pay' => $p->net,
];
});
}
public function headings(): array
{
return [
'Employee Code',
'Employee Name',
'Month',
'Year',
'Gross Salary',
'PF (Employee)',
'ESI (Employee)',
'Professional Tax',
'TDS',
'Total Deductions',
'Net Pay'
];
}
}


PK 99