<?php
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
session_start();

include("config.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);
	}
	
function getProductGrid($product_id,$connection){
	$query = "select Auto, name from product where Auto = $product_id";
	$result = mysql_query($query,$connection);
	$row = mysql_fetch_row($result);
	$product_name = $row[1];
	
	echo"<table border='0' style='table-layout:fixed' align='left' width='400px' valign='top' >
		<col width=100><col width=300>";
	echo "<tr>
			<td colspan='2'>
				<button type='button' id='btnSubmit' name='btnSubmit' onclick=\"saveProduct('$product_id');return false;\" title='Submit'><span><span>Submit</span></span></button>
			</td>
		</tr>";					
	echo "<tr>
			<td><span class='style1'>Product Name</span></td>
			<td><textarea name='product_name' id='product_name' cols='40' rows='4'>$product_name</textarea></td>
		</tr>";
	echo "</table>";
}

function getAllProductGrid($product_id,$connection){
	$query = "select Auto, name from product ";
	$result = mysql_query($query,$connection);
	
	
	echo" <table border='0' style='table-layout:fixed' align='left' width='320px' valign='top' >
		<col width=20><col width=20><col width=300>";
	echo "<tr><td></td><td></td><td><span class='style1'>Product Name</span></td></tr>";
	echo "</table>";
	echo"<div style='overflow-y:scroll;height:400px;overflow-x: hidden; width:340px;'>
		<table border='0' style='table-layout:fixed' align='left' width='320px' valign='top' >
		<col width=20><col width=20><col width=300>";
	$i=0;	
	while($row = mysql_fetch_row($result)){
		if($i%2) $bgcolor = "bgcolor = '#E6E6E6'";
		else $bgcolor = "bgcolor = '#F7F7F7'";
	echo "<tr $bgcolor>
			<td><img src='img/button_edit.png' onmouseover=\"this.style.cursor='pointer'\" onclick=\"editProduct('$row[0]')\" title='Edit Record' style='cursor: pointer;'></td>
			<td><img src='img/c_delete.png' onmouseover=\"this.style.cursor='pointer'\" onclick=\"deleteProduct('$row[0]')\" title='Edit Record' style='cursor: pointer;'></td>
			<td><span style='color:#5151FF; font-size:10px;'>$row[1]</span></td>
		</tr>";	
	$i++;		
	}
	echo "</table></div>";
}
	

function multiResult($strArray, $field){
	
	$strArray = explode('OR', strtoupper($strArray));
	$i=0;
	$querysearch = '';
	if(!(empty($strArray))){
		$querysearch = " and ( ";
		foreach( $strArray as $str){
			
			if($i > 0) $querysearch = $querysearch." or ";
			$querysearch = $querysearch." ifnull($field,'') like ('%".trim($str)."%') or ifnull($field,'') like ('% ".trim($str)."%') 
												or ifnull($field,'') like ('%".trim($str)." %')  ";
			$i++;	
		}
		$querysearch = $querysearch." ) ";
	}
	return $querysearch;
}

function multiResult2($strArray, $Arrfield){
	
	$strArray = explode('OR', strtoupper($strArray));
	$i=0;
	$querysearch = '';
	if(!(empty($strArray))){
		$querysearch = " and ( ";
		foreach( $strArray as $str){
			
			if($i > 0) $querysearch = $querysearch." or ";
			$j=0;
			foreach($Arrfield as $field){
				if($j > 0) $querysearch = $querysearch." or ";
				$querysearch = $querysearch." ifnull($field,'') like ('%".trim($str)."%')   or ifnull($field,'') like ('% ".trim($str)."%') 
												or ifnull($field,'') like ('%".trim($str)." %') ";
				$j++;
			}
			$i++;	
		}
		$querysearch = $querysearch." ) ";
	}
	
	return $querysearch;
}
function filterGrid($parameters, $perpage, $startrange, $connection){
$fromdate 				= $parameters['fromdate'];
$todate 				= $parameters['todate'];
$filterflag 			= $parameters['filterflag'];
$advfilterflag 			= $parameters['advfilterflag'];
$chkdetail 				= $parameters['chkdetail'];
$chkor 					= $parameters['chkor'];
$archive_company 		= $parameters['archive_company'];
$archive_consigned 		= $parameters['archive_consigned'];
$archive_loading 		= $parameters['archive_loading'];
$archive_freight 		= $parameters['archive_freight'];
$archive_shipper 		= $parameters['archive_shipper'];
$archive_docnumber 		= $parameters['archive_docnumber'];
$archive_discharge 		= $parameters['archive_discharge'];
$archive_producttype 	= $parameters['archive_producttype'];
$archive_container		= $parameters['archive_container'] ;
$archive_ForwarderL 	= $parameters['archive_ForwarderL'];
$archive_ForwarderB 	= $parameters['archive_ForwarderB'];
$archive_clearing 		= $parameters['archive_clearing'];
$period_id 				= $parameters['period_id'];
$chkdate 				= $parameters['chkdate'];
$chkdate2 				= $parameters['chkdate2'];
$advfield 				= $parameters['advfield'];
$orderby 				= $parameters['orderby'];
$archive_path			= $parameters['archive_path'];
$archive_issuedate		= $parameters['archive_issuedate'];
if($perpage == '') $perpage = 1000;
if($startrange == '') $startrange = 0;

if($filterflag == 1 || $advfilterflag == 1 ){

echo "<table border='0' style='table-layout:fixed' align='left' width='1300px' valign='top' > ";
echo "<col width='50px'><col width='130px'><col width='30px'><col width='30px'><col width='30px'><col width='100px'><col width='180px'><col width='180px'>
	<col width='100px'><col width='120px'><col width='100px'><col width='100px'><col width='100px'><col width='100px'><col width='50px'><col width='50px'><col width='50px'>";  
echo "<input type='hidden' name='startrange' value='$startrange'>";	 
$querysearch = $querysearch."select distinct companyname, consigned, portofloading, freight,shipper, containertype, ForwarderL, ForwarderB, clearingtime, issuedate, documentnumber, BL,
				GM, DT, fullpageBL, fullpageGM, fullpageDT, auto, autodt, period_id, autob from ( ";	
/*select '' as companyname, '' as consigned, '' as portofloading, '' as freight,'' as shipper, '' as containertye, '' as ForwarderL, '' as ForwarderB, '' as clearingtime ,'' as issuedate, documentnumber, '' as BL,
				filename as GM, '' as DT,  '' as fullpageBL, fullpage as fullpageGM, '' as fullpageDT, '' as vessel, '' as portofdischarge, '' as producttype,
				auto, '' as period_id
				from shipping
				union */				
if($chkdetail == 1)				
$querysearch = $querysearch." select ifnull(archiving.companyname, archivingdt.companyname) as companyname, consigned,  portofloading, freight, shipper, containertype, ForwarderL, ForwarderB,  clearingtime , issuedate, ifnull(archiving.documentnumber,archivingdt.documentnumber) as documentnumber,archiving.filename as BL,
				archivingb.filename as GM, archivingdt.filename as DT,  archiving.fullpage as fullpageBL, archivingb.fullpage as fullpageGM, archivingdt.fullpage as fullpageDT, vessel as vessel, portofdischarge, producttype as producttype,
				ifnull(archiving.auto, archivingdt.auto) as auto, archivingdt.auto as autodt, ifnull(archiving.PERIOD,archivingdt.PERIOD) as period_id, archivingb.auto as autob
				from archivingdt 
				left join archiving on archiving.documentnumber = archivingdt.documentnumber 
				left join archivingb on archivingb.documentnumber = archiving.documentnumber ";
else 	
$querysearch = $querysearch." 
				select archiving.companyname, consigned, portofloading, freight, shipper, containertype, ForwarderL, ForwarderB, clearingtime, issuedate, archiving.documentnumber, archiving.filename as BL,
				archivingb.filename as GM, '' as DT,  archiving.fullpage as fullpageBL, archivingb.fullpage as fullpageGM, '' as fullpageDT, vessel, portofdischarge, producttype,
				archiving.auto, '' as autodt,  archiving.PERIOD as period_id, archivingb.auto as autob
				from archiving
				left join archivingb on archivingb.documentnumber = archiving.documentnumber
				";
				
$querysearch = $querysearch." ) as Q where 1=1 ";
				
/*
union 
				select ifnull(archiving.companyname, archivingdt.companyname) as companyname, consigned, portofloading, freight, shipper, containertype, ForwarderL,ForwarderB, clearingtime ,issuedate, ifnull(archiving.documentnumber,archivingdt.documentnumber) as documentnumber, '' as BL,
				'' as GM, archivingdt.filename as DT,  '' as fullpageBL, '' as fullpageGM, archivingdt.fullpage as fullpageDT, vessel, portofdischarge, producttype,
				ifnull(archiving.auto, archivingdt.auto) as auto, archivingdt.auto  as autodt, ifnull(archiving.PERIOD,archivingdt.PERIOD) as period_id
				from archivingdt
				left join archiving on archiving.documentnumber = archivingdt.documentnumber 
*/
if($filterflag == 1 or $advfilterflag == 1){
	if($chkor == 1){
		if($archive_company != '')  $querysearch = $querysearch.multiResult($archive_company, 'companyname');
		if($archive_consigned != '') $querysearch = $querysearch.multiResult($archive_consigned, 'consigned');
		if($archive_loading != '')  $querysearch = $querysearch.multiResult($archive_loading, 'portofloading');
		if($archive_freight != '') $querysearch = $querysearch.multiResult($archive_freight, 'freight');
		if($archive_shipper != '') $querysearch = $querysearch.multiResult($archive_shipper, 'shipper');
		if($archive_docnumber != '') $querysearch = $querysearch.multiResult($archive_docnumber, 'documentnumber');
		if($archive_discharge != '') $querysearch = $querysearch.multiResult($archive_discharge, 'portofdischarge');
		if($archive_producttype != '') $querysearch = $querysearch.multiResult($archive_producttype, 'producttype');
		if($archive_container != '') $querysearch = $querysearch.multiResult($archive_container, 'containertype');
		if($archive_ForwarderL != '') $querysearch = $querysearch.multiResult($archive_ForwarderL, 'ForwarderL');
		if($archive_ForwarderB != '') $querysearch = $querysearch.multiResult($archive_ForwarderB, 'ForwarderB');
		if($archive_clearing != '') $querysearch = $querysearch.multiResult($archive_clearing, 'clearingtime');
	
	} else {	
		if($archive_company != '') $querysearch = $querysearch." and (ifnull(companyname,'') like ('%".$archive_company."%') or ifnull(companyname,'') like ('% ".$archive_company."%') 
												or ifnull(companyname,'') like ('%".$archive_company." %')  )";
		if($archive_consigned != '') $querysearch = $querysearch." and (ifnull(consigned,'') like ('%".$archive_consigned."%') or ifnull(consigned,'') like ('% ".$archive_consigned."%') 
									ifnull(consigned,'') like ('%".$archive_consigned." %') ) ";
		if($archive_loading != '') $querysearch = $querysearch." and (ifnull(portofloading,'') like ('%".$archive_loading."%') or ifnull(portofloading,'') like ('% ".$archive_loading."%')
									or ifnull(portofloading,'') like ('%".$archive_loading." %')) ";
		if($archive_freight != '') $querysearch = $querysearch." and (ifnull(freight,'') like ('%".$archive_freight."%') or ifnull(freight,'') like ('% ".$archive_freight."%') 
									or ifnull(freight,'') like ('%".$archive_freight." %')) ";
		if($archive_shipper != '') $querysearch = $querysearch." and (ifnull(shipper,'') like ('%".$archive_shipper."%') or ifnull(shipper,'') like ('% ".$archive_shipper."%') 
									or ifnull(shipper,'') like ('%".$archive_shipper." %')) ";
		if($archive_docnumber != '') $querysearch = $querysearch." and (ifnull(documentnumber,'') like ('%".$archive_docnumber."%') or ifnull(documentnumber,'') like ('% ".$archive_docnumber."%')
									or ifnull(documentnumber,'') like ('%".$archive_docnumber." %') )";
		
		if($archive_discharge != '') $querysearch = $querysearch." and (ifnull(portofdischarge,'') like ('%".$archive_discharge."%') or ifnull(portofdischarge,'') like ('% ".$archive_discharge."%')
									or  ifnull(portofdischarge,'') like ('%".$archive_discharge." %') ) ";
		if($archive_producttype != '') $querysearch = $querysearch." and (ifnull(producttype,'') like ('%".$archive_producttype."%') or ifnull(producttype,'') like ('%".$archive_producttype."%') 
									or ifnull(producttype,'') like ('%".$archive_producttype."%') ) ";
		
		if($archive_container != '') $querysearch = $querysearch." and (ifnull(containertype,'') like ('%".$archive_container."%') or ifnull(containertype,'') like ('% ".$archive_container."%') 
									or ifnull(containertype,'') like ('%".$archive_container." %') ) ";
		if($archive_ForwarderL != '') $querysearch = $querysearch." and (ifnull(ForwarderL,'') like ('%".$archive_ForwarderL."%') or ifnull(ForwarderL,'') like ('% ".$archive_ForwarderL."%') 
									or ifnull(ForwarderL,'') like ('%".$archive_ForwarderL." %')) ";
		if($archive_ForwarderB != '') $querysearch = $querysearch." and (ifnull(ForwarderB,'') like ('%".$archive_ForwarderB."%') or ifnull(ForwarderB,'') like ('% ".$archive_ForwarderB."%') 
									or ifnull(ForwarderB,'') like ('%".$archive_ForwarderB." %') ) ";
		if($archive_clearing != '') $querysearch = $querysearch." and (ifnull(clearingtime,'') like ('%".$archive_clearing."%') or ifnull(clearingtime,'') like ('% ".$archive_clearing."%') 
									or ifnull(clearingtime,'') like ('%".$archive_clearing." %')) ";
	}
	if($period_id != '') $querysearch = $querysearch." and ifnull(period_id,'') like ('%".$period_id."%') ";
	
	if($chkdate == 1) 
		$querysearch = $querysearch." and ( Check_DateFormat(issuedate) between date_format('$fromdate','%Y-%m-%d') and date_format('$todate','%Y-%m-%d') ) ";
	if($chkdate2 == 1) 
		$querysearch = $querysearch." and ( Check_DateFormat(issuedate) = date_format('$archive_issuedate', '%Y-%m-%d')) ";
	
} if($advfilterflag == 1){
		if($chkor == 1){
			$arrField = array('fullpageBL', 'fullpageGM', 'fullpageDT');
			if($advfield != '') $querysearch = $querysearch.multiResult2($advfield, $arrField);
		} else{
		if($advfield != '') 
			$querysearch = $querysearch." and ( ifnull(fullpageBL,'') like ('%".$advfield."%') or ifnull(fullpageBL,'') like ('% ".$advfield."%') or ifnull(fullpageBL,'') like ('%".$advfield." %') or 
							ifnull(fullpageGM,'') like ('%".$advfield."%') or ifnull(fullpageGM,'') like ('% ".$advfield."%') or ifnull(fullpageGM,'') like ('%".$advfield." %') or
							ifnull(fullpageDT,'') like ('%".$advfield."%') or ifnull(fullpageDT,'') like ('% ".$advfield."%') or ifnull(fullpageDT,'') like ('%".$advfield." %') ) ";
		}
	}
if($orderby == '1') $querysearch = $querysearch." order by  documentnumber desc ";
else  $querysearch = $querysearch." order by auto desc ";

//echo $querysearch;//exit;
$resultsearch = mysql_query($querysearch,$connection);
$totalrows = mysql_num_rows($resultsearch);

$querysearch = $querysearch." limit ".$startrange.",".$perpage;
	 
echo "<tr><td colspan='2'><span class='style1'>Results: $totalrows Row(s)</span></td><td colspan='4'><span class='style1'>Per Page </span><span class='style4'><select name='perpage' id='perpage' value='$perpage' onchange=\"RefreshPage();\">";
	if ($perpage==100)
		$s20 = 'selected';
	else if ($perpage==250)
		$s30 = 'selected';
	else if ($perpage==500)
		$s40 = 'selected';
	else if ($perpage==1000)
		$s50 = 'selected';
echo'<option '.$s20.' value="100">100</option>
	 <option '.$s30.' value="250">250</option>
	 <option '.$s40.' value="500">500</option>
	 <option '.$s50.' value="1000">1000</option>
	 </select></span>';	
echo "<td colspan='3'>";
	if($startrange > 0)
		echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='hand'\" onclick=SetFirstPage('0','".$perpage."','".json_encode($parameters)."')>";

	$diff= $startrange - $perpage;
		
	if (($diff) >= 0 ){
		$prvstartrange = $startrange - $perpage;
		echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."','".json_encode($parameters)."')>";
	}
	else
		echo "&nbsp;";
echo "</td><td colspan='3'>";	
	if ($startrange <= $totalrows){
		$startrange1 = $startrange + $perpage;
		if  ($startrange1 < $totalrows){
			echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange1."','".$perpage."','".json_encode($parameters)."')>";
			echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='hand'\" onclick=SetLastPage('".$perpage."','".$totalrows."','".json_encode($parameters)."')>";	
		}
	} else
		echo "&nbsp;";
echo"</td><td colspan='4'></td></tr>";
echo "<tr>
		<td><span class='style1'>Auto #</span></td>
		<td><span class='style1'>Document #</span></td>
		<td><span class='style1'>BL</span></td>
		<td><span class='style1'>GM</span></td>
		<td><span class='style1'>DT</span></td>
		<td><span class='style1'>Company Name</span></td>
		<td><span class='style1'>Shipper</span></td>
		<td><span class='style1'>Consigned</span></td>
		<td><span class='style1'>Port of Loading</span></td>
		<td><span class='style1'>Freight</span></td>
		<td><span class='style1'>Container</span></td>
		<td><span class='style1'>Forwarder L</span></td>
		<td><span class='style1'>Forwarder D</span></td>
		<td><span class='style1'>Clearing Time</span></td>
		<td><span class='style1'>Full Page BL</span></td>
		<td><span class='style1'>Full Page GM</span></td>
		<td><span class='style1'>Full Page DT</span></td>
	  </tr>";
echo "<tr><td colspan='16'><hr></td></tr>";

	  $i = 0;
	$resultsearch = mysql_query($querysearch,$connection);  
	while($rows = mysql_fetch_array($resultsearch)){
		extract($rows);
		
	if($i%2) $bgcolor = "bgcolor = '#E6E6E6'";
		else $bgcolor = "bgcolor = '#F7F7F7'";
		
	echo "<tr $bgcolor>
			<td><span class='style111'>$auto</span></td>
			<td><span class='style111'>$documentnumber</span></td>";
	echo "<td><span class='style111'>";
	if($BL != '')
	echo "<a href='./$archive_path$BL' download><img src='./icon/open-folder.png' height='20' width='20' ></a>";
	echo"</span></td>";
	echo "<td><span class='style111'>";
	if($GM != '')
	echo "<a href='./$archive_path$GM' download ><img src='./icon/open-folder.png' height='20' width='20' ></a>";
	echo"</span></td>";
	echo "<td><span class='style111'>";
	if($DT != '')
	echo "<a href='./$archive_path$DT' download ><img src='./icon/open-folder.png' height='20' width='20' ></a>";
	echo"</span></td>";
	echo "	<td><span class='style111'>$companyname</span></td>
	        <td><span class='style111'>$shipper</span></td>
			<td><span class='style111'>$consigned</span></td>
			<td><span class='style111'>$portofloading</span></td>
			<td><span class='style111'>$freight</span></td>
			<td><span class='style111'>$containertype</span></td>
			<td><span class='style111'>$ForwarderL</span></td>
			<td><span class='style111'>$ForwarderB</span></td>
			<td><span class='style111'>$clearingtime</span></td>"; 
	echo "<td><span class='style111'>";
	if($fullpageBL != '')		
	echo "<img src='./icon/open-folder.png' height='20' width='20' onclick=\"viewPage('$auto','BL');\">";
	echo"</span></td>";
	echo "<td><span class='style111'>";
	if($fullpageGM != '')
	echo "<img src='./icon/open-folder.png' height='20' width='20' onclick=\"viewPage('$autob','GM');\">";
	echo"</span></td>";
	echo "<td><span class='style111'>";
	if($fullpageDT != '')
	echo "<img src='./icon/open-folder.png' height='20' width='20' onclick=\"viewPage('$autodt','DT');\" >";
	echo"</span></td></tr>";	
	$i++;
	}
	

echo "</table>";
}
}	

function offerdtGrid($offer_id, $connection){
	echo "<table align='left'  border='0' width='1000px' >
	<col width='20px'><col width='30px'><col width='150px'><col width='180px'><col width='200px'><col width='100px'>
	<col width='60px'><col width='80px'><col width='80px'><col width='50px'>";

$i = 0;
$rnbr = 1;
$queryitems = "select item_code, item_description from items where SubGroup_code is not null order by SubGroup_code, item_code ";
$querycurr = "select currency_code from currency order by currency_code ";

$Disabled = 0;
$query ="select ifnull(CONFIRMED,0) from archivingoffer where auto='$offer_id';";
$res = mysql_query($query,$connection);
$row = mysql_fetch_row($res);
if ($row[0] == 1) $Disabled = 1;

if ($offer_id != ''){
	$querydt = "select offerdt_id, archivingofferdt.item_code, item_description, description, amount, qty, discount, archivingofferdt.currency_code 
				from archivingofferdt left join items on items.item_code = archivingofferdt.item_code
				where offer_id = $offer_id "; 
	$resdt = mysql_query($querydt, $connection);
	while ($rwdt = mysql_fetch_array($resdt)){
		$offerdt_id 			= $rwdt[0];
		$itemcode[$i] 			= $rwdt[1];
		$itemdesc[$i] 			= $rwdt[2];
		$txtdescription[$i] 	= $rwdt[3];
		$txtamount[$i] 			= $rwdt[4];
		$txtcurrency_code[$i] 	= $rwdt[7];
		$txtqty[$i] 			= $rwdt[5];
		$txtdiscount[$i] 		= $rwdt[6];
		
		echo "<tr height='30px' >
		<td>$rnbr</td><td><img src='img/delete.png' onmouseover=\"style.cursor='hand'\" ";
		if ($Disabled == 0) echo " onclick=\"DeleteRecord('$i', '$offerdt_id');\" ";
		echo " title='Delete Detail' style='width: 20px; height: 20px; cursor: pointer;'></td>
		<td align='center'><select name='itemcode$i' id='itemcode[$i]' style='width:145px;' onchange=\"setItemInfo('$i');\">";
		echo "<option value='' ".($itemcode[$i] == ''?'selected':'')."></option>";
		$resitems = mysql_query($queryitems, $connection);
		while ($rwitems = mysql_fetch_array($resitems)){
			echo "<option value='$rwitems[0]' ".($itemcode[$i] == $rwitems[0]?'selected':'').">$rwitems[0]</option>";
		}
		echo "</select></td>";
		echo "<td align='center'><input type='text' name='itemdesc$i' id='itemdesc[$i]' value='$itemdesc[$i]' style='width:175px;' readonly></td>";
		echo "<td align='center'><input type='text' name='txtdescription$i' id='txtdescription[$i]' value='$txtdescription[$i]' style='width:195px;'></td>";
		echo "<td align='center'><input type='text' name='txtamount$i' id='txtamount[$i]' value='$txtamount[$i]' style='width:95px;'></td>";
		echo "<td align='center'><select name='txtcurrency_code$i' id='txtcurrency_code[$i]' style='width:55px;'>";
		echo "<option value='' ".($txtcurrency_code[$i]==''?'selected':'')."></option>";
		$rescurr = mysql_query($querycurr, $connection);
		while($rwcurr = mysql_fetch_array($rescurr)){
			echo "<option value='$rwcurr[0]' ".($txtcurrency_code[$i]==$rwcurr[0]?'selected':'').">$rwcurr[0]</option>";
		}
		echo "</select></td>";
		echo "<td align='center'><input type='text' name='txtqty$i' id='txtqty[$i]' value='$txtqty[$i]' style='width:75px;'></td>";
		echo "<td align='center'><input type='text' name='txtdiscount$i' id='txtdiscount[$i]' value='$txtdiscount[$i]' style='width:75px;'></td>";
		echo "<td align='center'><input type=button' id='imgSubmit[$i]' ";
		if ($Disabled == 0) echo " onclick=\"submitDetails('$i','$offerdt_id');\" ";
		echo "title='Submit Record' style=\"width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png);\"></td>
	  </tr>";
		$rnbr++;
		$i++;
	}

}
echo "<tr height='30px' >
		<td>$rnbr</td><td></td>
		<td align='center'><select name='itemcode$i' id='itemcode[$i]' style='width:145px;' onchange=\"setItemInfo('$i');\">";
		echo "<option value=''></option>";
		$resitems = mysql_query($queryitems, $connection);
		while ($rwitems = mysql_fetch_array($resitems)){
			echo "<option value='$rwitems[0]' >$rwitems[0]</option>";
		}
		echo "</select></td>";
		echo "<td align='center'><input type='text' name='itemdesc$i' id='itemdesc[$i]' value='' style='width:175px;' readonly></td>";
		echo "<td align='center'><input type='text' name='txtdescription$i' id='txtdescription[$i]' value='' style='width:195px;'></td>";
		echo "<td align='center'><input type='text' name='txtamount$i' id='txtamount[$i]' value='' style='width:95px;'></td>";
		echo "<td align='center'><select name='txtcurrency_code$i' id='txtcurrency_code[$i]' style='width:55px;'>";
		echo "<option value=''></option>";
		$rescurr = mysql_query($querycurr, $connection);
		while($rwcurr = mysql_fetch_array($rescurr)){
			echo "<option value='$rwcurr[0]' >$rwcurr[0]</option>";
		}
		echo "</select></td>";
		echo "<td align='center'><input type='text' name='txtqty$i' id='txtqty[$i]' value='' style='width:75px;'></td>";
		echo "<td align='center'><input type='text' name='txtdiscount$i' id='txtdiscount[$i]' value='' style='width:75px;'></td>";
		echo "<td align='center'><input type=button' id='imgSubmit[$i]' ";
		if ($Disabled == 0) echo " onclick=\"submitDetails('$i','');\" ";
		echo " title='Submit Record' style=\"width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png);\"></td>
	  </tr>";	
	$rnbr++;
	$i++;
echo "</table>";
}

?>