@extends('backend._partials.app')
@section('maincontent')
    <style type="text/css">
        .btn-simple.btn-icon{
            padding: 1px !important;
        }
        .fresh-datatables table tbody tr td {
            padding: 8px;
        }
    </style>
    <div class="card col-md-12">
        <div class="header">
            <h4 class="title" style="display: inline;">Users Details</h4>
        </div>
        <div class="content">
            <div class="row">
                <div class="col-md-3">
                    <div class="card card-user">

                        <div class="content">
                            <div class="author">
                                <a href="javascript:void(0)">
                                    @if(empty($user->image))
                                        <img src="{{asset("public/img/users/default-avatar.png")}}" height="100">
                                    @else
                                        <img class="avatar border-gray" src="{{asset("public/img/users/$user->image")}}" height="100">
                                    @endif

                                    <h4 class="title">{{$user->first_name}}<br>
                                        <span class="text-info">{{@$user->designation->title}}</span><br>
                                        <small>{{$user->email}}</small>
                                    </h4>
                                    @if($user->status==1)
                                        <label class="label label-success">Active</label>
                                    @else
                                        <label class="label label-warning">Inactive</label>
                                    @endif
                                </a>
                            </div>

                        </div>

                    </div>
                </div>
                <div class="col-md-9">
                    <div class="col-md-6">
                        <table class="table table-stripped col-md-6">
                            <tbody>
                            <tr>
                                <th>First Name</th><td>{{$user->first_name}}</td>
                            </tr>
                            <tr>
                                <th>Last Name</th><td>{{$user->last_name}}</td>
                            </tr>
                            <tr>
                                <th>Join Date</th><td>{{$user->join_date}}</td>
                            </tr>
                            <tr>
                                <th>IN</th><td>{{$user->in_time}}</td>
                            </tr>
                            <tr>
                                <th>OUT</th><td>{{$user->out_time}}</td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="col-md-6">
                        <table class="table table-stripped col-md-6">
                            <tbody>
                            <tr>
                                <th>Mobile No</th><td>{{$user->mobile_no}}</td>
                            </tr>
                            <tr>
                                <th>Present Address</th><td>{{$user->present_address}}</td>
                            </tr>
                            <tr>
                                <th>Permanent Address</th><td>{{$user->permanent_address}}</td>
                            </tr>
                            <tr>
                                <th>Last Login</th><td>{{$user->last_login_time}}</td>
                            </tr>
                            <tr>
                                <?php
                                    $working= json_decode($user->userGroup->working_day);
                                    if(is_null($working)){
                                        $working="Not setup yet";
                                    }else{
                                        $working= implode(", ",$working);
                                    }
                                ?>
                                <th>Working days</th><td>{{$working}}</td>
                            </tr>

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


                </div>

            </div>
        </div>
    </div>
    <div class="card col-md-6 col-md-offset-3">
        <div class="content">
            <div class="row">
                {!! Form::open(['url'=>'user-details-report']) !!}
                {!! Form::hidden('user_id',$user->id) !!}
                {!! Form::hidden('search',true) !!}
                <div class="col-md-5">
                    <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-5">
                    <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-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">
        <div class="header text-center">
            <h4 class="title">Report: <strong>{{Helper::onlyDMY($from_date)}}</strong> to <strong>{{Helper::onlyDMY($to_date) }}</strong></h4>
            <div class="report-box">
                <div>
                    <div class="suc"><span>{{$attendanceSummary['present']}}</span> days</div>
                    Present
                </div>
                <div>
                    <div class="dan"><span>{{$attendanceSummary['absent']}}</span> days</div>
                    Absent
                </div>
                <div>
                    <div class="pri"><span>{{$attendanceSummary['close']}}</span> days</div>
                    Close
                </div>
                <div>
                    <div class="war"><span>{{$attendanceSummary['leave']}}</span> days</div>
                    Leave
                </div>
                <div>
                    <div class="suc"><span>{{$attendanceSummary['holiday_spent']}}</span> days</div>
                    Holiday
                </div>
                <div>
                    <div class="inf"><span>{{ $holidayLeft }}</span> days</div>
                    Holiday left
                </div>
                <div>
                    <div class="dan"><span>{{$attendanceSummary['late_count']}}</span> days</div>
                    Late
                </div>
            </div>
        </div>
        <div class="content">
            <div class="fresh-datatables">
                <table id="datatable" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%" style="width:100%">
                    <thead>
                    <tr>
                        <th>Date</th>
                        <th>IN</th>
                        <th>Out</th>
                        <th>Works</th>
                        <th>Task</th>
                        <th>Status</th>
                        <th>Action</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $totalWorks=0; rsort($result); ?>
                    @foreach($result as $data)
                        <?php
                        $minTime= $data['in_out']['min_time'];
                        $maxTime= $data['in_out']['max_time'];
                        $timeCalc= $data['in_out']['time_calc'];
                        ?>
                        @if($data['in_out']['date']==date('Y-m-d'))
                            <tr style="background-color:#D7F4D1">
                        @else
                            <tr>
                                @endif
                                <td>{{Helper::onlyDMY($data['in_out']['date'])}}</td>
                                <td> @if(strlen($minTime)>3) {{Helper::onlyTime($minTime)}} @endif</td> <!-- Actually this condition is check if any data which is greater than null i mean 3 char-->
                                <td>@if(strlen($maxTime)>3) {{Helper::onlyTime($maxTime)}} @endif</td>
                                <td>@if(strlen($timeCalc)>3) {{Helper::secondsToTime($timeCalc)}} @endif</td>
                                <td>@if($data['todayTask']!=null) {{strip_tags(substr($data['todayTask']->details,0,60))}}... @endif</td>
                                <?php $totalWorks+=$timeCalc; ?>
                                <td>
                                    @if($data['status']=='Present')
                                        <label class="label label-success my-present">{{$data['status']}}</label>
                                    @elseif($data['status']=='Closed')
                                        <label class="label label-primary my-close">Close</label>
                                    @elseif($data['status']=='Absent')
                                        <label class="label label-danger my-absent">{{$data['status']}}</label>
                                    @elseif($data['status']=='Exchanged')
                                        <label class="label label-default" title="Exchanged with {{$data['exchangeDate']}}">{{$data['status']}} with {{$data['exchangeDate']}}</label>
                                    @elseif($data['status']=='Applied for leave')
                                        <label class="label label-warning">{{$data['status']}}</label>
                                    @elseif($data['status']=='Leave')
                                        <label class="label label-info my-leave">{{$data['status']}}</label>
                                    @elseif($data['status']=='Past')
                                        <label title="Not join yet" class="label label-default" style="opacity:0.2"> - - - - - - </label>
                                    @elseif($data['status']=='Future')
                                        <label title="Future date" class="label label-default" style="opacity:0.2"> - - - - - - </label>
                                    @endif
                                </td>
                                <td style="cursor:pointer;" data-toggle="modal" data-target="#modal"  onclick="loadModalEdit('daily-in-out-report',{{$user->id}},'{{$data['in_out']['date']}}')">
                                    <a href="#" title="Detail" class="btn btn-simple btn-info btn-icon"><i class="fa fa-search-plus" style="font-size: 20px;"></i></a>
                                </td>

                            </tr>
                            @endforeach
                    </tbody>
                    <tfoot>
                    <tr>
                        <td colspan="3"></td>
                        <th>Total</th>
                        <td>{{Helper::secondsToTime($totalWorks)}}</td>
                        <td colspan="2"></td>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>


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

        });
        function taskDetails(i) {
            swal({  title: 'Task Details',
                html:$("#"+i).text()
            });
        }
    </script>
@endsection
