Internal

We have here gathered some internal links to stuff of interest.

Oneliners

  • Source tree cleanup - CRLF => LF
find ./ -type f \( -name "*.php" -o -name "*.css" -o -name "*.js" -o -name "*.txt" -o -name "*.inc" \) | xargs dos2unix -U
  • Crontab sql dumping backup:
mysqldump --host="hostingAddress" --user="databaseUserName" --password="databasePassword" "databaseName" | gzip > "~/frontaccounting_$(date +%Y%m%d).sql.gzip"

External

And these sites are of interest to all of us.

RESTful API

config_db.php structure

The installation scripts create the config_db.php file (as also the installed_extensions.php file both in the webroot and in the company/0/ folder).

This file is the link between FrontAccounting and its MySQL database.

This link is maintained via an array containing connection information ($db_connections).

The relevant fields are:

$def_coy - the array index in $db_connections for the default company used when you log on to FrontAccounting eg. 0. This database is pre-selected when logging in. $tb_pref_counter - the prefix to NEXT company database you create eg. 2
$db_connections - an array of companies in use by your FrontAccounting installation.


The relevant array entries are:
1) An index for the entry eg. 0 (the next company would be 1, then 2 etc). This number also points to the company specific information contained in the /company directory.
2) An array of database connection fields:
- 'name' - The name of your company
- 'host' - the host of the MySQL database (usually 'localhost')
- 'dbuser' - the MySQL user name
- 'password' - the MySQL password for the database
- 'dbname' - the MySQL database name
- 'tbpref' - the prefix to all tables in the company database (eg 1_)


Don't forget the file is a valid PHP file using native array code - this means be careful of brackets and quotes.


If you interfere with your installation and have problems logging in, here are some basic things to check
- Correct PHP syntax in the config_db.php file
- $def_coy - make sure this corresponds to a valid index in the $db_connections array, and also ensure that the company prefix (tbpref) is valid ie. your database contains (prefix)+table names.
- $db_connections - correct MySQL login information for the database,
- A corresponding directory in the /company directory containing your company information eg. 0 or 1 etc.

Creating your own chart of accounts for new company setup (DEVELOPERS ONLY)

For testing purposes you may want to create new companies with different charts of accounts and settings etc.
You can do this through the Setup - Create/Update Companies screen.
Here are some tips on what you need to do:
1) You must be logged on to company 0, as the admin user (otherwiser the Create/Update Companies menu option will be inaccessible).
2) Create your database SQL script. Make sure every table uses the "0_" prefix (line 298 of the /admin/db/maintenance_db.inc sets "0_" to whatever the next company in the config_db.php file is).
3) Modify /includes/ui/ui_lists.inc and add a descriptive name to SQL script in function function coa_list_row at around line 2350. You'll now see the readable name in the dropdown box.
4) Copy your .sql script to the /sql directory.
5) Ensure your config_db.php file is writeable. It will be updated with the new company details.
6) Provide the database password in the 'New script Admin Password' field.


Anatomy of a Transaction

If you're interested in modifying/extending FrontAccounting, it helps to know what database changes get made by different transactions.
An easy way to detect this is to either a) switch SQL trail on (config.php) and look at the SQL changes or b) make a backup of the database before and after your transaction to see what's changed using a tool like diff, KDiff3 (Mac and Win), WinMerge (Win) or online.
As an example I found the following:
Transaction: Quick Entry bank payment (for a tax inclusive transaction).
Tables changed
1) 0_gl_trans
3 entries
- a CR against the bank account for the full amount,
- a DR for Mobile Phone expense for the after-tax amount
- a DR for 'prepaid tax' for the 10% tax amount.
- each line had a comment, for the bank account it was the full memo entered in the memo box, the other two accounts only got 'userid: Quick Entry name' eg. 'admin - Mobile Phone Bill'


2) 0_comments
A specific memo for this transaction inserted into the comments table.


3) 0_refs
Updated for this transaction type and transaction number to the next reference eg. PMNT0002
Also, 0_audit_trail had an insert, as did 1_user_online.

FrontAccounting v2.4 record updations / insertions for various transactions

Using additional fonts

FA uses the TCPDF framework for creating its .pdf reports. This is somewhat restrictive in that you can't simply specify different .ttf files to display reports in different fonts.
There is however a way to add your own additional fonts and have them appear on your reports.


The TCPDF site has full details of the process, but briefly for version 1.2.007:
1) You need the ttf2pt1 or ttf2ufm binaries and the PHP makefont.php script. ttf2pt1 source is provided with the TCPDF distribution. Windows versions are available for the binaries in the TCPDF download, or you can compile them yourself (which you need to do for *nix). Keep your new font file names all lower case, no special characters and preferably 8 or fewer characters for best results.
2) Run ttf2pt1 against your .ttf file. This creates a numerous files, but the ones you need is the xxxxx.afm (font metrics) file, and also the .z (packed font) file if you want to embed the font in your .pdf document (which makes it larger, but everyone can see it).

     ./ttf2pt1 -a -F xxxxx.ttf

3) With your original xxxxx.ttf, and you new xxxxx.afm (plus xxxxx.z if needed) files you just created, you now need to run the PHP makefont.php script against them.

     php makefont.php -q xxxxx.ttf xxxxx.afm

This creates a xxxxx.php file which contains positioning data for your font.
4) Copy your xxxxx.php (and xxxxx.z if you're using it) to /reporting/fonts directory
5) If you want ALL report fonts changed, modify the class.pdf.inc file in /reporting/includes directory. At line 119 change the font to the new .php file you created (without the .php extension):

     // was helvetica
     $this->FontFamily = 'tradegot';

5a) If you want to change the font in just one report, enter the following code in your report, after the initialisation of the $rep object. The font name you supply must be the name of the makefont.php created font file. This is usually the same names as the font, but all lower case.

     $rep->Font('','tradegot');

Notes on makefont.php This file is included in the TCPDF distribution and its job is to create the fontname.php file that TCPDF uses to display your font on reports. Important tip: Your character mapping files (eg. iso-8859-1.map) need to be in a directory called 'enc' or the script won't finish, as this is the only place it looks for them.

Here's a *nix script that does it all for you:

#!/bin/bash

## Creating a new FrontAccounting font using the TCPDF framework. See http://www.tcpdf.org
## Instructions: ./makeFAfont.sh FONTNAME with no .ttf suffix.
## Assumes your ttf font file is in this current directory.

## Step 1 of 2: Making .afm and .z files (and some others we won't use).
## Assumes ttf2pt1 is in your /usr/local/bin location - change this if not the case
echo "Running makeFAfont.sh - to make new fonts for use in FrontAccounting. By Pete"
## Must supply one argument, .ttf file without .ttf suffix.

if [ "$#" -lt "1" ]
then 
    echo "Usage: ./makeFAfont.sh <fontname> (no .ttf). [character mapping]";
	exit 1;
fi

## Default iso-8859-1 mapping. Others included eg. cp1252. 

ENC=iso-8859-1
if [ "$#" -eq 2 ]
then 
    ENC="$2"
fi

## If the .ttf file does not exist, stop can't continue.
if [ ! -f "${1}.ttf" ]
then
	echo "${1}.ttf file not found. Exiting";
	exit 1;
fi

## If the character encoding map file is not in ./enc, stop
if [ "$#" -eq 2 ]
then
	if [ ! -f "./enc/${2}.map" ]
	then
		echo "${1}.map file not found in ./enc directory. Exiting";
		exit 1;
	fi
fi


## Must have ttf2pt1 or can't continue.
## Find it on path.
hash ttf2pt1 2>&- || {
	echo >&2 "I require ttf2pt1 but I cannot find it on the path. Exiting.";
	exit 1;
}

ttf2pt1 -a -F ${1}.ttf

## Step 2 of 2: Make the <fontname>.php file for use by FA via TCPDF
## Running makefont to create <fontname>.php file
## Default mapping is iso-8859-1. Change this parameter (2) if not the case. Note the .map files must reside in a ./enc directory.
php makefont.php ${1}.ttf ${1}.afm ${ENC}
## If makefont.php ran successfully, you now have a \<fontname\>.php file, as well as your \<fontname\>.afm (font metrics)
## and <fontname>.z (packed font) files. These three files are necessary for TCPDF to use the font.
echo "Finished creating font .php file. Now update /reporting/includes/class.pdf.inc line 119 with new font name, less the .php suffix."

The site http://www.tcpdf.org/fonts.php has more details on this process.
TIP: If you're running out of room on some of your reports, consider a more horizontally compressed font like 'tuffy' (GNU). tuffy is a very modern rounded looking sans-serifed font that packs alot of data onto the page neatly.