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

<link href="css/professional/default.css" rel="stylesheet" type="text/css" />
<table width="100%" border="0" style="border:1px solid #333333;" align="right" cellspacing="0" cellpadding="3">
<tr>
	<td><strong>Item Code/Name</strong></td>
	<td><input name="StockID" type="text" id="StockID" style="width:150px;" onkeyup="getItems(this.value)" /></td>
	<td><strong>Main category </strong></td>
	<td><select style="width:150px;" 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 /><br />
<form name="form1" action="" method="post">
<table width="100%" border="0" style="border:1px solid #333333;" align="right" cellspacing="0" cellpadding="3">
<tr style="height:30px;">
	<td style="border-bottom:1px solid #FF0000;"><strong>Select</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>Item Code</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>Item Name</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>Item Description</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>UOM</strong></td>
	<td style="border-bottom:1px solid #FF0000;"><strong>Stock Bal</strong></td>
</tr>
<?php  $sql=DB_query("Select id,StockID,item_name,item_desc,mst_unitid,mrp_rate,net_rate from item_master where CompanyId='".$_SESSION['ACGCompanyId']."'",$db); 
$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=$tot;
?>
<tr bgcolor="#c1c1c1">
	<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  $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><strong><?php echo $myrow['StockID'];?></strong></td>
	<td><?php echo  $myrow['item_name'];?></td>
	<td><?php echo $myrow['item_desc'];?></td>
	<td><?php $unit=$s->getField('unitsofmeasure','unitid',$myrow['unit'],'unitname'); echo $unit;?></td>
	<td><?php echo $total_current; ?></td>
</tr>
	<?php $i++;} }?>
 </table>
</form>
<script language="javascript" type="text/javascript">
//function getItemsList(id,code,shade,desc,netrate,mrprate,stock,ctr)
//{
//	var dup='empty';
//	var itemcount=parseInt(window.opener.document.getElementById('hiditemcount').value)+1;
//	alert(itemcount);
//	var edit_cnt=window.opener.document.getElementById('count1').value;
//	//alert(edit_cnt);
//	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 WE CHECK THE CHECK BOX FOR SELECT ANY ITEM***********************START HERE******************************************
//	
//	if(document.getElementById("row_id_"+ctr).checked==true)
//	{
//		if(window.opener.document.getElementById('itemid').value=='')
//		{
//			if(edit_cnt=='')
//			{
//				var counter=0;
//			}
//			for(var j=0; j<counter; j++)
//			{
//				if(window.opener.document.getElementById('itemid1_'+j).value==id)
//				{
//					alert("Duplicate Value"); 
//					document.getElementById("row_id_"+ctr).checked=false;
//					var dup = "dup";
//					break;
//				}
//			}
//			if(dup=='empty')
//			{
//				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('total_stock').value = stock;
//				window.opener.document.getElementById('itemdesc').value = desc;	
//				window.opener.document.getElementById('price').value = netrate;
//				window.opener.document.getElementById('mrpper').value = mrprate;
//			}
//		}
//		else
//		{
//			for(var i=counter; i<=itemcount; i++)
//			{	
//				if(edit_cnt=='')
//				{
//					var counter=0;
//				}
//				for(var j=0; j<counter; j++)
//				{
//					if(window.opener.document.getElementById('itemid1_'+j).value==id)
//					{
//						alert("Duplicate Value"); 
//						document.getElementById("row_id_"+ctr).checked=false;
//						var dup = "dup";
//						break;
//					}
//				}
//				if(window.opener.document.getElementById('itemid').value==id)
//				{
//					alert("Duplicate Value");
//					document.getElementById("row_id_"+ctr).checked=false;
//					break;
//				}
//				if(window.opener.document.getElementById('itemid_'+i).value==id)
//				{
//					alert("Duplicate Value"); 
//					document.getElementById("row_id_"+ctr).checked=false;
//					break;
//				}
//				if(dup=='empty')
//				{				
//					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('total_stock_'+i).value = stock;
//						window.opener.document.getElementById('itemdesc_'+i).value = desc;	
//						window.opener.document.getElementById('price_'+i).value = netrate;
//						window.opener.document.getElementById('mrpper_'+i).value = mrprate;	
//						break;
//						break;
//					}
//					else
//					{
//						continue;
//					}
//				}
//			}
//		}
//	}
//	
////IF WE CHECK THE CHECK BOX FOR SELECT ANY ITEM***********************END HERE******************************************
//
//
////IF WE UNCHECK THE CHECK BOX FOR DESELECT ANY ITEM***********************START HERE******************************************
//	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('total_stock').value='';
//			window.opener.document.getElementById('itemdesc').value = '';
//			window.opener.document.getElementById('price').value = '';
//			window.opener.document.getElementById('mrpper').value = '';
//		}
//		else
//		{
//			for(var 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('total_stock_'+i).value='';
//					window.opener.document.getElementById('itemdesc_'+i).value = '';	
//					window.opener.document.getElementById('price_'+i).value = '';
//					window.opener.document.getElementById('mrpper_'+i).value = '';
//				}
//			}
//		}
//	}
////IF WE UNCHECK THE CHECK BOX FOR DESELECT ANY ITEM***********************END HERE******************************************
//}

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>
