<?php



session_start();
if($HTTP_SESSION_VARS['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("Functions_Sales.php");
include("Forms_DataGrid.php");

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


$querylog="SELECT FI_DeliveryStatus as loginaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')	";
	$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultlog)){
		extract($rows);
	}

if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");


//Read From Module Table
$querymodule=" Select ifNull(Module_Delivery,0) As Module_Delivery, ifNull(Module_DirectStock,0) As Module_DirectStock, ".
		     " ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_ProjectParent,0) As Module_ProjectParent, ifNull(Module_CostCenterParent,0) As Module_CostCenterParent, ".
             " ifNull(Module_PrintWaybill,0) As Module_PrintWaybill, ifNull(Module_PostToJournal,0) As Module_PostToJournal From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}
	
//Read From Setup Table							
$querysetup= " select grid_color1, grid_color2,maxperpage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}
 
  
//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ifNull(Client_ValidateProject,0) as Client_ValidateProject, ".
             " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_AdditionalTaxes,0) As Module_AdditionalTaxes, ifNull(Module_Delivery,0) As Module_Delivery, ".
             " ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_RestrictProjCost,0) As Module_RestrictProjCost, ifNull(Module_RestrictCost,0) As Module_RestrictCost, ".
             " ifNull(module_DeliveryWithSorder,0) As Module_DeliveryWithSorder, ifNull(Module_DirectStock,0) As Module_DirectStock, ".
			 " ifNull(Module_PrintWaybill,0) As Module_PrintWaybill, ifNull(Module_ShowBalance,0) As Module_ShowBalance,	".
			 " ifNull(Module_SerialNo,0) As Module_SerialNo, ifNull(Module_PostToJournal,0) As Module_PostToJournal, ".
			 " ifNull(Module_ReferenceByProject,0) As Module_ReferenceByProject, ifNull(Module_CreditLimitByProj,0) As Module_CreditLimitByProj, ".
			 " ifNull(Module_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostCenterDt,0) As Module_CostCenterDt, ".
			 " ifNull(Module_DoubleUnit,0) As Module_DoubleUnit, ifNull(Module_ExpireDate,0) As Module_ExpireDate, ".
			 " ifNull(Module_Pack,0) As Module_Pack, ifNull(Module_Unit1Method,0) As Module_Unit1Method,  ".
			 " ifNull(Module_DeliveryClosingQty,0) As Module_DeliveryClosingQty, ifNull(Module_ChangeInvoiceItems,0) As Module_ChangeInvoiceItems, ".
			 " ifNull(Module_NegativeQuantity,0) As Module_NegativeQuantity, ifNull(Module_VehicleWeight,0) As Module_VehicleWeight, ".	
			 " ifNull(Module_LoadSoldItems,0) as Module_LoadSoldItems ".
			 " ,ifNull(Module_ImportExcell,0) As Module_ImportExcell ".
             " From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

//Read From SalesSetup Table
$querySalesSetup=" Select SalesTTC, ClientCur, Warehouse As SetupDftWareHouse, ifNull(ExportTransportToJV,0) As ExportTransportToJV, ".
				 " ifNull(ExportBonusToJV,0) As ExportBonusToJV, ifNull(Sale_MaxExceedQty,0) As Sale_MaxExceedQty, ifNull(ShowCostCentLayout,0) As ShowCostCentLayout From SalesSetup";
$resultSalesSetup=mysql_query($querySalesSetup,$connection) or die(mysql_error());
while($rowSalesSetup=mysql_fetch_array($resultSalesSetup)){
	extract($rowSalesSetup);
}

$querydflwh="select warehouse_code as defaultwarehouse from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."' and ifNull(default_warehouse,0) = 1 ";
$resultdflwh=mysql_query($querydflwh,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflwh)){
  extract($rows);
}



print <<<HERE
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}
.style1 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}

</style>

<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>


<link type="text/css" href="js/calendar/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datepick.js"></script>

<link type="text/css" href="js/grid/scripts/jquery-ui.css" rel="stylesheet">
<script type="text/javascript" src="js/grid/scripts/jquery-ui.min.js"></script>

<script type="text/javascript" language="javascript">
	$(document).ready(function() { 
		
		$(document).on('focus', '.date', function() {
			$('.date').datepick({showTrigger: '#calImg'});
		});
		
		$(document).on('focusin', '.table-focus-g1', function() {
			AutoSaveRecordGrid(this.id,'SelectedRec','ModRec_G1','imgSubmit');
			selRecordColor(this,'SelectedRec','SelectedRecColor');
		});
		
		//Set Scroll Positions on Page Load
		scrollToPage();
		
		$(window).scroll(function(){
			scrollPage();
		});
		
		//Set Cursor Position After Page Reload
		var NextElement = readCookie('ass-nextcell');
		MoveNextRecord(NextElement);
		eraseCookie('ass-nextcell');
		
		
		
	});
	
	
</script>

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



function returncolor(vobj,vtextname,vcolorname){

 

if (document.getElementById(vtextname).value=='')
	{
		document.getElementById(vtextname).value = vobj.id;
		document.getElementById(vcolorname).value = vobj.style.backgroundColor;
	}	
else {
var prevobj = document.getElementById(vtextname).value;
document.getElementById(prevobj).style.backgroundColor = document.getElementById(vcolorname).value;

		document.getElementById(vtextname).value = vobj.id;
		document.getElementById(vcolorname).value = vobj.style.backgroundColor;
}	
vobj.style.backgroundColor='#B8EDFF';
}







function showrelation(itemcode,lotnum){
 
	 
	
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
				{ 
				
					var data = xmlhttp.responseText.split("[BRK]");
					
					if(data[0]=='purchase')
						document.getElementById('purchasesdt').innerHTML=data[1];
					 
					if(data[0]=='production')
						document.getElementById('production').innerHTML=data[1];
					
				}
		}
  }

		xmlhttp.open("GET","Form_Productiongrid_Actions.php?actionmode=showrelation&itemcode="+itemcode+"&lotnum="+lotnum);
		xmlhttp.send();
 	

}


</script>

<title>Prodgrid</title>


<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>

</head>
<body>
<form name='production' method='post'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='message' value='$message' size='200'>

HERE;



 
$Parameters = array();
$Parameters['FI_SalesCheckSalesman'] = $FI_SalesCheckSalesman;
$Parameters['FI_DeliverySalesPrice'] = $FI_DeliverySalesPrice;
$Parameters['Login_NegativeQty'] = $Login_NegativeQty;
$Parameters['Login_ModifySellingPrice'] = $Login_ModifySellingPrice;
$Parameters['Login_ModifyDiscount'] = $Login_ModifyDiscount;
$Parameters['Login_MinAllowCostPer'] = $Login_MinAllowCostPer;
$Parameters['Login_MaxAllowCostPer'] = $Login_MaxAllowCostPer;
$Parameters['Module_Delivery'] = $Module_Delivery;
$Parameters['Module_NegativeQuantity'] = $Module_NegativeQuantity;
$Parameters['Module_Unit1Method'] = $Module_Unit1Method;
$Parameters['Module_Pack'] = $Module_Pack;
$Parameters['Module_DoubleUnit'] = $Module_DoubleUnit;
$Parameters['Module_Project'] = $Module_Project;
$Parameters['Module_CostCenter'] = $Module_CostCenter;
$Parameters['Module_ProjectDt'] = $Module_ProjectDt;
$Parameters['Module_CostCenterDt'] = $Module_CostCenterDt;
$Parameters['Module_RestrictProjCost'] = $Module_RestrictProjCost;
$Parameters['Module_RestrictCost'] = $Module_RestrictCost;
$Parameters['ShowCostCentLayout'] = $ShowCostCentLayout;
$Parameters['Module_SerialNo'] = $Module_SerialNo;
$Parameters['Module_ExpireDate'] = $Module_ExpireDate;
$Parameters['Module_DeliveryClosingQty'] = $Module_DeliveryClosingQty;
$Parameters['Module_DeliveryWithSorder'] = $Module_DeliveryWithSorder;
$Parameters['Sale_MaxExceedQty'] = $Sale_MaxExceedQty;
$Parameters['SalesTTC'] = $SalesTTC;
$Parameters['DecimalBase'] = $DecimalBase;
$Parameters['Setup_VatPercentage'] = $Setup_VatPercentage;
$Parameters['Module_AdditionalTaxes'] = $Module_AdditionalTaxes;
$Parameters['ExportTransportToJV'] = $ExportTransportToJV;
$Parameters['ExportBonusToJV'] = $ExportBonusToJV;
$Parameters['VatApplied'] = $VatApplied;
$Parameters['AllowModifyVAT'] = $AllowModifyVAT;

$Parameters['SetupDftWareHouse'] = $SetupDftWareHouse;
$Parameters['defaultwarehouse']  = $defaultwarehouse;

$Parameters['txtDate'] 		   = $txtDate;
$Parameters['txtClientCode']   = $txtClientCode;
$Parameters['txtClientDetail'] = $txtClientDetail;
$Parameters['txtCurrCode']     = $txtCurr;
$Parameters['Base1']    	   = $base1;
$Parameters['Base2']    	   = $base2;
$Parameters['useraccount']    	   =  $_SESSION['username'];


$Parameters['dbLabel']    	   =  $HTTP_SESSION_VARS['dbLabel'];
$Parameters['useraccount1']    	   =  $HTTP_SESSION_VARS['useraccount'];
$Parameters['Module_CostCenterParent']    	   =  $Module_CostCenterParent;
$Parameters['Module_ProjectParent']    	   =  $Module_ProjectParent;
$_SESSION['gpr_parameters']  = $Parameters;


//echo $lotnum;
//echo $itemcode;



echo "<font color=red><b>"."Production"."</b></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' value='Refresh' onclick='javascript:document.production.submit();'>";
echo"<div  id='production' style='overflow:scroll; height:250px; width:850px;' >";
ShowProductionDtGrid($itemcode,$lotnum,$connection,$_SESSION['gass_parameters'],$_SESSION['gass_arrayaccess']);
echo"</div>";



echo"<br><br>";
echo "<font color=red><b>"."Purchase"."</b></font>";
echo"<div id='purchasesdt' style='overflow:scroll; height:250px; width:850px;' >";
ShowPurchasesDtGrid($itemcode,$lotnum,$connection,$_SESSION['gass_parameters'],$_SESSION['gass_arrayaccess']);
echo"</div>";



function ShowProductionDtGrid($itemcode,$lotnum,$connection,$arrayparams,$arrayaccess){

	$DecimalBase  = $arrayparams['DecimalBase'];
	$DecimalBase1 = $arrayparams['DecimalBase1'];
	$DecimalBase2 = $arrayparams['DecimalBase2'];
	$Journal_DefaultCur = $arrayparams['Journal_DefaultCur'];
	$Base1 = $arrayparams['Base1'];
	$Base2 = $arrayparams['Base2'];
	
	$Module_Project = $arrayparams['Module_Project'];
	$Module_CostCenter = $arrayparams['Module_CostCenter'];
	$Module_ProjectDt = $arrayparams['Module_ProjectDt'];
	$Module_CostCenterDt = $arrayparams['Module_CostCenterDt'];
	
	$txtJourDate = $arrayparams['txtJourDate'];
	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_DataGrid.php';
	
	$i = 0;
		
		
	echo"
		
		 <input type='hidden' name='deliverydt_quantity' id='deliverydt_quantity' value='$deliverydt_quantity'>
		 <input type='hidden' name='SelectedRecDt' id='SelectedRecDt' value='$SelectedRecDt'>
		 <input type='hidden' name='SelectedRecColorDt' id='SelectedRecColorDt' value='$SelectedRecColorDt'>
		 
		 ";
	
				  
			$query = " Select ProductionDt.ProductionDt_ID, ProductionDt.Item_CodePacked, ProductionDt.Item_code, Item_Description, ProductionDt.Warehouse_Code, ".
					 " ProductionDt_Remark, ProductionDt_Quantity, ProductionDt_IdealQty,ProductionDt_BatchNo, Round(ProductionDt_Cost, 2), ProductionDt_CostBase1, ProductionDt_CostBase2, ".
					 " ifNull(ProductionDt_IdealQty,0) - ifNull(ProductionDt_Quantity,0) As ProductionDtWasteCalc, ProductionDt_Waste, ".
					 " Round((ProductionDt_Quantity*ProductionDt_Cost), 2) As TotalActual, ".
					 " Round((ProductionDt_IdealQty*ProductionDt_Cost), 2) As TotalIdeal, ".
					 " ifNull(item_withserialno,0) As ItemWithSerialNo, Item_UnitSalesDesc, ".
					 " Date_Format(ProductionDt_ExpireDate,'%d/%m/%Y') As ProductionDt_ExpireDate, ProductionDt_BatchNo, ProductionDt.Project_code, ".
					 " ProductionDt.CostCenter_Code, ifNull(ProductionDt_Checked,1) as ProductionDt_Checked,date_format(Production.Production_Date,'%d/%m/%Y'),Production_Reference ".
					 " From ProductionDt As ProductionDt Left Join Items on ProductionDt.Item_code = Items.Item_code ".
					 " Inner Join Production on Production.Production_ID = Productiondt.Production_ID ".
					 $query = $query . " WHERE 1=1 ";
					 $query = $query . " And Production.Production_BatchNo = '".$lotnum."' ";
					 $query = $query . " and Production.Item_Code = '$itemcode' ";
					 $query = $query . " Group By  ProductionDt.ProductionDt_ID ";
					 $query = $query . " Order By Production.Production_Date,Production_Reference,item_code  ";
					 			 
	         //echo $query;
			 //exit; 
			 
			 
		echo"<table onMouseOver=\"style.cursor='pointer'\"  border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:670px;'>";
		echo"<col width=90>";
		echo"<col width=90>";
		echo"<col width=90>";
		echo"<col width=90>";
		echo"<col width=190>";
		echo"<col width=60>";
		echo"<col width=40>";
		echo"<col width=200>";
		echo"  <th align='center' ><span>Date</span></th>";
		echo"  <th align='center' ><span>Reference</span></th>";
		echo"  <th align='center' ><span>Batch No.</span></th>";
		echo"  <th align='center' ><span>Item Code</span></th>";
		echo"  <th align='center' ><span>Description</span></th>";
		echo"  <th align='center' ><span>Warehouse</span></th>";
		echo"  <th align='center' ><span>Qty</span></th>";
		echo"  <th align='center' ><span>Remark</span></th>";
	//echo $query;
	$i=0;
	$result=mysql_query($query,$connection) or die(mysql_error());
    while ($row=mysql_fetch_array($result)){
	
	
	if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';

				
				
	echo"<tr height=20 id='deliverydt$row[0]' class='$bgcolor table-focus-g1'  
					onclick=\"returncolor(this,'SelectedRecDt','SelectedRecColorDt','$row[0]');showrelation('".$row[2]."','".$row[8]."')\" 
					 
					
					>";
	echo"<td>$row[23]</td>";
	echo"<td>$row[24]</td>";
	echo"<td>$row[8]</td>";
	echo"<td>$row[2]</td>";
	echo"<td>$row[3]</td>";
	echo"<td>$row[4]</td>";
	echo"<td>$row[6]</td>";
	echo"<td>$row[5]</td>";
	echo"</tr>";
	$i+=1;
	}
	echo"</table>";
	

	
	

}




function ShowPurchasesDtGrid($itemcode,$lotnum,$connection,$arrayparams,$arrayaccess){

	$DecimalBase  = $arrayparams['DecimalBase'];
	$DecimalBase1 = $arrayparams['DecimalBase1'];
	$DecimalBase2 = $arrayparams['DecimalBase2'];
	$Journal_DefaultCur = $arrayparams['Journal_DefaultCur'];
	$Base1 = $arrayparams['Base1'];
	$Base2 = $arrayparams['Base2'];
	
	$Module_Project = $arrayparams['Module_Project'];
	$Module_CostCenter = $arrayparams['Module_CostCenter'];
	$Module_ProjectDt = $arrayparams['Module_ProjectDt'];
	$Module_CostCenterDt = $arrayparams['Module_CostCenterDt'];
	
	$txtJourDate = $arrayparams['txtJourDate'];
	
	//Initializations
	
	$ClassE = 'grid_roundedtext1';
	$ClassI = 'grid_roundedtext2';
	
	$filepath = 'Forms_DataGrid.php';
	
	$i = 0;
		
		
	echo"
		
		 <input type='hidden' name='deliverydt_quantity' id='deliverydt_quantity' value='$deliverydt_quantity'>
		 <input type='hidden' name='SelectedRecDt' id='SelectedRecDt' value='$SelectedRecDt'>
		 <input type='hidden' name='SelectedRecColorDt' id='SelectedRecColorDt' value='$SelectedRecColorDt'>
		 
		 ";
	
				  
			$query = " Select PurchasesDt.PurchaseDt_ID, PurchasesDt.Item_CodePacked, PurchasesDt.Item_code, Item_Description, PurchasesDt.Warehouse_Code, ".
					 " Purchasedt_Remark, PurchaseDt_Quantity, PurchaseDt_Volume, Round(PurchaseDt_Price, 2), PurchaseDt_PriceBase1, PurchaseDt_PriceBase2, ".
					 " Round(PurchaseDt_DiscountPer, 2), PurchaseDt_ChargePer, PurchaseDt_ChargesAmnt, PurchaseDt_ChargesAmntB1, PurchaseDt_ChargesAmntB2,  ".
					 " Round(((PurchaseDt_Quantity*PurchaseDt_Price)-((PurchaseDt_Quantity*PurchaseDt_Price*ifNull(PurchaseDt_DiscountPer,0))/100)), 2) As Total, ".
					 " Round(PurchaseDt_PriceTTC, 2), ".
					 " Round(((PurchaseDt_Quantity*PurchaseDt_PriceTTC)-((PurchaseDt_Quantity*PurchaseDt_PriceTTC*ifNull(PurchaseDt_DiscountPer,0))/100)), 2) As TotalTTC, ".
					 " PurchasesDt.Item_Unit2Qty, Item_UnitPurchaseDesc, Item_UnitSalesDesc, PurchasesDt.Project_code, PurchasesDt.CostCent_Code,  ".
					 " PorderDt.PorderDt_Quantity, Porder.Porder_reference, PurchasesDt.RelatedDt_Id, ifNull(item_withserialno,0) As ItemWithSerialNo,   ".
					 " Date_Format(PurchaseDt_ExpireDate,'%d/%m/%Y') As PurchaseDt_ExpireDate, PurchaseDt_BatchNo,date_format(Purchases.Purchase_date,'%d/%m/%Y'),Purchase_Reference  ".
					 " From PurchasesDt As PurchasesDt Left Join Items on PurchasesDt.Item_code = Items.Item_code ".			 
					 " Left Join PorderDt on PorderDt.PorderDt_ID = PurchasesDt.RelatedDt_Id  ".
					 " Left Join Porder on Porder.Porder_ID = PorderDt.Porder_ID  ".
					  " Left Join Purchases on Purchases.Purchase_ID = PurchasesDt.Purchase_ID  ".
					 " Where PurchasesDt.Item_Code = '".$itemcode."' ";
					$query = $query ."	 and PurchasesDt.PurchaseDt_BatchNo = '".$lotnum."'".
								" Order By PurchasesDt.item_Code ";
					 			 
	         
		//	 echo $query;
			 
		echo"<table onMouseOver=\"style.cursor='pointer'\"  border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='1' style='width:670px;'>";
		echo"<col width=90>";
		echo"<col width=90>";
		echo"<col width=90>";
		echo"<col width=190>";
		echo"<col width=60>";
		echo"<col width=40>";
		echo"<col width=200>";
		echo"  <th align='center' ><span>Date</span></th>";
		echo"  <th align='center' ><span>Reference</span></th>";
		echo"  <th align='center' ><span>Item Code</span></th>";
		echo"  <th align='center' ><span>Description</span></th>";
		echo"  <th align='center' ><span>Warehouse</span></th>";
		echo"  <th align='center' ><span>Qty</span></th>";
		echo"  <th align='center' ><span>Remark</span></th>";
	//echo $query;
	$i=0;
	$result=mysql_query($query,$connection) or die(mysql_error());
    while ($row=mysql_fetch_array($result)){
	
	
	if ($i%2==0) $bgcolor='bgcolor1';
				else $bgcolor='bgcolor2';

				
				
	echo"<tr height=20 id='deliverydt$row[0]' class='$bgcolor table-focus-g1'  
					onclick=\"returncolor(this,'SelectedRecDt','SelectedRecColorDt','$row[0]');showrelation('".$row[2]."','".$lotnum."')\" 
					 
					
					>";
	echo"<td>$row[30]</td>";
	echo"<td>$row[31]</td>";
	echo"<td>$row[2]</td>";
	echo"<td>$row[3]</td>";
	echo"<td>$row[4]</td>";
	echo"<td>$row[6]</td>";
	echo"<td>$row[5]</td>";
	echo"</tr>";
	$i+=1;
	}
	echo"</table>";
	

	
	

}
?>