<div class="white-box">

            <div class="row" style="padding:20px">

                <div class="table-responsive" style="margin-bottom:25px">

   <table id="table_id1" style="margin-bottom:25px" class="display school-table table-responsive" cellspacing="0" width="100%">

                    <thead>

                        <tr>

                            <th width="6%">@lang('common.name')</th>

                            <th width="6%">@lang('student.admission_no')</th>

                            <th width="3%">P</th>

                            <th width="3%">L</th>

                            <th width="3%">A</th>

                            

                            <th width="3%">F</th>

                            <th width="3%">H</th>

                            <th width="2%">%</th>

                            @for($i = 1;  $i<=$days; $i++)

                            <th width="3%" class="{{($i<=18)? 'all':'none'}}">

                                {{$i}} <br>

                                @php

                                    $date = $year.'-'.$month.'-'.$i;

                                    $day = date("D", strtotime($date));

                                    echo $day;

                                @endphp

                            </th>

                            @endfor

                        </tr>

                    </thead>

                  

                    <tbody>

                        @php 

                        $total_grand_present = 0; 

                        $total_late = 0; 

                        $total_absent = 0; 

                        $total_holiday = 0; 

                        $total_halfday = 0; 

                        @endphp

                        @foreach($attendances as $values)
                        @php
                            $last_key_number = array_key_last(array($values));
                           
                        @endphp 
                        
                        @php $total_attendance = 0; @endphp

                        @php $count_absent = 0; @endphp

                        <tr>

                            <td>

                                @php $student = 0; @endphp

                                @foreach($values as $value)
                                
                                    @php $student++; @endphp

                                    @if($student == 1)

                                        {{@$value->full_name}}

                                    @endif

                                @endforeach

                               

                            </td>

                            <td>

                                @php $student = 0; @endphp

                                @foreach($values as $value)

                                    @php $student++; @endphp

                                    @if($student == 1)

                                        {{@$value->admission_no}}

                                    @endif

                                @endforeach

                               

                            </td>

                            <td>

                                @php $p = 0; @endphp

                                @foreach($values as $value)

                                    @if($value->attendance_type == 'P')

                                        @php $p++; $total_attendance++; $total_grand_present++; @endphp

                                    @endif

                                @endforeach

                                {{$p}}

                            </td>

                            <td>

                                @php $l = 0; @endphp

                                @foreach($values as $value)

                                    @if($value->attendance_type == 'L')

                                        @php $l++; $total_attendance++; $total_late++; @endphp

                                    @endif

                                @endforeach

                                {{$l}}

                            </td>

                            <td>

                                @php $a = 0; @endphp

                                @foreach($values as $value)

                                    @if($value->attendance_type == 'A')

                                        @php $a++; $count_absent++; $total_attendance++; $total_absent++; @endphp

                                    @endif

                                @endforeach

                                {{$a}}

                            </td>

                            

                            <td>

                                @php $f = 0; @endphp

                                @foreach($values as $value)

                                    @if($value->attendance_type == 'F')

                                        @php $f++; $total_attendance++; $total_halfday++; @endphp

                                    @endif

                                @endforeach

                                {{$f}}

                            </td>

                            <td>

                                @php $h = 0; @endphp

                                @foreach($values as $value)

                                    @if($value->attendance_type == 'H')

                                        @php $h++; $total_attendance++; $total_holiday++; @endphp

                                    @endif

                                @endforeach

                                {{$h}}

                            </td>

                            <td>  

                                @php
                                     $total_present = $total_attendance - $count_absent;
                                @endphp
                                {{$total_present.'/'.$total_attendance}}
                                <hr>
                               @php


                                 if($count_absent == 0){

                                     echo '100%';

                                 }else{

                                     $percentage = $total_present / $total_attendance * 100;

                                     echo number_format((float)$percentage, 2, '.', '').'%';

                                 }

                               @endphp



                            </td>

                            @for($i = 1;  $i<=$days; $i++)

                            @php

                                $date = $year.'-'.$month.'-'.$i;

                                $y = 0;

                            @endphp

                            <td width="3%" class="{{($i<=18)? 'all':'none'}}">

                                @php
                                    $date_present=0;
                                    $date_absent=0;
                                    $date_total_class=0;
                                @endphp
                                @foreach($values as $key => $value)

                                    @if(strtotime($value->attendance_date) == strtotime($date))

                                    @php
                                            
                                    
                                        if($value->attendance_type=='P'){
                                            $date_present++;
                                        }else{
                                            $date_absent++;
                                        }
                                        $date_total_class=$date_present+$date_absent;
                                    @endphp
                                        {{-- {{$value->attendance_type}} --}}
                                    @endif

                                @endforeach
                                        {{-- Date Report --}}
                                   

                                @if ($date_total_class!=0)
                                    
                                {{$date_present.'/'.$date_total_class}}
                                <hr>
                                
                                @php


                                if($date_absent == 0){

                                    echo '100%';

                                }else{
                                    // echo $date_present;
                                    if ($date_present!=0) {
                                      
                                        $date_percentage = $date_present / $date_total_class * 100;
                                        echo @number_format((float)$date_percentage, 2, '.', '').'%';
                                    }else{
                                        echo '0%';
                                    }
                                }

                            @endphp
                                @endif


                            </td>

                            @endfor

                        </tr>

                        @endforeach

                    </tbody>

                </table>

    </div>