<?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;
	display: inline-block;
	color: #021EF0;
}
.recepit {
	width: 717px !important;
	height: 344px !important;
}
</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'];
	$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)
	{
		foreach($aryForms as $aryForm)
		{
			$_GET["id"]=$aryForm["idno"]; $totalBus=0;$totalFee=0;
?>
<!-- Forms --> 
	
     <div style="height:300px;margin:25px 0px;border-bottom:1px dotted red;">
    <div class="headPrint">
      <table width="100%" style="border-bottom:1px solid #000; margin-bottom:10px;">
        <tr>
          <td align="center" style="text-align:center"><?php if($aryForm["photo"]!=""){
                            ?>
            <img src="<?php echo URL_ROOT; ?>media/photo/<?php echo $aryForm["photo"]; ?>" style="height:70px; float:right" />
            <?php
                        }?><img src="<?php echo $LinksDetails["logo"] ?>" style="float:left" height="60px"><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" width="100%" border="1">
        <tr>
        	<td>
            	<div class="span3">
                	<ul class="unstyled">
                      <li><strong class="st">Name</strong> : <?php echo $aryForm["name"] ?></li>
                      <li><strong class="st">Adm no</strong> : <?php echo $aryForm["admissionno"] ?></li>
                    </ul>
            	</div>
            </td>
            <td>
                <div class="span2">
                	<ul class="unstyled">
                      <li><strong class="st">Class</strong> : <?php echo $aryForm["class"] ?></li>
                      <li><strong class="st">Father</strong> : <?php echo $aryForm["fname"] ?></li>
                    </ul>
            	</div>
            </td>
            <td>
				<div class="span3">
                	<ul class="unstyled">
                      <li><strong class="st">Contact</strong> : <?php echo $aryForm["mobile"] ?></li>
                      <li><strong class="st" style="width:110px">Last Paid Date</strong> : <?php $udate=$db->getVal("select date from installment_time where idno='".$aryForm["idno"]."'");if($udate!="") echo date("d/F/Y",strtotime($udate));//echo $db->getErMsg().$db->getLastQuery(); ?></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 
						$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;
						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{
									$totalFee+=$aryInstall[$iis];
								}
							}
						}
						$ji=0;
						for($i=1;$i<=$month;$i++){
							$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]; 
								}
							}
						}
						$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;
					   ?>
                 <table class="table" width="100%" border="1">
                 	<tr>
                    	<th>Tution</th>
                        <th>Transport</th>
                        <th>Hostel</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 foreach($extraFee as $key=>$value){ ?>
                        <th><?php echo $value;$totalExt+=$value; ?></th>
                        <?php }?>
                        <th><?php echo $totalBus+$totalhostel+$totalFee+$totalExt; ?></th>
                    </tr>
                 </table>
                 <?php //echo $db->getErMsg().$db->getLastQuery(); ?>
          </div>
         </div>
    </div>
    </div>
       
<!-- / Forms -->
<?php
		}
	}
}
?>
<!-- / Forms -->
<script type="text/javascript">
window.print() ;
</script>