<?php

namespace App\Modules\HR\Reports\Exports;

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

class AbsenteeismSummaryExport implements FromCollection, WithHeadings
{
    protected $departments;

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

    public function collection()
    {
        $rows = collect();

        foreach ($this->departments as $dept) {

            $rows->push([
                $dept['department_name'],
                '',
                '',
                '',
                ''
            ]);

            foreach ($dept['designations'] as $des) {
                $rows->push([
                    '   '.$des['designation_name'],
                    $des['budget'],
                    $des['actual'],
                    $des['absent'],
                    $des['percent'].'%',
                ]);
            }
        }

        return $rows;
    }

    public function headings(): array
    {
        return [
            'Department / Designation',
            'Budgeted',
            'Actual',
            'Absent',
            'Percent',
        ];
    }
}

