Location: PHPKode > scripts > Simple Accounting System > SimpleAccounts/index.php
<?php
session_start();
include_once "member.php";
include_once 'lib.dbconnect.php';
//mysql_select_db($_SESSION['database']);
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Simple Accounting System</title>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<link rel="stylesheet" type="text/css" href="lib.global.css"/>

<!-- Backed up while updating the Date validation -->

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

//var urlPath="http://localhost/SimpleAccounts/";
var urlPath="";
var accountNames = new Array();

function postAction(isShowLedger) {
	
	// Change the day Book Format while sending it to the storage.
	var dayBookDate   = document.getElementById("dayBookDate").value;
	var dayBookDateTo = document.getElementById("dayBookDateTo").value;


	if(dayBookDate != "") 	dayBookDate = convertDateFormat(dayBookDate,"dd-mm-yyyy","yyyy-mm-dd");
	if(dayBookDateTo != "") dayBookDateTo = convertDateFormat(dayBookDateTo,"dd-mm-yyyy","yyyy-mm-dd");

	//alert(dayBookDateTo);
	
	// Do not change the order GET string series dayBookDate should follow dayBookDateTo and not viceversa.	
	var postStr = "dayBookDate=" + encodeURI( dayBookDate ) +
					"&dayBookDateTo=" + encodeURI( dayBookDateTo ) +
                    "&debit=" + encodeURI( document.getElementById("completefield").value ) + 
					"&credit=" + encodeURI( document.getElementById("completefield_1").value ) + 
					"&dayBookContra=" + encodeURI( document.getElementById("dayBookContra").value ) + 
					"&dayBookAmount=" + encodeURI( document.getElementById("dayBookAmount").value ) + 
					"&description=" + encodeURI( document.getElementById("description").value ) + 
					"&isShowLedger=" + encodeURI( isShowLedger )  

	//  http_request.send(parameters);
	
	//alert(postStr);
	
	var url= urlPath+"postAction.php?"+postStr;	                

	req.onreadystatechange = receiveUpdatedDayBookPosition;
	req.open("GET", url, true);   
	//req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    //req.setRequestHeader("Content-length", postStr.length);
    //req.setRequestHeader("Connection", "close");
	req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	req.send(null);
}


// postActionGroupName is a function to display the group wise results of ledgers.
// showType == "showGroup" displays GROUP data, it uses groupName as input.
// showType == "showLedger" displays LEDGER data, it uses debit as input.
function postActionGroupName(groupName,showType){
	//alert ("Show Type"+showType);
	// Change the day Book Format while sending it to the storage.
	var dayBookDate   = document.getElementById("dayBookDate").value;
	var dayBookDateTo = document.getElementById("dayBookDateTo").value;
	if(dayBookDate != "") 	dayBookDate = convertDateFormat(dayBookDate,"dd-mm-yyyy","yyyy-mm-dd");
	if(dayBookDateTo != "") dayBookDateTo = convertDateFormat(dayBookDateTo,"dd-mm-yyyy","yyyy-mm-dd");

	var postStr = "dayBookDate=" + encodeURI( dayBookDate ) +
					"&dayBookDateTo=" + encodeURI( dayBookDateTo ) +
					"&debit=" + encodeURI( groupName ) +
                    "&groupName=" + encodeURI( groupName ) + 
					"&isShowLedger=" + showType;
	
	var url= urlPath+"postAction.php?"+postStr;	                

	req.onreadystatechange = receiveUpdatedDayBookPosition;
	req.open("GET", url, true);   
	//req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    //req.setRequestHeader("Content-length", postStr.length);
    //req.setRequestHeader("Connection", "close");
	req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	req.send(null);
	
}


function receiveUpdatedDayBookPosition() {
	if (req.readyState == 4) {	
		if (req.status == 200) {	
			receiveUpdatedStatus();
		} else {
            alert('There was a problem with the request. Please try again.');
		}
	} else {		
		document.getElementById('displayDayBookEntries').innerHTML = " Loading ... ";
	}
}

function receiveUpdatedStatus() {
	//alert(http_request.responseText);
	//alert("Inside receive Updated Status");
	//alert(req.responseText);
	//alert(req.responseText);
	var displayDayBookEntries = document.getElementById("displayDayBookEntries");
	var popup = document.getElementById("popup");
	displayDayBookEntries.innerHTML = req.responseText;
	popup.innerHTML = "<a href=\"javascript:printPopup(\'<?php echo $companyname; ?>\')\">Popup to Print</a>";
	req.abort();
}

// callXML will accept two paramaters 1. NameofSelectBox 2. completeFieldChosen 
// NameofSelectBox is the current select box chosen.
// completeFieldChosen is the current text box for which the auto completion must be done.


function callXML(NameofSelectBox, completeFieldChosen) {  
	NameofSelect = NameofSelectBox;	
	completeFieldFocussed = completeFieldChosen;
	var cf = document.getElementById(completeFieldChosen);
	if (cf.value != ""){
		if(document.getElementById(NameofSelect).style.display != "none") {
			if (document.getElementById(NameofSelect).options.length > 0) {
				document.getElementById(NameofSelect).options.length = 0;
			}
		}
		for(var i=0 ; i < accountNames.length ; i++) {
			//alert(accountNames[i].substr(0,cf.value.length));
			//alert(cf.value);			
			if( (cf.value.toUpperCase()) == (accountNames[i].substr(0,cf.value.length)) ){
				var select1 = document.getElementById(NameofSelect);
				var namefield = document.createElement("OPTION");
				namefield.innerText = accountNames[i];
				namefield.Value = accountNames[i];
				select1.appendChild(namefield);
			}
		}	
	} else {
		if(document.getElementById(NameofSelect).style.display != "none") {
			if (document.getElementById(NameofSelect).options.length > 0) {
				document.getElementById(NameofSelect).options.length = 0;
			}
		}
		for(var i=0 ; i < accountNames.length ; i++) {
			var select1 = document.getElementById(NameofSelect);
			var namefield = document.createElement("OPTION");
			namefield.innerText = accountNames[i];
			namefield.Value = accountNames[i];
			select1.appendChild(namefield);
		}
	}
	//var url= "ac.xml?action=asf";	
	//req.onreadystatechange = processRequest;    
	//req.open("GET", url, true);   
	//req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	//req.send(null);
}

// ProcessRequest is called by callXML function once it get response from the url.
function processRequest() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			parseMessages();		
		} else {
		    
			alert('Not able to process message'); 
		}
	} else {		
		document.getElementById('displayDayBookEntries').innerHTML = " Loading ... ";
	}
}

function parseMessages() {
	//alert("insdie parse Messages");
	//alert(req.responseText);
	var employees = null;
	//alert(req.responseText);
	var employees=req.responseXML.getElementsByTagName("account");
	//alert(employees.length);
	for (loop = 0; loop < employees.length; loop++) {
		var accountName  = employees[loop].getElementsByTagName("accountname");
		//alert(accountName);
		//var lastName   = employees[loop].getElementsByTagName("last-name");
		//var employeeId = employees[loop].getElementsByTagName("id");
	
		var completefield = document.getElementById(completeFieldFocussed);
		var str = completefield.value;
		var firstNameText = accountName[0].childNodes[0].nodeValue;			
		firstNameText = firstNameText.toString();
		firstNameText = firstNameText.toUpperCase();
		var obtained_str = firstNameText.substring(0,str.length);
		obtained_str = obtained_str.toString();
		obtained_str = obtained_str.toUpperCase();
		str = str.toString();
		str = str.toUpperCase();
		//alert("STR : "+str+" \n First Name Text :" + firstNameText + " \n Obtained String : "+obtained_str);
		if ((str > obtained_str)||(str < obtained_str))
		{
					
		} else {
				appendAccounts(accountName[0].childNodes[0].nodeValue, loop);				
		}
	} 
	req.abort();
}

function appendAccounts(accountName, loop) {
	 var div_tag = document.getElementById(NameofSelect);
	 var namefield = document.createElement("OPTION");
	 namefield.innerText = accountName;
	 namefield.Value = accountName;
	 div_tag.appendChild(namefield);
}

function hideDiv(NameofSelectBox) {
	//alert(NameofSelect)
	var div_tag = document.getElementById(NameofSelectBox);
	div_tag.style.display = "none";
}

function hidePoll(NameofSelectBox) {
	//var	callFucntion = "hideDiv('"+NameofSelectBox+"')"
	//glbTmr = setTimeout("hideDiv('"+NameofSelectBox+"')",300);
	hideDiv(NameofSelectBox);
	//alert ('inside hidePoll'+NameofSelectBox);
}

function stopHide(NameofSelectBox) {
	clearTimeout(glbTmr);
	var div_tag = document.getElementById(NameofSelectBox);
	div_tag.style.display = "block";	
}

function displayDivTag(NameofSelectBox,completeFieldChosen) {
	//alert(NameofSelectBox);

	var div_tag = document.getElementById(NameofSelectBox);
	div_tag.style.display = "block";
	completeFieldFocussed = completeFieldChosen;
	callXML(NameofSelectBox,completeFieldChosen);
}

function controlCalendar1() {
	var calendar = document.getElementById('cal1Container');
	if (!calendar.focused) {		
		hideDiv('cal1Container');
	}	
}

function controlCalendar2() {
	var calendar = document.getElementById('cal2Container');
	if (!calendar.focused) {		
		hideDiv('cal2Container');
	}	
}


function getHTTPObject() {
var xmlhttp;
		if (window.ActiveXObject) {
			// ...otherwise, use the ActiveX control for IE5.x and IE6			
			  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			  return xmlhttp;
		}
		if (window.XMLHttpRequest) {
			 // If IE7, Mozilla, Safari, etc: Use native object
			  xmlhttp = new XMLHttpRequest()
			  xmlhttp.overrideMimeType("text/xml"); 
			  return xmlhttp;
		}
}

var displayAccountName;
function showAccountDetails(accountName) {
	displayAccountName = accountName;
	var postStr = "accountName=" + encodeURI(accountName)
	url = "ac.php"
	//  http_request.send(parameters);
	//alert(postStr);
	//var url= urlPath+"showAccountName.php?"+postStr;	
        //url = urlPath+"ac.xml";
	req.onreadystatechange = receiveAccountDetailsPosition;
	req.open("GET", url, true);   
	//req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    //req.setRequestHeader("Content-length", postStr.length);
    //req.setRequestHeader("Connection", "close");
	req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	req.send(null);
}

function receiveAccountDetailsPosition() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			receiveAccountDetails(displayAccountName);
		} else {
            alert('There was a problem with the request while getting the Account Details.');
		}
	} else {		
		document.getElementById('displayDayBookEntries').innerHTML = " Loading ... ";
	}
}

function receiveAccountDetails(displayAccountName) {
	//alert("insdie parseMessages");
	//alert(req.responseText);
	var employees = null;
	var employees=req.responseXML.getElementsByTagName("account");
	//alert(employees.length);
	for (loop = 0; loop < employees.length; loop++) {
		var accountName  = employees[loop].getElementsByTagName("accountname");
		accountName = accountName[0].firstChild.nodeValue;
		//alert(employees[loop].childNodes.length);
		if(displayAccountName == accountName){
			//alert(employees[loop].childNodes.length);
			var addAccountDetails = "";
			for (i = 0;i < employees[loop].childNodes.length;i++)
			{
				if(employees[loop].childNodes[i].text != "") {
					addAccountDetails += employees[loop].childNodes[i].nodeName+":"+employees[loop].childNodes[i].text+"<br>"
				}
			}
			//alert(addAccountDetails);
			//document.getElementById('displayAccountDetails').innerHTML = "<h2> Account Particulars </h2>";
			//document.getElementById('displayAccountDetails').innerHTML += addAccountDetails;

		}
	} 
	req.abort();
}


function selectValue(selectBox,nameOfTextbox) {		
	var completefield = document.getElementById(nameOfTextbox);
	//showAccountDetails(selectBox.options[selectBox.selectedIndex].text);
	if (selectBox.selectedIndex != "-1"){
		completefield.value = selectBox.options[selectBox.selectedIndex].text;
	}
}	

function textUpAction(selectBox,nameOfTextBox){
	var completefield = document.getElementById(nameOfTextBox);
	//var completefield = document.getElementById(nameOfTextbox);
	//showAccountDetails(selectBox.options[selectBox.selectedIndex].text);
	//completefield.value = selectBox.options[selectBox.selectedIndex].text;
	var selectBox = document.getElementById(selectBox);	
	//alert(selectBox.selectedIndex);
	if(selectBox.selectedIndex == -1){
		selectBox.selectedIndex = 1;
	}
	if(selectBox.selectedIndex > 1) {
		selectBox.selectedIndex = selectBox.selectedIndex-1;
	}
	completefield.value = selectBox.options[selectBox.selectedIndex].text;
}

function textDownAction(selectBox, nameOfTextBox){
	var completefield = document.getElementById(nameOfTextBox);
	//alert(selectBox.length);	
	if(selectBox.selectedIndex < (selectBox.length-1)) {
		selectBox.selectedIndex = selectBox.selectedIndex+1;
	}
        if(selectBox.selectedIndex != null){
	  completefield.value = selectBox.options[selectBox.selectedIndex].text;
	}
	//completefield.value = selectBox.options[selectBox.selectedIndex].text;
}

function validateButton(validateWhat) {
	var dayBookDate = document.getElementById('dayBookDate').value;
	var dayBookDateTo = document.getElementById('dayBookDateTo').value;
	var debit = document.getElementById('completefield').value;
	var credit = 	document.getElementById('completefield_1').value;
	var dayBookContra = document.getElementById('dayBookContra').value;
	var dayBookAmount = document.getElementById('dayBookAmount').value;
	var description = document.getElementById('description').value;

	switch (validateWhat)
	{
	case "saveDayBook": 
		if(!validateDate(dayBookDate)) {
			alert("Please Correct the Date format");
			return false;
		}
		if(dayBookDate == "" || 
		   debit == "" || 
		   credit == "" ||
		   dayBookContra == "" ||
		   dayBookAmount == "" || 
		   description == "")
		{
			alert("Please Submit all the values to save the form");
			return false;
		}
		
		
		if(debit == credit){
			alert("Debit and Credit cannot be same.");
			return false;
		} else {
			postAction(validateWhat);
		}
	break

	case "searchDayBook" : 
	 
	 if(!validateBothDates(dayBookDate,dayBookDateTo)){
		return false;
		break
	 }
	

		if(dayBookDate == "" &&
		   dayBookDateTo == "" &&	
		   debit == "" && 
		   credit == "" &&
		   dayBookContra == "" &&
		   dayBookAmount == "" && 
		   description == "")
		{
			alert("Please Enter Dates or any one of the Other values");
			return false;
		} else {
			postAction(validateWhat);
		}
	break

	case "showLedger":
		 if(!validateBothDates(dayBookDate,dayBookDateTo)){		 		
			return false;
			break
		 }

		if(debit == "") {
			alert("Please Enter Ledger Name");
			return false;
		} else {
			postAction(validateWhat);
		}
	break

	case "showTrialBalance":
		if(!validateBothDates(dayBookDate,dayBookDateTo)){				
			return false;
			break
		 }
		 postAction(validateWhat);
	break
	
	case "showBalanceSheet": 
		if(!validateBothDates(dayBookDate,dayBookDateTo)){
			return false;
			break;
		}
		postAction(validateWhat);
	break
	}
}

function selectKeyPress(event, thisItem,fieldName){
	var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if(Key == 13){
		selectValue(thisItem,fieldName);
		thisItem.blur(); 
	}
}

function completeFieldKeyUp(event,fieldName){
	var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if(Key == '38'){
		textUpAction('divautocomp',fieldName)
	} 
	if (Key == '40'){
		textDownAction('divautocomp',fieldName)
	}
}

function validateNumberForDate(event) {
	var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if ((Key >= 48 && Key <= 57) || Key == 45 || Key == 8 || Key == 46)
	{	
		return true;
	} else {
		alert("Please make sure entries are numbers and hyphen only");
		return false;
	}
	//alert(window.event.keyCode);
}

function validateNumberForAmount(event) {	
	var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	
	if ((Key >= 48 && Key <= 57) || Key == 8 || Key == 46)
	{	
		return true;
	} else {
		alert("Please make sure entries are numbers Only");
		return false;
	}
	//alert(window.event.keyCode); 
}

function validateDate(str)
{
	// Format Match 
	var reg = /^[0-9]{2}-[0-9]{2}-[0-9]{4}$/
	if (!(str.match(reg)))
	{
		//alert("Not a valid Date format. Please specify in : dd-mm-yyyy (day-month-year) format using hyphen as a delimiter");				
		return false;	
	}
	var date_array = str.split("-");	
	// date_array[0] is the day of variable "str" date
	// date_array[1] is the month of variable "str" date
	// date_array[2] is the year of variable "str" date
	if(date_array[0] == "00" || date_array[1] == "00" || date_array[2] == "0000" ){
		alert("Not a valid Date. Please enter valid Date. 0's are not valid date");
		return false; 
	}

	// initialize the variable is_leap_year to no.
	var is_leap_year = "no";
	if((date_array[2] % 4) == 0) {
		if((date_array[2] % 100) == 0 ) {
			if((date_array[2] % 400) == 0) {
				is_leap_year = "yes";
			} else {
				is_leap_year = "no";
			}
		} else {
			is_leap_year = "yes";
		}
	}

	//alert(is_leap_year);
	// If it is leap year then check the february month.	
	if(date_array[1] == "02") {
		if(is_leap_year == "yes") {
			//alert("Feb month with max of 29 days");	
			reg = /[012][0-9]\-02\-[0-9]{4}/			
		} else {
			//alert("Feb month with max of 28 days");
			reg = /[012][0-8]\-02\-[0-9]{4}/
		}
	} else {
		reg = /(([012][0-9]|30|31)\-(01|03|05|07|08|10|12)\-([0-9]{4}))|(([012][0-9]|30)\-(02|04|06|09|11)\-([0-9]{4}))/
	}

	//alert(reg);
	
	var assign_var;
	assign_var = reg.test(str);	
	if (assign_var) {
	  //alert("Valid Date Format");	
	  return true;
	} else {
	  //alert("Invalid Date Format");
	  return false;
	}
}
// End of validateDate

function populateTodayDate() {
	 var dt = new Date();
	 todayDate = dt.getDate();
	 todayMonth = dt.getMonth()+1;
	 
	 if (todayDate  < 10) todayDate = "0"+todayDate;
	 if (todayMonth < 10) todayMonth = "0"+todayMonth;

	 var date_string = todayDate+"-"+todayMonth+"-"+dt.getFullYear();
	 document.getElementById('dayBookDate').value = date_string;
}

function populateAccountNames() {	
	var url= "ac.php";	
	req.onreadystatechange = populateAcNames;    
	req.open("GET", url, true);   
	req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	req.send(null);
}
function populateAcNames() { // Follow up PopulateAccountNames()   
	if (req.readyState == 4) {
		if (req.status == 200) {		    
			populateAccNames();		
			document.getElementById('displayDayBookEntries').innerHTML = "";
		} else {
			//alert ('inside ac names');
			alert('Not able to process message'); 
		}
	} else {		
		document.getElementById('displayDayBookEntries').innerHTML = " Loading ... ";
	}
}
function populateAccNames() {	// Follow up PopulateAccountNames()	
	var employees = null;
	//alert(req);
	var employees=req.responseXML.getElementsByTagName("account");
	//alert(employees.length);
	for (loop = 0; loop < employees.length; loop++) {
		var accountName  = employees[loop].getElementsByTagName("accountname");
		//alert(accountName);
		//var lastName   = employees[loop].getElementsByTagName("last-name");
		//var employeeId = employees[loop].getElementsByTagName("id");
	
		var firstNameText = accountName[0].childNodes[0].nodeValue;	
			//alert (firstNameText);
		firstNameText = firstNameText.toString();
		firstNameText = firstNameText.toUpperCase();		

		accountNames.push(firstNameText);
		//alert(accountNames.length);
				
		var select1 = document.getElementById('divautocomp');
		var select2 = document.getElementById('divautocomp_1');
		
		var namefield = document.createElement("OPTION");
		namefield.innerHTML = firstNameText;
		namefield.Value = firstNameText;
		select1.appendChild(namefield);
		
		var namefield1 = document.createElement("OPTION");
		namefield1.innerHTML = firstNameText;
		namefield1.Value = firstNameText;
		select2.appendChild(namefield1);
		
	} 
	req.abort();
}

// library function
function convertDateFormat(dateValue, existingFormat, wantedFormat) {
	var date_array = dateValue.split("-");
	var existingFormat_array = existingFormat.split("-");
	var wantedFormat_array = wantedFormat.split("-");

	var standardDate_array = new Array();
	var convertedDate_array = new Array(3);
	var returnConvertedDateValue;
	
	for(var i = 0; i < existingFormat_array.length ; i++) {
		switch (existingFormat_array[i])
		{
			case "dd": standardDate_array[0] = 	date_array[i];	 break;
			case "mm": standardDate_array[1] = 	date_array[i];	 break;
			case "yyyy": standardDate_array[2] = date_array[i];  break;
		}
	}

	for(var i = 0; i < wantedFormat_array.length ; i++) {
		switch (wantedFormat_array[i])
		{
			case "dd": convertedDate_array[i] = standardDate_array[0];	break;
			case "mm": convertedDate_array[i] = standardDate_array[1];  break;
			case "yyyy": convertedDate_array[i] = standardDate_array[2]; break;
		}	
	}
	returnConvertedDate = convertedDate_array[0]+"-"+convertedDate_array[1]+"-"+convertedDate_array[2];
	return returnConvertedDate
}


var currentFinancialYearEnd = "";
var currentFinancialYearStart = "";

// Determine Current financial Year
function dcfy()
{
	var dt = new Date();
	todayDate = dt.getDate();
	todayMonth = dt.getMonth()+1;
	if(todayMonth < 4) {
		currentFinancialYearEnd = dt.getFullYear();
		currentFinancialYearStart = dt.getFullYear()-1;
	} else {
		currentFinancialYearEnd = dt.getFullYear()+1;
		currentFinancialYearStart = dt.getFullYear();
	}
}

function validateBothDates(dayBookDate,dayBookDateTo) {
	var dayBookFromDateEntered = false;
	var dayBookToDateEntered = false;
	var bothDatesEntered = false;
	if(dayBookDate != "") {
		dayBookFromDateEntered = true;
		if(dayBookDate != "" && (!validateDate(dayBookDate))){
			alert("Please correct \"From\" date format");
			return false;
		}
	}
	if(dayBookDateTo != "") {
		dayBookToDateEntered = true;
		if(dayBookDateTo != "" && (!validateDate(dayBookDateTo))){
			alert("Please correct \"To\" date format");
			return false;
		}
	}
	if(dayBookFromDateEntered == false &&  dayBookToDateEntered == false){
		bothDatesEntered = false;
		return true
	} else {
		if(dayBookFromDateEntered == true && dayBookToDateEntered == true) {
			bothDatesEntered = true;	
		} else {
			alert("Please Enter both the dates or do not Enter the Dates");
			return false;
		}
	}
	if(bothDatesEntered == true) {
		//alert('inside both dates');
		 var dt = new Date();
		 todayDate = dt.getDate();
		 todayMonth = dt.getMonth()+1;
		 if(todayMonth < 4) {
			currentFinancialYearEnd = dt.getFullYear();
			currentFinancialYearStart = dt.getFullYear()-1;
		 } else {
			currentFinancialYearEnd = dt.getFullYear()+1;
			currentFinancialYearStart = dt.getFullYear();
		 }
		 if (todayDate  < 10) todayDate = "0"+todayDate;
		 if (todayMonth < 10) todayMonth = "0"+todayMonth;
		 var date_string = todayDate+"-"+todayMonth+"-"+dt.getYear();
		 // document.getElementById('dayBookDate').value = date_string;
		 var dayBookDateArray = dayBookDate.split("-");
		 var dayBookDateToArray = dayBookDateTo.split("-");
		 // date_array[0] is the day of variable "str" date
		 // date_array[1] is the month of variable "str" date
		 // date_array[2] is the year of variable "str" date	
		 var dayBookDateObject = new Date(dayBookDateArray[2],dayBookDateArray[1],dayBookDateArray[0]);
		 var dayBookDateToObject = new Date(dayBookDateToArray[2],dayBookDateToArray[1],dayBookDateToArray[0]);
		 var currentFinancialYearEndObject = new Date(currentFinancialYearEnd,03,31);
		 var currentFinancialYearStartObject = new Date(currentFinancialYearStart,04,01);
		  //alert("From Date Time "+dayBookDateObject.getTime()+" \n To Date Time "+dayBookDateToObject.getTime());
		 dayBookDateTime = dayBookDateObject.getTime();
		 dayBookDateToTime = dayBookDateToObject.getTime();
		 currentFinancialYearStartTime =  	currentFinancialYearStartObject.getTime();
		 currentFinancialYearEndTime =  	currentFinancialYearEndObject.getTime();

			//alert("dayBookDateTime : "+dayBookDateTime+" \n dayBookDateToTime : "+dayBookDateToTime+" \n currentFinancialYearStartTime : "+currentFinancialYearStartTime+" \n currentFinancialYearEndTime : "+currentFinancialYearEndTime);
			
		  
		  /* if(dayBookDateTime < currentFinancialYearStartTime || dayBookDateTime > currentFinancialYearEndTime ||
			    dayBookDateToTime < currentFinancialYearStartTime || dayBookDateToTime > currentFinancialYearEndTime) {
					alert("Dates should fall in current financial Year");
					return false
		  }
		  */

		  if(dayBookDateObject.getTime() >  dayBookDateToObject.getTime()) {
				alert("From date cannot be greater than To date");
				return false;
		  }
		  return true;
	}
}		


var req = getHTTPObject(); // We create the HTTP Object
var totDisplayCount = 0; // Count of the total no of items displayed in the auto completion div tag
var trackCount = 0; // Track the count for arrow keys
var rollBackColorCount = 0; 
var glbTmr=0; // Timer to hide and show the select box / list box
var NameofSelect;
var completeFieldFocussed;


// Display Functions
function changeClassName(ithItem) {
	var legendTag = document.getElementById("legendTag");
	var countOfDivTag = legendTag.getElementsByTagName("div");
	//alert(countOfDivTag.length);
	for(i=1; i <= countOfDivTag.length ; i++) {
		if (ithItem == i){
			document.getElementById("legendLookTag"+i).className = "legendLookTagSel";
		}  else {
			document.getElementById("legendLookTag"+i).className = "legendLookTag";
		}
	}
}

function showSaveDayBook() {
	// Hide Items
	document.getElementById("dateRange").className = "hideDateRangeTag"; // TR
	document.getElementById("creditTr").className = "showCreditTr"; // TR	
	document.getElementById("contraTr").className = "showContraTr"; // TR
	document.getElementById("debitTr").className = "showDebitTr"; // Show
	document.getElementById("amountTr").className = "showAmountTr";
	document.getElementById("descriptionTr").className = "showDescriptionTr";
	document.getElementById("debitLabel").innerHTML = "Debit";
	// Hide Items
	document.getElementById("saveDayBookButton").className = "showSaveDayBookButton";
	document.getElementById("searchDayBookButton").className = "hideSearchDayBookButton";
	document.getElementById("viewLedgerButton").className = "hideViewLedgerButton";
	document.getElementById("viewTrialBalanceButton").className = "hideViewTrialBalanceButton";
	document.getElementById("viewBalanceSheetButton").className = "hideViewBalanceSheetButton";
	// div Items
	//document.getElementById("displayAccountDetails").className = "showDisplayAccountDetails";
	document.getElementById("displayDayBookEntries").innerHTML = "";	
}

function showSearchDayBook() {
	// Display Items
	document.getElementById("dateRange").className = "showDateRangeTag"; // TR
	document.getElementById("creditTr").className = "showCreditTr"; // TR	
	document.getElementById("contraTr").className = "showContraTr"; // TR
	document.getElementById("debitTr").className = "showDebitTr"; // Show
	document.getElementById("amountTr").className = "showAmountTr";
	document.getElementById("descriptionTr").className = "showDescriptionTr";
	document.getElementById("debitLabel").innerHTML = "Debit";
	// Hide Items
	document.getElementById("saveDayBookButton").className = "hideSaveDayBookButton";
	document.getElementById("searchDayBookButton").className = "showSearchDayBookButton";
	document.getElementById("viewLedgerButton").className = "hideViewLedgerButton";
	document.getElementById("viewTrialBalanceButton").className = "hideViewTrialBalanceButton";
	document.getElementById("viewBalanceSheetButton").className = "hideViewBalanceSheetButton";
	// div Items
	//document.getElementById("displayAccountDetails").className = "showDisplayAccountDetails";
	document.getElementById("displayDayBookEntries").innerHTML = "";
}

function viewLedger() {
	// Display Items
	document.getElementById("dateRange").className = "showDateRangeTag"; // Show
	document.getElementById("creditTr").className = "hideCreditTr";	
	document.getElementById("contraTr").className = "hideContraTr";
	document.getElementById("debitTr").className = "showDebitTr"; // Show	
	document.getElementById("amountTr").className = "hideAmountTr";
	document.getElementById("descriptionTr").className = "hideDescriptionTr";
	document.getElementById("debitLabel").innerHTML = "Ledger Account";
	// Display button Items
	document.getElementById("saveDayBookButton").className = "hideSaveDayBookButton";
	document.getElementById("searchDayBookButton").className = "hideSearchDayBookButton";
	document.getElementById("viewLedgerButton").className = "showViewLedgerButton";
	document.getElementById("viewTrialBalanceButton").className = "hideViewTrialBalanceButton";
	document.getElementById("viewBalanceSheetButton").className = "hideViewBalanceSheetButton";
	// Display div Items
	//document.getElementById("displayAccountDetails").className = "showDisplayAccountDetails";
	
	// Clear Items
	document.getElementById("debitTr").value = "";	
	//document.getElementById("displayAccountDetails").innerHTML = "<h2> Account Particulars </h2>";	
	document.getElementById("displayDayBookEntries").innerHTML = "";
	
}

function viewTrialBalance() {
	// Display Items
	document.getElementById("dateRange").className = "showDateRangeTag";
	document.getElementById("creditTr").className = "hideCreditTr";	
	document.getElementById("contraTr").className = "hideContraTr";
	document.getElementById("debitTr").className = "hideDebitTr";
	document.getElementById("amountTr").className = "hideAmountTr";
	document.getElementById("descriptionTr").className = "hideDescriptionTr";	
	// Hide Items
	document.getElementById("saveDayBookButton").className = "hideSaveDayBookButton";
	document.getElementById("searchDayBookButton").className = "hideSearchDayBookButton";
	document.getElementById("viewLedgerButton").className = "hideSearchDayBookButton";
	document.getElementById("viewTrialBalanceButton").className = "showViewTrialBalanceButton";
	document.getElementById("viewBalanceSheetButton").className = "hideViewBalanceSheetButton";
	// div Items
	//document.getElementById("displayAccountDetails").className = "hideDisplayAccountDetails";
	document.getElementById("displayDayBookEntries").innerHTML = "";
}

function viewBalanceSheet(){
	// Display Items
	document.getElementById("dateRange").className = "showDateRangeTag";
	document.getElementById("creditTr").className = "hideCreditTr";	
	document.getElementById("contraTr").className = "hideContraTr";
	document.getElementById("debitTr").className = "hideDebitTr";
	document.getElementById("amountTr").className = "hideAmountTr";
	document.getElementById("descriptionTr").className = "hideDescriptionTr";	
	// Hide Items
	document.getElementById("saveDayBookButton").className = "hideSaveDayBookButton";
	document.getElementById("searchDayBookButton").className = "hideSearchDayBookButton";
	document.getElementById("viewLedgerButton").className = "hideSearchDayBookButton";
	document.getElementById("viewTrialBalanceButton").className = "hideViewTrialBalanceButton";
	document.getElementById("viewBalanceSheetButton").className = "showViewBalanceSheetButton";
	// div Items
	//document.getElementById("displayAccountDetails").className = "hideDisplayAccountDetails";
	document.getElementById("displayDayBookEntries").innerHTML = "";
}

function printPopup(companyname){
	var displayDayBookEntries = "<html>";
	displayDayBookEntries += "<head>";
	displayDayBookEntries += '<link rel="stylesheet" type="text/css" href="lib.global.css"/>';
	displayDayBookEntries += "</head>";
	displayDayBookEntries += "<body>";
	displayDayBookEntries += "<h1>"+companyname+"</h1>";
	displayDayBookEntries += document.getElementById("displayDayBookEntries").innerHTML;
	displayDayBookEntries += "</body>";
	displayDayBookEntries += "</html>";	
	var popup = window.open();	
	popup.document.writeln(displayDayBookEntries);
}



function defaultDisplay() {
	populateTodayDate();
	changeClassName(1);
	showSaveDayBook();
}
</script>
<!--CSS file (default YUI Sam Skin) -->
<!-- <link rel="stylesheet" type="text/css" href="yui/build/calendar/assets/skins/sam/calendar.css"> -->
<link rel="stylesheet" type="text/css" href="yui/calendar.css">

<!-- Dependencies -->
<!-- <script type="text/javascript" src="yui/build/yahoo-dom-event/yahoo-dom-event.js"></script> -->
<script type="text/javascript" src="yui/yahoo-dom-event.js"></script>

<!-- Source file -->
<!-- <script type="text/javascript" src="yui/build/calendar/calendar-min.js"></script> -->
<script type="text/javascript" src="yui/calendar-min.js"></script>

</head>

<body onLoad="javascript:defaultDisplay();dcfy();">

<div id="maincontainer">
	<?php 
		$headerTitle = $companyname;
		include_once "header.php";		
	?>

<div id="contentwrapper">
	<div id="contentcolumn">		
		<div class="innertube">
			Using it for the first Time. <a href="addAccount.php">Click here to create ledgers</a>.
			<div id="legendTag">
				<div onClick="javascript: changeClassName(1);showSaveDayBook();" class="legendLookTag" name="legendLookTag1" id="legendLookTag1">Save Day Book</div>  
				<div onClick="javascript: changeClassName(2);showSearchDayBook();" class="legendLookTag" name="legendLookTag2" id="legendLookTag2">Search Day Book</div>  
				<div onClick="javascript: changeClassName(3);viewLedger();" class="legendLookTag" name="legendLookTag3" id="legendLookTag3">View Ledger</div>
				<div onClick="javascript: changeClassName(4);viewTrialBalance();" class="legendLookTag" name="legendLookTag4" id="legendLookTag4">View Trial Balance</div>  
				<div onClick="javascript: changeClassName(5);viewBalanceSheet();" class="legendLookTag" name="legendLookTag5" id="legendLookTag5">View Balance Sheet</div>  
			</div>
			<div class="divTableTag" style="clear:both;display:table">
				<table class="tableTag" cellpadding="10px">
				<tr>
					<td class="dateLabel" id="dateLabel" name="dateLabel">Date (dd-mm-yyyy)</td>
					<td class="dateField">
						<input type="text" name="dayBookDate" id="dayBookDate" onkeypress="return validateNumberForDate(event)" onfocus="javascript:document.getElementById('cal1Container').style.display='block';" maxlength="10"></input>
					</td>
					<td>
					<div>
						<!-- Yahoo Calendar Test -->
						<div class="yui-skin-sam" style="position:absolute;">
							<div id="cal1Container" style="display:none"></div> 
						</div>
						
						<script>
						// A DIV with id "cal1Container" should already exist on the page
						var cal1 = new YAHOO.widget.Calendar("cal1","cal1Container");
						//var cal1 = new YAHOO.widget.Calendar("cal1","cal1Container", 
	                    //                                        { mindate:"04/01/2011"+currentFinancialYearStart, 
	                    //                                          maxdate:"03/31/2012"+currentFinancialYearEnd }); 
						cal1.render();
						function handleSelect(type,args,obj) {
							var dates = args[0];
							var date = dates[0];
							var year = date[0], month = date[1], day = date[2];

							
							if (day  < 10) day = "0"+day;
							if (month < 10) month = "0"+month;
		 					document.getElementById("dayBookDate").value = day + "-" + month + "-" + year;
							document.getElementById("cal1Container").style.display="none";							
						}

						cal1.selectEvent.subscribe(handleSelect, cal1, true);
						</script>
						
					</div>	
						<!-- Yahoo Calendear End -->
					</td>
				</tr>
				<tr class="hideDateRangeTag" id="dateRange" name="dateRange">
					<td class="dateLabel" id="dateRangeToLabel" name="dateRangeToLabel">To Date (dd-mm-yyyy)</td>
					<td class="dateField"><input type="text" name="dayBookDateTo" id="dayBookDateTo" onkeypress="return validateNumberForDate(event)" onfocus="javascript:document.getElementById('cal2Container').style.display='block';"></input></td>
					<td>
					
					<div>
						<!-- Yahoo Calendar Test -->
						<div class="yui-skin-sam" style="position:absolute;">
							<div id="cal2Container" style="display:none"></div> 
						</div>
						 
						<script>
						// A DIV with id "cal1Container" should already exist on the page
						var cal2 = new YAHOO.widget.Calendar("cal2","cal2Container");
						//var cal2 = new YAHOO.widget.Calendar("cal2","cal2Container", 
	                    //                                        { mindate:"04/01/2011"+currentFinancialYearStart, 
	                    //                                          maxdate:"03/31/2012"+currentFinancialYearEnd }); 
						cal2.render();
						function handleSelect2(type,args,obj) {
							var dates = args[0];
							var date = dates[0];
							var year = date[0], month = date[1], day = date[2];

							
							if (day  < 10) day = "0"+day;
							if (month < 10) month = "0"+month;
		 					document.getElementById("dayBookDateTo").value = day + "-" + month + "-" + year;
							document.getElementById("cal2Container").style.display="none";							
						}

						cal2.selectEvent.subscribe(handleSelect2, cal2, true);
						</script>
					</div>	
					<!-- Yahoo Calendear End -->

					
					
					
					</td>
				</tr>
				<tr id="debitTr" name="debitTr" class="showDebitTr">
					<td class="debitLabelTag" id="debitLabel" name="debitLabel">Debit</td>
					<td class="debitFieldTag" id="debitFieldTag" name="debitFieldTag">
						<input type="text" size="20" id="completefield" name="completefield" onkeyup="callXML('divautocomp','completefield');completeFieldKeyUp(event,'completefield');"  onfocus="javascript:stopHide('divautocomp');hidePoll('divautocomp_1');" maxlength="50"></input>
					</td>
					<td>
						<div>
						<div style="position:absolute">
						<select id="divautocomp" name="divautocomp" class="debitTag" multiple="true"  onChange="javascript:selectValue(this,'completefield')" onfocus="javascript:stopHide('divautocomp');" onClick="javascript:selectValue(this,'completefield'); this.blur()" onKeyPress="selectKeyPress(event,this,'completefield')" onblur="javascript:hidePoll('divautocomp');"  >
						</select>
						</div>
						</div>					
					</td>
				</tr>
				<tr class="showCreditTr" id="creditTr" name="creditTr">
					<td id="creditLabel" name="creditLabel">Credit</td>
					<td id="creditField" name="creditField">
						<input type="text" size="20" id="completefield_1" name="completefield_1"  onfocus="javascript:stopHide('divautocomp_1');hidePoll('divautocomp');" onkeyup="callXML('divautocomp_1','completefield_1')" maxlength="50"></input> 
					</td>
					<td>
						<div>
						<div style="position:absolute">
						<select id="divautocomp_1" name="divautocomp_1" class="creditTag" multiple="true" onChange="javascript:selectValue(this,'completefield_1')" onfocus="javascript:stopHide('divautocomp_1');" onClick="javascript:selectValue(this,'completefield_1'); this.blur()" onKeyPress="selectKeyPress(event,this,'completefield_1')" onblur="javascript:hidePoll('divautocomp_1');document.getElementById('dayBookContra').focus()"  /> 
						</select>
						</div>
						</div>
					</td>
				</tr>
				<tr class="showContraTr" id="contraTr" name="contraTr">
					<td class="contraLabel">Contra</td>
					<td class="contraField">
						<select name="dayBookContra" id="dayBookContra">
							<option value="Y" selected>Y</option>
							<!-- <option value="N" style="visibility:hidden">N</option> -->
						</select>
					</td>
					<td></td>
				</tr>
				<tr class="showAmountTr" id="amountTr" name="amountTr">  
					<td class="amountLabel">Amount</td>
					<td class="amountField">
						<input type="text" name="dayBookAmount" id="dayBookAmount" onKeyPress="return validateNumberForAmount(event)" maxlength="15"></input>
					</td>
					<td></td>
				</tr>
				<tr class="showDescriptionTr" id="descriptionTr" name="descriptionTr">
					<td class="descriptionLabel">Description (100 Characters)</td>
					<td class="descriptionField">
						<input type="text" name="description" id="description" maxlength="100"></input>
					</td>
					<td></td>
				</tr>
				<tr>
					<td colspan="3" class="submitButtonTag">
						<input type="button" id="saveDayBookButton" name="saveDayBookButton" class="hideSaveDayBookButton" value="Save" onClick="javascript: validateButton('saveDayBook')"></input>
						<input type="button" id="searchDayBookButton" name="searchDayBookButton" class="hideSearchDayBookButton" value="Search Day Book" onClick="javascript: validateButton('searchDayBook')" ></input>
						<input type="button" id="viewLedgerButton" name="viewLedgerButton" class="hideViewLedgerButton" value="View Ledger" onClick="javascript: validateButton('showLedger')"></input>
						<input type="button" id="viewTrialBalanceButton" name="viewTrialBalanceButton" class="hideViewTrialBalanceButton" value="View Trial Balance" onClick="javascript: validateButton('showTrialBalance')"></input>
						<input type="button" id="viewBalanceSheetButton" name="viewBalanceSheetButton" class="hideViewBalanceSheetButton" value="View Balance Sheet" onClick="javascript: validateButton('showBalanceSheet')"></input>
					</td>
				</tr>
				</table>
			</div>
			<div style="clear:both;" class="displayDivTag" id="displayDayBookEntries" name="displayDayBookEntries"> </div>
			<div style="clear:both;" id="displayAccountDetails" name="displayAccountDetails"> </div>
			<div style="clear:both;" id="popup" name="popup"></div>
			<script language="javascript">
				populateAccountNames();
			</script>
		</div>
	</div>
</div>

<div id="leftcolumn">
	<div class="innertube">
		<b><a href="addAccount.php">Manage Account Details</a></b>
	</div>
	<div class="innertube_high">
		<b><a href="index.php">Transactions and Statements</a></b>
	</div>
</div>

<?php include_once 'footer.php' ?>

</div> 
<!-- End of Main Container -->



 
</body>
</html>
Return current item: Simple Accounting System