<?php ob_start();
$PageSecurity = 4;
$PageName = 'Add Items';
include('includes/session.inc');
include('includes/function_lib.php');
unset($_SESSION['ACGRequisition-ItemList']);


?>
<link href="css/professional/default.css" rel="stylesheet" type="text/css" />

<?php 
if($_REQUEST['ListItems']!='')
{	 
	$item_array=array();
	$item_array=$_REQUEST['item_issue']; 
 		$_SESSION['ACGRequisition-ItemList']=$item_array;
		
		
 	 if(isset($_SESSION['ACGRequisition-ItemList']))
		$_SESSION['ACGRequisition-ItemList']=array_unique($_SESSION['ACGRequisition-ItemList']);
	
	

	if(!empty($_SESSION['ACGRequisition-ItemList']))
	{
	$itemlist=implode("#",$_SESSION['ACGRequisition-ItemList']);
	$_SESSION['ACGRequisition-ItemList_1']=$itemlist;
	 
	}
	 
	  
if(count($_SESSION['ACGRequisition-ItemList'])==0)
{
	unset($_SESSION['ACGRequisition-ItemList']);
	unset($_SESSION['ACGRequisition-ItemList_1']);
 
}
?>
<script type="text/javascript">
	<?php if($_REQUEST['action']!='Edit'){?>
opener.window.location="index.php?route=Inventory/transation/Issue_slip_add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?> ";self.close();
<?php } else{?>
opener.window.location="index.php?route=Inventory/transation/Issue_slip_add&action=Edit&id=<?php echo $_REQUEST['id'];?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?> ";self.close();

<?php } ?>

</script>
<?php   
}
?>


 <h2 align="center">Search ITEMS</h2>
<form action=" " method="post" >
<table align="center" border="0">
<tr> <td><strong>Item main category </strong></td>
<td>
<?php  

 $item_query="select stockmaincategoryname, stockmaincategoryid from stockmaincategory where stockmaincategoryid != 'FG'   ";
  $res=DB_query($item_query ,$db);
  //echo DB_num_rows($res);
?>
<select name="CategoryID" onchange="showsubcat(this.value);">
	<option value="0">Select</option>
<?php	
		while($item_row1=DB_fetch_array($res))
		{?>
		 <option value="<?php echo $item_row1['stockmaincategoryid'];?>">
		 <?php echo $item_row1['stockmaincategoryname'];?></option>
          <?php 	} ?>
        </select>
		</td>
</tr>
<tr><td><strong>Item sub category</strong></td>
<td ><div id='txtcity'>
<select name="SubCategoryID" id="subcat">
<option value="0">Select</option>
</select></div></td>
</tr>
<tr><td><strong>Item code</strong></td>
  <td><input name="StockID" type="text" id="StockID" size="25" /></td>
  </tr>
<tr><td colspan="2"><input type="submit" value="Show" name="submit" /></td></tr>
</table></form>
<?php 

if(isset($_POST['submit']))
{
 
		$filter="1=1 ";
		$CategoryID=$_REQUEST['CategoryID'];
		$SubCategoryID=$_REQUEST['SubCategoryID'];
		$StockID=$_REQUEST['StockID'];
 
		 
		if(!empty($CategoryID))
		{
			$filter .=" and CategoryID = '".$CategoryID."'";
		} 
		if(!empty($SubCategoryID))
		{
			$filter .=" and  SubCategoryID = '".$SubCategoryID."'";
		}
		if(!empty($StockID))
		{
			$filter .=" and StockID LIKE '%".$StockID."%'";
		}
		 

			$Sql=" SELECT * FROM item_master where  $filter ";
			}
		
		else{	
  $Sql = "SELECT it.id,it.StockID,it.item_name,it.unit FROM item_master it ";
}
$Result = DB_query($Sql,$db,$ErrMsg);

    echo '<link href="'.$rootpath. '/css/'. $_SESSION['Theme'] .'/default.css" rel="stylesheet" type="text/css" />';

?>

 



<form  action="" method="post">
<input style="margin-left:25px;" type="submit" name="ListItems" id="button" value="Select Items" />


 <div align="center">
  <div style="overflow:auto; width:600px; height:250px">
 <table  width="100%" border="0" cellspacing="0" cellpadding="0"  >
 <tr>
        <th width="25%"><strong>Select</strong></th>
        <th width="35%"><strong>Item Code</strong></th>
        <th width="35%"><strong>Item Name </strong></th>
		<th width="15%"><strong>UOM </strong></th>
		
		<th ><strong>Stock Balance  </strong></th>
        <th ><strong> Opening Stock</strong></th>
		</tr>
  
	
		
  	
	
		
		
	
  <?php   
	  $counter = $_REQUEST['rowcount'];
	  //print_r($counter);
	  $ct = explode("_",$counter);
	 
	  $i=0;
	 	
	  while($myrow =DB_fetch_array($Result))
	  {  
	 // $_SESSION['product_id'] =$myrow['stockid'];
	 		$c=''; 
		 $item_name= $s->GetFieldValue('item_master'," StockID='".$myrow['StockID']."'" ,'item_name');
		 print_r($_SESSION['ACGRequisition-ItemList']);
		  if(isset($_SESSION['ACGRequisition-ItemList']))
		  {
			
			if(in_array($myrow['id'],$_SESSION['ACGRequisition-ItemList']) && count($_SESSION['ACGRequisition-ItemList'])>0) 
			{
					
			  	$c="checked";
 			 	$f=0;
			} 	
		 }	
	 	 $parameter=$myrow['id'];
		// echo "select * from stock_maintenance where itemcode='".$myrow['id']."' and  site='".$_REQUEST['site']."' and store='".$_REQUEST['store']."'";
		
 	  ?>
 	  
	   <tr bgcolor="#FFFFFF">
        <td ><?php //echo $myrow['id'];?>
		<input type="checkbox" name="item_issue[<?php echo $i;?>]" id="item_issue_<?php echo $i;?>"  value="<?php echo $parameter;?>" <?php echo $c; ?>/> </td>
        <td > <?php echo $myrow['StockID'];?> </td>
        <td ><?php echo $item_name;?></td>
		
		<td ><?php  
		 echo $s->GetFieldValue('unitsofmeasure',"unitid='".$myrow['unit']."'",'unitname');
		?></td>
		<td > <?php  echo $s->GetFieldValue('stock_maintenance',"itemcode='".$myrow['id']."' and site='".$_REQUEST['site']."' and store='".$_REQUEST['store']."'",'stockbalance'); ?>	
	      <input name="stock_qty[]" type="hidden" id="stock_qty_<?php echo $i;?>" value="<?php  echo $s->GetFieldValue('opening_stockitemwise',"itemcode='".$myrow['id']."'",'stock');?>"></td>
		  
        <td > <?php  echo $s->GetFieldValue('opening_stockitemwise',"itemcode='".$myrow['id']."' and site='".$_REQUEST['site']."' and store='".$_REQUEST['store']."'",'stock'); ?>	
	      <input name="stock_qty[]" type="hidden" id="stock_qty_<?php echo $i;?>" value="<?php  echo $s->GetFieldValue('opening_stockitemwise',"itemcode='".$myrow['id']."'",'stock');?>"></td>
		  
		  <!--  <td><input type="text" name="item_issue_qty[]"  id="issue_qty_<?php //echo $i; ?>" size="10" onblur="chkbalance(<?php //echo $i; ?>)" value=""/></td> -->
			
			
		</tr>
	  <?php $i++; } ?>
     <input type="hidden" name="row_count" id="row_count" value="<?php echo $i;?>">
   
		
		
		
	</table></div></div>

</form>


<script language="javascript" type="text/javascript">

function chkbalance(str)
{
	
	var k=parseFloat(document.getElementById('issue_qty_'+str).value);
	var j=parseFloat(document.getElementById('stock_qty_'+str).value);
	if(j<k)
	{
	alert("Issue Qty Not Grater then Stock Balance");
	document.getElementById('issue_qty_'+str).focus();
	}

}

function loadValue(str,ct)
{
	var spl = str.split(",");
	var code = spl[0];
	var name = spl[1];
	var makeid = spl[2];
	var makename = spl[3];
	var colorid = spl[4];
	var colorname = spl[5];
	var gradeid = spl[6];
	var gradename = spl[7];
	var uomid = spl[8];
	var uomname = spl[9];
	var received = spl[10];
	var average = spl[11];
	
	if(ct)
	{
		window.opener.document.getElementById('washing_profile_'+ct).value = code;
		window.opener.document.getElementById('desc_'+ct).value = name;
		window.opener.document.getElementById('make_'+ct).value = makename;
		window.opener.document.getElementById('color_'+ct).value = colorname;
		window.opener.document.getElementById('grade_'+ct).value = gradename;
		window.opener.document.getElementById('uom_'+ct).value = uomname;
		window.opener.document.getElementById('Stockbalance_'+ct).value = received;
	}
	else
	{
		window.opener.document.getElementById('washing_profile').value = code;
		window.opener.document.getElementById('desc').value = name;
		window.opener.document.getElementById('make').value = makename;
		window.opener.document.getElementById('color').value = colorname;
		window.opener.document.getElementById('grade').value = gradename;
		window.opener.document.getElementById('uom').value = uomname;
		window.opener.document.getElementById('Stockbalance').value = received;
	}
	window.close();
}
function showsubcat(str)
{
	if (str=="")
	{
		document.getElementById("txtcity").innerHTML="";
		return;
	}
	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)
		{
			document.getElementById("txtcity").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","subcategoryfind.php?site="+str,true);
	xmlhttp.send();
}
</script>


