<?php


session_start();
if($HTTP_SESSION_VARS['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($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");




$querylog="SELECT RA_StatementofAccount as loginaccess , ExporttoExcel from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['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 ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['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;

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

//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ifNull(module_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);
}

$querysetup ="select base1, base2 from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
$rowsetup=mysql_fetch_row($resultsetup);
$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 ".
		   " 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 project_code as defaultproject from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."' and default_project=1 ";
//echo$querydflproject;
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
	extract($rows);
}
$querydflcostcent="select costcent_code as defaultcostcent from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['useraccount']."' and default_costcenter=1 ";
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflcostcent)){
	extract($rows);
}

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

$query="select ifnull(ShowReportHeader,0) as ShowReportHeader from ".$HTTP_SESSION_VARS['dbLabel'].".loginstk where user_account='".$HTTP_SESSION_VARS['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 language="JavaScript" src="CalendarPopup.js" ></script><!-- Date only with year scrolling -->

<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>


<link type="text/css" href="js/calendar/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datepick.js"></script>

<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 cgr7(){
x=document.form1;
//code1a=x.code1a.value;
document.form1.action="select_item.php?item=1";
document.form1.btncode1.submit();

}

function cgr8(){
x=document.form1;
//code2a=x.code2a.value;
document.form1.action="select_item.php?item=2";
document.form1.btncode2.submit();

}

all = 0;  // 0 means 'no', 1 means 'yes'


function showresult(){

var fromdate=document.getElementById("fromdate").value
var todate=document.getElementById("todate").value
var fromledger=document.getElementById("fromledger").value
var toledger=document.getElementById("toledger").value
var fromledgername=document.getElementById("fromledgername").value
var toledgername=document.getElementById("toledgername").value
var concail=document.getElementById("concail").value
var currency = document.getElementById("currency").value  

//alert('reconcilation.php?fromledger='+fromledger+'&fromledgername='+fromledgername+'&toledger='+toledger+'&toledgername='+toledgername+'&fromdate='+fromdate+'&todate='+todate+'&action=search&currency='+currency+'&concail='+concail);

window.location.replace('reconcilation.php?fromledger='+fromledger+'&fromledgername='+fromledgername+'&toledger='+toledger+'&toledgername='+toledgername+'&fromdate='+fromdate+'&todate='+todate+'&action=search&currency='+currency+'&concail='+concail)

}

function saveresult(){
var fromdate=document.getElementById("fromdate").value
var todate=document.getElementById("todate").value
var fromledger=document.getElementById("fromledger").value
var toledger=document.getElementById("toledger").value
var fromledgername=document.getElementById("fromledgername").value
var toledgername=document.getElementById("toledgername").value
var i=0;
var strarray= new Array();
var strarray2= new Array();

/*if(!document.getElementById("check["+i+"]").checked){
alert("Please Check them");
}*/

var j=0;

while(document.getElementById("check["+i+"]")){

if(document.getElementById("check["+i+"]").checked){

//alert(i+': '+document.getElementById("check["+i+"]").value);
strarray[j] = document.getElementById("check["+i+"]").value;

}
else {
//alert(i+': '+document.getElementById("check["+i+"]").value);
strarray2[j] = document.getElementById("check["+i+"]").value;


}
i++;
j++;
}

//alert(fromledger+'&'+fromledgername+'&'+toledger+'&'+toledgername+'&'+fromdate+'&'+todate);

window.location.replace('reconcilation.php?fromledger='+fromledger+'&fromledgername='+fromledgername+'&toledger='+toledger+'&toledgername='+toledgername+'&fromdate='+fromdate+'&todate='+todate+'&action=save&tobechecked='+strarray+'&notchecked='+strarray2)
}


function showlistsalesman(str){
  var vdate, vcode; 
  vcode=encodeURIComponent(document.form1.clientsalesman.value);
  vname=encodeURIComponent(document.form1.clientsalesmanname.value);
  if(vcode=='')
	vcode=vname;
  window.open('List_Salesmen.php?frm=20&str=20&item='+str+'&PLedger_number='+vcode,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,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.transaction.length; i++)
	{
		if (document.form1.transaction[i].checked){
			var vartransaction = document.form1.transaction[i].value;
		}
	}
	 
	for (var i=0; i < document.form1.ledgeroption.length; i++)
	{
		if (document.form1.ledgeroption[i].checked) {
			var varledgeroption = document.form1.ledgeroption[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;		
	
	varcum = 0;
	if (document.form1.cumulative.checked)   varcum = 1;	
 	
  	

	varprtfolio = 0;
	if (document.form1.prtfolio.checked)   varprtfolio = 1;			
	
	varprtref = 0;
	if (document.form1.prtref.checked)	   varprtref = 1;
	
	varprtdesc = 0;
	if (document.form1.prtdesc.checked)    varprtdesc = 1;	
	
	varprtvaluedate = 0;
	if (document.form1.prtvaluedate.checked)    varprtvaluedate = 1;	
	
	varprtjvtype = 0;
	if (document.form1.prtjvtype.checked)    varprtjvtype = 1;		
	
	varshowunposted = 0;
	if (document.form1.showunposted.checked)    varshowunposted = 1;	
	
	varprtcostcent = 0;
	if (document.form1.prtcostcent.checked)    varprtcostcent = 1;		
  
	varprtproject = 0;
	if (document.form1.prtproject.checked)	   varprtproject = 1;			
	
	varprevbal = 0;
	if (document.form1.prevbal.checked)    varprevbal = 1;			
	
	vardtjv = 0;
	if (document.form1.dtjv.checked)    vardtjv = 1;	

	vardtdate = 0;
	if (document.form1.dtdate.checked)    vardtdate = 1;		
	
	varchecks = 0;
	if (document.form1.checks.checked)    varchecks = 1;	

	varparentprj = 0;
	if (document.form1.parentprj.checked)    varparentprj = 1;	
	
	varprintaging = 0;
	if (document.form1.prtaging.checked)    varprintaging = 1;		
	
	varprtheader = 0;
	if (document.form1.prtheader.checked)    varprtheader = 1;	
	
	varprtcstjour = 0;
	if (document.form1.prtcstjour.checked)    varprtcstjour = 1;	
	
	varprtwording = 0;
	if (document.form1.prtwording.checked)    varprtwording = 1;
	
    varprtwnac =0;
	if (document.form1.prtwnac.checked)    varprtwnac = 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;
	varfromcur    = document.form1.fromcur.value;
	varcltprj     = document.form1.clientproject.value;
	varcltcst     = document.form1.clientcostcent.value;
	varsalesman     = document.form1.clientsalesman.value;
  
	varcltprj = varcltprj.replace('&','%26');
	varcltcst = varcltcst.replace('&','%26');
  
  
    
	str =   'Exp_statementofaccount.php?fromdate='+varfromdate+'&todate='+vartodate+'&fromledger='+varfromledger
           +'&toledger='+vartoledger+'&fromproject='+varfromprj+'&fromcst='+varfromcst+'&fromcur='+varfromcur
		   +'&dateoption='+vardate+'&transaction='+vartransaction+'&ledgeroption='+varledgeroption
		   +'&curr='+varcurr+'&currbase1='+varcurrbase1+'&currbase2='+varcurrbase2+'&cum='+varcum
		   +'&alltypes='+varalltypes+'&exclude='+varexclude+'&jvtype='+varjvtype+'&showunposted='+varshowunposted
		   +'&prtfolio='+varprtfolio+'&prtref='+varprtref+'&prtdesc='+varprtdesc+'&prtvaluedate='+varprtvaluedate
		   +'&prtjvtype='+varprtjvtype+'&prtcostcent='+varprtcostcent+'&prtproject='+varprtproject+'&prevbal='+varprevbal
		   +'&dtjv='+vardtjv+'&dtdate='+vardtdate+'&checks='+varchecks+'&cltcst='+varcltcst+'&cltprj='+varcltprj
		   +'&parentprj='+varparentprj+'&prtaging='+varprintaging+'&prtheader='+varprtheader+'&prtcstjour='+varprtcstjour
		   +'&prtwording='+varprtwording+'&salesman='+varsalesman+'&prtwnac='+varprtwnac;
  
	window.open(str);
  
}


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

}


function kdSalesman(choice,e,app)
{   
	 x = document.form1;
	if(app==0){
		var clientcode = x.clientsalesman.value;
		var clientname = x.clientsalesmanname.value;
	} else {
		var clientcode = x.clientsalesman.value;
		var clientname = x.clientsalesmanname.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(data[0]!=''){
								x.clientsalesmanname.value = data[1];
									if(x.clientsalesman.value==''){
									x.clientsalesman.value = data[0];
									x.clientsalesmanname.value = data[1];
									
									}
						}
						else showlistsalesman(1);
					 
			}
		}
	    
		xmlhttp.open("GET","Form_statementofaccount_action.php?mode=getsalesmanname&clientcode="+clientcode+"&choice="+choice+"&clientname="+clientname);
		xmlhttp.send();
	
      
			
			
    }
	
	
  


}


function showlistledger(str){

	if(str==1){
		varledger = document.form1.fromledger.value;
		varledgername = document.form1.fromledgername.value;
	} else {
		varledger   = document.form1.toledger.value;
		varledgername = document.form1.toledgername.value;
	}

  var str1, selectpage;
  for (var i=0; i < document.form1.ledgeroption.length; i++)
  {
    if (document.form1.ledgeroption[i].checked)
    {
      str1 = document.form1.ledgeroption[i].value;
	  if (str1 == 1)
	    selectpage = 'select_ledger.php?item='+str+'&PLedger_Number='+varledger+'&PLedger_Name='+varledgername;
	  else
        selectpage = 'select_document.php?item='+str;	  
    }
  }

  
  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 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 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 CheckCummulative() {

	var x= document.form1;
	if (x.curr.checked == false && ((x.currbase1.checked == true && x.currbase2.checked == false) || 
									(x.currbase1.checked == false && x.currbase2.checked == true))) 
		x.cumulative.disabled = false;	 
	else {
	    x.cumulative.checked = false;
        x.cumulative.disabled = true;	 	
	}	

}

function CheckValueDate(option) {

	var x= document.form1;
	if (x.prtvaluedate.checked == true && x.prtjvtype.checked == true && option == 1 ) 
		x.prtjvtype.checked = false;	 
		
	if (x.prtvaluedate.checked == true && x.prtjvtype.checked == true && option == 2 ) 
		x.prtvaluedate.checked = false;	 	

}

function CheckDetailedPerDate() {

	var x= document.form1;
	if (x.dtdate.checked == false ) { 
	
	  x.prtref.checked = false;
	  x.checks.checked = false;
	  x.dtjv.checked = false;
	  x.prtref.disabled = true;
	  x.checks.disabled = true;
	  x.dtjv.disabled = true;
	  
    } else {
      
      x.prtref.checked = true;
	  x.checks.checked = true;
	  x.prtref.disabled = false;
	  x.checks.disabled = false;
	  x.dtjv.disabled = false;	  
	
	}
	
}
-->
//my code
function clearpage(){
	document.form1.fromledger.value='';
	document.form1.toledger.value='';
	document.form1.fromledgername.value='';
	document.form1.toledgername.value='';
	document.form1.fromdate.value='';
	document.form1.todate.value='';
	document.form1.fromledger.value='';
	document.form1.action = 'reconcilation.php';
	document.form1.submit();
}


function printPrev(printaccess){
	
	var fromledger=document.form1.fromledger.value;
	var toledger=document.form1.toledger.value;
	var fromledgername=document.form1.fromledgername.value;
	var toledgername=document.form1.toledgername.value;
	var fromdate=document.form1.fromdate.value;
	var todate=document.form1.todate.value;
	var concail=document.form1.concail.value;
	
	str='';
		   
    window.open('Rep_reconcilation.php?&fromledger='+fromledger+'&toledger='+toledger+'&fromledgername='+fromledgername
           +'&toledgername='+toledgername+'&fromdate='+fromdate+'&todate='+todate+'&concail='+concail);
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Reconcilation</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]'>";

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'>Reconcilation</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' title='Clear' onclick=\"clearpage();\"><span><span>Clear</span></span></button>";
	echo"<button type='button' id='btnSave' name='btnSave'  onClick=\"saveresult('".$printaccess."')\"; title='Save'><span><span>Save</span></span></button>";
	echo"<button type='button' id='btnSearch' name='btnSearch'  onClick=\"showresult('".$printaccess."')\"; title='Search'><span><span>Search</span></span></button>";
	echo"<button type='button' id='btnPreview' name='btnPreview'  onClick=\"printPrev('".$printaccess."')\"; title='Preview'><span><span>Preview</span></span></button>";
  
echo"	</td></tr></table>";
echo"</td></tr>";				

		
echo"<tr><td id='content-body'>
<table border='0'  height='534' align='center' valign='top' width=100% class='tablecontent'>
   <tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>";		
   
echo '  <table border="0" align="center" width="100%">';
//title date
echo" <tr>";	  
echo"   <td width='20%' height='19' colspan='2' align='left' bgcolor='#F5F5F5'><span class='style8'>";
echo"      <label><input name='date' type='radio' value='1' checked='checked'>Date</label>&nbsp;&nbsp;&nbsp;";
echo"   </td>";

//should be check to get the method ledger number
echo"   <td colspan='3' bgcolor='#F5F5F5'><span class='style8'>Ledger No. / Name ";
echo"   <label><input name='ledgeroption' type='radio' value='1' checked='checked'> Ledger No. </label>";
echo"   <label hidden><input name='ledgeroption' type='radio' value='2' hidden> Document </label></span>
		</td>";
echo" </tr>";

echo" <tr>";
echo "<td colspan=6></td>";

//dropdown preview
/* echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>View Option
		</td>"; */

echo" </tr>";



//from date
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>";
//todate			
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>";
		
//from ledger			
echo"   <td width='5%'  align='left' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td  colspan='3' 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);' />
        <input name='btncode1' type='hidden' id='btncode1' value='...' onclick='cgr7()' style='width:20px; height:20px; border:thin;' title='Select Ledger From' />
		</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='25' height='20' border='0' /></a> </span></label>";

//dropdown list show
		echo "   <td> <select name='currency' id='currency'>";
				echo " <option value='$base1' ";
				if($currency == '$base1' ) echo " selected ";
				echo " > $base1 </option>";
				
				echo "<option value='$base2' ";
				if($currency == '$base2' ) echo " selected ";
				echo" > $base2 </option>
				</select>
				</td>";
		echo"
		<td colspan=6>
				<select name='concail' id='concail'>";
					echo "  <option value='' ";
					if($concail == '' ) echo " selected "; 
					echo">All</option>";
					
					echo " <option value='1' ";
					if($concail == '1' ) echo "selected "; 
					echo " >Reconciled</option>";
					
					echo "<option value='0' ";
					if($concail == '0' ) echo  " selected "; 
					echo ">Un-Reconciled</option>
										</select>
				</td>";


//to date
echo" <tr height='15px' hidden> ";

			
//to ledger
echo"   <td width='5%'  align='left' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td   colspan='3' valign='middle' 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);' /> 
        <input name='btncode2' type='hidden' id='btncode2' value='...' onclick='cgr8()' style='width:20px; height:20px; border:thin;' title='Select Ledger To' />
		
      </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='25' height='20' border='0' /></a> 
		</span></label>";	
	
echo" </tr>";

echo "<tr>";

//table result

$new=$_GET['action'];
  
	if($new=='search'){

	  $fromledger=$_GET['fromledger'];
	  $fromledgername=$_GET['fromledgername'];
	  $toledger=$_GET['toledger'];
	  $toledgername=$_GET['toledgername'];
	  $fromdate=$_GET['fromdate'];
	  $todate=$_GET['todate'];
	  $currency= $_GET['currency'];
  
$expdate = explode("/",$fromdate);
$expdate1 = explode("/",$todate);

$fromdatenew = $expdate[2]."-".$expdate[1]."-".$expdate[0]; 
$todatenew = $expdate1[2]." -".$expdate1[1]."-".$expdate1[0];   echo $expdate1[1];   
$treconcail='';
$tunreconcail='';
$i=0;

//Table search result
echo '<table class="scroll" border=1 width=1100px style="border:0 solid black;">';
	echo "		<col width=60>
				<col width=10>
				<col width=60>
				<col width=250>
				<col width=10>
				<col width=80>
				<col width=80>
				<col width=80>
				<col width=10>
				<tr stle=' background-color:darkgray;'>
					<th style='font-family:cursive;'>Date</th>
					<th style='font-family:cursive;'>Ref</th>
					<th style='font-family:cursive;'>Date</th>
					<th style='font-family:cursive;'>Description</th>
					<th style='font-family:cursive;'>Curr</th>
					<th style='font-family:cursive;'>Debit</th>
					<th style='font-family:cursive;'>Credit</th>
					<th style='font-family:cursive;'>Balance</th>
					<th style='font-family:cursive;'>Check</th>
				</tr>
			</thead>";
			
	/* 	$queryall="select journaldt.ledger_number,ledger.ledger_name,journal_date,Journaldt_amount,journaldt.Currency_code,Journaldt_reconciled,Journaldt_reconciledref,journaldt.Journaldt_id,Journaldt_reconciled,
						journaldt.Journal_date,journaldt.journaldt_reconciledref,journaldt.Journaldt_ValueDate,journaldt.Journaldt_desc,journaldt.journaldt_dbcd,journaldt.Currency_code
					   from ledger left join journaldt on journaldt.ledger_number = ledger.ledger_number
					   where if('$concail'='',1=1, Journaldt_reconciled ='$concail')
					   and  journaldt.ledger_number BETWEEN '$fromledger' AND '$toledger'
					   and  date_format(journal_date,'%Y-%m-%d') BETWEEN '$fromdatenew' AND '$todatenew'"; */
					  

		$queryall="select journaldt.journal_id,journaldt.Ledger_number,journaldt.Journal_date,a.Journal_refgovernment ,journaldt.Journaldt_ValueDate,
							journaldt.Journaldt_desc,journaldt.Journaldt_dbcd, journaldt.Currency_code,
							journaldt.Journaldt_amount,journaldt.Journaldt_reconciled
						from journaldt
						left join journal a on a.journal_id=journaldt.journal_id
						where if('$concail'='',1=1, Journaldt_reconciled ='$concail') 
						AND journaldt.ledger_number BETWEEN '$fromledger' AND '$toledger'  AND journaldt.Currency_code ='$currency'
						AND date_format(journaldt.journal_date,'%Y-%m-%d') BETWEEN '$fromdatenew' AND '$todatenew'";
		
		/* $queryall=" select journal_id,Ledger_number,Journal_date,Journaldt_reconciledref ,Journaldt_ValueDate, Journaldt_desc,Journaldt_dbcd, Currency_code,  Journaldt_amount,Journaldt_reconciled
						from journaldt  
						where if('$concail'='',1=1, Journaldt_reconciled ='$concail') 
							AND ledger_number BETWEEN '$fromledger' AND '$toledger' 
							AND date_format(journal_date,'%Y-%m-%d') BETWEEN '$fromdatenew' AND '$todatenew'";	     */
						
			 echo $queryall; exit;
				   
		
				   
	
			
			$queryreconcail="select journaldt.journal_id,journaldt.Ledger_number,journaldt.Journal_date,a.Journal_refgovernment ,journaldt.Journaldt_ValueDate,
							journaldt.Journaldt_desc,journaldt.Journaldt_dbcd, journaldt.Currency_code,
							journaldt.Journaldt_amount,journaldt.Journaldt_reconciled
						from journaldt
						left join journal a on a.journal_id=journaldt.journal_id
						where journaldt.Journaldt_reconciled='1' AND journaldt.Currency_code ='$currency'
						AND journaldt.ledger_number BETWEEN '$fromledger' AND '$toledger' 
						AND date_format(journaldt.journal_date,'%Y-%m-%d') BETWEEN '$fromdatenew' AND '$todatenew'";
					
		//echo $queryreconcail; exit;
		
		//echo $querycurrency
		/*$querycurrency="select journaldt.journal_id,journaldt.Ledger_number,journaldt.Journal_date,a.Journal_refgovernment ,journaldt.Journaldt_ValueDate,
							journaldt.Journaldt_desc,journaldt.Journaldt_dbcd, journaldt.Currency_code,
							journaldt.Journaldt_amount,journaldt.Journaldt_reconciled
						from journaldt
						left join journal a on a.journal_id=journaldt.journal_id
						where journaldt.Currency_code ='$currency'
						AND journaldt.ledger_number BETWEEN '$fromledger' AND '$toledger' 
						AND date_format(journaldt.journal_date,'%Y-%m-%d') BETWEEN '$fromdatenew' AND '$todatenew'";
						//echo $querycurrency; exit;  */
		
						
		// end of currency
		
						
			$queryunreconcail="select journaldt.journal_id,journaldt.Ledger_number,journaldt.Journal_date,a.Journal_refgovernment ,journaldt.Journaldt_ValueDate,
									journaldt.Journaldt_desc,journaldt.Journaldt_dbcd, journaldt.Currency_code,
									journaldt.Journaldt_amount,journaldt.Journaldt_reconciled
								from journaldt
								left join journal a on a.journal_id=journaldt.journal_id
								where journaldt.Journaldt_reconciled='0' AND journaldt.Currency_code ='$currency'
								AND journaldt.ledger_number BETWEEN '$fromledger' AND '$toledger' 
								AND date_format(journaldt.journal_date,'%Y-%m-%d') BETWEEN '$fromdatenew' AND '$todatenew'";
			
		
			//echo $queryunreconcail;
			$result=mysql_query($queryunreconcail,$connection) or die(mysql_error());
			$num_rowss = mysql_num_rows($result);
			$tunreconcail=$num_rowss;
			
			$result2=mysql_query($queryreconcail,$connection) or die(mysql_error());
			$num_rows = mysql_num_rows($result2);
			$treconcail=$num_rows;	

			$result=mysql_query($queryall,$connection) or die(mysql_error());
			
			
			$debit=0;
			$credit=0;
			$balance=0;
			$balance2=0;
			while($row = mysql_fetch_row($result)){
			$journaldt_id = $row[0];
			$ledger_number = $row[1];;
			$journal_date = $row[2];
			$journal_date=explode(" ", $journal_date);
			$Journaldt_reconciledref=$row[3];
			$Journaldt_ValueDate=$row[4];
			$Journaldt_ValueDate=explode(" ", $Journaldt_ValueDate);
			$Journaldt_desc=$row[5];
			$journaldt_dbcd=$row[6];
			$Currency_code=$row[7];
			$Journaldt_amount = $row[8];
			$Journaldt_reconciled = $row[9];
			
			echo"	<tr width=75%>";
			echo"		<td style='font-family:monospace; font-size:15px;'>".$journal_date[0]."</td>";
			echo"		<td style='font-family:monospace; font-size:15px;'>".$Journaldt_reconciledref."</td>";
			echo"		<td style='font-family:monospace; font-size:15px;'>".$Journaldt_ValueDate[0]."</td>";
			echo"		<td style='font-family:monospace; font-size:15px;'>".$Journaldt_desc."</td>";
			echo"		<td style='font-family:monospace; font-size:15px;'>".$Currency_code."</td>";
				if($journaldt_dbcd == 'D'){
			echo"		<td style='font-family:monospace; font-size:15px;'>".number_format($Journaldt_amount,$DecimalBase)."</td>";
				$debit=$Journaldt_amount;
			echo"		<td style='font-family:monospace; font-size:15px;'></td>";
				}
				if($journaldt_dbcd == 'C'){
					 echo"		<td style='font-family:monospace; font-size:15px;'></td>";
					 $Credit=$Journaldt_amount;
					 echo"		<td style='font-family:monospace; font-size:15px;'>".number_format($Journaldt_amount,$DecimalBase)."</td>";
				}
				if($journaldt_dbcd ==''){
					 echo"		<td style='font-family:monospace; font-size:15px;'></td>";
					 echo"		<td style='font-family:monospace; font-size:15px;'></td>";
				}
			
				$balance=$balance2 + ($debit-$Credit);
				
				$balance2 = $balance;
				$debit = 0;
				$Credit = 0;
				
				if($balance<0){
					$balance_format=abs($balance);
			echo "<td style='font-family:monospace; font-size:15px;'>(".number_format($balance_format,$DecimalBase).")</td>";
				}
				else{
			echo"		<td style='font-family:monospace; font-size:15px;'>".number_format($balance,$DecimalBase)."</td>";
				}
			if($Journaldt_reconciled == 1) $chktrue = ' checked ';
			else $chktrue = ' ';
			echo "		<td style='text-align:center'><input type='checkbox' id='check[$i]' name='check' value='".$journaldt_id."' onclick='update()' width=5px height=50px $chktrue></td>
					</tr>";
					//	$treconcail=$treconcail+1;
						$tamount=$balance2;
						$i++;
			}
			echo "</tr>";
			
		//dropdown show
		echo "<td colspan='3' style='border:0'></td>";
			if($tamount<0){
				$tamount=abs($tamount);
		echo "<td colspan='3' align='right'>Total Amount:<b> (".number_format($tamount,$DecimalBase)." )</b></td>";
			}
			else{
				echo "<td colspan='3' align='right'>Total Amount:<b>".number_format($tamount,$DecimalBase)."</b></td>";
			}
		echo "<td  colspan='3'>Total UnReconcaile:<b>$tunreconcail</b><hr>Total Reconcaile:<b>$treconcail</b></td>";
		echo "</tr>";
echo"</tr>";
echo" </table>";

echo "</tr>";

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

$new1=$_GET['action'];

	if($new1=='save'){
	//echo"You have saved your option";
				
	  $fromledger=$_GET['fromledger'];
	  $fromledgername=$_GET['fromledgername'];
	  $toledger=$_GET['toledger'];
	  $toledgername=$_GET['toledgername'];
	  $fromdate=$_GET['fromdate'];
	  $todate=$_GET['todate'];
	  
  
$expdate = explode("/",$fromdate);
$expdate1 = explode("/",$todate);

$fromdatenew = $expdate[2]."-".$expdate[1]."-".$expdate[0]; 
$todatenew = $expdate1[2]."-".$expdate1[1]."-".$expdate1[0]; 
$treconcail='';
$tunreconcail='';
$i=0;
$journaldtids = explode(',',$tobechecked); 
$journaldtidsnotchecked = explode(',',$notchecked); 

//Table search result
echo '<table class="scroll" border=1 width=1100px style="border:0 solid black;">';
	echo "		<col width=60>
				<col width=10>
				<col width=60>
				<col width=250>
				<col width=10>
				<col width=80>
				<col width=80>
				<col width=80>
				<col width=10>
				<tr stle=' background-color:darkgray;'>
					<th style='font-family:cursive;'>Date</th>
					<th style='font-family:cursive;'>Ref</th>
					<th style='font-family:cursive;'>Date</th>
					<th style='font-family:cursive;'>Description</th>
					<th style='font-family:cursive;'>Curr</th>
					<th style='font-family:cursive;'>Debit</th>
					<th style='font-family:cursive;'>Credit</th>
					<th style='font-family:cursive;'>Balance</th>
					<th style='font-family:cursive;'>Check</th>
				</tr>
			</thead>";
			
				foreach($journaldtids as $journaldtid){ 
				$query1="UPDATE journaldt SET Journaldt_reconciled='1' 
				    WHERE Journal_id=$journaldtid"; 
				//echo $query1;exit;
					$resupdate = mysql_query($query1,$connection);
				}
				
				foreach($journaldtidsnotchecked as $notchecked){
					$query2="UPDATE journaldt SET Journaldt_reconciled='0' 
				    WHERE Journal_id=$notchecked"; 
				//echo $query1;exit;
					$resupdate2 = mysql_query($query2,$connection);
				}
					   
		$queryall="select journaldt.journal_id,journaldt.Ledger_number,journaldt.Journal_date,a.Journal_refgovernment ,journaldt.Journaldt_ValueDate,
							journaldt.Journaldt_desc,journaldt.Journaldt_dbcd, journaldt.Currency_code,
							journaldt.Journaldt_amount,journaldt.Journaldt_reconciled
						from journaldt
						left join journal a on a.journal_id=journaldt.journal_id
						where if('$concail'='',1=1, Journaldt_reconciled ='$concail') 
						AND journaldt.ledger_number BETWEEN '$fromledger' AND '$toledger' 
						AND date_format(journaldt.journal_date,'%Y-%m-%d') BETWEEN '$fromdatenew' AND '$todatenew'";


			$queryreconcail="select journaldt.journal_id,journaldt.Ledger_number,journaldt.Journal_date,a.Journal_refgovernment ,journaldt.Journaldt_ValueDate,
							journaldt.Journaldt_desc,journaldt.Journaldt_dbcd, journaldt.Currency_code,
							journaldt.Journaldt_amount,journaldt.Journaldt_reconciled
						from journaldt
						left join journal a on a.journal_id=journaldt.journal_id
						where journaldt.Journaldt_reconciled='1'
						AND journaldt.ledger_number BETWEEN '$fromledger' AND '$toledger' 
						AND date_format(journaldt.journal_date,'%Y-%m-%d') BETWEEN '$fromdatenew' AND '$todatenew'";
	
			$queryunreconcail="select journaldt.journal_id,journaldt.Ledger_number,journaldt.Journal_date,a.Journal_refgovernment ,journaldt.Journaldt_ValueDate,
							journaldt.Journaldt_desc,journaldt.Journaldt_dbcd, journaldt.Currency_code,
							journaldt.Journaldt_amount,journaldt.Journaldt_reconciled
							from journaldt
							left join journal a on a.journal_id=journaldt.journal_id
							where journaldt.Journaldt_reconciled='0'
							AND journaldt.ledger_number BETWEEN '$fromledger' AND '$toledger' 
							AND date_format(journaldt.journal_date,'%Y-%m-%d') BETWEEN '$fromdatenew' AND '$todatenew'";
			
			
			
			$result=mysql_query($queryunreconcail,$connection) or die(mysql_error());
			$num_rowss = mysql_num_rows($result);
			$tunreconcail=$num_rowss;
			
			$result2=mysql_query($queryreconcail,$connection) or die(mysql_error());
			$num_rows = mysql_num_rows($result2);
			$treconcail=$num_rows;	

			$result=mysql_query($queryall,$connection) or die(mysql_error());
			//echo $result;
			while($row = mysql_fetch_row($result)){
			$journaldt_id = $row[0];
			$ledger_number = $row[1];;
			$journal_date = $row[2];
			$journal_date=explode(" ", $journal_date);
			$Journaldt_reconciledref=$row[3];
			$Journaldt_ValueDate=$row[4];
			$Journaldt_ValueDate=explode(" ", $Journaldt_ValueDate);
			$Journaldt_desc=$row[5];
			$journaldt_dbcd=$row[6];
			$Currency_code=$row[7];
			$Journaldt_amount = $row[8];
			$Journaldt_reconciled = $row[9];
			
			echo"	<tr width=75%>";
			echo"		<td style='font-family:monospace; font-size:15px;'>".$journal_date[0]."</td>";
			echo"		<td style='font-family:monospace; font-size:15px;'>".$Journaldt_reconciledref."</td>";
			echo"		<td style='font-family:monospace; font-size:15px;'>".$Journaldt_ValueDate[0]."</td>";
			echo"		<td style='font-family:monospace; font-size:15px;'>".$Journaldt_desc."</td>";
			echo"		<td style='font-family:monospace; font-size:15px;'>".$Currency_code."</td>";
				if($journaldt_dbcd == 'D'){
			echo"		<td style='font-family:monospace; font-size:15px;'>".number_format($Journaldt_amount,$DecimalBase)."</td>";
				$debit=$Journaldt_amount;
			echo"		<td style='font-family:monospace; font-size:15px;'></td>";
				}
				if($journaldt_dbcd == 'C'){
					 echo"		<td style='font-family:monospace; font-size:15px;'></td>";
					 $Credit=$Journaldt_amount;
					 echo"		<td style='font-family:monospace; font-size:15px;'>".number_format($Journaldt_amount,$DecimalBase)."</td>";
				}
				if($journaldt_dbcd ==''){
					 echo"		<td style='font-family:monospace; font-size:15px;'></td>";
					 echo"		<td style='font-family:monospace; font-size:15px;'></td>";
				}
			
				$balance=$balance2 + ($debit-$Credit);
				
				$balance2 = $balance;
				$debit = 0;
				$Credit = 0;
				
				
			if($balance<0){
					$balance_format=abs($balance);
			echo "<td style='font-family:monospace; font-size:15px;'>(".number_format($balance_format,$DecimalBase).")</td>";
				}
				else{
			echo"		<td style='font-family:monospace; font-size:15px;'>".number_format($balance,$DecimalBase)."</td>";
				}
			if($Journaldt_reconciled == 1) $chktrue = ' checked ';
			else $chktrue = ' ';
			echo "		<td style='text-align:center'><input type='checkbox' id='check[$i]' name='check' value='".$journaldt_id."' onclick='update()' width=5px height=50px $chktrue></td>
					</tr>";
					//	$treconcail=$treconcail+1;
						$tamount=$balance2;
						$i++;
			}
			
			//dropdown show
		echo "<td colspan='3' style='border:0'></td>";
			if($tamount<0){
				$tamount=abs($tamount);
		echo "<td colspan='3' align='right'>Total Amount:<b> (".number_format($tamount,$DecimalBase)." )</b></td>";
			}
			else{
				echo "<td colspan='3' align='right'>Total Amount:<b>".number_format($tamount,$DecimalBase)."</b></td>";
			}
		echo "<td  colspan='3'>Total UnReconcaile:<b>$tunreconcail</b><hr>Total Reconcaile:<b>$treconcail</b></td>";
		echo "</tr>";
	
echo"</tr>";
echo" </table>";
echo "</tr>";
echo" </table></td>";		
echo" </tr>";		
}
echo "</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>";

?>

















