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

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


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

$query_setup  = "select DecimalBase, DecimalBase1, DecimalBase2, Base1, Base2, COMPANY_NAME as CompanyName from setup";
$result_setup = mysql_query($query_setup, $connection); 
$row_setup    = mysql_fetch_array($result_setup);
extract($row_setup);
if($export ==1){
	$filename = "Clients_Archeive" . date('d/m/Y') . ".xls";
	header("Content-Disposition: attachment; filename=\"$filename\"");
	header("Content-Type: application/vnd.ms-excel");
}
echo "<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1256\" />
<title>List of Clients</title>
</head>
<body>
<table width='3200' style='border-collapse:collapse'>
<tr>
<td ";
if($showBalance == 1)
{
	echo "colspan=25";
}
else
{
	echo "colspan=21";
}
echo " style='font-size: 22px; font; width: 1200px; text-align: center; font-weight: bold; border-bottom: solid 2px #000000; font-family: Times New Roman'>List of Clients</td>
</tr>
<tr>
<td style='font-size: 16px; font-weight: bold; font-family: Arial'>Group By:</td>
<td style='font-size: 16px; font-family: Arial' colspan='3'>";
if($groupby == 1)
{
	echo "Salesmen";
}
else
{
	echo "None";
}
echo "</td>
<td style='font-size: 16px; font-weight: bold; font-family: Arial'>Export/Local:</td>
<td style='font-size: 16px; font-family: Arial'>";
echo strtoupper ($exportlocal);
echo"</td>
</tr>
<tr>
<td style='font-size: 16px; font-weight: bold; font-family: Arial'>VAT:</td>
<td style='font-size: 16px; font-family: Arial' colspan='3'>";
echo strtoupper ($vat);
echo "</td>
<td style='font-size: 16px; font-weight: bold; font-family: Arial'>Active:</td>
<td style='font-size: 16px; font-family: Arial'>";
echo strtoupper ($active);
echo"</td>
</tr>
<tr style='height: 20px'>
<td ";
if($showBalance == 1)
{
	echo "colspan=25";
}
else
{
	echo "colspan=21";
}
echo "></td>

</tr>
<tr>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 100px'>Client Code</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 150px'>Client Name</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 100px'>Financial No.</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 100px'>Active</th>";
if($groupby != 1){
echo"<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 150px'>Salesman</th>";
}
echo "<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 100px'>Address 1</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 100px'>Address 2</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 100px'>Address 3</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 100px'>Telephone 1</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 100px'>Telephone 2</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 100px'>Telephone 3</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 100px'>Fax</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 50px'>Selling Price</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 40px'>Vatable</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 75px'>VAT No.</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 110px'>Credit Limit</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 50px'>Payment Terms</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 75px'>City</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 100px'>Email</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 110px'>Home Page</th>
<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 120px'>Profit Center</th>";
if($showBalance == 1){
	echo "<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 200px'>Creation Date</th>";
	echo "<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 200px'>Balance LBP</th>";
	echo "<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 200px'>Last Trans. Date</th>";
	echo "<th style='font-family: Arial; font-size: 14px; font-weight: bold; border-bottom: solid 1.5px #000000; width: 300px'>Last Trans. Desc.</th>";
}
echo "</tr>";
if($groupby == 8){
$query_clients = "select clients.Ledger_number as ClientCode, clients.Ledger_name as ClientName, client_financialno as FiancialNo, salesmen.ledger_name as SalesmanName, 
                  Client_Address as ClientAddress1, Client_Address2 as ClientAddress2, client_address3 as ClientAddress3, Client_Telephone1 as ClientTelephone1, Client_Telephone2 as ClientTelephone2,
				  client_dlvfax as ClientTelephone3, Client_Fax as ClientFax, Client_SellingPrice as ClientSellingPrice, if(Client_VAT = 1, 'Yes', 'No') as ClientVat, Client_VatNo as ClientVatNo,
				  if(Client_CreditLimit <> null or Client_CreditLimit <> '', format(Client_CreditLimit, 2), '') as ClientCreditLimit, Client_PaymentTerms as ClientPaymentTerms, Client_City as ClientCity, client_Email as ClientEmail, Client_homepage as ClientHomePage, ProfitCenter_CODE as ProfitCenter,
				  date_format(Client_CreationDate, '%d/%m/%Y') as ClientCreationDate, if(Client_deactivate = 1, 'No', 'Yes') as ActiveX, Clients.Costcenter_code as CostcentCode
				  from clients left join salesmen on clients.Salesmen_Code = salesmen.ledger_number 
				  where 1=1 ";
if($salesman_code != "")
{
	$query_clients = $query_clients." and clients.Salesmen_Code = '".$salesman_code."'";
}
if($exportlocal == "local")
{
	$query_clients = $query_clients." and client_local = 1";
}
else
	if($exportlocal == "export")
	{
		$query_clients = $query_clients." and client_export = 1";
	}
if($vat == "yes")
{
	$query_clients = $query_clients." and Client_VAT = 1";
}
else
	if($vat == "no")
	{
		$query_clients = $query_clients." and Client_VAT <> 1";
	}
if($active == "yes")
{
	$query_clients = $query_clients." and Client_deactivate <> 1";
}
else
	if($active == "no")
	{
		$query_clients = $query_clients." and Client_deactivate = 1";
	}
$result_clients = mysql_query($query_clients, $connection);
$count = 0;
while($row_clients = mysql_fetch_array($result_clients))
{
	extract($row_clients);
	$count++;
	if($count % 2 != 0)
	{
		$style="background-color: #b9bbbc";
	}
	else
	{
		$style="background-color: #909090";
	}
	echo "<tr style='".$style."; height: 45px'>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px'>".$ClientCode."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 150px'>".$ClientName."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px; text-align: right'>".$FiancialNo."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px; text-align: center;'>".$ActiveX."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 150px;'>".$SalesmanName."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientAddress1."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientAddress2."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientAddress3."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientTelephone1."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientTelephone2."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientTelephone3."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientFax."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 50px; text-align: center'>".$ClientSellingPrice."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 40px; text-align: center'>".$ClientVat."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 75px; text-align: center'>".$ClientVatNo."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 110px; text-align: right'>".$ClientCreditLimit."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 50px; text-align: center'>".$ClientPaymentTerms."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 75px; text-align: center'>".$ClientCity."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px; text-align: center'>".$ClientEmail."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 110px; text-align: center'>".$ClientHomePage."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 120px; text-align: center'>".$ProfitCenter."</td>";
	if($showBalance == 1){
		$queryBalance = "SELECT IFNULL(GetClientBalance('".$ClientCode."',now(),'".$CostcentCode."','".$Base1."','".$Base1."','".$Base2."',1) ,0) ";
	$resultBalance=mysql_query($queryBalance,$connection) or die(mysql_error());
	$rowBalance=mysql_fetch_array($resultBalance);
	$ClientCurrBalance = $rowBalance[0];
	
	//Get Client Last Transaction
	$queryTrans = "SELECT date_format(Journal_date,'%d/%m/%Y'), Journaldt_desc From JournalDt Where Ledger_Number = '".$ClientCode."' Order By Journal_date desc Limit 1";
	$resultTrans=mysql_query($queryTrans,$connection) or die(mysql_error());
	$rowTrans=mysql_fetch_array($resultTrans);
	$LastTransDate = $rowTrans[0];
	$LastTransDesc = $rowTrans[1];
	echo "<td style='font-family: Time New Roman; font-size: 14px; font-weight: bold; width: 150px; text-align: center'>".$ClientCreationDate."</td>";
	echo "<td style='font-family: Time New Roman; font-size: 14px; font-weight: bold; width: 150px; text-align: right'>".$ClientCurrBalance."</td>";
	echo "<td style='font-family: Time New Roman; font-size: 14px; font-weight: bold; width: 150px; text-align: center'>".$LastTransDate."</td>";
	echo "<td style='font-family: Time New Roman; font-size: 14px; font-weight: bold; width: 190px; text-align: left'>".$LastTransDesc."</td>";
	}
	echo "</tr>";
}
}
else
	if($groupby == 1)
	{
		if($salesman_code== null){
		$query_clients = "select clients.Ledger_number as ClientCode, clients.Ledger_name as ClientName, client_financialno as FiancialNo, salesmen.ledger_name as SalesmanName, 
                  Client_Address as ClientAddress1, Client_Address2 as ClientAddress2, client_address3 as ClientAddress3, Client_Telephone1 as ClientTelephone1, Client_Telephone2 as ClientTelephone2,
				  client_dlvfax as ClientTelephone3, Client_Fax as ClientFax, Client_SellingPrice as ClientSellingPrice, if(Client_VAT = 1, 'Yes', 'No') as ClientVat, Client_VatNo as ClientVatNo,
				  if(Client_CreditLimit <> null or Client_CreditLimit <> '', format(Client_CreditLimit, 2), '') as ClientCreditLimit, Client_PaymentTerms as ClientPaymentTerms, Client_City as ClientCity, client_Email as ClientEmail, Client_homepage as ClientHomePage, ProfitCenter_CODE as ProfitCenter,
				  date_format(Client_CreationDate, '%d/%m/%Y') as ClientCreationDate, if(Client_deactivate = 1, 'No', 'Yes') as ActiveX, Clients.Costcenter_code as CostcentCode
				  from clients left join salesmen on clients.Salesmen_Code = salesmen.ledger_number 
				  where 1=1 ";
if($exportlocal == "local")
{
	$query_clients = $query_clients." and client_local = 1";
}
else
	if($exportlocal == "export")
	{
		$query_clients = $query_clients." and client_export = 1";
	}
if($vat == "yes")
{
	$query_clients = $query_clients." and Client_VAT = 1";
}
else
	if($vat == "no")
	{
		$query_clients = $query_clients." and Client_VAT <> 1";
	}
if($active == "yes")
{
	$query_clients = $query_clients." and Client_deactivate <> 1";
}
else
	if($active == "no")
	{
		$query_clients = $query_clients." and Client_deactivate = 1";
	}
	$query_clients = $query_clients." and clients.salesmen_code is null or salesmen_code = ''";
	echo "<tr style='height: 45px'>
	<td colspan='20' style='font-size: 20px; font-family: Times New Roman; font-weight: bold; text-decoration: underline'>Salesman Name: -</td>
	</tr>";
	$result_clients = mysql_query($query_clients, $connection);
	$number_clients = mysql_num_rows($result_clients);
$count = 0;
while($row_clients = mysql_fetch_array($result_clients))
{
	extract($row_clients);
	$count++;
	if($count % 2 != 0)
	{
		$style="background-color: #b9bbbc";
	}
	else
	{
		$style="background-color: #909090";
	}
	echo "<tr style='".$style."; height: 45px'>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px'>".$ClientCode."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 150px'>".$ClientName."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px; text-align: right'>".$FiancialNo."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px; text-align: center;'>".$ActiveX."</td>";
	if($groupby != 1){
	echo"<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 150px;'>".$SalesmanName."</td>";
	}
	echo"<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientAddress1."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientAddress2."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientAddress3."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientTelephone1."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientTelephone2."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientTelephone3."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientFax."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 50px; text-align: center'>".$ClientSellingPrice."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 40px; text-align: center'>".$ClientVat."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 75px; text-align: center'>".$ClientVatNo."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 110px; text-align: right'>".$ClientCreditLimit."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 50px; text-align: center'>".$ClientPaymentTerms."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 75px; text-align: center'>".$ClientCity."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px; text-align: center'>".$ClientEmail."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 110px; text-align: center'>".$ClientHomePage."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 120px; text-align: center'>".$ProfitCenter."</td>";
	if($showBalance == 1){
		$queryBalance = "SELECT IFNULL(GetClientBalance('".$ClientCode."',now(),'".$CostcentCode."','".$Base1."','".$Base1."','".$Base2."',1) ,0) ";
	$resultBalance=mysql_query($queryBalance,$connection) or die(mysql_error());
	$rowBalance=mysql_fetch_array($resultBalance);
	$ClientCurrBalance = $rowBalance[0];
	
	//Get Client Last Transaction
	$queryTrans = "SELECT date_format(Journal_date,'%d/%m/%Y'), Journaldt_desc From JournalDt Where Ledger_Number = '".$ClientCode."' Order By Journal_date desc Limit 1";
	$resultTrans=mysql_query($queryTrans,$connection) or die(mysql_error());
	$rowTrans=mysql_fetch_array($resultTrans);
	$LastTransDate = $rowTrans[0];
	$LastTransDesc = $rowTrans[1];
	echo "<td style='font-family: Time New Roman; font-size: 14px; font-weight: bold; width: 150px; text-align: center'>".$ClientCreationDate."</td>";
	echo "<td style='font-family: Time New Roman; font-size: 14px; font-weight: bold; width: 150px; text-align: right'>".$ClientCurrBalance."</td>";
	echo "<td style='font-family: Time New Roman; font-size: 14px; font-weight: bold; width: 150px; text-align: center'>".$LastTransDate."</td>";
	echo "<td style='font-family: Time New Roman; font-size: 14px; font-weight: bold; width: 190px; text-align: left'>".$LastTransDesc."</td>";
	}
	echo "</tr>";
}
echo "<tr style='height: 45px'>
<td ";
if($showBalance == 1)
{
	echo "colspan=25";
}
else
{
	echo "colspan=21";
}
echo " style='font-size: 16px; font-weight: bold; font-family: Times New Roman'>Clients Count: ".$number_clients."</td>
</tr>";
		}
		$query_salesmen  = "select Ledger_number as SalesmanCode1, Ledger_name as SalesmanName1 from salesmen where salesmen.ledger_number in (select salesmen_code from clients)";
		if($salesman_code != "")
		{
			$query_salesmen = $query_salesmen." and salesmen.ledger_number = '".$salesman_code."'";
		}
		$result_salesmen = mysql_query($query_salesmen, $connection);
		while($row_salesmen = mysql_fetch_array($result_salesmen))
		{
			extract($row_salesmen);
			echo "<tr style='height: 45px'>
	        <td colspan='20' style='font-size: 20px; font-family: Times New Roman; font-weight: bold; text-decoration: underline'>Salesman Name: ".$SalesmanName1." [".$SalesmanCode1."]</td>
	        </tr>";
			$query_clients = "select clients.Ledger_number as ClientCode, clients.Ledger_name as ClientName, client_financialno as FiancialNo, salesmen.ledger_name as SalesmanName, 
                  Client_Address as ClientAddress1, Client_Address2 as ClientAddress2, client_address3 as ClientAddress3, Client_Telephone1 as ClientTelephone1, Client_Telephone2 as ClientTelephone2,
				  client_dlvfax as ClientTelephone3, Client_Fax as ClientFax, Client_SellingPrice as ClientSellingPrice, if(Client_VAT = 1, 'Yes', 'No') as ClientVat, Client_VatNo as ClientVatNo,
				  if(Client_CreditLimit <> null or Client_CreditLimit <> '', format(Client_CreditLimit, 2), '') as ClientCreditLimit, Client_PaymentTerms as ClientPaymentTerms, Client_City as ClientCity, client_Email as ClientEmail, Client_homepage as ClientHomePage, ProfitCenter_CODE as ProfitCenter,
				  date_format(Client_CreationDate, '%d/%m/%Y') as ClientCreationDate, if(Client_deactivate = 1, 'No', 'Yes') as ActiveX, Clients.Costcenter_code as CostcentCode
				  from clients left join salesmen on clients.Salesmen_Code = salesmen.ledger_number 
				  where 1=1 ";
if($SalesmanCode1 != "")
{
	$query_clients = $query_clients." and clients.Salesmen_Code = '".$SalesmanCode1."'";
}
if($exportlocal == "local")
{
	$query_clients = $query_clients." and client_local = 1";
}
else
	if($exportlocal == "export")
	{
		$query_clients = $query_clients." and client_export = 1";
	}
if($vat == "yes")
{
	$query_clients = $query_clients." and Client_VAT = 1";
}
else
	if($vat == "no")
	{
		$query_clients = $query_clients." and Client_VAT <> 1";
	}
if($active == "yes")
{
	$query_clients = $query_clients." and Client_deactivate <> 1";
}
else
	if($active == "no")
	{
		$query_clients = $query_clients." and Client_deactivate = 1";
	}
$result_clients = mysql_query($query_clients, $connection);
$number_clients = mysql_num_rows($result_clients);
$count = 0;
while($row_clients = mysql_fetch_array($result_clients))
{
	extract($row_clients);
	$count++;
	if($count % 2 != 0)
	{
		$style="background-color: #b9bbbc";
	}
	else
	{
		$style="background-color: #909090";
	}
	echo "<tr style='".$style."; height: 45px'>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px'>".$ClientCode."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 150px'>".$ClientName."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px; text-align: right'>".$FiancialNo."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px; text-align: center;'>".$ActiveX."</td>";
	if($groupby != 1){
	echo "<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 150px;'>".$SalesmanName."</td>";
	}
	echo"<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientAddress1."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientAddress2."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientAddress3."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientTelephone1."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientTelephone2."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientTelephone3."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px;'>".$ClientFax."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 50px; text-align: center'>".$ClientSellingPrice."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 40px; text-align: center'>".$ClientVat."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 75px; text-align: center'>".$ClientVatNo."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 110px; text-align: right'>".$ClientCreditLimit."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 50px; text-align: center'>".$ClientPaymentTerms."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 75px; text-align: center'>".$ClientCity."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 100px; text-align: center'>".$ClientEmail."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 110px; text-align: center'>".$ClientHomePage."</td>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 120px; text-align: center'>".$ProfitCenter."</td>";
	if($showBalance == 1){
		$queryBalance = "SELECT IFNULL(GetClientBalance('".$ClientCode."',now(),'".$CostcentCode."','".$Base1."','".$Base1."','".$Base2."',1) ,0) ";
	$resultBalance=mysql_query($queryBalance,$connection) or die(mysql_error());
	$rowBalance=mysql_fetch_array($resultBalance);
	$ClientCurrBalance = $rowBalance[0];
	
	//Get Client Last Transaction
	$queryTrans = "SELECT date_format(Journal_date,'%d/%m/%Y'), Journaldt_desc From JournalDt Where Ledger_Number = '".$ClientCode."' Order By Journal_date desc Limit 1";
	$resultTrans=mysql_query($queryTrans,$connection) or die(mysql_error());
	$rowTrans=mysql_fetch_array($resultTrans);
	$LastTransDate = $rowTrans[0];
	$LastTransDesc = $rowTrans[1];
	echo "<td style='font-family: Time New Roman; font-size: 14px; font-weight: bold; width: 150px; text-align: center'>".$ClientCreationDate."</td>";
	echo "<td style='font-family: Time New Roman; font-size: 14px; font-weight: bold; width: 150px; text-align: right'>".$ClientCurrBalance."</td>";
	echo "<td style='font-family: Time New Roman; font-size: 14px; font-weight: bold; width: 150px; text-align: center'>".$LastTransDate."</td>";
	echo "<td style='font-family: Time New Roman; font-size: 14px; font-weight: bold; width: 190px; text-align: left'>".$LastTransDesc."</td>";
	}
	echo "</tr>";
}
echo "<tr style='height: 30px'>	
<td ";
if($showBalance == 1)
{
	echo "colspan=25";
}
else
{
	echo "colspan=21";
}
echo " style='font-size: 16px; font-weight: bold;'>Clients Count: ".$number_clients."</td>
</tr>";
		}
	}
echo "</table>
</body>
</html>";
?>