@extends('layouts.dashboard')
@section('page-title')
    {{__('Monthly Attendance')}}
@endsection
@push('script-page')
    <script type="text/javascript" src="{{ asset('js/html2pdf.bundle.min.js') }}"></script>
    <script>


        var filename = $('#filename').val();

        function saveAsPDF() {
            var element = document.getElementById('printableArea');
            var opt = {
                margin: 0.3,
                filename: filename,
                image: {type: 'jpeg', quality: 1},
                html2canvas: {scale: 4, dpi: 72, letterRendering: true},
                jsPDF: {unit: 'in', format: 'A2'}
            };
            html2pdf().set(opt).from(element).save();

        }
    </script>

@endpush
@section('content')
    <div class="main-content">
        <section class="section">
            <div class="section-header">
                <h1>{{__('Manage Monthly Attendance')}}</h1>
                <div class="section-header-breadcrumb">
                    <div class="breadcrumb-item active"><a href="{{route('home')}}">{{__('Dashboard')}}</a></div>
                    <div class="breadcrumb-item">{{__('Monthly Attendance')}}</div>
                </div>
            </div>
            <div class="section-body">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                {{ Form::open(array('route' => array('report.monthly.attendance'),'method'=>'get')) }}
                                <div class="row">
                                    <div class="col">
                                        <h4 class="h4 mb-0">{{__('Filter')}}</h4>
                                    </div>
                                    <div class="col-md-2">
                                        {{Form::label('month',__('Month'))}}
                                        {{Form::month('month',isset($_GET['month'])?$_GET['month']:date('Y-m'),array('class'=>'form-control'))}}
                                    </div>
                                    <div class="col-md-2">
                                        {{ Form::label('branch', __('Branch')) }}
                                        {{ Form::select('branch', $branch,isset($_GET['branch'])?$_GET['branch']:'', array('class' => 'form-control select2')) }}
                                    </div>
                                    <div class="col-md-2">
                                        {{ Form::label('department', __('Department')) }}
                                        {{ Form::select('department', $department,isset($_GET['department'])?$_GET['department']:'', array('class' => 'form-control select2')) }}
                                    </div>
                                    <div class="col-auto apply-btn">
                                        {{Form::submit(__('Apply'),array('class'=>'btn btn-outline-primary btn-sm'))}}
                                        <a href="{{route('report.monthly.attendance')}}" class="btn btn-outline-danger btn-sm">{{__('Reset')}}</a>
                                        <a href="#" class="btn btn-outline-warning btn-sm mb-1" onclick="saveAsPDF()" id="">{{__('Download')}}</a>
                                    </div>
                                </div>
                                {{ Form::close() }}
                            </div>
                        </div>
                    </div>
                </div>
                <div id="printableArea">
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card">
                                <div class="card-wrap">
                                    <div class="card-body">
                                        <input type="hidden" value="{{  $data['branch'] .' '.__('Branch') .' '.$data['curMonth'].' '.__('Attendance Report of').' '. $data['department'].' '.'Department'}}" id="filename">

                                        <div class="row">
                                            <div class="col">
                                                {{__('Report')}} : <h6>{{__('Attendance Summary')}}</h6>
                                            </div>
                                            @if($data['branch']!='All')
                                                <div class="col">
                                                    {{__('Branch')}} : <h6>{{($data['branch']) }}</h6>
                                                </div>
                                            @endif
                                            @if($data['department']!='All')
                                                <div class="col">
                                                    {{__('Department')}} : <h6>{{$data['department'] }}</h6>
                                                </div>
                                            @endif
                                            <div class="col">
                                                {{__('Duration')}} : <h6>{{$data['curMonth']}}</h6>
                                            </div>

                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-3 col-md-6 col-sm-6 col-12">
                            <div class="card card-statistic-1">
                                <div class="card-wrap">
                                    <div class="card-header">
                                        <h4>{{__('attendance')}}</h4>
                                    </div>

                                </div>
                                <div class="card-stats">
                                    <div class="card-stats-title">
                                        <div class="progreess-status mt-2">
                                            <span>{{__('Total present')}} :</span>
                                            <span><strong>{{$data['totalPresent']}} </strong></span>
                                            <span class="float-right"><strong>{{$data['totalLeave']}} </strong></span>
                                            <span class="float-right">{{__('Total leave')}} :</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3 col-md-6 col-sm-6 col-12">
                            <div class="card card-statistic-1">
                                <div class="card-wrap">
                                    <div class="card-header">
                                        <h4>{{__('overtime')}}</h4>
                                    </div>
                                </div>
                                <div class="card-stats">
                                    <div class="card-stats-title">
                                        <div class="progreess-status mt-2">
                                            <span>{{__('Total overtime in hours')}} :</span>
                                            <span><strong>{{number_format($data['totalOvertime'],2)}} </strong></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3 col-md-6 col-sm-6 col-12">
                            <div class="card card-statistic-1">
                                <div class="card-wrap">
                                    <div class="card-header">
                                        <h4>{{__('early leave')}}</h4>
                                    </div>
                                </div>
                                <div class="card-stats">
                                    <div class="card-stats-title">
                                        <div class="progreess-status mt-2">
                                            <span>{{__('Total early leave in hours')}} :</span>
                                            <span><strong>{{number_format($data['totalEarlyLeave'],2)}} </strong></span>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-3 col-md-6 col-sm-6 col-12">
                            <div class="card card-statistic-1">
                                <div class="card-wrap">
                                    <div class="card-header">
                                        <h4>{{__('employee late')}}</h4>
                                    </div>
                                </div>
                                <div class="card-stats">
                                    <div class="card-stats-title">
                                        <div class="progreess-status mt-2">
                                            <span>{{__('Total late in hours')}} :</span>
                                            <span><strong>{{number_format($data['totalLate'],2)}} </strong></span>

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

                    </div>
                    <div class="row">
                        <div class="col">
                            <div class="card">
                                <div class="card-body">
                                    <div class="table-responsive py-4 attendance-table-responsive">
                                        <table class="table table-striped mb-0" id="dataTable-1">
                                            <thead>
                                            <tr>
                                                <th class="active">{{__('Name')}}</th>
                                                @foreach($dates as $date)
                                                    <th>{{$date}}</th>
                                                @endforeach
                                            </tr>
                                            </thead>
                                            <tbody>
                                            @foreach($employeesAttendance as $attendance)

                                                <tr>
                                                    <td>{{$attendance['name']}}</td>
                                                    @foreach($attendance['status'] as $status)
                                                        <td>
                                                            @if($status=='P')
                                                                <i class="custom-badge badge-success">{{__('P')}}</i>
                                                            @elseif($status=='L')
                                                                <i class="custom-badge badge-danger">{{__('L')}}</i>
                                                            @endif
                                                        </td>
                                                    @endforeach
                                                </tr>
                                            @endforeach
                                            </tbody>
                                        </table>

                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
@endsection

