<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-5{width:5%;}
            .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 transparent #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,h4,p{
                color:#191970;
                font-family:calibri;
                text-align:center;
            }
            .boxed{color:#000000;width:80%;margin:0 auto;}
            .header{
                width:100%;
                border-bottom:4px solid #191970;            
            }
            .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: 12px;
            }
            .x-x-small{
                font-size: 9px;
            }
            .page_break{
                width: 100vw;
                height: 100vh;
                padding: 10px 0px;
                box-sizing: border-box;
            }
            .tbl1
            {
                border: 1px solid #000;
                text-align:center;
                width:100%;
                min-height:20px;
            }
            th{
                font-size: 12px;
                border: 1px solid #000;
                  border-right: 0px;
                border-bottom: 0px; 
                background-color:#ccccb3; 
                padding: 3px !important;
            }
            td{
                font-size:12px;
                border: 1px solid #000;
                text-align: left;
                  border-right: 0px;
                border-bottom: 0px; 
                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;}
        </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 style="color:black"><?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><h4>Contact# <?php //echo $b_header['phone_no']; ?> / <?php //echo $b_header['email']; ?></h4></center>-->
                                    <center><h3 class="boxed" style="margin-top:0px !important;font-size:23px;">Fee History</h3></center>
                                </div>
                            </div>
                            <div class="wd-100 clear">
                                <div class="wd-100 left">
                                    <div class="wd-100 clear">
                                        <div class="wd-30 left">
                                            <div class="wd-50 left"><h3 style="color:black">Student Name:</h3></div>
                                            <div class="wd-50 left"><h4 style="color:black"><?php echo $detail['student_name'];?></h4></div>
                                        </div>
                                        <div class="wd-30 left">
                                            <div class="wd-50 left"><h3 style="color:black">S.ID:</h3></div>
                                            <div class="wd-50 left"><h4 style="color:black"><?php echo $detail['sid'];?></h4></div>
                                        </div>
                                         <div class="wd-30 left">
                                            <div class="wd-50 left"><h3 style="color:black">Parent Name:</h3></div>
                                            <div class="wd-50 left"><h4 style="color:black"><?php echo $detail['father_name'];?></h4></div>
                                        </div>
                                    </div>   
                                    <div class="wd-100 clear">
                                       
                                        <div class="wd-30 left">
                                            <div class="wd-50 left"><h3 style="color:black">Parent Contact:</h3></div>
                                            <div class="wd-50 left"><h4 style="color:black"><?php echo $detail['father_contact'];?></h4></div>
                                        </div>
                                         <div class="wd-30 left">
                                            <div class="wd-50 left"><h3 style="color:black">Class:</h3></div>
                                            <div class="wd-50 left"><h4 style="color:black"><?php echo $detail['class_name'];?></h4></div>
                                        </div>
                                         <div class="wd-30 left">
                                            <div class="wd-50 left"><h3 style="color:black">Section:</h3></div>
                                            <div class="wd-50 left"><h4 style="color:black"><?php echo $detail['section_name'];?></h4></div>
                                        </div>
                                        
                                    </div>    
                              
                             
                                </div>  

                            </div>
                        </div>
                        <div class="body">
                            <table class="tbl1">
                        <thead>
                                <tr>
                                 <th>#</th>
                                 <th>Voucher No.</th>
                                 <th>Total Fee</th>
                                 <th>Fine</th>
                                 <th>Fee Received</th>
                                 <th>Discount</th>
                                 <th>Remaining</th>
                                 <th>Advance</th>
                                 <th>Voucher Date</th>
                                 <th>Receiving Date</th>
                                </tr>
                      </thead>


                      <tbody>
                    
                        <?php $i=1;  $total=0; $t_fee= 0; $remain_fee=0; $discount=0;$fine=0;$advance=0;$grand_total=0; $prev_id=0;$f_rem=0;
                        foreach ($student as $key => $value) { 
                       
                        ?>
                        <tr>
                          <td><?php echo $i++; ?></td>
                          <td style = "text-align: center;">
    <a href='<?php echo base_url();?>voucher/view/<?php echo base64_encode(json_encode($value['invoice_id'].SALT)); ?>' target ='_blank' class='btn btn-md btn-info'>                          
                              <?php 
                              if($prev_id!=$value['inv_id'])
                              {
                                  $f=$this->voucher_model->countTotalFee_history($value['invoice_id']);
                                  
                                  $f_r=$this->voucher_model->getRemainingAmount($value['invoice_id']);
                                  $grand_total=$grand_total+$f;
                                 var_dump($grand_total);
                                  $f_rem=$f_rem+$f_r;
                              }
                              $prev_id=$value['inv_id'];
                              echo $value['invoice_id']; 
                              ?>
  </a>                              
                          </td>
                          <?php 
                          $last_adv=0;
                          if(!empty($value['flog_id']))
                          {
                            $last_adv = @$this->db->select('advance')
                                                ->where('id <',$value['flog_id'])
                                                ->where('student_id',$value['s_id'])
                                                ->order_by('id','DESC')
                                                ->get('fee_submit_logs')
                                                ->row()->advance;  
                          }
                          
                      if(($value['recieved'] == 0  || $value['advance'] > 0) && ($last_adv > 0)){
                         
                          ?>
                            <td style = "text-align: right;"><?php $value['fee_total'] = ($last_adv) + ($value['remaining'] + $value['discount'] - $value['fine'])-$value['advance'];echo $last_adv."<span style='font-size:10px;color:red' >(advance:$last_adv)</span>".number_format($value['fee_total']); $t_fee+=$value['fee_total']; ?></td>
                          <?php }else{
                          ?>
                     <td style = "text-align: right;"><?php
                     
                 $value['fee_total'] = ($value['recieved'] + $value['remaining'] + $value['discount'] - $value['fine'])-$value['advance'];
                     if(empty($value['fee_total'])){
                         $value['fee_total']=$this->voucher_model->countTotalFee($value['invoice_id']);
                         echo number_format($value['fee_total']);
                         $t_fee+=$value['fee_total'];
                     }else{
                         echo number_format($value['fee_total']);
                         $t_fee+=$value['fee_total'];
                     }?>
                     </td>
                          <?php } ?>
                          
                          <td style = "text-align: right;"><?php echo number_format($value['fine']); $fine += $value['fine']?></td>
                          <!--<td style = "text-align: right;"><?php// echo $last_adv;  ?></td>-->
                          <td style = "text-align: right;"><?php 
                          if($value['is_auto']==0)
                          {
                          echo number_format($value['recieved']); $total+=$value['recieved']; } ?></td>
                          <td style = "text-align: right;"><?php echo number_format($value['discount']); $discount += $value['discount']?></td>
                          <td style = "text-align: right;"><?php $value['remaining'];echo ($value['remaining'] > 0) ? number_format($value['remaining']) : 0; if($value['remaining'] > 0)$remain_fee +=$value['remaining']?></td>
                          <?php if($value['recieved'] == 0 && $last_adv > 0){?>
                                <td style = "text-align: right;"><?php $value['advance'] = 0;echo number_format($value['advance']); $advance += $value['advance']?></td>
                          <?php }else{?>
                                <td style = "text-align: right;"><?php echo number_format($value['advance']); $advance += $value['advance']?></td>
                          <?php }?>
                            <td style = "text-align: right;"><?php echo date('d-M-Y',strtotime($value['date'])) ?></td>
                          <td style = "text-align: right;"><?php 
                          if(!empty($value['f_date'])){
                              echo date('d-M-Y',strtotime($value['f_date']));
                          }else{

                          }?>
                          </td>
                        </tr>
                        <?php } ?>
                      </tbody>
                
                    </table>
                    <br>
            <div class="wd-100 clear">
                <div class="wd-25 left ">
                    <h3 style="text-align: left">Summary:</h3>
                       
                </div>
            </div>
               <br>
              <div class="wd-100 clear">
                 
                 <div class="wd-20 right ">
                  <h5 style="text-align: left">Fee Remaining:<?php echo number_format($f_rem); ?></h5>
                </div>
                
                <div class="wd-20 right ">
                  <h5 style="text-align: left">Fee Advance:<?php $advance = ($total + $discount + $remain_fee -$fine) - $t_fee;echo number_format($advance); ?></h5>
                </div>
                <div class="wd-20 right ">
                    <h5 style="text-align: left"> Fee Received:<?php echo number_format($total); ?></h5>
                </div>
                <div class="wd-20 right">
                    <h5 style="text-align: left">Total Fee:<?php echo number_format($grand_total);?></h5>
                </div>
                
                
                
            </div> 
            
             
               
               
                     <br>
<tr style="margin-top:50px;">
                                        <td colspan="11" style="border:0px;">
                                            <div class="wd-100 clear">
                                                <center>
                                                    <h1 class="ctitle" style="color:#000080">
                                                        Fee Statistics
                                                    </h1>
                                                </center>
                                                <br>
                                                <div class="wd-100 clear">
                                                    <center>
                                                        <div class="wd-100 left">
                                                        <div id="chartContainer" style="height: 400px; width: 800px;">
                                                            
                                                        </div>
                                                        </div>
                                                    </center>
                                                </div>
                                            </div>
                                        </td>
                               </tr>
                  </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script>
        window.print();
    </script>
</html>
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>

  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>

<script src="<?php echo base_url(); ?>assets/js/jquery.canvasjs.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/canvasjs.min.js"></script>

<script>
window.onload = function () {

var chart = new CanvasJS.Chart("chartContainer", {
	animationEnabled: true,
	title:{
		text: " ",
		horizontalAlign: "left"
	},
	data: [{
		type: "doughnut",
		startAngle: 60,
// 		innerRadius: 40,
		indexLabelFontSize: 17,
		indexLabel: "{label} - #percent%",
		toolTipContent: "<b>{label}:</b> {y} (#percent%)",
		dataPoints: [
		 { label: 'Received: '+ <?php echo $total ?> +'', y: <?php echo empty($total)? 0 : $total ?> },
         { label: 'Discount: '+ <?php echo $discount ?> +'', y: <?php if(empty($discount)){ echo '0'; }else{echo $discount; } ?> },
        { label: 'Advance: '+ <?php echo $advance ?> +'', y: <?php echo empty($advance)? 0 :$advance ?> },
        { label: 'Fine: '+ <?php echo $fine ?> +'', y: <?php echo empty($fine)? 0 :$fine ?> }
		]
	}]
});
chart.render();

}
</script>



