@extends('layouts.master')

@section('content')
<!-- DataTables -->
<link rel="stylesheet" href="{{ asset('/assets/') }}/css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/switch/rcswitcher.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/alert/pnotify.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/alert/sweetalert.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/alert/sweet-alert-animations.css">
<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
            <!-- Default panel contents -->
            <div class="panel-heading"></div>
                <header class="panel-heading" style="height:50px;">
                    <div class="pull-left">
                        {{$title}}
                    </div>
                    <div>
                        <a style="margin-left: 3px" href="{{ url('admin/leave_requests/apply') }}" class="btn btn-sm btn-info pull-right"><i class="fa fa-plus"></i> Leave Request</a>
                    </div>
                </header>
            <div class="panel-body">
                <div class="clearfix"></div>
                <table class="table table-bordered" id="example">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th class="text-center">
                                    Name
                                </th>
                                <th class="text-center">
                                    Purpose
                                </th>
                                <th class="text-center">
                                   Leave From
                                </th>
                                <th class="text-center">
                                   Leave To
                                </th>
                                <th class="text-center">
                                   Days
                                </th>
                                <th class="text-center">
                                    Status
                                </th>
                                <th class="text-center">
                                    Action
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                        @if (session('data'))
                            <div class="alert alert-success">
                                {{ session('data') }}
                            </div>
                        @endif
                       
                            <?php $count=1; ?>
                            @foreach($all as $info)
                                <tr>
                                    
                                    <td>{{ $count++ }}</td>
                                    <td class="text-center">
                                        @foreach($all_users as $user)
                                            @if($user['id']==$info->user_id)
                                               {{$user['name']}}
                                            @endif
                                        @endforeach
                                    </td>
                                    <td class="text-center">
                                        @foreach($purposes as $purp)
                                            @if($purp['id']==$info->purpose)
                                               {{$purp['name']}}
                                            @endif
                                        @endforeach
                                    </td>
                                    <td class="text-center">
                                        {{ date("jS-F-Y", strtotime($info->from)) }}
                                    </td>
                                    <td class="text-center">
                                        {{ date("jS-F-Y", strtotime($info->to)) }}
                                    </td>
                                    <td class="text-center">
                                        {{ $info->days}}
                                    </td>
                                    <td class="text-center">
                                        @if($info->approval == 0)
                                            <span class="label label-primary">Pending</span>
                                        @else
                                            {{ "" }}
                                            <span class="label label-success">Approved</span>
                                        @endif
                                    </td>
                                    <td class="parent-action-cls text-center">
                                        <a href="{{ url('admin/leave_requests/details') }}/{{ $info->id }}" class='btn btn-info btn-sm' data-toggle="tooltip" title="Details" data-placement="top"><i class="fa fa-edit"></i> Details</a>

                                        <a href="{{ url('admin/leave_requests/delete') }}/{{ $info->id }}" class='btn btn-default btn-sm' onclick="return confirm('Are you sure to delete this item ?')" data-toggle="tooltip" title="Delete" data-placement="top"><i class="fa fa-trash-o"></i></a>
                                       
                                        <!-- <span class="chk-active" style="cursor: pointer" data-id="{{$info->id}}" data-value="1">
                                            <i style="color:#398439;font-size: 18px;" class="fa fa-check-square-o" aria-hidden="true"></i> Approve
                                        </span>
                                        <span class="chk-active" style="cursor: pointer" data-id="{{$info->id}}" data-value="0">
                                            <i style="color:#d58512;font-size: 18px;" class="fa fa-square-o" aria-hidden="true"></i> Discard
                                        </span> -->
                                        <!-- 
                                        <input class="chk-active" data-id="{{$info->id}}" @if($info->approval == 1) checked="" @endif type="checkbox" value="1" /> Approve
                                        &nbsp;  &nbsp;
                                        <input class="chk-active" data-id="{{$info->id}}"  @if($info->approval == 1) checked="" @endif type="checkbox" value="0" /> Discard
                                        &nbsp;  &nbsp;
                                        </span> -->
                                    </td>
                                </tr>   
                            @endforeach
                        </tbody>
                    </table>
            </div>

        </div>
    </div>
</div>
    


<div class="modal fade" id="modalPreview">
    <div class="modal-dialog" style='width: 50%;'>
    
    </div>
</div>
@stop

@section('style')
<style>
    .modal-dialog {
      width: 70% !important;
      height: 70% !important;
    }

    .modal-content {
      height: auto;
      min-height: 70% !important;
      border-radius: 0;
    }
</style>
@stop

@section('script')
<script src="{{ asset('/assets/') }}/js/jquery.dataTables.min.js"></script>
<script src="{{ asset('/assets/') }}/js/dataTables.bootstrap.min.js"></script>
<script src="{{ asset('/assets/') }}/switch/rcswitcher.js"></script>
<script src="{{ asset('/assets/') }}/alert/sweetalert.min.js"></script>
<script src="{{ asset('/assets/') }}/alert/pnotify-init.js"></script>
<script src="{{ asset('/assets/') }}/alert/notify.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('body').on('hidden.bs.modal', '.modal', function () {
      $(this).removeData('bs.modal');
    });
    var table=$("#example").DataTable({
         "searching": true,
         "lengthChange": true,
         "ordering": true,
         stateSave: true       
    });

});
</script>
<script type="text/javascript">
    jQuery(document).ready(function($)
    {
        $('.chk-active').click(function(event)
        {
            var id = $(this).data('id');
            var stat = $(this).data('value');
            /*
            if($(this).is(':checked'))
            {
                stat = 10;
            }
            else
            {
                stat = 0;
            }*/

            $.ajax({
                url: "{{url('admin/leave_accept')}}",
                type: 'POST',
                data: {id: id,stat: stat},
            })
            .done(function(data){
                alert(data);
                location.reload();
            });
            
        });
        
    });
</script>
@if(Session::has('msg'))
    <div class="alert alert-success center-block msg_alt" >
        <a class="close" data-dismiss="alert" href="#">&times;</a>
        <strong><i class="fa fa-check"></i></strong>&nbsp;
    {{Session::get('msg')}}
    </div>
@endif
@stop