 <script src="<?php echo URL_ROOT; ?>js/jquery-1.10.2.js"></script>
<?php 
$pgMod="demand_bill";
$pgAct="view";
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

	  $month=0;
	  if($_GET["month"]<=3){
		$month=$_GET["month"]+9;
	  }
	  else{
		$month=($_GET["month"]-3);
	  }
	  
	  $where="";
	  if(isset($_GET['idno']) && trim($_GET['idno']) !='')$where=" and idno=".$_GET['idno'];
	  if(isset($_GET['section']) && trim($_GET['section']) !='')$where.=" and section='".$_GET['section']."'";
	$aryForms=$db->getRows("select *, REPLACE(sibling,idno,'') as sibling1 from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and (status=1 or status=2) and class='".$_GET["class"]."' $where order by name");		
	
	
	
	//print_r($aryForms);
	//echo $db->getLastQuery();
	//print_r($aryForms);exit;
	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:349.7px;margin:10px 0px;">
    <div class="headPrint">
      <table width="100%" style="border-bottom:1px solid #000; margin-bottom:10px;">
        <tr>
          <td align="center" style="text-align:center; font-size:20px; font-family: Berlin Sans FB Demi;"><strong><?php echo ucfirst($LinksDetails["site_name"]) ?></strong><br />
            <em><?php //echo ucfirst(nl2br($LinksDetails["contact_content"])) ?></em></td>         
        </tr>
      </table>
    </div>
        <table class="table" cellpadding="0" cellspacing="0" width="100%" border="1">
        <tr>
        	<td>
            	<div class="span3">
                	<ul class="unstyled">
                      <li class="size"><strong class="st">Name</strong> : <?php echo $aryForm["name"] ?></li>
                      <li class="size"><strong class="st">Adm no</strong> : <?php echo $aryForm["admissionno"] ?></li>
                    </ul>
            	</div>
            </td>
            <td>
                <div class="span2">
                	<ul class="unstyled">
                      <li class="size"><strong class="st">Class</strong> : <?php echo $aryForm["class"]."-".$aryForm["section"]; ?></li>
                      <li class="size"><strong class="st">Father</strong> : <?php echo $aryForm["fname"] ?></li>
                    </ul>
            	</div>
            </td>
            <td>
				<div class="span3">
                	<ul class="unstyled">
                      <li class="size"><strong class="st">Contact</strong> : <?php echo $aryForm["mobile"] ?></li>
                      <li class="size"><strong class="st">Address</strong> : <?php echo $aryForm["address"] ?></li>
                      
                    </ul>
            	</div>
            </td>
        </tr>
        </table>
        
     <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <center<em><strong><i class="icon-cog"></i> Remaining fee for 
				<?php $newMyDate=date("Y")."-".($_GET["month"])."-1";
					echo date("F",strtotime($newMyDate)); ?> month</strong></em></center>
            </div>
            <div class="well no-padding">
			<?php 
			//$sibling=$db->getVal("SELECT  concat(idno,sibling,'') as sibling1 from student  WHERE idno='".$aryForm['idno']."' and session='".$_SESSION["admin"]["session"]."' ");				
			$sibling=$aryForm['idno'];				
					
					//echo $sibling.'<br>'; ?>
                    <?php 
						
						$feeCount=array();$totalFee=0;$totalBus=0;$totalhostel=0;$extraFee=array();$totalExtra=0;$total=0;$dues=0;$duesother=0;
						$totalother=$totalhostelother=0;
						//echo $month;
						for($i=1;$i<=$month;$i++){
							$iis="i".$i;
							$iip="ip".$i;
							
							
							$aryInstall=$db->getRow("select sum(".$iis.") as ".$iis." , sum(".$iip.") as ".$iip."  from installment where school_id='".$_SESSION["admin"]["school_id"]."' and idno in ($sibling) and session='".$_SESSION["admin"]["session"]."'");
							
							
							
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								//echo $aryInstall[$iis].'<br>';
								$totalclasspayfee=$totalclasspayfee+$aryInstall[$iip];
								$is_rr=false;
								if($aryInstall[$iip]>0){}else{
									
									$totalFee+=$aryInstall[$iis];
								}
							}
						}
						$ji=0;
						
						for($i=1;$i<=$month;$i++){
							$iis="b".$i;
							$iip="bp".$i;$is_rr=false;
							
							$aryInstall=$db->getRow("select sum(".$iis.") as ".$iis." , sum(".$iip.") as ".$iip."  from installment where school_id='".$_SESSION["admin"]["school_id"]."' and idno in ($sibling) and session='".$_SESSION["admin"]["session"]."'");
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalbuspayfee=$totalbuspayfee+$aryInstall[$iip];$ji++;
								$is_rr=false;
								if($aryInstall[$iip]>0){}else{
									  $totalBus+=$aryInstall[$iis]; 
								}
							}
						}
						$aryInstall=$db->getRow("select * from hostelinstallment where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$aryForm["idno"]."' and session='".$_SESSION["admin"]["session"]."'");
						for($i=1;$i<=$month;$i++){
							$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];
								}
							}
						}
						$checkextFee=$db->getRows("select * from extrafee_type where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'");	
						if(is_array($checkextFee) && count($checkextFee)>0){
							foreach($checkextFee as $chkExtFee){
								for($i=1;$i<=$month;$i++){
									$iip="p".$i;
									$mycheckInstall=$db->getRow("select fee,pay from extrafee where idno='".$_GET["id"]."' and type='".$chkExtFee["id"]."' and pid='".$iip."'");
									if($mycheckInstall["fee"]>0){
										$type=$chkExtFee["type"];
										if($mycheckInstall["pay"]==0 || $mycheckInstall["pay"]=="")
										$extraFee[$type]=$extraFee[$type]+$mycheckInstall["fee"];
										$totalExtra=$totalExtra+$extraFee[$type];
									}
								}
							}
						}$totalExt=0;
						/*$install=$db->getRow("select * from otherfee_structure where otype ='".$aryForm['idno']."' and name like '%b%' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
						
							if(is_array($install) && count($install)>0){
								$installTution=$db->getRow("select * from installment_fine where idno=".$aryForm['idno']." and reasion = '".$install['name']."'");        if(is_array($installTution) && count($installTution)>0){
								if($install['fee']==$install
								['fine'])
									$dues=0;
								}
							   else 		
								$dues=$install['fee'];
							}*/
						?>
                 <table class="table" cellpadding="0" cellspacing="0" width="100%" border="1">
                 	<tr>
					
                    	<th>Tuition</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 month <= '".$month."' 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 month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
						if(is_array($aryother) && count($aryother)>0){$c=0;
					    		foreach($aryother as $other){$c++;?>
                        			<th class="other<?php echo $ij.$c ?>"><?php echo $other['name'] ?></th>
								<?php } } 
                      $htype=$aryForm['htype'];
					if($htype=="old"){
						 $aryhostelother=$db->getRows("select  distinct(name) from hostel_otherfee_structure where (otype ='' or otype ='old' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
				    elseif($htype=="new"){ 
						 $aryhostelother=$db->getRows("select  distinct(name) from hostel_otherfee_structure where (otype ='' or otype ='new' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
					else $aryhostelother=0;	
						if(is_array($aryhostelother) && count($aryhostelother)>0){ $c=0;
					    		foreach($aryhostelother as $other){$c++;?>
                        			<th class="hostelother<?php echo $ij.$c ?>"><?php echo $other['name'] ?></th>
								<?php } } ?>         
                       <!-- <th>Back Dues</th>-->
                        <?php foreach($extraFee as $key=>$value){ ?>
                        <th><?php echo $key ?></th>
                        <?php }?>
                        <th>TOTAL</th>
                    </tr>
                    <tr>
                    	<th><?php echo $totalFee; ?></th>
                        <th><?php 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 month <= '".$month."' 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 month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); } 
						 
						 //$aryother=$db->getRows("select sum(fee) as fee from otherfee_structure where (otype ='' or otype ='new' or otype ='old'  or otype in ($sibling)) and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  ");
						 
              			
						
						 //echo $db->getLastQuery();
						 if(is_array($aryother) && count($aryother)>0){$c=0;
					    	foreach($aryother as $other){$c++;
								$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 class="other<?php echo $ij.$c;?>"> <?php echo $duesother; ?></th>
                        <?php if($duesother==0){?>
                 <script type="text/javascript">$('.other<?php echo $ij.$c ?>').hide()</script>
                        <?php } ?>	
				     <?php } }
                     if($htype=="old"){
						 $aryhostelother=$db->getRows("select * from hostel_otherfee_structure where (otype ='' or otype ='old' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); }
						 
				    elseif($htype=="new"){ 
						 $aryhostelother=$db->getRows("select * from hostel_otherfee_structure where (otype ='' or otype ='new' or otype='".$aryForm['idno']."') and month <= '".$month."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$aryForm["class"]."'"); } 
						 //echo $db->getLastQuery();
					else $aryhostelother=0;		 
						 if(is_array($aryhostelother) && count($aryhostelother)>0){$c=0;
					    	foreach($aryhostelother as $other){$c++;
								$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;
					 }
						$totalhostelother+=$duesother;			
						?>		<th class="hostelother<?php echo $ij.$c ?>"> <?php echo $duesother; ?></th>	
                        <?php if($duesother==0){?>
                 <script type="text/javascript">$('.hostelother<?php echo $ij.$c ?>').hide()</script>
                        <?php } ?>
				     <?php } }?>
                       <!-- <th><?php echo $dues; ?></th>-->
                        <?php foreach($extraFee as $key=>$value){ ?>
                        <th><?php echo $value;$totalExt+=$value; ?></th>
                        <?php }?>
                        <th><?php echo $total=$totalBus+$totalhostel+$totalFee+$totalExt+$dues+$totalother+$totalhostelother; ?></th>
                    </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>
         </div>
    </div>
    </div>
       
<!-- / Forms -->
<?php
		}
	}
}
?>
<!-- / Forms -->
<script type="text/javascript">
window.print() ;
</script>