<?php
header("Content-type: text/html; charset=windows-1256");
session_start();

if (!function_exists('ConvertCurrency')) {
	function ConvertCurrency($FromCurr, $ToCurr, $FromDate, $Amount, $connection)
	{
		$query = "SELECT ifNull(convertcurfunc('".$FromCurr."', '".$ToCurr."', '".$FromDate."', 0, 0, '', '', ifNull($Amount,0)),0) From Dual ";
		$result = selectData($connection, $query);
		//echo $query;
		Return	$result[0];

	}
}

if (!empty($_GET["action"])) {

$form      		  = $_GET["form"];
$vRetId      	  = $_GET["transid"];



	include("config.inc.php");
	include("Functions_Sales.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");
	
	//echo $_SESSION['dbName']."<br>";
	if ($form == 'CashReg') {
		ShowRetailDtGrid($connection,$_SESSION['gret_parameters'],$vRetId);
	}
	else if ($form == 'RT-TOT') {
		ShowRetailTotals($connection,$_SESSION['gret_parameters'],$vRetId);
	}	
	else if ($form == 'OpenDrawer') {
		OpenCashDrawer($connection);
	}	
	else if ($form == 'DisplayShortCuts') {
		ShowShortCutGrid($connection,$_SESSION['gret_parameters'],$vRetId);
	}
	else if ($form == 'ShowItemModifiers') {
		ShowItemModifiers($connection,$_SESSION['gret_parameters'],$vRetId);
	}
	else if ($form == 'GetHoldItems') {
		ShowHoldItems($connection,$_SESSION['gret_parameters'],$vRetId);
	}
	
}

function OpenCashDrawer($connection) {
	//Read From CashRegister Table
	$queryCashRegister=" Select ifNull(CashRegister_Drawer,0) As CashRegister_Drawer, ifNull(CashRegister_DrawerCOM,0) As CashRegister_DrawerCOM, CashRegister_DrawerPrinter ".
					   " From CashRegister ".
					   " Where CashRegister_Name = '".$_SESSION['cashregister']."' ";
	$resultCashRegister=mysql_query($queryCashRegister,$connection) or die(mysql_error());
	while($rowCashRegister=mysql_fetch_array($resultCashRegister)){
		extract($rowCashRegister);
	}

	$message = '';
	
	if ($CashRegister_Drawer == 1 && $CashRegister_DrawerCOM != '' && $CashRegister_DrawerCOM != 0) { 
		$com = $CashRegister_DrawerCOM;
		if (empty($com)) $com = 0;
		$fp = fopen ("com".$com.":9600,n,8,1,DS", "wb+");
		
		if ($fp){
			$string=chr(12); //simulating device
			fputs ($fp, $string );             
			fclose ($fp);
		} else {
			$message = "Can't Open Port.";
		}	
	}
	else if ($CashRegister_Drawer == 1 && $CashRegister_DrawerPrinter != '') { 
		$handle = fopen("PRN", "w"); 
		if ($fp){	
			fwrite($handle, $CashRegister_DrawerPrinter); 
		} else {
			$message = "Can't Open Printer Port.";
		}	
	}
	
	$return_arr = array();
	$row_array['message'] = $message;
				
	array_push($return_arr,$row_array);
	echo json_encode($return_arr);
}



function ShowTableGrid($connection,$arrayparams,$PRetailId){

$querylog=" select ifNull(FC_CashRegisterDel,0) As FC_CashRegisterDel, ifNull(FC_CashRegisterMod,0) As FC_CashRegisterMod, ".
          " ifNull(FC_CashRegisterApp,0) As FC_CashRegisterApp, ifNull(FC_CashRegisterPosting,0) As FC_CashRegisterPosting, ".
		  " ifNull(FC_CashRegisterAskPrint,0) As FC_CashRegisterAskPrint, ifNull(FC_CashRegisterSearch,0) As FC_CashRegisterSearch, ".
		  " ifNull(FC_CashRegisterQtyRet,0) As FC_CashRegisterQtyRet, ifNull(FC_ShowBtnOpenDrawer,0) As FC_ShowBtnOpenDrawer, ".
		  " ifNull(Unmodify_sellingprice,0) As Unmodify_SellingPrice, ifNull(FC_CashRegisterClosing,0) As FC_CashRegisterClosing, ". 
		  " ifNull(FC_CashRegisterSetup,0) As FC_CashRegisterSetup, ifNull(FC_ShowBtnCancel,0) As FC_ShowBtnCancel, ".
		  " ifNull(FC_CashRegisterDelItem,0) As FC_CashRegisterDelItem,ifNull(FC_DiscountPerLimit,0) As FC_DiscountPerLimit, ".
		  " ifNull(FC_CashRegisterGift,0) As FC_CashRegisterGift, ifNull(FC_CashRegisterVoid,0) As FC_CashRegisterVoid, ".
		  " ifNull(FC_CashRegisterWaste,0) As FC_CashRegisterWaste, ifNull(FC_ShowAllTables,0) As FC_ShowAllTables, ".
		  " ifNull(login_belongstogrp,0) As FI_BelongsToGrp, ifNull(FC_CashRegisterMenu,0) As FC_CashRegisterMenu ".
		  " 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);
}



	$CashRegisterEditOnPrint	= $arrayparams['CashRegisterEditOnPrint'];
	$copiedVers					= $arrayparams['copiedVers'];
	$Module_PriceOffer			= $arrayparams['Module_PriceOffer'];
	$CashRegister_PrintBarcode	= $arrayparams['CashRegister_PrintBarcode'];
	$Module_SerialNo			= $arrayparams['Module_SerialNo'];
	$DecimalBase				= $arrayparams['DecimalBase']; 
	$CashRegisterTTC			= $arrayparams['CashRegisterTTC'];
	$CashReg_Weight				= $arrayparams['CashReg_Weight'];
	$Module_RestaurantDelivery	= $arrayparams['Module_RestaurantDelivery']; 
	$CashRegister_PrintBarcode	= $arrayparams['CashRegister_PrintBarcode'];
	$FC_CashRegisterMod			= $arrayparams['FC_CashRegisterMod'];
	$FC_CashRegisterDelItem		= $arrayparams['FC_CashRegisterDelItem'];
	$PriceLabel					= $arrayparams['PriceLabel'];
	$ShowSlipNumber				= $arrayparams['ShowSlipNumber'];
	$txtCurr					= $arrayparams['txtCurr'];
	$base1						= $arrayparams['base1'];
	$base2						= $arrayparams['base2'];
	$txtOrderId					= $arrayparams['txtOrderId'];
	$Unmodify_SellingPrice		= $arrayparams['Unmodify_SellingPrice'];
	$passchecked				= $arrayparams['passchecked'];
	$height						= $arrayparams['height'];
	$CashReg_Vendor				= $arrayparams['CashReg_Vendor'];
	$FC_DiscountPerLimit		= $arrayparams['FC_DiscountPerLimit'];
	$CashReg_ForcingVendor		= $arrayparams['CashReg_ForcingVendor'];
	$Module_CashRegisterTable	= $arrayparams['Module_CashRegisterTable'];
	$FC_ShowAllTables			= $arrayparams['FC_ShowAllTables'];


	$filepath = 'Functions_Retail.php';


	$queryMenu = " SELECT Menu_Index, Menu_Title, Menu_Link, Menu_ImageName, Menu_ShortCutLabel, ifNull(Menu_WinWidth,1000) as Menu_WinWidth, ifNull(Menu_WinHeight,700) as Menu_WinHeight ".
			 " From cashregistermenu ".
			 " where ifNull(Menu_Active,0) = 1 ".
			 " and ifNull(Menu_Belongstogrp,0) >= $FI_BelongsToGrp ".
			 " and Upper(menu_title) = 'TOOLS' ".
			 " Order By lpad(Menu_Order,3,'0') 	";
			 
	$resultMenu=mysql_query($queryMenu,$connection) or die(mysql_error());
	$rowsmenu=mysql_fetch_array($resultMenu);
	$vwidth = $rowsmenu[5];
	$vheight = $rowsmenu[6];

	echo"<div id='containertable' style='position: relative;z-index:1;' >";
	echo"	<div id='Loadertable' class=''></div>";
	echo"     <table border='0'  id='grid_datatable1' cellspacing='0'  cellpadding='0' align='left' style='margin-left:2px; margin-top:2px; '>	";


	$query = " select projectdt.Projectdt_id, Projectdt_name, Projectdt_numberofseats, projectdt.Project_id, Projectdt_Reserved, projectdt.cashregister_name, Projectdt_numberofguests 
				,temp_retail.Sale_id Sale_id
				from projectdt  
				left join temp_retail on projectdt.projectdt_id = temp_retail.projectdt_id 
				inner join ".$_SESSION['dbLabel'].".loginstk on ProjectDt.Projectdt_id = loginstk.projectdt_id and loginstk.user_account = '".$_SESSION['useraccount']."'
				,project
				where projectdt.project_id=project.project_id
				and upper(project.project_name) = 'TABLE'";
				
	if ($FC_ShowAllTables != 1){
		$query .= " and ((ifnull(temp_retail.Sale_id,'')!='' and temp_retail.user_account='".$_SESSION['useraccount']."') or (ifnull(temp_retail.Sale_id,'')='' and 1=1)) ";
	}
		//echo $query;		
	$result=mysql_query($query,$connection) or die(mysql_error());
				
	$i=1;
	while($rows=mysql_fetch_array($result)){
		//echo"<tr><td>$rows[1]</td></tr>";
		
			$q = "  Select date_format(res_fromdate,'%T'), res_todate, ampm from customer_res
					where 1 = 1
					and date_format(now(),'%Y%m%d') between date_format(res_fromdate,'%Y%m%d') and date_format(res_todate,'%Y%m%d')
					and date_format(now(),'%T') <= date_format(res_fromdate,'%T')
					and projectdt_id =	$rows[0]
					order by res_fromdate asc limit 0,1 ";
			$resultdt = mysql_query($q,$connection) or die(mysql_error());
			$rowsdt   = mysql_fetch_array($resultdt);
			//echo $q ."<br>";
		if($i==1) echo"<tr>";
		
		if($i==1 and $Module_RestaurantDelivery == 1 and $rowsmenu[0] != '') {
				echo"<td width='62px' height='47px'><input type='button' id='btnTbl0'  class='Tablebuttons' style='background-color:red' value='Tools' onclick=\"OpenForm($vwidth,$vheight);return false;\" > </td>";
				$i+=1;
				
				}
					
		if($rows[7]!='' && $rows[7] == $PRetailId){	//retail table
			if($copiedVers>0)
			echo "<td width='62px' height='47px'><input type='button' id='btnTbl$i' name='btnTbl$i' class='TablebuttonsActive' style='background-color:red !important;'  onclick=\"UpdateRecord('$rows[7]');\" value='$rows[1]\n$rowsdt[0]'><span><span></span></span></button></td>";
			else echo "<td width='62px' height='47px'><input type='button' id='btnTbl$i' name='btnTbl$i' class='TablebuttonsActive'   onclick=\"UpdateRecord('$rows[7]');\" value='$rows[1]\n$rowsdt[0]'><span><span></span></span></button></td>";
		}else if($rows[7]!='')	//retail table
			echo "<td width='62px' height='47px'><input type='button' id='btnTbl$i' name='btnTbl$i' class='TablebuttonsRetailed'   onclick=\"UpdateRecord('$rows[7]');\" value='$rows[1]\n$rowsdt[0]'><span><span></span></span></button></td>";
		else
			echo "<td width='63px' height='48px'><input type='button' id='btnTbl$i' name='btnTbl$i' onclick=\"ShowGuestsWin($rows[0]);return false;\"  class='Tablebuttons'  value='$rows[1]\n$rowsdt[0]'><span><span></span></span></button></td>";

		if($i%5==0)	echo"</tr><tr>";

		$i+=1;
	}


	echo " </table>";
	echo"</div>";	
	echo"</div>";	
	
}




function ShowRetailDtGrid($connection,$arrayparams,$PRetailId){

	//Read From Setup Table							
	$querysetup= " Select CashReg_BgColorOffer, CashReg_BgColorQty, CashReg_BgColorOrderQty, CashReg_BgColorZeroPrice, CashReg_BgColorZeroQty, CashReg_BgColorHasDiscount, ".
				 " ifNull(CashReg_ApplyColorOffer,0) As CashReg_ApplyColorOffer, ifNull(CashReg_ApplyColorQty,0) As CashReg_ApplyColorQty, ifNull(CashReg_ApplyColorOrderQty,0) As CashReg_ApplyColorOrderQty, ".
				 " ifNull(CashReg_ApplyColorZeroPrice,0) As CashReg_ApplyColorZeroPrice, ifNull(CashReg_ApplyColorZeroQty,0) As CashReg_ApplyColorZeroQty, ifNull(CashReg_ApplyColorHasDiscount,0) As CashReg_ApplyColorHasDiscount  ".
				 " From Setup ";
	$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
	while($rowsetup=mysql_fetch_array($resultsetup)){
		extract($rowsetup);
	}

	$Module_PriceOffer			= $arrayparams['Module_PriceOffer'];
	$CashRegister_PrintBarcode	= $arrayparams['CashRegister_PrintBarcode'];
	$Module_SerialNo			= $arrayparams['Module_SerialNo'];
	$DecimalBase				= $arrayparams['DecimalBase']; 
	$CashRegisterTTC			= $arrayparams['CashRegisterTTC'];
	$CashReg_Weight				= $arrayparams['CashReg_Weight'];
	$Module_RestaurantDelivery	= $arrayparams['Module_RestaurantDelivery']; 
	$CashRegister_PrintBarcode	= $arrayparams['CashRegister_PrintBarcode'];
	$FC_CashRegisterMod			= $arrayparams['FC_CashRegisterMod'];
	$FC_CashRegisterDelItem		= $arrayparams['FC_CashRegisterDelItem'];
	$PriceLabel					= $arrayparams['PriceLabel'];
	$ShowSlipNumber				= $arrayparams['ShowSlipNumber'];
	$txtCurr					= $arrayparams['txtCurr'];
	$base1						= $arrayparams['base1'];
	$base2						= $arrayparams['base2'];
	$txtOrderId					= $arrayparams['txtOrderId'];
	$Unmodify_SellingPrice		= $arrayparams['Unmodify_SellingPrice'];
	$passchecked				= $arrayparams['passchecked'];
	$height						= $arrayparams['height'];
	$CashReg_Vendor				= $arrayparams['CashReg_Vendor'];
	$FC_DiscountPerLimit		= $arrayparams['FC_DiscountPerLimit'];
	$CashReg_ForcingVendor		= $arrayparams['CashReg_ForcingVendor'];
	$Module_CashRegisterTable	= $arrayparams['Module_CashRegisterTable'];
	
	$CashRegister_showitemcode	= $arrayparams['CashRegister_showitemcode'];
	$CashRegister_showdiscount	= $arrayparams['CashRegister_showdiscount'];
	
	
	$CashRegister_showItemImage	= $arrayparams['CashRegister_showItemImage'];
	$CashRegister_showItemLocation	= $arrayparams['CashRegister_showItemLocation'];


	$filepath = 'Functions_Retail.php';
	$i=1;
	if($Module_CashRegisterTable==1)
		$DescriptionSize='410';
		else
		$DescriptionSize='345';
		$additionalsize = 80;
		if($cashregister_showItemImage == '1') $additionalsize-= 20;
		if($CashRegister_showItemLocation == '1' ) $additionalsize-= 60;
		$DescriptionSize+=$additionalsize;


if($Module_CashRegisterTable==1){
		$DescriptionSize='160';
	/*if ($Module_SerialNo == 1) $DescriptionSize -= 55;
	if ($CashReg_Vendor == 1)  $DescriptionSize -= 68;	
	if ($ShowSlipNumber == 1)  $DescriptionSize -= 55;	
	if ($Module_PriceOffer == 1)  $DescriptionSize -= 55;	*/
	
	if ($Module_SerialNo == 0) $colwidth9 += 55;
	if ($CashReg_Vendor == 0)  $colwidth9 += 68;	
	if ($ShowSlipNumber == 0)  $colwidth9 += 55;	
	if ($Module_PriceOffer == 0)  $colwidth9 += 55;	

}
else {
	if ($Module_SerialNo == 1) $DescriptionSize -= 55;
	if ($CashReg_Vendor == 1)  $DescriptionSize -= 68;	
	if ($ShowSlipNumber == 1)  $DescriptionSize -= 55;	
	if ($Module_PriceOffer == 1)  $DescriptionSize -= 55;	

}

	
$query = " Select Count(*) FROM Temp_RetailDt ".
		 " WHERE Sale_id = ".$PRetailId;
$result = selectData($connection, $query);
$txtCountDetail = $result[0];
if($txtCountDetail == '') $txtCountDetail = 0;

echo"<input type='hidden' name='txtCountDetail' value='$txtCountDetail' >";

if($Module_CashRegisterTable==1)
	{
		$TableWidth='730';
		
		
		if ($Module_PriceOffer > 0)
			$TableWidth+=75;
		
		if ($Module_SerialNo == 1) 
		   $TableWidth+=85;
		
		if($CashReg_Vendor==1)
			$TableWidth+=135;
			
		if($ShowSlipNumber==1)
			$TableWidth+=75;
			
	}	
else	
	$TableWidth='900';

	
$TableWidthStyle = 'width:'.$TableWidth.'px;';

	echo"<div id='container' style='position: relative;z-index:1;' >";
	echo"	<div id='Loader' class=''></div>";
	
	if($Module_CashRegisterTable==1)
		echo" 	<div id='grid_headerDiv' class='grid_headerDiv' style='width:780px;border:0px solid #000000;height:27px'>";
	else
		echo" 	<div id='grid_headerDiv' class='grid_headerDiv' style='width:900px;border:0px solid #000000;height:27px'>";

	if($Module_CashRegisterTable==1){
		$colwidth5 = 60;
		$colwidth6 = 25;
		$colwidth7 = 50;
		$colwidth8 = 50;
		$colwidth9 = 50;
		$colwidth10 = 55;
		$colwidth11 = 55;
		$colwidth12 = 60;
		$colwidth13 = 55;
	} else {
		$colwidth5 = 120;
		$colwidth6 = 45;
		$colwidth7 = 55;
		$colwidth8 = 50;
		$colwidth9 = 55;
		$colwidth10 = 55;
		$colwidth11 = 55;
		$colwidth12 = 68;
		$colwidth13 = 55;
	}
	//if($CashRegister_PrintBarcode != 1 || $CashRegister_showitemcode != 1) $TableWidthStyle = '800';
	//if($CashRegister_showdiscount != 1) $TableWidthStyle = $TableWidthStyle - $colwidth7;

	if($Module_CashRegisterTable==1){
		echo" <table border='0'  id='grid_datatable' class='grid_data' cellspacing='0'  cellpadding='0' align='left' style='$TableWidthStyle'>";
 	}else{		  
		echo" <table border='0'  id='grid_datatable' class='grid_data' cellspacing='0'  cellpadding='0' align='left' style='$TableWidthStyle'>";
	}
	
	if($CashRegister_showItemImage == '1')
		echo"	<col width=20>";
	if($CashRegister_showItemLocation == '1')
		echo"	<col width=60>";
	
	
	if($CashRegister_PrintBarcode == 1 || $CashRegister_showitemcode == 1)
		echo "<col width=$colwidth5>";
	echo"	<col width=$DescriptionSize>";
		 
	if($Module_CashRegisterTable==1){	
		echo"<col width=$colwidth6>";
		if($CashRegister_showdiscount==1) echo"<col width=$colwidth7>";
		echo"<col width=$colwidth8>";
		echo"<col width=$colwidth9>";
	} else {
		echo"<col width=$colwidth6>";
		if($CashRegister_showdiscount==1) echo"<col width=$colwidth7>";
		echo"<col width=$colwidth8>";
		echo"<col width=$colwidth9>";
	}
			
	if ($Module_PriceOffer > 0)
		echo"<col width=$colwidth10>";
		
	if ($Module_SerialNo == 1) 
	   echo"<col width=$colwidth11>";
	
	if($CashReg_Vendor==1)
		echo"<col width=$colwidth12>";
			
	if($ShowSlipNumber==1)
		echo"<col width=$colwidth13>";	
	
	$nbrcol = 0;		
	echo"<tr height='25px'>";
		  
		  
	if($CashRegister_showItemImage == '1'){
		echo"<th align='left' class='bg-header style27'>&nbsp;</th>";
		$nbrcol++;
	}
	if($CashRegister_showItemLocation == '1'){
		echo"<th align='left' class='bg-header style27'>Location</th>";
		$nbrcol++;
	}
	
	if ($CashRegister_PrintBarcode == 1){
		echo"<th align='left' class='bg-header style27'>Barcode</th>";
		$nbrcol++;
	}
	else if ($CashRegister_showitemcode == 1){	
		echo"<th align='left' class='bg-header style27'>Item Code</th>";	
		$nbrcol++;
	}
	
	
	echo"	<th align='left' class='bg-header style27'>Item Description</th>";
	echo"  	<th align='center' class='bg-header style27'>Qty</th>";	
	echo"  	<th align='center' class='bg-header style27'>$PriceLabel</th>";
	echo"  	<th align='center' class='bg-header style27'>Total </th>";	
	$nbrcol	= $nbrcol + 4;	
	if($CashRegister_showdiscount==1){ 
		echo" 	<th align='left' class='bg-header'>Disc(%)</th>";
		$nbrcol++;
	}
		
	if ($Module_PriceOffer > 0){
		echo"<th align='center' class='bg-header'>Price(O)</th>";
		$nbrcol++;
	}
	if ($Module_SerialNo == 1){
		echo"<th align='left' class='bg-header'>S/N Bal</th>";
		$nbrcol++;
	}
		
	if($CashReg_Vendor==1){
		echo"<th align='left' class='bg-header'>Vendor</th>";
		$nbrcol++;
	}
			
	if ($ShowSlipNumber == 1){	
		echo"<th align='left' class='bg-header'>Slip</th>";
		$nbrcol++;
	}
			 
			 
    echo"</tr>";
	echo"</table></div>";
		   
	if($Module_CashRegisterTable==1)	 
	    echo"<div id='grid_contentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('grid_headerDiv','grid_contentDiv')\" style='width:800px;height:$height'>";
	else
		echo"<div id='grid_contentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('grid_headerDiv','grid_contentDiv')\" style='width:1135px;height:$height'>";
				   
	echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='0' style='$TableWidthStyle'>";
	if($CashRegister_showItemImage == '1')
		echo"<col width=20>";
	if($CashRegister_showItemLocation == '1')
		echo"<col width=60>";

	if($CashRegister_PrintBarcode == 1 || $CashRegister_showitemcode == 1) 
		echo"<col width=$colwidth5>";
	
	echo"<col width=$DescriptionSize>";
	
	if($Module_CashRegisterTable==1){
		echo"<col width=$colwidth6>";
		if($CashRegister_showdiscount==1) echo"<col width=$colwidth7>";
		echo"<col width=$colwidth8>";
		echo"<col width=$colwidth9>";
	} else {		
		echo"<col width=$colwidth6>";
		if($CashRegister_showdiscount==1) echo"<col width=$colwidth7>";
		echo"<col width=$colwidth8>";
		echo"<col width=$colwidth9>";
	}
						
	if ($Module_PriceOffer > 0)
		echo"<col width=$colwidth10>";
		 
	if ($Module_SerialNo == 1) 
		echo"<col width=$colwidth11>";
			
	if($CashReg_Vendor==1)
		echo"<col width=$colwidth12>";
			
	if($ShowSlipNumber==1)
		echo"<col width=$colwidth13>";
			
				
	if ($PRetailId != '' ) {
		  
		//Checking For Difference Btw Qty and Count SerialNo
		$QtySerNoCheck = 0;
		echo '<script type="text/javascript" language="javascript">';
		echo ' x = document.retail; ';
  		echo ' x.QtySerNo.value=0; ';
		echo '</script>';
		      
				   
		$querydt = " Select RetailDt.SaleDt_id, RetailDt.Item_Barcode, RetailDt.Item_code, Items.Item_Description, RetailDt.Warehouse_Code, ".
				   " SaleDt_Quantity, if(ifNull(RetailDt.SaleDt_ItemStatus,0)!=3, Round(SaleDt_Price, ".$DecimalBase."), 0), SaleDt_PriceBase1, SaleDt_PriceBase2, ".
				   " if(ifNull(RetailDt.SaleDt_ItemStatus,0)!=3, Round(SaleDt_DiscountPer, ".$DecimalBase."),0),  ".
				   " if(ifNull(RetailDt.SaleDt_ItemStatus,0)!=3, Round(((SaleDt_Quantity*SaleDt_Price)-((SaleDt_Quantity*SaleDt_Price*ifNull(SaleDt_DiscountPer,0))/100)), ".$DecimalBase."), 0) As Total, ".
				   " if(ifNull(RetailDt.SaleDt_ItemStatus,0)!=3, Round(SaleDt_PriceTTC, ".$DecimalBase."), 0), ".
				   " if(ifNull(RetailDt.SaleDt_ItemStatus,0)!=3, Round(((SaleDt_Quantity*SaleDt_PriceTTC)-((SaleDt_Quantity*SaleDt_PriceTTC*ifNull(SaleDt_DiscountPer,0))/100)), ".$DecimalBase."), 0) As TotalTTC, ".
				   " ifNull(Items.Item_withserialno,0) As ItemWithSerialNo, Count(Temp_Purchasesserialno.SerialNo_Code) As CountSerialNo, ".
				   " RetailDt.Item_CodePacked, ifNull(Items1.Item_withserialno,0) As ItemPackWithSerialNo, RetailDt.Vendor_Code, if(ifNull(RetailDt.SaleDt_ItemStatus,0)!=3, Round(RetailDt.SaleDt_ActualPrice, ".$DecimalBase."), 0), ".
				   " if(ifNull(RetailDt.SaleDt_ItemStatus,0)!=3, ifNull(RetailDt.Price_Offer,0), 0) As Price_Offer, ifNull(Items.Item_Weight,0), RetailDt.Slip_Number, RetailDt.Warehouse_Code, ".
				   " ifNull(RetailDt.SaleDt_ItemStatus,0), SalesDt_Remark, saledt_printed ,REPLACE(ifnull(Items.Item_Picture,''), 'items_photos','items_photos2') as Item_Picture,ifnull(Items.Item_Picture,'') as Item_PictureOrg".
				   
				   " From Temp_RetailDt As RetailDt ".
				   " Left Join Items on RetailDt.Item_code = Items.Item_code ".
				   " Left Join Items As Items1 on RetailDt.Item_CodePacked = Items1.Item_code ".
				   " Left Join Temp_Purchasesserialno on RetailDt.SaleDt_ID = Temp_Purchasesserialno.RetailDt_ID ".
				   " And Temp_Purchasesserialno.Journal_Type In ('DI','DR') ".
				   " Where RetailDt.Sale_ID = ".$PRetailId.
				   //" And IfNull(RetailDt.SaleDt_ItemStatus,0) Not In (2) ".
				   " Group By  RetailDt.SaleDt_id ".
				   " Order By ifNull(RelatedDt_Id, RetailDt.SaleDt_ID) Desc, Sale_Date ";
		//echo $querydt;
			
		$resultdt=mysql_query($querydt,$connection) or die(mysql_error());
		while($rowsdt=mysql_fetch_array($resultdt)){
			    
			$ct+=1;

			/*if($ct%2==0)
				$Color="style='background-color:".$grid_color1."'";
			else			
				$Color="style='background-color:".$grid_color2."'";	*/
					
			if($ct%2==0)
				$Color="style='background-color:#f2f2f2'";
			else			
				$Color="style='background-color:#ffffff'";		
					
						
			$sub_query1  = " Select ifNull(Item_Pack,0), ifNull(Item_ModifySellingPrice,0) From Items Where Item_Code = '".$rowsdt[2]."' ";
			$sub_result1 = selectData($connection, $sub_query1);
			$ItemPack = $sub_result1[0];
			$ItemModifySellingPrice = $sub_result1[1];		
			
			// User Has No Access To Modify The Price	
				
			$ModeModifySellPrice = '';
			if ($Unmodify_SellingPrice == 1 || ($ItemModifySellingPrice == 0 && $rowsdt[2] != ''))	
				$ModeModifySellPrice = ' readonly ';
			if ($passchecked == 1 || ($ItemModifySellingPrice == 1 && $rowsdt[2] != ''))	
				$ModeModifySellPrice = '';	
					
					
			if($FC_CashRegisterMod==0){
				$ModeModifySellPrice= ' readonly ';
				$ModeModifyQty= ' readonly ';
				$ModeModifyVendor= ' readonly ';
				$ModeModifySlip= ' readonly ';
			}
			if ($passchecked == 1){
				$ModeModifySellPrice= '';
				$ModeModifyQty= '';
				$ModeModifyVendor= '';
				$ModeModifySlip='';
			}
				
			//If Item Price Offer True Color Background Honey
			//if ($rowsdt[19] == 1) $Color="style='background-color:#D7F754'";
			if ($rowsdt[19] == 1 && $CashReg_ApplyColorOffer == 1) $Color="style='background-color:#".$CashReg_BgColorOffer."'";
				
			//If Item Price Below 100 For Base1 Color Background Orange
			/*if ($CashRegisterTTC == 1) {
				if ($rowsdt[11] >= 0 && $rowsdt[11] < 100 && $txtCurr == $base1) $Color="style='background-color:#FACC2E'";
			} else {
				if ($rowsdt[6] >= 0 && $rowsdt[6] < 100 && $txtCurr == $base1) $Color="style='background-color:#FACC2E'";
			}	*/
				
			
			//If Item Qty Is Zero
			if ($rowsdt[5] == 0 && $CashReg_ApplyColorZeroQty == 1) $Color="style='background-color:#".$CashReg_BgColorZeroQty."'";
			
			//If Item Price Is Zero
			if ($rowsdt[6] == 0 && $CashReg_ApplyColorZeroPrice == 1) $Color="style='background-color:#".$CashReg_BgColorZeroPrice."'";
			
			//If Item Has Discount
			if ($rowsdt[9] != 0 && $CashReg_ApplyColorHasDiscount == 1) $Color="style='background-color:#".$CashReg_BgColorHasDiscount."'";
			
			//If Item Waste
			$WasteClass = '';
			if ($rowsdt[23] == 3) $WasteClass="style55";
			
			//If Item Hold
			if ($rowsdt[23] == 4) $Color="style='background-color:#FF6060'"; 
			
			//If Weight Module True and Item Weight > 0 and Item Qty Below 10 GRAMS Color Background Yellow
			$vItemQty = $rowsdt[5];
			if ($CashReg_Weight == 1 && $rowsdt[20] > 1 && abs($vItemQty) < 0.01 && $CashReg_ApplyColorQty == 1) { 
				//$Color="style='background-color:#FFFF00'";
				$Color="style='background-color:#".$CashReg_BgColorQty."'";
			}
						
				
			//If Item Qty Doesn't Match Order Item Qty In Case Delivery True Color Background Light Green
			if ($Module_RestaurantDelivery == 1 && $txtOrderId != '' && $CashReg_ApplyColorOrderQty == 1) {
				$sub_query = " Select ifNull(SaleDt_Quantity,0) From RetailOrderDt ".
							 " Where RetailOrderDt.Sale_ID = '".$txtOrderId."' ".
							 " And RetailOrderDt.Item_Code = '".$rowsdt[2]."'";
				$sub_result = selectData($connection, $sub_query);
				$vOrderQty  = $sub_result[0];
				if(empty($vOrderQty)) $vOrderQty = 0;
					
				$vItemQty = $rowsdt[5];
				if ($vOrderQty != $vItemQty) {
					//$Color="style='background-color:#81F7D8'";
					$Color="style='background-color:#".$CashReg_BgColorOrderQty."'";
				}
			}
			
			if($rowsdt[23] != 2)			
				echo "<tr  onMouseOver=\"style.cursor='pointer'\"  id='row$ct' onclick=\"changecolor(this,'SelectedRec','SelectedRecColor','$rowsdt[0]','$rowsdt[13]','$Module_SerialNo','$ct','".$rowsdt[23]."','".$rowsdt[25]."','uploads/".$rowsdt[27]."')\" ".$Color." height='25px'>";
			else
				echo "<tr  style='text-decoration:line-through;background-color:#A8A8A8' onMouseOver=\"style.cursor='pointer'\"  id='row$ct' ".$Color." height='25px'>";
				
			$rowsdt[2] = ereg_replace(' ','',$rowsdt[2]);
			
			if ($rowsdt[13] == 1 && $Module_SerialNo == 1)
				echo "<img hidden src='img/button_addserial.png' onMouseOver=\"style.cursor='pointer'\" onclick=AddSerialNo('".$rowsdt[0]."') title='Add Serial Nos'  >";
				
					
			echo "	<img hidden src='img/edit.png'  onMouseOver=\"style.cursor='pointer'\" onclick=UpdateRecordDt('".$rowsdt[0]."',$FC_CashRegisterMod) title='Edit Record'  >";
			echo "	<img hidden src='img/delete.png'  onMouseOver=\"style.cursor='pointer'\" id='imgDelete[$i]' onclick=DeleteRecordDt('".$rowsdt[0]."','".$rowsdt[2]."',$FC_CashRegisterDelItem,'$i') title='Delete Record'  width='20' height='20'>";
			echo "	<input hidden type='button' onMouseOver=\"style.cursor='pointer'\" id='imgSubmit[$i]' onclick=\"SubmitRecordGrid('".$i."','".$formpath."','".$rowsdt[0]."',$FC_DiscountPerLimit,$CashReg_ForcingVendor,'".$rowsdt[2]."'); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:bottom; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' >";
				
			
			if($CashRegister_showItemImage == '1'){
				echo "<td align='left'><img src='uploads/".$rowsdt[26]."' alt='img' width=20></td>";
			}	
			if($CashRegister_showItemLocation == '1'){
				$queryLocation = "select concat(description1, ' - ' ,description2, ' - ' ,description3 ) from item_location where item_code = '".$rowsdt[2]."'";
 				$sub_result1 = selectData($connection, $queryLocation);
				$ItemLoc = $sub_result1[0]; 
				echo "<td align='left'>$ItemLoc</td>";
			}	
			if ($CashRegister_PrintBarcode == 1){
				$txtBarcode[$i]=$rowsdt[1];
				echo "<td align='left'><span class='style15 $WasteClass'><input type='hidden' name='txtBarcode[$i]' id='barcodedt[$i]' value='".htmlspecialchars($txtBarcode[$i], ENT_QUOTES)."'  > ".$rowsdt[1]."</span></td>";
			}	
			else {
				$txtBarcode[$i]=$rowsdt[2];
				echo "<input type='hidden' name='txtBarcode[$i]' id='barcodedt[$i]' value='".htmlspecialchars($txtBarcode[$i], ENT_QUOTES)."'  >";
				if ($CashRegister_showitemcode == 1) 
				echo "<td align='left'><span class='style15 $WasteClass'>".$rowsdt[2]."</span></td>";
			}	
			
			echo "<td align='left'><span class='style15 $WasteClass'>".$rowsdt[3]."</span></td>";
			//echo "<td align='right'><span class='style15'>".number_format($rowsdt[5], $DecimalBase)."</span></td>";
				
				
			// if Total Quantity Differs From Total SerialNos
			if ($Module_SerialNo == 1 && (abs($rowsdt[5]) != $rowsdt[14] || $rowsdt[5] == 0) && (($rowsdt[13] == 1 && $rowsdt[15] == '') || ($rowsdt[13] == 1 && $rowsdt[15] != '' && $rowsdt[16] == 1)) )  {
			    if ($QtySerNoCheck == 0) {
					$QtySerNoCheck = 1;
						
					echo '<script type="text/javascript" language="javascript">';
					echo ' x = document.retail; ';
					echo ' x.QtySerNo.value=1; ';
					echo '</script>';
				}					
						
				echo "<td align='right' style='background-color:#FF0000' ><span class='style28' style='text-decoration:underline;'>".number_format($rowsdt[5], $DecimalBase)."</span></td>";
			} else	{
				$txtQty[$i]=$rowsdt[5];
				echo "<td align='right'><span class='style15 $WasteClass'><input type='text' name='txtQty[$i]' id='qtydt[$i]' onfocus=FillHidden('qtydt[$i]'); value='".htmlspecialchars($txtQty[$i], ENT_QUOTES)."' readonly  maxlength='4' class='".$ClassI."'  style='border:0px;background:transparent; text-align:right; width:100%; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." $ModeModifyQty></span></td>";
			}
				
				
			if ($CashRegisterTTC == 1) {
				$txtPrice[$i]=$rowsdt[11];
				echo "<td align='right' style='padding-right:3px;'><span class='style15 $WasteClass'><input type='text' name='txtPrice[$i]' id='pricedt[$i]' value='".htmlspecialchars($txtPrice[$i], ENT_QUOTES)."'  maxlength='20' class='".$ClassI."'  style='border:0px;background:transparent;width:100%; height:20px;text-align:center;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." $ModeModifySellPrice></span></td>";
			}	
			else{
				$txtPrice[$i]=$rowsdt[6];
				echo "<td align='right' style='padding-right:3px;'><span class='style15 $WasteClass'><input type='text' name='txtPrice[$i]' id='pricedt[$i]' value='".htmlspecialchars($txtPrice[$i], ENT_QUOTES)."'  maxlength='20' class='".$ClassI."'  style='border:0px;background:transparent; width:100%; height:20px;text-align:right;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." $ModeModifySellPrice></span></td>";
			}		
				
			
			if ($CashRegisterTTC == 1) 
				echo "<td align='right'><span class='style15 $WasteClass'>".number_format($rowsdt[12], $DecimalBase)."</span></td>";
			else
				echo "<td align='right'><span class='style15 $WasteClass'>".number_format($rowsdt[10], $DecimalBase)."</span></td>";
				
			$txtDisc[$i]=$rowsdt[9];		
			if($CashRegister_showdiscount==1) echo "<td align='left'><span class='style15 $WasteClass'><input type='text' name='txtDisc[$i]' id='discdt[$i]' onfocus=FillHidden('discdt[$i]'); value='".htmlspecialchars($txtDisc[$i], ENT_QUOTES)."'  maxlength='20' class='".$ClassI."'  style='border:0px;background:transparent; width:40px; height:20px;text-align:right;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." ></span></td>";
				
				
			if ($Module_PriceOffer > 0)	{
				echo "<td align='right'><span class='style15 $WasteClass'>".number_format($rowsdt[18], $DecimalBase)."</span></td>";
			}	

			if ($Module_SerialNo == 1)	{
				echo "<td align='left'><span class='style15 $WasteClass'>".$rowsdt[14]."</span></td>";	
			}

			if($CashReg_Vendor==1){
				$txtVendor[$i]=$rowsdt[17];
				echo "<td align='left'><span class='style15 $WasteClass'><input type='text' name='txtVendor[$i]' id='vendordt[$i]' value='".htmlspecialchars($txtVendor[$i], ENT_QUOTES)."'  maxlength='20' class='".$ClassI."'  style='border:0px;background:transparent; width:70px; height:20px;text-align:left;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." $ModeModifyVendor></span></td>";
			}	
			else {
				$txtVendor[$i]=$rowsdt[17];
				echo "<input type='hidden' name='txtVendor[$i]' id='vendordt[$i]' value='".htmlspecialchars($txtVendor[$i], ENT_QUOTES)."'  >";
			}
				
				
			if ($ShowSlipNumber == 1){
				$txtSlip[$i]=$rowsdt[21];
				echo "<td align='left'><span class='style15 $WasteClass'><input type='text' name='txtSlip[$i]' id='slipdt[$i]' value='".htmlspecialchars($txtSlip[$i], ENT_QUOTES)."'  maxlength='20' class='".$ClassI."'  style='border:0px;background:transparent; width:70px; height:20px;text-align:left;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." $ModeModifySlip></span></td>";
			}	
			else {
				echo "<input type='hidden' name='txtSlip[$i]' id='slipdt[$i]' value='".htmlspecialchars($txtSlip[$i], ENT_QUOTES)."'>";
			}
				
			$txtWarehouseCode[$i]=$rowsdt[4];		
			echo"<input type='hidden' name='txtWarehouseCode[$i]' id='Whdt[$i]'  value='$txtWarehouseCode[$i]' >";	
			echo "</tr>";
			
			
			if($rowsdt[24] != '') {
				echo "<tr>";
				echo "	<td align='left' style='padding-left: 80px;' colspan='$nbrcol'><span class='style15 $WasteClass' style='font-style:italic;'>".($rowsdt[24])."</span></td>";
				echo "</tr>";
			}
			
			
			$i=$i+1;
		}
	}
	echo"</table></div></div>";
	
			  
}

function ShowHoldItems($connection,$arrayparams,$PRetailId){
	
	$querydt = " Select RetailDt.SaleDt_id, Items.Item_Description, SaleDt_Quantity, SaleDt_ItemStatusRemark ".
			   " From Temp_RetailDt As RetailDt ".
			   " Left Join Items on RetailDt.Item_code = Items.Item_code ".
			   " Where RetailDt.Sale_ID = ".$PRetailId."  ".
			   " And IfNull(RetailDt.SaleDt_ItemStatus,0) = 4 ".
			   " Order By RetailDt.SaleDt_ID Desc ";
	//echo $querydt;
	
	echo" <table border='0' cellspacing='0'  cellpadding='0' align='left' style='width:330px;'>
		  <col width=25>
		  <col width=200>
		  <col width=45>
		  <col width=60>";
			
	$resultdt=mysql_query($querydt,$connection) or die(mysql_error());
	while($rowsdt=mysql_fetch_array($resultdt)){
	
		$ct+=1;

		if($ct%2==0)
			$Color="style='background-color:#f2f2f2'";
		else			
			$Color="style='background-color:#ffffff'";
				
		
		echo"<tr $Color>";
		echo"	<td align='center' valign='top'><input type='checkbox' name='ChkH[]' id='ChkH$rowsdt[0]' value='$rowsdt[0]' onclick='SelectFireItems();'></td>";
		echo"	<td align='left' valign='top' style='font-size:11px;'>$rowsdt[1]</td>";
		echo"	<td align='center' valign='top' style='font-size:11px;'>$rowsdt[2]</td>";
		echo"	<td align='center' valign='top' style='font-size:11px;'>$rowsdt[3]</td>";
		echo"</tr>";
	}
	
	echo"</table>";
}


function ShowRetailDtGrid_Split($connection,$arrayparams,$PRetailId){


$Module_PriceOffer=$arrayparams['Module_PriceOffer'];
$CashRegister_PrintBarcode=$arrayparams['CashRegister_PrintBarcode'];
$Module_SerialNo=$arrayparams['Module_SerialNo'];
$DecimalBase=$arrayparams['DecimalBase']; 
$CashRegisterTTC=$arrayparams['CashRegisterTTC'];
$CashReg_Weight=$arrayparams['CashReg_Weight'];
$Module_RestaurantDelivery=$arrayparams['Module_RestaurantDelivery']; 
$CashRegister_PrintBarcode=$arrayparams['CashRegister_PrintBarcode'];
$FC_CashRegisterMod=$arrayparams['FC_CashRegisterMod'];
$FC_CashRegisterDelItem=$arrayparams['FC_CashRegisterDelItem'];
$PriceLabel=$arrayparams['PriceLabel'];
$ShowSlipNumber=$arrayparams['ShowSlipNumber'];
$txtCurr=$arrayparams['txtCurr'];
$base1=$arrayparams['base1'];
$base2=$arrayparams['base2'];
$txtOrderId=$arrayparams['txtOrderId'];
$Unmodify_SellingPrice=$arrayparams['Unmodify_SellingPrice'];
$passchecked=$arrayparams['passchecked'];
$height=$arrayparams['height'];
$CashReg_Vendor=$arrayparams['CashReg_Vendor'];
$FC_DiscountPerLimit=$arrayparams['FC_DiscountPerLimit'];
$CashReg_ForcingVendor=$arrayparams['CashReg_ForcingVendor'];
$Module_CashRegisterTable=$arrayparams['Module_CashRegisterTable'];


$filepath = 'Functions_Retail.php';
$i=1;
	


	echo"<div id='container' style='position: relative;z-index:1;' >";
	echo"	<div id='Loader' class=''></div>";
	
	
		echo" 	<div id='grid_headerDiv' class='grid_headerDiv' style='width:450px;border:0px solid #000000;height:18px'>";


	
	

	
		echo" <table border='0'  id='grid_datatable' class='grid_data' cellspacing='0'  cellpadding='0' align='left' >
			  <col width=100>";
		echo"	<col width=280>"; 
		echo"<col width=50>";
			
			
	echo"<tr height='15px'>";
		  

	echo"	<th bgcolor='#F7F7F7' align='left'>Item Code</th>";	
	echo"	<th bgcolor='#F7F7F7' align='left'>Item Description</th>";
	echo"  	<th bgcolor='#F7F7F7' align='center'>Qty</th>";
	
				 
    echo"</tr>";
	echo"</table></div>";
		   
	
	    echo"<div id='grid_contentDiv' class='grid_contentDiv' onscroll=\"ScrollHeader('grid_headerDiv','grid_contentDiv')\" style='width:450px;height:280'>";
				   
	echo"<table border='0' align='left' id='grid_datatable' class='grid_data' cellpadding='0' cellspacing='0' style='$TableWidthStyle'>";
	echo"<col width=100>";
	echo"<col width=300>";
	echo"<col width=50>";
	
		
				
	if ($PRetailId != '' ) {
		  
		//Checking For Difference Btw Qty and Count SerialNo
		$QtySerNoCheck = 0;
 
				   
		$querydt = " Select RetailDt.SaleDt_id, RetailDt.Item_Barcode, RetailDt.Item_code, Items.Item_Description, RetailDt.Warehouse_Code, ".
				   " SaleDt_Quantity, Round(SaleDt_Price, ".$DecimalBase."), SaleDt_PriceBase1, SaleDt_PriceBase2, ".
				   " Round(SaleDt_DiscountPer, ".$DecimalBase."),  ".
				   " Round(((SaleDt_Quantity*SaleDt_Price)-((SaleDt_Quantity*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, ".
				   " ifNull(Items.Item_withserialno,0) As ItemWithSerialNo, Count(Temp_Purchasesserialno.SerialNo_Code) As CountSerialNo, ".
				   " RetailDt.Item_CodePacked, ifNull(Items1.Item_withserialno,0) As ItemPackWithSerialNo, RetailDt.Vendor_Code, Round(RetailDt.SaleDt_ActualPrice, ".$DecimalBase."), ".
				   " ifNull(RetailDt.Price_Offer,0) As Price_Offer, ifNull(Items.Item_Weight,0), RetailDt.Slip_Number,RetailDt.Warehouse_Code ".
				   " From Temp_RetailDt As RetailDt ".
				   " Left Join Items on RetailDt.Item_code = Items.Item_code ".
				   " Left Join Items As Items1 on RetailDt.Item_CodePacked = Items1.Item_code ".
				   " Left Join Temp_Purchasesserialno on RetailDt.SaleDt_ID = Temp_Purchasesserialno.RetailDt_ID ".
				   " And Temp_Purchasesserialno.Journal_Type In ('DI','DR') ".
				   " Where RetailDt.Sale_ID = ".$PRetailId.
				   " And IfNull(RetailDt.SaleDt_ItemStatus,0) Not In (2,3) ".
				   //" And RetailDt.Logged_Code = '".$HTTP_SESSION_VARS['useraccount']."' ".
				   " Group By  RetailDt.SaleDt_id ".
				   " Order By RetailDt.SaleDt_ID Desc ";
		//echo $querydt;
			
		$resultdt=mysql_query($querydt,$connection) or die(mysql_error());
		while($rowsdt=mysql_fetch_array($resultdt)){
			    
			$ct+=1;

			 
					
			if($ct%2==0)
				$Color="style='background-color:#f2f2f2'";
			else			
				$Color="style='background-color:#ffffff'";		
					
						
			$sub_query1  = " Select ifNull(Item_Pack,0), ifNull(Item_ModifySellingPrice,0) From Items Where Item_Code = '".$rowsdt[2]."' ";
			$sub_result1 = selectData($connection, $sub_query1);
			$ItemPack = $sub_result1[0];
			$ItemModifySellingPrice = $sub_result1[1];		
			
			// User Has No Access To Modify The Price	
				
			$ModeModifySellPrice = '';
			if ($Unmodify_SellingPrice == 1 || ($ItemModifySellingPrice == 0 && $rowsdt[2] != ''))	
				$ModeModifySellPrice = ' readonly ';
			if ($passchecked == 1 || ($ItemModifySellingPrice == 1 && $rowsdt[2] != ''))	
				$ModeModifySellPrice = '';	
					
					
			if($FC_CashRegisterMod==0){
				$ModeModifySellPrice= ' readonly ';
				$ModeModifyQty= ' readonly ';
				$ModeModifyVendor= ' readonly ';
				$ModeModifySlip= ' readonly ';
			}
			if ($passchecked == 1){
				$ModeModifySellPrice= '';
				$ModeModifyQty= '';
				$ModeModifyVendor= '';
				$ModeModifySlip='';
			}
				
			//If Item Price Offer True Color Background Honey
			if ($rowsdt[19] == 1) $Color="style='background-color:#D7F754'";
				
						
				
			//If Weight Module True and Item Weight > 0 and Item Qty Below 10 GRAMS Color Background Yellow
			$vItemQty = $rowsdt[5];
			if ($CashReg_Weight == 1 && $rowsdt[20] > 1 && abs($vItemQty) < 0.01) { 
				$Color="style='background-color:#FFFF00'";				
			}
						
				
			//If Item Qty Doesn't Match Order Item Qty In Case Delivery True Color Background Light Green
			if ($Module_RestaurantDelivery == 1 && $txtOrderId != '') {
				$sub_query = " Select ifNull(SaleDt_Quantity,0) From RetailOrderDt ".
							 " Where RetailOrderDt.Sale_ID = '".$txtOrderId."' ".
							 " And RetailOrderDt.Item_Code = '".$rowsdt[2]."'";
				$sub_result = selectData($connection, $sub_query);
				$vOrderQty  = $sub_result[0];
				if(empty($vOrderQty)) $vOrderQty = 0;
					
				$vItemQty = $rowsdt[5];
				if ($vOrderQty != $vItemQty) {
					$Color="style='background-color:#81F7D8'";
				}
			}
				
			echo "<tr  onMouseOver=\"style.cursor='pointer'\"  id='$rowsdt[0]' onclick=\"changecolor(this);\"  height='25px'>";
				
			$rowsdt[2] = ereg_replace(' ','',$rowsdt[2]);
			
				
			
				
			if ($CashRegister_PrintBarcode == 1){
				$txtBarcode[$i]=$rowsdt[1];
				echo "<td align='left'><span class='style15'><input type='hidden' name='txtBarcode[$i]' id='barcodedt[$i]' value='".htmlspecialchars($txtBarcode[$i], ENT_QUOTES)."'  >".$rowsdt[1]."</span></td>";
			}	
			else{
				$txtBarcode[$i]=$rowsdt[2];
				echo "<td align='left'><span class='style15'><input type='hidden' name='txtBarcode[$i]' id='barcodedt[$i]' value='".htmlspecialchars($txtBarcode[$i], ENT_QUOTES)."'  >".$rowsdt[2]."</span></td>";
			}	
			
			echo "<td align='left'><span class='style15'>".$rowsdt[3]."</span></td>";
			//echo "<td align='right'><span class='style15'>".number_format($rowsdt[5], $DecimalBase)."</span></td>";
				
				
			// if Total Quantity Differs From Total SerialNos
			if ($Module_SerialNo == 1 && (abs($rowsdt[5]) != $rowsdt[14] || $rowsdt[5] == 0) && (($rowsdt[13] == 1 && $rowsdt[15] == '') || ($rowsdt[13] == 1 && $rowsdt[15] != '' && $rowsdt[16] == 1)) )  {
			    if ($QtySerNoCheck == 0) {
					$QtySerNoCheck = 1;
						
					echo '<script type="text/javascript" language="javascript">';
					echo ' x = document.retail; ';
					echo ' x.QtySerNo.value=1; ';
					echo '</script>';
				}					
						
				echo "<td align='right' style='background-color:#FF0000' ><span class='style28' style='text-decoration:underline;'>".number_format($rowsdt[5], $DecimalBase)."</span></td>";
			} else	{
				$txtQty[$i]=$rowsdt[5];
				echo "<td align='right'><span class='style15'><input type='text' name='txtQty[$i]' id='qtydt[$i]' onfocus=FillHidden('qtydt[$i]'); value='".htmlspecialchars($txtQty[$i], ENT_QUOTES)."' readonly  maxlength='4' class='".$ClassI."'  style='border:0px;background:transparent; text-align:right; font-size:11px; width:100%; height:20px;' onchange=\"SetModRecord('ModRec_G1','$i');\" ".$KeyDown." $ModeModifyQty></span></td>";
			}
				
					
			
				
			$txtWarehouseCode[$i]=$rowsdt[4];		
			echo"<input type='hidden' name='txtWarehouseCode[$i]' id='Whdt[$i]'  value='$txtWarehouseCode[$i]' >";	
			echo "</tr>";
			$i=$i+1;
		}
	}
	echo"</table></div></div>";
	
			  
}

function ShowOrders($SRetId,$connection){

echo"     <table border='0'  id='grid_datatable1' cellspacing='0'  cellpadding='0' align='left' style='margin-left:2px; margin-top:2px;width:350px '>	";


	$query = " select temp_retail.Sale_reference,projectdt.Projectdt_id, Projectdt_name, Projectdt_numberofseats, projectdt.Project_id
				, Projectdt_Reserved, projectdt.cashregister_name, Projectdt_numberofguests 
				,temp_retail.Sale_id Sale_id
				from projectdt  left join temp_retail on projectdt.projectdt_id = temp_retail.projectdt_id  ,project
				where projectdt.project_id=project.project_id
				and upper(project.project_name) = 'TABLE'
				and if(temp_retail.Sale_id = '',1=1,ifnull(temp_retail.Sale_id,-1) != '$SRetId')
				";
	
	$result=mysql_query($query,$connection) or die(mysql_error());
				
	$i=1;
	while($rows=mysql_fetch_array($result)){
		if($i==1) echo"<tr>";
						
			echo "<td onclick=\"combine('$rows[8]',$rows[4],'$rows[1]')\" class='Tablebuttons'  width='62px' height='47px'>
			<font color=white></font> ";   
			if($rows[8]!='')
				echo"<input type='button' id='btnTbSplit$i'  class='TablebuttonsRetailed' style='height:60px' value='$rows[2]\n Order:\n $rows[0]'>";
				else echo"<input type='button' id='btnTbSplit$i'  class='Tablebuttons' style='height:60px' value='$rows[2]' >";
				
			echo"<span><span></span></span></button></td>";
		

		if($i%7==0)	echo"</tr><tr>";
		
		 

		$i+=1;
	}


	echo " </table>";
	
	}

	
function ShowOrders_Split($SRetId,$connection){

echo"     <table border='0'  id='grid_datatable1' cellspacing='0'  cellpadding='0' align='left' style='margin-left:2px; margin-top:2px;width:350px '>
			<col width=90>
			<col width=90>
			<col width=90>
			<col width=90>
			
			";


	$query = " select temp_retail.Sale_reference,projectdt.Projectdt_id, Projectdt_name, Projectdt_numberofseats, projectdt.Project_id
				, Projectdt_Reserved, projectdt.cashregister_name, Projectdt_numberofguests 
				,temp_retail.Sale_id Sale_id
				from projectdt  left join temp_retail on projectdt.projectdt_id = temp_retail.projectdt_id and ifnull(temp_retail.Sale_Posted,0) = 0
				and temp_retail.Sale_id != $SRetId
				,project
				where projectdt.project_id=project.project_id
				and upper(project.project_name) = 'TABLE'
				
					";
//echo $query;				
	$result=mysql_query($query,$connection) or die(mysql_error());
				
	$i=1;
	while($rows=mysql_fetch_array($result)){
		
		if($i==1)
			echo"<tr >";
			
			if($rows[8])
			$bg = 'background-color:yellow';
				else
			$bg = '';
			
			echo "<td width='62px' height='47px'><input type='button' id='btnTbl$i' name='btnTbl$i' class='TablebuttonsRetailed' style='width:100px;$bg' onclick=splitorderdt('$rows[8]','$rows[4]','$rows[1]') value='$rows[2]'><span><span></span></span></button>$xx</td>";
		
		//	echo "<td   width='20px' height='20px'>$rows[8]
		//	<font color=white>Order Ref : $rows[0]</font>    $rows[2]
		//	</td>";
		

		if($i%4==0) {
			echo"</tr>";
			echo"<tr>";
			
			}
		
		//echo"<tr><tD>&nbsp;</td>";
		//echo"</tr>";

		$i+=1;
	}


	echo " </table>";
	
}


function ShowShortCutGrid($connection,$arrayparams){

	$txtCurr=$arrayparams['txtCurr'];
	$txtDate=$arrayparams['txtDate'];
	$txtClientCode=$arrayparams['txtClientCode'];
	$Module_CashRegisterStandardView=$arrayparams['Module_CashRegisterStandardView'];
	$Module_CashRegisterFastItem=$arrayparams['Module_CashRegisterFastItem'];
	
	echo"<table border='0' cellspacing=0 cellpadding=0 >";
	echo"<tr>";
		

	$query_buttons = " Select ItemButton_Id, ItemButton_Value, substr(ItemButton_Label,1,20) as ItemButton_Label, ItemButton_Order, ItemButton_Color, ItemButton_Picture, ".
					" ItemButton_Width, ItemButton_Height ".
					 " From ItemButtons ";
	$query_buttons .= " inner join items on items.item_code = ItemButton_Value and ifnull(Item_active,0) = 1 ";				  
	if ($_GET['option']	== 'Modifier')
		$query_buttons .= " Where Upper(ItemButton_Type) = 'MODIFIER' And ifNull(ItemButton_Level,'') = '' ";
	else
		$query_buttons .= " Where Upper(ItemButton_Type) = 'SHORTCUT' ";
		
	$query_buttons .= " Order By ItemButton_Order Desc ";//and ifnull(Item_active,0) = 1
		//	echo $query_buttons;		
	$i=0;
	
	if ($_GET['option']	== 'Modifier') {
		echo" <td align='left'><div class='list-item' style='$float'><input type='button' name='BtnModOthers' id='BtnModOthers' class='fastbuttons' style='background:#f4f4f4;' onclick=\"OpenModifierWin(); return false;\" value='Others'></div></td>";	
		$i=$i+1;
	}
	
	$result_buttons=mysql_query($query_buttons,$connection) or die(mysql_error());
	while($rows_buttons=mysql_fetch_array($result_buttons)){
		extract($rows_buttons);
		
		$ButtonName  = "Btn_".$ItemButton_Order;
		$ButtonLabel = $ItemButton_Label;
		$ButtonValue = $ItemButton_Value;
		
		$ButtonColor = '';
		if ($ItemButton_Picture != '') {
			$ButtonLabel = '';
		}
		if ($ItemButton_Color != '') {
			$ButtonColor = "background-color:#".$ItemButton_Color;
		}	
		
		$sub_query = "SELECT Client_SellingPrice FROM Clients WHERE Ledger_Number = '".$txtClientCode."'";
		//echo $sub_query;
		$sub_result = selectData($connection, $sub_query);
		$c_sp = $sub_result[0];
			
		$sub_query = " Select Currency_Code, ".
					 " ifNull(Item_SellingPrice1,0), ifNull(Item_SellingPrice1Base1,0), ifNull(Item_SellingPrice1Base2,0), ifNull(Item_SellingPrice2,0), ifNull(Item_SellingPrice2Base1,0), ifNull(Item_SellingPrice2Base2,0), ".
					 " ifNull(Item_SellingPrice3,0), ifNull(Item_SellingPrice3Base1,0), ifNull(Item_SellingPrice3Base2,0), ifNull(Item_SellingPrice4,0), ifNull(Item_SellingPrice4Base1,0), ifNull(Item_SellingPrice4Base2,0), ".
					 " ifNull(Item_SellingPrice5,0), ifNull(Item_SellingPrice5Base1,0), ifNull(Item_SellingPrice5Base2,0), ifNull(Item_SellingPrice6,0), ifNull(Item_SellingPrice6Base1,0), ifNull(Item_SellingPrice6Base2,0), ".
					 " ifNull(Item_ModifySellingPrice,0) ".
					 " From Items Where Item_Code = '".$ItemButton_Value."'  ";
		//echo $sub_query; exit;
		$sub_result = selectData($connection, $sub_query);
		$ItemCurr   = $sub_result[0];	
		$ItemModifySellingPrice = $sub_result[19];
		
		if (empty($ItemCurr)) $ItemCurr = $txtCurr;
			
			if ($txtCurr != $ItemCurr) {
				if ($txtCurr == $base1) { 
					$Item_SellingPrice1 = $sub_result[2];
					$Item_SellingPrice2 = $sub_result[5];
					$Item_SellingPrice3 = $sub_result[8];
					$Item_SellingPrice4 = $sub_result[11];
					$Item_SellingPrice5 = $sub_result[14];
					$Item_SellingPrice6 = $sub_result[17];
				}
				else if ($txtCurr == $base2) {
					$Item_SellingPrice1 = $sub_result[3];
					$Item_SellingPrice2 = $sub_result[6];
					$Item_SellingPrice3 = $sub_result[9];
					$Item_SellingPrice4 = $sub_result[12];
					$Item_SellingPrice5 = $sub_result[15];
					$Item_SellingPrice6 = $sub_result[18];
				}
				else {
					$Item_SellingPrice1 = ConvertCurrency($ItemCurr, $txtCurr, insertMySQLDate($txtDate), $sub_result[1], $connection);
					$Item_SellingPrice2 = ConvertCurrency($ItemCurr, $txtCurr, insertMySQLDate($txtDate), $sub_result[4], $connection);
					$Item_SellingPrice3 = ConvertCurrency($ItemCurr, $txtCurr, insertMySQLDate($txtDate), $sub_result[7], $connection);
					$Item_SellingPrice4 = ConvertCurrency($ItemCurr, $txtCurr, insertMySQLDate($txtDate), $sub_result[10], $connection);
					$Item_SellingPrice5 = ConvertCurrency($ItemCurr, $txtCurr, insertMySQLDate($txtDate), $sub_result[13], $connection);
					$Item_SellingPrice6 = ConvertCurrency($ItemCurr, $txtCurr, insertMySQLDate($txtDate), $sub_result[16], $connection);
					
				}
				
			} else {
				$Item_SellingPrice1 = $sub_result[1];
				$Item_SellingPrice2 = $sub_result[4];
				$Item_SellingPrice3 = $sub_result[7];
				$Item_SellingPrice4 = $sub_result[10];
				$Item_SellingPrice5 = $sub_result[13];
				$Item_SellingPrice6 = $sub_result[16];
			}
			
			
			switch ($c_sp){
				case "I":
					$ItemSellPrice = $Item_SellingPrice1; break;
				case "II":
					$ItemSellPrice = $Item_SellingPrice2; break;
				case "III":
					$ItemSellPrice = $Item_SellingPrice3; break;
				case "IV":
					$ItemSellPrice = $Item_SellingPrice4; break;
				case "V":
					$ItemSellPrice = $Item_SellingPrice5; break;
				case "VI":
					$ItemSellPrice = $Item_SellingPrice6; break;
			}
			
		if($Module_CashRegisterStandardView==0 ){
			if($i%12==0)
				echo"</tr><tr>";
		
		}
		else{
			if($i%5==0)
				echo"</tr><tr>";
		}	
		if($ItemButton_Width != '' && $ItemButton_Width != 0)
			$bwidth = $ItemButton_Width."px";
		else $bwidth = '40px';
		
		if($ItemButton_Height != '' && $ItemButton_Height != 0)
			$bheight = $ItemButton_Height."px";
		else $bheight = '40px';
		
		if ($_GET['option']	== 'Modifier') {
			if ($ItemButton_Picture != '') {
				echo" <td align='left' width='$bwidth'><div class='list-item' style='$float'><button type='button' name='".$ButtonName."' id='".$ButtonName."' class='fastbuttons_1' style='$ButtonColor;width:$bwidth; height:$bheight;' onclick=\"SubmitItemModifier('".$ButtonValue."','".$ButtonLabel."','".$ItemSellPrice."'); return false;\"><img src='GetButtonImage.php?option=fast&id=$ItemButton_Id' style='width:$bwidth; height:$bheight;'></img></button></div></td>";	
			} else {
				echo" <td align='left' width='$bwidth'><div class='list-item' style='$float'><input type='button' name='".$ButtonName."' id='".$ButtonName."' class='fastbuttons' style='$ButtonColor;width:$bwidth; height:$bheight;' onclick=\"SubmitItemModifier('".$ButtonValue."','".$ButtonLabel."','".$ItemSellPrice."'); return false;\" value='$ButtonLabel' ></div></td>";	
			}
		} else {
			if ($ItemButton_Picture != '') {
				echo" <td align='left' width='$bwidth'><div class='list-item' style='$float'><button type='button' name='".$ButtonName."' id='".$ButtonName."' class='fastbuttons_1' style='$ButtonColor;width:$bwidth; height:$bheight;' onclick=\"LoadFastItem('".$ButtonValue."','".$ItemSellPrice."','".$Unmodify_SellingPrice."','".$ItemModifySellingPrice."'); return false;\"><img src='GetButtonImage.php?option=fast&id=$ItemButton_Id' style='width:$bwidth; height:$bheight;'></img></button></div></td>";	
			} else {
				echo" <td align='left' width='$bwidth'><div class='list-item' style='$float'><input type='button' name='".$ButtonName."' id='".$ButtonName."' class='fastbuttons' style='$ButtonColor;width:$bwidth; height:$bheight;' onclick=\"LoadFastItem('".$ButtonValue."','".$ItemSellPrice."','".$Unmodify_SellingPrice."','".$ItemModifySellingPrice."'); return false;\" value='$ButtonLabel'></div></td>";	
			}
		}
		
		$i=$i+1;
	}			
	echo"</tr></table>";


}

function ShowItemModifiers($connection,$arrayparams,$ItemCode){

	$sub_query = " Select Distinct ItemButton_Level From itembuttons ".
				 " Inner Join items on items.Item_Code = itembuttons.ItemButton_RelatedItem ".
			     " Where ((upper(Item_Code) = upper('".$ItemCode."')) or (upper(Item_Barcode) = upper('".$ItemCode."')) or  ".
				 "  	  (upper(Item_Barcode2) = upper('".$ItemCode."')) or (upper(Item_Barcode3) = upper('".$ItemCode."'))) ".
				 " And ifNull(ItemButton_Level,'') != '' and ifnull(item_active,0) = 1 ";
				 
				 
			
	echo "<table border='0' cellspacing='0' cellpadding='0' style='table-layout:fixed;'>";
	echo "<tr>";
	
	$sub_result=mysql_query($sub_query,$connection);
	while($sub_rows=mysql_fetch_array($sub_result)){
		echo "<td style='width:120px; text-align:center;'>
				<span style='font-weight:bold;'>Level $sub_rows[0]</span><br><br>";
		
		$sub_query1 = " Select ItemButton_Label From itembuttons ".
					  " Inner Join items on items.Item_Code = itembuttons.ItemButton_RelatedItem ".
					  " Where ((upper(Item_Code) = upper('".$ItemCode."')) or (upper(Item_Barcode) = upper('".$ItemCode."')) or  ".
					  "  	  (upper(Item_Barcode2) = upper('".$ItemCode."')) or (upper(Item_Barcode3) = upper('".$ItemCode."'))) ".
					  " And ifNull(ItemButton_Level,'') = '".$sub_rows[0]."'";
					  
		$j = 1;
		$sub_result1=mysql_query($sub_query1,$connection);
		while($sub_rows1=mysql_fetch_array($sub_result1)){
			$ButtonName = 'btnMod'.$j;
			echo "<input type='button' id='$ButtonName' onclick=\"FillItemModifiers('".$sub_rows1[0]."', this)\" class='subgroupbuttons' style='width:100px; height:40px;' value='".$sub_rows1[0]."' />";
			
			$j += 1;
		}
		
		echo "</td>";
	}	
	
	echo "</tr></table>";

}
	
function ShowRetailTotals($connection,$arrayparams,$PRetailId){
	
	
	
	$query = " select discount_amount from setup ";
	$result=mysql_query($query,$connection) or die(mysql_error());
	$rows=mysql_fetch_array($result);
	$discount_amount = $rows[0];
	
	$Module_AdditionalTaxes				= $arrayparams['Module_AdditionalTaxes'];
	$Module_PriceOffer					= $arrayparams['Module_PriceOffer'];
	$DecimalBase						= $arrayparams['DecimalBase'];
	$base1								= $arrayparams['base1'];
	$base2								= $arrayparams['base2'];
	$Setup_VatPercentage				= $arrayparams['Setup_VatPercentage'];
	$TaxableLabel						= $arrayparams['TaxableLabel'];
	$DiscountLabel						= $arrayparams['DiscountLabel'];
	$CashReg_RoundDivisor				= $arrayparams['CashReg_RoundDivisor'];
	$CashRegisterTTC					= $arrayparams['CashRegisterTTC'];
	$txtCurr							= $arrayparams['txtCurr'];
	$txtTotalAmountActual				= $arrayparams['txtTotalAmountActual'];
	$CashRegister_ShowTaxNonTax			= $arrayparams['CashRegister_ShowTaxNonTax'];
	$cashregister_service				= $arrayparams['cashregister_service'];
	$cashregister_servicePercentage		= $arrayparams['cashregister_servicePercentage'];
	$cashregister_TaxConsumption		= $arrayparams['cashregister_TaxConsumption'];
	$cashregister_TaxConsumptionpPer	= $arrayparams['cashregister_TaxConsumptionpPer'];
	$cashregister_ShowTaxConschkbox		= $arrayparams['cashregister_ShowTaxConschkbox'];
	$txtSaleStatus						= $arrayparams['txtSaleStatus'];
	$module_CashRegisterBase2			= $arrayparams['CashRegisterBase2'];
	$show_totalQty						= $arrayparams['show_totalQty'];
	
	$serviceChecked = 1;
	if($taxConsumptionChk == '') $taxConsumptionChk = 0;
	if($txtSaleStatus == 'dinein') $taxConsumptionChk = 1;
	if($txtSaleStatus == 'takeout' ||$txtSaleStatus == 'delivery' ) $taxConsumptionChk = 1;
	if($cashregister_ShowTaxConschkbox == 0)  $taxConsumptionChk = 1;
	
	if($PRetailId!=''){
		// Read From Temp Tables For Selected Record				 
		$query = " Select Retail.Sale_ID, Sale_Reference, Date_Format(Retail.Sale_Date,'%d/%m/%Y') As Sale_Date, ".
				 " Retail.Currency_code, Retail.Client_code As ClientCode, CashRegister_Name, Sale_Remark, Retail.Project_Code, Retail.Costcenter_code,  ".
				 " Round(ifNull(Sale_Taxable,0), ".$DecimalBase."), Round(ifNull(Sale_NoneTaxable,0), ".$DecimalBase."), ".
				 " Round(ifNull(Sale_Taxable,0) + ifNull(Sale_NoneTaxable,0), ".$DecimalBase.") As GrossTotal, ".
				 " Round(ifNull(Sale_DiscountPer,0), ".$DecimalBase."), Round(ifNull(Sale_DiscountAmount,0), ".$DecimalBase."),  ".
				 " Round(ifNull(Sale_VAT,0), ".$DecimalBase.") As Sale_VAT, ".
				 " Round((ifNull(Sale_Taxable,0) + ifNull(Sale_NoneTaxable,0) + IfNull(Sale_VAT,0) - IfNull(Sale_DiscountAmount,0) + (ifNull(Sale_Tax1,0) + ifNull(Sale_Tax2,0) + ifNull(Sale_Tax3,0) + ifNull(Sale_Tax4,0) + ifNull(Sale_Tax5,0))), ".$DecimalBase.") As Sale_NetTotal,  ".
				 " Round((ifNull(Sale_Tax1,0) + ifNull(Sale_Tax2,0) + ifNull(Sale_Tax3,0) + ifNull(Sale_Tax4,0) + ifNull(Sale_Tax5,0)), ".$DecimalBase.") As TotalTaxes,  ".
				 " Round(ifNull(Sale_NetTotal,0), ".$DecimalBase."),  ".
				 " Round(ifNull(Sale_NetTotalBase1,0) - (ifNull(Coupon_AmountBase1,0) + ifNull(Sales_CreditAmountBase1,0) + ifNull(Sale_CashBase1,0) + ifNull(Sales_CashInBase1,0) + ".
				 "       ifNull(convertcurfunc('".$base2."', '".$base1."', Retail.Sale_Date, 0, 0, '', '', ifNull(Sales_CashInBase2,0)),0)) + ifNull(Sales_CashOutBase1,0) + ".
				 "       ifNull(convertcurfunc('".$base2."', '".$base1."', Retail.Sale_Date, 0, 0, '', '', ifNull(Sales_CashOutBase2,0)),0)) As BalanceAmount,  ".
				 " Round((ifNull(Sale_Taxable,0)*(1+$Setup_VatPercentage/100)), ".$DecimalBase.") As SaleTaxableTTC, ".
				 " Round((ifNull(Sale_Taxable,0)*(1+$Setup_VatPercentage/100)) + ifNull(Sale_NoneTaxable,0), ".$DecimalBase.") As GrossTotalTTC, ".
				 " Round((((ifNull(Sale_Taxable,0)*(1+$Setup_VatPercentage/100)) + ifNull(Sale_NoneTaxable,0))*(ifNull(Sale_DiscountPer,0)/100)), ".$DecimalBase.") As SaleDiscountTTC, ".
				 " Retail.SaleOrder_Id, Retail.SaleOrder_Reference, Round(ifNull(Sale_NetTotalBase2,0), ".$DecimalBase.") as Sale_NetTotalBase2, ".
				 " round(ifnull(sale_service,0),".$DecimalBase.") as sale_service, round(ifnull(sale_TaxConsumption,0),".$DecimalBase.") as sale_TaxConsumption, ifnull(sale_serviceChecked,0) as serviceChecked, ".
				 " ifnull(sale_TaxConsumptionChecked,0) as taxConsumptionChk , ifnull(sum( SaleDt_Quantity ),0) as SaleTotQty ".
				 " From Temp_Retail As Retail ".
				 " LEFT JOIN temp_retaildt ON Retail.sale_id = temp_retaildt.sale_id ".
				 " Where Retail.Sale_ID = ".$PRetailId  . 
				 " GROUP BY Retail.sale_id";
				 //" And Logged_Code = '".$HTTP_SESSION_VARS['useraccount']."' ";
				 
		// echo $query;
		$result=mysql_query($query,$connection) or die(mysql_error());
		$rows=mysql_fetch_array($result);
		
			if ($CashRegisterTTC == 1) {
				$txtTaxable     = number_format($rows[19],$DecimalBase);
				$txtGrossTotal  = number_format($rows[20],$DecimalBase);
				$txtDiscountAmt = number_format($rows[21],$DecimalBase);
			} else {
				$txtTaxable     = number_format($rows[9],$DecimalBase);
				$txtGrossTotal  = number_format($rows[11],$DecimalBase);
				$txtDiscountAmt = number_format($rows[13],$DecimalBase);
			}
		
		$txtNoneTaxable 	= number_format($rows[10],$DecimalBase);
		$txtDiscount   	 	= number_format($rows[12],$DecimalBase);
		$txtVat         	= number_format($rows[14],$DecimalBase);
		$txtTotalTaxes  	= number_format($rows[16],$DecimalBase);
		$txtNetTotal    	= number_format($rows[17],$DecimalBase);
		$NetTotalDisplayB1 	= RoundTotal($rows[17],$CashReg_RoundDivisor, $connection);
		$NetTotalDisplayB2 	= ConvertCurrency($rows[3], $base2, insertMySQLDate($rows[2]), $NetTotalDisplayB1, $connection);
		
		$txtService       	= number_format($rows[25],$DecimalBase);
		$txtTaxConsumption 	= number_format($rows[26],$DecimalBase);
		
		$serviceChecked			= $rows[27];
		$taxConsumptionChk		= $rows[28];
		$SaleTotQty				= $rows[29];
		
		if($discount_amount>0){
			if ($CashRegisterTTC == 1)
				$query="update temp_retail set Sale_DiscountAmount = ".$rows[21]." where Sale_ID = ".$PRetailId;
				else
				$query="update temp_retail set Sale_DiscountAmount = ".$rows[13]." where Sale_ID = ".$PRetailId;
				
			//echo $query;
			$result=mysql_query($query,$connection) or die(mysql_error());
			}
	}
	
		$sub_query = " Select Sum((ifNull(SaleDt_Quantity,0)* ifNull(RetailDt.SaleDt_ActualPrice, 0))*(1 - ifNull(SaleDt_DiscountPer,0)/100)) As TotalAmountActual ".
					 " From Temp_RetailDt As RetailDt ".
					 " Where RetailDt.Sale_ID = '".$PRetailId."' ".
					 " And IfNull(RetailDt.SaleDt_ItemStatus,0) Not In (2,3) ";
					 //" And ifNull(Price_Offer,0) = 1 ";
		$sub_result = selectData($connection, $sub_query);
		$txtTotalAmountActual = number_format($sub_result[0],$DecimalBase);
		
	//id='total-topBig'
	//id='total-content-Big' 
	//id='total-bottom-Big' 
	echo"<table cellspacing=0 cellpadding=0 border='0' >
		<tr height='12px'><td ></td></tr>
		<tr><td style='width:200px;height:12px;' valign='top'>
			<table border='0' style='table-layout:fixed;z-index:999999;' cellspacing=0 cellpadding=0>
			<col width=90>
			<col width=35>
			<col width=70>";
			
			if ($CashRegister_ShowTaxNonTax == 1) {
				echo"<tr  height='10'>
						<td valign='center' align='right' ><span class='style17'>$TaxableLabel </span></td> 
						<td align='right' colspan='2'><span class='style17'>$txtTaxable</span>
							<input type='hidden' name='txtTaxable' value='$txtTaxable' maxlength='20' readonly style='text-align:right; color:#5151FF; font-weight: bold; width:146px; height=18px;'>
						</td>
					</tr>
					<tr  height='10'>
						<td valign='center' align='right' ><span class='style17'>None Taxable</span></td> 
						<td align='right' colspan='2'><span class='style17'>$txtNoneTaxable</span>
							<input type='hidden' name='txtNoneTaxable' value='$txtNoneTaxable' maxlength='20' readonly style='text-align:right; color:#5151FF; font-weight: bold; width:146px; height=18px;'>
						</td>
					</tr>";
			} else {
				echo"<input type='hidden' name='txtTaxable' value='$txtTaxable' >";
				echo"<input type='hidden' name='txtNoneTaxable' value='$txtNoneTaxable' >";
			}
			
			
	echo"	<tr  height='10'>
				<td valign='center' align='right' ><span class='style17'>Gross Total</span></td> 
				<td align='right' colspan='2'><span class='style17'>$txtGrossTotal </span>
					<input type='hidden' name='txtGrossTotal' value='$txtGrossTotal' maxlength='20' readonly style='text-align:right; color:#5151FF; font-weight: bold; width:146px; height=18px;'>
				</td>
			</tr>
			<tr  height='10'>
				<td valign='center' align='right' ><span class='style18'>$DiscountLabel</span></td> 
				<td align='right'><span class='style18'>$txtDiscount%</span>
					<input type='hidden' name='txtDiscount' value='$txtDiscount' maxlength='5'  style='text-align:right; color:#FF0000; font-weight: bold; width:45px; height=18px;'  readonly >
				</td>
				<td align='right'><span class='style18'>$txtDiscountAmt</span>
					<input type='hidden' name='txtDiscountAmt' value='$txtDiscountAmt' maxlength='20' style='text-align:right; color:#FF0000; font-weight: bold; width:85px; height=18px;'  readonly >
				</td>
			</tr>
			<tr  height='10'>
				<td valign='center' align='right' ><span class='style17'>VAT $Setup_VatPercentage%</span></td> 
				<td align='right' colspan='2'><span class='style17'>$txtVat</span>
					<input type='hidden' name='txtVat' value='$txtVat' maxlength='20' style='text-align:right; color:#5151FF; font-weight: bold; width:146px; height=18px;' readonly >
				</td>
			</tr>";
			if ($cashregister_service == 1)
				echo "<tr  height='10'>
				<td valign='center' align='right' ><span class='style17'><input type='checkbox' name='serviceChecked' id='serviceChecked' value='$serviceChecked' ".($serviceChecked==1?'checked':'')." 
					onclick=\"setService();\" style='width: 10px;'>
				Service $cashregister_servicePercentage%</span></td> 
				<td align='right' colspan='2'><span class='style17'>$txtService</span>
					<input type='hidden' name='txtService' value='$txtService' maxlength='20' style='text-align:right; color:#5151FF; font-weight: bold; width:146px; height=18px;' readonly >
				</td>
			</tr>";
			else echo "<input type='hidden' name='txtService' value='0' maxlength='20'><input type='hidden' name='serviceChecked' id='serviceChecked' value='0'>";
			if ($cashregister_TaxConsumption == 1){
				echo "<tr  height='10'>
						<td valign='center' align='right' ><span class='style17'>";
				if($cashregister_ShowTaxConschkbox == 1) echo "<input type='checkbox' name='taxConsumptionChk' id='taxConsumptionChk' value='$taxConsumptionChk' ".($taxConsumptionChk==1?'checked':'')."  
					onclick=\"setTaxConsumption();\" style='width: 10px;'>";	
				else 	echo "<input type='hidden' name='taxConsumptionChk' id='taxConsumptionChk' value='$taxConsumptionChk'>";	
				echo "	Tax $cashregister_TaxConsumptionpPer%</span></td> 
						<td align='right' colspan='2'><span class='style17'>$txtTaxConsumption</span>
							<input type='hidden' name='txtTaxConsumption' value='$txtTaxConsumption' maxlength='20' style='text-align:right; color:#5151FF; font-weight: bold; width:146px; height=18px;' readonly >
						</td>
					</tr>";	
				
			} 
			else echo "<input type='hidden' name='txtTaxConsumption' value='0' maxlength='20'><input type='hidden' name='taxConsumptionChk' id='taxConsumptionChk' value='$taxConsumptionChk'>";
				
			if ($Module_AdditionalTaxes == 1) {
				echo"<tr  height='10'>
					   <td valign='center' align='right' ><span class='style17'>Taxes</span></td> 
					   <td align='right' colspan='2'><span class='style17'>$txtTotalTaxes</span>
						  <input type='hidden' name='txtTotalTaxes' value='$txtTotalTaxes' maxlength='20' readonly style='text-align:right; color:#5151FF; font-weight: bold; width:146px; height=18px;'></td>
					 </tr>";
			} else {
				echo "<tr  height='10'><Td><input type='hidden' name='txtTotalTaxes' value='$txtTotalTaxes'></td></tr>";
			}		  

		echo"<tr  height='10'>
				<td valign='center' align='right' ><span class='style19'>Net Total $txtCurr</span></td> 
				<td align='right' colspan='2'><span class='style19'>$txtNetTotal</span>
					<input type='hidden' name='txtNetTotal' value='$txtNetTotal' maxlength='20' readonly style='text-align:right; color:#008000; font-weight: bold; width:146px; height=18px;'>
				</td>
			</tr>";
		  
		if ($Module_PriceOffer > 0) {
			echo"<tr  height='10'>
					<td valign='center' align='right' ><span class='style19'>Total (O) $txtCurr</span></td> 
					<td align='right' colspan='2'><span class='style19'>$txtTotalAmountActual</span></td>
				</tr>";
		}
		else {
			echo" <tr  height='10'>
					 <td valign='center' align='right' ><span class='style19'></span></td> 
					 <td align='right' colspan='2'><span class='style19'></span></td>
				  </tr>";
		}
		
		
			
		echo"<tr height='10'>
				<td align='center' colspan='3'><span class='style39'>". number_format($NetTotalDisplayB1, $DecimalBase1) ." $txtCurr</span></td>
			</tr>";
		// change here
		if($module_CashRegisterBase2 == 1){
			echo"<tr height='10'>
					<td align='center' colspan='3'><span class='style38'>". number_format($NetTotalDisplayB2, $DecimalBase) ." $base2 </span></td>
				</tr>";
		}
		if($show_totalQty == 1){
			echo"<tr height='10'>
					<td align='center' colspan='3'><span class='style38'> Total Qty. ". number_format($SaleTotQty, $DecimalBase) ." </span></td>
				</tr>";
		}
		 
	echo"	</table></td>";
	echo"</tr>
		
		</table>";
}

Function CalculateMasterAmountRetail($SRetId,$Setup_VatStartDate,$Module_AdditionalTaxes,$rate_dt,$rate_dt1,$rate_dt2,$connection){
		
		
		$vRetQty = 0;		$vRetDtTotal = 0;		$vItemVat = 0;		$vRetTaxable = 0;		$vRetNoneTaxable = 0;		$vRetGrossTotal = 0;
		$vRetDiscountAmt = 0;		$vRetVat = 0;		$vRetVatBase1 = 0;		$vRetVatBase2 = 0;
		
		$vRetDtDiscAmt       = 0;		$vRetDtDiscAmtBase1  = 0;		$vRetDtDiscAmtBase2  = 0;		$vRetDtActualPrice   = 0;
	
		$vRetTax1 = 0;		$vRetTax2 = 0;		$vRetTax3 = 0;		$vRetTax4 = 0;		$vRetTax5 = 0;		$vRetTax1B1 = 0;		$vRetTax2B1 = 0;
		$vRetTax3B1 = 0;		$vRetTax4B1 = 0;		$vRetTax5B1 = 0;		$vRetTax1B2 = 0;		$vRetTax2B2 = 0;		$vRetTax3B2 = 0;
		$vRetTax4B2 = 0;		$vRetTax5B2 = 0;
		

				$vRetDiscountAmt = 0;
				$vRetTotal = 0;
				$vRetDtTotal = 0;
					
				//Distribute The Total Discount On Detail Table
				$sub_query1 = " Select ifNull(Sale_DiscountAmount,0) As Sale_DiscountAmount , Date_Format(Sale_Date,'%Y%m%d') As Sale_Date".
							  " From Temp_Retail ".
							  " Where Sale_ID = '".$SRetId."' ";
				$sub_result1 = selectData($connection, $sub_query1);
				$vRetDiscountAmt = $sub_result1[0];	
				$txtDate = $sub_result1[1];	
					
				if ($vRetDiscountAmt > 0) {
						
					$sub_query2 = " Select Sum((ifNull(SaleDt_Quantity,0)*ifNull(SaleDt_Price,0))-((ifNull(SaleDt_Quantity,0)*ifNull(SaleDt_Price,0)*ifNull(SaleDt_DiscountPer,0))/100)) As Total ".
								  " From Temp_RetailDt ".
								  " Where Sale_ID = '".$SRetId."' ".
								  " And ifNull(Price_offer,0) = 0 ".
								  " And IfNull(SaleDt_ItemStatus,0) Not In (2,3) ";
					$sub_result2 = selectData($connection, $sub_query2);
					$vRetTotal   = $sub_result2[0];	
							
					$sub_query3 = " Select SaleDt_ID,  ".
								  " ((ifNull(SaleDt_Quantity,0)*ifNull(SaleDt_Price,0))-((ifNull(SaleDt_Quantity,0)*ifNull(SaleDt_Price,0)*ifNull(SaleDt_DiscountPer,0))/100)) As Total ".
								  " From Temp_RetailDt As RetailDt  ".
								  " Where RetailDt.Sale_ID = '".$SRetId."' ".
								  " And ifNull(Price_offer,0) = 0 ".
								  " And IfNull(RetailDt.SaleDt_ItemStatus,0) Not In (2,3) ";
									   
					//echo $sub_query3; 
					$sub_result3=mysql_query($sub_query3,$connection) or die(mysql_error());
					while($sub_rows3=mysql_fetch_array($sub_result3)){
							
						$vRetDtId      = $sub_rows3[0];
						$vRetDtTotal   = $sub_rows3[1];
								
								
						$vRetDtDiscAmt	    = 0;
						$vRetDtDiscAmt 	    = ($vRetDtTotal/$vRetTotal)*$vRetDiscountAmt;
						$vRetDtDiscAmtBase1 = ($vRetDtDiscAmt*$rate_dt)/$rate_dt1;
						$vRetDtDiscAmtBase2 = ($vRetDtDiscAmt*$rate_dt)/$rate_dt2;
								
						
						$sub_query4 =  " UPDATE temp_retaildt SET ".
									   " SaleDt_DiscountAmount = $vRetDtDiscAmt, SaleDt_DiscountBase1 = $vRetDtDiscAmtBase1, SaleDt_DiscountBase2 = $vRetDtDiscAmtBase2  ".
									   " Where SaleDt_ID = '".$vRetDtId."' ";
											   
											 
						//echo $sub_query4; exit;
						if (!updateData($connection, $sub_query4, true))
							$error  = mysql_error(); 
								

					}
				}
			
				$query = " Select Item_Code, ((ifNull(SaleDt_Quantity,0)*ifNull(SaleDt_Price,0))-((ifNull(SaleDt_Quantity,0)*ifNull(SaleDt_Price,0)*ifNull(SaleDt_DiscountPer,0))/100)) As Total, ifNull(Item_Vat,0),  ".
						 " SaleDt_Quantity, ifNull(SaleDt_DiscountAmount,0), ifNull(Item_Tax1,0), ifNull(Item_Tax2,0), ifNull(Item_Tax3,0), ifNull(Item_Tax4,0), ifNull(Item_Tax5,0) ".
						 " From Temp_RetailDt ".
						 " Where Sale_ID = ".$SRetId.
						 " And IfNull(SaleDt_ItemStatus,0) Not In (2,3) ";
						 //" And Logged_Code = '".$_SESSION['useraccount']."' ";	
										 
				//echo $query;
				$result=mysql_query($query,$connection) or die(mysql_error());
				while($rows=mysql_fetch_array($result)){

					$vRetDtTotal  = $rows[1];
					$vItemVat     = $rows[2];
					$vRetQty      = $vRetQty + $rows[3];
						
					$tax_flag = 0;
					$notax_flag = 1;
					if ($vItemVat > 0){
						$tax_flag = 1;
						$notax_flag = 0;
					}	
						
							
					$vRetTaxable     = $vRetTaxable     + ($vRetDtTotal*$tax_flag);
					$vRetNoneTaxable = $vRetNoneTaxable + ($vRetDtTotal*$notax_flag);
						
						
					// Calculation of Vat Amount
					
					
					
					if (($txtDate > $Setup_VatStartDate && $vItemVat > 0) || ($Module_AdditionalTaxes == 1))
						$vRetVat = $vRetVat + (($vRetDtTotal - $rows[4])*$vItemVat/100);
						
					if ($Module_AdditionalTaxes == 1) {
						if ($vItemVat > 0 && $rows[5] != 0)
							$vRetTax1 = $vRetTax1 + (($vRetDtTotal - $rows[4])*$rows[5]/100);
						if ($vItemVat > 0 && $rows[6] != 0)
							$vRetTax2 = $vRetTax2 + (($vRetDtTotal - $rows[4])*$rows[6]/100);
						if ($vItemVat > 0 && $rows[7] != 0)
							$vRetTax3 = $vRetTax3 + (($vRetDtTotal - $rows[4])*$rows[7]/100);
						if ($vItemVat > 0 && $rows[8] != 0)
							$vRetTax4 = $vRetTax4 + (($vRetDtTotal - $rows[4])*$rows[8]/100);
						if ($vItemVat > 0 && $rows[9] != 0)
							$vRetTax5 = $vRetTax5 + (($vRetDtTotal - $rows[4])*$rows[9]/100);	
					}
						
				}			
					
					
				$vRetGrossTotal = $vRetTaxable + $vRetNoneTaxable;
				if (empty($vRetDiscountAmt)) $vRetDiscountAmt = 0;
				$vRetDiscountPer      = ($vRetDiscountAmt/$vRetGrossTotal)*100;   
	
				// ****** ADDING  charge and tax consumption
				
				//Read From CashRegister Table
				$queryCashRegister=" Select Upper(CashRegister_Name) As CashRegister_Name, Currency_Code As StpCurrCode, CostCenter_Code As StpCostCentCode, Project_Code As StpProjectCode, ".
                   " ifNull(CashRegister_SerialNo,0) As CashRegisterSerialNo, CashRegister_Discount, CashRegisterTTC, Client_Account As StpClientAccount, Warehouse_Code As StpWarehouseCode, ".
				   " ifNull(CashRegister_AutoPost,0) As CashRegister_AutoPost, ifNull(CashRegister_RestSerialNo,0) As CashRegister_RestSerialNo, ".
				   " ifNull(CashRegister_DisplayLed,0) As CashRegister_DisplayLed, ifNull(CashRegister_DispCOM,0) As CashRegister_DispCOM, ".
				   " ifNull(CashRegister_LedDescLength,0) As CashRegister_LedDescLength ,ifNull(Module_CashRegAutoItemsList,0) As Module_CashRegAutoItemsList,ifNull(cashregister_DPbeforePosting,0) as cashregister_DPbeforePosting, ".
				   " ifNull(Module_RestaurantDelivery,0) As Module_RestaurantDelivery, ifnull(cashregister_service,0) as cashregister_service, ifnull(cashregister_servicePercentage, 0) as cashregister_servicePercentage, ".
				   " ifnull(cashregister_TaxConsumption,0) as cashregister_TaxConsumption, ifnull(cashregister_TaxConsumptionpPer,0) as cashregister_TaxConsumptionpPer, ifnull(cashregister_ShowTaxConsumptionchkbox,0) as cashregister_ShowTaxConschkbox, ".
				   " RedeemPoints_Account ".
				   " From CashRegister ".
				   " Where CashRegister_Name = '".$_SESSION['cashregister']."' ";
					$resultCashRegister=mysql_query($queryCashRegister,$connection) or die(mysql_error());
					while($rowCashRegister=mysql_fetch_array($resultCashRegister)){
						extract($rowCashRegister);
					}

				
				
				
				$queryChk = "select ifnull(sale_serviceChecked,0), ifnull(sale_TaxConsumptionChecked,0) from temp_retail where Sale_ID = $SRetId "; 
				$resChk = mysql_query($queryChk, $connection);
				$rowChk = mysql_fetch_row($resChk);
				$serviceChecked = $rowChk[0];
				$taxConsumptionChk = $rowChk[1];		
							
				if ($cashregister_service == 1 && $serviceChecked == 1){
					$vRetService = ((($vRetGrossTotal)-$vRetDiscountAmt)*$cashregister_servicePercentage/100);
					$vRetServiceBase1 = (((($vRetGrossTotal)-$vRetDiscountAmt)*$cashregister_servicePercentage/100)*$rate_dt)/$rate_dt1;
					$vRetServiceBase2 = (((($vRetGrossTotal)-$vRetDiscountAmt)*$cashregister_servicePercentage/100)*$rate_dt)/$rate_dt2;
				} 
				if ($cashregister_TaxConsumption == 1 && $taxConsumptionChk == 1){
					//fady stop vat
					//$vRetTaxConsp = ((($vRetGrossTotal+$vRetVatAmt)-$vRetDiscountAmt)*$cashregister_TaxConsumptionpPer/100);
					$vRetTaxConsp = ((($vRetGrossTotal)-$vRetDiscountAmt)*$cashregister_TaxConsumptionpPer/100);
					$vRetTaxConspBase1 = (((($vRetGrossTotal)-$vRetDiscountAmt)*$cashregister_TaxConsumptionpPer/100)*$rate_dt)/$rate_dt1;
					$vRetTaxConspBase2 = (((($vRetGrossTotal)-$vRetDiscountAmt)*$cashregister_TaxConsumptionpPer/100)*$rate_dt)/$rate_dt2;
				}
				
				
				if($vRetService == '' )$vRetService = 0 ;
				if($vRetServiceBase1 == '' )$vRetServiceBase1 = 0 ;
				if($vRetServiceBase2 == '' )$vRetServiceBase2 = 0 ;
				
				if($vRetTaxConsp == '') $vRetTaxConsp = 0 ;
				if($vRetTaxConspBase1 == '') $vRetTaxConspBase1 = 0 ;
				if($vRetTaxConspBase2 == '') $vRetTaxConspBase2 = 0 ;
				// ****** ADDING  charge and tax consumption
				
				
				
					
				//$vRetNetTotal         = $vRetGrossTotal + $vRetVat - $vRetDiscountAmt + $vRetTax1 + $vRetTax2 + $vRetTax3 + $vRetTax4 + $vRetTax5;
				$vRetNetTotal         = $vRetGrossTotal + $vRetVat + $vRetService + $vRetTaxConsp-$vRetDiscountAmt  + $vRetTax1 + $vRetTax2 + $vRetTax3 + $vRetTax4 + $vRetTax5;			
				$vRetNetTotalBase1    = ($vRetNetTotal*$rate_dt)/$rate_dt1;
				$vRetNetTotalBase2    = ($vRetNetTotal*$rate_dt)/$rate_dt2;
				$vRetTaxableBase1     = ($vRetTaxable*$rate_dt)/$rate_dt1;
				$vRetTaxableBase2     = ($vRetTaxable*$rate_dt)/$rate_dt2;
				$vRetNoneTaxableBase1 = ($vRetNoneTaxable*$rate_dt)/$rate_dt1;
				$vRetNoneTaxableBase2 = ($vRetNoneTaxable*$rate_dt)/$rate_dt2;
				$vRetDiscountAmtBase1 = ($vRetDiscountAmt*$rate_dt)/$rate_dt1;
				$vRetDiscountAmtBase2 = ($vRetDiscountAmt*$rate_dt)/$rate_dt2;
				$vRetGrossTotalBase1  = ($vRetGrossTotal*$rate_dt)/$rate_dt1;
				$vRetGrossTotalBase2  = ($vRetGrossTotal*$rate_dt)/$rate_dt2;
				$vRetVatBase1         = ($vRetVat*$rate_dt)/$rate_dt1;
				$vRetVatBase2         = ($vRetVat*$rate_dt)/$rate_dt2;
				

				$vRetTax1B1  = ($vRetTax1*$rate_dt)/$rate_dt1;
				$vRetTax1B2  = ($vRetTax1*$rate_dt)/$rate_dt2;		
				$vRetTax2B1  = ($vRetTax2*$rate_dt)/$rate_dt1;
				$vRetTax2B2  = ($vRetTax2*$rate_dt)/$rate_dt2;		
				$vRetTax3B1  = ($vRetTax3*$rate_dt)/$rate_dt1;
				$vRetTax3B2  = ($vRetTax3*$rate_dt)/$rate_dt2;		
				$vRetTax4B1  = ($vRetTax4*$rate_dt)/$rate_dt1;
				$vRetTax4B2  = ($vRetTax4*$rate_dt)/$rate_dt2;		
				$vRetTax5B1  = ($vRetTax5*$rate_dt)/$rate_dt1;
				$vRetTax5B2  = ($vRetTax5*$rate_dt)/$rate_dt2;	
					
					 
				fbegin();			 
				$query = " UPDATE temp_retail SET ".
						 " Sale_Taxable = $vRetTaxable, Sale_TaxableBase1 = $vRetTaxableBase1, Sale_TaxableBase2 = $vRetTaxableBase2, ".
						 " Sale_NoneTaxable = $vRetNoneTaxable, Sale_NoneTaxableBase1 = $vRetNoneTaxableBase1, Sale_NoneTaxableBase2 = $vRetNoneTaxableBase2, ".
						 " Sale_DiscountPer = $vRetDiscountPer, Sale_DiscountAmount = $vRetDiscountAmt, Sale_DiscountBase1 = $vRetDiscountAmtBase1, Sale_DiscountBase2 = $vRetDiscountAmtBase2, ".
						 " Sale_VAT = $vRetVat, Sale_VATBase1 = $vRetVatBase1, Sale_VATBase2 = $vRetVatBase2, ".
						 " Sale_Total = $vRetGrossTotal, Sale_TotalBase1 = $vRetGrossTotalBase1, Sale_TotalBase2 = $vRetGrossTotalBase2, ".
						 " Sale_NetTotal = $vRetNetTotal, Sale_NetTotalBase1 = $vRetNetTotalBase1, Sale_NetTotalBase2 = $vRetNetTotalBase2, ".
						 " Sale_Tax1 = $vRetTax1, Sale_Tax1Base1 = $vRetTax1B1, Sale_Tax1Base2 = $vRetTax1B2,  ".
						 " Sale_Tax2 = $vRetTax2, Sale_Tax2Base1 = $vRetTax2B1, Sale_Tax2Base2 = $vRetTax2B2,  ".
						 " Sale_Tax3 = $vRetTax3, Sale_Tax3Base1 = $vRetTax3B1, Sale_Tax3Base2 = $vRetTax3B2,  ".
						 " Sale_Tax4 = $vRetTax4, Sale_Tax4Base1 = $vRetTax4B1, Sale_Tax4Base2 = $vRetTax4B2,  ".
						 " Sale_Tax5 = $vRetTax5, Sale_Tax5Base1 = $vRetTax5B1, Sale_Tax5Base2 = $vRetTax5B2,  ".
						 " sale_service = $vRetService, sale_serviceB1 = $vRetServiceBase1, sale_serviceB2 = $vRetServiceBase2, sale_serviceChecked = $serviceChecked, ".
				         " sale_TaxConsumption = $vRetTaxConsp, sale_TaxConsumptionB1 = $vRetTaxConspBase1, sale_TaxConsumptionB2 = $vRetTaxConspBase2, ".
				         " sale_TaxConsumptionChecked = $taxConsumptionChk ".
						 
						  
						 " WHERE Sale_ID = ".$SRetId;
						 //" And Logged_Code = '".$_SESSION['useraccount']."' ";
						 
				 
				$result=mysql_query($query,$connection);
				//echo $query."<br>";exit;
				
				if ( $result ){ 
					
					fcommit();
				} else
				{
				   $message  = mysql_error(); 
				   frollback();
				} 
		 




}


?>