 by <?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 ".
             " From Module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$querylog="SELECT RA_Aging 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");
*/	
$jvtypelen = 0;
	if (!empty($jvtype))
	   $jvtypelen = strlen($jvtype);
	   
	if (empty($jvtype))
	   $jvtype = 'null'; 
   
if ($ExporttoExcel==1)
	$ExporttoExcelStatus= 'button';
else
	$ExporttoExcelStatus= 'hidden';
	
$querylog="select * 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);
}

$printaccess=$Print;

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


// 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];
  
if (!isset($rangefrom)) $rangefrom = '-0.5'  ;
if (!isset($rangeto))   $rangeto = '0.5'  ; 
   
if (!isset($daysfrom)) $daysfrom = '0'  ;
if (!isset($daysto))   $daysto = '90'  ; 
   

$querysalesmen= " select distinct clientsalesmen ".
			    " from ".$_SESSION['dbLabel'].".loginstk ".
			    " where user_account='".$_SESSION['useraccount']."' ".
			    " and (clientsalesmen != ''  and clientsalesmen is not null) ";
			  
$salesmenresult = mysql_query($querysalesmen,$connection) or die(mysql_error());
$salesmenexist   = mysql_num_rows($salesmenresult);
if ($salesmenexist>0) $supplierstatus='disabled';
else	$supplierstatus='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
<!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 MoveLevel12(option) {
	var ob = document.form1.availgroupby;
	var leng = ob.options.length;
	
	var vSelectedOptionValue='';
	var vSelectedOptionName='';
	var vSelectedCount=0;
	
	if(ob.selectedIndex == -1) {
		alert('No selection is done.');
		return;
	}
	
	while (ob.selectedIndex != -1)
    {
        if (ob.selectedIndex != -1) {
			vSelectedCount = vSelectedCount + 1;
			vSelectedOptionName  = ob.options[ob.selectedIndex].text;
			vSelectedOptionValue = ob.options[ob.selectedIndex].value;
		}	
        ob.options[ob.selectedIndex].selected = false;
    }

	if (vSelectedCount == 1) {
		if (option == 1) {
			document.form1.groupbylevel1name.value  = vSelectedOptionName;
			document.form1.groupbylevel1value.value = vSelectedOptionValue;
		}	
		else {
			document.form1.groupbylevel2name.value  = vSelectedOptionName;
			document.form1.groupbylevel2value.value = vSelectedOptionValue;
		}	
	}	
	else
		alert ('Not allowed multi selection for Level 1 and 2');
		
	
}

function RemoveLevel12(option) {
	var x = document.form1;
	
	if (option == 1) {
		x.groupbylevel1name.value = '';
		x.groupbylevel1value.value = '';
	}	
	else {
		x.groupbylevel2name.value = '';
		x.groupbylevel2value.value = '';
	}	
}

function MoveLevel3() {
	var ob = document.form1.availgroupby;
	var leng = ob.options.length;
	var TargetElement = document.form1.assigngroupby.options;
	
	var vExists = 0;
	
	if(ob.selectedIndex == -1) {
		alert('No selection is done.');
		return;
	}
	
	if(TargetElement[0] != null) {
		if (TargetElement[0].value=='') 
			TargetElement[0] = null;
	}	

		
	while (ob.selectedIndex != -1)
    {  
        if (ob.selectedIndex != -1) {
		
			vExists = 0;
			for(i=0; i < TargetElement.length; i++) {
				if (TargetElement[i].value == ob.options[ob.selectedIndex].value)
					vExists = 1;
			}
			
			if (vExists == 0)
				TargetElement[TargetElement.length] = new Option(ob.options[ob.selectedIndex].text, ob.options[ob.selectedIndex].value);
		}	  

		ob.options[ob.selectedIndex].selected = false;
    }

	
}

function RemoveLevel3() {
	var ob = document.form1.assigngroupby;
	var leng = ob.options.length;
	
	if(ob.selectedIndex == -1) {
		alert('No selection is done.');
		return;
	}
	
	while (ob.selectedIndex != -1)
    {  
        if (ob.selectedIndex != -1) 
			  ob.options[ob.selectedIndex] = null;
    }
	
}


function PrintPrev(printaccess)
{
	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.option.length; i++)
	{
		if (document.form1.option[i].checked)
		{
			var varoption = document.form1.option[i].value;
		}
	}
	 
	for (var i=0; i < document.form1.orderby.length; i++)
	{
		if (document.form1.orderby[i].checked)
		{
			var varorderby = document.form1.orderby[i].value;
		}
	}
  
	for (var i=0; i < document.form1.balorderby.length; i++)
	{
		if (document.form1.balorderby[i].checked)
		{
			var varbalorderby = document.form1.balorderby[i].value;
		}
	}
  
  
	for (var i=0; i < document.form1.accountno.length; i++)
	{
		if (document.form1.accountno[i].checked)
		{
			var varaccountno = document.form1.accountno[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.duebal.length; i++)
	{
		if (document.form1.duebal[i].checked)
		{
			var varduebal = document.form1.duebal[i].value;
		}
	}
	
  
  
    //Getting Group By Levels 1 and 3
	vargroupby1   = document.form1.groupbylevel1value.value;
	vargroupby2   = document.form1.groupbylevel2value.value;
	vartermsdays   = document.form1.termsdays.value;
	  
	//Getting Assigngroupby Values for level 3
	var ob = document.form1.assigngroupby;
	var vargroupby3 = '';
	for (var i = 0; i < ob.options.length; i++) {
		if (vargroupby3.length > 0)
			vargroupby3 += ",";
				
		vargroupby3 += ob.options[i].value;
	}
	  
	// If No Group By Option Selected
	if (vargroupby3 == '') vargroupby3 = 1;
	
	
	
	varriskbal = 0;
	if (document.form1.riskbal.checked)
		varriskbal = 1;			
	
	varshowbal = 0;
	if (document.form1.showbal.checked)
		varshowbal = 1;
	
	varlastbal = 0;
	if (document.form1.lastbal.checked)
		varlastbal = 1;	

	varshowdetail = 0;
	if (document.form1.showdetail.checked)
		varshowdetail = 1;
		
	//If No Group By Option Selected	
	if (vargroupby3 == 1 && vargroupby1 == '' && vargroupby2 == '')
		varshowdetail = 1;	

	varshownondues = 0;
	if (document.form1.shownondues.checked)
		varshownondues = 1;
		
	varprtheader = 0;
	if (document.form1.prtheader.checked)
		varprtheader = 1;
		
	varshowaddress = 0;
	if (document.form1.showaddress.checked)
		varshowaddress = 1;
		
	varprtcstjour = 0;
	if (document.form1.prtcstjour.checked)
		varprtcstjour = 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.fromsalesman.value;
	vartosalesman   = document.form1.tosalesman.value;
	varfromprj      = document.form1.fromproject.value;
	varfromcst      = document.form1.fromcostcent.value;
	varcltprj       = document.form1.clientproject.value;
	varcltcst       = document.form1.clientcostcent.value;
	varrangefrom    = document.form1.rangefrom.value;
	varrangeto      = document.form1.rangeto.value;
	varsubproj      = document.form1.subproj.value;
	varsubcostcent  = document.form1.subcostcent.value;
  
	varsubproj      = varsubproj.replace(/%/g,'-');
	varsubcostcent  = varsubcostcent.replace(/%/g,'-');
	
	var vshowvdate = 0;
	if(document.getElementById('showvdate').checked)
		vshowvdate = 1;
	
	varreport = '';
	if (varoption == 1)
		varreport = 'Rep_Aging.php';
	else if (varoption == 2)
		varreport = 'Rep_AgingDetail.php';  
  
    
	str = varreport +'?fromdate='+varfromdate+'&todate='+vartodate+'&agingdate='+varagingdate+'&fromledger='+varfromledger+'&toledger='+vartoledger
					+'&fromsalesman='+varfromsalesman+'&tosalesman='+vartosalesman+'&fromproject='+varfromprj+'&fromcst='+varfromcst
					+'&cltcst='+varcltcst+'&cltprj='+varcltprj+'&rangefrom='+varrangefrom+'&rangeto='+varrangeto+'&groupby1='+vargroupby1
					+'&groupby2='+vargroupby2+'&groupby3='+vargroupby3+'&dateoption='+vardate+'&orderby='+varorderby+'&lastbal='+varlastbal
					+'&balorderby='+varbalorderby+'&accountno='+varaccountno+'&curr='+varcurrency+'&riskbal='+varriskbal+'&showbal='+varshowbal
					+'&showdetail='+varshowdetail+'&shownondues='+varshownondues+'&subproj='+varsubproj+'&subcostcent='+varsubcostcent
					+'&duebal='+varduebal+'&prtheader='+varprtheader+'&showaddress='+varshowaddress+'&prtcstjour='+varprtcstjour+'&termsdays='+vartermsdays+'&showvdate='+vshowvdate;
				 
	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.date.length; i++)
	{
		if (document.form1.date[i].checked)
		{
			var vardate = document.form1.date[i].value;
		}
	}	 
  
	for (var i=0; i < document.form1.option.length; i++)
	{
		if (document.form1.option[i].checked)
		{
			var varoption = document.form1.option[i].value;
		}
	}
	 
	for (var i=0; i < document.form1.orderby.length; i++)
	{
		if (document.form1.orderby[i].checked)
		{
			var varorderby = document.form1.orderby[i].value;
		}
	}
  
	for (var i=0; i < document.form1.balorderby.length; i++)
	{
		if (document.form1.balorderby[i].checked)
		{
			var varbalorderby = document.form1.balorderby[i].value;
		}
	}
  
  
	for (var i=0; i < document.form1.accountno.length; i++)
	{
		if (document.form1.accountno[i].checked)
		{
			var varaccountno = document.form1.accountno[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.duebal.length; i++)
	{
		if (document.form1.duebal[i].checked)
		{
			var varduebal = document.form1.duebal[i].value;
		}
	}
  
    //Getting Group By Levels 1 and 3
	vargroupby1   = document.form1.groupbylevel1value.value;
	vargroupby2   = document.form1.groupbylevel2value.value;
	  
	//Getting Assigngroupby Values for level 3
	var ob = document.form1.assigngroupby;
	var vargroupby3 = '';
	for (var i = 0; i < ob.options.length; i++) {
		if (vargroupby3.length > 0)
			vargroupby3 += ",";
				
		vargroupby3 += ob.options[i].value;
	}
	  
	// If No Group By Option Selected
	if (vargroupby3 == '') vargroupby3 = 1;
	
	
	
	varriskbal = 0;
	if (document.form1.riskbal.checked)
		varriskbal = 1;			
	
	varshowbal = 0;
	if (document.form1.showbal.checked)
		varshowbal = 1;
	
	varlastbal = 0;
	if (document.form1.lastbal.checked)
		varlastbal = 1;	
	
	varshowdetail = 0;
	if (document.form1.showdetail.checked)
		varshowdetail = 1;
		
	//If No Group By Option Selected	
	if (vargroupby3 == 1 && vargroupby1 == '' && vargroupby2 == '')
		varshowdetail = 1;	

	varshownondues = 0;
	if (document.form1.shownondues.checked)
		varshownondues = 1;
		
	varprtheader = 0;
	if (document.form1.prtheader.checked)
		varprtheader = 1;
		
	varshowaddress = 0;
	if (document.form1.showaddress.checked)
		varshowaddress = 1;
		
	varprtcstjour = 0;
	if (document.form1.prtcstjour.checked)
		varprtcstjour = 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.fromsalesman.value;
	vartosalesman   = document.form1.tosalesman.value;
	varfromprj      = document.form1.fromproject.value;
	varfromcst      = document.form1.fromcostcent.value;
	varcltprj       = document.form1.clientproject.value;
	varcltcst       = document.form1.clientcostcent.value;
	varrangefrom    = document.form1.rangefrom.value;
	varrangeto      = document.form1.rangeto.value;
	varsubproj      = document.form1.subproj.value;
	varsubcostcent  = document.form1.subcostcent.value;
  
	varsubproj      = varsubproj.replace(/%/g,'-');
	varsubcostcent  = varsubcostcent.replace(/%/g,'-');
	
	var vshowvdate = 0;
	if(document.getElementById('showvdate').checked)
		vshowvdate = 1;
	
	varreport = '';
	if (varoption == 1)
		varreport = 'Exp_Aging.php';
	else if (varoption == 2)
		varreport = 'Exp_AgingDetail.php';  
  
    
	str = varreport +'?fromdate='+varfromdate+'&todate='+vartodate+'&agingdate='+varagingdate+'&fromledger='+varfromledger+'&toledger='+vartoledger
					+'&fromsalesman='+varfromsalesman+'&tosalesman='+vartosalesman+'&fromproject='+varfromprj+'&fromcst='+varfromcst
					+'&cltcst='+varcltcst+'&cltprj='+varcltprj+'&rangefrom='+varrangefrom+'&rangeto='+varrangeto+'&groupby1='+vargroupby1
					+'&groupby2='+vargroupby2+'&groupby3='+vargroupby3+'&dateoption='+vardate+'&orderby='+varorderby+'&lastbal='+varlastbal
					+'&balorderby='+varbalorderby+'&accountno='+varaccountno+'&curr='+varcurrency+'&riskbal='+varriskbal+'&showbal='+varshowbal
					+'&showdetail='+varshowdetail+'&shownondues='+varshownondues+'&subproj='+varsubproj+'&subcostcent='+varsubcostcent
					+'&duebal='+varduebal+'&prtheader='+varprtheader+'&showaddress='+varshowaddress+'&prtcstjour='+varprtcstjour+'&showvdate='+vshowvdate;

	window.open(str);

}


function showlistledger(str){

  var str1;
  for (var i=0; i < document.form1.accountno.length; i++)
  {
    if (document.form1.accountno[i].checked)
    {
      str1 = document.form1.accountno[i].value;
    }
  }

  
  window.open('select_accountno.php?item='+str+'&accountoption='+str1,'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 CheckAccountNo() {

	var x= document.form1;
	var ob = document.form1.assigngroupby;
	
	for (var i=0; i < x.accountno.length; i++)
    {
      
		if (x.accountno[i].checked && (x.accountno[i].value == '1'  || x.accountno[i].value == '3' ))
		{ 
			//Empty Assigngroupby Values
			for (var k=0; k < ob.options.length; k++) {
				ob.options[k].selected = true;
			}
			
			while (ob.selectedIndex != -1)
			{  
				if (ob.selectedIndex != -1) 
					  ob.options[ob.selectedIndex] = null;
			}
		  
			ob.disabled = true;
		}
		else if (x.accountno[i].checked && x.accountno[i].value == '2')
		{	  
			ob.disabled = false;
		}
    }
	
		

}

function LoadOptions() {
	x = document.form1;
    win = window.open('List_ReportsOptionsTemplates.php?formname=aging', 'List_ReportsOptionsTemplates', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1040,height=450,top=100,left=0');		
	win.creator = self;
	win.focus();		

}



function SelectOptions() {
	x = document.form1;
	vTemplateId = x.templateid.value;
	
    win = window.open('Form_ReportsOptions.php?isseloption=1&templateid='+vTemplateId+'&formname=aging', 'Form_ReportsOptions', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1230,height=650,top=30,left=0');
	win.creator = self;
	win.focus();		

}


function ClearPage() {
	
	if(confirm("Are you sure?")){
	window.location ='Form_AgingOfInvoicingReport.php';
	}
	
}

function AddOption(selectId, text, value) {
	var ob = document.form1.assigngroupby;
	var i = ob.options.length;
	var o = new Option(text,value);
	ob.options[i] = o;
	
}

function RemoveOption(selectId) {
	var ob = document.form1.assigngroupby;
	
	//Empty Assigngroupby Values
	for (var k=0; k < ob.options.length; k++) {
		ob.options[k].selected = true;
	}
	
	while (ob.selectedIndex != -1)
	{  
		if (ob.selectedIndex != -1) 
		  ob.options[ob.selectedIndex] = null;
	}
	

}

function SelectRecord(PPeriodId,PPeriod) {
	x = document.form1;
	
	x.txtPeriodId.value = PPeriodId;
	x.txtPeriod.value = PPeriod;
}
function openListCustomers(frm){
	var str = "List_SorClient.php?frm="+frm;
	window.open(str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
function openListSuppliers(frm){
	var str = "List_SorSalesman.php?frm="+frm;
	window.open(str,'mywindow2','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}
function chkOrderBySalesman(){
	if(document.getElementById('chk_orderby_salesman').checked){
		document.getElementById('orderby_salesman').value = 1;
	}
	else{
		document.getElementById('orderby_salesman').value = 0;
	}
}

var Type=0;
var Folio=0;
var amnt=1;
var amnt1=0;
var amnt2=0;
function showType(){
	if(document.getElementById('Type').checked){
		Type = 1;
	}
	else{
		Type = 0;
	}
}
function showFolio(){
	if(document.getElementById('Folio').checked){
		Folio = 1;
	}
	else{
		Folio = 0;
	}
}

function showAmnt(){
	
	if(document.getElementById('Amnt').checked){
		
		amnt = 1;
	}else{
		amnt = 0;
	}
	
}
function showAmnt1(){
	
	if(document.getElementById('Amnt1').checked){
		amnt1 = 1;
	}
	else{
		amnt1 = 0;
	}
}
function showAmnt2(){
	if(document.getElementById('Amnt2').checked){
		amnt2 = 1;
	}
	else{
		amnt2 = 0;
	}
}



function previewReport(){
	var till_date = document.getElementById('till_date').value;
	var from_client_code = document.getElementById('from_client_code').value;
	var to_client_code = document.getElementById('to_client_code').value;
	var from_client_name = document.getElementById('from_client_name').value;
	var to_client_name = document.getElementById('to_client_name').value;
	var from_salesman_code = document.getElementById('from_salesman_code').value;
	var to_salesman_code = document.getElementById('to_salesman_code').value;
	var from_salesman_name = document.getElementById('from_salesman_name').value;
	var to_salesman_name = document.getElementById('to_salesman_name').value;
	var orderby_salesman = document.getElementById('orderby_salesman').value;
	var Option="";
	if(document.getElementById("radio_1").checked) Option=document.getElementById('radio_1').value;
	if(document.getElementById("radio_2").checked) Option=document.getElementById('radio_2').value;
	//if(document.getElementById("radio_3").checked) Option=document.getElementById('radio_3').value;
	var Option2="";
	if(document.getElementById("radio1").checked) Option2=document.getElementById('radio1').value;
	if(document.getElementById("radio2").checked) Option2=document.getElementById('radio2').value;
	if(document.getElementById("radio3").checked) Option2=document.getElementById('radio3').value;
	if( document.getElementById('Amnt').checked || document.getElementById('Amnt1').checked || document.getElementById('Amnt2').checked){
	
	var str = "Rep_AgingOfInvoicingReport.php?till_date="+till_date+"&from_client_code="+from_client_code+"&to_client_code="+to_client_code+"&from_client_name="+from_client_name+"&to_client_name="+to_client_name+"&from_salesman_code="+from_salesman_code+"&to_salesman_code="+to_salesman_code+"&from_salesman_name="+from_salesman_name+"&to_salesman_name="+to_salesman_name+"&Option="+Option+"&Option2="+Option2+"&orderby_salesman="+orderby_salesman+"&Type="+Type+"&Folio="+Folio+"&Amnt="+amnt+"&Amnt1="+amnt1+"&Amnt2="+amnt2+"&exp=0";
	//alert(str);
	window.open(str);}
	else alert("Choose Currency to display")
}
function excelReport(){
	var till_date = document.getElementById('till_date').value;
	var from_client_code = document.getElementById('from_client_code').value;
	var to_client_code = document.getElementById('to_client_code').value;
	var from_client_name = document.getElementById('from_client_name').value;
	var to_client_name = document.getElementById('to_client_name').value;
	var from_salesman_code = document.getElementById('from_salesman_code').value;
	var to_salesman_code = document.getElementById('to_salesman_code').value;
	var from_salesman_name = document.getElementById('from_salesman_name').value;
	var to_salesman_name = document.getElementById('to_salesman_name').value;
	var orderby_salesman = document.getElementById('orderby_salesman').value;
	var Option="";
	if(document.getElementById("radio_1").checked) Option=document.getElementById('radio_1').value;
	if(document.getElementById("radio_2").checked) Option=document.getElementById('radio_2').value;
	//if(document.getElementById("radio_3").checked) Option=document.getElementById('radio_3').value;
	var Option2="";
	if(document.getElementById("radio1").checked) Option2=document.getElementById('radio1').value;
	if(document.getElementById("radio2").checked) Option2=document.getElementById('radio2').value;
	if(document.getElementById("radio3").checked) Option2=document.getElementById('radio3').value;
	var str = "Rep_AgingOfInvoicingReport.php?till_date="+till_date+"&from_client_code="+from_client_code+"&to_client_code="+to_client_code+"&from_client_name="+from_client_name+"&to_client_name="+to_client_name+"&from_salesman_code="+from_salesman_code+"&to_salesman_code="+to_salesman_code+"&from_salesman_name="+from_salesman_name+"&to_salesman_name="+to_salesman_name+"&Option="+Option+"&Option2="+Option2+"&orderby_salesman="+orderby_salesman+"&Type="+Type+"&Folio="+Folio+"&Amnt="+amnt+"&Amnt1="+amnt1+"&Amnt2="+amnt2+"&exp=1";
	//alert(str);
	window.open(str);
}
function SubmitRecord() {
	x = document.form1;
	
	var vPeriodId = x.txtPeriodId.value;
	
	if (vPeriodId != '') 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 of Invoicing</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}
.style4{
	font-family: Verdana, Arial, Helvetica, sans-serif;
	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>";


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 Invoicing</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='button' id='btnClear' name='btnClear' onclick='ClearPage();return false;' title='Clear'><span><span>Clear</span></span></button>";
		echo"<button type='button' id='btnPreview' name='btnPreview'  onClick=\"previewReport()\"; title='Preview'><span><span>Preview</span></span></button>";

		echo" <button type='button' id='btnExcel' name='btnExcel' onClick=\"excelReport()\"; title='Export Excel'><span><span>Export Excel</span></span></button>";


	 
  
echo"	</td></tr></table>";
echo"</td></tr>";				
$curr_date = date("d/m/Y");
		
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 width=100%>
<tr>
<td style='font-size: 12px; font-weight: bold; color: #999999'>Till Date</td>
<td><input type='text' name='till_date' id='till_date' value='$curr_date' /> <A HREF='#' onClick=\"displayCalendar(document.getElementById('till_date'),'dd/mm/yyyy',this);  return false; \" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A></td>
<td style='font-size: 12px; font-weight: bold; color: #999999'>Client From: </td>
<td><input type='text' name='from_client_code' id='from_client_code' style='width: 75px' /> <img src='img/btnopen.jpg' width=20 style='vertical-align: middle; cursor: pointer' onclick=\"openListCustomers(15)\" /> <input type='text' name='from_client_name' id='from_client_name' style='width: 250px' /></td>
<td style='font-size: 12px; font-weight: bold; color: #999999'>Salesman From: </td>
<td><input type='text' name='from_salesman_code' id='from_salesman_code' style='width: 50px' /> <img src='img/btnopen.jpg' width=20 style='vertical-align: middle; cursor: pointer' onclick=\"openListSuppliers(9)\" /> <input type='text' name='from_salesman_name' id='from_salesman_name' style='width: 150px' /></td>
</tr>
<tr>
<td></td>
<td></td>
<td style='font-size: 12px; font-weight: bold; color: #999999'>To:</td>
<td><input type='text' name='to_client_code' id='to_client_code' style='width: 75px' /> <img src='img/btnopen.jpg' width=20 style='vertical-align: middle; cursor: pointer' onclick=\"openListCustomers(16)\" /> <input type='text' name='to_client_name' id='to_client_name' style='width: 250px' /></td>
<td style='font-size: 12px; font-weight: bold; color: #999999'>To:</td>
<td><input type='text' name='to_salesman_code' id='to_salesman_code' style='width: 50px' /> <img src='img/btnopen.jpg' width=20 style='vertical-align: middle; cursor: pointer' onclick=\"openListSuppliers(10)\" /> <input type='text' name='to_salesman_name' id='to_salesman_name' style='width: 150px' /></td>
</tr>
<tr><td colspan=6 style='font-size: 12px; font-weight: bold; color: #999999'>Display Balance : &nbsp <input type='radio' id='radio_1' name='radios' value='All' checked='true'/><label for='radio-1'>All</label> &nbsp<input type='radio' id='radio_2' name='radios' value='DueOnly' /><label for='radio-1'>Due Only</label> &nbsp 
</tr>
<tr>
<td colspan=6 style='font-size: 12px;  font-weight: bold; color: #999999'>Amount :&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox'  checked='true' name='Amnt' id='Amnt' onclick=\"showAmnt()\" ><input type='hidden' name='Amnt' id='Amnt' value=0 />Currency &nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' name='Amnt1' id='Amnt1' onclick=\"showAmnt1()\" ><input type='hidden' name='Amnt1' id='Amnt1' value=0 />  Amount ".$base1."&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' name='Amnt2' id='Amnt2' onclick=\"showAmnt2()\" ><input type='hidden' name='Amnt2' id='Amnt2' value=0 />  Amount ".$base2."</td>

</tr>
<tr><td colspan=6 style='font-size: 12px; visibility: hidden; font-weight: bold; color: #999999'>Display Amount : &nbsp <input type='radio' id='radio1' name='Amount' value='Amnt' checked='true' /><label for='radio-1'>Amount By Currency</label> &nbsp<input type='radio' id='radio2' name='Amount' value='base1' /><label for='radio3'>Amount ".$base1."</label> &nbsp <input type='radio' id='radio3' name='Amount' value='base2' /><label for='radio-1'>Amount ".$base2."</label></td>
</tr>
<tr height=15px><td colspan=6>&nbsp;</td></tr>
<tr>
<td colspan=2 style='font-size: 12px; font-weight: bold; color: #999999'><input type='checkbox' name='chk_orderby_salesman' id='chk_orderby_salesman' onclick=\"chkOrderBySalesman()\"><input type='hidden' name='orderby_salesman' id='orderby_salesman' value=0 /> Group By Salesman</td>
<td  colspan =4 style='font-size: 12px;visibility: hidden; font-weight: bold; color: #999999'><input type='checkbox' name='Type' id='Type' onclick=\"showType()\" ><input type='hidden' name='Type' id='Type' value=0 /> Show Type</td>
</tr>
<tr>
<td  colspan=2 style='font-size: 12px;visibility: hidden; font-weight: bold; color: #999999 '><input type='checkbox' name='Folio' id='Folio' onclick=\"showFolio()\"><input type='hidden' name='Folio' id='Folio' value=0 /> Show Folio</td>
<td  colspan=4 style='font-size: 12px;visibility: hidden; font-weight: bold; color: #999999'><input type='checkbox' name='Amnt1' id='Amnt1' onclick=\"showAmnt1()\" ><input type='hidden' name='Amnt1' id='Amnt1' value=0 /> Show Amount ".$base1."&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' name='Amnt2' id='Amnt2' onclick=\"showAmnt2()\" ><input type='hidden' name='Amnt2' id='Amnt2' value=0 /> Show Amount ".$base2."</td>
</tr>

</table>";   
echo"</td></tr>"; 
 echo"   </table></td></tr><tr height='30'><td align='center' id='content-bottom' ></td></tr>"; 
  echo"</table>
 
</form>
</body>
</html>";

?>