<?php

namespace App\Http\Controllers\HR;

use App\Models\EmpLeave;
use App\Models\EmpLeaveDetail;
use App\Models\Employee;
use App\Models\EmployeeLeaveTotal;
use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Yajra\DataTables\DataTables;

class HRReportCreateController extends Controller
{
    function create_report()
    {
        //dd(11);

        return view('hr.hr-reports.index');
    }

    function create_report_total_leave(Request $request)
    {
        $rows = EmployeeLeaveTotal::with(['employee'])
            ->where(function ($q) use ($request) {
                $f_date = date('Y',strtotime($request->from_date));
                $t_date = date('Y', strtotime($request->to_date));
                $q->whereBetween('leave_year',[$f_date, $t_date]);
                if ($request->emp_id != null) {
                    if (is_array($request->emp_id)) {
                        $q->whereIn('emp_id', $request->emp_id);
                    } else {
                        $q->where('emp_id', $request->emp_id);
                    }
                }
            })
            ->get();
        return view('hr.hr-reports.total-leaves.list', compact('rows'));
    }

    function create_report_take_leave(Request $request)
    {
        $rows = EmpLeave::with(['employee', 'empLeave_detail'])
            ->where(function ($q) use ($request) {
                $f_date = date('Y-m-d',strtotime($request->from_date));
                $t_date = date('Y-m-d', strtotime($request->to_date));
                $q->whereBetween('request_date',[$f_date, $t_date]);
                if ($request->emp_id != null) {
                    if (is_array($request->emp_id)) {
                        $q->whereIn('emp_id', $request->emp_id);
                    } else {
                        $q->where('emp_id', $request->emp_id);
                    }
                }
            })
            ->get();
        return view('hr.hr-reports.take-leaves.list', compact('rows'));
    }


}
