@extends('layouts.app-hr')

@section('content')
    <?php Fun::lang() ?>
    @include('hr.take-leave.modal-status')
    @include('hr.take-leave.confirm-delete')
    @include('hr.take-leave.modal-deduct')
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <div class="top-header">
        <ol class="breadcrumb">
            <li><a href="#">{{__('administrator.dashboard')}}</a></li>
        </ol>
    </div>
    <div id="page" class="page">
        <div class="top-content">
            <div class="row">
                <div class="col-sm-6 col-xs-12">
                    <div class="title-add">
                        <div class="pull-left">
                            <h3>{{__('administrator.take_leave')}} </h3>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6 col-xs-12">
                    <div class="title-add1">
                        <div class="pull-right">
                            @if(Gate::check('Total Leave  Generate'))
                                <a href="{{url('take-leave/create')}}"
                                   class="button_primary">{{__('administrator.add_new')}}</a>
                            @endif
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-body">
            <table id="datatable_take_leave" class="table table-striped table-bordered table-hover nowrap">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>{{__('administrator.employee')}}</th>
                        <th>{{__('administrator.from_date')}}</th>
                        <th>{{__('administrator.to_date')}}</th>
                        <th>{{__('administrator.request_date')}}</th>
                        <th>{{__('administrator.leave_type')}}</th>
                        <th>{{__('administrator.total_leave')}}</th>
                        <th>{{__('administrator.deduct')}}</th>
                        <th style="width: 200px;">{{__('administrator.action')}}</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>

@endsection


@section('js')
    <script type="text/javascript">
        $(document).ready(function () {
            $(document).on('click', '.btn_delete', function () {
                var id = $(this).data('id');
                $('#delete-id').val(id);
                $('#form-delete').modal('show');
            });

            $(document).on('click', '.btn_deduct', function(){
                var id = $(this).data('id');
                var deduct_per_day = $(this).data('salary');
                $('#ids').val(id);
                $('#salary').val(deduct_per_day.toFixed(2));
                $('#form-deduct').modal('show');
            });

            $(document).on('click', '.btn_status', function () {
                var id = $(this).data('id');
                $('#id').val(id);
                $('#form-status').modal('show');
            });

            $('#datatable_take_leave').DataTable({
                ordering: false,
                processing: false,
                serverSide: true,
                searchable: false,
                ajax: '{{ route("take-leave.index") }}',
                lengthMenu: [[20, 30, 50, 100, 1000], [20, 30, 50, 100, 1000]],
                columns:
                    [
                        {data: 'DT_RowIndex', orderable: false, searchable: false},
                        {data: 'emp_id', name: 'users.name'},
                        {data: 'from_date'},
                        {data: 'to_date'},
                        {data: 'request_date'},
                        {data: 'leave_type'},
                        {data: 'num_take_leave'},
                        {data: 'deduct'},
                        {data: 'action'},
                    ],
                "initComplete": function (settings, json) {
                }
            });
            $.fn.dataTable.ext.errMode = 'throw';
        });
    </script>
@stop
