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

<?php
ini_set('maximum_execution_time',600);
$pgMod="DueSheet";
$pgAct="view";  

$allmonths = $db->getRows("select * from months");

$monthsList1 = array();
    foreach($allmonths as $my){
        $monthsList1[$my['month']] = $my['name'];
    }

$monthsList = array(
    'January',
    'February',
    'March',
    'April',
    'May',
    'June',
    'July ',
    'August',
    'September',
    'October',
    'November',
    'December',
);

// $monthsList1 = array(
//     1=>'Apr',
//     2=>'May',
//     3=>'Jun',
//     4=>'Jul ',
//     5=>'Aug',
//     6=>'Sep',
//     7=>'Oct',
//     8=>'Nov',
//     9=>'Dec',
// 	10=>'Jan',
//     11=>'Feb',
//     12=>'Mar'
// );
// print_r($monthsList1);
?>
<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;
}
</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 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");
		}
	}
function getStudentfinePopup(){
		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;
			}
		})
		//var month=$(".month").val();
		//url+="&month="+month;
		if(url!=""){
			getPopup("<?php echo URL_ROOT ?>Promote/?page_id=MigrateFine&month=<?php echo $_GET["fmonth"]?>&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");
		}
	}	
$(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="";
    var i = 1;
    var j = 1;
	$(".MyTotalLeft").each(function(index, element) {

		var myVal=parseInt($(this).html());

		if(myVal==0 && ids==0)
		{
			$(this).parent().hide('slow');
			$(this).parent().removeClass('none');
		}
		else
		{
    		$("#newid"+i).html(j);
			$(this).parent().show('slow');
			$(this).parent().addClass('none');
			j++;
		}
    i++;
	});
}

function filterPay(Tval){
	var val=$(Tval).val();
	if(val.trim()==""){
		$(".MyTotalLeft").parent().show('slow');
		$(".MyTotalLeft").parent().addClass('none');
		$(".dynamic").hide('slow');
	}
	else
	if(!isNaN(val)){
		$(".dynamic").show('slow');
		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 user only number");
		$(Tval).val('');
		$(".MyTotalLeft").parent().show();
		$(".MyTotalLeft").parent().addClass('none');
		$(".dynamic").hide();
	}
	var MyTotalLeft=0,MyTotalpaid=0,MyTotalLeft=0,MyDiscount=0,tamountvalue=0;
	$(".none").each(function(index, element) {
		var totalleft=val-parseInt($(this).children('.MyTotalpaid').html());
		$(this).children('.MyTotalLeftDynamic').html(totalleft);
		MyTotalLeft+=parseInt($(this).children('.MyTotalLeft').html());
		MyTotalpaid+=parseInt($(this).children('.MyTotalpaid').html());
		tamountvalue+=parseInt($(this).children('.tamountvalue').html());
		MyDiscount+=parseInt($(this).children('.MyDiscount').html());
	});
	$("#MyTotalLeft").html(MyTotalLeft);
	$("#MyTotalpaid").html(MyTotalpaid);
	$("#tamountvalue").html(tamountvalue);
	$("#MyDiscount").html(MyDiscount);
}

function getStudentSMS(){
   
		var url="";
		var idno = [];
		var amount = [];
		var mobile = [];
		var mname = '<?php echo $allmonths[$_GET['fmonth']-1]['name']; ?>';

		$(".checkboxes").each(function(){
			if($(this).prop('checked')==true){
			   
				idno.push($(this).val());

			}
		})
	
			//var left=$(".left"+idno).html()
		for (let i = 0; i < idno.length; ++i) {

            amount.push($("#total_amt"+idno[i]).val());
            mobile.push($("#mobile"+idno[i]).val());

        }

$.post( "ajax.php", { type: "outstandingmessage" ,idno: idno,mobile: mobile, amount: amount, mname: mname, month: <?php echo $_GET["fmonth"];  ?> } , function( data ) {
		alert(data);
	});

	}
	
	function AppSMS(){

		var url="";
		var idno = [];
		var amount = [];
		var mobile = [];
		var mname = '<?php echo $allmonths[$_GET['fmonth']-1]['name']; ?>';

		var ntype = $("#notification").val();
        // alert(ntype);
		$(".checkboxes").each(function(){
			if($(this).prop('checked')==true){
				idno.push($(this).val());
			}
		})

		for (let i = 0; i < idno.length; ++i) {

            amount.push($("#total_amt"+idno[i]).val());
            mobile.push($("#mobile"+idno[i]).val());

        }

        $.post( "ajax.php", { type: "appmessage" ,idno: idno,mobile: mobile, ntype: ntype, amount: amount, mname: mname, month: <?php echo $_GET["fmonth"];  ?> } , function( data ) {
	   // 	alert(data);
    	});

	}
	
</script>
<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="well no-padding">
                <div class="controls controls-row">
                    <div class="control-group span3" STYLE="width: 180px;">
                        
                        <div class="controls span3" STYLE="width: 150px;">
                                <select name="fmonth" id="fmonth" STYLE="width: 150px;">
                                    <option value="">Month</option>
                                 <?php
                                    // for($m = 1;$m <= 12; $m++){ 
                                    //     $newDate=date("Y")."-".$m."-1";
                                    //     $month =  date("F",strtotime($newDate));//."(".($ij+3).")";
                                    //     $selected="";if($_GET["fmonth"]==$m)$selected=" selected ";
                                    //     echo "<option $selected value='$m'>$month</option>";
                                    // }
                                    foreach($allmonths as $mn){
                                        $checked = "";
                                    	    if($_GET["fmonth"]=== trim($mn["month"]) ){
                						        $checked="selected='selected'";
                                    	    }
                                	    echo "<option value='".$mn['month']."' $checked>$mn[name]</option>";
                        	        }
                                 ?> 
                                </select>
                            </div>
                    </div>
                     
                    <div class="control-group span3" STYLE="width: 200px;">
                        
                        <div class="controls span3" STYLE="width: 170px;">
                                <select name="class" id="class" STYLE="width: 170px;">
									<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 span3" STYLE="width: 200px;">
                            <!--<label class="control-label" for="class">Section</label>-->
                            <div class="controls span3" STYLE="width: 170px;">
                               <select name="section" id="section"  STYLE="width: 170px;">
                <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 span3" STYLE="width: 200px;">
                            <!--<label class="control-label" for="class">Section</label>-->
                            <div class="controls span3" STYLE="width: 170px;">
                               <select name="bus" id="bus" STYLE="width: 150px;">
                <option value="">Bus Root</option>
                <?php 
                    $class=$db->getRows("select * from bus where  school_id='".$_SESSION["admin"]["school_id"]."'");
                    foreach($class as $cla){
                        ?>
                        <option <?php if($cla["id"]==$_GET["bus"])echo 'selected';?> value="<?php echo $cla["id"] ?>">
                            <?php echo $cla["root"] ?>
                        </option>
                        <?php
            
                    }
                ?>
            </select>
                            </div>
                        </div>                        
                        
                    <div class="control-group span3">



                      <div style="width:50%;display:inline-block;padding-top:-10px;">
					<select class="span12" name="location" id="location">
                                	<option value="">none</option>
									<?php 
										$location=$db->getRows("select id,name from location where school_id='".$_SESSION["admin"]["school_id"]."'");
										if(is_array($location) && count($location)>0){
											foreach($location as $loc){
												?>
												<option <?php if($loc["id"]==$aryForm["location"])echo 'selected';?> value="<?php echo $loc["id"] ?>">
													<?php echo $loc["name"] ?>
												</option>
												<?php
											}
										}
									?>
								</select><br>
								<select class="span12" id="notification">
								    <option value="1">Dues with Message</option>
								    <option value="2">Dues Only</option>
								    <option value="3">Message Only</option>
								</select>
								<button onclick="AppSMS()" class="btn btn-danger">App SMS</button>
                            
                        </div>

                      <div style="width:45%;display:inline-block;">
                      <button type="button" style="float:right" onclick="printDiv('printDiv')" class="btn btn-danger">Print</button>
                    	<button type="button" class="btn btn-danger hidet" onClick="getStudentSMS()" style="float:right;" >SMS</button>
				<!--<input  class="btn btn-primary" type="button"  onclick="$('.table').tableExport({type:'excel',escape:'false'});" id="btnExport" value=" Export To Excel " />-->
                    <!--<button class="btn btn-success" onclick="exportTableToExcel('tblData', 'DueSheet')" style="margin-left:35px;">Excel</button>				-->
                        <?php if(isset($_GET['total_amount'])){ ?>
                            <button class="btn btn-danger" id="btn_excel" style="margin-left:35px;">Excel</button>
                        <?php } else { ?>
                        <button class="btn btn-success" onclick="exportTableToExcel('tblData', 'DueSheet')" style="margin-left:35px;">Excel</button>
                        <?php } ?>
                      </div>
                      
                      </div>
                    <div class="control-group span12" style="margin:0;">
                    <!--<button type="submit" name="daily" class="btn-classic">Month Wise</button>-->
                    <button type="submit" name="month_report" class="btn-classic">Complete Outstanding</button>
					
					
                    
					
					
                    <!--<button type="submit" name="hostel" class="btn-classic">Hostel </button>-->
                    <!--<button type="submit" name="without_hostel" class="btn-classic">Without Hostel </button>-->
					
					
                    <button type="submit" name="month_report_without_hostel" class="btn-classic">Academic Outstanding</button>
                     <button type="submit" name="hostel_outstanding" class="btn-classic">Hostel Outstanding</button>
                      <button type="submit" name="pocket" class="btn-classic">Pocket Outstanding</button>
                    <!--<button type="submit" name="school_outstanding" class="btn-classic">School Outstanding</button>-->
                    <!--<button type="submit" name="bus_outstanding" class="btn-classic">Transport Outstanding</button>-->
                   <!--<button type="submit" name="transport_wcs" class="btn-classic">Transport Root Wise </button>-->
                    <!--<button type="submit" name="new_due" class="btn-classic">New Student</button>-->
                    <!--<button type="submit" name="student_due" class="btn-classic">Student Wise</button>-->
                     <button type="submit" name="student_list" class="btn-classic">Student Report</button>

                     <!--<button type="submit" name="short_list" class="btn-classic">Short List</button>-->
					 
                     <!--<button type="submit" name="cast_list" class="btn-classic">cast List</button>-->
                  
				  <!--<button type="submit" name="month_report_sibling" class="btn-classic">Sibling Outstanding</button>-->
				  <!--<button type="submit" name="sibling_wt_class" class="btn-classic">Sibling WT class</button>-->
				    <!--<button type="submit" name="location_wise" class="btn-classic">Location Outstanding</button>-->
					
					<!--<button type="submit" name="month_report_wtcl" class="btn-classic">Complete Outstanding wt class</button>-->
					<!--<button type="submit" name="month_report_wtcl" class="btn-classic">Overall Outstanding</button>-->
					
					<!--<button type="submit" name="Academic_Ledger" class="btn-classic">Academic Ledger</button>-->
					<!--<button type="submit" name="Hostel_Ledger" class="btn-classic">Hostel Ledger</button>-->
					
					<!--<button type="submit" name="month_report_wtcl_due" class="btn-classic">Complete Outstanding wt cls Due</button>-->
					
					                <br>                    
                <div> 
                    <select name="head_name">
                            <option value="Tuition">Tuition Fee</option>
        				    <option value="Transport">Transport Fee</option>
                            <?php $feehead = $db->getRows("SELECT DISTINCT name FROM `otherfee_structure` WHERE ( otype='' OR otype='new' or otype='old') and session='".$_SESSION["admin"]["session"]."' ");
                                    foreach($feehead as $cls){ 
                                    $otherfeeary[] = $cls['name'];
                                    ?>
                                        <option value="<?php echo $cls['name']; ?>"><?php echo $cls['name']; ?></option>
                                    <?php } 
 
                                    $extrafeetype = $db->getRows("select distinct(type) from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  order by type");
                                    foreach($extrafeetype as $ftype){ 
                                    $extrafeeary[] = $ftype["type"];
                                    ?>
                                        <option value="<?php echo $ftype['type']; ?>"><?php echo $ftype["type"]; ?></option>
                                    <?php } ?>
                            

                            <option value="Hostel">Hostel Fee</option>
                            <?php $hostelextra = $db->getRows("SELECT DISTINCT name FROM `hostel_otherfee_structure` WHERE ( otype='' OR otype='new' or otype='old') and session='".$_SESSION["admin"]["session"]."' ");
                                foreach($hostelextra as $cls){ 
                                $hostelotherfeeary[] = $cls['name'];
                                ?>
                                    <option value="<?php echo $cls['name']; ?>"><?php echo $cls['name']; ?></option>
                            <?php } ?>
                            <option value="Back_dues">Back_dues</option>

            <!--            <option value="Annual_fee">Annual_fee</option>-->
    				    <!--<option value="Activity_fee">Activity_fee</option>-->
    				    <!--<option value="Admission_fee">Admission_fee</option>-->
                    </select>
                    <button type="submit" name="search_head_fee" class="btn-classic margin">Head Wise Outstanding</button>
                    <button type="submit" name="single_month_dues" class="btn-classic margin">Single Month Outstanding</button>

                    <button type="submit" name="only_hostel" class="btn-classic margin">Only Hostel</button>
                    <!--<button type="submit" name="without_hostel_dues" class="btn-classic margin">Without Hostel</button>-->
                    
                    <button type="submit" name="total_amount" class="btn-classic margin">Total Outstanding Amount</button>
                    
                    <button type="submit" name="class_outstanding" class="btn-classic margin">Class Wise Outstanding</button>
                    
                    <button type="submit" name="new_ledger" class="btn-classic margin">New Ledger</button>
                    
                    <button type="submit" name="back_dues_outstanding" class="btn-classic margin">Back Dues</button>
                
                    <!--<p id="duebutton" class="btn-classic margin">Total amount ajax</p>-->
                
                    <!--<button type="submit" name="month_report_wtcl" class="btn-classic margin">Total Dues</button>-->

                    <!--<button type="submit" name="month_report_excel" class="btn-classic">Complete Outstanding Excel</button>-->
                </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<div id="printDiv">
    <div id="ajaxdata">
<?php

// sibling without class start 

if(isset($_REQUEST['sibling_wt_class']))
	{
		
		$whereS="";
	if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="")
			$whereS=" AND section='".$_REQUEST["section"]."' ";
		
		
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					$overAllNewextra=0;
		$aryStudentList=$db->getRows("select *, REPLACE(sibling,idno,'') as sibling1 from student where  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and status=1 and issue_TC=0 order by class,name");
		
		$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");
		$m=0;
		if(isset($_REQUEST['fmonth']) && $_REQUEST['fmonth']!=0){
			$month=$_GET["fmonth"];
			  if($month<4){
				$m=($month+9);
			  }
			  else{
				$m=$month-3;
			  }
		}
		else{
			$m=12;
		}
		 // echo $m;
		 
		 
		 
		 
		 
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData">
				<thead>
				<tr>
                	<td class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></td>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
                     <?php
			   if(is_array($monthsList1) && count($monthsList1)>0){
				/*foreach($monthsList1 as $ftype){
					?><th width="0.5%"><?php echo $ftype ?></th><?php
				}*/
					for($i=1;$i<=$m;$i++){?>
						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
					}
			   }
			  
			   //$install=$db->getRows("select * from otherfee_structure where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' )  and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' ");
			   
			   $install=$db->getRows("select * from otherfee_structure where   school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' )  and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' group by name order by id");
			   
			   //print_r($install);
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php										
					}?>
                    <th>Back Dues</th>
              <?php 
			  //$install=$db->getRows("select * from hostel_otherfee_structure where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");
			  
			  $install=$db->getRows("select * from hostel_otherfee_structure where   school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' group by name order by id");
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
                    <th>Fine</th>
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php $i=0;$total_comp=0;
		
		
		
					
					foreach($aryStudentList as $fStudent){
					$mn=$m;
					
					
					
					//$sib_chk=$db->getRow("select replace(GROUP_CONCAT(REPLACE(sibling,idno,'')),',','') as sibling from student where  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");
					
					$sib_chk1=$db->getRows("select GROUP_CONCAT(REPLACE(sibling,idno,'')) as sibling from student where sibling!='' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");
					
					
					//print_r(array_filter(explode(',',$sib_chk1[0][sibling])));
					
					
					//$sib_chk=str_split($sib_chk["sibling"],1);
					$sib_chk=array_filter(explode(',',$sib_chk1[0][sibling]));
					//print_r($sib_chk);
					//if(in_array($fStudent["idno"],$sib_chk)){
						$id33= $fStudent["idno"];
						if(in_array($id33,$sib_chk)){
							
					}
					else{ $i++;
					?>
                    <tr>
                    		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>
                        	<td><?php echo $i ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]; //echo "-"; echo $fStudent["section"]  ?></td>
                            <td><?php 
							
							/*$ndate=$db->getVal("select date from installment_time where idno='".$fStudent["idno"]."' order by id DESC");
							$fdate=$db->getVal("select udate from installment_fine where idno='".$fStudent["idno"]."' order by id DESC");
							if($ndate!='' or $fdate!=''){
							$fdate=date("d-M-Y",strtotime($fdate));
							
							$fudate=date("d-M-Y",strtotime($ndate));
							
							if ($fudate>$fdate){
							echo $fdate;}else echo $fudate; }*/
                           echo $fStudent["section"]
							?></td>
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							foreach($monthsList1 as $key=>$val){$count++;
							if($mn==0){
								
							}
							else{ $mn--;
						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");
						//$db->getLastQuery();
						if(is_array($installTution) && count($installTution)>0){	
							if($installTution[1]=="" || $installTution[1]=="0")
								$tution=$installTution[0];
							else
								$tution=0;	
							
						}else{
							$tution="";
						}
						$overAlltution=$tution;
						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							if($installTution[1]=="" || $installTution[1]=="0")
								$trasnport=$installTution[0];
							else
								$trasnport=0;
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;
						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							if($installTution[1]=="" || $installTution[1]=="0")
								$hostel=$installTution[0];
							else
								$hostel=0;	
						}else{
							$hostel="";
						}
						$overAllhotel=$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								///echo $db->getErMsg().$db->getLastQuery();
								//echo $Ftypeid."-";print_r($installTution);
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution[1]=="" || $installTution[1]=="0")
										$sums=$installTution[0];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}

						
						 $overAllNewextra=0;//print_r($extrasum);
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						//echo $ij.$overAllNewextra."-";
						}//$j++;
						/*$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								//echo $db->getErMsg().$db->getLastQuery();
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution[1]=="" || $installTution[1]=="0")
										$sums=$installTution[0];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total+=$sums;$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}*/
						  //if($i==23){echo $overAlltution."--".$overAllTransport."--".$overAllhotel."--".$overAllNewextra."!!!!";}
						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhotel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhotel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhotel+$overAllNewextra;}
						//if($i==23)echo "(".$total.")";
						$total_full=$total_full+$total;
					?><td><?php if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td>
					<?php }}
					
				//	$install=$db->getRows("select * from otherfee_structure where  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' group by name desc");	

				$install=$db->getRows("select * from otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");
					
						//echo  $db->getLastQuery();
						if(is_array($install) && count($install)>0){
							$k=0;$c=0;$other2=0;
							foreach($install as $ins){$k+=2;$c++;
							if($fStudent['stype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
						   elseif($fStudent['stype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from otherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt)
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
							
						}?>	<td><?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php }	
						}
					$total_full+=$other2;
						//echo $i."-".$t.$other1."<br/>";
					
					$install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					
					
				
					
					$discount= $db->getVal("SELECT discount from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
					
					$install2=$db->getRow("select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					$discount2= $db->getVal("SELECT COALESCE(sum(discount),0) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id in(select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."')   and session='".$_SESSION["admin"]["session"]."' ");
										
					//echo $discount;
					
					//print_r($install);
							$dues=0;
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'"); 
                                								
								
								if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									   
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; //echo 111; ?></td>	
					
					<?php 
					$install=$db->getRows("select * from hostel_otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						//echo  $db->getLastQuery();
						if(is_array($install) && count($install)>0){
							$k=0;$b=0;$other2_hostel=0;
							foreach($install as $ins){$k+=2;$b++;
							if($fStudent['htype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
						   elseif($fStudent['htype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							 elseif($fStudent['htype']==""){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
				$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther_hostel=$t - $other1;
						    $over_hostel=$overAllOther_hostel;
							$other2_hostel+=$over_hostel;
							
						}?>	<td><?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
				<?php }	
						}$total_full+=$other2_hostel; 
						$install=$db->getRows("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else 		
									//$dues=$ins['fee']-$discount;
										$dues=$ins['fee'];
								}
										if($fine_t==$total_dues)
												$dues=0;
						//else $dues=$fine_t-$total_dues-$discount;	
								else $dues=$fine_t-$total_dues;	
										
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues-$discount2;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues-$discount2;  ?></td>	
			
                    <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $total_full;
$sib_tot=$total_full;				?></td>		
				<?php $total_comp+=$total_full; ?>
				
				</tr>
<!--sibling student start-->

				<?php if(!empty($fStudent["sibling1"])){ 
				$sib= $fStudent["sibling1"];
				$sib_val=array_filter((explode(',',$sib)));
				//print_r($sib_val);
				
				
					
				foreach($sib_val as $sib_val1)
				{
				$mn=$m;
		$sibStudentList=$db->getRow("select * from student where idno='".$sib_val1."' ");
				?>
				<tr>
                 <td></td>
                 <td></td>
                 <td><?= $sibStudentList["name"] ?></td>
                 <td><?= $sibStudentList["fname"] ?></td>
                 <td><?= $sibStudentList["admissionno"] ?></td>
                 <td><?= $sibStudentList["class"] ?></td>
                 <td><?= $sibStudentList["section"] ?></td>
                 <td><?= $sibStudentList["mobile"] ?></td>
                 <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							foreach($monthsList1 as $key=>$val){$count++;
							if($mn==0){
								
							}
							else
							{ $mn--;
							
						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$sibStudentList["idno"]."'");
						
						//$db->getLastQuery();
						if(is_array($installTution) && count($installTution)>0){	
							if($installTution[1]=="" || $installTution[1]=="0")
								$tution=$installTution[0];
							else
								$tution=0;	
							
						}else{
							$tution="";
						}
						$overAlltution=$tution;
						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$sibStudentList["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							if($installTution[1]=="" || $installTution[1]=="0")
								$trasnport=$installTution[0];
							else
								$trasnport=0;
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;
						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$sibStudentList["idno"]."'");
						
						
						
						if(is_array($installTution) && count($installTution)>0){
							if($installTution[1]=="" || $installTution[1]=="0")
								$hostel=$installTution[0];
							else
								$hostel=0;	
						}else{
							$hostel="";
						}
						$overAllhotel=$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='".$sibStudentList["class"]."'");
								$installTution=$db->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$sibStudentList["idno"]."'");
								
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution[1]=="" || $installTution[1]=="0")
										$sums=$installTution[0];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}

						
						 $overAllNewextra=0;//print_r($extrasum);
						
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						//echo $ij.$overAllNewextra."-";
						}
						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhotel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhotel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhotel+$overAllNewextra;}
						//if($i==23)echo "(".$total.")";
						$total_full=$total_full+$total;
					?><td><?php if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td>
					<?php }
					} 
					
					$install=$db->getRows("select * from otherfee_structure where class='".$sibStudentList["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						//echo  $db->getLastQuery();
						if(is_array($install) && count($install)>0){
							$k=0;$c=0;$other2=0;
							foreach($install as $ins){$k+=2;$c++;
							if($sibStudentList['stype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
						   elseif($sibStudentList['stype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$sibStudentList['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$sibStudentList['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from otherfee_discount where idno=".$sibStudentList['idno']." and other_id='".$ins['id']."' and class='".$sibStudentList["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
						$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt)
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
							
						}?>	<td><?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php }	
						}
                 
                $total_full+=$other2;
						//echo $i."-".$t.$other1."<br/>";
					
					$install=$db->getRow("select * from otherfee_structure where otype ='".$sibStudentList['idno']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					
			$discount= $db->getVal("SELECT discount from otherfee_discount  WHERE  idno='$sibStudentList[idno]' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
					
					$install2=$db->getRow("select id from otherfee_structure where otype ='".$sibStudentList['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					$discount2= $db->getVal("SELECT COALESCE(sum(discount),0) from otherfee_discount  WHERE  idno='$sibStudentList[idno]' and other_id in(select id from otherfee_structure where otype ='".$sibStudentList['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."')   and session='".$_SESSION["admin"]["session"]."' ");
										
					//echo $discount;
					
					//print_r($install);
							$dues=0;
					if(is_array($install) && count($install)>0){
					$installTution=$db->getRows("select * from installment_fine where idno=".$sibStudentList['idno']." and reasion = '".$install['name']."'"); 
                                								
								
								if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									   
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$sibStudentList['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; //echo 111; ?></td>
                 
                <?php 
					$install=$db->getRows("select * from hostel_otherfee_structure where class='".$sibStudentList["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");

				
				
						//echo  $db->getLastQuery();
						if(is_array($install) && count($install)>0){
							$k=0;$b=0;$other2_hostel=0;
							foreach($install as $ins){$k+=2;$b++;
							if($sibStudentList['htype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
						   elseif($sibStudentList['htype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							 elseif($sibStudentList['htype']==""){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
				$installTution=$db->getRow("select * from installment_fine where idno=".$sibStudentList['idno']." and reasion = '".$ins['name']."'"); 
				
				//echo "select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'";
				
				
							
			$installTution1=$db->getRows("select * from installment_fine where idno=".$sibStudentList['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");
			
						
			$installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$sibStudentList['idno']." and other_id='".$ins['id']."' and class='".$sibStudentList["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
			
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther_hostel=$t - $other1;
						    $over_hostel=$overAllOther_hostel;
							$other2_hostel+=$over_hostel;
							
						}?>	<td><?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
				<?php }	
						}$total_full+=$other2_hostel; 
						$install=$db->getRows("select * from otherfee_structure where otype ='".$sibStudentList['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$sibStudentList['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else 		
									//$dues=$ins['fee']-$discount;
										$dues=$ins['fee'];
								}
										if($fine_t==$total_dues)
												$dues=0;
						//else $dues=$fine_t-$total_dues-$discount;	
								else $dues=$fine_t-$total_dues;	
										
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues-$discount2;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues-$discount2;  ?></td>	
			
                    <td class="MyTotalLeft left<?php echo $sibStudentList['idno'] ?>"><?php echo $total_full; ; ?></td>		
				<?php $total_compp+=$total_full; ?>
                   <?php } 
				
				   
				
				 ?> 
				 
                 <td><?= $total_compp+$sib_tot; ?></td>
                <?php unset($total_compp)?>
				</tr>
<!--sibling student end-->
				<?php 
				
				  } 
				 } 
				
				} ?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $m+10+$c+$b;?>">Gross Total</td>
					
				   <td><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
}

// sibling without class end

	elseif(isset($_REQUEST['transport_wcs'])){
			$overAllTotal=0;$overAllTransport=0;
		$aryStudentList=$db->getRows("select * from student where bus='".$_GET["bus"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0  order by class,name");
		
		//echo $ss="select * from student where bus='".$_GET["bus"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 and bus != '' order by class,name";
		
		$month=$_GET["fmonth"];$m=0;
		  if($month<4){
			$m=($month+9);
		  }
		  else{
			$m=$month-3;
		  }
		  //echo $m;
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
          <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List" style="float:left;" />
          <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Transport Fee outstanding Root Wise</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" id="tblData">
				<thead>
				<tr>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
                     <?php
			   if(is_array($monthsList) && count($monthsList)>0){
				for($i=1;$i<=$m;$i++){
					?><th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
				}
			   }
			  
			  ?>
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                        	<td><?php echo $i ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?></td>
                            <td><?php echo $fStudent["section"] ?></td>
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$c=0;
							foreach($monthsList1 as $key=>$val){$c++;
							if($mn==0){
								
							}
							else{ $mn--;
							
						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");
				// 		print_r($installTution);
						
						if(is_array($installTution) && count($installTution)>0){
							if($installTution["bp$key"]=="" || $installTution["bp$key"]=="0")
								$trasnport=$installTution["b$key"];
							else
								$trasnport=0;
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;
						
						if($overAllTransport=="0")
						 $total==0;
						elseif($overAllTransport=="")
						{$total="";}
						else $total=$overAllTransport;;
						$total_full=$total_full+$total;
							?><td><?php if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td>		<?php }}
					
						//echo $i."-".$t.$other1."<br/>";
					
						
					?><td class="MyTotalLeft"><?php echo $total_full; ?></td>
                    		
				    <?php $total_comp+=$total_full; }?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $c+6; ?>">Gross Total</td>
					
				   <td><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
         <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	   
<?php }
		}		

// complete outstanding wt clas start

elseif(isset($_REQUEST['month_report_wtcl'])){
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();
		$overAllNewextra=0; $totalstrength = 0; $totalamount = 0;

		$cls1=$db->getVal("SELECT GROUP_CONCAT('''',class,'''') FROM class");

    	if($_GET['class']!=""){
    	    $classAry = $db->getRows("select class from class where class='$_GET[class]' ");
    	}   else {
    	    $classAry = $db->getRows("select class from class");
    	}

		$m=0;

		if(isset($_REQUEST['fmonth']) && $_REQUEST['fmonth']!=0){
			$month=$_GET["fmonth"];
			
			  if($month<4){
				$m=($month+9);
			  }
			  else{
				$m=$month-3;
			  }
		}
		else{
			$m=12;
		}
		?>
		<style type="text/css">
            @media print {
                #btnduesend {
                    display :  none;
                }
            }
            
            @media print {
                #btnduesend1 {
                    display :  none;
                }
            }
            
            @media print {
                #searchfoertotal {
                    display :  none;
                }
            }
        </style>
        <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
        
         <input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
        <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
		<input type="button" class="btn btn-danger hidet" onclick="getStudentfinePopup()" value="Add Fine" style="float:left;" />
        <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>

        <div class="well no-padding divclass" >

            <?php $clsid = 0;
                foreach($classAry as $class){ 
                $secAry = array();
                $cls = $class['class'];
                if($_GET['section']!=""){
                    $secAry[] = $_GET['section'];
                } else {
                    $sections = $db->getRows("select name from section ");
                    foreach($sections as $sec){
                        $totalstu = $db->getVal("select count(idno) from student where class='$cls' and section='$sec[name]' and session='".$_SESSION["admin"]["session"]."' ");
                        if($totalstu > 0){
                            $secAry[] = $sec["name"];
                        }
                    }
                }

                $secstu = $db->getRows("select * from student where class='$cls' and section='' and session='".$_SESSION["admin"]["session"]."' ");
                $sectotal1 = 0;
                if(count($secstu) > 0 ){ $clsid++; ?>
                <div class="row-fluid mydiv" id="<?php echo $cls; ?>">
                    <table class='table' id="tblData" border="1" cellspacing="0">
                        <thead>
            				<tr>
                            	<th class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></th>
                            	<th>S.No</th>
            					<th>Student Name</th>
                                <th>Father Name</th>
                                <th>Reg. no</th>
            					<th>Class</th>
                                <th>Section</th>
            					<th>Contact No</th>
                                <th>Total</th>
                			</tr>
                        </thead>
                        <tbody>
                            <?php 	//$aryStudentList=$db->getRows("select * from student where  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and status=1 and issue_TC=0 ORDER BY FIELD(class,$cls1)");
                                    $aryStudentList=$db->getRows("select * from student where class='$cls' and section='' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 order by class,section");
                                    $i=0; $total_comp=0;
		
                        			for($i=1; $i<=$m; $i++){
                        				 
                        				$md[]='COALESCE(i'.$i.',0)';
                        				$md1[]='COALESCE(ip'.$i.',0)';
                        				$pid[]= "'p".$i."'";
                        				$pm[]= "'".$i."'";
                        				
                        				$mdb[]='COALESCE(b'.$i.',0)';
                        				$mdb1[]='COALESCE(bp'.$i.',0)';
                        		     }					
                                    $mdf= implode('+',$md);
                                    $mdf1= implode('+',$md1);
                                    
                                    $mdbf= implode('+',$mdb);
                                    $mdbf1= implode('+',$mdb1);
                                    
                                    $pid1 =implode(',',$pid);
                                    $pm1=implode(',',$pm);
                                    $z=0;$tut2=0;$bus2=0;

                					foreach($aryStudentList as $fStudent){
	                				$mn=$m;
	                				
    					      		$aryFeeType=$db->getRows("select distinct(type) from extrafee_type where class='$fStudent[class]' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 order by type");

                        			$tut2=0;$bus2=0;$install_hostel=0;$ext=0;
                        			for($i=1; $i<$m; $i++){
                        				$tut2+=$db->getVal("select i".$i." from installment where  idno='".$fStudent["idno"]."' and (ip".$i." is null or ip".$i."=0)");
                        				
                        				$bus2+=$db->getVal("select b".$i." from installment where  idno='".$fStudent["idno"]."' and (bp".$i." is null or bp".$i."=0)");
                        
                        				 $install_hostel+=$db->getVal("select i".$i." from hostelinstallment where  idno='".$fStudent["idno"]."' and (ip".$i." is null or ip".$i."=0)");
                        
                        				foreach($aryFeeType as $extrafee){
                        					$Ftypeid=$db->getVal("select id from extrafee_type where type='".$extrafee["type"]."' and class='".$fStudent["class"]."'");
                        				    $ext+=$db->getVal("select sum(fee)  from extrafee where type='$Ftypeid' and idno='".$fStudent["idno"]."' and pid ='p".$i."' and pay='0' ");
                        				}
                        			}

                        			$m1=$m+1;

                                	$tut_last=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)");
                                	$bus_last=$db->getVal("select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (bp".$m1." is null or bp".$m1."=0)");

                                    $hostel_last=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from hostelinstallment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)");

                                    foreach($aryFeeType as $extrafee){
                                	    $Ftypeid=$db->getVal("select id from extrafee_type where type='".$extrafee["type"]."' and class='".$fStudent["class"]."'");

                                	    $ext_last=$db->getVal("select sum(pay) from extrafee where type='$Ftypeid' and idno='".$fStudent["idno"]."' and pid ='p".$m1."' and pay='0' ");
                                    	 if($ext_last==0){
                                    		$ext_last1=$db->getVal("select sum(fee-pay)  from extrafee where type='$Ftypeid' and idno='".$fStudent["idno"]."' and pid ='p".$m."'  ");
                                    	 }
                                	     $ext+=$ext_last1;
                                    }

                                	$tut2+=$tut_last;
                                	$bus2+=$bus_last;
                                	$install_hostel+=$hostel_last;

                                    $cls=$fStudent["class"];
                                    $type=$fStudent["stype"];
                                    $htype=$fStudent["htype"];

                                    $other_fee_name= $db->getRow("SELECT sum(fee) as total, GROUP_CONCAT('''',name,'''') as name, GROUP_CONCAT('''',id,'''') as other_id from otherfee_structure WHERE class='$cls' and month in($pm1)  and (otype='".$fStudent[idno]."' or otype='$type' or otype='') and session='".$_SESSION["admin"]["session"]."'");

                                    $string=$other_fee_name[name];
                                    $id3=$other_fee_name[other_id];

                                    $other_fee_given= $db->getVal("SELECT sum(fine) from installment_fine WHERE   idno='".$fStudent[idno]."' and reasion in($string)  and session='".$_SESSION["admin"]["session"]."'");

                                    $total_other_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from otherfee_discount  WHERE idno='".$fStudent[idno]."' and class='$cls' and month in($pm1) and other_id in ($id3) and session='".$_SESSION["admin"]["session"]."' ");

                                    $g= $other_fee_given+$total_other_discount;
                                    
                                    $checkhostel = $db->getVal("select idno from hostelinstallment where idno='".$fStudent[idno]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' ");
                                    if($checkhostel > 0 ){
                                        $hostelother_fee_name= $db->getRow("SELECT sum(fee) as total, GROUP_CONCAT('''',name,'''') as name, GROUP_CONCAT('''',id,'''') as other_id from hostel_otherfee_structure WHERE class='$cls' and month in($pm1)  and (otype='".$fStudent[idno]."' or otype='$htype' or otype='') and session='".$_SESSION["admin"]["session"]."'");
    
                                        $hostelstring = $hostelother_fee_name[name];
                                        $hostelid = $hostelother_fee_name[other_id];
    
                                        $hostelother_fee_given = $db->getVal("SELECT sum(fine) from installment_fine WHERE   idno='".$fStudent[idno]."' and reasion in($hostelstring)  and session='".$_SESSION["admin"]["session"]."'");
                                        $hosteltotal_other_discount = $db->getVal("SELECT COALESCE(sum(discount),0) as result from hostel_otherfee_discount  WHERE idno='".$fStudent[idno]."' and class='$cls' and month in($pm1) and other_id in ($hostelid) and session='".$_SESSION["admin"]["session"]."' ");
    
                                        $hosteldue = $hostelother_fee_given;
                                        $t+=$hostelother_fee_name['total']-$hosteldue-$hosteltotal_other_discount;
                                    }
                                    $t+=$tut2; $t+=$bus2; $t+=$install_hostel; $t+=$ext; $t+=$other_fee_name['total']-$g; 
                                    $totalamount+=$t;
                                    if($t > 0){
                                        $z++;
                                         $totalstrength++; $sectotal1 = 1;
                                    ?>
                          			<tr>
                                		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>
                                    	<td><?php echo $z ?></td>
                        				<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                                        <td><?php echo $fStudent["fname"] ?></td>
                                        <td><?php echo $fStudent["admissionno"] ?></td>
                        				<td><?php echo $fStudent["class"]; //echo "-"; echo $fStudent["section"]  ?></td>
                                        <td><?php  echo $fStudent["section"]; ?></td>
                        				<td><?php echo $fStudent["mobile"]; ?></td>
                                        <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"  ><?php echo $t; $total_comp+=$t; ?></td>
                                    </tr>
                    				<?php } 
                    				$t=0;

                					} ?>

                        </tbody>

            		</table>
                </div>
                <style>
                    @media print {
                    .mydiv {page-break-after: always;}
                    }
                </style>
                <?php
                    if($sectotal1 ==  0){
                        echo "<script>$('#$clsid').remove();</script>";
                    }
                }

                $wheresection = '';        $sections = '';
                
                foreach($secAry as $sec){ $sectotal = 0; $clsid++;
                $secstu = $db->getRows("select * from student where class='$cls' and section='$sec' and session='".$_SESSION["admin"]["session"]."' ");
                    
                    if(count($secstu) > 0 ){ ?>

                    <div class="row-fluid mydiv" id="<?php echo $clsid; ?>">
                    <table class='table' id="tblData" border="1" cellspacing="0">
                        <thead>
            				<tr>
                            	<th class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></th>
                            	<th>S.No</th>
            					<th>Student Name</th>
                                <th>Father Name</th>
                                <th>Reg. no</th>
            					<th>Class</th>
                                <th>Section</th>
            					<th>Contact No</th>
                                <th>Total</th>
                			</tr>
                        </thead>
                        <tbody>
                            <?php 	//$aryStudentList=$db->getRows("select * from student where  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and status=1 and issue_TC=0 ORDER BY FIELD(class,$cls1)");
                                    $aryStudentList=$db->getRows("select * from student where class='$cls' and section='$sec' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 order by class,section");
                                    $i=0; $total_comp=0;
		
                        			for($i=1; $i<=$m; $i++){
                        				 
                        				$md[]='COALESCE(i'.$i.',0)';
                        				$md1[]='COALESCE(ip'.$i.',0)';
                        				$pid[]= "'p".$i."'";
                        				$pm[]= "'".$i."'";
                        				
                        				$mdb[]='COALESCE(b'.$i.',0)';
                        				$mdb1[]='COALESCE(bp'.$i.',0)';
                        		     }					
                                    $mdf= implode('+',$md);
                                    $mdf1= implode('+',$md1);
                                    
                                    $mdbf= implode('+',$mdb);
                                    $mdbf1= implode('+',$mdb1);
                                    
                                    $pid1 =implode(',',$pid);
                                    $pm1=implode(',',$pm);
                                    $z=0;$tut2=0;$bus2=0;

                					foreach($aryStudentList as $fStudent){
	                				$mn=$m;
	                				
    					      		$aryFeeType=$db->getRows("select distinct(type) from extrafee_type where class='$fStudent[class]' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 order by type");

                        			$tut2=0;$bus2=0;$install_hostel=0;$ext=0;
                        			for($i=1; $i<$m; $i++){
                        				$tut2+=$db->getVal("select i".$i." from installment where  idno='".$fStudent["idno"]."' and (ip".$i." is null or ip".$i."=0)");
                        				
                        				$bus2+=$db->getVal("select b".$i." from installment where  idno='".$fStudent["idno"]."' and (bp".$i." is null or bp".$i."=0)");
                        
                        				 $install_hostel+=$db->getVal("select i".$i." from hostelinstallment where  idno='".$fStudent["idno"]."' and (ip".$i." is null or ip".$i."=0)");
                        
                        				foreach($aryFeeType as $extrafee){
                        					$Ftypeid=$db->getVal("select id from extrafee_type where type='".$extrafee["type"]."' and class='".$fStudent["class"]."'");
                        				    $ext+=$db->getVal("select sum(fee)  from extrafee where type='$Ftypeid' and idno='".$fStudent["idno"]."' and pid ='p".$i."' and pay='0' ");
                        				}
                        			}

                        			$m1=$m+1;

                                	$tut_last=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)");
                                	$bus_last=$db->getVal("select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (bp".$m1." is null or bp".$m1."=0)");

                                    $hostel_last=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from hostelinstallment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)");

                                    foreach($aryFeeType as $extrafee){
                                	    $Ftypeid=$db->getVal("select id from extrafee_type where type='".$extrafee["type"]."' and class='".$fStudent["class"]."'");

                                	    $ext_last=$db->getVal("select sum(pay) from extrafee where type='$Ftypeid' and idno='".$fStudent["idno"]."' and pid ='p".$m1."' and pay='0' ");
                                    	 if($ext_last==0){
                                    		$ext_last1=$db->getVal("select sum(fee-pay)  from extrafee where type='$Ftypeid' and idno='".$fStudent["idno"]."' and pid ='p".$m."'  ");
                                    	 }
                                	     $ext+=$ext_last1;
                                    }

                                	$tut2+=$tut_last;
                                	$bus2+=$bus_last;
                                	$install_hostel+=$hostel_last;

                                    $cls=$fStudent["class"];
                                    $type=$fStudent["stype"];
                                    $htype=$fStudent["htype"];

                                    $other_fee_name= $db->getRow("SELECT sum(fee) as total, GROUP_CONCAT('''',name,'''') as name, GROUP_CONCAT('''',id,'''') as other_id from otherfee_structure WHERE class='$cls' and month in($pm1)  and (otype='".$fStudent[idno]."' or otype='$type' or otype='') and session='".$_SESSION["admin"]["session"]."'");

                                    $string=$other_fee_name[name];
                                    $id3=$other_fee_name[other_id];

                                    $other_fee_given= $db->getVal("SELECT sum(fine) from installment_fine WHERE   idno='".$fStudent[idno]."' and reasion in($string)  and session='".$_SESSION["admin"]["session"]."'");

                                    $total_other_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from otherfee_discount  WHERE idno='".$fStudent[idno]."' and class='$cls' and month in($pm1) and other_id in ($id3) and session='".$_SESSION["admin"]["session"]."' ");

                                    $g= $other_fee_given+$total_other_discount;

                                    $checkhostel = $db->getVal("select idno from hostelinstallment where idno='".$fStudent[idno]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' ");
                                    if($checkhostel > 0 ){
                                        $hostelother_fee_name= $db->getRow("SELECT sum(fee) as total, GROUP_CONCAT('''',name,'''') as name, GROUP_CONCAT('''',id,'''') as other_id from hostel_otherfee_structure WHERE class='$cls' and month in($pm1)  and (otype='".$fStudent[idno]."' or otype='$htype' or otype='') and session='".$_SESSION["admin"]["session"]."'");
    
                                        $hostelstring = $hostelother_fee_name[name];
                                        $hostelid = $hostelother_fee_name[other_id];
    
                                        $hostelother_fee_given = $db->getVal("SELECT sum(fine) from installment_fine WHERE   idno='".$fStudent[idno]."' and reasion in($hostelstring)  and session='".$_SESSION["admin"]["session"]."'");
                                        $hosteltotal_other_discount = $db->getVal("SELECT COALESCE(sum(discount),0) as result from hostel_otherfee_discount  WHERE idno='".$fStudent[idno]."' and class='$cls' and month in($pm1) and other_id in ($hostelid) and session='".$_SESSION["admin"]["session"]."' ");
                                        $t+=$hostelother_fee_name['total']-$hosteldue-$hosteltotal_other_discount;
                                    }

                                    $hosteldue = $hostelother_fee_given;
                                    $t+=$tut2; $t+=$bus2; $t+=$install_hostel; $t+=$ext; $t+=$other_fee_name['total']-$g; 
                                    $totalamount+=$t;
                                    if($t > 0){
                                        $z++;
                                         $totalstrength++; $sectotal = 1;
                                    ?>
                          			<tr>
                                		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>
                                    	<td><?php echo $z ?></td>
                        				<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                                        <td><?php echo $fStudent["fname"] ?></td>
                                        <td><?php echo $fStudent["admissionno"] ?></td>
                        				<td><?php echo $fStudent["class"]; //echo "-"; echo $fStudent["section"]  ?></td>
                                        <td><?php  echo $fStudent["section"]; ?></td>
                        				<td><?php echo $fStudent["mobile"]; ?></td>
                                        <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"  ><?php echo $t; $total_comp+=$t; ?></td>
                                    </tr>
                    				<?php } 
                    				$t=0;

                					} ?>

                        </tbody>

            		</table>
                        </div>

                    <style>
                        @media print {
                        .mydiv {page-break-after: always;}
                        }
                    </style>
                    <?php
                    }

                    if((int)$sectotal == 0){ ?>
                        <script>
                            $("#<?php echo $clsid; ?>").remove();
                        </script>
                        <?php
                    }
                }

            } ?>

            <label style="float:left;">Total Students: <?php echo $totalstrength; ?></label>
            <label style="float:right;">Total Dues: <?php echo $totalamount; ?></label>

        </div>

    <?php
}

// complete outstanding wt clas end


// Head wise outstanding start
	elseif(isset($_REQUEST['search_head_fee']))
	{
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					$overAllNewextra=0;
		$cls1=$db->getVal("SELECT GROUP_CONCAT('''',class,'''') FROM class");

        $whereclass = "";
        if($_GET['class']!=""){
            $whereclass .= " class='".$_GET["class"]."' and ";
        }

        if($_GET['section']!=""){
            $whereclass .= " section='".$_GET["section"]."' and ";
        }

		$aryStudentList=$db->getRows("select * from student where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and status=1 and issue_TC=0 ORDER BY FIELD(class,$cls1)");

		$m=0;

		if(isset($_REQUEST['fmonth']) && $_REQUEST['fmonth']!=0){
			$month=$_GET["fmonth"];

			 // if($month<4){
				// $m=($month+9);
			 // }
			 // else{
				// $m=$month-3;
			 // }
			 $m = $_GET['fmonth'];
		}
		else{
			$m=12;
		}

		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>

<style type="text/css">
@media print {
    #btnduesend {
        display :  none;
    }
}

@media print {
    #btnduesend1 {
        display :  none;
    }
}

@media print {
    #searchfoertotal {
        display :  none;
    }
}
</style>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            
             <input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
			<input type="button" class="btn btn-danger hidet" onclick="getStudentfinePopup()" value="Add Fine" style="float:left;" />
            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>

			<a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=DueSheet&fmonth=$_GET[fmonth]&class=$_GET[class]&search_head_fee=&section=$_GET[section]&bus=$_GET[bus]&location=$_GET[location]&head_name=$_GET[head_name]"; ?>" target="_blank" >Full Screen</a>
            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>


			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Month Report Without Class">
				<thead>
				<tr>
                	<!--<td class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></td>-->
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Roll No.</td>
					<td>Contact No</td>

					<?php	
					if($_GET["head_name"] == "Tuition" || $_GET["head_name"] == "Transport" || $_GET["head_name"] == "Hostel")
					{
    					for($i=1;$i<=$m;$i++){?>
    						<th width="0.5%"><?php echo $_GET['head_name']." ".$monthsList1[$i]; ?></th><?php
    					}
					}

					if (in_array($_GET["head_name"], $otherfeeary)){
                        echo "<th>$_GET[head_name]</th>";
                    }

    				if (in_array($_GET["head_name"], $hostelotherfeeary)){
                        echo "<th>$_GET[head_name]</th>";
                    }

                    if (in_array($_GET["head_name"], $extrafeeary)){
                        for($i=1;$i<=$m;$i++){?>
    						<th width="0.5%"><?php echo $_GET['head_name']." ".$monthsList1[$i]; ?></th><?php
    					}
                    }

                    if($_GET["head_name"] == "Back_dues"){
                        echo "<th>$_GET[head_name]</th>";
                    }
					?>

               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0; $total_comp=0;
		
			for($i=1; $i<=$m; $i++){

				$md[]='COALESCE(i'.$i.',0)';
				$md1[]='COALESCE(ip'.$i.',0)';
				$pid[]= "'p".$i."'";
				$pm[]= "'".$i."'";
				
				$mdb[]='COALESCE(b'.$i.',0)';
				$mdb1[]='COALESCE(bp'.$i.',0)';
		     }
					  $mdf= implode('+',$md);
					  $mdf1= implode('+',$md1);

					  $mdbf= implode('+',$mdb);
					  $mdbf1= implode('+',$mdb1);

					  $pid1 =implode(',',$pid);
					  $pm1=implode(',',$pm);
    		          $z=0;$tut2=0;$bus2=0;
    		          
    		          $columntotal = [];
					  foreach($aryStudentList as $fStudent){$z++;
					  $mn=$m;
					  ?>
                      <tr>
                    		<!--<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>-->
                        	<td id="newid<?php echo $z ?>"><?php echo $z ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]; echo "-"; echo $fStudent["section"]  ?></td>
                            <td><?php  echo $fStudent["fincome"]; ?></td>
							<td><?php echo $fStudent["mobile"]; ?></td>
                      <?php

			$tut2=0;$bus2=0;$install_hostel=0;$ext=0; $annualfee=0;
			$rowtotal = 0;

            if($_GET['head_name']=="Tuition" || $_GET['head_name']=="Transport" || $_GET['head_name']=="Hostel"){

			for($i=1; $i<=$m; $i++){

                if($_GET['head_name']=="Tuition"){

                    $installTution=$db->getRow("select i".$i.",ip".$i." from installment where idno='".$fStudent["idno"]."'");

						if(is_array($installTution) && count($installTution)>0){
						    $tution = $installTution["i$i"]-$installTution["ip$i"];
						}else{
							$tution="";
						}
                    $rowtotal+=$tution;
                    $columntotal[$i] += $tution;
                }

                if($_GET['head_name']=="Transport"){

                    $installTution=$db->getRow("select b".$i.",bp".$i." from installment where idno='".$fStudent["idno"]."'");

					if(is_array($installTution) && count($installTution)>0){
					    $trasnport=$installTution["b$i"]-$installTution["bp$i"];
					}   else    {
						$trasnport="";
					}
					
                    $rowtotal+=$trasnport;
                    $columntotal[$i] += $trasnport;
                }


                if($_GET['head_name']=="Hostel"){

                    $installTution=$db->getRow("select i".$i.",ip".$i." from hostelinstallment where idno='".$fStudent["idno"]."'");

						if(is_array($installTution) && count($installTution)>0){
						    $hostel = $installTution["i$i"]-$installTution["ip$i"];
						}else{
							$hostel="";
						}
                    $rowtotal+=$hostel;
                    $columntotal[$i] += $hostel;
                }

                ?>
  				<td> <?php 
  				if($_GET['head_name']=="Tuition"){
  				    if($tution=="0")echo "<lable style='color:red'>paid</label>";elseif($tution=="") echo "<lable style='color:red'>X</label>"; else echo $tution;
  				} 
  				elseif($_GET['head_name']=="Transport"){
  				    if($trasnport=="0")echo "<lable style='color:red'>paid</label>";elseif($trasnport=="") echo "<lable style='color:red'>X</label>";else echo $trasnport;
  				}
  				elseif($_GET['head_name']=="Hostel"){
  				    if($hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($hostel=="") echo "<lable style='color:red'>X</label>";else echo $hostel;
  				}

  				?>
  				</td>

				<?php

			}
		  }

                    if (in_array($_GET["head_name"], $extrafeeary)){
                        $Ftypeid=$db->getVal("select id from extrafee_type where type='".$_GET["head_name"]."' and class='".$fStudent["class"]."'");
                        for($i=1;$i<=$m;$i++){

        						$installTution=$db->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$i."' and idno='".$fStudent["idno"]."'");

								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									$extrafees = $installTution["fee"]-$installTution["pay"];
								}else{
									$extrafees="";
								}

                            echo "<td>";
                            if($extrafees=="0")echo "<lable style='color:red'>paid</label>";elseif($extrafees=="") echo "<lable style='color:red'>X</label>"; else echo $extrafees;
                            echo "</td>";
            
                                $rowtotal+=$extrafees;
                                $columntotal[$i] += $extrafees;
    					}
                    }

        $cls=$fStudent["class"];
        $type=$fStudent["stype"];

		if (in_array($_GET["head_name"], $otherfeeary)){

		   $other_fee_total = $db->getRow("SELECT sum(fee) as total, GROUP_CONCAT('''',name,'''') as name, GROUP_CONCAT('''',id,'''') as other_id from otherfee_structure WHERE name='$_GET[head_name]' and class='$cls' and month in($pm1)  and (otype='".$fStudent[idno]."' or otype='$type' or otype='') and session='".$_SESSION["admin"]["session"]."'");
           $other_fee_given = $db->getVal("SELECT sum(fine) from installment_fine WHERE (reasion like '$_GET[head_name]') and idno='".$fStudent[idno]."'  and session='".$_SESSION["admin"]["session"]."'");
           $other_fee_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from otherfee_discount  WHERE idno='".$fStudent[idno]."' and class='$cls' and month in($pm1) and other_id in ($other_fee_total[other_id]) and session='".$_SESSION["admin"]["session"]."' ");
           if($other_fee_total['total'] > 0){
            $otherfee = $other_fee_total['total'] - ($other_fee_given+$other_fee_discount);
           }
           else {
               $otherfee = "";
           }

                $rowtotal+=$otherfee;
                $columntotal[0]+= $otherfee;

                echo "<td>";
                if($otherfee=="0")echo "<lable style='color:red'>paid</label>";elseif($otherfee=="") echo "<lable style='color:red'>X</label>"; else echo $otherfee;
                echo "</td>";
			}

		if (in_array($_GET["head_name"], $hostelotherfeeary)){
		   $other_fee_total = $db->getRow("SELECT sum(fee) as total, GROUP_CONCAT('''',name,'''') as name, GROUP_CONCAT('''',id,'''') as other_id from hostel_otherfee_structure WHERE name='$_GET[head_name]' and class='$cls' and month in($pm1)  and (otype='".$fStudent[idno]."' or otype='$fStudent[htype]' or otype='') and session='".$_SESSION["admin"]["session"]."'");
           $other_fee_given = $db->getVal("SELECT sum(fine) from installment_fine WHERE (reasion like '$_GET[head_name]') and idno='".$fStudent[idno]."'  and session='".$_SESSION["admin"]["session"]."'");
           $other_fee_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from hostelotherfee_discount  WHERE idno='".$fStudent[idno]."' and class='$cls' and month in($pm1) and other_id in ($other_fee_total[other_id]) and session='".$_SESSION["admin"]["session"]."' ");
           if($other_fee_total['total'] > 0){
            $otherfee = $other_fee_total['total'] - ($other_fee_given+$other_fee_discount);
           }
           else {
               $otherfee = "";
           }

                $rowtotal+=$otherfee;
                $columntotal[0]+= $otherfee;

                echo "<td>";
                if($otherfee=="0")echo "<lable style='color:red'>paid</label>";elseif($otherfee=="") echo "<lable style='color:red'>X</label>"; else echo $otherfee;
                echo "</td>";
			}
			
            if($_GET["head_name"] == "Back_dues"){

                $other_fee_total = $db->getRow("SELECT sum(fee) as total, GROUP_CONCAT('''',name,'''') as name, GROUP_CONCAT('''',id,'''') as other_id from otherfee_structure WHERE name='$_GET[head_name]' and class='".$fStudent['class']."' and month in($pm1)  and otype='".$fStudent[idno]."' and session='".$_SESSION["admin"]["session"]."'");
                $other_fee_given = $db->getVal("SELECT sum(fine) from installment_fine WHERE (reasion like '$_GET[head_name]') and idno='".$fStudent[idno]."'  and session='".$_SESSION["admin"]["session"]."'");
                $other_fee_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from otherfee_discount  WHERE idno='".$fStudent[idno]."' and class='".$fStudent['class']."' and month in($pm1) and other_id in ($other_fee_total[other_id]) and session='".$_SESSION["admin"]["session"]."' ");

                if($other_fee_total['total'] > 0){
                    $otherfee = $other_fee_total['total'] - ($other_fee_given+$other_fee_discount);
                }
                else {
                    $otherfee = "";
                }

                $rowtotal+=$otherfee;
                $columntotal[0]+= $otherfee;

                echo "<td>";
                if($otherfee=="0")echo "<lable style='color:red'>paid</label>";elseif($otherfee=="") echo "<lable style='color:red'>X</label>"; else echo $otherfee;
                echo "</td>";
                
            }

          ?>
                <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"  ><?php echo $rowtotal; $total_comp+=$rowtotal; ?></td>
                <!--<td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"  ><?php //echo $t; $total_comp+=$t; ?></td>-->
				<?php $t=0; }?>
			</tbody>
				<tfoot>
					<td colspan="7">Gross Total</td>

                    <?php
                        if($_GET['head_name']=="Tuition" || $_GET['head_name']=="Transport" || $_GET['head_name']=="Hostel"){              
            	    		for($i=1; $i<=$m; $i++){
                			    echo "<td>$columntotal[$i]</td>";
                			}
                        }
            			
            			if (in_array($_GET["head_name"], $otherfeeary)){
            			    echo "<td>$columntotal[0]</td>";
            			}

            			if (in_array($_GET["head_name"], $hostelotherfeeary)){
            			    echo "<td>$columntotal[0]</td>";
            			}

            			if (in_array($_GET["head_name"], $extrafeeary)){
            			    for($i=1; $i<=$m; $i++){
            			        echo "<td>$columntotal[$i]</td>";
            			    }
            			}
            			
			            if($_GET["head_name"] == "Back_dues"){
			                echo "<td>$columntotal[0]</td>";
			            }
        			?>
					
				   <td id="MyTotalLeft"><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
}
// Head wise outstanding end

// back_dues_outstanding start
    
    elseif(isset($_REQUEST['back_dues_outstanding'])){

        $allstudents = $db->getRows("SELECT * from otherfee_structure WHERE (name='Back_dues' or name='Back_Dues') and session='".$_SESSION["admin"]["session"]."' ");
        ?>
        <center>

        <input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
        <h5><p style="float:right">Session: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Back Dues Fee outstanding</p></h5></center>

			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Month Report Without Class">
				<thead>
    				<tr>
                    	<!--<td class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></td>-->
                    	<td>S.No</td>
        				<td>Student Name</td>
                        <th>Father Name</th>
                        <th>Reg. no</th>
        				<td>Class</td>
                        <td>Roll No.</td>
        				<td>Contact No</td>
        				<td>Back_dues</td>
        			</tr>
    			</thead>
    			<tbody>
    			    <?php foreach($allstudents as $stu){ $i++;
    			        
    			        $student = $db->getRow("select * from student where idno='$stu[otype]' and status='1' and session='".$_SESSION["admin"]["session"]."' ");
    			        
        			    $fee_given = $db->getVal("SELECT sum(amount) from reff_receipt WHERE type='$stu[name]' and idno='$stu[otype]' and session='".$_SESSION["admin"]["session"]."' ");
        			    $discount = $db->getVal("SELECT COALESCE(sum(discount),0) as result from otherfee_discount  WHERE idno='$stu[otype]' and session='".$_SESSION["admin"]["session"]."' ");
        			    
        			    if($stu['fee'] > 0){
                            $otherfee = $stu['fee'] - ($fee_given+$discount);
                        }
                        else {
                            $otherfee = "";
                        }
                        $total+=$otherfee;
    			    ?>
    			        <tr>
    			            <td><?php echo $i; ?></td>
    			            <td><?php echo $student['name']; ?></td>
    			            <td><?php echo $student['fname']; ?></td>
    			            <td><?php echo $student['admissionno']; ?></td>
    			            <td><?php echo $student['class']; ?></td>
    			            <td><?php echo $student['fincome']; ?></td>
    			            <td><?php echo $student['mobile']; ?></td>
    			            <td>
    			            <?php if($otherfee=="0")echo "<lable style='color:red'>paid</label>";elseif($otherfee=="") echo "<lable style='color:red'>X</label>"; else echo $otherfee; ?>
                            </td>
    			        </tr>
    			    <?php } ?>
    			</tbody>
    			<tfoot>
    			    <tr>
    			        <td colspan="7">Total Back Dues</td>
    			        <td><?php echo $total; ?></td>
    			    </tr>
    			</tfoot>
    		</table>
    <?php
    }
    
// back_dues_outstanding end


// Single Month outstanding starts

	elseif(isset($_REQUEST['single_month_dues']))
	{
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					$overAllNewextra=0;
		$cls1=$db->getVal("SELECT GROUP_CONCAT('''',class,'''') FROM class");

        $whereclass = "";			
        if($_GET['class']!=""){
            $whereclass = " class='".$_GET["class"]."' and ";
        }

        if($_GET['section']!=""){
            $whereclass .= " section='".$_GET["section"]."' and ";
        }

		$aryStudentList=$db->getRows("select * from student where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and status=1 and issue_TC=0 ORDER BY FIELD(class,$cls1)");

		$m=0;

		if(isset($_REQUEST['fmonth']) && $_REQUEST['fmonth']!=0){
			$month=$_GET["fmonth"];

			 // if($month<4){
				// $m=($month+9);
			 // }
			 // else{
				// $m=$month-3;
			 // }
			 $m = $_GET['fmonth'];
		}
		else{
			$m=12;
		}

		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>

<style type="text/css">
@media print {
    #btnduesend {
        display :  none;
    }
}

@media print {
    #btnduesend1 {
        display :  none;
    }
}

@media print {
    #searchfoertotal {
        display :  none;
    }
}
</style>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            
             <input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
			<input type="button" class="btn btn-danger hidet" onclick="getStudentfinePopup()" value="Add Fine" style="float:left;" />
            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>

			<a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=DueSheet&fmonth=$_GET[fmonth]&class=$_GET[class]&single_month_dues=&section=$_GET[section]&bus=$_GET[bus]&location=$_GET[location]&head_name=$_GET[head_name]"; ?>" target="_blank" >Full Screen</a>
            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>

			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Month Report Without Class">
				<thead>
				<tr>
                	<!--<td class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></td>-->
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Roll No.</td>
					<td>Contact No</td>
                    <th width="0.5%"><?php echo $_GET['head_name']." ".$monthsList1[$m]; ?></th>
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0; $total_comp=0;

            // 	for($i=1; $i<=$m; $i++){
				$i = $m;
				$md[]='COALESCE(i'.$i.',0)';
				$md1[]='COALESCE(ip'.$i.',0)';
				$pid[]= "'p".$i."'";
				$pm[]= "'".$i."'";
				
				$mdb[]='COALESCE(b'.$i.',0)';
				$mdb1[]='COALESCE(bp'.$i.',0)';
		    //   }
					  $mdf= implode('+',$md);
					  $mdf1= implode('+',$md1);

					  $mdbf= implode('+',$mdb);
					  $mdbf1= implode('+',$mdb1);

					  $pid1 =implode(',',$pid);
					  $pm1=implode(',',$pm);
    		          $z=0;$tut2=0;$bus2=0;
    		          
    		          $columntotal = [];
					  foreach($aryStudentList as $fStudent){$z++;
					  $mn=$m;
					  ?>
                      <tr>
                    		<!--<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>-->
                        	<td id="newid<?php echo $z ?>"><?php echo $z ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]; echo "-"; echo $fStudent["section"]  ?></td>
                            <td><?php  echo $fStudent["fincome"]; ?></td>
							<td><?php echo $fStudent["mobile"]; ?></td>
                      <?php

			$tut2=0;$bus2=0;$install_hostel=0;$ext=0; $annualfee=0;
			$rowtotal = 0;
            $i = $m;
            if($_GET['head_name']=="Tuition" || $_GET['head_name']=="Transport" || $_GET['head_name']=="Hostel"){

// 			for($i=1; $i<=$m; $i++){

                if($_GET['head_name']=="Tuition"){

                    $installTution=$db->getRow("select i".$i.",ip".$i." from installment where idno='".$fStudent["idno"]."'");

						if(is_array($installTution) && count($installTution)>0){
						    $tution = $installTution["i$i"]-$installTution["ip$i"];
						}else{
							$tution="";
						}
                    $rowtotal+=$tution;
                    $columntotal[0] += $tution;
                }

                if($_GET['head_name']=="Transport"){

                    $installTution=$db->getRow("select b".$i.",bp".$i." from installment where idno='".$fStudent["idno"]."'");

					if(is_array($installTution) && count($installTution)>0){
						$trasnport=$installTution["b$i"]-$installTution["bp$i"];
					}   else    {
						$trasnport="";
					}
					
                    $rowtotal+=$trasnport;
                    $columntotal[0] += $trasnport;
                }


                if($_GET['head_name']=="Hostel"){

                    $installTution=$db->getRow("select i".$i.",ip".$i." from hostelinstallment where idno='".$fStudent["idno"]."'");

						if(is_array($installTution) && count($installTution)>0){
							$hostel = $installTution["i$i"]-$installTution["ip$i"];
						}else{
							$hostel="";
						}
                    $rowtotal+=$hostel;
                    $columntotal[0] += $hostel;
                }

                ?>
  				<td> <?php 
  				if($_GET['head_name']=="Tuition"){
  				    if($tution=="0")echo "<lable style='color:red'>paid</label>";elseif($tution=="") echo "<lable style='color:red'>X</label>"; else echo $tution;
  				} 
  				elseif($_GET['head_name']=="Transport"){
  				    if($trasnport=="0")echo "<lable style='color:red'>paid</label>";elseif($trasnport=="") echo "<lable style='color:red'>X</label>";else echo $trasnport;
  				}
  				elseif($_GET['head_name']=="Hostel"){
  				    if($hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($hostel=="") echo "<lable style='color:red'>X</label>";else echo $hostel;
  				}

  				?>
  				</td>

				<?php

// 			}
		  }

                    if (in_array($_GET["head_name"], $extrafeeary)){
                        $Ftypeid=$db->getVal("select id from extrafee_type where type='".$_GET["head_name"]."' and class='".$fStudent["class"]."'");

        						$installTution=$db->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$i."' and idno='".$fStudent["idno"]."'");

								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									$extrafees = $installTution["fee"]-$installTution["pay"];
								} else {
									$extrafees = "";
								}

                            echo "<td>";
                            if($extrafees=="0")echo "<lable style='color:red'>paid</label>";elseif($extrafees=="") echo "<lable style='color:red'>X</label>"; else echo $extrafees;
                            echo "</td>";

                                $rowtotal+=$extrafees;
                                $columntotal[0] += $extrafees;

                    }

        $cls=$fStudent["class"];
        $type=$fStudent["stype"];

		if (in_array($_GET["head_name"], $otherfeeary)){

		   $other_fee_total = $db->getRow("SELECT sum(fee) as total, GROUP_CONCAT('''',name,'''') as name, GROUP_CONCAT('''',id,'''') as other_id from otherfee_structure WHERE name='$_GET[head_name]' and class='$cls' and month in($pm1)  and (otype='".$fStudent[idno]."' or otype='$type' or otype='') and session='".$_SESSION["admin"]["session"]."'");
           $other_fee_given = $db->getVal("SELECT sum(fine) from installment_fine WHERE (reasion like '$_GET[head_name]') and idno='".$fStudent[idno]."'  and session='".$_SESSION["admin"]["session"]."'");
           $other_fee_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from otherfee_discount  WHERE idno='".$fStudent[idno]."' and class='$cls' and month in($pm1) and other_id in ($other_fee_total[other_id]) and session='".$_SESSION["admin"]["session"]."' ");
           if($other_fee_total['total'] > 0){
            $otherfee = $other_fee_total['total'] - ($other_fee_given+$other_fee_discount);
           }
           else {
               $otherfee = "";
           }

                $rowtotal+=$otherfee;
                $columntotal[0]+= $otherfee;

                echo "<td>";
                if($otherfee=="0")echo "<lable style='color:red'>paid</label>";elseif($otherfee=="") echo "<lable style='color:red'>X</label>"; else echo $otherfee;
                echo "</td>";
			}

		if (in_array($_GET["head_name"], $hostelotherfeeary)){

		   $other_fee_total = $db->getRow("SELECT sum(fee) as total, GROUP_CONCAT('''',name,'''') as name, GROUP_CONCAT('''',id,'''') as other_id from hostel_otherfee_structure WHERE name='$_GET[head_name]' and class='$cls' and month in($pm1)  and (otype='".$fStudent[idno]."' or otype='$type' or otype='') and session='".$_SESSION["admin"]["session"]."'");
           $other_fee_given = $db->getVal("SELECT sum(fine) from installment_fine WHERE (reasion like '$_GET[head_name]') and idno='".$fStudent[idno]."'  and session='".$_SESSION["admin"]["session"]."'");
           $other_fee_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from hostelotherfee_discount  WHERE idno='".$fStudent[idno]."' and class='$cls' and month in($pm1) and other_id in ($other_fee_total[other_id]) and session='".$_SESSION["admin"]["session"]."' ");
           if($other_fee_total['total'] > 0){
            $otherfee = $other_fee_total['total'] - ($other_fee_given+$other_fee_discount);
           }
           else {
               $otherfee = "";
           }

                $rowtotal+=$otherfee;
                $columntotal[0]+= $otherfee;

                echo "<td>";
                if($otherfee=="0")echo "<lable style='color:red'>paid</label>";elseif($otherfee=="") echo "<lable style='color:red'>X</label>"; else echo $otherfee;
                echo "</td>";
			}
			
            if($_GET["head_name"] == "Back_dues"){

                $other_fee_total = $db->getRow("SELECT sum(fee) as total, GROUP_CONCAT('''',name,'''') as name, GROUP_CONCAT('''',id,'''') as other_id from otherfee_structure WHERE name='$_GET[head_name]' and class='".$fStudent['class']."' and month in($pm1)  and otype='".$fStudent[idno]."' and session='".$_SESSION["admin"]["session"]."'");
                $other_fee_given = $db->getVal("SELECT sum(fine) from installment_fine WHERE (reasion like '$_GET[head_name]') and idno='".$fStudent[idno]."'  and session='".$_SESSION["admin"]["session"]."'");
                $other_fee_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from otherfee_discount  WHERE idno='".$fStudent[idno]."' and class='".$fStudent['class']."' and month in($pm1) and other_id in ($other_fee_total[other_id]) and session='".$_SESSION["admin"]["session"]."' ");

                if($other_fee_total['total'] > 0){
                    $otherfee = $other_fee_total['total'] - ($other_fee_given+$other_fee_discount);
                }
                else {
                    $otherfee = "";
                }

                $rowtotal+=$otherfee;
                $columntotal[0]+= $otherfee;

                echo "<td>";
                if($otherfee=="0")echo "<lable style='color:red'>paid</label>";elseif($otherfee=="") echo "<lable style='color:red'>X</label>"; else echo $otherfee;
                echo "</td>";
                
            }

          ?>
                <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"  ><?php echo $rowtotal; $total_comp+=$rowtotal; ?></td>
                <!--<td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"  ><?php //echo $t; $total_comp+=$t; ?></td>-->
				<?php $t=0; }?>
			</tbody>
				<tfoot>
					<td colspan="7">Gross Total</td>

                    <?php
			             echo "<td>$columntotal[0]</td>";
        			?>
					
				   <td id="MyTotalLeft"><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
}

// Single Month outstanding end

// complete outstanding wt clas due start
	elseif(isset($_REQUEST['month_report_wtcl_due']))
	{
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					$overAllNewextra=0;
		$cls1=$db->getVal("SELECT GROUP_CONCAT('''',class,'''') FROM class");
		
		$aryStudentList=$db->getRows("select * from student where  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and status=1 and issue_TC=0 ORDER BY FIELD(class,$cls1)");
			
		$m=0;
		//echo  $_REQUEST['fmonth'];
		if(isset($_REQUEST['fmonth']) && $_REQUEST['fmonth']!=0){
			$month=$_GET["fmonth"];
			
			  if($month<4){
				$m=($month+9);
			  }
			  else{
				$m=$month-3;
			  }
		}
		else{
			$m=12;
		}
		  //echo $m;
		 
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
			
<style type="text/css">
@media print {
    #btnduesend {
        display :  none;
    }
}

@media print {
    #btnduesend1 {
        display :  none;
    }
}

@media print {
    #searchfoertotal {
        display :  none;
    }
}
</style>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            
             <input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
			<input type="button" class="btn btn-danger hidet" onclick="getStudentfinePopup()" value="Add Fine" style="float:left;" />
            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Complete Outstanding without class due">
				<thead>
				<tr>
                	<td class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></td>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
                     
						<th width="0.5%">Tution </th>
						<th width="0.5%">Transport</th>
						<th>Hostel</th>
                    <th>Extra</th>
                    <th>Other</th>
              
					
                    
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0; $total_comp=0;
		
			for($i=1; $i<=$m; $i++){
				 
				$md[]='COALESCE(i'.$i.',0)';
				$md1[]='COALESCE(ip'.$i.',0)';
				$pid[]= "'p".$i."'";
				$pm[]= "'".$i."'";
				
				$mdb[]='COALESCE(b'.$i.',0)';
				$mdb1[]='COALESCE(bp'.$i.',0)';
		     }					
					 $mdf= implode('+',$md);
					  $mdf1= implode('+',$md1);
					 
					  $mdbf= implode('+',$mdb);
					  $mdbf1= implode('+',$mdb1);
					  
					   $pid1 =implode(',',$pid);
					   $pm1=implode(',',$pm);
		          $z=0;$tut2=0;$bus2=0;
					foreach($aryStudentList as $fStudent){$z++;
					$mn=$m;
					?>
                    <tr>
                    		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>
                        	<td><?php echo $z ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                         <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]; //echo "-"; echo $fStudent["section"]  ?></td>
                            <td><?php  echo $fStudent["section"]; ?></td>
							<td><?php echo $fStudent["mobile"]; ?></td>
                      <?php // tution 
					      
			//$install=$db->getRow("select (($mdf)-($mdf1)) as tution, (($mdbf)-($mdbf1)) as bus  from installment where idno='".$fStudent["idno"]."'");
			$tut2=0;$bus2=0;$install_hostel=0;$ext=0;
			for($i=1; $i<=$m; $i++){
								
				 $tut2+=$db->getVal("select i".$i." from installment where  idno='".$fStudent["idno"]."' ");
				
				 $bus2+=$db->getVal("select b".$i." from installment where  idno='".$fStudent["idno"]."' ");

				 $install_hostel+=$db->getVal("select i".$i." from hostelinstallment where  idno='".$fStudent["idno"]."' ");
												
				 $ext+=$db->getVal("select sum(fee)  from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$i."'  ");
			}			
			/*
			$m1=$m+1;
			
	$tut_last=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)");
	$bus_last=$db->getVal("select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (bp".$m1." is null or bp".$m1."=0)");
	
	//echo $fStudent["idno"].'<br>';
	
	 $hostel_last=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from hostelinstallment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)");
	 
	 $ext_last=$db->getVal("select sum(pay) from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$m1."' and pay='0' ");
 
	 if($ext_last==0){		 
		$ext_last1=$db->getVal("select sum(fee-pay)  from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$m."'  ");
				
	 }
	
	$tut2+=$tut_last;
	$bus2+=$bus_last;
	$install_hostel+=$hostel_last;
    $ext+=$ext_last1;
*/
					  ?>					  
				<td><?php echo $tut2; $t+=$tut2 ?></td>
				<td><?php echo $bus2; $t+=$bus2;  ?></td>
				<td><?php echo $install_hostel; $t+=$install_hostel; ?></td>	
				<?php
				
                  //$ext=$db->getVal("select sum(fee)  from extrafee where idno='".$fStudent["idno"]."' and pid in ($pid1) and pay='0' ");
				  				  
				?>
				<td><?php  echo $ext; $t+=$ext; ?></td>
          <?php 
             $cls=$fStudent["class"];
             $type=$fStudent["stype"];
	  
          $other_fee_name= $db->getRow("SELECT sum(fee) as total, GROUP_CONCAT('''',name,'''') as name, GROUP_CONCAT('''',id,'''') as other_id from otherfee_structure WHERE class='$cls' and month in($pm1)  and (otype='".$fStudent[idno]."' or otype='$type' or otype='') and session='".$_SESSION["admin"]["session"]."'");

		  $string=$other_fee_name[name];
		  $id3=$other_fee_name[other_id];
					
		  //$other_fee_given= $db->getVal("SELECT sum(fine) from installment_fine WHERE   idno='".$fStudent[idno]."' and reasion in($string)  and session='".$_SESSION["admin"]["session"]."'");

		  $total_other_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from otherfee_discount  WHERE idno='".$fStudent[idno]."' and class='$cls' and month in($pm1) and other_id in ($id3) and session='".$_SESSION["admin"]["session"]."' ");

		  //$g= $other_fee_given+$total_other_discount;
		  $g= $total_other_discount;
						
          ?>				
				<td><?php echo $other_fee_name['total']-$g; $t+=$other_fee_name['total']-$g; ?></td>
									
                <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $t; $total_comp+=$t; ?></td>		
				<?php $t=0; }?>
			</tbody>
				<tfoot>
					<td colspan="13">Gross Total</td>
					
				   <td id="MyTotalLeft"><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
}
// complete outstanding wt clas end

		// location wise start
	elseif(isset($_REQUEST['location_wise'])){
				$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					$overAllNewextra=0;
		$cls1=$db->getVal("SELECT GROUP_CONCAT('''',class,'''') FROM class");
		
		$aryStudentList=$db->getRows("select * from student where  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  and location='".$_GET['location']."' and status=1 and issue_TC=0 ORDER BY FIELD(class,$cls1)");
			
		$m=0;
		//echo  $_REQUEST['fmonth'];
		if(isset($_REQUEST['fmonth']) && $_REQUEST['fmonth']!=0){
			$month=$_GET["fmonth"];
			
			  if($month<4){
				$m=($month+9);
			  }
			  else{
				$m=$month-3;
			  }
		}
		else{
			$m=12;
		}
		  //echo $m;
		 
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
			
<style type="text/css">
@media print {
    #btnduesend {
        display :  none;
    }
}

@media print {
    #btnduesend1 {
        display :  none;
    }
}

@media print {
    #searchfoertotal {
        display :  none;
    }
}
</style>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            
             <input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
			<input type="button" class="btn btn-danger hidet" onclick="getStudentfinePopup()" value="Add Fine" style="float:left;" />
            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>

			<a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=DueSheet&fmonth=$_GET[fmonth]&class=$_GET[class]&location_wise=&section=$_GET[section]&bus=$_GET[bus]&location=$_GET[location]&head_name=$_GET[head_name]"; ?>" target="_blank" >Full Screen</a>
            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>

			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Location Wise">
				<thead>
				<tr>
                	<td class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></td>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
                     
						<th width="0.5%">Tution </th>
						<th width="0.5%">Transport</th>
						<th>Hostel</th>
                    <th>Extra</th>
                    <th>Other</th>
              
					
                    
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0; $total_comp=0;
		
			for($i=1; $i<=$m; $i++){
				 
				$md[]='COALESCE(i'.$i.',0)';
				$md1[]='COALESCE(ip'.$i.',0)';
				$pid[]= "'p".$i."'";
				$pm[]= "'".$i."'";
				
				$mdb[]='COALESCE(b'.$i.',0)';
				$mdb1[]='COALESCE(bp'.$i.',0)';
		     }					
					 $mdf= implode('+',$md);
					  $mdf1= implode('+',$md1);
					 
					  $mdbf= implode('+',$mdb);
					  $mdbf1= implode('+',$mdb1);
					  
					   $pid1 =implode(',',$pid);
					   $pm1=implode(',',$pm);
		          $z=0;$tut2=0;$bus2=0;
					foreach($aryStudentList as $fStudent){$z++;
					$mn=$m;
					?>
                    <tr>
                    		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>
                        	<td><?php echo $z ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                         <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]; //echo "-"; echo $fStudent["section"]  ?></td>
                            <td><?php  echo $fStudent["section"]; ?></td>
							<td><?php echo $fStudent["mobile"]; ?></td>
                      <?php // tution 
					      
			//$install=$db->getRow("select (($mdf)-($mdf1)) as tution, (($mdbf)-($mdbf1)) as bus  from installment where idno='".$fStudent["idno"]."'");
			$tut2=0;$bus2=0;$install_hostel=0;$ext=0;
			for($i=1; $i<$m; $i++){
								
				$tut2+=$db->getVal("select i".$i." from installment where  idno='".$fStudent["idno"]."' and (ip".$i." is null or ip".$i."=0)");
				
				$bus2+=$db->getVal("select b".$i." from installment where  idno='".$fStudent["idno"]."' and (bp".$i." is null or bp".$i."=0)");

				 $install_hostel+=$db->getVal("select i".$i." from hostelinstallment where  idno='".$fStudent["idno"]."' and (ip".$i." is null or ip".$i."=0)");
												
				$ext+=$db->getVal("select sum(fee)  from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$i."' and pay='0' ");
			}
			
			$m1=$m+1;
		//echo $ss="select (i".$m."-COALESCE(ip".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)";	
	$tut_last=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)");
	$bus_last=$db->getVal("select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (bp".$m1." is null or bp".$m1."=0)");
	
	//echo $fStudent["idno"].'<br>';
	
	 $hostel_last=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from hostelinstallment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)");
	 
	 $ext_last=$db->getVal("select sum(pay) from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$m1."' and pay='0' ");
 
	 if($ext_last==0){		 
		$ext_last1=$db->getVal("select sum(fee-pay)  from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$m."'  ");
				
	 }
	
	$tut2+=$tut_last;
	$bus2+=$bus_last;
	$install_hostel+=$hostel_last;
    $ext+=$ext_last1;

					  ?>					  
				<td><?php echo $tut2; $t+=$tut2 ?></td>
				<td><?php echo $bus2; $t+=$bus2;  ?></td>
				<td><?php echo $install_hostel; $t+=$install_hostel; ?></td>	
				<?php
				
                  //$ext=$db->getVal("select sum(fee)  from extrafee where idno='".$fStudent["idno"]."' and pid in ($pid1) and pay='0' ");
				  				  
				?>
				<td><?php  echo $ext; $t+=$ext; ?></td>
          <?php 
             $cls=$fStudent["class"];
             $type=$fStudent["stype"];
	  
          $other_fee_name= $db->getRow("SELECT sum(fee) as total, GROUP_CONCAT('''',name,'''') as name, GROUP_CONCAT('''',id,'''') as other_id from otherfee_structure WHERE class='$cls' and month in($pm1)  and (otype='".$fStudent[idno]."' or otype='$type' or otype='') and session='".$_SESSION["admin"]["session"]."'");

		 $string=$other_fee_name[name];
		 $id3=$other_fee_name[other_id];
		
			
		  $other_fee_given= $db->getVal("SELECT sum(fine) from installment_fine WHERE   idno='".$fStudent[idno]."' and reasion in($string)  and session='".$_SESSION["admin"]["session"]."'");

		  $total_other_discount=$db->getVal("SELECT COALESCE(sum(discount),0) as result from otherfee_discount  WHERE idno='".$fStudent[idno]."' and class='$cls' and month in($pm1) and other_id in ($id3) and session='".$_SESSION["admin"]["session"]."' ");

		  $g= $other_fee_given+$total_other_discount;
						
          ?>				
				<td><?php echo $other_fee_name['total']-$g; $t+=$other_fee_name['total']-$g; ?></td>
							
                <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"  ><?php echo $t; $total_comp+=$t; ?></td>		
				<?php $t=0; }?>
			</tbody>
				<tfoot>
					<td colspan="13">Gross Total</td>
					
				   <td id="MyTotalLeft"><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
		}

		// location wise end

	elseif(isset($_GET['only_hostel']))
	{
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					
		$overAllNewextra=0;

        $whereclass = "";
        $whereclass1 = "";
        if($_GET['class']!=""){
            $whereclass .= " class='".$_GET["class"]."' and ";
            $whereclass1 .= " s.class='".$_GET["class"]."' and ";
        }

        $wheresection = "";
        if($_GET['section']!=""){
            $wheresection .= " s.section='".$_GET["section"]."' and ";
        }

// 		$aryStudentList=$db->getRows("select * from student where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");

        $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";
		$aryStudentList=$db->getRows("SELECT s.* FROM ".$table." where $whereclass1 $wheresection s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".$where." order by s.name");

		$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");
		 
		$m=0;
		if(isset($_GET['fmonth']) && $_GET['fmonth']!=0){
			$month=$_GET["fmonth"];
			 // if($month<4){
				// $m=($month+9);
			 // }
			 // else{
				// $m=$month-3;
			 // }
			 
			 $m = $_GET['fmonth'];

		}
		else{
			$m=12;
			
		}
		  //echo $m;
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
			
<style type="text/css">
@media print {
    #btnduesend {
        display :  none;
    }
}

@media print {
    #btnduesend1 {
        display :  none;
    }
}

@media print {
    #searchfoertotal {
        display :  none;
    }
}
</style>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            
            <input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
			<input type="button" class="btn btn-danger hidet" onclick="getStudentfinePopup()" value="Add Fine" style="float:left;" />
			<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" style="float:left;">Sms Preview</a>


            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>

			<a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=DueSheet&fmonth=$_GET[fmonth]&class=$_GET[class]&month_report=&section=$_GET[section]&bus=$_GET[bus]&location=$_GET[location]&head_name=$_GET[head_name]"; ?>" target="_blank" >Full Screen</a>
            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>

			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Complete Outstanding">
				<thead>
				<tr>
                	<th class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></th>
                	<th>S.No</th>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<th>Class</th>
                    <th>Roll No</th>
					<th>Contact No</th>
                     <?php
			   if(is_array($monthsList1) && count($monthsList1)>0){
					for($i=1;$i<=$m;$i++){?>
						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
					}
			   }
// echo "select * from otherfee_structure where   school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' )  and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'";
			   $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
				// 	echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
                    <th>Back Dues</th>
              <?php 
			  
			  $install=$db->getRows("select * from hostel_otherfee_structure where $whereclass  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'  GROUP BY name");
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
					<th>Total_other</th>
                    <th>Fine</th>
               <th>Total</th>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;
			for($j=1; $j<=$m; $j++){
						$md[]=$j;
					}					
					//print_r($md);
					 $mdf= implode(',',$md);

                    $monthlycolumn = [];
                    $otherfeecolumn = [];
					$backduescolumn = [];
					$hostelothercolumn = [];
					$totalothercolumn = [];
					$finecolumn = [];
					
					 
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                    		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>
                        	<td id="newid<?php echo $i ?>"><?php echo $i ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?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 $fStudent["fincome"];?></td>
							<td><?php echo $fStudent["mobile"]; ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							$m1=$m+1;			
							foreach($monthsList1 as $key=>$val){$count++;

							if($mn===0){
							
							}
							else{ $mn--;
						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $tution = $installTution["i$key"]-$installTution["ip$key"];
						}else{
							$tution="";
						}
						$overAlltution=$tution;

						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $trasnport=$installTution["b$key"]-$installTution["bp$key"];
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;

						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $hostel = $installTution["i$key"] - $installTution["ip$key"];
						}else{
							$hostel="";
						}
						$overAllhotel=$hostel;
						
						$extrasum=array();
						$extrafeesingle = 0;
						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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
								    $sums = $installTution["fee"]-$installTution["pay"];
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
								$extrafeesingle+=$sums;
							}
						}
                        $monthlycolumn[$key] +=$tution+$trasnport+$hostel+$extrafeesingle; 
						
						 $overAllNewextra=0;
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						}

						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhotel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhotel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhotel+$overAllNewextra;}

			$total_full=$total_full+$total;
			?><td><?php if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td>

					<?php }}

						$other2=0; $c = 0;

                    $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                    foreach($install as $ins){ $c++;
                        $over = "";
                            $exists = $db->getRow("select * from otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' ");
						    if($exists > 1){
    						    $fee = $exists['fee'];
    						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");

    						    $discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' "); 

    						    if($fStudent['stype']=="old" && $exists['otype']=="new"){
								    $over="";
    							}
    						   elseif($fStudent['stype']=="new" && $exists['otype']=="old"){
    								$over="";
    							}
    							else {
    							    $over = $exists['fee'] - $discount - $paid;
        							$other2+=$over;
    							}

						    }
						    else {
						        $over = "";
						    }
                        $otherfeecolumn[$c]+= $over;
						?>
						<td> <?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
						<?php
					}
					$total_full+=$other2;
						/*
						if(is_array($install) && count($install)>0){
							$k=0;$c=0;$other2=0;
							foreach($install as $ins){$k+=2;$c++;
							if($fStudent['stype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
						   elseif($fStudent['stype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from otherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
					 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt)
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
							
						}?>	<td> 123 <?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php }	
						}
					*/
				// 	$total_full+=$other2;
						//echo $i."-".$t.$other1."<br/>";
					
					$install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and class='".$fStudent['class']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
									
					$discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and class='".$fStudent['class']."' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
					
					$install2=$db->getRow("select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					$discount2= $db->getVal("SELECT COALESCE(sum(discount),0) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id in(select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."')   and session='".$_SESSION["admin"]["session"]."' ");
										
					//echo $discount;
					
					//print_r($install);
							$dues=0;
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'"); 
                                								
								
								if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									   
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
						$backduescolumn[0]+=$dues;	
					?><td>  <?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; //echo 111; ?></td>

					<?php 
				// 	$install=$db->getRows("select * from hostel_otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
                    
					$other2_hostel=0; $b = 0;
                    $install=$db->getRows("select * from hostel_otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                    foreach($install as $ins){ $b++;
                        $over_hostel = "";
                            $exists = $db->getRow("select * from hostel_otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' ");
						    if($exists > 1){
    						    $fee = $exists['fee'];
    						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");

    						    $discount= $db->getVal("SELECT sum(discount) from hostelotherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' "); 

    						    if($fStudent['htype']=="old" && $exists['otype']=="new"){
								    $over_hostel="";
    							}
    						   elseif($fStudent['htype']=="new" && $exists['otype']=="old"){
    								$over_hostel="";
    							}
    							 elseif($fStudent['htype']==""){
    								$over_hostel="";
    							}
    							else {
    							    $over_hostel = $exists['fee'] - $discount - $paid;
        							$other2_hostel+=$over_hostel;
    							}

						    }
						    else {
						        $over_hostel = "";
						    }

						?>
						<td> <?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
						<?php
						$hostelothercolumn[$b]+=$over_hostel;
					}
					$total_full+=$other2_hostel;
                    
                    ?>

                    <?php
                    
/*
						if(is_array($install) && count($install)>0){
							$k=0;$b=0;$other2_hostel=0;
							foreach($install as $ins){$k+=2;$b++;
							if($fStudent['htype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
						   elseif($fStudent['htype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							 elseif($fStudent['htype']==""){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther_hostel=$t - $other1;
						    $over_hostel=$overAllOther_hostel;
							$other2_hostel+=$over_hostel;
							
						}?>	<td><?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
				<?php }	
						}
						$total_full+=$other2_hostel; */
						
						
						$install=$db->getRows("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else 		
									//$dues=$ins['fee']-$discount;
										$dues=$ins['fee'];
								}
										if($fine_t==$total_dues)
												$dues=0;
						//else $dues=$fine_t-$total_dues-$discount;	
								else $dues=$fine_t-$total_dues;	
										
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues-$discount2;
						
					 $install2=$db->getRow("SELECT otype,GROUP_CONCAT(id) as id FROM `otherfee_structure` where otype='".$fStudent['idno']."'  and class='".$fStudent['class']."' and name like 'Latefine%'");
							//echo $install2[id];
							
							$dis3= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and class='".$fStudent['class']."' and other_id in($install2[id])   and session='".$_SESSION["admin"]["session"]."' ");
							
							
					?>
					<td>
					<?php  
					
							
					$to=$db->getVal("select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf) and session='".$_SESSION["admin"]["session"]."'");
				
			//echo	$ss="select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf) and session='".$_SESSION["admin"]["session"]."'";
				$to1=$db->getVal("SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");
				
				//echo $ss="SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))";
					
				$dis1=$db->getVal("SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and class='".$fStudent['class']."' and session='".$_SESSION["admin"]["session"]."' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");
		//	echo	$ss="SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))";
										
					 echo $t2=$to-$to1-$dis1;
                    $totalothercolumn[0]+=$t2;
					?>
					
					
					</td>
					<?php 
						if($dues=="0")
					{
					 $finetotal=$dues;   
					}
					else
					{
					$finetotal=$dues-$dis3;    
					}
					$finecolumn[0]+=$finetotal;
					?>
		<td> <?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues-$dis3; ?></td>

			 <input type="hidden" name="amount" id="total_amt<?php echo $fStudent['idno'] ?>" value="<?php echo $total_full+$t2; ?>" />
    		 <input type="hidden" name="amount" id="mobile<?php echo $fStudent['idno'] ?>" value="<?php echo $fStudent['mobile'] ?>" />
      <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $total_full+$t2; ?></td>		
				<?php $total_comp+=$total_full+$t2; }

				?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo 8;?>">Gross Total</td>
					<?php for($s = 1; $s<=$m; $s++){
					    echo "<td>$monthlycolumn[$s]</td>";
					} 
					for($s = 1; $s<=$c; $s++){
					    echo "<td>$otherfeecolumn[$s]</td>";
					}
					
					echo "<td>$backduescolumn[0]</td>";
					for($s = 1; $s<=$b; $s++){
					    echo "<td>$hostelothercolumn[$s]</td>";
					}
					echo "<td>$totalothercolumn[0]</td>";
					echo "<td>$finecolumn[0]</td>";
					?>
				   <td id="MyTotalLeft"><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
}

	elseif(isset($_GET['without_hostel_dues']))
	{
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					
			$overAllNewextra=0;

        $whereclass = "";
        $whereclass1 = "";
        if($_GET['class']!=""){
            $whereclass .= " class='".$_GET["class"]."' and ";
            $whereclass1 .= " s.class='".$_GET["class"]."' and ";
        }

        $wheresection = "";
        if($_GET['section']!=""){
            $wheresection .= " s.section='".$_GET["section"]."' and ";
        }
// 		$aryStudentList=$db->getRows("select * from student where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");

// 		$aryStudentList=$db->getRows("select * from student where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");

//         $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";
// 		$aryStudentList=$db->getRows("SELECT s.* FROM ".$table." where $whereclass s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".$where." order by s.name");

		$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";
		$aryStudentList=$db->getRows("SELECT    s.* FROM ".$table." where $whereclass1 $wheresection 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 "SELECT    s.* FROM ".$table." where $whereclass1 $wheresection s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".implode(" AND ",$where)."  group by s.idno order by s.name";

		$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");
		
		$m=0;
		if(isset($_GET['fmonth']) && $_GET['fmonth']!=0){
			$month=$_GET["fmonth"];
			  if($month<4){
				$m=($month+9);
			  }
			  else{
				$m=$month-3;
			  }

		}
		else{
			$m=12;
			
		}
		  //echo $m;
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
			
<style type="text/css">
@media print {
    #btnduesend {
        display :  none;
    }
}

@media print {
    #btnduesend1 {
        display :  none;
    }
}

@media print {
    #searchfoertotal {
        display :  none;
    }
}
</style>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            
            <input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
			<input type="button" class="btn btn-danger hidet" onclick="getStudentfinePopup()" value="Add Fine" style="float:left;" />
			<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" style="float:left;">Sms Preview</a>


            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>

			<a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=DueSheet&fmonth=$_GET[fmonth]&class=$_GET[class]&month_report_without_hostel=&section=$_GET[section]&bus=$_GET[bus]&location=$_GET[location]&head_name=$_GET[head_name]"; ?>" target="_blank" >Full Screen</a>
            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>


			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Complete Outstanding">
				<thead>
				<tr>
                	<th class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></th>
                	<th>S.No</th>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<th>Class</th>
                    <th>Roll No</th>
					<th>Contact No</th>
                     <?php
			   if(is_array($monthsList1) && count($monthsList1)>0){
				/*foreach($monthsList1 as $ftype){
					?><th width="0.5%"><?php echo $ftype ?></th><?php
				}*/
					for($i=1;$i<=$m;$i++){?>
						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
					}
			   }
// echo "select * from otherfee_structure where   school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' )  and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'";
			   $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
				// 	echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
                    <th>Back Dues</th>
              
					<th>Total_other</th>
                    <th>Fine</th>
               <th>Total</th>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;
			for($j=1; $j<=$m; $j++){
						$md[]=$j;
					}					
					//print_r($md);
					 $mdf= implode(',',$md);

                    $monthlycolumn = [];
                    $otherfeecolumn = [];
					$backduescolumn = [];
					$hostelothercolumn = [];
					$totalothercolumn = [];
					$finecolumn = [];
					
					 
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                    		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>
                        	<td id="newid<?php echo $i ?>"><?php echo $i ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?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 $fStudent["fincome"];?></td>
							<td><?php echo $fStudent["mobile"]; ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							$m1=$m+1;			
							foreach($monthsList1 as $key=>$val){$count++;

							if($mn===0){
							
							}
							else{ $mn--;
						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");

						//$db->getLastQuery();
						if(is_array($installTution) && count($installTution)>0){	
						  //  echo "ip$key";
						  //  echo $installTution[0];
						  //print_r($installTution['ip1']);
							if($installTution["ip$key"]=="" || $installTution["ip$key"]=="0")
							{
							 //   echo "not paid";
								$tution=$installTution["i$key"];
							}
							else
							{
							 //   echo "<b>paid</b>";
				// 		echo gettype($key);
				// echo $key;
				if($m==$key)
				{
				$tution=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from installment where  idno='".$fStudent["idno"]."' ");
				}
                else
                   {
	             $tution=0;	
                     }

							}
							
						}else{
							$tution="";
						}

						$overAlltution=$tution;
				// 		$monthlycolumn[$key] +=$tution; 
												// echo $overAlltution;
												
						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");
				// 		echo "select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'";
						if(is_array($installTution) && count($installTution)>0){
							if($installTution["bp$key"]=="" || $installTution["bp$key"]==0)
							{
								$trasnport=$installTution["b$key"];
							}
							else
							{
								
					 $tut_last_val=$db->getVal("select bp".$key1." from installment where  idno='".$fStudent["idno"]."'");

				if($m==$key)
				{
				$trasnport=$db->getVal("select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' ");
				
				//echo $ss="select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)";
	
				}
                else
                   {
	             $trasnport=0;	
                     }				
								
								
							}
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;



						$extrasum=array();
						$extrafeesingle = 0;
						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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								///echo $db->getErMsg().$db->getLastQuery();
								//echo $Ftypeid."-";print_r($installTution);
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									
									if($installTution["pay"]=="" || $installTution["pay"]==0)
									{
										$sums=$installTution["fee"];
									}
									else
									{
										if($m==$key)
				{
					
									$ext_last=$db->getVal("select sum(pay) from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$key1."' ");
	
	if($ext_last==0)
									{	
									$sums=$db->getVal("select sum(fee-pay)  from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$key."'  ");
									
									//echo $ss="select sum(fee-pay)  from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$key."'  ";
									
									}
	
				}
                else
                   {
	             $sums=0;	
                     }	
										
									}
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
								$extrafeesingle+=$sums;
								// $monthlycolumn[$key] +=$sums;
							}
						}
$monthlycolumn[$key] +=$tution+$trasnport+$extrafeesingle; 
						
						 $overAllNewextra=0;//print_r($extrasum);
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						//echo $ij.$overAllNewextra."-";
						}//$j++;
						/*$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								//echo $db->getErMsg().$db->getLastQuery();
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution[1]=="" || $installTution[1]=="0")
										$sums=$installTution[0];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total+=$sums;$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}*/
						  //if($i==23){echo $overAlltution."--".$overAllTransport."--".$overAllhotel."--".$overAllNewextra."!!!!";}
						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhotel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhotel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhotel+$overAllNewextra;}
						//if($i==23)echo "(".$total.")";
						//$total_full=$total_full+$total;
			if($key=="12"){			
		$total23=$db->getVal("select (COALESCE(i12,0)+COALESCE(b12,0)-COALESCE(ip12,0)-COALESCE(bp12,0)) from installment where idno='".$fStudent["idno"]."'");
		
		$total24=$db->getVal("select (COALESCE(i12,0)-COALESCE(ip12,0)) from hostelinstallment where idno='".$fStudent["idno"]."'");
		
		$te=$db->getVal("SELECT sum(fee-pay) FROM `extrafee` WHERE idno='".$fStudent["idno"]."' and pid='p12' and session='".$_SESSION["admin"]["session"]."'  ");
		
		$total22=$total23+$total24+$te;
		$total_full+=$total22;
			?>
			<td><?php if( $total22=="0" )echo "<lable style='color:red'>paid</label>";elseif($total=="" && $total22=="") echo "<lable style='color:red'>X</label>";  else echo $total22; ?></td>
		<?php	}
			else{ 
			$total_full=$total_full+$total;
			?><td><?php 
			
			
			if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td> <?php }
					?>
					<?php }}
										
				// 	$install=$db->getRows("select * from otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						//echo  $db->getLastQuery();
						$other2=0; $c = 0;
                    // $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='1' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '1' and session='2021-2022' GROUP BY name");						
                    $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                    foreach($install as $ins){ $c++;
                        $over = "";
                            $exists = $db->getRow("select * from otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' ");
						    if($exists > 1){
    						    $fee = $exists['fee'];
    						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");

    						    $discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' "); 

    						    if($fStudent['stype']=="old" && $exists['otype']=="new"){
								    $over="";
    							}
    						   elseif($fStudent['stype']=="new" && $exists['otype']=="old"){
    								$over="";
    							}
    							else {
    							    $over = $exists['fee'] - $discount - $paid;
        							$other2+=$over;
    							}

						    }
						    else {
						        $over = "";
						    }
                        $otherfeecolumn[$c]+= $over;
						?>
						<td> <?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
						<?php
					}
					$total_full+=$other2;
						/*
						if(is_array($install) && count($install)>0){
							$k=0;$c=0;$other2=0;
							foreach($install as $ins){$k+=2;$c++;
							if($fStudent['stype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
						   elseif($fStudent['stype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from otherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
					 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt)
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
							
						}?>	<td> 123 <?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php }	
						}
					*/
				// 	$total_full+=$other2;
						//echo $i."-".$t.$other1."<br/>";
					
					$install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and class='".$fStudent['class']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
									
					$discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and class='".$fStudent['class']."' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
					
					$install2=$db->getRow("select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					$discount2= $db->getVal("SELECT COALESCE(sum(discount),0) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id in(select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."')   and session='".$_SESSION["admin"]["session"]."' ");
										
					//echo $discount;
					
					//print_r($install);
							$dues=0;
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'"); 
                                								
								
								if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									   
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
						$backduescolumn[0]+=$dues;	
					?><td>  <?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; //echo 111; ?></td>



                    <?php
                    
/*
						if(is_array($install) && count($install)>0){
							$k=0;$b=0;$other2_hostel=0;
							foreach($install as $ins){$k+=2;$b++;
							if($fStudent['htype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
						   elseif($fStudent['htype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							 elseif($fStudent['htype']==""){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther_hostel=$t - $other1;
						    $over_hostel=$overAllOther_hostel;
							$other2_hostel+=$over_hostel;
							
						}?>	<td><?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
				<?php }	
						}
						$total_full+=$other2_hostel; */
						
						
						$install=$db->getRows("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else 		
									//$dues=$ins['fee']-$discount;
										$dues=$ins['fee'];
								}
										if($fine_t==$total_dues)
												$dues=0;
						//else $dues=$fine_t-$total_dues-$discount;	
								else $dues=$fine_t-$total_dues;	
										
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues-$discount2;
						
					 $install2=$db->getRow("SELECT otype,GROUP_CONCAT(id) as id FROM `otherfee_structure` where otype='".$fStudent['idno']."'  and class='".$fStudent['class']."' and name like 'Latefine%'");
							//echo $install2[id];
							
							$dis3= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and class='".$fStudent['class']."' and other_id in($install2[id])   and session='".$_SESSION["admin"]["session"]."' ");
							
							
					?>
					<td>
					<?php  
					
							
					$to=$db->getVal("select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf) and session='".$_SESSION["admin"]["session"]."'");
				
			//echo	$ss="select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf) and session='".$_SESSION["admin"]["session"]."'";
				$to1=$db->getVal("SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");
				
				//echo $ss="SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))";
					
				$dis1=$db->getVal("SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and class='".$fStudent['class']."' and session='".$_SESSION["admin"]["session"]."' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");
		//	echo	$ss="SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))";
										
					 echo $t2=$to-$to1-$dis1;
                    $totalothercolumn[0]+=$t2;
					?>
					
					
					</td>
					<?php 
						if($dues=="0")
					{
					 $finetotal=$dues;   
					}
					else
					{
					$finetotal=$dues-$dis3;    
					}
					$finecolumn[0]+=$finetotal;
					?>
		<td> <?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues-$dis3; ?></td>
			 <input type="hidden" name="amount" id="total_amt<?php echo $fStudent['idno'] ?>" value="<?php echo $total_full+$t2; ?>" />
			  <input type="hidden" name="amount" id="mobile<?php echo $fStudent['idno'] ?>" value="<?php   echo $fStudent['mobile'] ?>" />
      <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $total_full+$t2; ?></td>		
				<?php $total_comp+=$total_full+$t2; }
				echo $b;
				?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo 8;?>">Gross Total</td>
					<?php for($s = 1; $s<=$m; $s++){
					    echo "<td>$monthlycolumn[$s]</td>";
					} 
					for($s = 1; $s<=$c; $s++){
					    echo "<td>$otherfeecolumn[$s]</td>";
					}
					
					echo "<td>$backduescolumn[0]</td>";

					echo "<td>$totalothercolumn[0]</td>";
					echo "<td>$finecolumn[0]</td>";
					?>
				   <td id="MyTotalLeft"><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
}

	elseif(isset($_GET['month_report'])){

		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					
		$overAllNewextra=0;
			
        $whereclass = "";			
        if($_GET['class']!=""){
            $whereclass .= " class='".$_GET["class"]."' and ";
        }
        
        $wheresection = "";
        if($_GET['section']!=""){
            $wheresection .= " section='".$_GET["section"]."' and ";
        }

		$aryStudentList=$db->getRows("select * from student where $whereclass $wheresection school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");
		
		$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");
		
		$m=0;
		if(isset($_GET['fmonth']) && $_GET['fmonth']!=0){
			$month=$_GET["fmonth"];
			 // if($month<4){
				// $m=($month+9);
			 // }
			 // else{
				// $m=$month-3;
			 // }
            $m = $_GET['fmonth'];
		}
		else{
			$m=12;
			
		}
		  //echo $m;
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
			
<style type="text/css">
@media print {
    #btnduesend {
        display :  none;
    }
}

@media print {
    #btnduesend1 {
        display :  none;
    }
}

@media print {
    #searchfoertotal {
        display :  none;
    }
}
</style>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            
            <input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
			<input type="button" class="btn btn-danger hidet" onclick="getStudentfinePopup()" value="Add Fine" style="float:left;" />
			<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" style="float:left;">Sms Preview</a>


            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>

			<a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=DueSheet&fmonth=$_GET[fmonth]&class=$_GET[class]&month_report=&section=$_GET[section]&bus=$_GET[bus]&location=$_GET[location]&head_name=$_GET[head_name]"; ?>" target="_blank" >Full Screen</a>
            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>

			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Complete Outstanding">
				<thead>
				<tr>
                	<th class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></th>
                	<th>S.No</th>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<th>Class</th>
                    <th>Roll No.</th>
					<th>Contact No</th>
                     <?php
        			   if(is_array($monthsList1) && count($monthsList1)>0){
        					for($i=1;$i<=$m;$i++){?>
        						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
        					}
        			   }

                    $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
					foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
                    <th>Back Dues</th>
                  <?php
    			  $install=$db->getRows("select * from hostel_otherfee_structure where $whereclass  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'  GROUP BY name");
					foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
					<th>Total_other</th>
                    <th>Fine</th>
               <th>Total</th>
			</tr>
			</thead>
			<tbody>
	    	<?php	$i=0;$total_comp=0;
    	    		for($j=1; $j<=$m; $j++){
						$md[]=$j;
					}

                    $mdf= implode(',',$md);

                    $monthlycolumn = [];
                    $otherfeecolumn = [];
					$backduescolumn = [];
					$hostelothercolumn = [];
					$totalothercolumn = [];
					$finecolumn = [];
					
					 
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                    		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>
                        	<td id="newid<?php echo $i ?>"><?php echo $i ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]." - ".$fStudent["section"]  ?></td>
                            <td><?php echo $fStudent["fincome"];?></td>
							<td><?php echo $fStudent["mobile"]; ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							$m1=$m+1;			
							foreach($monthsList1 as $key=>$val){$count++;

							if($mn===0){
							
							}
							else{ $mn--; 
						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $tution = $installTution["i$key"]-$installTution["ip$key"];
						}else{
							$tution="";
						}
						$overAlltution=$tution;

						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $trasnport=$installTution["b$key"]-$installTution["bp$key"];
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;

						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $hostel = $installTution["i$key"] - $installTution["ip$key"];
						}else{
							$hostel="";
						}
						$overAllhotel=$hostel;

						$extrasum=array();
						$extrafeesingle = 0;
						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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");

								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									$sums = $installTution["fee"]-$installTution["pay"];
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
								$extrafeesingle+=$sums;
							}
						}
                        $monthlycolumn[$key] +=$tution+$trasnport+$hostel+$extrafeesingle; 

                        $overAllNewextra=0;
						for($ij=0; $ij<count($aryFeeType); $ij++){
						    $overAllNewextra+=$extrasum[$ij];
						}

                        $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhotel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhotel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhotel+$overAllNewextra;}

        			$total_full=$total_full+$total;
        			?><td> <?php
        			if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td>
        			<?php }}

					$other2=0; $c = 0;
                    $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                    foreach($install as $ins){ $c++;
                        $over = "";
                            $exists = $db->getRow("select * from otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' ");
						    if($exists > 1){
    						    $fee = $exists['fee'];
    						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");

    						    $discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' "); 

    						    if($fStudent['stype']=="old" && $exists['otype']=="new"){
								    $over="";
    							}
    						   elseif($fStudent['stype']=="new" && $exists['otype']=="old"){
    								$over="";
    							}
    							else {
    							    $over = $exists['fee'] - $discount - $paid;
        							$other2+=$over;
    							}

						    }
						    else {
						        $over = "";
						    }
                        $otherfeecolumn[$c]+= $over;
						?>
						<td> <?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
						<?php
					}
					$total_full+=$other2;

					$install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and class='".$fStudent['class']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
									
					$discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and class='".$fStudent['class']."' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
					
					$install2=$db->getRow("select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					$discount2= $db->getVal("SELECT COALESCE(sum(discount),0) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id in(select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."')   and session='".$_SESSION["admin"]["session"]."' ");

							$dues=0;
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'"); 

								if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									   
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
									$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
						$backduescolumn[0]+=$dues;
					?>
					<td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; ?></td>
					<?php
					$other2_hostel=0; $b = 0;
                    $install=$db->getRows("select * from hostel_otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                    foreach($install as $ins){ $b++;
                        $over_hostel = "";
                            $exists = $db->getRow("select * from hostel_otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' ");
						    if($exists > 1){
    						    $fee = $exists['fee'];
    						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");

    						    $discount= $db->getVal("SELECT sum(discount) from hostelotherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' "); 

    						    if($fStudent['htype']=="old" && $exists['otype']=="new"){
								    $over_hostel="";
    							}
    						   elseif($fStudent['htype']=="new" && $exists['otype']=="old"){
    								$over_hostel="";
    							}
    							 elseif($fStudent['htype']==""){
    								$over_hostel="";
    							}
    							else {
    							    $over_hostel = $exists['fee'] - $discount - $paid;
        							$other2_hostel+=$over_hostel;
    							}

						    }
						    else {
						        $over_hostel = "";
						    }
						?>
						<td> <?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
						<?php
						$hostelothercolumn[$b]+=$over_hostel;
					}
					$total_full+=$other2_hostel;
                    
						$install=$db->getRows("select * from otherfee_structure where class='".$fStudent['class']."' and  otype ='".$fStudent['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else
										$dues=$ins['fee'];
								}
										if($fine_t==$total_dues)
												$dues=0;

								else $dues=$fine_t-$total_dues;
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues-$discount2;
						
                            $install2=$db->getRow("SELECT otype,GROUP_CONCAT(id) as id FROM `otherfee_structure` where otype='".$fStudent['idno']."'  and class='".$fStudent['class']."' and name like 'Latefine%'");

							$dis3= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and class='".$fStudent['class']."' and other_id in($install2[id])   and session='".$_SESSION["admin"]["session"]."' ");
					?>
					<td>
					<?php	$to=$db->getVal("select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf) and session='".$_SESSION["admin"]["session"]."'");
            				$to1=$db->getVal("SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");
            				$dis1=$db->getVal("SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and class='".$fStudent['class']."' and session='".$_SESSION["admin"]["session"]."' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");
        					echo $t2=$to-$to1-$dis1;
                            $totalothercolumn[0]+=$t2;
					?>
					</td>
					<?php 
						if($dues=="0")
					{
					 $finetotal=$dues;   
					}
					else
					{
					$finetotal=$dues-$dis3;    
					}
					$finecolumn[0]+=$finetotal;
					?>
            		<td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues-$dis3; ?></td>

			    <input type="hidden" name="amount" id="total_amt<?php echo $fStudent['idno'] ?>" value="<?php echo $total_full+$t2; ?>" />
    		    <input type="hidden" name="amount" id="mobile<?php echo $fStudent['idno'] ?>" value="<?php echo $fStudent['mobile'] ?>" />
                <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $total_full+$t2; ?></td>		
				<?php $total_comp+=$total_full+$t2; } ?> 
			</tbody>
				<tfoot>
					<td colspan="<?php echo 8;?>">Gross Total</td>
					<?php for($s = 1; $s<=$m; $s++){
					    echo "<td>$monthlycolumn[$s]</td>";
					} 
					for($s = 1; $s<=$c; $s++){
					    echo "<td>$otherfeecolumn[$s]</td>";
					}
					
					echo "<td>$backduescolumn[0]</td>";
					for($s = 1; $s<=$b; $s++){
					    echo "<td>$hostelothercolumn[$s]</td>";
					}
					echo "<td>$totalothercolumn[0]</td>";
					echo "<td>$finecolumn[0]</td>";
					?>
				   <td id="MyTotalLeft"><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>
<?php }
}

	elseif(isset($_GET['month_report_without_hostel']))
	{
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					
			$overAllNewextra=0;
			
        $whereclass = "";			
        if($_GET['class']!=""){
            $whereclass .= " class='".$_GET["class"]."' and ";
        }
        
        $wheresection = "";
        if($_GET['section']!=""){
            $wheresection .= " section='".$_GET["section"]."' and ";
        }

		$aryStudentList=$db->getRows("select * from student where $whereclass $wheresection school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");
		
		$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");
		
		$m=0;
		if(isset($_GET['fmonth']) && $_GET['fmonth']!=0){
			$month=$_GET["fmonth"];
			 // if($month<4){
				// $m=($month+9);
			 // }
			 // else{
				// $m=$month-3;
			 // }
            $m = $_GET['fmonth'];
		}
		else{
			$m=12;
		}
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
			
<style type="text/css">
@media print {
    #btnduesend {
        display :  none;
    }

    #btnduesend1 {
        display :  none;
    }

    #searchfoertotal {
        display :  none;
    }
}
</style>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            
            <input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
			<input type="button" class="btn btn-danger hidet" onclick="getStudentfinePopup()" value="Add Fine" style="float:left;" />
			<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" style="float:left;">Sms Preview</a>


            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>

			<a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=DueSheet&fmonth=$_GET[fmonth]&class=$_GET[class]&month_report_without_hostel=&section=$_GET[section]&bus=$_GET[bus]&location=$_GET[location]&head_name=$_GET[head_name]"; ?>" target="_blank" >Full Screen</a>
            <style>
                @media print {
                    #myPrntbtn {
                        display :  none;
                    }
                }
            </style>

			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Complete Outstanding">
				<thead>
				<tr>
                	<th class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></th>
                	<th>S.No</th>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<th>Class</th>
                    <th>Roll No.</th>
					<th>Contact No</th>
                     <?php
			   if(is_array($monthsList1) && count($monthsList1)>0){
					for($i=1;$i<=$m;$i++){?>
						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
					}
			   }

			   $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
					foreach($install as $ins){ ?>
    					<th><?php echo $ins['name'] ?></th>
					<?php } ?>
                    <th>Back Dues</th>
              
					<th>Total_other</th>
                    <th>Fine</th>
               <th>Total</th>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;
			for($j=1; $j<=$m; $j++){
						$md[]=$j;
					}					
					//print_r($md);
					 $mdf= implode(',',$md);

                    $monthlycolumn = [];
                    $otherfeecolumn = [];
					$backduescolumn = [];
					$hostelothercolumn = [];
					$totalothercolumn = [];
					$finecolumn = [];
					
					 
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                    		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>
                        	<td id="newid<?php echo $i ?>"><?php echo $i ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]." - ".$fStudent["section"]  ?></td>
                            <td><?php echo $fStudent["fincome"];?></td>
							<td><?php echo $fStudent["mobile"]; ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							$m1=$m+1;			
							foreach($monthsList1 as $key=>$val){$count++;

							if($mn===0){
							
							}
							else{ $mn--;
						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $tution = $installTution["i$key"]-$installTution["ip$key"];
						}else{
							$tution="";
						}

						$overAlltution=$tution;

						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $trasnport=$installTution["b$key"]-$installTution["bp$key"];
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;

						$extrasum=array();
						$extrafeesingle = 0;
						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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									$sums = $installTution["fee"]-$installTution["pay"];
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
								$extrafeesingle+=$sums;
							}
						}
                        $monthlycolumn[$key] +=$tution+$trasnport+$extrafeesingle; 
						
						 $overAllNewextra=0;
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						}

						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhotel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhotel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhotel+$overAllNewextra;}

			$total_full=$total_full+$total;
			?><td><?php if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td> 

					<?php }}
										
				// 	$install=$db->getRows("select * from otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						//echo  $db->getLastQuery();
						$other2=0; $c = 0;
                    // $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='1' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '1' and session='2021-2022' GROUP BY name");						
                    $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                    foreach($install as $ins){ $c++;
                        $over = "";
                            $exists = $db->getRow("select * from otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' ");
						    if($exists > 1){
    						    $fee = $exists['fee'];
    						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");

    						    $discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' "); 

    						    if($fStudent['stype']=="old" && $exists['otype']=="new"){
								    $over="";
    							}
    						   elseif($fStudent['stype']=="new" && $exists['otype']=="old"){
    								$over="";
    							}
    							else {
    							    $over = $exists['fee'] - $discount - $paid;
        							$other2+=$over;
    							}

						    }
						    else {
						        $over = "";
						    }
                        $otherfeecolumn[$c]+= $over;
						?>
						<td> <?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
						<?php
					}
					$total_full+=$other2;
						/*
						if(is_array($install) && count($install)>0){
							$k=0;$c=0;$other2=0;
							foreach($install as $ins){$k+=2;$c++;
							if($fStudent['stype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
						   elseif($fStudent['stype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from otherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
					 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt)
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
							
						}?>	<td> 123 <?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php }	
						}
					*/
				// 	$total_full+=$other2;
						//echo $i."-".$t.$other1."<br/>";
					
					$install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and class='".$fStudent['class']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
									
					$discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and class='".$fStudent['class']."' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
					
					$install2=$db->getRow("select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					$discount2= $db->getVal("SELECT COALESCE(sum(discount),0) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id in(select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."')   and session='".$_SESSION["admin"]["session"]."' ");
										
					//echo $discount;
					
					//print_r($install);
							$dues=0;
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'"); 
                                								
								
								if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									   
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
						$backduescolumn[0]+=$dues;	
					?><td>  <?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; //echo 111; ?></td>



                    <?php
                    
/*
						if(is_array($install) && count($install)>0){
							$k=0;$b=0;$other2_hostel=0;
							foreach($install as $ins){$k+=2;$b++;
							if($fStudent['htype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
						   elseif($fStudent['htype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							 elseif($fStudent['htype']==""){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther_hostel=$t - $other1;
						    $over_hostel=$overAllOther_hostel;
							$other2_hostel+=$over_hostel;
							
						}?>	<td><?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
				<?php }	
						}
						$total_full+=$other2_hostel; */
						
						
						$install=$db->getRows("select * from otherfee_structure where class='".$fStudent['class']."' and  otype ='".$fStudent['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else 		
									//$dues=$ins['fee']-$discount;
										$dues=$ins['fee'];
								}
										if($fine_t==$total_dues)
												$dues=0;
						//else $dues=$fine_t-$total_dues-$discount;	
								else $dues=$fine_t-$total_dues;	
										
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues-$discount2;
						
					 $install2=$db->getRow("SELECT otype,GROUP_CONCAT(id) as id FROM `otherfee_structure` where otype='".$fStudent['idno']."'  and class='".$fStudent['class']."' and name like 'Latefine%'");
							//echo $install2[id];
							
							$dis3= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and class='".$fStudent['class']."' and other_id in($install2[id])   and session='".$_SESSION["admin"]["session"]."' ");
							
							
					?>
					<td>
					<?php  
					
							
					$to=$db->getVal("select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf) and session='".$_SESSION["admin"]["session"]."'");
				
			//echo	$ss="select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf) and session='".$_SESSION["admin"]["session"]."'";
				$to1=$db->getVal("SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");
				
				//echo $ss="SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))";
					
				$dis1=$db->getVal("SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and class='".$fStudent['class']."' and session='".$_SESSION["admin"]["session"]."' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");
		//	echo	$ss="SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))";
										
					 echo $t2=$to-$to1-$dis1;
                    $totalothercolumn[0]+=$t2;
					?>
					
					
					</td>
					<?php 
						if($dues=="0")
					{
					 $finetotal=$dues;   
					}
					else
					{
					$finetotal=$dues-$dis3;    
					}
					$finecolumn[0]+=$finetotal;
					?>
		<td> <?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues-$dis3; ?></td>
			 <input type="hidden" name="amount" id="total_amt<?php echo $fStudent['idno'] ?>" value="<?php echo $total_full+$t2; ?>" />
			  <input type="hidden" name="amount" id="mobile<?php echo $fStudent['idno'] ?>" value="<?php   echo $fStudent['mobile'] ?>" />
      <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $total_full+$t2; ?></td>		
				<?php $total_comp+=$total_full+$t2; }
				echo $b;
				?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo 8;?>">Gross Total</td>
					<?php for($s = 1; $s<=$m; $s++){
					    echo "<td>$monthlycolumn[$s]</td>";
					} 
					for($s = 1; $s<=$c; $s++){
					    echo "<td>$otherfeecolumn[$s]</td>"; 
					}
					
					echo "<td>$backduescolumn[0]</td>";

					echo "<td>$totalothercolumn[0]</td>";
					echo "<td>$finecolumn[0]</td>";
					?>
				   <td id="MyTotalLeft"><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
}

	elseif(isset($_GET['new_ledger'])){

		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhostel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					
		$overAllNewextra=0;

        $whereclass = "";			
        if($_GET['class']!=""){
            $whereclass .= " class='".$_GET["class"]."' and ";
        }
 
        $wheresection = "";
        if($_GET['section']!=""){
            $wheresection .= " section='".$_GET["section"]."' and ";
        }

		$aryStudentList=$db->getRows("select * from student where $whereclass $wheresection  session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");

		$aryFeeType=$db->getRows("select distinct(type) from extrafee_type where  session='".$_SESSION["admin"]["session"]."' and status=1 order by type");
     
		$m=0;
		if(isset($_GET['fmonth']) && $_GET['fmonth']!=0){
			$month=$_GET["fmonth"];
			 // if($month<4){
				// $m=($month+9);
			 // } 
			 // else{
				// $m=$month-3;
			 // }
			 $m = $_GET['fmonth'];
		}
		else{
			$m=12;
			
		}
		  //echo $m;
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>

        <style type="text/css">
            @media print {
                #btnduesend {
                    display :  none;
                }
                #searchfoertotal {
                    display :  none;
                }
                #btnduesend1 {
                    display :  none;
                }
            }
        </style>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            
            <input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
			<input type="button" class="btn btn-danger hidet" onclick="getStudentfinePopup()" value="Add Fine" style="float:left;" />
			<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" style="float:left;">Sms Preview</a>

            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>

			<a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=DueSheet&fmonth=$_GET[fmonth]&class=$_GET[class]&month_report_without_hostel=&section=$_GET[section]&bus=$_GET[bus]&location=$_GET[location]&head_name=$_GET[head_name]"; ?>" target="_blank" >Full Screen</a>
            <style>
                @media print {
                    #myPrntbtn {
                        display :  none;
                    }
                }
            </style>


		<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Complete Outstanding">
			<thead>
				<tr>
                	<th class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></th>
                	<th>S.No</th>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<th>Class</th>
                    <th>Roll No.</th>
					<th>Contact No</th>
                    <?php
        			   if(is_array($monthsList1) && count($monthsList1)>0){
        					for($i=1;$i<=$m;$i++){?>
        						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
        					}
        			   }
        			   $install=$db->getRows("select * from otherfee_structure where $whereclass (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
					?>
                    <th>Total Outstanding</th>
                    <th>Total Paid</th>
                    <th>Remaining</th>
			    </tr>
			</thead>
			<tbody>
    		<?php	$i=0;$total_comp=0;
	        		for($j=1; $j<=$m; $j++){
						$md[]=$j;
					}
					//print_r($md);
					 $mdf= implode(',',$md);

                    $monthlycolumn = [];
                    $otherfeecolumn = [];
					$backduescolumn = [];
					$hostelothercolumn = [];
					$totalothercolumn = [];
					$finecolumn = [];
					
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                    		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>
                        	<td id="newid<?php echo $i ?>"><?php echo $i ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]." - ".$fStudent["section"]  ?></td>
                            <td><?php echo $fStudent["fincome"];?></td>
							<td><?php echo $fStudent["mobile"]; ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
						$m1=$m+1;			
						$total_paid = 0;
						foreach($monthsList1 as $key=>$val){$count++;
						
						$feeheads = "";

							if($mn===0){
							
							}
							else{ $mn--;
							
							/* Tuition Fee Starts */

        						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");
        
        						if(is_array($installTution) && count($installTution)>0){
        							if($installTution["ip$key"]=="" || $installTution["ip$key"]=="0"){
        								$tution=$installTution["i$key"];
        							}   else    {
                        				if($m==$key){
                            				$tution=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from installment where  idno='".$fStudent["idno"]."' ");
                        				}   else {
                                            $tution=0;	
                                        }
        							}
        						} else {
        							$tution="";
        						}
        
        						$overAlltution=$tution;
        						
    						/* Tuition Fee Ends */

                            /* Transport Fee Starts */
        						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");
        						if(is_array($installTution) && count($installTution)>0){
        							if($installTution["bp$key"]=="" || $installTution["bp$key"]==0){
        								$trasnport=$installTution["b$key"];
        							} else {
                                        $tut_last_val=$db->getVal("select bp".$key1." from installment where  idno='".$fStudent["idno"]."'");
                        				if($m==$key){
                            				$trasnport=$db->getVal("select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' ");
                        				} else {
                                            $trasnport=0;	
                                        }
        							}
        						}else{
        							$trasnport="";
        						}
        						$overAllTransport=$trasnport;
        						
    						/* Transport Fee Ends */

                        /* Extra Fee Starts */

						$extrasum=array();
						$extrafeesingle = 0;
						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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									
									if($installTution["pay"]=="" || $installTution["pay"]==0){
										$sums=$installTution["fee"];
									} else {
										if($m==$key){
        									$ext_last=$db->getVal("select sum(pay) from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$key1."' ");
                                            if($ext_last==0){
        									    $sums=$db->getVal("select sum(fee-pay)  from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$key."'  ");
        									}
                        				} else {
                        	                $sums=0;	
                                        }
									}
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
								$extrafeesingle+=$sums;
							}
						}
                        
                        $monthlycolumn[$key] +=$tution+$trasnport+$extrafeesingle; 
						
						 $overAllNewextra=0;
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						}
						
					/* Extra Fee Ends */

                    /* Other Fee Start */
                        
    					$other2=0; $c = 0;
                        $install=$db->getRows("select * from otherfee_structure where class='".$fStudent["class"]."' and (otype = '' or otype = '$fStudent[idno]' or otype = '$fStudent[stype]' ) and month = '$key' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                        foreach($install as $ins){ $c++;
                            $over = "";
                                $exists = $db->getRow("select * from otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and (otype =  '' or otype = '$fStudent[idno]' or otype = '$fStudent[stype]') and month = '$key' and session='".$_SESSION["admin"]["session"]."' ");
    						    if(count($exists) > 1){
        						    $fee = $exists['fee'];
    
        						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");
    
        						    $discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' ");
                                    
                                    $monthlyfees+=$fee-$discount;
                                    
        							    $over = $exists['fee'] - $discount - $paid;
            							$other2+=$over;
            							
            							$feeheads.=" '$ins[name]', ";
    						    }
    					}
                    
                    /* Other Fee End */

					/* Hostel Fee Starts */

						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$fStudent["idno"]."'");

						if(is_array($installTution) && count($installTution)>0){
							if($installTution["ip$key"]=="" || $installTution["ip$key"]=="0"){
								$hostel=$installTution["i$key"];
							}   else    {
                				if($m==$key){
                    				$hostel=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from hostelinstallment where  idno='".$fStudent["idno"]."' ");
                				}   else {
                                    $hostel=0;	
                                }
							}
						} else {
							$hostel="";
						}

						$overAllhostel=$hostel;
						
					/* Hostel Fee Ends */

            
                    /* Hostelother fee starts */
                        if($fStudent['hostel']!=""){
        					$other2_hostel=0; $b = 0;
                            $install=$db->getRows("select * from hostel_otherfee_structure where class='".$fStudent["class"]."' and (otype = '' or otype = '$fStudent[idno]' or otype = '$fStudent[htype]' ) and month = '$key' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                            foreach($install as $ins){ $b++;
                                $over_hostel = "";
                                $exists = $db->getRow("select * from hostel_otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and (otype =  '' or otype = '$fStudent[idno]' or otype = '$fStudent[htype]' ) and month = '$key' and session='".$_SESSION["admin"]["session"]."' ");
    						    if(count($exists) > 1){
        						    $fee = $exists['fee'];
        						    
        						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");
    
        						    $discount= $db->getVal("SELECT sum(discount) from hostelotherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' "); 
    
                                    $monthlyfees+=$fee-$discount;
    
    							    $over_hostel = $exists['fee'] - $discount - $paid;
        							$other2_hostel+=$over_hostel;
        							
        							$feeheads.=" '$ins[name]', ";
    						    }
        					}
                        }
                    /* Hostelother fee ends */
            

						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhostel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhostel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhostel+$overAllNewextra+$other2+$other2_hostel;}

			if($key=="12"){
		$total23=$db->getVal("select (COALESCE(i12,0)+COALESCE(b12,0)-COALESCE(ip12,0)-COALESCE(bp12,0)) from installment where idno='".$fStudent["idno"]."'");
		
		$total24=$db->getVal("select (COALESCE(i12,0)-COALESCE(ip12,0)) from hostelinstallment where idno='".$fStudent["idno"]."'");
		
		$te=$db->getVal("SELECT sum(fee-pay) FROM `extrafee` WHERE idno='".$fStudent["idno"]."' and pid='p12' and session='".$_SESSION["admin"]["session"]."'  ");

		$total22=$total23+$total24+$te; 
		$total_full+=$total22;
			?>
			<td><?php if( $total22=="0" )echo "<lable style='color:red'>paid</label>";elseif($total=="" && $total22=="") echo "<lable style='color:red'>X</label>";  else echo $total22; ?></td>
		<?php	}
			else{
			$total_full=$total_full+$total;
			?>
			<td><?php
                $paidreceipt = $db->getRows("select * from receipt where idno='$fStudent[idno]' and Months like '%$key%' and session='".$_SESSION["admin"]["session"]."' ");

    			if($total=="0"){
    			    echo "<lable style='color:red'>paid</label>";

    			    foreach($paidreceipt as $pr){
    			        echo "<label style='display:inline-block;border-bottom:solid 1px;'>$pr[id]-->". date('d-m-Y', strtotime($pr['udate']))." -->$pr[amount]</label>";
    			        $total_paid+=$pr['amount'];
    			    }
    			    
    			}   elseif($total==""){ echo "<lable style='color:red'>X</label>"; } else { echo $total;
	    			    foreach($paidreceipt as $pr){
        			        echo "<label style='display:inline-block;border-bottom:solid 1px;'>$pr[id]-->". date('d-m-Y', strtotime($pr['udate']))." -->$pr[amount]</label>";
        			        $total_paid+=$pr['amount'];
        			    }
    			} ?></td>
    			<?php   }
					}   }

            ?>
		<!--<td> <?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues-$dis3; ?></td>-->
			 <input type="hidden" name="amount" id="total_amt<?php echo $fStudent['idno'] ?>" value="<?php echo $total_full+$t2; ?>" />
			  <input type="hidden" name="amount" id="mobile<?php echo $fStudent['idno'] ?>" value="<?php   echo $fStudent['mobile'] ?>" />
              <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $total_full+$t2+$total_paid; ?></td>
              
              <td><?php echo $total_paid; $completepaid+=$total_paid; ?></td>
              <td><?php echo ($total_full+$t2+$total_paid)-$total_paid; $completeremaining+=($total_full+$t2+$total_paid)-$total_paid; ?></td>
              
				<?php $total_comp+=$total_full+$t2+$total_paid; }
				echo $b;
				?> 
			</tbody>
				<tfoot>
					<td colspan="<?php echo 8;?>">Gross Total</td>
					<?php for($s = 1; $s<=$m; $s++){
					    echo "<td>$monthlycolumn[$s]</td>";
					} 
					
					?>
				   <td id="MyTotalLeft"><?php echo $total_comp; ?></td>
				   <td><?php echo $completepaid; ?></td>
				   <td><?php echo $completeremaining; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
}


	elseif(isset($_GET['total_amount']))
	{
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					
		$overAllNewextra=0; $totalstrength = 0; $totalamount = 0;

    	if($_GET['class']!=""){
    	    $classAry = $db->getRows("select class from class where class='$_GET[class]' ");
    	}   else {
    	    $classAry = $db->getRows("select class from class");
    	}

		$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");
		
		$m=0;
		if(isset($_GET['fmonth']) && $_GET['fmonth']!=0){
			$month=$_GET["fmonth"];
			 // if($month<4){
				// $m=($month+9);
			 // }
			 // else{
				// $m=$month-3;
			 // }
			 $m = $_GET['fmonth'];
		}
		else{
			$m=12;
		}

        ?>

        <div class="well no-padding divclass" >
            <div class="row-fluid mydiv">
                <table class='table' id="tblData" border="1" cellspacing="0">
    				<thead>
        				<tr>
                        	<!--<th class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></th>-->
                        	<th>S.No</th>
        					<th>Student Name</th>
                            <th>Father Name</th>
                            <th>Reg. no</th>
        					<th>Class</th>
                            <th>Roll No.</th>
        					<th>Contact No</th>
                       <th>Total</th>
        			</tr>
        			</thead>
        			<tbody>
        <?php foreach($classAry as $class){
                $secAry = array();
                $cls = $class['class'];

                $secstu = $db->getRows("select * from student where class='$cls' and session='".$_SESSION["admin"]["session"]."' and status='1' ");

                if(count($secstu) > 0 ){
                ?>
            
    	                <?php //$allstudents = $db->getRows("select * from student where class='$cls' and section='$sec' and session='".$_SESSION["admin"]["session"]."' and status=1 ");
        	                $aryStudentList=$db->getRows("select * from student where class='$cls' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 order by class,section");

                            $i=0;$total_comp=0;
                			for($j=1; $j<=$m; $j++){
            						$md[]=$j;
            					}
        
        					 $mdf= implode(',',$md);
        
                            $monthlycolumn = [];
                            $otherfeecolumn = [];
        					$backduescolumn = [];
        					$hostelothercolumn = [];
        					$totalothercolumn = [];
        					$finecolumn = [];

                        foreach($aryStudentList as $fStudent){
					$mn=$m;

						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							$m1=$m+1;			
							foreach($monthsList1 as $key=>$val){$count++;

							if($mn===0){
							
							}
							else{ $mn--;

						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $tution = $installTution["i$key"]-$installTution["ip$key"];
						}else{
							$tution="";
						}
						$overAlltution=$tution;

						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $trasnport = $installTution["b$key"]-$installTution["bp$key"];
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;

						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $hostel = $installTution["i$key"] - $installTution["ip$key"];
						} else{
							$hostel="";
						}
						$overAllhotel=$hostel;

						$extrasum=array();
						$extrafeesingle = 0;
						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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");

								$no=array();
								if(is_array($installTution) && count($installTution)>0){
								    $sums = $installTution["fee"]-$installTution["pay"];
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
								$extrafeesingle+=$sums;
							}
						}
                        $monthlycolumn[$key] +=$tution+$trasnport+$extrafeesingle; 
						
						 $overAllNewextra=0;
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						}

						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhotel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhotel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhotel+$overAllNewextra;}
			
			$total_full=$total_full+$total;
			 }}
						$other2=0; $c = 0;
                    $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                    foreach($install as $ins){ $c++;
                        $over = "";
                            $exists = $db->getRow("select * from otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' ");
						    if($exists > 1){
    						    $fee = $exists['fee'];
    						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");

    						    $discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' "); 

    						    if($fStudent['stype']=="old" && $exists['otype']=="new"){
								    $over="";
    							}
    						   elseif($fStudent['stype']=="new" && $exists['otype']=="old"){
    								$over="";
    							}
    							else {
    							    $over = $exists['fee'] - $discount - $paid;
        							$other2+=$over;
    							}

						    }
						    else {
						        $over = "";
						    }
                        $otherfeecolumn[$c]+= $over;
						?>
						<!--<td> <?php //if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>-->
						<?php
					}
					$total_full+=$other2;

					$install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and class='".$fStudent['class']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
									
					$discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and class='".$fStudent['class']."' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
					
					$install2=$db->getRow("select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					$discount2= $db->getVal("SELECT COALESCE(sum(discount),0) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id in(select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."')   and session='".$_SESSION["admin"]["session"]."' ");

							$dues=0;
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'"); 
                                								
								
								if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									   
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
						$backduescolumn[0]+=$dues;	

						$install=$db->getRows("select * from otherfee_structure where class='".$fStudent['class']."' and otype ='".$fStudent['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else
										$dues=$ins['fee'];
								}
										if($fine_t==$total_dues)
												$dues=0;
								else $dues=$fine_t-$total_dues;
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues-$discount2;
						
                        $install2=$db->getRow("SELECT otype,GROUP_CONCAT(id) as id FROM `otherfee_structure` where otype='".$fStudent['idno']."'  and class='".$fStudent['class']."' and name like 'Latefine%'");

						$dis3= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and class='".$fStudent['class']."' and other_id in($install2[id])   and session='".$_SESSION["admin"]["session"]."' ");

                        $to=$db->getVal("select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf) and session='".$_SESSION["admin"]["session"]."'");
                        $to1=$db->getVal("SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");
                        $dis1=$db->getVal("SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and class='".$fStudent['class']."' and session='".$_SESSION["admin"]["session"]."' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");

                        $t2=$to-$to1-$dis1;
                        $totalothercolumn[0]+=$t2;

    					if($dues=="0"){
                            $finetotal=$dues;
    					}
    					else
    					{
    					    $finetotal=$dues-$dis3;
    					}
    					$finecolumn[0]+=$finetotal;

    					$other2_hostel=0; $b = 0;
                        $install=$db->getRows("select * from hostel_otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                        foreach($install as $ins){ $b++;
                            $over_hostel = "";
                                $exists = $db->getRow("select * from hostel_otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' ");
    						    if($exists > 1){
        						    $fee = $exists['fee'];
        						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");
    
        						    $discount= $db->getVal("SELECT sum(discount) from hostelotherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' "); 
    
        						    if($fStudent['htype']=="old" && $exists['otype']=="new"){
    								    $over_hostel="";
        							}
        						   elseif($fStudent['htype']=="new" && $exists['otype']=="old"){
        								$over_hostel="";
        							}
        							 elseif($fStudent['htype']==""){
        								$over_hostel="";
        							}
        							else {
        							    $over_hostel = $exists['fee'] - $discount - $paid;
            							$other2_hostel+=$over_hostel;
        							}
    						    }
    						    else {
    						        $over_hostel = "";
    						    }
    					}
    					$total_full+=$other2_hostel;
					
					if($total_full+$t2 > 0){ $i++; $totalstrength++;
					?>
                    <tr>
                		<!--<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>-->
                    	<td id="newid<?php echo $i ?>"><?php echo $i ?></td>
						<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                        <td><?php echo $fStudent["fname"] ?></td>
                        <td><?php echo $fStudent["admissionno"] ?></td>
						<td><?php echo $fStudent["class"]." - ".$fStudent["section"]  ?></td>
                        <td><?php echo $fStudent["fincome"];?></td>
						<td><?php echo $fStudent["mobile"]; ?></td>
                    <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $total_full+$t2; $totalamount+=$total_full+$t2; ?></td>
            </tr>
			<?php } $total_comp+=$total_full+$t2; 
			} 
                    
                }
            
        } ?>
        			</tbody>
                </table>
            </div>
            <label style="float:left;">Total Students: <?php echo $totalstrength; ?></label>
            <label style="float:right;">Total Dues: <?php echo $totalamount; ?></label>
        </div>

        <?php
	}

	elseif(isset($_GET['class_outstanding']))
	{
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					
		$overAllNewextra=0; $totalstrength = 0; $totalamount = 0;

    	    $classAry = $db->getRows("select class from class");

		$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");
		
		$m=0;
		if(isset($_GET['fmonth']) && $_GET['fmonth']!=0){
			$month=$_GET["fmonth"];
			 // if($month<4){
				// $m=($month+9);
			 // }
			 // else{
				// $m=$month-3;
			 // }
			 $m = $_GET['fmonth'];
		}
		else{
			$m=12;
		}

        ?>

        <div class="well no-padding divclass" >
                <table class='table' id="tblData" border="1" cellspacing="0">
    				<thead>
        				<tr>
                        	<th>S.No</th>
        					<th>Class</th>
                            <th>Total Student</th>
                           <th>Total</th>
            			</tr>
        			</thead>
        			<tbody>
        <?php 
        $totalstrength = 0;
        foreach($classAry as $class){  $z++;
                $cls = $class['class'];
                

            $wheresection = '';        $sections = '';
                
                $secstu = $db->getRows("select * from student where class='$cls' and session='".$_SESSION["admin"]["session"]."' and status='1' ");
                ?>

    	                <?php //$allstudents = $db->getRows("select * from student where class='$cls' and section='$sec' and session='".$_SESSION["admin"]["session"]."' and status=1 ");
        	                $aryStudentList=$db->getRows("select idno, class, stype, htype from student where class='$cls' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 order by class,section");

                            $i=0;$total_comp=0;
                			for($j=1; $j<=$m; $j++){
            						$md[]=$j;
            					}
        
        					 $mdf= implode(',',$md);
        
                            $monthlycolumn = [];
                            $otherfeecolumn = [];
        					$backduescolumn = [];
        					$hostelothercolumn = [];
        					$totalothercolumn = [];
        					$finecolumn = [];

                        foreach($aryStudentList as $fStudent){
					$mn=$m;

						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							$m1=$m+1;			
							foreach($monthsList1 as $key=>$val){$count++;

							if($mn===0){
							
							}
							else{ $mn--;

						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $tution = $installTution["i$key"]-$installTution["ip$key"];
						}else{
							$tution="";
						}
						$overAlltution=$tution;

						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $trasnport = $installTution["b$key"]-$installTution["bp$key"];
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;

						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $hostel = $installTution["i$key"] - $installTution["ip$key"];
						} else{
							$hostel="";
						}
						$overAllhotel=$hostel;

						$extrasum=array();
						$extrafeesingle = 0;
						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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");

								$no=array();
								if(is_array($installTution) && count($installTution)>0){
								    $sums = $installTution["fee"]-$installTution["pay"];
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
								$extrafeesingle+=$sums;
							}
						}
                        $monthlycolumn[$key] +=$tution+$trasnport+$extrafeesingle; 
						
						 $overAllNewextra=0;
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						}

						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhotel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhotel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhotel+$overAllNewextra;}
			
			$total_full=$total_full+$total;
			 }}
						$other2=0; $c = 0;
                    $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                    foreach($install as $ins){ $c++;
                        $over = "";
                            $exists = $db->getRow("select * from otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' ");
						    if($exists > 1){
    						    $fee = $exists['fee'];
    						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");

    						    $discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' "); 

    						    if($fStudent['stype']=="old" && $exists['otype']=="new"){
								    $over="";
    							}
    						   elseif($fStudent['stype']=="new" && $exists['otype']=="old"){
    								$over="";
    							}
    							else {
    							    $over = $exists['fee'] - $discount - $paid;
        							$other2+=$over;
    							}

						    }
						    else {
						        $over = "";
						    }
                        $otherfeecolumn[$c]+= $over;
						?>
						<!--<td> <?php //if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>-->
						<?php
					}
					$total_full+=$other2;

					$install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and class='".$fStudent['class']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
									
					$discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and class='".$fStudent['class']."' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
					
					$install2=$db->getRow("select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					$discount2= $db->getVal("SELECT COALESCE(sum(discount),0) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id in(select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."')   and session='".$_SESSION["admin"]["session"]."' ");

							$dues=0;
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'"); 
                                								
								
								if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									   
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
						$backduescolumn[0]+=$dues;	

						$install=$db->getRows("select * from otherfee_structure where class='".$fStudent['class']."' and otype ='".$fStudent['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else
										$dues=$ins['fee'];
								}
										if($fine_t==$total_dues)
												$dues=0;
								else $dues=$fine_t-$total_dues;
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues-$discount2;
						
                        $install2=$db->getRow("SELECT otype,GROUP_CONCAT(id) as id FROM `otherfee_structure` where otype='".$fStudent['idno']."'  and class='".$fStudent['class']."' and name like 'Latefine%'");

						$dis3= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and class='".$fStudent['class']."' and other_id in($install2[id])   and session='".$_SESSION["admin"]["session"]."' ");

                        $to=$db->getVal("select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf) and session='".$_SESSION["admin"]["session"]."'");
                        $to1=$db->getVal("SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");
                        $dis1=$db->getVal("SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and class='".$fStudent['class']."' and session='".$_SESSION["admin"]["session"]."' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");

                        $t2=$to-$to1-$dis1;
                        $totalothercolumn[0]+=$t2;

    					if($dues=="0"){
                            $finetotal=$dues;
    					}
    					else
    					{
    					    $finetotal=$dues-$dis3;
    					}
    					$finecolumn[0]+=$finetotal;

    					$other2_hostel=0; $b = 0;
                        $install=$db->getRows("select * from hostel_otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                        foreach($install as $ins){ $b++;
                            $over_hostel = "";
                                $exists = $db->getRow("select * from hostel_otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' ");
    						    if($exists > 1){
        						    $fee = $exists['fee'];
        						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");
    
        						    $discount= $db->getVal("SELECT sum(discount) from hostelotherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' "); 
    
        						    if($fStudent['htype']=="old" && $exists['otype']=="new"){
    								    $over_hostel="";
        							}
        						   elseif($fStudent['htype']=="new" && $exists['otype']=="old"){
        								$over_hostel="";
        							}
        							 elseif($fStudent['htype']==""){
        								$over_hostel="";
        							}
        							else {
        							    $over_hostel = $exists['fee'] - $discount - $paid;
            							$other2_hostel+=$over_hostel;
        							}
    						    }
    						    else {
    						        $over_hostel = "";
    						    }
    					}
    					$total_full+=$other2_hostel;

                  $total_comp+=$total_full+$t2; 
			}
			?>
                <tr>
                	<td><?php echo $z; ?></td>
					<td><?php echo $cls;  ?></td>
					<td><?php echo count($secstu); $totalstrength+=count($secstu); ?></td>
                    <td><?php echo $total_comp; $totalamount+=$total_comp; ?></td>
                </tr>

                <?php

        } ?>
        			</tbody>
                </table>

            <label style="float:left;">Total Students: <?php echo $totalstrength; ?></label>
            <label style="float:right;">Total Dues: <?php echo $totalamount; ?></label>
        </div>

        <?php
	}

	elseif(isset($_GET['hostel_outstanding']))
	{
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					
		$overAllNewextra=0;

        $whereclass = "";
        $hostelotherclass = "";
        if($_GET['class']!=""){
            $whereclass .= " s.class='".$_GET["class"]."' and ";
            $hostelotherclass = " class='".$_GET["class"]."' and ";
        }

        $wheresection = "";
        if($_GET['section']!=""){
            $wheresection .= " s.section='".$_GET["section"]."' and ";
        }

        $where=" s.session='".$_SESSION["admin"]["session"]."' and s.status=1  and i.idno=s.idno and i.total>0 and i.session='".$_SESSION["admin"]["session"]."' ";
		$table=" student as s, hostelinstallment as i";
		$aryStudentList=$db->getRows("SELECT s.* FROM ".$table." where $whereclass $wheresection s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and ".$where." order by s.name");

		$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");
		
		$m=0;
		if(isset($_GET['fmonth']) && $_GET['fmonth']!=0){
			$month=$_GET["fmonth"];
			 // if($month<4){
				// $m=($month+9);
			 // }
			 // else{
				// $m=$month-3;
			 // }
			 $m = $_GET['fmonth'];
		}
		else{
			$m=12;
		}
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
        <style type="text/css">
            @media print {
                #btnduesend {
                    display :  none;
                }
            
                #btnduesend1 {
                    display :  none;
                }
            
                #searchfoertotal {
                    display :  none;
                }
            }
        </style>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            
            <input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
			<input type="button" class="btn btn-danger hidet" onclick="getStudentfinePopup()" value="Add Fine" style="float:left;" />
			<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" style="float:left;">Sms Preview</a>

            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>

			<a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=DueSheet&fmonth=$_GET[fmonth]&class=$_GET[class]&hostel_outstanding=&section=$_GET[section]&bus=$_GET[bus]&location=$_GET[location]&head_name=$_GET[head_name]"; ?>" target="_blank" >Full Screen</a>
            <style>
                @media print {
                    #myPrntbtn {
                        display :  none;
                    }
                }
            </style>

			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Complete Outstanding">
				<thead>
				<tr>
                	<th class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></th>
                	<th>S.No</th>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<th>Class</th>
                    <th>Roll No.</th>
					<th>Contact No</th>
                     <?php
			   if(is_array($monthsList1) && count($monthsList1)>0){
					for($i=1;$i<=$m;$i++){?>
						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
					}
			   }
                ?>

                <?php $install=$db->getRows("select * from hostel_otherfee_structure where $hostelotherclass  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'  GROUP BY name");
					foreach($install as $ins){ ?>
					    <th><?php echo $ins['name'] ?></th>
			    <?php } ?>
               <th>Total</th>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;
			for($j=1; $j<=$m; $j++){
						$md[]=$j;
					}					

					 $mdf= implode(',',$md);

                    $monthlycolumn = [];
                    $otherfeecolumn = [];
					$backduescolumn = [];
					$hostelothercolumn = [];
					$totalothercolumn = [];
					$finecolumn = [];

					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                    		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>
                        	<td id="newid<?php echo $i ?>"><?php echo $i ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]." - ".$fStudent["section"]  ?></td>
                            <td><?php echo $fStudent["fincome"];?></td>
							<td><?php echo $fStudent["mobile"]; ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							$m1=$m+1;			
							foreach($monthsList1 as $key=>$val){$count++;

							if($mn===0){
							
							}
							else{ $mn--;

						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
						    $hostel = $installTution["i$key"]-$installTution["ip$key"];
						}else{
							$hostel="";
						}
						$overAllhotel=$hostel;
						

                    $monthlycolumn[$key] +=$hostel; 
						
						  //if($i==23){echo $overAlltution."--".$overAllTransport."--".$overAllhotel."--".$overAllNewextra."!!!!";}
						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhotel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhotel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhotel+$overAllNewextra;}
						//if($i==23)echo "(".$total.")";
						//$total_full=$total_full+$total;
			$total_full=$total_full+$total;
			?><td><?php
			if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td> 
			<?php 
					?>
					<?php }}


					?>

					<?php 
				// 	$install=$db->getRows("select * from hostel_otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
                    
					$other2_hostel=0; $b = 0;
                    $install=$db->getRows("select * from hostel_otherfee_structure where $hostelotherclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                    foreach($install as $ins){ $b++;
                        $over_hostel = "";
                            $exists = $db->getRow("select * from hostel_otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' ");
						    if($exists > 1){
    						    $fee = $exists['fee'];
    						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");

    						    $discount= $db->getVal("SELECT sum(discount) from hostelotherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' "); 

    						    if($fStudent['htype']=="old" && $exists['otype']=="new"){
								    $over_hostel="";
    							}
    						   elseif($fStudent['htype']=="new" && $exists['otype']=="old"){
    								$over_hostel="";
    							}
    							 elseif($fStudent['htype']==""){
    								$over_hostel="";
    							}
    							else {
    							    $over_hostel = $exists['fee'] - $discount - $paid;
        							$other2_hostel+=$over_hostel;
    							}

						    }
						    else {
						        $over_hostel = "";
						    }

						?>
						<td> <?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
						<?php
						$hostelothercolumn[$b]+=$over_hostel;
					}
					$total_full+=$other2_hostel;
                    
                    ?>

                    <?php
                    
/*
						if(is_array($install) && count($install)>0){
							$k=0;$b=0;$other2_hostel=0;
							foreach($install as $ins){$k+=2;$b++;
							if($fStudent['htype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
						   elseif($fStudent['htype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							 elseif($fStudent['htype']==""){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther_hostel=$t - $other1;
						    $over_hostel=$overAllOther_hostel;
							$other2_hostel+=$over_hostel;
							
						}?>	<td><?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
				<?php }	
						}
						$total_full+=$other2_hostel; */

					?>

      <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $total_full+$t2; ?>
      
      			 <input type="hidden" name="amount" id="total_amt<?php echo $fStudent['idno'] ?>" value="<?php echo $total_full+$t2; ?>" />
			  <input type="hidden" name="amount" id="mobile<?php echo $fStudent['idno'] ?>" value="<?php   echo $fStudent['mobile'] ?>" />
      </td>		
				<?php $total_comp+=$total_full+$t2; }

				?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo 8;?>">Gross Total</td>
					<?php for($s = 1; $s<=$m; $s++){
					    echo "<td>$monthlycolumn[$s]</td>";
					} 


					for($s = 1; $s<=$b; $s++){
					    echo "<td>$hostelothercolumn[$s]</td>";
					}

					?>
				   <td id="MyTotalLeft"><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
}


	elseif(isset($_GET['month_report_excel']))
	{
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					
			$overAllNewextra=0;
			
        $whereclass = "";			
        if($_GET['class']!=""){
            $whereclass = " class='".$_GET["class"]."' and ";
        }
// 		$aryStudentList=$db->getRows("select * from student where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");

		$aryStudentList=$db->getRows("select * from student where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");
		
		$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");
		
		$m=0;
		if(isset($_GET['fmonth']) && $_GET['fmonth']!=0){
			$month=$_GET["fmonth"];
			  if($month<4){
				$m=($month+9);
			  }
			  else{
				$m=$month-3;
			  }

		}
		else{
			$m=12;
			
		}
		  //echo $m;
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
			
<style type="text/css">
@media print {
    #btnduesend {
        display :  none;
    }
}

@media print {
    #btnduesend1 {
        display :  none;
    }
}

@media print {
    #searchfoertotal {
        display :  none;
    }
}
</style>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            
            <input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
			<input type="button" class="btn btn-danger hidet" onclick="getStudentfinePopup()" value="Add Fine" style="float:left;" />
			<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" style="float:left;">Sms Preview</a>


            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Complete Outstanding">
				<thead>
				<tr>
                	<!--<th class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></th>-->
                	<th>S.No</th>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<th>Class</th>
                    <th>Section</th>
					<th>Contact No</th>
                     <?php
			   if(is_array($monthsList1) && count($monthsList1)>0){
				/*foreach($monthsList1 as $ftype){
					?><th width="0.5%"><?php echo $ftype ?></th><?php
				}*/
					for($i=1;$i<=$m;$i++){?>
						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
					}
			   }
// echo "select * from otherfee_structure where   school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' )  and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'";			  
			   $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
				// 	echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
                    <th>Back Dues</th>
              <?php 
			  
			  $install=$db->getRows("select * from hostel_otherfee_structure where $whereclass  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'  GROUP BY name");
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
					<th>Total_other</th>
                    <th>Fine</th>
               <th>Total</th>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;
			for($j=1; $j<=$m; $j++){
						$md[]=$j;
					}					
					//print_r($md);
					 $mdf= implode(',',$md);
					 
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                    		<!--<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>-->
                        	<td><?php echo $i ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]; //echo "-"; echo $fStudent["section"]  ?></td>
                            <td><?php echo $fStudent["section"];?></td>
							<td><?php echo $fStudent["mobile"]; ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							$m1=$m+1;			
							foreach($monthsList1 as $key=>$val){$count++;

							if($mn===0){
							
							}
							else{ $mn--;
						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");

						//$db->getLastQuery();
						if(is_array($installTution) && count($installTution)>0){	
						  //  echo "ip$key";
						  //  echo $installTution[0];
						  //print_r($installTution['ip1']);
							if($installTution["ip$key"]=="" || $installTution["ip$key"]=="0")
							{
							 //   echo "not paid";
								$tution=$installTution["i$key"];
							}
							else
							{
							 //   echo "<b>paid</b>";
				// 		echo gettype($key);
				// echo $key;
				if($m==$key)
				{
				$tution=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from installment where  idno='".$fStudent["idno"]."' ");
				}
                else
                   {
	             $tution=0;	
                     }

							}
							
						}else{
							$tution="";
						}

						$overAlltution=$tution;
												// echo $overAlltution;
												
						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");
				// 		echo "select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'";
						if(is_array($installTution) && count($installTution)>0){
							if($installTution["bp$key"]=="" || $installTution["bp$key"]==0)
							{
								$trasnport=$installTution["b$key"];
							}
							else
							{
								
					 $tut_last_val=$db->getVal("select bp".$key1." from installment where  idno='".$fStudent["idno"]."'");

				if($m==$key)
				{
				$trasnport=$db->getVal("select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' ");
				
				//echo $ss="select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)";
	
				}
                else
                   {
	             $trasnport=0;	
                     }				
								
								
							}
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;
				// 		echo $overAllTransport;
						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							if($installTution["ip$key"]=="" || $installTution["ip$key"]==0)
							{
								$hostel=$installTution["i$key"];
							}
							else
							{
							if($m==$key)
				{
				$hostel=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from hostelinstallment where  idno='".$fStudent["idno"]."' ");
				
	
				}
                else
                   {
	             $hostel=0;	
                     }	

							}								
						}else{
							$hostel="";
						}
						$overAllhotel=$hostel;
				// 		echo $overAllhotel;
						$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								///echo $db->getErMsg().$db->getLastQuery();
								//echo $Ftypeid."-";print_r($installTution);
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									
									if($installTution["pay"]=="" || $installTution["pay"]==0)
									{
										$sums=$installTution["fee"];
									}
									else
									{
										if($m==$key)
				{
					
									$ext_last=$db->getVal("select sum(pay) from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$key1."' ");
	
	if($ext_last==0)
									{	
									$sums=$db->getVal("select sum(fee-pay)  from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$key."'  ");
									
									//echo $ss="select sum(fee-pay)  from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$key."'  ";
									
									}
	
				}
                else
                   {
	             $sums=0;	
                     }	
										
									}
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}

						
						 $overAllNewextra=0;//print_r($extrasum);
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						//echo $ij.$overAllNewextra."-";
						}//$j++;
						/*$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								//echo $db->getErMsg().$db->getLastQuery();
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution[1]=="" || $installTution[1]=="0")
										$sums=$installTution[0];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total+=$sums;$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}*/
						  //if($i==23){echo $overAlltution."--".$overAllTransport."--".$overAllhotel."--".$overAllNewextra."!!!!";}
						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhotel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhotel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhotel+$overAllNewextra;}
						//if($i==23)echo "(".$total.")";
						//$total_full=$total_full+$total;
			if($key=="12"){			
		$total23=$db->getVal("select (COALESCE(i12,0)+COALESCE(b12,0)-COALESCE(ip12,0)-COALESCE(bp12,0)) from installment where idno='".$fStudent["idno"]."'");
		
		$total24=$db->getVal("select (COALESCE(i12,0)-COALESCE(ip12,0)) from hostelinstallment where idno='".$fStudent["idno"]."'");
		
		$te=$db->getVal("SELECT sum(fee-pay) FROM `extrafee` WHERE idno='".$fStudent["idno"]."' and pid='p12' and session='".$_SESSION["admin"]["session"]."'  ");
		
		$total22=$total23+$total24+$te;
		$total_full+=$total22;
			?>
			<td><?php if( $total22=="0" )echo "<lable style='color:red'>paid</label>";elseif($total=="" && $total22=="") echo "<lable style='color:red'>X</label>";  else echo $total22; ?></td>
		<?php	}
			else{ 
			$total_full=$total_full+$total;
			?><td><?php 
			
			
			if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td> <?php }
					?>
					<?php }}
										
				// 	$install=$db->getRows("select * from otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						//echo  $db->getLastQuery();
						$other2=0; $c = 0;
                    // $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='1' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '1' and session='2021-2022' GROUP BY name");						
                    $install=$db->getRows("select * from otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                    foreach($install as $ins){ $c++;
                        $over = "";
                            $exists = $db->getRow("select * from otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' ");
						    if($exists > 1){
    						    $fee = $exists['fee'];
    						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");

    						    $discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' "); 

    						    if($fStudent['stype']=="old" && $exists['otype']=="new"){
								    $over="";
    							}
    						   elseif($fStudent['stype']=="new" && $exists['otype']=="old"){
    								$over="";
    							}
    							else {
    							    $over = $exists['fee'] - $discount - $paid;
        							$other2+=$over;
    							}

						    }
						    else {
						        $over = "";
						    }

						?>
						<td> <?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
						<?php
					}
					$total_full+=$other2;
						/*
						if(is_array($install) && count($install)>0){
							$k=0;$c=0;$other2=0;
							foreach($install as $ins){$k+=2;$c++;
							if($fStudent['stype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
						   elseif($fStudent['stype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from otherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
					 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt)
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
							
						}?>	<td> 123 <?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php }	
						}
					*/
				// 	$total_full+=$other2;
						//echo $i."-".$t.$other1."<br/>";
					
					$install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and class='".$fStudent['class']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
									
					$discount= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and class='".$fStudent['class']."' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
					
					$install2=$db->getRow("select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					$discount2= $db->getVal("SELECT COALESCE(sum(discount),0) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id in(select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."')   and session='".$_SESSION["admin"]["session"]."' ");
										
					//echo $discount;
					
					//print_r($install);
							$dues=0;
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'"); 
                                								
								
								if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									   
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; //echo 111; ?></td>

					<?php 
				// 	$install=$db->getRows("select * from hostel_otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
                    
					$other2_hostel=0; $b = 0;
                    $install=$db->getRows("select * from hostel_otherfee_structure where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and (otype = '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' GROUP BY name");
                    foreach($install as $ins){ $b++;
                        $over_hostel = "";
                            $exists = $db->getRow("select * from hostel_otherfee_structure where name='$ins[name]' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."' ");
						    if($exists > 1){
    						    $fee = $exists['fee'];
    						    $paid = $db->getVal("select sum(amount) from reff_receipt where idno=".$fStudent['idno']." and type='$exists[name]' and session='".$_SESSION["admin"]["session"]."' ");

    						    $discount= $db->getVal("SELECT sum(discount) from hostelotherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$exists[id]'   and session='".$_SESSION["admin"]["session"]."' "); 

    						    if($fStudent['htype']=="old" && $exists['otype']=="new"){
								    $over_hostel="";
    							}
    						   elseif($fStudent['htype']=="new" && $exists['otype']=="old"){
    								$over_hostel="";
    							}
    							 elseif($fStudent['htype']==""){
    								$over_hostel="";
    							}
    							else {
    							    $over_hostel = $exists['fee'] - $discount - $paid;
        							$other2_hostel+=$over_hostel;
    							}

						    }
						    else {
						        $over_hostel = "";
						    }

						?>
						<td> <?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
						<?php
					}
					$total_full+=$other2_hostel;
                    
                    ?>

                    <?php
                    
/*
						if(is_array($install) && count($install)>0){
							$k=0;$b=0;$other2_hostel=0;
							foreach($install as $ins){$k+=2;$b++;
							if($fStudent['htype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
						   elseif($fStudent['htype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							 elseif($fStudent['htype']==""){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther_hostel=$t - $other1;
						    $over_hostel=$overAllOther_hostel;
							$other2_hostel+=$over_hostel;
							
						}?>	<td><?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
				<?php }	
						}
						$total_full+=$other2_hostel; */
						
						
						$install=$db->getRows("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else 		
									//$dues=$ins['fee']-$discount;
										$dues=$ins['fee'];
								}
										if($fine_t==$total_dues)
												$dues=0;
						//else $dues=$fine_t-$total_dues-$discount;	
								else $dues=$fine_t-$total_dues;	
										
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues-$discount2;
						
					 $install2=$db->getRow("SELECT otype,GROUP_CONCAT(id) as id FROM `otherfee_structure` where otype='".$fStudent['idno']."'  and class='".$fStudent['class']."' and name like 'Latefine%'");
							//echo $install2[id];
							
							$dis3= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and class='".$fStudent['class']."' and other_id in($install2[id])   and session='".$_SESSION["admin"]["session"]."' ");
							
							
					?>
					<td>
					<?php  
					
							
					$to=$db->getVal("select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf) and session='".$_SESSION["admin"]["session"]."'");
				
			//echo	$ss="select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf) and session='".$_SESSION["admin"]["session"]."'";
				$to1=$db->getVal("SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");
				
				//echo $ss="SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))";
					
				$dis1=$db->getVal("SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and class='".$fStudent['class']."' and session='".$_SESSION["admin"]["session"]."' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and class='".$fStudent['class']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");
		//	echo	$ss="SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))";
										
					 echo $t2=$to-$to1-$dis1;
   
					?></td>
					<?php 
						if($dues=="0")
					{
					 $finetotal=$dues;   
					}
					else
					{
					$finetotal=$dues-$dis3;    
					}
					
					?>
		<td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues-$dis3; ?></td>
			 <input type="hidden" name="amount" id="total_amt<?php echo $fStudent['idno'] ?>" value="<?php echo $total_full+$t2; ?>" />
			  <input type="hidden" name="amount" id="mobile<?php echo $fStudent['idno'] ?>" value="<?php   echo $fStudent['mobile'] ?>" />
      <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $total_full+$t2; ?></td>		
				<?php $total_comp+=$total_full+$t2; }?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $m+10+$c+$b;?>">Gross Total</td>
				   <td id="MyTotalLeft"><?php echo $total_comp; ?></td>
				</tfoot> 
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
} 


    elseif(isset($_GET["class"]) && trim($_GET["class"])!=""){
	$whereS="";
	if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="")
			$whereS=" AND section='".$_REQUEST["section"]."' ";
	
	if(isset($_REQUEST["daily"])){
		if(isset($_GET["fmonth"]) && trim($_GET["fmonth"])!="" && isset($_GET["class"]) && trim($_GET["class"])!=""){
		$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;
		
		$aryStudentList=$db->getRows("select * from student where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");
		$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");
		//echo $db->getErMsg().$db->getLastQuery();
		$month=$_GET["fmonth"];$m=0;
		  if($month<4){
			$m=($month+9);
		  }
		  else{
			$m=$month-3;
		  }
		  //echo $m;
		 $aryother=$db->getRows("select * from otherfee_structure where (otype ='' or otype ='old' or otype ='new') and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$_GET["class"]."'"); 
						 
		//echo $db->getLastQuery();exit;								 
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List" style="float:left;" />
            <h5><p style="float:right">Month: <?php echo $monthsList[$month-1]; ?></p> <p>Monthly Due Sheet</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" id="tblData">
				<thead>
				<tr>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
					<td>Tution Fee</td>
					<td>Transport fee</td>
					<td>Hostel Fee</td>
				   <?php
				   if(is_array($aryFeeType) && count($aryFeeType)>0){
					foreach($aryFeeType as $ftype){
						?><td><?php echo $ftype["type"] ?></td><?php
					}
				   }
				   if(is_array($aryother) && count($aryother)>0){
					foreach($aryother as $otype){
						?><td><?php echo $otype["name"] ?></td><?php
					}
				   }
				   ?>
				   <th>Back Dues</th> 
				   <td>Total</td>
				</tr>
				</thead>
				<tbody>
					<?php $i=0;
					foreach($aryStudentList as $fStudent){$i++;
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$duesother=0;
						$installTution=$db->getRow("select i".$m.",ip".$m." from installment where idno='".$fStudent["idno"]."'");
						//echo $db->getErMsg().$db->getLastQuery();
						if(is_array($installTution) && count($installTution)>0){
							if($installTution[1]=="" || $installTution[1]=="0")
								$tution=$installTution[0];
							else
								$tution=0;	
						}else{
							$tution="";
						}
						$overAlltution+=$tution;
						$total+=$tution;
						$installTution=$db->getRow("select b".$m.",bp".$m." from installment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							if($installTution[1]=="" || $installTution[1]=="0")
								$trasnport=$installTution[0];
							else
								$trasnport=0;
						}else{
							$trasnport="";
						}
						$overAllTransport+=$trasnport;
						$total+=$trasnport;
						$installTution=$db->getRow("select i".$m.",ip".$m." from hostelinstallment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							if($installTution[1]=="" || $installTution[1]=="0")
								$hostel=$installTution[0];
							else
								$hostel=0;	
						}else{
							$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$m."' and idno='".$fStudent["idno"]."'");
								//echo $db->getErMsg().$db->getLastQuery();
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution[1]=="" || $installTution[1]=="0")
										$sums=$installTution[0];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total+=$sums;$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}
						
						$overAllNewextra+=$newExtra;
						$otherarrr=array();
						
					if(is_array($aryother) && count($aryother)>0){
						foreach($aryother as $otype){
							if($fStudent['stype']=="old" && $otype['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$other="";
							}
						   elseif($fStudent['stype']=="new" && $otype['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$other="";
							}
							else{ 
						    $installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$otype['name']."'"); 
							$installTution1=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$otype['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from otherfee_discount where idno=".$fStudent['idno']." and other_id='".$otype['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$total_fine=0;$other_left=$other=0;$t=$otype['fee'];
						//echo $fStudent['idno'];exit;	
							if(is_array($installTution2) && count($installTution2)>0){
										 $dis=$installTution2['discount'];
												if($otype['fee']==$dis)
													$t=0;
												else 
													$t=$t-$dis;
							 }
					 if($t!=0 && $t<=$otype['fee']){
							 if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
									 if(is_array($installTution1) && count($installTution1)>0)
										 {$other_left=$installTution1['fine'];}
									 $other=$installTution['fine'];
									 if($other!=$t && $other_left!=0)
									 	$total_fine=$other+$other_left;
									 else
										$total_fine=$other;
									 //if($i==12)echo $other;
									if($total_fine!=$t)
									{$other=$t-$total_fine;}
									elseif($total_fine==$t){$other=0;}
								}
									
							}else{
								$other=$t;
							}
						}
						else{
							$other=0;
						}
					}	
							$other1=$t-$other;
							$otherarrr[]=$other;$tp=$otype['name'];
							$overAllOther22[$tp]+=$other;
							$total+=$other;
							  /*if(is_array($installOther) && count($installOther)>0){
									foreach($installOther as $installOther1){
										$total_fine+=$installOther1['fine'];	
										  if($total_fine==$otype['fee'])	
												$duesother=0;
										  else
										  		$duesother=$otype['fee']-$total_fine;	
							  		}
							  }
							   else 		
									$duesother=$otype['fee'];
						$othersum[]=$duesother;*/
						
						
						}
					}//print_r($otherarrr);exit;
						//echo $db->getErMsg();
						$install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$installTution_remain="";
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'");        
								if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues;	
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee'];
									
							}
							else
								$dues="";
							$alldues+=$dues;
							$total+=$dues;
						?>
						<tr>
                        	<td><?php echo $i ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?></td>
                            <td><?php echo $fStudent["section"] ?></td>
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
							<td><?php if($tution=="0")echo "<lable style='color:red'>paid</label>";elseif($tution=="") echo "<lable style='color:red'>X</label>"; else echo $tution; ?></td>
							<td><?php if($trasnport=="0")echo "<lable style='color:red'>paid</label>";elseif($trasnport=="") echo "<lable style='color:red'>X</label>";else echo $trasnport ?></td>
							<td><?php if($hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($hostel=="") echo "<lable style='color:red'>X</label>";else echo $hostel ?></td>
							<?php for($ij=0; $ij<count($aryFeeType); $ij++){ ?><td><?php if($extrasum[$ij]=="0")echo "<lable style='color:red'>paid</label>";elseif($extrasum[$ij]=="") echo "<lable style='color:red'>X</label>";else echo $extrasum[$ij]; ?></td><?php } ?>
						    <?php for($ij=0; $ij<count($otherarrr); $ij++){ ?><td><?php if($otherarrr[$ij]=="0")echo "<lable style='color:red'>paid</label>";elseif($otherarrr[$ij]=="") echo "<lable style='color:red'>X</label>";else echo $otherarrr[$ij]; ?></td><?php } ?>
                           <th><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>";else echo $dues ?></th>
						   <td class="MyTotalLeft"><?php echo $total;$overAllTotal+=$total; ?></td>
						</tr>
						<?php
					}
					?>
				</tbody>
				<tfoot>
					<td colspan="7">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
						}
					   }?>
                    <?php
					if(is_array($overAllOther22) && count($overAllOther22)>0){
						foreach($overAllOther22 as $otype){
							?><td><?php echo $otype ?></td><?php
						}
					   }?>   
                       <th style="font-weight:800"><?php echo $alldues;	 ?></th>
				   <td><?php echo $overAllTotal; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
			<?php 
		}else{
			//echo $db->getErMsg().$db->getLastQuery();
		}
	}}


// sibling start 

elseif(isset($_REQUEST['month_report_sibling']))
	{
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					$overAllNewextra=0;
		$aryStudentList=$db->getRows("select *, REPLACE(sibling,idno,'') as sibling1 from student where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");
		
		$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");
		$m=0;
		if(isset($_REQUEST['fmonth']) && $_REQUEST['fmonth']!=0){
			$month=$_GET["fmonth"];
			  if($month<4){
				$m=($month+9);
			  }
			  else{
				$m=$month-3;
			  }
		}
		else{
			$m=12;
		}
		 // echo $m;
		 
		 
		 
		 
		 
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData">
				<thead>
				<tr>
                	<td class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></td>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
                     <?php
			   if(is_array($monthsList1) && count($monthsList1)>0){
				/*foreach($monthsList1 as $ftype){
					?><th width="0.5%"><?php echo $ftype ?></th><?php
				}*/
					for($i=1;$i<=$m;$i++){?>
						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
					}
			   }
			  
			   $install=$db->getRows("select * from otherfee_structure where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' )  and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php										
					}?>
                    <th>Back Dues</th>
              <?php $install=$db->getRows("select * from hostel_otherfee_structure where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
                    <th>Fine</th>
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php $i=0;$total_comp=0;
		
					foreach($aryStudentList as $fStudent){
					$mn=$m;
					
					//$sib_chk=$db->getRow("select replace(GROUP_CONCAT(REPLACE(sibling,idno,'')),',','') as sibling from student where  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");
					
					//$sib_chk=str_split($sib_chk["sibling"],1);
					
					$sib_chk1=$db->getRows("select GROUP_CONCAT(REPLACE(sibling,idno,'')) as sibling from student where sibling!='' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");
					
					
					//print_r(array_filter(explode(',',$sib_chk1[0][sibling])));
					
					
					//$sib_chk=str_split($sib_chk["sibling"],1);
					$sib_chk=array_filter(explode(',',$sib_chk1[0][sibling]));
					
				
					//print_r($sib_chk);
					//if(in_array($fStudent["idno"],$sib_chk)){
						$id33= $fStudent["idno"];
						if(in_array($id33,$sib_chk)){
							
					}
					else{ $i++;
					?>
                    <tr>
                    		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>
                        	<td><?php echo $i ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]; //echo "-"; echo $fStudent["section"]  ?></td>
                            <td><?php 
							
							/*$ndate=$db->getVal("select date from installment_time where idno='".$fStudent["idno"]."' order by id DESC");
							$fdate=$db->getVal("select udate from installment_fine where idno='".$fStudent["idno"]."' order by id DESC");
							if($ndate!='' or $fdate!=''){
							$fdate=date("d-M-Y",strtotime($fdate));
							
							$fudate=date("d-M-Y",strtotime($ndate));
							
							if ($fudate>$fdate){
							echo $fdate;}else echo $fudate; }*/
                           echo $fStudent["section"]
							?></td>
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							foreach($monthsList1 as $key=>$val){$count++;
							if($mn==0){
								
							}
							else{ $mn--;
						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");
						//$db->getLastQuery();
						if(is_array($installTution) && count($installTution)>0){	
							if($installTution[1]=="" || $installTution[1]=="0")
								$tution=$installTution[0];
							else
								$tution=0;	
							
						}else{
							$tution="";
						}
						$overAlltution=$tution;
						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							if($installTution[1]=="" || $installTution[1]=="0")
								$trasnport=$installTution[0];
							else
								$trasnport=0;
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;
						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							if($installTution[1]=="" || $installTution[1]=="0")
								$hostel=$installTution[0];
							else
								$hostel=0;	
						}else{
							$hostel="";
						}
						$overAllhotel=$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								///echo $db->getErMsg().$db->getLastQuery();
								//echo $Ftypeid."-";print_r($installTution);
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution[1]=="" || $installTution[1]=="0")
										$sums=$installTution[0];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}

						
						 $overAllNewextra=0;//print_r($extrasum);
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						//echo $ij.$overAllNewextra."-";
						}//$j++;
						/*$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								//echo $db->getErMsg().$db->getLastQuery();
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution[1]=="" || $installTution[1]=="0")
										$sums=$installTution[0];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total+=$sums;$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}*/
						  //if($i==23){echo $overAlltution."--".$overAllTransport."--".$overAllhotel."--".$overAllNewextra."!!!!";}
						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhotel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhotel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhotel+$overAllNewextra;}
						//if($i==23)echo "(".$total.")";
						$total_full=$total_full+$total;
					?><td><?php if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td>
					<?php }}
					
					$install=$db->getRows("select * from otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						//echo  $db->getLastQuery();
						if(is_array($install) && count($install)>0){
							$k=0;$c=0;$other2=0;
							foreach($install as $ins){$k+=2;$c++;
							if($fStudent['stype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
						   elseif($fStudent['stype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from otherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt)
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
							
						}?>	<td><?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php }	
						}
					$total_full+=$other2;
						//echo $i."-".$t.$other1."<br/>";
					
					$install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					
					
				
					
					$discount= $db->getVal("SELECT discount from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
					
					$install2=$db->getRow("select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					$discount2= $db->getVal("SELECT COALESCE(sum(discount),0) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id in(select id from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."')   and session='".$_SESSION["admin"]["session"]."' ");
										
					//echo $discount;
					
					//print_r($install);
							$dues=0;
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'"); 
                                								
								
								if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									   
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; //echo 111; ?></td>	
					
					<?php 
					$install=$db->getRows("select * from hostel_otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						//echo  $db->getLastQuery();
						if(is_array($install) && count($install)>0){
							$k=0;$b=0;$other2_hostel=0;
							foreach($install as $ins){$k+=2;$b++;
							if($fStudent['htype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
						   elseif($fStudent['htype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							 elseif($fStudent['htype']==""){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
				$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther_hostel=$t - $other1;
						    $over_hostel=$overAllOther_hostel;
							$other2_hostel+=$over_hostel;
							
						}?>	<td><?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
				<?php }	
						}$total_full+=$other2_hostel; 
						$install=$db->getRows("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else 		
									//$dues=$ins['fee']-$discount;
										$dues=$ins['fee'];
								}
										if($fine_t==$total_dues)
												$dues=0;
						//else $dues=$fine_t-$total_dues-$discount;	
								else $dues=$fine_t-$total_dues;	
										
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues-$discount2;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues-$discount2;  ?></td>	
			
                    <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $total_full; $sib_tot=$total_full; ?></td>		
				<?php $total_comp+=$total_full; ?>
				
				</tr>
<!--sibling student start-->

				<?php if(!empty($fStudent["sibling1"])){ 
				$sib= $fStudent["sibling1"];
				$sib_val=array_filter((explode(',',$sib)));
				//print_r($sib_val);
				
				
					
				foreach($sib_val as $sib_val1)
				{
				$mn=$m;
		$sibStudentList=$db->getRow("select * from student where idno='".$sib_val1."' ");
				?>
				<tr>
                 <td></td>
                 <td></td>
                 <td><?= $sibStudentList["name"] ?></td>
                 <td><?= $sibStudentList["fname"] ?></td>
                 <td><?= $sibStudentList["admissionno"] ?></td>
                 <td><?= $sibStudentList["class"] ?></td>
                 <td><?= $sibStudentList["section"] ?></td>
                 <td><?= $sibStudentList["mobile"] ?></td>
                 <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							foreach($monthsList1 as $key=>$val){$count++;
							if($mn==0){
								
							}
							else
							{ $mn--;
							
						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$sibStudentList["idno"]."'");
						
						//$db->getLastQuery();
						if(is_array($installTution) && count($installTution)>0){	
							if($installTution[1]=="" || $installTution[1]=="0")
								$tution=$installTution[0];
							else
								$tution=0;	
							
						}else{
							$tution="";
						}
						$overAlltution=$tution;
						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$sibStudentList["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							if($installTution[1]=="" || $installTution[1]=="0")
								$trasnport=$installTution[0];
							else
								$trasnport=0;
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;
						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$sibStudentList["idno"]."'");
						
						
						
						if(is_array($installTution) && count($installTution)>0){
							if($installTution[1]=="" || $installTution[1]=="0")
								$hostel=$installTution[0];
							else
								$hostel=0;	
						}else{
							$hostel="";
						}
						$overAllhotel=$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='".$sibStudentList["class"]."'");
								$installTution=$db->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$sibStudentList["idno"]."'");
								
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution[1]=="" || $installTution[1]=="0")
										$sums=$installTution[0];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}

						
						 $overAllNewextra=0;//print_r($extrasum);
						
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						//echo $ij.$overAllNewextra."-";
						}
						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhotel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhotel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhotel+$overAllNewextra;}
						//if($i==23)echo "(".$total.")";
						$total_full=$total_full+$total;
					?><td><?php if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td>
					<?php }
					} 
					
					$install=$db->getRows("select * from otherfee_structure where class='".$sibStudentList["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new' ) and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						//echo  $db->getLastQuery();
						if(is_array($install) && count($install)>0){
							$k=0;$c=0;$other2=0;
							foreach($install as $ins){$k+=2;$c++;
							if($sibStudentList['stype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
						   elseif($sibStudentList['stype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$sibStudentList['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$sibStudentList['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from otherfee_discount where idno=".$sibStudentList['idno']." and other_id='".$ins['id']."' and class='".$sibStudentList["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
						$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt)
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
							
						}?>	<td><?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php }	
						}
                 
                $total_full+=$other2;
						//echo $i."-".$t.$other1."<br/>";
					
					$install=$db->getRow("select * from otherfee_structure where otype ='".$sibStudentList['idno']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					
			$discount= $db->getVal("SELECT discount from otherfee_discount  WHERE  idno='$sibStudentList[idno]' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
					
					$install2=$db->getRow("select id from otherfee_structure where otype ='".$sibStudentList['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					$discount2= $db->getVal("SELECT COALESCE(sum(discount),0) from otherfee_discount  WHERE  idno='$sibStudentList[idno]' and other_id in(select id from otherfee_structure where otype ='".$sibStudentList['idno']."' and name like 'Latefine%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."')   and session='".$_SESSION["admin"]["session"]."' ");
										
					//echo $discount;
					
					//print_r($install);
							$dues=0;
					if(is_array($install) && count($install)>0){
					$installTution=$db->getRows("select * from installment_fine where idno=".$sibStudentList['idno']." and reasion = '".$install['name']."'"); 
                                								
								
								if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									   
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$sibStudentList['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; //echo 111; ?></td>
                 
                <?php 
					$install=$db->getRows("select * from hostel_otherfee_structure where class='".$sibStudentList["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");

				
				
						//echo  $db->getLastQuery();
						if(is_array($install) && count($install)>0){
							$k=0;$b=0;$other2_hostel=0;
							foreach($install as $ins){$k+=2;$b++;
							if($sibStudentList['htype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
						   elseif($sibStudentList['htype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							 elseif($sibStudentList['htype']==""){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
				$installTution=$db->getRow("select * from installment_fine where idno=".$sibStudentList['idno']." and reasion = '".$ins['name']."'"); 
				
				//echo "select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'";
				
				
							
			$installTution1=$db->getRows("select * from installment_fine where idno=".$sibStudentList['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");
			
						
			$installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$sibStudentList['idno']." and other_id='".$ins['id']."' and class='".$sibStudentList["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
			
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther_hostel=$t - $other1;
						    $over_hostel=$overAllOther_hostel;
							$other2_hostel+=$over_hostel;
							
						}?>	<td><?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
				<?php }	
						}$total_full+=$other2_hostel; 
						$install=$db->getRows("select * from otherfee_structure where otype ='".$sibStudentList['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$sibStudentList['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else 		
									//$dues=$ins['fee']-$discount;
										$dues=$ins['fee'];
								}
										if($fine_t==$total_dues)
												$dues=0;
						//else $dues=$fine_t-$total_dues-$discount;	
								else $dues=$fine_t-$total_dues;	
										
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues-$discount2;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues-$discount2;  ?></td>	
			
                    <td class="MyTotalLeft left<?php echo $sibStudentList['idno'] ?>"><?php echo $total_full;  ?></td>		
				<?php $total_compp+=$total_full; ?>
                   <?php } 
				
				   
				
				 ?> 
				 
                 <td><?= $total_compp+$sib_tot; ?></td>
                <?php unset($total_compp)?>
				</tr>
<!--sibling student end-->
				<?php 
				
				} 
				 } 
				
				} ?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $m+10+$c+$b;?>">Gross Total</td>
					
				   <td><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
}


// sibling end


		// hostel 


	elseif(isset($_REQUEST['hostel'])){
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					$overAllNewextra=0;
		//$aryStudentList=$db->getRows("select * from student where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");
		if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="")
		$whereS1=" AND s.section='".$_REQUEST["section"]."' ";
		$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";
		$aryStudentList=$db->getRows("SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and s.class='".$_GET["class"]."' and ".$where." $whereS1 order by s.name");
		
		//echo "SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and s.class='".$_GET["class"]."' and ".$where." $whereS1 order by s.name"
		
		$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");
		$m=0;
		if(isset($_REQUEST['fmonth']) && $_REQUEST['fmonth']!=0){
			$month=$_GET["fmonth"];
			  if($month<4){
				$m=($month+9);
			  }
			  else{
				$m=$month-3;
			  }
		}
		else{
			$m=12;
		}
		 // echo $m;
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p> Hostel outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;"  id="tblData" data-tblname="Hostel">
				<thead>
				<tr>
                	<td class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></td>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
                     <?php
			   if(is_array($monthsList1) && count($monthsList1)>0){
				/*foreach($monthsList1 as $ftype){
					?><th width="0.5%"><?php echo $ftype ?></th><?php
				}*/
					for($i=1;$i<=$m;$i++){?>
						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
					}
			   }
			  
			   $install=$db->getRows("select * from otherfee_structure where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
                    <th>Back Dues</th>
              <?php $install=$db->getRows("select * from hostel_otherfee_structure where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
                    <th>Fine</th>
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                    		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>
                        	<td><?php echo $i ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]; //echo "-"; echo $fStudent["section"]  ?></td>
                            <td><?php 
							/*$ndate=$db->getVal("select date from installment_time where idno='".$fStudent["idno"]."' order by id DESC");
							$fdate=$db->getVal("select udate from installment_fine where idno='".$fStudent["idno"]."' order by id DESC");
							if($ndate!='' or $fdate!=''){
							$fdate=date("d-M-Y",strtotime($fdate));
							
							$fudate=date("d-M-Y",strtotime($ndate));
							
							if ($fudate>$fdate){
							echo $fdate;}else echo $fudate; } */
							echo $fStudent["section"]
							?></td>
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							foreach($monthsList1 as $key=>$val){$count++;
							if($mn==0){
								
							}
							else{ $mn--;
						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");
						//$db->getLastQuery();

						if(is_array($installTution) && count($installTution)>0){	
							if($installTution["ip$key"]=="" || $installTution["ip$key"]=="0")
								$tution=$installTution["i$key"];
							else
								$tution=0;	
							
						}else{
							$tution="";
						}
						$overAlltution=$tution;
						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");

						if(is_array($installTution) && count($installTution)>0){
							if($installTution["bp$key"]=="" || $installTution["bp$key"]=="0")
								$trasnport=$installTution["b$key"];
							else
								$trasnport=0;
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;
						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$fStudent["idno"]."'");

						if(is_array($installTution) && count($installTution)>0){
							if($installTution["ip$key"]=="" || $installTution["ip$key"]=="0")
								$hostel=$installTution["i$key"];
							else
								$hostel=0;	
						}else{
							$hostel="";
						}
						$overAllhotel=$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
                            	// print_r($installTution);
								///echo $db->getErMsg().$db->getLastQuery();
								//echo $Ftypeid."-";print_r($installTution);
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution["pay"]=="" || $installTution["pay"]=="0")
										$sums=$installTution["fee"];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}

						
						 $overAllNewextra=0;//print_r($extrasum);
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						//echo $ij.$overAllNewextra."-";
						}//$j++;
						/*$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								//echo $db->getErMsg().$db->getLastQuery();
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution[1]=="" || $installTution[1]=="0")
										$sums=$installTution[0];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total+=$sums;$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}*/
						  //if($i==23){echo $overAlltution."--".$overAllTransport."--".$overAllhotel."--".$overAllNewextra."!!!!";}
						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhotel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhotel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhotel+$overAllNewextra;}
						//if($i==23)echo "(".$total.")";
						$total_full=$total_full+$total;
						
					if($key=='12'){			
		//$total23=$db->getVal("select (COALESCE(i13,0)+COALESCE(b13,0)) from installment where idno='".$fStudent["idno"]."'");
		
		$total24=$db->getVal("select (COALESCE(i13,0)) from hostelinstallment where idno='".$fStudent["idno"]."'");
		
		$te=$db->getVal("SELECT sum(fee-pay) FROM `extrafee` WHERE idno='".$fStudent["idno"]."' and pid='p12' and pay!='0'");
		
		$total22=$total23+$total24+$te;
		$total_full+=$total22;
			}
			else{ $total22=0; }
					?><td><?php if($total=="0" AND $total22=="0" )echo "<lable style='color:red'>paid</label>";elseif($total=="" AND $total22=="") echo "<lable style='color:red'>X</label>";  else echo $total+$total22; ?></td>
					<?php }}
					
					$install=$db->getRows("select * from otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						//echo  $db->getLastQuery();
						if(is_array($install) && count($install)>0){
							$k=0;$c=0;$other2=0;
							foreach($install as $ins){$k+=2;$c++;
							if($fStudent['stype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
						   elseif($fStudent['stype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from otherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt)
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
							
						}?>	<td><?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php }	
						}
					$total_full+=$other2;
						//echo $i."-".$t.$other1."<br/>";
					
					$install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					
					$discount= $db->getVal("SELECT discount from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
					//echo $discount;
							$dues=0;
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'");        if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; ?></td>	<?php 
					$install=$db->getRows("select * from hostel_otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						//echo  $db->getLastQuery();
						if(is_array($install) && count($install)>0){
							$k=0;$b=0;$other2_hostel=0;
							foreach($install as $ins){$k+=2;$b++;
							if($fStudent['htype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
						   elseif($fStudent['htype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							 elseif($fStudent['htype']==""){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther_hostel=$t - $other1;
						    $over_hostel=$overAllOther_hostel;
							$other2_hostel+=$over_hostel;
							
						}?>	<td><?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
				<?php }	
						}$total_full+=$other2_hostel; 
						$install=$db->getRows("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else 		
											$dues=$ins['fee']-$discount;
								}
										if($fine_t==$total_dues)
												$dues=0;
										else $dues=$fine_t-$total_dues-$discount;	
										
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; ?></td>	
			
                    <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $total_full; ?></td>		
				<?php $total_comp+=$total_full; }?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $m+10+$c+$b;?>">Gross Total</td>
					
				   <td><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
		}

	// complete oustanding without hostel

	elseif(isset($_REQUEST['without_hostel'])){
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					$overAllNewextra=0;
		//$aryStudentList=$db->getRows("select * from student where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");
		if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="")
		$whereS1=" AND section='".$_REQUEST["section"]."' ";
		
		$where="session='".$_SESSION["admin"]["session"]."' and status=1  and idno NOT IN(select idno from hostelinstallment ) ";
		$table=" student as s, hostelinstallment as i";
		
		//$aryStudentList=$db->getRows("SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and s.class='".$_GET["class"]."' and ".$where." $whereS1 order by s.name");
		
		
		$aryStudentList=$db->getRows("SELECT * FROM student where school_id='".$_SESSION["admin"]["school_id"]."' and issue_TC=0 and class='".$_GET["class"]."' and ".$where." $whereS1 order by name");
		
		//echo "SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and s.class='".$_GET["class"]."' and ".$where." $whereS1 order by s.name";
		//die;
		$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");
		$m=0;
		if(isset($_REQUEST['fmonth']) && $_REQUEST['fmonth']!=0){
			$month=$_GET["fmonth"];
			  if($month<4){
				$m=($month+9);
			  }
			  else{
				$m=$month-3;
			  }
		}
		else{
			$m=12;
		}
		 // echo $m;
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p> Without Hostel outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Without Hostel">
				<thead>
				<tr>
                	<td class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></td>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
                     <?php
			   if(is_array($monthsList1) && count($monthsList1)>0){
				/*foreach($monthsList1 as $ftype){
					?><th width="0.5%"><?php echo $ftype ?></th><?php
				}*/
					for($i=1;$i<=$m;$i++){?>
						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
					}
			   }
			  
			   $install=$db->getRows("select * from otherfee_structure where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
                    <th>Back Dues</th>
              <?php $install=$db->getRows("select * from hostel_otherfee_structure where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
                    <th>Fine</th>
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                    		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" /></td>
                        	<td><?php echo $i ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"]; //echo "-"; echo $fStudent["section"]  ?></td>
                            <td><?php 
							/*$ndate=$db->getVal("select date from installment_time where idno='".$fStudent["idno"]."' order by id DESC");
							$fdate=$db->getVal("select udate from installment_fine where idno='".$fStudent["idno"]."' order by id DESC");
							if($ndate!='' or $fdate!=''){
							$fdate=date("d-M-Y",strtotime($fdate));
							
							$fudate=date("d-M-Y",strtotime($ndate));
							
							if ($fudate>$fdate){
							echo $fdate;}else echo $fudate; } */
							echo $fStudent["section"]
							?></td>
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							foreach($monthsList1 as $key=>$val){$count++;
							if($mn==0){
								
							}
							else{ $mn--;
						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");

						//$db->getLastQuery();
						if(is_array($installTution) && count($installTution)>0){	
							if($installTution["ip$key"]=="" || $installTution["ip$key"]=="0")
								$tution=$installTution["i$key"];
							else
								$tution=0;	
							
						}else{
							$tution="";
						}
						$overAlltution=$tution;
						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");

						if(is_array($installTution) && count($installTution)>0){
							if($installTution["bp$key"]=="" || $installTution["bp$key"]=="0")
								$trasnport=$installTution["b$key"];
							else
								$trasnport=0;
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;
						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$fStudent["idno"]."'");

						if(is_array($installTution) && count($installTution)>0){
							if($installTution["ip$key"]=="" || $installTution["ip$key"]=="0")
								$hostel=$installTution["i$key"];
							else
								$hostel=0;	
						}else{
							$hostel="";
						}
						$overAllhotel=$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								///echo $db->getErMsg().$db->getLastQuery();
								//echo $Ftypeid."-";print_r($installTution);
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution["pay"]=="" || $installTution["pay"]=="0")
										$sums=$installTution["fee"];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}

						
						 $overAllNewextra=0;//print_r($extrasum);
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						//echo $ij.$overAllNewextra."-";
						}//$j++;
						/*$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								//echo $db->getErMsg().$db->getLastQuery();
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution[1]=="" || $installTution[1]=="0")
										$sums=$installTution[0];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total+=$sums;$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}*/
						  //if($i==23){echo $overAlltution."--".$overAllTransport."--".$overAllhotel."--".$overAllNewextra."!!!!";}
						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllhotel==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllhotel==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllhotel+$overAllNewextra;}
						//if($i==23)echo "(".$total.")";
						$total_full=$total_full+$total;
						
					if($key=='12'){			
		//$total23=$db->getVal("select (COALESCE(i13,0)+COALESCE(b13,0)) from installment where idno='".$fStudent["idno"]."'");
		
		$total24=$db->getVal("select (COALESCE(i13,0)) from hostelinstallment where idno='".$fStudent["idno"]."'");
		
		$te=$db->getVal("SELECT sum(fee-pay) FROM `extrafee` WHERE idno='".$fStudent["idno"]."' and pid='p12' and pay!='0'");
		
		$total22=$total23+$total24+$te;
		$total_full+=$total22;
			}
			else{ $total22=0; }
					?><td><?php if($total=="0" AND $total22=="0" )echo "<lable style='color:red'>paid</label>";elseif($total=="" AND $total22=="") echo "<lable style='color:red'>X</label>";  else echo $total+$total22; ?></td>
					<?php }}
					
					
					$install=$db->getRows("select * from otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						//echo  $db->getLastQuery();
						if(is_array($install) && count($install)>0){
							$k=0;$c=0;$other2=0;
							foreach($install as $ins){$k+=2;$c++;
							if($fStudent['stype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
						   elseif($fStudent['stype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from otherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt)
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
							
						}?>	<td><?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php }	
						}
					$total_full+=$other2;
						//echo $i."-".$t.$other1."<br/>";
					
					$install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					$discount= $db->getVal("SELECT discount from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
					
					
							$dues=0;
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'");        if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; ?></td>	<?php 
					$install=$db->getRows("select * from hostel_otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						//echo  $db->getLastQuery();
						if(is_array($install) && count($install)>0){
							$k=0;$b=0;$other2_hostel=0;
							foreach($install as $ins){$k+=2;$b++;
							if($fStudent['htype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
						   elseif($fStudent['htype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							 elseif($fStudent['htype']==""){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over_hostel="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{	foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther_hostel=$t - $other1;
						    $over_hostel=$overAllOther_hostel;
							$other2_hostel+=$over_hostel;
							
						}?>	<td><?php if($over_hostel=="0")echo "<lable style='color:red'>paid</label>";elseif($over_hostel=="") echo "<lable style='color:red'>X</label>"; else echo $over_hostel; ?></td>
				<?php }	
						}$total_full+=$other2_hostel; 
						$install=$db->getRows("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else 		
											$dues=$ins['fee']-$discount;
								}
										if($fine_t==$total_dues)
												$dues=0;
										else $dues=$fine_t-$total_dues-$discount;	
										
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; ?></td>	
			
                    <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $total_full; ?></td>		
				<?php $total_comp+=$total_full; }?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $m+10+$c+$b;?>">Gross Total</td>
					
				   <td><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
			}



/*
    elseif(isset($_REQUEST['month_report_without_hostel'])){
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;
        $wh="";
	    if(isset($_GET["class"]) && $_GET["class"]!=""){
		    $wh.=" AND class='".$_GET["class"]."'";
	    }

        if($_GET['section']!=""){
            $wh .= " section='".$_GET["section"]."' and ";
        }
		$aryStudentList=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $wh  $whereS and status=1 and issue_TC=0 order by class,name");
		//echo $db->getLastQuery(); 
		$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");
		$m=0;
		if(isset($_REQUEST['fmonth']) && $_REQUEST['fmonth']!=0){
			$month=$_GET["fmonth"];
			  if($month<4){
				$m=($month+9);
			  }
			  else{
				$m=$month-3;
			  }
		}
		else{
			$m=12;
		}
		 // echo $m;
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
			
			<input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
			
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentfinePopup()" value="Add Fine" style="float:left;" />
            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;"  id="tblData" data-tblname="Academic Standing">
				<thead>
				<tr>
                	<td class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></td>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
                     <?php
			   if(is_array($monthsList1) && count($monthsList1)>0){

					for($i=1;$i<=$m;$i++){?>
						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
					}
			   }
			  
			   $install=$db->getRows("select * from otherfee_structure where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
                    <th>Back Dues</th>
					<th>Other</th>
                    <th>Fine</th>
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;
		
		for($i=1; $i<=$m; $i++){
						$md[]=$i;
					}					
					//print_r($md);
					 $mdf= implode(',',$md);
					 $i=0;
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                    		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" />
                        	<td id="newid<?php echo $i ?>"><?php echo $i ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?></td>
                            <td><?php echo $fStudent["section"] ?></td>
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
						
				$m1=$m+1;				
			
	//echo $ss="select (i".$m."-COALESCE(ip".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)";
	$bus_last=$db->getVal("select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (bp".$m1." is null or bp".$m1."=0)");		
						
							foreach($monthsList1 as $key=>$val){$count++;
							if($mn==0){
								
							}
							else{ $mn--;
							$key1=$key+1;
							
									
						
						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");

						//$db->getLastQuery();
						if(is_array($installTution) && count($installTution)>0){	
							if($installTution["ip$key"]=="" || $installTution["ip$key"]=="0")
							{
								 $tution=$installTution["i$key"];
							}
							else
							{

           // echo $ss="select ip".$key1." from installment where  idno='".$fStudent["idno"]."'";
	      $tut_last_val=$db->getVal("select ip".$key1." from installment where  idno='".$fStudent["idno"]."'");

					
							
			  //tutions=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)");
						
						
				if($m==$key)
				{
				$tution=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from installment where  idno='".$fStudent["idno"]."' ");
	
				}
                else
                   {
	             $tution=0;	
                     }	
						
							
								
						}								
							
						}else{
							$tution="";
						}
						
						
						$overAlltution=$tution;
						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");

						if(is_array($installTution) && count($installTution)>0){
							if($installTution["bp$key"]=="" || $installTution["bp$key"]=="0")
							{
								$trasnport=$installTution["b$key"];
							}
							
							else
							{
								
           // echo $ss="select ip".$key1." from installment where  idno='".$fStudent["idno"]."'";
	      $tut_last_val=$db->getVal("select bp".$key1." from installment where  idno='".$fStudent["idno"]."'");

					
							
			  //tutions=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)");
						
						
				if($m==$key)
				{
				$trasnport=$db->getVal("select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' ");
				
				//echo $ss="select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)";
	
				}
                else
                   {
	             $trasnport=0;	
                     }	
						
								
							}
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;
						
						$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								///echo $db->getErMsg().$db->getLastQuery();
								//echo $Ftypeid."-";print_r($installTution);
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution["pay"]=="" || $installTution["pay"]=="0")
									{
										$sums=$installTution["fee"];
									}
									else
									{
										
									if($m==$key)
				{
					
									$ext_last=$db->getVal("select sum(pay) from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$key1."' ");
	
	if($ext_last==0)
									{	
									$sums=$db->getVal("select sum(fee-pay)  from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$key."'  ");
									
									//echo $ss="select sum(fee-pay)  from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$key."'  ";
									
									}
	
				}
                else
                   {
	             $sums=0;	
                     }		
										
										
									
									
									}
									
									
									
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}

						
						 $overAllNewextra=0;//print_r($extrasum);
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						//echo $ij.$overAllNewextra."-";
						}//$j++;
						
						  //if($i==23){echo $overAlltution."--".$overAllTransport."--".$overAllhotel."--".$overAllNewextra."!!!!";}
						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllNewextra;}
						//if($i==23)echo "(".$total.")";
						
					if($key=='12'){			
		$total23=$db->getVal("select (COALESCE(i12,0)+COALESCE(b12,0)-COALESCE(ip12,0)-COALESCE(bp12,0)) from installment where idno='".$fStudent["idno"]."'");
				
		//$total24=$db->getVal("select (COALESCE(i13,0)) from hostelinstallment where idno='".$fStudent["idno"]."'");
		
		$te=$db->getVal("SELECT sum(fee-pay) FROM `extrafee` WHERE idno='".$fStudent["idno"]."' and pid='p12' and session='".$_SESSION["admin"]["session"]."'  ");
		
		
		
		$total22=$total23+$total24+$te;
		$total_full+=$total22;?>
		
		<td><?php if( $total22=="0" )echo "<lable style='color:red'>paid</label>";elseif($total=="" AND $total22=="") echo "<lable style='color:red'>X</label>";  else echo $total22; ?></td>
		<?php	}
			else{ 
			$total_full=$total_full+$total;
			?><td><?php if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td> <?php }
					?>
										
					<?php }
					}
					
					$install=$db->getRows("select * from otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						//echo  $db->getLastQuery();
						if(is_array($install) && count($install)>0){
							$k=0;$c=0;$other2=0;
							foreach($install as $ins){$k+=2;$c++;
							if($fStudent['stype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
						   elseif($fStudent['stype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from otherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
								{
									foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
								}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
							
						}?>	<td><?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php }	
						}
					$total_full+=$other2;
						//echo $i."-".$t.$other1."<br/>";
					
					$install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					$discount= $db->getVal("SELECT discount from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
										
							$dues=0;
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'");        if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; ?></td>  
					<?php $install=$db->getRows("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else 		
									//$dues=$ins['fee']-$discount;
									$dues=$ins['fee'];
								}
										if($fine_t==$total_dues)
												$dues=0;
					//else $dues=$fine_t-$total_dues-$discount;	
					else $dues=$fine_t-$total_dues;	
										
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
							// discount
							 $install2=$db->getRow("SELECT otype,GROUP_CONCAT(id) as id FROM `otherfee_structure` where otype='".$fStudent['idno']."' and name like 'Latefine%'");
							//echo $install2[id];
							
							$dis3= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id in($install2[id])   and session='".$_SESSION["admin"]["session"]."' ");
						
					?>
					
					<td>
					<?php 					
					$to=$db->getVal("select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf) and session='".$_SESSION["admin"]["session"]."'");
				
			//echo	$ss="select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf) and session='".$_SESSION["admin"]["session"]."'";
				$to1=$db->getVal("SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");
				
				//echo $ss="SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))";
					
				$dis1=$db->getVal("SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))");
		//	echo	$ss="SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and name NOT like 'Latefine%' and month in ($mdf))";
										
					 echo $t2=$to-$to1-$dis1;
					
					?>
					</td>
					
					<td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else //echo $dues-$dis3; ?></td>
                    <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $total_full-$dis3+$t2; ?></td>		
				<?php $total_comp+=$total_full-$dis3+$t2; }?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $m+11+$c;?>">Gross Total</td>
					
				   <td id="MyTotalLeft"><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
		}
*/
	// academic ladger	
	elseif(isset($_REQUEST['Academic_Ledger'])){
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllFine=0;$overAllextra=array();$overAllNewextra=0;
		$wh="";
		   if(isset($_GET["class"]) && $_GET["class"]!="")
				$wh=" AND class='".$_GET["class"]."'";
		$aryStudentList=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $wh  $whereS and status=1 and issue_TC=0 order by class,name");
		//echo $db->getLastQuery(); 
		$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");
		$m=0;
		if(isset($_REQUEST['fmonth']) && $_REQUEST['fmonth']!=0){
			$month=$_GET["fmonth"];
			  if($month<4){
				$m=($month+9);
			  }
			  else{
				$m=$month-3;
			  }
		}
		else{
			$m=12;
		}
		 // echo $m;
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
			
			<input type="text" placeholder="Search Amount" id="searchfoertotal" onkeyup="filterPay(this)" />
			
            <input type="button" class="btn btn-danger hidet" onclick="getStudentPopup()" value="Migrate Left Fee" style="float:left;" />
            <input type="button" class="btn btn-danger hidet" onclick="getStudentfinePopup()" value="Add Fine" style="float:left;" />
            <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Complete Student Fee outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Academic Ledger">
				<thead>
				<tr>
                	<td class=""><input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" /></td>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    
					<td>Contact No</td>
					<td>Receipt.........>Date.........>Amount </td>
                     <?php
			   if(is_array($monthsList1) && count($monthsList1)>0){
				/*foreach($monthsList1 as $ftype){
					?><th width="0.5%"><?php echo $ftype ?></th><?php
				}*/
					for($i=1;$i<=$m;$i++){?>
						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
					}
			   }
			  
			   $install=$db->getRows("select * from otherfee_structure where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
                    <th>Back Dues</th>
					<th>Other</th>
                    <th>Fine</th>
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;
		
		for($i=1; $i<=$m; $i++){
						$md[]=$i;
					}					
					//print_r($md);
					 $mdf= implode(',',$md);
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                    		<td class=""><input class="checkboxes" type="checkbox" name="sid" value="<?php echo $fStudent["idno"];?>" id="cat<?php echo $fStudent["mobile"]; ?>" />
                        	<td><?php echo $i ?></td>
							<td class="name<?php echo $fStudent["idno"];?>"><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"].'-'.$fStudent["section"] ?></td>
                            
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
							
							<td style="width:20% !important">
							<?php
							$reff_idd=$db->getRows("SELECT id,udate, amount,Months FROM receipt WHERE idno ='".$fStudent["idno"]."'  and session='".$_SESSION["admin"]["session"]."'");
			
			foreach($reff_idd as $reff_idd1){
				$r=$reff_idd1[udate];
				echo $reff_idd1[id].'->'.date("d-m-Y", strtotime($r)).'->'.$reff_idd1[amount].'<br>';
				
			}
							
							?>
							
							</td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$count=0;
							foreach($monthsList1 as $key=>$val){$count++;
							if($mn==0){
								
							}
							else{ $mn--;
						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");
						//$db->getLastQuery();

						if(is_array($installTution) && count($installTution)>0){	
							if($installTution["ip$key"]=="" || $installTution["ip$key"]=="0")
								$tution=$installTution["i$key"];
							else
								$tution=0;	
							
						}else{
							$tution="";
						}
						$overAlltution=$tution;
						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");

						if(is_array($installTution) && count($installTution)>0){
							if($installTution["bp$key"]=="" || $installTution["bp$key"]=="0")
								$trasnport=$installTution["b$key"];
							else
								$trasnport=0;
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;
						/*$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$fStudent["idno"]."'");
						if(is_array($installTution) && count($installTution)>0){
							if($installTution[1]=="" || $installTution[1]=="0")
								$hostel=$installTution[0];
							else
								$hostel=0;	
						}else{
							$hostel="";
						}
						$overAllhotel=$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");

								///echo $db->getErMsg().$db->getLastQuery();
								//echo $Ftypeid."-";print_r($installTution);
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution["pay"]=="" || $installTution["pay"]=="0")
										$sums=$installTution["fee"];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total_extra+=$sums;
								$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}

						
						 $overAllNewextra=0;//print_r($extrasum);
						for($ij=0; $ij<count($aryFeeType); $ij++){
						 $overAllNewextra+=$extrasum[$ij];
						//echo $ij.$overAllNewextra."-";
						}//$j++;
						/*$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->getRow("select fee,pay from extrafee where type='".$Ftypeid."' and pid= 'p".$key."' and idno='".$fStudent["idno"]."'");
								//echo $db->getErMsg().$db->getLastQuery();
								$no=array();
								if(is_array($installTution) && count($installTution)>0){
									if($installTution[1]=="" || $installTution[1]=="0")
										$sums=$installTution[0];
									else
										$sums=0;
									
								}else{
									$sums="";
								}
								$extrasum[]=$sums;
								$total+=$sums;$tp=$ftype["type"];
								$overAllextra[$tp]+=$sums;
							}
						}*/
						  //if($i==23){echo $overAlltution."--".$overAllTransport."--".$overAllhotel."--".$overAllNewextra."!!!!";}
						  $total=0;
						if($overAlltution=="0"&&$overAllTransport==0&&$overAllNewextra==0)
						 {$total==0;}
						elseif($overAlltution==""&&$overAllTransport==""&&$overAllNewextra=="")
						{$total="";}
						 else{ $total=$overAlltution+$overAllTransport+$overAllNewextra;}
						//if($i==23)echo "(".$total.")";
						
					if($key=='12'){			
		$total23=$db->getVal("select (COALESCE(i12,0)+COALESCE(b12,0)-COALESCE(ip12,0)-COALESCE(bp12,0)) from installment where idno='".$fStudent["idno"]."'");
				
		//$total24=$db->getVal("select (COALESCE(i13,0)) from hostelinstallment where idno='".$fStudent["idno"]."'");
		
		$te=$db->getVal("SELECT sum(fee-pay) FROM `extrafee` WHERE idno='".$fStudent["idno"]."' and pid='p12' ");
		
		
		
		$total22=$total23+$total24+$te;
		$total_full+=$total22;?>
		
		<td><?php if( $total22=="0" )echo "<lable style='color:red'>paid</label>";elseif($total=="" AND $total22=="") echo "<lable style='color:red'>X</label>";  else echo $total22; ?></td>
		<?php	}
			else{ 
			$total_full=$total_full+$total;
			?><td><?php if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td> <?php }
					?>
										
					<?php }
					}
					
					$install=$db->getRows("select * from otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						//echo  $db->getLastQuery();
						if(is_array($install) && count($install)>0){
							$k=0;$c=0;$other2=0;
							foreach($install as $ins){$k+=2;$c++;
							if($fStudent['stype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
						   elseif($fStudent['stype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	$installTution2=$db->getRow("select * from otherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							$t=$ins['fee'];
							 if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
								{
									foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
								}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
							
						}?>	<td><?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php }	
						}
					$total_full+=$other2;
						//echo $i."-".$t.$other1."<br/>";
					
					$install=$db->getRow("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
					
					$discount= $db->getVal("SELECT discount from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id='$install[id]'   and session='".$_SESSION["admin"]["session"]."' ");
										
							$dues=0;
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$install['name']."'");        if(is_array($installTution) && count($installTution)>0){
									$total_dues=0;
									foreach($installTution as $ins){
										$total_dues+=$ins['fine'];
									}
									if($install['fee']==$total_dues)
										$dues=0;
									else $dues=$install['fee']-$total_dues-$discount;	
									
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
											$dues=$dues-$installTution_remain;
								}
							  else 		
									$dues=$install['fee']-$discount;
							}
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
							
					?><td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues; ?></td>  
					<?php $install=$db->getRows("select * from otherfee_structure where otype ='".$fStudent['idno']."' and name like 'Latefine%' and month <= '".$m."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							$dues=0;$total_dues=0;$fine_t=0;
							if(is_array($install) && count($install)>0){
								foreach($install as $ins){
									$fine_t+=$ins["fee"];
								$installTution=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'");  
								      if(is_array($installTution) && count($installTution)>0){
											foreach($installTution as $ins){
												$total_dues+=$ins['fine'];
											}
									   }
									  else 		
									//$dues=$ins['fee']-$discount;
									$dues=$ins['fee'];
								}
										if($fine_t==$total_dues)
												$dues=0;
					//else $dues=$fine_t-$total_dues-$discount;	
					else $dues=$fine_t-$total_dues;	
										
						    }
							else
								$dues="";
							$alldues+=$dues;
							
							$total_full+=$dues;
							// discount
							 $install2=$db->getRow("SELECT otype,GROUP_CONCAT(id) as id FROM `otherfee_structure` where otype='".$fStudent['idno']."' and name like 'Latefine%'");
							//echo $install2[id];
							
							$dis3= $db->getVal("SELECT sum(discount) from otherfee_discount  WHERE  idno='$fStudent[idno]' and other_id in($install2[id])   and session='".$_SESSION["admin"]["session"]."' ");
						
					?>
					
					<td>
					<?php 					
					$to=$db->getVal("select sum(fee) from otherfee_structure where otype='".$fStudent['idno']."' and name!='Back_Dues' and month in ($mdf) and session='".$_SESSION["admin"]["session"]."'");
				
					$to1=$db->getVal("SELECT sum(amount) FROM reff_receipt WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and type in (SELECT name FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and month in ($mdf))");
					
					$dis1=$db->getVal("SELECT sum(discount) FROM otherfee_discount WHERE idno='".$fStudent['idno']."' and session='".$_SESSION["admin"]["session"]."' and other_id in (SELECT id FROM otherfee_structure WHERE otype='".$fStudent['idno']."' and name!='Back_Dues' and month in ($mdf))");
										
					 echo $t2=$to-$to1-$dis1;
					
					?>
					</td>
					
					<td><?php if($dues=="0")echo "<lable style='color:green'>paid</label>";elseif($dues=="") echo "<lable style='color:red'>X</label>"; else echo $dues-$dis3; ?></td>
                    <td class="MyTotalLeft left<?php echo $fStudent['idno'] ?>"><?php echo $total_full; ?></td>		
				<?php $total_comp+=$total_full; }?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $m+11+$c;?>">Gross Total</td>
					
				   <td id="MyTotalLeft"><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
		}
		
	elseif(isset($_REQUEST['school_outstanding'])){
			$overAllTotal=0;$overAlltution=0;
		$aryStudentList=$db->getRows("select * from student where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 order by class,name");
		
		$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");
		
		$month=$_GET["fmonth"];$m=0;
		  if($month<4){
			$m=($month+9);
		  }
		  else{
			$m=$month-3;
		  }
		  //echo $m;
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
          <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List" style="float:left;" />
          <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Tution Fee outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" id="tblData" data-tblname="School Outstanding">
				<thead>
				<tr>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
                     <?php
			   if(is_array($monthsList1) && count($monthsList1)>0){
				/*foreach($monthsList1 as $ftype){
					?><th width="0.5%"><?php echo $ftype ?></th><?php
				}*/
				
				for($i=1;$i<=$m;$i++){?>
						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
					}
			   }
			  
			  ?>
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;
					foreach($aryStudentList as $fStudent){$i++;
					?>
                    <tr>
                        	<td><?php echo $i ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?></td>
                            <td><?php echo $fStudent["section"] ?></td>
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$c=0;
							for($i=1;$i<=$m;$i++){$c++;
							$key=$i;
							
						$installTution=$db->getRow("select i".$key.",ip".$key." from installment where idno='".$fStudent["idno"]."'");

						//echo $db->getErMsg().$db->getLastQuery();
						if(is_array($installTution) && count($installTution)>0){
														
							if($installTution["ip$key"]=="" || $installTution["ip$key"]=="0")
								$tution=$installTution["i$key"];
							else
								$tution=0;	
							
						}else{
							$tution="";
						}
						$overAlltution=$tution;
						
						if($overAlltution=="0")
						 $total==0;
						elseif($overAlltution=="")
						{$total="";}
						else $total=$overAlltution;;
						$total_full=$total_full+$total;
					?><td><?php if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td>
					<?php }
							
					?><td class="MyTotalLeft"><?php echo $total_full; ?></td>
                    		
				    <?php $total_comp+=$total_full; }?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $c+7; ?>">Gross Total</td>
					
				   <td><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
		}
		
	elseif(isset($_REQUEST['bus_outstanding'])){
			$overAllTotal=0;$overAllTransport=0;
		$aryStudentList=$db->getRows("select * from student where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and bus_status=0 and issue_TC=0 and bus != '' order by class,name");
		
		$month=$_GET["fmonth"];$m=0;
		  if($month<4){
			$m=($month+9);
		  }
		  else{
			$m=$month-3;
		  }
		  //echo $m;
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
          <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List" style="float:left;" />
          <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Transport Fee outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" id="tblData" data-tblname="Bus Outstanding">
				<thead>
				<tr>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
                     <?php
			   if(is_array($monthsList) && count($monthsList)>0){
				for($i=1;$i<=$m;$i++){
					?><th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
				}
			   }
			  
			  ?>
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                        	<td><?php echo $i ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?></td>
                            <td><?php echo $fStudent["section"] ?></td>
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
                      <?php     
						$tution=0;$trasnport=0;$hostel=0;$otherExtra=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$c=0;
							foreach($monthsList1 as $key=>$val){$c++;
							if($mn==0){
								
							}
							else{ $mn--;
							
						$installTution=$db->getRow("select b".$key.",bp".$key." from installment where idno='".$fStudent["idno"]."'");
				// 		print_r($installTution); 
						if(is_array($installTution) && count($installTution)>0){
							if($installTution["bp$key"]=="" || $installTution["bp$key"]=="0")
								$trasnport=$installTution["b$key"];
							else
								$trasnport=0;
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;
						
						if($overAllTransport=="0")
						 $total==0;
						elseif($overAllTransport=="")
						{$total="";}
						else $total=$overAllTransport;;
						$total_full=$total_full+$total;
							?><td><?php if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td>		<?php }}
					
						//echo $i."-".$t.$other1."<br/>";
					
						
					?><td class="MyTotalLeft"><?php echo $total_full; ?></td>
                    		
				    <?php $total_comp+=$total_full; }?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $c+7; ?>">Gross Total</td>
					
				   <td><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
         <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	   
<?php }
		}
/*
	elseif(isset($_REQUEST['hostel_outstanding'])){
			$overAllTotal=0;$overAllhotel=0;
		//$aryStudentList=$db->getRows("select * from student where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and hostel != '' order by class,name");
		if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="")
			$whereS1=" AND s.section='".$_REQUEST["section"]."' ";
			
		$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";
		$aryStudentList=$db->getRows("SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and s.class='".$_GET["class"]."' and ".$where." $whereS1 order by s.name");
		if(isset($_REQUEST['fmonth']) && $_REQUEST['fmonth']!=0){
			$month=$_GET["fmonth"];$m=0;
			  if($month<4){
				$m=($month+9);
			  }
			  else{
				$m=$month-3;
			  }
		}
		else{
			$m=12;
		}
		  //echo $m;
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
          <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List" style="float:left;" />
          <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Hostel Fee outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:10px;"  id="tblData" data-tblname="Hostel Outstanding">
				<thead>
				<tr>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
                     <?php
			   if(is_array($monthsList1) && count($monthsList1)>0){
					for($i=1;$i<=$m;$i++){?>
						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
					}
			   }
			  $install=$db->getRows("select * from hostel_otherfee_structure where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;$mn=0;
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;?>
                    <tr>
                        	<td  id="newid<?php echo $i ?>"><?php echo $i ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?></td>
                            <td><?php echo $fStudent["section"] ?></td>
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
                      <?php     
						$hostel=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$c=0;
							foreach($monthsList1 as $key=>$val){
							if($mn==0){
							}
							else{$mn--;$c++;
							$m1=$m+1;
							$key1=$key+1;
						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$fStudent["idno"]."'");
						
						if(is_array($installTution) && count($installTution)>0){
							if($installTution["ip$key"]=="" || $installTution["ip$key"]=="0")
							{
								$hostel=$installTution["i$key"];
							}
							else
							{
								
													
						
				if($m==$key)
				{
				$hostel=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from hostelinstallment where  idno='".$fStudent["idno"]."' ");
	
				}
                else
                   {
	        $hostel=0;
                     }		
								
								
							}								
						}else{
							$hostel="";
						}
						$overAllhotel=$hostel;
						
						if($overAllhotel=="0")
						 $total==0;
						elseif($overAllhotel=="")
						{$total="";}
						else $total=$overAllhotel;;
						//$total_full=$total_full+$total;
						
						
					if($key=='12'){			
		//$total23=$db->getVal("select (COALESCE(i13,0)+COALESCE(b13,0)) from installment where idno='".$fStudent["idno"]."'");
		
		$total24=$db->getVal("select (COALESCE(i12,0)-COALESCE(ip12,0)) from hostelinstallment where idno='".$fStudent["idno"]."'");
		
		//$te=$db->getVal("SELECT sum(fee-pay) FROM `extrafee` WHERE idno='".$fStudent["idno"]."' and pid='p12' and pay!='0'");
		
		$total22=$total23+$total24+$te;
		$total_full+=$total22;
		
			?>
			<td><?php if( $total22=="0" )echo "<lable style='color:red'>paid</label>";elseif($total=="" AND $total22=="") echo "<lable style='color:red'>X</label>";  else echo $total22; ?></td>
		<?php	}
			else{ 
			$total_full=$total_full+$total;
			?><td><?php if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td> <?php }
					?>
					<?php }}
					$install=$db->getRows("select * from hostel_otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype ='new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						
						if(is_array($install) && count($install)>0){
							
							$k=0;$b=0;$other2=0;
							
							foreach($install as $ins){$k+=2;$b++;
							
							if($fStudent['htype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
						   elseif($fStudent['htype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							 elseif($fStudent['htype']==""){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{   //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	
							
							$installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							
							$t=$ins['fee'];
							
							if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
							
						}?>	<td><?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php }	
						}
					$total_full+=$other2;
					
						
					?><td class="MyTotalLeft"><?php echo $total_full; ?></td>
                    		
				    <?php $total_comp+=$total_full; }?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $c+$b+7; ?>">Gross Total</td>
					
				   <td><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
		}
*/


    elseif(isset($_REQUEST['Hostel_Ledger'])){
			$overAllTotal=0;$overAllhotel=0;
		//$aryStudentList=$db->getRows("select * from student where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and hostel != '' order by class,name");
		if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="")
			$whereS1=" AND s.section='".$_REQUEST["section"]."' ";
			
		$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";
		$aryStudentList=$db->getRows("SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and s.class='".$_GET["class"]."' and ".$where." $whereS1 order by s.name");
		if(isset($_REQUEST['fmonth']) && $_REQUEST['fmonth']!=0){
			$month=$_GET["fmonth"];$m=0;
			  if($month<4){
				$m=($month+9);
			  }
			  else{
				$m=$month-3;
			  }
		}
		else{
			$m=12;
		}
		  //echo $m;
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
          <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List" style="float:left;" />
          <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>Hostel Fee outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:10px;" id="tblData" data-tblname="Hostel Ledger">
				<thead>
				<tr>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                  
					<td>Contact No</td>
					<td>Receipt.........>Date.........>Amount </td>
                     <?php
			   if(is_array($monthsList1) && count($monthsList1)>0){
					for($i=1;$i<=$m;$i++){ ?>
						<th width="0.5%"><?php echo $monthsList1[$i]; ?></th><?php
					}
			   }
			  $install=$db->getRows("select * from hostel_otherfee_structure where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype = 'new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;$mn=0;
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;?>
                    <tr>
                        	<td><?php echo $i ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"].'-'.$fStudent["section"] ?></td>
                            
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
							
							<td style="width:20% !important">
							<?php
							$reff_idd=$db->getRows("SELECT id,udate, amount,Months FROM hostel_receipt WHERE idno ='".$fStudent["idno"]."'  and session='".$_SESSION["admin"]["session"]."'");
			
			foreach($reff_idd as $reff_idd1){
				$r=$reff_idd1[udate];
				echo $reff_idd1[id].'->'.date("d-m-Y", strtotime($r)).'->'.$reff_idd1[amount].'<br>';
				
			}?>		
		    </td>
                      <?php     
						$hostel=0;$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$k=0;$total_extra=0;$c=0;
							foreach($monthsList1 as $key=>$val){
							if($mn==0){
							}
							else{$mn--;$c++;
						$installTution=$db->getRow("select i".$key.",ip".$key." from hostelinstallment where idno='".$fStudent["idno"]."'");

						if(is_array($installTution) && count($installTution)>0){
							if($installTution["ip$key"]=="" || $installTution["ip$key"]=="0")
								$hostel=$installTution["i$key"];
							else
								$hostel=0;	
						}else{
							$hostel="";
						}
						$overAllhotel=$hostel;
						
						if($overAllhotel=="0")
						 $total==0;
						elseif($overAllhotel=="")
						{$total="";}
						else $total=$overAllhotel;;
						//$total_full=$total_full+$total;
						
						
					if($key=='12'){			
		//$total23=$db->getVal("select (COALESCE(i13,0)+COALESCE(b13,0)) from installment where idno='".$fStudent["idno"]."'");
		
		$total24=$db->getVal("select (COALESCE(i12,0)-COALESCE(ip12,0)) from hostelinstallment where idno='".$fStudent["idno"]."'");
		
		//$te=$db->getVal("SELECT sum(fee-pay) FROM `extrafee` WHERE idno='".$fStudent["idno"]."' and pid='p12' and pay!='0'");
		
		$total22=$total23+$total24+$te;
		$total_full+=$total22;
		
			?>
			<td><?php if( $total22=="0" )echo "<lable style='color:red'>paid</label>";elseif($total=="" AND $total22=="") echo "<lable style='color:red'>X</label>";  else echo $total22; ?></td>
		<?php	}
			else{ 
			$total_full=$total_full+$total;
			?><td><?php if($total=="0")echo "<lable style='color:red'>paid</label>";elseif($total=="") echo "<lable style='color:red'>X</label>"; else echo $total; ?></td> <?php }
					?>
					<?php }}
					$install=$db->getRows("select * from hostel_otherfee_structure where class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and (otype =  '' or otype = 'old' or otype ='new') and month <= '".$m."' and session='".$_SESSION["admin"]["session"]."'");					
						
						if(is_array($install) && count($install)>0){
							
							$k=0;$b=0;$other2=0;
							
							foreach($install as $ins){$k+=2;$b++;
							
							if($fStudent['htype']=="old" && $ins['otype']=="new"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
						   elseif($fStudent['htype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							 elseif($fStudent['htype']==""){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{   //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); 
							$installTution1=$db->getRows("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");	
							
							$installTution2=$db->getRow("select * from hostelotherfee_discount where idno=".$fStudent['idno']." and other_id='".$ins['id']."' and class='".$fStudent["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
							//echo $db->getLastQuery();
							//echo $installTution2['discount']."--";
							$t=0;$other1=0;$other_left=0;$dis=0;
							
							$t=$ins['fee'];
							
							if(is_array($installTution2) && count($installTution2)>0){
									 $dis=$installTution2['discount'];
											if($t==$dis)
												$t=0;
											else 
												$t=$t-$dis;
							 }
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{foreach ($installTution1 as $instt) 
											$other_left+=$instt['fine'];
									}
									 $other=$installTution['fine'];
																		
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
														
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
							
						}?>	<td><?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php }	
						}
					$total_full+=$other2;
					
						
					?><td class="MyTotalLeft"><?php echo $total_full; ?></td>
                    		
				    <?php $total_comp+=$total_full; }?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $c+$b+7; ?>">Gross Total</td>
					
				   <td><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
		}		
	
	elseif(isset($_REQUEST['pocket'])){
			$overAllTotal=0;$overAllTransport=0;
		if(isset($_REQUEST["section"]) && $_REQUEST["section"]!="")
			$whereS1=" AND s.section='".$_REQUEST["section"]."' ";
			
		$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";
		$aryStudentList=$db->getRows("SELECT s.* FROM ".$table." where s.school_id='".$_SESSION["admin"]["school_id"]."' and s.issue_TC=0 and s.class='".$_GET["class"]."' and ".$where." $whereS1 order by s.name");
		
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
          <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List" style="float:left;" />
          <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>
          Pocket outstanding</p>	</h5></center>

			<a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=DueSheet&fmonth=$_GET[fmonth]&class=$_GET[class]&pocket=&section=$_GET[section]&bus=$_GET[bus]&location=$_GET[location]&head_name=$_GET[head_name]"; ?>" target="_blank" >Full Screen</a>
            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>

			<table class="table" cellpadding="0" cellspacing="0" border="1" id="tblData" data-tblname="Pocket Outstanding">
				<thead>
				<tr>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
                    <td>All Income</td>
                    <td>All Expense</td>
               <td>Total Balance</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;$total_income=$total_expance=0;
					foreach($aryStudentList as $fStudent){$i++;
					?>
                    <tr>
                        	<td><?php echo $i ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?></td>
                            <td><?php echo $fStudent["section"] ?></td>
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
                      <?php     
						$total=0;$fine=0;$total_full=0;

						$income=$db->getVal("select sum(amount) from transaction where rid='".$fStudent["idno"]."' and type='deposit' and tfor='hostel-income' and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."'");

					?><td><?php echo $income; $total_income+=$income; ?></td>	<?php 

						$expance=$db->getVal("select sum(amount) from transaction where rid='".$fStudent["idno"]."' and type='withdraw' and tfor='hostel-expance' and session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."'");

					?><td><?php echo $expance; $total_expance+=$expance;?></td>	 <?php 

						$total_full=$income-$expance;

					?><td class="MyTotalLeft"><?php echo $total_full; ?></td>

				    <?php $total_comp+=$total_full; }?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo 7; ?>">Gross Total</td>
					<td><?php echo $total_income; ?></td>
                    <td><?php echo $total_expance; ?></td>
				   <td><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
       <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
		}
	
	elseif(isset($_REQUEST['student_due'])){
			
		  $install=$db->getRows("select distinct(otype) from otherfee_structure where class='".$_REQUEST["class"]."' and otype != 'new' and otype != '' and otype != 'old' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
		  //echo $db->getLastQuery();
		  if(is_array($install) && count($install)>0){
			  
		?>
          <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List" style="float:left;" />
          <h5><p style="float:right">Class: <?php echo $_GET['class']; ?></p> <p>Back-Dues outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" id="tblData" data-tblname="Student Wise">
				<thead>
				<tr>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
                     <?php
			  	  
			   /*$install1=$db->getRows("select distinct(name) from otherfee_structure where class='".$_REQUEST["class"]."' and otype != 'new' and otype != '' and otype != 'old' ");
					//echo $db->getLastQuery();
					$j=0;
						foreach($install1 as $ins){$j++;
						
					?><th><?php echo $in= $ins['name'] ?></th><?php 		
								
					}*/?>
               <td colspan="5" style="text-align:center;">Summary</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;$c1=0;
					foreach($install as $ins1){
		$fStudent=$db->getRow("select * from student where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 and idno =".$ins1['otype']." order by class,name");
		  				$i++;
						//echo $db->getLastQuery();
					?>
                    <tr>
                        	<td><?php echo $i ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?></td>
                            <td><?php echo $fStudent["section"] ?></td>
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
                      <?php     
						$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$total_extra=0;
							$count=0;
					$install2=$db->getRows("select * from otherfee_structure where class='".$fStudent["class"]."' and otype = '".$fStudent['idno']."'");			
					// $install2=$db->getRows("select * from otherfee_structure where class='".$_REQUEST["class"]."' and otype != 'new' and otype != '' and otype != 'old' and otype = '".$fStudent['idno']."' ");
					///echo $db->getLastQuery();	
						if(is_array($install2) && count($install2)>0){
						foreach($install2 as $inst){ $count++;
							//if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$inst['name']."'"); //echo $db->getLastQuery();
							///print_r($installTution);
							$installTution1=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$inst['name']."' and id !=".$installTution['id']."");
							//echo $db->getLastQuery();
							$t=0;$other1=0;$other2=0;$other_left=0;
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{$other_left=$installTution1['fine'];}
									 $other=$installTution['fine'];
									 //if($i==12)echo $other;
									if($other_left!=0 && $other!=$inst['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
									
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
							$t=$inst['fee'];
							
							$overAllOther=$t - $other1;
							$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
									  	$overAllOther=$overAllOther-$installTution_remain;
						    $over=$overAllOther;
							$other2+=$over;
						?> <td style="border:2px inset #600;"><?php echo $inst['name'] ?></td>
                        	<td style="border:2px inset #600;"><?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php $total_full+=$other2; }	
						} 
						$c=$count+8;
					//echo $i."-".$t.$other1."<br/>";
						$c1+=$count;
					?><td class="MyTotalLeft" style="text-align:right" colspan="<?php echo $c; ?>"><?php echo $total_full; ?></td>
                    		
				    <?php $total_comp+=$total_full;
					 } ?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $c ?>">Gross Total</td>
					
				   <td><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
		}		
		
	elseif(isset($_REQUEST['student_due'])){
			
		  $install=$db->getRows("select distinct(otype) from otherfee_structure where class='".$_REQUEST["class"]."' and otype != 'new' and otype != '' and otype != 'old' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
		  //echo $db->getLastQuery();
		  if(is_array($install) && count($install)>0){
			  
		?>
          <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List" style="float:left;" />
          <h5><p style="float:right">Class: <?php echo $_GET['class']; ?></p> <p>Back-Dues outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1">
				<thead>
				<tr>
                	<td>S.No</td>
					<td>Student Name</td>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<td>Class</td>
                    <td>Section</td>
					<td>Contact No</td>
                     <?php
			  	  
			   /*$install1=$db->getRows("select distinct(name) from otherfee_structure where class='".$_REQUEST["class"]."' and otype != 'new' and otype != '' and otype != 'old' ");
					//echo $db->getLastQuery();
					$j=0;
						foreach($install1 as $ins){$j++;
						
					?><th><?php echo $in= $ins['name'] ?></th><?php 		
								
					}*/?>
               <td colspan="5" style="text-align:center;">Summary</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;$c1=0;
					foreach($install as $ins1){
		$fStudent=$db->getRow("select * from student where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 and idno =".$ins1['otype']." order by class,name");
		  				$i++;
						//echo $db->getLastQuery();
					?>
                    <tr>
                        	<td><?php echo $i ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?></td>
                            <td><?php echo $fStudent["section"] ?></td>
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
                      <?php     
						$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$total_extra=0;
							$count=0;
					$install2=$db->getRows("select * from otherfee_structure where class='".$fStudent["class"]."' and otype = '".$fStudent['idno']."'");			
					// $install2=$db->getRows("select * from otherfee_structure where class='".$_REQUEST["class"]."' and otype != 'new' and otype != '' and otype != 'old' and otype = '".$fStudent['idno']."' ");
					///echo $db->getLastQuery();	
						if(is_array($install2) && count($install2)>0){
						foreach($install2 as $inst){ $count++;
							//if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$inst['name']."'"); //echo $db->getLastQuery();
							///print_r($installTution);
							$installTution1=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$inst['name']."' and id !=".$installTution['id']."");
							//echo $db->getLastQuery();
							$t=0;$other1=0;$other2=0;$other_left=0;
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{$other_left=$installTution1['fine'];}
									 $other=$installTution['fine'];
									 //if($i==12)echo $other;
									if($other_left!=0 && $other!=$inst['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
									
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
							$t=$inst['fee'];
							
							$overAllOther=$t - $other1;
							$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$fStudent['idno']." and reasion like 'remain%' ");
									  	$overAllOther=$overAllOther-$installTution_remain;
						    $over=$overAllOther;
							$other2+=$over;
						?> <td style="border:2px inset #600;"><?php echo $inst['name'] ?></td>
                        	<td style="border:2px inset #600;"><?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php $total_full+=$other2; }	
						} 
						$c=$count+8;
					//echo $i."-".$t.$other1."<br/>";
						$c1+=$count;
					?><td class="MyTotalLeft" style="text-align:right" colspan="<?php echo $c; ?>"><?php echo $total_full; ?></td>
                    		
				    <?php $total_comp+=$total_full;
					 } ?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $c ?>">Gross Total</td>
					
				   <td><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }
		}	
		
	elseif(isset($_REQUEST['new_due'])){
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllFine=0;$overAllextra=array();					$overAllNewextra=0;
		$aryStudentList=$db->getRows("select * from student where class='".$_GET["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 and stype  ='new' order by class,name");
		
		if(is_array($aryStudentList) && count($aryStudentList)>0){
			?>
          <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List" style="float:left;" />
          <h5><p style="float:right">Class: <?php echo $_GET['class']."(".$_SESSION["admin"]["session"].")"; ?></p> <p>New Student Fee outstanding</p>	</h5></center>
			<table class="table" cellpadding="0" cellspacing="0" border="1" id="tblData" data-tblname="New Student">
				<thead>
				<tr>
                	<th>S.No</th>
					<th>Student Name</th>
                    <th>Father Name</th>
                    <th>Reg. no</th>
					<th>Class</th>
                    <th>section</th>
					<th>Contact No</th>
                     <?php
			  	  
			   $install=$db->getRows("select * from otherfee_structure where class='".$_REQUEST["class"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and otype = 'new'");
					//echo $db->getLastQuery();
						foreach($install as $ins){
					?><th><?php echo $ins['name'] ?></th><?php		
								
					}?>
               <td>Total</td>
			</tr>
			</thead>
			<tbody>
		<?php	$i=0;$total_comp=0;
					foreach($aryStudentList as $fStudent){$i++;
					?>
                    <tr>
                        	<td><?php echo $i ?></td>
							<td><?php echo $fStudent["name"] ?></td>
                            <td><?php echo $fStudent["fname"] ?></td>
                            <td><?php echo $fStudent["admissionno"] ?></td>
							<td><?php echo $fStudent["class"] ?></td>
                            <td><?php echo $fStudent["section"] ?></td>
							<td><?php echo $fStudent["mobile"]//$newDate="2015-".$month."-1"; echo   date("F",strtotime($newDate)); ?></td>
                      <?php     
						$total=0;$fine=0;$total_full=0;
						$j=0;$other=0;$total_extra=0;$count=0;
							
					$install=$db->getRows("select * from otherfee_structure where class='".$fStudent["class"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and  otype = 'new'");					
						if(is_array($install) && count($install)>0){
						foreach($install as $ins){ $count++;
							if($fStudent['stype']=="new" && $ins['otype']=="old"){
								//echo $i.$ins['otype']."-".$fStudent['stype'];
								$over="";
							}
							else{ //if($i==12)echo $db->getLastQuery();
							$installTution=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."'"); ///echo $db->getLastQuery();
							///print_r($installTution);
							$installTution1=$db->getRow("select * from installment_fine where idno=".$fStudent['idno']." and reasion = '".$ins['name']."' and id !=".$installTution['id']."");
							//echo $db->getLastQuery();
							$t=0;$other1=0;$other2=0;$other_left=0;
							if(is_array($installTution) && count($installTution)>0){
								if($installTution['fine']!=""){
								if(is_array($installTution1) && count($installTution1)>0)
									{$other_left=$installTution1['fine'];}
									 $other=$installTution['fine'];
									 //if($i==12)echo $other;
									if($other_left!=0 && $other!=$ins['fee'] && $installTution['id']!=$installTution1['id'])
									{$other+=$other_left;}
								}
								else
									$other=0;	
							}else{
								$other="";
							}
							$other1=$other;
							$t=$ins['fee'];
							
							$overAllOther=$t - $other1;
						    $over=$overAllOther;
							$other2+=$over;
						}?>	<td><?php if($over=="0")echo "<lable style='color:red'>paid</label>";elseif($over=="") echo "<lable style='color:red'>X</label>"; else echo $over; ?></td>
				<?php $total_full+=$other2; }	
						}
					
						//echo $i."-".$t.$other1."<br/>";
						
					?><td class="MyTotalLeft"><?php echo $total_full; ?></td>
                    		
				    <?php $total_comp+=$total_full;
					 } $c=$count+7;?>
			</tbody>
				<tfoot>
					<td colspan="<?php echo $c ?>">Gross Total</td>
					
				   <td><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
     <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	       
<?php }
		}	
}
    elseif(isset($_REQUEST['student_list'])){
    			
    		$aryClass=$db->getRows("select * from class where school_id='".$_SESSION["admin"]["school_id"]."' and status=1");
    		
    		if(is_array($aryClass) && count($aryClass)>0){
    			?>
              <center><h5><p>Class Wise Total Student List</p>	</h5></center>
    
    			<a class="btn btn-primary" id="myPrntbtn" href="<?php echo URL_ROOT."print/?page_id=DueSheet&fmonth=$_GET[fmonth]&class=$_GET[class]&student_list=&section=$_GET[section]&bus=$_GET[bus]&location=$_GET[location]&head_name=$_GET[head_name]"; ?>" target="_blank" >Full Screen</a>
                <style>
                    @media print {
                
                        #myPrntbtn {
                            display :  none;
                        }
                
                    }
                </style>
    
    			<table class="table" cellpadding="0" cellspacing="0" border="1" id="tblData" data-tblname="Student List">
    				<thead>
    				<tr>
                    	<td>S.No</td>
    					<td>Class</td>
                        <th>No of Male</th>
                        <th>No of Female</th>
    					<td>Total Student</td>
    					<td>Cancelled Student</td>
                        
    			</tr>
    			</thead>
    			<tbody>
    		<?php	$i=0;$total_male=$total_female=$total_student=$total_cancel=0;$total=0;
    					foreach($aryClass as $fclass){$i++;
    					$male=$db->getVal("select Count(*) from student where class='".$fclass["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and gender = 'male'");
    					$female=$db->getVal("select Count(*) from student where class='".$fclass["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and gender = 'female'");
    					$totStudent=$db->getVal("select Count(*) from student where class='".$fclass["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 ");
    					$cancelStudent=$db->getVal("select Count(*) from student where class='".$fclass["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=3 and issue_TC=0 ");
    					?>
                        <tr>
                            	<td><?php echo $i ?></td>
    							<td><?php echo $fclass["class"] ?></td>
                                <td><?php echo $male ?></td>
                                <td><?php echo $female ?></td>
    							<td><?php echo $totStudent ?></td>
    							<td><?php echo $cancelStudent ?></td>
                          <?php     
    						$total_male+=$male;	$total_female+=$female;	$total_student+=$totStudent; $total_cancel+=$cancelStudent;
    					    					 
    					 } ?>
    			</tbody>
    				<tfoot><td></td><td></td>
    					<td>total = <?php echo $total_male ?></td>
    					<td>total = <?php echo $total_female ?></td>
    				    <td>total = <?php echo $total_student ?></td>
                        <td>total = <?php echo $total_cancel ?></td>
    				</tfoot>
    			</table>  Print date : <?php echo date("d-M-Y") ?>
    <?php }
    }	
    elseif(isset($_REQUEST['short_list'])){
    			
    		$aryClass=$db->getRows("select distinct(mincome) from student where school_id='".$_SESSION["admin"]["school_id"]."' and status=1");
    		
    		if(is_array($aryClass) && count($aryClass)>0){
    			?>
              <center><h5><p>Address Wise Total Student List</p>	</h5></center>
    			<table class="table" cellpadding="0" cellspacing="0" border="1" id="tblData" data-tblname="Short List">
    				<thead>
    				<tr>
                    	<td>S.No</td>
    					<td>Short</td>
                        <th>No of Male</th>
                        <th>No of Female</th>
                        <th>Total Student</th>
                        <th>Male Transport</th>
    					<th>Female Transport</th>
                        <th>Total Transport</th>
    			</tr>
    			</thead>
    			<tbody>
    		<?php	$i=0;$total_male=$total_female=$total_student=$total_male_bus=$total_female_bus=$total_student_bus=$total_cancel=0;$total=0;
    					foreach($aryClass as $fclass){$i++;
    					$male=$db->getVal("select Count(*) from student where mincome='".$fclass["mincome"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and gender = 'male'");
    					$female=$db->getVal("select Count(*) from student where mincome='".$fclass["mincome"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and gender = 'female'");
    					$totStudent=$db->getVal("select Count(*) from student where mincome='".$fclass["mincome"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 ");
    					$male_bus=$db->getVal("select Count(*) from student where mincome='".$fclass["mincome"]."' and bus !='' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and gender = 'male'");
    					$female_bus=$db->getVal("select Count(*) from student where mincome='".$fclass["mincome"]."' and bus !='' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and gender = 'female'");
    					$totStudent_bus=$db->getVal("select Count(*) from student where mincome='".$fclass["mincome"]."' and bus !='' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 ");
    					//$cancelStudent=$db->getVal("select Count(*) from student where mincome='".$fclass["mincome"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=3 and issue_TC=0 ");
    					?>
                        <tr>
                            	<td><?php echo $i ?></td>
    							<td><?php echo $fclass["mincome"] ?></td>
                                <td><?php echo $male ?></td>
                                <td><?php echo $female ?></td>
    							<td><?php echo $totStudent ?></td>
    							<td><?php echo $male_bus ?></td>
                                <td><?php echo $female_bus ?></td>
    							<td><?php echo $totStudent_bus ?></td>
                          <?php     
    						$total_male+=$male;	$total_female+=$female;	$total_student+=$totStudent; //$total_cancel+=$cancelStudent;
    					    $total_male_bus+=$male_bus;	$total_female_bus+=$female_bus;	$total_student_bus+=$totStudent_bus;					
    					 } ?>
    			</tbody>
    				<tfoot><td></td><td></td>
    					<td>total = <?php echo $total_male ?></td>
    					<td>total = <?php echo $total_female ?></td>
    				    <td>total = <?php echo $total_student ?></td>
                        <td>total = <?php echo $total_male_bus ?></td>
    					<td>total = <?php echo $total_female_bus ?></td>
    				    <td>total = <?php echo $total_student_bus ?></td>
    				</tfoot>
    			</table>  Print date : <?php echo date("d-M-Y") ?>
    <?php }
    }	
    elseif(isset($_REQUEST['cast_list'])){
    			
    		$aryClass=$db->getRows("select distinct(cast) from student where school_id='".$_SESSION["admin"]["school_id"]."' and status=1");
    		
    		if(is_array($aryClass) && count($aryClass)>0){
    			?>
              <center><h5><p>Cast Wise Total Student List</p>	</h5></center>
    			<table class="table" cellpadding="0" cellspacing="0" border="1" id="tblData" data-tblname="Cast List">
    				<thead>
    				<tr>
                    	<td>S.No</td>
    					<td>Cast</td>
                        <th>No of Male</th>
                        <th>No of Female</th>
    					<td>Total Student</td>
    					
                        
    			</tr>
    			</thead>
    			<tbody>
    		<?php	$i=0;$total_male=$total_female=$total_student=$total_cancel=0;$total=0;
    					foreach($aryClass as $fclass){$i++;
    					$male=$db->getVal("select Count(*) from student where cast='".$fclass["cast"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and gender = 'male'");
    					$female=$db->getVal("select Count(*) from student where cast='".$fclass["cast"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and gender = 'female'");
    					$totStudent=$db->getVal("select Count(*) from student where cast='".$fclass["cast"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 ");
    					//$cancelStudent=$db->getVal("select Count(*) from student where mincome='".$fclass["mincome"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=3 and issue_TC=0 ");
    					?>
                        <tr>
                            	<td><?php echo $i ?></td>
    							<td><?php echo $fclass["cast"] ?></td>
                                <td><?php echo $male ?></td>
                                <td><?php echo $female ?></td>
    							<td><?php echo $totStudent ?></td>
    							
                          <?php     
    						$total_male+=$male;	$total_female+=$female;	$total_student+=$totStudent; $total_cancel+=$cancelStudent;
    					    					
    					 } ?>
    			</tbody>
    				<tfoot><td></td><td></td>
    					<td>total = <?php echo $total_male ?></td>
    					<td>total = <?php echo $total_female ?></td>
    				    <td>total = <?php echo $total_student ?></td>
                        
    				</tfoot>
    			</table>  Print date : <?php echo date("d-M-Y") ?>
    <?php }
    }
    else{
    	echo "Please select class First";
    }
//echo $db->getErMsg()
?>


        
    </div>

</div>
 

<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+' - '+tableType+'.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();
}

        $("#btn_excel").click(function(e) {
            var filename = $("#filename").val();

        let file = new Blob([$('.divclass').html()], {type:"application/vnd.ms-excel"});
        let url = URL.createObjectURL(file);
        let a = $("<a />", {
        href: url,
        download: "Total Dues.xls"}).appendTo("body").get(0).click();
        e.preventDefault();
        });

$("#duebutton").click(function(){
    // alert('hello');
    var month = $("#fmonth").val();
    // alert(month)
    var cls = $("#class").val();
    var section = $("#section").val();

    if(month == '') return alert('Please select month');

  $.post("Account/ajax.php", {type:"total_amount_dues", fmonth: month, cls: cls, section:section} ,function(data){
    //   alert(data);
      $("#ajaxdata").html(data);
//     alert("Data: " + data + "\nStatus: " + status);
  });
});
        
</script>
