<?php
$pgMod="bus_report";
$pgAct="view";
$monthsList = array(
    1=>'Apr',
    2=>'May',
    3=>'Jun',
    4=>'Jul ',
    5=>'Aug',
    6=>'Sep',
    7=>'Oct',
    8=>'Nov',
    9=>'Dec',
	10=>'Jan',
    11=>'Feb',
    12=>'Mar'
); 
?>
<style>.top-bar-minimize{display:none;}
thead, tfoot {display: table-header-group;}
.top-bar+.well,.accordion .accordion-heading+.accordion-body{display: inline-block !important;width: 100% !important;overflow: inherit !important;} 
.dynamic{display:none}
table td {
padding: 6px !important;
}
.data{border-right: 3px solid #04606C;}
legend{line-height: 16px;font-weight:100;}
</style>

<div id="printDiv" class="divclass">
<?php

 	$aryList=$db->getRows("SELECT * FROM bus where school_id='".$_SESSION["admin"]["school_id"]."' "); $i=0;
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <!--<button class="btn btn-danger" onclick="exportTableToExcel('tblData', 'Get Report')" style="float:right;margin-top:10px;">Excel</button>-->
        <input type="button" class="btn btn-primary" id="btn_excel" value="Excel" style="float:right;"/>
        <button type="button" onclick="printDiv('printDiv')" class="btn btn-danger" style="float:right;">Print</button>
		<table cellpadding="0" cellspacing="0" class="table" border="1" id="tblData">
        <!--<table class="table" id="example">-->
            <thead>
                <tr>
                    <th>S.No.</th>
                    <th>Pickup Point</th>
                    <th>Address</th>
                    <th>Distance (KM) </th>
                    <th>Fee</th>
                    <!--<th>Installment</th>-->
                    <!--<th>Action</th>-->
                </tr>
            </thead>
            <tbody>
            <?php foreach($aryList as $clist){ $i++; 
            $aryPgAct["id"]=$clist['id'];
            ?>
                <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                    <td><?php echo $i; ?></td>
                    <td><?php echo $clist["root"] ?></td>
                    <td><?php echo $clist["bus"] ?></td>
                    <td><?php echo $clist["distance"] ?></td> 
                    <td><?php echo $clist["fee"] ?></td>
                    <!--<td><?php echo $clist["installment"] ?></td>-->
                    <!--<td>-->
                    <!--    <?php $aryPgAct['action']="edit"; ?>-->
                    <!--        <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">Edit</button></a>-->
                    <!--    <?php $aryPgAct['action']="delete"; ?>-->
                    <!--        <a href="javascript:;" onclick="del('<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>')" class="confirmation"><button type="button" class="btn btn-danger">Delete</button></a>  -->
                    <!--</td>-->
                </tr>
            <?php } ?>
            </tbody>
        </table>
		<?php
	}



?>
</div>


<script>

function getpickup(route){

    $.post( "Transport/ajax.php", { type: "route_pickup" ,route: route} , function( data ) {
        $("#pickup").html(data);
    });

}

    $("#btn_excel").click(function(e) {
        // var filename = $("#filename").val();

    let file = new Blob([$('.divclass').html()], {type:"application/vnd.ms-excel"});
    let url = URL.createObjectURL(file);
    let a = $("<a />", {
    href: url,
    download: "Pickup Fare Report.xls"}).appendTo("body").get(0).click();
    e.preventDefault();
    });


    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>