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

?>

<link href="css/professional/default.css" rel="stylesheet" type="text/css" />
<h2 align="center">SEARCH ITEMS</h2>

<form name="form1" action="" method="post">
<input type="hidden"  name="acgteephonicitems"  id="acgteephonicitems" value=""/>
  <table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
  <tr>
  	<th width="5%"><strong>SELECT</strong></th>
    <th width="20%"><strong>ITEM CODE</strong></th>
	<th width="20%"><strong>ITEM/SHADE NAME</strong></th>
	<th width="35%"><strong>ITEM DESCRIPTION </strong></th>
	<th width="20%"><strong>UNIT</strong></th>
	<th width="20%"><strong>Stock Bal</strong></th>
	</tr>
  </table>

<div style="overflow: scroll; height: 300px" id="ItemListDiv">
	<?php  $sql=DB_query("Select * from item_master where CompanyId='".$_SESSION['ACGCompanyId']."' ",$db); ?>
	<table width="100%" border="0" cellspacing="3" cellpadding="2" align="center">
	<?php	$i=0;
	if(DB_num_rows($sql)>0)
	{
		while($myrow=DB_fetch_array($sql))
	  	{ 	
		 $parameter=$myrow['id'];
		 
		   
		 $data1='';
		 
		$unit=DB_query("select * from  unitsofmeasure 
		where unitid ='".$myrow['mst_unitid']."'  ",$db);
		$numrow=DB_num_rows($unit);
		if($numrow>0)
		{
						   while($unit_row=DB_fetch_array($unit))
						   {
						   $data1.="<option value=".$unit_row['unitid'].">".$unit_row['unitname']."</option>";
						   }
		 
		 }
		 else
		 {
		 $unit=DB_query("select * from  unitsofmeasure",$db);
		 while($unit_row=DB_fetch_array($unit))
		 {
		 $data1.="<option value=".$unit_row['unitid'].">".$unit_row['unitname']."</option>";
		 }
		 }
		 
		
		 
		 
		 
		 
		 
		 
  ?>
 <tr bgcolor="#CCCCCC">
      <td width="9%"><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  $myrow['item_name'];?>','<?php echo $myrow['net_rate'];?>','<?php echo $data1; ?>','<?php echo $i;?>')"/></td>
      <td width="20%"><strong><?php echo $myrow['StockID'];?></strong></td>
	     <td width="20%"><?php echo  $myrow['item_name'];?></td>
      <td width="35%"><?php echo $myrow['item_desc'];?></td>
      <td width="20%"><?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['mst_unitid'],'unitname'); echo $unit;?></td>
      <td width="22"><?php echo $total_current; ?></td>
	 
    </tr>
<?php $i++;} }?>
 </table>
</div>
</form>
</table>
<script language="javascript" type="text/javascript">
function getItemsList(id,code,shade,mrprate,data11,ctr)
{
	
	if(window.opener.document.getElementById('hiditemcount1').value!='')
	var itemcount=parseInt(window.opener.document.getElementById('hiditemcount1').value)+1;
	else
	var itemcount=1;
	var edit_cnt=window.opener.document.getElementById('edit_cnt1').value;
	if(edit_cnt=='')
	{
	var counter=1;
	} 
	else if(edit_cnt>itemcount)
	{
	var counter=edit_cnt;
	var itemcount=parseFloat(counter)+parseFloat(itemcount);
	} 
	else  
	{
	var counter=edit_cnt;
	}
	if(document.getElementById("row_id_"+ctr).checked==true)
	{
	
	for(i=counter; i<=itemcount; i++)
	{
	
	if(window.opener.document.getElementById("hardwareid_"+i))
	{
	if(window.opener.document.getElementById('hardwareid_'+i).value=='')
	{
			window.opener.document.getElementById('hardwareid_'+i).value = id;
			window.opener.document.getElementById('hardwarecode_'+i).value = code;
			window.opener.document.getElementById('hardwarename_'+i).value = shade;
			window.opener.document.getElementById('hardwareunit_'+i).innerHTML = data11;	
			window.opener.document.getElementById('hrdprice_'+i).value = netrate;
		break;
	}
	}
	else
	{
	continue;
	}
	
	}}
	else
	{
	for(i=counter; i<itemcount; i++)
	{
	if(window.opener.document.getElementById("hardwareid_"+i))
	{
	if(window.opener.document.getElementById('hardwareid_'+i).value==document.getElementById("row_id_"+ctr).value)
	{
			window.opener.document.getElementById('hardwareid_'+i).value = '';
	window.opener.document.getElementById('hardwarecode_'+i).value = '';
	window.opener.document.getElementById('hardwarename_'+i).value = '';
	window.opener.document.getElementById('hardwareunit_'+i).innerHTML = '';	
	window.opener.document.getElementById('hrdprice_'+i).value = '';
	}
	}
	else
	{
	continue;
	}
	}
	//alert('false123');
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

}




function getdata1(str)
{  
	var xmlhttp;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	var data=xmlhttp.responseText.split("__");	 
	document.getElementById("ItemListDiv").innerHTML=data[0];
	//document.getElementById("subcategory1").innerHTML=data[0];
	}
	}
	xmlhttp.open("GET","item_list_ajax.php?site="+str,true);
	xmlhttp.send();
	//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
}	


</script>
