Financial accounting in a text console

    “Only a skirt can not be a good accountant.”

    A few years ago I had the task of keeping track of cash expenses so that at the end of the month I understand how much and where money is being spent.
    After going through the most famous applications ( GnuCash , Kmymoney , aqbanking , grisbi , cbb , ledger, I didn’t like any of these for one reason or another. Except the last.

    Ledger is a console utility that will help you control your personal finances. My acquaintance with it began with an article on the blog “Ledger - command line accounting”. And, as far as I know, there are no more articles in Russian about her. Let's try to fix this misunderstanding.

    Before you start reading about the use of personal finance programs, I would advise you to get initial knowledge about accounting (at the minimum that you need for home accounting), which can be gleaned from the blog , and expand your knowledge about personal finances, loans and credit cards, for example, in articles by Max Krainov . This is not necessary, but knowledge of how to manage personal finances will perfectly complement the knowledge of how to manage these finances.

    Briefly describe the capabilities of this utility, then I would single out the following among them:

    - Support for dual recording. This allows you to simultaneously track the sources of receipt and direction of spending.
    - open data storage format: transactions are stored in plain text files (as I like).
    - flexible reporting: on accounts, transactions, etc.
    - support for multiple accounts: banking, debt, investment, credit, cash
    - support for multiple currencies (yes, even Bitcoin)
    - a simple and fairly convenient console interface
    - import from CSV format, export to OFX format
    - there is no automation: ledger does not change your data. And this is correct in my opinion. Where automatic operations with finances begin, control over these finances ends.
    - open source code (distributed under the BSD license).

    The principle of work is this: you make entries to the file, then based on the collected data, you make reports about the funds spent, etc.

    File organization

    You can enter all transactions in a single text file, but for me it was inconvenient and I did this: I made a shared file and included files with transactions for each year.

    It looks like this:

    	~$ cat .ledger/sergeyb-finance.dat
    	;; N RUR
    	N ₽
    	!account sergeyb
    	!include sergeyb-finance-2012.dat
    	!include sergeyb-finance-2013.dat
    	!include sergeyb-finance-2014.dat
    	!include sergeyb-finance-2015.dat
    	!include sergeyb-finance-2016.dat
    	!apply end

    At the beginning of the file is the currency that ledger will use by default for all transactions where it is not specified. The sergeyb-finance.dat file is exported in the LEDGER_FILE environment variable so that you do not have to specify it each time in the utility options.

    Each file begins with an indication of the year:

    	~$ head -1 .ledger/sergeyb-finance-2014.dat

    If you will use several currencies in transactions, it makes sense to maintain a file with exchange rates. It can be set in the environment variable LEDGER_PRICE_DB or in the configuration file:

    	~$ cat .ledgerrc
    	--pager /usr/bin/less
    	--file /Users/sergeyb/.ledger/sergeyb-finance.dat
    	--price-db /Users/sergeyb/.ledger/sergeyb-finance-currency.dat
    	--sort date

    The file with exchange rates is filled in automatically with a script, downloading data from the website of the Central Bank of the Russian Federation. It starts once a day according to the schedule in crontab (5) and adds the rates of the currencies I need to this file.

    	~$ ccc 10 USD RUR

    For digital currencies (Bitcoin, Litecoin) there are also scripts .

    The result is a file like this:

    	~$ head -10 .ledger/sergeyb-finance-currency.dat
    	; -*- ledger -*-
    	N $
    	N USD
    	N EUR
    	P 2011/05/29 EUR 40.08020851 RUR
    	P 2011/06/10 $ 27.79070045 RUR
    	P 2011/07/13 $ 28.25570737 RUR


    The principle of double entry can be summarized as follows: when in one place the funds decrease, in another they arrive. For example, if after visiting the store in your wallet money decreased, then the amount in one of the assets decreased, and the amount in the “expenses” account increased. The principle of double-entry is a fundamental principle in accounting.

    According to this principle, there are usually at least two accounts in each record, but it is not necessary to indicate the amount for one of them, it is clear that the change will be equal to the sum of all the others, but with the opposite sign:

    2016-08-22 мороженое
    		актив:наличные	; понятно, что здесь должно быть -75
    		расходы:проезд		75

    * assets ( assets ) - this is what you really have. More precisely your property. It can be your money for pocket expenses, a bank deposit, an account in Yandex.Money, etc .;
    * Liabilities ( Liabilities ) - this is what you have to someone. That is, for example, you may have an apartment, but you do not owe a bank;
    * capital ( equity ) - your net money. In other words, this is what remains if your debts are deducted from your assets;
    * income ( income ) - you somehow earn? For example, your salary or gratitude from a neighbor for a computer repair is a good example of profit;
    * expenses ( expenses ) - went to a movie with a friend? There you have the expenses;

    If you use Vim or Sublime Text, then for making entries it is convenient to use plugins to highlight syntax for ledger format. For Vim, the plugin is in the ledger repository, for Sublime Text on the wiki .

    As I already wrote, ledger does not modify your data in any way and proceeds only from what was manually entered into the file. But if you still want to make the same entries on a regular basis (for example, monthly payments for the phone), then you can automate the addition of entries using the “ledger entry” option and schedule in cron (8) .

    Accounts can be called as you like in any language (ledger perfectly supports UTF-8). You can make calculations using a colon in the name of the account, for example, “expenses: communication: Internet”. The main thing is not to get confused then in them :) I advise you to make basic accounts and then expand them as necessary. It all depends on how detailed a report you want to see later. For starters, you can create accounts for at least five categories: asset, debt, income, expenses and some account to balance the balance sheet. I called it “own”, in English examples it is usually called “equity”.

    The amount in the transaction can be written as convenient: "$ 15", "28 EUR", "21 €", "66 ₽". Ledger understands that different units must be read separately. Units of measure can be specified any, those that need to be taken into account. Including non-monetary ones (and the program can correctly count them if you give it a file with a price history).

    I still continue to use ledger, but if you only choose a tool for accounting finance, then I would advise you to look at beancount . Primarily due to the built-in posting analysis tools.

    Useful links: documentation for Ledger , .

    Also popular now: