<style>
    @media print {

        #myPrntbtn {
            display :  none;
        }

    }
</style>

<input type="button" onclick="printDiv('printableArea')" value="Print" />


<div id="printableArea">
    <div style="width:100%;text-align:center;">

        <img src="<?php echo $LinksDetails['logo']; ?>" style="width:200px;float:left;height:80px;"/>

        <h1><?php
            echo $LinksDetails['site_name']; ?>
        </h1>
        <label><?php
                echo $LinksDetails['contact_content']; ?>
        </label>

    </div>
<hr>

<?php

$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'
);

	if(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 ";
        }
        
        if($_GET['section']!=""){
            $whereclass .= " 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");
		
		$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>



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

                    $monthlycolumn = [];
                    $otherfeecolumn = [];
					$backduescolumn = [];
					$hostelothercolumn = [];
					$totalothercolumn = [];
					$finecolumn = [];
					
					 
					foreach($aryStudentList as $fStudent){$i++;
					$mn=$m;
					?>
                    <tr>
                        	<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"]; //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;
				// 		$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;
				// 		$monthlycolumn[$key] +=$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;
						
				// 		$monthlycolumn[$key] +=$hostel;
				// 		echo $overAllhotel;
						$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+$hostel+$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 
				// 	$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 7;?>">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 ";
        }
        
        if($_GET['section']!=""){
            $whereclass .= " 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");
		
		$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>

			<table class="table" cellpadding="0" cellspacing="0" border="1" style="font-size:9.5px;" id="tblData" data-tblname="Complete Outstanding">
				<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
			   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 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"]; //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;
				// 		$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="7">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['hostel_outstanding']))
	{
			$overAllTotal=0;$overAlltution=0;$overAllTransport=0;$overAllhotel=0;$overAllOther=0;$overAllOther_hostel=0;$overAllFine=0;$overAllextra=array();					
			$overAllNewextra=0;
			
        $whereclass = "";			
        if($_GET['class']!=""){
            $whereclass .= " s.class='".$_GET["class"]."' and ";
        }
        
        if($_GET['section']!=""){
            $whereclass .= " 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");
// echo "select * from student where $whereclass school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' $whereS and status=1 and issue_TC=0 and hostel != '' 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 and hostel != '' 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");


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



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

              <?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</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 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"]; //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 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;
						

                    $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;
			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 }}


					?>

					<?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; */

					?>

      <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="7">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($_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>

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

			<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['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>
            <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="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 }
		}

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

            <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="Month Report Without Class">
				<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>
                     
						<th width="0.5%">Tution </th>
						<th width="0.5%">Transport</th>
						<th>Hostel</th>
                    <th>Extra</th>
                    <th>Other</th>
                    <th>Hostel 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><?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;

		  $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='$type' 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;//$hostelother_fee_given+$hosteltotal_other_discount;

          ?>				
				<td><?php echo $other_fee_name['total']-$g; $t+=$other_fee_name['total']-$g; ?></td>
				<td><?php echo $hostelother_fee_name['total']-$hosteldue; $t+=$hostelother_fee_name['total']-$hosteldue; ?></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 }
}

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

    <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="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){
							if($installTution["ip$i"]=="" || $installTution["ip$i"]=="0")
							{
								$tution=$installTution["i$i"];
							} 
							else
							{
                				if($m==$i)
                				{
                				    $tution=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from installment where  idno='".$fStudent["idno"]."' ");
                				}
                                else
                                {
	                             $tution=0;	
                                }
							}
						}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){
						if($installTution["bp$i"]=="" || $installTution["bp$i"]==0){
							$trasnport=$installTution["b$i"];
						}
						else    {
        				if($m==$i)
        				{
            				$trasnport=$db->getVal("select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' ");
        				}
                        else    {
                	             $trasnport=0;	
                                }
							}
					}   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){
							if($installTution["ip$i"]=="" || $installTution["ip$i"]=="0")
							{
								$hostel=$installTution["i$i"];
							} 
							else
							{
                				if($m==$i)
                				{
                				    $hostel=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from hostelinstallment where  idno='".$fStudent["idno"]."' ");
                				}
                                else
                                {
	                             $hostel=0;	
                                }
							}
						}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){
									
									if($installTution["pay"]=="" || $installTution["pay"]==0)
									{
										$extrafees = $installTution["fee"];
									}
									else
									{
									if($m==$i)
		                    		{
    									$extrafees=$db->getVal("select sum(fee-pay)  from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$i."'  ");
                    				}
                                    else
                                       {
                    	             $extrafees = 0;	
                                         }	
									}
								}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='$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
                        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 }
}


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

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

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

					<?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++){
				$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){
							if($installTution["ip$i"]=="" || $installTution["ip$i"]=="0")
							{
								$tution=$installTution["i$i"];
							} 
							else
							{
                				if($m==$i)
                				{
                				    $tution=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from installment where  idno='".$fStudent["idno"]."' ");
                				}
                                else
                                {
	                             $tution=0;	
                                }
							}
						}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){
						if($installTution["bp$i"]=="" || $installTution["bp$i"]==0){
							$trasnport=$installTution["b$i"];
						}
						else    {
        				if($m==$i)
        				{
            				$trasnport=$db->getVal("select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' ");
        				}
                        else    {
                	             $trasnport=0;	
                                }
							}
					}   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){
							if($installTution["ip$i"]=="" || $installTution["ip$i"]=="0")
							{
								$hostel=$installTution["i$i"];
							} 
							else
							{
                				if($m==$i)
                				{
                				    $hostel=$db->getVal("select (i".$m."-COALESCE(ip".$m.",0)) from hostelinstallment where  idno='".$fStudent["idno"]."' ");
                				}
                                else
                                {
	                             $hostel=0;	
                                }
							}
						}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"]."'");
                        // 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){
									
									if($installTution["pay"]=="" || $installTution["pay"]==0)
									{
										$extrafees = $installTution["fee"];
									}
									else
									{
									if($m==$i)
		                    		{
    									$extrafees=$db->getVal("select sum(fee-pay)  from extrafee where idno='".$fStudent["idno"]."' and pid ='p".$i."'  ");
                    				}
                                    else
                                       {
                    	             $extrafees = 0;	
                                         }	
									}
								}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 /*
                        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>";
			            }*/
			             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 }
}


?>

</div>

<script>

function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}

</script>



