<?php

session_start();
if($_SESSION['dbName']==""){
	header("location:../index.php");
}

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


//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ifNull(module_ReferenceByCostcenter,0) As module_ReferenceByCostcenter,Ifnull(Module_RestrictProjectReport,0) as Module_RestrictProjectReport ".
             " From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$querylog="SELECT RA_Trialbalance as loginaccess,ExporttoExcel 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);
}
if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");
	
	

if ($ExporttoExcel==1)
$ExporttoExcelStatus= 'button';
else
$ExporttoExcelStatus= 'hidden';	
	
$querylog="select * from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."'";
$resultlog=mysql_query($querylog) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
extract($rows);

}
$printaccess=$Print;
print <<< HERE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

HERE;


$querysetup ="select base1, base2 from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
$rowsetup=mysql_fetch_row($resultsetup);

// Setting Initial Values For Parameters
$querydate=" Select Date_Format(Min(Journal_date),'%d/%m/%Y') As DefaultFromDate, ".
           " Date_Format(Max(Journal_date),'%d/%m/%Y') As DefaultToDate ".
		   " From JournalDt ";
$resultdate=mysql_query($querydate,$connection) or die(mysql_error());
$rowdate=mysql_fetch_row($resultdate);

if (!isset($fromdate)) $fromdate = $rowdate[0];
if (!isset($todate))   $todate = $rowdate[1];
  
  
$querycurrency="select Currency_code from currency order by currency_code";
$resultcurrency=mysql_query($querycurrency,$connection) or die(mysql_error());

$queryjvtype="select type_name from jourtype order by type_name";
$resultjvtype=mysql_query($queryjvtype,$connection) or die(mysql_error());


$querydflproject="select log.project_code as defaultproject,project_name as defaultprojname from ".$_SESSION['dbLabel'].".loginstk as log
					left join project on project.project_code = log.project_code 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);

}
$querydflcostcent="select log.costcent_code as defaultcostcent, costcent_name as defaultcostcentname from ".$_SESSION['dbLabel'].".loginstk as log 
				left join costcent on costcent.costcent_code = log.costcent_code 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);

}

$querylog=" select ifNull(FI_RepRestrictProject,0) As FI_RepRestrictProject, ifNull(FI_RepRestrictCostcenter,0) As FI_RepRestrictCostcenter ".
          " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."') ";
$resultlog=mysql_query($querylog) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}


$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$_SESSION['dbLabel'].".loginstk on project.project_code like concat(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());
$projectrows   = mysql_num_rows($projectresult);
if ($projectrows == 0 || $FI_RepRestrictProject == 0)
    $queryproject=" select distinct project_code, project_name from project order by project_code ";			  
$resultproject=mysql_query($queryproject,$connection) or die(mysql_error());
$projectrows   = mysql_num_rows($resultproject);

$querycostcent=" select distinct costcent.costcent_code, costcent_name ".
               " from costcent left join ".$_SESSION['dbLabel'].".loginstk on costcent.costcent_code like concat(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());
$costcentrows   = mysql_num_rows($costcentresult);
if ($costcentrows == 0 || $FI_RepRestrictCostcenter == 0)
    $querycostcent=" select distinct costcent_code, costcent_name from costcent order by costcent_code ";			  
$resultcostcent = mysql_query($querycostcent,$connection) or die(mysql_error());
$costcentrows   = mysql_num_rows($resultcostcent);
$resultcostcent1= mysql_query($querycostcent,$connection) or die(mysql_error());

$queryacctype="select acctype_code, acctype_name from acctype order by acctype_code";
$resultacctype=mysql_query($queryacctype,$connection) or die(mysql_error());

$querybustype="Select distinct Client_BusinessType From Clients Where Client_BusinessType is Not Null Order By Client_BusinessType ";
$resultbustype=mysql_query($querybustype,$connection) or die(mysql_error());




//maroun
$queryproject2=" select distinct project.project_code, project_name ".
              " from project left join ".$_SESSION['dbLabel'].".loginstk on project.project_code like concat(ifnull(loginstk.masterproject,''),'%') ".
			  " where user_account='".$_SESSION['useraccount']."' ".
			  " and (loginstk.masterproject is not null and loginstk.masterproject != '') ".
			  " order by project.project_code";
//echo $queryproject2;
$resultproject2=mysql_query($queryproject2,$connection) or die(mysql_error());

//maroun
$querycostcent2=" select distinct costcent.costcent_code, costcent_name ".
               " from costcent left join ".$_SESSION['dbLabel'].".loginstk on costcent.costcent_code like concat(ifnull(loginstk.mastercostcenter,''),'%') ".
 			   " where user_account='".$_SESSION['useraccount']."' ".
			   " and (loginstk.mastercostcenter is not null and loginstk.mastercostcenter != '') ".
 			   " order by costcent.costcent_code";
$resultcostcent2=mysql_query($querycostcent2,$connection) or die(mysql_error());


//maroun
$querysalesmen=" select distinct clientsalesmen ".
			   " from ".$_SESSION['dbLabel'].".loginstk ".
			   " where user_account='".$_SESSION['useraccount']."' ".
			   " and (clientsalesmen != ''  and clientsalesmen is not null) ";
			   
//echo $querysalesmen;			  
$salesmenresult = mysql_query($querysalesmen,$connection) or die(mysql_error());
$salesmenexist   = mysql_num_rows($salesmenresult);

//echo $salesmenexist;

if ($salesmenexist!=0 or $salesmenexist!='')
	{
		$RadioOpt = 'disabled';
	}
else
		{
		$RadioOpt = 'enabled';
		}

$query="select ifnull(ShowReportHeader,0) as ShowReportHeader from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' ";
$result=mysql_query($query,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($result)){
	extract($rows);
}
if($ShowReportHeader=='')
	$ShowReportHeader=1;

print <<< HERE

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>

<script language="JavaScript" src="CalendarPopup.js" ></script><!-- Date only with year scrolling -->
<link type="text/css" href="js/grid/scripts/jquery-ui.css" rel="stylesheet">
<script type="text/javascript" src="js/grid/scripts/jquery-ui.min.js"></script>
<script type="text/javascript" language="javascript">
<!--

function PrintPrev(printaccess)
{
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
  	
 
	for (var i=0; i < document.form1.options.length; i++)
	{
		if (document.form1.options[i].checked)
		{
			var varoptions = document.form1.options[i].value;
		}
	}
	 
  
	varexclude = 0;
	if (document.form1.exclude.checked)
		varexclude = 1;	
	
	varalltypes = 0;
	if (document.form1.alltypes.checked)
		varalltypes = 1;	
	
	var checkname;
	var x, varjvtype;
	varjvtype = '';
	for (var i=1; i <= document.form1.i.value; i++)
	{
		checkname='type'+i;
	
		x = document.getElementById(checkname);
		if (varalltypes == 0 && x.checked) 
			varjvtype = varjvtype+",'"+x.value+"'";
    
	}
	varjvtype = varjvtype.substr(1);
  
	varcurr = 0;
	if (document.form1.curr.checked) 
		varcurr = 1;	 
	
	varcurrbase1 = 0;
	if (document.form1.currbase1.checked)
		varcurrbase1 = 1;	
	
	varcurrbase2 = 0;
	if (document.form1.currbase2.checked)
		varcurrbase2 = 1;		
	
  	
  	

	varprtcv = 0;
	if (document.form1.prtcv.checked)
		varprtcv = 1;			
	
	varprtselper = 0;
	if (document.form1.prtselper.checked)
		varprtselper = 1;
	
	varprtzerobal = 0;
	if (document.form1.prtzerobal.checked)
		varprtzerobal = 1;	
	
	varprtgrponly = 0;
	if (document.form1.prtgrponly.checked)
		varprtgrponly = 1;	
	
	varprtdtonly = 0;
	if (document.form1.prtdtonly.checked)
		varprtdtonly = 1;		
	
	varprtreqdt = 0;
	if (document.form1.prtreqdt.checked)
		varprtreqdt = 1;	
	
	varprtparents = 0;
	if (document.form1.prtparents.checked)
		varprtparents = 1;		
  
	varprtdoc = 0;
	if (document.form1.prtdoc.checked)
		varprtdoc = 1;			

	varprtprjcst = 0;
	if (document.form1.prtprjcst.checked)
		varprtprjcst = 1;				
  	varprtprjcst2 = 0;
	if (document.form1.prtprjcst2.checked)
		varprtprjcst2 = 1;				

	varshowprevdbcd = 0;
	if (document.form1.showprevdbcd.checked)
		varshowprevdbcd = 1;	

	varshowactbal = 0;
	if (document.form1.showactbal.checked){
		varshowactbal = 1;
		document.form1.showprevdbcd.checked = 'false';	
		varshowprevdbcd = 0;
	}

	varCompare = 0;
	if(document.form1.compare.checked)
		varCompare = 1;

	varprtheader = 0;
	if (document.form1.prtheader.checked)
		varprtheader = 1;		
	
	varbalancecur = 0;
	if (document.form1.balanceCur.checked)
		varbalancecur = 1;		
	
	varfromdate   = document.form1.fromdate.value;
	vartodate     = document.form1.todate.value;
	varfromledger = document.form1.fromledger.value;
	vartoledger   = document.form1.toledger.value;
	varfromprj    = document.form1.fromproject.value;
	varfromcst    = document.form1.fromcostcent.value;
	varexcludecst = document.form1.exclcostcent.value;
	varfromcur    = document.form1.fromcur.value;
	vargrplen     = document.form1.grplen.value;
	varfromacctype = document.form1.fromacctype.value;
	varfrombustype = document.form1.frombustype.value;
	
	var ob = document.form1.valueOfI;
	var checkName;
	var dbNames = '';
	var obFound = 'false';
	if(varCompare == 1){
		if(ob.value >= 2){
			for(var i=1, iLen=ob.value; i <= iLen; i++){
				checkname='dbName'+i;
				y = document.getElementById(checkname)
				if(y.checked){
					if(i > 1)
						dbNames = dbNames + ','
					dbNames = dbNames + y.value;
					obFound = 'true';
				}
			}
		}
		if(obFound == 'false'){
			alert("Please Choose At Least 2 Schema");
			return;	
		}
	}
	
	
	var vFromSalesman = document.form1.fromsalesman.value;
	var vToSalesman   = document.form1.tosalesman.value;
  
	varcltprj       = document.form1.clientproject.value;
	varcltcst       = document.form1.clientcostcent.value;
	vrange1       = document.form1.range1.value;
	vrange2       = document.form1.range2.value;
  
	varcltprj = varcltprj.replace('&','%26');
	varcltcst = varcltcst.replace('&','%26');
	
	varfromcst = encodeURIComponent(varfromcst);
	varexcludecst = encodeURIComponent(varexcludecst);
	varfromprj = encodeURIComponent(varfromprj);
	varcltprj = encodeURIComponent(varcltprj);
	varcltcst = encodeURIComponent(varcltcst);
	var unbalanceRep = 0;
	if(document.getElementById("unbalanceRep").checked)
		unbalanceRep = 1;
	var unbrange = document.getElementById('unbrange').value;
	if(unbrange == '') unbrange = 0;
	
	if(unbalanceRep == 1) { 
		str =   'rep_unbalancedReport.php?fromdate='+varfromdate+'&todate='+vartodate+'&curr='+varcurr+'&currbase1='+varcurrbase1+
				'&currbase2='+varcurrbase2+'&unbrange='+unbrange;
	} else {	   
	if(varbalancecur == 1)
		str =   'Rep_TrialBalanceWithCur.php?fromdate='+varfromdate+'&todate='+vartodate+'&fromledger='+varfromledger
			   +'&toledger='+vartoledger+'&fromproject='+varfromprj+'&fromcst='+varfromcst+'&fromcur='+varfromcur
			   +'&excludecst='+varexcludecst+'&options='+varoptions+'&grplen='+vargrplen+'&fromacctype='+varfromacctype
			   +'&frombustype='+varfrombustype+'&curr=1'
			   +'&alltypes='+varalltypes+'&exclude='+varexclude+'&jvtype='+varjvtype
			   +'&prtcv='+varprtcv+'&prtselper='+varprtselper+'&prtzerobal='+varprtzerobal+'&prtgrponly='+varprtgrponly
			   +'&prtdtonly='+varprtdtonly+'&prtreqdt='+varprtreqdt+'&prtparents='+varprtparents+'&prtdoc='+varprtdoc
			   +'&prtprjcst='+varprtprjcst+'&prtprjcst2='+varprtprjcst2+'&cltprj='+varcltprj+'&cltcst='+varcltcst+'&showactbal='+varshowactbal
			   +'&showprevdbcd='+varshowprevdbcd+'&prtheader='+varprtheader+'&fromsalesman='+vFromSalesman+'&tosalesman='+vToSalesman+'&vrange1='+vrange1+'&vrange2='+vrange2;
		else 
		if(varCompare == 1){
		str =	'rep_trialbalancecomparator.php?fromdate='+varfromdate+'&todate='+vartodate+'&fromledger='+varfromledger
				+'&toledger='+vartoledger+'&fromproject='+varfromprj+'&fromcst='+varfromcst+'&fromcur='+varfromcur
				+'&excludecst='+varexcludecst+'&options='+varoptions+'&grplen='+vargrplen+'&fromacctype='+varfromacctype
				+'&frombustype='+varfrombustype+'&curr='+varcurr+'&currbase1='+varcurrbase1+'&currbase2='+varcurrbase2
				+'&alltypes='+varalltypes+'&exclude='+varexclude+'&jvtype='+varjvtype
				+'&prtcv='+varprtcv+'&prtselper='+varprtselper+'&prtzerobal='+varprtzerobal+'&prtgrponly='+varprtgrponly
				+'&prtdtonly='+varprtdtonly+'&prtreqdt='+varprtreqdt+'&prtparents='+varprtparents+'&prtdoc='+varprtdoc
				+'&prtprjcst='+varprtprjcst+'&prtprjcst2='+varprtprjcst2+'&cltprj='+varcltprj+'&cltcst='+varcltcst+'&showactbal='+varshowactbal
				+'&showprevdbcd='+varshowprevdbcd+'&prtheader='+varprtheader+'&fromsalesman='+vFromSalesman+'&tosalesman='+vToSalesman
				+'&vrange1='+vrange1+'&vrange2='+vrange2+'&dbNames='+dbNames;
		}else
		str =   'rep_trialbalance.php?fromdate='+varfromdate+'&todate='+vartodate+'&fromledger='+varfromledger
			   +'&toledger='+vartoledger+'&fromproject='+varfromprj+'&fromcst='+varfromcst+'&fromcur='+varfromcur
			   +'&excludecst='+varexcludecst+'&options='+varoptions+'&grplen='+vargrplen+'&fromacctype='+varfromacctype
			   +'&frombustype='+varfrombustype+'&curr='+varcurr+'&currbase1='+varcurrbase1+'&currbase2='+varcurrbase2
			   +'&alltypes='+varalltypes+'&exclude='+varexclude+'&jvtype='+varjvtype
			   +'&prtcv='+varprtcv+'&prtselper='+varprtselper+'&prtzerobal='+varprtzerobal+'&prtgrponly='+varprtgrponly
			   +'&prtdtonly='+varprtdtonly+'&prtreqdt='+varprtreqdt+'&prtparents='+varprtparents+'&prtdoc='+varprtdoc
			   +'&prtprjcst='+varprtprjcst+'&prtprjcst2='+varprtprjcst2+'&cltprj='+varcltprj+'&cltcst='+varcltcst+'&showactbal='+varshowactbal
			   +'&showprevdbcd='+varshowprevdbcd+'&prtheader='+varprtheader+'&fromsalesman='+vFromSalesman+'&tosalesman='+vToSalesman+'&vrange1='+vrange1
			   +'&vrange2='+vrange2;
	}
	if (printaccess==1)
		window.open(str);
	else
		window.open(str,"Report", "width=900,height=600,screenX=0,left=50,screenY=0,top=0,status=no,menubar=no,scrollbars=yes,resizable=yes");
 
}

function ExportExcel()
{
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
  	

	for (var i=0; i < document.form1.options.length; i++)
	{
		if (document.form1.options[i].checked)
		{
			var varoptions = document.form1.options[i].value;
		}
	}
	 
  
	varexclude = 0;
	if (document.form1.exclude.checked)
		varexclude = 1;	
	
	varalltypes = 0;
	if (document.form1.alltypes.checked)
		varalltypes = 1;	
	
	var checkname;
	var x, varjvtype;
	varjvtype = '';
	for (var i=1; i <= document.form1.i.value; i++)
	{
		checkname='type'+i;
	
		x = document.getElementById(checkname);
		if (varalltypes == 0 && x.checked) 
			varjvtype = varjvtype+",'"+x.value+"'";
    
	}
	varjvtype = varjvtype.substr(1);
  
	varcurr = 0;
	if (document.form1.curr.checked) 
		varcurr = 1;	 
	
	varcurrbase1 = 0;
	if (document.form1.currbase1.checked)
		varcurrbase1 = 1;	
	
	varcurrbase2 = 0;
	if (document.form1.currbase2.checked)
		varcurrbase2 = 1;		
	
  	
  	

	varprtcv = 0;
	if (document.form1.prtcv.checked)
		varprtcv = 1;			
	
	varprtselper = 0;
	if (document.form1.prtselper.checked)
		varprtselper = 1;
	
	varprtzerobal = 0;
	if (document.form1.prtzerobal.checked)
		varprtzerobal = 1;	
	
	varprtgrponly = 0;
	if (document.form1.prtgrponly.checked)
		varprtgrponly = 1;	
	
	varprtdtonly = 0;
	if (document.form1.prtdtonly.checked)
		varprtdtonly = 1;		
	
	varprtreqdt = 0;
	if (document.form1.prtreqdt.checked)
		varprtreqdt = 1;	
	
	varprtparents = 0;
	if (document.form1.prtparents.checked)
		varprtparents = 1;		
  
	varprtdoc = 0;
	if (document.form1.prtdoc.checked)
		varprtdoc = 1;			

	varprtprjcst = 0;
	if (document.form1.prtprjcst.checked)
		varprtprjcst = 1;	
	
	varprtprjcst2 = 0;
	if (document.form1.prtprjcst2.checked)
		varprtprjcst2 = 1;

	varshowactbal = 0;
	if (document.form1.showactbal.checked)
		varshowactbal = 1;		
	
	varshowprevdbcd = 0;
	if (document.form1.showprevdbcd.checked)
		varshowprevdbcd = 1;

	varprtheader = 0;
	if (document.form1.prtheader.checked)
		varprtheader = 1;			
	 
	varmonthly   = 0;
	varprtprebal = 0;
	varprtcurbal = 0;
	varprtactbal = 0;
	varprtpredt  = 0;
	varprtcurdt  = 0;
	varprtactdt  = 0;
	if (document.form1.monthly.checked)	    varmonthly   = 1;	
	if (document.form1.prtprebal.checked)	varprtprebal = 1;	
	if (document.form1.prtcurbal.checked)	varprtcurbal = 1;	
	if (document.form1.prtactbal.checked)	varprtactbal = 1;	
	if (document.form1.prtpredt.checked)	varprtpredt  = 1;	
	if (document.form1.prtcurdt.checked)	varprtcurdt  = 1;	
	if (document.form1.prtactdt.checked)	varprtactdt  = 1;	
	
	varCompare = 0;
	if(document.form1.compare.checked)
		varCompare = 1;

	varbalancecur = 0;
	if (document.form1.balanceCur.checked)
		varbalancecur = 1;	
  
	varfromdate   = document.form1.fromdate.value;
	vartodate     = document.form1.todate.value;
	varfromledger = document.form1.fromledger.value;
	vartoledger   = document.form1.toledger.value;
	varfromprj    = document.form1.fromproject.value;
	varfromcst    = document.form1.fromcostcent.value;
	varexcludecst = document.form1.exclcostcent.value;
	varfromcur    = document.form1.fromcur.value;
	vargrplen     = document.form1.grplen.value;
	varfromacctype = document.form1.fromacctype.value;
	varfrombustype = document.form1.frombustype.value;
	
	var vFromSalesman = document.form1.fromsalesman.value;
	var vToSalesman   = document.form1.tosalesman.value;
  
	varcltprj       = document.form1.clientproject.value;
	varcltcst       = document.form1.clientcostcent.value;
	vrange1       = document.form1.range1.value;
	vrange2       = document.form1.range2.value;
	
	var ob = document.form1.valueOfI;
	var checkName;
	var dbNames = '';
	var obFound = 'false';
	if(varCompare == 1){
		for(var i=1, iLen=ob.value; i <= iLen; i++){
			checkname='dbName'+i;
			y = document.getElementById(checkname)
			if(y.checked){
				if(i > 1)
					dbNames = dbNames + ','
				dbNames = dbNames + y.value;
				obFound = 'true';
			}
		}
		if(obFound == 'false'){
			alert("Please Choose At Least 1 Schema");
			return;	
		}
	}
  
	varcltprj = varcltprj.replace('&','%26');
	varcltcst = varcltcst.replace('&','%26');
	
	varfromcst = encodeURIComponent(varfromcst);
	varexcludecst = encodeURIComponent(varexcludecst);
	varfromprj = encodeURIComponent(varfromprj);
	varcltprj = encodeURIComponent(varcltprj);
	varcltcst = encodeURIComponent(varcltcst);
	
	if (varmonthly == 1) RepName = 'Exp_TrialBalanceMonthly.php';
	else if(varCompare == 1) RepName = 'Exp_TrialBalanceComparator.php';
	else RepName = 'Exp_TrialBalance.php';
	var unbalanceRep = 0;
	if(document.getElementById("unbalanceRep").checked)
		unbalanceRep = 1;
	var unbrange = document.getElementById('unbrange').value;
	if(unbrange == '') unbrange = 0;
	
	if(unbalanceRep == 1) {
		str =  'Exp_UnbalancedJournal.php?fromdate='+varfromdate+'&todate='+vartodate+'&curr='+varcurr+'&currbase1='+varcurrbase1
			   +'&currbase2='+varcurrbase2+'&unbrange='+unbrange;
	} else {
	if(varbalancecur == 1)
		str =   'Exp_TrialBalanceWithCur.php?fromdate='+varfromdate+'&todate='+vartodate+'&fromledger='+varfromledger
			   +'&toledger='+vartoledger+'&fromproject='+varfromprj+'&fromcst='+varfromcst+'&fromcur='+varfromcur
			   +'&excludecst='+varexcludecst+'&options='+varoptions+'&grplen='+vargrplen+'&fromacctype='+varfromacctype
			   +'&frombustype='+varfrombustype+'&curr=1'
			   +'&alltypes='+varalltypes+'&exclude='+varexclude+'&jvtype='+varjvtype
			   +'&prtcv='+varprtcv+'&prtselper='+varprtselper+'&prtzerobal='+varprtzerobal+'&prtgrponly='+varprtgrponly
			   +'&prtdtonly='+varprtdtonly+'&prtreqdt='+varprtreqdt+'&prtparents='+varprtparents+'&prtdoc='+varprtdoc
			   +'&prtprjcst='+varprtprjcst+'&prtprjcst2='+varprtprjcst2+'&cltprj='+varcltprj+'&cltcst='+varcltcst+'&showactbal='+varshowactbal
			   +'&showprevdbcd='+varshowprevdbcd+'&prtheader='+varprtheader+'&fromsalesman='+vFromSalesman+'&tosalesman='+vToSalesman+'&vrange1='+vrange1+'&vrange2='+vrange2;
		else 
		if(varCompare == 1){
		str =	'Exp_TrialBalanceComparator.php?fromdate='+varfromdate+'&todate='+vartodate+'&fromledger='+varfromledger
				+'&toledger='+vartoledger+'&fromproject='+varfromprj+'&fromcst='+varfromcst+'&fromcur='+varfromcur
				+'&excludecst='+varexcludecst+'&options='+varoptions+'&grplen='+vargrplen+'&fromacctype='+varfromacctype
				+'&frombustype='+varfrombustype+'&curr='+varcurr+'&currbase1='+varcurrbase1+'&currbase2='+varcurrbase2
				+'&alltypes='+varalltypes+'&exclude='+varexclude+'&jvtype='+varjvtype
				+'&prtcv='+varprtcv+'&prtselper='+varprtselper+'&prtzerobal='+varprtzerobal+'&prtgrponly='+varprtgrponly
				+'&prtdtonly='+varprtdtonly+'&prtreqdt='+varprtreqdt+'&prtparents='+varprtparents+'&prtdoc='+varprtdoc
				+'&prtprjcst='+varprtprjcst+'&prtprjcst2='+varprtprjcst2+'&cltprj='+varcltprj+'&cltcst='+varcltcst+'&showactbal='+varshowactbal
				+'&showprevdbcd='+varshowprevdbcd+'&prtheader='+varprtheader+'&fromsalesman='+vFromSalesman+'&tosalesman='+vToSalesman
				+'&dbNames='+dbNames;
		}else
		str =   RepName+'?fromdate='+varfromdate+'&todate='+vartodate+'&fromledger='+varfromledger
			   +'&toledger='+vartoledger+'&fromproject='+varfromprj+'&fromcst='+varfromcst+'&fromcur='+varfromcur
			   +'&excludecst='+varexcludecst+'&options='+varoptions+'&grplen='+vargrplen+'&fromacctype='+varfromacctype
			   +'&frombustype='+varfrombustype+'&curr='+varcurr+'&currbase1='+varcurrbase1+'&currbase2='+varcurrbase2
			   +'&alltypes='+varalltypes+'&exclude='+varexclude+'&jvtype='+varjvtype
			   +'&prtcv='+varprtcv+'&prtselper='+varprtselper+'&prtzerobal='+varprtzerobal+'&prtgrponly='+varprtgrponly
			   +'&prtdtonly='+varprtdtonly+'&prtreqdt='+varprtreqdt+'&prtparents='+varprtparents+'&prtdoc='+varprtdoc
			   +'&prtprjcst='+varprtprjcst+'&prtprjcst2='+varprtprjcst2+'&prtprebal='+varprtprebal+'&prtcurbal='+varprtcurbal+'&prtactbal='+varprtactbal
			   +'&prtpredt='+varprtpredt+'&prtcurdt='+varprtcurdt+'&prtactdt='+varprtactdt
			   +'&cltprj='+varcltprj+'&cltcst='+varcltcst+'&showactbal='+varshowactbal+'&prtheader='+varprtheader
			   +'&showprevdbcd='+varshowprevdbcd+'&fromsalesman='+vFromSalesman+'&tosalesman='+vToSalesman+'&vrange1='+vrange1+'&vrange2='+vrange2;
	}
	window.open(str);
  
}

function showlistledger(str){

 var str1;
  for (var i=0; i < document.form1.options.length; i++)
  {
    if (document.form1.options[i].checked)
    {
      str1 = document.form1.options[i].value;
    }
  }
  
  var selectpage;
  if (document.form1.prtdoc.checked)
    selectpage = 'select_document.php?item='+str;
  else
    selectpage = 'select_ledger.php?item='+str+'&accountoption='+str1;	  
  
  window.open(selectpage,'mywindow','width=800,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistsalesman(str){
  window.open('select_salesman.php?item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistprojectcostcent(str,option){

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

function select_alljvtypes() {
   
   var checkname;
   var x;
   for (var i=1; i <= document.form1.i.value; i++)
  {
    checkname='type'+i;
	
	x = document.getElementById(checkname);
	if (document.form1.alltypes.checked) 
		x.checked = true;
	else
       	x.checked = false;
    
  }
  
  if (document.form1.alltypes.checked) {
     document.form1.exclude.checked = false;
     document.form1.exclude.disabled = true;
  }	 
  else
     document.form1.exclude.disabled = false;

}


function SelectPrtDetailCV() {
	var x= document.form1;
	
	if (x.prtcv.checked) {
	    x.curr.disabled = false;
	}	
	else {
		x.curr.checked = false;
	    x.curr.disabled = true;
		x.fromcur.value = '';
	}

}

function CheckPrjCstDt() {
    var x= document.form1;
	if (x.prtprjcst.checked == true || x.prtprjcst2.checked == true) {
	    x.curr.checked = false;
	    x.curr.disabled = true;
	}  
	else { 
    	x.curr.checked = true;
	    x.curr.disabled = false;
	}


}

function CheckOptions(option) {

	var x= document.form1;
	if (option==1) {
	    if (x.prtgrponly.checked == true) {
	       x.prtdtonly.checked = false;
		   x.prtreqdt.checked = false;
		}  
	}
	else if (option==2) {
	    if (x.prtdtonly.checked == true) {
	       x.prtgrponly.checked = false;
		   x.prtreqdt.checked = false;
		}  
	}
	else if (option==3) {
	    if (x.prtreqdt.checked == true) {
	       x.prtgrponly.checked = false;
		   x.prtdtonly.checked = false;
		}  
	}
	
	
	if (x.prtgrponly.checked == true) {
		x.prtparents.checked = true;	 
		x.prtparents.disabled = false;
	} else {	
	    x.prtparents.checked = false;	 
		x.prtparents.disabled = true;
	}	
	
	if (x.prtdtonly.checked == true) {
		x.prtdoc.disabled = false;
	} else {	
	    x.prtdoc.checked = false;	 
		x.prtdoc.disabled = true;
	}
		
	
}

function SelectMonthlyOption() {
	var x= document.form1;
	
	if (x.monthly.checked == true) {
	    x.prtprebal.disabled = false;
		x.prtcurbal.disabled = false;
		x.prtactbal.disabled = false;
		x.prtpredt.disabled  = false;
		x.prtcurdt.disabled  = false;
		x.prtactdt.disabled  = false;
		x.prtprebal.checked  = true;
		x.prtcurbal.checked  = true;
		x.prtactbal.checked  = true;
		x.prtpredt.checked   = true;
		x.prtcurdt.checked   = true;
		x.prtactdt.checked   = true;
	}  
	else {
		x.prtprebal.disabled = true;
		x.prtcurbal.disabled = true;
		x.prtactbal.disabled = true;
		x.prtpredt.disabled  = true;
		x.prtcurdt.disabled  = true;
		x.prtactdt.disabled  = true;
		x.prtprebal.checked  = false;
		x.prtcurbal.checked  = false;
		x.prtactbal.checked  = false;
		x.prtpredt.checked   = false;
		x.prtcurdt.checked   = false;
		x.prtactdt.checked   = false;
	}
}
function showlistProject(str){

  window.open('List_SorProject.php?frm=29&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=29&item='+str,'mywindow','width=850,height=550,,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function kdClient(choice,e,app)
{   
	 x = document.form1;
	if(app==0){
		var clientcode = x.fromledger.value;
		if(clientcode=='')
		var clientcode = x.fromledgername.value;
	} else {
		var clientcode = x.toledger.value;
		if(clientcode=='')
		var clientcode = x.toledgername.value;
	}	
    var intKey = (window.Event) ? e.which : e.keyCode;
	
		
    if (intKey == 13) { //enter key
	
	
		var xmlhttp = getXMLHttpRequest();	
		
		
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				var data = xmlhttp.responseText.split("[BRK]");
				
					if(app==0){
						if(data[0]!=''){
								x.fromledger.value = data[0];
								x.fromledgername.value = data[1];
									if(x.toledger.value==''){
									x.toledger.value = data[0];
									x.toledgername.value = data[1];
									
									}
						}
						else showlistledger(1);
					} else {
						if(data[0]!=''){
								x.toledger.value = data[0];
								x.toledgername.value = data[1];
							//if(x.toledgername.value!=''){
							//	x.submit();	
							//} 
						}
						else showlistledger(2);						
					}
			}
		}
	    
		xmlhttp.open("GET","Form_Statementofaccount_Action.php?mode=getclientname&clientcode="+clientcode+"&choice="+choice);
		xmlhttp.send();
	
     }
	

}
-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Trial Balance</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
.style1 {
	color: #FF0000;
	font-family: "Times New Roman", Times, serif;
	font-size: 20px;
}
.style8 {font-size: 11px; color: #999999; font-weight: bold; }
.style11 {font-size: 11px}
body {
	margin-top: 0px;
}
-->
</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='select_alljvtypes();'>
HERE;

echo "<form id='form1' name='form1' method='post' action='$_SERVER[PHP_SELF]'>";


echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";


echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>Trial Balance </span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";

echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='30'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px' align='left'>";
		
	echo" <button type='reset' id='btnClear' name='btnClear'  title='Clear'><span><span>Clear</span></span></button>";
		echo"<button type='button' id='btnPreview' name='btnPreview'  onClick=\"PrintPrev('".$printaccess."')\"; title='Preview'><span><span>Preview</span></span></button>";

	if ($ExporttoExcel==1){
		echo" <button type='button' id='btnExcel' name='btnExcel' onClick=\"ExportExcel()\"; title='Export Excel'><span><span>Export Excel</span></span></button>";

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

		
echo"<tr><td id='content-body'>
<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
   <tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>";		
echo '  <table height="450" border="0" align="center" width="100%">';

echo" <tr>";	  
echo"   <td width='20%' height='19' colspan='2' align='left' bgcolor='#F5F5F5'><span class='style8'>Date</span></td>";
echo"   <td width='25%' height='19' align='center' bgcolor='#F5F5F5'><span class='style8'>Currency</span></td>";
echo"   <td width='55%' height='19' colspan='3' align='center' bgcolor='#F5F5F5'><span class='style8'>Options </span></td>";
echo" </tr>";

echo" <tr height='15px'>";	  
echo"   <td width='5%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='15%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"      <input type='text' name='fromdate'  id='fromdate' value='$fromdate' maxlength='10' size='10'>";
echo"      <A HREF=\"#\" onClick=\"displayCalendar(document.form1.fromdate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span></td>";
echo"   <td width='25%' rowspan='2' bgcolor='#F5F5F5' valign='top'><span class='style8'><label>";
echo"      <input name='curr' type='checkbox' value='currency1' >Currency</label></span>";
echo"      <span class='style8'><select name='fromcur' id='fromcur'>";
		echo"<option></option>";
		while($curf=mysql_fetch_row($resultcurrency)){
		echo"<option ";
			if ($fromcur==$curf[0])
				echo " selected ";
		echo" value='$curf[0]'>$curf[0] </option>";
		}
		echo"</select></span>";

echo"   <br><span class='style8'><label>";
echo"      <input name='currbase1' type='checkbox' value='$rowsetup[0]' checked>$rowsetup[0]</label></span>";
echo"   <br><span class='style8'><label>";
echo"      <input name='currbase2' type='checkbox' value='$rowsetup[1]' >$rowsetup[1]</label></span>";
echo"	<br><br><br><div style='overflow:auto; height:125px; width:150px;' ><table border='1'><tr><td>";
$querydb = "SELECT LOWER(CONCAT(`companyName`,'_',`Diryear`)) AS dbName FROM ".$_SESSION['dbLabel'].".listuserdir WHERE usercode = ".$_SESSION['useraccount']." ORDER BY companyName, Diryear DESC";
//echo $querydb;exit;
$result_querydb = mysql_query($querydb, $connection);
$i = 0;
while($row_querydb = mysql_fetch_row($result_querydb)){
	$i = $i + 1;
	$$dbValue = $row_querydb[0];
	echo"	<span class='style8'><label>";
	echo"	<input type='checkbox' name='dbName".$i."' id='dbName".$i."' value='".$$dbValue."'/>$row_querydb[0]</label></span>";
}
echo "<input type='hidden' name='valueOfI' value='$i'>";
echo "</td></tr></table></div>";
echo"	</td>";

echo"   <td width='20%' rowspan='2' valign='top' bgcolor='#F5F5F5'><span class='style8'><label>";
echo"      <input name='prtcv' type='checkbox' id='prtcv' value='1' onclick='SelectPrtDetailCV()' checked />";
echo"      Print Detail C/V</label></span>";	
echo"   <br><span class='style8'><label>";
echo"      <input name='prtselper' type='checkbox' id='prtselper' value='1' />";
echo"      Selected Period Only</label></span>";
echo"   <br><span class='style8'><label>";
echo"      <input name='prtzerobal' type='checkbox' id='prtzerobal' value='1' checked/>";
echo"      Zero Balance</label></span>";
echo"   <br><span class='style8'><label>";
echo"      ";
echo"      Account balances not between</label></span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo"		<input type='text' name='range1' id='range1'  value='$range1' style='width:50px'> <span class='style8'>To</span> <input type='text' name='range2' id='range2'  value='$range2' style='width:50px'>";
echo"   <br><span class='style8'><label>";
echo"      <input name='showactbal' type='checkbox' id='showactbal' value='1' checked/>";
echo"      Show Actual Balance Only</label><br>";

echo"      <input name='showprevdbcd' type='checkbox' id='showprevdbcd' value='1'/>";
echo"      Show Previous Debit/Credit<br>";
echo"      <input name='balanceCur' type='checkbox' id='balanceCur' value='0' />Show All Currency";
echo"     <br> <input name='unbalanceRep' type='checkbox' id='unbalanceRep' value='0' />Print Unbalanced Journal Report &nbsp;&nbsp; >
		 <input type='text' name='unbrange' id='unbrange'  value='0.99' style='width:40px;font-size:12px;'> ";
echo"</span></td>";

		
echo"   <td width='17%' rowspan='2' valign='top' bgcolor='#F5F5F5'><span class='style8'><label>";
echo"      <input name='prtgrponly' type='checkbox' id='prtgrponly' value='1' onClick='return CheckOptions(1);' />";
echo"      Group Only</label></span>";
echo"      <select name='grplen' id='grplen' >";
		for ($i=1; $i<=10; $i++) {
		  echo"<option value='$i' "; if($i==1) echo " selected "; echo "> $i </option>";
		}
		echo"</select>";	
echo"   <br><span class='style8'><label>";
echo"      <input name='prtdtonly' type='checkbox' id='prtdtonly' value='1' onClick='return CheckOptions(2);' />";
echo"      Detail Only</label></span>";
echo"   <br><span class='style8'><label>";
echo"      <input name='prtreqdt' type='checkbox' id='prtreqdt' value='1' onClick='return CheckOptions(3);' />";
echo"      Required Detail</label></span>";
echo"   <br><span class='style8'><label>";


if($ShowReportHeader== 1 && $module_ReferenceByCostcenter== 1)
	echo"      <input name='prtheader' type='checkbox' id='prtheader' value='1' checked />";
else
if($ShowReportHeader== 0 && $module_ReferenceByCostcenter== 1)
	echo"      <input name='prtheader' type='checkbox' id='prtheader' value='1'  />";
else
if($module_ReferenceByCostcenter== 0)
	echo"      <input name='prtheader' type='checkbox' id='prtheader' value='1' checked />";
else
	echo"      <input name='prtheader' type='checkbox' id='prtheader' value='1'  />";
echo"      Show Report Header</label></span>";
echo"   <br><span class='style8'><label>";
echo"		<input name='compare' type='checkbox' id='compare' value='1' />";
echo"      Compare Years</label></span></td>";
		
echo"   <td width='18%' rowspan='2' valign='top' bgcolor='#F5F5F5' valign='top' ><span class='style8'><label>";
echo"      <input name='prtparents' type='checkbox' id='prtparents' value='1' disabled />";
echo"      With Parents</label></span>";	
echo"   <br><span class='style8'><label>";
echo"      <input name='prtdoc' type='checkbox' id='prtdoc' value='1' disabled />";
echo"      By Document</label></span>";

echo"   <br><span class='style8'><label>";
echo"      <input name='prtprjcst' type='checkbox' id='prtprjcst' value='1' onClick='return CheckPrjCstDt();' />";
echo"      Print Detail Shipment Ref</label></span>";
echo"   <br><span class='style8'><label>";
echo"      <input name='prtprjcst2' type='checkbox' id='prtprjcst2' value='1' onClick='return CheckPrjCstDt();' />";
echo"      Print Detail Costcenter</label></span></td>";			
echo" </tr>";

echo" <tr height='15px'>";
echo"   <td width='5%' valign='top' bgcolor='#F5F5F5'><span class='style8'>To</span></td>";
echo"   <td width='15%' valign='top' bgcolor='#F5F5F5'><span class='style8'>";
echo"      <input type='text' name='todate'  id='todate' value='$todate'  maxlength='10' size='10'>";
echo"      <A HREF=\"#\" onClick=\"displayCalendar(document.form1.todate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A></span></td>";
echo" </tr>";

echo" <tr height='15px'>";
echo"   <td colspan='6' bgcolor='#F5F5F5'><span class='style8'>&nbsp;";

echo"Periods: <select name='period' id='period' onchange=\"setdateperiods(this.value,'fromdate','todate')\" >";
echo"<option value=0></option>";
echo"<option value=1>Today</option>";
echo"<option value=2>Week</option>";
echo"<option value=3>This Month</option>";
echo"<option value=4>1st Quarter</option>";
echo"<option value=5>2nd Quarter</option>";
echo"<option value=6>3rd Quarter</option>";
echo"<option value=7>Last Quarter</option>";
echo"<option value=8>This Year</option>";
echo"</select>";


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

echo" <tr height='15px'>";
echo"   <td colspan='3' bgcolor='#F5F5F5'><span class='style8'>Ledger No. / Name </span></td>";
echo"   <td  bgcolor='#F5F5F5'><span class='style8'>&nbsp; </span></td>";
echo"   <td bgcolor='#F5F5F5'><span class='style8'> ";
echo"   	<label><input name='alltypes' type='checkbox' id='alltypes' value='1' onclick='select_alljvtypes();' checked/>All Types</label>";
echo"   	<label><input name='exclude' type='checkbox' id='exclude' value='1' />Exclude</label></span></td>";
echo"   <td bgcolor='#F5F5F5'><span class='style8'> ";
echo"   	<label><input name='monthly' type='checkbox' id='monthly' value='1' onclick='SelectMonthlyOption();' /> Monthly Distribution </label></span></td>";
echo" </tr>";



echo" <tr height='15px'>";	  
echo"   <td width='5%'  align='left' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='40%'  colspan='2' valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <input name='fromledger' type='text' id='fromledger' size='10' value='".$fromledger."' onkeydown='return kdClient(0,event,0);' />
        <input name='fromledgername' type='text' id='fromledgername' size='35' value='".$fromledgername."' onkeydown='return kdClient(1,event,0);' />
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Ledger From ' 
             onClick='showlistledger(1); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label>      ";

echo"   <td width='20%' rowspan='7' valign='top' bgcolor='#F5F5F5'><span class='style8'><label>";
		if (($options=="1"  || $options=="") and $RadioOpt=='enabled')
           echo "<input name='options' type='radio' value='1' checked $RadioOpt/>";
		else	
		   echo "<input name='options' type='radio' value='1' $RadioOpt/>";
		echo "Trial Balance</label></span>";
echo"   <br><span class='style8'><label>";
		if (($options=="2") and $RadioOpt=='enabled')
           echo "<input name='options' type='radio' value='2' checked $RadioOpt/>";
		else	
		   echo "<input name='options' type='radio' value='2' $RadioOpt/>";
		echo "Debitors</label></span>";		
echo"   <br><span class='style8'><label>";
		if (($options=="3") and $RadioOpt=='enabled')
           echo "<input name='options' type='radio' value='3' checked $RadioOpt/>";
		else	
		   echo "<input name='options' type='radio' value='3' $RadioOpt/>";
		echo "Creditors </label></span>";
echo"   <br><span class='style8'><label>";
		if (($options=="4") or  $RadioOpt=='disabled')
           echo "<input name='options' type='radio' value='4' checked />";
		else	
		   echo "<input name='options' type='radio' value='4' />";
		echo "Clients </label></span>";
echo"   <br><span class='style8'><label>";
		if (($options=="5") and $RadioOpt=='enabled')
           echo "<input name='options' type='radio' value='5' checked $RadioOpt/>";
		else	
		   echo "<input name='options' type='radio' value='5' $RadioOpt/>";
		echo "Suppliers </label></span>";		
echo"   <br><span class='style8'><label>";
		if (($options=="6") and $RadioOpt=='enabled')
           echo "<input name='options' type='radio' value='6' checked $RadioOpt/>";
		else	
		   echo "<input name='options' type='radio' value='6' $RadioOpt/>";
		echo "Debitors/Creditors </label></span>";
echo"   <br><span class='style8'><label>";
		if (($options=="7") and $RadioOpt=='enabled')
           echo "<input name='options' type='radio' value='7' checked $RadioOpt />";
		else	
		   echo "<input name='options' type='radio' value='7' $RadioOpt/>";
		echo "Acctype </label></span>";		
		
		echo"<br><select name='fromacctype' id='fromacctype' style='font-size: 10px; width:200px;'>";
		echo"<option></option>";
		while($rowacctype=mysql_fetch_row($resultacctype)){
		echo"<option ";
			if (($fromacctype==$rowacctype[0]))
				echo " selected ";
		echo" value='$rowacctype[0]'>$rowacctype[0] / $rowacctype[1]</option>";
		}
		echo"</select>";
		
echo"   <br><span class='style8'><label>";
		if (($options=="8") and $RadioOpt=='enabled')
           echo "<input name='options' type='radio' value='8' checked $RadioOpt />";
		else	
		   echo "<input name='options' type='radio' value='8' $RadioOpt/>";
		echo "Business Type </label></span>";	
echo"	<br><select name='frombustype' id='frombustype' style='font-size: 10px; width:200px;'>";
		echo"<option></option>";
		while($rowbustype=mysql_fetch_row($resultbustype)){
		echo"<option ";
			if (($frombustype==$rowbustype[0]))
				echo " selected ";
		echo" value='$rowbustype[0]'>$rowbustype[0]</option>";
		}
		echo"</select>";
		
echo"   </td>";	
			 
echo"   <td width='17%' rowspan='7' valign='top' bgcolor='#F5F5F5'><div style='overflow:auto; height:120px; width:80px;' ><table border='0'><tr><td>";
		
		$i = 0;
		while($jvtype=mysql_fetch_row($resultjvtype)){
		   $i = $i + 1;
		   $type  = 'type'.$i;
		   $$type = $jvtype[0];
		   
		   echo"<span class='style8'><label>";
           echo"<input name='$type' type='checkbox' id='$type' value='".$$type."' /> $jvtype[0] </label></span>";
		}
		echo "<input type='hidden' name='i' value='$i'>";
		echo "</td></tr></table></div></td>";   

echo"   <td width='18%' rowspan='7' valign='top' bgcolor='#F5F5F5'><span class='style8'>";
echo"   	<label><input name='prtprebal' type='checkbox' id='prtprebal' value='1' disabled /> Show Prev. Balance </label>";
echo"   	<br>&nbsp;&nbsp;<label><input name='prtpredt' type='checkbox' id='prtpredt' value='1' disabled /> Show Details </label>";
echo"   	<br><label><input name='prtcurbal' type='checkbox' id='prtcurbal' value='1' disabled /> Show Current Balance </label>";
echo"   	<br>&nbsp;&nbsp;<label><input name='prtcurdt' type='checkbox' id='prtcurdt' value='1' disabled /> Show Details </label>";
echo"   	<br><label><input name='prtactbal' type='checkbox' id='prtactbal' value='1' disabled /> Show Actual Balance </label>";
echo"   	<br>&nbsp;&nbsp;<label><input name='prtactdt' type='checkbox' id='prtactdt' value='1' disabled /> Show Details </label>";
echo"   </span></td>";

echo" </tr>";
   
echo" <tr height='15px'>";	  
echo"   <td width='5%'  align='left' bgcolor='#F5F5F5' valign='top'><span class='style8'>To</span></td>";
echo"   <td width='40%'  colspan='2' valign='top' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <input name='toledger' type='text' id='toledger' size='10' value='".$toledger."' onkeydown='return kdClient(0,event,1);' />
        <input name='toledgername' type='text' id='toledgername' size='35' value='".$toledgername."' onkeydown='return kdClient(1,event,1);' />
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Ledger To ' 
             onClick='showlistledger(2); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label>      ";


echo" </tr>";

echo"<tr height='15px'><td bgcolor='#F5F5F5' colspan='3'><span class='style8'>Salesman Code / Description <label><input name='grpsalesman' type='checkbox' id='grpsalesman' value='1'>Group By Salesman</label></span></td><tr>";
echo"<tr height='15px'><td bgcolor='#F5F5F5'><span class='style8'>From</span></td>";
echo"	 <td bgcolor='#F5F5F5' colspan='2'><span class='style8'>
			<input type='text' name='fromsalesman'  value='$fromsalesman' size='10'>
			<input type='text' name='fromsalesmandesc'  value='$fromsalesmandesc' size='35'>
			<img src='img/btnopen.jpg' title=' Select Salesman '  width='15' height='17' border='0' style='cursor:pointer;' onClick='showlistsalesman(1); return false'>";
echo"		</span></td>
	  </tr>";		
echo"<tr height='15px'><td bgcolor='#F5F5F5'><span class='style8'>To</span></td>";
echo"	 <td bgcolor='#F5F5F5' colspan='2'><span class='style8'>
			<input type='text' name='tosalesman'  value='$tosalesman' size='10'>
			<input type='text' name='tosalesmandesc'  value='$tosalesmandesc' size='35'>
			<img src='img/btnopen.jpg' title=' Select Salesman '  width='15' height='17' border='0' style='cursor:pointer;' onClick='showlistsalesman(2); return false'>";
echo"		</span></td>
	 </tr>";

echo" <tr height='20px'>";
echo"   <td colspan='3' bgcolor='#F5F5F5'><span class='style8'>Excluded Costcenter </span></td>";
echo" </tr>";
echo" <tr height='20'>";
echo"   <td colspan='3' bgcolor='#F5F5F5'><span class='style8'>";
echo "<input type='text' name='exclcostcent' id='exclcostcent' value='$exclcostcent' style='width:102px;' maxlength='20'  />";
echo " <input type='text' name='exclcostcentdesc' id='exclcostcentdesc' value='$exclcostcentdesc' style='width:102px;'  /></span>";
echo " <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCostcenter(3); ' /></span></label></td>";

/*echo "<select name='exclcostcent' id='exclcostcent' style='width:420px'>";
		echo"<option></option>";
		while($cst=mysql_fetch_row($resultcostcent1)){
		echo"<option ";
			if ($exclcostcent==$cst[0]) echo " selected ";
		echo" value='$cst[0]'>$cst[0] / $cst[1]</option>";
		}
		echo"</select></span></td>";*/
echo" </tr>";




if($fromproject == '') { $fromproject=$defaultproject;	$fromprojectdesc = $defaultprojname;}
echo" <tr height='35px'>";
echo"   <td width='45%' colspan='3' valign='middle' bgcolor='#F5F5F5'><span class='style8'> Shipment Ref  ";
echo "<input type='text' name='fromproject' id='fromproject' value='$fromproject' style='width:130px;' maxlength='20'  />";
echo " <input type='text' name='fromprojectdesc' id='fromprojectdesc' value='$fromprojectdesc' style='width:130px;'  /></span>";
echo " <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistProject(1); '  /></span></label></td>";
			
/*echo"      <select name='fromproject' id='fromproject' style='width:370px'>";
		if ($projectrows > 0) echo"<option></option>";
		while($prj=mysql_fetch_row($resultproject)){
		echo"<option ";
			if (($fromproject==$prj[0]) || ($defaultproject==$prj[0] && $Module_RestrictProjectReport==1))
				echo " selected ";
		echo" value='$prj[0]'>$prj[0] / $prj[1]</option>";
		}
		echo"</select></span>";*/
if($clientproject == ''){ $clientproject=$defaultproject;	$clientprojectdesc = $defaultprojname;}
echo"   <td width='55%' colspan='3' valign='middle' bgcolor='#F5F5F5'><span class='style8'> Client Project&nbsp;&nbsp;";
 echo "<input type='text' name='clientproject' id='clientproject' value='$clientproject' style='width:130px;' maxlength='20'  />";
echo " <input type='text' name='clientprojectdesc' id='clientprojectdesc' value='$clientprojectdesc' style='width:130px;'   /></span>";

     /*echo  " <select name='clientproject' id='clientproject' style='width:400px'>";
		echo"<option></option>";
		while($prj=mysql_fetch_row($resultproject2)){
		echo"<option ";
			if (($clientproject==$prj[0]) || ($defaultproject==$prj[0]  && $Module_RestrictProjectReport==1))
				echo " selected ";
		echo" value='$prj[0]'>$prj[0] / $prj[1]</option>";
		}
		echo"</select>";*/
echo" <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Project ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistProject(2); '  /></span></label></td>";	
echo" </tr>";

if($fromcostcent == '') { $fromcostcent=$defaultcostcent;	$fromcostcentdesc = $defaultcostcentname; }
echo" <tr height='20'>";
echo"   <td colspan='3' bgcolor='#F5F5F5'><span class='style8'> CostCenter ";
echo "<input type='text' name='fromcostcent' id='fromcostcent' value='$fromcostcent' style='width:102px;' maxlength='20'  />";
echo " <input type='text' name='fromcostcentdesc' id='fromcostcentdesc' value='$fromcostcentdesc' style='width:102px;'   /></span>";
echo " <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCostcenter(1); ' /></span></label></td>";
/*echo "<select name='fromcostcent' id='fromcostcent' style='width:345px'>";
		if ($costcentrows > 0) echo"<option></option>";
		while($cst=mysql_fetch_row($resultcostcent)){
		echo"<option ";
			if (($fromcostcent==$cst[0]) || ($defaultcostcent==$cst[0]))
				echo " selected ";
		echo" value='$cst[0]'>$cst[0] / $cst[1]</option>";
		}
		echo"</select>";*/
			
		//maroun
	if($clientcostcent == '') { $clientcostcent=$defaultcostcent;	$clientcostcentdesc = $defaultcostcentname; }
		echo"   <td width='45%' colspan='3' valign='top' bgcolor='#F5F5F5'><span class='style8'> Client CostCent &nbsp;&nbsp;";
	echo "<input type='text' name='clientcostcent' id='clientcostcent' value='$clientcostcent' style='width:102px;' maxlength='20' />";
	echo " <input type='text' name='clientcostcentdesc' id='clientcostcentdesc' value='$clientcostcentdesc' style='width:102px;'   /></span>";
	echo " <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Costcenter ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  onClick='showlistCostcenter(2); ' /></span></label></td>";
	
		/*echo "<select name='clientcostcent' id='clientcostcent' style='width:400px'>";
		echo"<option></option>";
		while($cst=mysql_fetch_row($resultcostcent2)){
		echo"<option ";
			if (($clientcostcent==$cst[0]) || ($defaultcostcent==$cst[0]))
				echo " selected ";
		echo" value='$cst[0]'>$cst[0] / $cst[1]</option>";
		}
		echo"</select></span></td>";*/
		
		
echo" </tr>";

echo" <tr >";
echo"   <td colspan='6' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";
  /*  <tr>
      <td colspan='6' align='center' bgcolor='#F5F5F5'>
		<input type='reset'  name='btnClear' value='Clear' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' />
		<input type='button' name='btnPreview' id='btnPreview' value='Preview' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"PrintPrev('".$printaccess."')\"; />
		<input type='".$ExporttoExcelStatus."' name='btnExcel' id='btnExcel' value='Export Excel' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"ExportExcel()\";/>	  
      </td>
    </tr>*/
		echo"   </table></td></tr>"; 
	echo"   </table></td></tr><tr height='30'><td align='center' id='content-bottom' ></td></tr>"; 
  echo"</table>
 
</form>
</body>
</html>";

?>