 <script src="<?php echo URL_ROOT; ?>js/jquery-1.10.2.js"></script>
<?php 
$pgMod="demand_bill";
$pgAct="view";
$monthsList = 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'
);
unset($_SESSION["recept"]);
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);

if(isset($_GET['class']) && trim($_GET['class']) !='')
{ 
	?><style>
.st {
	width: 55px;
	font-size:10px;
	display: inline-block;
	color: #021EF0;
}
.size{
	font-size:10px;
}
.recepit {
	width: 717px !important;
	height: 344px !important;
}
.unstyled{
	margin:3px 0px 0px 0px;
}
</style><?php

	   $where="";
	  if(isset($_GET['idno']) && trim($_GET['idno']) !='')$where=" and idno=".$_GET['idno'];
	$aryForms=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and (status=1 or status=2) and class='".$_GET["class"]."' $where order by name");
	if(is_array($aryForms) && count($aryForms)>0)
	{	$ij=0;
		foreach($aryForms as $aryForm)
		{ $ij++;
			$_GET["id"]=$aryForm["idno"]; $totalBus=0;$totalFee=0;
?>
<!-- Forms --> 
	
     <div id="demand-<?php echo $ij; ?>" style="height:950px;margin:10px 0px;border:5px solid #F00;">
    <div class="headPrint" style="border: none;text-align:center;">
			 <div style="margin-left:20px"> <img src="<?php echo $LinksDetails["logo"] ?>" height="80px" width="110px" style="margin:6px 0px 0px 10px;"></div>
			 <div style="text-align:center;margin-bottom:18px;"> <h1 style="font-size:32px;margin:5px 0px 0px 0px;color: #EC1E1E;"><?php echo ucfirst($LinksDetails["site_name"]) ?></h1>
			   <span style="font-size:17px;font-weight:800;  color: #186916;"> <?php echo ucfirst(nl2br($LinksDetails["contact_content"])) ?></span>
			 </div> 
		  </div>
				
				<div style="font-size: 16px;clear: both;background-color: #D5DA13;font-weight: bold;padding: 5px;color: #000;text-align: center;  border-top: 1px solid #000;border-bottom: 1px solid #000;"> ACADEMIC FEES (<?php echo $_SESSION["admin"]["session"];?>)</div>
				<table style="width:100%;font-size:13px;font-weight: bold;color:#1224A5;" cellpadding="5" cellspacing="2">
				  <tr>
					<td width="20%">Name</td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["name"] ?></td>
					<td width="20%">Class</td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["class"] ?></td>
				  </tr>
				  <tr>
					<td width="20%"><strong>Father</strong></td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["fname"] ?></td>
					<td width="20%"><strong>Adm/No.</strong></td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["admissionno"] ?></td>				
				  </tr>
				  <tr>
					<td width="21%"><strong>Mother</strong></td><td width="2%">:</td>
					<td width="30%"><?php echo $aryForm["mname"] ?></td>
					<td width="20%"><strong>D.O.B</strong></td><td width="2%">:</td>
					<td width="30%"><?php if($aryForm["dob"]!="")echo date("d-M-Y",strtotime($aryForm["dob"])); ?></td>
				  </tr>
				 <tr><td width="21%"><strong class="st">Contact</strong></td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["mobile"] ?></td></tr>
				</table>
            <br />
                 <table class="table" cellpadding="2" cellspacing="0" width="100%" border="1" style="color:blue;">
                 	<tr>
                    	<th>Month</th>
                    	<th>Tution</th>
                        <th>Transport</th>
                        <!--<th>Hostel</th>-->
                                
			 <?php    $stype=$aryForm['stype'];
					if($stype=="old"){
						 $aryother=$db->getRows("select  distinct(name) from otherfee_structure where (otype ='' or otype ='old' or otype='".$aryForm['idno']."') and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
				    elseif($stype=="new"){ 
						 $aryother=$db->getRows("select  distinct(name) from otherfee_structure where (otype ='' or otype ='new' or otype='".$aryForm['idno']."') and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
						if(is_array($aryother) && count($aryother)>0){
					    		foreach($aryother as $other){$c++;?>
                        			<th class="other<?php echo $ij.$c ?>"><?php echo $other['name'] ?></th>
								<?php } } 							
                  ?>
                       
                    </tr>
                    <?php $i=0; $overalltution=$overallbus=$overallhostel=0;$overother=array();$c=0;
					 foreach($monthsList as $month=>$value){$c++;
						$i=$month;
						$aryInstall=$db->getRow("select * from installment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and session='".$_SESSION["admin"]["session"]."'");
						$feeCount=array();$totalFee=0;$totalBus=0;$totalhostel=0;$extraFee=array();$totalExtra=0;$total=0;$dues=0;$duesother=0;
						$totalother=$totalhostelother=0;
							$iis="i".$i;
							$iip="ip".$i;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalclasspayfee=$totalclasspayfee+$aryInstall[$iip];
								$is_rr=false;
								if($aryInstall[$iip]>0){}else{
									$totalFee+=$aryInstall[$iis];
								}
							}
						$overalltution+=$totalFee;
						$ji=0;
						
							$iis="b".$i;
							$iip="bp".$i;$is_rr=false;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalbuspayfee=$totalbuspayfee+$aryInstall[$iip];$ji++;
								$is_rr=false;
								if($aryInstall[$iip]>0){}else{
									  $totalBus+=$aryInstall[$iis]; 
								}
							}
						$overallbus+=$totalBus;
						$aryInstall=$db->getRow("select * from hostelinstallment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and session='".$_SESSION["admin"]["session"]."'");
						
							$iis="i".$i;
							$iip="ip".$i;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalclasspayfee=$totalclasspayfee+$aryInstall[$iip];
								$is_rr=false;
								if($aryInstall[$iip]>0){}else{
									$totalhostel+=$aryInstall[$iis];
								}
							}
						$overallhostel+=$totalhostel;
						 
					?>
                    <tr>
                    	<th><?php echo $value; ?></th>
                    	<th><?php if($totalFee==0) echo "<span style='color:red'>paid</span>"; else echo $totalFee; ?></th>
                        <th><?php if($totalBus==0) echo "<span style='color:red'>paid</span>"; else echo $totalBus; ?></th>
                       <!-- <th><?php echo $totalhostel; ?></th>-->
                <?php if($stype=="old"){
						 $aryother=$db->getRows("select * from otherfee_structure where (otype ='' or otype ='old' or otype='".$aryForm['idno']."') and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
				    elseif($stype=="new"){ 
						 $aryother=$db->getRows("select * from otherfee_structure where (otype ='' or otype ='new' or otype='".$aryForm['idno']."') and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); } 
						 //echo $db->getLastQuery();
						 
						 if(is_array($aryother) && count($aryother)>0){$tc=0;
					    	foreach($aryother as $other){$tc++;
								$installOther=$db->getRows("select * from installment_fine where idno=".$aryForm['idno']." and reasion = '".$other['name']."'");       	    $total_fine=0;
							  $installTution2=$db->getRow("select * from otherfee_discount where idno=".$aryForm['idno']." and other_id='".$other['id']."' and class='".$aryForm["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
								$t=$other['fee'];
						//echo $fStudent['idno'];exit;	
							if(is_array($installTution2) && count($installTution2)>0){
										 $dis=$installTution2['discount'];
												if($other['fee']==$dis)
													$t=0;
												else 
													$t=$t-$dis;
							 }
					 if($t!=0 && $t<=$other['fee']){
							  if(is_array($installOther) && count($installOther)>0){
									foreach($installOther as $installOther1){
										$total_fine+=$installOther1['fine'];	
										  if($total_fine==$t)	
												$duesother=0;
										   	
										  else
										  		$duesother=$t-$total_fine;	
							  		}
									if($total_fine!=$t)
										{$duesother=$t-$total_fine;}
									if(stripos($other["name"], "b") !== FALSE){
									$installTution_remain=$db->getVal("select sum(fine) from installment_fine where idno=".$aryForm['idno']." and reasion like 'remain%' ");							  		$duesother=$duesother-$installTution_remain;
									}
							  }
							 
							   else 		
									$duesother=$t;
							
					 }
					 else{
						 $duesother=0;	
					 } $totalother+=$duesother;
					
						?><th> <?php if($c==1){ $overother[]=$duesother; if($duesother==0) echo "<span style='color:red'>paid</span>"; else echo $duesother; }?></th>
                     <?php 
					  } }
                     ?>  <!-- <th><?php echo $dues; ?></th>-->
                        <!--<th><?php $total=$totalBus+$totalhostel+$totalFee+$totalExt+$dues+$totalother+$totalhostelother; ?></th>-->
                    </tr>
                   <?php  } ?>
                   <tr>
                    <th>Total</th>
                    <th><?php echo $overalltution ?></th>
                    <th><?php echo $overallbus ?></th>
                   <!-- <th><?php echo $overallhostel ?></th>-->
                  <?php foreach($overother as $over){?>
                   <th><?php echo $over; ?></th><?php } ?>
                   </tr>
                 </table>
                 <?php //echo $db->getErMsg().$db->getLastQuery(); ?>
                 <?php if($total==0){?>
                <!-- <script type="text/javascript">$('#demand-<?php echo $ij ?>').hide()</script>-->
                <!-- <style>#demand<?php echo $ij ?>{display:none;}</style>-->
                 <?php } ?>
        
    </div>
       
<!-- / Forms -->
<?php
		}
	}
}
?>
<!-- / Forms -->
<script type="text/javascript">
window.print();
</script>