@extends('layouts.app-hr')
@section('content')
    <?php Fun::lang()?>
    @php
        $from_date      = @$_GET['from_date'];
        $to_date        = @$_GET['to_date'];
        $emp_id         = @$_GET['emp_id'];
        $branch_id      = @$_GET['branch_id'];
        $department_id  = @$_GET['department_id'];
        $position_id    = @$_GET['position_id'];
    @endphp
    <div class="page">
        <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.report_employee')}}</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>
                            {!! Form::open(array('route' => 'get-report-employee','method'=>'get')) !!}
                                <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', 'id' => 'emp_id','autocomplete' => 'off']) !!}
                                    </div>
                                </div>
                                <div class="col-sm-4">
                                    <div class="form-group">
                                        @php
                                            $branch = App\Model\setup\BranchModel::pluck('name', 'id')->prepend(__('administrator.please_select'), '');
                                        @endphp
                                        <strong for="">{{__('administrator.branch')}}</strong>
                                        {!! Form::select('branch_id', $branch, null, array('class' => 'form-control select2','autocomplete' => 'off')) !!}
                                    </div>
                                </div>
                                <div class="col-sm-4">
                                    <div class="form-group">
                                        @php
                                            $department = App\Model\Hr\HrDepartmentModel::pluck('english_name', 'id')->prepend(__('administrator.please_select'), '');
                                        @endphp
                                        <strong for="">{{__('administrator.department')}}</strong>
                                        {!! Form::select('department_id', $department, null, array('class' => 'form-control select2','autocomplete' => 'off')) !!}
                                    </div>
                                </div>
                                <div class="col-sm-4">
                                    <div class="form-group">
                                        @php
                                            $position = App\Model\Hr\HrPositionModel::pluck('english_name', 'id')->prepend(__('administrator.please_select'), '');
                                        @endphp
                                        <strong for="">{{__('administrator.position')}}</strong>
                                        {!! Form::select('position_id', $position, null, array('class' => 'form-control select2','autocomplete' => 'off')) !!}
                                    </div>
                                </div>
                                <div class="col-sm-4">
                                    <div class="form-group">
                                        <strong for="">{{__('administrator.from_date')}}</strong>
                                        {!! Form::text('from_date', $from_date, array('placeholder' => __('administrator.from_date'),'class' => 'form-control date_picker', 'id' => 'from_date','autocomplete' => 'off')) !!}
                                    </div>
                                </div>
                                <div class="col-sm-4">
                                    <div class="form-group">
                                        <strong for="">{{__('administrator.to_date')}}</strong>
                                        {!! Form::text('to_date', $to_date, array('placeholder' => __('administrator.to_date'),'class' => 'form-control date_picker', 'id' => 'to_date','autocomplete' => 'off')) !!}
                                    </div>
                                </div>
                                <div class=" col-sm-12">
                                    <button class=" button_success pull-right print_button" type="button" data-text="{{__('administrator.report_employee')}}" ><i class="fa fa-print "></i> {{__('administrator.print')}}</button>
                                    <button class=" button_primary pull-right" type="button" onclick="search()"> {{__('administrator.search')}}</button>
                                </div>
                            {!! Form::close() !!}
                        </div>
                    </div>
                </div>
            </div>
            <div class="wrapper-table">
                <table id="print_table" width="100%" class="table table-striped table-hover ">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>{{__('administrator.employee_code')}}</th>
                            <th>{{__('administrator.en_name')}}</th>
                            <th>{{__('administrator.kh_name')}}</th>
                            <th>{{__('administrator.gender')}}</th>
                            <th>{{__('administrator.date_of_birth')}}</th>
                            <th>{{__('administrator.email')}}</th>
                            <th>{{__('administrator.phone')}}</th>
                            <th>{{__('administrator.branch')}}</th>
                            <th>{{__('administrator.department')}}</th>
                            <th>{{__('administrator.position')}}</th>
                        </tr>
                    </thead>
                    <tbody class="tbody">
                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endsection

@section('script')
    <script type="text/javascript">
        $(document).ready(function () {
            $('#print_table').DataTable({
                ordering: false,
                serverSide: true,
                lengthMenu: [[20, 30, 50, 100, 200, 500, 1000], [20, 30, 50, 100, 200, 500, 1000]],
                ajax: "{{ route('get-report-employee') }}",
                columns:
                    [
                        {data: 'DT_RowIndex' ,'searchable': false},
                        {data: 'code', 'searchable': false},
                        {data: 'name', name:'users.name'},
                        {data: 'name_kh', name:'users.name_kh'},
                        {data: 'gender', 'searchable': false},
                        {data: 'dob', 'searchable': false},
                        {data: 'email', name:'users.email'},
                        {data: 'phone', 'searchable': false},
                        {data: 'branch', 'searchable': false},
                        {data: 'department', 'searchable': false},
                        {data: 'position', 'searchable': false},
                    ],
            });
            $.fn.dataTable.ext.errMode = 'throw';
        });
        function search(){
            var emp_id          = $('select[name="emp_id"]').find(':selected').val();
            var branch_id       = $('select[name="branch_id"]').find(':selected').val();
            var department_id   = $('select[name="department_id"]').find(':selected').val();
            var position_id     = $('select[name="position_id"]').find(':selected').val();
            var from_date       = $('#from_date').val();
            var to_date         = $('#to_date').val();

            $('#print_table').DataTable().destroy();
            $('#print_table').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-employee') }}",
                    type:'POST',
                    data:{

                        _token:"{{csrf_token()}}",
                        emp_id:emp_id,
                        branch_id: branch_id,
                        department_id: department_id,
                        position_id: position_id,
                        from_date: from_date,
                        to_date: to_date
                    }
                },
                columns:
                    [
                        {data: 'DT_RowIndex', 'searchable': false},
                        {data: 'code', 'searchable': false},
                        {data: 'name','searchable': false},
                        {data: 'name_kh','searchable': false},
                        {data: 'gender', 'searchable': false},
                        {data: 'dob', 'searchable': false},
                        {data: 'email', 'searchable': false},
                        {data: 'phone', 'searchable': false},
                        {data: 'branch', 'searchable': false},
                        {data: 'department', 'searchable': false},
                        {data: 'position', 'searchable': false},

                    ],
            });
            $.fn.dataTable.ext.errMode = 'throw';
        }
    </script>
@stop




