<html>
    <head>
        <title><?php echo $b_header['title']; ?></title>
                <style>
            @media print
            {
                * {-webkit-print-color-adjust:exact;}
                @page {margin:0in 0.10in 0in 0in; }
                .super_container
                {
                    page-break-after: always;
                    margin-top:0.25in;
                    position:relative;
                    width:100vw;
                    height:710px;
                }
            }
            body {margin: 0.25in 0.25in 0.63in 0.25in; box-sizing:border-box;width:100vw; height:100vh;padding-bottom:0.63in;}
            *{margin:0;padding:0;font-family:calibri;}
            .clear:after{content:"";clear:both;display:block;}
            .left{float:left;}
            .right{float:right;}
            .wd-10{width:10%;}
            .wd-20{width:20%;}
            .wd-30{width:30%;}
            .wd-40{width:40%;}
            .wd-50{width:50%;}
            .wd-60{width:60%;}
            .wd-70{width:70%;}
            .wd-80{width:80%;}
            .wd-90{width:90%;}
            .wd-100{width:100%;}
            .wd-15{width:15%;}
            .wd-25{width:25%;}
            .wd-35{width:35%;}
            .wd-45{width:45%;}
            .wd-55{width:55%;}
            .wd-65{width:65%;}
            .wd-75{width:75%;}
            .wd-85{width:85%;}
            .wd-95{width:95%;}
            .wd-100{width:100%;}
            .title{font-size:35px;}
            .super_container
            {
                margin-bottom:200px;
                position:relative;
                width:100vw;
                height:710px;
            }
               .wrapper{
                border:4px dotted #18a05e;
                outline: 7px double #18a05e;
                outline-offset: 5px;
                box-sizing: border-box;
                padding:5px;
            }
             .super_wrapper
            {
                position:absolute;
                top:0;
                left:0;
                width:100%;
                z-index:120;
                margin:0;
                padding:0;
            }
            .watermark
            {
                height:200px;
                width:300px;
                margin:auto;
                padding-top:50px;
                padding-left:100px;
                opacity:0.1;
                background:url("<?php echo base_url().$b_header['logo1']; ?>");
                background-size:100% 100%;
            }
            .watermark_wrapper
            {
                height:470px;
                width:100%;
                margin-top:50px;
                display:inline-flex;
                display:-webkit-inline-flex;
             }
            .wrapper.left2{
                width: calc(90vw);
                margin-right: 20px;
                margin-left: 20px;
            }
            h1,h2,h3{
                color:#18a05e;
                font-family:calibri;
                text-align:center;
            }
            .boxed{background:#18a05e;color:#fff;width:80%;margin:0 auto;}
            .header{
                width:100%;
                border-bottom:4px double #18a05e;            
            }
            .body{
                padding:10px;
            }
            .row{
                width:100%;
                margin: 0px auto;  
            }
            .text-center{text-align:center;}
            .bold{font-weight:bold;}
            .b-u-l{
                border-bottom: 1px solid #000;
                height:inherit;
            }
            .x-small{
                font-size: 10px;
            }
            .x-x-small{
                font-size: 7px;
            }
            .page_break{
                width: 100vw;
                height: 100vh;
                padding: 10px 0px;
                box-sizing: border-box;
            }
            .tbl1
            {
                border: 2px dotted #000;
                text-align:center;
                width:100%;
                min-height:20px;
            }
            th{
                border: 1px solid #000;
                background-color:#18a05e; 
                padding: 3px !important;
                color: #fff;
            }
            td{
                border: 1px solid #000;
                padding: 2px !important;
            }
            .normal{
                font-weight: normal !important;
            }
            .text-right{
                text-align: right !important;
            }
            .text-left{
                text-align: left !important;
            }
            .margin-a{margin: 30px auto 0px auto;}
            table { page-break-inside:auto }
            tr    { page-break-inside:avoid; page-break-after:auto }
            thead { display:table-header-group }
            tfoot { display:table-footer-group }
        </style>
    </head>
    <body class="clear">
        <?php date_default_timezone_set("Asia/Karachi"); ?>
        <div class="super_container">
            <div class="page_break clear">
                <div class="watermark_wrapper">
                    <div class="watermark"></div>
                </div>
                <div class="super_wrapper">
                    <div class="wrapper left2 left">
                        <div class="header">
                            <div class="wd-100 clear">
                                <div class=" text-left left ">
                                    <img src="<?php echo base_url().$b_header['logo1']; ?>" style="width:50px;height:50px;">
                                </div>
                                <div class=" text-left right ">
                                    <img src="<?php echo base_url().$b_header['logo2']; ?>" style="width:50px;height:50px;">
                                </div>
                                <div style="">
                                    <center><h1><?php echo $b_header['title']; ?></h1></center>
                                    <center><h3 style="color:#000 !important;"><i><?php echo $b_header['tagline']; ?></i></h3></center>
                                    <center><i><h3 style="color:#000 !important;font-weight:normal;"><?php echo $b_header['short_address']; ?></h3></i></center>
                                    <center><h3 class="boxed" style="margin-top:0px !important;font-size:23px;">Assessment Report Card</h3></center>
                                </div>
                            </div><br>
                            <div class="wd-100 clear">
                                <div class="wd-80 left">
                                    <div class="wd-100 clear">
                                        <div class="wd-50 left">
                                            <div class="wd-50 left"><h4>Student Name:</h4></div>
                                            <div class="wd-50 left"><h5><?php echo $result['student_name'];?></h5></div>
                                        </div>
                                        <div class="wd-50 left">
                                            <div class="wd-50 left"><h4>Father Name:</h4></div>
                                            <div class="wd-50 left"><h5><?php echo $result['father_name'];?></h5></div>
                                        </div>
                                    </div>   
                                    <div class="wd-100 clear">
                                        <div class="wd-50 left">
                                            <div class="wd-50 left"><h4>S.Id:</h4></div>
                                            <div class="wd-50 left"><h5><?php echo $result['sid'];?></h5></div>
                                        </div>
                                        <div class="wd-50 left">
                                            <div class="wd-50 left"><h4>Class:</h4></div>
                                            <div class="wd-50 left"><h5><?php echo $result['class_name'];?></h5></div>
                                        </div>
                                    </div>    
                                    <div class="wd-100 clear">
                                        <div class="wd-50 left">
                                            <div class="wd-50 left"><h4>Section:</h4></div>
                                            <div class="wd-50 left"><h5><?php echo $result['section_name'];?></h5></div>
                                        </div>
                                        <div class="wd-50 left">
                                            <div class="wd-50 left"><h4>Term:</h4></div>
                                            <div class="wd-50 left"><h5><?php echo $result['exam_name'];?></h5></div>
                                        </div>
                                    </div>
                                  
                                </div>  
                                <div class="wd-20 left" style="margin-bottom:15px;">
                                    <img src="<?php echo base_url();?><?php echo $result['img'];?>" width="80px" height="80px">
                                </div>
                            </div>
                        </div>
                        <div class="body">
                            <?php
                            $obtian=0;$rowtotal=0;$rowobtain=0; $total = 0; $high=0;$low=0; $serial=1;$re=0;$too=0;$totup=0;$totdown=0;$totupob=0;$totdownob=0;
                   
                            if(!empty($ass_subject))
                            { ?>
                            <table class="tbl1 new">
                                <thead>
                                <tr>
                                    <th>#</th>
                                    <!--<th class="th">Subject</th>-->
                                   <?php
                                foreach ($sbs as $key => $res) { ?>
                                   <th class="th" colspan="2"><?php echo $res['subject_name']; ?></th>
                                   <?php } ?>
                                   <th class="th" colspan="3">Total</th>
                                </tr>
                                 <tr>
                                    <th rowspan="2">Assesments</th>
                                    <?php for($i=0;$i<count($sbs);$i++) {
                                        echo "<th>O</th><th>T</th>";
                                    } ?>
                                    <th rowspan="2">O</th>
                                    <th rowspan="2">T</th>
                                    <th rowspan="2">%</th>
                                </tr>
                                <tr>
                                  <?php for($i=0;$i<count($sbs);$i++) {
                                        echo "<th colspan='2'>Date</th>";
                                    } ?>
                                </tr>
							</thead> 
                                <?php
                                // foreach ($sbs as $key => $res) { 
                                foreach($types as $rw=>$row)
                                      {
                                ?>
                                <tr>
                                    <td class="td" rowspan='2'><?php echo $row['name']; ?></td>
                                      <?php
                                      $rowtotal=0;$rowobtain=0;
                                     foreach ($sbs as $key => $res) { 
                                         
                                          $this->db->select('*');
                                                           $this->db  ->from('result_subject');
                                                            $this->db ->where('result_id',$res['result_id']);
                                                            $this->db ->where('subject_id',$res['subject_id']);
                                                            $this->db ->where('subexam_id',$row['subexam_id']);
                                //          if($sub_typeid>0){
                                //       $this->db->where('subexam_id',$sub_typeid); 
                                //   }
                                  
                                           $this->db->where('is_delete',0);
                                        $chckdata=$this->db->get()->row_array();
                                        
                                      if(!empty($chckdata))
                                      {
                                          $total=$total+$chckdata['total_marks'];
                                          $rowtotal=$rowtotal+$chckdata['total_marks'];
                                          $obtian=$obtian+$chckdata['obtained_marks'];
                                          $rowobtain=$rowobtain+$chckdata['obtained_marks'];
                                          ?>
                                         <td><?php echo $chckdata['obtained_marks']; ?></td>  
                                          <td><?php echo $chckdata['total_marks']; ?></td> 
                                    <?php  }else
                                    {
                                        echo "<td>-</td>";
								        echo "<td>-</td>";
                                    }
                                      ?>
                                         
                                    <?php  }
                                       echo "<td rowspan='2'>";
								               echo @$rowobtain;
								               echo "</td>";
								               echo "<td rowspan='2'>";
								               echo @$rowtotal;
								               echo"</td>";
								               echo "<td rowspan='2'>";
								               if($rowtotal==0)
								               {
								                   $rowtotal=1;
								               }
								               echo round((@$rowobtain/@$rowtotal)*100);
								               echo "</td>";
                                    
                                    ?>
                               </tr>
                               <?php
                               //Dates
                               echo "<tr>";
                               
                                foreach ($sbs as $key => $res) { 
                                          $this->db->select('*');
                                                             $this->db->from('result_subject');
                                                             $this->db->where('result_id',$res['result_id']);
                                                            $this->db ->where('subject_id',$res['subject_id']);
                                                            $this->db ->where('subexam_id',$row['subexam_id']);
                                //                                   if($sub_typeid>0){
                                //       $this->db->where('subexam_id',$sub_typeid); 
                                //   }
                                 
                                                             $this->db->where('is_delete',0);
                                                             $chckdata=$this->db->get()->row_array();
                                       
                                      if(!empty($chckdata))
                                      {
                                                 echo "<td colspan='2'>";
								                 echo date('d-m-Y',strtotime(@$chckdata['paper_date']));
								                 echo "</td>";
                                          ?>
                                    <?php  }else
                                    {
                                        echo "<td colspan='2'>-</td>";
                                    }
                                      ?>
                                         
                                    <?php  }
                                    
                                     echo "<tr>";
                                    ?>
                                <?php } ?>
                               
                            </table>
                        <?php  } 
                            ?>
                            <br><br><br>
                            <div class="wd-100 clear">
                                <div class="wd-40 left">
                                    <div class="wd-50 left"><h3 class="text-left">Marks %:</h3></div>
                                    <div class="wd-50 left"><h4><?php if($total!=0){echo round( (@$obtian / @$total) * 100, 2)."%";}else{ echo 0;}  ?></h4></div>
                                </div>

                                <div class="wd-50 left">
                                    <div class="wd-50 left"><h3 class="text-left">Grade:</h3></div>
                                    <div class="wd-50 left">
                                        <h4><?php echo $result['grade'];?></h4>
                                    </div>
                                </div>
                            </div>
                            <div class="wd-100 clear">
                                 <div class="wd-40 left">
                                    <div class="wd-50 left"><h3 class="text-left">Position:</h3></div>
                                    <div class="wd-50 left"><h4><?php echo $result['position'];?></h4></div>
                                </div>
                               
                                 <div class="wd-50 left">
                                    <div class="wd-50 left"><h3 class="text-left">Class Highest %:</h3></div>
                                    <div class="wd-50 left">
                                    <h4><?php 
                                    $res=@$this->db->select('sum(result_subject.obtained_marks) as obt_mrks,sum(result_subject.total_marks) as totl,result_subject.result_id')
                                                                   ->from('promotion')
                                                                   ->join('result','result.promotion_id=promotion.id')
                                                                   ->join('result_subject','result_subject.result_id=result.id')
                                                                   ->where('promotion.class_id',$prom['class_id'])
                                                                   ->where('promotion.section_id',$prom['section_id'])
                                                                   ->where('promotion.session_id',$prom['session_id'])
                                                                   ->where('result.exam_id',$examtype)
                                                                   ->where('result_subject.subexam_id>',0)
                                                                   ->where('promotion.is_active',1)
                                                                   ->group_by('result_id')
                                                                   ->order_by('obt_mrks','desc')
                                                                   ->limit('1')
                                                                   ->get()->result_array();
                                            
                                                       if(!empty($res))
                                                       {
                                                           @$high=($res[0]['obt_mrks']/$res[0]['totl'])*100;
                                                          
                                                           echo round(@$high,2)."%";
                                                       }
                                    ?>
                                    </h4></div>
                                </div>
                              
                            </div>
                            
                            <div class="wd-100 clear">
                                 <div class="wd-40 left">
                                    <div class="wd-50 left"><h3 class="text-left">Class Lowest %:</h3></div>
                                    <div class="wd-50 left"><h4>
                                    <?php 
                                    $res=@$this->db->select('sum(result_subject.obtained_marks) as obt_mrks,sum(result_subject.total_marks) as totl,result_subject.result_id')
                                                                   ->from('promotion')
                                                                   ->join('result','result.promotion_id=promotion.id')
                                                                   ->join('result_subject','result_subject.result_id=result.id')
                                                                   ->where('promotion.class_id',$prom['class_id'])
                                                                   ->where('promotion.section_id',$prom['section_id'])
                                                                   ->where('promotion.session_id',$prom['session_id'])
                                                                   ->where('result.exam_id',$examtype)
                                                                   ->where('result_subject.subexam_id>',0)
                                                                   ->where('promotion.is_active',1)
                                                                   ->group_by('result_id')
                                                                   ->order_by('obt_mrks','asc')
                                                                   ->limit('1')
                                                                   ->get()->result_array();
                                            //   var_dump('<pre>',$res);
                                            //   die();
                                                       if(!empty($res))
                                                       {
                                                           @$low=($res[0]['obt_mrks']/$res[0]['totl'])*100;
                                                          
                                                           echo round(@$low,2)."%";
                                                       }
                            
                                    ?></h4></div>
                                </div>
                               
                                 <div class="wd-50 left">
                                    <div class="wd-50 left"><h3 class="text-left">Class Average %:</h3></div>
                                    <div class="wd-50 left">
                                    <h4><?php 
                                    @$avr=(@$high+@$low)/2;
                                     echo round(@$avr,2)."%";
                                      
                                    ?>
                                    </h4></div>
                                </div>
                              
                            </div>
                            
                            <div class="wd-100 clear">
                              
                                  <div class="wd-40 left">
                                    <div class="wd-50 left"><h3 class="text-left">Total Marks:</h3></div>
                                    <div class="wd-50 left"><h4>
                                        <?php 
                                         echo $total ?></h4></div>
                                </div>
                                
                                 <div class="wd-50 left">
                                    <div class="wd-50 left"><h3 class="text-left">Total Marks:</h3></div>
                                    <div class="wd-50 left"><h4><?php  
                                     echo $obtian  ?></h4></div>
                                </div>
                            </div> 
                            <div class="wd-100 clear">
                                <div class="wd-30 left text-center">
                                    <div class="row text-center bold">
                                        Examination Officer
                                    </div>
                                    <div class="wd-50 margin-a b-u-l"></div>
                                </div>
                                <div class="wd-30 left text-center">
                                    <div class="row text-center bold">
                                    </div>
                                </div>
                                <div class="wd-40 right text-center">
                                    <div class="row text-center bold">
                                        Principal
                                    </div>
                                    <div class="wd-50 margin-a b-u-l"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script>
        window.print();
    </script>
</html>
