<?php
session_start();

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


$query1="select grid_color1,grid_color2 from setup";
$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

}


$str   		= $_GET['str']; if ($str == ""){$str = $_POST["str"];}
$startrange = $_GET['startrange'];if ($startrange == ""){$startrange = $_POST["startrange"];}
$perpage  	= $_GET['perpage'];if ($perpage == ""){$perpage = $_POST["perpage"];}

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




?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>List of Salesmen</title>
<script type="text/javascript" language="javascript">

function clearform()
{
  document.form1.PLedger_number.value='';
  document.form1.action='List_Salesmen.php';
  document.form1.submit();

}
</script>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
.style1 {
	color: #333333;
	font-weight: bold;
}
.style2 {
	color: #999999;
	font-weight: bold;
}
.style3 {color: #999999}
-->
</style></head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="800" border="0" align="center">
    <tr>
      <th colspan="3" bgcolor="#DDDDDD"><span class="style1"> Salesmen </span></th>
    </tr>
    <tr>
      <td bgcolor="#DDDDDD"> <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for Salesmen <br> Number / Name</span></td>
      <td bgcolor="#DDDDDD" colspan=2><input type="text" name="PLedger_number" value="<?php echo $PLedger_number; ?>"  />
        <input name="code1" type="hidden" id="code1"  value="<?php echo $_GET['lcode']; ?>">
		<input name="com" type="hidden" id="com"  value="<?php echo $_GET['com']; ?>">
		   <input name="str" type="hidden"   value="<?php echo $str; ?>">

     
        <input name="desc1" type="hidden" id="desc1" value="<?php echo $_GET['desc1']; ?>" />
	    <input type="submit" name="Submit" value="Find" style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/>
		<input type="button" name="cancelbtn" value="Cancel" onclick='clearform();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/></td>
   
    </tr>
<?php if($_GET['post']=="1") { ?>
<script type="text/javascript" language="javascript">

var str;
str=document.form1.str.value;


if(str=='1'){
opener.document.clientdt.salesman_code.value=document.form1.code1.value;
opener.document.clientdt.salesman_name.value=document.form1.desc1.value;

opener.document.clientdt.salesman_com.value=document.form1.com.value;


opener.document.clientdt.salesman_code.focus();
}
else if(str=='10'){
    opener.document.clientdt.salesman2_code.value=document.form1.code1.value;
    opener.document.clientdt.salesman2_name.value=document.form1.desc1.value;



    opener.document.clientdt.salesman2_code.focus();
}
else if(str=='20'){
    opener.document.form1.clientsalesman.value=document.form1.code1.value;
    opener.document.form1.clientsalesmanname.value=document.form1.desc1.value;

}

else if(str=='2'){
opener.document.clientdt.competitor_salesman.value=document.form1.code1.value;




}

self.close();

</script>
<?php } ?>
    <tr bgcolor="#E5E5E5">
      <td width="136"><span class="style2">Salesman Number </span></td>
      <td width="411" ><span class="style2">Salesman Name </span></td>
      <td width="57" colspan=1><span class="style2">Commission</span></td>
    </tr>
<?php
	//maroun
$querysalesmen=" select distinct clientsalesmen 
			from ".$_SESSION['dbLabel'].".loginstk ".
			  " where user_account='".$_SESSION['useraccount']."' 
			  and clientsalesmen<>'' 
			  or clientsalesmen <> null
			  "  ;
//echo $querysalesmen;			  
$salesmenresult = mysql_query($querysalesmen,$connection) or die(mysql_error());
$salesmenexist   = mysql_num_rows($salesmenresult);


$query1=" select Ledger_number,Ledger_name, salesman_commission ".
		" from salesmen ";
		


$query1=$query1."where (ledger_number like"."('%".$PLedger_number."%') or ledger_name like"."('%".$PLedger_number."%')) ";

if ($salesmenexist > 0) {
						$query1 = $query1 . " and salesmen.ledger_number in 
															(select distinct clientsalesmen from ".$_SESSION['dbLabel'].".loginstk where user_account = '".$_SESSION['useraccount']."'
															 and (clientsalesmen <>'' and clientsalesmen is not null)
															)";	
	}
	
$query1=$query1." order by Ledger_number";	 

//echo $query1;

$result1=mysql_query($query1,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result1)){
extract($rows);

$ct+=1;

if($ct%2==0)
{
	$Color="style='color:#0000FF;background-color:".$grid_color1."'";
	
	}else{
		
	$Color="style='color:#0000FF;background-color:".$grid_color2."'";	
}

?>
    <tr <?php echo $Color; ?>>
      <td align="left"><a href="List_Salesmen.php?post=1&str=<?php echo $str;?>&lcode=<?php echo $rows[0]; ?>&desc1=<?php echo$rows[1] ?>&com=<?php echo$rows[2]; ?>"><?php echo $rows[0]; ?></a></td>
  <td align="left"><a href="List_Salesmen.php?post=1&str=<?php echo $str;?>&lcode=<?php echo $rows[0]; ?>&desc1=<?php echo$rows[1] ?>&com=<?php echo$rows[2]; ?>"><?php echo $rows[1]; ?></a></td>
    <td align="left"><a href="List_Salesmen.php?post=1&str=<?php echo $str;?>&lcode=<?php echo $rows[0]; ?>&desc1=<?php echo$rows[1] ?>&com=<?php echo$rows[2]; ?>"><?php echo $rows[2]; ?></a></td>
    </tr>
<?php
}

function explodeword($date)
{

$trim = explode('/',$date);
$trim = "$trim[2]"."-"."$trim[1]"."-"."$trim[0]";
return $trim;
}
?>
  </table>
</form>
</body>
</html>
