<?php 
$pgMod="income";
$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="post" action="">.
    <div class="row-fluid">
        <div class="control-group">
          <div class="span3">
            	<select name="pmode">
                    <option value="all">All Bank</option>
                     <?php 
    					$Expensemode=$db->getRows("select * from bank where school_id='".$_SESSION["admin"]["school_id"]."' ");
					    foreach($Expensemode as $Expense){ 	?>
					  	<option value="<?php echo $Expense["id"] ?>" <?php if($_POST["pmode"]==$Expense["id"])echo "selected"; ?> ><?php echo $Expense["bank"] ?></option>
                    <?php } ?>
                    </select>
            </div>
            <div class="span3"><input required type="date" id="tfrom" name="tfrom" class="input-block-level" value="<?php if($_POST)echo $_POST["tfrom"];?>"></div>
            <div class="span3"> <input required type="date" id="tto" name="tto" class="input-block-level" value="<?php if($_POST)echo $_POST["tto"];?>"></div>
            <div class="span3"><input type="submit" class="btn" /></div>
        </div>
    </div>
</form>

<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', 'Complete Deposit')" style="margin-left:35px;">Excel</button>
        <a onclick="printDiv('printableDiv')" class="btn btn-primary" target="_blank">Print</a>
    </div>
</div>
<div class="well no-padding" id="printableDiv">
<?php
    $aryPgAct=array("src"=>"Account", "page_id"=>$pgMod,"action"=>"add");
    
    $between="";
    if(isset($_POST["tfrom"]) && isset($_POST["tto"])){
    $between=" and udate between '".$_POST["tfrom"]."' and '".$_POST["tto"]."' ";
    
    if($_POST["pmode"]=='all')
    {
    $aryList_ex=$db->getRows("SELECT * FROM banktransaction where school_id='".$_SESSION["admin"]["school_id"]."' and type='deposit' and status=1 and amount!=0 and session='".$_SESSION["admin"]["session"]."' $between ");
    }
    else
    {
    $aryList_ex=$db->getRows("SELECT * FROM banktransaction where school_id='".$_SESSION["admin"]["school_id"]."' and type='deposit' and status=1 and amount!=0 AND bankname='".$_POST["pmode"]."' and session='".$_SESSION["admin"]["session"]."' $between "); 
    }

?>

	<center><h5><p style="float:right"> Date: 
        			<?php if(strtotime($tndate)==strtotime($_POST["tfrom"])){echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
        			else echo date("d-M-Y",strtotime($_POST["tfrom"])) ." to ".date("d-M-Y",strtotime($tndate)); ?>
    			</p>
    			<p>Deposit Detail</p>	
			</h5>
	</center>

	<?php
	$i=0;
	if(is_array($aryList_ex) && count($aryList_ex)>0){
		$tndate = date('Y/m/d', strtotime('-1 days',strtotime($_POST["tto"])));
			?>

	<table class="table" id="tblData" border="1">
		<thead>
			<tr>
				<th>S. No.</th>
				<th>Depositor Name</th>
				<th>Detail</th>
                <th>Bank Name</th>
                <th>Mode</th>
				<th>Date</th>
				<th>Amount</th>
			</tr>
		</thead>
		<tbody>
		<?php foreach($aryList_ex as $clist){ $i++; 
		$aryPgAct["id"]=$clist['id'];
		$bankname = $db->getVal("select bank from bank where id='$clist[bankname]' ");
		
           if($clist['payment_mode'] == "Cheque/DD"){
		        $payment_mode = "$clist[payment_mode] - $clist[cheque_no]"; 
		    } else {
		        $payment_mode = "$clist[payment_mode]";
		    }
		?>
			<tr>
				<td><?php echo $i; ?></td>
				<td><?php echo $clist["name"]; ?></td>
				<td><?php echo $clist["detail"] ?></td>
				<td><?php echo $bankname; ?></td>
				<td><?php echo $payment_mode; ?></td>
				<td><?php echo $clist["udate"] ?></td>
				<td><?php echo number_format(($clist["amount"]),2); $total1+=$clist["amount"]; ?></td>
			</tr>
		<?php } ?>
		</tbody>
		<tfoot style="color:#F00">
			<tr>
				<td colspan="6">Total</td>
                <td><?php echo number_format($total1,2) ?></td>
               <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 </i>
	</div>
	<?php
}
}
?>
<br><br>
<center><span  style="font-size: 21px !important;  color:#F00;">Total: <?php echo number_format(($total1),2); ?></span></center>
<br>
</div>


</div>

</div>
<?php

?>
<style>
table.gridtable {
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}
table.gridtable th {
	border-width: 1px;
	padding: 3px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}
table.gridtable td {
	border-width: 1px;
	padding: 3px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}
</style>
<!-- Table goes in the document BODY -->

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