<?php
session_start();

include("config.inc.php");
include("Functions_Trans.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass'])
		or die("Could not connect to DB");
mysql_select_db($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");


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

}

?>

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

function clearform()
{
  document.form1.PBill_Number.value='';
  document.form1.action='Form_Trans_ListBills.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-size: 12px;
	font-weight: bold;
}
.style3 {color: #999999}
-->
</style></head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="600" border="0" align="center">
    <tr>
      <th colspan="4" bgcolor="#DDDDDD"><span class="style1"> Bills</span></th>
    </tr>
    <tr>
      <td bgcolor="#DDDDDD"> <span style="font-size: 11px; color: #999999; font-weight: bold;">Search for Bills <br> Number / Bank</span></td>
      <td bgcolor="#DDDDDD" colspan='3'><input type="text" name="PBill_Number" value="<?php echo $PBill_Number; ?>"  />
        <input name="code1" type="hidden" id="code1"  value="<?php echo $lcode; ?>">
        <input name="desc1" type="hidden" id="desc1" value="<?php echo $desc1; ?>" />
		<input name="amount" type="hidden" id="amount" value="<?php echo $amount; ?>" />
		<input name="amount1" type="hidden" id="amount1" value="<?php echo $amount1; ?>" />
		<input name="amount2" type="hidden" id="amount2" value="<?php echo $amount2; ?>" />
		<input name="valuedate" type="hidden" id="valuedate" value="<?php echo $valuedate; ?>" />
		<input name="PTransDtId" type="hidden" id="PTransDtId" value="<?php echo $PTransDtId; ?>" />
		<input name="PBillJourDtId" type="hidden" id="PBillJourDtId" value="<?php echo $PBillJourDtId; ?>" />
	    <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($post=="1") { ?>
	
<script type="text/javascript" language="javascript">

opener.document.billjourdt.txtBillNo.value=document.form1.code1.value;
opener.document.billjourdt.txtBank.value=document.form1.desc1.value;
opener.document.billjourdt.txtBillJourDtAmt.value=document.form1.amount.value;
opener.document.billjourdt.txtBillJourDtAmt1.value=document.form1.amount1.value;
opener.document.billjourdt.txtBillJourDtAmt2.value=document.form1.amount2.value;
opener.document.billjourdt.txtBillJourDtAmt_D.value=document.form1.amount.value;
opener.document.billjourdt.txtBillJourDtAmt1_D.value=document.form1.amount1.value;
opener.document.billjourdt.txtBillJourDtAmt2_D.value=document.form1.amount2.value;
opener.document.billjourdt.txtValueDate.value=document.form1.valuedate.value;

self.close();

</script>
<?php } ?>
    <tr bgcolor="#E5E5E5">
      <td width="120"><span class="style2">Bill Number </span></td>
      <td width="200" ><span class="style2">Bank </span></td>
	  <td width="80" align='center'><span class="style2">Value Date </span></td>
	  <td width="100" align='center'><span class="style2">Amount </span></td>
  
    </tr>
<?php



//Select Data From TransDt For Selected Record
$sub_query = " Select TransDt.Ledger_Number, ifNull(Ledger.Ledger_Activity,0), TransDt.Currency_Code, TransDt.Trans_ID ".
			 " From Temp_TransDt As TransDt Left Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
	         " Where TransDt.TransDt_ID = '".$PTransDtId."' ";
					      
//echo $sub_query;
$sub_result = selectData($connection, $sub_query);

$LedgerNumber = $sub_result[0];
$LedgerActivity = $sub_result[1];
$TransDtCurr = $sub_result[2];
$TransID = $sub_result[3];
		
$sub_query1 = " select Bill_increment, Bill_number, Bill_bank, date_format(Bill_ValueDate,'%d/%m/%Y'), Bill_amount, ".
              " convertcurfunc(currency_code, '".$base1."', now(), 0, 0, '', '', Bill_amount) as Bill_amount1, ".
			  " convertcurfunc(currency_code, '".$base2."', now(), 0, 0, '', '', Bill_amount) as Bill_amount2 ".
			  " from Bills ".
              " where ((Journaldt_id2 is null or Journaldt_id2 = 0 or Journaldt_id2 = '') ".
			  " and ledger_number = '".$LedgerNumber."' ".
			  //" and Ledger_Activity = '".$LedgerActivity."' " .
			  " and Currency_code = '".$TransDtCurr."' ".
			  " or Bill_number in ( select Bill_number from billjourdt, transdt where billjourdt.transdt_id=transdt.transdt_id ".
			  " 				    and transdt.trans_id='".$TransID."') ) ".
			  " and Bill_number not in ( select Bill_number from temp_billjourdt,temp_transdt where temp_billjourdt.transdt_id=temp_transdt.transdt_id ".
			  " 						and temp_transdt.trans_id='".$TransID."' ".
			  "                         and temp_billjourdt.billjourdt_ID != '".$PBillJourDtId."' ) ".
			  " and (Bill_number like "."('%".$PBill_Number."%') or Bill_bank like "."('%".$PBill_Number."%')) ".
			  " order by Bill_number ";
			

	

//echo $sub_query1;
$sub_result1=mysql_query($sub_query1,$connection);
while($sub_rows1=mysql_fetch_array($sub_result1)){


$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; 
	
	
	?>>
	
	 <?php
		$desc=ereg_replace("'","%27",$sub_rows1[2]);
		?>
		
		
     <td align="left"><a href="Form_Trans_ListBills.php?valuedate=<?php echo $sub_rows1[3];?>&amount2=<?php echo $sub_rows1[6];?>&amount1=<?php echo $sub_rows1[5]; ?>&amount=<?php echo $sub_rows1[4];?>&post=1&lcode=<?php echo $sub_rows1[1];?>&desc1=<?php echo $desc;?>"><?php echo $sub_rows1[1]; ?></a></td>
     <td ><?php echo $sub_rows1[2]; ?></td>
	 <td ><?php echo $sub_rows1[3]; ?></td>
	 <td align='right'><?php echo number_format($sub_rows1[4], $DecimalBase); ?></td>
	</tr>
	
<?php }?>
  </table>
</form>
</body>
</html>
