@extends('adminlte::page')
@section('content')
    <?php Fun::lang() ?>
    <?php
        $rand_id = rand(1,1000).time().rand(1,1000);

    ?>
    @include('hr.page-breadcrumb',['l1'=>'Manage HR','l2'=>'','l3'=>'Take Leave'])
    <div id="page" class="page">
        @include('hr.top-content',['l1'=>'Take Leave Authorize',
        'create'=> 0,
        'route' => 'take-leave-authorize',
        'btn_custom' => '',
        'search' => 0,
        ])
        <div class="alert-message alert-success" style="display: none">
            <button type="button" class="close" data-dismiss="alert">×</button>
            <i class="fa fa-check"></i>
            <h3>Success</h3>
            <p class="message"></p>
        </div>
        <div class="box-body table-responsive">
            <table id="datatable_leave" class="table table-striped table-bordered table-hover nowrap">
                <thead>
                <tr>
                    <th >Employee</th>
                    <th >From date</th>
                    <th >To date</th>
                    <th >Request date</th>
                    <th >Request to</th>
                    <th >Leave type</th>
                    <th >Total Leave</th>
                    <th >Review</th>
                    <th >Approve</th>
                    <th >Action</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>

@endsection


@section('js')

    <script type="text/javascript">
        $(function () {
            $('#datatable_leave').DataTable({
                processing: true,
                serverSide: true,
                searchable: false,
                ajax: '{{ route('api.take_leave_authorize_row_attributes') }}',
                columns: [
                    { data: 'emp_id', name: 'employee.user_firstname'},
                    { data: 'from_date', name: 'emp_leaves.from_date' },
                    { data: 'to_date', name: 'emp_leaves.to_date' },
                    { data: 'request_date', name: 'emp_leaves.request_date' },
                    { data: 'request_to', name: 'request_to' },
                    { data: 'leave_type', name: 'leave_type.name'},
                    { data: 'num_take_leave', name: 'emp_leaves.num_take_leave'},
                    { data: 'review', name: 'emp_leaves.review', searchable: false},
                    { data: 'approve', name: 'emp_leaves.approve', searchable: false},
                    { data: 'action',searchable: false},
                ],
            });

        });
        function remove_leave(id) {
            var csrf_token = $('meta[name="csrf-token"]').attr('content');
            $.ajax({
                url:"{{url('/take-leave-delete')}}" +'/'+id,
                type:"POST",
                data : {'_method': 'POST', '_token': csrf_token},
                success:function (data) {
                    $('.alert-success').show();
                    $('.message').text(data.message);
                    $('#datatable_leave').DataTable().ajax.reload();
                },
                error:function (err) {
                    console.log(err);
                }
            });
        }
    </script>
@stop