<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
include("config.inc.php");
include("function.inc.php");

$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, DecimalBase, DecimalBase1, DecimalBase2, base1, base2 from setup";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

}



set_time_limit(0);

//Read From Login Table
$querylog=" select ifNull(FI_ShowCostPrice,0) As FI_ShowCostPrice, ifNull(Login_negativeQty,0) As Login_negativeQty ".
		  " 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);
}


//Read From Module Table
$querymodule=" Select ifNull(Module_Grn,0) As Module_Grn, ifNull(Module_NegativeQuantity,0) As Module_NegativeQuantity,module_autodiscount
				From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

   
$frm	   			= $_GET['frm']; 				if ($frm == "")				 {	$frm 				= $_POST["frm"];				}
$index				= $_GET['index']; 				if ($index == "") 			 {	$index 				= $_POST['index'];				}
$perpage   			= $_GET['perpage']; 			if ($perpage == "")			 {	$perpage 			= $_POST["perpage"];			}
$startrange 		= $_GET['startrange']; 			if ($startrange == "")		 {	$startrange 		= $_POST["startrange"];			}
$TransDate  		= $_GET['TransDate']; 			if ($TransDate == "")		 {	$TransDate 			= $_POST["TransDate"];			}
$CurrCode  			= $_GET['CurrCode']; 			if ($CurrCode == "")		 {	$CurrCode 			= $_POST["CurrCode"];			}
$ItemType   		= $_GET['ItemType']; 			if ($ItemType == "")		 {	$ItemType 			= $_POST["ItemType"];			}
$ItemSort   		= $_GET['ItemSort']; 			if ($ItemSort == "")		 {	$ItemSort 			= $_POST["ItemSort	"];			}
$ItemGroup  		= $_GET['ItemGroup']; 			if ($ItemGroup == "")		 {	$ItemGroup 			= $_POST["ItemGroup"];			}
$ItemWh  			= $_GET['ItemWh'];	 			if ($ItemWh == "")			 {	$ItemWh 			= $_POST["ItemWh"];				}
$PItem_Code 		= $_POST["PItem_Code"]; 		if ($PItem_Code == "")		 {	$PItem_Code 		= $_GET["PItem_Code"];			}

$PExact 		    = $_POST["PExact"]; 		    if ($PExact == "")		     {	$PExact 		= $_GET["PExact"];			}
$checkexact='';
if ($PExact=='%') {
		$checkexact='checked';
}
$PItem_Description  = $_POST["PItem_Description"]; 	if ($PItem_Description == ""){	$PItem_Description 	= $_GET["PItem_Description"];	}

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

	$query1="select Item_Code, Item_Description, if(Items.Item_Vat !='', 1, 0) As ItemVat, ifNull(item_withserialno,0) As ItemWithSerial,Item_WarehouseCode, Item_NetWeight as NetWeight,
			ifnull(Item_Production,0) as Item_Production, Item_UnitSalesDesc,if(item_barcode='',if(item_barcode2='',if(item_barcode3='',item_code,item_barcode3),item_barcode2),item_barcode) as Item_Barcode
			from items where item_code='".str_replace('\\','\\\\',$_GET['lcode'])."'";
	
	$result1=mysql_query($query1,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($result1)){
    	extract($rows);
	}

    $_GET['post']="1";
	
}
//Gilbert 19-11-2013
$query_login=" select ifNull(FI_Items,0) as FI_Items, ifNull(FI_ItemsApp,0) as FI_ItemsApp, ".
			 " FI_SellingPriceInItems as FI_SellingPriceInItems, FI_CostPriceInItems as FI_CostPriceInItems   ".
			 " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlogin=mysql_query($query_login,$connection) or die(mysql_error());

while($rows=mysql_fetch_array($resultlogin)){
	extract($rows);
}

$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2 from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

?>
<!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=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Select Items</title>
<link rel="stylesheet" type="text/css" media="all" href="js/grid/UI_DataGrid_V1.css">
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>

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

function getParameterByName(name) {
    var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}



function clearform()
{
	document.form1.PItem_Description.value='';
	document.form1.PItem_Code.value='';
	document.form1.SCode.value='';
	document.form1.Item_WarehouseCode.value='';
	document.form1.Item_UnitSalesDesc.value='';
	
	var theurl = 'List_SorItems.php'; 
	
	try{
		
		if (getParameterByName('filtercostinputexist').length>0)
		{
		 theurl= theurl+ '?filtercostinputexist='+getParameterByName('filtercostinputexist');
		}
	}
	catch(err){}
	
	
	document.form1.action= theurl;
	document.form1.submit();
}
function SetNextPage(startrange,perpage){
	vFrm       = document.form1.frm.value;
	vItemType  = document.form1.ItemType.value;
	vItemSort  = document.form1.ItemSort.value;
	vItemGroup = document.form1.ItemGroup.value;
	vItemWh    = document.form1.ItemWh.value;
	vTransDate = document.form1.TransDate.value;
	
	document.form1.action='List_SorItems.php?PItem_Code=&lcode=&frm='+vFrm+'&ItemType='+vItemType+'&ItemSort='+vItemSort+'&ItemGroup='+vItemGroup+'&ItemWh='+vItemWh+'&TransDate='+vTransDate+'&startrange='+startrange+'&perpage='+perpage;
	document.form1.submit();
}

function SetPrvPage(startrange,perpage){
	vFrm       = document.form1.frm.value;
	vItemType  = document.form1.ItemType.value;
	vItemSort  = document.form1.ItemSort.value;
	vItemGroup = document.form1.ItemGroup.value;
	vItemWh    = document.form1.ItemWh.value;
	vTransDate = document.form1.TransDate.value;
	
	document.form1.action='List_SorItems.php?PItem_Code=&lcode=&frm='+vFrm+'&ItemType='+vItemType+'&ItemSort='+vItemSort+'&ItemGroup='+vItemGroup+'&ItemWh='+vItemWh+'&TransDate='+vTransDate+'&startrange='+startrange+'&perpage='+perpage;
	document.form1.submit();
}
function RefreshPage(){
	vFrm       = document.form1.frm.value;
	vItemType  = document.form1.ItemType.value;
	vItemSort  = document.form1.ItemSort.value;
	vItemGroup = document.form1.ItemGroup.value;
	vItemWh    = document.form1.ItemWh.value;
	vTransDate = document.form1.TransDate.value;
	vPerPage   = document.form1.perpage.value;
	
	document.form1.action='List_SorItems.php?PItem_Code=&lcode=&frm='+vFrm+'&ItemType='+vItemType+'&ItemSort='+vItemSort+'&ItemGroup='+vItemGroup+'&ItemWh='+vItemWh+'&TransDate='+vTransDate+'&startrange=0&perpage='+vPerPage;
	document.form1.submit();
}

function ShowSlidingDiv(PIndex) {
	var Div = "#slidingDiv"+PIndex;
	$(Div).slideToggle();
	
}

function openitemform(){

 win = window.open('./Form_Items.php?mainmode=insert', 'Form_Items', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1200,height=750,top=20,left=100');		
	win.creator = self;
	win.focus();
}



</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: 11px;
}
.style3 {color: #999999}
.style4{
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
-->
</style>

<script>

var  a = '';

try
{
	a = $('#txtCostCentCode', window.opener.document).val();
}
catch(err)
{
	a = '';
}


if(a.length>0)
{
	
	
	try
	{
		if(getParameterByName('filtercostinputexist').length==0)
	   {
		   var appendurl = '&filtercostinputexist='+a;
		  // window.open(window.location.href+appendurl,"");
		  
		
		  
					  if(document.location.search.length) {
			  location.href = location.href + "&filtercostinputexist=" + a;
			} else {
				  location.href = location.href + "?filtercostinputexist=" + a;
			}


	   }
	}
	catch (err)
	{
		var appendurl = '&filtercostinputexist='+a;
		 //  window.open(window.location.href+appendurl,"");
		   if(document.location.search.length) {
			  location.href = location.href + "&filtercostinputexist=" + a;
			} else {
				  location.href = location.href + "?filtercostinputexist=" + a;
			}
	}
	   
	
}
</script>
</head>

<body>

 

<?php

	//by rod  check cost center 
 
 
$querymodule=" Select ifNull(Module_CostCenterParent,0) As Module_CostCenterParent From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}


$querymastercostcenter=" select distinct Mastercostcenter from ".$_SESSION['dbLabel'].".loginstk ".
					   " where loginstk.user_account='".$_SESSION['useraccount']."' ".
					   " and (Mastercostcenter is not null and Mastercostcenter != '') ";

$costcentermasterresult  = mysql_query($querymastercostcenter,$connection) or die(mysql_error());
$costcentermasterexist   = mysql_num_rows($costcentermasterresult);



$query1=" select distinct costcent.costcent_code as costcent_code, costcent_name as costcent_name ".
		" from Costcent  ";
if ($costcentermasterexist > 0) {	
							$query1= $query1." inner join ( select distinct Mastercostcenter from ".$_SESSION['dbLabel'].".loginstk ".
														 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
														 "             and (Mastercostcenter is not null and Mastercostcenter != '') ".
														 "			 ) CstMasterQry on ifnull(Costcent.CostCent_Code ,concat(CstMasterQry.Mastercostcenter,'%')) like concat(CstMasterQry.Mastercostcenter,'%') ";
							}	

$query1=$query1." left join ".$_SESSION['dbLabel'].".loginstk on (($Module_CostCenterParent=1 and costcent.costcent_code like concat(ifnull(loginstk.costcent_code,costcent.costcent_code),'%')) or ($Module_CostCenterParent=0 and costcent.costcent_code = loginstk.costcent_code )) ".
 			   " where user_account='".$_SESSION['useraccount']."' ".
			   " and (loginstk.costcent_code is not null and loginstk.costcent_code != '') ".
			   " and ifnull(costcent.costcent_deactivate,0) = 0 ".
			    " ";
			   
$query1=$query1." and (costcent.Costcent_code  like"."('%".$PRef."%') or Costcent_name like"."('%".$PRef."%')) and ifnull(Costcent_Deactivate,0)=0 ".
		        " order by costcent.costcent_code";
				

 

$result1=mysql_query($query1,$connection) or die(mysql_error());
	 
 
//echo $query1;exit;

$costcentrows   = mysql_num_rows($result1);
if ($costcentrows != 0){
	
	$costcent_array = "";
	$i = 0;
	$costcent_array = "(";
	while($rows=mysql_fetch_array($result1)){
		
		 
		if($i==0)
		{
			$costcent_array = $costcent_array. "'" .$rows[0] ."'";
		}
		else
		{
				$costcent_array =$costcent_array. ",'" .$rows[0] ."'";
		}
		$i = $i +1;
		 
	}
	$costcent_array =$costcent_array. ")";
	
	//echo $costcent_array; echo "<br>";
	$filtercostcent = "and ( costcent_code in";
	$filtercostcent = $filtercostcent . $costcent_array;
	
	
	$filtercostcent.=" or costcent_code IS NULL   or costcent_code = '')";
	 
  //  echo $filtercostcent;exit;		
}


//by rod  end check cost center 

 
	$appendcostcenter = "";
	//  echo $_GET['filtercostinputexist'];exit;
	
	if (isset($_GET['filtercostinputexist']))
	{
		 
		$appendcostcenter = " and ( costcent_code in ('"  .$_GET['filtercostinputexist']. "') or costcent_code IS NULL   or costcent_code = '')";
	 // second choice
	//  $appendcostcenter = " and   costcent_code in ('"  .$_GET['filtercostinputexist']. "')  ";
	}
	  if(!empty($costcent_array))
  {
	 $appendcostcenter =  $appendcostcenter   . "  " .$filtercostcent;
  }
  //echo $appendcostcenter;exit;
	
//end by rod 

/* if (!empty($_GET['filtercostinputexist']))
{
	echo $_GET['filtercostinputexist'];exit;
} */




echo "
<form id='form1' name='form1' method='post' action=''>
  <table width='760' border='0' cellspacing='1' align='center' style='table-layout:fixed'>
	<col width=25>
	<col width=150>
	<col width=220>
	<col width=150>
	<col width=70>
	<col width=130>
	<col width=130>";
	
/*	
if($FI_ShowCostPrice == 1) {	
	echo "<col width=235>
		  <col width=80>
		  <col width=60>
		  <col width=70>
		  <col width=50>
		  <col width=80>
	      <col width=60>
	      <col width=60>";
} else {
	echo "<col width=375>
		  <col width=80>
		  <col width=60>
		  <col width=70>
		  <col width=50>
	      <col width=60>";
}	*/	  

echo "
    <tr>
      <th colspan='7' bgcolor='#DDDDDD'><span class='style1'> ITEMS </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. / Remark</span></td>
      <td bgcolor='#DDDDDD' colspan='5'>
		    
			<input type='hidden' name='PExact' value=''  size=12/>
	        %<input type='checkbox' name='PExact' $checkexact value='%'  size=12/>
	        <input type='text' name='PItem_Code' value='$PItem_Code' placeholder='Item Code' autofocus style='width: 120px;' />
            <input type='hidden' name='module_autodiscount' id='module_autodiscount'  value='$module_autodiscount'>
            <input type='hidden' name='DiscountPerc' id='DiscountPerc'  value='$DiscountPerc'>
            <input type='hidden' name='Item_Unit' id='Item_Unit'  value='$Item_Unit'>
            <input type='hidden' name='Item_Package' id='Item_Package'  value='$Item_Package'>
            <input type='hidden' name='code1' id='code1'  value='$Item_Code'>
			<input type='hidden' name='ItemVat' id='ItemVat'  value='$ItemVat'>
			<input type='hidden' name='Item_Barcode' id='Item_Barcode' value='$Item_Barcode'>
			<input type='hidden' name='Item_UnitSalesDesc' id='Item_UnitSalesDesc'  value='$Item_UnitSalesDesc'>
			<input type='hidden' name='vcurr' id='vcurr'  value='$vcurr'>
	        <input type='text' name='PItem_Description' placeholder='Description/Remark'  value='$PItem_Description' style='width: 150px;'  />
			<input type='text' name='Item_WarehouseCode' placeholder='Warehouse Code' value='$Item_WarehouseCode' style='width: 120px;' /><br>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='search_subgroup' id='search_subgroup' value='$search_subgroup' style='width:100px' placeholder='Sub Group' />
	        <input type='submit' name='Submit' value='Find' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>
			<input type='button' name='cancelbtn' value='Cancel' onclick='clearform();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>";
			
			//Gilbert 19-11-2013
			if($FI_ItemsApp==1 && $FI_Items==1)
				echo"&nbsp;<input type='button' name='addbtn' value='Add Item' onclick='openitemform();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>";
				
			echo"<input name='desc1' type='hidden' id='desc1' value='$Item_Description' />
			<input type='hidden' name='TransDate' value='$TransDate' />
			<input type='hidden' name='ItemType' value='$ItemType' />
			<input type='hidden' name='ItemSort' value='$ItemSort' />
			<input type='hidden' name='ItemGroup' value='$ItemGroup' />
			<input type='hidden' name='ItemWh' value='$ItemWh' />
			<input type='hidden' name='frm' value='$frm' />
			<input type='hidden' name='SCode' value='$SCode' />
			<input type='hidden' name='index' value='$index'>
			<input type='hidden' name='Item_SellingPrice1Base1' value='$Item_SellingPrice1Base1'>
			<input type='hidden' name='Item_SellingPrice1Base2' value='$Item_SellingPrice1Base2'>
			<input type='hidden' name='itemSellingPrice' value='$itemSellingPrice'>
			<input type='hidden' name='itemWarehoouse' value='$itemWarehoouse'>
			<input type='hidden' name='NetWeight' value='$NetWeight'>
			<input type='hidden' name='ItemProd' value='$Item_Production'>
			
			<span style='font-size: 11px; color: #999999; font-weight: bold;'>Result per page </span><select name='perpage' id='perpage' value='$perpage' onchange='RefreshPage();' >";
              


        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($_GET['post']=="1") { ?>
<script type="text/javascript" language="javascript">
var FormOption = document.form1.frm.value;
var vIndex	   = document.form1.index.value; 

if (FormOption == 1) {
	opener.document.salesorderdt.txtItemCode.value=document.form1.code1.value;
	opener.document.salesorderdt.txtItemDesc.value=document.form1.desc1.value;
	opener.document.salesorderdt.txtSorDtVat.value=document.form1.ItemVat.value;
	opener.document.salesorderdt.txtItemCode.focus();
	opener.document.salesorderdt.txtItemCode.blur();
	opener.document.salesorderdt.submit();
} else if (FormOption == 2) {
	opener.document.salesdt.txtItemCode.value=document.form1.code1.value;
	opener.document.salesdt.txtItemDesc.value=document.form1.desc1.value;
	opener.document.salesdt.txtSaDtVat.value=document.form1.ItemVat.value;
	opener.document.salesdt.txtItemCode.focus();
	opener.document.salesdt.txtItemCode.blur();
	opener.document.salesdt.submit();

} else if (FormOption == 3) {
	opener.document.production.txtItemCodeFG.value=document.form1.code1.value;
	opener.document.production.txtItemDescFG.value=document.form1.desc1.value;
	opener.document.production.txtWhCode.value=document.form1.ItemWh.value;
	opener.document.production.txtItemCodeFG.focus();
	opener.document.production.submit();

} else if (FormOption == 4) {
	opener.document.productiondt.txtItemCode.value=document.form1.code1.value;
	opener.document.productiondt.txtItemDesc.value=document.form1.desc1.value;
	opener.document.productiondt.txtItemCode.focus();
	opener.document.productiondt.submit();

} else if (FormOption == 5) {
	opener.document.adjustmentdt.txtItemCode.value=document.form1.code1.value;
	opener.document.adjustmentdt.txtItemDesc.value=document.form1.desc1.value;
	opener.document.adjustmentdt.txtItemCode.focus();
	opener.document.adjustmentdt.submit();

} else if (FormOption == 6) {
	opener.document.returnsalesdt.txtItemCode.value=document.form1.code1.value;
	opener.document.returnsalesdt.txtItemDesc.value=document.form1.desc1.value;
	opener.document.returnsalesdt.txtRSaDtVat.value=document.form1.ItemVat.value;
	opener.document.returnsalesdt.txtItemCode.focus();
	opener.document.returnsalesdt.txtItemCode.blur();
	opener.document.returnsalesdt.submit();

} 
else if (FormOption == 7) {
	var idholder = opener.document.getElementById('itemcode['+vIndex+']');
	
	opener.document.getElementById('itemcode['+vIndex+']').value=document.form1.code1.value;
	opener.document.getElementById('itemdescription['+vIndex+']').value= document.form1.desc1.value;
	//alert(opener.document.getElementById('itemcode['+vIndex+']').value);
	if(opener.document.getElementById('sadtdiscount['+vIndex+']') && document.form1.module_autodiscount.value==1)
		opener.document.getElementById('sadtdiscount['+vIndex+']').value=document.form1.DiscountPerc.value;
	
	if(opener.document.getElementById('sorderdt_itemunit['+vIndex+']'))
		opener.document.getElementById('sorderdt_itemunit['+vIndex+']').value=document.form1.Item_Unit.value;	
		
	if(opener.document.getElementById('sorderdt_itempackage['+vIndex+']'))
		opener.document.getElementById('sorderdt_itempackage['+vIndex+']').value=document.form1.Item_Package.value;
		
	if(opener.document.getElementById('deliverydt_itemunit['+vIndex+']'))
		opener.document.getElementById('deliverydt_itemunit['+vIndex+']').value=document.form1.Item_Unit.value;	
		
	if(opener.document.getElementById('deliverydt_itempackage['+vIndex+']'))
		opener.document.getElementById('deliverydt_itempackage['+vIndex+']').value=document.form1.Item_Package.value;
	
	//alert(opener.document.getElementById('itemdescription['+vIndex+']').value);
	/*if(opener.document.getElementById('txtSellingPrice['+vIndex+']')){
	if(document.form1.vcurr.value==1)
		opener.document.getElementById('txtSellingPrice['+vIndex+']').value=document.form1.Item_SellingPrice1Base1.value;
	else
		opener.document.getElementById('txtSellingPrice['+vIndex+']').value=document.form1.Item_SellingPrice1Base2.value;
	}*/
	
	if(opener.document.getElementById('warehousecode['+vIndex+']'))
	{ if(document.form1.itemWarehoouse.value != '')
		opener.document.getElementById('warehousecode['+vIndex+']').value=document.form1.itemWarehoouse.value;
	}
	if(opener.document.getElementById('sellingPrice['+vIndex+']'))
	opener.document.getElementById('sellingPrice['+vIndex+']').value=document.form1.itemSellingPrice.value;	
	
	if(opener.document.getElementById('deliverydt_netweight['+vIndex+']'))
	opener.document.getElementById('deliverydt_netweight['+vIndex+']').value=document.form1.NetWeight.value;	
	
	if (document.form1.ItemProd.value == 1 && opener.document.getElementById('itemprodqty['+vIndex+']')){
		opener.document.getElementById('itemprodqty['+vIndex+']').disabled = false;
		opener.document.getElementById('itemsentprod['+vIndex+']').disabled = false;
	} else if (document.form1.ItemProd.value == 0 && opener.document.getElementById('itemprodqty['+vIndex+']')) {
		opener.document.getElementById('itemprodqty['+vIndex+']').value = '';
		opener.document.getElementById('itemprodqty['+vIndex+']').disabled = true;
		opener.document.getElementById('itemsentprod['+vIndex+']').value = 0;
		opener.document.getElementById('itemsentprod['+vIndex+']').disabled = true;
	}
	//$('#'.idholder).trigger("change");
	fireTrigger(idholder,'change');
	opener.document.getElementById('itemcode['+vIndex+']').focus();
	
}
else if (FormOption == 8) {
	var idholder = opener.document.getElementById('itemcodefg['+vIndex+']');
	
	opener.document.getElementById('itemcodefg['+vIndex+']').value=document.form1.code1.value;
	opener.document.getElementById('itemdescriptionfg['+vIndex+']').value=document.form1.desc1.value;
	
	//$('#'.idholder).trigger("change");
	fireTrigger(idholder,'change');
	opener.document.getElementById('itemcodefg['+vIndex+']').focus();
	
}
else if (FormOption == 9) {
	var idholder = opener.document.getElementById('itemcoderm['+vIndex+']');
	
	opener.document.getElementById('itemcoderm['+vIndex+']').value=document.form1.code1.value;
	opener.document.getElementById('itemdescriptionrm['+vIndex+']').value=document.form1.desc1.value;
	
	//$('#'.idholder).trigger("change");
	fireTrigger(idholder,'change');
	opener.document.getElementById('itemcoderm['+vIndex+']').focus();
	
}
else if (FormOption == 10) {
	//var idholder = opener.document.getElementById('itemcoderm['+vIndex+']');
	
	opener.document.transForm.item_code.value=document.form1.code1.value;
	 opener.document.transForm.item_desc.value=document.form1.desc1.value;
	
	//$('#'.idholder).trigger("change");
	/*fireTrigger(idholder,'change');
	opener.document.getElementById('itemcoderm['+vIndex+']').focus();
	 */
}else if (FormOption == 11) {
	//var idholder = opener.document.getElementById('itemcoderm['+vIndex+']');
	
	opener.document.getElementById('itemjour_code['+vIndex+']').value=document.form1.code1.value;
	opener.document.getElementById('itemjour_description['+vIndex+']').value=document.form1.desc1.value;
	
}
else
	if(FormOption == 12){
		opener.document.getElementById('item_code').value = document.form1.code1.value;
		opener.document.getElementById('item_description').value = document.form1.desc1.value;
		opener.document.getElementById('RMADt_Remark').value = document.form1.desc1.value;
		opener.document.getElementById('RMADt_Quantity').focus();
	}
	else
	if(FormOption == 13){
		opener.document.getElementById('item_code_<?php echo $_GET['rmadt_id']; ?>').value = document.form1.code1.value;
		opener.document.getElementById('item_description_<?php echo $_GET['rmadt_id']; ?>').value = document.form1.desc1.value;
		opener.document.getElementById('RMADt_Remark_<?php echo $_GET['rmadt_id']; ?>').value = document.form1.desc1.value;
		opener.document.getElementById('RMADt_Quantity_<?php echo $_GET['rmadt_id']; ?>').focus();
	} 
	else if (FormOption == 14) {
	var idholder = opener.document.getElementById('itemcodefg['+vIndex+']');
	
	opener.document.getElementById('itemcodefg['+vIndex+']').value=document.form1.code1.value;
	opener.document.getElementById('itemdescriptionfg['+vIndex+']').value=document.form1.desc1.value;
	
	//$('#'.idholder).trigger("change");
	fireTrigger(idholder,'change');
	opener.document.getElementById('itemcodefg['+vIndex+']').focus();
	
} else if (FormOption == 15){ 
	opener.document.getElementById('txtWasteItem').value=document.form1.code1.value;
	opener.document.getElementById('txtWasteItemdesc').value=document.form1.desc1.value;
}
else
	if(FormOption == 16){
		opener.document.getElementById('item_code').value = document.form1.code1.value;
		opener.document.getElementById('item_description').value = document.form1.desc1.value;
		opener.document.getElementById('serial_number').focus();
	}
	else
	if(FormOption == 17){
		opener.document.getElementById('item_code_<?php echo $_GET['rmadtrpc_id']; ?>').value = document.form1.code1.value;
		opener.document.getElementById('item_description_<?php echo $_GET['rmadtrpc_id']; ?>').value = document.form1.desc1.value;
		opener.document.getElementById('serial_number_<?php echo $_GET['rmadtrpc_id']; ?>').focus();
	}
	else
	if(FormOption == 18){
		opener.document.getElementById('item_coderep').value = document.form1.code1.value;
		//opener.document.getElementById('item_description').value = document.form1.desc1.value;
		opener.document.getElementById('serial_numberRep').focus();
	}

else if (FormOption == 19) {
	var idholder = opener.document.getElementById('itemcode['+vIndex+']');
	
	opener.document.getElementById('itemcode['+vIndex+']').value=document.form1.code1.value;
	opener.document.getElementById('itemdescription['+vIndex+']').value= document.form1.desc1.value;
	
	if(opener.document.getElementById('warehousecode['+vIndex+']'))
	{ if(document.form1.itemWarehoouse.value != '')
		opener.document.getElementById('warehousecode['+vIndex+']').value=document.form1.itemWarehoouse.value;
	}
	
	//$('#'.idholder).trigger("change");
	fireTrigger(idholder,'change');
	opener.document.getElementById('itemcode['+vIndex+']').focus();
	
}	
else if (FormOption == 20) {
	opener.document.getElementById('itemnCode_NonStock').value=document.form1.code1.value;
	opener.document.getElementById('itemndesc_NonStock').value= document.form1.desc1.value;
}
else if (FormOption == 21) {
	var idholder = opener.document.getElementById('txtItemCode['+vIndex+']');
	
	opener.document.getElementById('txtItemCode['+vIndex+']').value=document.form1.code1.value;
	opener.document.getElementById('txtItemDesc['+vIndex+']').value= document.form1.desc1.value;
	
	if (opener.document.getElementById('Item_Unit['+vIndex+']'))
		opener.document.getElementById('Item_Unit['+vIndex+']').value= document.form1.Item_Unit.value;
	
	if (opener.document.getElementById('txtItemUnit1['+vIndex+']'))
		opener.document.getElementById('txtItemUnit1['+vIndex+']').value= document.form1.Item_UnitSalesDesc.value;
	
	
	//$('#'.idholder).trigger("change");
	fireTrigger(idholder,'change');
	opener.document.getElementById('txtItemCode['+vIndex+']').focus();
	
}else if (FormOption == 22) {
	opener.document.getElementById('Item_code').value = document.form1.code1.value; 
}else if (FormOption == 23) {
	opener.document.getElementById('itemcode1').value = document.form1.code1.value; 
	opener.document.getElementById('txtItemBarcode').value=document.form1.Item_Barcode.value;
}
self.close();


</script>
<?php } ?>

<?php

echo" <tr bgcolor='#E5E5E5'>
        <td ><span class='style2'>&nbsp</span></td>
		<td ><span class='style2'>Item Code </span></td>
        <td ><span class='style2'>Item Description </span></td>
		<td align='center'><span class='style2'>Remark</span></td>
		<td align='center'><span class='style2'>Unit</span></td>
		<td align='center'><span class='style2'> Group</span></td>
		<td align='center'><span class='style2'> Subgroup</span></td>";
/*
if($FI_ShowCostPrice == 1) {
    echo" <td align='center'><span class='style2'> Warehouse</span></td>
	      <td align='center'><span class='style2'>Unit</span></td>
		  <td align='center'><span class='style2'> Qty Exists</span></td>
		  <td><span class='style2'> Currency</span></td>
	      <td><span class='style2'> Last Cost Price</span></td>
	      <td align='center'><span class='style2'> $base1</span></td>
	      <td align='center'><span class='style2'> $base2</span></td>";
} else {
	echo" <td align='center'><span class='style2'> Warehouse</span></td>
		  <td align='center'><span class='style2'>Unit</span></td>
	      <td align='center'><span class='style2'> Qty Exists</span></td>
	      <td colspan='4'><span class='style2'> &nbsp;</span></td>";
}*/		  
echo" </tr>";

$TransDate1 = $TransDate;
$FromDate = $TransDate;
if($FromDate == '')
	$FromDate = "NULL";
else {
	$ndate = explode('/', $FromDate);
	$FromDate = $ndate[2]."-".$ndate[1]."-".$ndate[0];
}
if (!empty($TransDate))
   $TransDate = formatDateNoTime($TransDate);

if (empty($TransDate))   
   $TransDate = 'null';
else
   $TransDate = "'".$TransDate."'"; 
   
if (empty($ItemWh))
   $ItemWh = 'null';
else
   $ItemWh = "'".$ItemWh."'"; 

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

$querywarehouse=" select distinct warehouse.warehouse_code, warehouse_name ".
				" from warehouse where warehouse_code in (select warehouse_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."') ".
				" order by warehouse.warehouse_code";
$resultwh = mysql_query($querywarehouse,$connection) or die(mysql_error());
$whexist   = mysql_num_rows($resultwh);

 
$querySaleatCost=" select Client_priceatcost ".
				" from clients where ledger_number = '$ClientCode'";
$resultSC = mysql_query($querySaleatCost,$connection) or die(mysql_error());
$SC  = mysql_num_rows($resultSC);

$query = "";
/*if ($ItemType == 'Packed' || $ItemType == 'PromoPacked') {
	$query =" select Item_Code, Item_Description, Group_code, Currency_code, item_lastcostprice, item_lastcostpricebase1, item_lastcostpricebase2, ".
			" ItemVat, Item_UnitSalesDesc, Warehouse_Code, Min(floor(QuantityExists/PackDt_Quantity)) As QuantityExists ".
			" from ( ".
			" select Item_Code, Item_Description, Group_code, Currency_code, item_lastcostprice, ".
			" item_lastcostpricebase1, item_lastcostpricebase2, ItemVat, Item_UnitSalesDesc, Warehouse_Code, ".
			" Item_CodePackDt, QuantityExists, Sum(PackDt_Quantity) As PackDt_Quantity ".
			" from ( ";
}	*/		
// add query to check if sister Company

// if yes meancost else selling price
$query = $query." select Items.Item_Code as Item_Code, Items.Item_Description, Items.Currency_code, Items.item_lastcostprice, Items.item_lastcostpricebase1
		, Items.item_lastcostpricebase2, if(Items.Item_Vat !='', 1, 0) As ItemVat, ".
			    " Items.Item_UnitSalesDesc, Items.Group_Code, Group_Name, Items.SubGroup_Code, SubGroup_Name ";
				
//StkTransaction.Warehouse_Code, ";
/*				
if ($ItemType == 'Packed' || $ItemType == 'PromoPacked') 				
	$query = $query." PackDt.Item_CodePackDt, PackDt_Quantity, cast(ifNull(Sum((QuantityProduceIn - QuantityProduceOut + QuantityEntered - QuantityDelivered)), 0) as decimal(20,2)) as QuantityExists ";
else 	
	$query = $query." cast(ifNull(Sum(QuantityProduceIn - QuantityProduceOut + QuantityEntered - QuantityDelivered),0 ) as decimal(20,2)) as QuantityExists ";
*/				
$query = $query." ,Item_SellingPrice1Base1,Item_SellingPrice1Base2 ";
$query = $query." ,Item_Unit,Item_Package, Item_WarehouseCode, Items.Item_Remark as Item_Remark ,ifnull(item_barcode,ifnull(item_barcode2,ifnull(item_barcode3,item_code))) as Item_Barcode from Items ".
				" Left Join Grouping on Grouping.Group_code = Items.Group_code ".
				" Left Join SubGroup on SubGroup.SubGroup_Code = Items.SubGroup_Code ";

/*
if ($ItemType == 'Packed' || $ItemType == 'PromoPacked') {
	$query = $query." Inner Join PackDt on Items.Item_Code = PackDt.Item_Code ".
					" Inner Join StkTransaction on StkTransaction.Item_Code = PackDt.Item_CodePackDt ";
} 
else					
	$query = $query." Left Join StkTransaction on StkTransaction.Item_Code = Items.Item_Code  ";

if ($whexist >	0) {
	$query = $query." Inner join ( select distinct warehouse_code from ".$_SESSION['dbLabel'].".loginstk ".
					"			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
					"              and (warehouse_code is not null and warehouse_code != '') ".
					"			 ) Q1 on (StkTransaction.Warehouse_Code = Q1.warehouse_code or StkTransaction.Warehouse_Code is null) ";
}
	*/						 
$query = $query." where 1=1  ";
$wild=$PExact;

//if ($PExact!='')
//	$wild='%';
if($PItem_Code!= '') $query = $query." and (					
							Items.Item_Code like ".GetSQLValueString($wild.str_replace('\\','\\\\\\',$PItem_Code).'%','text')."  
							or Items.Item_Barcode like ".GetSQLValueString($wild.str_replace('\\','\\\\\\',$PItem_Code).'%','text')." 
							or Items.Item_Barcode2 like ".GetSQLValueString($wild.str_replace('\\','\\\\\\',$PItem_Code).'%','text')." 
							or Items.Item_Barcode3 like ".GetSQLValueString($wild.str_replace('\\','\\\\\\',$PItem_Code).'%','text')." 
						    
						)";
if($search_subgroup != ""){	$query = $query." and items.SubGroup_Code like '%$search_subgroup%'"; }	
if($PItem_Description!= '') $query = $query." and if('$PItem_Description' = '', 1=1,Items.Item_Description like '%$PItem_Description%' or   Items.Item_Remark like '%$PItem_Description%' ) ";
	
//$query = $query." where Items.Item_Code like '%".str_replace('\\','\\\\\\\\',$PItem_Code)."%' ".
	//			" and Items.Item_Description like '%".$PItem_Description."%'  ";
		
if ($groupexist > 0)
    $query = $query. " and items.group_code In (select group_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')  ";
	
//if ($whexist > 0)
  //  $query = $query. " and if(StkTransaction.Item_Code is null, True, StkTransaction.Warehouse_Code In (select Warehouse_Code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."')) ";	
	
$query = $query.	
		" and (('".$ItemType."' = 'Trading'      and ifNull(Items.Item_Pack,0) = 0 and ifNull(Items.Item_Promotion,0) = 0 and ifNull(Items.Item_Visible,0) = 1) or ".
		"      ('".$ItemType."' = 'Packed'       and ifNull(Items.Item_Pack,0) = 1 and ifNull(Items.Item_Promotion,0) = 0 and ifNull(Items.Item_Production,0) = 0 and ifNull(Items.Item_SemiFinished,0) = 0 and ifNull(Items.Item_NonStock,0) = 0) or ".
		"      ('".$ItemType."' = 'PromoPacked'  and ifNull(Items.Item_Pack,0) = 1 and ifNull(Items.Item_Promotion,0) = 1 and ifNull(Items.Item_Production,0) = 0 and ifNull(Items.Item_SemiFinished,0) = 0 and ifNull(Items.Item_NonStock,0) = 0) or ".
		"      ('".$ItemType."' = 'PromoTrading' and ifNull(Items.Item_Pack,0) = 0 and ifNull(Items.Item_Promotion,0) = 1 and ifNull(Items.Item_Visible,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."' = 'NonStock'     and ifNull(Items.Item_Pack,0) = 0 and ifNull(Items.Item_Production,0) = 0 and ifNull(Items.Item_SemiFinished,0) = 0  and ifNull(Items.Item_NonStock,0) = 1) or ".
		"      ('".$ItemType."' = 'Assemble'     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) ) or  ".
		"      ('".$ItemType."' = 'RawMaterial'  and  (ifNull(Items.Item_Production,0) = 0 and ifNull(Items.Item_SemiFinished,0) = 0 )) or  ".
		"      ('".$ItemType."' = 'All' and 1 = 1) ) ".
		//" and ifNull(Items.Item_Production,0) = 0 ".
		" and ((ifNull(Items.item_active,0) = 1 and 1 = 1) Or (ifNull(Items.item_active,0) = 0 and ifNull(Date_Format(Items.item_inactivedate,'%Y%m%d'), $TransDate) >= $TransDate) )  ".
		" and (('".$ItemGroup."' != '' and Items.Group_code = '".$ItemGroup."') or ('".$ItemGroup."' = '' and 1 = 1)) ";
		//" and if(StkTransaction.Item_Code is null, True, if($TransDate is null,True,Date_Format(Transaction_Date,'%Y%m%d') <= $TransDate)) ".
		//" and if($Module_Grn=1,Transaction_Type<>'PI' or Transaction_Type is null,True) ";
		
/*if ($Login_negativeQty == 0 || $Module_NegativeQuantity == 0)		
	$query = $query." and if(StkTransaction.Item_Code is null, True, ifNull(StkTransaction.Warehouse_Code, -1) = ifNull($ItemWh, ifNull(StkTransaction.Warehouse_Code, -1))) ";
		
if ($ItemType == 'PromoPacked') {		
	$query = $query." and (PackDt.PackDt_ToDate >= now() or PackDt.PackDt_ToDate is null ) ";
}

if ($ItemType == 'Packed' || $ItemType == 'PromoPacked') {		
	$query = $query."   group by Items.Item_Code, Items.Item_Description, PackDt.Item_CodePackDt, PackDt_Quantity, StkTransaction.Warehouse_Code ".
					" ) Q1 ".
					" group by Item_Code, Item_Description, Item_CodePackDt, Warehouse_Code ".
                    " ) Q2 ".
                    " group by Item_Code, Item_Description, Warehouse_Code ".
                    " order by if('".$ItemSort."'='ItemCode', Item_Code, Item_Description), Warehouse_Code ";
}
else {
	$query = $query." group by Items.Item_Code, Items.Item_Description, StkTransaction.Warehouse_Code ".
					" order by if('".$ItemSort."'='ItemCode', Items.Item_Code, Items.Item_Description), StkTransaction.Warehouse_Code  ";		
}	*/

//$query = $query." order by if('".$ItemSort."'='ItemCode', Items.Item_Code, Items.Item_Description)  ";

//by rod

//echo $appendcostcenter;exit;
$query = $query.  $appendcostcenter;


// echo $query;//exit;
// end by rod
if ($PItem_Description != '') {
	$query = $query." order by Items.Item_Description  ";
} else {
	$query = $query." order by Items.Item_Code  ";
}
 	
// if($startrange == '') $startrange = 0;
// if($perpage == '') $$perpage = 20;
// $query = $query." limit ".$startrange.",".$perpage;
// echo $query; exit;	

if($_GET['post']!="1") {
	
	$resultsearch=mysql_query($query,$connection) or die(mysql_error());
	$totalrows = mysql_num_rows($resultsearch);
	
	if ($startrange=='') $startrange = 0;
	if ($perpage=='')	 $perpage = 20;
		
	$query = $query." limit ".$startrange.",".$perpage;
	//echo $query;exit;
	$result1=mysql_query($query,$connection) or die(mysql_error());
	
	$ct = 0;
	while($rows=mysql_fetch_array($result1)){
		extract($rows);

		$ct+=1;

		if($frm==7 && $module_autodiscount==1){
		
		$DiscountPerc = GetDiscountValue($Item_Code,$ClientCode,$connection);
		 
		
		}
		
		if($ct%2==0)
		{
			$Color="style='color:#0000FF;background-color:".$grid_color1."'";
		} else {
			$Color="style='color:#0000FF;background-color:".$grid_color2."'";	
		}
		
		$vItemCode = rawurlencode($Item_Code);
		$itemSellingPrice = ConvertCurrency($base1, $CurrCode, $FromDate, $Item_SellingPrice1Base1, $connection);
		echo "<tr  $Color > 
				<td align='center'><label><span><img src='img/scroll-down-1.png' title='Show Details'  width='20' height='20' border='0' onMouseOver=\"style.cursor='pointer'\" onclick=\"ShowItemQtyByWarehouse('getitemqtybywh','slidingDiv$ct','".$Item_Code."',$ItemWh,'".$TransDate1."');\" style='vertical-align:bottom;'/></span></label>
				</td>
				<td align='left' ><span class='style4'>
				<a href='List_SorItems.php?vcurr=$vcurr&itemSellingPrice=$itemSellingPrice&Item_SellingPrice1Base1=$Item_SellingPrice1Base1&DiscountPerc=$DiscountPerc&Item_Unit=$Item_Unit&Item_Package=$Item_Package&Item_SellingPrice1Base2=$Item_SellingPrice1Base2&lcode=$vItemCode&frm=$frm&index=$index&ItemType=$ItemType&ItemSort=$ItemSort&ItemGroup=$ItemGroup&ItemWh=$Warehouse_Code&itemWarehoouse=$Item_WarehouseCode&TransDate=$TransDate1&rmadt_id=$rmadt_id&rmadtrpc_id=$rmadtrpc_id'>$Item_Code</a>
				</span>	<div id='slidingDiv$ct' class='slidingDiv slidingDivHide'></div></td>
				<td align='left' ><span class='style4'>$Item_Description </span></td>
				<td align='left' ><span class='style4'>$Item_Remark</span></td>
				<td align='center'><span class='style4'>".$Item_UnitSalesDesc."</span></td>
				<td align='left'><span class='style4'>".$Group_Code."</span></td>
				<td align='left'><span class='style4'>".$SubGroup_Code."</span></td>";

/*				
		if($FI_ShowCostPrice == 1) {		
			echo "<td align='left'><span class='style4'>".$Warehouse_Code."</span></td>
				  <td align='center'><span class='style4'>".$Item_UnitSalesDesc."</span></td>
				  <td align='right'><span class='style4'>".$QuantityExists."</span></td>
				  <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>";
		} else {
			echo "<td align='left'><span class='style4'>".$Warehouse_Code."</span></td>
				  <td align='center'><span class='style4'>".$Item_UnitSalesDesc."</span></td>
				  <td align='right'><span class='style4'>".$QuantityExists."</span></td>
				  <td align='left' colspan='4'><span class='style4'>&nbsp;</span></td>";
		}	*/	
				
		echo "</tr>";


	}
	
	echo"<tr><td colspan='6'>&nbsp;</td></tr>
		 <tr><td colspan='6'><table width='100%' border=0><tr><td width='270'>&nbsp;</td><td width='110' align='center'>";
		
	$diff= $startrange - $perpage;
		
	if (($diff) >= 0 ){
		$prvstartrange = $startrange - $perpage;
		echo"<img src='img/arrowleft.jpg' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
	}
	else
		echo "&nbsp;";
		
	echo"</td><td width='110' align='center'>";
		
		
	if ($startrange <= $totalrows){
		$startrange = $startrange + $perpage;
		if  ($startrange <= $totalrows)
			echo"<img src='img/arrowright.jpg' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
	} else
		echo "&nbsp;";
			
	echo"</td><td width='270'>&nbsp;</td></tr>";
	echo"</table>";

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

function ConvertCurrency($FromCurr, $ToCurr, $FromDate, $Amount, $connection)
	{
		$query = "SELECT ifNull(convertcurfunc('".$FromCurr."', '".$ToCurr."', '".$FromDate."', 0, 0, '', '', ifNull($Amount,0)),0) From Dual ";
		$result = mysql_query($query, $connection);
		$row = mysql_fetch_row($result);
		//echo $query;exit;
		Return	$row[0];

	}

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