<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;} 
</style>
 <?php 
$pgMod="summery";
$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
}

?>
<div class="row-fluid"><div class="span12"><div class="top-bar">
<h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
<div style="float:right; margin-top:5px">
    <button class="btn btn-success" onclick="exportTableToExcel('tblData', 'Expenses Report')" style="margin-left:35px;">Excel</button>
                    <button type="button" onclick="printDiv('printableDiv')" class="btn btn-primary">Print</button>
                </div>
</div> 
<div class="well no-padding" id="printableDiv">
<?php
if(isset($_POST["tfrom"]) && isset($_POST["tto"])){
	
	$aryList=$db->getRows("SELECT * FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."' and status=1 and amount!=0 and session='".$_SESSION["admin"]["session"]."' and udate between '".$_POST["tfrom"]."' and '".$_POST["tto"]."' ");
	if($_POST["pmode"]=="income"){
		$aryList=$db->getRows("SELECT * FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."' and status=1 and rid=0 and session='".$_SESSION["admin"]["session"]."' and type ='deposit' and amount!=0 and udate between '".$_POST["tfrom"]."' and '".$_POST["tto"]."' ");
	}elseif($_POST["pmode"]=="expance"){
		$aryList=$db->getRows("SELECT * FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."' and status=1 and rid=0 and session='".$_SESSION["admin"]["session"]."' and type ='withdraw' and amount!=0 and udate between '".$_POST["tfrom"]."' and '".$_POST["tto"]."' ");
	}elseif($_POST["pmode"]!=""){
		$aryList=$db->getRows("SELECT * FROM transaction where school_id='".$_SESSION["admin"]["school_id"]."' and status=1 and rid=0 and session='".$_SESSION["admin"]["session"]."' and detail like '%".$_POST["pmode"]."%' and amount!=0 and udate between '".$_POST["tfrom"]."' and '".$_POST["tto"]."' ");
	}
	//echo $db->getLastQuery();
	 $i=0;$total=0;
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
	
		<table class="table" id="tblData" border="1">
			<thead>
				<tr>
					<th>Serial No</th>
					<th>Detail</th>
					<th>Date</th>
					<th>Expance</th>
					<th>Income</th>
					<th>Amount</th>
					<th>Balance</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["detail"] ?></td>
					<td><?php echo $clist["udate"] ?></td>
					<td><?php if($clist["type"]=='withdraw')echo $clist["tfor"]; ?></td>
					<td><?php if($clist["type"]=='deposit')echo $clist["tfor"]; ?></td>
					<td><?php echo $clist["amount"]; ?></td>
					<td><?php if($clist["type"]=='deposit')echo $total+=$clist["amount"];
					else if($clist["type"]=='withdraw')echo $total-=$clist["amount"]; ?></td>
				</tr>
			<?php } ?>
			</tbody>
			<tfoot>
				<tr>
					<th></th>
					<th></th>
                    <th></th>
					<th></th>
					<th></th>
					<th></th>
					<th></th>
				</tr>
			</tfoot>
		</table>
		<?php
	}
	else{
		?>
		<div class="alert alert-info">
		  <a class="close" data-dismiss="alert">×</a>
		  <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found <?php echo $db->getErMsg() ?></i>
		</div>
		<?php
	}
}else{
	?>
    <img src="./assets/img/search.png" style="float:right" />
    <form method="post" action="">
    <div class="span6">
		<div class="well no-padding">
            <div class="control-group">
                <label class="control-label" for="tfrom">Income/Expense </label>
                <div class="controls">
                    <select name="pmode">
                    <option value="">All Mode</option>
                    <option value="income">All Income</option>
                    <option value="expance">All Expance</option>
                    <?php 
					$incomemode=$db->getRows("select * from mode where school_id='".$_SESSION["admin"]["school_id"]."' and type='Income' and status=1");
					if(is_array($incomemode) && count($incomemode)>0){
					?>
                      <optgroup label="Income">
                      <?php foreach($incomemode as $Income){
					  	?><option><?php echo $Income["mode"] ?></option><?php
					  }?>
                      </optgroup>
                    <?php } ?>
                     <?php 
					$Expensemode=$db->getRows("select * from mode where school_id='".$_SESSION["admin"]["school_id"]."' and type='Expense' and status=1");
					if(is_array($Expensemode) && count($Expensemode)>0){
					?>
                      <optgroup label="Expense">
                      <?php foreach($Expensemode as $Expense){
					  	?><option><?php echo $Expense["mode"] ?></option><?php
					  }?>
                      </optgroup>
                    <?php } ?>
                    </select>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="tfrom">From</label>
                <div class="controls">
                    <input required type="date" id="tfrom" name="tfrom" class="input-block-level" value="<?php if($_POST)echo $_POST["tfrom"];?>">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="tfrom">To</label>
                <div class="controls">
                    <input required type="date" id="tto" name="tto" class="input-block-level" value="<?php if($_POST)echo $_POST["tto"];?>">
                </div>
            </div>
            <div class="control-group">
				<button type="submit" class="btn btn-primary"> Search</button>
     		</div>
        </div>
    </div>
    </form>
	<?php
}
?>
</div></div></div>
<?php

?>


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

<!-- / Forms -->