@extends('hr.hr-reports.includes.divToPrint')

@section('content')
    <table class="table-data table-bordered-dd" id="table-data" ​​ border="1">
        <thead>
        <tr>
            <th align="center" rowspan="2">Name</th>
            <th align="center" rowspan="2">Join Date</th>
            <th align="center" colspan="3" class="page_speed_1482399860">Special leave</th>
            <th align="center" colspan="3" class="page_speed_1482399860">Sick leave</th>
            <th align="center" colspan="3" class="page_speed_1482399860">Maternity leave</th>
            <th align="center" colspan="3" class="page_speed_1482399860">Annual leave</th>
            <th align="center" colspan="3" class="page_speed_1482399860">Unpaid leave</th>
        </tr>
        <tr>
            <th align="center">all</th>
            <th align="center">use</th>
            <th align="center">bal</th>

            <th align="center">all</th>
            <th align="center">use</th>
            <th align="center">bal</th>

            <th align="center">all</th>
            <th align="center">use</th>
            <th align="center">bal</th>

            <th align="center">all</th>
            <th align="center">use</th>
            <th align="center">bal</th>

            <th align="center">all</th>
            <th align="center">use</th>
            <th align="center">bal</th>
        </tr>
        </thead>
        <tbody>
            @if(isset($rows))
                <?php
                    $m = \App\Models\LeaveType::all();
                ?>
                @foreach($rows as $key=> $row)
                    <tr>
                        <td align="center">{{optional($row->employee)->full_name}}</td>
                        <td align="center">{{date('Y-m-d', strtotime(optional($row->employee)->joined_date))}}</td>

                        <td align="center">{{optional($row)->special_leave}}</td>
                        <td align="center">{{optional($row->employee->leave->where('approve','>',0)->where('leave_type', $m[0]->id))->sum('num_take_leave')}}</td>
                        <td align="center">{{optional($row)->special_leave - optional($row->employee->leave->where('approve','>',0)->where('leave_type', $m[0]->id))->sum('num_take_leave')}}</td>

                        <td align="center">{{optional($row)->sick_leave}}</td>
                        <td align="center">{{optional($row->employee->leave->where('approve','>',0)->where('leave_type', $m[1]->id))->sum('num_take_leave')}}</td>
                        <td align="center"> {{optional($row)->sick_leave - optional($row->employee->leave->where('approve','>',0)->where('leave_type', $m[1]->id))->sum('num_take_leave')}}</td>

                        <td align="center">{{optional($row)->maternity_leave}}</td>
                        <td align="center">{{optional($row->employee->leave->where('approve','>',0)->where('leave_type', $m[2]->id))->sum('num_take_leave')}}</td>
                        <td align="center">{{optional($row)->maternity_leave - optional($row->employee->leave->where('approve','>',0)->where('leave_type', $m[2]->id))->sum('num_take_leave') }}</td>

                        <td align="center">{{optional($row)->annual_leave}}</td>
                        <td align="center">{{optional($row->employee->leave->where('approve','>',0)->where('leave_type', $m[3]->id))->sum('num_take_leave')}}</td>
                        <td align="center">{{optional($row)->annual_leave - optional($row->employee->leave->where('approve','>',0)->where('leave_type', $m[3]->id))->sum('num_take_leave')}}</td>

                        <td align="center">{{optional($row)->unpaid_leave}}</td>
                        <td align="center">{{optional($row->employee->leave->where('approve','>',0)->where('leave_type', $m[4]->id))->sum('num_take_leave')}}</td>
                        <td align="center">{{optional($row)->unpaid_leave - optional($row->employee->leave->where('approve','>',0)->where('leave_type', $m[4]->id))->sum('num_take_leave')}}</td>
                    </tr>
                @endforeach
            @endif
        </tbody>
    </table>

@stop

