<?php 
include("../../db.php");
$pgMod="fee_summery";
$pgAct="view";

 $_SESSION["admin"]["session"]=$_REQUEST['session'];
 $_SESSION["admin"]["school_id"]= $_REQUEST['school_id'];
 $_REQUEST['fmonth']=$_GET['fmonth'];

$monthsList = array(
    'January',
    'February',
    'March',
    'April',
    'May',
    'June',
    'July ',
    'August',
    'September',
    'October',
    'November',
    'December',
);
$monthsList1 = array(
    1=>'Apr',
    2=>'May',
    3=>'Jun',
    4=>'Jul ',
    5=>'Aug',
    6=>'Sep',
    7=>'Oct',
    8=>'Nov',
    9=>'Dec',
	10=>'Jan',
    11=>'Feb',
    12=>'Mar'
);

$whereclass="";
if(isset($_REQUEST["class"]) && $_REQUEST["class"]!="")
    $whereclass=" AND class='".$_REQUEST["class"]."' ";

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

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

@media print {
    #searchfoertotal {
        display :  none;
    }
}
</style>
            <center><input type="button" class="btn btn-danger" id="btnduesend" value="Due List " style="float:left;" />
</center>

            <style>
                @media print {
            
                    #myPrntbtn {
                        display :  none;
                    }
            
                }
            </style>

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

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

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

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

							}
							
						}else{
							$tution="";
						}

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

				if($m==$key)
				{
				$trasnport=$db->getVal("select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' ");
				
				//echo $ss="select (b".$m."-COALESCE(bp".$m.",0)) from installment where  idno='".$fStudent["idno"]."' and (ip".$m1." is null or ip".$m1."=0)";
	
				}
                else
                   {
	             $trasnport=0;	
                     }				
								
								
							}
						}else{
							$trasnport="";
						}
						$overAllTransport=$trasnport;
				// 		$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 8;?>">Gross Total</td>
					<?php for($s = 1; $s<=$m; $s++){
					    echo "<td>$monthlycolumn[$s]</td>";
					} 
					for($s = 1; $s<=$c; $s++){
					    echo "<td>$otherfeecolumn[$s]</td>";
					}
					
					echo "<td>$backduescolumn[0]</td>";
					for($s = 1; $s<=$b; $s++){
					    echo "<td>$hostelothercolumn[$s]</td>";
					}
					echo "<td>$totalothercolumn[0]</td>";
					echo "<td>$finecolumn[0]</td>";
					?>
				   <td id="MyTotalLeft"><?php echo $total_comp; ?></td>
				</tfoot>
			</table>  Print date : <?php echo date("d-M-Y") ?>
            <p style="font-size:10px;">This page shows the account of only above session and final account is shown only in current session.</p>	
<?php }

?>
<style>.top-bar-minimize{display:none;}
thead, tfoot {display: table-header-group;}
.top-bar+.well,.accordion .accordion-heading+.accordion-body{display: inline-block !important;width: 100% !important;overflow: inherit !important;} 
.dynamic{display:none}
table td {
padding: 6px !important;
}
legend{line-height: 16px;font-weight:100;}



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