<?php $PageSecurity = 11;
include('includes/session.inc');
include('includes/function_lib.php');
include('includes/SQL_CommonFunctions.inc');

//echo $_REQUEST['q'];
 // echo $_GET['q'] .$_GET['led'];
 //echo "select *  from receiptbankcheckissue where ledger_id='".$_GET['q']."' and status='0'";
 
if($_REQUEST['VPREFIXTYPE']=='3')
{?>
<input type="text" name="banks_checkno"  id="banks_checkno" style="width:150px;" value="<?php echo $banks_checkno; ?>"  />
<?php }
else
{
if($_REQUEST['q']!='0'){
$data=array();
$explo1=array();


$ResultData=DB_query("select *  from receiptbankcheckissue where ledger_id='".$_REQUEST['q']."' and status='0'",$db);

if(DB_num_rows($ResultData)>0)
{
//$DBallSQL=DB_query("select *  from receiptbankcheckissue where ledger_id='".$_REQUEST['q']."' and status='0' order by id ASC limit 0,1",$db);
//$AllchkNoStart=DB_fetch_array($DBallSQL);
//
//
//$DBallSQL1=DB_query("select *  from receiptbankcheckissue where ledger_id='".$_REQUEST['q']."' and status='0' order by id DESC limit 0,1",$db);
//$AllchkNoEnd=DB_fetch_array($DBallSQL1);



while($RowData = DB_fetch_array($ResultData))
{
$data[]=array("fist"=>$RowData['checkno_from'],"last"=>$RowData['checkno_to'],"used"=>$RowData['curr_check_no'],"cancel"=>$RowData['cancel_check_no'],"id"=>$RowData['id']);
}


//echo $explo1;

?>
<select name="banks_checkno" id="banks_checkno">

<?php
$t=array(); 
foreach($data as $key1=>$valu1)
{
$explo1=explode(",",$valu1['used']);
$explo2=explode(",",$valu1['cancel']);
$explo3=array_merge($explo1,$explo2);
for($i=$valu1['fist'];$i<=$valu1['last'];$i++)
{
 if (in_array($i,$explo3)) 
 {
 }
 else
 {
 if(empty($t))
 $t[0]=$i;
 
 }
 }
 }
 //print_r($t);
?>
	<option value="<?php echo $t[0]; ?>"><?php echo $t[0]; ?></option>
<?php 
 //} 
 //} 
//}
?>
</select>
<input type="hidden" name="ledgertID" id="ledgertID" value="<?php echo $_REQUEST['q']; ?>" />
<?php 
}
else
{?>
	<input type="text" name="banks_checkno"  id="banks_checkno" value="<?php echo $banks_checkno; ?>"   />
<?php	
} 
	}
	else
	{?>
<input type="text" name="banks_checkno"  id="banks_checkno" value="<?php echo $banks_checkno; ?>"  />
<?php } 

}?>