<?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']);
	
	
	$transfer_date1=$transfer_date;
	$transfer_date1 =  str_replace(' ','%20',$transfer_date1);
	$data = substr($transfer_date, 6, 4) . substr($transfer_date, 3, 2) . substr($transfer_date, 0, 2);
    $transfer_date = substr($data, 0, 4) ."-". substr($data, 4, 2) ."-".substr($data, 6, 2)." ".strftime("%H").":".strftime("%M").":".strftime("%S");




$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);
}

//Read From Login Table
$querylog=" select ifNull(FI_ShowCostPrice,0) As FI_ShowCostPrice from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

$querygroup=" select distinct group_code,group_name ".
			" from grouping where group_code in (select group_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."') ".
			" order by group_code";
			
$resultgroup = mysql_query($querygroup,$connection) or die(mysql_error());
$groupexist   = mysql_num_rows($resultgroup);


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

}
$i=0;
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 RefreshPage(fromwarehouse,towarehouse,index,fromproject,toproject,actionmode,transfer_id,transfer_date,td,TransType){
	vFrm       = document.form1.frm.value;
	vPerPage   = document.form1.perpage.value;
	
	fromwarehouse = fromwarehouse.replace('&','%26');
	towarehouse = towarehouse.replace('&','%26');
	var item = document.form1.item1.value;
	str1= 'Form_ListItems.php?item='+item+'&index='+index+'&fromwarehouse='+fromwarehouse+'&towarehouse='+towarehouse+'&fromproject='+fromproject+'&toproject='+toproject+'&actionmode='+actionmode+'&transfer_id='+transfer_id+'&transfer_date='+transfer_date+'&td='+td+'&startrange=0&perpage='+vPerPage+'&TransType='+TransType;

	document.form1.action=str1;
	document.form1.submit();
}

function SetNextPage(fromwarehouse,towarehouse,index,fromproject,toproject,actionmode,transfer_id,transfer_date,td,startrange,perpage,TransType){
	vFrm       = document.form1.frm.value;
	var item = document.form1.item1.value;
	str1= 'Form_ListItems.php?item='+item+'&index='+index+'&fromwarehouse='+fromwarehouse+'&towarehouse='+towarehouse+'&fromproject='+fromproject+'&toproject='+toproject+'&actionmode='+actionmode+'&transfer_id='+transfer_id+'&transfer_date='+transfer_date+'&td='+td+'&startrange='+startrange+'&perpage='+perpage+'&TransType='+TransType;	
	document.form1.action=str1;
	document.form1.submit();
}

function SetPrvPage(fromwarehouse,towarehouse,index,fromproject,toproject,actionmode,transfer_id,transfer_date,td,startrange,perpage,TransType){
	vFrm       = document.form1.frm.value;
	var item = document.form1.item1.value;
	str1= 'Form_ListItems.php?item='+item+'&index='+index+'&fromwarehouse='+fromwarehouse+'&towarehouse='+towarehouse+'&fromproject='+fromproject+'&toproject='+toproject+'&actionmode='+actionmode+'&transfer_id='+transfer_id+'&transfer_date='+transfer_date+'&td='+td+'&startrange='+startrange+'&perpage='+perpage+'&TransType='+TransType;	
	document.form1.action = str1;
	document.form1.submit();
}


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;
opener.document.transferitems.action='Form_transferitems.php';
opener.document.transferitems.submit();
self.close();
}else if(item1=="2"){
opener.document.transferitems.tocode.value=document.form1.code1.value;
opener.document.transferitems.todesc.value=document.form1.desc1.value;
opener.document.transferitems.action='Form_transferitems.php';
opener.document.transferitems.submit();
self.close();
}
else if(item1=="3"){ 
var itemcode = 'p_item_code['+index+']';
var qty = 'p_item_quantity['+index+']';
var qty1 = 'p_item_quantity1['+index+']';
var desc = 'p_item_description['+index+']';
var price = 'p_item_sellingprice1['+index+']';
var qtyexists = 'txtAvailableQty['+index+']';

window.opener.document.getElementById(itemcode).value=document.form1.code1.value;
window.opener.document.getElementById(qty).value=document.form1.quantity1.value;
window.opener.document.getElementById(qty1).value=document.form1.quantity1.value;
window.opener.document.getElementById(qtyexists).value=document.form1.qtyexist.value;
window.opener.document.getElementById(desc).value=document.form1.desc1.value;
window.opener.document.getElementById(price).value=document.form1.price.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="900" border="0" align="center">
    <tr>
      <th colspan="10" bgcolor="#DDDDDD"><span class="style1">Search for Item </span></th>
    </tr>
  
   <tr>
   <td bgcolor="#DDDDDD" colspan="2"> <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="Item_UnitSalesDesc" type="hidden" id="Item_UnitSalesDesc" value="<?php echo $Item_UnitSalesDesc; ?>"/>
        <input name="Item_UnitPurchaseDesc" type="hidden" id="Item_UnitPurchaseDesc" value="<?php echo $Item_UnitPurchaseDesc; ?>"/>
        <input name="Item_Unit" type="hidden" id="Item_Unit" value="<?php echo $Item_Unit; ?>"/>
        
		
		<input name="index" type="hidden" id="index" value="<?php echo $index; ?>"/>
		 <input name="price2" type="hidden"  id="price2" value="<?php echo $Item_SellingPrice1; ?>" size="10"/>
		<input type='hidden' name='frm' value='$frm' />     
		<input type='hidden' name='TransType' value='<?php echo $TransType; ?>' />     
      <th bgcolor="#DDDDDD"><input type="hidden" name="textfield2" value="<?php echo $Item_Code; ?>"  />
	  <input type="text" name="PItem_Code" autofocus="autofocus" 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 $quantity1; ?>">
		<input name="qtyexist" type="hidden" id="qtyexist"  value="<?php echo $qtyexist; ?>">
		<input name="desc1" type="hidden" id="desc1" value="<?php echo $Item_Description; ?>" />
		</th>
      
      <td bgcolor="#DDDDDD" colspan="7">
	        <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;'/>
		
        
      <input name="item1" type="hidden" id="item1" value="<?php echo $_GET['item']; ?>" />
 
 <?php 
 
 echo"&nbsp;<span style='font-size: 11px; color: #999999; font-weight: bold;'>Result per page </span><select name='perpage' id='perpage' value='$perpage' onchange=\"RefreshPage('".htmlentities($fromwarehouse)."','".htmlentities($towarehouse)."','".$index."','".htmlentities($fromproject)."','".htmlentities($toproject)."','".$actionmode."','".$transfer_id."','".$transfer_date1."','".$td."',',TransType');\" > ";



        if ($perpage==20)
			$s20 = 'selected';
		else if ($perpage==30)
			$s30 = 'selected';
		else if ($perpage==40)
			$s40 = 'selected';
		else if ($perpage==50)
			$s50 = 'selected';

			
				
        echo"<option ".$s20." value='20'>20</option>
			 <option ".$s30." value='30'>30</option>
			 <option ".$s40." value='40'>40</option>
			 <option ".$s50." value='50'>50</option>
			 </select></tD></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;
opener.document.transferitems.p_item_sellingprice1.value=document.form1.price.value;
opener.document.transferitems.action='Form_transferitems.php?TransType='+document.form1.TransType.value;
opener.document.transferitems.submit();

self.close();
}else if(item1=="2"){
opener.document.transferitems.tocode.value=document.form1.code1.value;
opener.document.transferitems.todesc.value=document.form1.desc1.value;
opener.document.transferitems.p_item_sellingprice1.value=document.form1.price.value;
opener.document.transferitems.action='Form_transferitems.php?TransType='+document.form1.TransType.value;
opener.document.transferitems.submit();
self.close();
}
else if(item1=="3"){

index = document.form1.index.value;
var itemcode = 'p_item_code['+index+']';
var qty = 'p_item_quantity['+index+']';
var qty1 = 'p_item_quantity1['+index+']';
var desc = 'p_item_description['+index+']';
var price = 'p_item_sellingprice1['+index+']';
var itemunit1 = 'Item_Unit['+index+']';
var Item_UnitSalesDesc1 = 'Item_UnitSalesDesc['+index+']';
var Item_UnitPurchaseDesc1 = 'Item_UnitPurchaseDesc['+index+']';

var qtyexists = 'txtAvailableQty['+index+']';

window.opener.document.getElementById(itemcode).value=document.form1.code1.value;
window.opener.document.getElementById(qty).value=document.form1.quantity1.value;
window.opener.document.getElementById(qty1).value=document.form1.quantity1.value;
window.opener.document.getElementById(desc).value=document.form1.desc1.value;
window.opener.document.getElementById(qtyexists).value=document.form1.qtyexist.value;

if (window.opener.document.getElementById(price))
window.opener.document.getElementById(price).value=document.form1.price.value;


if (window.opener.document.getElementById(itemunit1))
window.opener.document.getElementById(itemunit1).value=document.form1.Item_Unit.value;


if (window.opener.document.getElementById(Item_UnitSalesDesc1))
window.opener.document.getElementById(Item_UnitSalesDesc1).value=document.form1.Item_UnitSalesDesc.value;


if (window.opener.document.getElementById(Item_UnitPurchaseDesc1))
window.opener.document.getElementById(Item_UnitPurchaseDesc1).value=document.form1.Item_UnitPurchaseDesc.value;
window.opener.document.getElementById(itemcode).onchange();

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">Remark</span></td>
      <td width="108"><span class="style2">Group Code </span></td>
      <td width="108"><span class="style2">Qty Exists </span></td>
     
	  <?php if($FI_ShowCostPrice == 1) {
	  echo'<td width="108"><span class="style2">Currency </span></td>
      <td width="108"><span class="style2">Last Cost Price </span></td>
      <td width="108"><span class="style2"> '.$base1.' </span></td>
      <td width="108"><span class="style2"> '.$base2.' </span></td>';}
	  ?>
	  
    </tr>
<?php
/*
$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 ($td==''){
$query1="select q1.Item_Code,q1.Item_Description,q1.Group_code,q1.SubGroup_Code,q1.qtyexists,q1.Item_Pack
,q1.Currency_code, q1.item_lastcostprice, q1.item_lastcostpricebase1, q1.item_lastcostpricebase2, Items.Item_Remark as Item_Remark 
from (
select DISTINCT(Item_Code),Item_Description,Group_code,SubGroup_Code,QtyExistsWSorder(Item_Code,'".$fromwarehouse."',now(),0,'TR',null,null) as qtyexists
,Item_Pack,items.Currency_code, item_lastcostprice, item_lastcostpricebase1, item_lastcostpricebase2
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."%' or Items.Item_Remark like '%".$PItem_Description."%') ";
}
else
{
$query1="select q1.Item_Code,q1.Item_Description,q1.Group_code,q1.SubGroup_Code,q1.qtyexists,q1.Item_Pack
,q1.Currency_code, q1.item_lastcostprice, q1.item_lastcostpricebase1, q1.item_lastcostpricebase2,Items.Item_Remark as Item_Remark
from (
select DISTINCT(Item_Code),Item_Description,Group_code,SubGroup_Code,QtyExistsWSorder(Item_Code,'".$fromwarehouse."',now(),0,'TR',null,null) as qtyexists
,Item_Pack,items.Currency_code, item_lastcostprice, item_lastcostpricebase1, item_lastcostpricebase2
from items,transferdt
where (item_withserialno = 0 or item_withserialno ='' or item_withserialno is null )
and transferdt.item_code = items.item_code
and transfer_id in (select transfer_id from transfer where transfer_id in(".$td."))
and item_withserialno = 0
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."%' or Items.Item_Remark like '%".$PItem_Description."%') ";
}


if ($td==''){
$query1="select Item_Code,Item_Description,Group_code,SubGroup_Code,Item_Pack
,Currency_code, item_lastcostprice, item_lastcostpricebase1, item_lastcostpricebase2, Items.Item_Remark as Item_Remark
from items where 1=1 ";

//if ($ItemType=='AllItems') 
//$query1 = $query1." and (item_withserialno = 0 or item_withserialno =''  or item_withserialno is null ) ";
$query1 = $query1." 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 ($ItemType=='')
	$ItemType = 'AllItems';

if ($ItemType!='AllItems')
$query1 = $query1." and ((('".$ItemType."' = 'FinishGoodPack')  and ifNull(Items.Item_Production,0) = 1 and ifNull(Items.Item_SemiFinished,0) = 0  ) or  ".
		"    (('".$ItemType."' = 'SemiFinishSingle' or '".$ItemType."' = 'SemiFinishPack')  and ifNull(Items.Item_Production,0) = 0 and ifNull(Items.Item_SemiFinished,0) = 1  ) or  ".
		"    ('".$ItemType."' = 'Production'   and ifNull(Items.Item_Pack,0) = 0 and (ifNull(Items.Item_Production,0) = 1 or ifNull(Items.Item_SemiFinished,0) = 1 or ifNull(Items.Item_ReverseProduction,0) = 1) and ifNull(Items.Item_NonStock,0) = 0)".
		" or (('".$ItemType."' = 'rawmaterials') and ifNull(Items.Item_Visible,0) = 0 and ifNull(Items.Item_Pack,0) = 0  and ifNull(Items.Item_Production,0) = 0 and ifNull(Items.Item_SemiFinished,0) = 1  ) ".
		" or (('".$ItemType."' = 'FinsihGoodSingle') and ifNull(Items.Item_Pack,0) = 0  and ifNull(Items.Item_Production,0) = 1 and ifNull(Items.Item_SemiFinished,0) = 0  ) ".
		" or ('".$ItemType."' = 'AllItems'  and 1 = 1 ) ".
		") ";

//echo $query1;
}
else
{
$query1="select DISTINCT(transferdt.Item_Code),Item_Description,Group_code,SubGroup_Code,Item_Pack
,Currency_code, item_lastcostprice, item_lastcostpricebase1, item_lastcostpricebase2, Items.Item_Remark as Item_Remark
from items,transferdt
where (item_withserialno = 0 or item_withserialno ='' or item_withserialno is null )
and transferdt.item_code = items.item_code
and transfer_id in (select transfer_id from transfer where transfer_id in(".$td."))
and item_withserialno = 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."%' or Items.Item_Remark like '%".$PItem_Description."%') ";

if ($ItemType=='')
	$ItemType = 'AllItems';

if ($ItemType!='AllItems')
$query1 = $query1." and ((('".$ItemType."' = 'FinishGoodPack')  and ifNull(Items.Item_Production,0) = 1 and ifNull(Items.Item_SemiFinished,0) = 0  ) or  ".
		"      (('".$ItemType."' = 'SemiFinishSingle' or '".$ItemType."' = 'SemiFinishPack')  and ifNull(Items.Item_Production,0) = 0 and ifNull(Items.Item_SemiFinished,0) = 1  ) or  ".
		"      ('".$ItemType."' = 'Production'   and ifNull(Items.Item_Pack,0) = 0 and (ifNull(Items.Item_Production,0) = 1 or ifNull(Items.Item_SemiFinished,0) = 1 or ifNull(Items.Item_ReverseProduction,0) = 1) and ifNull(Items.Item_NonStock,0) = 0)".
		" or (('".$ItemType."' = 'rawmaterials') and ifNull(Items.Item_Visible,0) = 0 and ifNull(Items.Item_Pack,0) = 0  and ifNull(Items.Item_Production,0) = 0 and ifNull(Items.Item_SemiFinished,0) = 1  ) ".
		" or (('".$ItemType."' = 'FinsihGoodSingle') and ifNull(Items.Item_Pack,0) = 0  and ifNull(Items.Item_Production,0) = 1 and ifNull(Items.Item_SemiFinished,0) = 0  ) ".
		" or ('".$ItemType."' = 'AllItems'  and 1 = 1 ) ".
		") ";

}

/*
$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 ='')";
*/
	if ($startrange=='' || $PItem_Code != '')
		$startrange = 0;
	if ($perpage=='')
		$perpage = 20;
		
if ($groupexist > 0)
    $query1 = $query1. " and items.group_code In (select group_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')  ";

	
	$resultsearch=mysql_query($query1,$connection) or die(mysql_error());
	$totalrows = mysql_num_rows($resultsearch);
		
$query1 = $query1." limit ".$startrange.",".$perpage;


	//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."'";	
}

?>
 <?php
	  
			
		
		
	  if ($Item_Pack==1)
		{
			
				
				$min_sorder_qty = 0;
				$min_available_qty = 9999999999;
				$min_exists_qty = 9999999999;
				$available_qty = 0;
				$exist_qty = 0;
			
			$queryPack = "SELECT Item_CodePackDt, PackDt_Quantity FROM packdt WHERE Item_Code = '".$Item_Code."' And ifNull(PackDt_CostPercentage,0) != 0 ";
			$resultPack = mysql_query($queryPack, $connection);
			
			while($cur = mysql_fetch_row($resultPack)){
			
			/*$Qry_QtyExists    = " Select cast(ifNull(Sum(ifNull(QuantityProduceIn,0) - ifNull(QuantityProduceOut,0) + ifNull(QuantityEntered,0) - ifNull(QuantityDelivered,0)),0) as decimal(20,2)) as QuantityExists From StkTransaction 
		    				     Where StkTransaction.Item_Code = '".$cur[0]."' 
			    			     And (('".$fromwarehouse."' = '' and 1 = 1) or ('".$fromwarehouse."' != '' and ifNull(StkTransaction.Warehouse_Code, -1) = ifNull('".$fromwarehouse."', ifNull(StkTransaction.Warehouse_Code, -1))) )
				    		     And Transaction_Date <= '".$transfer_date."' ";
			*/
			
			
			 $Qry_QtyExists = " SELECT ifnull(QtyExists('".$cur[0]."', '".$fromwarehouse."', '".$transfer_date."', 0, 'TR', '', ''),0) As QtyExists ";
			
			//echo $Qry_QtyExists."<br><br>";							
			
			$resultex = mysql_query($Qry_QtyExists, $connection);
			$sub_result3 = mysql_fetch_row($resultex);
		
			$exist_qty = ($sub_result3[0] / $cur[1]); 
			if ($exist_qty < $min_exists_qty && $exist_qty != 0){
				$min_exists_qty = $exist_qty;
			}
			
			}
			$min_exists_qty = floor($min_exists_qty);
		}
	  else
		{
		/*$Qry_QtyExists = " Select cast(ifNull(Sum(ifNull(QuantityProduceIn,0) - ifNull(QuantityProduceOut,0) + ifNull(QuantityEntered,0) - ifNull(QuantityDelivered,0)),0) as decimal(20,2)) as QuantityExists From StkTransaction 
						  Where StkTransaction.Item_Code = '".$Item_Code."' 
						  And (('".$fromwarehouse."' = '' and 1 = 1) or ('".$fromwarehouse."' != '' and ifNull(StkTransaction.Warehouse_Code, -1) = ifNull('".$fromwarehouse."', ifNull(StkTransaction.Warehouse_Code, -1))) ) 
						  And Transaction_Date <= '".$transfer_date."' ";
		*/
		$Qry_QtyExists = " SELECT ifnull(QtyExists('".$Item_Code."', '".$fromwarehouse."', '".$transfer_date."', 0, 'TR', '', ''),0) As QtyExists ";
			
		//echo $Qry_QtyExists."<br><br>";				  
		$resultex = mysql_query($Qry_QtyExists, $connection);
		$rex = mysql_fetch_row($resultex);		
		$min_exists_qty = $rex[0];
		
		}
	  
	 	  
	  ?>
    <tr <?php echo $Color; ?>>
      <td align="left"><a href="Form_ListItems.php?index=<?php echo $index; ?>&item=<?php echo $_GET['item']; ?>&icode=<?php echo $Item_Code; ?>&quantity1=<?php echo $qtyexists; ?>&qtyexist=<?php echo $min_exists_qty; ?>&TransType=<?php echo $TransType; ?>"><span class="style4"><?php echo $Item_Code; ?></span></a></td>
      <td colspan="2"><a href="Form_ListItems.php?index=<?php echo $index; ?>&item=<?php echo $_GET['item']; ?>&icode=<?php echo $Item_Code; ?>&quantity1=<?php echo $qtyexists; ?>&qtyexist=<?php echo $min_exists_qty; ?>&TransType=<?php echo $TransType; ?>"><span class="style4"><?php echo $Item_Description; ?></span></a></td>
		 <td align="center"><span class="style4"><?php echo $Item_Remark; ?>&nbsp;</span></td>
      <td align="center"><span class="style4"><?php echo $Group_code; ?>&nbsp;</span></td>
      
      
	 
	 <td><span class='style4'><?php echo number_format($min_exists_qty,2)?></span></td> 
	  <?php
	  echo"<td align='center'><span class='style4'>".$Currency_code."</span></td>
				  <td align='right'><span class='style4'>".number_format($item_lastcostprice, $DecimalBase)."</span></td>
				  <td align='right'><span class='style4'>".number_format($item_lastcostpricebase1, $DecimalBase1)."</span></td>
				  <td align='right'><span class='style4'>".number_format($item_lastcostpricebase2, $DecimalBase2)."</span></td>";
	    //, item_lastcostprice, item_lastcostpricebase1, item_lastcostpricebase2,
	  
	  
	  
	  ?>
    </tr>
<?php
	}
	echo"<tr><td >&nbsp;</td></tr>
		 <tr><td colspan=9 width='100%' ><table width='100%' border=0><tr><td width='160' >&nbsp;</td><td  width='160' align='center'>";
		
	$diff= $startrange - $perpage;
	//echo $startrange." ".$perpage;	
	if (($diff) >= 0 ){
		$prvstartrange = $startrange - $perpage;
		echo"<img src='img/arrowleft.jpg' title='Previous' onMouseOver=\"style.cursor='pointer'\"  onclick=\"SetPrvPage('".htmlentities($fromwarehouse)."','".htmlentities($towarehouse)."','".$index."','".htmlentities($fromproject)."','".htmlentities($toproject)."','".$actionmode."','".$transfer_id."','".$transfer_date1."','".$td."','".$prvstartrange."','".$perpage."','".$TransType."')\">";
	}
	else
		echo "&nbsp;";
		
	echo"</td><td width='150' align='center'>";
		
		//echo $startrange." ".$totalrows;
	if ($startrange <= $totalrows){
		$startrange = $startrange + $perpage;
	//	echo "<br>".$startrange." ".$totalrows;
		if  ($startrange <= $totalrows)
			echo"<img src='img/arrowright.jpg' title='Next' onMouseOver=\"style.cursor='pointer'\" onclick=\"SetNextPage('".htmlentities($fromwarehouse)."','".htmlentities($towarehouse)."','".$index."','".htmlentities($fromproject)."','".htmlentities($toproject)."','".$actionmode."','".$transfer_id."','".$transfer_date1."','".$td."','".$startrange."','".$perpage."','".$TransType."')\">";
	} else
		echo "&nbsp;";
			
	echo"</td><td width='170'>&nbsp;</td></tr>";
	echo"<table>";

	echo"</td></tr>";


?>
  </table>
</form>
</body>
</html>
