<?php

namespace App\Http\Controllers\HR;

use App\Http\Requests\TakeLeaveAuthorizeRequest;
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;
use App\Http\Requests\TakeLeaveRequest ;

class TakeLeaveAuthorizeController extends Controller
{
    public function index(Request $request)
    {

        return view('hr.take-leave-authorize.index');
    }

    public function create()
    {
        $job = Employee::pluck('user_firstname', 'id');
        return view('hr.take-leave-authorize.create', compact('job'));


    }

    public function store(TakeLeaveRequest $r)
    {

        EmpLeave::saveDetail( null, $r);

        return redirect('take-leave-authorize')->with('success', 'Employee leave success full');
    }

    public function show($id)
    {
        //
    }

    public function edit($id)
    {
        $d = EmpLeave::find($id);
        return view('hr.take-leave-authorize.create', compact('d'));
    }

    public function update(TakeLeaveAuthorizeRequest $r, $id)
    {
        EmpLeave::saveDetail( $id, $r);

        return redirect('take-leave-authorize')->with('success', 'Employee leave success full');
    }

    public function destroy($id)
    {
        //
        $d = EmpLeave::findOrFail($id);
        $d->delete();

        return redirect('take-leave-authorize')->with('success', 'Employee leave is successfully deleted');
    }
    function delete($id){
        EmpLeave::find($id)->delete();
        return response()->json([
            'success' => true,
            'message' => 'Employee leave is successfully deleted'
        ]);
    }

    function review($id){
        EmpLeave::saveReview($id);
        $d = EmpLeave::find($id);
        return view('hr.take-leave-authorize.review', compact('d'));
    }




}
