<?php
$acedemic_session=2;
$sid=$this->uri->segment('3');
$annual_working_days =140;

$annual_attendance =120;


$table='student';
$student_name='';
$father_name='';
$sch_no='';
$roll_no='';
$course_id='';
$course='';
$section='';
$dob='';

$get_student_detail=$this->ReportCardModel->get_item_data($sid,$table);
if($get_student_detail){
    foreach($get_student_detail as $student_detail){
        $student_name=$student_detail['student_name'];
        $father_name=$student_detail['father_name'];
        $dob=date('d-m-Y',strtotime($student_detail['dob']));
        $sch_no=$student_detail['sch_no'];
        $course=$student_detail['class'];
        $section=$student_detail['section'];
    }
}


$get_active_course_info=$this->ReportCardModel->student_course_info($sid,$acedemic_session);

if($get_active_course_info){
    foreach($get_active_course_info as $course_info){
        $course_id=$course_info['course_id'];
    }
}
$exam_head_table='exam_heads_2';
$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;        
    }
}

$working_days=0;
$attendance_days=0;
$remark='';
$result_table='exam_result';
$exam_id=1;
$attendance=0;
$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'];
        $working_days=$exam_data['working_days'];
        $attendance= number_format($exam_data['attendance'], 2);
    }
}

$course_subjects_table='exam_subjects_2';
$get_course_exam_subjects=$this->ReportCardModel->get_course_active_subjects($course_id,$course_subjects_table);


?>

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" >
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" ></script>
        <title>Annual Report Card</title>
        <style>
        html{padding:0px;margin:0px;}
        body{padding:10px;margin:0px;vertical-align:middle;}
            tr td{margin:0px;padding:0px;}
            tr th{margin:0px;padding:0px;}
            .report-card{
                /*border:2px solid #a1def4;*/
                border : 2px solid #4F3F83;
                /*height:94.5%;*/
                height:94%;
                border-radius:5px;
                /*outline-offset: -10px;*/
                margin:0px;
                padding:5px;
            }
            .report-2{
                border:2px solid #4F3F83;
                height:95.4%;
                /*height:auto;*/
                border-radius:5px;
            }
            table tr{border :1px solid #a1def4 !important;padding:0px;margin:0px;}
            
            .report-card-body{
                background-image: url("<?php echo logo_png; ?>");
                opacity: 0.05;
                background-repeat: no-repeat;
                background-size: 40% auto;
                background-position: center;
                
                /*height:auto;width: 100%;margin: 0px;padding: 20px;padding-left: 20px;padding-right: 20px;padding-top: 10px;*/
                /*background-image: url("http://localhost/cmsnew/assets/G-Web-Logo-1.png");*/
                /*opacity: 0.05;*/
                /*background-repeat: no-repeat;*/
                /*background-size: 70% auto;*/
                /*background-position: center;*/
            }
        
        
        </style>
    </head>
    <body>
        <div class="report-card p-1">
            <div class="report-2">

                <div  style='margin:0px;padding:0px;width:100%;border-bottom:2px solid #4F3F83;height:100px;' class=''>
                    <div style="width:15%;float:left;text-align:center;padding-top:15px;">
                        <img src='<?php echo logo_png; ?>' style="width:auto;height:80px;" />
                    </div>
                    <!--<img src='<?php echo logo_png; ?>' style="padding:5px;float:left;width:auto;height:80px;" />-->
                    <div style='color:#DA4940 !important;width:85%;float:left;text-align:center;'>
                        <p style="font-size:32px;text-align:center;font-weight:600;"><?php echo school_full_name; ?></p>
                        <p style='padding:0px; margin:0px;width:100%;font-size:16px;text-align:center;font-weight:500;padding-bottom:2px; '><?php echo school_address; ?></p>
                        <p style='padding:0px; margin:0px;text-align:center;'><b>PROGRESS REPORT - SESSION 2021-2022</b></p>
                    </div>
                </div>

                <!--<p style='padding:0px; margin:0px;width:100%;font-size:16px;text-align:center;font-weight:500;padding-bottom:2px; '><?php echo school_address; ?></p>-->
                <!--<p style='padding:0px; margin:0px;text-align:center;border-bottom:2px solid #4F3F83;'><b>ANNUAL PROGRESS REPORT - SESSION 2021-2022</b></p>-->

    
                <div style='width:100%;height:30px;'>
                    <div style='width:50%;float:left;margin:0px;padding:0px;'>
                        <p class='pl-1' style='margin:0px;padding:0px;padding-left:5px;'><b>NAME : </b><?php echo $student_name;?></p>
                        
                    </div>

                    <div style='width:50%;float:left;'>
                        <p class='pl-1' style='margin:0px;padding:0px;'><b>FATHER'S NAME : </b><?php echo $father_name; ?></p>
                        <!--<p style='margin:0px;padding:0px;'><b>SCHOLAR NO: </b><?php echo $sch_no; ?></p>-->
                    </div>
                </div>

                <div style="width:100%;height:25px;border-bottom:2px solid #4F3F83;">
                    <div style="width:30%;float:left;">
                        <p style='margin:0px;padding:0px;padding-left:5px;'><b>CLASS : </b><?php echo $course; echo " "; echo $section; ?></p>
                    </div>
                    <div style='width:30%;float:left;'>
                        <!--<p style='margin:0px;padding:0px;'><b>ROLL NO: </b>61</p>-->
                        <p style='margin:0px;padding:0px;'><b>D. O. B. : </b><?php echo $dob; ?></p>

                    </div>

                    <div style='width:40%;float:left;'>
                        <p style='margin:0px;padding:0px;'><b>ATTENDANCE : </b><?php echo $attendance_days."/".$working_days; ?>  (<?php echo $attendance;?> %)</p>

                    </div>
                </div>

                <div style="padding:0px;" class="report-card-body">
                    <table class="table table-bordered" style="margin:0px;padding:0px;">
                        <thead>
                            <tr style="margin:0px;padding:0px;background:#DBF7F3;">
                                <td style="text-align:center;margin:0px;padding:0px;" colspan="<?php echo $exam_head_count + 7;?>"><b>SCHOLASTIC AREAS</b></td>
                            </tr>
                            <tr style="background:#DBF7F3;margin:0px;padding:0px;">

                                <th colspan="4" style="margin:0px;padding:0px;">SUBJECTS</th>
                                <th style="text-align:center;margin:0px;padding:0px;">MAX MARKS</th>
                                <?php 
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                ?>
                                <th style="text-align:center;margin:0px;padding:0px;"><?php echo $exam_heads['exam_head'];?>
                                </th>
                                <?php
                                    }
                                }
                                ?>
                                <th style="text-align:center;margin:0px;padding:0px;">TOTAL</th>
                                <th style="text-align:center;margin:0px;padding:0px;">Avg.</th>
                            </tr>
                            <tr>
                                <th colspan="4"></th>
                                <th></th>
                                <?php 
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                ?>
                                <th style="text-align:center;margin:0px;padding:0px;">
                                    <?php echo $exam_heads['mm']; ?>
                                </th>
                                <?php
                                    }
                                }
                                ?>
                                <th style="text-align:center;margin:0px;padding:0px;">200</th>
                                <th style="margin:0px;padding:0px;text-align:center;">100</th>
                                <!--<th></th>-->
                            </tr>
                        </thead>
                        <tbody>
                            
                            <?php
                            $mm_total=0;
                            $grand_total=0;
                            if($get_course_exam_subjects){
                                foreach($get_course_exam_subjects as $exam_subjects){
                                    
                                    $mm_total=$mm_total + $exam_subjects['MM'];
                                    $sub_total=0;
                                    $subject_id=$exam_subjects['id'];
                                    $sub_type=$exam_subjects['subject_type'];
                                    $exam_type=$exam_subjects['exam_type'];
                            ?>
                            <tr style="margin:0px;padding:0px;">
                                <th colspan="4" style="margin:0px;padding:2px;"><?php echo $exam_subjects['subject']; ?></th>
                                <th style="text-align:center;margin:0px;padding:2px;"><?php echo $exam_subjects['MM']; ?></th>
                                
                                <?php 
                                if($get_course_exam_heads){
                                    foreach($get_course_exam_heads as $exam_heads){
                                        $ehid=$exam_heads['id'];
                                        $elog_table='exam_log_2';
                                        $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;
                                                ?>
                                                <th style="text-align:center;margin:0px;padding:2px;"><?php echo $elog['obtained_marks']; ?></th>
                                                <?php
                                                }else if($exam_type == "Grade"){
                                                ?>
                                                <th style="text-align:center;margin:0px;padding:2px;"><?php echo $elog['grade']; ?></th>
                                                <?php
                                                }
                                            }
                                        }else{
                                        ?>
                                        <th style="text-align:center;margin:0px;padding:2px;">--</th>        
                                        <?php
                                        }
                                        
                                        
                                    }
                                }
                                ?>
                                
                                
                                <th style="text-align:center;margin:0px;padding:2px;"><?php echo $sub_total; ?></th>
                                <th style="text-align:center;margin:0px;padding:2px;"><?php echo $sub_total / 2; ?></th>
                            </tr>
                            
                            <?php
                            if($sub_type == "Main Subject"){
                                $grand_total= $grand_total + $sub_total;    
                            }
                            
                                }
                            }
                            ?>

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

                                
                                <th style="text-align:center;"><?php echo $mm_total; ?></th>
                                <th colspan="4" style="margin:0px;padding:3px;"></th>
                                <th colspan="" style="text-align:center;margin:0px;padding:3px;"><?php echo $grand_total; ?></th>
                                <th colspan="" style="text-align:center;margin:0px;padding:3px;"><?php echo $grand_total / 2; ?></th>
                            </tr>
                            <?php 
                            $grand_total_avg=$grand_total/2;
                            $percentage=($grand_total_avg * 100)/$mm_total;
                            ?>
                            <tr style="background:#DBF7F3;border:1px solid #4F3F83;">
                                <td colspan="<?php echo $exam_head_count + 4;?>" style="margin:0px;padding:3px;"><b>REMARK :</b>School will reopen on -</td>
                                <td colspan="3" style="margin:0px;padding:3px;"><b>PERCENTAGE : <?php echo number_format((float)$percentage, 2, '.', ''); ?> % </b></td>

                            </tr>
                            
                            <!--<tr>-->
                            <!--    <th colspan="5" rowspan="5" class="text-center">-->
                            <!--        <br>-->
                            <!--CLASS TEACHER-->
                            <!--    </th>-->
                            <!--    <th colspan="5" rowspan="5" class="text-center"> -->
                            <!--        <br>-->
                            <!--PRINCIPAL-->
                            <!--    </th>-->
                            <!--</tr>-->
                        </tbody>
                    </table>
                </div>
                <div style="width:100%;height:100px;">
                    <!--<div style="width:50%;height:100px;float:left;">-->
                    <!--    <table class="table table-bordered" style="width:100%;">-->
                    <!--        <thead>-->
                    <!--            <tr>-->
                    <!--                <th colspan="2" style="text-align:center;">Grade Subjects</th>-->
                    <!--            </tr>-->
                    <!--            <tr>-->
                    <!--                <th></th>-->
                    <!--                <th></th>-->
                    <!--            </tr>-->
                    <!--        </thead>-->
                    <!--        <tbody>-->
                    <!--            <tr>-->
                    <!--                <td></td>-->
                    <!--                <td></td>-->
                    <!--            </tr>-->
                    <!--        </tbody>-->
                    <!--    </table>-->
                    <!--</div>-->
                    <div style="width:100%;height:100px;float:left;">
                        <div style="width:50%;height:100px;text-align:center;float:left;"><br>
                            <p style="padding:2px;margin:0px;padding-left:50px;">CLASS TEACHER</p>
                        </div>
                        <div style="width:50%;height:100px;text-align:center;float:right;"><br>
                            <p style="padding:2px;margin:0px;padding-right:50px;">PRINCIPAL</p>
                        </div>
                    </div>
                </div>
                
            </div>
        </div>
    </body>
</html>