<style>
.st {
	width: 55px;
	display: inline-block;
	color: #021EF0;
}
.recepit {
	width: 717px !important;
	height: 344px !important;
}
.outer, .inner{ 
  max-height: 800px;
  min-height: 460px;
 }
 .outer .undefined{
  background-color: #DADADA !important;
  border: 5px inset #181616 !important;
  min-height: 440px;
  min-width:675px;
}
.half {
	width: 49%;
	display: inline-block;
	vertical-align: top;
	border-left: 4px solid #f00;
border-right: 5px solid #f00;
}
.half .input-block-level {
	width: 80px;
}
.half .table td {
	padding: 3px 5px;
}
.half center {
	font-weight: bold;
	border-top: 1px solid #f00;
	padding: 5px;
	background-color: #A7A1A1;
	color: #000;
}
</style>

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



if($pgAct=="viewall"){
	global $db,$LinksDetails;
	$pgTable = "student";
	$dataAry = array();
	$sqlArray = array();
	$i = 0;
	$table = "";
	$select = "";
	$where = "";
	$whereAry = array();
	
	$whereAry[] = " school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0";
	if (isset($_REQUEST["class"]) && $_REQUEST["class"] != "") {
		$whereAry[] = " class='".$_REQUEST["class"]."' ";
	}
	if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="" && $_REQUEST["section"]!="undefined"){
		$whereAry[] = " section='".$_REQUEST["section"]."' ";
	}
	if (isset($_REQUEST["q"]) && $_REQUEST["q"] != "") {
		$whereAry[] = " (admissionno like '%".$_REQUEST["q"]."%'
					OR name like '%".$_REQUEST["q"]."%'
					OR class like '%".$_REQUEST["q"]."%'
					OR section like '%".$_REQUEST["q"]."%'
					OR medium like '%".$_REQUEST["q"]."%'
					OR cast like '%".$_REQUEST["q"]."%'
					OR fname like '%".$_REQUEST["q"]."%'
					OR mobile like '%".$_REQUEST["q"]."%') ";
	}
	
	if (is_array($whereAry) && count($whereAry) > 0)
		$where = " WHERE " . implode(" AND ", $whereAry);
		
	$pcount = $db->getVal("select count(admissionno) from  student $where");

	$startV = $_REQUEST['startV'];
	$endV = $_REQUEST['endV'];
	$ProDetail["totPost"] = $pcount;

	$contentDetail = $db->getRows("select * from student $where order by name DESC " . ($endV == 'All' ? "" : "limit $startV, $endV"));
	$ProDetail["query"] = $db->getLastQuery();
	$ProDetail["ncount"] = count($contentDetail);
	$ProDetail["tcolumn"] = 9;
	if (is_array($contentDetail) && count($contentDetail) > 0) {
		$aryData = array();
		$i = 0;
		foreach ($contentDetail as $iList) {
			$button = "";
			$aryPgAct["id"] = $iList['id'];
			$aryPgAct["page_id"] = $pgMod;
			$image="<img src='".URL_ROOT."uploads/product/50/50/".$iList['front_image']."' width='50'  />";
			$button = "";
			$aryPgAct["action"] = "print";
			$button .= '<a href=\''.URL_ROOT.'print/?page_id=admission_print&id='.$iList['idno'].'\'  target=\'_blank\' data-class=\'idcard\'><button type=\'button\' class=\'btn btn-danger\'>Print</button></a> ';
			$aryPgAct["action"] = "edit";
			$button .= '<a href=\''.URL_ADMIN_HOME.getQueryString($aryPgAct).'&id='.$iList['idno'].'\'><button type=\'button\' class=\'btn btn-info\'>Edit</button></a>';
			$aryPgAct["action"] = "delete";
			$button .= '<a href="javascript:;" onclick="del(\''.URL_ADMIN_HOME.getQueryString($aryPgAct).'&id='.$iList['idno'].'\')" class="confirmation"><button type="button" class="btn btn-danger">Delete</button></a>';
			$i++;
			//$aryPgAct["action"] = "submenu";
			$aryData[] = array(
				POST($iList['admissionno']),
				POST($iList['name']),
				POST($iList['class'])."(".POST($iList['section']).")",
				POST($iList['medium']),
				POST($db->getVal("select root from bus where id=".$iList["bus"])),
				POST($iList["cast"]),
				POST($iList['fname']),
				POST($iList['mobile']),
				$button,
			);
		}
		$ProDetail["Result"] = $aryData;
	}
	echo json_encode($ProDetail);
	exit;
}


elseif($_POST)
{
	$_SESSION['form']=$_POST;
	$flgEr=FALSE;
	if(!isset($_POST['mode']) || trim($_POST['mode'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter Income mode.");
	}elseif(!isset($_POST['detail']) || trim($_POST['detail'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter Detail.");
	}elseif(!isset($_POST['amount']) || trim($_POST['amount'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter Amount.");
	}
	/*elseif(!isset($_POST['pmode']) || trim($_POST['pmode'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter Payment mode.");
	}*/
	
	/*if($flgEr!=TRUE && $pgAct=="add")
	{
		$detail=$_POST["detail"]." ".$_POST["mode"];
		if($_POST["chque"]!="")$detail.="<hr/>Cheque No:".$_POST["chque"];
		if($_POST["chque"]!="")$detail.="<br/>Bank Name:".$_POST["bankname"];
		$data = array(	
					 'rid'=>0,
					 'tid'=>0,
					 'tfor'=>$_POST["mode"],
					 'type'=>"withdraw",
					 'amount'=>$_POST["amount"],
					 'status'=>"1",
					'session'=>$_SESSION["admin"]["session"],
					 'udate'=>$_POST["idate"],
					 "school_id"=>$_SESSION["admin"]["school_id"],"added_by"=>$_SESSION["admin"]["uid"],
					 'detail'=>$detail);
				
				
		$flgIn = $db->insertAry(TRANSACTION,$data);
		 //$id=print_r(mysql_insert_id()); ?>
		
		
		
		 <a href="javascript:;" onclick="checkRecept('<?php print_r(mysql_insert_id()) ?>')" class="btn btn-danger">Recepit</a>
		<?php
		if(!is_null($flgIn))
		{
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			sms($LinksDetails["DirectorNumber"],"Expense Amount of Rs. ".$_POST["amount"]." from ".$_POST["mode"]."(".$_POST['detail'].") is withdrawn ","Income_Expense");
			//redirect(URL_ADMIN_HOME.getQueryString(array("page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
			
		}
	}*/
/*elseif($flgEr!=TRUE && $pgAct=="edit")
	{
		
	$detail=$_POST["detail"]." ".$_POST["mode"];
	$data = array(	
					 'tfor'=>$_POST["mode"],
					 
					 'amount'=>$_POST["amount"],
					 
					 'udate'=>$_POST["idate"],
				
					 'detail'=>$detail);
	foreach($data as $key => $val)
	{
		$fields.=$key."='".$val."',";
	}				
	$fields = substr($fields,0,strlen($fields)-1);			 

$q = mysql_query("update TRANSACTION set $fields where id='".$_GET['id']."'")or die("Update Error.".mysql_error());
$_SESSION['msg']='Updated Successfully'; ?>
 <a href="javascript:;" onclick="checkRecept('<?php print_r($_GET[id]) ?>')" class="btn btn-danger">Recepit</a>

	<?php
	}*/
}
if($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
	$res=$db->delete(TRANSECTION,"where school_id='".$_SESSION["admin"]["school_id"]."' and id='".$_GET['id']."'");
	
	if(!is_null($res)) { $_SESSION['msg']='Deleted Successfully'; }
	else { array_push($alert_err,$db->getErMsg()); }
	redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Account", "page_id"=>$pgMod)));
} 
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
}
if($pgAct=="edit" && $_GET["id"]!="")
{   
	$aryForm=$db->getRow("SELECT * FROM ".TRANSECTION." WHERE school_id='".$_SESSION["admin"]["school_id"]."' and id='".$_GET['id']."'");
	
	
}
if($pgAct=="add" || ($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''))
{
?>
<!-- Forms --> 
	<div class="row-fluid">
        <form method="post" action="">
			<!-- Forms: Box -->
			<div class="span12">

				<!-- Forms: Top Bar -->
				<div class="top-bar">
					<h3><i class="icon-cog"></i> <?php echo ucwords($pgAct); ?> Expance Transection</h3>
					
					<button style="float:right; margin-top:5px" onclick="window.location='./?src=Account&page_id=<?php echo $pgMod; ?>&action=add'" class="btn" type="button">Add <?php echo $pgMod; ?></button>
				</div>
				<!-- / Forms: Top Bar -->

				<!-- Forms: Content -->
				<div class="well no-padding">

						<div class="control-group">
							<label class="control-label" for="mode">Expance mode</label>
							<div class="controls">
								<select name="mode" class="span12" id="class">
                                    <option value=""><?php if($_POST)echo $_POST["mode"];elseif(!empty($aryForm["tfor"])) echo $aryForm["tfor"]; else echo 'mode'; ?></option>
                                    <?php 
                                        $class=$db->getRows("select * from mode where school_id='".$_SESSION["admin"]["school_id"]."' and type='Expense'");
                                        foreach($class as $cla){
                                            ?>
                                            <option <?php if($cla["mode"]==$aryForm["tfor"])echo 'selected';?> value="<?php echo $cla["mode"] ?>">
                                                <?php echo $cla["mode"] ?>
                                            </option>
                                            <?php
                                        }
                                    ?>
                                </select>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="detail">Expance Detail</label>
							<div class="controls">
								<textarea type="text" id="detail" name="detail" class="input-block-level"><?php if($_POST)echo $_POST["detail"];else echo $aryForm["detail"] ?></textarea>
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="idate">Expance Date</label>
							<div class="controls">
								<input type="text" id="idate" name="idate" class="input-block-level datepicker" value="<?php if($_POST)echo $_POST["idate"]; elseif (!empty($aryForm["udate"])) echo $aryForm["udate"]; else echo date('Y-m-d H:i:s'); ?>">
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="amount">Expance Amount</label>
							<div class="controls">
								<input type="text" id="amount" name="amount" class="input-block-level" value="<?php if($_POST)echo $_POST["amount"];else echo $aryForm["amount"] ?>">
							</div>
						</div>
                        <div class="control-group">
                            <label class="control-label" for="netsalery">Pay Type</label>
                            <div class="controls">
                                    <label class="radio"><span><input onchange="hide_underof('1')" <?php if($pgAct=="add"){echo 'checked="checked"';}elseif($aryForm["tfor"]=="cash")echo 'checked="checked"';?> type="radio" name="pmode" value="cash"></span> Cash</label>
                                    <label class="radio"><span><input onchange="hide_underof('2')" <?php if($aryForm["tfor"]=="cheque")echo 'checked="checked"';?> type="radio" name="pmode" value="cheque" ></span> Cheque/DD</label> 
                            </div>
                        </div>
                        <div id="paymode" <?php if($pgAct=="add"){ echo 'style="display:none"';}elseif($aryForm["tfor"]=="cash"){echo 'style="display:none"';} ?>>
                            <div class="control-group">
                                <label class="control-label" for="chque">Cheque/DD No</label>
                                <div class="controls">
                                        <input type="text" id="chque" name="chque" class="input-block-level" value="<?php  echo $salDetail["cheque"];?>" > 
                                </div>
                            </div>
                             <div class="control-group">
                                <label class="control-label" for="bankname">Bank Name</label>
                                <div class="controls">
                                        <input type="text" id="bankname" name="bankname" class="input-block-level" value="<?php  echo $salDetail["bankname"];?>" > 
                                </div>
                            </div>
                        </div>
						<div class="form-actions">
					
							
						<?php if(empty($_POST)){?>
							<button type="submit" class="btn btn-primary"> Save</button>
							
							<button type="button" class="btn"> Cancel</button>
						<?php } ?>
<?php if($_POST){							if($flgEr!=TRUE && $pgAct=="add")
	{
		$detail=$_POST["detail"];
		if($_POST["chque"]!="")$detail.="<hr/>Cheque No:".$_POST["chque"];
		if($_POST["chque"]!="")$detail.="<br/>Bank Name:".$_POST["bankname"];
		$val=$db->getVal("select max(exp_id) from transaction where type='mode_income' ");	
		$exp_val=$val+1;
		$data = array(	
					 'rid'=>0,
					 'tid'=>0,
					 'exp_id'=>$exp_val,
					 'tfor'=>$_POST["mode"],
					 'type'=>"mode_income",
					 'amount'=>$_POST["amount"],
					 'status'=>"1",
					'session'=>$_SESSION["admin"]["session"],
					 'udate'=>$_POST["idate"],
					 "school_id"=>$_SESSION["admin"]["school_id"],"added_by"=>$_SESSION["admin"]["uid"],
					 'detail'=>$detail);
					 
					 
		
		
				
		$flgIn = $db->insertAry(transaction,$data);
		 //$id=print_r(mysql_insert_id()); ?>
		
		
		
		 <a href="javascript:;" onclick="checkRecept('<?php print_r($flgIn) ?>')" class="btn btn-danger">Receipt</a>
		 
		 <!--<a href="#" onClick="myfun()" class="btn btn-danger">new test</a>-->
		 
		<?php
		if(!is_null($flgIn))
		{
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			sms($LinksDetails["DirectorNumber"],"Expense Amount of Rs. ".$_POST["amount"]." from ".$_POST["mode"]."(".$_POST['detail'].") is withdrawn ","Income_Expense");
			//redirect(URL_ADMIN_HOME.getQueryString(array("page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
			
		}
	}
	
	
	elseif($flgEr!=TRUE && $pgAct=="edit")
	{
		
	$detail=$_POST["detail"]." ".$_POST["mode"];
	$data = array(	
					 'tfor'=>$_POST["mode"],
					 
					 'amount'=>$_POST["amount"],
					 
					 'udate'=>$_POST["idate"],
				
					 'detail'=>$detail);
	foreach($data as $key => $val)
	{
		$fields.=$key."='".$val."',";
	}				
	$fields = substr($fields,0,strlen($fields)-1);			 

$q = mysql_query("update transaction set $fields where id='".$_GET['id']."'")or die("Update Error.".mysql_error());
$_SESSION['msg']='Updated Successfully'; ?>
 <a href="javascript:;" onclick="checkRecept('<?php print_r($_GET[id]) ?>')" class="btn btn-danger">Recepit</a>

	<?php
	}
	
}?>
							
						</div>
                        
				</div>
				<!-- / Forms: Content -->

			</div>
			<!-- / Forms: Box -->

        </form>
		

	</div>
<!-- / Forms -->
<?php
}else{
	?>
	<div class="row-fluid"><div class="span12"><div class="top-bar">
    <h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
    <button style="float:right; margin-top:5px" onclick="window.location='./?src=Account&page_id=<?php echo $pgMod; ?>&action=add'" class="btn" type="button">Add <?php echo $pgMod; ?></button>
    </div>
    <div class="well no-padding">
	<?php
	$aryPgAct=array("src"=>"Account", "page_id"=>$pgMod,"action"=>"add");
	$aryList=$db->getRows("SELECT * FROM ".TRANSECTION." where type='mode_income' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'"); $i=0;
	//echo $db->getLastQuery();
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <input type="hidden" id="tabletype" value="modeincome_data" />
       <table class="table" id="ajaxtable">
            <thead>
                <tr>
                    <th>Type</th>
                    <th>Amount</th>
                    <th>mode</th>
                    <th>Date</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tfoot>
            </tfoot>
            <tbody>
            </tbody>
            
        </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
	}
	?>
	</div></div></div>
	<?php
}
?>
<script>
$(document).ready(function(e) {
    var oTable = $('#ajaxtable').dataTable( {
		"bProcessing": true,
		'sPaginationType': 'full_numbers',
		"sAjaxSource": 'Account/ajax.php?type='+$('#tabletype').val(),
		'iDisplayLength': 5,
		"oLanguage": {
			"sSearch": "Search by any columns:"
		}
	});
});
function fetchByClass(id){
	var name=id.value;
	if(name!=""){
		 oTable = $('#ajaxtable').dataTable( {
			"bProcessing": true,
			'sPaginationType': 'full_numbers',
			"bServerSide": false,
			"bDestroy":true,
			"sAjaxSource": 'Account/ajax.php?class='+name+'&type='+$('#tabletype').val(),
			'iDisplayLength': 5,
			"oLanguage": {
				"sSearch": "Search by any columns:"
			}
		});
	}else{
		var oTable = $('#ajaxtable').dataTable( {
			"bProcessing": true,
			'sPaginationType': 'full_numbers',
			"bServerSide": false,
			"bDestroy":true,
			"sAjaxSource": 'ajax.php?type='+$('#tabletype').val(),
			'iDisplayLength': 5,
			"oLanguage": {
				"sSearch": "Search by any columns:"
			}
		});
	}
}
function hide_underof(valu)
{
	if(valu=='1'){
		$('#paymode').hide('slow');
		$("#chque").val('');$("#backname").val('');
	}else 
	if(valu=='2'){
		$('#paymode').show('slow');
	}
}
$(function() {
	$(".datepicker").each(function(index, element) {
        var d = new Date(); // for now
		datetext=d.getHours()+": "+d.getMinutes()+": "+d.getSeconds();
		$( this ).datepicker({
		  changeMonth: true,
		  changeYear: true,
		  showOn: "button",
		  buttonImage: "js/images/calendar.gif",
		  buttonImageOnly: true,
		  buttonText: "Select date",
		  dateFormat: 'yy-mm-dd ',
		  onSelect: function(datetext){
			var d = new Date(); // for now
			datetext=datetext+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
			$(this).val(datetext);
		  }
		});
    });
});

function checkRecept(id){
	
	getPopup("<?php echo URL_ROOT ?>print/?page_id=exp_receipt&id="+id);
	$(".close").click(function() {
		$(this).parent().remove();
	});
	$(".outer").click(function() {
		$(this).remove();
	});
}

function myfun(){
    alert('hello');   
}

</script>