<?php $PageSecurity = 4;
global  $db;
include('includes/session.inc');
include('includes/function_lib.php');
?>

<link href="css/professional/default.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/new_mxerp.css">
<style type="text/css">
	table tr.row1 {
    background-color: #c1e0c0;
    border: 1px solid #778d77;
    height: 30px;
}
</style>
<div class="body_contain">
<div class="tab_div">
<table width="100%" border="0" align="left" cellspacing="0" cellpadding="3">
<tr class="row1">
	<td width="13%" align="right"><strong>Main Category:</strong></td>
	<td width="35%"><select name="CategoryID" id="CategoryID" onchange="getSubCategory(this.value)">
		<option value="0">Select</option>
		<?php
        $item_query="SELECT * FROM stockmaincategory where CompanyId='".$_SESSION['ACGCompanyId']."'";
		$res=DB_query($item_query ,$db);
		while($item_row1=DB_fetch_array($res)){
		$p='';
		if($item_row1['id'] == $_REQUEST['CategoryID'])	
		$p="selected";?>
		 <option value="<?php echo $item_row1['id'];?>"<?php echo $p;?>><?php echo $item_row1['stockmaincategoryname'];?></option>
       <?php }?>
      </select></td>
  	<td width="13%" align="right"><strong>Sub Category:</strong></td>
  	<td><select name="subcategory" id="srch_subcateory"><option>Select sub group</option></select></td>
</tr>
<tr class="row1">
  	<td align="right"><strong>Item Name:</strong></td>
	<td><input name="StockID" type="text" id="StockID" /></td>
 	<td align="right"><strong>Item Code:</strong></td>
	<td><input name="itenScode" type="text" id="itemScode" /></td>
</tr>
<tr class="row1">
	<td colspan="4" style="text-align:center;"><input type="button" onclick="getdataforSearch()" value="Search" class="search" /></td>
</tr>
</table>

<div id="ItemListDiv" style="width:100%; float:left; margin-top:10px;">
<form name="form1" action="" method="post">
<table width="100%" border="0" style="border:1px solid #808080;" align="LEFT" cellspacing="0" cellpadding="3">
<tr>
	<th width="7%">Select</th>
	<th width="13%">Item Code</th>
	<th>Item Name</th>
	<th width="32%">Item Description</th>
	<th width="9%">UOM</th>	
</tr>
<?php 

$date1=date('Y-m-d');
   $sqlSub='';
       if($_REQUEST['mainCategoryid']!=0)  
        $sqlSub.=" and CategoryID='".$_REQUEST['mainCategoryid']."'";

       if($_REQUEST['subCategoryid']!=0)
       	$sqlSub.=" and SubCategoryID='".$_REQUEST['subCategoryid']."'";

         if($_REQUEST['itemName']!='')
         	$sqlSub.=" and item_name like '".$_REQUEST['itemName']."%'";
         	
         if($_REQUEST['itemScode']!='')
         	$sqlSub.=" and StockID like '".$_REQUEST['itemScode']."%'";	
if($sqlSub!='')
{
	//echo "Select id,StockID,item_name,item_desc,mst_unitid,mrp_rate,net_rate,item_mst_form_rate from item_master where CompanyId='".$_SESSION['ACGCompanyId']."' ".$sqlSub." ";
$sql=DB_query("Select id,StockID,item_name,item_desc,mst_unitid,mrp_rate,net_rate,item_mst_form_rate 
	from item_master where CompanyId='".$_SESSION['ACGCompanyId']."' ".$sqlSub." ",$db); 
$i=0;
if(DB_num_rows($sql)>0)
{
	while($myrow=DB_fetch_array($sql))
	{ 	
		$parameter=$myrow['id'];
		$unit=$s->getField('unitsofmeasure','unitid',$myrow['mst_unitid'],'unitname');
		$vendor=$_REQUEST['vendor']."_suppliers";
      
		 $sql_rate=DB_Fetch_array(DB_query("SELECT B.Net_amount AS itemrate FROM rate_master A 
       	INNER JOIN rate_details B ON A.id=B.Rate_id WHERE B.Item_id='".$myrow['id']."'
       	and  Client_id='".$vendor."'
       	AND '".$date1."' BETWEEN  EffictiveDate AND EffictiveDate_to",$db));
       
        $itemrate=$sql_rate['itemrate'];
?>
<tr bgcolor="#FFF">
	<td><input type="checkbox" name="row_id[<?php echo $i;?>]" id="row_id_<?php echo $i;?>" value="<?php echo $parameter;?>" onclick="getItemsList('<?php echo $parameter;?>','<?php echo $myrow['StockID'];?>','<?php echo   htmlspecialchars($myrow['item_name'], ENT_QUOTES);?>','<?php echo  $unit;?>','<?php echo $i;?>')"/></td>
	<td><?php echo $myrow['StockID'];?></td>
	<td><?php echo  $myrow['item_name'];?></td>
	<td><?php echo $myrow['item_desc'];?></td>
	<td><?php  echo $unit;?></td>	
</tr>
	<?php $i++;} } }?>
 </table>
</form>
</div>

</div>
</div>