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

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('".$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");

$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];
	
	
	
$querylog="SELECT FI_Purchases as loginaccess 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");

$query_login="select login_belongstogrp,ifNull(FA_LedgerDel,0),ifNull(FA_LedgerMod,0) from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['useraccount']."' and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['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];


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

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

///// query for Access
$query_login="select ifNull(FA_LedgerApp,0)from ".$HTTP_SESSION_VARS['dbLabel'].".login where user_account='".$HTTP_SESSION_VARS['useraccount']."' and Upper(Login_Schema) = Upper('".$HTTP_SESSION_VARS['dbName']."')  ";

//echo $query_login;
$resultlogin=mysql_query($query_login,$connection) or die(mysql_error());

$row_login=mysql_fetch_row($resultlogin);
$FA_Ledger_App=$row_login[0];

$AddMode='';

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

function get_acctype($connection)
{	$query_acc = "select Acctype_increment,Acctype_name from acctype";
	$result_acc=mysql_query($query_acc, $connection);
	return $result_acc;
}
	$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
				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];

	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>
<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='';
	 
}
	
	
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 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';
		document.ledger.submit();
	}	
}

function SetLedger(LedgerNumber){
	//alert(LedgerNumber);
	document.ledger.ledger_number.value=LedgerNumber;
	document.ledger.message.value='';
	document.ledger.actionmode.value='editmode';
	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();
}

</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Ledger</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'>LEDGER</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='38'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px'>";
echo"		<button type='button' id='btnClear' name='btnClear' onclick='ClearPage(); return false;' title='Clear Page'><span><span>Clear Page</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='SubmitRecord($module_autoledger); return false;' title='Save Changes' $Insmode><span><span>Save</span></span></button>
<button  type='button'  value='Print' onclick='PrintPreview();return false;' title='print' ";


echo"><span><span>Print</span></span></button>

		
</td><td align='left' width='260px'>
	<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>Results/page</b></span>
	 <span class='style1'><select name='perpage' id='perpage' value='$perpage' onchange=set_limit();>";
	 
	if ($startrange=='')
		$startrange = 0;
	if ($perpage=='')
		$perpage = 20;
		
	for($i=10;$i<=$maxperpage;$i=$i+10){
		if($i==$perpage)
			echo "<option value='$i'  selected>$i</option>";
		else echo "<option value='$i'>$i</option>";
		
	} 
	 
			
echo"   </td></tr>";
echo"	</table>";
echo"</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=100% class='tablecontent'>
	<col width=65%>";
		
	echo"   <tr bgcolor='#F7F7F7'>";
	echo"   <td valign='top'><table style='table-layout:fixed' align='left' valign='top'  border=0>
		<col width=170>
		<col width=160>
		<col width=80>
	
		";
		 
if($module_autoledger=='1'){
 echo" <tr bgcolor='#F7F7F7' height='25'>
		<td valign='center' align='left' bgcolor='#F7F7F7'><span class='style1'>Ledger Group</span>";
	 echo"<span class='style26'></span>";
	 echo"</td>";
	echo"<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>";
	
	echo"</tr>";} else {
	echo"<input type='hidden' name='ledger_group' value='".$ledger_group."' m >";
	}
	
 echo" <tr bgcolor='#F7F7F7' height='25'>
		<td valign='center' align='left' bgcolor='#F7F7F7'><span class='style1'>Number/Name</span>";
	 echo"<span class='style26'>*</span>";
	 echo"</td>";
	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 colspan=2 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='center' ><span class='style1'><b>Type</b></span></td>";
	echo"</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  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"</td><input type='hidden' name='ledger_activity' value='$ledger_activity'></select>";
			echo" <td align='center'> <span class='style1'>Type</span></td><td align=left ><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>";	
			echo"<td rowspan=4 valign=top   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>
			<br>
			&nbsp;&nbsp;&nbsp;<input type=radio name='ledgertype' $dis value='1'";
						 
		if($ledgertype=='1')
			echo"checked ";
		echo" ><span class='style1'> Clients</span>
			<br>
			&nbsp;&nbsp;&nbsp;<input type=radio value='2' $dis name='ledgertype'";
						
		if($ledgertype=='2')
			echo"checked ";
		echo"><span class='style1'> Suppliers</span>
			<br>&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>";
								
			
		echo"<tr bgcolor='#F7F7F7'><td align=left  bgcolor='#F7F7F7'><span class='style1'>Ledger inactive Date</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'>";
		
		echo"</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='right' bgcolor='#F7F7F7' height='25' colspan=1><span class='style1'>Currency</span>";
		echo"<span class='style26'>* &nbsp;</span>";
	 
	 echo"</td><td  bgcolor='#F7F7F7' height='25' align='left'><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'></td>";
	echo"";
	echo"</tr>";
					
	echo"<tr bgcolor='#F7F7F7' height='25'>
          <td valign='center' align='left' ><span class='style1'>Co-Number / Name</span>";
	echo"</td>
	<td align='left'><input type='text' name='ledger_number2' value='".htmlspecialchars($ledger_number2, ENT_QUOTES)."' maxlength='10' style='font-size:12px; width:120px; height:18px;' $status />";
			
	echo"</td><td colspan='2' align='left'><input type='text' name='ledger_name2' value='".htmlspecialchars($ledger_name2, ENT_QUOTES)."' maxlength='50' style='font-size:12px; width:220px; height:18px;' $status /></td>";
	
	echo"</tr>";										

echo"<tr bgcolor='#F7F7F7'><td align='left'><span class='style1'>CashType Code</span></td><td align='left'><input type='text' name='cashtype_code' value='".htmlspecialchars($cashtype_code, ENT_QUOTES)."'  style='font-size:12px; width:120px; 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  colspan='2' align='left'><input type='text' name='cashtype_description' value='".htmlspecialchars($cashtype_description, ENT_QUOTES)."' style='font-size:12px; width:220px; height:18px;'  readonly /></td>
	</tr>";
		
echo"	<tr bgcolor='#F7F7F7' height='25'> <td align='left' bgcolor='#F7F7F7' height='25'><span class='style1'>Project Code/Name</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:120px; 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  colspan=2 align=left><input type=text name='project_name' value='$project_name' maxlength='20' $status readonly size='24' style='font-size:12px; width:220px; 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><input type=checkbox name='grpdet' onclick='changegrpdet()'  $dis $typestatus $checkedgrp>";
	echo"<input type='hidden' name='ledger_grpdet' value='$ledger_grpdet'><span class='style1'> Group</span>&nbsp&nbsp;</td></tr>";
	
	
echo"	<tr bgcolor='#F7F7F7' height='25'><td align='left' bgcolor='#F7F7F7' height='25'><span class='style1'>CostCenter Code/Name</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:120px; 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  colspan=2 align=left><input type=text name='costcenter_name' value='$costcenter_name' maxlength='20' $status readonly size='24' style='font-size:12px; width:220px; 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>";
	
	echo"<td><input type=checkbox name='notrequired' onclick='changerequired()'  $dis $selectedrequired><span class='style1'> Require Detail &nbsp;&nbsp;</span>
		<input type='hidden' name='ledger_requireddetail' value='$ledger_requireddetail'><br>
		<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'><br>
		<input type='text' name='ledger_length' id='ledger_length' value='$ledger_length' style='width:25px'><span class='style1'>&nbsp;Length</span>
		 
		</td>
		
		</tr>";
		
	echo"<tr bgcolor='#F7F7F7' height='25'>
        <td valign='center' align='left' ><span class='style1'>Document</span></td>
	    <td colspan='4' align='left'>
		<input type='text' name='document' value='".htmlspecialchars($document, ENT_QUOTES)."' maxlength='30' style='font-size:12px; width:490px; height:18px;'  $status /></td></tr>";
		
echo"<tr bgcolor='#F7F7F7' height='100'><td rowspan=2><span class='style1'><span class='style1'>Description</span></td>
	<td colspan=4 align='left'><textarea name='ledger_description'  size=100% cols=59 rows=4 maxlength='100' $status >".htmlspecialchars($ledger_description, ENT_QUOTES)."</textarea></td>
		</tr>
	</table>";

	
echo"</td><td  valign='top'> ";
	echo"<table style='width:380px;' border='0' cellspacing=0><col width=100><col width=150>
	<tr><td id='search-top' style='width:380px;height:15px;' colspan='4'></td>
	</tr>
	 <tr><td  valign='top' colspan=3 id='search-content' style='width:380px;'><table style='width:380px;' border='0' cellspacing=0><col width=30><col width=80><col width=140><col width=130>
	<tr height='30px'><td>&nbsp;</td>
	<td align='center'><span class='style1'><b>Code</b></td><td align='center'><span class='style1'><b>Name</b></td><td align='center'><span class='style1'><b>Type</b></td></tr>";
	 
	echo"<tr><td colspan=4 id='search-content'><div style='overflow-y:scroll;height:250px;width:370px;border:0px solid #000000;padding-left:5px;'><table  border='0' width='352px'><col width=30><col width=80><col width=140><col width=112>
	";
	
	$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);
	

	
	$querysearch = $querysearch." limit ".$startrange.",".$perpage;
	//echo$querysearch;
	$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>";
	

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

echo"<tr ><td >&nbsp;</td><td align='right'>";
		
		$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='right'>";
		
		
		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>&nbsp;</td></tr>";



echo"</table></td></tr><tr>
					<td id='search-bottom' style='width:380px;height:20px;' colspan='4'></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>";
			
	}

}


print <<<HERE
</form>
</body>

HERE;

?>
