<script type="text/javascript" src="https://unpkg.com/xlsx@0.15.1/dist/xlsx.full.min.js"></script>
<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;
}
legend{line-height: 16px;font-weight:100;}

.outer .MigrateLeftFee{
  background-color: #DADADA !important;
  border: 5px solid #181616 !important;
  min-height: 440px;
  min-width:700px;
}
.st {
	width: 55px;
	font-size:10px;
	display: inline-block;
	color: #021EF0;
}
.size{
	font-size:12px;
}
.recepit {
	width: 717px !important;
	height: 344px !important;
}
.total{
	color: darkgreen;
    font-weight: 800;
}
</style>

<?php
$pgMod="enquiry_report";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);

if(isset($_SESSION['msg']) && $_SESSION['msg']!=""){
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0){
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}

	?>
    <form method="get" action="">
        <input type="hidden" name="src" value="Enquiry" />
    <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 span6">
                           <label class="control-label">Enquiry Status</label>
                            <div class="controls span6">
								<select class="span12" name="status">
                                	<option value="">All</option>
									<?php
										$location=$db->getRows("select * from remarks where school_id='".$_SESSION["admin"]["school_id"]."'");
										if(is_array($location) && count($location)>0){
											foreach($location as $loc){
												?>
												<option <?php if($loc["name"]==$aryForm["discount_mode"])echo 'selected';?> value="<?php echo $loc["name"] ?>">
													<?php echo $loc["name"] ?>
												</option>
												<?php
											}
										}
									?>
								</select>
                            </div>
                        </div>

                        <div class="control-group span6">
                            <button type="submit" name="search" class="btn-classic margin">Get Report</button>
                        </div>
                        </div>
                        	<div class="controls controls-row">
                        <div class="control-group span5">
                            <label class="control-label" for="class">From Date</label>
                            <div class="controls">
                                     <select class="span3" name="fdate"  id="date" style="width: 65px !important;">
                                    <option value="">Date</option>
                                    <?php
									$ndate=date("d");
									$mdate=date("m");
									$ydate=date("Y");
                                    for($m = 01;$m <= 31; $m++){ 
                                        $selected="";
										if($_GET["fdate"]==$m)
										{
											$selected=" selected ";
										}
										if($ndate==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                                <select class="span5" name="fmonth" id="fmonth" style="width: 90px !important;">
                                    <option value="">Month</option>
                                 <?php
                                    for($m = 1;$m <= 12; $m++){ 
                                        $newDate=date("Y")."-".$m."-1";
                                        $month =  date("F",strtotime($newDate));//."(".($ij+3).")";
                                        //$month =  date("F", mktime(0, 0, 0, $m)); 
                                        $selected="";if($_GET["fmonth"]==$m)
										{
											$selected=" selected ";
										}
										
										if($mdate==$m)
										{
											$selected=" selected ";
										}
											if(strlen($m)==1){
										    $m='0'.$m;
										}
                                        echo "<option $selected value='$m'>$month</option>";
                                    }
                                 ?> 
                                </select>
                                <select class="span4" name="fyear" id="fyear" style="width: 73px !important;">
                                    <option value="">Year</option>
                                    <?php
                                    for($m = 2013;$m <= 2050; $m++){  
                                        $selected="";if($_GET["fyear"]==$m)
										{	
										$selected=" selected ";
										}										
										if($ydate==$m)
										{	
										$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                                </div>
                        </div>
                        
                        <div class="control-group span5">
                            <label class="control-label" for="medium">To date</label>
                            <div class="controls">
                                    <select class="span3" name="tdate" id="tdate" style="width: 65px !important;">
                                    <option value="">Date</option>
                                    <?php
                                    for($m = 01;$m <= 31; $m++){ 
                                         $selected="";
										 if($_GET["tdate"]==$m)
										 {
											 $selected=" selected ";
										 }
										 if($ndate+1==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                                <select class="span5" name="tmonth" id="tmonth" style="width: 90px !important;">
                                    <option value="">Month</option>
                                 <?php
                                    for($m = 1;$m <= 12; $m++){ 
                                        $newDate=date("Y")."-".$m."-1";
                                        $month =  date("F",strtotime($newDate));//."(".($ij+3).")";
                                        //$month =  date("F", mktime(0, 0, 0, $m)); 
                                        $selected="";if($_GET["tmonth"]==$m)
										{
										$selected=" selected ";
										}
										if($mdate==$m)
										{
											$selected=" selected ";
										}
										if(strlen($m)==1){
										    $m='0'.$m;
										}
                                        echo "<option $selected value='$m'>$month</option>";
                                    }
                                 ?> 
                                </select>
                                <select class="span4" name="tyear" id="tyear" style="width: 73px !important;">
                                    <option value="">Year</option>
                                    <?php
                                    for($m = 2013;$m <= 2050; $m++){  
                                         $selected="";if($_GET["tyear"]==$m)
										 {	 
										 $selected=" selected ";
										 }
										 if($ydate==$m)
										{
											$selected=" selected ";
										}
                                        echo "<option $selected value='$m'>$m</option>";
                                    }
                                    ?> 
                                </select>
                                </div>
                        </div>

                        <div class="control-group span2">
                            <button type="submit" name="search_date" class="btn-classic margin">Search</button>
                            </div>
                        </div>

				</div>
			</div>
    </div>
    </form>
	<?php
	$where=array();
	$qry="";
	
	if(isset($_GET["search"])){

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

		$where[]=" session='".$_SESSION["admin"]["session"]."' and status=1 ";

		$result=$db->getRows("SELECT * FROM enquiry where school_id='".$_SESSION["admin"]["school_id"]."' and ".implode(" AND ",$where)." order by name");
		?>
		 <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Detail</h3>
                <div style="float:right; margin-top:5px">
                    <button class="btn btn-danger" onclick="ExportToExcel('xlsx')">Export Excel</button>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">

                <h4 style="position:absolute;padding-left:100px;padding-bottom:-50px;"><?php echo $_GET["status"]; ?> Report</h4>

            	<table class="table" id="tbl_exporttable_to_xls">
                    <thead>
                        <tr>
                            <th width="5%">S.No</th>
                            <th>Name</th>
                            <th style="width: 5%;">Class</th>
                            <th style="width: 7%;">Apply Class</th>
                            <th>Father</th> 
                            <th>Mother</th>                    
                            <th>Mobile</th>
                            <th>Address</th>
                            <!--<th>Test Date</th>-->
                            <!--<th>Test Time</th>-->
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $full_total=0;
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo ucfirst($detail["name"]); ?></td>
                                    <td><?php echo $detail["class"]; ?></td>
                                    <td><?php echo $detail["apply_class"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php echo $detail["mobile"]; ?></td>
                                    <td><?php echo $detail["address"]; ?></td>
                                    <!--<td><?php if($detail["test_date"]!="") echo date("d-m-Y",strtotime($detail["test_date"])); ?></td>-->
                                    <!--<td><?php if($detail["test_time"]!="") echo date("h:s a",strtotime($detail["test_time"])); ?></td>-->
                                </tr>
								<?php
							}?>
                           
				<?php }else{
							?><tr>
                            <td colspan="13">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<th colspan="13"></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	
	if(isset($_GET["search_date"])){
$wheres="";
		if(isset($_GET["status"]) && trim($_GET["status"])!=""){
			$where[]=" discount_mode='".$_GET["status"]."' ";
		}
			if(isset($_GET["fyear"]) && trim($_GET["fyear"])!="" && isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["fdate"]) && trim($_GET["fdate"])!="" && isset($_GET["tyear"]) && trim($_GET["tyear"])!="" && isset($_GET["tmonth"]) && trim($_GET["tmonth"])!="" && isset($_GET["tdate"]) && trim($_GET["tdate"])!=""){
			
			$fdate=$_GET["fyear"]."-".$_GET["fmonth"]."-".$_GET["fdate"];
			$tdate=$_GET["tyear"]."-".$_GET["tmonth"]."-".$_GET["tdate"];
				$wheres.=" (doa between '$fdate' and '$tdate') ";
		}
	

		$where[]=" session='".$_SESSION["admin"]["session"]."' and status=1 ";

		$result=$db->getRows("SELECT * FROM enquiry where school_id='".$_SESSION["admin"]["school_id"]."' and $wheres and ".implode(" AND ",$where)." order by name");
	//	print_r("SELECT * FROM enquiry where school_id='".$_SESSION["admin"]["school_id"]."' and $wheres and ".implode(" AND ",$where)." order by name");
		?>
		 <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Detail</h3>
                <div style="float:right; margin-top:5px">
                    <button class="btn btn-danger" onclick="ExportToExcel('xlsx')">Export Excel</button>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">

                <h4 style="position:absolute;padding-left:100px;padding-bottom:-50px;"><?php echo $_GET["status"]; ?> Report</h4>

            	<table class="table" id="tbl_exporttable_to_xls">
                    <thead>
                        <tr>
                            <th width="5%">S.No</th>
                            <th>Name</th>
                            <th style="width: 5%;">Class</th>
                            <th style="width: 7%;">Apply Class</th>
                            <th>Father</th> 
                            <th>Mother</th>                    
                            <th>Mobile</th>
                            <th>Address</th>
                            <th>Date</th>
                            <!--<th>Test Date</th>-->
                            <!--<th>Test Time</th>-->
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $full_total=0;
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo ucfirst($detail["name"]); ?></td>
                                    <td><?php echo $detail["class"]; ?></td>
                                    <td><?php echo $detail["apply_class"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php echo $detail["mobile"]; ?></td>
                                    <td><?php echo $detail["address"]; ?></td>
                                    <td><?php echo $detail["doa"]; ?></td>
                                    <!--<td><?php if($detail["test_date"]!="") echo date("d-m-Y",strtotime($detail["test_date"])); ?></td>-->
                                    <!--<td><?php if($detail["test_time"]!="") echo date("h:s a",strtotime($detail["test_time"])); ?></td>-->
                                </tr>
								<?php
							}?>
                           
				<?php }else{
							?><tr>
                            <td colspan="13">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<th colspan="13"></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}

?>

	<script type="text/javascript">
	$(document).ready(function(e) {
		var oTable = $('.table').dataTable( {
			"bPaginate": false,
			"bLengthChange": false,
			"bFilter": true,
			"bSort": true,
			"bInfo": true,
			"bAutoWidth": false
		});
	});
	function activeNowMe(id){
		$.ajax({
			url: "<?php echo URL_ROOT ?>Promote/ajax.php?type=activeMe&id="+id
		}).done(function(data) {
			$("#row"+id).hide("slow");
		});
	}
	function getStudentPopup(){
		var url="";
		$(".checkboxes").each(function(){
			if($(this).prop('checked')==true){
				var idno=$(this).val();
				var name=$(".name"+idno).html()
				var left=$(".left"+idno).html()
				url+="&"+name+"`"+idno+"="+left;
			}
		})
		if(url!=""){
			getPopup("<?php echo URL_ROOT ?>Promote/?page_id=MigrateLeftFee&class=<?php echo $_GET["class"] ?>"+url,"1","MigrateLeftFee");
			$(".close").click(function() {
				$(this).parent().remove();
			});
			$(".outer").click(function() {
				$(this).remove();
			});

		}else{
			alert("select atleast one student to mgrate");
		}
	}
	
    function ExportToExcel(type, fn, dl) {
        var elt = document.getElementById('tbl_exporttable_to_xls');
        var wb = XLSX.utils.table_to_book(elt, { sheet: "sheet1" });
        return dl ?
            XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }) :
            XLSX.writeFile(wb, fn || ('Pending FollowUp Report.' + (type || 'xlsx')));
    }
	</script>
    <style>
    tfoot{display: table-footer-group !important;}
	.MigrateLeftFee{width:650px !important}
    </style>