<script type="text/javascript" src="js/tableExport.js"></script>

<script type="text/javascript" src="js/jquery.base64.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>
<input type="hidden" name="tog" id="togglevalueforzeoshow" value="0" />
<script>


function checkAll(){
	if($('#checkboxa').prop('checked')) {
		$('.checkboxes').prop('checked', true);
		 
    } else {
		
        $('.checkboxes').prop('checked', false);
    }
	
	//var chk=$('input[name=cat]:checked').length;
	
	//alert(chk);
	
}
function  sendAll(){
	checked = $('input[name=sid]:checked');
        if( checked.length > 0 ) {
            var checkValues = checked.map(function(){
               return $(this).val();
            }).get();
			//alert(checkValues);
			//confirm();
			var chk=checkValues.toString();
			$.post( "?page_id=sms&type=student", { type: "POST" ,chk: chk} , function( data ) {
	  
				window.location.href = './?page_id=sms&type=student&chk='+chk+'';
		});
          /*$.ajax({
                type: "POST",
				 url: "http://127.0.0.1/sms/?page_id=sms&type=student",
                data: { ids: checkValues },
                success:function(data){
						window.location.href = '?page_id=sms&type=student';
					 },
            });*/
        }else{
             alert("You need to pick at least one checkbox!");
        }
	//var date=$("#date").val();
	//$.post( "ajax.php", { type: "DATE_SEARCH" ,date: date } , function( data ) {
	//  	$("#date_content").html(data);
	//	getTotal();
	//});
}

function SMSComplete(valueid,act){
	$(this).hide();
	var Fee=$("#"+valueid).html();
	var fdate='<?php if($_GET["fdate"]!="")echo $_GET["fdate"];else echo "0" ?>';
	var fmonth='<?php if($_GET["fmonth"]!="")echo $_GET["fmonth"];else echo "0" ?>';
	var fyear='<?php if($_GET["fyear"]!="")echo $_GET["fyear"];else echo "0" ?>';
	var tdate='<?php if($_GET["tdate"]!="")echo $_GET["tdate"];else echo "0" ?>';
	var tmonth='<?php if($_GET["tmonth"]!="")echo $_GET["tmonth"];else echo "0" ?>';
	var tyear='<?php if($_GET["tyear"]!="")echo $_GET["tyear"];else echo "0" ?>';
	var cls='<?php if($_GET["class"]!="")echo $_GET["class"];else echo "0" ?>';
	$.post( "ajax.php", { type: act ,fee: Fee, fdate:fdate, fmonth:fmonth, fyear:fyear, tdate:tdate, tmonth:tmonth, tyear:tyear,class: cls  } , function( data ) {
	  	//$("#ins").html(data);getTotal();
		alert(data);
		$(this).show();
	});
}
function SMS(type){
	if(confirm('Do you want to send sms now..!')){
	//var ids=document.getElementsByName('mobile[]');
	
	var ids=document.getElementsByName('idno[]');
	var detail=document.getElementsByName('details[]');
	var arr = [];
	for(var i=0;i<ids.length;i++){
		arr.push(ids[i].value+"-"+detail[i].value);
	}
	var Fee=arr.join(",");
	var fdate='<?php if($_GET["fdate"]!="")echo $_GET["fdate"];else echo "0" ?>';
	var fmonth='<?php if($_GET["fmonth"]!="")echo $_GET["fmonth"];else echo "0" ?>';
	var fyear='<?php if($_GET["fyear"]!="")echo $_GET["fyear"];else echo "0" ?>';
	var tdate='<?php if($_GET["tdate"]!="")echo $_GET["tdate"];else echo "0" ?>';
	var tmonth='<?php if($_GET["tmonth"]!="")echo $_GET["tmonth"];else echo "0" ?>';
	var tyear='<?php if($_GET["tyear"]!="")echo $_GET["tyear"];else echo "0" ?>';
	var cls='<?php if($_GET["class"]!="")echo $_GET["class"];else echo "0" ?>';
	$.post( "ajax.php", { type: type ,fee: Fee, fdate:fdate, fmonth:fmonth, fyear:fyear, tdate:tdate, tmonth:tmonth, tyear:tyear,class: cls  } , function( data ) {
		alert(data);
	});
}}
function sendSMDTO(){
	//alert("sms sending process under constration...");
}

function filterPayleft(Tval){
	var val=$(Tval).val();
	if(val.trim()==""){
		$(".MyTotalFee").parent().show();
		$(".MyTotalFee").parent().addClass('none');
	}
	else
	if(!isNaN(val)){
		var allTot="";
		$(".MyTotalLeft").each(function(index, element) {
			var myVal=parseInt($(this).html());
			if(myVal>val)
			{
				$(this).parent().hide('slow');
				$(this).parent().removeClass('none');
			}
			else
			{
				$(this).parent().show('slow');
				$(this).parent().addClass('none');
			}
        });
		//alert(allTot);
	}else{
		alert("Please enter only number");
		$(Tval).val('');
		$(".MyTotalFee").parent().show('slow');
		$(".MyTotalFee").parent().addClass('none');
	}
	var MyTotalFee=0,MyTotalpaid=0,MyTotalLeft=0,MyDiscount=0;
	$(".none").each(function(index, element) {
		MyTotalFee+=parseInt($(this).children('.MyTotalFee').html());
		MyTotalpaid+=parseInt($(this).children('.MyTotalpaid').html());
		MyTotalLeft+=parseInt($(this).children('.MyTotalLeft').html());
		MyDiscount+=parseInt($(this).children('.MyDiscount').html());
	});
	$("#MyTotalFee").html(MyTotalFee);
	$("#MyTotalpaid").html(MyTotalpaid);
	$("#MyTotalLeft").html(MyTotalLeft);
	$("#MyDiscount").html(MyDiscount);
}

function filterPay(Tval){
	var val=$(Tval).val();
	if(val.trim()==""){
		$(".MyTotalFee").parent().show('slow');
		$(".MyTotalFee").parent().addClass('none');
		$(".dynamic").hide('slow');
	}
	else
	if(!isNaN(val)){
		$(".dynamic").show('slow');
		var allTot="";
		$(".MyTotalpaid").each(function(index, element) {
			var myVal=parseInt($(this).html());
			if(myVal>val)
			{
				$(this).parent().hide('slow');
				$(this).parent().removeClass('none');
			}
			else
			{
				$(this).parent().show('slow');
				$(this).parent().addClass('none');
			}
        });
		//alert(allTot);
	}
	else{
		alert("Please user only number");
		$(Tval).val('');
		$(".MyTotalFee").parent().show();
		$(".MyTotalFee").parent().addClass('none');
		$(".dynamic").hide();
	}
	var MyTotalFee=0,MyTotalpaid=0,MyTotalLeft=0,MyDiscount=0,MyTotalLeftDynamic=0;
	$(".none").each(function(index, element) {
		var totalleft=val-parseInt($(this).children('.MyTotalpaid').html());
		$(this).children('.MyTotalLeftDynamic').html(totalleft);
		MyTotalFee+=parseInt($(this).children('.MyTotalFee').html());
		MyTotalpaid+=parseInt($(this).children('.MyTotalpaid').html());
		MyTotalLeftDynamic+=parseInt($(this).children('.MyTotalLeftDynamic').html());
		MyTotalLeft+=parseInt($(this).children('.MyTotalLeft').html());
		MyDiscount+=parseInt($(this).children('.MyDiscount').html());
	});
	$("#MyTotalFee").html(MyTotalFee);
	$("#MyTotalpaid").html(MyTotalpaid);
	$("#MyTotalLeftDynamic").html(MyTotalLeftDynamic);
	$("#MyTotalLeft").html(MyTotalLeft);
	$("#MyDiscount").html(MyDiscount);
}
$(document).ready(function(e) {
	$("#btnduesend").click(function () {
		var ch=$("#togglevalueforzeoshow").val();
		if(ch==0){
			$("#togglevalueforzeoshow").val('1');
	   		filterLeftZero(0)
		}else{
			$("#togglevalueforzeoshow").val('0');
			filterLeftZero(1)
		}
	 });
});
function filterLeftZero(ids){
	var allTot="";
	$(".MyTotalLeft").each(function(index, element) {
		var myVal=parseInt($(this).html());
		if(myVal==0 && ids==0)
		{
			$(this).parent().hide('slow');
			$(this).parent().removeClass('none');
		}
		else
		{
			$(this).parent().show('slow');
			$(this).parent().addClass('none');
		}
	});
	//alert(allTot);
	
	var MyTotalFee=0,MyTotalpaid=0,MyTotalLeft=0,MyDiscount=0;
	$(".none").each(function(index, element) {
		MyTotalFee+=parseInt($(this).children('.MyTotalFee').html());
		MyTotalpaid+=parseInt($(this).children('.MyTotalpaid').html());
		MyTotalLeft+=parseInt($(this).children('.MyTotalLeft').html());
		MyDiscount+=parseInt($(this).children('.MyDiscount').html());
	});
	$("#MyTotalFee").html(MyTotalFee);
	$("#MyTotalpaid").html(MyTotalpaid);
	$("#MyTotalLeft").html(MyTotalLeft);
	$("#MyDiscount").html(MyDiscount);
}
</script>
<?php
$pgMod="fee_summery";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);
if($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
	$res=$db->delete("student","where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_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
}
function inst($str){
	$arr1 = str_split($str);
	if($arr1[1]=="p"){
		$i="Fee ";
		if($arr1[0]=="b")$i="Bus ";
		return $i." "." Installment ".$arr1[2];
	}
	else
		return $str;
}
function instFine($str,$reasion=""){
	global $db;
	$arr1 = explode("-",$str);
	if($arr1[1]=="class")
		$i="<span style='color:#FF0000'>$reasion (Class Fine)</span>";
	elseif($arr1[1]=="bus")
		$i="<span style='color:#00CC00'>$reasion (Bus Fine)</span>";
	elseif($arr1[1]=="otherfee")
		$i="<span style='color:#660000'>$reasion (Other Fee)</span>";
	elseif($arr1[1]=="hostel")
		$i="<span style='color:#FF00FF'>$reasion (Hostel Fine)</span>";
	else{
		$det=$db->getVal("select type from extrafee_type where id='".str_replace("extra","",$arr1[1])."'");
		if($det=="")
		$i="<span style='color:#660000'>$reasion (".$arr1[1].")</span>";
		else
		$i="<span style='color:#660000'>$reasion (".$det.")</span>";
	}
	//if($reasion!="")$i.=" ".$reasion."";
	return $i.$db->getErMsg();;
}
	?>
    <form method="get" action="">
    <input type="hidden" name="src" value="Account" />
    <input type="hidden" name="page_id" value="<?php echo $pgMod; ?>" />
	<div class="row-fluid">
            <div class="span12">
            	<div class="top-bar">
                    <br />
      <!--              <fieldset style="width:48%; float:right"><legend>Outstanding Section</legend>-->
						<!--<button type="submit" name="outstanding" class="btn-classic margin">OverAll Due</button>-->
						<!--<button type="submit" name="outstanding_wt_class" class="btn-classic margin">OverAll Due wt_class </button>-->
      <!--                  <button type="submit" name="bus_outstanding" class="btn-classic margin"> Bus Outstanding</button>-->
      <!--                  <button type="submit" name="school_outstanding" class="btn-classic margin"> School Outstanding</button>-->
      <!--                  <button type="submit" name="hostel_outstanding" class="btn-classic margin"> Hostel Outstanding</button> -->
      <!--              </fieldset>  -->
      <!--              <fieldset style="width:48%; float:left"><legend>Detail Section</legend>-->
						<!--<button type="submit" name="detail" class="btn-classic margin"> Personal Detail</button>-->
      <!--                  <button type="submit" name="canceldetail" class="btn-classic margin"> Cancel Student</button>-->
      <!--                  <button type="submit" name="bus_detail" class="btn-classic margin"> Bus Detail</button>-->
      <!--                  <button type="submit" name="hostel_detail" class="btn-classic margin"> Hostel Detail</button>-->
      <!--                  <button type="submit" name="is_bpl" class="btn-classic margin"> BPL</button>-->
      <!--                   <button type="submit" name="sibling" class="btn-classic margin"> Sibling Detail</button>-->
      <!--                   <button type="submit" name="getpass" class="btn-classic margin"> Gate Pass Detail</button>-->
      <!--              </fieldset>-->
      <!--              <fieldset style="width:48%; float:right"><legend>Fee Section</legend>-->
      <!--                  <button type="submit" name="fee" class="btn-classic margin"> Complete Fee</button>-->
      <!--                  <button type="submit" name="school_fee" class="btn-classic margin"> School fee</button>-->
      <!--                  <button type="submit" name="bus_fee" class="btn-classic margin"> Bus fee</button>-->
      <!--                  <button type="submit" name="hostel_fee" class="btn-classic margin"> Hostel fee</button>-->
      <!--                  <button type="submit" name="combine_fee" class="btn-classic margin"> Combine Fee</button>-->
      <!--                  <button type="submit" name="other_fix_fee" class="btn-classic margin"> Other Separate fee</button>-->
      <!--                  <button type="submit" name="delete_report" class="btn-classic margin">Delete report</button>-->
      <!--                  <button type="submit" name="pocket_delete_report" class="btn-classic margin">Pocket Delete report</button>-->
      <!--              </fieldset>-->
      <!--              <fieldset style="width:48%; float:left"><legend>Fine Section</legend>-->
      <!--                  <button type="submit" name="school_fine" class="btn-classic margin"> School fine</button>-->
      <!--                  <button type="submit" name="bus_fine" class="btn-classic margin"> Bus fine</button>-->
      <!--                  <button type="submit" name="hostel_fine" class="btn-classic margin"> Hostel fine</button>-->
      <!--                  <button type="submit" name="other_fee" class="btn-classic margin"> Other Fee</button>-->
      <!--                  <button type="submit" name="demand_bill" class="btn-classic margin"> Demand Bill</button>-->
      <!--              </fieldset>-->
                      <button type="submit" name="demand_bill" class="btn-classic margin"> Demand Bill</button>
					<!--<fieldset style="width:100%; float:left"><legend>Extra Section</legend>-->
                        <?php /*
						$checkextFee=$db->getRows("select * from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$_GET["class"]."'");	
						if(is_array($checkextFee) && count($checkextFee)>0){
							?><?php
							foreach($checkextFee as $cFee){
								?><button type="submit" name="extraFee" value="<?php echo $cFee["id"] ?>" class="btn-classic margin"><?php echo $cFee["type"] ?></button><?php
							}
						}else{
							?><button type="submit" class="btn-classic margin"> Show Extrafee by class</button><?php
						}*/
						?>
                        <!--<button type="submit" name="ChequeDetail" class="btn-classic margin"> Show Cheque Detail</button>-->
                        <!-- <button type="submit" name="sms_demand_bill" class="btn-classic margin">SMS Demand Bill</button>-->
                        <!-- <button type="submit" name="discount_detail" class="btn-classic margin"> Discount Detail</button>-->
                        <!-- <button type="submit" name="monthly_demand_bill" class="btn-classic margin">Monthly Demand Bill</button>-->
                        <!-- <button type="submit" name="discount_mode_detail" class="btn-classic margin">Discount Mode</button>-->
                         
                         
                    <!--</fieldset>-->
				</div>
				<div class="well no-padding">
                	<div class="controls controls-row">
                        <div class="control-group span4">
                           <label class="control-label" for="class">Class</label>
                            <div class="controls span3">
                                <select onchange="changeIns()" name="class" id="class">
                                    <option value="">Class</option>
                                    <?php 
                                        $class=$db->getRows("select * from class  where school_id='".$_SESSION["admin"]["school_id"]."'");
                                        foreach($class as $cla){
                                            ?>
                                            <option <?php if($cla["class"]==$_GET["class"])echo 'selected';?> value="<?php echo $cla["class"] ?>">
                                                <?php echo $cla["class"] ?>
                                            </option>
                                            <?php
                                        }
                                    ?>
                                </select>
                            </div>
                        </div>
                         <div class="control-group span4">
                            <label class="control-label" for="class">Section</label>
                            <div class="controls span3">
                               <select name="section"  id="section" >
                                <option value="">Section</option>
                                <?php 
                                    $class=$db->getRows("select * from section where school_id='".$_SESSION["admin"]["school_id"]."'");
                                    foreach($class as $cla){
                                        ?>
                                        <option <?php if($cla["name"]==$_GET["section"])echo 'selected';?> value="<?php echo $cla["name"] ?>">
                                            <?php echo $cla["name"] ?>
                                        </option>
                                        <?php
                                    }
                                ?>
                            </select>
                            </div>
                        </div>
                        
                   
                        <div class="control-group span4">
                            <label class="control-label" for="class">Month</label>
                            <div class="controls span3">

                                    <select name="fmonth" id="fmonth">
                                    	<option value="">Month</option>
                                     <?php
                                 	$allmonths = $db->getRows("select * from months");

                                    foreach($allmonths as $m){
            
                        	    	    $checked = "";
            					        $cmonth=(date("n")+9);
            						    if($cmonth>12){ $cmonth = date("n")-3; }
                                    	    if($cmonth===$m['month'] ){
                						        $checked="selected='selected'";
                                    	    }
                                	    echo "<option value='".$m['month']."' $checked>$m[name]</option>";
                            	    }
								// 	    for($m = 1;$m <= 12; $m++){ 
								// 			$newDate=date("Y")."-".$m."-1";
								// 			$month =  date("F",strtotime($newDate));
								// 			$selected="";if($_GET["fmonth"]==$m)$selected=" selected ";
								// 			echo "<option $selected value='$m'>$month</option>";
        //                                 }
									 ?> 
                                    </select>

                                </div>
                        </div>
                        
                    </div>

                    
				</div>
			</div>
    </div>
    </form>
	<?php
	$where=array();
	$qry="";
	
	if(isset($_GET["fee"])){
		$conwhere="";
		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"];
			$where[]=" (rr.date between '$fdate' and '$tdate') ";
			$conwhere.=" and  (installment_fine.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["section"]) && $_GET["section"]!=""){
			$where[]=" s.section='".$_GET["section"]."' ";
			$conwhere.=" and student.section='".$_GET["section"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]=" rr.idno=s.idno and s.session='".$_SESSION["admin"]["session"]."' and (rr.type='fee' or rr.type='busfee' or rr.type='hostelfee' or rr.type like 'extrafee%') and s.status=1 ";
		$table=" reff_receipt as rr, student as s";
		$result=$db->getRows("SELECT rr.*,rr.id as recid,s.class as sclass,s.section,s.name,s.medium,s.fname,s.dob,s.mname FROM ".$table." where rr.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0  AND ".implode(" AND ",$where)." group by rr.id order by rr.date");
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();
		?>
		 <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 onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button onclick="SMSComplete('completeFeeShw','completeFeeShowSMS')" type="button" class="btn btn-primary">SMS</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table tableSummery" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>S. No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Section</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>Receipt ID</th>
                            <th>Quater</th>
                            <th>Fee</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;$ijk=0;
						if(is_array($result) && count($result)>0)
						{
							foreach($result as $detail)
							{$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo ucfirst($detail["name"]); ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["section"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php 
									$rids=array();
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									//echo "<pre>";print_r($rrde);echo "</pre>";
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$detail["recid"]){
													$rids[]=$rr["id"];
												}
											}
										}
									}
									echo implode(",",$rids) ?></td>
                                    <td><?php $ins_iods = $detail["inst_id"];//." (".($detail["type"] == "fee" ? "School Fee" : "Bus Fee").")" 
									if($detail["type"]=="fee")
										echo "<span style='color:#FF0000'>$ins_iods(School Fee)</span>";
									else if($detail["type"]=="busfee")
										echo "<span style='color:#00CC00'>$ins_iods(Transport Fee)</span>"; 
									else if($detail["type"]=="hostelfee") 
										echo "<span style='color:#FF00FF'>$ins_iods(Hostel Fee)</span>";
									else{
										$det=$db->getVal("select type from extrafee_type where id='".str_replace("extrafee","",$detail["type"])."'");
										echo "<span style='color:#FF0000'>$ins_iods($det)</span>";
									}?></td>
                                    <td><?php echo $all=$detail["amount"];
									$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["date"]; ?></td>
                                </tr>
								<?php
							}
						}
						$result=$db->getRows("select student.idno,student.name,student.class as sclass,student.medium,student.fname,student.dob,student.mname,installment_fine.* from installment_fine,student where student.school_id='".$_SESSION["admin"]["school_id"]."' and student.session='".$_SESSION["admin"]["session"]."' and student.issue_TC=0 and installment_fine.status=1 and installment_fine.fine!='' and installment_fine.idno=student.idno $conwhere order by student.name");
						//echo $db->getErMsg().$db->getLastQuery();
						if(is_array($result) && count($result)>0){
							foreach($result as $detail){$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $detail["name"]; ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                     <td><?php echo $detail["section"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php $detail["id"];
									//echo $db->getVal("select id from receipt where rrid=(select id from reff_receipt where inst_id=".$detail["id"].")"); 
									$rids=array();
									$recpID=$db->getVal("select id from reff_receipt where inst_id='".$detail["id"]."'");
									$rrde=$db->getRows("select rrid,id from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											//print_r($rr);
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$recpID){
													$rids[]=$rr["id"];
													//echo "select id from receipt where rrid='".$rrids."'<br />";
												}
											}
										}
									}//echo $db->getLastQuery();
									echo implode(",",$rids).$db->getErMsg();
									?></td>
                                    <td><?php $qua=$detail["ins_name"];echo instFine($qua,$detail["reasion"]); ?></td>
                                    <td><?php $otfee=str_replace("_detail","_fee",$qua);
									echo $all=$detail["fine"];$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["udate"]; ?></td>
                                </tr>
								<?php
							}
						}
						$newwhere="";
						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"];
							$newwhere=" and (udate between '$fdate' and '$tdate') ";
						}
						$finalresult=$db->getRows("select * from transaction where type='deposit' $newwhere and rid=0 and tid=0");
						if(is_array($finalresult) && count($finalresult)>0){
							foreach($finalresult as $detail){$ijk++;
								?><tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td>--</td>
                                    <td>--</td>
                                    <td>--</td>
                                    <td>--</td>
                                    <td>--</td>
									<td>--</td>
                                    <td><?php echo $detail["detail"] ?></td>
                                    <td><?php echo $detail["amount"];$ollTotal+=$detail["amount"]; ?></td>
                                    <td><?php echo $detail["udate"] ?></td>
									<?php
							}
						}
						?>
                        
                    </tbody>
                    <tfoot>
                    	<tr style="border-top:1px solid #F00; color:#F00">
                        	<td colspan="6">Total</td><td></td><td></td><td id="completeFeeShw"><?php echo $ollTotal; ?></td><td></td>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
          </div>
		<?php
	}
	
	
	elseif(isset($_GET["outstanding_wt_class"])){ 
		
    $cla= $db->getRows("select class from class" );
	?>
	
	<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">
                <?php if(isset($_GET["class"]) && $_GET["class"]!=""){
				?><input type="button" class="btn btn-primary" onclick="getStudentPopup()" value="Migrate Left Fee"  /><?php	
				} ?>
            	<input type="button" class="btn btn-primary" id="btnduesend" value="Due List"  />
               <input type="button" class="btn btn-primary" onclick="sendAll()" id="btnsend" value="Send SMS"  />     
                <input style="margin-right:3px;" type="text" placeholder="search by total left" onkeyup="filterPayleft(this)" />
                <input type="text" placeholder="search by total paid" id="searchfoertotal" onkeyup="filterPay(this)" />
                <button onclick="printDiv('printDiv1')" type="button" class="btn btn-primary">Print</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv1">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                        
                            <th>Serial No</th>                         
                            <th>Class</th>                  
                            <th>Total Fee</th>
                            <th>Total paid</th>
                            
                            <th>Total Left</th>
                            <th>Discount</th>
                        </tr>
                    </thead>
                    <tbody>
	<?php
$i=0;
	foreach($cla as $cl){$i++;	
	    $c= $cl["class"]; 		
		// tution fee
		$total=$db->getVal("SELECT fee from class where class='".$c."' ");
		
		$total_student= $db->getVal("SELECT count(idno) FROM student WHERE class='".$c."' AND session='".$_SESSION["admin"]["session"]."' and status='1' ");
				
		$total_tution=$total*$total_student;		
		// bus fee

		$bus=$db->getVal("select sum(total) from (select student.bus, bus.fee as f, count(student.bus) as bus_count, count(student.bus) *  bus.fee as total FROM student  inner join bus on bus.id=student.bus where student.class='".$c."' and student.bus!='' and student.session='".$_SESSION["admin"]["session"]."' and student.status='1' GROUP BY student.bus) as result");
		
        $hostel=$db->getVal("SELECT sum(total) as result from hostelinstallment  WHERE idno in (select idno from student where class='".$c."' and session='".$_SESSION["admin"]["session"]."' ) ");
		// hostel other
	
	   $hostel_total_student=$db->getVal("SELECT count(idno) FROM student WHERE class='".$c."' and htype!='' AND session='".$_SESSION["admin"]["session"]."' and status='1' ");
	   
	   $hostel_total_other=$db->getVal("SELECT COALESCE(sum(fee),0) as result from hostel_otherfee_structure  WHERE class='$c' and otype='' and session='".$_SESSION["admin"]["session"]."' ");
				
	   $hostel_other_fee_all= $hostel_total_student*$hostel_total_other;
	   
	   $hostel_student_new=$db->getVal("SELECT count(idno) FROM student WHERE class='".$c."' and htype!='new' AND session='".$_SESSION["admin"]["session"]."' and status='1' ");
	   
	   $hostel_total_other_new=$db->getVal("SELECT COALESCE(sum(fee),0) as result from hostel_otherfee_structure  WHERE class='$c' and otype='new' and session='".$_SESSION["admin"]["session"]."' ");
	   
	   $hostel_other_fee_new=$hostel_student_new*$hostel_total_other_new; 
	   
	   $hostel_student_old=$db->getVal("SELECT count(idno) FROM student WHERE class='".$c."' and htype!='old' AND session='".$_SESSION["admin"]["session"]."' and status='1' ");
	   
	   $hostel_total_other_old=$db->getVal("SELECT COALESCE(sum(fee),0) as result from hostel_otherfee_structure  WHERE class='$c' and otype='old' and session='".$_SESSION["admin"]["session"]."' ");
	   
	   $hostel_other_fee_old=$hostel_student_old*$hostel_total_other_old;
	   
		$hostel_total_other_id=$db->getVal("SELECT COALESCE(sum(fee),0) as result from hostel_otherfee_structure  WHERE class='$c'  and session='".$_SESSION["admin"]["session"]."' and otype!='' and otype!='new' and otype!='old'  ");
		
	   $hostel_total_other_fee= $hostel_other_fee_all+$hostel_other_fee_new + $hostel_other_fee_old+$hostel_total_other_id;
	   // hostel other discount
			$hostel_other_dis= $db->getVal("SELECT sum(discount) FROM `hostelotherfee_discount` WHERE idno in (select idno from student where class='".$c."' and session='".$_SESSION["admin"]["session"]."' )");
			
		
		// extra 
		$extra=$db->getVal("SELECT sum(total) from extrafee_type  WHERE class='".$c."' and session='".$_SESSION["admin"]["session"]."' ");
				
		$total_extra =$extra*$total_student;
		// extra discount
		$extra_discount=$db->getVal("SELECT sum(discount) as result from extrafee  WHERE idno in (select idno from student where class='".$c."' and session='".$_SESSION["admin"]["session"]."' )");
		
		
		
		// other fee
		
		$total_other=$db->getVal("SELECT COALESCE(sum(fee),0) as result from otherfee_structure  WHERE class='$c' and otype='' and session='".$_SESSION["admin"]["session"]."' ");
				
		$other_fee_all= $total_student*$total_other;
		
		//new other
		$total_student_new= $db->getVal("SELECT count(idno) FROM student WHERE class='".$c."' and stype='new' AND session='".$_SESSION["admin"]["session"]."' and status='1' ");
		
		$total_other_new=$db->getVal("SELECT COALESCE(sum(fee),0) as result from otherfee_structure  WHERE class='$c' and otype='new'   and session='".$_SESSION["admin"]["session"]."' ");
		
		$other_fee_new= $total_student_new*$total_other_new;
		// old other
		
		$total_student_old= $db->getVal("SELECT count(idno) FROM student WHERE class='".$c."' and stype='old' AND session='".$_SESSION["admin"]["session"]."' and status='1' ");
		 
		$total_other_old=$db->getVal("SELECT COALESCE(sum(fee),0) as result from otherfee_structure  WHERE class='$c' and otype='old'   and session='".$_SESSION["admin"]["session"]."' ");
				
		$total_other_id=$db->getVal("SELECT COALESCE(sum(fee),0) as result from otherfee_structure  WHERE class='$c'  and session='".$_SESSION["admin"]["session"]."' and otype!='' and otype!='new' and otype!='old'  ");
						
        $other_fee_old= $total_student_old*$total_other_old;		
		
	    $total_other_fee= $other_fee_all+$other_fee_new+$other_fee_old+$total_other_id;
		
		$total_paid=$db->getVal("SELECT sum(COALESCE(amount,0)) as amt from reff_receipt  WHERE idno IN (SELECT idno FROM student WHERE class='".$c."' AND session='".$_SESSION["admin"]["session"]."'and status='1') ");
				
		// discount
		$discount=$db->getVal("SELECT sum(COALESCE(discount,0)+COALESCE(busdiscount,0)+COALESCE(hosteldiscount,0)) as tution_dis from installment_discount  WHERE idno IN (SELECT idno FROM student WHERE class='".$c."' AND session='".$_SESSION["admin"]["session"]."'and status='1')");
				
		$total_other_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from otherfee_discount  WHERE class='$c' and session='".$_SESSION["admin"]["session"]."'");
						
		$dis=$discount+$total_other_discount+$extra_discount+$hostel_other_dis;
		$tf=$total_tution+$bus+$total_other_fee+$total_extra+$hostel-$dis;
		$tl=$tf-$total_paid;
			$total_bus=0;			
		  ?>
                            <tr>
							     <td><?= $i;  ?></td>
							     <td><?=  $c; ?></td>
				                 <td><?php echo $tf; $MyTotalFee +=$tf; ?></td>
							     <td><?php  echo $total_paid; $MyTotalpaid+=$total_paid; ?></td>
							     <td> <?php  echo $tl; $MyTotalLeft+=$tl; ?></td>
							     <td><?php echo $dis; $MyDiscount+=$dis;?></td> 
                            	
							</tr>
	<?php  } ?>						
                    </tbody>
   
                    <tfoot>
                    	<tr>
                        	<th colspan="2" >Gross Total</th>
                            <th id="MyTotalFee"><?php echo $MyTotalFee?></th>
                            <th id="MyTotalpaid"><?php echo $MyTotalpaid;?></th>
                            <th id="MyTotalLeftDynamic" class="dynamic"></th>
                            <th id="MyTotalLeft"><?php echo $MyTotalLeft; ?></th>
                            <th id="MyDiscount"><?php echo $MyDiscount; ?></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
		echo $db->getErMsg();
	}
	elseif(isset($_GET["outstanding"])){ 
		/*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"];
			$where[]=" (it.date between '$fdate' and '$tdate') ";
		}*/
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["section"]) && $_GET["section"]!=""){
			$where[]=" s.section='".$_GET["section"]."' ";
			$conwhere.=" and student.section='".$_GET["section"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]=" i.idno=s.idno and  s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";
		$table=" installment as i, student as s";
		$result=$db->getRows("SELECT i.*,i.bus as busfe,s.class as sclass,s.section,s.name,s.medium,s.fname,s.dob,s.mname FROM ".$table." where i.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".implode(" AND ",$where)." group by s.idno order by s.name");
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getErMsg();echo $db->getLastQuery();
		?>
		 <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">
                <?php if(isset($_GET["class"]) && $_GET["class"]!=""){
				?><input type="button" class="btn btn-primary" onclick="getStudentPopup()" value="Migrate Left Fee"  /><?php	
				} ?>
            	<input type="button" class="btn btn-primary" id="btnduesend" value="Due List"  />
               <input type="button" class="btn btn-primary" onclick="sendAll()" id="btnsend" value="Send SMS"  />     
                <input style="margin-right:3px;" type="text" placeholder="search by total left" onkeyup="filterPayleft(this)" />
                <input type="text" placeholder="search by total paid" id="searchfoertotal" onkeyup="filterPay(this)" />
                <button onclick="printDiv('printDiv1')" type="button" class="btn btn-primary">Print</button>
                <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv1">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                        	<td>All<input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></td>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Section</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>DOB</th>
                            <th>Total Fee</th>
                            <th>Total paid</th>
                            <th class="dynamic">Current Left</th>
                            <th>Total Left</th>
                            <th>Discount</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php
						$MyTotalFee=0;
						$MyTotalpaid=0;
						$MyTotalLeft=0;
						$MyDiscount=0;
						
						
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
								$busFine=0;
								$schoolFine=0;
								$hostelFine=0;
								
						$aryForm["idno"]=$_GET["id"]=$detail["idno"];
						$aryForm["class"]=$detail["sclass"];
						$aryInstall=$db->getRow("select * from installment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and session='".$_SESSION["admin"]["session"]."'");
						$feeCount=array();$totalclasspayfee=0;$totalbuspayfee=0;
						for($i=1;$i<=12;$i++){
							$iis="i".$i;
							$iip="ip".$i;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalclasspayfee=$totalclasspayfee+$aryInstall[$iip];
								
								$ij=$i;
								
								$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-class'");
								$fine=$fineAry["fine"];
								$schoolFine+=$fine;
							}
						}
						$ji=0;
						for($i=1;$i<=12;$i++){
							$iis="b".$i;
							$iip="bp".$i;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalbuspayfee=$totalbuspayfee+$aryInstall[$iip];$ji++;
							
								$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-bus'");
								$fine=$fineAry["fine"];
								$busFine+=$fine;
								$recpChkData=checkRecepit($_GET["id"],$iip,"busfee");
								
							}
						}
						$aryHostelInstall=$db->getRow("select * from hostelinstallment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and session='".$_SESSION["admin"]["session"]."'");
						$feeHostelCount=array();$totalhostelpayfee=0;
						for($i=1;$i<=12;$i++){
							$iis="i".$i;
							$iip="ip".$i;
							if($aryHostelInstall[$iis]!="" && $aryHostelInstall[$iis]!=0){
								$totalhostelpayfee=$totalhostelpayfee+$aryHostelInstall[$iip];
								
								$ij=$i;
								
								$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-hostel'");
								$fine=$fineAry["fine"];
								$hostelFine+=$fine;
							}
						}
						/*$extrafeeFine=0;
						$checkextFee=$db->getRows("select * from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'");	
						if(is_array($checkextFee) && count($checkextFee)>0){
							foreach($checkextFee as $chkExtFee){
								$mycheckInstall=$db->getRows("select * from extrafee where idno='".$_GET["id"]."' and type='".$chkExtFee["id"]."'");
								if(is_array($mycheckInstall) && count($mycheckInstall)>0){
									foreach($mycheckInstall as $myinstall){
										$fine="";$ipi=ltrim ($myinstall["pid"], 'p');
										$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$ipi."-extra".$myinstall["type"]."'");
										if(is_array($fineAry) && count($fineAry)>0){
											$fine=$fineAry["fine"];
											$extrafeeFine=$extrafeeFine+$fineAry["fine"];
										}
									}
								}
							}
						}*/
						
						$i=1;$totalOther=0;$payOther=0;$fineTotal=0;$allReasion=array();$OtherSiteTotal=0;
						if($_GET["id"]!='')
						{
							$utype=mydetail("stype",$_GET["id"],"student");
							$all_other=$db->getRows("select * from otherfee_structure where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and class='".$aryForm["class"]."' and (otype='' OR otype='".$utype."' OR otype='".$_GET["id"]."')");
							 //echo"<pre>";print_r($all_other);echo"</pre>";
							if(is_array($all_other) && count($all_other))
							{
								foreach($all_other as $iPro)
								{
									$i++;
									$paid_Fee=$db->getVal("select fine from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."' and reasion='".$iPro["name"]."' and ins_name like '%otherfee%'");
									$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-other'");
									$other_Fee=$db->getRow("select discount,detail from otherfee_discount where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and other_id='".$iPro["id"]."'");	
									//$installTution_remain=$db->getRow("select fine from installment_fine where idno=".$aryForm["idno"]." and reasion like 'remain%'");
									  	
									$OtherSiteTotal+=(int)$other_Fee["discount"];
									
									$paid_Fee+$fine; 
									
									$totalOther+=(int)$iPro["fee"]-(int)$other_Fee["discount"];
									
									$payOther+=(int)$paid_Fee;
									
									$fine=$fineAry["fine"];
									
									//if(is_array($installTution_remain) && count($installTution_remain)>0)
										//	$fine=$fine-$installTution_remain["fine"];
									
									$fineTotal+=(int)$fine;
									
									$i++;
								} 
							}
						}
					
						if($_GET["id"]!='')
						{ 
							$all_product=$db->getRows("select * from installment_fine where idno='".$_GET["id"]."' and ins_name like '%otherfee%' and reasion not in (select name from otherfee_structure where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and  class='".$aryForm["class"]."')");
							 
							 //echo"<pre>";print_r($all_product);echo"</pre>";
							if(is_array($all_product) && count($all_product))
							{
								foreach($all_product as $iPro)
								{
									
									$totalOther+=(int)$iPro["fine"];
									$payOther+=(int)$iPro["fine"]; 
									$i++;
								}
							}
						} 
				 		$overAllTotal=0;$overAllPay=0;$overAllRemaining=0;$overAllDiscount=0; 
				 
						$overAllTotal+=$aryInstall["total"];
						$overAllPay+=$totalclasspayfee;
						$rem=(int)($aryInstall["total"]-$totalclasspayfee);$overAllRemaining+=$rem;
						$overAllDiscount+=$aryInstall["discount"];
						
						//Total Transport Fee
						
						$overAllTotal+=$aryInstall["bus"];
						$overAllPay+=$totalbuspayfee;
						$rem=(int)($aryInstall["bus"]-$totalbuspayfee);$overAllRemaining+=$rem;
						$overAllDiscount+=$aryInstall["busdiscount"];
						
						//Total Hostel Fee
						
						$overAllTotal+=$aryHostelInstall["total"];
						$overAllPay+=$totalhostelpayfee;
						$rem=(int)($aryHostelInstall["total"]-$totalhostelpayfee);$overAllRemaining+=$rem;
						$overAllDiscount+=$aryHostelInstall["discount"];
						
						//for all Extra fee 
						$extrafeeFine=0;
						$checkextFee=$db->getRows("select * from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'");	
						if(is_array($checkextFee) && count($checkextFee)>0){
							foreach($checkextFee as $chkExtFee){
								$mycheckInstall=$db->getRow("select SUM(fee) as feetotal,SUM(pay) as payfee  from extrafee where idno='".$_GET["id"]."' and type='".$chkExtFee["id"]."'");
								$ipi=ltrim ($myinstall["pid"], 'p');
								//echo $db->getLastQuery();
								if($mycheckInstall[0]>0){
									$overAllTotal+=$chkExtFee["total"];
									$overAllPay+=$mycheckInstall[1];
									$rem=(int)($chkExtFee["total"]-$mycheckInstall[1]); $overAllRemaining+=$rem;
								}
								$mycheckInstall=$db->getRows("select * from extrafee where idno='".$_GET["id"]."' and type='".$chkExtFee["id"]."'");
								if(is_array($mycheckInstall) && count($mycheckInstall)>0){
									foreach($mycheckInstall as $myinstall){
										$fine="";$ipi=ltrim ($myinstall["pid"], 'p');
										$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$ipi."-extra".$myinstall["type"]."'");
										if(is_array($fineAry) && count($fineAry)>0){
											$fine=$fineAry["fine"];
											$extrafeeFine=$extrafeeFine+$fineAry["fine"];
										}
									}
								}
							}
						}
						
						//Total Other Fee
						$overAllTotal+=$totalOther+$hostelFine+$extrafeeFine;
						$overAllPay+=($payOther+$fineTotal+$hostelFine+$extrafeeFine);
						$rem= (int)($totalOther-($payOther+$fineTotal));$overAllRemaining+=$rem;
						$OtherSiteTotal;
				  
							?>
							<tr>
                            	<td><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $detail["idno"];?>" id="cat<?php echo $detail["mobile"]; ?>" /></td>
								<td><?php echo $ijk; ?><input type="hidden" name="mobile[]" value="<?php echo $detail["mobile"] ?>" /></td>
								<td class="name<?php echo $detail["idno"];?>"><?php echo $detail["name"]; ?></td>
								<td><?php echo $detail["sclass"]; ?></td>
                                <td><?php echo $detail["section"]; ?></td>
								<td><?php echo $detail["fname"]; ?></td>
								<td><?php echo $detail["mname"]; ?></td>
								<td><?php echo $detail["dob"]; ?></td>
								<td class="MyTotalFee"><?php echo $overAllTotal+$schoolFine+$busFine;								
								$MyTotalFee+=$overAllTotal+$schoolFine+$busFine; ?></td>
								<td class="MyTotalpaid"><?php echo $overAllPay+$schoolFine+$busFine;									
								$MyTotalpaid+=$overAllPay+$schoolFine+$busFine; ?></td>
                                <th class="MyTotalLeftDynamic dynamic"></th>
								<td class="MyTotalLeft left<?php echo $detail["idno"];?>"><?php echo $remen=(int)($overAllTotal-$overAllPay);		$MyTotalLeft+=$remen; ?></td>
								<td class="MyDiscount"><?php echo $ovAll=$overAllDiscount+$OtherSiteTotal;		$MyDiscount+=$ovAll; ?></td>
							</tr>
							<?php
							}
						}else{
							?><tr>
                            <td colspan="10">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<th colspan="8"></th>
                            <th id="MyTotalFee"><?php echo $MyTotalFee?></th>
                            <th id="MyTotalpaid"><?php echo $MyTotalpaid;?></th>
                            <th id="MyTotalLeftDynamic" class="dynamic"></th>
                            <th id="MyTotalLeft"><?php echo $MyTotalLeft; ?></th>
                            <th id="MyDiscount"><?php echo $MyDiscount; ?></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
		echo $db->getErMsg();
	}
	elseif(isset($_GET["detail"])){
		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"];
			$where[]=" (s.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["section"]) && $_GET["section"]!=""){
			$where[]=" s.section='".$_GET["section"]."' ";
			$conwhere.=" and student.section='".$_GET["section"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		if(isset($_GET["location"]) && trim($_GET["location"])!=""){
			$where[]=" s.location='".$_GET["location"]."' ";
			$conwhere.=" and student.location='".$_GET["location"]."' ";
		}
		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";
		$table=" student as s";
		$result=$db->getRows("SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".implode(" AND ",$where)." order by s.name");
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();		echo $db->getErMsg();
		?>
		 <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">
				<!--<input  class="btn btn-primary" type="button"  onclick="$('.table').tableExport({type:'excel',escape:'false'});" id="btnExport" value=" Export To Excel " />-->
                   <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">
            	<table class="table" border="1" id="tblData">
                    <thead>
                        <tr>
                            <th>S.No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Sec</th>
                            <th>Sex</th>
                            <th>DOB</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>Adm.Date</th>
                            <th>address</th>
                            <th>Mobile</th>
                            <th>Adm. no</th>
                            <th>Roll. no</th>
                            <th>R</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php
						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["section"]; ?></td>
                                    <td><?php echo $detail["gender"]; ?></td>
                                    <td><?php if($detail["dob"]!="")echo date("d-M-Y",strtotime($detail["dob"])); ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                     <td><?php echo $detail["doa"]; ?></td>
                                    <td><?php echo $detail["address"]; ?></td>
                                    <td><?php echo $detail["mobile"]; ?></td>
                                    
                                    <td><?php echo $detail["admissionno"]; ?></td>
                                    <td><?php echo $detail["feducation"]; ?></td>
                                    <td><?php echo $detail["sssmid"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="10">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <!--<tfoot>-->
                    <!--	<tr>-->
                    <!--    	<th colspan="10"></th>-->
                    <!--    </tr>-->
                    <!--</tfoot>-->
                 </table>
              </div>
          </div>
		<?php
	}
	elseif(isset($_GET["canceldetail"])){
		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"];
			$where[]=" (s.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["section"]) && trim($_GET["section"])!=""){
			$where[]=" s.section='".$_GET["section"]."' ";
			$conwhere.=" and student.section='".$_GET["section"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=3 ";
		$table=" student as s";
		$result=$db->getRows("SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".implode(" AND ",$where)." order by s.name");
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();		echo $db->getErMsg();
		?>
		 <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-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Section</th>
                            <th>Father</th>
                            <th>address</th>
                            <th>Mobile</th>
                            <th>Adm. no</th>
                            <th>Cancel date</th>
                            <th>Cancel By</th>
                            <th>action</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
								?>
                                <tr id="row<?php echo $detail["idno"] ?>">
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo ucfirst($detail["name"]); ?></td>
                                    <td><?php echo $detail["class"]; ?></td>
                                    <td><?php echo $detail["section"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["address"]; ?></td>
                                    <td><?php echo $detail["mobile"]; ?></td>
                                    <td><?php echo $detail["admissionno"]; ?></td>
                                    <td><?php if($detail["idate"]!="0000-00-00") echo date("d-M-Y",strtotime($detail["idate"])); ?></td>
                                    <td><?php echo $user=$db->getVal("Select name from users where id='".$detail["added_by"]."'"); ?></td>
                                	<td><input type="button" class="btn btn-danger" value="active" onclick="activeNowMe('<?php echo $detail["idno"] ?>')" /></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="11">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<td colspan="11"></td>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	elseif(isset($_GET["is_bpl"])){
		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"];
			$where[]=" (s.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1 and bpl=1 ";
		$table=" student as s";
		$result=$db->getRows("SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".implode(" AND ",$where)." order by s.name");
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();		echo $db->getErMsg();
		?>
		 <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-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Cast</th>
                            <th>Gender</th>
                            <th>DOB</th>
                            <th>Father name</th>
                            <th>address</th>
                            <th>Mobile</th>
                            <th>Admission no</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php
						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["cast"]; ?></td>
                                    <td><?php echo $detail["gender"]; ?></td>
                                    <td><?php echo $detail["dob"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["address"]; ?></td>
                                    <td><?php echo $detail["mobile"]; ?></td>
                                    <td><?php echo $detail["admissionno"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="10">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<th colspan="10"></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	
	elseif(isset($_GET["sibling"])){

				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"];
			$where[]=" (s.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1  ";
		$table=" student as s";
		$result=$db->getRows("SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and (sibling!='' and sibling!='0')  and ".implode(" AND ",$where)." order by s.name");
		
		//echo $ss="SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and (sibling!='' and sibling!='0')  and ".implode(" AND ",$where)." order by s.name";
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();		echo $db->getErMsg();
		?>
		 <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-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Cast</th>
                            <th>Gender</th>
							 <th colspan="4">Sibling Detail</th>
                           
                        </tr>
                    </thead>
                    <tbody>
                    	<?php
						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["cast"]; ?></td>
                                    <td><?php echo $detail["gender"]; ?></td>
									  <?php  $stu_sib=$detail["sibling"];
									// print_r($stu_sib);
									$csvString= "$stu_sib";
									
$options = explode(",", $csvString);
//print_r($options);
foreach($options as $val) { $ijs++;
	
	
	?><td><?php
	

	echo $sib_name=$db->getval("select name from student where idno='".$val."'"); ?>&nbsp;- <?php  echo $sib_class=$db->getval("select class from student where idno='".$val."'"); ?></td><?php
						}
					   $ijs=0;
                             ?>      
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="10">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<th colspan="10"></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	//gate pass
	elseif(isset($_GET["getpass"])){
		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"];
			$where[]=" ( where udate between '$fdate' and '$tdate') ";
		  //$conwhere = "( where udate between '$fdate' and '$tdate')";
		}
// 		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
// 			$where[]=" s.stype='".$_GET["stype"]."' ";
// 			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
// 		}
// 		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
// 			$where[]=" s.medium='".$_GET["medium"]."' ";
// 			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
// 		}
// 		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
// 			$where[]=" s.class='".$_GET["class"]."' ";
// 			$conwhere.=" and class='".$_GET["class"]."' ";
// 		}
// 		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
// 			$where[]=" s.gender='".$_GET["gender"]."' ";
// 			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
// 		}
// 		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
// 			$where[]=" s.cast='".$_GET["cast"]."' ";
// 			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
// 		}
// 		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
// 			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
// 			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
// 			$where[]=" (s.dob between '".$end."' and '".$start."')";
// 			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
// 		}
		$where[]=" s.session='".$_SESSION["admin"]["session"]."' ";
		$table=" student as s";
// 		$result=$db->getRows("SELECT * FROM student_entry_pass WHERE  session='".$_SESSION["admin"]["session"]."'    $conwhere   order by id");

		$result=$db->getRows("SELECT * FROM gatepass $conwhere order by id");

	//	echo $ss="SELECT * FROM student_entry_pass WHERE session='".$_SESSION["admin"]["session"]."  $conwhere   order by id";
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();		echo $db->getErMsg();
		?>
		 <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-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Father Name</th>
                            <th>Class</th>
                            <th>Visitor Name</th>
                            <th>Reletion</th>
                            <th>Mobile No</th>
                            
                           
                        </tr>
                    </thead>
                    <tbody>
                    	<?php
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
							
							    $student = $db->getRow("select name, fname, class from student where idno='".$detail["idno"]."' ");
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $student['name']; ?></td>
                                    <td><?php echo $student['fname']; ?></td>
                                    <td><?php echo $student["class"]; ?></td>
                                  
                                    <td><?php echo $detail["name"]; ?></td>
                                    <td><?php echo $detail["relation"]; ?></td>
                                 
                                    <td><?php echo $detail["contact"]; ?></td>
                                  
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="10">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<th colspan="10"></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	
	elseif(isset($_GET["bus_detail"])){
		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"];
			$where[]=" (s.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		
		if(isset($_GET["section"]) && trim($_GET["section"])!=""){
			$where[]=" s.section='".$_GET["section"]."' ";
			$conwhere.=" and student.section='".$_GET["section"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1 and s.bus!='' ";
		$table=" student as s";
		$result=$db->getRows("SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and s.bus_status=0 and s.issue_TC=0 and ".implode(" AND ",$where)." order by s.name");
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();		echo $db->getErMsg();
		?>
		 <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-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Cast</th>
                            <th>Gender</th>
                            <th>DOB</th>
                            <th>Father name</th>
                            <th>address</th>
                            <th>Mobile</th>
                            <th>Admission no</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php
						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["cast"]; ?></td>
                                    <td><?php echo $detail["gender"]; ?></td>
                                    <td><?php echo $detail["dob"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["address"]; ?></td>
                                    <td><?php echo $detail["mobile"]; ?></td>
                                    <td><?php echo $detail["admissionno"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="10">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<th colspan="10"></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	elseif(isset($_GET["hostel_detail"])){
		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"];
			$where[]=" (s.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1  and i.idno=s.idno and i.total>0 ";
		$table=" student as s, hostelinstallment as i";
		$result=$db->getRows("SELECT    s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".implode(" AND ",$where)."  group by s.idno order by s.name");
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();		echo $db->getErMsg();
		?>
		 <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-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Cast</th>
                            <th>Gender</th>
                            <th>DOB</th>
                            <th>Father name</th>
                            <th>address</th>
                            <th>Mobile</th>
                            <th>Admission no</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php
						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["cast"]; ?></td>
                                    <td><?php echo $detail["gender"]; ?></td>
                                    <td><?php echo $detail["dob"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["address"]; ?></td>
                                    <td><?php echo $detail["mobile"]; ?></td>
                                    <td><?php echo $detail["admissionno"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="10">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<th colspan="10"></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	elseif(isset($_GET["bus_outstanding"])){
		/*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"];
			$where[]=" (it.date between '$fdate' and '$tdate') ";
		}*/
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]=" s.bus!='' and i.idno=s.idno and s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";
		$table=" installment as i, student as s";
		$result=$db->getRows("SELECT i.*,i.bus as busfe,s.class as sclass,s.name,s.mobile,s.medium,s.fname,s.dob,s.mname FROM ".$table." where i.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".implode(" AND ",$where)." group by s.idno order by s.name");
		//echo $db->getLastQuery();
		?>
		 <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 type="button"  onclick="SMS('bus_outstanding')" class="btn btn-primary">SMS</button>     
                    <input style="margin-right:3px;" type="text" placeholder="search by total left" onkeyup="filterPayleft(this)" />
                    <input type="text" placeholder="search by total paid" id="searchfoertotal" onkeyup="filterPay(this)" />
                    <button type="button"  onclick="printDiv('printDiv3')" class="btn btn-primary">Print</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv3">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>DOB</th>
                            <th>Mobile</th>
                            <th>Total Fee</th>
                            <th>Total Paid</th>
                            <th class="dynamic">Current Left</th>
                            <th>Total Left</th>
                            <th>Discount</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php
						$overAllTotal=0;$overAllFee=0;$overAllBus=0;$overAllDiscount=0;$ij=0;
						$overTotal=0;$overFee=0;$overBus=0;$iptotal=0;$bptotal=0;$ipremail=0;$bpremail=0;
						if(is_array($result) && count($result)>0){
							foreach($result as $detail){$overBus=0;$bptotal=0;$ij+=1;
								(int)$total=(int)$detail["total"]+(int)$detail["busfe"];
								(int)$overTotal=(int)$overTotal+(int)$total;
								(int)$overFee=(int)$overFee+(int)$detail["total"];
								(int)$overBus=(int)$overBus+(int)$detail["busfe"];
								$ip=$detail["ip1"]+$detail["ip2"]+$detail["ip3"]+$detail["ip4"]+$detail["ip5"]+$detail["ip6"]+$detail["ip7"]+$detail["ip8"]+$detail["ip9"]+$detail["ip10"]+$detail["ip11"]+$detail["ip12"]+$detail["ip13"]+$detail["ip14"]+$detail["ip15"];
								$iptotal=$ip;
								$bp=$detail["bp1"]+$detail["bp2"]+$detail["bp3"]+$detail["bp4"]+$detail["bp5"]+$detail["bp6"]+$detail["bp7"]+$detail["bp8"]+$detail["bp9"]+$detail["bp10"]+$detail["bp11"]+$detail["bp12"]+$detail["bp13"]+$detail["bp14"]+$detail["bp15"];
								$bptotal=$bp;
								?>
                                <tr>
                                    <td><?php echo $ij; ?>
                                 </td>   <input type="hidden" name="mobile[]" value="<?php echo $detail["mobile"] ?>" />
                                    <td><?php echo $detail["name"]; ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php echo $detail["dob"]; ?></td>
                                     <td><?php echo $detail["mobile"]; ?></td>
                                    <td class="MyTotalFee"><?php echo $overBus; $overAllTotal=$overAllTotal+$overBus;?></td>
                                    <td class="MyTotalpaid"><?php echo $bptotal; $overAllFee=$overAllFee+$bptotal;?></td>
                                    <th class="MyTotalLeftDynamic dynamic"></th>
                                    <td class="MyTotalLeft"><?php echo $rem=$overBus-$bptotal; $overAllBus=$overAllBus+$rem;?></td>
                                    <td class="MyDiscount"><?php echo $detail["busdiscount"]; ?>
                                    </td>
                                </tr>
								<?php $overAllDiscount=$overAllDiscount+$detail["busdiscount"]?>
                                    <input type="hidden" name="details[]" value="<?php echo $overBus."-".$bptotal."-".$rem ?>" />
                                    <?php
							}
						
						?>
                    </tbody>
                    <tfoot style="color:#FF0;">
                    	<tr>
                        	<th colspan="7" align="right">Total</th>
                            <th id="MyTotalFee"><?php echo $overAllTotal ?></th>
                            <th id="MyTotalpaid"><?php echo $overAllFee; ?></th>
                            <th id="MyTotalLeftDynamic" class="dynamic"></th>
                            <th id="MyTotalLeft"><?php echo $overAllBus; ?></th></th>
                            <th id="MyDiscount"><?php echo $overAllDiscount; ?></th></th>
                        </tr>
                    </tfoot>
                    <?php } else{
							?><tr>
                            <td colspan="10">No record Found</td>
                            </tr><?php
						}
					?>
                 </table>
              </div>
          </div>
		<?php
	
	}
	elseif(isset($_GET["school_outstanding"])){
		/*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"];
			$where[]=" (it.date between '$fdate' and '$tdate') ";
		}*/
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]=" i.idno=s.idno and s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";
		$table=" installment as i, student as s";
		$result=$db->getRows("SELECT i.*,i.bus as busfe,s.class as sclass,s.name,s.medium,s.fname,s.dob,s.mname,s.mobile FROM ".$table." where i.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".implode(" AND ",$where)." group by s.idno order by s.name");
		//echo $db->getLastQuery();
		?>
		 <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 type="button"  onclick="printDiv('printDiv4')" class="btn btn-primary">Print</button>
                    <input style="margin-right:3px;" type="text" placeholder="search by total left" onkeyup="filterPayleft(this)" />
                    <input type="text" placeholder="search by total paid" id="searchfoertotal" onkeyup="filterPay(this)" />
                    <button type="button"  onclick="SMS('school_outstanding')" class="btn btn-primary">SMS</button>
                    
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv4">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>DOB</th>
                            <th>Total Fee</th>
                            <th>Total Paid</th>
                            <th class="dynamic">Current Left</th>
                            <th>Total Left</th>
                            <th>Discount</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php
						$overAllTotal=0;$overAllFee=0;$overAllBus=0;$overAllDiscount=0;
						$overTotal=0;$bptotal=0;$ipremail=0;$bpremail=0;
						if(is_array($result) && count($result)>0){$overFee=0;$overBus=0;$iptotal=0;$ijk=0;
							foreach($result as $detail){$ijk++;
								(int)$total=(int)$detail["total"]+(int)$detail["busfe"];
								(int)$overTotal=(int)$overTotal+(int)$total;
								(int)$overFee=(int)$overFee+(int)$detail["total"];
								(int)$overBus=(int)$overBus+(int)$detail["busfe"];
								$ip=$detail["ip1"]+$detail["ip2"]+$detail["ip3"]+$detail["ip4"]+$detail["ip5"]+$detail["ip6"]+$detail["ip7"]+$detail["ip8"]+$detail["ip9"]+$detail["ip10"]+$detail["ip11"]+$detail["ip12"]+$detail["ip13"]+$detail["ip14"]+$detail["ip15"];
								$iptotal=$ip;
								$bp=$detail["bp1"]+$detail["bp2"]+$detail["bp3"]+$detail["bp4"]+$detail["bp5"]+$detail["bp6"]+$detail["bp7"]+$detail["bp8"]+$detail["bp9"]+$detail["bp10"]+$detail["bp11"]+$detail["bp12"]+$detail["bp13"]+$detail["bp14"]+$detail["bp15"];
								$bptotal=$bp;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $detail["name"]; ?>
                                    <input type="hidden" name="mobile[]" value="<?php echo $detail["mobile"] ?>" />
                                    </td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php echo $detail["dob"]; ?></td>
                                    <td class="MyTotalFee"><?php echo $detail["total"];$overAllTotal=$overAllTotal+$detail["total"];?></td>
                                    <td class="MyTotalpaid"><?php echo $iptotal;$overAllFee=$overAllFee+$iptotal; ?></td>
                                    <th class="MyTotalLeftDynamic dynamic"></th>
                                    <td class="MyTotalLeft"><?php echo $ABC=$detail["total"]-$iptotal;$overAllBus=$overAllBus+$ABC; ?></td>
                                    <td class="MyDiscount"><?php echo $detail["discount"];$overAllDiscount=$overAllDiscount+$detail["discount"]; ?><input type="hidden" name="details[]" value="<?php echo $detail["total"]."-".$iptotal."-".$ABC ?>" /></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="10">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot style="color:#F00">
                    	<tr>
                        	<th colspan="6" align="right">Total</th>
                            <th id="MyTotalFee"><?php echo $overAllTotal ?></th>
                            <th id="MyTotalpaid"><?php echo $overAllFee; ?></th>
                            <th id="MyTotalLeftDynamic" class="dynamic"></th>
                            <th id="MyTotalLeft"><?php echo $overAllBus; ?></th></th>
                            <th id="MyDiscount"><?php echo $overAllDiscount; ?></th></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	
	}
	elseif(isset($_GET["hostel_outstanding"])){
		/*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"];
			$where[]=" (it.date between '$fdate' and '$tdate') ";
		}*/
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]=" i.idno=s.idno and i.total>0 and s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";
		$table=" hostelinstallment as i, student as s";
		$result=$db->getRows("SELECT i.*,s.class as sclass,s.name,s.medium,s.fname,s.dob,s.mname,s.mobile FROM ".$table." where i.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".implode(" AND ",$where)." group by s.idno order by s.name");
		//echo $db->getLastQuery();
		?>
		 <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 type="button"  onclick="printDiv('printDiv4')" class="btn btn-primary">Print</button>
                    <input style="margin-right:3px;" type="text" placeholder="search by total left" onkeyup="filterPayleft(this)" />
                    <input type="text" placeholder="search by total paid" id="searchfoertotal" onkeyup="filterPay(this)" />
                    <button type="button"  onclick="SMS('school_outstanding')" class="btn btn-primary">SMS</button>
                    
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv4">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>DOB</th>
                            <th>Total Fee</th>
                            <th>Total Paid</th>
                            <th class="dynamic">Current Left</th>
                            <th>Total Left</th>
                            <th>Discount</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php
						$overAllTotal=0;$overAllFee=0;$overAllBus=0;$overAllDiscount=0;
						$overTotal=0;$bptotal=0;$ipremail=0;$bpremail=0;
						if(is_array($result) && count($result)>0){$overFee=0;$overBus=0;$iptotal=0;$ijk=0;
							foreach($result as $detail){$ijk++;
								(int)$total=(int)$detail["total"]+(int)$detail["busfe"];
								(int)$overTotal=(int)$overTotal+(int)$total;
								(int)$overFee=(int)$overFee+(int)$detail["total"];
								(int)$overBus=(int)$overBus+(int)$detail["busfe"];
								$ip=$detail["ip1"]+$detail["ip2"]+$detail["ip3"]+$detail["ip4"]+$detail["ip5"]+$detail["ip6"]+$detail["ip7"]+$detail["ip8"]+$detail["ip9"]+$detail["ip10"]+$detail["ip11"]+$detail["ip12"]+$detail["ip13"]+$detail["ip14"]+$detail["ip15"];
								$iptotal=$ip;
								$bp=$detail["bp1"]+$detail["bp2"]+$detail["bp3"]+$detail["bp4"]+$detail["bp5"]+$detail["bp6"]+$detail["bp7"]+$detail["bp8"]+$detail["bp9"]+$detail["bp10"]+$detail["bp11"]+$detail["bp12"]+$detail["bp13"]+$detail["bp14"]+$detail["bp15"];
								$bptotal=$bp;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $detail["name"]; ?>
                                    <input type="hidden" name="mobile[]" value="<?php echo $detail["mobile"] ?>" />
                                    </td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php echo $detail["dob"]; ?></td>
                                    <td class="MyTotalFee"><?php echo $detail["total"];$overAllTotal=$overAllTotal+$detail["total"];?></td>
                                    <td class="MyTotalpaid"><?php echo $iptotal;$overAllFee=$overAllFee+$iptotal; ?></td>
                                    <th class="MyTotalLeftDynamic dynamic"></th>
                                    <td class="MyTotalLeft"><?php echo $ABC=$detail["total"]-$iptotal;$overAllBus=$overAllBus+$ABC; ?></td>
                                    <td class="MyDiscount"><?php echo $detail["discount"];$overAllDiscount=$overAllDiscount+$detail["discount"]; ?><input type="hidden" name="details[]" value="<?php echo $detail["total"]."-".$iptotal."-".$ABC ?>" /></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="10">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot style="color:#F00">
                    	<tr>
                        	<th colspan="6" align="right">Total</th>
                            <th id="MyTotalFee"><?php echo $overAllTotal ?></th>
                            <th id="MyTotalpaid"><?php echo $overAllFee; ?></th>
                            <th id="MyTotalLeftDynamic" class="dynamic"></th>
                            <th id="MyTotalLeft"><?php echo $overAllBus; ?></th></th>
                            <th id="MyDiscount"><?php echo $overAllDiscount; ?></th></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	
	}
	elseif(isset($_GET["school_fee"])){
		$conwhere="";
		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"];
			$where[]=" (rr.date between '$fdate' and '$tdate') ";
			//$conwhere.=" and  (reff_receipt.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]=" rr.idno=s.idno and s.session='".$_SESSION["admin"]["session"]."' and s.status=1 and rr.type='fee'";
		$table=" reff_receipt as rr, student as s";
		$result=$db->getRows("SELECT rr.*,rr.id as recid,s.class as sclass,s.name,s.medium,s.mname,s.fname,s.gender FROM ".$table." where rr.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".implode(" AND ",$where)." group by rr.id order by rr.date");
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();
		?>
		<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 onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button onclick="SMSComplete('SchoolFeeShw','SchoolFeeShowSMS')" type="button" class="btn btn-primary">SMS</button>
                    
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>Receipt</th>
                            <th>Quater</th>
                            <th>Fee</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $detail["name"]; ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php 
									$rids=array();
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$detail["recid"]){
													$rids[]=$rr["id"];
													//echo "select id from receipt where rrid='".$rrids."'<br />";
												}
											}
										}
									}
									echo implode(",",$rids) ?></td>
                                    <td><?php echo $detail["inst_id"]; ?></td>
                                    <td><?php echo $all=$detail["amount"];
									$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["date"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="7">No Bus and Class record Found</td>
                            </tr><?php
						}
						
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<td colspan="7">Total</td><td id="SchoolFeeShw"><?php echo $ollTotal; ?></td><td></td>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	elseif(isset($_GET["bus_fee"])){
		$conwhere="";
		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"];
			$where[]=" (rr.date between '$fdate' and '$tdate') ";
			//$conwhere.=" and  (reff_receipt.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]="rr.idno=s.idno and s.session='".$_SESSION["admin"]["session"]."' and s.status=1 and rr.type='busfee'";
		$table=" reff_receipt as rr, student as s";
		$result=$db->getRows("SELECT rr.*,rr.id as recid,rr.id as recid,s.class as sclass,s.name,s.medium,s.fname,s.mname,s.gender FROM ".$table." where rr.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".implode(" AND ",$where)." group by rr.id order by rr.date");
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();
		?>
		 <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 onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button onclick="SMSComplete('BusFeeShw','BusFeeShowSMS')" type="button" class="btn btn-primary">SMS</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father </th>
                            <th>Mother </th>
                            <th>Receipt ID</th>
                            <th>Quater</th>
                            <th>Fee</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $detail["name"]; ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php 
									$rids=array();
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$detail["recid"]){
													$rids[]=$rr["id"];
													//echo "select id from receipt where rrid='".$rrids."'<br />";
												}
											}
										}
									}
									echo implode(",",$rids) ?></td>
                                    <td><?php echo $detail["inst_id"]; ?></td>
                                    <td><?php echo $all=$detail["amount"];$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["date"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="7">No Bus and Class record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<td colspan="7">Total</td><td id="BusFeeShw"><?php echo $ollTotal; ?></td><td></td>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	elseif(isset($_GET["hostel_fee"])){
		$conwhere="";
		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"];
			$where[]=" (rr.date between '$fdate' and '$tdate') ";
			//$conwhere.=" and  (reff_receipt.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]=" rr.idno=s.idno and s.session='".$_SESSION["admin"]["session"]."' and s.status=1 and rr.type='hostelfee'";
		$table=" reff_receipt as rr, student as s";
		$result=$db->getRows("SELECT rr.*,rr.id as recid,s.class as sclass,s.name,s.medium,s.mname,s.fname,s.gender FROM ".$table." where rr.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".implode(" AND ",$where)." group by rr.id order by rr.date");
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();
		?>
		<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 onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button onclick="SMSComplete('SchoolFeeShw','SchoolFeeShowSMS')" type="button" class="btn btn-primary">SMS</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>Receipt</th>
                            <th>Quater</th>
                            <th>Fee</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $detail["name"]; ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php 
									$rids=array();
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$detail["recid"]){
													$rids[]=$rr["id"];
													//echo "select id from receipt where rrid='".$rrids."'<br />";
												}
											}
										}
									}
									echo implode(",",$rids) ?></td>
                                    <td><?php echo $detail["inst_id"]; ?></td>
                                    <td><?php echo $all=$detail["amount"];
									$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["date"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="7">No Bus and Class record Found</td>
                            </tr><?php
						}
						
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<td colspan="7">Total</td><td id="SchoolFeeShw"><?php echo $ollTotal; ?></td><td></td>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	elseif(isset($_GET["school_fine"])){
		$conwhere="";
		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"];
			$where[]=" (it.date between '$fdate' and '$tdate') ";
			$conwhere=" and  (installment_fine.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		?>
		 <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 onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button onclick="SMSComplete('SchoolFineFeeShw','SchoolFineFeeShowSMS')" type="button" class="btn btn-primary">SMS</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>Receipt No</th>
                            <th>Quater</th>
                            <th>Fee</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;
						$result=$db->getRows("select student.idno,student.name,student.class as sclass,student.medium,student.fname,student.dob,student.mname,installment_fine.* from installment_fine,student where student.session='".$_SESSION["admin"]["session"]."' and student.issue_TC=0 and installment_fine.ins_name like '%class' and installment_fine.status=1 and installment_fine.idno=student.idno $conwhere order by student.name");
						echo $db->getErMsg();
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $detail["name"]; ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php $detail["id"];
									//echo $db->getVal("select id from receipt where rrid=(select id from reff_receipt where inst_id=".$detail["id"].")"); 
									$rids=array();
									$recpID=$db->getVal("select id from reff_receipt where inst_id='".$detail["id"]."'");
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$recpID){
													$rids[]=$rr["id"];
													//echo "select id from receipt where rrid='".$rrids."'<br />";
												}
											}
										}
									}
									echo implode(",",$rids).$db->getErMsg();
									?></td>
                                    <td><?php $qua=$detail["ins_name"];echo instFine($qua); ?></td>
                                    <td><?php $otfee=str_replace("_detail","_fee",$qua);
									echo $all=$detail["fine"];$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["udate"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="7">No Fine record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<td colspan="7">Total</td><td id="SchoolFineFeeShw"><?php echo $ollTotal; ?></td><td></td>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	elseif(isset($_GET["bus_fine"])){
		$conwhere="";
		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"];
			$where[]=" (it.date between '$fdate' and '$tdate') ";
			$conwhere=" and  (installment_fine.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		?>
		 <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 onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button onclick="SMSComplete('BusFineFeeShw','BusFineFeeShowSMS')" type="button" class="btn btn-primary">SMS</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>Receipt no</th>
                            <th>Quater</th>
                            <th>Fee</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;
						$result=$db->getRows("select student.idno,student.name,student.class as sclass,student.medium,student.mname,student.dob,student.fname,installment_fine.* from installment_fine,student where student.session='".$_SESSION["admin"]["session"]."' and student.issue_TC=0 and  installment_fine.ins_name like '%bus' and installment_fine.status=1 and installment_fine.idno=student.idno $conwhere order by student.name");
						echo $db->getErMsg();
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $detail["name"]; ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php $detail["id"];
									//echo $db->getVal("select id from receipt where rrid=(select id from reff_receipt where inst_id=".$detail["id"].")"); 
									$rids=array();
									$recpID=$db->getVal("select id from reff_receipt where inst_id='".$detail["id"]."'");
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$recpID){
													$rids[]=$rr["id"];
													//echo "select id from receipt where rrid='".$rrids."'<br />";
												}
											}
										}
									}
									echo implode(",",$rids).$db->getErMsg();
									?></td>
                                    <td><?php $qua=$detail["ins_name"];echo instFine($qua); ?></td>
                                    <td><?php $otfee=str_replace("_detail","_fee",$qua);
									echo $all=$detail["fine"];$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["udate"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="9">No Fine record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<td colspan="7">Total</td><td id="BusFineFeeShw"><?php echo $ollTotal; ?></td><td></td>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	elseif(isset($_GET["hostel_fine"])){
		$conwhere="";
		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"];
			$where[]=" (it.date between '$fdate' and '$tdate') ";
			$conwhere=" and  (installment_fine.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		?>
		 <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 onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button onclick="SMSComplete('SchoolFineFeeShw','SchoolFineFeeShowSMS')" type="button" class="btn btn-primary">SMS</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>Receipt No</th>
                            <th>Quater</th>
                            <th>Fee</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;
						$result=$db->getRows("select student.idno,student.name,student.class as sclass,student.medium,student.fname,student.dob,student.mname,installment_fine.* from installment_fine,student where student.session='".$_SESSION["admin"]["session"]."' and student.issue_TC=0 and installment_fine.ins_name like '%hostel' and installment_fine.status=1 and installment_fine.idno=student.idno $conwhere order by student.name");
						echo $db->getErMsg();
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $detail["name"]; ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php $detail["id"];
									//echo $db->getVal("select id from receipt where rrid=(select id from reff_receipt where inst_id=".$detail["id"].")"); 
									$rids=array();
									$recpID=$db->getVal("select id from reff_receipt where inst_id='".$detail["id"]."'");
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$recpID){
													$rids[]=$rr["id"];
													//echo "select id from receipt where rrid='".$rrids."'<br />";
												}
											}
										}
									}
									echo implode(",",$rids).$db->getErMsg();
									?></td>
                                    <td><?php $qua=$detail["ins_name"];echo instFine($qua); ?></td>
                                    <td><?php $otfee=str_replace("_detail","_fee",$qua);
									echo $all=$detail["fine"];$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["udate"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="7">No Fine record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<td colspan="7">Total</td><td id="SchoolFineFeeShw"><?php echo $ollTotal; ?></td><td></td>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	elseif(isset($_GET["other_fee"])){
		$conwhere="";
		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"];
			$where[]=" (it.date between '$fdate' and '$tdate') ";
			$conwhere=" and  (installment_fine.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		?>
		 <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 onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button onclick="SMSComplete('OtherFineFeeShw','OtherFineFeeShowSMS')" type="button" class="btn btn-primary">SMS</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>Receipt no</th>
                            <th>Quater</th>
                            <th>Fee</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;
					
						$result=$db->getRows("select student.idno,student.name,student.class as sclass,student.medium,student.fname,student.dob,student.mname,installment_fine.* from installment_fine,student where student.school_id='".$_SESSION["admin"]["school_id"]."' and student.session='".$_SESSION["admin"]["session"]."' and student.issue_TC=0 and (installment_fine.ins_name not like '%bus' and installment_fine.ins_name not like '%class' and installment_fine.ins_name not like '%hostel') and  installment_fine.status=1 and installment_fine.fine!='' and installment_fine.idno=student.idno $conwhere order by student.name");
						echo $db->getErMsg();
						if(is_array($result) && count($result)>0){$ij=0;
							foreach($result as $detail){$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $detail["name"]; ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php $detail["id"];
									//echo $db->getVal("select id from receipt where rrid=(select id from reff_receipt where inst_id=".$detail["id"].")"); 
									$rids=array();
									$recpID=$db->getVal("select id from reff_receipt where inst_id='".$detail["id"]."'");
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$recpID){
													$rids[]=$rr["id"];
													//echo "select id from receipt where rrid='".$rrids."'<br />";
												}
											}
										}
									}
									echo implode(",",$rids).$db->getErMsg();
									?></td>
                                    <td><?php $qua=$detail["ins_name"];echo instFine($qua); ?></td>
                                    <td><?php $otfee=str_replace("_detail","_fee",$qua);
									echo $all=$detail["fine"];$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["udate"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="9">No Fine record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<td colspan="7">Total</td><td id="OtherFineFeeShw"><?php echo $ollTotal; ?></td><td></td>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	elseif(isset($_GET["combine_fee"])){
		$conwhere="";
		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"];
			$where[]=" (rr.date between '$fdate' and '$tdate') ";
			$conwhere.=" and  (installment_fine.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]=" rr.idno=s.idno and s.session='".$_SESSION["admin"]["session"]."' and (rr.type='fee') and s.status=1 ";
		$table=" reff_receipt as rr, student as s";
		$result=$db->getRows("SELECT rr.*,rr.id as recid,s.class as sclass,s.name,s.medium,s.fname,s.dob,s.mname FROM ".$table." where rr.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0  AND ".implode(" AND ",$where)." group by rr.id order by rr.date");
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();
		?>
		 <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 onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button onclick="SMSComplete('completeFeeShw','completeFeeShowSMS')" type="button" class="btn btn-primary">SMS</button>
                    
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table" id="example_new">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>Receipt ID</th>
                            <th>Quater</th>
                            <th width="100px">Fee</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=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["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php 
									$rids=array();
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$detail["recid"]){
													$rids[]=$rr["id"];
													//echo "select id from receipt where rrid='".$rrids."'<br />";
												}
											}
										}
									}
									echo implode(",",$rids) ?></td>
                                    <td><?php $ins_iods = $detail["inst_id"];//" (".($detail["type"] == "fee" ? "School Fee" : "Bus Fee").")";
									if($detail["type"]=="fee")
										echo "<span style='color:#FF0000'>$ins_iods(School Fee)</span>";
									else if($detail["type"]=="busfee")
										echo "<span style='color:#00CC00'>$ins_iods(Transport Fee)</span>"; 
									else if($detail["type"]=="hostelfee") 
										echo "<span style='color:#FF00FF'>$ins_iods(Hostel Fee)</span>";							
									 ?></td>
                                    <td><?php echo $all=$detail["amount"];
									$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["date"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?>
                            <tr>
                            	<td colspan="9">No Bus and Class record Found</td>
                            </tr>
							<?php
						}
						$result=$db->getRows("select student.idno,student.name,student.class as sclass,student.medium,student.fname,student.dob,student.mname,installment_fine.* from installment_fine,student where student.school_id='".$_SESSION["admin"]["school_id"]."' and student.session='".$_SESSION["admin"]["session"]."' and student.issue_TC=0 and installment_fine.status=1 and installment_fine.fine!='' and installment_fine.idno=student.idno $conwhere order by student.name");
						echo $db->getErMsg();
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $detail["name"]; ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php $detail["id"];
									//echo $db->getVal("select id from receipt where rrid=(select id from reff_receipt where inst_id=".$detail["id"].")"); 
									$rids=array();
									$recpID=$db->getVal("select id from reff_receipt where inst_id='".$detail["id"]."'");
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$recpID){
													$rids[]=$rr["id"];
													//echo "select id from receipt where rrid='".$rrids."'<br />";
												}
											}
										}
									}
									echo implode(",",$rids).$db->getErMsg();
									?></td>
                                    <td><?php $qua=$detail["ins_name"];echo instFine($qua); ?></td>
                                    <td><?php $otfee=str_replace("_detail","_fee",$qua);
									echo $all=$detail["fine"];$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["udate"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="9">No Fine record Found</td>
                            </tr><?php
						}
						?>
                        
                    </tbody>
                    <tfoot><tr style="border-top:1px solid #F00; color:#F00">
                        <td colspan="5">Total</td><td></td><td></td><td id="completeFeeShw"><?php echo $ollTotal; ?></td><td></td>
                        </tr></tfoot>
                 </table>
                 
              </div>
          </div>
          </div>
		<?php
	}
	elseif(isset($_GET["other_fix_fee"])){
		$conwhere="";
		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"];
			$where[]=" (it.date between '$fdate' and '$tdate') ";
			$conwhere=" and  (installment_fine.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		if(isset($_GET["optype"]) && trim($_GET["optype"])!=""){
			//$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and installment_fine.reasion='".$_GET["optype"]."' ";
		}
		//optype
		?>
		 <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 onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button onclick="SMSComplete('OtherFineFeeShw','OtherFineFeeShowSMS')" type="button" class="btn btn-primary">SMS</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>Serial No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>Receipt no</th>
                            <th>Reasion</th>
                            <th>Quater</th>
                            <th>Fee</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php 
						$ollTotal=0;
						
						$result=$db->getRows("select installment_fine.reasion,student.idno,student.name,student.class as sclass,student.medium,student.fname,student.dob,student.mname,installment_fine.* from installment_fine,student where student.school_id='".$_SESSION["admin"]["school_id"]."' and student.session='".$_SESSION["admin"]["session"]."' and student.issue_TC=0 and (installment_fine.ins_name not like '%bus' and installment_fine.ins_name not like '%class' and installment_fine.ins_name not like '%hostel' and installment_fine.ins_name not like '%-extra%') and  installment_fine.status=1 and installment_fine.fine!='' and installment_fine.idno=student.idno $conwhere order by student.name");
						echo $db->getErMsg();
						if(is_array($result) && count($result)>0){$ij=0;
							foreach($result as $detail){$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo $detail["name"]; ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php $detail["id"];
									//echo $db->getVal("select id from receipt where rrid=(select id from reff_receipt where inst_id=".$detail["id"].")"); 
									$rids=array();
									$recpID=$db->getVal("select id from reff_receipt where inst_id='".$detail["id"]."'");
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$recpID){
													$rids[]=$rr["id"];
													//echo "select id from receipt where rrid='".$rrids."'<br />";
												}
											}
										}
									}
									echo implode(",",$rids).$db->getErMsg();
									?></td>
                                     <td><?php echo $detail["reasion"]; ?></td>
                                    <td><?php $qua=$detail["ins_name"];echo instFine($qua); ?></td>
                                    <td><?php $otfee=str_replace("_detail","_fee",$qua);
									echo $all=$detail["fine"];$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["udate"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="9">No Fine record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<td colspan="8">Total</td><td id="OtherFineFeeShw"><?php echo $ollTotal; ?></td><td></td>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}
	elseif(isset($_GET["demand_bill"])){
		$where="";
		if(isset($_GET["section"]) && $_GET["section"]!=""){
			$where=" section='".$_GET["section"]."' ";
			$conwhere.=" and student.section='".$_GET["section"]."' ";
		}
		?> <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">
                    <?php
                        if(isset($_GET["class"]) && $_GET["class"]!="" && isset($_GET["fmonth"]) && $_GET["fmonth"]!=""){
							?><button type="button" onclick="window.location='<?php echo URL_ROOT ?>print/?page_id=demand_bill&class=<?php echo $_GET["class"] ?>&month=<?php echo $_GET["fmonth"]?>&section=<?php echo $_GET["section"] ?>&idno='+$('#idno').val()" name="other_fix_fee" class="btn btn-primary"> Print Demand Bill</button><?php
						}
						?>
                </div>
            </div>
            <div class="well no-padding" id="printDiv"><?php
			if($_REQUEST["section"]=='')
		$subjects=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."'  and session='".$_SESSION["admin"]["session"]."'  and status='1' order by name");
	else{
		$subjects=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and section='".$_REQUEST["section"]."' and session='".$_SESSION["admin"]["session"]."'  and status='1' order by name");
		
	}
	?><select name="idno" id="idno" class="span6"><?php
	if(is_array($subjects) && count($subjects)>0){
		?><option value="">All Student</option><?php
		foreach($subjects as $cla){
			?>
			<option value="<?php echo $cla["idno"] ?>">
				<?php echo $cla["name"] ?>
			</option>
			<?php
		}
	}
	?></select>
	</div></div>
	
	<?php
	}
	elseif(isset($_GET["monthly_demand_bill"])){
		?> <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">
                    <?php
                        if(isset($_GET["class"]) && $_GET["class"]!=""){
							?><a target="_blank"><button type="button" onclick="window.location='<?php echo URL_ROOT ?>print/?page_id=monthly_demand_bill&section=<?php echo $_GET["section"] ?>&class=<?php echo $_GET["class"] ?>&idno='+$('#idno').val()"  name="other_fix_fee" class="btn btn-primary"> Print Demand Bill</button></a><?php
						}
						?>
                </div>
            </div>
            <div class="well no-padding" id="printDiv"><?php
		$subjects=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' and section='".$_GET["section"]."' order by name");
		
	//	echo "select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' and section='".$_GET["section"]."' order by name";
	?><select name="idno" id="idno" class="span6"><?php
	if(is_array($subjects) && count($subjects)>0){
		?><option value="">All Student</option><?php
		foreach($subjects as $cla){
			?>
			<option value="<?php echo $cla["idno"] ?>">
				<?php echo $cla["name"] ?>
			</option>
			<?php
		}
	}
	?></select>
	</div></div>
	
	<?php
	}

	elseif(isset($_GET["sms_demand_bill"])){
		?> <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">
                    <?php
                        if(isset($_GET["class"]) && $_GET["class"]!="" && isset($_GET["fmonth"]) && $_GET["fmonth"]!=""){
							?>
                            <!--<button type="button" onclick="window.location='<?php echo URL_ROOT ?>print/?page_id=demand_bill&class=<?php echo $_GET["class"] ?>&month=<?php echo $_GET["fmonth"]?>&idno='+$('#idno').val()" name="other_fix_fee" class="btn btn-primary"> Print Demand Bill</button>-->
                             <!--<button onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>-->
							 
							 
					 <a href="print/?page_id=sms_pre&fmonth=<?php echo $_GET["fmonth"] ?> &class=<?php echo $_GET["class"] ?>&section=<?php echo $_GET["section"] ?>" class="btn btn-danger fancybox">Sms Prev</a>
							 
							 
                    <button onclick="SMS('sms_demand_bill')" type="button" class="btn btn-primary">SMS</button>
					
					
                  
					
							<?php
						}
						?>
                </div>
            </div>
           
            <div class="well no-padding" id="printDiv"><?php
if(isset($_GET['class']) && trim($_GET['class']) !='')
{ 
	  $month=0;
	  if($_GET["fmonth"]<=3){
		$month=$_GET["fmonth"]+9;
	  }
	  else{
		$month=($_GET["fmonth"]-3);
	  }
	  
	  $where="";
	  if(isset($_GET['idno']) && trim($_GET['idno']) !='')$where=" and idno=".$_GET['idno'];
	if($_GET["section"]==''){
	$aryForms=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and (status=1 or status=2) and class='".$_GET["class"]."'  $where order by name");
	}
	
	else{
			$aryForms=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and (status=1 or status=2) and class='".$_GET["class"]."'  and section='".$_GET["section"]."' $where order by name");
		
	}
	//echo count($aryForms);
	
	if(is_array($aryForms) && count($aryForms)>0)
	{	$ij=0;
		foreach($aryForms as $aryForm)
		{ $ij++;
			$_GET["id"]=$aryForm["idno"]; $totalBus=0;$totalFee=0;
			//if($ij==6)exit;
?>	
     <div id="demand-<?php echo $ij; ?>" style="height:158px;margin:20px 0px;border-bottom:1px dotted red;">
   		<div class="row-fluid">
        <div class="span12">
        <table class="table" cellpadding="0" cellspacing="0" width="100%" border="1">
        <tr>
        	<td> <input type="hidden" name="mobile[]" value="<?php echo $aryForm["mobile"] ?>" />
        	     <input type="hidden" name="idno[]" value="<?php echo $aryForm["idno"] ?>" />
            	
            	<div class="span12">
                	<ul class="unstyled">
                      <li class="size"><strong class="st">Name</strong> : <?php echo $aryForm["name"] ?></li>
                      <li class="size"><strong class="st">Adm no</strong> : <?php echo $aryForm["admissionno"] ?></li>
                    </ul>
            	</div>
            </td>
            <td>
                <div class="span12">
                	<ul class="unstyled">
                      <li class="size"><strong class="st">Class</strong> : <?php echo $aryForm["class"] ?>- <?php echo $aryForm["section"] ?></li>
                      <li class="size"><strong class="st">Father</strong> : <?php echo $aryForm["fname"] ?></li>
                    </ul>
            	</div>
            </td>
            <td>
				<div class="span12">
                	<ul class="unstyled">
                      <li class="size"><strong class="st">Contact</strong> : <?php echo $aryForm["mobile"] ?></li>
                      <li class="size"><strong class="st" style="width:110px">Last Paid Date</strong> : <?php $udate=$db->getVal("select date from installment_time where idno='".$aryForm["idno"]."'");if($udate!="") echo date("d/F/Y",strtotime($udate));//echo $db->getErMsg().$db->getLastQuery(); ?></li>
                    </ul>
            	</div>
            </td>
        </tr>
        </table>
        </div>
        </div>
       
    	 <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <center><em><strong><i class="icon-cog"></i> Remaining fee for 
				<?php $newMyDate=date("Y")."-".($_GET["fmonth"])."-1";
					echo date("F",strtotime($newMyDate)); ?> month</strong></em></center>
            </div>
            <div class="well no-padding">
                    <?php 
						$aryInstall=$db->getRow("select * from installment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and session='".$_SESSION["admin"]["session"]."'");
						$feeCount=array();$totalFee=0;$totalBus=0;$totalhostel=0;$extraFee=array();$totalExtra=0;$total=0;$dues=0;$duesother=0;
						$totalother=0;$totalhostelother=0;
						for($i=1;$i<=$month;$i++){
							$iis="i".$i;
							$iip="ip".$i;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalclasspayfee=$totalclasspayfee+$aryInstall[$iip];
								$is_rr=false;
								if($aryInstall[$iip]>0){}else{
									$totalFee+=$aryInstall[$iis];
								}
							}
						}
						$ji=0;
						for($i=1;$i<=$month;$i++){
							$iis="b".$i;
							$iip="bp".$i;$is_rr=false;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalbuspayfee=$totalbuspayfee+$aryInstall[$iip];$ji++;
								$is_rr=false;
								if($aryInstall[$iip]>0){}else{
									  $totalBus+=$aryInstall[$iis]; 
								}
							}
						}
						$aryInstall=$db->getRow("select * from hostelinstallment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and session='".$_SESSION["admin"]["session"]."'");
						for($i=1;$i<=$month;$i++){
							$iis="i".$i;
							$iip="ip".$i;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalclasspayfee=$totalclasspayfee+$aryInstall[$iip];
								$is_rr=false;
								if($aryInstall[$iip]>0){}else{
									$totalhostel+=$aryInstall[$iis];
								}
							}
						}
						$checkextFee=$db->getRows("select * from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'");	
						if(is_array($checkextFee) && count($checkextFee)>0){
							foreach($checkextFee as $chkExtFee){
								for($i=1;$i<=$month;$i++){
									$iip="p".$i;
									$mycheckInstall=$db->getRow("select fee,pay from extrafee where idno='".$_GET["id"]."' and type='".$chkExtFee["id"]."' and pid='".$iip."'");
									if($mycheckInstall["fee"]>0){
										$type=$chkExtFee["type"];
										if($mycheckInstall["pay"]==0 || $mycheckInstall["pay"]=="")
										$extraFee[$type]=$extraFee[$type]+$mycheckInstall["fee"];
										$totalExtra=$totalExtra+$extraFee[$type];
									}
								}
							}
						}$totalExt=0;
						/*$install=$db->getRow("select * from otherfee_structure where otype ='".$aryForm['idno']."' and name like '%b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
						
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRow("select * from installment_fine where idno=".$aryForm['idno']." and reasion = '".$install['name']."'");        if(is_array($installTution) && count($installTution)>0){
								if($install['fee']==$installTution['fine'])
									$dues=0;
								}
							   else 		
								$dues=$install['fee'];
							}*/
						?>
                 <table class="table" cellpadding="0" cellspacing="0" width="100%" border="1">
                 	<tr>
                    	<th>Tution</th>
                        <th>Transport</th>
                        <th>Hostel</th>
                <?php    $stype=$aryForm['stype'];
					if($stype=="old"){
						 $aryother=$db->getRows("select  distinct(name) from otherfee_structure where (otype ='' or otype ='old' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
				    elseif($stype=="new"){ 
						 $aryother=$db->getRows("select  distinct(name) from otherfee_structure where (otype ='' or otype ='new' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
						if(is_array($aryother) && count($aryother)>0){
							
					    		foreach($aryother as $other){?>
                        			<th><?php echo $other['name'] ?></th>
								<?php } }
                       $htype=$aryForm['htype'];
					if($htype=="old"){
						 $aryhostelother=$db->getRows("select  distinct(name) from hostel_otherfee_structure where (otype ='' or otype ='old' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
				    elseif($htype=="new"){ 
						 $aryhostelother=$db->getRows("select  distinct(name) from hostel_otherfee_structure where (otype ='' or otype ='new' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
					else $aryhostelother=0;		
						if(is_array($aryhostelother) && count($aryhostelother)>0){ $c=0;
					    		foreach($aryhostelother as $other){$c++;?>
                        			<th class="hostelother<?php echo $ij.$c ?>"><?php echo $other['name'] ?></th>
								<?php } } ?>                  
                       <!-- <th>Back Dues</th>-->
                        <?php foreach($extraFee as $key=>$value){ ?>
                        <th><?php echo $key ?></th>
                        <?php }?>
                        <th>TOTAL</th>
                    </tr>
                    <tr>
                    	<th><?php echo $totalFee; ?></th>
                        <th><?php echo $totalBus; ?></th>
                        <th><?php echo $totalhostel; ?></th>
                <?php if($stype=="old"){
						 $aryother=$db->getRows("select * from otherfee_structure where (otype ='' or otype ='old' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
				    elseif($stype=="new"){ 
						 $aryother=$db->getRows("select * from otherfee_structure where (otype ='' or otype ='new' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); } 
						 //echo $db->getLastQuery();
						 if(is_array($aryother) && count($aryother)>0){
					    	foreach($aryother as $other){
								$installOther=$db->getRows("select * from installment_fine where idno=".$aryForm['idno']." and reasion = '".$other['name']."'"); 
														    $total_fine=0;
								$installTution2=$db->getRow("select * from otherfee_discount where idno=".$aryForm['idno']." and other_id='".$other['id']."' and class='".$aryForm["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
								//echo $db->getLastQuery();
								$t=$other['fee'];
								
							if(is_array($installTution2) && count($installTution2)>0){
										 $dis=$installTution2['discount'];
												if($other['fee']==$dis)
													$t=0;
												else 
													$t=$t-$dis;
							 }
					 if($t!=0 && $t<=$other['fee']){
							  if(is_array($installOther) && count($installOther)>0){
									foreach($installOther as $installOther1){
										$total_fine+=$installOther1['fine'];	
										  if($total_fine==$t)	
												$duesother=0;
										   	
										  else
										  	  $duesother=$t-$total_fine;	
							  		}
									if($total_fine!=$t)
										{echo $duesother=$t-$total_fine;}
									if(stripos($other["name"], "b") !== FALSE){
										$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$aryForm['idno']." and reasion like 'remain%' ");							 			 $duesother=$duesother-$installTution_remain;
									}
							  }
							 
							   else 		
									$duesother=$t;
							
					 }
					 else{
						 $duesother=0;
					 }
						$totalother+=$duesother;			
						?>		<th> <?php echo $duesother; ?></th>	
				     <?php } }?>
                   <?php  if($htype=="old"){
						 $aryhostelother=$db->getRows("select * from hostel_otherfee_structure where (otype ='' or otype ='old' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
				    elseif($htype=="new"){ 
						 $aryhostelother=$db->getRows("select * from hostel_otherfee_structure where (otype ='' or otype ='new' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); } 
						 //echo $db->getLastQuery();
					else $aryhostelother=0;		 
						 if(is_array($aryhostelother) && count($aryhostelother)>0){$c=0;
					    	foreach($aryhostelother as $other){$c++;
							
								$installOther=$db->getRows("select * from installment_fine where idno=".$aryForm['idno']." and reasion = '".$other['name']."'");       	    $total_fine=0;
							  $installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$aryForm['idno']." and other_id='".$other['id']."' and class='".$aryForm["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
								$t=$other['fee'];
						//echo $fStudent['idno'];exit;	
							if(is_array($installTution2) && count($installTution2)>0){
										 $dis=$installTution2['discount'];
												if($other['fee']==$dis)
													$t=0;
												else 
													$t=$t-$dis;
							 }
					 if($t!=0 && $t<=$other['fee']){
							  if(is_array($installOther) && count($installOther)>0){
									foreach($installOther as $installOther1){
										$total_fine+=$installOther1['fine'];	
										  if($total_fine==$t)	
												$duesother=0;
										   	
										  else
										  		$duesother=$t-$total_fine;	
							  		}
									if($total_fine!=$t)
										{$duesother=$t-$total_fine;}
									if(stripos($other["name"], "b") !== FALSE){
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$aryForm['idno']." and reasion like 'remain%' ");							  		$duesother=$duesother-$installTution_remain;
									}
							  }
							 
							   else 		
									$duesother=$t;
							
					 }
					 else{
						 $duesother=0;
					 }
						$totalhostelother+=$duesother;			
						?>		<th class="hostelother<?php echo $ij.$c ?>"> <?php echo $duesother; ?></th>	
                        <?php if($duesother==0){?>
                 <script type="text/javascript">$('.hostelother<?php echo $ij.$c ?>').hide()</script>
                        <?php } ?>
				     <?php } }?>
                       <!-- <th><?php echo $dues; ?></th>-->
                        <?php foreach($extraFee as $key=>$value){ ?>
                        <th><?php echo $value;$totalExt+=$value; ?></th>
                        <?php }?>
                        <th><?php echo $total=$totalBus+$totalhostel+$totalFee+$totalExt+$dues+$totalother+$totalhostelother; ?></th>
                    </tr>
                  					
                 </table>
                 
                 <?php if($total==0){?>
                 <script type="text/javascript">$('#demand-<?php echo $ij ?>').hide()</script>
                <!-- <style>#demand<?php echo $ij ?>{display:none;}</style>-->
                 <?php } ?>
                <input type="hidden" name="details[]" value="<?php echo $total."-".$_GET['fmonth']; ?>" />
          </div>
         </div>
    </div>
    </div>
       <br/><br/>
<!-- / Forms -->
<?php
		}
	}
}
?>
		
	</div>
    </div></div>
	
	<?php
	}
	elseif(isset($_GET["extraFee"])){
		$conwhere="";
		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"];
			$where[]=" (rr.date between '$fdate' and '$tdate') ";
			$conwhere.=" and  (installment_fine.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		$where[]=" rr.idno=s.idno and s.session='".$_SESSION["admin"]["session"]."' and rr.type='extrafee".$_GET["extraFee"]."' and s.status=1 ";
		$table=" reff_receipt as rr, student as s";
		$result=$db->getRows("SELECT rr.*,rr.id as recid,s.class as sclass,s.name,s.medium,s.fname,s.dob,s.mname FROM ".$table." where rr.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0  AND ".implode(" AND ",$where)." group by rr.id order by rr.date");
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();
		?>
		 <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 onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button onclick="SMSComplete('completeFeeShw','completeFeeShowSMS')" type="button" class="btn btn-primary">SMS</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table tableSummery" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>S. No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>Receipt ID</th>
                            <th>Quater</th>
                            <th>Fee</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;$ijk=0;
						if(is_array($result) && count($result)>0)
						{
							foreach($result as $detail)
							{$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo ucfirst($detail["name"]); ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                    <td><?php 
									$rids=array();
									$rrde=$db->getRows("select * from receipt where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."'");
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rel_rrid=explode("-",$rr["rrid"]);
											foreach($rel_rrid as $rrids){
												if($rrids==$detail["recid"]){
													$rids[]=$rr["id"];
												}
											}
										}
									}
									echo implode(",",$rids) ?></td>
                                    <td><?php $ins_iods = $detail["inst_id"];//." (".($detail["type"] == "fee" ? "School Fee" : "Bus Fee").")" 
									if($detail["type"]=="fee")
										echo "<span style='color:#FF0000'>$ins_iods(School Fee)</span>";
									else if($detail["type"]=="busfee")
										echo "<span style='color:#00CC00'>$ins_iods(Transport Fee)</span>"; 
									else if($detail["type"]=="hostelfee") 
										echo "<span style='color:#FF00FF'>$ins_iods(Hostel Fee)</span>";
									else{
										$det=$db->getVal("select type from extrafee_type where id='".str_replace("extrafee","",$detail["type"])."'");
										echo "<span style='color:#FF0000'>$ins_iods($det)</span>";
									}?></td>
                                    <td><?php echo $all=$detail["amount"];
									$ollTotal=$ollTotal+$all; ?></td>
                                    <td><?php echo $detail["date"]; ?></td>
                                </tr>
								<?php
							}
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr style="border-top:1px solid #F00; color:#F00">
                        	<td colspan="5">Total</td><td></td><td></td><td id="completeFeeShw"><?php echo $ollTotal; ?></td><td></td>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
          </div>
		<?php
	}
	elseif(isset($_GET["ChequeDetail"])){
		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"];
			$where[]=" (ch.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
		}
		$where[]=" ch.status!='' ";
		$table=" chequefee as ch, student as s";
		$result=$db->getRows("SELECT ch.*,s.class as sclass,s.name,s.medium,s.fname,s.dob,s.mname FROM ".$table." where ch.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0  AND ".implode(" AND ",$where)." group by ch.id order by ch.udate");
		?>
		 <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 onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table tableSummery" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>S. No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>Cheque No</th>
                            <th>Receipt ID</th>
                            <th>Amount</th>
                            <th>Bank name</th>
                            <th>Date</th>
                            <th>Detail</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;$ijk=0;
						if(is_array($result) && count($result)>0)
						{
							foreach($result as $detail)
							{$ijk++;
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo ucfirst($detail["name"]); ?></td>
                                    <td><?php echo $detail["sclass"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["number"]; ?></td>
                                    <td><?php echo $detail["rid"] ?></td>
                                    <td><?php echo $detail["bankname"] ?></td>
                                    <td><?php echo $detail["amount"] ?></td>
                                    <td><?php echo $detail["udate"]; ?></td>
                                    <td><?php echo $detail["detail"]; ?></td>
                                    <td><?php echo $detail["status"] ?></td>
                                </tr>
								<?php
							}
						}
						?>
                    </tbody>
                    
                 </table>
              </div>
          </div>
          </div>
		<?php
	}
	elseif(isset($_GET['delete_report'])){
		
		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"];
			$where[]=" (ch.udate between '$fdate' and '$tdate') ";
		}
		
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
		}
		
		$where[]=" ch.status!='' ";
		$table=" delete_report as ch, student as s";
		$result=$db->getRows("SELECT ch.*,s.class as sclass,s.name,s.fname,s.mname FROM ".$table." where ch.school_id='".$_SESSION["admin"]["school_id"]."' and ch.session='".$_SESSION["admin"]["session"]."' and s.issue_TC=0 and ch.paytype!='enquiry' AND ".implode(" AND ",$where)." group by ch.id order by ch.udate");
		//echo $db->getLastQuery();
		?>
		 <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 onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table tableSummery" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>S. No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>fee</th>
                            <th>Receipt No</th>
                            <th>Amount</th>
                            <th>Type</th>
                            <th>Date</th>
                                                   
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;$ijk=0;
						if(is_array($result) && count($result)>0)
						{
							foreach($result as $detail)
							{$ijk++;
							$stu=$db->getRow("Select * from student where idno='".$detail['idno']."' and status =1 and issue_TC=0");
							$ollTotal+=$detail["amount"];
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo ucfirst($stu["name"]); ?></td>
                                    <td><?php echo $stu["class"]; ?></td>
                                    <td><?php echo $stu["fname"]; ?></td>
                                    <td><?php echo $detail["detail"]; ?></td>
                                    <td><?php echo $detail["receipt_id"]; ?></td>     
                                    <td><?php echo $detail["amount"] ?></td>
                                    <td><?php echo $detail["paytype"]; ?></td>
                                    <td><?php echo $detail["udate"]; ?></td>
                                    
                                    
                                </tr>
								<?php
							}
						}
						?>
                    </tbody>
                    <tfoot>
                    <tr>
                    <td colspan="5">Total</td>
                    <td><?php echo $ollTotal;?></td>
                    </tr>
                  </tfoot>  
                 </table>
              </div>
          </div>
          </div>
		<?php
	
	}
	elseif(isset($_GET['pocket_delete_report'])){
		
		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"];
			$where[]=" (ch.udate between '$fdate' and '$tdate') ";
		}
		
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
		}
		
		$where[]=" ch.status!='' ";
		$table=" pocket_delete_report as ch, student as s";
		$result=$db->getRows("SELECT ch.*,s.class as sclass,s.name,s.fname,s.mname FROM ".$table." where ch.school_id='".$_SESSION["admin"]["school_id"]."' and ch.session='".$_SESSION["admin"]["session"]."' and s.issue_TC=0 and ch.paytype!='enquiry' AND ".implode(" AND ",$where)." group by ch.id order by ch.udate");
		//echo $db->getLastQuery();
		?>
		 <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 onclick="printDiv('printDiv')" type="button" class="btn btn-primary">Print</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv">
            	<table class="table tableSummery" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>S. No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Father</th>
                            <th>fee</th>
                            <th>Receipt No</th>
                            <th>Amount</th>
                            <th>Type</th>
                            <th>Date</th>
                                                   
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $ollTotal=0;$ijk=0;
						if(is_array($result) && count($result)>0)
						{
							foreach($result as $detail)
							{$ijk++;
							$stu=$db->getRow("Select * from student where idno='".$detail['idno']."' and status =1 and issue_TC=0");
							$ollTotal+=$detail["amount"];
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo ucfirst($stu["name"]); ?></td>
                                    <td><?php echo $stu["class"]; ?></td>
                                    <td><?php echo $stu["fname"]; ?></td>
                                    <td><?php echo $detail["detail"]; ?></td>
                                    <td><?php echo $detail["receipt_id"]; ?></td>     
                                    <td><?php echo $detail["amount"] ?></td>
                                    <td><?php echo $detail["paytype"]; ?></td>
                                    <td><?php echo $detail["udate"]; ?></td>
                                    
                                    
                                </tr>
								<?php
							}
						}
						?>
                    </tbody>
                    <tfoot>
                    <tr>
                    <td colspan="5">Total</td>
                    <td><?php echo $ollTotal;?></td>
                    </tr>
                  </tfoot>  
                 </table>
              </div>
          </div>
          </div>
		<?php
	
	}
	
    elseif(isset($_GET["discount_mode_detail"])){
		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"];
			$where[]=" (s.udate between '$fdate' and '$tdate') ";
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and student.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and student.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and student.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["section"]) && $_GET["section"]!=""){
			$where[]=" s.section='".$_GET["section"]."' ";
			$conwhere.=" and student.section='".$_GET["section"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and student.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and student.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (student.dob between '".$end."' and '".$start."') ";
		}
		if(isset($_GET["location"]) && trim($_GET["location"])!=""){
			$where[]=" s.location='".$_GET["location"]."' ";
			$conwhere.=" and student.location='".$_GET["location"]."' ";
		}
		
		if(isset($_GET["discount_mode"]) && trim($_GET["discount_mode"])!=""){
			$where[]=" s.discount_mode='".$_GET["discount_mode"]."' ";
			$conwhere.=" and student.discount_mode='".$_GET["discount_mode"]."' ";
		}
		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";
		$table=" student as s";
		$result=$db->getRows("SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".implode(" AND ",$where)." order by s.name");
		//echo $ss="SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".implode(" AND ",$where)." order by s.name";
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();		echo $db->getErMsg();
		?>
		 <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">
				<!--<input  class="btn btn-primary" type="button"  onclick="$('.table').tableExport({type:'excel',escape:'false'});" id="btnExport" value=" Export To Excel " />-->
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">
            	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th>S.No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Sec</th>
                            <th>Sex</th>
                            <th>DOB</th>
                            <th>Father</th>
                            <th>Mother</th>
                            <th>Adm.Date</th>
                            <th>address</th>
                            
                            <th>Mobile</th>
                            <th>Adm. no</th>
                            <th>Roll. no</th>
                            <th>R</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php
						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["section"]; ?></td>
                                    <td><?php echo $detail["gender"]; ?></td>
                                    <td><?php if($detail["dob"]!="")echo date("d-M-Y",strtotime($detail["dob"])); ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mname"]; ?></td>
                                     <td><?php echo $detail["doa"]; ?></td>
                                    <td><?php echo $detail["address"]; ?></td>
                                    <td><?php echo $detail["mobile"]; ?></td>
                                    
                                    <td><?php echo $detail["admissionno"]; ?></td>
                                    <td><?php echo $detail["feducation"]; ?></td>
                                    <td><?php echo $detail["sssmid"]; ?></td>
                                </tr>
								<?php
							}
						}else{
							?><tr>
                            <td colspan="10">No record Found</td>
                            </tr><?php
						}
						?>
                    </tbody>
                    <tfoot>
                    	<tr>
                        	<th colspan="10"></th>
                        </tr>
                    </tfoot>
                 </table>
              </div>
          </div>
		<?php
	}	
		
	elseif(isset($_GET["discount_detail"])){
		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"];
			$where[]=" (s.udate between '$fdate' and '$tdate') ";
			$conwhere="  and b.date between '$fdate' and '$tdate' ";
			
		$extrawhere="  and date >= '$fdate' and date <= '$tdate' ";	
		}
		if(isset($_GET["stype"]) && trim($_GET["stype"])!=""){
			$where[]=" s.stype='".$_GET["stype"]."' ";
			$conwhere.=" and s.stype='".$_GET["stype"]."' ";
		}
		if(isset($_GET["medium"]) && trim($_GET["medium"])!=""){
			$where[]=" s.medium='".$_GET["medium"]."' ";
			$conwhere.=" and s.medium='".$_GET["medium"]."' ";
		}
		if(isset($_GET["class"]) && trim($_GET["class"])!=""){
			$where[]=" s.class='".$_GET["class"]."' ";
			$conwhere.=" and s.class='".$_GET["class"]."' ";
		}
		if(isset($_GET["section"]) && $_GET["section"]!=""){
			$where[]=" s.section='".$_GET["section"]."' ";
			$conwhere.=" and s.section='".$_GET["section"]."' ";
		}
		if(isset($_GET["gender"]) && trim($_GET["gender"])!=""){
			$where[]=" s.gender='".$_GET["gender"]."' ";
			$conwhere.=" and s.gender='".$_GET["gender"]."' ";
		}
		if(isset($_GET["cast"]) && trim($_GET["cast"])!=""){
			$where[]=" s.cast='".$_GET["cast"]."' ";
			$conwhere.=" and s.cast='".$_GET["cast"]."' ";
		}
		if(isset($_GET["startage"]) && trim($_GET["startage"])!="" && isset($_GET["endage"]) && trim($_GET["endage"])!=""){
			$start = date('Y-m-d', strtotime('-'.$_GET["startage"].' years'));
			$end = date('Y-m-d', strtotime('-'.$_GET["endage"].' years'));
			$where[]=" (s.dob between '".$end."' and '".$start."')";
			$conwhere.=" and (s.dob between '".$end."' and '".$start."') ";
		}
		if(isset($_GET["location"]) && trim($_GET["location"])!=""){
			$where[]=" s.location='".$_GET["location"]."' ";
			$conwhere.=" and s.location='".$_GET["location"]."' ";
		}
		if(isset($_GET["discount_mode"]) && trim($_GET["discount_mode"])!=""){
			$where[]=" s.discount_mode='".$_GET["discount_mode"]."' ";
			$conwhere.=" and s.discount_mode='".$_GET["discount_mode"]."' ";
		}
		$where[]=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1 ";
		$table=" student as s";
		
		$result=$db->getRows("select b.idno,b.discount_amount,b.installment,b.type,b.session,b.school_id,b.date,b.added_by,s.idno,s.class,s.section,s.name,s.fname,s.mobile from discount_detail as b inner join student as s on b.idno=s.idno  where b.session='".$_SESSION["admin"]["session"]."' and b.school_id='".$_SESSION["admin"]["school_id"]."'$conwhere group by b.idno ");
		 $s="select b.idno,b.discount_amount,b.installment,b.type,b.session,b.school_id,b.date,b.added_by,s.idno,s.class,s.section,s.name,s.fname,s.mobile from discount_detail as b inner join student as s on b.idno=s.idno  where b.school_id='".$_SESSION["admin"]["school_id"]."'$conwhere group by b.idno  ";
		//echo "<pre>";print_r($result);echo "</pre>";echo $db->getLastQuery();		echo $db->getErMsg();
		?>
		 <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 type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                    <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">
                <h5>Detail-<?php echo $_GET["discount_mode"]?> </h5>
                  	<table class="table" id="tblData" border="1">
                    <thead>
                        <tr>
                            <th width="5%">S.No</th>
                            <th>Name</th>
                            <th>Class</th>
                            <th>Sec</th>
                            <th>Father</th>                    
                            <th>Mobile</th>
							
                            <th>Discount By</th>
                            <th>Fee</th>
                            <th>Bus Fee</th>
                            <th>Hostel Fee</th>
							 <th>Hostel Other</th>
                            <th>Extra Fee</th>
                            <th>Other fee</th>
                            <th>Total</th>
                        </tr>
                    </thead>
                    <tbody>
                    	<?php $full_total=0;
						if(is_array($result) && count($result)>0){$ijk=0;
							foreach($result as $detail){$ijk++;
							$fee=$busfee=$hostelfee=0;$other_Fee=$total=0;$other_detail=""; $total=0;
							
						$pdate = date("Y-m-d", strtotime($detail["date"]));	
				
								?>
                                <tr>
                                    <td><?php echo $ijk; ?></td>
                                    <td><?php echo ucfirst($detail["name"]); ?></td>
                                    <td><?php echo $detail["class"]; ?></td>
                                    <td><?php echo $detail["section"]; ?></td>
                                    <td><?php echo $detail["fname"]; ?></td>
                                    <td><?php echo $detail["mobile"]; ?></td>
									
                                    <td style="border-right:1px solid #FA0606;"><?php echo $addedby=$db->getVal("SELECT name FROM users  where school_id='".$_SESSION["admin"]["school_id"]."' and id='".$detail["added_by"]."'"); ?></td>
									
                <?php
     $feeall=$db->getRows("SELECT date FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' GROUP BY DATE_FORMAT(date, '%Y-%m-%d')");
	 
 //$ss="SELECT date FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' GROUP BY DATE_FORMAT(date, '%Y-%m-%d')";
 

				$fee=$db->getVal("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='tution' $extrawhere ");
		//echo 	  $s="SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='tution' and date between '$fdate' and '$tdate'";
				 	  $busfee=$db->getVal("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='bus' $extrawhere ");
					  
					   $s="SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='bus' and date_format(date, '%Y-%m-%d')='".$pdate = date("Y-m-d", strtotime($detail["date"]))."'";
					  $hostelfee=$db->getVal("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='hostel' $extrawhere ");
					  
	    $hostelother=$db->getVal("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='hostelother' $extrawhere ");

					  $extrafee=$db->getval("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='extra' $extrawhere ");
					
					 $otherfee=$db->getval("SELECT sum(discount_amount) FROM discount_detail where  school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$detail["idno"]."' and type='otherfee' $extrawhere ");
					
					 /* 
					  foreach($otherfee as $other){
						  $other_fee+=$other["discount"];
						  $other_detail[]=$other["detail"];
					  } $other_detail=implode(",",$other_detail);
					  */
					  $total=$fee+$busfee+$hostelfee+$hostelother+$extrafee+$otherfee;
					  $full_total+=$total;
					  ?>	
                      			<td style="border-right:1px solid #FA0606;"><?php echo $fee; ?></td>
                                <td style="border-right:1px solid #FA0606;"><?php echo $busfee; ?></td>
                                <td style="border-right:1px solid #FA0606;"><?php echo $hostelfee; ?></td>
                        <td style="border-right:1px solid #FA0606;"><?php echo $hostelother; ?></td>

                                <td style="border-right:1px solid #FA0606;"><?php echo $extrafee; ?></td>
                                <td style="border-right:1px solid #FA0606;"><?php echo $otherfee; ?></td>
                                <td ><?php echo $total; ?></td>
                                </tr>
								<?php
								
							}?>
							<?php  ?>
                        <tr>
                        	<th colspan="13">Total</th>
                            <th><?php echo $full_total; ?></th>
                        </tr>    
				<?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
	}
	//echo "<pre>";print_r($result);echo $db->getLastQuery();
	echo $db->getErMsg();
	
?>

	<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");
		}
	}
	</script>
    <style>
    tfoot{display: table-footer-group !important;}
	.MigrateLeftFee{width:650px !important}
    </style>
    
    
            <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>
    
    
    
    