@extends('backend._partials.app')
@section('maincontent')
    <style type="text/css">
        .btn-simple.btn-icon {
            padding: 1px !important;
        }

        @media print {
            .reportHead {
                display: none;
            }

            .copyright {
                display: none;
            }

            .dotted {
                display: none;
            }
        }
    </style>
    <div class="card col-md-6 col-md-offset-3 reportHead">
        <div class="content">
            <div class="row">
                {!! Form::open(['url'=>'attendance-details']) !!}
                {!! Form::hidden('search','yes') !!}
                <div class="col-md-3">
                    <label>FROM</label>
                    <div class="form-group">
                        <input type="text" name="from_date" class="form-control fromdatepicker"
                               placeholder="From Date here"/>
                    </div>
                </div>
                <div class="col-md-3">
                    <label>TO</label>
                    <div class="form-group">
                        <input type="text" name="to_date" class="form-control todatepicker" placeholder="To Date Here"/>
                    </div>
                </div>
                <div class="col-md-4">
                    <label>USER GROUP</label>
                    {!! Form::select('user_group',$userGroup,$defaultGroup,['class'=>'form-control','id'=>'selectedGroup']) !!}
                </div>
                <div class="col-md-2">
                    <label>&nbsp;</label>
                    <div class="form-group">
                        <button class="btn btn-info btn-fill" type="submit">Search</button>
                    </div>
                </div>
                {!! Form::close() !!}
            </div>
        </div>
    </div>
    <div class="card col-md-12"  style="width: auto !important;">
        <div class="header text-center">
            <h4 class="title">Attendance Report: <strong>{{DT::onlyDMY($from_date) }}</strong> to <strong>{{DT::onlyDMY($to_date) }}</strong></h4>

        </div>
        <div class="content">
            <?php
            $totalTime = [];

            ?>
            <table id="" class="table table-striped table-bordered table-responsive" cellspacing="0" width="100%"
                   style="width:100%">
                <thead>
                <tr>
                    <th colspan="{{count($data)+1}}" class="text-center"><b>User Group: <span
                                    id="userGroupDisplay"></span></b></th>
                </tr>
                <tr>
                    <th style="width: 200px;">Employee</th>
                    @foreach($data as $date =>$val)
                        <th>{{DT::onlyDMY($date)}}
                            <table class="table table-bordered">
                                <tr>
                                    <td width="31%">IN</td>
                                    <td width="31%">OUT</td>
                                    <td width="38%">TOTAL</td>
                                </tr>
                            </table>
                        </th>
                    @endforeach

                </tr>

                </thead>
                <tbody>

                @foreach($users as $user)
                    <tr>
                        <td>{{$user->first_name.' '.$user->last_name}}</td>
                        <?php $flag = 0; ?>
                        @foreach($data as $date =>$val)
                            @foreach($val as $records)
                                @if($records->user_id==$user->id)
                                    <?php $flag = 1; break; ?>
                                @endif
                            @endforeach
                            @if($flag==1)
                                <td>
                                    <table class="table table-bordered">
                                        <td width="31%">{{$records->min_time}}</td>
                                        <td width="31%">
                                            @if(empty($records->max_time))
                                                &nbsp;<span class="dotted"> &nbsp;</span>
                                            @else
                                                {{$records->max_time}}
                                            @endif
                                        </td>
                                        <td width="38%">
                                            @if(empty($records->timediff))
                                                <?php $elapsed=0; ?>
                                            @else
                                                <?php $elapsed=$records->timediff; ?>
                                            @endif
                                                {{Helper::secondsToTime($records->timediff)}}
                                        </td>
                                    </table>
                                </td>
                            @else
                                <td>
                                    <table class="table table-bordered">
                                        <td width="31%">&nbsp;<span class="dotted"> &nbsp; </span></td>
                                        <td width="31%">&nbsp;<span class="dotted"> &nbsp; </span></td>
                                        <td width="38%">&nbsp;<span class="dotted"> &nbsp; </span></td>
                                    </table>
                                </td>
                            @endif
                        @endforeach
                    </tr>
                @endforeach
                </tbody>

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

    <script>
        $().ready(function () {
            $("#userGroupDisplay").text($("#selectedGroup option:selected").text());
            $("#present").text($('.my-present').length);
            $("#absent").text($('.my-absent').length);
            $("#leave").text($('.my-leave').length);

            var table = $('#datatable-report').DataTable({
                "pagingType": "full_numbers",
                "lengthMenu": [[31, 60, 120, -1], [31, 60, 120, "All"]],
                responsive: true,
                language: {
                    search: "_INPUT_",
                    searchPlaceholder: "Search records",
                }

            });
        });
    </script>
    <script src="{{asset('public/vendor/unisharp/laravel-ckeditor/ckeditor.js')}}"></script>

@endsection