<?php
$PageSecurity = 11;
//echo $_SERVER['QUERY_STRING'];exit;
//print_r($_GET['itemcode']);
include('includes/session.inc');
include('includes/function_lib.php');
if(isset($_GET['q']))
{ 
     $type=$_GET['q'];
	$idx=explode(' ',$type);
for($i=0;$i<count($idx);$i++)
	{
	     $prefix_type[$i]=substr($idx[$i], 0, 3);
	}
	 
	  $prefix_type1=implode("-",$prefix_type);
//echo 	 $prefix_type=	 $s->GetFieldValue('stockcategory',"id='".$type."'" ,'item_prefix');

 	  $sql='select * from desigmaster where designame="'.$type.'" order by designame desc limit 1';
	  $result = DB_query($sql,$db);
	
	   $numrows = DB_num_rows($result);
	  if($numrows >0 )
	 {
			 $i=0;
			 $strmax = "";
			 $myrow=DB_Fetch_array($result);
			 
			 if($myrow['desigcode'] !='')
			 {
			 
				$len=strlen($myrow['desigcode']);
				$count=$len-4;
					 //$enquiry_row[request_no];
				$en1=substr($myrow['desigcode'],0,$count);					
				$en2=substr($myrow['desigcode'],-2);							
				$next=$en2+1;	
 				
			}
		}
		else
		{
			  $type=$_GET['q'];
			  $idx=explode(' ',$type);
			for($i=0;$i<count($idx);$i++)
			{
	    			 $prefix_type[$i]=substr($idx[$i], 0, 3);
			}
			$next='0001';
	 
				$prefix_type1=implode("-",$prefix_type);
		
	  } 
	 
	$strBothFinal=$prefix_type1.str_pad($next,4,"0",STR_PAD_LEFT);

}
	 
?>
<input name="desigcode"  type="text" id="desigcode" value="<?php echo $strBothFinal; ?>" size="30" readonly="true"/>