<?php
$PageSecurity = 2;
include('includes/session.inc');
$title = _('View/Search Items') ;
include('includes/SQL_CommonFunctions.inc');
if($_REQUEST['q']!='')
{
$sql="select StockID,item_name from item_master where SubCategoryID='".$_REQUEST['q']."' ";
$result=DB_query($sql,$db);
?>
<select name="item" id="item">
<option value="0">Select</option>
<?php 
while($row3=DB_fetch_array($result)){
?>  
<option value="<?php echo $row3['StockID'];?>"><?php echo $row3['StockID']." - ".$row3['item_name'];?></option>
<?php }?>
</select>
<?php } ?>
<?php 
if($_REQUEST['subcat']!='')
{
	?>
<div style="overflow:auto; height:150px; width:100%; border:1px solid; " >
	<?php 
	if($_REQUEST['sub']=='0'){$item_sql11=DB_query("select StockID,item_name from item_master",$db);}
	else
	{$item_sql11=DB_query("select StockID,item_name from item_master where SubCategoryID='".$_REQUEST['subcat']."'",$db); }
	$c4=0;
	while($row11=DB_fetch_array($item_sql11))
	{//echo $c4;?>
	<input type="checkbox" name="item[<?php echo $c4;?>]" id="item_<?php echo $c4;?>" value="<?php echo $row11['StockID'];?>" /><?php echo $row11['StockID']." - ".$row11['item_name'];?><br />
	<?php 	
	$c4++;
	}
	?>
	</div>
<?php  } 
if($_REQUEST['partName']!='')
{
	if($_REQUEST['site']=='' || $_REQUEST['site']=='0' || $_REQUEST['store']=='')
	{
		echo "<div style=\"padding:6px; border:1px solid;\">Select site and store first.</div>";
		exit;
	}
	$query="Select item_master.id,item_master.StockID,item_master.item_name
	        from item_master
	        where item_master.item_name like '%".$_REQUEST['partName']."%'
	        and exists (
	        	select 1
	        	from opening_stockitemwise
	        	where opening_stockitemwise.itemcode = item_master.id
	        	and opening_stockitemwise.site = '".$_REQUEST['site']."'
	        	and opening_stockitemwise.store = '".intval($_REQUEST['store'])."'
	        	and opening_stockitemwise.stock > 0
	        )
	        order by item_master.item_name";
?>
<div style="overflow:auto; height:100px; width:100%; border:1px solid; " >
	<?php 
	$item_sql=DB_query($query,$db);
	$c3=0;
	while($row3=DB_fetch_array($item_sql))
	{ 	
		 $c3='';
		 if($_REQUEST['item'][$c3]==$row3['StockID'])
		 {$c3="checked";}
	?>
	<input type="checkbox" name="item[<?php echo $c3;?>]" id="item_<?php echo $c3;?>" value="<?php echo $row3['id'];?>" <?php echo $c3;?>/><?php echo $row3['StockID']." - ".$row3['item_name'];?><br />
	<?php 	
	$c3++;
	}
	?>
	</div>
<?php 	
}
else if($_REQUEST['ledgerPartName']!='')
{
	
	?>
<select name="item" id="" style="width:100%" onchange="get_batch(this.value);" >
<option value="0">Select</option>
    <?php 
	$itemSql=DB_query("Select id,StockID,item_name from item_master where item_name like '%".$_REQUEST['ledgerPartName']."%'",$db);
	while($itemRow=DB_fetch_array($itemSql))
	{?>
    	<option value="<?php echo $itemRow['id'];?>"><?php echo $itemRow['StockID']." - ".$itemRow['item_name'];?></option>
	<?php 	
	}
	?>
    	
    </select>
<?php 		
}
?>
