<?php
    $pgMod="transport_reports";
    $pgAct="view";
?>

<div id="printDiv">
<?php   $aryList=$db->getRows("select * from bus_detail where school_id='".$_SESSION["admin"]["school_id"]."' ");   ?>
 <h5><p style="text-align:center">Total Transport Report</p></h5>
    <button class="btn btn-danger" onclick="exportTableToExcel('tblData', 'Bus Report')" style="float:right;margin:10px;">Excel</button>
        <table cellpadding="0" cellspacing="0" class="table" border="1" id="tblData">
			<thead>
			<tr>
            	<th>S.No</th>
				<th>Bus Name</th>
				<th>Driver Name</th>
				<th>Mobile</th>
                <th>Total student</th>
                <th>No. of seats</th>
                <th>Remaining seats</th>
			</tr>
			</thead>
			<tbody>
				<?php $i=0;$total_r=$tot_boys=$tot_girls=$tot_teacher=$tot_student=$tot_seats=0;
				foreach($aryList as $arr){$i++;
					$slist=$db->getRows("Select * from student where old_school ='".$arr['id']."'and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 order by name");

					$mcount=0;$fcount=0;$total=0;
					if(is_array($slist)&& count($slist)!=""){
						foreach($slist as $s){
						if($s['gender']=="male")
							$mcount++;
						elseif($s['gender']=="female")
							$fcount++;
							$total++;	
						} 
					}$total_s=$total;$total+=$tcount;
					$tot_boys+=$mcount;$tot_girls+=$fcount;$tot_student+=$total_s;
					$remain=$arr['no_of_stduent']-$total;
					$total_r+=$remain;$tot_seats+=$arr['no_of_stduent'];?>
					<tr>
                    	<td><?php echo $i; ?></td>
						<td><?php echo $arr["name"] ?></td>
						<td><?php echo $arr["driver_name"] ?></td>
						<td><?php echo $arr["driver_no"] ?></td>
                        <td><?php echo $total_s; ?></td>
                        <td><?php echo $arr["no_of_stduent"] ?></td>
                        <td><?php echo $remain; ?></td>
						
					</tr>
					<?php
				}
				?>
                <tr>
                	<td colspan="4">Gross Total</td>
                    <td><?php echo $tot_student; ?></td>
                    <td><?php echo $tot_seats; ?></td>
                    <td><?php echo $total_r; ?></td>
                </tr>
			</tbody>
			
		</table>

        Print date : <?php echo date("d-M-Y") ?>
<?php 
?>
</div>


<script>
    function exportTableToExcel(tableID, filename = '',e){
    
    var tableType = document.getElementById('tblData').getAttribute("data-tblname");

    var downloadLink;
    var dataType = 'application/vnd.ms-excel';
    var tableSelect = document.getElementById(tableID);
    var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');

    // Specify file name
    filename = filename?filename+'.xls':'excel_data.xls';
    
    // Create download link element
    downloadLink = document.createElement("a");
    
    document.body.appendChild(downloadLink);
    
    if(navigator.msSaveOrOpenBlob){
        var blob = new Blob(['\ufeff', tableHTML], {
            type: dataType
        });
        navigator.msSaveOrOpenBlob( blob, filename);
    }else{
        // Create a link to the file
        downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
    
        // Setting the file name
        downloadLink.download = filename;
        
        //triggering the function
        downloadLink.click();
    }
    e.preventDefault();
}
</script>