<?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");
include("Functions_Trans.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);
}

$fromdate   =$_POST["fromdate"];
$todate     =$_POST["todate"];

$querydate="select search_startingdate from setup";
$resultdate=mysql_query($querydate,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdate)){
	extract($rows);
}	
$MainCompanyName=explode('_',$_SESSION['dbName']); 
$QueryDir = " Select Date_Format(StartFinancialDate,'%d/%m/%Y') 
			From ".$_SESSION['dbLabel'].".Directories ". 	
			" Where  Upper(CompanyName) = Upper('".$MainCompanyName[0]."') ".
			" and Upper(Diryear) = Upper('".$MainCompanyName[1]."') ";
//echo $QueryDir;			
$ResultDir=mysql_query($QueryDir,$connection) or die(mysql_error());   
$RowsDir=mysql_fetch_row($ResultDir);
$StartFinancialDate = $RowsDir[0];


if ($fromdate == '') {
if ($search_startingdate == '-1') {
	$fromdate = $StartFinancialDate;
}

else if($search_startingdate == '0') {
	$fromdate = date('01/m/Y');
}

else if($querydate > '0') {
	$added_timestamp = strtotime('-'.$search_startingdate.' month', time());

	$fromdate = date('01/m/Y', $added_timestamp); 
}
}

if ($todate == '')
	$todate =  date('d/m/Y');



if ($perpage == '' ) $perpage = $config['trowlimit'][0];

$querylog=" select ifNull(FA_PaymentDel,0) As FA_PaymentDel, ifNull(FA_PaymentMod,0) As FA_PaymentMod, ".
		  " ifNull(FA_ReceiptDel,0) As FA_ReceiptDel, ifNull(FA_ReceiptMod,0) As FA_ReceiptMod, ".
		  " ifNull(FA_CreditNoteDel,0) As FA_CreditNoteDel, ifNull(FA_CreditNoteMod,0) As FA_CreditNoteMod, ".
		  " ifNull(FA_DebitNoteDel,0) As FA_DebitNoteDel, ifNull(FA_DebitNoteMod,0) As FA_DebitNoteMod, ".
		  " ifNull(FA_ContraDel,0) As FA_ContraDel, ifNull(FA_ContraMod,0) As FA_ContraMod, ifnull(Trans_ModAfterPost,0) as afterpost, ".
          " ifNull(login_belongstogrp,0) As FI_BelongsToGrp, ifNull(ShowTransaction,0) As ShowTransaction, ifnull(FA_ReceiptApp,0) as FA_ReceiptApp ".
          " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ifNull(Module_ProjectParent,0) As Module_ProjectParent, ".
			 " ifNull(Module_CostCenterParent,0) As Module_CostCenterParent, ifNull(Module_BelongsToGroup,0) As Module_BelongsToGroup, ".
			 " ifnull(Module_AcctrxPostPV,0) as Module_AcctrxPostPV, ifnull(Module_AcctrxPostRV,0) as Module_AcctrxPostRV, ifnull(Module_AcctrxPostDV,0) as Module_AcctrxPostDV, ".
			 " ifnull(Module_AcctrxPostCV,0) as Module_AcctrxPostCV ".
			 " From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}


//Access Mode On Insert/Edit/Delete
$DelMode  =1;
$EditMode =1;
$PrevMode =1;

$PrevHint   = '';
$EditHint   = '';
$DelHint    = '';

$Title = '';
if ($TransType == 'PV') {
	$Title = 'Payment'; 
	$FA_Del = $FA_PaymentDel;
	$FA_Mod = $FA_PaymentMod;
	$FA_App = '';
	if ($Module_AcctrxPostPV == 1) $ModPost = 1;
}	
else if ($TransType == 'RV') {
	$Title = 'Receipt';      
	$FA_Del = $FA_ReceiptDel;
	$FA_Mod = $FA_ReceiptMod;
	$FA_App = $FA_ReceiptApp;
	if ($Module_AcctrxPostRV == 1) $ModPost = 1;
}	
else if ($TransType == 'CV') {
	$Title = 'Credit Note';  
	$FA_Del = $FA_CreditNoteDel;
	$FA_Mod = $FA_CreditNoteMod;
	$FA_App = '';
	if ($Module_AcctrxPostDV == 1) $ModPost = 1;
}	
else if ($TransType == 'DV') {
	$Title = 'Debit Note';   
	$FA_Del = $FA_DebitNoteDel;
	$FA_Mod = $FA_DebitNoteMod;
	$FA_App = '';
	if ($Module_AcctrxPostCV == 1) $ModPost = 1;
}	
else if ($TransType == 'CT') {
	$Title = 'Contra';   
	$FA_Del = $FA_ContraDel;
	$FA_Mod = $FA_ContraMod;
	$FA_App = '';
	$ModPost = 0;
}


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

$MainCompanyName=explode('_',$_SESSION['dbName']);

$queryperiod= " Select ifNull(LockViewPeriod,0) As LockViewPeriod, ViewPeriodDate, ifNull(ViewLockDaily,0) As ViewLockDaily, ViewNumberOfDays, ifNull(AllowLockedPeriod,0) As AllowLockedPeriod, ".
			  " LockedPeriod As LockedPeriodDate, LockedPeriodDays As LockedPeriodDays,FI_login_ViewDocument as FI_login_ViewDocument ".
              " From ".$_SESSION['dbLabel'].".ListUserDir  ".
			  " Where Usercode='".$_SESSION['useraccount']."' ".
			  " And Upper(CompanyName) = Upper('".$MainCompanyName[0]."') ".
			  " And Upper(Diryear) = Upper('".$MainCompanyName[1]."') ";
			  
$resultperiod = mysql_query($queryperiod,$connection) or die(mysql_error());
$rowsperiod   = mysql_num_rows($resultperiod);

while($rows=mysql_fetch_array($resultperiod)){
	extract($rows);
}	
			  
//echo $queryperiod;	

$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$_SESSION['dbLabel'].".loginstk on (($Module_ProjectParent=1 and project.project_code like concat(ifnull(loginstk.project_code,project.project_code),'%')) or ($Module_ProjectParent=0 and project.project_code = loginstk.project_code )) ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " and (loginstk.project_code is not null and loginstk.project_code != '') ".
			  " order by project.project_code";
$projectresult = mysql_query($queryproject,$connection) or die(mysql_error());
$projectexist  = mysql_num_rows($projectresult);		  

$querycostcent=" select distinct costcent.costcent_code, costcent_name ".
               " from costcent left join ".$_SESSION['dbLabel'].".loginstk on (($Module_CostCenterParent=1 and costcent.costcent_code like concat(ifnull(loginstk.costcent_code,costcent.costcent_code),'%')) or ($Module_CostCenterParent=0 and costcent.costcent_code = loginstk.costcent_code )) ".
			   " where user_account='".$_SESSION['useraccount']."' ".
			   " and (loginstk.costcent_code is not null and loginstk.costcent_code != '') ".
			   " order by costcent.costcent_code";
$costcentresult = mysql_query($querycostcent,$connection) or die(mysql_error());
$costcentexist  = mysql_num_rows($costcentresult);		  

$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];


//Get Default Project
$querydflproject="select project_code as defaultproject from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_project=1 ";
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
	extract($rows);
}
	
//Get Default Coscenter
$querydflcostcent="select costcent_code as defaultcostcent from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_costcenter=1 ";
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflcostcent)){
	extract($rows);
}


$queryset = "select distinct ifnull(show_prqstref,0) as show_prqstref from transsetup where journaltype = 'PV';";
$resset = mysql_query($queryset,$connection);
while($rows=mysql_fetch_array($resset)){
	extract($rows);
}

if ((!isset($PProjectCode)) && $Module_Project == 1)
	$PProjectCode = $defaultproject;
if ((!isset($PCostCentCode)) && $Module_CostCenter == 1)	
	$PCostCentCode = $defaultcostcent;	

if (empty($orderby)) $orderby = 1;
if (empty($searchby)) $searchby = 2;
	
if ($startrange=='')
	$startrange = 0;
if ($perpage=='')
	$perpage = 20;

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" />
<link rel="stylesheet" type="text/css" media="all" href="css/style.css">
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<title>Search $Title</title>
<script type="text/javascript" language="javascript">

function clearform()
{
  var vTransType = document.search.TransType.value;	
  document.search.keyword.value='';
  document.search.PProjectCode.value='';
  document.search.PCostCentCode.value='';
  document.search.fromdate.value='';
  document.search.todate.value='';
 
  document.search.action='Form_TransSearch.php?TransType='+vTransType;
  document.search.submit();

}

function LoadForm() 
{
	x=document.search;
	x.keyword.focus();
	
	ChangeLocation();
}

function SetNextPage(startrange,perpage){ 
    var vTransType = document.search.TransType.value;	
	
	document.search.action='Form_TransSearch.php?TransType='+vTransType+'&keyword=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}

function SetPrvPage(startrange,perpage){
    var vTransType = document.search.TransType.value;
	
	document.search.action='Form_TransSearch.php?TransType='+vTransType+'&keyword=&startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}


function DeleteRecord(TransId, TransRef){
	var vTransType = document.search.TransType.value;
	
	if (TransId != '') {
		if (confirm ( "Are you sure you want to Delete this record with reference = "+TransRef+" ?") )
		{
			document.search.action="Form_Trans_Actions.php?TransType="+vTransType+"&mainmode=delete&STransId="+TransId;
			document.search.submit();
		}
	}
	
}

function UploadDocuments(vform,txtPorId){



	win = window.open('UploadDocuments.php?vform='+vform+'&prqstid='+txtPorId +'&readonly=readonly', 'Upload', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=990,height=600,top=60,left=100');		
	  win.creator = self;
	  win.focus();	 
  
  }

function ConfirmTrans(TransId, TransRef){
	var vTransType = document.search.TransType.value;
	
	if (TransId != '') {
		if (confirm ( "Are you sure you want to Approve this record with reference = "+TransRef+" ?") )
		{
			document.search.action="Form_Trans_Actions.php?TransType="+vTransType+"&mainmode=ConfirmTrans&STransId="+TransId;
			document.search.submit();
		}
	}
	
}

function UpdateRecord(TransId){
	var vTransType = document.search.TransType.value;
	
	document.search.action="Form_Trans_Actions.php?TransType="+vTransType+"&mainmode=search&STransId="+TransId;
	document.search.submit();
	
	document.search.PMode.value=1;
	
	opener.document.trans.txtTransId.value=TransId;
	opener.document.trans.mainaction.value='edit';
	opener.document.trans.actionmode.value='';
	
	//opener.document.trans.action='Form_Trans.php';
	//opener.document.trans.submit();
	
	
	//self.close();
	

}



function PrintPreview(TransId,exp)
{	var hide='';
	if(document.getElementById('hide').checked)
	hide=1;
	else hide=0;
	var str = '';
	var vTransType = document.search.TransType.value;
	var cashtype_code = document.search.cashtype_code.value;
	var bank=document.search.bank.value;
	if (cashtype_code=='Cash')
	str = 'Form_Trans_CashPreview.php?hide='+hide+'&TransId='+TransId+'&TransType='+vTransType+'&bank='+bank;
	else 
	str = 'Form_TransPreview.php?TransId='+TransId+'&TransType='+vTransType+'&bank='+bank+'&exp='+exp;
	window.open(str);
	
	

}

function ShowHideDetails(TransId, Option, startrange) {
	/*if (Option == 'S') {
		document.search.SelectedID.value = TransId;
		document.search.action='Form_TransSearch.php?startrange='+startrange+'&SelectedID='+TransId;
	}
	else if (Option == 'H') {
		document.search.SelectedID.value = '';
		document.search.action='Form_TransSearch.php?startrange='+startrange;
	}	
	
	document.search.submit();*/
	
	vSlideDivId = '#displaydetails'+TransId;
	$(vSlideDivId).slideToggle();
}

function ChangeLocation()
{
	var vTransType = document.search.TransType.value;
	
    if (document.search.PMode.value == 1) {
		opener.document.trans.message.value = document.search.message.value;
		opener.document.trans.action='Form_Trans.php?TransType='+vTransType;
		opener.document.trans.submit();
		self.close();
	}	
}

function showlistProject(str){

  window.open('List_SorProject.php?frm=6&item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistCostcenter(str){

  window.open('List_SorCostcenter.php?frm=6&item='+str,'mywindow','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}



function RefreshPage()
{
	document.search.action='Form_TransSearch.php?startrange=0';
	document.search.submit();
}

function SelectSearchBy()
{	
  
  //document.search.keyword.value='';
  //document.search.action='Form_TransSearch.php';
  document.search.submit();

}

function SubmitForm()
{	
  
  //document.search.keyword.value='';
  document.search.action='Form_TransSearch.php?startrange=0';
  document.search.submit();

}

function kd(e)
{
	x=document.search;
    var intKey = (window.Event) ? e.which : e.keyCode;
	
    if (intKey == 13) { //enter key
        x.btnSubmit.click();
		return false;
    }
    return true;
}

function SetFirstPage(startrange,perpage){
	document.search.action='Form_TransSearch.php?startrange=0&perpage='+perpage;
	document.search.submit();
}

function SetLastPage(perpage,totalrows){
	var result=totalrows % perpage;
	if (result == 0) result = perpage;
	startrange=totalrows-result;
	document.search.action='Form_TransSearch.php?startrange='+startrange+'&perpage='+perpage;
	document.search.submit();
}
function showAllDetails(){ 
	if (document.search.showDetails.checked) {
		$('.slideAll').slideDown();
	}else{
		$('.slideAll').slideUp();
	}
}
function setShowPre(){
	if(document.getElementById('showPreReceipts').checked)
		document.getElementById('showPreReceipts').value='1';
	else document.getElementById('showPreReceipts').value='0';
}
</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:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}

.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>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>
</head>
<body onLoad='LoadForm();' class='bodybackground'>
<form name='search' method='post' action="">
<input type='hidden' name='TransType' value='$TransType' >

HERE;
	
echo "<input type='hidden' name='message' value='".htmlspecialchars($message, ENT_QUOTES)."'>";

$PRef = GetSQLValueString($keyword, 'text');

if (empty($ViewPeriodDate))
   $ViewPeriodDate = 'Null';
if (empty($ViewNumberOfDays))   
   $ViewNumberOfDays = 1;
			 
$querysearch=" Select Distinct Trans.Trans_ID, Trans.Trans_Reference, Date_Format(Trans.Trans_Date,'%d-%m-%Y') As Trans_Date, ".
             " Trans.Trans_Type, Trans.Trans_Remark, Trans.Trans_Representative, Trans.Trans_CashReference, Trans.CashType_code, ".
			 " Trans.Trans_ManualNo, Project.Project_Name As ProjectName, Costcent.Costcent_name As CostcentName, ".
			 " Round(ifNull(Trans.Trans_AmountDb1,0), ".$DecimalBase1.") as Trans_AmountDb1, Round(ifNull(Trans.Trans_AmountDb2,0), ".$DecimalBase2.") as Trans_AmountDb2, ".
			 " Round(ifNull(Trans.Trans_Amountcd1,0), ".$DecimalBase1.") as Trans_Amountcd1, Round(ifNull(Trans.Trans_Amountcd2,0), ".$DecimalBase2.") as Trans_Amountcd2, ".
			 " ifNull(Temp_Trans.Trans_Id, -1) As TempTransId, Journal.Journal_folio, Journal.Journal_refgovernment, Trans.Trans_ManualNo as TransManualNo, trans.user_account as user_account ";
			 
if ($Setup_TransShowLedger == 1) {	
	$querysearch .=	", Ledger.Ledger_Name as LedgerName ";
}
	
$querysearch .=	" , ifnull(trans.Trans_Confirmed,0)  as Trans_Confirmed,Trans.cashtype_code ";
if($show_prqstref==1) 	
$querysearch .=" , PaymentRqst_refgovernment ";	
else $querysearch .=" , null as PaymentRqst_refgovernment ";	
$querysearch .=" From Trans ";
			 
if ($Setup_TransShowLedger == 1) {
	$querysearch .=	" Inner Join TransDt on TransDt.Trans_Id = Trans.Trans_Id ".
					" Left Join Ledger on Ledger.Ledger_Number = TransDt.Ledger_Number ";
}

$querysearch .=	" Left Join Project on Trans.Project_Code = Project.Project_Code ".
				" Left Join Costcent on Trans.Costcent_code = Costcent.Costcent_code ".
				" Left Join Journal on Trans.Journal_ID = Journal.Journal_ID ".
				" Left Join Temp_Trans on Temp_Trans.Trans_ID = Trans.Trans_ID ";
if($show_prqstref==1) 
	$querysearch .= " left join paymentrqst on paymentrqst.PaymentRqst_id = trans.PaymentRqst_id ";			 
if($showPreReceipts != 1){			 
if ($projectexist >	0)
  $querysearch= $querysearch." Inner join ( select distinct project_code from ".$_SESSION['dbLabel'].".loginstk ".
							 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
							 "             and (project_code is not null and project_code != '') ".
							 "			 ) Q1 on (($Module_ProjectParent=1 and Trans.project_code like concat(Q1.project_code,'%')) or ($Module_ProjectParent=0 and Trans.project_code = Q1.project_code )) ";
							 
if ($costcentexist > 0)
  $querysearch= $querysearch." Inner join ( select distinct costcent_code from ".$_SESSION['dbLabel'].".loginstk ".
							 "			   where loginstk.user_account='".$_SESSION['useraccount']."' ".
							 "             and (costcent_code is not null and costcent_code != '') ".
							 "			 ) Q2 on (($Module_CostCenterParent=1 and Trans.costcent_code like concat(Q2.costcent_code,'%')) or ($Module_CostCenterParent=0 and Trans.costcent_code = Q2.costcent_code )) ";
}
$querysearch= $querysearch.											 
			 " Where (($searchby = 2 and ifNull(Trans.Trans_Reference,-1) Like Concat(ifNull($PRef, ifNull(Trans.Trans_Reference,-1)),'%')) Or ".
			 "        ($searchby = 1 and Date_Format(Trans.Trans_Date,'%Y-%m-%d') = ifNull(Date_Format($PRef,'%Y-%m-%d'), Date_Format(Trans.Trans_Date,'%Y-%m-%d'))) Or  ".
			 "        ($searchby = 3 and Journal.Journal_folio Like Concat(ifNull($PRef, Journal.Journal_folio),'%')) Or ".
			 "        ($searchby = 4 and Journal.Journal_refgovernment Like Concat(ifNull($PRef, Journal.Journal_refgovernment),'%')) Or ".
			 "        ($searchby = 5 and Round(ifNull(Trans.Trans_AmountDb1,0), ".$DecimalBase1.") Like Concat( ifNull($PRef, Round(ifNull(Trans.Trans_AmountDb1,0), ".$DecimalBase1.")),'%')) or ".
			 "        ($searchby = 6 and Trans.Trans_ManualNo Like Concat(ifNull($PRef, Trans.Trans_ManualNo),'%')) or ";
			 
if ($Setup_TransShowLedger == 1) {
	$querysearch .= " ($searchby = 7 and Ledger.Ledger_Name Like Concat('%',ifNull($PRef, Ledger.Ledger_Name),'%')) or ";
	
}
			 
$querysearch .= "     ($searchby = 8 and Trans.Trans_Representative Like Concat('%',ifNull($PRef, Trans.Trans_Representative),'%')) ) ".
				" And Trans.Trans_Type = '".$TransType."' ".
				" And (($rowsperiod = 0 and 1 = 1) Or ($rowsperiod > 0 and (($LockViewPeriod = 1 and  Date_Format(Trans.Trans_Date,'%Y-%m-%d') >= Date_Format(ifNull('".$ViewPeriodDate."',Trans.Trans_Date),'%Y-%m-%d')) Or ($LockViewPeriod = 0 and 1=1 ))   ".
				"                                                      and (($ViewLockDaily = 1 and DateDiff(Date_Format(Now(),'%Y-%m-%d'),Date_Format(Trans.Trans_Date,'%Y-%m-%d')) <= $ViewNumberOfDays) Or ($ViewLockDaily = 0 and  1 = 1 ))) ) ";
			 
if ($Setup_TransShowLedger == 1) {
	if ($TransType == 'RV' || $TransType == 'CV' || $TransType == 'CT')
		$querysearch= $querysearch." And upper(TransDt_dbcd) = 'C' ";
	else	
		$querysearch= $querysearch." And upper(TransDt_dbcd) = 'D' ";
}
			 
if ($Module_BelongsToGroup == 1)
	$querysearch= $querysearch." And ifNull(Trans.Trans_BelongsToGroup,0) >= ifNull($FI_BelongsToGrp,0) ";
	
if ($ShowTransaction != 1)
	$querysearch= $querysearch." And Upper(Trans.User_Account) = Upper('".$_SESSION['useraccount']."') ";
			 
if ($PProjectCode != '')
	$querysearch= $querysearch." And Trans.project_code like concat('".$PProjectCode."','%') ";
if ($PCostCentCode != '')
	$querysearch= $querysearch." And Trans.costcent_code like concat('".$PCostCentCode."','%') ";			 
if($showPreReceipts == 1)	
	$querysearch= $querysearch." and trans.journal_id is null ";

if ($fromdate != '' && $todate !='' )
	$querysearch = $querysearch." And Date_Format(Trans.Trans_Date,'%Y-%m-%d') between '".explodeword($fromdate)."' and '".explodeword($todate)."' ";

if ($orderby == 1)
	$querysearch= $querysearch." Order By Trans.Trans_Date Desc, Trans.Trans_Reference Desc ";
else if ($orderby == 2)
	$querysearch= $querysearch." Order By Trans.Trans_Reference Desc ";	
else if($orderby == 3) 	$querysearch= $querysearch." Order By PaymentRqst_refgovernment Desc ";	
	
//$querysearch= $querysearch." Limit 1 ";
			 
//echo $querysearch;			 

$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
$totalrows = mysql_num_rows($resultsearch);
	
	
$querysearch = $querysearch." limit ".$startrange.",".$perpage;

$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	

echo"<table cellpadding='0' cellspacing='0' border='0'  align='left' style='table-layout:fixed' width='1130px;'>";
echo"<tr>
		<td id='search-top1' style='height:34px; width:31px;'>&nbsp;</td>
	  	<td id='search-top2' style='height:34px; ' align='center' valign='middle'>
			<table border='0'>
			<tr><td><span class='style3'>List of $Title</span></td></tr>
			</table>
		</td>
		<td id='search-top3' style='height:34px; width:31px;'>&nbsp;</td>
	</tr>";

echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		 <td id='search-content2' >";
		 


echo"<table border='0' cellspacing='1'  style='table-layout:fixed'>
	  <col width=20>
	  <col width=20>
	  <col width=20>";

echo "<col width=65>
	  <col width=70>
	  <col width=50>
	  <col width=50>
	  <col width=75>
	  <col width=180>
	  <col width=110>
	  <col width=110>
	  <col width=75>
	  <col width=90>
	  <col width=125>
		     
	
	  <tr class='Search-header-bg'>";
	  
if ($Module_Project == 1) {
	echo" <td align='left' colspan='4'><span class='style4'>Shipment Ref</span></td>
	      <td align='left' colspan='3'><span class='style4'>
		    <input type='text' name='PProjectCode' id='PProjectCode' value='$PProjectCode' size='15' maxlength='20' onkeydown=\"return kd(event);\" /></span>
		    <label><span class='style4'><img src='img/btnopen.jpg' title=' Select Shipment Ref ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistProject(1); '  /></span></label></td>";
} else {
	echo" <td align='left' colspan='7'><input type='hidden' name='PProjectCode' id='PProjectCode' value='$PProjectCode' /></td>";

}			

if ($Module_CostCenter == 1) {		  
	echo" <td align='left' ><span class='style4'>Costcenter</span></td>		
		  <td align='left' ><span class='style4'>
		    <input type='text' name='PCostCentCode' id='PCostCentCode' value='$PCostCentCode' size='15' maxlength='20' onkeydown=\"return kd(event);\" /></span>
		    <label><span class='style4'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCostcenter(1); ' /></span></label></td>";
} else {
	echo" <td align='left' colspan='2'><input type='hidden' name='PCostCentCode' id='PCostCentCode' value='$PCostCentCode' /></td>";

}	  


echo" <td align='right' ><span class='style4'>Order By</span></td>		
		  <td align='left' ><span class='style4'><select name='orderby' id='orderby' value='$orderby' onchange='RefreshPage();'>";
		
		if ($orderby==1)
			$s11 = 'selected';
		else if ($orderby==2)
			$s12 = 'selected';
		else if ($orderby==3)
			$s13 = 'selected';
			
		echo"<option ".$s11." value='1'>Date</option>
			 <option ".$s12." value='2'>Reference</option>";
		if($show_prqstref==1) 	 
			echo "<option ".$s13." value='3'>Payment Rqst. Reference</option>	"; 
		echo " </select></span></td>";
		echo "<td><input type='checkbox' name='hide' value='0' id='hide'><span class='style4'>hide</span></td>";

		echo" <td align='left' colspan='4'>";
	if ($TransType == 'RV'){
		if($showPreReceipts == '') $showPreReceipts = 0;
		echo "<input type='checkbox' name='showPreReceipts' value='$showPreReceipts' id='showPreReceipts' onclick=\"setShowPre();\" ".($showPreReceipts == 1?'checked':'')."> <span class='style4'>Show Pre-Receipts</span>";
	}	
		echo "</td>";
echo" </tr>";
echo" <tr class='Search-header-bg'>	  
	    <td align='left' colspan='4'><span class='style4'>Search By</span></td>
		<td align='left' colspan='8'><span class='style4'><input type='text' name='keyword' id='keyword' value='$keyword' size='15' maxlength='100' onkeydown=\"return kd(event);\"/><input type='hidden' name='PMode' id='PMode' value='$PMode' size='15' maxlength='30'/></span>
			
			<select name='searchby' id='searchby' value='$searchby' onchange='SelectSearchBy();'>";
		
			if ($searchby==1)		$s21 = 'selected';
			else if ($searchby==2)	$s22 = 'selected';
			else if ($searchby==3)	$s23 = 'selected';
			else if ($searchby==4)	$s24 = 'selected';		
			else if ($searchby==5)	$s25 = 'selected';	
			else if ($searchby==6)	$s26 = 'selected';		
			else if ($searchby==7)	$s27 = 'selected';		
			else if ($searchby==8)	$s28 = 'selected';
				
			echo"<option ".$s21." value='1'>Date (yyyy-mm-dd)</option>
				 <option ".$s22." value='2'>Reference</option>
				 <option ".$s23." value='3'>Folio</option>
				 <option ".$s24." value='4'>Jv Ref.</option>
				 <option ".$s25." value='5'>Amount</option>
				 <option ".$s26." value='6'>ManualNo</option>
				 <option ".$s27." value='7'>Ledger Name</option>
				 <option ".$s28." value='8'>Representative</option>
				 </select>";	
				 
echo"      	<button type='button' id='btnSubmit' name='btnSubmit' onclick='SubmitForm(); return false;' title='Find'><span><span>Find</span></span></button>
			<button type='button' id='btnCancel' name='btnCancel' onclick='clearform(); return false;' title='Cancel'><span><span>Cancel</span></span></button>
			&nbsp;&nbsp;<span class='style4'>Show Details</span><input type='checkbox' name='showDetails' id='showDetails' onclick='showAllDetails()' value='' >";
			//&nbsp;&nbsp;<span class='style4'>With Check</span>
echo "			<span class='style4'> Bank </span>	
				<select name='bank' id='bank' >
				<option value='bankmed' selected>BankMed</option>
				<option value='bankmed2' selected>BankMed 2</option>
				<option value='bankaudi' selected>BankAudi</option>
				<option value='FransaBank' selected>FransaBank</option>
				<option value='' selected> </option>
			</select>
</td>";
 

echo" <td align='left' colspan='3'>&nbsp;</td>";			 
echo" </tr>";
 echo "<tr class='Search-header-bg'><td colspan='15'><span class='style4'>From&nbsp;</span><input type='text' name='fromdate' id='fromdate' value='$fromdate' maxlength='10' size='9'>
		<A HREF=\"#\" onClick=\"displayCalendar(document.search.fromdate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span>
&nbsp; &nbsp;<span class='style4'>To&nbsp;</span><input type='text' name='todate' id='todate' value='$todate' maxlength='10' size='9'>
		<A HREF=\"#\" onClick=\"displayCalendar(document.search.todate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span></td>
</tr>";

echo"</table>
		</td>
		<td id='search-content3' style='width:31px;'>&nbsp;</td>"; 
echo" </tr>";

echo"<tr>
		<td  id='search-content1' style='height:34px;width:31px;'>&nbsp;</td>
		<td  id='search-content2' style='height:34px;width:1025px;'>
		<table width='100%' border=0>
		<tr>
			<td align='right' style='width:380px;'><span class='style4'>Per Page </span><span class='style4'><select name='perpage' id='perpage' value='$perpage' onchange='RefreshPage();'>";
              
            $perpages = $config['trowlimit'];
			foreach ($perpages as $val){
			echo" <option value = '$val' "; if ($perpage ==$val) echo "selected"; 
			echo" >$val</option> ";
			}
	echo'					
				</select></span></td>
			<td  style="width:74px;border-right:1px solid #000000;text-align:right;">';
			
			if($startrange > 0)
				echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='hand'\" onclick=SetFirstPage('".$startrange."','".$perpage."')>";

			$diff= $startrange - $perpage;
				
			if (($diff) >= 0 ){
				$prvstartrange = $startrange - $perpage;
				echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
			}
			else
				echo "&nbsp;";
		
echo"		</td><td  align='left' style='width:74px;'>";
		
		
			if ($startrange <= $totalrows){
				$startrange1 = $startrange + $perpage;
				if  ($startrange1 < $totalrows){
					echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange1."','".$perpage."')>";
					echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='hand'\" onclick=SetLastPage('".$perpage."','".$totalrows."')>";	
				}
			} else
				echo "&nbsp;";
				
			
echo"		</td><td style='width:380px;'>&nbsp;</td>
		</tr>";
echo"	</table></td>
		<td id='search-content3' style='width:31px;'>&nbsp;</td>";
echo"</tr>";

echo"<tr><td id='search-content1' style='width:31px;'>&nbsp;</td>
		<td id='search-content2'>
			<div style='overflow:scroll;height:400px;width:1055px;'>
			<table border='0'  cellpadding='0' cellspacing='1' width='1285px'>
			<col width=20><col width=20>
			<col width=20>
			<col width=20>
			<col width=20>
			";
if($FA_App == 1) echo "<col width=20>";	  			
echo"<col width=20>";
if($show_prqstref == 1)  
echo "<col width=65>";	
echo "<col width=65>
			<col width=90>
			<col width=50>
			<col width=50>
			<col width=75>
			<col width=200>";
			
	if ($Setup_TransShowLedger == 1)
		echo"<col width=200>";
	else
		echo"<col width=10>";
				
echo"		<col width=110>
			<col width=110>
			<col width=75>
			<col width=90>
			<col width=90>
			<col width=90>";

	if($message!=''){
		echo"<tr class='Search-header-bg'>
				<td height='15' align='center' colspan='16' class='searchmessage'>".$message."</td>
			</tr>";
	}
	
	echo"<tr class='Search-Label-bg'>
			<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
			<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
			<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>
			<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>";
if($FA_App == 1) 	echo "<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>";	
	echo"<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>";
	echo"<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>";

	echo "	<td  height='25' align='left'><span class='style4'>Reference </span></td>";


if($show_prqstref == 1)	
	echo "	<td  height='25' align='left'><span class='style4'>Payment Rqst. REF </span></td>";
	echo "	<td  height='25' align='center'><span class='style4'>Date </span></td>
			<td  height='25' align='center'><span class='style4'>Folio </span></td>
			<td  height='25' align='center'><span class='style4'>JV Ref. </span></td>
			<td  height='25' align='center'><span class='style4'>Cash Ref.</span></td>
			<td  height='25' align='center'><span class='style4'>Representative</span></td>";
			
			if ($Setup_TransShowLedger == 1)
				echo"<td  height='25' align='center'><span class='style4'>Ledger Name</span></td>";
			else
				echo"<td  height='25' align='center'><span class='style4'>&nbsp;</span></td>";
				
	echo"	<td  height='25' align='center'><span class='style4'>Shipment Ref</span></td>
			<td  height='25' align='center'><span class='style4'>Cost Center</span></td>
			<td  height='25' align='center'><span class='style4'>Manual No</span></td>
			<td  height='25' align='center'><span class='style4'>$base1</span></td>
			<td  height='25' align='center'><span class='style4'>$base2</span></td>
			<td  height='25' align='center'><span class='style4'>User</span></td>
		</tr>";
		
	

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

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

	$PrevHint   = 'Preview';
	$EditHint   = 'Edit Record';
	$DelHint    = 'Delete Record';
	
	if ($TempTransId != -1) {$PrevHint=$EditHint=$DelHint = 'Exists in Pending';}
	
   	if ($ModPost==0)  {
	
    if ($FA_Mod == 0)	$EditMode = 0; 
	else if ($FA_Mod == 1 && $TempTransId != -1) $EditMode = 0;
	else if ($FA_Mod == 1 && $TempTransId == -1) $EditMode = 1;
	
    } else {
	
    if ($FA_Mod == 0)	$EditMode = 0; 	
	else if ($afterpost==1 )$EditMode = 1;	else $EditMode = 0;
		
	}
	
	if ($FA_Del == 0)	$DelMode =0; 
	else if ($FA_Del == 1 && $TempTransId != -1) $DelMode =0;
	else if ($FA_Del == 1 && $TempTransId == -1) $DelMode =1;
	
	if ($TempTransId != -1) $PrevMode =0; else $PrevMode =1;		
	
	if ($rowsperiod > 0 && $AllowLockedPeriod == 1) {
		if (!(empty($LockedPeriodDate)) && $LockedPeriodDate != '' && date('Y-m-d',strtotime(insertMySQLDate($Trans_Date))) <= date('Y-m-d',strtotime($LockedPeriodDate))) $ExceedLockPeriod = 1;
		if ($LockedPeriodDays != '' && dateDiff(insertMySQLDate(displayToday()),insertMySQLDate($Trans_Date)) >= $LockedPeriodDays) $ExceedLockPeriod = 1;
	}
	
	if ($ExceedLockPeriod == 1){
		$EditMode = 0;
		$DelMode = 0;
	}	 
		   
	echo'<tr '.$Color.'>';
		echo "<input type='hidden' name='cashtype_code' value='$cashtype_code' id ='cashtype_code'>";
		if($PrevMode==1){
		echo'<td align="center"><span class="style5"><img src="img/mag.jpg" onMouseOver="style.cursor=\'hand\'"  onclick="PrintPreview('.$Trans_ID.',0);"  title="'.$PrevHint.'" style="width: 15px; height: 15px; " ></span></td>';
		echo'<td align="center"><span class="style5"><img src="img/excelbtn.png" onMouseOver="style.cursor=\'hand\'"  onclick="PrintPreview('.$Trans_ID.',1);"  title="Exp Excel" style="width: 15px; height: 15px; " ></span></td>';
		}else echo'<td align="center">&nbsp;</td><td align="center">&nbsp;</td>';		
		
		if($EditMode==1)
			echo'<td align="center"><span class="style5"><img  src="img/edit.png" onMouseOver="style.cursor=\'hand\'" onclick="UpdateRecord('.$Trans_ID.');" title="'.$EditHint.'" style="width:20px; height:20px; "></span></td>';
		else echo'<td align="center">&nbsp;</td>';	
		
		if($DelMode==1)
			echo'<td align="center"><span class="style5"><img src="img/delete.png" onMouseOver="style.cursor=\'hand\'" onclick="DeleteRecord('.$Trans_ID.', '.$Trans_Reference.');" title="'.$DelHint.'"  style="width:20px; height:20px; "></span></td>';
		else echo'<td align="center">&nbsp;</td>';	
		
		
		if($FA_App == 1 && $Trans_Confirmed==0)
		echo'<td align="center"><span class="style5"><img src="img/confirmorder.png" onMouseOver="style.cursor=\'hand\'" onclick="ConfirmTrans('.$Trans_ID.', \''.$Trans_Reference.'\');" title="Approve" style="width: 20px; height: 20px; "  ></span></td>';	

		else if($FA_App == 1 && $Trans_Confirmed==1)
		echo'<td align="center">&nbsp;</td>';	
	
		echo'<td align="center"><span class="style5"><img src="img/details.gif" onMouseOver="style.cursor=\'hand\'"  onclick="ShowHideDetails('.$Trans_ID.', \''.'S'.'\','.$startrange.');" title="Show Details" style="width:15px; height:15px; "></span></td>';	
		//echo " <td align = \"center\"<span class = \"style5\"><a onclick=\"UploadDocuments('Payment','$Trans_ID');\"   onMouseOver='style.cursor=\'hand\'' >View </a> </span></td>";	
        if($FI_login_ViewDocument==1){
			echo'<td align="center"><span class="style5"><img src="img/viewdoc.png" onMouseOver="style.cursor=\'hand\'"  onclick="UploadDocuments(\''.'Payment'.'\','.$Trans_ID.');"  title="Show Document" style="width: 18px; height: 15px; " ></span></td>';
		}else{
			echo'<td align="center">&nbsp;</td>';  
		}
		echo'<td align="left"><span class="style5">'.$Trans_Reference.'</span></td>';
		if($show_prqstref == 1)	
		echo'<td align="left"><span class="style5">'.$PaymentRqst_refgovernment.'</span></td>';
		echo '<td align="center"><span class="style5">'.$Trans_Date.'</span></td>
			<td align="center"><span class="style5">'.$Journal_folio.'</span></td>
			<td align="center"><span class="style5">'.$Journal_refgovernment.'</span></td>
			<td align="center"><span class="style5">'.$Trans_CashReference.'</span></td>
			<td align="left"><span class="style5">'.$Trans_Representative.'</span></td>';
			
			if ($Setup_TransShowLedger == 1)
				echo'<td align="left"><span class="style5">'.$LedgerName.'</span></td>';
			else
				echo'<td align="left"><span class="style5">&nbsp;</span></td>';
			
		echo'<td align="left"><span class="style5">'.$ProjectName.'</span></td>
			<td align="left"><span class="style5">'.$CostcentName.'</span></td>
			<td align="left"><span class="style5">'.$TransManualNo.'</span></td>
			<td align="right"><span class="style5">'.number_format($Trans_AmountDb1,$DecimalBase1).'</span></td>
			<td align="right"><span class="style5">'.number_format($Trans_AmountDb2,$DecimalBase2).'</span></td>
			<td align="right"><span class="style5">'.$user_account.'</span></td>
		</tr>';
		
		
		$sub_query = " Select TransDt.TransDt_ID, Ledger.Ledger_Number, Ledger.Ledger_Name, TransDt.TransDt_Description, TransDt.TransDt_Description2, ".
					 " TransDt_dbcd, Round(ifNull(Transdt_Amount,0), ".$DecimalBase."), Round(ifNull(Transdt_Amount1,0), ".$DecimalBase1."),".
					 " Round(ifNull(Transdt_Amount2,0), ".$DecimalBase2."), date_format(TransDt_ValueDate,'%d-%m-%Y'), TransDt.Currency_code, TransDt.TransDt_ManualNo ".
					 " From TransDt ".
					 " Inner Join Ledger on TransDt.Ledger_Number = Ledger.Ledger_Number ".
					 " Where TransDt.Trans_ID = '".$Trans_ID."' ".
					 " Order By Ledger.Ledger_Number ";

		$sub_result=mysql_query($sub_query,$connection) or die(mysql_error($connection));	
		$sub_totalrows = mysql_num_rows($sub_result);
		
		if ($sub_totalrows > 0) {
			$SlideDivId = 'displaydetails'.$Trans_ID;
			
			echo "<tr ".$Color.">";
			echo "<td colspan='16' valign='top' align='left'><div id='$SlideDivId' class='div-search-details slideAll' style='display:none; margin-left:80px;'>";
			echo "<table border='0' style='table-layout:fixed' cellpadding='0' cellspacing='1' width='1020px'>";
			echo "<tr><td width='100px'><span class='style4'>Ledger No.</span></td>
					  <td width='130px'><span class='style4'>Ledger Name</span></td> 
					  <td width='240px'><span class='style4'>Description</span></td> 
					  <td width='50px' align='center'><span class='style4'>Curr.</span></td>
					  <td width='40px' align='center'><span class='style4'>D/C</span></td>
					  <td width='100px' align='center'><span class='style4'>Amount</span></td>
					  <td width='100px' align='center'><span class='style4'>$base1</span></td>
					  <td width='100px' align='center'><span class='style4'>$base2</span></td>
					  <td width='80px' align='center'><span class='style4'>Manual No</span></td>
					  <td width='80px' align='center'><span class='style4'>Value Date</span></td>
				  </tr>";
			while($sub_rows=mysql_fetch_array($sub_result)){
				echo "<tr><td align='left' valign='top' class='style9'>".$sub_rows[1]."</td>
						  <td align='left' valign='top' class='style9'>".$sub_rows[2]."</td>
						  <td align='left' valign='top' class='style9'>".$sub_rows[3]."</td>
						  <td align='center' valign='top' class='style9'>".$sub_rows[10]."</td>
						  <td align='center' valign='top' class='style9'>".$sub_rows[5]."</td>
						  <td align='right' valign='top' class='style9'>".number_format($sub_rows[6],$DecimalBase)."</td>
						  <td align='right' valign='top' class='style9'>".number_format($sub_rows[7],$DecimalBase1)."</td>
						  <td align='right' valign='top' class='style9'>".number_format($sub_rows[8],$DecimalBase2)."</td>
						  <td align='left' valign='top' class='style9' style='padding-left:5px;'>".$sub_rows[11]."</td>
						  <td align='center' valign='top' class='style9'>".$sub_rows[9]."</td>";
  				echo "</tr>";
				
				if ($sub_rows[4] != "") {
					echo "<tr><td align='left' valign='top' class='style9' colspan='2'>&nbsp;</td>
						  <td align='left' valign='top' class='style9' colspan='8'>".$sub_rows[4]."</td>";
					echo "</tr>";	  
				}
				
				// Display Projects/Costcenters
				$sub_query6 = " Select Project_code as CstJourDt_Project, Costcenter_Code as CstJourDt_CostCent, CstJourDt_Per, ".
							  " Round(CstJourDt_Amount, ".$DecimalBase.") As CstJourDt_Amount, ".
							  " Round(CstJourDt_Amount1, ".$DecimalBase1."), Round(CstJourDt_Amount2, ".$DecimalBase2.") ".
							  " From cstjourdt ".
							  " Where TransDt_id = '".$sub_rows[0]."' ".
							  " Order By Project_code, Costcenter_Code ";			  
				//echo $sub_query6;
				$sub_result6=mysql_query($sub_query6,$connection) or die(mysql_error());			  
				$CstCount = mysql_num_rows($sub_result6);
				
				if ($CstCount > 0) {			  
					echo "<tr><td colspan='7'>";	
					echo "<table border=0 width='630' cellspacing=1 class='subdetail' style='table-layout:fixed;' >
						  <col width=90>
						  <col width=80>
						  <col width=200>
						  <col width=70>
						  <col width=55>
						  <col width=80>
						  <col width=50>";
					echo "<tr>";
					echo "   <th align='left'>&nbsp;</th>";
					echo "   <th align='left'>Shipment Ref</th>";
					echo "	 <th align='left'>Cost Center</th>";
					echo "	 <th align='center'>Percentage</th>";
					echo "	 <th align='center'>&nbsp;</th>";
					echo "	 <th align='center'>Amount</th>";
					echo "   <th align='left'>&nbsp;</th>";
					echo "</tr>";	
					
					
					$sub_result6=mysql_query($sub_query6,$connection) or die(mysql_error());
					while($sub_rows6=mysql_fetch_array($sub_result6)){
						extract($sub_rows6);
						
						echo "<tr>";
						echo "  <td align='left' valign='top'>&nbsp;</td>";
						echo "  <td align='left' valign='top'>$CstJourDt_Project</td>";
						echo "  <td align='left' valign='top'>$CstJourDt_CostCent</td>";
						echo "	<td align='center' valign='top'>".number_format($CstJourDt_Per, $DecimalBase)."%</td>";
						echo "	<td align='center' valign='top'>&nbsp;</td>";
						echo "	<td align='right' valign='top'>".number_format($CstJourDt_Amount, $DecimalBase)."</td>";
						echo "  <td align='left' valign='top'>&nbsp;</td>";
						echo "</tr>";
						
					}	
					
					echo"</table></td></tr>";
				}
			
			}
			
			echo "</table></div></td>";
			echo "</tr>";
		}
}
							


echo"</table></div></td><td id='search-content3' style='width:31px;'>&nbsp;</td></tr>";			
		
echo"   <tr ><td id='search-content1'>&nbsp;</td><td id='search-content2'>&nbsp;</td><td id='search-content3'>&nbsp;</td></tr>";
echo"	<tr >
		<td id='search-bottom1' style='height:34px; width:31px;'>&nbsp;</td>
		<td id='search-bottom2' style='height:34px; width:1025px;' valign='top'><table width='100%' border=0 height=28px>
		<tr><td style='width:380px;'>&nbsp;</td><td align='right' style='width:74px;border-right:1px solid #000000;'>";

		
		if($startrange>0)
			echo"<img src='img/firstpage.png' title='First Page' onMouseOver=\"style.cursor='hand'\" onclick=SetFirstPage('".$startrange."','".$perpage."')>";

		//$diff= $startrange - $perpage;
		
		if (($diff) >= 0 ){
			//$prvstartrange = $startrange - $perpage;
			echo"&nbsp;&nbsp;<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
		}
		else
			echo "&nbsp;";
		
		echo"</td><td  align='left' style='width:74px;'>";
		
		
		if ($startrange <= $totalrows){
			//$startrange = $startrange + $perpage;
			if  ($startrange1 < $totalrows){
				echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange1."','".$perpage."')>";
				echo"&nbsp;&nbsp;<img src='img/lastpage.png' title='Last Page' onMouseOver=\"style.cursor='hand'\" onclick=SetLastPage('".$perpage."','".$totalrows."')>";	
			}
		} else
			echo "&nbsp;";
	
			
		echo"</td><td style='width:380px;'>&nbsp;</td></tr>";
		echo"</table></td><td id='search-bottom3' style='height:34px; width:31px;'>&nbsp;</td>";

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


          

		  

print <<<HERE

</form>
</body>

HERE;
function explodeword($date)
{

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