<?php

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


include("config.inc.php");
include("Functions_Sales.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");



//Read From Login Table
$querylog=" select ifNull(Unmodify_sellingprice,0) As Unmodify_SellingPrice, ifNull(Login_ModifyDiscount,0) As Login_ModifyDiscount, ".
		  " ifNull(Login_ModifySellingPrice,0) As Login_ModifySellingPrice ".
		  " from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['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);
}
//echo $querylog;
	
//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ".
             " 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_Pack,0) As Module_Pack, ".
			 " ifNull(Module_Delivery,0) As Module_Delivery, ifNull(Module_DoubleUnit,0) As Module_DoubleUnit, ".
			 " ifNull(Module_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostCenterDt,0) As Module_CostCenterDt, ".
			 " ifNull(Module_Unit1Method,0) As Module_Unit1Method, ifNull(Module_ExpireDate,0) As Module_ExpireDate ".
			 " 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, Warehouse As SetupDftWareHouse From SalesSetup";
$resultSalesSetup=mysql_query($querySalesSetup,$connection) or die(mysql_error());
while($rowSalesSetup=mysql_fetch_array($resultSalesSetup)){
	extract($rowSalesSetup);
}






print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="default.css" type="text/css" />
<script type="text/javascript" language="javascript">


function SubmitRecord(ItemExpire) {
	x = document.returnsalesdt;
	
	var result = CheckFields(ItemExpire);
	var vSaId     = x.PSaId.value;
	var vSaDtId   = x.txtSaDtId.value;
	var vMainMode = x.mainaction.value;
	var vMode     = x.actionmode.value;
	
	if (vSaDtId == '')
		vMode = 'submitrecord';	
	else
		vMode = 'editdt';	
	   
	if (result == 1) {
		x.action="Form_ReturnSales_Actions.php?mode="+vMode+"&mainmode="+vMainMode+"&SSaId="+vSaId+"&SSaDtId="+vSaDtId;
		x.submit();
		
	}	
}

function ChangeLocation() {
	x = document.returnsalesdt;
	var vMode = x.actionmode.value;
	
	if (vMode == 'submitrecord') {
		
		opener.document.returnsales.actionmode.value = x.actionmode.value;
		opener.document.returnsales.mainaction.value = x.mainaction.value;
		//opener.document.returnsales.message.value = x.message.value;
		opener.document.returnsales.txtSaId.value = x.PSaId.value;
		opener.document.returnsales.submit();
		
	} 
	else if (vMode == 'submitrecord' || vMode == 'editdt') {
		opener.document.returnsales.actionmode.value = x.actionmode.value;
		opener.document.returnsales.mainaction.value = x.mainaction.value;
		opener.document.returnsales.txtSaId.value = x.PSaId.value;
		opener.document.returnsales.submit();
		
		self.close();
	
	}
	
	
	//x.txtItemCode.focus();
}

function CheckFields(ItemExpire){
  
    x = document.returnsalesdt;
	
	var SaDtQty   = x.txtSaDtQty.value;
	var SaDtQty2  = x.txtSaDtQty2.value;
	var SaDtPrice = x.txtSaDtPrice.value;
	var SaDtDisc  = x.txtSaDtDiscount.value;
	
	var SaDtExpireDate = x.txtSaDtExpireDate.value;
	var SaDtBatchNo    = x.txtSaDtBatchNo.value;
	
	var vmode = x.actionmode.value;
	
	if (SaDtPrice == '') SaDtPrice = 0;
	if (SaDtQty == '')   SaDtQty = 0;
	if (SaDtQty2 == '')  SaDtQty2 = 0;
	
	SaDtQty = parseInt(SaDtQty);	
	
	if ( SaDtQty*1 != SaDtQty/1 || SaDtQty < 0 ) {
		alert('Quantity ('+SaDtQty+') should be a NUMERIC and MORE THAN ZERO. ');
		x.txtSaDtQty.focus();
		return 0;
	}
	else if ((SaDtPrice*1 != SaDtPrice/1 || SaDtPrice < 0) ) {
		alert('Price should be a NUMERIC and POSITIVE value');
		x.txtSaDtPrice.focus();
		return 0;
	}
	else if ((SaDtDisc != '' && SaDtDisc*1 != SaDtDisc/1) ) {
		alert('Discount should be a NUMERIC value');
		x.txtSaDtDiscount.focus();
		return 0;
	}
	else if ((SaDtQty2 != '' && SaDtQty2*1 != SaDtQty2/1) ) {
		alert('Item Qty2 should be a NUMERIC value.');
		x.txtSaDtQty2.focus();
		return 0;
	}
	else if (ItemExpire == 1 && SaDtExpireDate == '' ) {
		alert('Item Expire Date is mandatory.');
		x.txtSaDtExpireDate.focus();
		return 0;
	}
	else if (ItemExpire == 1 && SaDtBatchNo == '' ) {
		alert('Item Batch No is mandatory.');
		x.txtSaDtBatchNo.focus();
		return 0;
	}
		
	
	else
	return 1 ;	
}


function CalcSaDtTotal(dec) {
	x = document.returnsalesdt;
	var vmode = x.actionmode.value;
	var Qty = x.txtSaDtQty.value;
	var Price = x.txtSaDtPrice.value;
	var Discount = x.txtSaDtDiscount.value;
	if (Qty == '') Qty = 0;
	if (Price == '') Price = 0;
	if (Discount == '') Discount = 0;
	
	Qty = parseInt(Qty);
	Price = parseFloat(Price);
	Discount = parseFloat(Discount);
	
	if (Qty > 0 && Price >= 0)
	   x.txtSaDtTotal.value = Math.round(((Qty*Price) - (Qty*Price*Discount/100))*Math.pow(10,dec))/Math.pow(10,dec);

}

function CheckSaDtQty() {

	x = document.returnsalesdt;
	var RQty = x.txtSaDtRemainQty.value;
	var SQty = x.txtSaDtQty.value;
	
	if (RQty == '') RQty = 0;
	if (SQty == '') SQty = 0;
	
	RQty = parseInt(RQty);
	SQty = parseInt(SQty);
	
	if (SQty*1 != SQty/1 || SQty < 0) {
		alert('Quantity ('+SQty+') should be a NUMERIC and POSITIVE value.');
		x.txtSaDtQty.focus();
	}
	else if (SQty > RQty && RQty >= 0 ) {
		alert('Quantity entered not allowed. Qty must be <= Available Qty ['+RQty+'].');
		x.txtSaDtQty.focus();
	} 
	
}


function CalcQty2(ModuleUnit1Method,UnitCoef,Option) {
	x = document.returnsalesdt;
	var Qty  = x.txtSaDtQty.value;
	var Qty2 = x.txtSaDtQty2.value;
	
	if (Qty == '')  Qty = 0;
	if (Qty2 == '') Qty2 = 0;
	
	if(ModuleUnit1Method == 1) {
		if (Qty > 0 && Option == 1 && document.getElementById('txtSaDtQty2').type == 'text') {
			x.txtSaDtQty2.value = Qty*UnitCoef;
		}	
		else if (Qty == 0 && Option == 1 && document.getElementById('txtSaDtQty2').type == 'text') {
			x.txtSaDtQty2.value = '';
		}
	}
	//Case Modify Qty and Qty2 Should Be Empty
	else if(ModuleUnit1Method == 0 && Option == 1 && Qty2 == 0) {
		if (Qty > 0 && UnitCoef != 0 && document.getElementById('txtSaDtQty2').type == 'text') {
			x.txtSaDtQty2.value = Qty/UnitCoef;
		}	
		else if (Qty == 0 && document.getElementById('txtSaDtQty2').type == 'text') {
			x.txtSaDtQty2.value = '';
		}
	}
	//Case Modify Qty2 Get Qty
	else if(ModuleUnit1Method == 0 && Option == 2) {
		if (Qty2 > 0 && document.getElementById('txtSaDtQty2').type == 'text') {
			x.txtSaDtQty.value = Qty2*UnitCoef;
		}	
		else if (Qty2 == 0 && document.getElementById('txtSaDtQty2').type == 'text') {
			x.txtSaDtQty.value = '';
		}
	}
}

function showlistBatchNo(str) {
	x = document.returnsalesdt;
	vItemCode  = x.txtItemCode.value;
	
	window.open('List_BatchNo.php?frm=6&PItem_Code='+vItemCode,'List_BatchNo','width=580,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistProject(str){

  window.open('List_SorProject.php?frm=22&item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistCostcenter(str){

  window.open('List_SorCostcenter.php?frm=22&item='+str,'mywindow','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function kd(e)
{
	x=document.returnsalesdt;
    var intKey = (window.Event) ? e.which : e.keyCode;
    if (intKey == 13) { //enter key
        //x.btnSubmitRecord.click();
		return false;
    }
    return true;
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Return Waybill Detail - Add Items</title>


<script type="text/javascript" src="dropdown.js"></script>
<link rel="stylesheet" href="default.css" type="text/css" />
<link rel="stylesheet" href="short.css" type="text/css" />
<link rel="stylesheet" href="dropdown.css" type="text/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;
}
.style11 {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 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 onLoad='ChangeLocation();' >
<form name='returnsalesdt' method='post'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='PSaDate' value='$PSaDate'>
<input type='hidden' name='PSaId' value='$PSaId'>
<input type='hidden' name='PSaDtId' value='$PSaDtId'>
<input type='hidden' name='PSaMaturityDate' value='$PSaMaturityDate'>
<input type='hidden' name='PSaClientCode' value='$PSaClientCode'>
<input type='hidden' name='PSaSalesmanCode' value='$PSaSalesmanCode'>
<input type='hidden' name='PSaCurr' value='$PSaCurr'>
<input type='hidden' name='PSaProjectCode' value='$PSaProjectCode'>
<input type='hidden' name='PSaCostCentCode' value='$PSaCostCentCode'>
<input type='hidden' name='PSaDiscount' value='$PSaDiscount'>
<input type='hidden' name='PSaDiscountAmt' value='$PSaDiscountAmt'>
<input type='hidden' name='PSaVatChkbx' value='$PSaVatChkbx'>


HERE;
	


// User Has No Access To Modify The Price / Discount	
$ModeModifySellPrice = '';
$DiscountMode = '';
if ($Login_ModifySellingPrice == 0) $ModeModifySellPrice = ' readonly ';
if ($Login_ModifyDiscount == 0)	$DiscountMode = ' readonly ';

$PriceLabel = 'Price';	
if ($SalesTTC == 1)  $PriceLabel = 'Price TTC';	

if ($Module_ProjectDt == 1 && empty($txtProjectCodeDt))     $txtProjectCodeDt  = $PSaProjectCode; 
if ($Module_CostCenterDt == 1 && empty($txtCostCentCodeDt)) $txtCostCentCodeDt = $PSaCostCentCode; 


//Edit Sales Detail Mode
if($PSaDtId != ''){
	$querydt = " Select SalesDt.SaleDt_id, SalesDt.Item_code, SalesDt.Item_CodePacked, Item_Description, SalesDt.Warehouse_Code, Warehouse.Warehouse_name, ".
	           " SalesDt_Remark, SaleDt_Quantity, Round(SalesDt.SaleDt_Price, ".$DecimalBase."), SalesDt.SaleDt_PriceBase1, SalesDt.SaleDt_PriceBase2, ".
			   " Round(SaleDt_DiscountPer, ".$DecimalBase."), if(Items.Item_Vat !='', 1, 0) As ItemVat, ".
			   " Round(((SaleDt_Quantity*SalesDt.SaleDt_Price)-((SaleDt_Quantity*SalesDt.SaleDt_Price*ifNull(SaleDt_DiscountPer,0))/100)), ".$DecimalBase.") As Total, ".
			   " Round(SaleDt_PriceTTC, ".$DecimalBase."), ".
			   " Round(((SaleDt_Quantity*SaleDt_PriceTTC)-((SaleDt_Quantity*SaleDt_PriceTTC*ifNull(SaleDt_DiscountPer,0))/100)), ".$DecimalBase.") As TotalTTC, ".
			   " Deliveries.Delivery_reference, DeliveryDt.DeliveryDt_Quantity, DeliveryDt.DeliveryDt_ID, SalesDt.Item_Unit2Qty, ".
			   " Date_Format(SalesDt.SaleDt_ExpireDate,'%d/%m/%Y') As SaleDt_ExpireDate, SalesDt.SaleDt_BatchNo, SalesDt.Project_code, SalesDt.CostCenter_Code ".
			   " From Temp_SalesDt As SalesDt ".
			   //" Inner Join Temp_Deliveries on SalesDt.Delivery_ID = Temp_Deliveries.Delivery_ID ".
			   " Left Join DeliveryDt on DeliveryDt.DeliveryDt_ID = SalesDt.RelatedDt_Id And DeliveryDt.Journal_Type = 'DR' ".
			   " Left Join Deliveries on Deliveries.Delivery_ID = DeliveryDt.Delivery_ID  ".
			   " Left Join Items on SalesDt.Item_code = Items.Item_code ".
			   " Left Join Warehouse on SalesDt.Warehouse_code = Warehouse.Warehouse_code ".
	           " Where SalesDt.SaleDt_id = '".$PSaDtId."' ".
			   " And SalesDt.Journal_Type = 'SR' ";
			   //" And Logged_Code = '".$HTTP_SESSION_VARS['useraccount']."' ";	

	//echo $querydt;
	$resultdt=mysql_query($querydt,$connection) or die(mysql_error());
    $rowsdt=mysql_fetch_array($resultdt);
	
	$txtSaDtId        = $rowsdt[0];
	$txtItemCode      = $rowsdt[1];
	$txtItemCodePack  = $rowsdt[2];
	$txtItemDesc      = $rowsdt[3];
	$txtWarehouseCode = $rowsdt[4];
	$txtWarehouseName = $rowsdt[5];
	$txtSaDtRemark    = $rowsdt[6];
	$txtSaDtQty       = $rowsdt[7];
	$txtSaDtQty2      = $rowsdt[19];
	
	if ($SalesTTC == 1) 	
		$txtSaDtPrice 	   = $rowsdt[14];
	else
		$txtSaDtPrice 	   = $rowsdt[8];
		
	$txtSaDtDiscount  = $rowsdt[11];
	
	if ($SalesTTC == 1) 	
		$txtSaDtTotal     = $rowsdt[15];
	else
		$txtSaDtTotal     = $rowsdt[13];
		
	$chkSaDtVat  = $rowsdt[12];
	$txtSaDtVat  = $rowsdt[12];
	
	$txtSaDtDeliveryRef  = $rowsdt[16];
	$txtSaDtDeliveryQty  = $rowsdt[17];
	$txtSaDtDeliveryDtID = $rowsdt[18];
	
	$txtSaDtExpireDate  = $rowsdt[20];
	$txtSaDtBatchNo     = $rowsdt[21];
	$txtProjectCodeDt	= $rowsdt[22]; 
	$txtCostCentCodeDt	= $rowsdt[23];
	
				 
	$sub_query = " Select Sum(Q1.QtyReturned) As QtyReturned From ".
				 " ( Select ifNull(Sum(ifNull(SaleDt_Quantity,0)), 0) As QtyReturned ".
				 "   From SalesDt ".
				 "   Where SalesDt.RelatedDt_Id = '".$txtSaDtDeliveryDtID."' ".
				 "   And SalesDt.SaleDt_id != '".$txtSaDtId."' ".
				 "   And SalesDt.Sale_id != '".$PSaId."' ".
				 "   And SalesDt.Journal_Type = 'SR' ".
				 "   Union ".
				 "   Select ifNull(Sum(ifNull(SaleDt_Quantity,0)), 0) As QtyReturned ".
				 "   From Temp_SalesDt ".
				 "   Where Temp_SalesDt.RelatedDt_Id = '".$txtSaDtDeliveryDtID."' ".
				 "   And Temp_SalesDt.SaleDt_id != '".$txtSaDtId."' ".
				 "   And Temp_SalesDt.Journal_Type = 'SR' ".
				 " ) As Q1 ";			 
	//echo $sub_query;
	$sub_result = selectData($connection, $sub_query);	

	$txtSaDtRemainQty = $txtSaDtDeliveryQty - $sub_result[0];
	
}

$i_unitcoef = 1;
$i_expire   = 0;

if($txtItemCode != ''){

	
	if (empty($PSaId)) $PSaId = 0;
	if (empty($PSaDtId)) $PSaDtId = 0;
	
		
	//Get The Last Selling Price For The Item
	if ($txtItemCodePack != ''){
		$query = " SELECT if($SalesTTC = 1, SaleDt_PriceTTC, SaleDt_Price) FROM SalesDt WHERE Client_Code = '".$PSaClientCode."' And Item_CodePacked = '".$txtItemCodePack."' And ifNull(SaleDt_Price,0) > 0 ".
				 //" And (('".$lstWarehouse."' = '' And 1 = 1) Or ('".$lstWarehouse."' != '' And Warehouse_Code = '".$lstWarehouse."' )) ".
				 " Order By Sale_Date Desc Limit 1 ";
		
	} else {
		$query = " SELECT if($SalesTTC = 1, SaleDt_PriceTTC, SaleDt_Price) FROM SalesDt WHERE Client_Code = '".$PSaClientCode."' And Item_code = '".$txtItemCode."' And ifNull(SaleDt_Price,0) > 0 ".
				 //" And (('".$lstWarehouse."' = '' And 1 = 1) Or ('".$lstWarehouse."' != '' And Warehouse_Code = '".$lstWarehouse."' )) ".
				 " Order By Sale_Date Desc Limit 1 ";
		
	}

	
	//echo $query;
	$result = selectData($connection, $query);
	$i_lsp = $result[0];
	if(!isset($i_lsp)) $i_lsp = 0;
	
	$txtItemLastSellPrice = number_format($i_lsp, $DecimalBase);
	
	$query = " SELECT Item_UnitSalesDesc, Item_UnitPurchaseDesc, ifNull(Item_Unit,1), ifNull(Item_Expire,1) ".
			 " FROM items WHERE Item_Code = '".$txtItemCode."'";
		
	//echo "<br><br>".$query;
	$result = selectData($connection, $query);
	$i_unit1     = $result[0];
	$i_unit2 	 = $result[1]; 
	$i_unitcoef  = $result[2];
	$i_expire	 = $result[3];
	
	$txtItemUnit1 = $i_unit1;
	$txtItemUnit2 = $i_unit2;
}


$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";

echo"   <tr><td valign='top'>
        <table border='0' style='table-layout:fixed' align='center' valign='top' >
          <col width=75>
		  <col width=170>
		  <col width=80>
          <col width=470>
		   <tr bgcolor='#F7F7F7' height='25'>
		     <th colspan='4'><span class='style3'>Add Items </span></th></tr>
		   <tr bgcolor='#F7F7F7' >	
			 <td colspan='4' align='center'><font size='1' color='#FF0000' face='Verdana'><b>".$message."<br>".$WarningMsg."</b></font></td></tr>			 
			 
		   <tr bgcolor='#F7F7F7' height='25'>
             <td valign='center' align='left' ><input type='hidden' name='txtSaDtId' value='$txtSaDtId' >
			 <span class='style12'>Warehouse</span></td>
			 <td colspan='3'><b>$txtWarehouseCode - $txtWarehouseName</b></td>
		  </tr>	 
		
	
		  <tr bgcolor='#F7F7F7' height='25'>
             <td valign='center' align='left' ><span class='style12'>Item</span></td>
			 <td colspan='3'><input type='hidden' name='txtItemCode' value='$txtItemCode' ><input type='hidden' name='txtItemDesc' id='txtItemDesc' value='$txtItemDesc'  />
				<b>$txtItemCode&nbsp;-&nbsp;$txtItemDesc</b>
		
		  </tr>	 
		  <tr bgcolor='#F7F7F7' height='25'>
             <td valign='center' align='left' ><span class='style12'>Remark</span></td>
			 <td colspan='3'><input type='text' name='txtSaDtRemark' value='".htmlspecialchars($txtSaDtRemark, ENT_QUOTES)."'  maxlength='100' style='font-size:12px; width:400px; height:20px;'></td>
		  </tr>";

if ($Module_ProjectDt == 1 || $Module_CostCenterDt == 1) {
	echo"   <tr bgcolor='#F7F7F7'>";

	if ($Module_ProjectDt == 1) {
		echo" <td align='left'><span class='style12'>Project&nbsp;<span class='style12'>*</span></span></td>
			  <td align='left'> <span class='style12'>
				<input type='text' name='txtProjectCodeDt' id='txtProjectCodeDt' value='$txtProjectCodeDt' style='width:120px;' maxlength='15' readonly /></span>
				<label><span class='style12'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistProject(1); '  /></span></label></td>";
	} else {
		echo" <td align='left'>&nbsp;</td>
			  <td align='left'><input type='hidden' name='txtProjectCodeDt' id='txtProjectCodeDt' value='' /></td>";
	}

	if ($Module_CostCenterDt == 1) {		  
		echo" <td align='left'><span class='style12'>Costcenter&nbsp;<span class='style12'>*</span></span></td>
			  <td align='left'><span class='style12'>
				<input type='text' name='txtCostCentCodeDt' id='txtCostCentCodeDt' value='$txtCostCentCodeDt' style='width:130px;' maxlength='15' readonly /></span>
				<label><span class='style12'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCostcenter(1); ' /></span></label></td>";
	} else {
		echo" <td align='left'>&nbsp;</td>
			  <td align='left'><input type='hidden' name='txtCostCentCodeDt' id='txtCostCentCodeDt' value='' /></td>";

	}
	echo"   </tr>";
}

if ($Module_ExpireDate == 1) {
	echo" <tr bgcolor='#F7F7F7' height='25'>
             <td valign='center' align='left' ><span class='style12'>Batch No</span></td>
			 <td><input type='text' name='txtSaDtBatchNo' value='".htmlspecialchars($txtSaDtBatchNo, ENT_QUOTES)."'  maxlength='40' style='font-size:12px; width:120px; height:20px;' readonly >
				<label><span class='style12'><img src='img/btnopen.jpg' title='Select Batch No'  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistBatchNo(1); ' /></span></label></td>
			 <td valign='center' align='left' ><span class='style12'>Expire Date</span></td>
			 <td><input type='text' name='txtSaDtExpireDate' value='$txtSaDtExpireDate' maxlength='10' style='font-size:12px; width:90px; height:20px;'>
					<a HREF='#' onClick=\"displayCalendar(document.returnsalesdt.txtSaDtExpireDate,'dd/mm/yyyy',this); return false;\" NAME='anchor1' ID='anchor1'><img src='./img/cal.gif' border=0 align=center></a>
			 </td>
		  </tr>	"; 	 
} else {
	echo" <input type='hidden' name='txtSaDtExpireDate' value='$txtSaDtExpireDate'>";
	echo" <input type='hidden' name='txtSaDtBatchNo' value='$txtSaDtBatchNo'>";
}
		  
echo"	  <tr bgcolor='#F7F7F7'><td valign='top' colspan='4'>
		  <table border='0' style='table-layout:fixed' align='left' valign='top' >";
		  
if ($Module_DoubleUnit == 1) {	  
	echo" <col width=75>
          <col width=75>
		  <col width=40>
		  <col width=75>
		  <col width=40>
		  <col width=75>
		  <col width=90>
		  <col width=90>
		  <col width=60>
	      <col width=100>
		  <col width=50>";
} else {
	echo" <col width=75>
          <col width=75>
		  <col width=75>
		  <col width=90>
		  <col width=100>
		  <col width=60>
	      <col width=100>
		  <col width=70>";
}
		echo"<tr>";   
		echo"	<td valign='center' align='center' ><span class='style12'>Return Delivery Ref</span></td> ";
		echo"  	<td valign='center' align='center' ><span class='style12'>Return Delivery Qty</span></td> ";
		
		if ($Module_DoubleUnit == 1)
			echo"<td valign='center' align='center' ><span class='style12'>Unit1</span></td>";		
			
		echo"	<td valign='center' align='center' ><span class='style12'>Qty</span></td>";
		
		if ($Module_DoubleUnit == 1) {
			echo"<td valign='center' align='center' ><span class='style12'>Unit2</span></td>";
			echo"<td valign='center' align='center' ><span class='style12'>Unit2 Qty</span></td>";
		}
		
		echo"	<td valign='center' align='center' ><span class='style12'>$PriceLabel&nbsp;<span class='style26'>*</span></span></td> ";
		echo"	<td valign='center' align='center' ><span class='style12'>Last Sell. Price</span></td> ";
		echo"	<td valign='center' align='center' ><span class='style12'>Disc(%)</span></td>";
		echo"	<td valign='center' align='center' ><span class='style12'>Total</span></td> ";
		echo"   <td valign='center' align='center' ><span class='style12'>VAT</span></td> ";
			 
		
		echo"</tr>
		  <tr bgcolor='#F7F7F7' height='25'>
			<td align='center'><b>$txtSaDtDeliveryRef</b><input type='hidden' name='txtSaDtDeliveryRef' value='$txtSaDtDeliveryRef' ></td>
		    <td align='center'><b>$txtSaDtRemainQty</b><input type='hidden' name='txtSaDtDeliveryQty' value='$txtSaDtDeliveryQty'  ><input type='hidden' name='txtSaDtRemainQty' value='$txtSaDtRemainQty'  ></td>";
			
		if ($Module_DoubleUnit == 1) echo"<td align='center'><b>$txtItemUnit1</b></td>";		 	
		
		echo"<td align='center'><input type='text' name='txtSaDtQty' value='$txtSaDtQty' maxlength='20'  onBlur='CheckSaDtQty(); CalcSaDtTotal($DecimalBase);' onchange='CalcQty2($Module_Unit1Method,$i_unitcoef,1);' style='font-size:12px; width:60px; height:20px;'  ></td>";
		
		if ($Module_DoubleUnit == 1) {
			echo"<td align='center'><b>$txtItemUnit2</b></td>";
			echo "<td align='center'><input type='text' name='txtSaDtQty2' id='txtSaDtQty2' value='$txtSaDtQty2' maxlength='20' onchange='CalcQty2($Module_Unit1Method,$i_unitcoef,2);' style='font-size:12px; width:60px; height:20px;' ></td>";
		} else {
			echo "<input type='hidden' name='txtSaDtQty2' id='txtSaDtQty2' value='$txtSaDtQty2' >";
		}
		
		echo"<td align='center'><input type='text' name='txtSaDtPrice' value='$txtSaDtPrice' maxlength='20' onBlur='CalcSaDtTotal($DecimalBase);' style='text-align:right; font-size:12px; width:80px; height:20px;' $ModeModifySellPrice></td>
			<td align='center'><b>$txtItemLastSellPrice</b><input type='hidden' name='txtItemLastSellPrice' value='$txtItemLastSellPrice' maxlength='20' style='text-align:right; font-size:12px; width:90px; height:20px;' ></td>
			<td align='center'><input type='text' name='txtSaDtDiscount' value='$txtSaDtDiscount' maxlength='20' onBlur='CalcSaDtTotal($DecimalBase);'  style='text-align:right; font-size:12px; width:50px; height:20px;' $DiscountMode></td>
			<td align='center'><input type='text' name='txtSaDtTotal' value='$txtSaDtTotal' maxlength='20' style='text-align:right; font-size:12px; width:90px; height:20px;' ></td>
			<td align='center'><input type='hidden' name='txtSaDtVat' value='$txtSaDtVat'><input name='chkSaDtVat' type='checkbox' id='chkSaDtVat' value='1' disabled "; 
		    if($chkSaDtVat==1 || $txtSaDtVat == 1) echo "checked /></td>"; else echo " /></td>";   
		
		
echo"    
		  </tr>
		  </table></td></tr>
		  <tr bgcolor='#F7F7F7' height='30'>
		     <td colspan='4' align='center' bgcolor=#D8D8D8>
			    <input type='button' id='btnSubmitRecord' name='btnSubmitRecord'  value='Submit Record'  onclick='SubmitRecord($i_expire)' $style title='Submit Record'></td>
			 
		  </tr>
        </table>";

	

print <<<HERE
</form>
</body>

HERE;

?>