<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 	print "<script> alert('Session timed out'); parent.document.location='../../index.php'; </script>";
 	return;
}
include("../../opendb.php");
?>
<head>
<title>ZF</title>
<script type="text/javascript" src="../../scripts/jquery-latest.js"></script>
<link type="text/css" href="../../includes/style1.css" rel="stylesheet" />
<link type="text/css" href="../../css/form.css" rel="stylesheet" />
<script type="text/javascript">
$(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>
    <script>

  
  var chqno1=[];
  var chqno2=[];
  var bnk=[];

    
  function chkno(val,id1)
    {
     if(isNaN(val))
       {
       alert('Invalid Number');
        document.getElementById(id1).value='';
       document.getElementById(id1).focus;
       }
    }
 

  function valid()
    {

   var chkno1=  document.getElementById('stno').value;
   var chkno2=  document.getElementById('endno').value;
   
  var bnk=document.f1.bank.value;
   if((chkno1='')||(chkno2==''))
   {
alert('Enter Cheque No');
return false;
  }
 if(bnk=='none')
  {
  alert('Select Bank/Account No');
  return false;
  }
 }

   

function setvalue(str)
 {



   var k;
      var value="<select name='stno' id='stno' onChange='setvalue1(this.value)'><option value='0' >select</option>";
   
	for(k=1;k<chqno1.length;k++)
          {
                if(bnk[k]==str)
                {
		 value=value+"<option>"+chqno1[k]+"</option>";
                }
          }
	       value=value+"</select>"; 
 
     document.getElementById('chqnotd').innerHTML=value;
 
 }



function setvalue1(str)
 {


     var k;
      var value="<select name='endno' id='endno'>";
   
	for(k=1;k<chqno2.length;k++)
          {
                if(chqno1[k]==str)
                {
		 value=value+"<option>"+chqno2[k]+"</option>";
                }
          }
	       value=value+"</select>"; 
 
     document.getElementById('chqnotd1').innerHTML=value;
 
 }
</script>

     

<body background="../../back_ground.jpg">
<?php include('logo1.php'); ?>
<?php include('top.php'); ?>
<br>
<body>
<center>
<table class="container"><tr><td>
<form name=f1 action='<?print $PHP_SELF;?>' method='post' onSubmit="return valid()">
<table class='form' align='center' width='40%'><tr><th colspan=2  bgcolor='grey'>Cheque Book Cancellation</th></tr>

<td>Bank</td><td><select name='bank' onchange='setvalue(this.value)'><option value='none'>-Select-</option>
<?
 $i=1;
$re=mysqli_query($db,"select * from ledger where (grp='Bank accounts' or grp='Bank O/d') and brcode='$brcode' order by led") or die(mysqli_error());

while($row=mysqli_fetch_row($re))
 {
 print "<option>$row[0]</option>";

 	 $re1=mysqli_query($db,"select * from chq_det where bank='$row[0]' and brcode='$brcode' AND status<>'CANCEL' ") or die(mysqli_error());

	while($row1=mysqli_fetch_row($re1))
 	{ 
  
    print "\n<script>chqno1[$i]='$row1[0]' </script>";
    print "\n<script>chqno2[$i]='$row1[10]' </script>";
     print "\n<script>bnk[$i]='$row1[7]' </script>";
   
    $i++;
 	}
 }
 ?>
</select>
</td></tr>
<tr bgcolor='grey'><th colspan=2>Cheque Number</th></tr>
<tr><td>Staring No.</td><td id='chqnotd'><select name='stno' id='stno'><option >-Select-</option></td></tr>
<!--<tr><td>Ending No.</td><td id='chqnotd1'><select name='endno' id='endno'><option >-Select-</option></td></tr>-->
<tr><th colspan=2  bgcolor='grey'>Remark</th></tr>
<tr><td >Remark.</td><td><textarea name='remark' ></textarea></td></tr>
<tr><td colspan='2' align='center'><input type='submit' name='save' value='Save'/></td></tr>
</table>
</td></tr></table>

<?
if(isset($_POST['save']))
 {
  $date=date('Y-m-d h:i:s');
  $stno=$_REQUEST['stno'];
  $bank=$_REQUEST['bank'];
  $remark=$_REQUEST['remark'];
  $endno=$_REQUEST['endno'];
  mysqli_query($db,"insert into chq_det (chq_no,chq_dt,brcode,bank,status,remarks,end_chq_no) values('$stno','$date','$brcode','$bank','CANCEL','$remark','')");
   print"<script>alert('Your Selected Cheque has been successfully cancelled');</script>";
   }
?>
