<?php
$pgMod="school_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">
                        <label class="control-label">From Date</label>
                        <div class="controls span4">
                            <input type="date" name="fdate" value="<?php if($_GET["fdate"]==""){echo date('Y-m-d');} else { echo $_GET['fdate']; } ?>" />
                        </div>
                    </div>

                    <div class="control-group span4">
                        <label class="control-label">To Date</label>
                        <div class="controls span4">
                            <input type="date" name="tdate"  value="<?php if($_GET["tdate"]==""){echo date("Y-m-d", strtotime("+1 day"));} else { echo $_GET['tdate']; } ?>" />
                        </div>
                    </div>

                    <div class="control-group span4">
                        <label class="control-label">Sales Person</label>
                        <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 style="width:100%;padding:20px;margin-top:50px;">

                        <button type="submit" name="date_wise_report" class="btn-classic margin">Date Wise Report</button>
                        <button type="submit" name="user_wise_report" class="btn-classic margin">User Wise Report</button>
                        <button type="submit" name="hot_cases" class="btn-classic margin">Hot Cases</button>
                        <button type="submit" name="active_cases" class="btn-classic margin">Active Cases</button>
                        <button type="submit" name="closed_cases" class="btn-classic margin">Closed Cases</button>

                        <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['date_wise_report'])){
    
	$where="";
	if(isset($_GET["id"]) && $_GET["id"]!=""){
	    $where=" id='".$_GET["id"]."' and ";
    }

	$aryStudentList=$db->getRows("select * from school_data where $where udate > '$_GET[fdate]' and udate<'$_GET[tdate]' ");

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

        <?php $aryList=$db->getRow("select * from school_data where udate > '$_GET[fdate]' and udate<'$_GET[tdate]' ")?>
        <!--<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>School Name</th>
    				<th>Email</th>
    				<th>Principal</th>
    				<th>Director</th>
    				<th>Address</th>
    				<th>Visit Date</th>
    				<th>Sales Person</th>
    				<th>Status</th>
    			    <th>Feedback</th>
    			</tr>
			</thead>
			<tbody>
				<?php
				foreach($aryStudentList as $fStudent){ $j++;
					?>
					<tr>
                    	<td><?php echo $j; ?></td>
						<td><?php echo $fStudent["school_name"] ?></td>
						<td><?php echo $fStudent["email"] ?></td>
                        <td><?php echo $fStudent["principal_contact"] ?></td>
                        <td><?php echo $fStudent["director_contact"] ?></td>
                        <td><?php echo $fStudent["address"] ?></td>
                        <td><?php echo $fStudent["visit_date"] ?></td>
                        <td><?php echo $db->getVal("select name from sales_person where id='$fStudent[id]' "); ?></td>
						<td><?php echo $fStudent["status"] ?></td>
						<td><?php echo $fStudent["feedback"] ?></td>
					</tr>
					<?php
				}
				?>
			</tbody>

		</table>

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

elseif(isset($_REQUEST['hot_cases'])){

	$aryStudentList=$db->getRows("select * from school_data where status='Hot' ");

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

        <?php $aryList=$db->getRow("select * from school_data where udate > '$_GET[fdate]' and udate<'$_GET[tdate]' ")?>
        <!--<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>School Name</th>
    				<th>Email</th>
    				<th>Principal</th>
    				<th>Director</th>
    				<th>Address</th>
    				<th>Visit Date</th>
    				<th>Sales Person</th>
    				<th>Status</th>
    			    <th>Feedback</th>
    			</tr>
			</thead>
			<tbody>
				<?php
				foreach($aryStudentList as $fStudent){ $j++;
					?>
					<tr>
                    	<td><?php echo $j; ?></td>
						<td><?php echo $fStudent["school_name"] ?></td>
						<td><?php echo $fStudent["email"] ?></td>
                        <td><?php echo $fStudent["principal_contact"] ?></td>
                        <td><?php echo $fStudent["director_contact"] ?></td>
                        <td><?php echo $fStudent["address"] ?></td>
                        <td><?php echo $fStudent["visit_date"] ?></td>
                        <td><?php echo $db->getVal("select name from sales_person where id='$fStudent[id]' "); ?></td>
						<td><?php echo $fStudent["status"] ?></td>
						<td><?php echo $fStudent["feedback"] ?></td>
					</tr>
					<?php
				}
				?>
			</tbody>

		</table>

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

elseif(isset($_REQUEST['active_cases'])){

	$aryStudentList=$db->getRows("select * from school_data where status='Active' ");

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

        <?php $aryList=$db->getRow("select * from school_data where udate > '$_GET[fdate]' and udate<'$_GET[tdate]' ")?>
        <!--<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>School Name</th>
    				<th>Email</th>
    				<th>Principal</th>
    				<th>Director</th>
    				<th>Address</th>
    				<th>Visit Date</th>
    				<th>Sales Person</th>
    				<th>Status</th>
    			    <th>Feedback</th>
    			</tr>
			</thead>
			<tbody>
				<?php
				foreach($aryStudentList as $fStudent){ $j++;
					?>
					<tr>
                    	<td><?php echo $j; ?></td>
						<td><?php echo $fStudent["school_name"] ?></td>
						<td><?php echo $fStudent["email"] ?></td>
                        <td><?php echo $fStudent["principal_contact"] ?></td>
                        <td><?php echo $fStudent["director_contact"] ?></td>
                        <td><?php echo $fStudent["address"] ?></td>
                        <td><?php echo $fStudent["visit_date"] ?></td>
                        <td><?php echo $db->getVal("select name from sales_person where id='$fStudent[id]' "); ?></td>
						<td><?php echo $fStudent["status"] ?></td>
						<td><?php echo $fStudent["feedback"] ?></td>
					</tr>
					<?php
				}
				?>
			</tbody>

		</table>

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

elseif(isset($_REQUEST['closed_cases'])){

	$aryStudentList=$db->getRows("select * from school_data where status='Closed' ");

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

        <?php $aryList=$db->getRow("select * from school_data where udate > '$_GET[fdate]' and udate<'$_GET[tdate]' ")?>

		<table cellpadding="0" cellspacing="0" class="table" border="1" id="tblData">
			<thead>
    			<tr>
                	<th>S.No</th>
    				<th>School Name</th>
    				<th>Email</th>
    				<th>Principal</th>
    				<th>Director</th>
    				<th>Address</th>
    				<th>Visit Date</th>
    				<th>Sales Person</th>
    				<th>Status</th>
    			    <th>Feedback</th>
    			</tr>
			</thead>
			<tbody>
				<?php
				foreach($aryStudentList as $fStudent){ $j++;
					?>
					<tr>
                    	<td><?php echo $j; ?></td>
						<td><?php echo $fStudent["school_name"] ?></td>
						<td><?php echo $fStudent["email"] ?></td>
                        <td><?php echo $fStudent["principal_contact"] ?></td>
                        <td><?php echo $fStudent["director_contact"] ?></td>
                        <td><?php echo $fStudent["address"] ?></td>
                        <td><?php echo $fStudent["visit_date"] ?></td>
                        <td><?php echo $db->getVal("select name from sales_person where id='$fStudent[id]' "); ?></td>
						<td><?php echo $fStudent["status"] ?></td>
						<td><?php echo $fStudent["feedback"] ?></td>
					</tr>
					<?php
				}
				?>
			</tbody>

		</table>

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

elseif(isset($_REQUEST['user_wise_report'])){

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

	$aryStudentList=$db->getRows("select * from school_data $where ");

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

        <?php $aryList=$db->getRow("select * from school_data where udate > '$_GET[fdate]' and udate<'$_GET[tdate]' ")?>
        <!--<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>School Name</th>
    				<th>Email</th>
    				<th>Principal</th>
    				<th>Director</th>
    				<th>Address</th>
    				<th>Visit Date</th>
    				<th>Sales Person</th>
    				<th>Status</th>
    			    <th>Feedback</th>
    			</tr>
			</thead>
			<tbody>
				<?php
				foreach($aryStudentList as $fStudent){ $j++;
					?>
					<tr>
                    	<td><?php echo $j; ?></td>
						<td><?php echo $fStudent["school_name"] ?></td>
						<td><?php echo $fStudent["email"] ?></td>
                        <td><?php echo $fStudent["principal_contact"] ?></td>
                        <td><?php echo $fStudent["director_contact"] ?></td>
                        <td><?php echo $fStudent["address"] ?></td>
                        <td><?php echo $fStudent["visit_date"] ?></td>
                        <td><?php echo $db->getVal("select name from sales_person where id='$fStudent[id]' "); ?></td>
						<td><?php echo $fStudent["status"] ?></td>
						<td><?php echo $fStudent["feedback"] ?></td>
					</tr>
					<?php
				}
				?>
			</tbody>

		</table>

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

?>
</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>