<?php 
$pgMod="pay_fee_next";
$pgAct="view";
unset($_SESSION["recept"]);
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);
		

	
if(isset($_SESSION['msg']) && $_SESSION['msg']!="")
{
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0)
{
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}
 
	if(isset($_SESSION['form']))
	{
		$aryForm=$_SESSION['form'];
		unset($_SESSION['form']);
	}
	$aryForm=$db->getRow("SELECT * FROM student WHERE school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
?>
<style>
.st {
	width: 55px;
	display: inline-block;
	color: #021EF0;
}
.recepit {
	width: 717px !important;
	height: 344px !important;
}
.half {
	width: 49%;
	display: inline-block;
	vertical-align: top;
	border-left: 5px solid #f00;
border-right: 5px solid #f00;
}
.half .input-block-level {
	width: 80px;
}
.half .table td {
	padding: 3px 5px;
}
.half center {
	font-weight: bold;
	border-top: 1px solid #f00;
	padding: 5px;
	background-color: #A7A1A1;
	color: #000;
}
</style>
<!-- Forms --> 
<?php
$students=$db->getRows("select * from student");
if(is_array($students) && count($students)>0){
	foreach($students as $stu){
		$_GET["id"]=$stu["idno"];//echo "<pre>";print_r($stu);exit;
		$aryForm=$db->getRow("SELECT * FROM student WHERE school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
?>
<div id="printDiv">		
     <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Student detail</h3>
                <div style="float:right; margin-top:5px;">
                    <a href="javascript:;" onclick="checkRecept('<?php echo $aryForm["class"]; ?>')" class="btn btn-danger">Recepit</a>
                </div>
            </div>
            <div class="well" id="userdetails" style="padding: 0;margin: 0;">
            	<table class="table">
                	<tr style="border-right: 5px solid #f00;border-left: 5px solid #f00;">
                    	<td><strong class="st">Name</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["name"] ?></td>
                        <td><strong class="st">Class</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["class"] ?></td>
                        <td><strong class="st">id no</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["idno"] ?></td>
                        <td><strong class="st">Medium</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["medium"] ?></td>
                        <td rowspan="2"><?php if($aryForm["photo"]!=""){
                        ?><img src="media/photo/<?php echo $aryForm["photo"]; ?>" style="height:70px" /><?php
                    }else{
                        echo "No photo uploaded";
                    }?></td>
                    </tr>
                    <tr style="border-right: 5px solid #f00;border-left: 5px solid #f00;">
                    	<td><strong class="st">DOB</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["dob"] ?></td>
                        <td><strong class="st">Father</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["fname"] ?></td>
                        <td><strong class="st">DOA</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["doa"] ?></td>
                        <td><strong class="st">Contact</strong></td><td style="border-right:5px solid #f00"><?php echo $aryForm["mobile"] ?></li></td>
                    </tr>
                </table>
            </div>
        </div>
     </div> 
     <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Payment detail</h3>
                
            </div>
            <div class="well no-padding">
                    <?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["admin"]["school_id"]."' and session='".$_SESSION["admin"]["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>Quater</th>
                            <th>Amount</th>
                            <th>Amount Given</th>
                            <th width="50px">Late Fee</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th><span class="action">Action</span></th>
                            <th></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["admin"]["school_id"]."' and idno='".$_GET["id"]."' and reasion='".$iPro["name"]."' and ins_name like '%otherfee%'");
							$fineAry=$db->getRow("select fine,reasion,id from installment_fine where school_id='".$_SESSION["admin"]["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["admin"]["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="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='span12' type='text' title='<?php echo $fineAry["reasion"];?>' rel='tooltip' value='<?php echo $fine=$fineAry["fine"];?>'/>
                        <?php if($fineAry["fine"]!="")echo $db->updateAry("installment_fine",array("reasion"=>$iPro["name"])," where id=".$fineAry["id"]); ?>
                        <?php $fineTotal+=(int)$fine; ?>
                        </td>
                        <td><input type="text" id="odate<?php echo $i ?>" class="odate<?php echo $i ?> datepicker span12" value="<?php echo date("Y-m-d H:i:g"); ?>" /></td>
                        <td>
						<?php 
						if($paid_Fee=="" || $paid_Fee=="0"){  ?><font color="#FF0000">Due</font><?php }else{ ?><font color="#99CC00">Paid</font><?php } ?>
                        
                        </td>
                        <td></td>
                        <td></td>
                      </tr>
                     <?php $i++;} 
					 
					 ?></tbody>
                  </table>
                  </div><?php
					  }
					 
					 echo $db->getErMsg();
					 }?>
                  	
                  <div class="half">
                  <center>Misceleanious fee</center>
                  <table class="table">
                    <thead>
                        <tr>
                        	
                            <th>Quater</th>
                            <th>Detail</th>
                            <th>Amount Given</th>
                            <th style="display:none" width="50px">Late Fee</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th><span class="action">Action</span></th>
                            <th></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["admin"]["school_id"]."' and idno='".$_GET["id"]."' and ins_name like '%otherfee%' and reasion not in (select name from otherfee_structure where session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["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>Other <?php echo $i; ?></td>
                        <td><input type="hidden" name="idno" value="<?php echo $_GET["id"]; ?>" />
                        <input style="width:150px" type="text" placeholder="enter detail" id="reasion<?php echo $i; ?>" readonly="readonly" class="input-block-level" value="<?php echo $iPro["reasion"]; ?>" name="reasion[]"></td>
                        <td><input type="text" w id="givenother<?php echo $i; ?>" class="input-block-level" value="<?php echo $iPro["fine"]; ?>" name="othergiven[]" readonly="readonly">
                        <input type="hidden" id="feeother<?php echo $i; ?>" class="input-block-level" value="<?php echo $iPro["fine"]; ?>" name="fee[]" readonly="readonly"></td>
                        <td style="display:none"></td>
                        <td><input type="text" id="odate<?php echo $i ?>" class="odate<?php echo $i ?> datepicker span12" value="<?php echo date("Y-m-d H:i:g"); ?>" /></td>
                        <td><font color="#99CC00">Paid</font></td>
                        <td><?php
                        echo '<a data-class="recepit" href="print/?page_id=recepit&idno='.$_GET["id"].'&udate='.date("d-m-Y").'&amount='.$iPro["fine"].'&type=fee&paytype=extraotherfinefee&detail='.$iPro["reasion"].'&install='.$i.'&class='.$aryForm["class"].'" class="btn btn-danger fancybox">Recepit</button>';
						$totalOther+=(int)$iPro["fine"];
						$payOther+=(int)$iPro["fine"]; 
						?></td>
                        <td>
                        <?php 
						
						$LastQ=$db->getVal("select max(id) from reff_receipt where idno='".$_GET["id"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and type='".$iPro["reasion"]."'");
						if($iPro["fine"]>0){ ?>
                                <input type="checkbox" class="other" name="newRec[]" data-rr="<?php echo $LastQ ?>" value="<?php echo $iPro["fine"]; ?>" /><?php //print_r($recpChkData); ?>
                            <?php }?>
                            </td>
                      </tr>
                     <?php $i++;} 
					 ?>
                      <tr>
                      
                      	<td>Other <?php echo $i; ?></td>
                        <td > <input type="hidden" name="idno" value="<?php echo $_GET["id"]; ?>" />
                        <input style="width:150px" 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 style="display:none"></td>
                        <td><input type="text" id="odate<?php echo $i ?>" class="odate<?php echo $i ?> datepicker span12" value="<?php echo date("Y-m-d H:i:g"); ?>" /></td>
                        <td>---</td>
                        <td><a style="float:left" href="javascript:;" id="saveother<?php echo $i ?>" onclick="payother('<?php echo $i; ?>')"><button type="button" class="btn btn-info">Pay Fees</button></a>
                        <a style="display:none" id="add" href="javascript:;"><button type="button" class="btn btn-info">Add Other</button></a>
                        </td>
                        <td></td>
                      </tr>
					 <?php	
					 }else{
					 ?>
                      <tr>
                      
                      	<td>Other <?php echo $i; ?></td>
                        <td > <input type="hidden" name="idno" value="<?php echo $_GET["id"]; ?>" />
                        <input  style="width:150px" 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><input type="text" id="odate<?php echo $i ?>" class="odate<?php echo $i ?> datepicker span12" value="<?php echo date("Y-m-d H:i:g"); ?>" /></td>
                        <td>---</td>
                        <td><a style="float:left" href="javascript:;" id="saveother<?php echo $i ?>" onclick="payother('<?php echo $i; ?>')"><button type="button" class="btn btn-info">Pay Fees</button></a>
                        <a style="display:none" id="add" href="javascript:;"><button type="button" class="btn btn-info">Add Other</button></a>
                        </td>
                        <td style="display:none"></td>
                      </tr>
					 <?php					 
					 }
					 } ?>
                  	</tbody>
                 </table>
                 </div>
                 <?php $overAllTotal=0;$overAllPay=0;$overAllRemaining=0;$overAllDiscount=0; ?>
                 
                 <?php //echo $db->getErMsg().$db->getLastQuery(); ?>
          </div>
         </div>
    </div>
</div>        
<?php 
	}
}
redirect("?page_id=pay_fee");
?>
<!-- / Forms -->
