<?php
session_start();

include("config.inc.php");
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
$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);
}
$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);

}

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

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

if($_GET['lcode']!="") { 

	$query1="select Ledger_number, Ledger_name from ledger where ledger_number='".$_GET['lcode']."'";
    $result1=mysql_query($query1,$connection) or die(mysql_error());
	while($rows=mysql_fetch_array($result1)){
    	extract($rows);
		
	}

    $_GET['post']="1";
}

?>

<!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>Select Ledgers</title>
<script type="text/javascript" language="javascript">

function clearform()
{
	document.form1.PLedger_Name.value='';
	document.form1.PLedger_Number.value='';
	document.form1.action='List_Ledgers.php';
	document.form1.submit();
}
</script>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.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="700" border="0" align="center">
    <tr>
      <th colspan="5" bgcolor="#DDDDDD"><span class="style1"> Ledgers </span></th>
    </tr>
    <tr>
      <td bgcolor="#DDDDDD" width="136"> <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for Ledger  <br> Number / Name</span></td>
      <td bgcolor="#DDDDDD" width="100"><input type="text" name="PLedger_Number" value="<?php echo $PLedger_Number; ?>"  />
        <input name="code1" type="hidden" id="code1"  value="<?php echo $Ledger_number; ?>"></td>
      <td bgcolor="#DDDDDD" width="450"><input type="text" name="PLedger_Name"  value="<?php echo $PLedger_Name; ?>" size='35'/>
	    <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;'/>
        <input name="desc1" type="hidden" id="desc1" value="<?php echo $Ledger_name; ?>" />
        <input name="item" type="hidden" id="item" value="<?php echo $item; ?>" /></td>
    </tr>
<?php if($_GET['post']=="1") { ?>
<script type="text/javascript" language="javascript">
x=document.form1;
item1=x.item.value;
if(item1=="1"){
opener.document.purchasecharges.txtLedgerNoDebit.value   = document.form1.code1.value;
opener.document.purchasecharges.txtLedgerDescDebit.value = document.form1.desc1.value;
self.close();
}else if(item1=="2"){
opener.document.purchasecharges.txtLedgerNoCredit.value   = document.form1.code1.value;
opener.document.purchasecharges.txtLedgerDescCredit.value = document.form1.desc1.value;
self.close();
}
else if(item1=="3"){
opener.document.purchaseordercharges.txtLedgerNoDebit.value   = document.form1.code1.value;
opener.document.purchaseordercharges.txtLedgerDescDebit.value = document.form1.desc1.value;
self.close();
}else if(item1=="4"){
opener.document.purchaseordercharges.txtLedgerNoCredit.value   = document.form1.code1.value;
opener.document.purchaseordercharges.txtLedgerDescCredit.value = document.form1.desc1.value;
self.close();
}
else if (item1=="5"){
opener.document.transfercharges.txtLedgerNoDebit.value   = document.form1.code1.value;
opener.document.transfercharges.txtLedgerDescDebit.value = document.form1.desc1.value;
self.close();
}
else if (item1=="6"){
opener.document.transfercharges.txtLedgerNoCredit.value   = document.form1.code1.value;
opener.document.transfercharges.txtLedgerDescCredit.value = document.form1.desc1.value;
self.close();
}
else if (item1=="7"){
opener.document.Setup.Ledger_NumberDebit11.value   = document.form1.code1.value;
self.close();
}
else if (item1=="8"){
opener.document.Setup.Ledger_numberCredit11.value   = document.form1.code1.value;
self.close();
}
else if (item1=="9"){
opener.document.Setup.Ledger_NumberDebit18.value   = document.form1.code1.value;
self.close();
}
else if (item1=="10"){
opener.document.Setup.Ledger_numberCredit18.value   = document.form1.code1.value;
self.close();
}
else if (item1=="12"){
opener.document.Setup.debitledger.value   = document.form1.code1.value;
opener.document.Setup.debitledgerdesc.value = document.form1.desc1.value;
self.close();
}



</script>
<?php } ?>
    <tr bgcolor="#E5E5E5">
      <td><span class="style2">Ledger Number </span></td>
      <td colspan="2"><span class="style2">Ledger Name </span></td>
    </tr>
<?php
$query1=" select Ledger_number, Ledger_name from ledger ".
        " where Ledger_number like '".$PLedger_Number."%' ".
		" and Ledger_name like '%".$PLedger_Name."%' ".
		" and ifnull(Ledger_grpdet,0) = 0 ".
		" order by ledger_number ";

$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_Ledgers.php?lcode=<?php echo $Ledger_number; ?>&item=<?php echo $item; ?>"><?php echo $Ledger_number; ?></a></td>
      <td align="left" colspan="2"><a href="List_Ledgers.php?lcode=<?php echo $Ledger_number; ?>&item=<?php echo $item; ?>"><?php echo $Ledger_name; ?></a></td>
    </tr>
<?php
}
?>
  </table>
</form>
</body>
</html>
