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

$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);
}
$index 	   	= $_GET['index']; if ($index == ""){$index = $_POST["index"];}
//echo "test";
$queryledger= " select distinct ledger_number, ledger_include ".
              " from ".$_SESSION['dbLabel'].".ledgerstk  ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " order by ledger_number";
$ledgerresult = mysql_query($queryledger,$connection) or die(mysql_error());
$ledgerexist  = mysql_num_rows($ledgerresult);	
$rows=mysql_fetch_array($ledgerresult) ;
$ledgerinclude = $rows[1];

$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2 from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}



print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>$title</title>
<script type="text/javascript" language="javascript">




function clearform()
{
  document.search.PRef.value='';
  document.search.action='List_Checkss.php';
  document.search.submit();

}

function LoadForm() 
{
	x=document.search;
	x.PRef.focus();
	

}

function SetNextPage(startrange,perpage){
	document.search.action='List_Agents_orderbycode.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function SetPrvPage(startrange,perpage){
	document.search.action='List_Agents_orderbycode.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}




function Viewclient(value1,value2){



opener.document.clientdt.agent_code.value=value1;
opener.document.clientdt.agent_name.value=value2;
opener.document.clientdt.keepcompany.value=1;
opener.clientdt.submit();


self.close();
}
function chkFilterByPer(){
	if(document.getElementById('chk_filter_by_per').checked){
		document.getElementById('filter_by_per').value = 1;
	}
	else{
		document.getElementById('filter_by_per').value = 0;
	}
}


function fillfield(value1,value2,value3,value4,value5,value6,value7,value8,value9,value10,value11,value12,value13){

	var str     = document.search.str.value;
	var vIndex	= document.search.index.value;
		var desc=value6.concat(" - Chk No . ").concat(value12);

	if(value13==0){
		
		opener.document.getElementById('ledgernumber['+vIndex+']').value=value1;
		opener.document.getElementById('ledgername['+vIndex+']').value=value2;
		opener.document.getElementById('currencycode['+vIndex+']').value=value4;
		opener.document.getElementById('journaldtactivity['+vIndex+']').value=value5;
		opener.document.getElementById('journaldtdesc['+vIndex+']').value=desc;
		
		opener.document.getElementById('journaldtamount['+vIndex+']').value=value7;
		opener.document.getElementById('journaldtvaluedate['+vIndex+']').value=value8;
		opener.document.getElementById('journaldtamount1['+vIndex+']').value=value9;
		opener.document.getElementById('journaldtamount2['+vIndex+']').value=value10;
		opener.document.getElementById('journaldtdbcd['+vIndex+']').value=value11;
		opener.document.getElementById('ChecksNo').value=1;	
		opener.document.getElementById('vChecksNo').value=value12;
		opener.document.getElementById('ledgernumber['+vIndex+']').focus();
		
		//opener.document.getElementById('chkjourbank[0]').value=value6;
		//opener.document.getElementById('imgSubmit_C[0]').click();
		opener.document.getElementById('imgSubmit['+vIndex+']').click();
		
		
		
	}else{
		opener.document.getElementById('ledgernumber['+vIndex+']').value=value1;
		opener.document.getElementById('ledgername['+vIndex+']').value=value2;
		opener.document.getElementById('currencycode['+vIndex+']').value=value4;
		opener.document.getElementById('journaldtactivity['+vIndex+']').value=value5;
		
		
		opener.document.getElementById('ledgernumber['+vIndex+']').focus();
		
		
	}

	
	

	self.close();
	
}



</script>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}

a:visited {
	text-decoration: none;
	color: #0000FF;
}


.style11 {color: #999999; font-weight: bold; }
.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; }
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #000000 ;font-size: 10px;}

</style>

</head>
<body >
<form name='search' method='post' action=''>
<input type='hidden' name='str'  value='$str'>

HERE;

echo"<input type='hidden' name='index' value='".$index."'>";
echo"<input type='hidden' name='CashBank' value='".$CashBank."'>";
echo"<input type='hidden' name='TransType' value='".$TransType."'>";
if($filter_by_per == "") { 
$filter_by_per = 1;
}
if($filter_by_per == 1){
	$checked = "checked";
}
else{
	$checked = "";
}
echo"<table border='0' style='table-layout:fixed'>

	  <col width=3%>
	  <col width=10%>
	  <col width=10%>
	  <col width=35%><col width=10%><col width=10%><col width=10%>
	
		     
	  <tr bgcolor='#DDDDDD'>
	    <td align='center' colspan='4'><span class='style16'>$label</span></td></tr>
	  <tr bgcolor='#DDDDDD' height=30px>
	    <td align='left' colspan='2'><span class='style11'>Search by Check No</span></td>
		<td align='left' colspan='5'><span class='style11'><input type='hidden' name='filter_by_per' id='filter_by_per' value='$filter_by_per' /><input type='text' name='PRef' id='PRef' value='$PRef' size='15' maxlength='30'/><input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30'/></span><form method='POST'>
		    <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='btnCancel' value='Cancel' onclick='clearform();'style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'/></form></td>
		";
echo" </tr>
	  <tr bgcolor='#DDDDDD'>
		<td height='15' align='center' colspan='7'><font size='1' color='#FF0000' face='Verdana'><b>".$message."</b></font></td>
	  </tr>	
	  <tr bgcolor='#CCD8E6'>
	  
	
		<td  height='25' align='left' width=10% colspan=2><span class='style25'>Check No </span></td>
		<td  height='25' align='left' width=10% colspan=><span class='style25'>Ledger No </span></td>
		<td  height='25' align='center'><span class='style25'>Ledger Name </span></td>
		<td  height='25' align='center'><span class='style25'>Bank Name </span></td>
		<td  height='25' align='center'><span class='style25'>Amount </span></td>
		<td  height='25' align='center'><span class='style25'>Date </span></td>
		
		
	  </tr>";
		

	

	



		

$querysearch="select Chk_number,checks.ledger_number,ledger.Ledger_name,Chk_bank,Chk_amount,checks.Currency_code,DATE_FORMAT(Chk_ValueDate,'%d/%m/%Y'),Chk_amount1,Chk_amount2,(case when ledger.Ledger_activity=1 then 'C' else 'D' END) from checks inner join ledger on checks.Ledger_number=ledger.Ledger_number AND (Journaldt_id2 IS NULL or Journaldt_id2=0) and checks.ledger_activity=1 ";
$searchId=$_POST["PRef"];
if (isset($_POST["Submit"])){
	IF($searchId!="") $querysearch=$querysearch."and (Chk_number like '%$searchId%' or checks.ledger_number  like '%$searchId%' or ledger.Ledger_name like '%$searchId%' or Chk_bank like '%$searchId%' )";
	
}
//echo $querysearch;
$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());		


while($rows=mysql_fetch_array($resultsearch)){
		
	extract($rows);
	$ct+=1;

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




$desc=ereg_replace("'","%27",$rows[1]);

  echo"<tr $Color>";
  
  print<<<HERE
      <td align='left' colspan=2><a onclick="fillfield('$rows[1]','$rows[2]','$rows[3]','$rows[5]','$rows[4]','$rows[3]','$rows[4]','$rows[6]','$rows[7]','$rows[8]','$rows[9]','$rows[0]','0');" href='#'>$rows[0]</a></td>
      <td align='left'><a onclick="fillfield('$rows[1]','$rows[2]','$rows[3]','$rows[5]','$rows[4]','$rows[3]','$rows[4]','$rows[6]','$rows[7]','$rows[8]','$rows[9]','$rows[0]','0');" href='#'>$rows[1]</a></td>
	  
      <td ><a onclick="fillfield('$rows[1]','$rows[2]','$rows[3]','$rows[5]','$rows[4]','$rows[3]','$rows[4]','$rows[6]','$rows[7]','$rows[8]','$rows[9]','$rows[0]','0');" href='#'>$rows[2]</a></td>
	  <td ><a onclick="fillfield('$rows[1]','$rows[2]','$rows[3]','$rows[5]','$rows[4]','$rows[3]','$rows[4]','$rows[6]','$rows[7]','$rows[8]','$rows[9]','$rows[0]','0');" href='#'>$rows[3]</a></td>
	  <td ><a onclick="fillfield('$rows[1]','$rows[2]','$rows[3]','$rows[5]','$rows[4]','$rows[3]','$rows[4]','$rows[6]','$rows[7]','$rows[8]','$rows[9]','$rows[0]','0');" href='#'>$rows[4]  $rows[5]</a></td>
	   <td ><a onclick="fillfield('$rows[1]','$rows[2]','$rows[3]','$rows[5]','$rows[4]','$rows[3]','$rows[4]','$rows[6]','$rows[7]','$rows[8]','$rows[9]','$rows[0]','0');" href='#'>$rows[6]</a></td>
     
    </tr>
	
	
	

HERE;
}
							
//<td height="20" align="left"><a href="#" onClick="SelectRef('.$Purchase_ID.');" class="style15"><span class="style15 style17" style="text-decoration:underline;">'.$Purchase_Reference.'</span></a></td>			
			
		
echo"   <tr><td colspan='7'>&nbsp;</td></tr>
		<tr><td colspan=7><table width='100%' border=0><tr><td width='260'>&nbsp;</td><td width='150' align='center'>
		<col width=20%>
	  <col width=50%>
	  <col width=30%>
	  <col width=30%>
	  <col width=30%>";
		
		$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			$prvstartrange = $startrange - $perpage;
			
		}
		else
			echo "&nbsp;";
		
		echo"</td><td width='150' align='center'>";
		
		
		if ($startrange <= $totalrows){
			$startrange = $startrange + $perpage;
			if  ($startrange <= $totalrows);
				
		} else
			echo "&nbsp;";
			
		echo"</td><td width='170'>&nbsp;</td></tr>";
		echo"<table>";

echo"</td></tr></table>";
	


          

		  

print <<<HERE
</form>
</body>

HERE;

?>