<?php
session_start(); 
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
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");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}
//amin nabil spanish

if(!isset($actionmode))
$actionmode='';


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


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

$query_module="select module_bill,ifnull(module_autoledger,0) as module_autoledger from module";
	$result=mysql_query($query_module);
	$row=mysql_fetch_row($result);
	$module_autoledger=$row[1];
	
	
$query_login="select login_belongstogrp, ifNull(FA_LedgerDel,0), ifNull(FA_LedgerMod,0), ifNull(FA_LedgerApp,0)
			  from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlogin=mysql_query($query_login,$connection) or die(mysql_error());

//echo  $query_login;
$row_login=mysql_fetch_row($resultlogin);
$belongstogroup = $row_login[0];
$FA_Ledger_Del  = $row_login[1];
$FA_Ledger_Mod  = $row_login[2];
$FA_Ledger_App	= $row_login[3];

//// Delete   Edit 
$DeleteMode=' ';
if($FA_Ledger_Del==0)
$DeleteMode ='disabled';

$EditMode=' ';
if($FA_Ledger_Mod==0)
$EditMode = ' disabled ';

$AddMode='';

if($FA_Ledger_App==0)
$AddMode = ' disabled ';

$saveEnabled = 0;
if ( ($FA_Ledger_Mod == 1 && $actionmode=='editmode') || ($FA_Ledger_App == 1))
	$saveEnabled = 1;

$query_language  = "select user_account, Language from ".$_SESSION['dbLabel'].".login  where user_account = '".$_SESSION['useraccount']."'";
		 $result_language = mysql_query($query_language, $connection); 
		 $row_language    = mysql_fetch_array($result_language);
		 extract($row_language);
		 
$query_labels  = "select Language, NumberName, Description, CoNumberName, Document, CashTypeCode, ProjectCodeName, CostCenterCodeName, Type, Nature, LedgerinactiveDate, Currency  as Currency1, Groupp, RequireDetail, Sequence, Length, Other, Clients as Clients1, Suppliers, Salesmen, Student, Code as Code1, Name as Name1, AddLedger as AddLedger1
                  From ".$_SESSION['dbLabel'].".ledger_label
                  where Language = '".$Language."'";
$result_labels = mysql_query($query_labels, $connection);
$row_labels    = mysql_fetch_array($result_labels);
extract($row_labels);

$query_navigator = "SELECT LANGUAGE,
       ClearPage,
       Excel,
       Save,
       Print,
       Addd,
       SEARCH,
       Pending,
       CopyJV,
       PaymentRequests,
       ExportExcel
FROM ".$_SESSION['dbLabel'].".mainform_label
WHERE LANGUAGE = '".$Language."'";
$result_navigator = mysql_query($query_navigator, $connection);
$row_navigator    = mysql_fetch_array($result_navigator);
extract($row_navigator);

$query_ledger  = "select Ledger as Ledger1, ResultsPage as ResultsPage1 from ".$_SESSION['dbLabel'].".mainform_label where Language = '".$Language."'";
$result_ledger = mysql_query($query_ledger, $connection);
$row_ledger    = mysql_fetch_array($result_ledger);
extract($row_ledger);
//echo $ResultsPage1; exit;

$accresult = get_acctype($connection);

	
if($actionmode=='editmode' or $actionmode=='view'){

	$query_edit="select Ledger_number, Ledger_name, Ledger_desc, Ledger_grpdet, Ledger_activity, Acctype_increment, Document, 
				Ledger_number2, Ledger_name2,Project_Code, Ledger_BelongsToGroup,CashType_Code, Ledger_Deactivate, 
				Ledger_RequiredDetail,CostCenter_code, date_format(Ledger_inactivedate,'%d-%m-%Y'), Currency_code,ledger_type,ledger_sequence,ledger_length,
				ledger_asset, ledger_assetPer, ledger_assetCode, ledger_assetLength, ledger_assetCredit, ledger_assetDebit, ledger_assetSequence
				from ledger where ledger_number='".$ledger_number."'";
	//echo$query_edit;
	$resultedit=mysql_query($query_edit,$connection) or die(mysql_error());
	while($row=mysql_fetch_array($resultedit)){

	$ledger_number			= $row[0];
	$ledger_numberPrv		= $row[0];
	$ledger_name			= $row[1];
	$ledger_description		= $row[2];
	$ledger_grpdet			= $row[3];
	$ledger_activity		= $row[4];
	$acctypename			= $row[5];
	$document				= $row[6];
	$ledger_number2			= $row[7];
	$ledger_name2			= $row[8];
	$project_code			= $row[9];
	$cashtype_code			= $row[11];
	$ledger_inactive		= $row[12];
	$ledger_requireddetail	= $row[13];
	$costcenter_code		= $row[14];
	$deactivatedate			= $row[15];
	$currency_code			= $row[16];
	$ledgertype				= $row[17];
	$ledger_sequence		= $row[18];
	$ledger_length			= $row[19];
	$showAsset				= $row[20];
	$assetper				= $row[21];
	$assetcode				= $row[22];
	$assetlength			= $row[23];
	$assetcrdt				= $row[24];
	$assetdbt				= $row[25];
	$assetseq				= $row[26];
	
	if($actionmode!='view')
		$actionmode='edit';
}

	$query2="select Project_code,Project_name from project where project_code='$project_code'";
	$result=mysql_query($query2, $connection);
	$row=mysql_fetch_row($result);
	$project_name=$row[1];

	$query3="select costcent_code,costcent_name from costcent where costcent_code='$costcenter_code'";
	$result=mysql_query($query3, $connection);
	$row=mysql_fetch_row($result);
	$costcenter_name=$row[1];

	$query4="select CashType_Code,CashType_Description from cashtype where CashType_Code='$cashtype_code'";
	$result=mysql_query($query4, $connection);
	$row=mysql_fetch_row($result);
	$cashtype_description=$row[1];
}

if($actionmode=='') $actionmode='insert';


print <<<HERE

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<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/tabs.css">

<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">

<script type="text/javascript" language="javascript">

function selectgroup(){
		var str = '';
		str = 'Form_SelectLedgerGroup.php';
		window.open(str,'mywindow','width=650,height=600,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
		


}


function PrintPreview()
{
	if (confirm ( "Do you want to Print List of Ledgers?")){
		var str = '';
		str = 'Form_LedgerPreview.php';
		window.open(str);
	}
}


function ExportExcel() {
	var str = '';
	str = 'Form_LedgerExcel.php';
	window.open(str);
}


function editmode () {

	var l=document.ledger.ledger_number.value;
	document.ledger.actionmode.value='editmode';
	document.ledger.action="Form_Ledger.php?ledger_number="+l;
	document.ledger.submit();
}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters center' counter
else {
countfield.value = maxlimit - field.value.length;}
}

function set_nature(){

	document.ledger.ledger_activity.value=document.ledger.nature.value;
}

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


function AddLedger () {

  win = window.open('Form_Ledger_Options.php', 'optionwindow', 'addressbar=no,statusbar=0,toolbar=no,location=no,status=0,menubar=no,scrollbars=no,resizable=no,width=200,height=150,top=200,left=350,titlebar=0');		

}


function CancelRecord () {
	if (confirm ( "Are you sure you want to Cancel Page?")){
		ClearForm('All');
		document.ledger.action="Form_Ledger.php?actionmode=";
		document.ledger.submit();
	}
}


//All= All form; D= Detail Part
function ClearForm(Option){
	x = document.ledger;
	var s=document.ledger.actionmode.value;

	x.ledger_number.value='';
	x.ledger_name.value='';
	x.ledger_description.value='';
	x.ledger_grpdet.value='0';
	x.ledger_activity.value='';
	x.acctypename.value='';
	x.document.value='';
	x.ledger_number2.value='';
	x.ledger_name2.value='';
	x.project_code.value='';
	x.project_name.value='';
	x.ledgertype.value='';
	x.cashtype_code.value	='';
	x.cashtype_description.value	='';
	x.ledger_requireddetail.value	='';
	x.ledger_sequence.value	= '';
	x.ledger_length.value	= '';
	x.costcenter_code.value	= '';
	x.costcenter_name.value	= '';
	x.ledger_inactive.value	= '';
	x.deactivatedate.value	= '';
	x.currency_code.value	= '';
	x.actionmode.value		= '';
	x.ledger_group.value	= '';
	x.message.value 		= '';
	x.showAsset.value		= '';
	x.assetper.value		= '';
	x.assetcode.value		= '';
	x.assetlength.value		= '';
	x.assetcrdt.value		= '';
	x.assetdbt.value		= '';
	x.assetseq.value		= '';
}
	
	
function ClearPage(){
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		x.actionmode.value='';
		x.action='Form_Ledger.php';
		x.submit();
	}	
}


function fill_curr(){
	document.ledger.currency_code.value=document.ledger.currency.value;
}

function fill_currdt(){
	document.ledger.currencydt_code.value=document.ledger.currencydt.value;
}

function fill_acctype(){
	document.ledger.acctypename.value=document.ledger.acctype.value;
}

function changeinactive(){
	if(document.ledger.inactive.checked){
		document.ledger.ledger_inactive.value=1;
}
else
{
	document.ledger.ledger_inactive.value=0;
	document.ledger.deactivatedate.value='';
}

	var m;
	m=document.ledger.actionmode.value;
	document.ledger.action='Form_Ledger.php?actionmode='+m;
	document.ledger.submit();
}

function changerequired(){
	if(document.ledger.notrequired.checked){
		document.ledger.ledger_requireddetail.value=1;
	}
	else
	{
	document.ledger.ledger_requireddetail.value=0;
	}
}
function changesequence(){
	if(document.ledger.sequencechk.checked){
		document.ledger.ledger_sequence.value=1;
	}
	else
	{
	document.ledger.ledger_sequence.value=0;
	}
}

function changegrpdet (){
	if(document.ledger.grpdet.checked){
		document.ledger.ledger_grpdet.value=1;
	}
	else{
	document.ledger.ledger_grpdet.value=0;
	}
}

function changedeactive(){
	if(document.ledger.deactive.checked){
	document.ledger.ledger_deactivate.value=1;
	}
	else
	{
	document.ledger.ledger_deactivate.value=0;
	}
}

function showlistprojects(str){

  window.open('List_Project_orderbycode.php?str='+str,'mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistprojectsname(str){

  window.open('List_Project_orderbyname.php?str='+str,'mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistcostcenter(str){

  window.open('List_CostCenter.php?str='+str,'mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


function showlistcostcentercode(str){

  window.open('List_CostCenter_orderbycode.php?str='+str,'mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistcostcentername(str){

  window.open('List_CostCenter_orderbyname.php?str='+str,'mywindow','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


/*
function SearchForLedger(){
    ClearForm('All');
    x = document.ledger;
    win = window.open('Form_LedgerSearch.php', 'Form_LedgerSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=775,height=450,top=100,left=100');		
	win.creator = self;
	win.focus();		
			
}*/

function SearchForLedger(){
	x = document.ledger;
	document.ledger.action='Form_Ledger.php?startrange=0';
	document.ledger.submit();
}

function ClearKeyword(){
	x = document.ledger;
	x.txtKeyword.value='';
	document.ledger.submit();
}




function SubmitRecord(module_autoledger) {

var perpage=document.ledger.perpage.value;

var checkOK = "0123456789";

var checkStr = ledger.ledger_number.value;
var allValid = true;
var allNum = "";
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}



var checkStr = ledger.acctypename.value;
var allValid = true;
var allNum = "";
for (i = 0;  i < checkStr.length;  i++)
{
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid)
{
alert("Please enter only digit characters in the \"Type\" field.");
ledger.acctypename.focus();
return (false);
}



var m=document.ledger.actionmode.value;

	 if (document.ledger.ledger_number.value=='' && module_autoledger==0)
		{alert('Unable to save : check missing field Number ');
		document.ledger.ledger_number.focus();
		
		}
		
		else	if (document.ledger.ledger_name.value=='' )
		{alert('Unable to save : check missing field Name ');
		document.ledger.ledger_name.focus();
		}
		
		else	if (document.ledger.currency_code.value=='' )
		{alert('Unable to save : check missing field Currency ');
		document.ledger.currency_code.focus();
		
		}
		
	else{
		document.ledger.checkcode.value='1';
		document.ledger.action='Form_Ledger.php?&perpage='+perpage;
		document.ledger.submit();
	}	
}

function SetLedger(LedgerNumber){
	//alert(LedgerNumber);
	document.ledger.ledger_number.value=LedgerNumber;
	document.ledger.message.value='';
var actionmode=	document.ledger.actionmode.value='editmode';
	document.ledger.action='Form_Ledger.php?&actionmode='+actionmode;
	document.ledger.submit();
}

function submitenter(myfield,e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   	document.ledger.action='Form_Ledger.php?startrange=0';
	document.ledger.submit();
  
   return false;
   }
else
   return true;
}

function confirm_delete(Code) {
	
				
	if (confirm ( "Are you sure you want to Delete this Record " + "?")) {
		//window.event.returnValue = true;
		document.ledger.actionmode.value='delete';	
		
		document.ledger.action='Form_Ledger_Actions.php?ledgernumber='+Code;
		document.ledger.submit();
	}
					
}

function SetNextPage(startrange,perpage){
	document.ledger.action='Form_Ledger.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.ledger.submit();
}

function SetPrvPage(startrange,perpage){
	document.ledger.action='Form_Ledger.php?PRef=&startrange='+startrange+'&perpage='+perpage;
	document.ledger.submit();
}

function set_limit(){

	perpage=document.ledger.perpage.value;
	document.ledger.action='Form_Ledger.php?perpage='+perpage+'&startrange=0';
	document.ledger.submit();
}

function addserial(){
	var ledgernumber= document.ledger.ledger_number.value;
	//alert(ledgernumber);
//	alert(ledgernumber.toString().length);
	if(ledgernumber.toString().length<4){
			alert("Minimum Number/Name of digits is 4");
			return;
	}
	
	document.ledger.action='Form_Ledger_Actions.php?actionmode=getledgergroup&ledger_number='+ledgernumber;
	document.ledger.submit();
	
}

function returnMsg(){
	alert("Access Denied!");
	return 0;
}

function openLedgerList(str){
	window.open('select_ledger.php?item='+str,'ledger','width=600px,height=600px');	
}

function showAssets(){
	if (document.getElementById('showAsset').checked){
		document.getElementById('showAsset').value 	= 1;
		document.getElementById('assetper').disabled 	= false;
		document.getElementById('assetcode').disabled 	= false;
		document.getElementById('assetlength').disabled = false;
		document.getElementById('assetcrdt').disabled 	= false;
		document.getElementById('assetdbt').disabled 	= false;
		document.getElementById('assetseq').disabled 	= false;
	} else {
		document.getElementById('showAsset').value 	= 0;
		document.getElementById('assetper').disabled 	= true;
		document.getElementById('assetcode').disabled 	= true;
		document.getElementById('assetlength').disabled = true;
		document.getElementById('assetcrdt').disabled 	= true;
		document.getElementById('assetdbt').disabled 	= true;
		document.getElementById('assetseq').disabled 	= true;
	}
	
}
</script>

<title>$AddLedger1</title>

<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
body {
	margin-top: 2px;
	margin-left: 1px;
}
a:link {
	text-decoration: none;
	color: #0000FF;
}
a:visited {
	text-decoration: none;
	color: #0000FF;
}
a:hover {
	text-decoration: none;
	color: #0000FF;
}
a:active {
	text-decoration: none;
	color: #0000FF;
}

.style12 {
	font-size: 9px;
	color: #999999;
	font-weight: bold;
}
.style15 {color: #5151FF; font-size: 10px;}
.style16 {
	font-size: 16px;
	color: #FF0000;
	font-weight: bold;
	font-family: "Times New Roman", Times, serif;
}
.style17 {font-size: 9px}
.style25 {color: #999999; font-weight: bold; font-size: 10px; }
.style26 {color: #FF0000}
.style27 {color: #999999 ;font-size: 10px;}
.style28 {color: #FFFFFF ;font-size: 10px;}


			
</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>

</head>
<body >
<form name='ledger' method='post' onKeyPress="return submitenter(this,event)">
<input type=hidden name='checkcode' value='$checkcode'>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='typestatus' value='$typestatus'>
<input type='hidden' name='ledgertype' value='$ledgertype'>
<input type='hidden' name='ledger_numberPrv' value='$ledger_numberPrv'>
<input type=hidden name='message' value='$message'>
HERE;

//$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";

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' style='text-transform: uppercase'>".$Ledger1."</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' width='1100px'>
				<col width='450'>
				<col width='120'>
				<col width='150'>
				<col width='250'>
				<col width='200'>
				<col width='200'>
				<tr>
					<td valign='middle' height='34' style='padding-left:40px'>";
	echo"				<button type='button' id='btnClear' name='btnClear' onclick='ClearPage(); return false;' title='Clear Page'><span><span>$ClearPage</span></span></button>";
	echo"				<button type='button' id='btnExcel' name='btnExcel' onclick='ExportExcel(); return false;' title='Export Excel' ><span><span>$Excel</span></span></button>";
	echo"				<button type='button' id='btnPost' name='btnPost' onclick=\"";
	if ($saveEnabled == 1)
		echo "SubmitRecord($module_autoledger); ";
	else
		echo "returnMsg(); ";	
	echo "return false;\" title='Save Changes' $Insmode><span><span>$Save</span></span></button>
						<button  type='button'  value='Print' onclick='PrintPreview();return false;' title='print'><span><span>$Print</span></span></button>";
	if ($FA_Ledger_App == 1)					
		echo "<button  type='button'  value='Add' onclick='addserial();return false;' title='ADD'><span><span>$Addd</span></span></button>";
	echo "</td>";
					
					
						$querysearch="select ledger_number,ledger_name,if(ifnull(ledger_grpdet,0)=0,'Detail','Group') from ledger where ifNull(Ledger_BelongsToGroup,0) >= ".$login_belongstogrp;
							$querysearch=$querysearch." and (ledger_number like"."('%".$txtKeyword."%') or ledger_name like"."('%".$txtKeyword."%')) ";
							
							$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());
							$totalrows = mysql_num_rows($resultsearch);
							
							if ($startrange=='')
								$startrange = 0;
							if ($perpage=='')
								$perpage = 20;
							
							$querysearch = $querysearch." limit ".$startrange.",".$perpage;
							//echo$querysearch;
							
echo"					<td align='center'>";
						$diff= $startrange - $perpage;
						
						if (($diff) >= 0 ){
							$prvstartrange = $startrange - $perpage;
							echo"<img src='img/arrowleft.png' title='Previous' onMouseOver=\"style.cursor='hand'\"  onclick=SetPrvPage('".$prvstartrange."','".$perpage."')>";
						}
						else
							echo "&nbsp;";
						
						echo"</td><td  align='center'>";
						
						
						if ($startrange <= $totalrows){
							$startrange = $startrange + $perpage;
							if  ($startrange <= $totalrows)
								echo"<img src='img/arrowright.png' title='Next' onMouseOver=\"style.cursor='hand'\" onclick=SetNextPage('".$startrange."','".$perpage."')>";
						} else
							echo "&nbsp;";
						
echo"				</td>
					
					<td align='left' width='263px'>
						<input type='text' name='txtKeyword' value='$txtKeyword' style='width:115px;' onKeyPress='return submitenter(this,event)'>
						<button type='button' id='btnSearch' name='btnSearch' onclick='SearchForLedger(); return false;' title='Search Ledger'><span><span>Find</span></span></button>
						<button type='button' id='btnClear' name='btnClear' onclick='ClearKeyword(); return false;' title='Clear Keyword'><span><span>Clear</span></span></button>
					</td>
					
					<td colspan=2 align='left'><span class='style1'><b>".$ResultsPage1."</b></span>
						<span class='style1'><select name='perpage' id='perpage' value='$perpage' onchange=set_limit();>";
	 
						if ($startrange=='')
							$startrange = 0;
						if ($perpage=='')
							$perpage = 20;
						//row limit loop
						foreach ($config['trowlimit'] as $value) {
							echo "<option value='$value' ";
									if($value==$perpage) echo "selected";
										echo " >$value</option>";
						}
			
echo"  				 </td>
				</tr>
			</table>
		</td>
	</tr>";


$query="select count(*) from journaldt where ledger_number='".$ledger_numberPrv."'";
$result=mysql_query($query,$connection);
$row=mysql_fetch_row($result);
$countLedger=$row[0];


if($countLedger>0){
	$statuscode='readonly';
}

if(empty($ledgertype))
	$ledgertype=0;

if($actionmode==''){
	$status='disabled';
	$dis='disabled';
	
}

if($actionmode=='view'){
	$statuscode='readonly';
	$status='readonly';
	$dis='disabled';
}

if($actionmode=='insert'){
	$status='';
	$statuscode='';
}


if($ledger_inactive=='')
	$ledger_inactive='0';
			
if(!isset($ledger_activity))
	$ledger_activity=0;		


if($ledger_activity=='1')
	$selectednature1='selected';
	
if($ledger_activity=='2')
	$selectednature2='selected';

if($ledger_activity=='3')
	$selectednature3='selected';

if($ledger_activity=='4')
	$selectednature4='selected';

if(empty($ledger_grpdet))
	$ledger_grpdet=0;	
					  
if($ledger_grpdet=='1')	{				  
	$checkedgrp='checked';
}

if($ledger_requireddetail=='1')
	$selectedrequired='checked';
if($ledger_sequence=='1')
	$selectedsequence='checked';
	  
echo"	<tr>
			<td id='content-body'>";		
echo"			<table border='0'  align='center' valign='top' width=1100px class='tablecontent'>";
	echo"   			<tr bgcolor='#F7F7F7'>";
	echo"   				<td valign='top'>
								<table style='table-layout:fixed' align='left' valign='top' width='1100px' border=0>
									<col width=150>
									<col width=170>
									<col width=260>
									<col width=70>
									<col width=400>";
		 
									if($module_autoledger=='1'){
 echo"								 <tr bgcolor='#F7F7F7' height='25'>
										<td valign='center' align='left' bgcolor='#F7F7F7'><span class='style1'>Ledger Group</span><span class='style26'></span></td>
										<td colspan=2 align='left'>
											<input type='text' readonly name='ledger_group' value='".$ledger_group."' maxlength='10' style='font-size:12px; width:155px; height:18px;'/>
											<input type='button' name='but1' value='..'  onMouseOver=\"style.cursor='hand'\"  onclick='selectgroup()'>
										</td>
									</tr>";
									} else {
echo"										<input type='hidden' name='ledger_group' value='".$ledger_group."' m >";
									}
									if(isset($_GET['msg'])){$msg=$_GET['msg'];$ledger_number_plus=$_GET['ledger_number_plus'];$ledgetdtserial=$_GET['ledgetdtserial'];}
echo"								 <tr bgcolor='#F7F7F7' height='25'>
										<td valign='left' align='left' bgcolor='#F7F7F7'><span class='style1'>".$NumberName."</span><span class='style26'>*</span></td>";
									
											if($msg=='hasledgerdt'){
echo "									<span class='style1' style='color:red;'>Auto Detail Ledger Number</span>
										<td align='left'><input type='text' name='ledger_number' value='".$ledger_number_plus."' maxlength='10' style='font-size:12px; width:155px; height:18px;' $statuscode/></td>";
												}
											if($msg=='noledgerdt'){
echo "									<span class='style1' style='color:red;'>Start Detail Ledger Number</span>	
										<td align='left'><input type='text' name='ledger_number' value='".$ledgetdtserial."' maxlength='10' style='font-size:12px; width:155px; height:18px;' $statuscode/></td>";
												}
											if($msg=='ledgernotfound'){
echo"										<span class='style1' style='color:red;'>Ledger Not Found</span>	
										<td align='left'><input type='text' name='ledger_number' value='".$ledger_number."' maxlength='10' style='font-size:12px; width:155px; height:18px;' $statuscode/></td>";
											}
											if($msg==''){
echo"									<td align='left'><input type='text' name='ledger_number' value='".$ledger_number."' maxlength='10' style='font-size:12px; width:155px; height:18px;' $statuscode/></td>";
											}
echo"									<td align='left'><input type='text' name='ledger_name' value='".htmlspecialchars($ledger_name, ENT_QUOTES)."' maxlength='50' style='font-size:12px; width:255px; height:18px;' $status /></td>
										<td align='left'><span class='style1'><span class='style1'>".$Description."</span></td>
										<td align='left'><textarea name='ledger_description'  size=100% cols=45 rows=4 maxlength='100' $status >".htmlspecialchars($ledger_description, ENT_QUOTES)."</textarea></td>
									</tr>";
									
			
											

function get_currency($connection){
$query_cr = "select currency_code,currency_name from currency";
$result_cr=mysql_query($query_cr, $connection);
return $result_cr;
}

$curr = get_currency($connection);
 
if(empty($currency_code) && $actionmode=='insert') {
 
$query_defaultcur="select Journal_DefaultCur from setup";
$result_cr=mysql_query($query_defaultcur, $connection);
$row_cur=mysql_fetch_row($result_cr);
$currency_code= $row_cur[0];
}

if($ledger_inactive=='1')			
$selectedactive='checked';				

$query_module="select module_bill,ifnull(module_autoledger,0) as module_autoledger from module";
$result=mysql_query($query_module);
$row=mysql_fetch_row($result);
$module_bill=$row[0];
$module_autoledger=$row[1];


echo "									<tr bgcolor='#F7F7F7' height='25'>
											<td valign='center' align='left' ><span class='style1'>".$CoNumberName."</span></td>
											<td align='left'><input type='text' name='ledger_number2' value='".htmlspecialchars($ledger_number2, ENT_QUOTES)."' maxlength='10' style='font-size:12px; width:154px; height:18px;' $status /></td>
											<td align='left'><input type='text' name='ledger_name2' value='".htmlspecialchars($ledger_name2, ENT_QUOTES)."' maxlength='50' style='font-size:12px; width:255px; height:18px;' $status /></td>
											<td align='left' ><span class='style1'>".$Document."</span></td>
											<td align='left'>
												<input type='text' name='document' value='".htmlspecialchars($document, ENT_QUOTES)."' maxlength='30' style='font-size:12px; width:389px; height:18px;'  $status />
											</td>
										</tr>
										
										<tr bgcolor='#F7F7F7'>
											<td align='left'><span class='style1'>".$CashTypeCode."</span></td>
											<td align='left'><input type='text' name='cashtype_code' value='".htmlspecialchars($cashtype_code, ENT_QUOTES)."'  style='font-size:12px; width:137px; height:18px;'  readonly/>";
												if($actionmode!='view' && $actionmode!='')
echo" 											<label><span class='style1'><input type='image' src='img/btnopen.jpg' title=' Select Cash Type '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistcash(); return false' /></span></label>&nbsp;";
												else echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo"										</td>
											<td align='left'><input type='text' name='cashtype_description' value='".htmlspecialchars($cashtype_description, ENT_QUOTES)."' style='font-size:12px; width:255px; height:18px;'  readonly /></td>									
										</tr>

										<tr bgcolor='#F7F7F7' height='25'> 
											<td align='left' bgcolor='#F7F7F7' height='25'><span class='style1'>".$ProjectCodeName."</span></td>
											<td align=left   bgcolor='#F7F7F7' height='25' ><input type=text name='project_code' value='$project_code' maxlength='30' $status readonly size='24' style='font-size:12px; width:138px; height:18px;'>";
												if($actionmode!='view' && $actionmode!='')
													echo" <label><span class='style1'><input type='image' src='img/btnopen.jpg' title=' Select Project '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistprojects(3); return false' /></span></label>";
												else echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";	
															
echo"										</td>
											<td  align=left><input type=text name='project_name' value='$project_name' maxlength='20' $status readonly size='24' style='font-size:12px; width:237px; height:18px;'>";			
												if($actionmode!='view' && $actionmode!='') {
													echo"&nbsp;<label><span class='style1'><input type='image' src='img/btnopen.jpg' title=' Select Project '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistprojectsname(3); return false' /></span></label>
											</td>";
												}
												
echo"										<td></td>
											<td>
												<input type=checkbox name='grpdet' onclick='changegrpdet()'  $dis $typestatus $checkedgrp>
												<input type='hidden' name='ledger_grpdet' value='$ledger_grpdet'><span class='style1'> ".$Groupp."</span>&nbsp&nbsp;
												<input type=checkbox name='notrequired' onclick='changerequired()'  $dis $selectedrequired><span class='style1'> ".$RequireDetail." &nbsp;&nbsp;</span>
												<input type='hidden' name='ledger_requireddetail' value='$ledger_requireddetail'>
												<input type=checkbox name='sequencechk' onclick='changesequence()'  $dis $selectedsequence><span class='style1'> ".$Sequence." &nbsp;&nbsp;</span>
												<input type='hidden' name='ledger_sequence' value='$ledger_sequence'>
												<input type='text' name='ledger_length' id='ledger_length' value='$ledger_length' style='width:25px'><span class='style1'>&nbsp;".$Length."</span>
											</td>
										</tr>

										<tr bgcolor='#F7F7F7' height='25'>
											<td align='left' bgcolor='#F7F7F7' height='25'><span class='style1'>".$CostCenterCodeName."</span></td>
											<td align=left   bgcolor='#F7F7F7' height='25'><input type=text name='costcenter_code' value='$costcenter_code' maxlength='30' $status readonly size='24' style='font-size:12px; width:138px; height:18px;'>";
												if($actionmode!='view' && $actionmode!='')
													echo" <label><span class='style1'><input type='image' src='img/btnopen.jpg' title=' Select Costcenter '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistcostcentercode(3); return false' /></span></label>&nbsp;";
													
												else  echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";	
										
echo"										</td>
											<td align=left><input type=text name='costcenter_name' value='$costcenter_name' maxlength='20' $status readonly size='24' style='font-size:12px; width:237px; height:18px;'>";			
												 if($actionmode!='view' && $actionmode!='')
													echo"&nbsp;<label><span class='style1'><input type='image' src='img/btnopen.jpg' title=' Select Costcenter '  width='15' height='17' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistcostcentername(3); return false' /></span></label>
											</td>
											<td><span class='style1'><b>".$Type.":</b></span></td>
											<td  bgcolor='#F7F7F7' align='left' >&nbsp;&nbsp;&nbsp;<input type=radio name=ledgertype  $dis value='0'";
												if($ledgertype=='0')
													echo"checked ";
												echo"><span class='style1'> ".$Other."</span>
													
													&nbsp;&nbsp;&nbsp;<input type=radio name='ledgertype' $dis value='1'";
																 
												if($ledgertype=='1')
													echo"checked ";
												echo" ><span class='style1'> ".$Clients1."</span>
													
													&nbsp;&nbsp;&nbsp;<input type=radio value='2' $dis name='ledgertype'";
																
												if($ledgertype=='2')
													echo"checked ";
												echo"><span class='style1'> ".$Suppliers."</span>
													&nbsp;&nbsp;&nbsp;<input type=radio $dis name=ledgertype value='3'";
													
												if($ledgertype=='3')
													echo"checked ";
												echo"><span class='style1'> ".$Salesmen."</span><br>
												&nbsp;&nbsp;&nbsp;<input type=radio $dis name=ledgertype value='4'";
															
												if($ledgertype=='4')
													echo"checked ";
												echo"><span class='style1'> ".$Student."</span>
											</td>
										</tr>
											
										<tr bgcolor='#F7F7F7' height='25'>
											<td  bgcolor='#F7F7F7' align='left'><span class='style1'> ".$Nature." </span>&nbsp&nbsp</td>
											<td  bgcolor='#F7F7F7' height='25' align='left'>
												<select name='nature' $naturestatus $dis onchange='set_nature();' style='width:160px;'>
													<option>&nbsp;</option>
													<option value='1' $selectednature1>Checks for Collections</option>
													<option value='2' $selectednature2>Checks for Payments</option>";
														
													if($module_bill=='1'){
														echo"	<option value='3' $selectednature3>Bills for Collections</option>
																<option value='4' $selectednature4>Bills for Payments</option>";
													}
echo"											<input type='hidden' name='ledger_activity' value='$ledger_activity'></select>
											</td>
											<td align='left'> <span class='style1'>".$Type."</span>
												<select  name='acctype' onchange='fill_acctype();' $status $dis style='width:180px;'>
													<option value=''></option>";
													while ($row=mysql_fetch_row($accresult))
													{
													if ($row[0]==$acctypename)
														echo"<option selected value='$row[0]'><font size=1>$row[1]</font></option>";
													else
														echo"<option value='$row[0]'><font size=1>$row[1]</font></option>";
													}	
					
echo"											<input type='hidden' name='acctypename' value='$acctypename' maxlength='5' style='font-size:12px; width:80px; height:18px;' $status />
											</td>
										</tr>
									
										<tr>
											<td align=left  bgcolor='#F7F7F7'>
												<span class='style1'>".$LedgerinactiveDate."</span><span class='style1'>&nbsp;<input type=checkbox name='inactive' onclick='changeinactive();'  $dis $selectedactive>
												<input type='hidden' name='ledger_inactive' value='$ledger_inactive'><span class='style1'>
											</td>
											<td align='left'>
												<input type='text' readonly name='deactivatedate' value='$deactivatedate' maxlength='10' size='10' style='font-size:12px; width:120px; height:18px;'>";
												if($actionmode!='view' && $actionmode!='' && $ledger_inactive=='1')
print<<<HERE
												&nbsp;&nbsp;<A HREF="#" onClick="displayCalendar(document.ledger.deactivatedate,'dd-mm-yyyy',this); return false;" NAME="anchor1" ID="anchor1"><image src='./img/cal.gif' border=0 align=center></image></A>
HERE;
echo"										</td>
											<td align='left' bgcolor='#F7F7F7' height='25'>
												<span class='style1'>".$Currency1."</span>
												<span class='style26'>* &nbsp;</span>
												<select  name='currency' onchange='fill_curr();'  $dis>
													<option value=''></option>";
													while ($cr=mysql_fetch_row($curr))
													{
													if ($cr[0]==$currency_code)
													echo"<option selected value='$cr[0]'>$cr[0]</option>";
													else
													echo"<option value='$cr[0]'>$cr[0]</option>";
													}	
													echo"<input type='hidden' name='currency_code' value='$currency_code'>
												</select>
											</td>
										</tr>";
if ($showAsset == '') $showAsset = 0;
if ($showAsset == 0) $disAsset = "disabled";
										
echo "								<tr bgcolor='#F7F7F7'><td colspan='5'><table><col width=150px><col width=200px><col width=120px><col width=190px><col width=120px><col width=190px>
										<tr>
										   <td><span class='style1'>Ledger Assests</span><input type='checkbox' name='showAsset' id='showAsset' value='$showAsset' onclick=\"showAssets();\" ".($showAsset == 1?'checked':'')."></td>		
										   <td><span class='style1'>Asset % </span><input type='text' name='assetper' id='assetper' value='$assetper' style='width:105px;' $disAsset max=100></td>		
										   <td><span class='style1'>Asset Code </span></td><td> <input type='text' name='assetcode' id='assetcode' value='$assetcode' style='width:170px;' $disAsset></td>		
										   <td><span class='style1'>Asset Length </span></td><td> <input type='text' name='assetlength' id='assetlength' value='$assetlength' style='width:150px;' $disAsset></td>	
										</tr>
										<tr>
										    <td ><span class='style1'>Asset Credit </span></td>	
											<td><input type='text' name='assetcrdt' id='assetcrdt' value='$assetcrdt' style='width:160px;' $disAsset>
												<img src='img/btnopen.jpg' title='Select Ledger' height=17 width=15 onMouseOver=\"style.cursor='hand'\" onclick=\"openLedgerList('20');\">	
											</td>
                                            <td ><span class='style1'>Asset Debit </span></td>	
											<td><input type='text' name='assetdbt' id='assetdbt' value='$assetdbt' style='width:160px;' $disAsset>
												<img src='img/btnopen.jpg' title='Select Ledger' height=17 width=15 onMouseOver=\"style.cursor='hand'\" onclick=\"openLedgerList('21');\">	
											</td>	
 											<td><span class='style1'>Asset Sequence </span></td><td> <input type='text' name='assetseq' id='assetseq' value='$assetseq' style='width:150px;' $disAsset></td>
										</tr>
									</table></td></tr>";							
echo "									</table>
								</td>
							</tr>";
							//table fetch
							//table fetch
echo "						<tr>
								<td  valign='top'>
									<table style='width:1100px;' border='0' cellspacing=0>
										<col width=100>
										<col width=150>
										<tr>
											<td style='width:1100px;height:15px;' colspan='4'></td>
										</tr>
										<tr>
											<td  valign='top' colspan=3 id='search-content' style='width:1100px;'>
												<table style='width:380px;' border='0' cellspacing=0>
													<col width=30>
													<col width=80>
													<col width=140>
													<col width=130>
													<tr height='30px' style='background-color:darkgray;'>
														<td>&nbsp;</td>
														<td align='center'><span class='style1'><b>".$Code1."</b></td>
														<td align='center'><span class='style1'><b>".$Name1."</b></td>
														<td align='center'><span class='style1'><b>".$Type."</b></td>
													</tr>
													<tr>
														<td colspan=4>";
															//<div style='overflow-y:scroll;height:250px;width:1100px;border:0px solid #000000;padding-left:5px;'>
															echo"	<table  border='0' width='1100px'>
																	<col width=30>
																	<col width=80>
																	<col width=140>
																	<col width=112>";
	
																	$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
																	//$resultsearch=mysql_query($querysearch,$connection) or die(mysql_error());	
																	while($rows=mysql_fetch_array($resultsearch)){
																		$ct+=1;
																		$stylefont='style15';
																		if($ct%2==0)
																			$Color="style='background-color:".$grid_color1."'";
																		else			
																			$Color="style='background-color:".$grid_color2."'";	
																				
																		if($actionmode=='edit' && $ledger_numberPrv==$rows[0]){
																			//echo$ledger_number.'  '.$rows[0];
																			$Color="style='background-color:#1e87a5'";
																			$stylefont='style28';
																		}	
		
																echo'<tr '.$Color.' height="20px" >';
	
																		if($FA_Ledger_Del==1)	
print<<<HERE
																		<td align=center ><img border='0' src='img/c_delete.png' width='9' height='10' title='Delete Detail' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$rows[0]')" $DelMode></td>
HERE;
else print<<<HERE
																		<td align=center >&nbsp;</td>
HERE;
echo"																	<td style='cursor:pointer;' ";if($FA_Ledger_Mod==1) echo " onclick=SetLedger('$rows[0]');";echo"><span class='$stylefont' >$rows[0]&nbsp;</span></font></td>
																		<td style='cursor:pointer;' ";if($FA_Ledger_Mod==1) echo " onclick=SetLedger('$rows[0]');";echo"><font face='Arial' size='2' color='#186194'><span class='$stylefont'>$rows[1]&nbsp;</span></font></td>";
echo"																	<td style='cursor:pointer;'><span class='style15' >$rows[2]</span></td>
																	</tr>";
																	}		
echo"															</table>";
														//	</div>
echo "													</td>
													</tr>
											</table>
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>";	
/*		
echo"<table border=0 align=center width=100%> <tr bgcolor=#D8D8D8 height='35'> ";
echo"	<td align=center><input type='button'  value='Add Ledger'";  	
	if($actionmode=='insert' or $actionmode=='edit')
		echo "disabled ";
	echo"onclick='AddLedger()' $style title='Add Ledger'  '".$AddMode."'>";
				
echo" <input type='button' id='btnClear' name='BtnClear' value='Clear Page'   onclick='ClearPage();' $style title='Clear Page'>";

if($actionmode=='view'){
	echo"           <input type='button' name='btnEdit' id='btnEdit' value='Edit' ";//Edit
	echo" onclick='editmode();' $style	title='Edit Ledger' />";
}
else	{
echo"           <input type='button' name='btnPost' id='btnPost' value='Save' ";//post
				if ($actionmode=='')
						echo " disabled ";
				
				echo" onclick='SubmitRecord();' $style	title='Save Changes' />";}

/*echo"           <input name='btnSearch' type='button' id='btnSearch' value='Search' onclick='SearchForLedger();' $style title='Search Ledger' ";
                if ($actionmode=='edit' or $actionmode=='insert') 
				    echo " disabled ";
		        echo " />*/
		/*		
echo"&nbsp;<input  type='button'  value='Print' onclick='PrintPreview();' $style title='Print' ";
if ($actionmode!='') 
	echo " disabled ";
		        echo " />			
</td>";
echo"  </tr></table>";*/
		  
 echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";
include("footer.php");	
print <<< HERE
			</td>
		</tr>
	</table>
HERE;

if($checkcode=='1'){
	$ledger_number=trim($ledger_number);
	$ledger_numberPrv=trim($ledger_numberPrv);
	
	if($actionmode=='insert' || ($actionmode=='edit' && $ledger_number!=$ledger_numberPrv)){
		$query_ledger="select count(*) from ledger where ledger_number=".$ledger_number;
		$result=mysql_query($query_ledger, $connection);
		$row_code=mysql_fetch_row($result);
		$num=$row_code[0];
	
	}
	else $num=0;
	if($num>0){
		$message="Code Already exists";
		
		echo"<script type='text/javascript'>";
		echo"	document.ledger.message.value='Code Already Exists';";
		echo"	document.ledger.checkcode.value='0';";
		echo"	document.ledger.submit();";	
		echo"</script>";
		
	}

	else{

		echo"<script type='text/javascript'>";
		echo"	document.ledger.action='Form_Ledger_Actions.php';";
		echo"	document.ledger.submit();";
		echo"</script>";
			
	}

}

if($pageclear == 1){
	echo"<script type='text/javascript'> ";
	echo"	ClearPage(); ";
	echo"</script>";
}
function explode_word($date)
{
	$trim = explode('-',$date);
	$trim = substr($trim[2],0,2) . "/" . "$trim[1]" . "/" . "$trim[0]";
	return $trim;
}

function get_acctype($connection)
{	$query_acc = "select Acctype_increment,Acctype_name from acctype";
	$result_acc=mysql_query($query_acc, $connection);
	return $result_acc;
}
print <<<HERE
</form>
</body>

HERE;

?>
