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


$querylog="SELECT RA_AgingOfClientInvoices as loginaccess, ExporttoExcel, Print 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';
	

$printaccess=$Print;


$querysetup ="select base1, base2, if(DefaultBase=1, base1, base2) as defaultcurr, grid_color1, grid_color2 from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
$rowsetup=mysql_fetch_row($resultsetup);
$defaultcurr = $rowsetup[2];


// 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, Date_Format(NOW(),'%d/%m/%Y') As DefaultAgingDate ".
		   " 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];
if (!isset($agingdate)) $agingdate = $rowdate[2];
  

$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);
}
$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);
}

$queryInvoice="select ifNull(module_invoicegrid,0) As module_invoicegridAll from Module ";
$resultInvoice=mysql_query($queryInvoice,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultInvoice)){
	extract($rows);
}

if ((empty($fromproject)) && $Module_Project == 1)
	$fromproject = $defaultproject;
if ((empty($fromcostcent)) && $Module_CostCenter == 1)
	$fromcostcent = $defaultcostcent;	

print <<< HERE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=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 language="JavaScript" src="CalendarPopup.js" ></script><!-- Date only with year scrolling -->
<script type="text/javascript" language="javascript">
<!--


function PrintPrev(printaccess,indx)
{
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
  	
	for (var i=0; i < document.form1.date.length; i++)
	{
		if (document.form1.date[i].checked)
		{
			var vardate = document.form1.date[i].value;
		}
	}	 
  
	for (var i=0; i < document.form1.currency.length; i++)
	{
		if (document.form1.currency[i].checked)
		{
			var varcurrency = document.form1.currency[i].value;
		}
	}
	
	for (var i=0; i < document.form1.repoption.length; i++)
	{
		if (document.form1.repoption[i].checked)
		{
			var varrepoption = document.form1.repoption[i].value;
		}
	}
  
	varprtclosedinv = 0;
	if (document.form1.prtclosedinv.checked)
		varprtclosedinv = 1;
	
	if (document.form1.showall)
		if (document.form1.showall.checked)
			varprtclosedinv = 0;
		
	varprtdesc = 0;
	if (document.form1.prtdesc.checked)
		varprtdesc = 1;
		
	varprtsummary = 0;
	if (document.form1.prtsummary.checked)
		varprtsummary = 1;		

	/*varprtreturn = 0;
	if (document.form1.prtreturn.checked)
		varprtreturn = 1;*/
		
	varriskbal = 0;
	if (document.form1.riskbal)
	if (document.form1.riskbal.checked)
		varriskbal = 1;
		
	varshownondues = 0;
	if (document.form1.shownondues)
	if (document.form1.shownondues.checked)
		varshownondues = 1;	
 
	varfromdate     = document.form1.fromdate.value;
	vartodate       = document.form1.todate.value;
	varagingdate    = document.form1.agingdate.value;
	varfromledger   = document.form1.fromledger.value;
	vartoledger     = document.form1.toledger.value;
	
	varfromsalesman   = document.form1.fromsalesmancode.value;
	vartosalesman     = document.form1.tosalesmanname.value;
	
	varfromprj      = document.form1.fromproject.value;
	varfromcst      = document.form1.fromcostcent.value;
	
	var chkper = 0;
	if(document.getElementById("chkper").checked)
		chkper = 1;
	 
	var examnt1 = document.getElementById("examnt1").value;
	var examnt2 = document.getElementById("examnt2").value;
	
	var chksalesman = 0;
	if(document.getElementById("chksalesman").checked)
		chksalesman = 1;
	
	varreport = '';
	
	
	if(indx == 2){
		if(chkper == 1) varreport = 'Rep_AgingClientInvoicesDays.php';
		else {
			if (varrepoption == 1) varreport = 'Rep_AgingClientInvoicesDetails2.php';
			else if (varrepoption == 2) varreport = 'Rep_AgingClientInvoices2.php';
		}
	} else {
		varreport = 'Rep_AgingClientInvoices.php?';	
		if (varrepoption == 2) varreport = 'Rep_AgingClientInvoicesSummary.php';
		else if (varrepoption == 3) varreport = 'Rep_AgingClientInvoicesDetail.php';
	}
		
	str = varreport +'?fromdate='+varfromdate+'&todate='+vartodate+'&agingdate='+varagingdate+'&fromledger='+varfromledger+'&toledger='+vartoledger
					+'&dateoption='+vardate+'&curr='+varcurrency+'&prtclosedinv='+varprtclosedinv+'&riskbal='+varriskbal
					+'&shownondues='+varshownondues+'&fromproject='+varfromprj+'&fromcst='+varfromcst+'&prtdesc='+varprtdesc+'&prtsummary='+varprtsummary
					+'&fromsalesman='+varfromsalesman+'&tosalesman='+vartosalesman+"&examnt1="+examnt1+"&examnt2="+examnt2+"&chksalesman="+chksalesman;
					//+'&prtreturn='+varprtreturn
				 
	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(indx)
{
	width = screen.width - 10;
	height = screen.height - 66;
	var str='';
  	
	for (var i=0; i < document.form1.date.length; i++)
	{
		if (document.form1.date[i].checked)
		{
			var vardate = document.form1.date[i].value;
		}
	}	 
  
	for (var i=0; i < document.form1.currency.length; i++)
	{
		if (document.form1.currency[i].checked)
		{
			var varcurrency = document.form1.currency[i].value;
		}
	}
	
	for (var i=0; i < document.form1.repoption.length; i++)
	{
		if (document.form1.repoption[i].checked)
		{
			var varrepoption = document.form1.repoption[i].value;
		}
	}
  
	varprtclosedinv = 0;
	if (document.form1.prtclosedinv.checked)
		varprtclosedinv = 1;
	
	if (document.form1.showall)
		if (document.form1.showall.checked)
			varprtclosedinv = 0;
		
	varprtdesc = 0;
	if (document.form1.prtdesc.checked)
		varprtdesc = 1;
		
	varprtsummary = 0;
	if (document.form1.prtsummary.checked)
		varprtsummary = 1;		

	/*varprtreturn = 0;
	if (document.form1.prtreturn.checked)
		varprtreturn = 1;*/
		
	varriskbal = 0;
	if (document.form1.riskbal)
	if (document.form1.riskbal.checked)
		varriskbal = 1;
		
	varshownondues = 0;
	if (document.form1.shownondues)
	if (document.form1.shownondues.checked)
		varshownondues = 1;
      
	varfromdate     = document.form1.fromdate.value;
	vartodate       = document.form1.todate.value;
	varagingdate    = document.form1.agingdate.value;
	varfromledger   = document.form1.fromledger.value;
	vartoledger     = document.form1.toledger.value;
	
	varfromprj      = document.form1.fromproject.value;
	varfromcst      = document.form1.fromcostcent.value;
	
	varfromsalesman   = document.form1.fromsalesmancode.value;
	vartosalesman     = document.form1.tosalesmanname.value;
	
	var chkper = 0;
	if(document.getElementById("chkper").checked)
		chkper = 1;
	
	var examnt1 = document.getElementById("examnt1").value;
	var examnt2 = document.getElementById("examnt2").value;
	
	var chksalesman = 0;
	if(document.getElementById("chksalesman").checked)
		chksalesman = 1;
	
	varreport = '';
	if(indx == 2){
		if (chkper==1) varreport = 'Exp_AgingClientInvoicesDays.php';
		else {
			if (varrepoption == 2) varreport = 'Exp_AgingClientInvoices2.php';
			else if (varrepoption == 1) varreport = 'Exp_AgingClientInvoicesDetails2.php';
		}
	} else{
	varreport = 'Exp_AgingClientInvoices.php';
	if (varrepoption == 2) varreport = 'Exp_AgingClientInvoicesSummary.php';
	else if (varrepoption == 3) varreport = 'Exp_AgingClientInvoicesDetail.php';
	}
	str = varreport +'?fromdate='+varfromdate+'&todate='+vartodate+'&agingdate='+varagingdate+'&fromledger='+varfromledger+'&toledger='+vartoledger
					+'&dateoption='+vardate+'&curr='+varcurrency+'&prtclosedinv='+varprtclosedinv+'&riskbal='+varriskbal
					+'&shownondues='+varshownondues+'&fromproject='+varfromprj+'&fromcst='+varfromcst+'&prtdesc='+varprtdesc+'&prtsummary='+varprtsummary
					+'&fromsalesman='+varfromsalesman+'&tosalesman='+vartosalesman+"&examnt1="+examnt1+"&examnt2="+examnt2+"&chksalesman="+chksalesman;

					//+'&prtreturn='+varprtreturn
	window.open(str);

}


function showlistledger(str){

	var str1 = 2;
	window.open('select_accountno.php?item='+str+'&accountoption='+str1,'mywindow','width=710,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

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

function showlistCostcenter(frm){

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

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

function ClearPage() {
	x = document.form1;
	
	//x.templateid.value = '';
	//x.action='Form_AgingClientInvoices.php';
	//x.submit();
	
	window.location ='Form_AgingClientInvoices.php';
	
}

function SelectReportOption(pvalue) {
	x = document.form1;

	if (pvalue == 1) {
		if (document.form1.riskbal) 
			x.riskbal.disabled = true;
		if (document.form1.shownondues)
			x.shownondues.disabled = true;
		x.prtdesc.disabled = false;
		x.prtsummary.disabled = false;
	}
	else if (pvalue == 2) {
		if (document.form1.riskbal)
			x.riskbal.disabled = false;
		if (document.form1.shownondues)
			x.shownondues.disabled = false;
		x.prtdesc.disabled = true;
		x.prtsummary.disabled = true;
	}
	else if (pvalue == 3) {
		if (document.form1.riskbal) 
			x.riskbal.disabled = true;
		if (document.form1.shownondues)
			x.shownondues.disabled = true;
		x.prtdesc.disabled = true;
		x.prtsummary.disabled = true;
	}
}
/* function showSelected(indx){
	if(indx == 1){
	if(document.getElementById("showall").checked){
		document.getElementById("showall").checked=false;
		document.getElementById("showall").value=0;
		document.getElementById("prtclosedinv").checked=true;
		document.getElementById("prtclosedinv").value=1;
	} else if(!document.getElementById("showall").checked){
		document.getElementById("showall").checked=true;
		document.getElementById("showall").value=1;
		document.getElementById("prtclosedinv").checked=false;
		document.getElementById("prtclosedinv").value=0;
	}
	}
	else if(indx == 2){
	if(!document.getElementById("prtclosedinv").checked){
		document.getElementById("prtclosedinv").checked=true;
		document.getElementById("prtclosedinv").value=1;
		document.getElementById("showall").checked=false;
		document.getElementById("showall").value=0;
	} else 	
	if(document.getElementById("prtclosedinv").checked){
		document.getElementById("prtclosedinv").checked=false;
		document.getElementById("prtclosedinv").value=0;
		document.getElementById("showall").checked=true;
		document.getElementById("showall").value=1;
	}	
	}
} */


function SelectRecord(PPeriodPrev,PPeriod) {
	x = document.form1;
	
	x.txtPeriodPrev.value = PPeriodPrev;
	x.txtPeriod.value = PPeriod;
}

function SubmitRecord() {
	x = document.form1;
	
	var vPeriodPrev = x.txtPeriodPrev.value;
	
	if (vPeriodPrev != '') x.actionmode.value='editperiod';
	else x.actionmode.value='insertperiod';
	
	x.submit();
}

-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Aging Client Invoices</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>
HERE;



echo "<form id='form1' name='form1' method='post' action='$_SERVER[PHP_SELF]' >
		<input type='hidden' name='templateid' value='$templateid'>.
		<input type='hidden' name='actionmode' value='$actionmode'>";
		
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>";
	

if (isset($_POST['actionmode']) && $_POST['txtPeriod'] != '' && $_POST['txtPeriodPrev'] == '' && $_POST['actionmode']=='insertperiod') {
	$query="select * from aging where  Period = '".$_POST['txtPeriod']."' ;";
	$res = mysql_query($query,$connection);
	$num = mysql_num_rows($res);
	if($num == 0){	
		$sub_query  = "insert into aging (Period) values ('".$_POST['txtPeriod']."') ";
		$sub_result = mysql_query($sub_query);
	}
	$_POST['txtPeriod'] ='';
	 $_POST['txtPeriodPrev'] = '';
	$actionmode = "";
}
else if (isset($_POST['actionmode']) && $_POST['actionmode'] == 'editperiod' && $_POST['txtPeriodPrev'] != "") {
	$sub_query  = "update aging set Period='".$_POST['txtPeriod']."' where Period='".$_POST['txtPeriodPrev']."' ";
	$sub_result = mysql_query($sub_query);
	$_POST['txtPeriod'] ='';
	 $_POST['txtPeriodPrev'] = '';
	$actionmode = "";
}

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'>Aging of Client Invoices</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>";
if($module_invoicegridAll == 2) 	
		echo"<button type='button' id='btnPreview' name='btnPreview'  onClick=\"PrintPrev('".$printaccess."',2)\"; title='Preview'><span><span>Preview</span></span></button>";
else echo"<button type='button' id='btnPreview' name='btnPreview'  onClick=\"PrintPrev('".$printaccess."',1)\"; title='Preview'><span><span>Preview</span></span></button>";

	if ($ExporttoExcel==1){
		if($module_invoicegridAll == 2) 	
			echo" <button type='button' id='btnExcel' name='btnExcel' onClick=\"ExportExcel(2)\"; title='Export Excel'><span><span>Export Excel</span></span></button>";
		else echo" <button type='button' id='btnExcel' name='btnExcel' onClick=\"ExportExcel(1)\"; 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 border="0" align="center" valign="top" 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='23%' height='19' align='center' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo"   <td width='12%' height='19' align='center' bgcolor='#F5F5F5'><span class='style8'> Currency</span></td>";
echo"   <td width='20%' height='19' align='center' bgcolor='#F5F5F5'><span class='style8'>Options</span></td>";
echo"   <td width='25%' height='19' align='left' bgcolor='#F5F5F5'><span class='style8'>";
if($module_invoicegridAll == 2) echo "<input type='checkbox' name='chkper' id='chkper' value='0'>Period";
else echo "<input type='hidden' name='chkper' id='chkper' value='0'>";
echo"</span></td>";
echo" </tr>";

echo" <tr height='25'>";	  
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' 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='23%' rowspan='2' valign='top' bgcolor='#F5F5F5'><span class='style8'>Up to date ";
echo"      <input type='text' name='agingdate' value='$agingdate' maxlength='10' size='10'>";
echo"      <A HREF=\"#\" onClick=\"displayCalendar(document.form1.agingdate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A>";
echo"      <br><label><input name='date' type='radio' value='1' checked='checked'>Date</label>";
echo"      <br><label><input name='date' type='radio' value='2'>Value Date</label> ";
echo"      <br><label>Exlude Amounts <input name='examnt1' id='examnt1' type='text' value='$examnt1' style='width:50px;'>
		- <input name='examnt2' id='examnt2' type='text' value='$examnt2' style='width:50px;'></label></span> ";
echo"   </td>";

echo"   <td width='12%' rowspan='2' valign='top' bgcolor='#F5F5F5'><span class='style8'><label>";
echo"      <input name='currency' type='radio' value='$rowsetup[0]' "; if($defaultcurr == $rowsetup[0]) echo "checked"; echo">$rowsetup[0]</label></span>";
echo"   <br><span class='style8'><label>";
echo"      <input name='currency' type='radio' value='$rowsetup[1]' "; if($defaultcurr == $rowsetup[1]) echo "checked"; echo">$rowsetup[1]</label></span></td>";


echo"   <td width='20%' rowspan='2' valign='top' bgcolor='#F5F5F5'>";
if($module_invoicegridAll ==2){
echo "<span class='style8'><label><input type='checkbox' name='showall' id='showall' value='1' checked onclick=\"showSelected(1);\" />Show All</label></span>";
echo" <br><span class='style8'><label><input type='checkbox' name='prtclosedinv' id='prtclosedinv' value='0' onclick=\"showSelected(2);\" />Show Closed Invoices Only";
} else echo" <span class='style8'><label><input type='checkbox' name='prtclosedinv' id='prtclosedinv' value='0' />Show Closed Invoices ";

echo "</label></span>";
echo"   <br><span class='style8'><label>";
echo"      <input type='checkbox' name='prtdesc' id='prtdesc' value='1' />Print Description</label></span>";
//echo"   <br><span class='style8'><label>";
//echo"      <input type='checkbox' name='prtreturn' id='prtreturn' value='1' />Show Return Sales</label></span>";

echo"   <br><span class='style8'><label>";
echo"      <input type='checkbox' name='prtsummary' id='prtsummary' value='1' />Show Summary</label></span>";
echo "	</td>";	

		
echo"   <td width='25%' rowspan='2' valign='top' bgcolor='#F5F5F5'><span class='style8'>";
if($module_invoicegridAll ==2){
	
	echo "<input type='hidden' name='txtPeriodPrev' id='txtPeriodPrev' value=''>";
	echo "<input type='text' name='txtPeriod' id='txtPeriod' value='' maxlength='10' style='width:55px;'>".
		"<input type='button' id='imgSubmit' onclick=\"SubmitRecord(); return false;\" title='Submit Record' style='width:20px; height:20px; vertical-align:middle; cursor:pointer; outline:none; border:0px; background-image:url(img/confirm-1.png)' ><br>";
		$ct=0;
		$queryperiods  = " select period, name from aging order by period ";
		$resultperiods = mysql_query($queryperiods,$connection) or die(mysql_error());
		echo "<div style='overflow-y:scroll;height:100px;width:100px;'><table width='80px'>";
		while($rows=mysql_fetch_array($resultperiods)){
			$ct+=1;

			if($ct%2==0)
			{
				$Color="style='cursor:pointer;color:#0000FF;background-color:".$rowsetup[3]."'";
			} else {
				$Color="style='cursor:pointer;color:#0000FF;background-color:".$rowsetup[4]."'";	
			}
			echo "<tr $Color onclick=\"SelectRecord('$rows[0]','$rows[0]');\" height='20px;'>";
			echo "	<td align='center'><span class='style4'>$rows[0]</span></td>";
			echo "</tr>";
		}
		echo "</table></div>";
}		
	
echo"</span></td>";
				
echo" </tr>";

echo" <tr height='25'>";
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' 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>";

//ledger client
echo" <tr>";
echo"   <td colspan='3' bgcolor='#F5F5F5'><span class='style8'>Ledger No. / Name </span></td>";
echo"   <td colspan='3' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";


echo" <tr>";	  
echo"   <td width='5%'  align='left' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='50%'  colspan='2' valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <input name='fromledger' type='text' id='fromledger' size='10' value='".$fromledger."' />
        <input name='fromledgername' type='text' id='fromledgername' size='35' value='".$fromledgername."' />
		</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>";
echo"   <td rowspan='2' valign='top' bgcolor='#F5F5F5'><span class='style8'><label>";
		if ($repoption=="1" || $repoption=="")
           echo "<input name='repoption' type='radio' value='1' onclick='SelectReportOption(this.value);' checked />";
		else	
		   echo "<input name='repoption' type='radio' value='1' onclick='SelectReportOption(this.value);' />";
		echo "Detail Aging</label></span>";
echo"   <br><span class='style8'><label>";
		if ($repoption=="2")
           echo "<input name='repoption' type='radio' value='2' onclick='SelectReportOption(this.value);' checked />";
		else	
		   echo "<input name='repoption' type='radio' value='2' onclick='SelectReportOption(this.value);' />";
		echo "Summary Aging</label>";
	 echo "<input name='chksalesman' id='chksalesman' type='checkbox' value='0' /> Group By Salesman";
	echo "</span>";
if($module_invoicegridAll !=2){		
echo"   <br><span class='style8'><label>";
		if ($repoption=="3")
           echo "<input name='repoption' type='radio' value='3' onclick='SelectReportOption(this.value);' checked />";
		else	
		   echo "<input name='repoption' type='radio' value='3' onclick='SelectReportOption(this.value);' />";
		echo "Summary Aging by Invoice</label></span>";
}
echo "</td>";		
echo"   <td rowspan='2' colspan='2' valign='top' bgcolor='#F5F5F5' ><span class='style8'>";
if($module_invoicegridAll !=2) {
	echo"      <label><input type='checkbox' name='riskbal' id='riskbal' value='1' disabled />Risk Balance</label><br>";
	echo"      <label><input type='checkbox' name='shownondues' id='shownondues' value='1' checked disabled />Show Non Dues</label></span>";
}	
echo"	</td>";
echo"</tr>";

echo" <tr>";	  
echo"   <td width='5%'  align='left' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='50%'  colspan='2' valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <input name='toledger' type='text' id='toledger' size='10' value='".$toledger."' />
        <input name='toledgername' type='text' id='toledgername' size='35' value='".$toledgername."' />
      </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"	</td>";
//echo"   <td colspan='2' bgcolor='#F5F5F5' ><span class='style8'>&nbsp;</span?</td>";
echo" </tr>";

echo "<tr height='10px'><td></td></tr>";

//salesman
echo" <tr>";
echo"   <td colspan='3' bgcolor='#F5F5F5'><span class='style8'>Salesman No. / Name </span></td>";
echo"   <td colspan='3' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";
echo" <tr>";	  
echo"   <td width='5%'  align='left' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='50%'  colspan='2' valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <input name='fromsalesmancode' type='text' id='fromsalesmancode' size='10' value='".$fromsalesmancode."' />
        <input name='fromsalesmanname' type='text' id='fromsalesmanname' size='35' value='".$fromsalesmanname."' />
		</span>
		<label><span class='style1'><img src='img/btnopen.jpg' title=' Select Salesman ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  
		onClick='showlistSalesman(1); ' /> </span></label>";
echo"	</td>";
echo "</tr>";
echo" <tr>";	  
echo"   <td width='5%'  align='left' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='50%'  colspan='2' valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <input name='tosalesmancode' type='text' id='tosalesmancode' size='10' value='".$tosalesmancode."' />
        <input name='tosalesmanname' type='text' id='tosalesmanname' size='35' value='".$tosalesmanname."' />
      </span>
        <label><span class='style1'><img src='img/btnopen.jpg' title=' Select Salesman ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\"  
		onClick='showlistSalesman(2); ' /> </span></label>";
echo"	</td>";
//echo"   <td colspan='2' bgcolor='#F5F5F5' ><span class='style8'>&nbsp;</span?</td>";
echo" </tr>";

echo" <tr><td colspan='4' bgcolor='#F5F5F5'><table border='0' cellpading=1 cellspacing=0 width=100%>";
echo" <tr>";
echo"   <td width='20%' bgcolor='#F5F5F5'><span class='style8'>Project</span></td>";
echo"   <td width='80%' bgcolor='#F5F5F5'>
			<input name='fromproject' type='text' id='fromproject' style='width:100px;' value='".$fromproject."' />
			<input name='fromprojectname' type='text' id='fromprojectname' style='width:250px;' value='".$fromprojectname."' />
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title='Select Project' onClick='showlistProject(17); '>
			<img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label>
		</td>";
echo" </tr>";

echo" <tr>";
echo"   <td width='20%' bgcolor='#F5F5F5'><span class='style8'>CostCenter</span></td>";
echo"   <td width='80%' bgcolor='#F5F5F5'>	
			<input name='fromcostcent' type='text' id='fromcostcent' style='width:100px;' value='".$fromcostcent."' />
			<input name='fromcostcentname' type='text' id='fromcostcentname' style='width:250px;' value='".$fromcostcentname."' />
			<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title='Select CostCenter' onClick='showlistCostcenter(17); '>
			<img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label>
		</td>";
echo" </tr>";
echo" </table></td>";

echo" <td colspan='3' bgcolor='#F5F5F5'>&nbsp;</td>";		
echo" </tr>";


    

echo" <tr height='130'>";
echo"   <td colspan='6' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";
   /* <tr>
      <td colspan='6' align='center' bgcolor='#F5F5F5'>
	  <input type='button' name='btnClear' value='Clear' style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;' onClick=\"ClearPage()\"; />
	  <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>";

?>