<?php

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


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

set_time_limit(0);

$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");

	
//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, Base1, Base2, grid_color1, grid_color2, 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 CashRegister Table
$queryCashRegister=" Select Upper(CashRegister_Name) As CashRegister_Name, Currency_Code As StpCurrCode, ifNull(CashRegister_AutoClosePrint,0) as CashRegister_AutoClosePrint ".
				   " From CashRegister ".
				   " Where CashRegister_Name = '".$_SESSION['cashregister']."' ";
$resultCashRegister=mysql_query($queryCashRegister,$connection) or die(mysql_error());
while($rowCashRegister=mysql_fetch_array($resultCashRegister)){
	extract($rowCashRegister);
}


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


if (empty($CashReg)) $CashReg = $_SESSION['cashregister'];


print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
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
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<script type="text/javascript" language="javascript">


function SubmitRecord(PCloseAmount,AutoClosePrint) {
	x = document.form1;
	
	var vCashReg = x.CashReg.value;
	var vTransType = x.TransType.value;
	
	var vMode = 'cashregtrans';
	var vnewshiftopen = document.getElementById("txtnewshiftopen").value;
	if (vCashReg != '') {
		if (vTransType == 'OUT' && AutoClosePrint == 1) PrintSummary(0);
		
		x.action="Form_Retail_Actions.php?mode="+vMode+"&TransType="+vTransType+"&CashReg="+vCashReg+"&CloseAmount="+PCloseAmount+"&txtnewshiftopen="+vnewshiftopen;
		x.submit();
	} else {
		alert('Please choose a cashregister.');
	}
}


function CloseForm() {
	self.close();
}


function roundNumber(num, dec) { // Arguments: number to round, number of decimal places
  var newnumber = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
  newnumber = parseFloat(newnumber); 
  
  return newnumber;
}

function kd(e)
{ 
	x=document.form1;
	if (!e) { var e = window.event;}
    var intKey = (window.Event) ? e.which : e.keyCode;
	
	 
	// Block browser short cuts     
	//F1, F3, F4  key
	if (intKey == 112 || intKey == 114 || intKey == 115 ) {
		if(e.preventDefault) // non-IE browsers         
			e.preventDefault();     
		else  // IE Only  
		{
			e.keyCode=0;  
			e.returnValue = false; 
			
		}	
	}

	
    if (intKey == 113) { //F2 key
		x.btnSubmit.click();
		return false;
	}
	else if (intKey == 27) { //ESC key
		x.btnClose.click();
		return false;
	}
	
	
    return true;
}

function SelectCashReg(PCashReg,PTransId){
	x=document.form1;
	var vTransType = x.TransType.value;
	
	if (vTransType == 'IN' && PTransId != '') {
		alert('Cash Register already open.');
	} else {
		x.CashReg.value = PCashReg;
		x.submit();
	}
	
}

function FillInput(PValue){
	var vField=document.form1.FocusField.value;
	
	if (document.getElementById(vField)) {
		if(isTextSelected(document.getElementById(vField))){
			document.form1[vField].value=PValue;
		} else {
			document.form1[vField].value=document.form1[vField].value+PValue;
		}
	
		$(document.getElementById(vField)).trigger("change");
	}
}

function isTextSelected(input) {
    if (typeof input.selectionStart == "number") {
        return input.selectionStart == 0 && input.selectionEnd == input.value.length;
    } else if (typeof document.selection != "undefined") {
        input.focus();
        return document.selection.createRange().text == input.value;
    }
}

function FillHidden(PField){
	document.form1.FocusField.value=PField;
}

function EraseInput(PValue){
	var vField=document.form1.FocusField.value;
	document.form1[vField].value='';
	
	if (document.getElementById(vField)) {
		$(document.getElementById(vField)).trigger("change");
	}
}

function CalcSubTotal(PIndex){
	vCashUnit = document.getElementById('txtCashUnit'+PIndex).value;
	vCashQty  = document.getElementById('txtCashQty'+PIndex).value;
	
	if (vCashUnit=='') vCashUnit = 0;
	if (vCashQty=='')  vCashQty = 0;
	
	document.getElementById('txtCashTotal'+PIndex).value = (vCashUnit*vCashQty);
	CalcTotal();
}

function CalcTotal(){
	vCounter = document.getElementById('Counter').value;
	var vSubTotalCash = 0;
	var vTotalCash = 0;
	
	for(var i=1; i <= vCounter; i++){
		vSubTotalCash = document.getElementById('txtCashTotal'+i).value;
		if (vSubTotalCash == '') vSubTotalCash = 0;
		vTotalCash = parseFloat(vTotalCash) + parseFloat(vSubTotalCash);
	}
	
	document.getElementById('TotalCash').value = vTotalCash;
	
}

function PrintSummary(detail) {
	var x = document.form1;
	var vCashReg = x.CashReg.value;
	
	var str = 'Form_RetailCashCount.php?PCashReg='+vCashReg+'&PrintDetail='+detail;
	window.open(str, 'Form_RetailCashCount', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=500,top=100');	

}
function setnewshift(){
	if(document.getElementById("txtnewshiftopen").checked)
		document.form1.txtnewshiftopen.value=1;
	else document.form1.txtnewshiftopen.value=0;
		
}
</script>
<title>CashRegister-Trans</title>
<style type="text/css">

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

 button {
  padding: 0 0 0 0;
  margin: 0 3px 0 3px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  outline: none;
  white-space: nowrap;
  overflow: visible;
  height: 22px; 
  font-family: 11px Arial, sans-serif;
  font-size: 13px;
  color: #000000;
  background: none;
  font-weight: bold;

}
</style>


</head>
<body onkeydown='return kd(event);'>
<form name='form1' method='post'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='message' value='$message'>
<input type='hidden' name='TransType' value='$TransType'>
<input type='hidden' name='FocusField' value='$FocusField'>
<input type='hidden' name='CashReg' value='$CashReg'>		
HERE;


echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' style='table-layout:fixed' width='680px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px;' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>Cash Registers</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' cellpadding='0' style='table-layout:fixed' align='center' valign='top' >
          <col width=275>
		  <col width=350>

			<tr bgcolor='#F7F7F7'><td colspan='2' align='center'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td></tr>
			<tr bgcolor='#F7F7F7'><td colspan='2' align='left'><div style='width:100%; height:65px; padding-top:3px; overflow-x:auto; border:1px solid #D8D8D8;'>";
			
			$sub_query = " Select upper(cashregister.cashregister_name), ctrans_id, date_format(ctrans_timein,'%d/%m/%Y') As ctrans_datein, date_format(ctrans_timein,'%H:%i %p') As ctrans_timein, ".
						 " cashregister.currency_code, Round(ifNull(ctrans_totalcashstart,0), ".$DecimalBase.") as ctrans_totalcashstart, Round(ifNull(ctrans_totalcashclose,0), ".$DecimalBase.") as ctrans_totalcashclose ".
						 " From cashregister  Inner Join ".$HTTP_SESSION_VARS['dbLabel'].".logindt on logindt.Cash_Register = CashRegister.CashRegister_Name ";
						 

					 
			if ($TransType == 'IN')			 
				$sub_query .= " Left Join cashregistertrans on upper(cashregistertrans.cashregister_name) = upper(cashregister.cashregister_name) and ctrans_timeout is null ";
			else if ($TransType == 'OUT')
				$sub_query .= " Inner Join cashregistertrans on upper(cashregistertrans.cashregister_name) = upper(cashregister.cashregister_name) and ctrans_timeout is null ";
						
				$sub_query .= " Where logindt.User_Account = '".$HTTP_SESSION_VARS['useraccount']."' ";
						
			//echo $sub_query;
			$sub_result=mysql_query($sub_query,$connection) or die(mysql_error());
			while($sub_rows=mysql_fetch_array($sub_result)){
				$BtnName  = 'btn'.$sub_rows[0];
				$BtnValue = $sub_rows[0] . '<br>' . $sub_rows[2] . '<br>' . $sub_rows[3];
				
				echo"<button type='button' id='$BtnName' name='$BtnName' onclick=\"SelectCashReg('$sub_rows[0]','$sub_rows[1]'); return false;\" class='cashregbuttons'>$BtnValue</button>";
			}
			
echo"		</div></td></tr>";

if ($TransType == 'IN'){
	echo"	  	<tr bgcolor='#F7F7F7' height='50'>
					<td align='left' valign='top'><table cellspacing=1 cellpadding=1 border='0' style='padding-top:5px;'>";
					
				$Counter = 0;	
				$sub_query1 = " Select Cash_Id, Cash_Value From cashamounts order by Cash_Value desc ";
				//echo $sub_query1;
				$sub_result1=mysql_query($sub_query1,$connection) or die(mysql_error());
				while($sub_rows1=mysql_fetch_array($sub_result1)){
					$Counter += 1;
					
					$UnitFieldName   = 'txtCashUnit'.$Counter;
					$QtyFieldName    = 'txtCashQty'.$Counter;
					$TotalFieldName  = 'txtCashTotal'.$Counter;
					
					echo"<tr>
							<td width='50px;' align='right'><span class='style4'>$sub_rows1[1]</span></td> 
							<td width='100px;' align='right' ><input type='text' name='$QtyFieldName' id='$QtyFieldName' value='' maxlength='20' onfocus=\"FillHidden('$QtyFieldName')\"; onChange='CalcSubTotal($Counter);' class='roundInputPos' style='text-align:right; width:70px; height:27px;' ></td>
							<td width='100px;' align='right' >
								<input type='text' name='$TotalFieldName' id='$TotalFieldName' value='' maxlength='20'  class='roundInputPos' style='text-align:right; width:90px; height:27px;' readonly />
								<input type='hidden' name='$UnitFieldName' id='$UnitFieldName' value='$sub_rows1[1]' maxlength='20'  />
							</td>
						<tr>";
					
				}
				
	echo"				<tr>
							<td width='50px;' align='right' style='border-top:1px solid black;'><span class='style4'>Total</span></td> 
							<td width='100px;' align='right' style='border-top:1px solid black;'>&nbsp;</td>
							<td width='100px;' align='right' style='border-top:1px solid black;'>
								<input type='hidden' name='Counter' id='Counter' value='$Counter' maxlength='20'  />
								<input type='text' name='TotalCash' id='TotalCash' value='' maxlength='20'  class='roundInputPos' style='text-align:right; width:90px; height:27px;' readonly />
							</td>
						<tr>";	
					
	echo"			</table></td>
					<td align='right' valign='top'><table cellspacing=1 cellpadding=1 border='0' style='padding-top:5px;'>
					<tr>
						<td rowspan='2'><input type='button' id='btnSubmit' name='btnSubmit' value='Enter' class='submitbutton' onclick=\"SubmitRecord(0,0);\"></td>
						<td><input type='button' value='.' class='calculatorbutton' onclick=FillInput('.');></td>
						<td><input type='button' value='1' class='calculatorbutton' onclick='FillInput(1);'></td>
						<td><input type='button' value='2' class='calculatorbutton' onclick='FillInput(2);' id='button2'></td>
						<td><input type='button' value='3' class='calculatorbutton' onclick='FillInput(3);'></td>
					</tr>
					<tr>
						<td><input type='button' value='00' class='calculatorbutton' onclick=FillInput('00');></td>
						<td><input type='button' value='4' class='calculatorbutton' onclick='FillInput(4);'></td>
						<td><input type='button' value='5' class='calculatorbutton' onclick='FillInput(5);'></td>
						<td><input type='button' value='6' class='calculatorbutton' onclick='FillInput(6);'></td>
					</tr>
					<tr>
						<td><input type='button' value='Clr' class='calculatorbutton' onclick='EraseInput();'></td>
						<td><input type='button' value='0' class='calculatorbutton' onclick='FillInput(0);'></td>
						<td><input type='button' value='7' class='calculatorbutton' onclick='FillInput(7);'></td>
						<td><input type='button' value='8' class='calculatorbutton' onclick='FillInput(8);'></td>
						<td><input type='button' value='9' class='calculatorbutton' onclick='FillInput(9);'></td>
					</tr>
					</table></td>
				</tr>";	
} else {
	$PCashReg = $CashReg; //$_SESSION['cashregister'];
	
	$sub_query4 = " Select ctrans_id, date_format(ctrans_timein, '%Y-%m-%d %h:%i %p') as ctrans_timein, ctrans_timeout, currency_code as ctrans_currency, ctrans_additionalcash, ".
				  " ifnull(ctrans_totalcashstart,0) as ctrans_totalcashstart, ifnull(ctrans_totalcashclose,0) as ctrans_totalcashclose ".
				  " From cashregistertrans ".
				  " Where upper(cashregister_name) = upper('".$PCashReg."') ".
				  " And cashregistertrans.ctrans_timeout is null ";
	$sub_result4=mysql_query($sub_query4,$connection) or die(mysql_error());
	while($sub_row4=mysql_fetch_array($sub_result4)){
		extract($sub_row4);
	}
			
	$sub_query5 = " Select Round(Sum(ifNull(ctransdt_amountb1,0)), ".$DecimalBase1.") As  ctransdt_amountb1, Round(Sum(ifNull(ctransdt_amountb2,0)), ".$DecimalBase2.") As  ctransdt_amountb2 ".
				  " From cashregistertransdt ".
				  " Where ctrans_id = '".$ctrans_id."' ".
				  " And upper(ctransdt_type) = 'OUT' ";
	$sub_result5=mysql_query($sub_query5,$connection) or die(mysql_error());
	while($sub_row5=mysql_fetch_array($sub_result5)){
		extract($sub_row5);
	}
			
	$sub_query6 = " Select Retail.Currency_Code as CurrencyCode, ".
				 " Round(Sum(ifNull(Sale_TaxableBase1,0))) As  SaleTaxableBase1, Round(Sum(ifNull(Sale_TaxableBase2,0)), ".$DecimalBase2.") As  SaleTaxableBase2, ".
				 " Round(Sum(ifNull(Sale_NoneTaxableBase1,0))) As  SaleNoneTaxableBase1, Round(Sum(ifNull(Sale_NoneTaxableBase2,0)), ".$DecimalBase2.") As  SaleNoneTaxableBase2, ".
				 " Round(Sum(ifNull(Sale_DiscountBase1,0))) As  SaleDiscountBase1, Round(Sum(ifNull(Sale_DiscountBase2,0)), ".$DecimalBase2.") As  SaleDiscountBase2, ".
				 " Round(Sum(ifNull(Sale_VATBase1,0))) As  SaleVATBase1, Round(Sum(ifNull(Sale_VATBase2,0)), ".$DecimalBase2.") As  SaleVATBase2, ".
				 " Round(Sum(ifNull(Sales_CashInBase1,0)),5) As SalesCashInBase1, Round(Sum(ifNull(Sales_CashOutBase1,0)),5) As SalesCashOutBase1,  ".
				 " Round(Sum(ifNull(Sales_CashInBase2,0)),5) As SalesCashInBase2, Round(Sum(ifNull(Sales_CashOutBase2,0)),2) As SalesCashOutBase2, ".
				 " Round(Sum(ifNull(Sale_NetTotalBase1,0)),5) As NetSalesBase1, Round(Sum(ifNull(Sale_NetTotalBase2,0)),2) As NetSalesBase2, ".
				 " Sum(ifNull(Sale_CashBase1,0)) As SaleCheckBase1, Sum(ifNull(Sale_CashBase2,0)) As SaleCheckBase2, ".
				 " Sum(ifNull(Sales_CreditAmountBase1,0)) As SalesCreditAmountBase1, Sum(ifNull(Sales_CreditAmountBase2,0)) As SalesCreditAmountBase2, ".
				 " Sum(ifNull(Sales_TipsBase1,0)) As SalesTipsBase1, ".
				 " Sum(ifNull(Coupon_AmountBase1,0)) As CouponAmountBase1, Sum(ifNull(Coupon_AmountBase2,0)) As CouponAmountBase2 ".
				 " From Retail ".
				 " Inner Join cashregistertrans on Upper(cashregistertrans.CashRegister_Name) = Upper(Retail.CashRegister_Name) ".
				 " Where Upper(Retail.CashRegister_Name) = Upper('".$PCashReg."') ".
				 " And cashregistertrans.ctrans_timeout is null ".
				 " And Retail.Sale_Date >= cashregistertrans.ctrans_timein ".
				 " Group By Retail.Currency_Code ";
			 
	$sub_result6=mysql_query($sub_query6,$connection) or die(mysql_error());
	while($sub_row6=mysql_fetch_array($sub_result6)){
		extract($sub_row6);
	}


	$TotalCashInB1  = $SalesCashInBase1;
	$TotalCashInB2  = $SalesCashInBase2;
	$TotalCashOutB1 = $SalesCashOutBase1;
	$TotalCashOutB2 = $SalesCashOutBase2;
	$TotalChecksB1  = $SaleCheckBase1;
	$TotalChecksB2  = $SaleCheckBase2;
	$TotalCreditsB1 = $SalesCreditAmountBase1;
	$TotalCreditsB2 = $SalesCreditAmountBase2;
	$TotalCouponB1  = $CouponAmountBase1;
	$TotalCouponB2  = $CouponAmountBase2;
	$TotalTipsB1 	= $SalesTipsBase1;
			
	$SubTotalCashB1 = $TotalCashInB1 - $TotalCashOutB1;
	$SubTotalCashB2 = $TotalCashInB2 - $TotalCashOutB2;
			
	$CurrDate = Date('Y-m-d h:i:s');
	$SubTotalCashB11 = ConvertCurrency($Base2, $Base1, $CurrDate, $SubTotalCashB2, $connection);
	$SubTotalCashB22 = ConvertCurrency($Base1, $Base2, $CurrDate, $SubTotalCashB1, $connection);
			
	$TotalCashB1 = $SubTotalCashB1 + $SubTotalCashB11;
	$TotalCashB2 = $SubTotalCashB2 + $SubTotalCashB22;
			
	$TotalTipsB2 = ConvertCurrency($Base1, $Base2, $CurrDate, $TotalTipsB1, $connection);
			
	$NetTotalB1	 = $TotalCashB1 + $TotalChecksB1 + $TotalCreditsB1 + $TotalCouponB1 + $TotalTipsB1;
	$NetTotalB2	 = $TotalCashB2 + $TotalChecksB2 + $TotalCreditsB2 + $TotalCouponB2 + $TotalTipsB2;
			
	if ($CurrencyCode == $Base1) {
		$TotalCashAmount    = $TotalCashB1;
		$TotalChecksAmount  = $TotalChecksB1;
		$TotalCreditsAmount = $TotalCreditsB1;
		$TotalCashPayOut    = $ctransdt_amountb1;
		$TotalCashInDrawer  = $ctrans_totalcashstart + $TotalCashAmount + $TotalChecksAmount + $TotalCreditsAmount - $TotalCashPayOut;
	}	
	else {
		$TotalCashAmount 	= $TotalCashB2;
		$TotalChecksAmount  = $TotalChecksB2;
		$TotalCreditsAmount = $TotalCreditsB2;
		$TotalCashPayOut    = $ctransdt_amountb2;
		$TotalCashInDrawer  = $ctrans_totalcashstart + $TotalCashAmount + $TotalChecksAmount + $TotalCreditsAmount - $TotalCashPayOut;
	}
	
	$PDateFrom = $ctrans_timein;
	$PDateTo   = Date('Y-m-d h:i A');	
	
	echo"<tr bgcolor='#F7F7F7' height='50'><td align='left' valign='top' colspan='2'>";
	echo "<table border=0 width='250' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
		  <col width=100>
		  <col width=120>
		  <col width=40>";
	echo"	<tr><th align='left' valign='top'>Date From/To:</th><td align='left' colspan='2'>". $PDateFrom ." <br> ". $PDateTo ."</td></tr>";
	echo"	<tr><th align='left' style='padding-bottom:10px;'>CashRegister:</th><td align='left' colspan='2' style='padding-bottom:10px;'>". $PCashReg ."</td></tr>";	  
	echo"	<tr><td align='left' colspan='3' style='height:10px; border-top:1px dashed black;'>&nbsp;</th>";

	echo"	<tr><th align='left'>Open Balance</th><td align='right'>". number_format($ctrans_totalcashstart, $DecimalBase1) ."</td><th align='center'>$ctrans_currency</th></tr>";
	echo"	<tr><th align='left'>Total Cash</th><td align='right'>". number_format($TotalCashAmount, $DecimalBase1) ."</td><th align='center'>$CurrencyCode</th></tr>";
	echo"	<tr><td align='left' colspan='3' style='padding-left:10px;'>
				<table border=0 width='150' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
				<col width=50>
				<col width=100>";
	echo"			<tr><th align='left'>$Base1</th><td align='right'>". number_format($SubTotalCashB1, $DecimalBase1) ."</td></tr>";
	echo"			<tr><th align='left'>$Base2</th><td align='right'>". number_format($SubTotalCashB2, $DecimalBase2) ."</td></tr>";
	echo"	   	</table>";
	echo"	</td></tr>";

	if ($TotalChecksAmount != 0) {
		echo"<tr><th align='left'>Total Checks</th><td align='right'>". number_format($TotalChecksAmount, $DecimalBase1) ."</td><th align='center'>$CurrencyCode</th></tr>";
		echo"	<tr><td align='left' colspan='3' style='padding-left:10px;'>
				<table border=0 width='150' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
				<col width=50>
				<col width=100>";
				
		$sub_query2 = " Select Retail.Sale_CashCur as Sale_CashCur, Sum(ifNull(Sale_Cash,0)) As Sale_Cash ".
					  " From Retail ".
					  " Inner Join cashregistertrans on Upper(cashregistertrans.CashRegister_Name) = Upper(Retail.CashRegister_Name) ".
					  " Where Upper(Retail.CashRegister_Name) = Upper('".$PCashReg."') ".
					  " And cashregistertrans.ctrans_timeout is null ".
					  " And Retail.Sale_Date >= cashregistertrans.ctrans_timein ".
					  " Group By Retail.Sale_CashCur ";
				 
		$sub_result2=mysql_query($sub_query2,$connection) or die(mysql_error());
		while($sub_rows2=mysql_fetch_array($sub_result2)){
			extract($sub_rows2);
			
			echo"<tr><th align='left'>$Sale_CashCur</th><td align='right'>". number_format($Sale_Cash, $DecimalBase1) ."</td></tr>";
		}
		
		echo"  	</table>";
		echo"</td></tr>";
	}
		
	if ($TotalCreditsAmount != 0) {
		echo"<tr><th align='left'>Total Credits</th><td align='right'>". number_format($TotalCreditsAmount, $DecimalBase1) ."</td><th align='center'>$CurrencyCode</th></tr>";
		
		echo"	<tr><td align='left' colspan='3' style='padding-left:10px;'>
				<table border=0 width='150' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
				<col width=50>
				<col width=100>";
				
		$sub_query3 = " Select Retail.Sales_creditacccur as Sales_CreditAccCur, Sum(ifNull(Sales_CreditAmount,0)) As Sales_CreditAmount ".
					  " From Retail ".
					  " Inner Join cashregistertrans on Upper(cashregistertrans.CashRegister_Name) = Upper(Retail.CashRegister_Name) ".
					  " Where Upper(Retail.CashRegister_Name) = Upper('".$PCashReg."') ".
					  " And cashregistertrans.ctrans_timeout is null ".
					  " And Retail.Sale_Date >= cashregistertrans.ctrans_timein ".
					  " Group By Retail.Sales_CreditAccCur ";
				 
		$sub_result3=mysql_query($sub_query3,$connection) or die(mysql_error());
		while($sub_rows3=mysql_fetch_array($sub_result3)){
			extract($sub_rows3);
			
			echo"<tr><th align='left'>$Sales_CreditAccCur</th><td align='right'>". number_format($Sales_CreditAmount, $DecimalBase1) ."</td></tr>";
		}
		
		echo"  	</table>";
		echo"</td></tr>";
	}	
	echo"	<tr><th align='left'>Total Cash Out</th><td align='right'>". number_format($TotalCashPayOut, $DecimalBase1) ."</td><th align='center'>$CurrencyCode</th></tr>";
	echo"	<tr><th align='left' style='height:30px;'>Drawer Count</th><th align='right' style='border-top:1px dotted black;'>". number_format($TotalCashInDrawer, $DecimalBase1) ."</th><th align='center'>$CurrencyCode</th></tr>";
	echo"	<tr><td align='left' colspan='3' style='height:10px; border-top:1px dashed black;'>&nbsp;</th>";

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

}
if ($TransType == 'OUT'){
			 echo "<tr bgcolor='#F7F7F7'><td colspan='2' bgcolor=#D8D8D8 align='right'>
				<input type='checkbox' name='txtnewshiftopen' id='txtnewshiftopen' value='$txtnewshiftopen' onclick='setnewshift();'>End shift with shift reopen</td></tr>";
			}
			
echo"		<tr bgcolor='#F7F7F7' height='25px'>	 
				<td colspan='2' align='right' bgcolor=#D8D8D8>";

			if ($TransType == 'OUT'){
				
				echo"<button type='button' id='btnPrint' name='btnPrint' onclick='PrintSummary(0);return false;'   title='Print'><span><span>Print</span></span></button>";
				echo"<button type='button' id='btnPrintDt' name='btnPrintDt' onclick='PrintSummary(1);return false;'   title='Print With Detail'><span><span>Print With Detail</span></span></button>";
				echo"<button type='button' id='btnSubmit' name='btnSubmit' onclick=\"SubmitRecord('".$TotalCashInDrawer."','".$CashRegister_AutoClosePrint."');return false;\"   title='End Shift'><span><span>End Shift</span></span></button>";
			}
			
echo"				<button type='button' id='btnClose' name='btnClose' onclick='CloseForm();return false;'   title='Close'><span><span>Esc:Close</span></span></button>";
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></table>";	  


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

}

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

HERE;

?>