<?php
include("db.php");
$_GET["id"]=$_SESSION["user"]["uid"];
//&action=view_fees&id=1
if(isset($_GET['action']) && trim($_GET['action'])!='')
	$pgAct=strtolower($_GET['action']);
else
	$pgAct="view_fees";

if($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
	$res=$db->delete("student","where idno='".$_GET['id']."'");
	if(!is_null($res)) { $_SESSION['msg']='Deleted Successfully'; }
	else { array_push($alert_err,$db->getErMsg()); }
	redirect(URL_ADMIN_HOME.getQueryString(array("page_id"=>$pgMod)));
}
?>
<?php
{ 
	if(isset($_SESSION['form']))
	{
		$aryForm=$_SESSION['form'];
		unset($_SESSION['form']);
	}
	$aryForm=$db->getRow("SELECT * from student where status=1 and  idno='".$_GET['id']."'");
?>
<style>
td input {
    width: 100%;
    background-color: transparent;
    border: 0;
}
.half {
    display: inline-block;
    width: 49%;
    border: 1px solid #ccc;
    font-size: 11px;
	vertical-align:top;
}
.no-padding {
    padding: 0;
}
.feedetails {
    font-size: 11px;
}
center {
    border: 1px solid #ccc;
    font-size: 17px;
    font-weight: bold;
    background-color: rgba(202, 33, 175, 0.73);
    color:#fff;
    padding: 4px 0;
}
</style>
<div id="printableDiv">
  <div class="row-fluid">
    <div class="span12">
      <div class="top-bar">
        <h3 class="hd"><i class="icon-cog"></i> Student detail</h3>
      </div>
      <div class="well no-padding only">
            	<table class="table" cellpadding="0" cellspacing="0">
                	<tr>
                    	<td><strong class="st">Name</strong></td><td ><?php echo $aryForm["name"] ?></td>
                        <td><strong class="st">Class</strong></td><td><?php echo $aryForm["class"] ?></td>
                        <td><strong class="st">id no</strong></td><td><?php echo $aryForm["idno"] ?></td>
                        <td><strong class="st">Admission No</strong></td><td><?php echo $aryForm["admissionno"] ?></td>
                    </tr>
                    <tr>
                    	<td><strong class="st">Mother</strong></td><td><?php echo $aryForm["mname"] ?></td>
                        <td><strong class="st">Father</strong></td><td><?php echo $aryForm["fname"] ?></td>
                        <td><strong class="st">DOA</strong></td><td><?php echo $aryForm["doa"] ?></td>
                        <td><strong class="st">Contact</strong></td><td><?php echo $aryForm["mobile"] ?></td>
                    </tr>
                </table>
            </div>
    </div>
  </div>
  <div class="row-fluid" >
    <div class="span12">
      <div class="top-bar">
        <h3 class="hd"><i class="icon-cog"></i> Payment detail</h3>
      </div>
      <div class="well no-padding">
             	<div class="half"><center>Tuition fee</center>
            	<table class="table">
                    <thead>
                        <tr>
                        	<th width="20%">Quater</th>
                            <th width="20%">Amount</th>
                            <th width="20%">Given</th>
                            <th width="15%">fine</th>
                            <!--<th width="35%">Date</th>-->
                            <th width="20%">Status</th>
                            
                        </tr>
                    </thead>
                    <tbody>
                    <?php 
						$aryInstall=$db->getRow("select * from installment where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$aryForm["idno"]."' and session='".$_SESSION["user"]["session"]."'");
						$feeCount=array();$totalclasspayfee=0;$totalbuspayfee=0;$busFine=0;$schoolFine=0;
						for($i=1;$i<=12;$i++){
							$iis="i".$i;
							$iip="ip".$i;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalclasspayfee=$totalclasspayfee+$aryInstall[$iip];
							?>
                            <tr>
                            	
                                <td><?php $ij=$i;
						  if($ij<=9){
							$newDate=date("Y")."-".($ij+3)."-1";
							echo date("F",strtotime($newDate));//."(".($ij+3).")";
						  }
						  else{
							$newDate=date("Y")."-".($ij-9)."-1";
							echo date("F",strtotime($newDate));//."(".($ij-9).")";
						  } ?></td>
              					
                                <td><input readonly type="text" id="fee<?php echo $i ?>" class="input-block-level" value="<?php echo $aryInstall[$iis]; ?>"  name="fee[]"></td>
                                <td><input type="text" id="given<?php echo $i ?>" class="input-block-level" value="<?php echo $aryInstall[$iip]; ?>" <?php if($aryInstall[$iip]>0)echo 'readonly="readonly"'; ?> name="given[]"></td>
                                
                                <td><?php 
								$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-class'");
								echo "<input  readonly='readonly' class='input-block-level1' type='text' title='".$fineAry["reasion"]."' rel='tooltip' value='".$fine=$fineAry["fine"]."'/>";$schoolFine+=$fine; ?></td>
                                <!--<td><?php $udate=$db->getVal("select date from installment_time where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$_GET["id"]."' and ins_name='".$iip."'");
								if(trim($udate)!="")echo date("d-M-Y",strtotime($udate)); ?></td>-->
                                <td><?php if($aryInstall[$iip]>0)echo '<font color="#009900">Paid</font>';else echo '<font color="#FF0000">Due</font>'; ?></td>
                                <td class="classtd">
								<input type="hidden" value="<?php echo $aryInstall[$iis]; ?>" class="instalment" />
                                <input type="hidden" value="<?php echo $i ?>" class="instalment_no" />
								<?php
								$recpChkData=checkRecepit($_GET["id"],$iip,"fee"); 
							/*	if($recpChkData){
									//print_r($recpChkData);
									if($recpChkData["i"]==1){
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$recpChkData["amount"].'&type=fee&paytype=classfee&detail=School fee&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fee Recepit</a>';
									}
									if($fine=="" || $fine==0){
											
									}else{
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=classfinefee&detail=School Fine&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Recepit</a>';
									}
								}else{
									if($aryInstall[$iip]>0){
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$aryInstall[$iip].'&type=fee&paytype=classfee&detail=School fee&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fee Recepit</a>';
										if($fine=="" || $fine==0){
											
										}else{
											echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=classfinefee&detail=School Fine&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Recepit</a>';
										}
									}else{ 
										echo '<a style="float:left" id="save'.$i.'" onclick="paynow(\''.$i.'\')" href="javascript:;"><button type="button" class="btn btn-info">Pay Fees</button></a>'; 
										if($fine=="" || $fine==0){
											echo '<a href="add_fine.php?idno='.$aryForm["idno"].'&no='.$i.'&type=class" data-class="pradesh" class="fancybox"><button type="button" class="btn btn-primary">Add Fine</button></a>';
										}else{
											echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&detail=School Fine&paytype=classfinefee&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Recepit</button>';
										}
									}
								}*/
								echo $db->getErMsg();
								?></td>
                            </tr>
							<?php
							}
						}
					?>
					</tbody>
                    </table>
				</div>	
				<?php 
				 if($aryForm["bus"]!=""){
				 ?><div class="half"><center>Transport fee</center>
                    <table class="table">
                    <thead>
                        <tr>
                        	<th width="20%">Quater</th>
                            <th width="20%">Amount</th>
                            <th width="20%">Given</th>
                            <th width="15%">fine</th>
                           <!-- <th width="35%">Date</th>-->
                            <th width="20%">Status</th>
                        </tr>
                    </thead>
					<?php
						$ji=0;
						for($i=1;$i<=12;$i++){
							$iis="b".$i;
							$iip="bp".$i;
							if($aryInstall[$iis]!="" && $aryInstall[$iis]!=0){
								$totalbuspayfee=$totalbuspayfee+$aryInstall[$iip];$ji++;
							?>
                            <tr <?php if($ji==1)echo 'class="first" style="border-top:2px solid #F00"'; ?>>
                            	
                                <td><?php $ij=$i;
						  if($ij<=9){
							$newDate=date("Y")."-".($ij+3)."-1";
							echo date("F",strtotime($newDate));//."(".($ij+3).")";
						  }
						  else{
							$newDate=date("Y")."-".($ij-9)."-1";
							echo date("F",strtotime($newDate));//."(".($ij-9).")";
						  }?></td>
                                <td><input readonly type="text" id="busfee<?php echo $i ?>" class="input-block-level" value="<?php echo $aryInstall[$iis]; ?>"  name="busfee[]"></td>
                                <td><input type="text" id="busgiven<?php echo $i ?>" class="input-block-level" value="<?php echo $aryInstall[$iip]; ?>" <?php if($aryInstall[$iip]>0)echo 'readonly="readonly"'; ?> name="busgiven[]"></td>
                                <td><?php 
								$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-bus'");
								//echo "<a href='#' title='".$fineAry["reasion"]."' rel='tooltip'>".$fine=$fineAry["fine"]."</a>";
								echo "<input  readonly='readonly' class='span4' type='text' title='".$fineAry["reasion"]."' rel='tooltip' value='".$fine=$fineAry["fine"]."'/>";
								$busFine+=$fine;
								 ?></td>
                                 <!--<td><?php $udate=$db->getVal("select date from installment_time where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$_GET["id"]."' and ins_name='".$iip."'");
								if(trim($udate)!="")echo date("d-M-Y",strtotime($udate)); ?></td>-->
                                <td><?php 
								if($aryInstall[$iip]>0)echo '<font color="#009900">Paid</font>';
								else echo '<font color="#FF0000">Due</font>'; ?></td>
                                <td class="bustd"><input type="hidden" value="<?php echo $aryInstall[$iis]; ?>" class="instalmentbus" />
                                <input type="hidden" value="<?php echo $i ?>" class="instalmentbus_no" /><?php 
								$recpChkData=checkRecepit($_GET["id"],$iip,"busfee"); 
								/*if($recpChkData){
									if($recpChkData["i"]==1)
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$recpChkData["amount"].'&type=fee&paytype=busfee&detail=Bus fee&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fee Recepit</a>';
								}else{
									if($aryInstall[$iip]>0){
										echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$aryInstall[$iip].'&type=fee&paytype=busfee&detail=Bus fee&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fee Recepit</a>';
										if($fine=="" || $fine==0){
											
										}else{
											echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=busfinefee&detail=Bus Fine&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Recepit</a>';
										}
										
									}
									else {echo '<a style="float:left" id="savebus'.$i.'" onclick="paybusnow(\''.$i.'\')" href="javascript:;"><button type="button" class="btn btn-info">Pay Fees</button></a>'; 
										if($fine=="" || $fine==0){
											echo '<a href="add_fine.php?idno='.$aryForm["idno"].'&no='.$i.'&type=bus" data-class="pradesh" class="fancybox"><button type="button" class="btn btn-primary">Add Fine</button></a>';
											
										}else{
											echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$fineAry["fine"].'&type=fee&paytype=busfinefee&detail=Bus Fine&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Fine Recepit</button>';
										}
									}
								}*/
								?></td>
                            </tr>
							<?php
							}
						}
					?>
                    </table>
                 </div>
                 <?php }
				 ?>
                 <?php 
				 $checkhostelFee=$db->getVal("select id from hostelinstallment where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$_GET["id"]."'");	
				if($checkhostelFee){
				 ?><div class="half"><center>Hostel fee</center>
                    <table class="table">
                    <thead>
                        <tr>
                        	<th width="20%">Quater</th>
                            <th width="20%">Amount</th>
                            <th width="20%">Given</th>
                            <th width="15%">fine</th>
                             <!-- <th width="35%">Date</th>-->
                            <th width="20%">Status</th>
                        </tr>
                    </thead>
					<?php
						$aryHostelInstall=$db->getRow("select * from hostelinstallment where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$aryForm["idno"]."' and session='".$_SESSION["user"]["session"]."'");
						$feeCount=array();$totalhostelpayfee=0;$hostelFine=0;
						$ji=0;
						for($i=1;$i<=12;$i++){
							$iis="i".$i;
							$iip="ip".$i;
							$ihp="hp".$i;
							if($aryHostelInstall[$iis]!="" && $aryHostelInstall[$iis]!=0){
								$totalhostelpayfee=$totalhostelpayfee+$aryHostelInstall[$iip];$ji++;
							?>
                            <tr <?php if($ji==1)echo 'class="first" style="border-top:2px solid #F00"'; ?>>
                            	
                                <td><?php $ij=$i;
						  if($ij<=9){
							$newDate=date("Y")."-".($ij+3)."-1";
							echo date("F",strtotime($newDate));//."(".($ij+3).")";
						  }
						  else{
							$newDate=date("Y")."-".($ij-9)."-1";
							echo date("F",strtotime($newDate));//."(".($ij-9).")";
						  }?></td>
                                <td><input readonly type="text" id="hostelfee<?php echo $i ?>" class="input-block-level" value="<?php echo $aryHostelInstall[$iis]; ?>"  name="hostelfee[]"></td>
                                <td><input type="text" id="hostelgiven<?php echo $i ?>" class="input-block-level" value="<?php echo $aryHostelInstall[$iip]; ?>" <?php if($aryHostelInstall[$iip]>0)echo 'readonly="readonly"'; ?> name="hostelgiven[]"></td>
                                <td><?php 
								$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-hostel'");
								//echo "<a href='#' title='".$fineAry["reasion"]."' rel='tooltip'>".$fine=$fineAry["fine"]."</a>";
								echo "<input  readonly='readonly' class='span4' type='text' title='".$fineAry["reasion"]."' rel='tooltip' value='".$fine=$fineAry["fine"]."'/>";
								$busFine+=$fine;
								 ?></td>
                                <!-- <td><?php $udate=$db->getVal("select date from installment_time where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$_GET["id"]."' and ins_name='".$ihp."'");
								if(trim($udate)!="")echo date("d-M-Y",strtotime($udate)); ?></td>-->
                                <td><?php 
								if($aryHostelInstall[$iip]>0)echo '<font color="#009900">Paid</font>';
								else echo '<font color="#FF0000">Due</font>'; ?></td>
                            </tr>
							<?php
							}
						}
					?>
                    </table>
                 </div>
                 <?php }
				 ?>
                 <?php $extrafeeFine=0;
					$checkextFee=$db->getRows("select * from extrafee_type where school_id='".$_SESSION["user"]["school_id"]."' and session='".$_SESSION["user"]["session"]."' and class='".$aryForm["class"]."'");	
					if(is_array($checkextFee) && count($checkextFee)>0){
						foreach($checkextFee as $chkExtFee){
							$mycheckInstall=$db->getRows("select * from extrafee where idno='".$_GET["id"]."' and type='".$chkExtFee["id"]."'");
							if(is_array($mycheckInstall) && count($mycheckInstall)>0){
						?>
                        <div  class="half">
                        <center><?php echo $chkExtFee["type"];?></center>
                        <table class="table">
                	
                    <thead>
                        
                        <tr>
                       		 <th width="20%">Quater</th>
                            <th width="10%">Amount</th>
                            <th width="10%">Given</th>
                            <th width="5%">fine</th>
                            <th width="35%">Date</th>
                            <th width="20%">Status</th>
                           <!-- <th >Quater</th>
                            <th>Amount</th>
                            <th>Amount Given</th>
                            <th width="50px">Late Fee</th>
                            <th>Date</th>
                            <th>Status</th>-->
                        </tr>
                    </thead>
                    <tbody>
                    <?php 
						foreach($mycheckInstall as $myinstall){
							$fine="";
							?>
							<tr><td><?php $ipi=ltrim ($myinstall["pid"], 'p');
							if($ipi<=9){
										$newDate=date("Y")."-".($ipi+3)."-1";
										echo date("F",strtotime($newDate));//."(".($ij+3).")";
									  }
									  else{
										$newDate=date("Y")."-".($ipi-9)."-1";
										echo date("F",strtotime($newDate));//."(".($ij-9).")";
									  }
							 ?></td>
                           <td><input data-month="month<?php echo $ipi; ?>" data-value="<?php echo $myinstall["fee"]; ?>-<?php echo $myinstall["pay"]; ?>" data-type="<?php echo $chkExtFee["id"] ?>" data-name="<?php echo $chkExtFee["type"] ?>" readonly type="text" id="extra<?php echo $myinstall["type"] ?>fee<?php echo $ipi ?>" class="input-block-level findFeeNow" value="<?php echo $myinstall["fee"]; ?>"  name="extra<?php echo $myinstall["type"] ?>fee[]"></td>
                                <td><input type="text" id="extragiven<?php echo $myinstall["type"] ?>fee<?php echo $ipi ?>" class="input-block-level" value="<?php if($myinstall["pay"]>0)echo $myinstall["pay"]; ?>" <?php if($myinstall["pay"]>0)echo 'readonly="readonly"'; ?> name="extra<?php echo $myinstall["type"] ?>feegiven[]"></td>
                            <td>
							
							<?php 
								
								$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$ipi."-extra".$myinstall["type"]."'");
								if(is_array($fineAry) && count($fineAry)>0){
								echo "<input  readonly='readonly' class='span12' type='text' title='".$fineAry["reasion"]."' rel='tooltip' value='".$fine=$fineAry["fine"]."'/>";
									$extrafeeFine=$extrafeeFine+$fineAry["fine"];
								}
								else{
								echo "<input  readonly='readonly' class='span12' type='text' title='' rel='tooltip' value=''/>";
								}
								 ?></td>
                                <td><?php $udate=$db->getVal("select date from installment_time where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$_GET["id"]."' and ins_name='ext-".$myinstall["type"]."-".$ipi."'");
								if(trim($udate)!="")echo date("d-M-Y",strtotime($udate)); ?></td>
                                <td><?php 
								if($myinstall["pay"]>0)echo '<font color="#009900">Paid</font>';
								else echo '<font color="#FF0000">Due</font>'; ?></td>

                            </tr>
							<?php
						}
					?>
					</tbody>
                </table>
                        </div>
                		<?php
							}
						}
					}
				?>
                 
                    	<?php $i=1;$totalOther=0;$payOther=0;$fineTotal=0;$allReasion=array();$OtherSiteTotal=0;
					 if($_GET["id"]!=''){ 
					 $utype=mydetail("stype",$_GET["id"],"student");
					 $all_other=$db->getRows("select * from otherfee_structure where school_id='".$_SESSION["user"]["school_id"]."' and session='".$_SESSION["user"]["session"]."' and class='".$aryForm["class"]."' and (otype='' OR otype='".$utype."' OR otype='".$_GET["id"]."')");
					 //echo"<pre>";print_r($all_other);echo"</pre>";
					  if(is_array($all_other) && count($all_other))
                      {
						  ?><div class="half"><center>Extra fee</center>
                    <table class="table">
                    <thead>
                        <tr>
                        	<th width="20%">Quater</th>
                            <th width="10%">Amount</th>
                            <th width="10%">Given</th>
                            <th width="10%">fine</th>
                           <!-- <th width="35%">Date</th>-->
                            <th width="20%">Status</th>
                        </tr>
                    </thead>
                    <tbody id="tbody" style="border-top:2px solid #F00"><?php
                        foreach($all_other as $iPro)
                        {
							$i++;
							$paid_Fee=$db->getVal("select fine from installment_fine where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$_GET["id"]."' and reasion='".$iPro["name"]."' and ins_name like '%otherfee%'");
							$fineAry=$db->getRow("select fine,reasion from installment_fine where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$aryForm["idno"]."' and ins_name='".$i."-other'");
							$other_Fee=$db->getRow("select discount,detail from otherfee_discount where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$aryForm["idno"]."' and other_id='".$iPro["id"]."'");		
							$OtherSiteTotal+=(int)$other_Fee["discount"];
					 ?>
                     <tr>
                      
                      	<td><?php echo $iPro["name"]; ?></td>
                        <td >
                        <input type="hidden" name="idno[]" value="<?php echo $_GET["id"]; ?>" />
                        <input type="hidden" name="reasion[]" id="reasion<?php echo $i; ?>" value="<?php echo $iPro["name"]; ?>" />
                        <input rel='tooltip' type="text" id="feeother<?php echo $i; ?>" readonly class="input-block-level" value="<?php echo ($iPro["fee"]-(int)$other_Fee["discount"]); ?>" title="<?php echo $other_Fee["detail"]; ?>" name="fee[]"><?php $totalOther+=(int)$iPro["fee"]-(int)$other_Fee["discount"]; ?></td>
                        <td><input type="text" id="givenother<?php echo $i; ?>" class="input-block-level" value="<?php echo $paid_Fee; ?>" name="othergiven[]" ><?php $payOther+=(int)$paid_Fee; ?></td>
                        <td>
                        <input  readonly='readonly' class='span4' type='text' title='<?php echo $fineAry["reasion"];?>' rel='tooltip' value='<?php echo $fine=$fineAry["fine"];?>'/>
                        <?php $fineTotal+=(int)$fine; ?>
                        </td>
                       <!-- <td><?php $udate=$db->getVal("select udate from installment_fine where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$_GET["id"]."' and reasion='".$iPro["name"]."' and ins_name like '%otherfee%'");
								if(trim($udate)!="")echo date("d-M-Y",strtotime($udate)); ?></td>-->
                        <td>
						<?php 
						if($paid_Fee=="" || $paid_Fee=="0"){  ?><font color="#FF0000">Due</font><?php }else{ ?><font color="#009900">Paid</font><?php } ?>
                        
                        </td>
                        
                      </tr>
                     <?php $i++;} 
					 ?></tbody>
                    </table>
                  </div><?php
					 }
					 echo $db->getErMsg();
					 }?>
                     <div class="half"><center>Miscellaneous fee</center>
                  	<table class="table">
                    <thead>
                        <tr>
                        	<th width="30%">Quater</th>
                           <th width="15%">Given</th>
                            <th width="35%">Date</th>
                            <th width="20%">Status</th>
                        </tr>
                    </thead>
                    <tbody id="tbody" style="border-top:2px solid #F00">
                    	<?php 
					if($_GET["id"]!=''){ 
					 $all_product=$db->getRows("select * from installment_fine where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$_GET["id"]."' and ins_name like '%otherfee%' and reasion not in (select name from otherfee_structure where session='".$_SESSION["user"]["session"]."' and school_id='".$_SESSION["user"]["school_id"]."' and class='".$aryForm["class"]."')");
					 echo $db->getErMsg();
					 //echo"<pre>";print_r($all_product);echo"</pre>";
					  if(is_array($all_product) && count($all_product))
                      {
                        foreach($all_product as $iPro)
                        {
							
							?>
                      <tr>
                         	      <td><input type="hidden" name="idno" value="<?php echo $_GET["id"]; ?>" /><input type="text" placeholder="enter detail" id="reasion<?php echo $i; ?>" readonly class="input-block-level" value="<?php echo $iPro["reasion"]; ?>" name="reasion[]"></td>
                        <td><input type="text" id="givenother<?php echo $i; ?>" class="input-block-level" value="<?php echo $iPro["fine"]; ?>" name="othergiven[]" readonly>
                        
                        <input type="hidden" id="feeother<?php echo $i; ?>" class="input-block-level" value="<?php echo $iPro["fine"]; ?>" name="fee[]" readonly></td>
                        <td><?php $udate=$db->getVal("select udate from installment_fine where school_id='".$_SESSION["user"]["school_id"]."' and idno='".$_GET["id"]."' and reasion='".$iPro["reasion"]."' and ins_name like '%otherfee%'");
								if(trim($udate)!="")echo date("d-M-Y",strtotime($udate));
								$totalOther+=(int)$iPro["fine"];
						$payOther+=(int)$iPro["fine"];  ?> </td>
                        
                        <td><font color="#99CC00">Paid</font></td>
                        
                      </tr>
                     <?php $i++;} 
					 ?>
                      <!--<tr>
                     
                      	<td>Other <?php echo $i; ?></td>
                        <td > <input type="hidden" name="idno" value="<?php echo $_GET["id"]; ?>" />
                        <input type="text" placeholder="enter detail" id="reasion<?php echo $i; ?>" class="input-block-level"  name="reasion[]"></td>
                        <td><input type="text" onkeyup="$('#feeother<?php echo $i; ?>').val(this.value)" id="givenother<?php echo $i; ?>" class="input-block-level" value="" name="othergiven[]" >
                        <input type="hidden" id="feeother<?php echo $i; ?>" class="input-block-level" value="" name="fee[]" ></td>
                        <td></td>
                        <td>---</td>
                      </tr>-->
					 <?php	
					 }else{
					 ?>
                      <!--<tr>
                      <td></td>
                      	<td>Other <?php echo $i; ?></td>
                        <td > <input type="hidden" name="idno" value="<?php echo $_GET["id"]; ?>" />
                        <input type="text" placeholder="enter detail" id="reasion<?php echo $i; ?>" class="input-block-level"  name="reasion[]"></td>
                        <td><input type="text" onkeyup="$('#feeother<?php echo $i; ?>').val($(this).val())" id="givenother<?php echo $i; ?>" class="input-block-level" value="" name="othergiven[]" >
                        <input type="hidden" id="feeother<?php echo $i; ?>" class="input-block-level" value="" name="fee[]" ></td>
                        <td></td>
                        <td>---</td>
                      </tr>-->
					 <?php					 
					 }
					 } ?>
                  	</tbody>
                 </table>
                 </div>
                 <?php $overAllTotal=0;$overAllPay=0;$overAllRemaining=0;$overAllDiscount=0; ?>
                 <table class="table">
                 	<thead>
                    	<tr>
                        	<th>School Fee Description</th>
                            <th>Total Fee</th>
                            <th>Total Paid</th>
                            <th>Total Left</th>
                            <th>Discount</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="first"  style="border-top:2px solid #F00">
                            <th>Total Class Fee</th>
                            <th><?php echo (int)$aryInstall["total"];$overAllTotal+=$aryInstall["total"]; ?></th>
                            <th><?php echo (int)$totalclasspayfee;$overAllPay+=$totalclasspayfee; ?></th>
                            <th><?php echo $rem=(int)($aryInstall["total"]-$totalclasspayfee);$overAllRemaining+=$rem; ?></th>
                           <td><?php echo (int)$aryInstall["discount"];$overAllDiscount+=$aryInstall["discount"]; ?></td>
                       </tr>
                        <tr>
                            <th>Total Transport Fee</th>
                            <th><?php echo (int)$aryInstall["bus"];$overAllTotal+=$aryInstall["bus"]; ?></th>
                            <th><?php echo (int)$totalbuspayfee;$overAllPay+=$totalbuspayfee; ?></th>
                            <th><?php echo $rem=(int)($aryInstall["bus"]-$totalbuspayfee);$overAllRemaining+=$rem; ?></th>
                            <td><?php echo (int)$aryInstall["busdiscount"];$overAllDiscount+=$aryInstall["busdiscount"]; ?></td>
                       </tr>
                       <tr>
                            <th>Total Hostel Fee</th>
                            <th><?php echo (int)$aryHostelInstall["total"];$overAllTotal+=$aryHostelInstall["total"]; ?></th>
                            <th><?php echo (int)$totalhostelpayfee;$overAllPay+=$totalhostelpayfee; ?></th>
                            <th><?php echo $rem=(int)($aryHostelInstall["total"]-$totalhostelpayfee);$overAllRemaining+=$rem; ?></th>
                            <td><?php echo (int)$aryHostelInstall["discount"];$overAllDiscount+=$aryHostelInstall["discount"]; ?></td>
                       </tr>
                       <?php
						$checkextFee=$db->getRows("select * from extrafee_type where school_id='".$_SESSION["user"]["school_id"]."' and session='".$_SESSION["user"]["session"]."' and class='".$aryForm["class"]."'");	
						if(is_array($checkextFee) && count($checkextFee)>0){
							foreach($checkextFee as $chkExtFee){
								$mycheckInstall=$db->getRow("select SUM(fee) as feetotal,SUM(pay) as payfee  from extrafee where idno='".$_GET["id"]."' and type='".$chkExtFee["id"]."'");
								if($mycheckInstall[0]>0){
									?>
									<tr>
                                        <th>Total <?php echo $chkExtFee["type"]; ?></th>
                                        <th><?php echo $chkExtFee["total"];$overAllTotal+=$chkExtFee["total"]; ?></th>
                                        <th><?php echo $mycheckInstall[1]; $overAllPay+=$mycheckInstall[1]; ?></th>
                                        <th><?php echo $rem=(int)($chkExtFee["total"]-$mycheckInstall[1]); $overAllRemaining+=$rem; ?></th>
                                        <td><?php echo 0;//(int)$aryHostelInstall["discount"];$overAllDiscount+=$aryHostelInstall["discount"]; ?></td>
                                   </tr>
									<?php
								}
							}
						}
					   ?>
                       <tr>
                            <th>Total Other Fee</th>
                            <th><?php echo (int)$totalOther;$overAllTotal+=$totalOther; ?></th>
                            <th><?php echo $payOther."+".$fineTotal;$overAllPay+=($payOther+$fineTotal); ?></th>
                            <th><?php echo $rem= (int)($totalOther-($payOther+$fineTotal)); $overAllRemaining+=$rem;?></th>
                            <td><?php echo (int)$OtherSiteTotal; ?></td>
                       </tr>
                        <tr>
                            <th>Total Fine</th>
                            <th><?php echo (int)$schoolFine+$busFine+$hostelFine+$extrafeeFine;$overAllPay+=($schoolFine+$busFine+$hostelFine+$extrafeeFine); ?></th>
                            <th><?php echo (int)$schoolFine+$busFine+$hostelFine+$extrafeeFine;$overAllTotal+=($schoolFine+$busFine+$hostelFine+$extrafeeFine); ?></th>
                            <th><?php echo 0;?></th>
                            <td><?php echo 0; ?></td>
                       </tr>
                       <tr style="border-bottom:2px solid #F00; border-top:2px solid #F00;">
                            <th>OverAll Detail</th>
                            <th><?php echo (int)$overAllTotal; ?></th>
                            <th><?php echo (int)$overAllPay; ?></th>
                            <th><?php echo (int)($overAllTotal-$overAllPay); ?></th>
                            <td><?php echo (int)$overAllDiscount+$OtherSiteTotal; ?></td>
                       </tr>
					 <?php 
                     $session=$db->getRows("select session from session where school_id='".$_SESSION["user"]["school_id"]."' and session!='".$_SESSION["user"]["session"]."'");
					 
                     $my_root=$db->getVal("select is_root from session_idno	where school_id='".$_SESSION["user"]["school_id"]."' and session='".$_SESSION["user"]["session"]."' and idno='".$_GET["id"]."'"); 
                     if(is_array($session) && count($session)>0){
                         foreach($session as $s){
                            $installs=$db->getRow("select * from installment where school_id='".$_SESSION["user"]["school_id"]."' and session='".$s["session"]."' and idno=(select idno from session_idno where session='".$s["session"]."' and is_root=".$my_root.")");
                            $classFee=0;$busFee=0;$classFeePay=0;$busFeePay=0;
                            for($i=1;$i<=15;$i++){
                                $classFee=$classFee+$installs["i".$i];
                                $busFee=$busFee+$installs["b".$i];
                                $classFeePay=$classFeePay+$installs["ip".$i];
                                $busFeePay=$busFeePay+$installs["bp".$i];
                            }
							if(($classFee+$busFee)>($classFeePay+$busFeePay) ){
                            ?>
							<tr style="border-top:2px solid #090">
                                <th>Remainin Class Fee for <?php echo $s["session"]; ?></th>
                                <th><?php echo $installs["total"]; ?></th>
                                <th><?php echo $classFeePay; ?></th>
                                <th><?php echo (int)($installs["total"]-$classFeePay); ?></th>
                                <td>Login with <?php echo $s["session"]; ?> session to pay fee</td>
                           </tr>
                           <tr>
                                <th>Remainin Bus Fee for <?php echo $s["session"]; ?></th>
                               <th><?php echo $installs["bus"]; ?></th>
                                <th><?php echo $busFeePay; ?></th>
                                <th><?php echo (int)($installs["bus"]-$busFeePay); ?></th>
                                <td>Login with <?php echo $s["session"]; ?> session to pay fee</td>
                           </tr>
							<?php
							}
                         }
                     }
                     ?>
                 	</tbody>
                 </table>
            </div>
    </div>
  </div>
</div>
<!-- / Forms -->
<?php
}
?>