@extends('layouts.master')

@section('content')
<style type="text/css">
        .cls-overflow{
            height: 800px;
            overflow: scroll;
        }

        .cls-overflow-one{
            height: 400px;
            overflow: scroll;
        }
    </style>
<!-- Main content -->
<section class="content">
    <!-- Main row -->
    <div class="row">
        <div class="col-md-12">
            
            <section class="panel tasks-widget">
                <header class="panel-heading" style="height:40px;">
                    <div class="pull-left">
                        {{$title}}
                    </div>
                    
                    <div>
                        <a href="{{url('admin/attendace_report')}}" class="btn btn-success btn-xs pull-right" style="margin-left: 2%">Attendance Report</a>
                        <button class="btn btn-success btn-xs pull-right" data-toggle="modal" data-target="#attendace">Add Attendance Sheet</button>
                    </div>
                </header>
                @if (session('status'))
                    <div class="alert alert-success">
                        {{ session('status') }}
                    </div>
                @endif
                <div class="row">
                    <div class="col-md-12">
                        <div class="col-md-6">
                            <header class="" style="height:40px;">
                                <div class="text-center">
                                    <span style="font-weight: bolder;font-size: 20px">Attendance of: {{ date('d/m/Y')}}</span>
                                </div>
                            </header>
                            <div class="table-responsive  cls-overflow-one">
                                <table class="table table-striped table-hover">
                                    <thead>
                                        <tr>
                                            <th class="text-center">
                                                User Name
                                            </th>
                                            <th class="text-center">
                                                Entry Time
                                            </th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @if(!empty($entry_time))
                                            @foreach($entry_time as $entry)
                                            
                                                <tr>
                                                    <td class="text-center">
                                                        <span style="font-size:12px">
                                                            @if($entry['absent_count'] == 0)
                                                            	{{ $entry['user_name'] }}
                                                            @endif
                                                        </span>
                                                    </td>
                                                    
                                                    <td class="text-center">
                                                        <span style="font-size:12px">
                                                            <?php
                                                                $a=strtotime('today 9:30 am');
                                                                $c=date('Y-m-d H:i:s', $a);
                                                                $exact_time= $a;
                                                                $timestamp = date('Y-m-d H:i:s',strtotime('today midnight'));
                                                                if($c < date('Y-m-d H:i:s',strtotime($entry['attendance_time'])))
                                                                {
                                                                    echo '<span class="text-center" style="color:red;font-weight:bolder;font-size:12px">'.date('H:i:s A',strtotime($entry['attendance_time'])).'</span>';
                                                                }
                                                                else if($entry['absent_count'] == 1 )
                                                                {
                                                                } 
                                                                else 
                                                                {
                                                                    echo '<span class="text-center" style="color:green;font-weight:bolder;font-size:12px">'.date('H:i:s A',strtotime($entry['attendance_time'])) .'</span>';
                                                                }
                                                            ?>
                                                            
                                                        </span> 
                                                    </td>
                                                </tr>
                                            @endforeach
                                        @endif  
                                    </tbody>
                                </table>
                                <hr>
                                </hr>
                                <header class="" style="height:40px;">
                                    <div class="text-center">
                                        <span style="font-weight: bolder;font-size: 20px">Checkout Time of: {{ date('d/m/Y',strtotime('yesterday'))}}</span>
                                    </div>
                                </header>
                                <table class="table table-striped table-hover">
                                    <thead>
                                        <tr>
                                            <th class="text-center">
                                                User Name
                                            </th>
                                            <th class="text-center">
                                                Exit Time
                                            </th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @if(!empty($exit_time))
                                            @foreach($exit_time as $entry)
                                                <tr >
                                                    <td class="text-center">
                                                        <span style="font-size:12px">
                                                            {{ $entry['user_name'] }}
                                                        </span>
                                                    </td>
                                                    <td class="text-center">
                                                        <span style="font-size:12px">
                                                            {{ date('h:i:s A',strtotime($entry['attendance_time'])) }}
                                                        </span> 
                                                    </td>
                                                </tr>
                                            @endforeach
                                        @endif
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="table-responsive project-list cls-overflow-one">
                                <header class="" style="height:40px;">
                                    <div class="text-center">
                                        <span style="font-weight: bolder;font-size: 20px">Summery : <span style="text-transform: uppercase;">{{ date('F'),time()}}</span></span>
                                    </div>
                                </header>
                                
                                <table class="table table-striped table-hover">
                                    <thead>
                                        <tr>
                                            <th class="text-center">
                                                User Name
                                            </th>
                                            <th class="text-center">
                                                Late Count
                                            </th>
                                            <th class="text-center">
                                                Absent Count
                                            </th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @if(!empty($late_array))
                                            @foreach($late_array as $late)
                                            
                                                <tr>
                                                    <td class="text-center">
                                                        <span style="font-size:12px">
                                                            {{ $late['user_name'] }}
                                                        </span>
                                                    </td>
                                                    <td class="text-center">
                                                        <span style="font-size:12px;margin-left: 10%;">
                                                           <span class="badge" style="color:red;background:rgba(221, 221, 226, 0.84)">{{ $late['late_count'] }}</span>
                                                        </span>   
                                                    </td>
                                                    <td class="text-center">
                                                        <span style="font-size:12px;margin-left: 10%;">
                                                           <span class="badge" style="color:red;background:rgba(221, 221, 226, 0.84)">{{ $late['absent_count'] }}</span>
                                                        </span>   
                                                    </td>
                                                </tr>
                                            @endforeach
                                        @endif  
                                    </tbody>
                                </table>
                                <hr>
                                </hr>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="panel-body">
                    <div class=" add-task-row">
                    </div>
                    <div class="table-foot">
                        
                    </div>
                </div>
            </section>
        </div>
    </div>
</section>
<!-- row end -->
<!-- /.content -->


<!-- Modal Add User -->
<div class="modal fade" id="attendace" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="gridSystemModalLabel">Add Attendace Sheet</h4>
      </div>
      <div class="modal-body">

        <form action="{{url('admin/attendace_sheet_entry')}}" enctype="multipart/form-data" method="POST">

            {{ csrf_field() }}
            
            <div class="form-group">
                <label for="exampleInputPassword1">Attendace Sheet(csv format)*</label>
                <input type="file" name="import_file" class="form-control"  placeholder="Upload File"  required="">
            </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Submit</button>
      </div>
      </form>  
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div>

@endsection


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

            $.ajax({
                url: '{{url('admin/user_active')}}',
                type: 'POST',
                data: {id: id,stat: stat},
            })
            .done(function(data){
                //alert(data);
            });
            
        });
    });
</script>
@endsection
