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

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

print <<< HERE
<HTML>
<HEAD>
<TITLE> Slip Report </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">

<style type="text/css">

table.master h1 { font-size: 16px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                }				 
				
table.master th { font-size: 12px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                }				 
table.master td { font-size: 12px; 
                  font-family:Times-New-Roman;
                 }
table.detail th { font-size: 12px; 
                  font-weight: bold;
                  font-family:Times-New-Roman;
                }				 
				 
table.detail td { font-size: 11px; 
                  font-family:Times-New-Roman;
                 }				 
				 
				 
table.totals td.labels { font-size: 11px; 
                         font-weight: bold;
                         font-family:Times-New-Roman;
					  }					  
table.totals td.labels1 { font-size: 16px; 
                          font-weight: bold;
                          font-family:Times-New-Roman;
					   }					  					  
table.totals td.amounts { font-size: 11px; 
                          font-family:Times-New-Roman;
					    }
table.totals td.amounts1 { font-size: 16px; 
						   font-weight: bold;
                           font-family:Times-New-Roman;
					     }
table.totals p { border-width: 1px;
 				 border-style: none none dotted none;
				 border-color: #666666;
				}	
h4 { border-top-style: double; 
	 border-top-color: black; 
	 border-top-width: 1px;
   }				
				 
table.notes th { font-size: 12px; 
                 font-weight: bold;
                 font-family:Times-New-Roman;
                }				 
table.notes td { font-size: 11px; 
                 font-family:Times-New-Roman;
                }
</style>


</HEAD>

<BODY>
HERE;

include("config.inc.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 FullName As User_FullName ".
          " 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 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, ifNull(CashRegister_SlipCopy,1) As CashRegister_SlipCopy  ".
				   " 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_Name As User_FullName ".
			" From ".$_SESSION['dbLabel'].".users where user_account='".$_SESSION['useraccount']."' ";
$resultusers=mysql_query($queryusers,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultusers)){
	extract($rows);
}


//Read From Setup Table							
$querysetup= " Select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, ".
             " Company_Name As CompanyName, Company_Memo As CompanyMemo, Company_City As CompanyCity, ".
			 " Company_Telephone As CompanyTelephone, Company_Fax As CompanyFax, Company_Logo As CompanyLogo, ".
			 " Setup_VatNo, Setup_VatPercentage, ifNull(CashReg_RoundDivisor,1) As CashReg_RoundDivisor, ".
			 " Setup_SlipFooter As SetupSlipFooter 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 ifNull(CashRegisterTTC,0) As CashRegisterTTC,ifNull(CashRegister_DrawerCOM,0) As CashRegister_DrawerCOM ".
				   " From CashRegister ".
				   " Where CashRegister_Name = '".$_SESSION['cashregister']."' ";
$resultCashRegister=mysql_query($queryCashRegister,$connection) or die(mysql_error());
while($rowCashRegister=mysql_fetch_array($resultCashRegister)){
	extract($rowCashRegister);
}

	
$now=current_server_time($connection);
$dt=split(" ",$now[0]);
$printdate=split("-",$dt[0]);

$TotalQty = 0;
$TotalItems = 0;

$RetailId = $_GET['RetailId']; if ($RetailId == ""){$RetailId = $_POST["RetailId"];}

if($RetailId=='')
	{
	
		$query = " Select max(Sale_ID) From Retail where CashRegister_Name = '".$_SESSION['cashregister']."' ";
		$result=mysql_query($query,$connection) or die(mysql_error());
		$rows=mysql_fetch_array($result);
		$RetailId = $rows[0];
		$_GET['TempRep'] = 0;
		
		
	}


if($RetailId != '')
{
			 
	$query = " Select Sale_ID, Sale_Reference, Date_Format(Sale_Date,'%d/%m/%Y') As Sale_Date, Retail.Currency_code As CurrCode, ".
			 " Retail.Client_code As ClientCode, Clients.Ledger_name As ClientName, Retail.CashRegister_Name, Sale_Remark, ".
			 " if(Sale_Information='' or Sale_Information is null, Clients.Ledger_name, Sale_Information) As Sale_Information, ".
			 " Round(ifNull(Sale_Taxable,0), ".$DecimalBase.") As SaleTaxable, Round(ifNull(Sale_NoneTaxable,0), ".$DecimalBase.") As SaleNoneTaxable, ".
			 " Round(ifNull(Sale_Taxable,0) + ifNull(Sale_NoneTaxable,0), ".$DecimalBase.") As GrossTotal, ".
			 " Round(ifNull(Sale_DiscountPer,0), ".$DecimalBase."), Round(ifNull(Sale_DiscountAmount,0), ".$DecimalBase.") As Sale_DiscountAmount,  ".
			 " 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_NetTotal1,  ".
			 " 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.") As  Sale_NetTotal, ".
			 " Round(ifNull(Sale_NetTotalBase2,0), ".$DecimalBase.") As  SaleNetTotalB2, ".
			 " ifNull(Sales_CashInBase1,0) As CashInBase1, ifNull(Sales_CashInBase2,0) As CashInBase2, ".
			 " ifNull(Sales_CashOutBase1,0) As CashOutBase1, ifNull(Sales_CashOutBase2,0) As CashOutBase2,  ".
			 " Retail.Coupon_Id, Coupon_Reference As CouponReference, Coupon_Name As CouponName, ifNull(Retail.Coupon_Amount,0) As CouponAmount, ".
			 " ifNull(Retail.Coupon_Amount,0) - ifNull(convertcurfunc(Coupon.Currency_Code, Retail.Currency_code, Coupon_Date, 0, 0, '', '', ifNull(Coupon.Coupon_AmountConsum,0)),0) As CouponRemAmount, ".
			 " Sale_CashCur As CashCur, ifNull(Sale_Cash,0) As SaleCash, Sale_CheckNo As CheckNo, Date_Format(Sale_CheckDate,'%d/%m/%Y') As CheckDate, Sale_Bank As BankName, Sale_BankBranch As BankBranch, ".
			 " Sales_CreditAccCur As CreditAccCur, ifNull(Sales_CreditAmount,0) As CreditAmount, Sales_CreditAcc As CreditAcc, Ledger.Ledger_Name As CreditName,  ".
			 " ifNull(Sales_TipsBase1,0) As SalesTipsBase1, ".
			 " 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 Sale_DiscountAmountTTC, ".
			 " Round((ifNull(Sale_Taxable,0)*(1+$Setup_VatPercentage/100)), ".$DecimalBase.") As SaleTaxableTTC, ".
			 " Date_Format(Sale_Date,'%h:%i %p') As Sale_Time, Customer.Customer_Name As CustomerName, Customer_Telephone1, Customer_Telephone2, Customer_Address, ".
			 " Users.User_Name as UserName, ProjectDt_Name as TableName,sale_numberofguests, Sale_Remark ";
			 
	if ($_GET['TempRep'] == 1) $query .= " From Temp_Retail as Retail ";
	else $query .= " From Retail ";
	
	$query .= " Left Join Clients on Retail.Client_code = Clients.Ledger_Number ".
			  " Left Join Coupon on Retail.Coupon_Id =  Coupon.Coupon_Id ".
			  " Left Join Ledger on Retail.Sales_CreditAcc =  Ledger.Ledger_Number ".
			  " Left Join Customer on Retail.Customer_Code =  Customer.Customer_Code ".
			  " Left Join projectdt on projectdt.projectdt_id =  Retail.projectdt_id ".
			  " Left Join ".$_SESSION['dbLabel'].".users on users.User_account =  Retail.User_account ".
	          " Where Sale_ID = '".$RetailId."'";		 
	//	echo $query;	 
	$result=mysql_query($query,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($result)){
		extract($rows);
	}
	
		
	echo "<table border=0 width=100% cellspacing=0 cellpadding=0><tr><td align='left'>";
	echo "<table border=0 width='250' cellspacing=0 cellpadding=0 class='master' style='table-layout:fixed;' >
		  <col width=45>
		  <col width=95>
		  <col width=40>
		  <col width=70>";
	
	if ($CompanyLogo != '') {
		echo "<tr height='25'>";
		echo "  <td align='center' valign='top' colspan='4'><img src='LogoFile.php' width='140' height='120' /></td>";
		echo "</tr>";
	} 
	
	echo "<tr>";
	echo "  <td align='center' valign='top' colspan='4'><h1>$CompanyName</h1></td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "  <td align='center' valign='top' colspan='4'>".nl2br($CompanyMemo)."</td>";
	echo "</tr>";
		
	if ($Setup_VatPercentage > 0) {
		echo "<tr>";
		echo "  <td align='center' valign='top' colspan='4'>Vat# $Setup_VatNo</td>";
		echo "</tr>";
	} 	
	
		
	
	echo "<tr>";
	echo "  <th align='left' valign='top' style='border-top:1px solid black;'>INV.</th>";
	if ($Sale_Reference >0){
	echo "  <td align='left' valign='top' style='border-top:1px solid black;'>$Sale_Reference</td>";
	} else echo "  <td align='left' valign='top' style='border-top:1px solid black;'>$Sale_Remark &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
	echo "  <th align='left' valign='top' style='border-top:1px solid black;'>DATE</th>";
	echo "  <td align='left' valign='top' style='border-top:1px solid black;'>$Sale_Date</td>";
	echo "</tr>";
	
	echo "<tr>";
	echo "  <th align='left' valign='top'>Table</th>";
	echo "  <td align='left' valign='top'>".strtoupper($TableName)."</td>";
	echo "  <th align='left' valign='top'>TIME</th>";
	
	echo "  <td align='left' valign='top'>$Sale_Time</td>";
	echo "</tr>";
	echo"<tr>"; 
	echo "  <th align='left' valign='top'>guest#</th>";
	echo "  <td align='left' valign='top'>".strtoupper($sale_numberofguests)."</td>";
	echo "</tr>";	
    echo "<tr>";
	echo "  <td align='left' colspan='4' style='font-weight:bold;'> Served By &nbsp;&nbsp ".$_SESSION['cashregister']." / ".strtoupper($UserName)."</td>";
	echo "</tr>";
	
	if ($CustomerName != '') {
		echo "<tr>";
		echo "  <td align='left' colspan='4' style='padding-top:8px; font-style:italic;'>Customer: $CustomerName";
		if ($Customer_Telephone1 != '') echo " - $Customer_Telephone1";
		if ($Customer_Telephone2 != '') echo " / $Customer_Telephone2";
		echo"	</td>";
		echo "</tr>";
		if($Customer_Address != ''){
			echo "<tr>";
			echo "  <td align='left' colspan='4' style='padding-bottom:10px; padding-left:60px; font-style:italic;'>$Customer_Address</td>";
			echo "</tr>";
		}
	}
	/*else if ($Sale_Information != '') {
		echo "<tr>";
		echo "  <th align='left'>&nbsp;</th>";
		echo "  <td align='left' colspan='4'>$Sale_Information</td>";
		echo "</tr>";
	}*/
	
	
	echo "</table></td></tr>";

	
		   
	$querydt = " Select RetailDt.Item_CodePacked, RetailDt.Item_code As ItemCode, Substr(Item_Description,1,22) As ItemDescription, ".
			   " if(ifNull(Items.Item_Vat,0) > 0, '*', ' ') As ItemVat, Sum(ifNull(SaleDt_Quantity,0)) as SaleDt_Quantity, Round(SaleDt_Price, ".$DecimalBase.") As SaleDtPrice, SaleDt_PriceBase1, SaleDt_PriceBase2, ".
			   " Round(SaleDt_DiscountPer, ".$DecimalBase.") As SaleDtDiscountPer,  ".
			   " Round(Sum((SaleDt_Quantity*SaleDt_Price)-((SaleDt_Quantity*SaleDt_Price*ifNull(SaleDt_DiscountPer,0))/100)), ".$DecimalBase.") As SaleDtTotal, ".
			   " Round(SaleDt_PriceTTC, ".$DecimalBase.") As SaleDtPriceTTC, ".
			   " Round(Sum((SaleDt_Quantity*SaleDt_PriceTTC)-((SaleDt_Quantity*SaleDt_PriceTTC*ifNull(SaleDt_DiscountPer,0))/100)), ".$DecimalBase.") As SaleDtTotalTTC, ".
			   " SalesDt_Remark as SalesDtRemark, RetailDt.RelatedDt_Id as RelatedDtId, if(Q1.CountItemModifiers > 0, 1, 0) as ItemHasModifiers, IfNull(SaleDt_ItemStatus,0) as SaleDtItemStatus ";
			   
	if ($_GET['TempRep'] == 1) $querydt .= " From Temp_RetailDt as RetailDt ";
	else $querydt .= " From RetailDt ";
	
	$querydt .= " Left Join ( Select RetailDt1.RelatedDt_Id, count(*) as CountItemModifiers ";
	if ($_GET['TempRep'] == 1) $querydt .= " From Temp_RetailDt as RetailDt1 ";
	else $querydt .= " From RetailDt as RetailDt1 ";
	$querydt .= " 			  Where RetailDt1.Sale_ID = '".$RetailId."' ".
				" 			  Group By RetailDt1.RelatedDt_Id) as Q1 on Q1.RelatedDt_Id = RetailDt.SaleDt_Id ";
	
	$querydt .= " Left Join Items on RetailDt.Item_code = Items.Item_code ".
			    " Where RetailDt.Sale_ID = '".$RetailId."' ";
				
	if ($_GET['TempRep'] == 1) {
		$querydt1 = $querydt." And IfNull(SaleDt_ItemStatus,0) Not In (2,3,4) ".
							 " Group By RetailDt.Item_CodePacked, RetailDt.Item_code,  ItemHasModifiers ".
							 " Order By ifNull(RetailDt.RelatedDt_Id, RetailDt.SaleDt_ID) Asc  ";
							 
		$querydt2 = $querydt." And IfNull(SaleDt_ItemStatus,0) = 4 ".
							 " Group By RetailDt.Item_CodePacked, RetailDt.Item_code,  ItemHasModifiers ".
							 " Order By ifNull(RetailDt.RelatedDt_Id, RetailDt.SaleDt_ID) Asc  ";
	}	
	else {
		$querydt1 = $querydt." And IfNull(SaleDt_ItemStatus,0) Not In (2,3) ".
							 " Group By RetailDt.Item_CodePacked, RetailDt.Item_code,  ItemHasModifiers ".
							 " Order By ifNull(RetailDt.RelatedDt_Id, RetailDt.SaleDt_ID) Asc  ";
	}	
			    
			   
					   
	//echo $querydt1;
	echo "<tr><td align='left'>";
	echo "<table border=0 width='250' cellspacing=0 class='detail' style='table-layout:fixed;' >
		  <col width=40>
		  <col width=40>
		  <col width=70>
		  <col width=100> ";
	echo "<tr height='25'>";
	echo "   <th align='left' style='border-top:2px solid black; border-bottom:2px solid black;'>Desc.</th>";
	echo "	 <th align='right' style='border-top:2px solid black; border-bottom:2px solid black;'>Qty.</th>";
	echo "	 <th align='right' style='border-top:2px solid black; border-bottom:2px solid black;'>Price</th>";
	echo "	 <th align='right' style='border-top:2px solid black; border-bottom:2px solid black;'>Total $CurrCode</th>";
	echo "</tr>";			
		  
	
	$resultdt=mysql_query($querydt1,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($resultdt)){
		extract($rows);
		
		$TotalQty = $TotalQty + $SaleDt_Quantity;
		$TotalItems += 1;
		
		$VoidStyle = '';
		if ($SaleDtItemStatus == 2) $VoidStyle = "style='text-decoration: line-through'";
		
		if ($RelatedDtId != '') {
			echo "<tr $VoidStyle>";
			echo "  <td align='left' valign='top' colspan='4' style='padding-left:20px;'>$ItemDescription</td>";
			echo "</tr>";
		} else {
			echo "<tr $VoidStyle>";
			echo "  <td align='left' valign='top' colspan='4'>$ItemVat&nbsp;$ItemDescription</td>";
			echo "</tr>";
		}
		
		echo "<tr $VoidStyle>";
		echo "  <td align='left' valign='top'>&nbsp;</td>";
		echo "	<td align='right' valign='top'>$SaleDt_Quantity</td>";
			
		if ($CashRegisterTTC == 1) {
			echo "	<td align='right' valign='top'>".number_format($SaleDtPriceTTC, $DecimalBase)."</td>";
			echo "	<td align='right' valign='top'>".number_format($SaleDtTotalTTC, $DecimalBase)."</td>";
		}	
		else {
			echo "	<td align='right' valign='top'>".number_format($SaleDtPrice, $DecimalBase)."</td>";
			echo "	<td align='right' valign='top'>".number_format($SaleDtTotal, $DecimalBase)."</td>";
		}	
				
		echo "</tr>";
		
		/*if($SalesDtRemark != '') {
			echo "<tr $VoidStyle>";
			echo "  <td align='left' valign='top' colspan='4' style='padding-left:20px;'>".$SalesDtRemark."</td>";
			echo "</tr>";		
		}*/
		
	}
	
	
	//Print Hold Items
	if ($_GET['TempRep'] == 1) {
		
		$resultdt2=mysql_query($querydt2,$connection) or die(mysql_error());
		$countdt2 = mysql_num_rows($resultdt2);
		
		if ($countdt2 > 0) {
			echo "<tr height='25'>";
			echo "   <th align='center' colspan='4' style='border-top:1px dotted black; border-bottom:1px dotted black;'>Hold</th>";
			echo "</tr>";	
		}
				
		while($rows2=mysql_fetch_array($resultdt2)){
			extract($rows2);
			
			$TotalQty = $TotalQty + $SaleDt_Quantity;
			$TotalItems += 1;
			
			if ($RelatedDtId != '') {
				echo "<tr>";
				echo "  <td align='left' valign='top' colspan='4' style='padding-left:20px;'>$ItemDescription</td>";
				echo "</tr>";
			} else {
				echo "<tr>";
				echo "  <td align='left' valign='top' colspan='4'>$ItemVat&nbsp;$ItemDescription</td>";
				echo "</tr>";
			}
			
			echo "<tr>";
			echo "  <td align='left' valign='top'>&nbsp;</td>";
			echo "	<td align='right' valign='top'>$SaleDt_Quantity</td>";
				
			if ($CashRegisterTTC == 1) {
				echo "	<td align='right' valign='top'>".number_format($SaleDtPriceTTC, $DecimalBase)."</td>";
				echo "	<td align='right' valign='top'>".number_format($SaleDtTotalTTC, $DecimalBase)."</td>";
			}	
			else {
				echo "	<td align='right' valign='top'>".number_format($SaleDtPrice, $DecimalBase)."</td>";
				echo "	<td align='right' valign='top'>".number_format($SaleDtTotal, $DecimalBase)."</td>";
			}	
					
			echo "</tr>";
			
			if($SalesDtRemark != '') {
				echo "<tr>";
				echo "  <td align='left' valign='top' colspan='4' style='padding-left:20px;'>".$SalesDtRemark."</td>";
				echo "</tr>";		
			}
			
		}
	}	
	
	echo "</table></td></tr>";
	
	
		
	echo "<tr><td align='left'>";
	echo "<table border=0 width='250' cellspacing=0 cellpadding=1  class='totals' style='table-layout:fixed;' >
		  <col width=30>
		  <col width=120>
		  <col width=100>";
		  /*
	echo "<tr>";
	echo "   <td align='left' >&nbsp;</td>";
	echo "	 <td align='left' class='labels'>Total</td>";
	
	if ($CashRegisterTTC == 1) 
		echo "	 <td align='right' class='amounts'>".number_format($GrossTotalTTC, $DecimalBase)."</td>";
	else
		echo "	 <td align='right' class='amounts'>".number_format($GrossTotal, $DecimalBase)."</td>";
	echo "</tr></p>";	
		*/
/*	echo "<tr>";
	echo "   <td align='left' >&nbsp;</td>";
	echo "	 <td align='left' class='labels'>Discount</td>";
	
	if ($CashRegisterTTC == 1) 
		echo "	 <td align='right' class='amounts'><p>".number_format($Sale_DiscountAmountTTC, $DecimalBase)."</p></td>";
	else
		echo "	 <td align='right' class='amounts'><p>".number_format($Sale_DiscountAmount, $DecimalBase)."</p></td>";
	echo "</tr>";	
	*/

	
	if ($Setup_VatPercentage > 0) {
		echo "<tr>";
		echo "   <td align='left' style='border-top:2px solid black;'>&nbsp;</td>";
		echo "	 <td align='left' class='labels' style='border-top:2px solid black;'>Taxable</td>";
		
		if ($CashRegisterTTC == 1) 
			echo "	 <td align='right' class='amounts' style='border-top:2px solid black;'>".number_format($SaleTaxableTTC, $DecimalBase)."</td>";
		else
			echo "	 <td align='right' class='amounts' style='border-top:2px solid black;'>".number_format($SaleTaxable, $DecimalBase)."</td>";
		echo "</tr>";	
		
		echo "<tr>";
		echo "   <td align='left' >&nbsp;</td>";
		echo "	 <td align='left' class='labels'>None Taxable</td>";
		echo "	 <td align='right' class='amounts'>".number_format($SaleNoneTaxable, $DecimalBase)."</td>";
		echo "</tr>";	
	
		echo "<tr>";
		echo "   <td align='left' style='border-bottom:1px solid black;'>&nbsp;</td>";
		echo "	 <td align='left' class='labels1' style='border-bottom:1px solid black;'>Net Total $CurrCode</td>";
		echo "	 <td align='right' class='amounts1' style='border-top:1px dotted black; border-bottom:1px solid black;'>".number_format($Sale_NetTotal1, $DecimalBase)."</td>";
		echo "</tr>";	

		echo "<tr>";
		echo "   <td align='left' >&nbsp;</td>";
		echo "	 <td align='left' class='labels'>VAT $Setup_VatPercentage% $CurrCode</td>";
		echo "	 <td align='right' class='amounts'>".number_format($Sale_VAT, $DecimalBase)."</td>";
		echo "</tr>";	
		
	} else {
		echo "<tr>";
		echo "   <td align='left' style='border-top:2px solid black;'>&nbsp;</td>";
		echo "	 <td align='left' class='labels' style='border-top:2px solid black;'>Total Brut</td>";
	    echo "	 <td align='right' class='amount' style='border-top:2px solid black;'>".number_format($GrossTotal, $DecimalBase)."</td>";
		echo "</tr>";	
		echo "<tr>";
		echo "   <td align='left'>&nbsp;</td>";
		echo "	 <td align='left' class='labels'>Discount</td>";
	    echo "	 <td align='right' class='amount' >".number_format($Sale_DiscountAmount, $DecimalBase)."</td>";
		echo "</tr>";
		echo "<tr>";
		echo "   <td align='left'>&nbsp;</td>";
		echo "	 <td align='left' class='labels1' >Net Total $CurrCode</td>";
		echo "	 <td align='right' class='amounts1' style='border-top:2px solid black;'>".number_format($Sale_NetTotal1, $DecimalBase)."</td>";
		echo "</tr>";		
        echo "<tr>";
		echo "   <td align='left'>&nbsp;</td>";
		echo "	 <td align='left' class='labels1' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Net $base2</td>";
		echo "	 <td align='right' class='amounts1' >".number_format($SaleNetTotalB2, $DecimalBase)."</td>";
		echo "</tr>";	
	}
		
	echo "</table></td></tr>";
	
	echo "<tr><td align='left' style='padding-top:15px;'>";
		echo "<table border=0 width='250' cellspacing=0 cellpadding=1  class='totals' style='table-layout:fixed;' >
			  <col width=130>
			  <col width=120>";
			  
		echo "<tr> <td align='left' class='labels' $BorderStyle>All Taxes Included</td></tr>";
		
	if ($CashInBase1 !=0 || $CashInBase2 !=0 || $CashOutBase1 !=0 || $CashOutBase2 !=0) {
		
		
		
		/*echo "<tr style='height:10px;'>";
		echo "	 <td align='right' colspan='2' style='border-top:1px solid black;'>&nbsp;</td>";
		echo "</tr>";*/
		
		if ($CashInBase1 !=0) {
			echo "<tr>";
			echo "	 <td align='left' class='labels' style='border-top:1px solid black;'>Cash Paid $base1</td>";
			echo "	 <td align='right' class='amounts' style='border-top:1px solid black;'>".number_format($CashInBase1, $DecimalBase)."</td>";
			echo "</tr>";
		}

		
		
		if ($CashInBase2 !=0) {
			if ($CashInBase1 !=0) {
				$BorderStyle="style='border-top:1px solid black;'";
			}
			
			echo "<tr>";
			echo "	 <td align='left' class='labels' $BorderStyle>Cash Paid $base2</td>";
			echo "	 <td align='right' class='amounts' $BorderStyle>".number_format($CashInBase2, $DecimalBase)."</td>";
			echo "</tr>";
		}

		if ($CashOutBase1 !=0) {
			echo "<tr>";
			echo "	 <td align='left' class='labels'>Cash Returned $base1</td>";
			echo "	 <td align='right' class='amounts'>".number_format($CashOutBase1, $DecimalBase)."</td>";
			echo "</tr>";
		}		
		
		if ($CashOutBase2 !=0) {
			echo "<tr>";
			echo "	 <td align='left' class='labels'>Cash Returned $base2</td>";
			echo "	 <td align='right' class='amounts'>".number_format($CashOutBase2, $DecimalBase)."</td>";
			echo "</tr>";
		}
		
		if (Round($SalesTipsBase1) != 0) {
			echo "<tr>";
			echo "	 <td align='left' class='labels'>Dead Balance $base1</td>";
			echo "	 <td align='right' class='amounts'>".number_format($SalesTipsBase1, $DecimalBase)."</td>";
			echo "</tr>";	
		
		}
			
			
	
	
	
	}
		echo "</table></td></tr>";
	
	
		
		echo "<tr><td align='left'>";
		echo "<table border=0 width='250' cellspacing=0 cellpadding=1  class='totals' style='table-layout:fixed;' >
			  <col width=130>
			  <col width=120>";
		
	
		
		if ($SaleCash !=0) {
			echo "<tr>";
			echo "	 <td align='left' class='labels' style='border-top:1px solid black;'>Check# $CheckNo $CashCur</td>";
			echo "	 <td align='right' class='amounts' style='border-top:1px solid black;'>".number_format($SaleCash, $DecimalBase)."</td>";
			echo "</tr>";
		
			echo "<tr>";
			echo "	 <td align='left' class='labels'>$BankName</td>";
			echo "	 <td align='left' class='labels'>$BankBranch</td>";
			echo "</tr>";
			
		}	
		
		if ($CreditAmount != 0) {
			echo "<tr>";
		   	echo "	 <td align='left' class='labels' style='border-top:1px solid black;'>Credit $CreditName</td>";
			echo "	 <td align='right' class='amounts' style='border-top:1px solid black;'>".number_format($CreditAmount, $DecimalBase)."</td>";
			echo "</tr>";
		}
		
		if ($CouponAmount != 0) {
			echo "<tr>";
	     	echo "	 <td align='left' class='labels' style='border-top:1px solid black;'>Coupon</td>";
			echo "	 <td align='right' class='amounts' style='border-top:1px solid black;'>".number_format($CouponAmount, $DecimalBase)."</td>";
			echo "</tr>";
		}	
			
		echo "</table></td></tr>";
		
	
	
	echo "<tr><td align='left'>";
	echo "<table border=0 width='250' cellspacing=0 cellpadding=1  class='notes' style='table-layout:fixed;' >
		  <col width=130>
		  <col width=120>";
		  
		  
	echo "<tr height='20'>";
	echo "	 <td align='left'>Number of Items: $TotalQty</td>";
	echo "	 <td align='left'>Number of Lines: $TotalItems</td>";
	echo "</tr>";	
	
	echo "<tr height='20'>";
	echo "	 <th align='left' colspan='2'>&nbsp;</th>";
	echo "</tr>";	
	
	if ($SetupSlipFooter != '') {
		echo "<tr>";
		echo "	 <th align='center' colspan='2'>".nl2br($SetupSlipFooter)."</th>";
		echo "</tr>";
	}
	
	/*echo "<tr>";
	echo "	 <th align='center' colspan='2'>Thank you for your visit</th>";
	echo "</tr>";	
		
	echo "<tr>";
	echo "   <th align='center' colspan='2'>You are served by ".ucwords(strtolower($User_FullName))."</th>";
	//echo "	 <th align='left' >".ucwords(strtolower($User_FullName))."</th>";
	echo "</tr>";	*/
		
	echo "</table></td></tr>";
	
	echo "</table>";
	echo "<br>";
	

}





//maroun 01.08.2014
/*if($Module_RestaurantDelivery==1) {
	$querydt = " Select distinct items.subgroup_code ,p_name".
			   " From RetailDt Left Join Items on RetailDt.Item_code = Items.Item_code ".
			   " left join ".$_SESSION['dbLabel'].".printersubgroup on items.subgroup_code=printersubgroup.p_subgroup ".
			   " Where RetailDt.Sale_ID = '".$RetailId."' ".
			   " and saledt_itemstatus = 0".
			   " Order By RetailDt.SaleDt_id  ";
	
	$result=mysql_query($querydt,$connection) or die(mysql_error());
	$i=0;
	echo ' <script type="text/javascript" language="javascript"> ';
	while ($row=mysql_fetch_row($result)) {
	
	if ($CashRegister_SlipPrinter == 1) 
		{
			$ReportName = 'Form_RetailSlipSubGroup.php';
		}	
	else 
		exit;
	
	//if($i==0)
		//echo ' <script type="text/javascript" language="javascript"> ';
	
	if ($CashRegister_Printer == 1) 
		{	
		echo " var str = ''; ";
		echo " str = '$ReportName?RetailId=$RetailId&subgroupcode=$row[0]&printername=$row[1]'; ";
		//echo " alert(str); ";
		echo " window.open(str, 'Form_RetailSlipSubGroup$i', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=500,top=100'); ";
		}
	
	$i+=1;
	}
	
	echo ' </script> ';
}	*/

	


function current_server_time($connection){

  $string="Select date_format(NOW(),'%Y-%m-%d %h:%i %p') ";
  $result=mysql_query($string,$connection) or die(mysql_error());
  $now=mysql_fetch_row($result);

  return $now;
}

function format_currency($amount, $DecimalBase) { 

    if($amount < 0) 
        return "(".number_format(abs($amount),$DecimalBase).")"; 
 
    else return number_format($amount, $DecimalBase); 
} 

 
print <<< HERE

<script language='VBScript'>
Sub Print()
       OLECMDID_PRINT = 6
       OLECMDEXECOPT_DONTPROMPTUSER = 2
       OLECMDEXECOPT_PROMPTUSER = 1
       call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
End Sub
document.write "<object ID='WB' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>"
</script>

<script language=javascript>
if (typeof(window.print) != 'undefined')
{
    window.print();
	
	 setTimeout(function() {
		window.close();
	}, 500 ); 
}

//self.close();
</script>

</BODY>
</HTML>
HERE;
 


?>

