<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");
include 'function.inc.php';

print <<< HERE
<HTML>
<HEAD>
<TITLE> List of Salesmen </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">

<style type="text/css">
	
.data{
	
	 FONT-WEIGHT: normal;
	 FONT-SIZE: 8pt;	 
	
	 FONT-FAMILY: arial, sans-serif;
	}

.header{
	
	 FONT-WEIGHT: bold;
	 FONT-SIZE: 9pt;	 
	
	 FONT-FAMILY: arial, sans-serif;
	}
	
.footerbox{
				
							   
	border-left: 0 solid #000000; border-top: 1 solid #000000; border-bottom: 0 solid #000000;
	FONT-WEIGHT: bold;
	FONT-SIZE: 14px;	 
	 color:#2D2D2D;
	  font-family:Times-New-Roman;
	 BACKGROUND-COLOR: #FFFFFF; 
	
	 height: 20;
	 	}
		
</style>





</HEAD>

<BODY>
HERE;


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

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}

$querysetup=" select report_color1, report_color2 from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultsetup)){
  extract($rows);
} 

$query_login="select login_belongstogrp from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlogin=mysql_query($query_login,$connection) or die(mysql_error());

$row_login=mysql_fetch_row($resultlogin);
$belongstogroup=$row_login[0];

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;
}


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



echo "<table border=0 width='100%' cellspacing=0 cellpadding=0  style='table-layout:fixed;' >
		<col width=10%> 
		<col width=25%> 
		<col width=10%> 
		<col width=5%> 
		<col width=8%> 
	<col width=42%>
		";
	
	echo "<tr><td height='60' colspan=2><img src='img/imgheader1.jpg' width='115' height='50' /></td><td colspan=3 align='center'><b><font size=5><u>List of Salesmen</u></font></td>
				<td align='right' colspan=2><font size='2'><b>Printed&nbsp;Date&nbsp;&amp;&nbsp;Time:</b>&nbsp;&nbsp;";
	echo $printdate[2]."/".$printdate[1]."/".$printdate[0];
	echo "<br>".$dt[1]." ".$dt[2];
	echo "</font></td></tr>";
	
	echo"</td></tr>";
	
	
	echo"
		
	
		";
	echo"<tr height=20px></tr>";
	echo "<tr height=30px>";
	echo "<td align='left'  class='header' 	style='border-top: 2 solid #000000; border-bottom: 1 solid #000000' >Code</td>";
	echo "<td align='left'  class='header' 	style='border-top: 2 solid #000000; border-bottom: 1 solid #000000'>Name</td>";

	echo "<td align='left'  class='header'  style='border-top: 2 solid #000000; border-bottom: 1 solid #000000'>Credit Limit</td>";
	echo "<td align='center'  class='header'  style='border-top: 2 solid #000000; border-bottom: 1 solid #000000'>Cur</td>";
	echo "<td align='center'  class='header'  style='border-top: 2 solid #000000; border-bottom: 1 solid #000000'>Area</td>";
	echo "<td align='left'  class='header'  style='border-top: 2 solid #000000; border-bottom: 1 solid #000000'>Address</td>";

	echo"</tr>";
	echo"<tr height=10px></tr>";
	

	
	
	$query_salesmen="select ledger_number,
							ledger_name,
							Salesman_CreditLimit,
							Currency_Code,
							Area_Code,
							Salesman_address
							
						 from salesmen
							where ifNull(Salesman_BelongsToGroup,0) >= ".$belongstogroup."
							order by ledger_number";
	
	//echo$query_salesmen;
	
		$result_salesmen=mysql_query($query_salesmen,$connection) or die(mysql_error());
		
		$totalrecords=mysql_num_rows($result_salesmen);
		//echo  $totalrecords;
		$col=0;
		while($row=mysql_fetch_row($result_salesmen)){
			
			if($col%2==0){
				$color = "style='background-color:".$report_color1."'";
			}else{
				$color = "style='background-color:".$report_color2."'";
			}
			echo"<tr $color>
					<td class='data' valign='top'  style='border-right:1px solid black; padding-left:2px;'>$row[0] &nbsp;</td>
					<td class='data' valign='top'  style='border-right:1px solid black; padding-left:2px;'>$row[1] &nbsp;</td>
					<td class='data' valign='top' align=right  style='border-right:1px solid black; padding-right:2px;'>$row[2] &nbsp;</td>
					<td class='data' valign='top' align=center  style='border-right:1px solid black; '>$row[3] &nbsp;</td>
					<td align=center class='data' valign='top'  style='border-right:1px solid black; padding-left:2px;'>$row[4] &nbsp;</td>
					<td align='left' class='data' valign='top'  style='border-right:1px solid black; padding-left:2px;'>$row[5] &nbsp;</td>
				</tr>";
			$col+=1;
		}
		
 echo" <tr>
        <td height='1' align='left' colspan='11' class='footerbox'>Total Records: $totalrecords</td>
    </tr>";
	echo "</table>";


print <<< HERE

<script language=javascript>
if (typeof(window.print) != 'undefined')
{
    window.print();
}
</script>
</BODY>
</HTML>
HERE;
?>


