<?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>
<table width="100%" style="border: solid 1px #CCCCCC">
<tr>
<th><strong>Item/Shade Name</strong></th>
<td><input name="StockID" type="text" id="StockID" style="width:99%" onkeyup="getItems(this.value)" />
</td>
<th><strong>Main category </strong></th>
<td>
<select style="width:99%" name="CategoryID" id="CategoryID " onchange="getdata1(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>
</tr>
</table>
<br />
<form name="form1" action="" method="post">
<input type="text"  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 id,StockID,item_name,item_desc,unit,mrp_rate,net_rate from item_master ",$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'];
		 
		 /*$op=openingBalance($function_filter,$myrow['id']);
              //echo "openingBalance"."<br>";
 		      $in_1=receivedMRN($function_filter,$myrow['id']);
          //echo "receivedMRN"."<br>";
 		    $out_1=issueSlip($function_filter,$myrow['id']);
           // echo "issueSlip"."<br>";
		   $out_2=issueSiteToSite($function_filter,$myrow['id']);		
          // echo "issuesitetosite"."<br>";
		   $in_2=receivedSiteToSite($function_filter,$myrow['id']);
		// echo " receivesitetosite"."<br>";
		  $out_3=issueMatarialReturn($function_filter,$myrow['id']);
		 
		   $out_4=Rgpchallan($function_filter,$myrow['id']);
		   $out_5=Nrgp($function_filter,$myrow['id']);
		  $in_3=receivedReturn($function_filter,$myrow['id']);		 
		  //$in_4=return_rejection($function_filter,$myrow['id']);
		   $in_4=Rgpreturn($function_filter,$myrow['id']);
		    $invalue=($op+$in_1[0]+$in_2+$in_3+$in_4);
		
		     $outvalue=($out_1+$out_2+$out_3+$out_4+$out_5);
		  $tot=trim($invalue)-trim($outvalue);*/
		
		
		 $total_current=0;
		 
		 
		 
		 
		 
		 
		 
		 
		 
		 
		 
  ?>
 <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['item_desc'];?>','<?php echo $myrow['net_rate'];?>','<?php echo $myrow['mrp_rate'];?>',<?php echo $total_current; ?>,'<?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['unit'],'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,desc,netrate,mrprate,stock,ctr)
{
	
	var itemcount=parseInt(window.opener.document.getElementById('hiditemcount').value)+1;
	var edit_cnt=window.opener.document.getElementById('edit_cnt').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){
	if(window.opener.document.getElementById('itemid').value=='')
	{
	window.opener.document.getElementById('itemid').value = id;
	window.opener.document.getElementById('itemcode').value = code;
	window.opener.document.getElementById('itemname').value = shade;
		window.opener.document.getElementById('itemdesc').value = desc;	
		window.opener.document.getElementById('total_stock').value = stock;
	window.opener.document.getElementById('price').value = netrate;
	window.opener.document.getElementById('mrpper').value = mrprate;
	
	}
	else
	{
	for(i=counter; i<=itemcount; i++)
	{
	
	if(window.opener.document.getElementById('itemid_'+i).value=='')
	{
	window.opener.document.getElementById('itemid_'+i).value = id;
	window.opener.document.getElementById('itemcode_'+i).value = code;
	window.opener.document.getElementById('itemname_'+i).value = shade;
	window.opener.document.getElementById('itemdesc_'+i).value = desc;	
	window.opener.document.getElementById('total_stock_'+i).value = stock;	
	window.opener.document.getElementById('price_'+i).value = netrate;
	window.opener.document.getElementById('mrpper_'+i).value = mrprate;	
	break;
	}
	else
	{
	continue;
	}
	}
	}}
	else
	{
	if(window.opener.document.getElementById('itemid').value==document.getElementById("row_id_"+ctr).value)
	{
	window.opener.document.getElementById('itemid').value = '';
	window.opener.document.getElementById('itemcode').value = '';
	window.opener.document.getElementById('itemname').value = '';
	window.opener.document.getElementById('itemdesc').value = '';
	window.opener.document.getElementById('total_stock').value='';	
	window.opener.document.getElementById('price').value = '';
	window.opener.document.getElementById('mrpper').value = '';
	}
	else
	{
	for(i=counter; i<itemcount; i++)
	{
	if(window.opener.document.getElementById('itemid_'+i).value==document.getElementById("row_id_"+ctr).value)
	{
	window.opener.document.getElementById('itemid_'+i).value = '';
	window.opener.document.getElementById('itemcode_'+i).value = '';
	window.opener.document.getElementById('itemname_'+i).value = '';
	window.opener.document.getElementById('itemdesc_'+i).value = '';	
	window.opener.document.getElementById('total_stock_'+i).value='';	
	window.opener.document.getElementById('price_'+i).value = '';
	window.opener.document.getElementById('mrpper_'+i).value = '';
	}
	}
	}
	//alert('false123');
	}
	//var data= addRow('dataTable');
	
	
	
}

function addRow(tableID) 
{

	if(document)
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	window.opener.document.getElementById("hiditemcount").value=rowCount;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	
	
	var newcell = row.insertCell(i);
	//newcell.style.background='#e7e7e7';
	newcell.className='tabledata';
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id_hidden = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id_chk = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	window.opener.document.getElementById("stock_perunit_"+rowCount).value='1';
}



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>
