📜 ⬆️ ⬇️

Financial accounting in the text console

"A good accountant can not get together only a skirt."

Several years ago, I faced the task of keeping track of cash expenses so that at the end of the month I would understand how much and where the money is spent.
I went through the most famous applications ( GnuCash , Kmymoney , aqbanking , grisbi , cbb , ledger for one reason or another did not like one. Besides the last.

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

Before you start reading about using personal finance programs, I would advise you to get some initial knowledge of accounting (in the minimum that you need for home accounting), which can be found in the city-rat.livejournal.com blog, and expand your knowledge about personal finance, loans and credit cards for example in articles by Max Krainov . This is not necessary, but the knowledge of how to manage personal finances will perfectly complement the knowledge of how to manage these finances.
')
If I briefly describe the capabilities of this utility, then I would single out the following among them:

- support double entry. This allows you to simultaneously track the sources of receipt and direction of expenditure of funds.
- open data storage format: postings are stored in plain text files (as I like).
- flexible creation of reports: bills, transactions, etc.
- support of several accounts: bank, debt, investment, credit, cash
- support multiple currencies (yes, even Bitcoin)
- 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 in my opinion right. Where automatic operations with finances begin, the control over these finances ends.
- open source (distributed under the BSD license).

The principle of operation is this: you make the postings to a file, then, based on the collected data, you make reports on funds spent, etc.

File organization


You can make all the postings in a single text file, but for me it was inconvenient and I did this: I made a general file and included posting files for it every 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, the currency is specified, which 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 in the utility options each time.

Each file starts with a year:

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

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

  ~$ cat .ledgerrc --wide --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 currency rates is automatically filled in by me using a script, downloading data from the website of the Central Bank of the Russian Federation. It runs once a day according to the schedule in crontab (5) and adds the rates of currencies I need to this file.

  ~$ ccc 10 USD RUR 370.86609471 ~$ 

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

This results in the following file:

  ~$ 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 ~$ 

Posting


The principle of double entry can be briefly formulated as follows: when in one place funds decrease, in another they come. For example, if after visiting a store in your wallet the 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, each record usually has at least two accounts, 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 others, but with the opposite sign:

 2016-08-22  : ; ,     -75 : 75 


* assets - this is what you really have. More precisely your property. This can be your pocket money, a deposit in a bank, a Yandex.Money account, etc .;
* liabilities ( liabilities ) - this is what you owe to someone. That is, for example, you may have an apartment, but you do not have to bank;
* equity ( equity ) - your net money. In other words, this is what will remain if you deduct your debts from your assets;
* income ( income ) - you somehow earn? For example, your salary or a neighbor's gratitude for computer repair is a good example of profit;
* expenses ( expenses ) - went to the cinema with a friend? Here you have the costs;

If you use Vim or Sublime Text, then to make entries it is convenient to use plugins to highlight the syntax for the 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 it comes only from what was manually entered into the file. But if you still want to make the same postings regularly (for example, monthly payments for the phone), then you can automate the addition of entries with the option '' ledger entry 'and schedules in cron (8) .

Accounts can be called as you like and in any language (ledger perfectly supports UTF-8). Counting can be done using a colon in the account name, for example, “expenses: connection: Internet”. The main thing is not to get lost in them later :) I advise you to make basic accounts and then expand them as needed. It all depends on how detailed you want to see later. For starters, you can have accounts for at least five categories: asset, debt, income, expenses, and some account for balancing balances. I called it “own”, in English-speaking examples it is usually called “equity”.

The amount in the wiring can be written as it is convenient: "$ 15", "28 EUR", "21 €", "66 ₽". Ledger understands that different units need to be read separately. Units of measure can be any, those that need to be considered. Including non-monetary (and the program can correctly recalculate them, if she is given a file with a price history).

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

Useful links: documentation for Ledger , site plaintextaccounting.org .

Source: https://habr.com/ru/post/308434/


All Articles