<?php
$class=$this->uri->segment('3');
$section=$this->uri->segment('4');
$exam_id=$this->uri->segment('5');
$acedemic_session=$this->session->userdata('acedemic_session');
$all_students=$this->ExamManagementModel->get_students_ac_session_by_course_and_class_new($acedemic_session,$class,$section);
$exam_head_table='exam_head_master_'.$acedemic_session;

$exam_id_term_1=1;

$get_term_1_course_exam_heads=$this->ExamManagementModel->get_course_exam_wise_heads($class,$exam_id_term_1,$exam_head_table);

$get_term_2_course_exam_heads=$this->ExamManagementModel->get_course_exam_wise_heads($class,$exam_id,$exam_head_table);

// $get_course_exam_heads=$this->ExamManagementModel->get_course_exam_wise_heads($class,$exam_id,$exam_head_table);

$ehcount_1=count($get_term_1_course_exam_heads);
$ehcount=count($get_term_2_course_exam_heads);
                            
$subject_table='exam_subject_master_'.$acedemic_session;
$get_course_exam_subjects=$this->ExamManagementModel->get_course_active_subjects($class,$subject_table);

$t1_exam_id=1;

$promoted_class="";

if($class == "NURSERY"){
    $promoted_class="LKG";
}else if($class == "LKG"){
    $promoted_class="UKG";
}else if($class == "UKG"){
    $promoted_class=1;
}else{
    $promoted_class=$class + 1;    
}


if($promoted_class == 1){
    $promoted_class=$promoted_class."<sup>st</sup>";
}else if($promoted_class == 2){
    $promoted_class=$promoted_class."<sup>nd</sup>";
}else if($promoted_class == 3){
    $promoted_class=$promoted_class."<sup>rd</sup>";
}else if($promoted_class == 4 || $promoted_class == 5 || $promoted_class == 6 || $promoted_class == 7 || $promoted_class == 8 || $promoted_class == 9  || $promoted_class == 10 || $promoted_class == 11 || $promoted_class == 12){
    $promoted_class=$promoted_class."<sup>th</sup>";
}
?>
<!DOCTYPE html>
<html>
    <head>
        <link rel="preconnect" href="https://fonts.googleapis.com">
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link href="https://fonts.googleapis.com/css2?family=Inconsolata:wght@200;300;400;500;600;700&display=swap" rel="stylesheet"> 
        <title>Term II Report Card</title>
        <style>
            html{padding:0px;margin:0px;}
            body{
                padding:15px;margin:0px;vertical-align:middle;
                font-family: 'Inconsolata', monospace;
            }
            .report-card{
                border : 2px solid #4F3F83;
                height:95%;
                border-radius:5px;
                margin:0px;
                padding:5px;
            }
            .report-2{
                border:1px solid #4F3F83 !important;
                height:96%;
                border-radius:5px;
                
            }
            
            
            .report-card-body{
                background-image: url("<?php echo logo_png; ?>");
                opacity: 0.1;
                background-repeat: no-repeat;
                background-size:auto 40%;
                background-position: center;
            }
            table{border-collapse:collapse;width:100%;}
            table tr{
                border :1px solid !important;
                border-collapse:collapse;
            }
            tr th{
                margin:0px;
                padding:2px;
                font-size:14px;
                font-weight:700;
                border :1px solid !important;
                border-collapse:collapse;
            }
            .report-3{
                height:97%;
                /*background-image: url("<?php echo logo_png; ?>");*/
                /*opacity: 0.1;*/
                /*background-repeat: no-repeat;*/
                /*background-size:auto 40%;*/
                /*background-position: center;*/
            }
        </style>
    </head>
    <body>
        
<?php

// var_dump($get_course_exam_heads);
$count=0;
if($all_students){
    foreach($all_students as $students){
        ?>
        <!--<div style="width:100%;height:100%;">-->
        <!--    <img src="<?php echo base_url(); ?>assets/a.png" style="width:100% !important;height:100% !important;">-->
        <!--</div>-->
        <?php
        $t1_height=0;
        $t1_weight=0;
        
        $height=0;
        $weight=0;
        
        $sid=$students['sid'];
        $student_table='student';
        $course_id=$students['course_id'];
        $roll_no=$students['roll_no'];
        // $height=$students['height'];
        // $weight=$students['weight'];
        
        
        $working_days=0;
        $exam_course_data_table="exam_course_data";
        $get_exam_course_data=$this->ExamManagementModel->get_session_exam_course_data($exam_id,$course_id,$acedemic_session);
        if($get_exam_course_data){
            foreach($get_exam_course_data as $exam_course_data){
                $working_days=$exam_course_data['working_days'];
            }
        }
        
        $t1_working_days=0;
        $get_t1_exam_course_data=$this->ExamManagementModel->get_session_exam_course_data($t1_exam_id,$course_id,$acedemic_session);
        if($get_t1_exam_course_data){
            foreach($get_t1_exam_course_data as $t1_exam_course_data){
                $t1_working_days=$t1_exam_course_data['working_days'];
            }
        }

        // $get_student_data=$this->NewExamModel->get_item_data($sid,$student_table);
        // if($get_student_data ){
        //     foreach($get_student_data as $students){
                    
                // if($students['status'] == 1){
                    $count=$count + 1;
                    if($count <=100){
                        
                        $remark="";
                        $student_name=$students['student_name'];
                        $father_name=$students['father_name'];
                        $dob=date('d-m-Y',strtotime($students['dob']));
                        $sch_no=$students['sch_no'];
                            
                        $attendance_days=0;
                            
                        $attendance=0;
                        $remark='';
                        $result_table='exam_result';
                        // $exam_id=3;
                        
                        $rank_in_class="";
                        $result_status="";
                        
                        $t1_attendance_days=0;
                        $get_student_t1_exam_data=$this->NewExamModel->get_student_exam_data($sid,$t1_exam_id,$course_id,$result_table);
                        if($get_student_t1_exam_data){
                            foreach($get_student_t1_exam_data as $t1_exam_data){
                                $t1_attendance_days=$t1_exam_data['attendance_days'];
                                $t1_height=$students['height'];
                                $t1_weight=$students['weight'];
                            }
                            
                        }
                        $check_student_exam_data=$this->NewExamModel->get_student_exam_data($sid,$exam_id,$course_id,$result_table);
                        if($check_student_exam_data){
                            foreach($check_student_exam_data as $exam_data){
                                $attendance_days=$exam_data['attendance_days'];
                                    $remark=$exam_data['remark'];
                                    // $attendance=$exam_data['attendance'];
                                    // $roll_no=$exam_data['roll_no'];
                                    $rank_in_class=$exam_data['rank_in_class'];
                                    $result_status=trim($exam_data["result_status"]);
                                    $height=$students['height'];
                                    $weight=$students['weight'];
                                }
                            }
                            
                            if($working_days > 0){
                                $attendance=$attendance_days * 100/$working_days;
                            }
                            
                            
                            $avg_attendance=0;
                            $avg_working_days=$working_days + $t1_working_days;
                            $avg_attendance_days=$attendance_days + $t1_attendance_days;
                            if($avg_working_days > 0){
                                $avg_attendance=$avg_attendance_days * 100/$avg_working_days;
                            }
// $exam_head_table='exam_heads_3';
// $get_course_exam_heads=$this->ReportCardModel->get_course_active_exam_heads($course_id,$exam_head_table);
                            
// $course_subjects_table='exam_subjects_3';
// $get_course_exam_subjects=$this->ReportCardModel->get_course_active_subjects($course_id,$course_subjects_table);



$student_subjects_table="student_subjects_".$acedemic_session;
$get_student_subjects=$this->ExamManagementModel->get_student_subjects($sid,$course_id,$acedemic_session,$student_subjects_table);



$elog_table="exam_log_".$acedemic_session;
$get_exam_log=$this->NewExamModel->students_exam_log($sid,$acedemic_session,$elog_table);
?>
        <div class="report-card p-1">
            <div class="report-2" >
                <div class="report-3">
                <!--<div style="height:100px;">-->
                <!--</div>-->
                <div>
                    <table class="table" style="width:100%;border:1px solid #4F3F83;width:100%;">
                        <tr>
                            <th style="width:15%;border:none !important;">
                                <img src='<?php echo school_logo_full_1; ?>' style="width:auto;height:80px;" />
                            </th>
                            <th style="width:85%;border:none !important;">
                                <p style="padding:0px; margin:0px;font-size:26px;text-align:center;font-weight:900;color:#29166f;"><?php echo school_full_name_1; ?></p>
                                <p style='padding:0px; margin:0px;text-align:center;color:#29166f;font-size:18px;'><b><?php echo school_address_1; ?></b></p>
                                
                                <p style='padding:0px; margin:0px;text-align:center;color:#29166f;font-size:18px;'><b>PROGRESS REPORT 2023-2024</b></p>
                            </th>
                        </tr>
                    </table>
                </div>
                <table style="text-align:left;">
                    <tr>
                        <th style="text-align:left;">
                            
                <div style="width:100%;height:25px;">
                    <div style='width:40%;float:left;margin:0px;padding:0px;'>
                        <p class='pl-1' style='margin:0px;padding:0px;padding-left:5px;text-transform:uppercase;'><b>NAME: </b><?php echo $student_name;?></p>
                    </div>

                    <div style='width:20%;float:left;'>
                        <p style='margin:0px;padding:0px;'><b>SCHOLAR NO: </b><?php echo $sch_no; ?></p>

                    </div>

                    <div style='width:20%;float:left;'>
                        <p style='margin:0px;padding:0px;'><b>ROLL NO: <?php echo sprintf("%02d",$roll_no); ?></b></p>

                    </div>

                    <div style='width:20%;float:left;'>
                        <p style='margin:0px;padding:0px;'><b>ATTENDANCE: </b><?php echo round($avg_attendance,2); ?>%(<?php echo $avg_attendance_days."/".$avg_working_days; ?>)</p>


                    </div>
                </div>
                <div style="width:100%;height:25px;">
                    <div style='width:60%;float:left;margin:0px;padding:0px;'>
                        
                        <p class='pl-1' style='margin:0px;padding:0px;padding-left:5px;text-transform:uppercase;'><b>FATHER'S NAME: </b><?php echo $father_name; ?></p>
                    </div>
                    <div style='width:20%;float:left;'>
                        <p style='margin:0px;padding:0px;'><b>D.O.B: </b><?php echo $dob; ?></p>
                    </div>
                    <div style='width:20%;float:left;'>
                        <p style='margin:0px;padding:0px;'><b>CLASS: </b><?php echo $class; echo "-"; echo $section; ?></p>
                    </div>

                    
                </div>

                        </th>
                    </tr>
                </table>
                
                <div style="padding:0px;" class="report-card-body">
                    <table class="table table-bordered" style="width:100%;">
                        <thead>
                            <tr style="margin:0px;padding:0px;background:#DBF7F3;">
                                <th style="text-align:center;margin:0px;font-weight:700;" colspan="<?php echo $ehcount + $ehcount_1 + 2 + 5 + 1; ?>"><b>ACADEMIC PERFORMANCE</b></th>
                            </tr>
                            <tr>
                                <th colspan="2" style="max-width:250px !important;margin:0px;height:20px;" rowspan="3">&nbsp;SUBJECTS</th>
                                <th rowspan="3">MM</th>
                                <th colspan="<?php echo $ehcount_1 + 1; ?>">TERM I</th>
                                <th colspan="<?php echo $ehcount + 1; ?>">TERM II</th>
                                <th rowspan="2">GRAND <br>TOTAL.</th>                                                                        
                                <th rowspan="2">AVG.</th>
                                <th rowspan="3">GRADE</th>
                            </tr>
                            <tr>
                                <?php
                                $mm_eh_total=0;
                                // var_dump($get_course_exam_heads);
                                if($get_term_1_course_exam_heads){
                                    foreach($get_term_1_course_exam_heads as $exam_heads){
                                        $mm_eh_total=$mm_eh_total + $exam_heads['mm'];
                                ?>
                                <th style="text-align:center;height:20px;font-size:12px;text-transform:uppercase;"><?php echo $exam_heads['exam_head'];?>
                                </th>
                                
                                <?php
                                        
                                    }
                                }
                                ?>
                                <th>Total</th>
                                
                                <?php
                                $mm_eh_total=0;
                                // var_dump($get_course_exam_heads);
                                if($get_term_2_course_exam_heads){
                                    foreach($get_term_2_course_exam_heads as $exam_heads_2){
                                        $mm_eh_total=$mm_eh_total + $exam_heads_2['mm'];
                                ?>
                                <th style="text-align:center;height:20px;text-transform:uppercase;"><?php echo $exam_heads_2['exam_head'];?>
                                </th>
                                <?php
                                        
                                    }
                                }
                                ?>
                                <th>Total</th>
                            </tr>
                            
                            <tr>
                                <?php
                                $mm_eh_total=0;
                                // var_dump($get_course_exam_heads);
                                if($get_term_1_course_exam_heads){
                                    foreach($get_term_1_course_exam_heads as $exam_heads){
                                        $mm_eh_total=$mm_eh_total + $exam_heads['mm'];
                                ?>
                                <th style="text-align:center;height:20px;text-transform:uppercase;"><?php echo $exam_heads['mm'];?>
                                </th>
                                
                                <?php
                                        
                                    }
                                }
                                ?>
                                <th style="text-align:center;height:20px;text-transform:uppercase;">100</th>
                                
                                <?php
                                $mm_eh_total=0;
                                // var_dump($get_course_exam_heads);
                                if($get_term_2_course_exam_heads){
                                    foreach($get_term_2_course_exam_heads as $exam_heads_2){
                                        $mm_eh_total=$mm_eh_total + $exam_heads_2['mm'];
                                ?>
                                <th style="text-align:center;height:20px;text-transform:uppercase;"><?php echo $exam_heads_2['mm'];?>
                                </th>
                                <?php
                                        
                                    }
                                }
                                ?>
                                <th style="text-align:center;height:20px;text-transform:uppercase;">100</th>
                                <th style="text-align:center;height:20px;text-transform:uppercase;">200</th>
                                <th style="text-align:center;height:20px;text-transform:uppercase;">100</th>
                            </tr>
                            
                        </thead>
                        <tbody>
                            
                            <?php
                            
                            $sub_failure_count=0;
                            
                            $mm_total=0;
                            $grand_total=0;
                            $hy_grand_total=0;
                            $annual_grand_total=0;
                            
                            $t1_grand_total=0;
                            $t2_grand_total=0;
                            if($get_course_exam_subjects){
                                foreach($get_course_exam_subjects as $subjects){
                                    $subject_id=$subjects['id'];
                                    $exam_type=$subjects['exam_type'];
                                    $student_subject=0;
                                    if($get_student_subjects){
                                        foreach($get_student_subjects as $subjectss){
                                            if($subjectss['subject_id'] == $subject_id){
                                                $student_subject=$student_subject + 1;    
                                            }
                                        }
                                    }
                                    
                                    if($student_subject == 1  && $exam_type == "Marks"){
                                        $subject_mm=$subjects['MM'];
                                        $obtained_marks_t1=0;
                                        $obtained_marks_t2=0;
                                        $hy_total=0;
                                        
                                        
                                        $t1_sub_total=0;
                                        $t2_sub_total=0;
                                        
                                        $t1_total=0;
                                        $t2_total=0;
                                        
                                        // $hic=$subjects['hy_hic'];
                                        $hic=0;
                                        $get_hic_data=$this->ExamManagementModel->get_hic_data_manual($subject_id,$class,$section,$acedemic_session);
                                        if($get_hic_data){
                                            foreach($get_hic_data as $hic_data){
                                                $hic=$hic_data['hy_total_marks'];
                                            }
                                        }
                                        
                                        
                                        $sub_total=0;
                                        $sub_type=$subjects['subject_type'];
                            ?>                    
                            <tr style="padding:0px;margin:0px;">
                                <th style="margin:0px;text-align:left;width:250px !important" colspan="2">&nbsp;<?php echo $subjects['subject']; ?>
                                </th>
                                <th><?php 
                                if($exam_type == "Marks"){
                                    echo $subject_mm; 
                                }else{
                                    echo "Grade";
                                }
                                ?>
                                </th>
                                
                                <?php 
                                $grade="";
                                if($get_term_1_course_exam_heads){
                                    foreach($get_term_1_course_exam_heads as $exam_heads){
                                    // if($exam_heads['exam_mode'] =='FirstTerm'){
                                    
                            ?>         
                            <th style="text-align:center;margin:0px;">
                               <?php
                               $ehid=$exam_heads['id'];
                                    if($get_exam_log){
                                    foreach($get_exam_log as $elog){
                                        
                                        if($elog['exam_head'] == $ehid && $elog['subject_id'] == $subject_id){
                                            
                                        $e_log_attendance=$elog['attendance'];
                                        if($e_log_attendance == "A" || $e_log_attendance == "ML"){
                                            echo "<span style='color:red;'>".$e_log_attendance."</span>";
                                        }else{
                                            if($exam_type == "Marks"){
                                                $obtained_marks_t1=$obtained_marks_t1 + $elog['obtained_marks'];
                                                   
                                        // $hy_grand_total=$hy_grand_total + $obtained_marks;
                                                
                                                if($obtained_marks_t1 > $subject_mm){
                                            echo "<span style='background:red;'>".$elog['obtained_marks']."</span>";
                                        }else{
                                            echo sprintf("%02d",$elog['obtained_marks']);
                                        }
                                        
                                            }else if($exam_type == "Grade"){
                                                
                                
                                                    $grade=$elog['grade'];
                                        
                                                
                                                // echo $elog['grade'];
                                            }
                                        }    
                                        }
                                        
                                    
                                            }
                                            
                                            
                                            
                                            
                                            
                                        }else{
                                        
                                        echo "--";
                                        
                                        }
                                        ?>    
                                        </th>
                                <?php        
                                        
                                    }
                                }
                                ?>
                                <th style="margin:0px;text-align:center;">
                                    <?php 
                                    if($exam_type == "Marks"  ){ 
                                        $t1_sub_total=$t1_sub_total + $obtained_marks_t1;
                                        $t1_total=$t1_total + $obtained_marks_t1;    
                                        $sub_pc=($t1_sub_total*100)/$subject_mm;
                                        if($sub_pc > 33){
                                            echo sprintf("%02d",$t1_sub_total);
                                        }else{
                                            echo "<u> ".sprintf("%02d",$t1_sub_total)." </u>";
                                        }
                                        
                                        if($sub_type == "Main Subject"){
                                            
                                        }
                                    }else if($exam_type == "Grade"){
                                        // }
                                            
                                            echo $grade;
                                    }
                                    ?>
                                </th>
                                
                                
                                <?php 
                                $grade="";
                            if($get_term_2_course_exam_heads){
                                foreach($get_term_2_course_exam_heads as $exam_heads_2){
                                    // if($exam_heads['exam_mode'] =='FirstTerm'){
                                    
                            ?>         
                            <th style="text-align:center;margin:0px;">
                               <?php
                               $ehid=$exam_heads_2['id'];
                                    if($get_exam_log){
                                    foreach($get_exam_log as $elog){
                                        
                                        if($elog['exam_head'] == $ehid && $elog['subject_id'] == $subject_id){
                                            
                                        $e_log_attendance=$elog['attendance'];
                                        if($e_log_attendance == "A" || $e_log_attendance == "ML"){
                                            echo "<span style='color:red;'>".$e_log_attendance."</span>";
                                        }else{
                                            if($exam_type == "Marks"){
                                                $obtained_marks_t2=$obtained_marks_t2 + $elog['obtained_marks'];
                                                   
                                        // $hy_grand_total=$hy_grand_total + $obtained_marks;
                                                
                                                if($obtained_marks > $subject_mm){
                                            echo "<span style='background:red;'>".$elog['obtained_marks']."</span>";
                                        }else{
                                            echo sprintf("%02d",$elog['obtained_marks']);
                                        }
                                        
                                            }else if($exam_type == "Grade"){
                                                
                                
                                                    $grade=$elog['grade'];
                                        
                                                
                                                // echo $elog['grade'];
                                            }
                                        }    
                                        }
                                        
                                    
                                            }
                                            
                                            
                                            
                                            
                                            
                                        }else{
                                        
                                        echo "--";
                                        
                                        }
                                        ?>    
                                        </th>
                                <?php        
                                        
                                    }
                                }
                                ?>
                                <th style="margin:0px;text-align:center;">
                                    <?php 
                                    if($exam_type == "Marks"  ){
                                        $t2_sub_total=$t2_sub_total + $obtained_marks_t2;
                                        $t2_total=$t2_total + $obtained_marks_t2;    
                                        $sub_pc=($t2_sub_total*100)/$subject_mm;
                                        if($sub_pc > 33){
                                            echo sprintf("%02d",$t2_sub_total);
                                        }else{
                                            echo "<u> ".sprintf("%02d",$t2_sub_total)." </u>";
                                        }
                                        
                                        if($sub_type == "Main Subject"){
                                            
                                        }
                                    }else if($exam_type == "Grade"){
                                        // }
                                            
                                            echo $grade;
                                    }
                                    ?>
                                </th>
                                    <th style="margin:0px;text-align:center;">
                                        <?php
                                        if($exam_type == "Marks"  ){
                                            echo $t1_sub_total + $t2_sub_total; 
                                        }
                                        ?>
                                    </th>
                                 <th style="margin:0px;text-align:center;">
                                    <?php 
                                    if($exam_type == "Marks"  ){ 
                                        $sub_total=($t1_sub_total + $t2_sub_total)/2;
                                        // $annual_grand_total=$annual_grand_total + $obtained_marks;    
                                        $sub_pc=($sub_total*100)/$subject_mm;
                                        if($sub_pc >= 33){
                                            // echo sprintf("%02d",$sub_total);
                                            echo $sub_total;
                                        }else{
                                            // echo "<u> ".sprintf("%02d",$sub_total)." </u>";
                                            echo "<u> ".$sub_total." </u>";
                                        }
                                        
                                        if($sub_type == "Main Subject"){
                                            
                                        }
                                    }else if($exam_type == "Grade"){
                                        // }
                                            
                                            echo $grade;
                                    }
                                    ?>
                                </th>
                                
                                <th style="margin:0px;text-align:center;">
                                    <?php 
                                    if($exam_type == "Marks"){
                                        $sub_total=($t1_sub_total + $t2_sub_total)/2;
                                    if($sub_total >90 && $sub_total<=100 ){
                                        echo "A1";
                                    }else if($sub_total >80 && $sub_total<=90 ){
                                        echo "A2";
                                    }else if($sub_total >70 && $sub_total<=80 ){
                                        echo "B1";
                                    }else if($sub_total >60 && $sub_total<=70 ){
                                        echo "B2";
                                    }else if($sub_total >50 && $sub_total<=60 ){
                                        echo "C1";
                                    }else if($sub_total >40 && $sub_total<=50 ){
                                        echo "C2";
                                    }else if($sub_total >=33 && $sub_total<=40 ){
                                        echo "D";
                                    }else if($sub_total <33){
                                        echo "E";
                                    }
                                    }
                                    
                                    ?>
                                    
                                </th>
                            </tr>                    
                                                
                                                
                                                
                            <?php       
                            
                            $sub_mm=$subjects['MM'];
                            $sub_annual_total=($t1_sub_total + $t2_sub_total)/2;
                            $sub_avg_per=($sub_annual_total * 100)/$sub_mm;
                                
                            if($sub_type == "Main Subject"){
                                
                                
                                $mm_total=$mm_total + $subjects['MM'];
                                $grand_total= $grand_total + $sub_annual_total;    
                                $t1_grand_total=$t1_grand_total + $t1_sub_total;  
                                $t2_grand_total=$t2_grand_total + $t2_sub_total;
                            }
                            
                                
                                if($sub_avg_per < 33){
                                    $sub_failure_count=$sub_failure_count + 1;
                                }
                            
                            
                                    }
                                }
                            }
                            ?>
                            <tr style="background:#DBF7F3;border-top:1px solid #4F3F83 !important;padding:0px;margin:0px;">
                                <th colspan="2" style="margin:0px;textalign:left !important;">GRAND TOTAL</th>

                                
                                <th style="text-align:center;margin:0px;"><?php echo $mm_total; ?></th>
                                
                                <th colspan="<?php echo $ehcount; ?>"></th>
                                <th><?php echo $t1_grand_total; ?></th>
                                <th colspan="<?php echo $ehcount_1; ?>"></th>
                                <th><?php echo $t2_grand_total; ?></th>
                                <th><?php echo $t1_grand_total + $t2_grand_total; ?></th>
                                <!--<th></th>-->
                                
                                <th style="text-align:center;margin:0px;">
                                    <?php // echo sprintf("%02d",$grand_total); ?>
                                    <?php echo round($grand_total); ?>
                                </th>
                                <th></th>
                            </tr>
                            
                            <?php 
                            // $avg_grand_total=$grand_total/2;
                            $percentage="";
                            if($mm_total != 0){
                                $percentage=($grand_total * 100)/$mm_total;    
                            }else{
                                $percentage=0;
                            }
                            
                            ?>
                        </tbody>
                    </table>
                    
                    
                    <table style="width:100%">
                        <tr style="background:#DBF7F3;border:1px solid #4F3F83;padding:0px;margin:0px;">
                                <th style="margin:0px;text-align:left;padding-left:5px;width:50%;"> Rank in class : <?php
                                    if($rank_in_class <= 10){
                                        echo $rank_in_class;
                                    }
                                ?></th>
                                <th style="margin:0px;text-align:left;padding-left:5px;width:50%;"> PERCENTAGE : <b>&nbsp; <?php echo number_format((float)$percentage, 2, '.', ''); ?> % </b></th>
                                
                            </tr>
                            <tr style="background:#DBF7F3;border:1px solid #4F3F83;padding:0px;margin:0px;">
                                
                            
                                <th style="margin:0px;text-align:left;padding-left:5px;width:50%;">Half Yearly : Height : <?php echo $t1_height; ?> cm, Weight : <?php echo $t1_weight; ?> kg, Attendance : <b><?php echo $t1_attendance_days.'/'.$t1_working_days; ?></b></th>
                                
                                <th style="margin:0px;text-align:left;padding-left:5px;width:50%;">Annual : Height : <?php echo $height; ?> cm, Weight : <?php echo $weight; ?> kg, Attendance : <b><?php echo $attendance_days.'/'.$working_days; ?></b> </th>
                            </tr>
                            
                        </tbody>
                    </table>
                </div>
                
                <div style="padding:0px;">
                    <table style="border:1px solid;border-collapse:collapse;">
                        <tr style="height:25px;width:100%;text-align:center;margin-bottom:0px;">
                            <th colspan="2">CO SCHOLASTIC AREAS</th>
                        </tr>    
                        <tr>
                            <td style="width:50% !important">
                                <table style="height:auto;border:1px solid;border-collapse:collapse;">
                                    <tr>
                                        <th>SUBJECT</th>
                                        <th>TERM I</th>
                                        <th>TERM II</th>
                                    </tr>
                                <?php
                                if($get_course_exam_subjects){
                                    foreach($get_course_exam_subjects as $subjects){
                                        if($subjects['exam_type'] == "Grade" && $subjects['subject_group'] == "CO SCHOLASTIC AREAS"  && $subjects['subject_group_code'] =="A"){
                                            $subject_id=$subjects['id'];
                                            $t1_grade="";
                                            $head_t1_attendance="";
                                            // $get_term_1_course_exam_heads
                                            // $get_term_2_course_exam_heads
                                            if($get_term_1_course_exam_heads){
                                                foreach($get_term_1_course_exam_heads as $exam_heads){
                                                    $ehid=$exam_heads['id'];
                                                    if($get_exam_log){
                                                        foreach($get_exam_log as $elog){
                                        
                                                            if($elog['exam_head'] == $ehid && $elog['subject_id'] == $subject_id){
                                            
                                                                $e_log_attendance=$elog['attendance'];
                                                                if($e_log_attendance == "A" || $e_log_attendance == "ML"){
                                                                    $head_t1_attendance=$e_log_attendance;
                                                                }else{
                                                                    $t1_grade=$elog['grade'];
                                            
                                                                }    
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            
                                            $t2_grade="";
                                            $head_t2_attendance="";
                                            if($get_term_2_course_exam_heads){
                                                foreach($get_term_2_course_exam_heads as $exam_heads){
                                                    $ehid=$exam_heads['id'];
                                                    if($get_exam_log){
                                                        foreach($get_exam_log as $elog){
                                        
                                                            if($elog['exam_head'] == $ehid && $elog['subject_id'] == $subject_id){
                                            
                                                                $e_log_attendance=$elog['attendance'];
                                                                if($e_log_attendance == "A" || $e_log_attendance == "ML"){
                                                                    $head_t2_attendance=$e_log_attendance;
                                                                }else{
                                                                    $t2_grade=$elog['grade'];
                                            
                                                                }    
                                                            }
                                                        }
                                                    }
                                                }
                                            }
	                                        ?>
	                                    <tr style="height:20px;width:100%;border-bottom:1px solid; border-left:1px solid;border-right:1px solid;">
	                                        <th style="text-align:left;width:50%;float:left;">&nbsp;<?php echo $subjects['subject']; ?></th>
	                                        <th style="width:25%;float:right;border-left:1px solid;text-align:center;"><?php if($head_t1_attendance == "A" || $head_t1_attendance == "ML"){ if($head_t1_attendance == "A"){ echo "Ab"; }else{ echo $head_attendance; } }else{ echo $t1_grade; } ?> </th>
	                                        <th style="width:25%;float:right;border-left:1px solid;text-align:center;"><?php if($head_t2_attendance == "A" || $head_t2_attendance == "ML"){ if($head_t2_attendance == "A"){ echo "Ab"; }else{ echo $head_attendance; } }else{ echo $t2_grade; } ?> </th>
	                                    </tr>
	                            <?php
	                                    }
                                    }
                                }
                                ?>
                    
                                </table>
                            </td>
                            <td style="width:50% !important;"> 
                                <table style="height:auto;border:1px solid;border-collapse:collapse;">
                                    <tr>
                                        <th>SUBJECT</th>
                                        <th>TERM I</th>
                                        <th>TERM II</th>
                                    </tr>
                                <?php
                                if($get_course_exam_subjects){
                                    foreach($get_course_exam_subjects as $subjects){
                                        if($subjects['exam_type'] == "Grade" && $subjects['subject_group'] == "CO SCHOLASTIC AREAS"  && $subjects['subject_group_code'] =="B"){
                                            $subject_id=$subjects['id'];
                                            $t1_grade="";
                                            $head_t1_attendance="";
                                            // $get_term_1_course_exam_heads
                                            // $get_term_2_course_exam_heads
                                            if($get_term_1_course_exam_heads){
                                                foreach($get_term_1_course_exam_heads as $exam_heads){
                                                    $ehid=$exam_heads['id'];
                                                    if($get_exam_log){
                                                        foreach($get_exam_log as $elog){
                                        
                                                            if($elog['exam_head'] == $ehid && $elog['subject_id'] == $subject_id){
                                            
                                                                $e_log_attendance=$elog['attendance'];
                                                                if($e_log_attendance == "A" || $e_log_attendance == "ML"){
                                                                    $head_t1_attendance=$e_log_attendance;
                                                                }else{
                                                                    $t1_grade=$elog['grade'];
                                            
                                                                }    
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            
                                            $t2_grade="";
                                            $head_t2_attendance="";
                                            if($get_term_2_course_exam_heads){
                                                foreach($get_term_2_course_exam_heads as $exam_heads){
                                                    $ehid=$exam_heads['id'];
                                                    if($get_exam_log){
                                                        foreach($get_exam_log as $elog){
                                        
                                                            if($elog['exam_head'] == $ehid && $elog['subject_id'] == $subject_id){
                                            
                                                                $e_log_attendance=$elog['attendance'];
                                                                if($e_log_attendance == "A" || $e_log_attendance == "ML"){
                                                                    $head_t2_attendance=$e_log_attendance;
                                                                }else{
                                                                    $t2_grade=$elog['grade'];
                                            
                                                                }    
                                                            }
                                                        }
                                                    }
                                                }
                                            }
	                                        ?>
	                                    <tr style="height:20px;width:100%;border-bottom:1px solid; border-left:1px solid;border-right:1px solid;">
	                                        <th style="text-align:left;width:50%;float:left;">&nbsp;<?php echo $subjects['subject']; ?></th>
	                                        <th style="width:25%;float:right;border-left:1px solid;text-align:center;"><?php if($head_t1_attendance == "A" || $head_t1_attendance == "ML"){ if($head_t1_attendance == "A"){ echo "Ab"; }else{ echo $head_attendance; } }else{ echo $t1_grade; } ?> </th>
	                                        <th style="width:25%;float:right;border-left:1px solid;text-align:center;"><?php if($head_t2_attendance == "A" || $head_t2_attendance == "ML"){ if($head_t2_attendance == "A"){ echo "Ab"; }else{ echo $head_attendance; } }else{ echo $t2_grade; } ?> </th>
	                                    </tr>
	                            <?php
	                                    }
                                    }
                                }
                                ?>
                    
                                </table>
                            </td>
                        </tr>
                    </table>
                </div>
                
                <table class="">
                    <tbody>
                        <tr>
                            <th colspan="3" style="text-align:left;">REMARK : <?php echo $remark; ?></td>
                        </tr>
                        <!--<tr style="background:#DBF7F3;border:1px solid #4F3F83;padding:0px;margin:0px;">-->
                        <!--    <th style="margin:0px;text-align:left;padding-left:5px;font-size:18px;width:50% !important;" > Result : -->
                                
                        <!--    </th>-->
                        <!--    <th style="margin:0px;text-align:left;padding-left:5px;font-size:18px;width:50% !important;"></th>-->
                        <!--</tr>-->
                            <tr>
                                <th class="text-center" style="vertical-align:top;width:34%;">
                                    <p style="padding:5px;margin:0px;text-align:left;">Result : <b><?php if($sub_failure_count == 0 ){ echo "Promoted to Class ".$promoted_class; } ?></b></p>
                                    <p style="padding:5px;margin:0px;text-align:left;">School Will Reopen On : <b>01 APRIL, 2024</b></p>
                                </th>
                                <th colspan="" rowspan="" class="text-center" style="vertical-align:bottom;width:33%;"> 
                                    
                                 
                                    
                            CLASS TEACHER
                                </th>
                                <th colspan="" rowspan="" class="text-center" style="vertical-align:bottom;min-height:55px;width:33%;"> 
                                
                                <?php 
                                if(PrincipalSign !=""){
                                ?>
                                    <p style="padding:0px !important;margin:0px !important;">
                                        <img src="<?php echo base_url().PrincipalSign; ?>" style="height:85px;width:auto;">
                                    </p>
                                <?php
                                } 
                                ?> 
                                    PRINCIPAL
                                </th>
                            </tr>
                        </tbody>
                </table>
                </div>
            </div>
                
        </div>
        
        
        <?php
                            }
                        // }
                //     }
                // }
            }
        }
        ?>
    </body>
</html>