@extends('layouts.app-hr')

@section('content')
    @include('hr.attendance-finger-print.confirm-delete')
    @include('hr.attendance-finger-print.import-form')
    <?php Fun::lang()?>
    <div class="top-header">
        <ol class="breadcrumb">
            <li><a href="#">{{__('administrator.Dashboard')}}</a></li>
        </ol>
    </div>
    <div 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.attendance')}} </h3>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6 col-xs-12">
                    <div class="title-add">
                        {{-- <div class="pull-right">
                            <a href="{{route('hr.get-attendance-finger-print')}}"
                               class="button_warning">{{__('administrator.get_data')}}</a>
                        </div> --}}
                        <div class="pull-right">
                            @if(Gate::check('Attendance Finger Create'))
                            <a href="{{route('hr-attendance-fingerprint.create')}}"
                               class="button_info">{{__('administrator.add_new')}}</a>
                                @endif
                        </div>
                        <div class="pull-right">
                            <a href="#"
                               class="button_success btn_import">{{__('administrator.import')}}</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-body">
            <table id="datatable_products" width="100%" class="table table-striped">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>{{__('administrator.finger_name')}}</th>
                        <th>{{__('administrator.fingerprint_no')}}</th>
                        <th>{{__('administrator.check_in_out')}}</th>
                        <th>{{__('administrator.check_type')}}</th>
                        <th>{{__('administrator.type')}}</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_import', function(){
                $('#form-import').modal('show');
            });

            $(document).on('click', '.btn_finger_print', function(e){
                e.preventDefault();
                var route = '{{ route("hr.get-attendance-finger-print") }}';

                $.ajax({
                    url:route,
                    method:'GET',
                    data:{

                    },
                    success:function(response){
                        if(response.success){
                            alert(response.message) //Message come from controller
                        }else{
                            alert("Error")
                        }
                    },
                    error:function(error){
                        console.log(error)
                    }
                });
            })

            $('#datatable_products').DataTable({
                ordering: false,
                serverSide: true,
                lengthMenu: [[20, 30, 50, 100, 200, 500, 1000], [20, 30, 50, 100, 200, 500, 1000]],
                ajax: "{{ route('hr-attendance-fingerprint.index') }}",
                columns:
                    [
                        {data: 'DT_RowIndex', orderable: false, searchable: false},
                        {data: 'finger_print_name'},
                        {data: 'finger_print_no'},
                        {data: 'check_in_out'},
                        {data: 'check_type'},
                        {data: 'attend_type'},
                        {data: 'action'},
                    ],
                "initComplete": function (settings, json) {
                }
            });
            $.fn.dataTable.ext.errMode = 'throw';
        });
    </script>
@endsection
