Ledger
Table of Contents
Why Ledger?
For me, there are several advantages to using Ledger:
- text-based, hence SVN, hence diffable
- creation of accounts is easier than columns under Excel (no limitation in width)
-
automatic import of transactions through
CSV2Ledger
Ledger
Installing Ledger
Prerequisites
Install the following packages:
sudo aptitude install build-essential sudo aptitude install libtool sudo aptitude install autoconf sudo aptitude install automake sudo aptitude install texinfo sudo aptitude install python-dev sudo aptitude install zlib1g-dev sudo aptitude install libbz2-dev sudo aptitude install stow sudo aptitude install libgmp3-dev sudo aptitude install bjam sudo aptitude install libboost-dev sudo aptitude install libboost-regex-dev sudo aptitude install libboost-date-time-dev sudo aptitude install libboost-filesystem-dev sudo aptitude install gettext sudo aptitude install cvs sudo aptitude install libmpfr-dev sudo aptitude install libpcre3-dev sudo aptitude install libedit-dev sudo aptitude install libcppunit-dev
Fetch Ledger
Get Ledger from Git. Type:
git clone git://git.savannah.nongnu.org/ledger.git
Configure Ledger
cd ledger rm -f config.log # for git pull git submodule init # for utf8.h git submodule update # for utf8.h chmod +x autogen.sh ./autogen.sh ./acprep ./configure
Build Ledger
make check make
Install Ledger
make install link <full-path-to-ledger>/ledger /usr/local/bin/ledger
Test Ledger
ledger -f XXX/XXX.dat
Rebuild Ledger
The best way to update to the latest version is:
make distclean ./acprep update
This should do everything you need (create the configure script, call
configure, and call make). It's an "all-in-one" solution to make it
easy for those who are tracking Git to stay up to date.
CSV2Ledger
CSV2Ledger reads a CSV file and outputs it in Ledger format. It is useful for converting data from financial institutions into your Ledger.
Fetch it
Go to launchpad and get the latest files on the branch, not the tarball (which can be older).
Installing Perl modules
Searching for the Perl modules to install with commands such as apt-cache search perl | grep csv (or grep yaml), we find that we have to install
the following:
sudo aptitude install libtext-csv-perl sudo aptitude install libyaml-perl sudo aptitude install libsmart-comments-perl sudo aptitude install libtemplate-perl
Errors
-
Field separator must be the comma. Though, the following patch would
accept semi-colons:
my $CSV = Text::CSV->new({sep_char => ';'});
-
Amounts have to be "numeric":
- no thousand separator (dots removed)
- decimal separator must be a dot (comma removed)
- Accents in the description are not supported… (otherwise, field count did not match).
- Virtual accounts (..) (..) lines should be removed
-
Pay attention not having quotes in field labels, as in the following
example:
AmountField: 'Montant de l'operation'
CSV2Ledger.pl -i 979086845418.csv -o 979086845418.dat
Debugging
I've had a problem of field counts with a DOS file. I could find this thanks to the help of Russell, and thanks to his smart comments in the code.
Smart_Comments="### ####" perl ~/src/CSV2Ledger-1.4/CSV2Ledger.pl -i telechargement-for-CSV2Ledger.csv
This produces verbose logs during the program execution. It is worth mentioning.
Missing stuff
What CSV2Ledger is missing, for me, is:
-
a default "Commodity" option (for example: EUR or USD) in the
FileMatches.yamlfile. - a default payee, when there is none.
- a date format specification.
- a way to specify a destination account when amount is positive, and another when amount is negative. Wait. That does exist, but not tested yet.
Features
- CSV2Ledger adds a trailing whitespace after each payee.
- Duplicate detection is great. Pay attention, though, than taking twice the same highway, and paying at the same toll could be detected as duplicate!
hledger
Installing
Install it following one of the methods described on http://hledger.org/MANUAL.html#installing.
sudo aptitude install ghc6 cabal-install happy cabal update cabal install cabal-install cabal install hledger
The executable is now installed in ~/.cabal/bin.
For ease of access, make a link to it:
cd ~/bin
ln ~/.cabal/bin/hledger hledger
Though, I had to install libboost-serialization-dev as well to make it
work.
sudo aptitude install libboost-serialization-dev
Features
-
Full account names must be <= 34 characters (otherwise, they get
truncated by the
printcommand). For example,Expenses:House:Repair-and-Maintenanceis 3 chars too long.
Subtle differences between ledger and hledger
-
The
printcommand of ledger reorders the transactions by date. The one from hledger does not change the initial order found in the source.datfile. That's the most important difference. - The print command of Ledger truncates the payees' name when they have 2 or more subsequent whitespaces in them.
- The print command of ledger leaves useless trailing whitespaces in the payees. ledger does remove them.
Beancount
Beancount is a subset of Ledger (a little more restrictive), with a few additional directives.
- Check account names at http://furius.ca/beancount/examples/demo.ledger
- Read all the doc (in doc directory)… very interesting on how to write transactions
Download it
cd ~/Downloads/
hg clone https://hg.furius.ca/public/beancount
Build it
cd beancount/
python ./setup.py build
Install it
sudo python ./setup.py install
This creates a couple of directories in /usr/local/lib and copies the
following scripts to the right places:
/usr/local/bin/bean-web /usr/local/bin/bean-convert-rbc-activity /usr/local/bin/bean-trial /usr/local/bin/bean-suck /usr/local/bin/bean-convert-paypal-csv /usr/local/bin/bean-convert-ofx
Notes
- Every amount must have a currency
- The account names must not contain spaces: use a dash instead.
Open issues and remarks
Transfer between own accounts
When uploading transactions with CSV2Ledger from files from your bank, pay attention that, if you use the real account names, transactions will appear as doubled:
-
In the file of the Savings account:
2009/05/11 * ( ) NIESSEN Assets:Bank:Savings -420.00 EUR Assets:Bank:Checking
-
In the file of the Checking account:
2009/05/11 * ( ) NIESSEN Assets:Bank:Checking 420.00 EUR Assets:Bank:Savings
Transactions are added, leading to wrong figures.
Better would be to use a "virtual" transfer account:
-
In the file of the Savings account:
2009/05/11 * ( ) NIESSEN Assets:Bank:Savings -420.00 EUR Assets:Bank:Transferred
-
In the file of the Checking account:
2009/05/11 * ( ) NIESSEN Assets:Bank:Checking 420.00 EUR Assets:Bank:Transferred
There, only the Transfer account gets void at the end of the day. The amounts reported in both the Savings and the Checking account are appearing there once, and only once.
Future versions
What could we expect from future versions?
- UI Web to enter transactions (creating, not only reading)
- more colors in any interface
- integrated reports like Assets, P&L