<?php
namespace App\Modules\HR\Reports\Exports;

use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class OvertimeSummaryExport implements FromCollection, WithHeadings
{
    protected $departments;

    public function __construct($data)
    {
        $this->departments = $data['departments'];
    }

    public function collection()
    {
        return $this->departments->map(function ($dept) {
            return [
                $dept->department_name,
                number_format($dept->total_ot_hrs, 2),
                number_format($dept->total_dot_hrs, 2),
                number_format($dept->total_ot_all, 2),
                $dept->ot_count,
            ];
        });
    }

    public function headings(): array
    {
        return [
            'Department',
            'OT Hours',
            'DOT Hours',
            'Total OT Hours',
            'OT Records',
        ];
    }
}
