<?php $PageSecurity = 5;
include('includes/session.inc');
if($_REQUEST['site']!=''){
$sql="Select prefix from locations where loccode='".$_REQUEST['site']."'";
$res=DB_query($sql,$db);
$row=DB_fetch_array($res);
$branchPrefix=$row['prefix'];

$importnosql="Select orderDigit from import_purchaseorder where site='".$_REQUEST['site']."' order by orderDigit desc limit 1";
$importnoResult=DB_query($importnosql,$db);

if(DB_num_rows($importnoResult)>0)
{
	$importNo_row=DB_fetch_array($importnoResult);
	$importDigit=$importNo_row['orderDigit'];
	$importDigit_brk=substr($importDigit,-4);
	$next222=$importDigit_brk+1;
	$next=str_pad($next222,4,"0",STR_PAD_LEFT);
	
}
else
{
	$next="0001";
}
?>
<input name="orderPrefix" type="text" id="orderPrefix" value="<?php echo "IMPO/".$branchPrefix;?>" size="7" />
-		  <input name="orderDigit" type="text" id="orderDigit" value="<?php echo $next;?>" size="5" />
<?php } 
if($_REQUEST['billsite']!='')
{
$sql="Select prefix from locations where loccode='".$_REQUEST['billsite']."'";
$res=DB_query($sql,$db);
$row=DB_fetch_array($res);
$branchPrefix=$row['prefix'];

$billnosql="Select billDigit from import_billbook where site='".$_REQUEST['billsite']."' order by billDigit desc limit 1";
$billnoResult=DB_query($billnosql,$db);

if(DB_num_rows($billnoResult)>0)
{
	$billNo_row=DB_fetch_array($billnoResult);
	$billDigit=$billNo_row['billDigit'];
	$billDigit_brk=substr($billDigit,-4);
	$next222=$billDigit_brk+1;
	$next=str_pad($next222,4,"0",STR_PAD_LEFT);
	
}
else
{
	$next="0001";
}
?>
<input name="billPrefix" type="text" id="billPrefix" value="<?php echo "IMBB/".$branchPrefix;?>" size="7" />
-		  <input name="billDigit" type="text" id="billDigit" value="<?php echo $next;?>" size="5" />
<?php 
}
?>