<style>

.popup-form{
	margin:0px;
	border:2px solid #600;
	padding:5px;
}
.title{
  text-align: center;
  color: #fff;
  background-color: #1443BD;
  padding: 4px;
  border: 1px inset #1443BD;
  box-shadow: 0px 0px 10px #050101;
  border-radius: 5px;
}
.btn-new{
  background-color: #05967A;
  color: #fff;
  border: 2px outset #05967A;
  padding: 4px 15px;
  font-weight: 700;
  border-radius: 5px;
  box-shadow: 0px 2px #352E2E;
}
.btn-delete{
  background-color: #CA1A1A;
  border: 2px outset #CA1A1A;
  box-shadow: 1px 3px #322C2C;
  color: #fff;
  padding: 4px 15px;
  font-weight: 700;
  border-radius: 5px;
}
.select-text{
	padding: 3px;
  border: 2px solid #747171;
  color: #380303;
  font-weight: 600;
}
.level, .btn-new, .btn-delete{
	margin-left: 10px;
  margin-right: 5px;
}
</style>
<?php
if($_POST){
	
	
		$saveAry=array("idno"=>$_GET["id"],
						"amount"=>$_POST["amount"],
						"type"=>$_POST["name"],
						"date"=>$_POST["udate"],
						"detail"=>$_POST["detail"],
						"session"=>$_SESSION["admin"]["session"],
						"school_id"=>$_SESSION["admin"]["school_id"],
						"added_by"=>$_SESSION["admin"]["uid"]);
						//if(isset($_POST["udate"]))$saveAry["date"]=$_POST["udate"];
		$db->insertAry("extra_amount",$saveAry);
		echo "Record Save Successfully<br>".$db->getErMsg();
		
}

$aryForm=$db->getRow("SELECT * FROM student WHERE school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET['id']."'");
?>
<link rel="stylesheet" href="<?php echo URL_ROOT; ?>js/jquery-ui.css">
<script src="<?php echo URL_ROOT; ?>js/jquery-1.10.2.js"></script>
<script src="<?php echo URL_ROOT; ?>js/jquery-ui.js"></script>
<script>
var add_tr='<tr id="row_1"><td ><input type="text" class="st-forminput" style="width:86%;" name="attr_month[]" /></td><td ><textarea type="text" class="st-forminput" style="width:86%;" name="attr_name[]" ></textarea></td><td><input type="text" class="st-forminput" style="width:90%;" name="attr_value[]" /></td><td><a class="delete" href="javascript:;">X</a></td></tr>';
$(document).ready(function(){
	$("#add").click(function(){
		$("#tbody").append($(add_tr));
	
		$('#tbody td a.delete').on('click',function() { 
			var rowCount = $('#tbody tr').length;
			if(rowCount<=1){
				//alert("This item cannot deleted !!!");
			}else{
				$(this).parent().parent().remove(); 
			}
		});	
	});
});
function fetchDetail(ids){
	var values=$(ids).val();
	 $.getJSON("ajax.php?type=getValByRecepit&id="+values, function(field){
		 //alert(field.month)
		$("#month").val(field.month)
		$("#name").val(field.name)
		$("#value").val(field.value)
    });
}
$(function() {
	$(".datepicker").each(function(index, element) {
        var d = new Date(); // for now
		datetext=d.getHours()+": "+d.getMinutes()+": "+d.getSeconds();
		$( this ).datepicker({
		  changeMonth: true,
		  changeYear: true,
		  showOn: "button",
		  buttonImage: "<?php echo URL_ROOT ?>js/images/calendar.gif",
		  buttonImageOnly: true,
		  buttonText: "Select date",
		  dateFormat: 'yy-mm-dd ',
		  onSelect: function(datetext){
			var d = new Date(); // for now
			datetext=datetext+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
			$(this).val(datetext);
		  }
		});
    });
});
</script>

<h2 class="title">Cheque Detail</h2>
<form method="post" action="">
<table border="2">

    <tr>
        <th>S.No.</th>
        <th>Cheque No</th>
        <th>Cheque Date</th>
        
        <th>Bank Name</th>
        <th>Branch Name</th>
        <th>Receipt No</th>
		<th>Cheque Amount</th>
		<th>Status</th>
		<th></th>
		
    </tr>
	<?php  
	
	
	$cheque=$db->getRows("select * from chequefee where  idno='".$_GET[id]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
	
	$i=0;
foreach($cheque as $chequ){ $i++;
	$id=$chequ['id'];
?>
    <tr>
         <td><?= $i; ?></td>       
         <td><?= $chequ['number'];?></td>       
         <td><?= $chequ['udate'];?></td>       
         <td><?= $chequ['bankname'];?></td>       
         <td><?= $chequ['bankno'];?></td>       
         <td><?= $id; ?></td>       
         <td><?= $chequ['amount']; $total+=$chequ['amount']; ?></td>
       <td>
       	    <?php if(!empty($chequ['cheque_status'])){?>
		   <select id='status<?= $id?>'>
		  
		   
		   
       	   	     <option <?php if($chequ['cheque_status']=='Pending') echo 'selected'?>  >Pending</option>
       	   	     <option <?php if($chequ['cheque_status']=='Bounce') echo 'selected'?>>Bounce</option>
       	   	     <option <?php if($chequ['cheque_status']=='cleared') echo 'selected'?>>cleared</option>
				 </select>
		   <?php }
            else{
		   ?>
		    <select id='status<?= $id ?>'>
		        <option>Pending</option>
       	   	     <option>Bounce</option>
       	   	     <option>cleared</option>
				  	</select>
			<?php } ?>
       	  
       	   	<?php echo '<a style="float:left" href="javascript:;" id="saveother'.$i.'" onclick="update(\''.$id.'\')"><button type="button" class="btn btn-info">Update</button></a>'; ?>
       </td>
	   <?php 
$hrf="addcheque_receiptNew.php?id=".$chequ[idno]."&amt=".$chequ[amount]."&ch_no=".$chequ[number]."&rno=".$id."&bank=".$chequ[bankname];
?>
<td>&nbsp;<a style="background: firebrick;color: white;height: 26px;width: 53px;border: 2px inset snow;"  class="btn btn-info"    href="<?= $hrf ?>" >Print</td>
  
    </tr>
<?php } ?>

   <tr>
        <td colspan="6">Total Amount</td>
		<td><?= $total ?></td>
    </tr>
	
</table>
</form>
<script type="text/javascript">
	// update_back_dues start--------
function update(id){	
	//alert(id);
	var sta = $('#status'+id).val();
			
$.post( "ajax.php", {type: "cheque_status" ,	
								cheque_s: sta,
								id:id} , function( data ) {
									alert(data);
																		
		});
}

// update_back_dues end
</script>