<?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 Salesmen</title>
</head>
<body>
<table width=1500 style='border-collapse: collapse'>
<tr>
<th colspan='10' style=' font-size: 24px; border-bottom: solid 2px #000000'>List of Salesmen</th>
</tr>
<tr style='height: 30px'>
<td colspan='10'></td>
</tr>
<tr>
<th style='width: 150px; font-family: Arial; border-bottom: solid 1px #000000'>Salesman Code</th>
<th style='width: 250px; font-family: Arial; border-bottom: solid 1px #000000'>Salesman Name</th>
<th style='width: 50px; font-family: Arial; border-bottom: solid 1px #000000'>Active</th>
<th style='width: 150px; font-family: Arial; border-bottom: solid 1px #000000'>Address</th>
<th style='width: 150px; font-family: Arial; border-bottom: solid 1px #000000'>Telephone 1</th>
<th style='width: 150px; font-family: Arial; border-bottom: solid 1px #000000'>Telephone 2</th>
<th style='width: 100px; font-family: Arial; border-bottom: solid 1px #000000'>Fax</th>
<th style='width: 150px; font-family: Arial; border-bottom: solid 1px #000000'>Credit Limit</th>
<th style='width: 170px; font-family: Arial; border-bottom: solid 1px #000000'>E-mail</th>
<th style='width: 180px; font-family: Arial; border-bottom: solid 1px #000000'>Creation Date</th>
</tr>";
$query_salesmen = "select Ledger_number as SalesmanCode, Ledger_name as SalesmanName, if(salesmen_deactivate = '1', 'No', 'Yes') as SalesmanActive,
                   Salesman_address as SalesmanAddress, Salesman_Telephone1 as SalesmanPhone1, Salesman_Telephone2 as SalesmanPhone2, Salesman_Fax as SalesmanFax,
				   Salesman_CreditLimit as SalesmanCreditLimit, Salesman_Email as SalesmanEmail, salesman_CreationDate as SalesmanCreationDate
				   from salesmen
				   where 1=1";
if($active != "all")
{
	if($active == 1)
	{
		$query_salesmen = $query_salesmen." and salesmen_deactivate = 0";
	}
	else
	{
		$query_salesmen = $query_salesmen." and salesmen_deactivate = 1";
	}
}


if($salesman_code!= "" && $salesman_code != null)
{
	$query_salesmen = $query_salesmen." and Ledger_number = '".$salesman_code."'";
}
//echo $query_salesmen; exit;
$result_salesmen = mysql_query($query_salesmen, $connection);
$count = 0;
while($row_salesmen = mysql_fetch_array($result_salesmen))
{
	extract($row_salesmen);
	$count++;
	if($count %2 != 0)
	{
	$style="height: 45px; background-color: #b9bbbc";
	}
	else
	{
		$style="height: 45px; background-color: #909090";
	}
	echo "<tr style='$style'>
	<td style='font-family: Time New Roman; font-size: 16px; font-weight: bold; width: 150px'>".$SalesmanCode."</td>
	<td>".$SalesmanName."</td>
	<td>".$SalesmanActive."</td>
	<td>".$SalesmanAddress."</td>
	<td>".$SalesmanPhone1."</td>
	<td>".$SalesmanPhone2."</td>
	<td>".$SalesmanFax."</td>
	<td>".$SalesmanCreditLimit."</td>
	<td>".$SalesmanEmail."</td>
	<td>".$SalesmanCreationDate."</td>
	</tr>";
}
echo "</table>
";

?>