<!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>Mid Term Report Card</title>
        <style>
            html{padding:0px;margin:0px;}
            body{
                padding:25px;margin:0px;vertical-align:middle;
                font-family: 'Inconsolata', monospace;
            }
            .report-card{
                /*border:2px solid #a1def4;*/
                border : 2px solid #4F3F83;
                /*height:94.5%;*/
                height:96%;
                border-radius:5px;
                /*outline-offset: -10px;*/
                margin:0px;
                padding:5px;
            }
            .report-2{
                border:1px solid #4F3F83;
                height:96%;
                /*height:auto;*/
                border-radius:5px;
            }
            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
        $acedemic_session=$this->session->userdata('acedemic_session');
        $course_id=$this->uri->segment('3');
        $section=$this->uri->segment('4');
        $course=$this->uri->segment('5');
        $acedemic_session=$this->session->userdata('acedemic_session');
        $subject_table="exam_subjects_".$acedemic_session;
        $exam_heads_table="exam_heads_".$acedemic_session;
        $exam_id=3;
        $get_course_exam_subjects=$this->NewExamModel->get_course_active_subjects($course_id,$subject_table);

$get_course_exam_heads=$this->NewExamModel->get_course_active_exam_heads($course_id,$exam_heads_table);
$count=0;
// $course_students=$this->NewExamModel->course_students_list($course_id,$acedemic_session,$section);

$course_students=$this->NewExamModel->get_students_ac_session_by_course_and_class($acedemic_session,$course,$section);
if($course_students){
    foreach($course_students as $students){
        $count = $count + 1;
        // if($count<=50){
            
        $sid=$students['sid'];
        $course=$students['class'];
        $section=$students['section'];
        
        $elog_table="exam_log_".$acedemic_session;
        $get_exam_log=$this->NewExamModel->students_exam_log($sid,$acedemic_session,$elog_table);
        $student_subjects_table="student_subjects";
        $get_student_subjects=$this->NewExamModel->get_student_subjects($sid,$course_id,$acedemic_session);
        
        $exam_result_table="exam_result";
        $exam_result_data=$this->NewExamModel->student_result($sid,$acedemic_session,$exam_id,$course_id,$exam_result_table);
        $student_table="student";
        $get_student_info=$this->NewExamModel->get_item_data($sid,$student_table);
        $student_name='';
        $father_name='';
        $sch_no='';
        $roll_no='';
        // $section='';
        $dob='';
        if($get_student_info){
            foreach($get_student_info as $student_info){
                $student_name=$student_info['student_name'];
                $father_name=$student_info['father_name'];
                $dob=date('d-m-Y',strtotime($student_info['dob']));
                $sch_no=$student_info['sch_no'];
            }
        }
        
        
        $attendance_days=0;
        $attendance=0;
        $remark='';
        $roll_no='';
        $rank_in_class="";
        if($exam_result_data){
            foreach($exam_result_data as $result_data){
                $attendance_days=$result_data['attendance_days'];
                $remark=$result_data['remark'];
                $attendance=$result_data['attendance'];
                $roll_no=$result_data['roll_no'];
                $rank_in_class=$result_data['rank_in_class'];
            }
        }
        
?>




        <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>FIRST TERM PROGRESS REPORT - SESSION 2022-2023</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 $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 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-size:18px;" colspan="7"><b>ACADEMIC PERFORMANCE</b></th>
                            </tr>
                            <tr>
                                <th rowspan="2" colspan="2" style="width:180px;margin:0px;">&nbsp;SUBJECTS</th>
                                <th rowspan="2" style="text-align:center;margin: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;"><?php echo $exam_heads['exam_head'];?>
                                </th>
                                <?php
                                        }
                                    }
                                }
                                ?>
                                <th style="margin:0px;text-align:center;">Total</th>
                                <th style="margin:0px;text-align:center;">HIC</th>
                            </tr>
                            
                            <tr>
                                
                                <?php 
                                $eh_mm=0;
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        if($exam_heads['exam_mode'] =='FirstTerm'){
                                            $eh_mm=$eh_mm + $exam_heads['mm'];
                                ?>
                                <th style="text-align:center;margin:2px;">
                                    <?php echo $exam_heads['mm']; ?>
                                </th>
                                <?php
                                        }
                                    }
                                }
                                ?>
                                <th style="text-align:center;margin:2px;"><?php echo $eh_mm; ?></th>
                                <th style="text-align:center;margin:2px;"><?php echo $eh_mm; ?></th>
                                
                            </tr>
                        </thead>
                        <tbody>
                            
                            <?php
                            $mm_total=0;
                            $grand_total=0;
                            $hy_grand_total=0;
                            $annual_grand_total=0;
                            $sub_count=0;
                            if($get_course_exam_subjects){
                                foreach($get_course_exam_subjects as $exam_subjects){
                            $hic_subject_id=$exam_subjects['hic_subject_id'];
                            
                                    $subject_id=$exam_subjects['id'];
                                    $exam_type=$exam_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($exam_type == "Marks"){
                                    if($student_subject >= 1){
                                        
                                        $sub_count=$sub_count + 1;
                                        $hy_total=0;
                                        $hic=0;
                                        $get_hic_data=$this->NewExamModel->get_hic_data($hic_subject_id,$class,$section,$acedemic_session);
                                        if($get_hic_data){
                                            foreach($get_hic_data as $hic_data){
                                                $hic=$hic_data['hy_hic'];        
                                            }
                                        }
                                        
                                    
                                    $mm_total=$mm_total + $exam_subjects['MM'];
                                    $sub_total=0;
                                    
                                    $subject_mm=$exam_subjects['MM'];
                                    
                                    $sub_type=$exam_subjects['subject_type'];
                                    
                            ?>
                            <tr style="padding:0px;margin:0px;">
                                <th colspan="2" style="margin:0px;text-align:left;">&nbsp;<?php echo $exam_subjects['subject']; ?></th>
                                <th style="text-align:center;margin:0px;"><?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'){
                            ?>         
                            <th style="text-align:center;margin:0px;">
                               <?php
                               $ehid=$exam_heads['id'];
                                    if($get_exam_log){
                                    foreach($get_exam_log as $elog){
                                    if($exam_type == "Marks"  && $elog['exam_head'] == $ehid && $elog['subject_id'] == $subject_id){
                                        $obtained_marks=$elog['obtained_marks'];
                                                    $sub_total=$sub_total + $obtained_marks;
                                        $hy_total=$hy_total + $obtained_marks;
                                        $hy_grand_total=$hy_grand_total + $obtained_marks;
                                        
                                        $bg_color="red";
                                        if($obtained_marks > $subject_mm){
                                            echo "<span style='background:red;'>".$elog['obtained_marks']."</span>";
                                        }else{
                                            echo $elog['obtained_marks'];
                                        }
                                    }else if($exam_type == "Grade" && $elog['exam_head'] == $ehid && $elog['subject_id'] == $subject_id){
                                             echo $elog['grade'];
                                            
                                                }
                                            }
                                            
                                            
                                            
                                            
                                            
                                        }else{
                                        
                                        echo "--";
                                        
                                        }
                                        ?>    
                                        </th>
                                <?php        
                                        }
                                    }
                                }
                                ?>
                                <th style="margin:0px;text-align:center;"><?php echo $hy_total; ?></th>
                                <th><?php echo $hic; ?></th>
                                
                                
                            </tr>
                            
                            <?php
                            if($sub_type == "Main Subject"){
                                $grand_total= $grand_total + $sub_total;    
                            }
                                    }
                            
                                }
                            }
                            ?>

                           
                            <tr style="background:#DBF7F3;border-top:1px solid #4F3F83 !important;padding:0px;margin:0px;">
                                <th colspan="2" style="margin:0px;">GRAND TOTAL</th>

                                
                                <th style="text-align:center;margin:0px;"><?php echo $mm_total; ?></th>
                                
                                <th></th>
                                <th></th>
                                
                                <th style="text-align:center;margin:0px;"><?php echo $hy_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;
                            }
                            
                            ?>
                            <tr style="background:#DBF7F3;border:1px solid #4F3F83;padding:0px;margin:0px;">
                                
                                <th style="margin:0px;text-align:left;padding-left:5px;" colspan="2"> Rank in class : <?php echo $rank_in_class;?></th>
                                <th style="margin:0px;text-align:left;padding-left:5px;" colspan="5"> PERCENTAGE : <b>&nbsp; <?php echo number_format((float)$percentage, 2, '.', ''); ?> % </b></th>
                            </tr>
                            
                        </tbody>
                    </table>  
                </div>
                
                <div style="height:300px;width:100%;padding:25px;">
	                    <table style="height:250px; width: 100%;">
	                        <thead style="border-bottom:2px solid #000;width:100%;">
		                    <tr style="">
		                        <td style="height:200px;vertical-align:bottom;">
				                    <div style="width:45px;border-right:2px solid;height:200px;">
					                    <div style="height: 18px;margin:0px;width: 100%;border-top:2px solid;">100%</div>
					                    <div style="height: 18px;margin:0px;width: 100%;border-top:2px solid;">90%</div>
					                    <div style="height: 18px;margin:0px;width: 100%;border-top:2px solid;">80%</div>
					                    <div style="height: 18px;margin:0px;width: 100%;border-top:2px solid;">70%</div>
					                    <div style="height: 18px;margin:0px;width: 100%;border-top:2px solid;">60%</div>
					                    <div style="height: 18px;margin:0px;width: 100%;border-top:2px solid;">50%</div>
					                    <div style="height: 18px;margin:0px;width: 100%;border-top:2px solid;">40%</div>
					                    <div style="height: 18px;margin:0px;width: 100%;border-top:2px solid;">30%</div>
					                    <div style="height: 18px;margin:0px;width: 100%;border-top:2px solid;">20%</div>
					                    <div style="height: 18px;margin:0px;width: 100%;border-top:2px solid;">10%</div>
				                    </div>
			                    </td>
                        <?php

                        if($get_course_exam_subjects){
                            foreach($get_course_exam_subjects as $exam_subjects){
                                $exam_type=$exam_subjects['exam_type'];
                                if($exam_type == "Marks"){                      
                                    $sub_mm=$exam_subjects['MM'];
                                    $sub_total=0;
                                    $subject_id=$exam_subjects['id'];
                                    $sub_type=$exam_subjects['subject_type'];
                                    $subject =$exam_subjects['subject'];  
                                    
                                $hic_subject_id=$exam_subjects['hic_subject_id'];
                                $hic1=0;
                                        $get_hic_data=$this->NewExamModel->get_hic_data($hic_subject_id,$class,$section,$acedemic_session);
                                        if($get_hic_data){
                                            foreach($get_hic_data as $hic_data){
                                                $hic1=$hic_data['hy_hic'];        
                                            }
                                        }
                                    // $hic1=$exam_subjects['hy_hic'];      
            
                                    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_'.$acedemic_session;
                                    // $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($elog['exam_head'] == $ehid && $elog['subject_id'] == $subject_id){
                                                
                                            
                                            $obtained_marks=$elog['obtained_marks'];
                                            $sub_total=$sub_total + $obtained_marks;
                                            }
                                                    }
                                                }
                                            }
                                        }
                                    }
                        $chart_h=200;
                        $perr=0;
                        if($sub_mm == 0){
                            $perr=0;
                        }else{
                            $perr=($sub_total*100)/$sub_mm;    
                        }
                        
                        $height=$sub_total * 2;
                        // $height=50;
                        $hic=$hic1 * 2;
                        $margin_top=0;
                        
                        
                        $margin_top=$hic - $height;
                        // $hic=$perr;
                        // $subject=$subject."(".$sub_total.")";
                        // $width=0;
                        // if($sub_count > 0){
                        //     $width=70/$sub_count;    
                        // }else{
                        //     $width=0;
                        // }
                        
                        ?>
                        
                        <td style="padding: 5px; padding-bottom: 0px !important;vertical-align: bottom;width: 50px;">
                            <div style="bottom: 0px !important;width:40px;border:1px solid #000;height:<?php echo $hic; ?>px;background:#000;vertical-align: bottom !important;display: block;">
                                <div style="display: block;width:28px;background:#EAEDED;height:<?php echo $height; ?>px;margin-top:<?php echo $margin_top; ?>px;padding-right: 2px;font-weight: 700;letter-spacing: 0.3px;text-transform: uppercase;text-align:center;">
                                    <?php if($sub_total >0){ echo $sub_total; } ?>
                                </div>
                            </div>
                        </td>
                        <?php
                                }
                            }
                        }
                        ?>
                        <td></td>
                            </tr>
                        </thead>    
                        <tr>    
                        <td></td>
                        <?php
                        if($get_course_exam_subjects){
                            foreach($get_course_exam_subjects as $exam_subjects){
                                $exam_type=$exam_subjects['exam_type'];
                                if($exam_type == "Marks"){                      
                                    $sub_mm=$exam_subjects['MM'];
                                    $sub_total=0;
                                    $subject_id=$exam_subjects['id'];
                                    $sub_type=$exam_subjects['subject_type'];
                                    $subject =$exam_subjects['subject'];  
                        ?>            
                            <td style="vertical-align: top;width: 50px;text-align:left;font-size:11px;height:80px;">
                                   <div style="transform: rotate(-75deg); transform-origin: 90% ;text-align:center;"><?php echo $subject; ?></div> 
                                </td>
                            
                        <?php
                                }
                            }
                        }
                        ?>
                        <td></td>
                        </tr>
                        </table>
                    </div>
                    
                    <table class="table table-bordered">
                        <tbody>
                            
                            <!--<tr>-->
                            <!--    <th colspan="2">PERSONALITY TRAITS/NON - SCHOLASTICS</th>-->
                            <!--</tr>-->
                             
                            
                            <tr>
                                <th colspan="3" style="text-align:left;height:70px;">REMARK : <?php echo $remark; ?></td>
                            </tr>
                            <tr>
                                <th class="text-center">
                                    <br>
                                    <br>
                                    <br>
                                    Parent
                                </th>
                                <th colspan="" rowspan="" class="text-center">
                                    <br>
                                    <br>
                                    <br>
                            CLASS TEACHER
                                </th>
                                <th colspan="" rowspan="" class="text-center"> 
                                    <br>
                                    <br>
                                    <br>
                            PRINCIPAL
                                </th>
                            </tr>
                        </tbody>
                    </table>
                
                
            </div>
        </div>    
 
<?php
            
        // }
    }
}
?>
   </body>
</html>    
