<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");
ini_set('max_execution_time', $config['ReportTimeExecution']);

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}


$query1="select grid_color1,grid_color2 from setup";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

}


$post  = $_GET['post'];if ($post == ""){$post = $_POST["post"];}

$PItem_Code  = $_POST["PItem_Code"]; if ($PItem_Code == ""){$PItem_Code = $_GET["PItem_Code"];}
$PItem_Description  = $_POST["PItem_Description"]; if ($PItem_Description == ""){$PItem_Description = $_GET["PItem_Description"];}

if($_GET['icode']!=""){

$query1="select * from items where item_code='".$_GET['icode']."'";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);
//$iccode=$Item_Code.",".$Item_Description;

}
$post="1";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Select Items</title>
<script type="text/javascript" language="javascript">
function postitem(){
x=document.form1;
item1=x.item1.value;
if(item1=="1"){

opener.document.transferitems.p_item_code.value=document.form1.code1.value;
opener.document.transferitems.p_item_quantity.value=document.form1.quantity1.value;
opener.document.transferitems.p_item_quantity1.value=document.form1.quantity1.value;
opener.document.transferitems.p_item_description.value=document.form1.desc1.value;
opener.document.transferitems.p_item_sellingprice1.value=document.form1.price.value;
self.close();
}else if(item1=="2"){
opener.document.transferitems.tocode.value=document.form1.code1.value;
opener.document.transferitems.todesc.value=document.form1.desc1.value;
self.close();
}



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

function clearform()
{
  document.form1.PItem_Description.value='';
  document.form1.PItem_Code.value='';
  document.form1.SCode.value='';

}
</script>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style1 {
	color: #333333;
	font-weight: bold;
}
.style2 {
	color: #999999;
	font-weight: bold;
	font-size: 12px;
}
.style3 {color: #999999}
.style4{
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
-->
</style></head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="800" border="0" align="center">
    <tr>
      <th colspan="6" bgcolor="#DDDDDD"><span class="style1">Search for Item </span></th>
    </tr>
  
   <tr>
   <td bgcolor="#DDDDDD" > <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for Item  <br> Code / Desc.</span></td>
      
        <input name="price" type="hidden" id="price" value="<?php echo $Item_SellingPrice1; ?>"/>
		 <input name="price2" type="hidden"  id="price2" value="<?php echo $Item_SellingPrice1; ?>" size="10"/>
      
      <th bgcolor="#DDDDDD" align='left' colspan='5'><input type="hidden" name="textfield2" value="<?php echo $Item_Code; ?>"  />
	  <input type="text" name="PItem_Code" value="<?php echo $PItem_Code; ?>"  />
        <input name="code1" type="hidden" id="code1"  value="<?php echo $Item_Code; ?>">
		<input name="quantity1" type="hidden" id="quantity1"  value="<?php echo $_GET['quantity1']; ?>">
		<input name="desc1" type="hidden" id="desc1" value="<?php echo $Item_Description; ?>" />
		
	        <input type="text" name="PItem_Description"  value="<?php echo $PItem_Description; ?>" size='35'/>
	        <input type="submit" name="Submit" value="Find" style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>
		</tD><th>
        
      <input name="item1" type="hidden" id="item1" value="<?php echo $_GET['item']; ?>" />
	  <input name="PGroup_Code" type="hidden" id="PGroup_Code"  value="<?php echo $_GET['PGroup_Code']; ?>">
	  </th>
      
    </tr>

	
	              			
      
			

	
<?php if($post=="1") { ?>
<script type="text/javascript" language="javascript">
x=document.form1;
item1=x.item1.value;
if(item1=="1"){
opener.document.transferitems.p_item_code.value=document.form1.code1.value;
opener.document.transferitems.p_item_quantity.value=document.form1.quantity1.value;
opener.document.transferitems.p_item_quantity1.value=document.form1.quantity1.value;
opener.document.transferitems.p_item_description.value=document.form1.desc1.value;
opener.document.transferitems.p_item_sellingprice1.value=document.form1.price.value;
self.close();
}else if(item1=="2"){
opener.document.transferitems.tocode.value=document.form1.code1.value;
opener.document.transferitems.todesc.value=document.form1.desc1.value;
self.close();
}

else if(item1=="3"){
opener.document.items.item_packcode.value=document.form1.code1.value;
opener.document.items.item_packdesc.value=document.form1.desc1.value;
self.close();
}
else if(item1=="4"){
opener.document.items.opt_itemcode.value=document.form1.code1.value;
opener.document.items.opt_itemdesc.value=document.form1.desc1.value;
self.close();
}
</script>
<?php } ?>
    <tr bgcolor="#E5E5E5">
      <td width="110"><span class="style2">Item Code </span></td>
      <td width="411" colspan="2"><span class="style2">Item Description </span></td>
      <td width="108"><span class="style2">Group Code </span></td>
      <td width="108"><span class="style2">Subgroup Code </span></td>
      <td width="108"><span class="style2">Qty Exists </span></td>
    </tr>
<?php
if($withoutitemexists==1)
$query1="select Item_Code,Item_Description,Group_code,SubGroup_Code,
		0 as qtyexists 
		from items where (item_withserialno = 0 or item_withserialno ='')
		and item_active = 1";
else		
$query1="select Item_Code,Item_Description,Group_code,SubGroup_Code,
		QtyExistsWSorder(Item_Code,'".$fromwarehouse."',now(),0,'TR',null,null) as qtyexists 
		from items where (item_withserialno = 0 or item_withserialno ='')
		and QtyExistsWSorder(Item_Code,'".$fromwarehouse."',now(),0,'TR',null,null) > 0
		and item_active = 1";
		
if ($PItem_Code !='')
	$query1 = $query1 ." and item_code like '%".$PItem_Code."%'";
if ($PItem_Description !='')
	$query1 = $query1 ." and Item_Description like '%".$PItem_Description."%'";

if ($_GET['PGroup_Code'] != '')
	$query1 = $query1 ." and items.Group_Code = '".$_GET['PGroup_Code']."'";

if($withoutitemexists==1)	
$query1="select q1.Item_Code,q1.Item_Description,q1.Group_code,q1.SubGroup_Code,q1.qtyexists
		from (
			select Item_Code,Item_Description,Group_code,SubGroup_Code,0 as qtyexists
			from items
			where (item_withserialno = 0 or item_withserialno ='')
			and item_active = 1
		) q1
		where q1.qtyexists > 0 ";
else
$query1="select q1.Item_Code,q1.Item_Description,q1.Group_code,q1.SubGroup_Code,q1.qtyexists
		from (
			select Item_Code,Item_Description,Group_code,SubGroup_Code,QtyExistsWSorder(Item_Code,'".$fromwarehouse."',now(),0,'TR',null,null) as qtyexists
			from items
			where (item_withserialno = 0 or item_withserialno ='')
			and item_active = 1
		) q1
		where q1.qtyexists > 0 ";
		
if ($PItem_Code !='')
	$query1 = $query1 ." and item_code like '%".$PItem_Code."%'";
if ($PItem_Description !='')
	$query1 = $query1 ." and Item_Description like '%".$PItem_Description."%'";

if ($_GET['PGroup_Code'] != '')
	$query1 = $query1 ." and items.Group_Code = '".$_GET['PGroup_Code']."'";
	
$query1="select Item_Code,Item_Description,Group_code,SubGroup_Code
		 from items where 1=1 ";

if($item=="1" or $item=="2"){
	$query1=$query1." and (item_withserialno = 0 or item_withserialno ='') and item_active = 1";
}

if($item=="3" ){
	$query1=$query1." and  ifnull(item_pack,0)=0 ";
}
	
if ($PItem_Code !='')
	$query1 = $query1 ." and item_code like '%".$PItem_Code."%'";
if ($PItem_Description !='')
	$query1 = $query1 ." and Item_Description like '%".$PItem_Description."%'";
	
if ($_GET['PGroup_Code'] != '')
	$query1 = $query1 ." and items.Group_Code = '".$_GET['PGroup_Code']."'";


/*
$query1="select q1.Item_Code as Item_Code,q1.Item_Description as Item_Description,q1.Group_code as Group_code,q1.SubGroup_Code as SubGroup_Code,q1.qtyexists as qtyexists from
(select Item_Code,Item_Description,Group_code,SubGroup_Code,QtyExistsWSorder(Item_Code,'LAG-001',now(),0,'TR',null,null) as qtyexists
from items
where (item_withserialno = 0 or item_withserialno ='')) q1
where q1.qtyexists > 0 ";
*/
/*
$query1=" select Item_Code,Item_Description,Group_code,SubGroup_Code
from items
where (item_withserialno = 0 or item_withserialno ='')";
*/

//echo$query1;
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

$ct+=1;

if($ct%2==0)
{
	$Color="style='font-size:12px;color:#0000FF;background-color:".$grid_color1."'";
	
	}else{
		
	$Color="style='font-size:12px;color:#0000FF;background-color:".$grid_color2."'";	
}

?>
    <tr <?php echo $Color; ?>>
      <td align="left"><a href="list_items.php?item=<?php echo $_GET['item']; ?>&icode=<?php echo $Item_Code; ?>&quantity1=<?php echo $qtyexists; ?>"><span class="style4"><?php echo $Item_Code; ?></span></a></td>
      <td colspan="2"><a href="list_items.php?item=<?php echo $_GET['item']; ?>&icode=<?php echo $Item_Code; ?>&quantity1=<?php echo $qtyexists; ?>"><span class="style4"><?php echo $Item_Description; ?></span></a></td>
      <td align="center"><span class="style4"><?php echo $Group_code; ?>&nbsp;</span></td>
      <td><span class="style4"><?php echo $SubGroup_Code; ?>&nbsp;</span></td>
      <td><span class="style4"><?php echo $qtyexists; ?>&nbsp;</span></td>
    </tr>
<?php
}
?>
  </table>
</form>
</body>
</html>
