@extends('layouts.app-hr')
@section('content')
    <?php Fun::lang()?>
    <div class="page">
        <style>
            .table>thead>tr>th {
                vertical-align: inherit;
            }
            .table.table-striped.table-hover{
                width: 100%;
            }
        </style>
        <div class=container-fluid>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12 form-group">
                        <div class="title-add">
                            <div class="pull-left">
                                <h3>{{__('administrator.leave_summary')}}</h3>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12 form-group paddin-0">
                        <div>
                                <div class="col-sm-4">
                                    <div class="form-group">
                                        @php
                                            $user = App\User::pluck('name', 'id')->prepend(__('administrator.please_select'),'');
                                        @endphp
                                        <strong for="">{{__('administrator.employee')}}</strong>
                                        {!! Form::select('emp_id',$user , null, ['class' => 'form-control select2 emp_id','autocomplete' => 'off','id' => 'emp_id']) !!}
                                    </div>
                                </div>
                                <div class="col-sm-4">
                                    <div class="form-group">
                                        <strong for="">{{__('administrator.from_date')}}</strong>
                                        {!! Form::text('from_date',null, array('placeholder' => __('administrator.from_date'),'class' => 'form-control date_picker','autocomplete' => 'off','','id' => 'from_date')) !!}
                                    </div>
                                </div>
                                <div class="col-sm-4">
                                    <div class="form-group">
                                        <strong for="">{{__('administrator.to_date')}}</strong>
                                        {!! Form::text('to_date',null, array('placeholder' => __('administrator.to_date'),'class' => 'form-control date_picker','autocomplete' => 'off','','id' => 'end_date')) !!}
                                    </div>
                                </div>
                                <div class=" col-sm-12">
                                    <button class=" button_success pull-right print_button" type="button" data-text="{{__('administrator.leave_summary')}}"><i class="fa fa-print "></i> {{__('administrator.print')}}</button>
                                    <button class=" button_primary pull-right button_search" type="button"> {{__('administrator.search')}}</button>
                                </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="wrapper-table">
                <table id="print_table" class="table table-striped table-hover ">
                    <thead>
                        <tr>
                            <th rowspan="2" style="text-align: center;">#</th>
                            <th rowspan="2" style="text-align: center;">{{__('administrator.code')}}</th>
                            <th rowspan="2" style="text-align: center;">{{__('administrator.employee')}}</th>
                            <th rowspan="2" style="text-align: center;">{{__('administrator.join_date')}}</th>
                            <th colspan="3" style="text-align: center;">{{__('administrator.annual_leave')}}</th>
                            <th colspan="3" style="text-align: center;">{{__('administrator.sick_leave')}}</th>
                            <th colspan="3" style="text-align: center;">{{__('administrator.special_leave')}}</th>
                            <th colspan="3" style="text-align: center;">{{__('administrator.unpaid_leave')}}</th>
                            <th colspan="3" style="text-align: center;">{{__('administrator.maternity')}}</th>
                            <th colspan="3" style="text-align: center;">{{__('administrator.other_leave')}}</th>
                        </tr>
                        <tr>
                            <th>{{__('administrator.all')}}</th>
                            <th>{{__('administrator.use')}}</th>
                            <th>{{__('administrator.bal')}}</th>
                            <th>{{__('administrator.all')}}</th>
                            <th>{{__('administrator.use')}}</th>
                            <th>{{__('administrator.bal')}}</th>
                            <th>{{__('administrator.all')}}</th>
                            <th>{{__('administrator.use')}}</th>
                            <th>{{__('administrator.bal')}}</th>
                            <th>{{__('administrator.all')}}</th>
                            <th>{{__('administrator.use')}}</th>
                            <th>{{__('administrator.bal')}}</th>
                            <th>{{__('administrator.all')}}</th>
                            <th>{{__('administrator.use')}}</th>
                            <th>{{__('administrator.bal')}}</th>
                            <th>{{__('administrator.all')}}</th>
                            <th>{{__('administrator.use')}}</th>
                            <th>{{__('administrator.bal')}}</th>
                        </tr>
                    </thead>
                    <tbody class="tbody">

                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endsection

@section('script')
    <script type="text/javascript">
        $(document).ready(function () {
                function get_data(employee='',from_date='',end_date)
                {
                $('#print_table').DataTable({
                    ordering: false,
                    serverSide: true,
                    searching : false,
                    lengthMenu: [[20, 30, 50, 100, 200, 500, 1000], [20, 30, 50, 100, 200, 500, 1000]],
                    ajax: {
                        url:"{{ route('get-report-leave-summary') }}",
                        data:{
                            "employee" : employee,
                            "from_date" : from_date,
                            "end_date" : end_date
                        }
                    },
                    columns:
                        [
                            {data: 'DT_RowIndex'},
                            {data: 'emp_code','searchable': false},
                            {data: 'emp_id','searchable': false},
                            {data: 'joined_date','searchable': false},
                            {data: 'annual_leave','searchable': false},
                            {data: 'annual_leave_use','searchable': false},
                            {data: 'annual_leave_bal','searchable': false},
                            {data: 'sick_leave','searchable': false},
                            {data: 'sick_leave_use','searchable': false},
                            {data: 'sick_leave_bal','searchable': false},
                            {data: 'special_leave','searchable': false},
                            {data: 'special_leave_use','searchable': false},
                            {data: 'special_leave_bal','searchable': false},
                            {data: 'unpaid_leave','searchable': false},
                            {data: 'unpaid_leave_use','searchable': false},
                            {data: 'unpaid_leave_bal','searchable': false},
                            {data: 'maternity_leave','searchable': false},
                            {data: 'maternity_leave_use','searchable': false},
                            {data: 'maternity_leave_bal','searchable': false},
                            {data: 'other_leave','searchable': false},
                            {data: 'other_leave_use','searchable': false},
                            {data: 'other_leave_bal','searchable': false},
                        ],
                    // "scrollX": true
                });
                $.fn.dataTable.ext.errMode = 'throw';
                }
                get_data();
                $('.button_search').on('click',function (e)
                {
                    e.preventDefault();
                    var employee = $('select[name="emp_id"]').find(':selected').val();
                    var from_date = $('#from_date').val();
                    var end_date = $('#end_date').val();
                    $('#print_table').DataTable().destroy();
                    get_data(employee,from_date,end_date);
                });
            });
        {{--function search(){--}}
        {{--    var emp_id = $('select[name="emp_id"]').find(':selected').val();--}}
        {{--    $('#table_employee').DataTable().destroy();--}}
        {{--    $('#table_employee').DataTable({--}}
        {{--        ordering: false,--}}
        {{--        serverSide: true,--}}
        {{--        lengthMenu: [[20, 30, 50, 100, 200, 500, 1000], [20, 30, 50, 100, 200, 500, 1000]],--}}
        {{--        ajax: {--}}
        {{--            url:"{{ route('get-report-attendance') }}",--}}
        {{--            type:'POST',--}}
        {{--            data:{--}}
        {{--                emp_id:emp_id,--}}
        {{--                _token:"{{csrf_token()}}"--}}
        {{--            }--}}
        {{--        },--}}
        {{--        columns:--}}
        {{--            [--}}
        {{--                {data: 'DT_RowIndex'},--}}
        {{--                {data: 'employee','searchable': false},--}}
        {{--                {data: 'total','searchable': false},--}}
        {{--                {data: 'before','searchable': false},--}}
        {{--                {data: 'bot', 'searchable': false},--}}
        {{--                {data: 'ot_type', 'searchable': false},--}}
        {{--                {data: 'total_ot', 'searchable': false},--}}
        {{--                {data: 'total_sun', 'searchable': false},--}}
        {{--                {data: 'total_hol', 'searchable': false},--}}
        {{--                {data: 'missing', 'searchable': false},--}}
        {{--                {data: 'late', 'searchable': false},--}}

        {{--            ],--}}
        {{--        "scrollX": true--}}
        {{--    });--}}
        {{--    $.fn.dataTable.ext.errMode = 'throw';--}}
        {{--}--}}
    </script>
@stop




