<?php
$PageSecurity = 11;
//echo $_SERVER['QUERY_STRING'];exit;
include('includes/session.inc');
include('includes/function_lib.php');

//print_r($_GET['Category']); die;
 if(isset($_GET['Category']))
{
		echo $type=$_GET['Category'];
	 
	 $strChar = "";
	 $sql='select vendor_code from suppliers where category="'.$type.'" order by vendor_code desc limit 0,1';
	 $result = DB_query($sql,$db);
	 $numrows = DB_num_rows($result);
	 if($numrows>0)
	 {
			 $i=0;
			 $strmax = "";
			while($myrow=DB_Fetch_array($result))
			{
			    //print_r($myrow); 
				if($myrow['vendor_code']!="")
				{
					$val= substr($myrow['vendor_code'],1);
					$strChar = substr($myrow['vendor_code'],0,1);
					 
					
					 if($val!="")
					 {
						 $arr[$i] = $val;
						 $i++;
					}
				}
				
			}
			if(is_array($arr))
			{ 
				$maxval =  max($arr);
			}
			else
			{
				$maxval=0;
			}
			
	        $strFinal = $maxval+1;
			$strBothFinal = $strChar.str_pad($strFinal,4,"000",STR_PAD_LEFT);
		   //echo $strBothFinal ; 
			echo '<div id="SupplierID"><input type="text" name="vendor_code" value="'.$strBothFinal.'" readonly="readonly"></div>';
	 }
 else
	 {   
		if($type == "Expenses")
		    {
			  echo '<div id="SupplierID"><input type="text" name="vendor_code" class="cap"  value="E0001" readonly="readonly"></div>';
			}
		else if($type == "SiteVendor")
		    {
			  echo '<div id="SupplierID"><input type="text" name="vendor_code" class="cap"  value="L0001" readonly="readonly"></div>';
			}
		else if($type == "HeadOfficeVendor"){ echo '<div id="SupplierID"><input type="text" name="vendor_code" class="cap"  value="H0001" readonly="readonly"</div>'; }
		else
		{
			echo '<div id="SupplierID"><input type="text" name="vendor_code" class="cap"  value="" readonly="readonly"</div>';
		}
	 }	 
	 
	
}
if(isset($_GET['q']))
{ $vid= $s->GetFieldValue('accountledger',"AccountsID='".$_GET['q']."'" ,'vender_client');
$ledgertype= $s->GetFieldValue('accountledger',"AccountsID='".$_GET['q']."'" ,'ledgertype');
if($ledgertype=='vendor')
{
$code= $s->GetFieldValue('suppliers',"id='".$vid."'" ,'vendor_code');

}else{
$code= $s->GetFieldValue('clientmaster',"id='".$vid."'" ,'client_code');

}
			echo " <input type='text' name='mst_ledger_code'    value='".$code."' readonly='readonly' >";

}


?>
