<?php

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

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

if($_SESSION['cashregister']==""){
header("location:Form_Retail_CashUsers.php");
}

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

$querylog=" select ifNull(FC_CashRegisterTools,0) As FC_CashRegisterTools  ".
		  " from ".$_SESSION['dbLabel'].".listuserdir 
		  where Usercode='".$_SESSION['useraccount']."' and Upper(concat(CompanyName,'_',Diryear)) = Upper('".$_SESSION['dbName']."')  "; 
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

$querylog="SELECT FC_CashRegister as loginaccess,FC_CashRegisterCustomer as FC_CashRegisterCustomer 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);
}
if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");


//If User has no access to add discount then password form will open
if ($FC_CashRegisterTools == 0 && $PassDisc == 0 && $actionmode == '')
	header("location:Form_RetailTools_Passwords.php?PForm=1&mainaction=".$mainaction."&actionmode=&RetId=".$RetId);
print <<<HERE
<head>

<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" language="javascript"> 

function SelectTable(vRetid){
x = document.split;
x.action = 'Form_Split.php?RetId='+vRetid;
x.submit();
}


function changecolor(vobj){
x = document.split.selecteddt;
if(x.value=='')
	x.value = '[-1]'
if(vobj.style.backgroundColor=='#FFFFFF' || vobj.style.backgroundColor==''  || vobj.style.backgroundColor=='rgb(255, 255, 255)' ) {
	vobj.style.backgroundColor='#B8EDFF';
	x.value = x.value + ',[' + vobj.id + ']';
	}
else	{
			vobj.style.backgroundColor='#FFFFFF';
			x.value = x.value.replace(',[' + vobj.id + ']','');
		}	




}

function combine(vtoretid,projectdtid,toprojectdtid){
	x = document.split;
	var vRetId = x.txtId.value;
	
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}

	else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){{ 
			document.getElementById('ordergrid').innerHTML=xmlhttp.responseText;
			window.opener.location.reload();
			window.location.reload();
		}

		}
	}
	
	xmlhttp.open("GET","Form_Split_Actions.php?toprojectdtid="+toprojectdtid+"&SRetId="+vRetId+"&SToRetId="+vtoretid+"&projectdtid="+projectdtid+"&mode=combineorder",true);
	xmlhttp.send();

}

function combineorder(){

	x = document.split;
	var vRetId = x.txtId.value;
	
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}

	else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){{ 
			document.getElementById('ordergrid').innerHTML=xmlhttp.responseText;
		}

		}
	}
	
	xmlhttp.open("GET","Form_Split_Actions.php?SRetId="+vRetId+"&mode=combine",true);
	xmlhttp.send();
	


}


function splitorder(){

	x = document.split;
	var vRetId = x.txtId.value;
	var vselecteddt = x.selecteddt.value;
	
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}

	else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){{ 
			document.getElementById('ordergrid').innerHTML=xmlhttp.responseText;
		}

		}
	}
	
	xmlhttp.open("GET","Form_Split_Actions.php?SRetId="+vRetId+"&mode=split&selecteddt="+vselecteddt,true);
	xmlhttp.send();
	


}



function splitorderdt(vtoretid,projectdtid,toprojectdtid){
	
	x = document.split;
	var vRetId = x.txtId.value;
	var vselecteddt = x.selecteddt.value;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}

	else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){{ 
			document.getElementById('ordergrid').innerHTML=xmlhttp.responseText;
			window.opener.location.reload();
			window.location.reload();
		}

		}
	}

	xmlhttp.open("GET","Form_Split_Actions.php?SRetId="+vRetId+"&SToRetId="+vtoretid+"&projectdtid="+projectdtid+"&toprojectdtid="+toprojectdtid+"&mode=splitorder&selecteddt="+vselecteddt,true);
	xmlhttp.send();

}

</script>

HERE;


if($cashreg_colortheme=='red'){
	echo'<link rel="stylesheet" type="text/css" media="all" href="css-v2/style-red.css">';
	echo'<link rel="stylesheet" type="text/css" href="js/menu-v2/menu-red.css" />';
}	
else if($cashreg_colortheme=='' || $cashreg_colortheme=='default')	{
	echo'<link rel="stylesheet" type="text/css" media="all" href="css-v2/style-default.css">';
	echo'<link rel="stylesheet" type="text/css" href="js/menu-v2/menu-default.css" />';
}

		 
print <<<HERE
<link rel="stylesheet" type="text/css" media="all" href="js/grid/UI_DataGrid_V1.css">



</script>
<title>Cash Register</title>
<style type="text/css">

body,td,th {
	font-family: Arial, Times, sans-serif;
	font-size: 14px;
}
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;
}

.style16 {color: #000000; font-weight: normal; font-size: 14px; font-family: Arial, Times, sans-serif; padding:2px;}
.style17 {color: #FFFFFF; font-weight: bold; font-size: 12px; font-family: Arial, Times, sans-serif; padding:2px;}
.style18 {color: #DE9BA5; font-weight: bold; font-size: 12px; font-family: Arial, Times, sans-serif; padding:2px;}
.style19 {color: #C2DCE4; font-weight: bold; font-size: 12px; font-family: Arial, Times, sans-serif; padding:2px;}
.style20 {color: #FF0000; font-weight: bold; font-size: 13px; font-family: Arial, Times, sans-serif;}
.style21 {color: #FF0000; font-weight: bold; font-size: 14px; font-family: Arial, Times, sans-serif; padding-left:20px; background-color:#81F7D8;}
.style26 {color: #FF0000; font-weight: bold; font-size: 14px;}
.style15 {color: #000000; font-size: 11px; font-family: Arial, Times, sans-serif; padding:2px;}
.style27 {color: #999999 ;font-size: 14px; font-family: Arial, Times, sans-serif;}
.style28 {color: #FFFFFF ;font-size: 11px; font-family: Arial, Times, sans-serif;}
.style39 {color: #C2DCE4; font-weight: bold; font-size: 23px; font-family: Arial, Times, sans-serif; padding:2px;}


.list-containerfast {
	
    /*width: 90px;*/
    /*overflow-x: auto;
    overflow-y: hidden;*/
	/*white-space: nowrap;*/
	border: 0px #D8D8D8 solid;
	overflow-y:scroll;
	overflow-x:hidden;
	background:#ffffff;
	
}

.list-container {
	
    /*width: 90px;*/
    overflow-x: auto;
    overflow-y: hidden;
	/*white-space: nowrap;*/
	border: 1px #D8D8D8 solid;
	height:280px;


	background:#ffffff;
}

.list-item {
	
    width:62px;
	margin-right:0px;
	margin-left:0px;
	margin-top:1px;
	margin-bottom:0px;
	/*display: inline-block;*/
	display: block;
    /* for ie7 */
    /**display: inline;*/
    zoom: 1;
	border:0px solid #000000;

}

h5 { border-left-style: solid; 
	 border-left-color: black; 
	 border-left-width: 1px;
	 margin-left: 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>
<form name='split' method='post' action=''>

<input type='hidden' name='SelectedRec' id='SelectedRec' value='$SelectedRec'>
<input type='hidden' name='SelectedRecColor' id='SelectedRecColor' value='$SelectedRecColor'>
<input type='hidden' name='SelectedDtId' id='SelectedDtId' value='$SelectedDtId'>
<input type='hidden' name='index' id='index' value='$index'>
<input type='hidden' name='selecteddt' id='selecteddt' value='$selecteddt'>
HERE;
    
		
//$querylog="select * from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$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 ".
		  " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}


	
//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ifNull(ShowSlipNumber,0) As ShowSlipNumber, ".
             " Date_Format(Setup_VatStartDate,'%Y%m%d') As Setup_VatStartDate, ifNull(Setup_VatPercentage,0) As Setup_VatPercentage, Company_Name As CompanyName, ".
			 " ifNull(CashReg_DispLedMsg, 'Welcome !') As CashReg_DispLedMsg, ifNull(CashReg_Weight,0) As CashReg_Weight, ifNull(CashReg_RoundDivisor,1) As CashReg_RoundDivisor,ifnull(cashreg_colortheme,'default') as cashreg_colortheme ".
			 " 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_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_SerialNo,0) As Module_SerialNo, ifNull(Module_PriceOffer,0) As Module_PriceOffer ".
			 " From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

//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_BarCode,0) As CashRegisterBarCode, ifNull(CashRegister_SerialNo,0) As CashRegisterSerialNo, ifNull(CashRegister_Discount,0) As CashRegisterDiscount, ".
				   " CashRegisterTTC, Client_Account As StpClientAccount, ifNull(CashRegister_SlipPrinter,0) As CashRegister_SlipPrinter, ".
				   " ifNull(CashRegister_AutoPost,0) As CashRegister_AutoPost, ifNull(CashReg_Vendor,0) As CashReg_Vendor, ".
				   " ifNull(CashRegister_DisplayLed,0) As CashRegister_DisplayLed, ifNull(CashRegister_DispCOM,0) As CashRegister_DispCOM, ".
				   " ifNull(CashRegister_PrintBarcode,0) As CashRegister_PrintBarcode, ifNull(CashReg_ForcingVendor,0) As CashReg_ForcingVendor, ".
				   " ifNull(CashRegister_LedDescLength,0) As CashRegister_LedDescLength, ifNull(CashRegister_Printer,0) As CashRegister_Printer, ".
				   " ifNull(Module_CashRegisterFastItem,0) As Module_CashRegisterFastItem, ifNull(Module_RestaurantDelivery,0) As Module_RestaurantDelivery, ".
				   " ifNull(Module_CashRegisterStandardView,0) As Module_CashRegisterStandardView, ifNull(Module_CashRegisterTable,0) As Module_CashRegisterTable, ".
				   " ifNull(Module_CashRegAutoItemsList,0) As Module_CashRegAutoItemsList  ".
				   " From CashRegister ".
				   " Where CashRegister_Name = '".$_SESSION['cashregister']."' ";
				 //echo$queryCashRegister;
$resultCashRegister=mysql_query($queryCashRegister,$connection) or die(mysql_error());
while($rowCashRegister=mysql_fetch_array($resultCashRegister)){
	extract($rowCashRegister);
}


	
$queryUsers="SELECT User_Account As UserAccount, FullName As UserFullName From ".$_SESSION['dbLabel'].".Users where user_account='".$_SESSION['useraccount']."' 	";
$resultUsers=mysql_query($queryUsers,$connection) or die(mysql_error());
while($rowUsers=mysql_fetch_array($resultUsers)){
	extract($rowUsers);
}

$actionmode = $_POST["actionmode"]; if ($actionmode == ""){$actionmode = $_GET["actionmode"];}   
$mainaction = $_POST["mainaction"]; if ($mainaction == ""){$mainaction = $_GET["mainaction"];}   
$message 	= $_POST["message"]; if ($message == ""){$message = $_GET["message"];}   

// Read From Temp Tables For Selected Record				 
	$query = " Select Sale_ID, Sale_Reference, Date_Format(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."', Sale_Date, 0, 0, '', '', ifNull(Sales_CashInBase2,0)),0)) + ifNull(Sales_CashOutBase1,0) + ".
			 "       ifNull(convertcurfunc('".$base2."', '".$base1."', 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,Retail.Projectdt_id Projectdt_id ".
			 " From Temp_Retail As Retail ".
	         " Where Sale_ID = '".$RetId."'";
			 //" And Logged_Code = '".$_SESSION['useraccount']."' ";
			 
			 
			 
	//echo $query;
	$result=mysql_query($query,$connection) or die(mysql_error());
    $rows=mysql_fetch_array($result);
	
	$txtId    = $rows[0];
	$txtRef   = $rows[1];
	$txtDate  = $rows[2];
	$txtCurr  = $rows[3];
	$txtClientCode   = $rows[4];
	$txtCashRegister = $rows[5];
	$txtRemark       = $rows[6];
	$txtProjectCode  = $rows[7];
	$txtCostCentCode = $rows[8];
	
	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);
	$NetTotalDisplay = RoundTotal($rows[17], $CashReg_RoundDivisor, $connection);
	
	$txtBalanceAmount = $rows[18];
	$txtOrderId       = $rows[22];
	$txtOrderRef      = $rows[23];
	$txtProjectDtId      = $rows[24];
	
	$query = " Select Count(*) FROM Temp_RetailDt ".
			 " WHERE Sale_id = ".$txtId;
	$result = selectData($connection, $query);
	$txtCountDetail = $result[0];
	if($txtCountDetail == '') $txtCountDetail = 0;
	
	
	if ($Module_PriceOffer > 0) {
		$sub_query = " Select Sum(ifNull(SaleDt_Quantity,0)* ifNull(RetailDt.SaleDt_ActualPrice, 0)) As TotalAmountActual ".
					 " From Temp_RetailDt As RetailDt ".
					 " Where RetailDt.Sale_ID = '".$txtId."' ";
					 //" And ifNull(Price_Offer,0) = 1 ";
		$sub_result = selectData($connection, $sub_query);
		$txtTotalAmountActual = number_format($sub_result[0],$DecimalBase);
	
	}
	

echo"<br><table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='1060px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:12px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; width:360px' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Split/Move</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

	  
echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";  	  	  

		 
		 
		 
		 
		 
		 
		 
		 
		 



echo"<table border='0' width=100%>";
echo"	<tr><td valign='top' >";
ShowTableGridSplit($connection,$_SESSION['gret_parameters'],$txtId);



echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type='button' name='butsplit'  class='splitbutton'  id='butsplit'    onclick='splitorder()'  onMouseOver=\"style.cursor='hand'\" >";			
echo "&nbsp;&nbsp;&nbsp;&nbsp;<input type='button'   class='combinebutton' name='butcombine' id='butcombine'   onclick='combineorder()' onMouseOver=\"style.cursor='hand'\" >";			
echo"	</td>";
			
echo"</tr>";

echo"	<tr style='background-color:#016A84'><td valign='top' colspan=2 >
			<table border='0' cellpadding='0' cellspacing='0'  width='875px'  >
			<col width=190px>
			<col width=85px>
			<col width=200px>
			<col width=250px>
			<col width=350px>";
				
										
			echo"<tr height='20px' style='background-color:#016A84'>
					<td align='left' valign='center'  style='padding-left:10px'><span class='style1'>&nbsp;Date&nbsp;<span class='style26'></span></span>";
					 echo"<span class='style3' >&nbsp;&nbsp;&nbsp; $txtDate</span><input type='hidden' size='10' name='txtDate' value='$txtDate' maxlength='10' > 
					</td>
					<td ><span class='style1'>Reference</span></td>
					<td align='left'>
					  <span class='style3'>$txtRef</span>";
					  
					 // if($tablename)
					  
					  if($txtProjectDtId!='' && $Module_CashRegisterTable==1) {
					  
							$subquery = "select projectdt_name from projectdt where projectdt_id = $txtProjectDtId";
							$resultsub=mysql_query($subquery,$connection);
							$rowsub=mysql_fetch_row($resultsub);
					  
						echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='style1'>Table</span>
						<span class='style3'>$rowsub[0]</span>";
						
						
						}
					  
			echo"	</td>";
			echo"	<td rowspan=1 valign='top' align='right'>";

				
			if($Module_CashRegisterStandardView==1 && $Module_CashRegisterFastItem==1){
				$height='190px';
			}
			else if($Module_CashRegisterStandardView==0 && $Module_CashRegisterFastItem==1){
				$height='230px'; 
			}
			else if($Module_CashRegisterStandardView==1 && $Module_CashRegisterFastItem==0){
				$height='190px'; 
			}
			else if($Module_CashRegisterStandardView==0 && $Module_CashRegisterFastItem==0){
				$height='410px'; 
			}


			$Parameters = array();
			$Parameters['Module_PriceOffer'] = $Module_PriceOffer;
			$Parameters['CashRegister_PrintBarcode'] = $CashRegister_PrintBarcode;
			$Parameters['Module_SerialNo'] = $Module_SerialNo;
			$Parameters['DecimalBase'] = $DecimalBase;
			$Parameters['CashRegisterTTC'] = $CashRegisterTTC;
			$Parameters['CashReg_Weight'] = $CashReg_Weight;
			$Parameters['Module_RestaurantDelivery'] = $Module_RestaurantDelivery;

			$Parameters['FC_CashRegisterMod'] = $FC_CashRegisterMod;
			$Parameters['FC_CashRegisterDelItem'] = $FC_CashRegisterDelItem;
			$Parameters['DecimalBase1'] = $DecimalBase1;
			$Parameters['Module_AdditionalTaxes'] = $Module_AdditionalTaxes;
			$Parameters['PriceLabel'] = $PriceLabel;
			$Parameters['TaxableLabel'] = $TaxableLabel;
			$Parameters['DiscountLabel'] = $DiscountLabel;
			$Parameters['base1'] = $base1;
			$Parameters['base2'] = $base2;
			$Parameters['Setup_VatPercentage'] = $Setup_VatPercentage;
			$Parameters['ShowSlipNumber'] = $ShowSlipNumber;
			$Parameters['txtCurr'] = $txtCurr;
			$Parameters['txtOrderId'] = $txtOrderId;
			$Parameters['Unmodify_SellingPrice'] = $Unmodify_SellingPrice;
			$Parameters['passchecked'] = $passchecked;
			$Parameters['height'] = $height;
			$Parameters['CashReg_Vendor'] = $CashReg_Vendor;
			$Parameters['CashReg_RoundDivisor'] = $CashReg_RoundDivisor;
			$Parameters['FC_DiscountPerLimit'] = $FC_DiscountPerLimit;
			$Parameters['CashReg_ForcingVendor'] = $CashReg_ForcingVendor;
			$Parameters['txtTotalAmountActual'] = $txtTotalAmountActual;
			$Parameters['Module_CashRegisterTable'] = $Module_CashRegisterTable;


			$_SESSION['gret_parameters']  = $Parameters;

			

			echo"	<td valign='top'  align='right' rowspan=3>
						
					</td>";
			echo"</tr>";

			if ($CashRegisterSerialNo == 0) $ItemOptionLabel = 'Barcode';
			else $ItemOptionLabel = 'SerialNo';

			$sub_query  = " Select ifNull(Item_ModifySellingPrice,0) From Items ".
						  " Where Item_Code = '".$txtItemBarcode."' or  Item_Barcode = '".$txtItemBarcode."' or ".
						  " Item_Barcode2 = '".$txtItemBarcode."' or Item_Barcode3 = '".$txtItemBarcode."'";
			$sub_result = selectData($connection, $sub_query);

			$ItemModifySellingPrice = $sub_result[0];
				
			// User Has No Access To Modify The Price	
			$ModeModifySellPrice = '';
			if ($Unmodify_SellingPrice == 1 || ($ItemModifySellingPrice == 0 && $txtItemBarcode != ''))	
				$ModeModifySellPrice = ' readonly ';


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




		   echo"   <input type='hidden' name='txtOrderId' value='$txtOrderId' size='10'>
			  <input type='hidden' name='txtOrderRef' value='$txtOrderRef' size='10'>
			  <input type='hidden' name='txtId' value='$txtId' size='10'>
			  <input type='hidden' name='txtRef' value='$txtRef' size='10' >
			  <input type='hidden' name='txtCashRegister' value='$txtCashRegister' >
			  <input type='hidden' name='txtCurr' value='$txtCurr' >
			  <input type='hidden' name='txtClientCode' value='$txtClientCode' >
			  <input type='hidden' name='txtProjectCode' id='txtProjectCode' value='$txtProjectCode' />
			  <input type='hidden' name='txtCostCentCode' id='txtCostCentCode' value='$txtCostCentCode' />
			  <input type='hidden' name='txtBalanceAmount' value='$txtBalanceAmount' >";
		  //</td>	  
   
$PaymentMode  = ' ';
$DiscountMode = '';
$PostingMode  = ' ';

if ($FC_CashRegisterPosting == 0 || $CashRegister_AutoPost == 1 || ($FC_CashRegisterPosting == 1 && $txtId != '')) 
	$PostingMode = ' disabled ';
	
if ($txtId == '') 
	$PaymentMode = ' disabled ';	

if ($CashRegisterDiscount == 0 || ($CashRegisterDiscount == 1 && $txtId == ''))
	$DiscountMode = ' disabled ';

	

echo"   <tr><td valign='top' align='left' colspan='1'>
		<table border='0'  cellspacing=0 cellpadding=0 valign='top' align='left'>
		
		<tr><td valign='top' align='left'>";
		
		
			echo"<div style='height:300;margin-top:3px; float:left;width:500px;' id='datagrid' >";
		
			
		ShowRetailDtGrid_Split($connection,$_SESSION['gret_parameters'],$txtId);		
		echo "</div></td>";
		
		echo"<tD><div style='height:300;margin-top:3px;align:left; float:left;width:250px;' id='ordergrid' >";		
		//ShowOrders($connection,$_SESSION['gret_parameters'],$txtId);		
		echo "</div></td>";
		
echo"</tr>";
echo"</table></td></tr>";
/*
echo"<tr><td>";
	echo"		<div id='totals' style='width:200px; margin-top:3px; margin-left:35px; float:right; position:absolute;' >";
						ShowRetailTotals($connection,$_SESSION['gret_parameters'],$txtId);		
			echo"		</div>";
echo"</td></tr>";
*/
echo"</table>";

		 
 echo "</td><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";			 
	echo"	<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:560px;' valign='top'></td>
		<td id='search-bottom3' style='height:34px; width:31px;' valign='top'></td>";
echo" </tr>";	
echo"</table>";
echo"</body>";
echo"</form>";


function ShowTableGridSplit($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'];
	$FC_ShowAllTables=$arrayparams['FC_ShowAllTables'];


	$filepath = 'Functions_Retail.php';


	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 ,project
				where projectdt.project_id=project.project_id
				and upper(project.project_name) = 'TABLE'
				and temp_retail.sale_id <> ''
				order by Projectdt_id asc
				";
				
	 
	 
				
	$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($rows[7]!='' && $rows[7] == $PRetailId)	//retail table
			echo "<td width='62px' height='47px'><input type='button' id='btnTbl$i' name='btnTbl$i' class='TablebuttonsActive'   onclick=\"SelectTable('$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=\"SelectTable('$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=\"SelectTable($rows[7]);return false;\"  class='Tablebuttons'  value='$rows[1]\n$rowsdt[0]'><span><span></span></span></button></td>";

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

		$i+=1;
	}


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


?>