<?php 
include("../../db.php");
$pgMod="collection_sheet";
$pgAct="view";
?>
<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;}



 .gmaps{margin:0;padding:0;height:400px;border-radius:0 0 5px 5px;overflow:hidden;box-sizing:content-box}
 .gmaps>div>div:nth-child(3),.gmaps>div>div:nth-child(2){display:none}
 .gmaps img{max-width:none}
 .gmaps.map-small{height:200px}
 table.dataTable td,table.dataTable th{padding:12px 0;line-height:24px}
 .table-bordered.table{background-color:#eee;border:1px solid #c2c2c2;box-shadow:0 1px 0 white}
 .table-bordered.table tbody>tr:nth-child(odd)>td,.table-bordered.table .table tbody>tr:nth-child(odd)>td,.table-bordered.table .data-table tbody>tr:nth-child(odd)>td,.table-bordered.table .table-striped tbody>tr:nth-child(odd)>th,.table-bordered.table .table tbody>tr:nth-child(odd)>th,.table-bordered.table .data-table tbody>tr:nth-child(odd)>th,.table-bordered.table tbody tr,.table-bordered.table tbody td,.table-bordered.table th,.table-bordered.table td{border:0;box-shadow:none}
 .table-bordered.table tbody>tr:nth-child(odd)>td,.table-bordered.table .table tbody>tr:nth-child(odd)>td,.table-bordered.table .data-table tbody>tr:nth-child(odd)>td,.table-bordered.table .table-striped tbody>tr:nth-child(odd)>th,.table-bordered.table .table tbody>tr:nth-child(odd)>th,.table-bordered.table .data-table tbody>tr:nth-child(odd)>th,.table-bordered.table tbody tr,.table-bordered.table tbody td,.table-bordered.table th,.table-bordered.table td{border-bottom:1px solid #c2c2c2;border-top:1px solid white}
 .table-bordered.table tbody tr:last-child td{border-bottom:0}
 table.dataTable{margin:0 auto;clear:both;width:100%}
 table.dataTable thead th{cursor:pointer;*cursor:hand}
 table.dataTable thead tr{background:#3B5999}
 .table thead{background:crimson;color:#fff;}
 table.dataTable tfoot th,table.dataTable thead th,table.dataTable thead td{font-weight:bold;background-image:-moz-linear-gradient(bottom,rgba(0,0,0,0.05) 0,rgba(255,255,255,0.05) 100%);background-image:-o-linear-gradient(bottom,rgba(0,0,0,0.05) 0,rgba(255,255,255,0.05) 100%);background-image:-webkit-linear-gradient(bottom,rgba(0,0,0,0.05) 0,rgba(255,255,255,0.05) 100%);background-image:linear-gradient(bottom,rgba(0,0,0,0.05) 0,rgba(255,255,255,0.05) 100%);color:#fff;border-bottom:1px solid #c2c2c2;-webkit-box-shadow:0 2px 0 #fff;-moz-box-shadow:0 2px 0 #fff;box-shadow:0 2px 0 #fff}
 table.dataTable tfoot th:first-child,table.dataTable thead th:first-child{padding-left:20px}
 table.dataTable thead th{border-top:1px solid #c2c2c2;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,0.7),0 2px 0 white;-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,0.7),0 2px 0 white;box-shadow:inset 0 1px 0 rgba(255,255,255,0.7),0 2px 0 white}
 table.dataTable td.center,table.dataTable td.dataTables_empty{text-align:center}
 .dataTables_length select{max-width:50px}
 .dataTables_wrapper{position:relative;clear:both;*zoom:1}
 th.center{text-align:center}
 .dataTables_length{float:left}
 .dataTables_filter{float:right;text-align:right;padding-left:0!important}
 .dataTables_filter,.dataTables_length{padding:24px 20px}
 .dataTables_filter select,.dataTables_length select,.dataTables_filter textarea,.dataTables_length textarea,.dataTables_filter input[type="text"],.dataTables_length input[type="text"],.dataTables_filter input[type="password"],.dataTables_length input[type="password"]{margin:0;margin-left:5px}
 .dataTables_length{padding-top:24px;padding-bottom:23px;padding-right:0;display:none;}
 .dataTables_info{clear:both;float:left;padding:12px 20px;color:blue}
 .dataTables_paginate{float:right;text-align:right;padding:12px 20px}
 .paginate_disabled_previous,.paginate_enabled_previous,.paginate_disabled_next,.paginate_enabled_next{height:18px;float:left;cursor:pointer;*cursor:hand;color:#6b8a41!important}
 .paginate_disabled_previous:hover,.paginate_enabled_previous:hover,.paginate_disabled_next:hover,.paginate_enabled_next:hover{text-decoration:none!important}
 .paginate_disabled_previous:active,.paginate_enabled_previous:active,.paginate_disabled_next:active,.paginate_enabled_next:active{outline:0}
 .paginate_disabled_previous,.paginate_disabled_next{color:#c5c5c5!important}
 .paginate_disabled_previous,.paginate_enabled_previous{padding-left:23px}
 .paginate_disabled_next,.paginate_enabled_next{padding-right:0;margin-left:10px}
 .paging_full_numbers{height:28px}
 .paging_full_numbers a:active{outline:0}
 .paging_full_numbers a:hover{text-decoration:none}
 .paging_full_numbers a.paginate_button,.paging_full_numbers a.paginate_active{border:1px solid #aaa;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;padding:2px 5px;margin:0 3px;cursor:pointer;*cursor:hand;color:#333!important}
 .paging_full_numbers a.paginate_button{background-color: #88DFE2;font-weight: 800}
 .paging_full_numbers a.paginate_button:hover{background-color:#ccc;text-decoration:none!important}
 .paging_full_numbers a.paginate_active{background-color:#99b3ff}
 .dataTables_processing{position:absolute;top:50%;left:50%;width:250px;height:30px;margin-left:-125px;margin-top:-15px;padding:14px 0 2px 0;border:1px solid #ddd;text-align:center;color:#999;background-color:white}
 table.dataTable thead th:active,table.dataTable thead td:active{outline:0}
 .dataTables_scroll{clear:both}
 .dataTables_scrollBody{*margin-top:-1px;-webkit-overflow-scrolling:touch}
 .gallery{padding:24px}
 .gallery .element{display:inline-block;padding:0 1.5% 3% 1.5%;position:relative;text-align:center;width:16%}
 .gallery .element .img-polaroid{padding:5%;border-radius:5px;border:0;background-color:#fcfcfc;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,1),0 2px 4px rgba(0,0,0,0.08),inset 0 -1px 0 rgba(0,0,0,0.25);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,1),0 2px 4px rgba(0,0,0,0.08),inset 0 -1px 0 rgba(0,0,0,0.25);box-shadow:inset 0 1px 0 rgba(255,255,255,1),0 2px 4px rgba(0,0,0,0.08),inset 0 -1px 0 rgba(0,0,0,0.25)}
 .gallery .element a .icon-eye-open,.gallery .element a .icon-eye-open:hover{position:absolute;z-index:1006;color:white;text-shadow:0 -1px 0 rgba(0,0,0,0.3);vertical-align:center;background-color:rgba(0,0,0,0.7);border-radius:200em;left:50%;top:44%;margin-left:-26px;margin-top:-25px;width:52px;height:50px;padding:.70em .5em;box-sizing:border-box}
 .img-polaroid{padding:10px;box-sizing:border-box}
 .gallery img{zoom:1;filter:alpha(opacity=75);opacity:.75}
 .gallery img:hover{filter:alpha(opacity=100);opacity:1}
 
 .table,.data-table{margin-bottom:0}
 .table-striped,.table,.data-table{color:blue;font-weight:bolder;width:100%}
 .table-striped th,.table th,.data-table th,.table-striped td,.table td,.data-table td{padding:8px;text-align:left;vertical-align:top}
 .table-striped th,.table th,.data-table th{font-weight:bold}
 .table-striped thead th,.table thead th,.data-table thead th{vertical-align:bottom}
 .table-striped thead th:first-child,.table thead th:first-child,.data-table thead th:first-child{padding-left:20px}
 .table-striped thead th:last-child,.table thead th:last-child,.data-table thead th:last-child{padding-right:20px}
 .table-striped tbody i,.table tbody i,.data-table tbody i{color:#cacaca}
 .table-striped tbody td:first-child,.table tbody td:first-child,.data-table tbody td:first-child{padding-left:20px}
 .table-striped tbody td:last-child,.table tbody td:last-child,.data-table tbody td:last-child{padding-right:20px}
 .table-striped tbody td,.table tbody td,.data-table tbody td,.table-striped tbody th,.table tbody th,.data-table tbody th{background-image:-moz-linear-gradient(bottom,rgba(0,0,0,0.01) 0,rgba(255,255,255,0.01) 100%);background-image:-o-linear-gradient(bottom,rgba(0,0,0,0.01) 0,rgba(255,255,255,0.01) 100%);background-image:-webkit-linear-gradient(bottom,rgba(0,0,0,0.01) 0,rgba(255,255,255,0.01) 100%);background-image:linear-gradient(bottom,rgba(0,0,0,0.01) 0,rgba(255,255,255,0.01) 100%);border-bottom:1px solid #c2c2c2;-webkit-box-shadow:0 2px 0 #fff;-moz-box-shadow:0 2px 0 #fff;font-weight:800;box-shadow:0 2px 0 #fff}
 .st{font-weight:800;}
 .controls .input-block-level{font-weight:800;}
 .table-striped tbody .small,.table tbody .small,.data-table tbody .small{text-align:right;color:#c3c3c3}
 .table-striped tbody>tr:nth-child(odd)>td,.table tbody>tr:nth-child(odd)>td,.data-table tbody>tr:nth-child(odd)>td,.table-striped tbody>tr:nth-child(odd)>th,.table tbody>tr:nth-child(odd)>th,.data-table tbody>tr:nth-child(odd)>th{background-color:#f9f9f9;background-image:-moz-linear-gradient(bottom,rgba(0,0,0,0.03) 0,rgba(255,255,255,0.03) 100%);background-image:-o-linear-gradient(bottom,rgba(0,0,0,0.03) 0,rgba(255,255,255,0.03) 100%);background-image:-webkit-linear-gradient(bottom,rgba(0,0,0,0.03) 0,rgba(255,255,255,0.03) 100%);background-image:linear-gradient(bottom,rgba(0,0,0,0.03) 0,rgba(255,255,255,0.03) 100%);border-bottom:1px solid #c2c2c2}
 table .btn{padding:0 6px;margin-right:0;margin-left:2px !important;}
 table .right .btn{float:right}
 table.dataTable thead th.right,table.dataTable tfoot th.right{text-align:right;padding-right:20px}
</style>
<link rel="stylesheet" href="../../assets/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">


<script>
$(document).ready(function(){
var rows = $('table.table tr');
var Cash = rows.filter('.Cash');
var Cheque = rows.filter('.Cheque');
var NEFT = rows.filter('.NEFT');
var empty = rows.filter('.empty');

$('#Cash').click(function() {
   // Cash.show();
    Cheque.hide();
    NEFT.hide();
    empty.hide();
	// for grand total
	  $(".rm1").empty();
	
	var sum = 0;
// iterate through each td based on class and add the values
$(".Cash").each(function() {

    var value = $(this).text();
    // add only if the value is number
    if(!isNaN(value) && value.length != 0) {
        sum += parseFloat(value);
    }
});

$('#completeFeeShw').text(sum); 
	
	// grand total end
	
});

$('#Cheque').click(function() {
    Cash.hide();
    NEFT.hide();
    empty.hide();
	 $(".rm1").empty();
	// for grand total
	
	var sum = 0;
// iterate through each td based on class and add the values
$(".Cheque").each(function() {

    var value = $(this).text();
    // add only if the value is number
    if(!isNaN(value) && value.length != 0) {
        sum += parseFloat(value);
    }
});
$('#completeFeeShw').text(sum); 
	
	// grand total end
	
});
$('#NEFT').click(function() {
    Cash.hide();
    Cheque.hide();
    empty.hide();
	 $(".rm1").empty();
	
	
	// for grand total
	
	var sum = 0;
// iterate through each td based on class and add the values
$(".NEFT").each(function() {

    var value = $(this).text();
    // add only if the value is number
    if(!isNaN(value) && value.length != 0) {
        sum += parseFloat(value);
    }
});
$('#completeFeeShw').text(sum); 
	
	// grand total end
	
});
$('#showAll').click(function() {
	location.reload();
   /* Cash.show();
    Cheque.show();
    empty.show();
	 NEFT.show();
	 
	 var temp = 0;
	var temp1 = 0;
	var temp2 = 0;
$('.Cash ').each(function(){

var tdTxt = $(this).text();
    if(!isNaN(tdTxt) && tdTxt.length != 0) {
       temp+= parseFloat(tdTxt);    
	}            
});

$('.Cheque ').each(function(){

var tdTxt = $(this).text();
     if(!isNaN(tdTxt) && tdTxt.length != 0) {
       temp1+= parseFloat(tdTxt);    
	}
                  
});

$('.NEFT').each(function(){

var tdTxt = $(this).text();
     if(!isNaN(tdTxt) && tdTxt.length != 0) {
       temp2+= parseFloat(tdTxt);    
     }
                  
});
$('#completeFeeShw').text(temp+temp1+temp2);
*/	
});
});
</script>

<div id="printDiv">
<?php
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"];
	if($_GET["fdate"]==7&&$_GET["fmonth"]==14){
		echo "No records available";
	}else{
       session_start();
	//print_r($_GET["user1"]);
		 $_SESSION["admin"]["session"]=$_REQUEST["session"];
     
        $_SESSION["admin"]["school_id"]= $_REQUEST["school_id"];
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllHostelOther=$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;$overAllTot=0;
		$whereLocation="";
		if(isset($_GET["location"]) && $_GET["location"]!=""){
			$whereLocation=" and location='".$_GET["location"]."' ";
		}
		
		if(!empty($_GET["user1"]) ){
			$u=implode(',',$_GET["user1"]);
			$whereUser=" and added_by in ($u) ";		
		}
	
		
		$aryFeeType=$db->getRows("select distinct(type) from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 order by type");
				
		$aryStudentList=$db->getRows("SELECT idno,added_by FROM `reff_receipt` WHERE  date between '$fdate' and '$tdate' and session='".$_SESSION["admin"]["session"]."'  $whereUser  group by idno");
				
		//echo $db->getErMsg().$db->getLastQuery();
		if(is_array($aryStudentList) && count($aryStudentList)>0){
				
			$tndate = date('Y/m/d', strtotime('-1 days',strtotime($tdate)));
			//echo $tndate." ".$fdate
			?>
            <center><h5><p style="float:right">Collection Date: 
			<?php if(strtotime($tndate)==strtotime($fdate)){
			echo date("d-M-Y",strtotime($tndate));?> - <?php echo date("l",strtotime($tndate));}
			else echo date("d-M-Y",strtotime($fdate)) ." to ".date("d-M-Y",strtotime($tndate)); ?></p> <p>Daily Collection Report</p>	</h5></center>
			<table class="table" cellspacing="0" cellpadding="0" border="1">
				<thead>
				<tr style="cursor:pointer">
                	<td>S.No</td>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Admission no</th>
					<td>Class</th>
					<th><div style="width:70px">Branch</div></th>
					<td>User</td>
                    <td>Receipt No</td>
                    <td>Payment Mode</td>
					
                    <td>Month</td>
					<th>Tution Fee</th>
					<th>Transport fee</th>
					<th>Hostel Fee</th>
				   <?php
				   if(is_array($aryFeeType) && count($aryFeeType)>0){
					foreach($aryFeeType as $ftype){
						?><th><?php echo $ftype["type"] ?></th><?php
					}
				   }
				   ?>
				   <th>Fee/other</td>
				   <th>Fine</th>
                   <th>Hostel Other</th>
				   <th>Extra</th> 
                   <th>Income</th> 
				   <th>Total</th>
				</tr>
				</thead>
		<tbody>
					<?php $s=0;
					//foreach($aryStudentList as $fStudent){
												
						foreach($aryStudentList as $s_id){
							$loc=$db->getRow("select idno from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and session='".$_SESSION["admin"]["session"]."' and (status=1 or status=3)  and issue_TC=0  $whereLocation");
							
						if(!empty($loc)){
							
							$fStudent=$db->getRow("select idno, name,fname,admissionno,stype,class,section,location from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."' and session='".$_SESSION["admin"]["session"]."' and (status=1 or status=3)   and issue_TC=0 ");
							
						
						
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$hotherExtra=$h1otherExtra=$hostelotherExtra=0;$total=0;$fine=0;
						/*$installTution=$db->getRows("select ins_name from installment_time where ins_name like 'ip%' and (date between '$fdate' and '$tdate') and idno='".$s_id[idno]."'  ");
						if(is_array($installTution) && count($installTution)>0){
							foreach($installTution as $installT){
								$tution+=$db->getVal("select ".$installT["ins_name"]." from installment where idno=".$s_id[idno]);
								
							}
							$overAlltution+=$tution;
							$total+=$tution;
						}*/
						// tution new
						$tution=$db->getVal("select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and type='fee' and (date between '$fdate' and '$tdate') ");
							if(!empty($tution)){
							$overAlltution+=$tution;
							$total+=$tution;
							}
							
						/*$installTution=$db->getRows("select ins_name from installment_time where ins_name like 'bp%' and (date between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ");
						if(is_array($installTution) && count($installTution)>0){
							foreach($installTution as $installT){
								$trasnport+=$db->getVal("select ".$installT["ins_name"]." from installment where idno=".$s_id[idno]);
							}
							$overAllTransport+=$trasnport;
							$total+=$trasnport;
						}*/
						// tranasport
						 $trasnport=$db->getVal("select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and type='busfee' and (date between '$fdate' and '$tdate') ");
						

							if(!empty($trasnport)){
							$overAllTransport+=$trasnport;
							$total+=$trasnport;
							}
						
						/*$installTution=$db->getRows("select ins_name from installment_time where ins_name like 'hp%' and (date between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ");
						if(is_array($installTution) && count($installTution)>0){
							foreach($installTution as $installT){
								$inst="ip".preg_replace("/hp/","",$installT["ins_name"]);
								$hostel+=$db->getVal("select ".$inst." from hostelinstallment where idno=".$s_id[idno] );
							}
							$overAllhotel+=$hostel;
							$total+=$hostel;
							}
							*/
														
							$hostel=$db->getVal("select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and type='hostelfee' and (date between '$fdate' and '$tdate') ");
														
							if(!empty($hostel)){
							$overAllhotel+=$hostel;
							$total+=$hostel;
							}
													
						$extrasum=array();
						if(is_array($aryFeeType) && count($aryFeeType)>0){
							foreach($aryFeeType as $ftype){  
								$sums=0;
								$Ftypeid=$db->getVal("select id from extrafee_type where type='".$ftype["type"]."' and class='".$fStudent["class"]."'");
								
								
								/*$installTution=$db->getRows("select ins_name from installment_time where ins_name like 'ext-".$Ftypeid."-%' and (date between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ");$no=array(); //if($s==0) {echo $db->getLastQuery();}
								if(is_array($installTution) && count($installTution)>0){
									foreach($installTution as $installT){
										$no=explode("-",$installT[0]);
										$sums+=$db->getVal("select pay from extrafee where idno='".$s_id[idno]."' and  pid='p".$no[2]."' and type='".$Ftypeid."' ");
										
										
										
								
										
										echo $db->getErMsg();
									}
									
								}*/
								
								
								
								if($Ftypeid) { //echo $Ftypeid;
								$sums=$db->getVal("select sum(amount) from reff_receipt where idno='".$s_id[idno]."' and type='extrafee".$Ftypeid."' and (date between '$fdate' and '$tdate') ");
								}
								$extrasum[]=$sums;
								$total+=$sums;$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}
						
						
						$installOtherExtra=$db->getRows("select ins_name from installment_time where ins_name like 'other%' and (date between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ");
						if(is_array($installOtherExtra) && count($installOtherExtra)>0){
							foreach($installOtherExtra as $installT){
								//other1_detail
								$idSdetail=str_replace("_detail","",$installT[ins_name]);
								$idSdetail=str_replace("other","",$idSdetail);
								//$otherExtra+=$db->getVal("select fine from installment_fine where ins_name='".$idSdetail."-otherfee' and idno=".$s_id[idno]);
							$otherExtra+=$db->getVal("select fine from installment_fine where ins_name='".$idSdetail."-otherfee'  and  (udate between '$fdate' and '$tdate') and idno=".$s_id[idno]);
	
								
								//echo $db->getLastQuery();
							}
							
							
						}
						
						//$otherExtra=$db->getVal("select sum(fine) from installment_fine where ins_name like '%other%' and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ");
						 //$ss="select sum(fine) from installment_fine where ins_name like '%other%' and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ";
							

							$overAllOther+=$otherExtra;
							$total+=$otherExtra;
						
						/*$installOtherExtra=$db->getRows("select ins_name from installment_time where ins_name like 'hostelother%' and (date between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ");
						if(is_array($installOtherExtra) && count($installOtherExtra)>0){
							foreach($installOtherExtra as $installT){
								//other1_detail
								$idSdetail=str_replace("_detail","",$installT[0]);
								$idSdetail=str_replace("hostelother","",$idSdetail);
								$hotherExtra+=$db->getVal("select fine from installment_fine where ins_name='".$idSdetail."-otherfeehostel' and idno=".$s_id[idno]);          						//echo $db->getLastQuery();
								$h1otherExtra+=$db->getVal("select sum(fine) from installment_fine where ins_name='".$idSdetail."-otherhostel' and idno=".$s_id[idno]);
								//echo $db->getLastQuery();
							}$hostelotherExtra=$hotherExtra+$h1otherExtra;
							$overAllHostelOther+=$hostelotherExtra;
							$total+=$hostelotherExtra;
						}*/
						
						$hostelotherExtra=$db->getVal("select sum(fine) from installment_fine where ins_name like '%hostel' and (udate between '$fdate' and '$tdate') and idno=".$s_id[idno]);
						
						$overAllHostelOther+=$hostelotherExtra;
						$total+=$hostelotherExtra;
						
						$fine=(float)$db->getVal("select sum(fine) from installment_fine where (ins_name like '%-class' or ins_name like '%-hostel' or ins_name like '%-bus' or ins_name like '%-extra%') and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."'");
						$total+=$fine;
						$overAllFine+=$fine;
						$newExtra=(float)$db->getVal("select sum(fine) from installment_fine where (ins_name like '%-other') and (udate between '$fdate' and '$tdate') and idno='".$s_id[idno]."' ");
						$rdate=date("Y-m-d",strtotime($fdate));
						$sdate=date("Y-m-d",strtotime($tdate));
						$ref=$db->getRows("select * from reff_receipt where date > '$rdate' and date < '$sdate' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$s_id[idno]."' ");
							//echo $db->getLastQuery();
								//print_r($ref);exit;
									$rids=array();$rrmonth=array();
									
						$rdate1=date("d-m-Y",strtotime($fdate));
						$sdate1=date("d-m-Y",strtotime($tdate));
						$rrde=$db->getRows("select * from receipt where  session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."'  ");
							
							
									//echo $db->getLastQuery();
								   //print_r($rrde);exit;
									//echo "<pre>";print_r($rrde);echo "</pre>";
									if(is_array($rrde) && count($rrde)>0){
										foreach($rrde as $rr){
											$rl_rrid=explode("-",$rr["rrid"]);
											//print_r($rl_rrid);exit;
										foreach($ref as $reff){
											//echo $reff['given_date'];exit;
											//if($reff["date"]!=$reff["given_date"])
												///$date_ary[]=date("d-m-Y",strtotime($reff["given_date"]));
											foreach($rl_rrid as $rrids){
											//echo $rrids;exit;
											if($rrids==$reff["id"]){
													$r=$rr['id'];
													if(!($r==$ridss)) {
													$ridss=$r;
													$rrmonth[]=$rr['Months'];
													$rids[]=$ridss;}
												}
											}
										}
										
									}
								}    //$recno=$ridss;
									$recno= implode(",",$rids);
						$total+=$newExtra;
						$overAllNewextra+=$newExtra;
						$fmonths="";$monthname1="";$monthname=array();
						$fmonths=implode(",",$rrmonth);
					$im=explode(",",$fmonths);
					$mn=array_unique($im);$months="";
					if(is_array($mn) && count($mn)){
						foreach($mn as $ipi){					
							if($ipi!=""){
								if($months!="")$months.=",";
								if($ipi<=9){
									$newDate=date("Y")."-".($ipi+3)."-1";
									$months.= date("M",strtotime($newDate));//."(".($ij+3).")";
								}
								else{
									$newDate=date("Y")."-".($ipi-9)."-1";
									$months.= date("M",strtotime($newDate));//."(".($ij-9).")";
								}
							}
						}
					}
						//echo $db->getErMsg();
						if($total>0){ $s++;
						?>
						<?php //$mode= $db->getVal("select if(payment_mode ='',null, payment_mode) from receipt where id in (select id from receipt where  (udate between '$rdate1' and '$sdate1') and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$s_id[idno]."'  ) order by payment_mode DESC ");
					
						/*$mode=$db->getVal("select if(payment_mode ='',null, payment_mode) from receipt where id in ($recno) order by payment_mode DESC ");*/
						
                      
					
						?>
						
						
						<tr class="<?php //if(!empty($mode)){ echo $mode; } else echo 'empty' ;?>">
                        	<td><?php echo $s; ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?>-<?php echo $fStudent["section"] ?></td>
						
                            <td><?php echo $db->getVal("select name from users where id='$s_id[added_by]'"); ?></td>
                            <td><?php echo $fStudent["stype"] ?></td>
                            <td><?php echo $recno; ?></td>
														
                            <td><?php 
							
							if(!empty($recno)){
							$m= $db->getVal("select if(payment_mode ='',null, payment_mode) from receipt where id in ($recno) order by payment_mode DESC ");
							} else { $m='';}	
							
if($m!='') echo $m; else echo 'Cash';

							?></td>
                            <td><?php echo $months; ?></td>
							<td><?php echo $tution; ?></td>
							<td><?php echo $trasnport ?></td>
							<td><?php echo $hostel ?></td>
							<?php  for($ij=0; $ij<count($aryFeeType); $ij++){ ?><td><?php echo $extrasum[$ij]; ?></td><?php } ?>
						   <td><?php echo $otherExtra; ?></td>
						   <td><?php echo $fine; ?></td>
                           <td><?php echo $hostelotherExtra; ?></td>
						   <td><?php echo $newExtra; ?></td>
                           <td>0</td>
						   <td><?php echo $total;$overAllTotal+=$total; ?></td>
						</tr>
						<?php
						}
					}
					}
					?>
                    <tr class="empty">
                    	<td></td>
                    		<td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                       
                        <td><?php if($_GET["location"]=="")echo "All";else echo $db->getVal("select name from location where id='".$_GET["location"]."' and school_id='".$_SESSION["admin"]["school_id"]."'"); //echo $db->getLastQuery();//echo date("d-M-y",strtotime($fdate));//" to ".date("d/m/y",strtotime($tdate)); ?></td>
                       
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>0</td>
                        <td>0</td>
                        <td>0</td>
                        <?php
						if(is_array($aryFeeType) && count($aryFeeType)>0){
							foreach($aryFeeType as $installT){
								?><td>0</td><?php
							}
						}
						?>
                        <td>0</td>
                        <td>0</td>
                        <td>0</td>
                        <td>0</td>
                        <td><?php echo $tot=$db->getVal("select sum(amount) from transaction where type='deposit' and (udate between '$fdate' and '$tdate') and (tfor='cash' or tfor='cheque' or tfor='hostel-income') and session='".$_SESSION["admin"]["session"]."' $whereUser"); ?></td>
                        <td><?php echo $tot;$overAllTot+=$tot;$overAllTotal+=$tot; ?></td>
                    </tr>
				</tbody>
				<tfoot>
					<td colspan="10">Gross Total</td>
					<td><?php echo $overAlltution ?></td>
					<td><?php echo $overAllTransport ?></td>
					<td><?php echo $overAllhotel ?></td>
					<?php
					if(is_array($overAllextra) && count($overAllextra)>0){
						foreach($overAllextra as $ftype){
							?><td><?php echo $ftype ?></td><?php
						}
					   }?>
				   <td><?php echo $overAllOther ?></td>
				   <td><?php echo $overAllFine ?></td>
                   <td><?php echo $overAllHostelOther ?></td>
				   <td><?php echo $overAllNewextra ?></td>
                   <td><?php echo $overAllTot; ?></td>
				   <td id="completeFeeShw"><?php echo $overAllTotal; ?></td>
				</tfoot>
			</table>  
            Print Date : <?php echo date('d-M-Y'); ?>
			<?php
		}else{
			echo "No record found<br />".$db->getErMsg();
		}
	
		}
	}

?>
</div>
<script type="text/javascript">
	$(document).ready(function(e) {
		var oTable = $('.table').dataTable( {
			"bPaginate": false,
			"bLengthChange": true,
			"bFilter": true,
			"bSort": true,
			"bInfo": true,
			"fnRowCallback" : function(nRow, aData, iDisplayIndex){
                $("td:first", nRow).html(iDisplayIndex +1);
               return nRow;
            },
			"bAutoWidth": false
		});
	});
	
	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();
	});
}
	</script>
    <style>
    tfoot{display: table-footer-group !important;}
    </style>