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


<!DOCTYPE html>
<html>
    <head>
        <!--<title>Transfer Certificate</title>-->
        <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>Annual Report Card</title>
        <style>
            html{padding:0px;margin:0px;}
            body{
                padding:20px;margin:0px;vertical-align:middle;
                font-family: 'Inconsolata', monospace;
                /*background-image: url("<?php echo logo_png; ?>");*/
                /*opacity: 0.1;*/
                /*background-repeat: repeat;*/
                /*background-size: 10% auto;*/
                /*background-position: center;*/
            }
            
            .report-card{
                /*border:2px solid #a1def4;*/
                border : 2px solid #4F3F83;
                /*height:94.5%;*/
                height:95%;
                border-radius:5px;
                /*outline-offset: -10px;*/
                margin:0px;
                padding:5px;
            }
            .report-2{
                border:1px solid #4F3F83;
                height:96%;
                /*height:auto;*/
                border-radius:5px;
                /*padding:0px;margin:0px;*/
            }
            table{border-collapse:collapse;width:100%;}
            table tr{
                border :1px solid !important;
                border-collapse:collapse;
            }
            tr th{
                margin:0px;
                padding:3px;
                font-size:14px;
                font-weight:700;
                border :1px solid !important;
                border-collapse:collapse;
            }
            /*.report-card-body{*/
            .report-2{
                /*background-image: url("<?php echo logo_png; ?>");*/
                /*opacity: 0.1;*/
                /*background-repeat: no-repeat;*/
                /*background-size: 40% auto;*/
                /*background-size:auto 40%;*/
                /*background-position: center;*/
            }
        
        
        </style>
    </head>
    <body>
        <?php
        $count=0;
        if($all_students){
            foreach($all_students as $data){
                $count=$count + 1;
                if($count == 1){
                
                $sid=$data['sid'];
                $student_name=$data['student_name'];
                $father_name=$data['father_name'];
                $sch_no=$data['sch_no'];
                $roll_no=$data['roll_no'];
                $course_id=$data['course_id'];
                $course=$data['class'];
                $section=$data['section'];
                $dob1=$data['dob'];
                $dob='';
                if($dob1 !=""){
                    $dob=date('d-m-Y',strtotime($dob1));
                }
                

                $exam_head_table='exam_heads_3';
                $get_course_exam_heads=$this->ReportCardModel->get_course_active_exam_heads($course_id,$exam_head_table);


                $exam_head_count=0;
                if($get_course_exam_heads){
                    foreach($get_course_exam_heads as $heads){
                        $exam_head_count=$exam_head_count + 1;        
                    }
                }


                $attendance_days=0;
                $attendance=0;
                $remark='';
                $result_table='exam_result';
                
                // $roll_no='';
                $rank_in_class="";
                $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'];
                    }
                }


                $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";
                $get_student_subjects=$this->NewExamModel->get_student_subjects($sid,$course_id,$acedemic_session);
                            
?>
        <div class="report-card p-1">
            <div class="report-2">
                <!--<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 logo_png; ?>' style="width:auto;height:60px;" />-->
                <!--            </th>-->
                <!--            <th style="width:85%;border:none !important;">-->
                <!--                <p style="padding:0px; margin:0px;font-size:36px;text-align:center;font-weight:900;color:#29166f;"><?php echo school_full_name; ?></p>-->
                <!--                <p style='padding:0px; margin:0px;text-align:center;color:#29166f;font-size:22px;'><b><?php echo school_address; ?></b></p>-->
                                
                <!--                <p style='padding:0px; margin:0px;text-align:center;color:#29166f;font-size:22px;'><b> PROGRESS REPORT - SESSION 2022-2023</b></p>-->
                <!--            </th>-->
                <!--        </tr>-->
                <!--    </table>-->
                <!--</div>-->
                
                <div style="height:90px;"></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 $roll_no; ?></b></p>

                    </div>

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

                    </div>
                </div>
                <div style="width:100%;height:25px;">
                    <div style='width:80%;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>CLASS: </b><?php echo $course; echo " "; echo $section; ?></p>

                    </div>

                    
                </div>

                        </th>
                    </tr>
                </table>

                <div class="report-card-body">
                    <table class="table table-bordered" >
                        <thead>
                            <tr style="margin:0px;padding:0px;background:#DBF7F3;">
                                <th style="text-align:center;margin:0px;font-size:15px;padding:0px;" colspan="14"><b>ACADEMIC PERFORMANCE</b></th>
                            </tr>
                            <tr>
                                <th rowspan="2" colspan="2" style="width:auto;margin:0px;font-size:12px;padding:0px;">&nbsp;SUBJECTS</th>
                                <th rowspan="2" style="text-align:center;margin:0px;width:30px;font-size:12px;padding:0px;">MM</th>
                                <?php 
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='FirstTerm'){
                                ?>
                                <th style="text-align:center;padding:0px;margin:0px;font-size:12px;width:75px;text-transform:uppercase;"><?php echo $exam_heads['exam_head'];?>
                                </th>
                                <?php
                                        }
                                    }
                                }
                                ?>
                                <th style="text-align:center;padding:0px;margin:0px;font-size:12px;width:55px;text-transform:uppercase;">Total</th>
                                <?php
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='SecondTerm'){
                                ?>
                                <th style="text-align:center;padding:0px;margin:0px;font-size:12px;width:75px;text-transform:uppercase;"><?php echo $exam_heads['exam_head'];?>
                                </th>
                                <?php
                                        }
                                    }
                                }
                                ?>
                                <th style="text-align:center;padding:0px;margin:0px;font-size:12px;width:55px;text-transform:uppercase;">Total</th>
                                <?php
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='AnnualExam'){
                                ?>
                                <th style="text-align:center;padding:0px;margin:0px;font-size:12px;width:75px !important;text-transform:uppercase;"><?php echo $exam_heads['exam_head'];?>
                                </th>
                                <?php
                                        }
                                    }
                                }
                                ?>
                                <th style="margin:0px;text-align:center;width:55px;text-transform:uppercase;font-size:12px;">Total</th>
                                <th style="margin:0px;text-align:center;width:55px;text-transform:uppercase;font-size:12px;">HIC</th>
                                
                                <!--<th>Term II<br> Total</th>-->
                                <th style="margin:0px;text-align:center;width:55px;text-transform:uppercase;font-size:12px;">Years Avg</th>
                            </tr>
                            
                            <tr>
                                <?php 
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='FirstTerm' ){
                                ?>
                                <th style="text-align:center;margin:0px;padding:0px;font-size:12px;">
                                    <?php echo $exam_heads['mm']; ?>
                                </th>
                                <?php
                                        }
                                    }
                                }
                                ?>
                                <th>100</th>
                                <?php
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='SecondTerm' ){
                                ?>
                                <th style="text-align:center;margin:0px;padding:0px;font-size:12px;">
                                    <?php echo $exam_heads['mm']; ?>
                                </th>
                                <?php
                                        }
                                    }
                                }
                                ?>
                                <th>100</th>
                                <?php
                                
                                
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='AnnualExam' ){
                                ?>
                                <th style="text-align:center;margin:0px;padding:0px;font-size:12px;">
                                    <?php echo $exam_heads['mm']; ?>
                                </th>
                                <?php
                                        }
                                    }
                                }
                                ?>
                                
                                <th style="text-align:center;margin:0px;padding:0px;">100</th>
                                
                                <th style="text-align:center;margin:0px;padding:0px;">100</th>
                                <th style="text-align:center;margin:0px;padding:0px;">100</th>
                                <!--<th style="text-align:center;margin:2px;">100</th>-->
                                
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $mm_total=0;
                            $grand_total=0;
                            $annual_grand_total=0;
                            $FirstTerm_total=0;
                            $SecondTermTotal=0;
                            $sub_count=0;
                            if($get_course_exam_subjects){
                                foreach($get_course_exam_subjects as $exam_subjects){
                                    $exam_type=$exam_subjects['exam_type'];
                                    if($exam_type == "Marks"){
                                        $sub_count=$sub_count + 1;
                                        $sub_annual_total=0;
                                        // $hic=$exam_subjects['annual_hic'];
                                        
                                    
                                        
                                        $sub_total=0;
                                        $subject_id=$exam_subjects['id'];
                                        $sub_type=$exam_subjects['subject_type'];
                                        
                                        $FirstTerm_Sub_Total=0;
                                        $SecondTerm_SubTotal=0;
                                        
                                        
                                        
                                        $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){
                                            $mm_total=$mm_total + $exam_subjects['MM'];
                                            $hic=0;
                                            $hic_subject_id=$exam_subjects['hic_subject_id'];
                                            $get_hic_data=$this->NewExamModel->get_hic_data_annual($hic_subject_id,$class,$section,$acedemic_session);
                                            if($get_hic_data){
                                                foreach($get_hic_data as $hic_data){
                                                    $hic= $hic_data['annual_total_marks'];
                                                }
                                            }
                                            
                                        
                                        
                                    
                            ?>
                            <tr style="padding:0px;margin:0px;">
                                <th colspan="2" style="margin:0px;text-align:left;padding:0px;">&nbsp;<?php echo $exam_subjects['subject']; ?></th>
                                <th style="text-align:center;margin:0px;padding:0px;font-size:12px;"><?php if($exam_type == "Marks"){ echo $exam_subjects['MM']; } ?></th>
                                <?php
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='FirstTerm'){
                                            $ehid=$exam_heads['id'];
                                            $elog_table='exam_log_3';
                                            $get_exam_log=$this->ReportCardModel->get_log_item_data($sid,$ehid,$subject_id,$elog_table);
                                            if($get_exam_log){
                                                foreach($get_exam_log as $elog){
                                                    
                                                        $obtained_marks=$elog['obtained_marks'];
                                                        $FirstTerm_Sub_Total=$FirstTerm_Sub_Total + $obtained_marks;
                                                        $FirstTerm_total=$FirstTerm_total + $obtained_marks;
                                ?>
                                <th style="text-align:center;margin:0px;padding:0px;font-size:12px;"><?php echo $obtained_marks; ?></th>
                                <?php
                                               
                                                }
                                            }else{
                                        ?>
                                <th style="text-align:center;margin:0px;font-size:12px;padding:0px;">--</th>        
                                <?php
                                            }
                                        
                                        }
                                    }
                                }
                                ?>
                                <th>
                                <?php
                                if($FirstTerm_Sub_Total < 33){
                                    echo "<u>".$FirstTerm_Sub_Total."</u>";
                                }else{
                                    echo $FirstTerm_Sub_Total;
                                }
                                ?>
                                </th>
                                <?php
                                

                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='SecondTerm'){
                                            $ehid=$exam_heads['id'];
                                            $elog_table='exam_log_3';
                                            $get_exam_log=$this->ReportCardModel->get_log_item_data($sid,$ehid,$subject_id,$elog_table);
                                            if($get_exam_log){
                                                foreach($get_exam_log as $elog){
                                                    if($exam_type == "Marks"){
                                                        $obtained_marks=$elog['obtained_marks'];
                                                        $SecondTerm_SubTotal=$SecondTerm_SubTotal + $obtained_marks;
                                                        $SecondTermTotal=$SecondTermTotal + $obtained_marks;
                                ?>
                                                <th style="text-align:center;margin:0px;font-size:12px;padding:0px;"><?php echo $obtained_marks; ?></th>
                                                <?php
                                                }else if($exam_type == "Grade"){
                                                ?>
                                                <th style="text-align:center;margin:0px;font-size:12px;padding:0px;"><?php echo $elog['grade']; ?></th>
                                                <?php
                                                }
                                            }
                                        }else{
                                        ?>
                                        <th style="text-align:center;margin:0px;font-size:12px;padding:0px;">--</th>        
                                        <?php
                                        }
                                        
                                        }
                                    }
                                }
                                ?>
                                <th>
                                <?php
                                if($SecondTerm_SubTotal < 33){
                                    echo "<u>".$SecondTerm_SubTotal."</u>";
                                }else{
                                    echo $SecondTerm_SubTotal;
                                }
                                ?>
                                </th>
                                
                                
                                <?php
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='AnnualExam'){
                                            $ehid=$exam_heads['id'];
                                            $elog_table='exam_log_3';
                                            $get_exam_log=$this->ReportCardModel->get_log_item_data($sid,$ehid,$subject_id,$elog_table);
                                            if($get_exam_log){
                                                foreach($get_exam_log as $elog){
                                                    if($exam_type == "Marks"){
                                                        $obtained_marks=$elog['obtained_marks'];
                                                        $sub_total=$sub_total + $obtained_marks;
                                                        $sub_annual_total=$sub_annual_total + $obtained_marks;
                                                        $annual_grand_total=$annual_grand_total + $obtained_marks;
                                ?>
                                                <th style="text-align:center;margin:0px;font-size:12px;padding:0px;"><?php echo $elog['obtained_marks']; ?></th>
                                                <?php
                                                }else if($exam_type == "Grade"){
                                                ?>
                                                <th style="text-align:center;margin:0px;font-size:12px;padding:0px;"><?php echo $elog['grade']; ?></th>
                                                <?php
                                                }
                                            }
                                        }else{
                                        ?>
                                        <th style="text-align:center;margin:0px;font-size:12px;padding:0px;">--</th>        
                                        <?php
                                        }
                                        
                                        }
                                    }
                                }
                                ?>
                                <th style="margin:0px;text-align:center;">
                                    <?php 
                                    if($sub_annual_total < 33){
                                        echo "<u>".$sub_annual_total."</u>";
                                    }else{
                                        echo $sub_annual_total;
                                    }
                                    
                                    ?>
                                </th>
                                <th><?php echo $hic; ?></th>
                                
                                
                                <?php 
                                $sub_avgg_11=($sub_annual_total + $SecondTerm_SubTotal + $FirstTerm_Sub_Total)/3;
                                $sub_avgg_12=number_format((float)$sub_avgg_11, 2, '.', '');
                                ?>
                                <th><?php if($sub_avgg_11 < 33){  echo "<u>".$sub_avgg_12."</u>"; }else{ echo $sub_avgg_12; }  ?></th>
                                
                                
                            </tr>
                            
                            <?php
                                        if($sub_type == "Main Subject"){
                                            $grand_total= $grand_total + $sub_total;    
                                        }
                                    }
                            
                                }
                            }
                            ?>

                            <?php
                                foreach($get_course_exam_subjects as $exam_subjects){
                                    $exam_type=$exam_subjects['exam_type'];
                                    if($exam_type == "Grade"){
                                        $subject_id=$exam_subjects['id'];
                                        $sub_type=$exam_subjects['subject_type'];
                            ?>
                            <tr style="padding:0px;margin:0px;">
                                <th colspan="2" style="margin:0px;text-align:left;padding:0px;font-size:12px;">&nbsp;<?php echo $exam_subjects['subject']; ?></th>
                                <th></th>
                                <?php 
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='FirstTerm'){
                                ?>
                                <th style='text-align:center;margin:0px;'>
                                <?php 
                                            $ehid=$exam_heads['id'];
                                            $elog_table='exam_log_3';
                                            $get_exam_log=$this->ReportCardModel->get_log_item_data($sid,$ehid,$subject_id,$elog_table);
                                            if($get_exam_log){
                                                foreach($get_exam_log as $elog){
                                                    echo $elog['grade']; 
                                                }
                                            }else{
                                                echo '--';
                                            }
                                        ?>
                                        </th>
                                <?php
                                        }
                                       
                                    }
                                }
                                ?>
                                <th style="text-align:center;margin:0px;"></th>
                                <?php 
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='SecondTerm'){
                                ?>
                                <th style='text-align:center;margin:0px;'>
                                <?php 
                                            $ehid=$exam_heads['id'];
                                            $elog_table='exam_log_3';
                                            $get_exam_log=$this->ReportCardModel->get_log_item_data($sid,$ehid,$subject_id,$elog_table);
                                            if($get_exam_log){
                                                foreach($get_exam_log as $elog){
                                                    echo $elog['grade']; 
                                                }
                                            }else{
                                                echo '--';
                                            }
                                        ?>
                                        </th>
                                <?php
                                        }
                                       
                                    }
                                }
                                ?>
                                <th style="text-align:center;margin:0px;"></th>
                                <?php 
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='AnnualExam'){
                                ?>
                                <th style='text-align:center;margin:0px;'>
                                <?php
                                            $ehid=$exam_heads['id'];
                                            $elog_table='exam_log_3';
                                            $get_exam_log=$this->ReportCardModel->get_log_item_data($sid,$ehid,$subject_id,$elog_table);
                                            if($get_exam_log){
                                                foreach($get_exam_log as $elog){
                                                    echo $elog['grade']; 
                                                }
                                            }else{
                                                echo '--';
                                            }
                                ?>            
                                         </th>
                                <?php         
                                        }
                                       
                                    }
                                }
                                ?>
                                <th>--</th>
                                
                                <th>--</th>
                                <th>--</th>
                                
                                <!--<th>--</th>-->
                            </tr>
                        <?php 
                                    }
                                }
                        }
                        ?>   
                            <tr style="background:#DBF7F3;border-top:1px solid #4F3F83 !important;padding:0px;margin:0px;">
                                <th colspan="2" style="margin:0px;padding:0px;">GRAND TOTAL</th>
                                <th style="text-align:center;margin:0px;"><?php echo $mm_total; ?></th>
                                <th></th>
                                <th></th>
                                <th><?php echo $FirstTerm_total; ?></th>
                                <th></th>
                                <th></th>
                                <th><?php echo $SecondTermTotal; ?></th>
                                <th></th>
                                <th></th>
                                <th style="text-align:center;margin:0px;"><?php echo $annual_grand_total; ?></th>
                                <th></th>
                                <?php
                                $grand_total_1=$annual_grand_total + $FirstTerm_total + $SecondTermTotal;
                                $avg_grand_total=$grand_total_1/3;
                                ?>    
                                <th><?php if($avg_grand_total < 33){ echo "<u>".$avg_grand_total."</u>"; }else{ echo ($annual_grand_total + $FirstTerm_total)/2 ; } ?></th>
                            </tr>
                            
                            <?php 
                            
                            $percentage="";
                            if($mm_total != 0){
                                $percentage=($annual_grand_total * 100)/$mm_total;    
                            }else{
                                $percentage=0;
                            }
                            
                            ?>
                            <tr style="background:#DBF7F3;border:1px solid #4F3F83;padding:0px;margin:0px;">
                                <th style="margin:0px;text-align:left;padding-left:5px;" colspan="3"> Rank in class : <?php echo $rank_in_class;?></th>
                                <th style="margin:0px;text-align:left;padding-left:5px;" colspan="11"> PERCENTAGE : <b>&nbsp; <?php echo number_format((float)$percentage, 2, '.', ''); ?> % </b></th>
                            </tr>
                            
                        </tbody>
                    </table>  
                    
                    
                    
                    

			
			          
                    
                    <table class="table table-bordered">
                        <tbody>
                            <tr>
                                <th colspan="3" style="text-align:left;height:50px;">REMARK : <?php echo $remark; ?></td>
                            </tr>
                            <tr>
                                <th colspan="" rowspan="" class="text-center">
                                    <br>
                                    <br>
                                    <br>
                            PARENT'S SIGN
                                </th>
                                <th colspan="" rowspan="" class="text-center">
                                    <br>
                                    <br>
                                    <br>
                            CLASS TEACHER
                                </th>
                                <th colspan="" rowspan="" class="text-center"> 
                                       <img src="<?php echo base_url(); ?>assets/sjec-principal-sign.png" style="width:80px;"><br>
                            PRINCIPAL
                                </th>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
                
        </div>
        <?php 
                }
            }
        }
        ?>
    </body>
</html>    