<?php
$pgMod="user_wise_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>
<form method="get" action="">
    <input type="hidden" name="src" value="ERP" />
    <input type="hidden" name="page_id" value="<?php echo $pgMod; ?>" />
	<div class="row-fluid">
        <div class="span12">
            <div class="well no-padding">
                <div class="controls controls-row">

                    <div class="control-group span4">
                        <div class="controls span4">
                            <select name="id">
                            	<option value="">All</option>
								<?php 
									$aryList=$db->getRows("select * from sales_person where school_id='".$_SESSION["admin"]["school_id"]."' order by name");
										foreach($aryList as $clist){
                                        ?>
                                        <option value="<?php echo $clist['id']; ?>" <?php if($clist['id'] == $_GET["id"]){echo "selected"; } ?> ><?php echo $clist['name']; ?></option>
                                        <?php }
								?>
							</select>
                        </div>
                    </div>

                    <div class="control-group span3">
                    <button type="submit" name="get_report" class="btn-classic margin">Get Report</button>
                    <!--<button type="submit" name="bus_detail" class="btn-classic margin">Bus Report</button>-->
                    <!--<button type="submit" name="teacher_detail" class="btn-classic margin">Teacher Report</button>                    -->
                    <!--<button type="submit" name="daily_att" class="btn-classic margin">Bus Attendance</button>-->
                   
                    </div>

                    <div class="control-group span2">
                      <button type="button" onclick="printDiv('printDiv')" class="btn btn-danger">Print</button>
                      </div>

                </div>
            </div>
        </div>
    </div>
</form>
<div id="printDiv">
<?php
if(isset($_REQUEST['get_report'])){

	$where="";
	if(isset($_GET["id"]) && $_GET["id"]!=""){
	    $where=" where id='".$_GET["id"]."' ";
    }

	$aryStudentList=$db->getRows("select * from sales_person $where order by name");

	if(is_array($aryStudentList) && count($aryStudentList)>0){
		?>
		<h5><p>Sales Person List :</p></h5>

        <?php $aryList=$db->getRow("select * from bus_detail where id='".$_GET["old_school"]."' and school_id='".$_SESSION["admin"]["school_id"]."'")?>
        <!--<button class="btn btn-danger" onclick="exportTableToExcel('tblData', 'Get Report')" style="float:right;margin-top:10px;">Excel</button>-->

		<table cellpadding="0" cellspacing="0" class="table" border="1" id="tblData">
			<thead>
    			<tr>
                	<th>S.No</th>
    				<th>Name</th>
    				<th>Father Name</th>
    				<th>Mother Name</th>
    				<th>D.O.B.</th>
    				<th>Email</th>
    				<th>Mobile</th>
    				<th>Location</th>
    				<th>Address</th>
    			    <th>Photo</th>
    			</tr>
			</thead>
			<tbody>
				<?php $i=0;$j=0; $columntotal = [];
				foreach($aryStudentList as $fStudent){$i++;$total=0;$j++;
					?>
					<tr >
                    	<td><?php echo $j; ?></td>
						<td><?php echo $fStudent["name"] ?></td>
						<td><?php echo $fStudent["fname"] ?></td>
                        <td><?php echo $fStudent["mname"] ?></td>
                        <td><?php echo $fStudent["dob"] ?></td>
                        <td><?php echo $fStudent["email"] ?></td>
                        <td><?php echo $fStudent["mobile"] ?></td>
                        <td><?php echo $fStudent["location"]; ?></td>
						<td><?php echo $fStudent["address"] ?></td>
						<td><img src="<?php echo URL_ROOT."media/photo/$fStudent[photo]"; ?>" style="width:80px;height:100px;" /></td>
					</tr>
					<?php
				}
				?>
			</tbody>

		</table>

        Print date : <?php echo date("d-M-Y") ?>
		<?php
	}else{

	}
 
}

 elseif(isset($_REQUEST['daily_att'])){
if(isset($_GET["old_school"]) && trim($_GET["old_school"])!=""){
	$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;
	$aryStudentList=$db->getRows("select * from student where old_school='".$_GET["old_school"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 order by class,name");
	
	$month=$_GET["fmonth"];$m=0;
	  if($month<4){
		$m=($month+9);
	  }
	  else{
		$m=$month-3;
	  }
	  //echo $m;
	if(is_array($aryStudentList) && count($aryStudentList)>0){
		?>
		<h5><p style="float:right">Vechicle No : <?php echo $db->getVal("select name from bus_detail where id='".$_GET["old_school"]."' and school_id='".$_SESSION["admin"]["school_id"]."'");echo $db->getErMsg(); ?></p>	<p>Transport Attendance list Vechicle no Wise :</p></h5>
    <?php $aryList=$db->getRow("select * from bus_detail where id='".$_GET["old_school"]."' and school_id='".$_SESSION["admin"]["school_id"]."'")?>
    <button class="btn btn-danger" onclick="exportTableToExcel('tblData', 'Bus Attendance')" style="float:right;margin:10px;">Excel</button>
        <table class="table" style="border: 2px solid red" cellpadding="0" cellspacing="0">
        <tr>
        <td>Driver Name</td><td class="data"><?php echo $db->getVal("select name from staff where idno='".$aryList['driver_name']."' "); ?></td>
               
        <td>Driver No</td><td class="data"><?php echo $aryList['driver_no']; ?> </td>
         
          <td>Conductor Name</td><td class="data"><?php echo $aryList['conductor_name']; ?> </td>
           <td>Conductor No</td><td class="data"><?php echo $aryList['conductor_no']; ?> </td>
        </tr> 
        <tr>
        	<td>Route</td><td class="data"><?php echo $db->getVal("select name from location where id='".$aryList['route']."' "); ?> </td>
           <td>Vehicle No</td><td class="data"><?php echo $aryList['vehicle_no']; ?> </td>
           <td>Vehicle Type</td><td class="data"><?php echo $aryList['vehicle_type']; ?> </td>
           <td>Incharge name</td><td class="data"><?php echo $aryList['incharge_name']; ?> </td>

        </tr>
         <tr>
           <td>Mileage</td><td class="data"><?php echo $aryList['mileage']; ?> </td>
           <td>K.M./day Type</td><td class="data"><?php echo $aryList['km_per_day']; ?> </td>
           <td>No of student</td><td class="data"><?php echo $aryList['no_of_stduent']; ?> </td>
           <td>Incharge No.</td><td class="data"><?php echo $aryList['incharge_no']; ?> </td>
        </tr>
        </table>
               	<table cellpadding="0" cellspacing="0" class="table" border="1" id="tblData">
			<thead>
			<tr>
            	<th width="1%">S.No</td>
				<th width="50%">Student Name</td>
				<th  width="50%">Father Name</th>
				<th width="2%">Contact no</th>
                <th width="2%">Short Add.</th>
				<th width="2%">Class</th>
			   <?php  
			  	for($i=1;$i<=31;$i++){
					?><th><?php echo $i ?></th><?php
				}
			   ?>
			</tr>
			</thead>
			<tbody>
				<?php $ij=0;
				foreach($aryStudentList as $fStudent){$ij++;
					?>
					<tr>
                    	<td><?php echo $ij; ?></td>
						<td><?php echo $fStudent["name"] ?></td>
						<td><?php echo $fStudent["fname"] ?></td>
						<td><?php echo $fStudent["mobile"] ?></td>
                        <td><?php echo $fStudent["mincome"] ?></td>
						<td><?php echo $fStudent["class"] ?></td>
						<?php
						   for($i=1;$i<=31;$i++){
					?><th><?php echo " "; ?></th><?php
				}
						 ?>
					</tr>
					<?php
				}
				?>
			</tbody>
			
		</table>

        Print date : <?php echo date("d-M-Y") ?>
		<?php
	}else{
		//echo $db->getErMsg().$db->getLastQuery();
	}
 }  }
 if(isset($_REQUEST['teacher_detail'])){
if(isset($_GET["old_school"]) && trim($_GET["old_school"])!=""){
	
	
	$aryStudentList=$db->getRows("select * from staff where medium='".$_GET["old_school"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 order by name");
	//echo $db->getLastQuery();exit;

	if(is_array($aryStudentList) && count($aryStudentList)>0){
		?>
		<h5><p style="float:right">Vechicle No : <?php echo $db->getVal("select name from bus_detail where id='".$_GET["old_school"]."' and school_id='".$_SESSION["admin"]["school_id"]."'");echo $db->getErMsg(); ?></p>	<p>Transport dues list Vechicle no Wise :</p></h5>
        <?php $aryList=$db->getRow("select * from bus_detail where id='".$_GET["old_school"]."' and school_id='".$_SESSION["admin"]["school_id"]."'")?>
        <button class="btn btn-danger" onclick="exportTableToExcel('tblData', 'Bus Teacher Report')" style="float:right;margin-top:10px;">Excel</button>
        <table class="table" style="border: 2px solid red" cellpadding="0" cellspacing="0">
        <tr>
        <td>Driver Name</td><td class="data"><?php echo $aryList['driver_name']; ?></td>
               
        <td>Driver No</td><td class="data"><?php echo $aryList['driver_no']; ?> </td>
         
          <td>Conductor Name</td><td class="data"><?php echo $aryList['conductor_name']; ?> </td>
           <td>Conductor No</td><td class="data"><?php echo $aryList['conductor_no']; ?> </td>
        </tr>
        <tr>
        	<td>Route</td><td class="data"><?php echo $aryList['root']; ?> </td>
           <td>Vehicle No</td><td class="data"><?php echo $aryList['vehicle_no']; ?> </td>
           <td>Vehicle Type</td><td class="data"><?php echo $aryList['vehicle_type']; ?> </td>
           <td>Vehicle Scholar No</td><td class="data"><?php echo $aryList['vehicle_sch_no']; ?> </td>
        </tr>
         <tr>
        	<td>Category</td><td class="data"><?php echo $aryList['category']; ?> </td>
           <td>Mileage</td><td class="data"><?php echo $aryList['miladge']; ?> </td>
           <td>K.M./day Type</td><td class="data"><?php echo $aryList['km_per_day']; ?> </td>
           <td>No of student</td><td class="data"><?php echo $aryList['no_of_stduent']; ?> </td>
        </tr>
        </table>
		<table cellpadding="0" cellspacing="0" class="table" border="1" id="tblData">
			<thead>
			<tr>
            	<th width="1%">S.No</td>
				<th >Teacher Name</td>
				<th >Father Name</th>
				<th >Contact no</th>
				<th >Address</th>
                		  
			</tr>
			</thead>
			<tbody>
				<?php $i=0;
				foreach($aryStudentList as $fStudent){$i++;$total=0;
					?>
					<tr>
                    	<td><?php echo $i; ?></td>
						<td><?php echo $fStudent["name"] ?></td>
						<td><?php echo $fStudent["fname"] ?></td>
						<td><?php echo $fStudent["mobile"] ?></td>
						<td><?php echo $fStudent["address"] ?></td>
					</tr>
					<?php } ?>
			</tbody>
			
		</table>

        Print date : <?php echo date("d-M-Y") ?>
		<?php
	}else{
		//echo $db->getErMsg().$db->getLastQuery();
	}
 }
}
elseif(isset($_REQUEST['bus_detail'])){ 
    
    $wherebus = "";
    if($_GET['old_school']!=''){
        $wherebus = " and id='$_GET[old_school]' ";
    }
    
 $aryList=$db->getRows("select * from bus_detail where school_id='".$_SESSION["admin"]["school_id"]."' $wherebus ")
  ?> <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>No. of boys</th>-->
                <!--<th>No. of girls</th>-->
                <!--<th>No. of Teacher</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");
				// 	$tlist=$db->getRows("Select * from staff where medium ='".$arr['id']."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1");
				// 	$tcount=0;
				// 	if(is_array($tlist)&& count($tlist)!=""){
				// 		foreach($tlist as $s){
				// 			$tcount++;
				// 			}
				// 		}
				// 		$tot_teacher+=$tcount;
					$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 $mcount; ?></td>-->
                        <!--<td><?php echo $fcount; ?></td>-->
                        <!--<td><?php echo $tcount; ?></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_boys; ?></td>-->
                    <!--<td><?php echo $tot_girls; ?></td>-->
                    <!--<td><?php echo $tot_teacher; ?></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 }else{
	echo "Please select date First";
}
//echo $db->getErMsg()
?>
</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>