2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
hledger_journal(5) hledger User Manuals hledger_journal(5)
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
NAME
|
2016-04-14 08:29:16 +03:00
|
|
|
Journal - hledger's default file format, representing a General Journal
|
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
DESCRIPTION
|
2019-09-13 18:26:49 +03:00
|
|
|
hledger's usual data source is a plain text file containing journal en-
|
|
|
|
tries in hledger journal format. This file represents a standard ac-
|
|
|
|
counting general journal. I use file names ending in .journal, but
|
2016-04-14 08:29:16 +03:00
|
|
|
that's not required. The journal file contains a number of transaction
|
|
|
|
entries, each describing a transfer of money (or any commodity) between
|
|
|
|
two or more named accounts, in a simple format readable by both hledger
|
|
|
|
and humans.
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
hledger's journal format is a compatible subset, mostly, of ledger's
|
|
|
|
journal format, so hledger can work with compatible ledger journal
|
|
|
|
files as well. It's safe, and encouraged, to run both hledger and
|
2016-04-14 08:29:16 +03:00
|
|
|
ledger on the same journal file, eg to validate the results you're get-
|
|
|
|
ting.
|
|
|
|
|
|
|
|
You can use hledger without learning any more about this file; just use
|
2019-09-02 21:11:56 +03:00
|
|
|
the add or web commands to create and update it. Many users, though,
|
2019-09-13 18:26:49 +03:00
|
|
|
also edit the journal file directly with a text editor, perhaps as-
|
|
|
|
sisted by the helper modes for emacs or vim.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
Here's an example:
|
|
|
|
|
|
|
|
; A sample journal file. This is a comment.
|
|
|
|
|
2019-06-12 16:01:17 +03:00
|
|
|
2008/01/01 income ; <- transaction's first line starts in column 0, contains date and description
|
|
|
|
assets:bank:checking $1 ; <- posting lines start with whitespace, each contains an account name
|
|
|
|
income:salary $-1 ; followed by at least two spaces and an amount
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
2008/06/01 gift
|
2019-06-12 16:01:17 +03:00
|
|
|
assets:bank:checking $1 ; <- at least two postings in a transaction
|
|
|
|
income:gifts $-1 ; <- their amounts must balance to 0
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
2008/06/02 save
|
|
|
|
assets:bank:saving $1
|
2019-06-12 16:01:17 +03:00
|
|
|
assets:bank:checking ; <- one amount may be omitted; here $-1 is inferred
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-06-12 16:01:17 +03:00
|
|
|
2008/06/03 eat & shop ; <- description can be anything
|
2016-04-14 08:29:16 +03:00
|
|
|
expenses:food $1
|
2019-06-12 16:01:17 +03:00
|
|
|
expenses:supplies $1 ; <- this transaction debits two expense accounts
|
|
|
|
assets:cash ; <- $-2 inferred
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2017-07-25 00:19:25 +03:00
|
|
|
2008/10/01 take a loan
|
|
|
|
assets:bank:checking $1
|
|
|
|
liabilities:debts $-1
|
|
|
|
|
2019-06-12 16:01:17 +03:00
|
|
|
2008/12/31 * pay off ; <- an optional * or ! after the date means "cleared" (or anything you want)
|
2016-04-14 08:29:16 +03:00
|
|
|
liabilities:debts $1
|
|
|
|
assets:bank:checking
|
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
FILE FORMAT
|
|
|
|
Transactions
|
2019-09-02 21:11:56 +03:00
|
|
|
Transactions are movements of some quantity of commodities between
|
2019-09-13 18:26:49 +03:00
|
|
|
named accounts. Each transaction is represented by a journal entry be-
|
|
|
|
ginning with a simple date in column 0. This can be followed by any of
|
|
|
|
the following, separated by spaces:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2017-05-25 03:44:32 +03:00
|
|
|
o (optional) a status character (empty, !, or *)
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
o (optional) a transaction code (any short number or text, enclosed in
|
2017-06-30 22:45:50 +03:00
|
|
|
parentheses)
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2017-05-25 03:44:32 +03:00
|
|
|
o (optional) a transaction description (any remaining text until end of
|
2017-09-05 21:44:02 +03:00
|
|
|
line or a semicolon)
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
o (optional) a transaction comment (any remaining text following a
|
2017-09-05 21:44:02 +03:00
|
|
|
semicolon until end of line)
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
Then comes zero or more (but usually at least 2) indented lines repre-
|
2017-05-25 03:44:32 +03:00
|
|
|
senting...
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2017-05-25 03:44:32 +03:00
|
|
|
Postings
|
2019-09-02 21:11:56 +03:00
|
|
|
A posting is an addition of some amount to, or removal of some amount
|
|
|
|
from, an account. Each posting line begins with at least one space or
|
2017-05-25 03:44:32 +03:00
|
|
|
tab (2 or 4 spaces is common), followed by:
|
2016-06-03 20:21:09 +03:00
|
|
|
|
2017-05-25 03:44:32 +03:00
|
|
|
o (optional) a status character (empty, !, or *), followed by a space
|
2016-06-03 20:21:09 +03:00
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
o (required) an account name (any text, optionally containing single
|
2017-05-25 03:44:32 +03:00
|
|
|
spaces, until end of line or a double space)
|
2016-06-03 20:21:09 +03:00
|
|
|
|
2017-05-25 03:44:32 +03:00
|
|
|
o (optional) two or more spaces or tabs followed by an amount.
|
2016-06-03 20:21:09 +03:00
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
Positive amounts are being added to the account, negative amounts are
|
2017-05-25 03:44:32 +03:00
|
|
|
being removed.
|
|
|
|
|
|
|
|
The amounts within a transaction must always sum up to zero. As a con-
|
2019-09-02 21:11:56 +03:00
|
|
|
venience, one amount may be left blank; it will be inferred so as to
|
2017-05-25 03:44:32 +03:00
|
|
|
balance the transaction.
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
Be sure to note the unusual two-space delimiter between account name
|
|
|
|
and amount. This makes it easy to write account names containing spa-
|
|
|
|
ces. But if you accidentally leave only one space (or tab) before the
|
2017-05-25 03:44:32 +03:00
|
|
|
amount, the amount will be considered part of the account name.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Dates
|
|
|
|
Simple dates
|
2019-09-02 21:11:56 +03:00
|
|
|
Within a journal file, transaction dates use Y/M/D (or Y-M-D or Y.M.D)
|
|
|
|
Leading zeros are optional. The year may be omitted, in which case it
|
2019-09-13 18:26:49 +03:00
|
|
|
will be inferred from the context - the current transaction, the de-
|
|
|
|
fault year set with a default year directive, or the current date when
|
|
|
|
the command is run. Some examples: 2010/01/31, 1/31, 2010-01-31,
|
2016-05-28 22:58:30 +03:00
|
|
|
2010.1.31.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Secondary dates
|
2019-09-02 21:11:56 +03:00
|
|
|
Real-life transactions sometimes involve more than one date - eg the
|
2016-04-14 08:29:16 +03:00
|
|
|
date you write a cheque, and the date it clears in your bank. When you
|
2019-09-13 18:26:49 +03:00
|
|
|
want to model this, eg for more accurate balances, you can specify in-
|
|
|
|
dividual posting dates, which I recommend. Or, you can use the sec-
|
2019-09-02 21:11:56 +03:00
|
|
|
ondary dates (aka auxiliary/effective dates) feature, supported for
|
2016-05-28 22:58:30 +03:00
|
|
|
compatibility with Ledger.
|
|
|
|
|
|
|
|
A secondary date can be written after the primary date, separated by an
|
2019-09-02 21:11:56 +03:00
|
|
|
equals sign. The primary date, on the left, is used by default; the
|
|
|
|
secondary date, on the right, is used when the --date2 flag is speci-
|
2016-05-28 22:58:30 +03:00
|
|
|
fied (--aux-date or --effective also work).
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
The meaning of secondary dates is up to you, but it's best to follow a
|
|
|
|
consistent rule. Eg write the bank's clearing date as primary, and
|
2016-05-28 22:58:30 +03:00
|
|
|
when needed, the date the transaction was initiated as secondary.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
Here's an example. Note that a secondary date will use the year of the
|
|
|
|
primary date if unspecified.
|
|
|
|
|
|
|
|
2010/2/23=2/19 movie ticket
|
|
|
|
expenses:cinema $10
|
|
|
|
assets:checking
|
|
|
|
|
|
|
|
$ hledger register checking
|
|
|
|
2010/02/23 movie ticket assets:checking $-10 $-10
|
|
|
|
|
|
|
|
$ hledger register checking --date2
|
|
|
|
2010/02/19 movie ticket assets:checking $-10 $-10
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
Secondary dates require some effort; you must use them consistently in
|
2016-04-14 08:29:16 +03:00
|
|
|
your journal entries and remember whether to use or not use the --date2
|
2016-05-28 22:58:30 +03:00
|
|
|
flag for your reports. They are included in hledger for Ledger compat-
|
2019-09-13 18:26:49 +03:00
|
|
|
ibility, but posting dates are a more powerful and less confusing al-
|
|
|
|
ternative.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Posting dates
|
2019-09-02 21:11:56 +03:00
|
|
|
You can give individual postings a different date from their parent
|
|
|
|
transaction, by adding a posting comment containing a tag (see below)
|
2016-05-28 22:58:30 +03:00
|
|
|
like date:DATE. This is probably the best way to control posting dates
|
2019-09-13 18:26:49 +03:00
|
|
|
precisely. Eg in this example the expense should appear in May re-
|
|
|
|
ports, and the deduction from checking should be reported on 6/1 for
|
2016-05-28 22:58:30 +03:00
|
|
|
easy bank reconciliation:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
2015/5/30
|
2019-06-12 16:01:17 +03:00
|
|
|
expenses:food $10 ; food purchased on saturday 5/30
|
|
|
|
assets:checking ; bank cleared it on monday, date:6/1
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2016-05-28 22:58:30 +03:00
|
|
|
$ hledger -f t.j register food
|
2016-04-14 08:29:16 +03:00
|
|
|
2015/05/30 expenses:food $10 $10
|
|
|
|
|
2016-05-28 22:58:30 +03:00
|
|
|
$ hledger -f t.j register checking
|
2016-04-14 08:29:16 +03:00
|
|
|
2015/06/01 assets:checking $-10 $-10
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
DATE should be a simple date; if the year is not specified it will use
|
|
|
|
the year of the transaction's date. You can set the secondary date
|
|
|
|
similarly, with date2:DATE2. The date: or date2: tags must have a
|
|
|
|
valid simple date value if they are present, eg a date: tag with no
|
2016-05-28 22:58:30 +03:00
|
|
|
value is not allowed.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2016-05-28 22:58:30 +03:00
|
|
|
Ledger's earlier, more compact bracketed date syntax is also supported:
|
2019-09-02 21:11:56 +03:00
|
|
|
[DATE], [DATE=DATE2] or [=DATE2]. hledger will attempt to parse any
|
2016-05-28 22:58:30 +03:00
|
|
|
square-bracketed sequence of the 0123456789/-.= characters in this way.
|
2019-09-02 21:11:56 +03:00
|
|
|
With this syntax, DATE infers its year from the transaction and DATE2
|
2016-05-28 22:58:30 +03:00
|
|
|
infers its year from DATE.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2017-05-25 03:44:32 +03:00
|
|
|
Status
|
2019-09-02 21:11:56 +03:00
|
|
|
Transactions, or individual postings within a transaction, can have a
|
2019-09-13 18:26:49 +03:00
|
|
|
status mark, which is a single character before the transaction de-
|
|
|
|
scription or posting account name, separated from it by a space, indi-
|
|
|
|
cating one of three statuses:
|
2017-11-29 04:20:41 +03:00
|
|
|
|
2017-06-10 23:58:14 +03:00
|
|
|
mark status
|
2017-06-16 02:27:09 +03:00
|
|
|
------------------
|
|
|
|
unmarked
|
2017-06-10 23:58:14 +03:00
|
|
|
! pending
|
|
|
|
* cleared
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
When reporting, you can filter by status with the -U/--unmarked,
|
|
|
|
-P/--pending, and -C/--cleared flags; or the status:, status:!, and
|
2017-06-10 23:58:14 +03:00
|
|
|
status:* queries; or the U, P, C keys in hledger-ui.
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
Note, in Ledger and in older versions of hledger, the "unmarked" state
|
2019-09-13 18:26:49 +03:00
|
|
|
is called "uncleared". As of hledger 1.3 we have renamed it to un-
|
|
|
|
marked for clarity.
|
2017-06-10 23:58:14 +03:00
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
To replicate Ledger and old hledger's behaviour of also matching pend-
|
2017-06-16 02:27:09 +03:00
|
|
|
ing, combine -U and -P.
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
Status marks are optional, but can be helpful eg for reconciling with
|
2017-06-10 23:58:14 +03:00
|
|
|
real-world accounts. Some editor modes provide highlighting and short-
|
2019-09-02 21:11:56 +03:00
|
|
|
cuts for working with status. Eg in Emacs ledger-mode, you can toggle
|
2017-06-10 23:58:14 +03:00
|
|
|
transaction status with C-c C-e, or posting status with C-c C-c.
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
What "uncleared", "pending", and "cleared" actually mean is up to you.
|
2017-06-10 23:58:14 +03:00
|
|
|
Here's one suggestion:
|
|
|
|
|
2017-06-11 00:12:21 +03:00
|
|
|
status meaning
|
|
|
|
--------------------------------------------------------------------------
|
|
|
|
uncleared recorded but not yet reconciled; needs review
|
2017-12-15 05:20:07 +03:00
|
|
|
pending tentatively reconciled (if needed, eg during a big reconcil-
|
|
|
|
iation)
|
|
|
|
cleared complete, reconciled as far as possible, and considered cor-
|
|
|
|
rect
|
2017-06-10 23:58:14 +03:00
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
With this scheme, you would use -PC to see the current balance at your
|
2019-09-13 18:26:49 +03:00
|
|
|
bank, -U to see things which will probably hit your bank soon (like un-
|
|
|
|
cashed checks), and no flags to see the most up-to-date state of your
|
2017-06-10 23:58:14 +03:00
|
|
|
finances.
|
2017-05-25 03:44:32 +03:00
|
|
|
|
2017-09-06 00:06:43 +03:00
|
|
|
Description
|
2019-09-02 21:11:56 +03:00
|
|
|
A transaction's description is the rest of the line following the date
|
|
|
|
and status mark (or until a comment begins). Sometimes called the
|
2017-09-06 00:06:43 +03:00
|
|
|
"narration" in traditional bookkeeping, it can be used for whatever you
|
2019-09-02 21:11:56 +03:00
|
|
|
wish, or left blank. Transaction descriptions can be queried, unlike
|
2017-09-06 00:06:43 +03:00
|
|
|
comments.
|
|
|
|
|
|
|
|
Payee and note
|
2019-09-01 07:02:00 +03:00
|
|
|
You can optionally include a | (pipe) character in descriptions to sub-
|
|
|
|
divide the description into separate fields for payee/payer name on the
|
2019-09-13 18:26:49 +03:00
|
|
|
left (up to the first |) and an additional note field on the right (af-
|
|
|
|
ter the first |). This may be worthwhile if you need to do more pre-
|
|
|
|
cise querying and pivoting by payee or by note.
|
2017-09-05 21:44:02 +03:00
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Account names
|
2019-09-02 21:11:56 +03:00
|
|
|
Account names typically have several parts separated by a full colon,
|
|
|
|
from which hledger derives a hierarchical chart of accounts. They can
|
|
|
|
be anything you like, but in finance there are traditionally five top-
|
2019-05-24 08:26:43 +03:00
|
|
|
level accounts: assets, liabilities, income, expenses, and equity.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
Account names may contain single spaces, eg: assets:accounts receiv-
|
|
|
|
able. Because of this, they must always be followed by two or more
|
2016-06-12 07:34:20 +03:00
|
|
|
spaces (or newline).
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
Account names can be aliased.
|
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Amounts
|
2019-09-28 03:32:59 +03:00
|
|
|
After the account name, there is usually an amount. (Important: be-
|
|
|
|
tween account name and amount, there must be two or more spaces.)
|
2017-11-29 04:20:41 +03:00
|
|
|
|
2019-09-28 03:32:59 +03:00
|
|
|
hledger's amount format is flexible, supporting several international
|
|
|
|
formats. Here are some examples. Amounts have a number (the "quan-
|
|
|
|
tity"):
|
|
|
|
|
|
|
|
1
|
|
|
|
|
|
|
|
..and usually a currency or commodity name (the "commodity"). This is
|
|
|
|
a symbol, word, or phrase, to the left or right of the quantity, with
|
|
|
|
or without a separating space:
|
|
|
|
|
|
|
|
$1
|
|
|
|
4000 AAPL
|
|
|
|
|
|
|
|
If the commodity name contains spaces, numbers, or punctuation, it must
|
|
|
|
be enclosed in double quotes:
|
|
|
|
|
|
|
|
3 "no. 42 green apples"
|
|
|
|
|
|
|
|
Amounts can be negative. The minus sign can be written before or after
|
|
|
|
a left-side commodity symbol:
|
|
|
|
|
|
|
|
-$1
|
|
|
|
$-1
|
|
|
|
|
|
|
|
Scientific E notation is allowed:
|
|
|
|
|
|
|
|
1E-6
|
|
|
|
EUR 1E3
|
|
|
|
|
|
|
|
A decimal mark (decimal point) can be written with a period or a comma:
|
|
|
|
|
|
|
|
1.23
|
|
|
|
1,23456780000009
|
|
|
|
|
|
|
|
Digit group marks
|
|
|
|
In the integer part of the quantity (left of the decimal mark), groups
|
|
|
|
of digits can optionally be separated by a "digit group mark" - a
|
|
|
|
space, comma, or period (different from the decimal mark):
|
2017-11-29 04:20:41 +03:00
|
|
|
|
2019-09-28 03:32:59 +03:00
|
|
|
$1,000,000.00
|
|
|
|
EUR 2.000.000,00
|
|
|
|
INR 9,99,99,999.00
|
|
|
|
1 000 000.9455
|
2017-11-29 04:20:41 +03:00
|
|
|
|
2019-09-28 03:32:59 +03:00
|
|
|
Note, a number containing a single group mark and no decimal mark is
|
|
|
|
ambiguous. Are these group marks or decimal marks ?
|
2016-05-28 22:58:30 +03:00
|
|
|
|
2019-09-28 03:32:59 +03:00
|
|
|
1,000
|
|
|
|
1.000
|
2016-05-28 22:58:30 +03:00
|
|
|
|
2019-09-28 03:32:59 +03:00
|
|
|
hledger will treat them both as decimal marks by default (cf #793). If
|
|
|
|
you use digit group marks, to prevent confusion and undetected typos we
|
|
|
|
recommend you write commodity directives at the top of the file to ex-
|
|
|
|
plicitly declare the decimal mark (and optionally a digit group mark).
|
|
|
|
Note, these formats ("amount styles") are specific to each commodity,
|
|
|
|
so if your data uses multiple formats, hledger can handle it:
|
2016-05-28 22:58:30 +03:00
|
|
|
|
2019-09-28 03:32:59 +03:00
|
|
|
commodity $1,000.00
|
|
|
|
commodity EUR 1.000,00
|
|
|
|
commodity INR 9,99,99,999.00
|
2019-10-01 18:59:32 +03:00
|
|
|
commodity 1 000 000.9455
|
2019-09-28 03:32:59 +03:00
|
|
|
|
|
|
|
Amount display format
|
|
|
|
For each commodity, hledger chooses a consistent format to use when
|
|
|
|
displaying amounts. (Except price amounts, which are always displayed
|
|
|
|
as written). The display format is chosen as follows:
|
|
|
|
|
|
|
|
o If there is a commodity directive for the commodity, that format is
|
|
|
|
used (see examples above).
|
|
|
|
|
|
|
|
o Otherwise the format of the first posting amount in that commodity
|
|
|
|
seen in the journal is used. But the number of decimal places ("pre-
|
|
|
|
cision") will be the maximum from all posting amounts in that comm-
|
|
|
|
modity.
|
|
|
|
|
|
|
|
o Or if there are no such amounts in the journal, a default format is
|
2016-05-28 22:58:30 +03:00
|
|
|
used (like $1000.00).
|
|
|
|
|
2019-09-28 03:32:59 +03:00
|
|
|
Price amounts, and amounts in D directives don't affect the amount dis-
|
|
|
|
play format directly, but occasionally they can do so indirectly. (Eg
|
|
|
|
when D's default commodity is applied to a commodity-less amount, or
|
|
|
|
when an amountless posting is balanced using a price's commodity, or
|
|
|
|
when -V is used.) If you find this causing problems, use a commodity
|
|
|
|
directive to set the display format.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Virtual Postings
|
2019-09-01 07:02:00 +03:00
|
|
|
When you parenthesise the account name in a posting, we call that a
|
2016-06-12 07:34:20 +03:00
|
|
|
virtual posting, which means:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
o it is ignored when checking that the transaction is balanced
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
o it is excluded from reports when the --real/-R flag is used, or the
|
2016-04-14 08:29:16 +03:00
|
|
|
real:1 query.
|
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
You could use this, eg, to set an account's opening balance without
|
2016-04-14 08:29:16 +03:00
|
|
|
needing to use the equity:opening balances account:
|
|
|
|
|
|
|
|
1/1 special unbalanced posting to set initial balance
|
|
|
|
(assets:checking) $1000
|
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
When the account name is bracketed, we call it a balanced virtual post-
|
|
|
|
ing. This is like an ordinary virtual posting except the balanced vir-
|
2019-09-01 07:02:00 +03:00
|
|
|
tual postings in a transaction must balance to 0, like the real post-
|
|
|
|
ings (but separately from them). Balanced virtual postings are also
|
2016-05-28 22:58:30 +03:00
|
|
|
excluded by --real/-R or real:1.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2016-05-28 22:58:30 +03:00
|
|
|
1/1 buy food with cash, and update some budget-tracking subaccounts elsewhere
|
|
|
|
expenses:food $10
|
|
|
|
assets:cash $-10
|
|
|
|
[assets:checking:available] $10
|
|
|
|
[assets:checking:budget:food] $-10
|
|
|
|
|
|
|
|
Virtual postings have some legitimate uses, but those are few. You can
|
2019-09-01 07:02:00 +03:00
|
|
|
usually find an equivalent journal entry using real postings, which is
|
2016-05-28 22:58:30 +03:00
|
|
|
more correct and provides better error checking.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Balance Assertions
|
2019-09-01 07:02:00 +03:00
|
|
|
hledger supports Ledger-style balance assertions in journal files.
|
|
|
|
These look like, for example, = EXPECTEDBALANCE following a posting's
|
|
|
|
amount. Eg here we assert the expected dollar balance in accounts a
|
2019-02-21 00:15:41 +03:00
|
|
|
and b after each posting:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
2013/1/1
|
|
|
|
a $1 =$1
|
|
|
|
b =$-1
|
|
|
|
|
|
|
|
2013/1/2
|
|
|
|
a $1 =$2
|
|
|
|
b $-1 =$-2
|
|
|
|
|
|
|
|
After reading a journal file, hledger will check all balance assertions
|
2019-09-01 07:02:00 +03:00
|
|
|
and report an error if any of them fail. Balance assertions can pro-
|
|
|
|
tect you from, eg, inadvertently disrupting reconciled balances while
|
|
|
|
cleaning up old entries. You can disable them temporarily with the
|
2019-02-21 00:15:41 +03:00
|
|
|
-I/--ignore-assertions flag, which can be useful for troubleshooting or
|
2016-04-14 08:29:16 +03:00
|
|
|
for reading Ledger files.
|
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Assertions and ordering
|
2019-09-01 07:02:00 +03:00
|
|
|
hledger sorts an account's postings and assertions first by date and
|
|
|
|
then (for postings on the same day) by parse order. Note this is dif-
|
2016-04-14 08:29:16 +03:00
|
|
|
ferent from Ledger, which sorts assertions only by parse order. (Also,
|
2019-09-01 07:02:00 +03:00
|
|
|
Ledger assertions do not see the accumulated effect of repeated post-
|
2016-04-14 08:29:16 +03:00
|
|
|
ings to the same account within a transaction.)
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
So, hledger balance assertions keep working if you reorder differently-
|
2019-09-01 07:02:00 +03:00
|
|
|
dated transactions within the journal. But if you reorder same-dated
|
|
|
|
transactions or postings, assertions might break and require updating.
|
2019-05-24 08:26:43 +03:00
|
|
|
This order dependence does bring an advantage: precise control over the
|
|
|
|
order of postings and assertions within a day, so you can assert intra-
|
|
|
|
day balances.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2017-01-15 04:49:26 +03:00
|
|
|
Assertions and included files
|
2019-09-01 07:02:00 +03:00
|
|
|
With included files, things are a little more complicated. Including
|
|
|
|
preserves the ordering of postings and assertions. If you have multi-
|
|
|
|
ple postings to an account on the same day, split across different
|
|
|
|
files, and you also want to assert the account's balance on the same
|
2016-04-14 08:29:16 +03:00
|
|
|
day, you'll have to put the assertion in the right file.
|
|
|
|
|
2017-01-15 04:49:26 +03:00
|
|
|
Assertions and multiple -f options
|
|
|
|
Balance assertions don't work well across files specified with multiple
|
|
|
|
-f options. Use include or concatenate the files instead.
|
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Assertions and commodities
|
2019-09-01 07:02:00 +03:00
|
|
|
The asserted balance must be a simple single-commodity amount, and in
|
|
|
|
fact the assertion checks only this commodity's balance within the
|
2018-12-03 04:26:18 +03:00
|
|
|
(possibly multi-commodity) account balance.
|
|
|
|
This is how assertions work in Ledger also. We could call this a "par-
|
|
|
|
tial" balance assertion.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-12-03 04:26:18 +03:00
|
|
|
To assert the balance of more than one commodity in an account, you can
|
|
|
|
write multiple postings, each asserting one commodity's balance.
|
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
You can make a stronger "total" balance assertion by writing a double
|
2019-02-21 00:15:41 +03:00
|
|
|
equals sign (== EXPECTEDBALANCE). This asserts that there are no other
|
|
|
|
unasserted commodities in the account (or, that their balance is 0).
|
2018-12-03 04:26:18 +03:00
|
|
|
|
|
|
|
2013/1/1
|
|
|
|
a $1
|
2019-05-24 08:26:43 +03:00
|
|
|
a 1EUR
|
2018-12-03 04:26:18 +03:00
|
|
|
b $-1
|
2019-05-24 08:26:43 +03:00
|
|
|
c -1EUR
|
2018-12-03 04:26:18 +03:00
|
|
|
|
|
|
|
2013/1/2 ; These assertions succeed
|
|
|
|
a 0 = $1
|
2019-05-24 08:26:43 +03:00
|
|
|
a 0 = 1EUR
|
2018-12-03 04:26:18 +03:00
|
|
|
b 0 == $-1
|
2019-05-24 08:26:43 +03:00
|
|
|
c 0 == -1EUR
|
2018-12-03 04:26:18 +03:00
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
2013/1/3 ; This assertion fails as 'a' also contains 1EUR
|
2018-12-03 04:26:18 +03:00
|
|
|
a 0 == $1
|
|
|
|
|
|
|
|
It's not yet possible to make a complete assertion about a balance that
|
2019-09-01 07:02:00 +03:00
|
|
|
has multiple commodities. One workaround is to isolate each commodity
|
2018-12-03 04:26:18 +03:00
|
|
|
into its own subaccount:
|
|
|
|
|
|
|
|
2013/1/1
|
|
|
|
a:usd $1
|
2019-05-24 08:26:43 +03:00
|
|
|
a:euro 1EUR
|
2018-12-03 04:26:18 +03:00
|
|
|
b
|
|
|
|
|
|
|
|
2013/1/2
|
|
|
|
a 0 == 0
|
|
|
|
a:usd 0 == $1
|
2019-05-24 08:26:43 +03:00
|
|
|
a:euro 0 == 1EUR
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-01-05 10:31:13 +03:00
|
|
|
Assertions and prices
|
2019-09-01 07:02:00 +03:00
|
|
|
Balance assertions ignore transaction prices, and should normally be
|
2019-01-27 02:56:43 +03:00
|
|
|
written without one:
|
|
|
|
|
|
|
|
2019/1/1
|
2019-05-24 08:26:43 +03:00
|
|
|
(a) $1 @ EUR1 = $1
|
2019-01-27 02:56:43 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
We do allow prices to be written there, however, and print shows them,
|
|
|
|
even though they don't affect whether the assertion passes or fails.
|
|
|
|
This is for backward compatibility (hledger's close command used to
|
|
|
|
generate balance assertions with prices), and because balance assign-
|
2019-01-27 02:56:43 +03:00
|
|
|
ments do use them (see below).
|
2019-01-05 10:31:13 +03:00
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Assertions and subaccounts
|
2019-09-01 07:02:00 +03:00
|
|
|
The balance assertions above (= and ==) do not count the balance from
|
|
|
|
subaccounts; they check the account's exclusive balance only. You can
|
2019-02-21 00:15:41 +03:00
|
|
|
assert the balance including subaccounts by writing =* or ==*, eg:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-02-21 00:15:41 +03:00
|
|
|
2019/1/1
|
|
|
|
equity:opening balances
|
|
|
|
checking:a 5
|
|
|
|
checking:b 5
|
|
|
|
checking 1 ==* 11
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Assertions and virtual postings
|
2016-04-14 08:29:16 +03:00
|
|
|
Balance assertions are checked against all postings, both real and vir-
|
|
|
|
tual. They are not affected by the --real/-R flag or real: query.
|
|
|
|
|
2019-01-20 02:29:23 +03:00
|
|
|
Assertions and precision
|
2019-09-01 07:02:00 +03:00
|
|
|
Balance assertions compare the exactly calculated amounts, which are
|
|
|
|
not always what is shown by reports. Eg a commodity directive may
|
|
|
|
limit the display precision, but this will not affect balance asser-
|
2019-01-20 02:29:23 +03:00
|
|
|
tions. Balance assertion failure messages show exact amounts.
|
|
|
|
|
2016-12-10 18:56:57 +03:00
|
|
|
Balance Assignments
|
2019-09-01 07:02:00 +03:00
|
|
|
Ledger-style balance assignments are also supported. These are like
|
|
|
|
balance assertions, but with no posting amount on the left side of the
|
|
|
|
equals sign; instead it is calculated automatically so as to satisfy
|
|
|
|
the assertion. This can be a convenience during data entry, eg when
|
2016-12-10 18:56:57 +03:00
|
|
|
setting opening balances:
|
|
|
|
|
|
|
|
; starting a new journal, set asset account balances
|
|
|
|
2016/1/1 opening balances
|
|
|
|
assets:checking = $409.32
|
|
|
|
assets:savings = $735.24
|
|
|
|
assets:cash = $42
|
|
|
|
equity:opening balances
|
|
|
|
|
|
|
|
or when adjusting a balance to reality:
|
|
|
|
|
|
|
|
; no cash left; update balance, record any untracked spending as a generic expense
|
|
|
|
2016/1/15
|
|
|
|
assets:cash = $0
|
|
|
|
expenses:misc
|
|
|
|
|
|
|
|
The calculated amount depends on the account's balance in the commodity
|
2019-09-01 07:02:00 +03:00
|
|
|
at that point (which depends on the previously-dated postings of the
|
|
|
|
commodity to that account since the last balance assertion or assign-
|
2016-12-10 18:56:57 +03:00
|
|
|
ment). Note that using balance assignments makes your journal a little
|
|
|
|
less explicit; to know the exact amount posted, you have to run hledger
|
|
|
|
or do the calculations yourself, instead of just reading it.
|
|
|
|
|
2019-01-27 02:56:43 +03:00
|
|
|
Balance assignments and prices
|
2019-09-01 07:02:00 +03:00
|
|
|
A transaction price in a balance assignment will cause the calculated
|
2019-01-27 02:56:43 +03:00
|
|
|
amount to have that price attached:
|
|
|
|
|
|
|
|
2019/1/1
|
2019-05-24 08:26:43 +03:00
|
|
|
(a) = $1 @ EUR2
|
2019-01-27 02:56:43 +03:00
|
|
|
|
|
|
|
$ hledger print --explicit
|
|
|
|
2019/01/01
|
2019-05-24 08:26:43 +03:00
|
|
|
(a) $1 @ EUR2 = $1 @ EUR2
|
2019-01-27 02:56:43 +03:00
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Transaction prices
|
2017-05-23 03:32:33 +03:00
|
|
|
Within a transaction, you can note an amount's price in another commod-
|
2019-09-01 07:02:00 +03:00
|
|
|
ity. This can be used to document the cost (in a purchase) or selling
|
|
|
|
price (in a sale). For example, transaction prices are useful to
|
|
|
|
record purchases of a foreign currency. Note transaction prices are
|
2018-06-09 03:26:58 +03:00
|
|
|
fixed at the time of the transaction, and do not change over time. See
|
|
|
|
also market prices, which represent prevailing exchange rates on a cer-
|
|
|
|
tain date.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2016-12-31 01:31:54 +03:00
|
|
|
There are several ways to record a transaction price:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2017-05-23 03:32:33 +03:00
|
|
|
1. Write the price per unit, as @ UNITPRICE after the amount:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
2009/1/1
|
2019-05-24 08:26:43 +03:00
|
|
|
assets:euros EUR100 @ $1.35 ; one hundred euros purchased at $1.35 each
|
2019-09-01 07:02:00 +03:00
|
|
|
assets:dollars ; balancing amount is -$135.00
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2017-05-23 03:32:33 +03:00
|
|
|
2. Write the total price, as @@ TOTALPRICE after the amount:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
2009/1/1
|
2019-05-24 08:26:43 +03:00
|
|
|
assets:euros EUR100 @@ $135 ; one hundred euros purchased at $135 for the lot
|
2017-05-23 03:32:33 +03:00
|
|
|
assets:dollars
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2017-05-23 03:32:33 +03:00
|
|
|
3. Specify amounts for all postings, using exactly two commodities, and
|
|
|
|
let hledger infer the price that balances the transaction:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
2009/1/1
|
2019-05-24 08:26:43 +03:00
|
|
|
assets:euros EUR100 ; one hundred euros purchased
|
2019-09-01 07:02:00 +03:00
|
|
|
assets:dollars $-135 ; for $135
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-06-09 03:26:58 +03:00
|
|
|
(Ledger users: Ledger uses a different syntax for fixed prices, {=UNIT-
|
|
|
|
PRICE}, which hledger currently ignores).
|
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
Use the -B/--cost flag to convert amounts to their transaction price's
|
2018-06-09 03:26:58 +03:00
|
|
|
commodity, if any. (mnemonic: "B" is from "cost Basis", as in Ledger).
|
|
|
|
Eg here is how -B affects the balance report for the example above:
|
2017-05-23 03:32:33 +03:00
|
|
|
|
|
|
|
$ hledger bal -N --flat
|
|
|
|
$-135 assets:dollars
|
2019-05-24 08:26:43 +03:00
|
|
|
EUR100 assets:euros
|
2017-05-23 03:32:33 +03:00
|
|
|
$ hledger bal -N --flat -B
|
|
|
|
$-135 assets:dollars
|
|
|
|
$135 assets:euros # <- the euros' cost
|
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
Note -B is sensitive to the order of postings when a transaction price
|
|
|
|
is inferred: the inferred price will be in the commodity of the last
|
2017-05-23 03:32:33 +03:00
|
|
|
amount. So if example 3's postings are reversed, while the transaction
|
|
|
|
is equivalent, -B shows something different:
|
|
|
|
|
|
|
|
2009/1/1
|
2019-09-01 07:02:00 +03:00
|
|
|
assets:dollars $-135 ; 135 dollars sold
|
2019-06-12 16:01:17 +03:00
|
|
|
assets:euros EUR100 ; for 100 euros
|
2017-05-23 03:32:33 +03:00
|
|
|
|
|
|
|
$ hledger bal -N --flat -B
|
2019-05-24 08:26:43 +03:00
|
|
|
EUR-100 assets:dollars # <- the dollars' selling price
|
|
|
|
EUR100 assets:euros
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Comments
|
2017-11-29 04:20:41 +03:00
|
|
|
Lines in the journal beginning with a semicolon (;) or hash (#) or star
|
2019-09-01 07:02:00 +03:00
|
|
|
(*) are comments, and will be ignored. (Star comments cause org-mode
|
|
|
|
nodes to be ignored, allowing emacs users to fold and navigate their
|
2017-11-29 04:20:41 +03:00
|
|
|
journals with org-mode or orgstruct-mode.)
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-13 18:26:49 +03:00
|
|
|
You can attach comments to a transaction by writing them after the de-
|
|
|
|
scription and/or indented on the following lines (before the postings).
|
|
|
|
Similarly, you can attach comments to an individual posting by writing
|
|
|
|
them after the amount and/or indented on the following lines. Transac-
|
|
|
|
tion and posting comments must begin with a semicolon (;).
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
Some examples:
|
|
|
|
|
2017-11-29 04:20:41 +03:00
|
|
|
# a file comment
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2017-11-29 04:20:41 +03:00
|
|
|
; also a file comment
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
comment
|
2017-11-29 04:20:41 +03:00
|
|
|
This is a multiline file comment,
|
2016-04-14 08:29:16 +03:00
|
|
|
which continues until a line
|
|
|
|
where the "end comment" string
|
2017-11-29 04:20:41 +03:00
|
|
|
appears on its own (or end of file).
|
2016-04-14 08:29:16 +03:00
|
|
|
end comment
|
|
|
|
|
|
|
|
2012/5/14 something ; a transaction comment
|
|
|
|
; the transaction comment, continued
|
|
|
|
posting1 1 ; a comment for posting 1
|
|
|
|
posting2
|
|
|
|
; a comment for posting 2
|
|
|
|
; another comment line for posting 2
|
2017-11-29 04:20:41 +03:00
|
|
|
; a file comment (because not indented)
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
You can also comment larger regions of a file using comment and end
|
2019-05-24 08:26:43 +03:00
|
|
|
comment directives.
|
2018-04-30 04:04:59 +03:00
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Tags
|
2019-09-01 07:02:00 +03:00
|
|
|
Tags are a way to add extra labels or labelled data to postings and
|
2017-01-17 03:26:51 +03:00
|
|
|
transactions, which you can then search or pivot on.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
A simple tag is a word (which may contain hyphens) followed by a full
|
2017-01-17 03:26:51 +03:00
|
|
|
colon, written inside a transaction or posting comment line:
|
|
|
|
|
2019-06-12 16:01:17 +03:00
|
|
|
2017/1/16 bought groceries ; sometag:
|
2017-01-17 03:26:51 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
Tags can have a value, which is the text after the colon, up to the
|
2017-01-17 03:26:51 +03:00
|
|
|
next comma or end of line, with leading/trailing whitespace removed:
|
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
expenses:food $10 ; a-posting-tag: the tag value
|
2017-01-17 03:26:51 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
Note this means hledger's tag values can not contain commas or new-
|
2017-01-17 03:26:51 +03:00
|
|
|
lines. Ending at commas means you can write multiple short tags on one
|
|
|
|
line, comma separated:
|
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
assets:checking ; a comment containing tag1:, tag2: some value ...
|
2017-01-17 03:26:51 +03:00
|
|
|
|
|
|
|
Here,
|
|
|
|
|
|
|
|
o "a comment containing" is just comment text, not a tag
|
|
|
|
|
|
|
|
o "tag1" is a tag with no value
|
|
|
|
|
|
|
|
o "tag2" is another tag, whose value is "some value ..."
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
Tags in a transaction comment affect the transaction and all of its
|
|
|
|
postings, while tags in a posting comment affect only that posting.
|
|
|
|
For example, the following transaction has three tags (A, TAG2, third-
|
2019-05-24 08:26:43 +03:00
|
|
|
tag) and the posting has four (those plus posting-tag):
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
1/1 a transaction ; A:, TAG2:
|
2017-01-17 03:26:51 +03:00
|
|
|
; third-tag: a third transaction tag, <- with a value
|
2016-04-14 08:29:16 +03:00
|
|
|
(a) $1 ; posting-tag:
|
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
Tags are like Ledger's metadata feature, except hledger's tag values
|
2016-05-28 22:58:30 +03:00
|
|
|
are simple strings.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
Directives
|
2019-09-01 07:02:00 +03:00
|
|
|
A directive is a line in the journal beginning with a special keyword,
|
2018-07-01 00:08:48 +03:00
|
|
|
that influences how the journal is processed. hledger's directives are
|
|
|
|
based on a subset of Ledger's, but there are many differences (and also
|
|
|
|
some differences between hledger versions).
|
|
|
|
|
|
|
|
Directives' behaviour and interactions can get a little bit complex, so
|
2019-09-01 07:02:00 +03:00
|
|
|
here is a table summarising the directives and their effects, with
|
2018-07-01 00:08:48 +03:00
|
|
|
links to more detailed docs.
|
|
|
|
|
2019-09-13 18:26:49 +03:00
|
|
|
direc- end di- subdi- purpose can affect (as of
|
|
|
|
tive rective rec- 2018/06)
|
2019-05-24 08:26:43 +03:00
|
|
|
tives
|
|
|
|
------------------------------------------------------------------------------------
|
2019-09-13 18:26:49 +03:00
|
|
|
account any document account names, de- all entries in all
|
|
|
|
text clare account types & dis- files, before or
|
2019-09-02 21:11:56 +03:00
|
|
|
play order after
|
2019-09-13 18:26:49 +03:00
|
|
|
alias end rewrite account names following in-
|
|
|
|
aliases line/included en-
|
|
|
|
tries until end of
|
|
|
|
current file or end
|
|
|
|
directive
|
|
|
|
apply end apply prepend a common parent to following in-
|
|
|
|
account account account names line/included en-
|
|
|
|
tries until end of
|
|
|
|
current file or end
|
|
|
|
directive
|
|
|
|
comment end com- ignore part of journal following in-
|
|
|
|
ment line/included en-
|
|
|
|
tries until end of
|
|
|
|
current file or end
|
|
|
|
directive
|
2019-09-02 21:11:56 +03:00
|
|
|
commod- format declare a commodity and its number notation:
|
2019-05-24 08:26:43 +03:00
|
|
|
ity number notation & display following entries
|
|
|
|
style in that commodity
|
2019-09-02 21:11:56 +03:00
|
|
|
in all files; dis-
|
2019-05-24 08:26:43 +03:00
|
|
|
play style: amounts
|
|
|
|
of that commodity
|
|
|
|
in reports
|
2019-09-02 21:11:56 +03:00
|
|
|
D declare a commodity, number commodity: all com-
|
2019-05-24 08:26:43 +03:00
|
|
|
notation & display style for modityless entries
|
2019-09-02 21:11:56 +03:00
|
|
|
commodityless amounts in all files; num-
|
|
|
|
ber notation: fol-
|
2019-05-24 08:26:43 +03:00
|
|
|
lowing commodity-
|
2019-09-02 21:11:56 +03:00
|
|
|
less entries and
|
2019-05-24 08:26:43 +03:00
|
|
|
entries in that
|
2019-09-02 21:11:56 +03:00
|
|
|
commodity in all
|
2019-05-24 08:26:43 +03:00
|
|
|
files; display
|
|
|
|
style: amounts of
|
|
|
|
that commodity in
|
|
|
|
reports
|
|
|
|
include include entries/directives what the included
|
|
|
|
from another file directives affect
|
|
|
|
P declare a market price for a amounts of that
|
2019-09-13 18:26:49 +03:00
|
|
|
commodity commodity in re-
|
|
|
|
ports, when -V is
|
2019-05-24 08:26:43 +03:00
|
|
|
used
|
2019-09-13 18:26:49 +03:00
|
|
|
Y declare a year for yearless following in-
|
|
|
|
dates line/included en-
|
|
|
|
tries until end of
|
|
|
|
current file
|
2018-07-01 00:08:48 +03:00
|
|
|
|
|
|
|
And some definitions:
|
|
|
|
|
2018-12-03 04:26:18 +03:00
|
|
|
subdirec- optional indented directive line immediately following a par-
|
|
|
|
tive ent directive
|
2019-09-02 21:11:56 +03:00
|
|
|
number how to interpret numbers when parsing journal entries (the
|
|
|
|
notation identity of the decimal separator character). (Currently
|
|
|
|
each commodity can have its own notation, even in the same
|
2018-07-01 00:08:48 +03:00
|
|
|
file.)
|
|
|
|
display how to display amounts of a commodity in reports (symbol side
|
|
|
|
style and spacing, digit groups, decimal separator, decimal places)
|
2019-09-28 03:32:59 +03:00
|
|
|
|
|
|
|
|
2018-07-01 00:08:48 +03:00
|
|
|
directive which entries and (when there are multiple files) which files
|
|
|
|
scope are affected by a directive
|
|
|
|
|
|
|
|
As you can see, directives vary in which journal entries and files they
|
2019-09-13 18:26:49 +03:00
|
|
|
affect, and whether they are focussed on input (parsing) or output (re-
|
|
|
|
ports). Some directives have multiple effects.
|
2018-07-01 00:08:48 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
If you have a journal made up of multiple files, or pass multiple -f
|
|
|
|
options on the command line, note that directives which affect input
|
|
|
|
typically last only until the end of their defining file. This pro-
|
2018-07-01 00:08:48 +03:00
|
|
|
vides more simplicity and predictability, eg reports are not changed by
|
2019-09-01 07:02:00 +03:00
|
|
|
writing file options in a different order. It can be surprising at
|
2018-07-01 00:08:48 +03:00
|
|
|
times though.
|
2018-06-09 03:26:58 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
Comment blocks
|
2019-09-01 07:02:00 +03:00
|
|
|
A line containing just comment starts a commented region of the file,
|
2018-04-30 04:04:59 +03:00
|
|
|
and a line containing just end comment (or the end of the current file)
|
|
|
|
ends it. See also comments.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
Including other files
|
2019-09-01 07:02:00 +03:00
|
|
|
You can pull in the content of additional files by writing an include
|
2018-04-30 04:04:59 +03:00
|
|
|
directive, like this:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
include path/to/file.journal
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
If the path does not begin with a slash, it is relative to the current
|
|
|
|
file. The include file path may contain common glob patterns (e.g.
|
2018-07-25 00:49:47 +03:00
|
|
|
*).
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-13 18:26:49 +03:00
|
|
|
The include directive can only be used in journal files. It can in-
|
|
|
|
clude journal, timeclock or timedot files, but not CSV files.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
Default year
|
2019-09-01 07:02:00 +03:00
|
|
|
You can set a default year to be used for subsequent dates which don't
|
|
|
|
specify a year. This is a line beginning with Y followed by the year.
|
2018-04-30 04:04:59 +03:00
|
|
|
Eg:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
Y2009 ; set default year to 2009
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
12/15 ; equivalent to 2009/12/15
|
2018-04-30 04:04:59 +03:00
|
|
|
expenses 1
|
|
|
|
assets
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
Y2010 ; change default year to 2010
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
2009/1/30 ; specifies the year, not affected
|
|
|
|
expenses 1
|
|
|
|
assets
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
1/31 ; equivalent to 2010/1/31
|
2018-04-30 04:04:59 +03:00
|
|
|
expenses 1
|
|
|
|
assets
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
Declaring commodities
|
2019-09-01 07:02:00 +03:00
|
|
|
The commodity directive declares commodities which may be used in the
|
|
|
|
journal, and their display format.
|
|
|
|
|
|
|
|
It may be written on a single line, like this:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
; commodity EXAMPLEAMOUNT
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
; display AAAA amounts with the symbol on the right, space-separated,
|
|
|
|
; using period as decimal point, with four decimal places, and
|
|
|
|
; separating thousands with comma.
|
|
|
|
commodity 1,000.0000 AAAA
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
or on multiple lines, using the "format" subdirective. In this case
|
|
|
|
the commodity symbol appears twice and should be the same in both
|
2018-04-30 04:04:59 +03:00
|
|
|
places:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
; commodity SYMBOL
|
|
|
|
; format EXAMPLEAMOUNT
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
; display indian rupees with currency name on the left,
|
|
|
|
; thousands, lakhs and crores comma-separated,
|
|
|
|
; period as decimal point, and two decimal places.
|
|
|
|
commodity INR
|
|
|
|
format INR 9,99,99,999.00
|
2017-09-30 08:31:44 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
Declaring commodites may be useful as documentation, but currently we
|
|
|
|
do not enforce that only declared commodities may be used. This direc-
|
|
|
|
tive is mainly useful for customising the preferred display format for
|
|
|
|
a commodity.
|
|
|
|
|
|
|
|
Normally the display format is inferred from journal entries, but this
|
|
|
|
can be unpredictable; declaring it with a commodity directive overrides
|
2019-09-13 18:26:49 +03:00
|
|
|
this and removes ambiguity. Towards this end, amounts in commodity di-
|
|
|
|
rectives must always be written with a decimal point (a period or
|
2019-09-01 07:02:00 +03:00
|
|
|
comma, followed by 0 or more decimal digits).
|
|
|
|
|
|
|
|
Commodity directives do not affect how amounts are parsed; the parser
|
|
|
|
will read multiple formats.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
Default commodity
|
2019-05-24 08:26:43 +03:00
|
|
|
The D directive sets a default commodity (and display format), to be
|
2018-04-30 04:04:59 +03:00
|
|
|
used for amounts without a commodity symbol (ie, plain numbers). (Note
|
2019-05-24 08:26:43 +03:00
|
|
|
this differs from Ledger's default commodity directive.) The commodity
|
|
|
|
and display format will be applied to all subsequent commodity-less
|
2018-04-30 04:04:59 +03:00
|
|
|
amounts, or until the next D directive.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
; commodity-less amounts should be treated as dollars
|
|
|
|
; (and displayed with symbol on the left, thousands separators and two decimal places)
|
2018-04-30 04:04:59 +03:00
|
|
|
D $1,000.00
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
1/1
|
2019-09-01 07:02:00 +03:00
|
|
|
a 5 ; <- commodity-less amount, becomes $1
|
2018-04-30 04:04:59 +03:00
|
|
|
b
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
As with the commodity directive, the amount must always be written with
|
|
|
|
a decimal point.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-06-09 03:26:58 +03:00
|
|
|
Market prices
|
2019-09-13 18:26:49 +03:00
|
|
|
The P directive declares a market price, which is an exchange rate be-
|
|
|
|
tween two commodities on a certain date. (In Ledger, they are called
|
2019-05-24 08:26:43 +03:00
|
|
|
"historical prices".) These are often obtained from a stock exchange,
|
2018-06-09 03:26:58 +03:00
|
|
|
cryptocurrency exchange, or the foreign exchange market.
|
|
|
|
|
|
|
|
Here is the format:
|
|
|
|
|
|
|
|
P DATE COMMODITYA COMMODITYBAMOUNT
|
|
|
|
|
|
|
|
o DATE is a simple date
|
|
|
|
|
|
|
|
o COMMODITYA is the symbol of the commodity being priced
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
o COMMODITYBAMOUNT is an amount (symbol and quantity) in a second com-
|
2018-06-09 03:26:58 +03:00
|
|
|
modity, giving the price in commodity B of one unit of commodity A.
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
These two market price directives say that one euro was worth 1.35 US
|
2018-06-09 03:26:58 +03:00
|
|
|
dollars during 2009, and $1.40 from 2010 onward:
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
P 2009/1/1 EUR $1.35
|
|
|
|
P 2010/1/1 EUR $1.40
|
2018-06-09 03:26:58 +03:00
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
The -V/--value flag can be used to convert reported amounts to another
|
2018-06-09 03:26:58 +03:00
|
|
|
commodity using these prices.
|
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
Declaring accounts
|
2019-09-13 18:26:49 +03:00
|
|
|
account directives can be used to pre-declare accounts. Though not re-
|
|
|
|
quired, they can provide several benefits:
|
2018-12-03 04:26:18 +03:00
|
|
|
|
|
|
|
o They can document your intended chart of accounts, providing a refer-
|
|
|
|
ence.
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
o They can store extra information about accounts (account numbers,
|
2018-12-03 04:26:18 +03:00
|
|
|
notes, etc.)
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
o They can help hledger know your accounts' types (asset, liability,
|
|
|
|
equity, revenue, expense), useful for reports like balancesheet and
|
2018-12-03 04:26:18 +03:00
|
|
|
incomestatement.
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
o They control account display order in reports, allowing non-alpha-
|
2018-12-03 04:26:18 +03:00
|
|
|
betic sorting (eg Revenues to appear above Expenses).
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
o They help with account name completion in the add command, hledger-
|
|
|
|
iadd, hledger-web, ledger-mode etc.
|
2018-12-03 04:26:18 +03:00
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
The simplest form is just the word account followed by a hledger-style
|
2019-01-23 00:36:11 +03:00
|
|
|
account name, eg:
|
2018-12-03 04:26:18 +03:00
|
|
|
|
2019-01-23 00:36:11 +03:00
|
|
|
account assets:bank:checking
|
|
|
|
|
|
|
|
Account comments
|
|
|
|
Comments, beginning with a semicolon, optionally including tags, can be
|
|
|
|
written after the account name, and/or on following lines. Eg:
|
|
|
|
|
|
|
|
account assets:bank:checking ; a comment
|
|
|
|
; another comment
|
|
|
|
; acctno:12345, a tag
|
2018-12-03 04:26:18 +03:00
|
|
|
|
2019-01-23 00:36:11 +03:00
|
|
|
Tip: comments on the same line require hledger 1.12+. If you need your
|
|
|
|
journal to be compatible with older hledger versions, write comments on
|
|
|
|
the next line instead.
|
|
|
|
|
|
|
|
Account subdirectives
|
2019-05-24 08:26:43 +03:00
|
|
|
We also allow (and ignore) Ledger-style indented subdirectives, just
|
2019-01-23 00:36:11 +03:00
|
|
|
for compatibility.:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
account assets:bank:checking
|
2019-01-23 00:36:11 +03:00
|
|
|
format blah blah ; <- subdirective, ignored
|
|
|
|
|
|
|
|
Here is the full syntax of account directives:
|
|
|
|
|
|
|
|
account ACCTNAME [ACCTTYPE] [;COMMENT]
|
|
|
|
[;COMMENTS]
|
|
|
|
[LEDGER-STYLE SUBDIRECTIVES, IGNORED]
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-12-03 04:26:18 +03:00
|
|
|
Account types
|
2019-05-24 08:26:43 +03:00
|
|
|
hledger recognises five types (or classes) of account: Asset, Liabil-
|
|
|
|
ity, Equity, Revenue, Expense. This is used by a few accounting-aware
|
2019-01-23 00:36:11 +03:00
|
|
|
reports such as balancesheet, incomestatement and cashflow.
|
2018-12-03 04:26:18 +03:00
|
|
|
|
2019-01-23 00:36:11 +03:00
|
|
|
Auto-detected account types
|
2018-12-03 04:26:18 +03:00
|
|
|
If you name your top-level accounts with some variation of assets, lia-
|
2019-05-24 08:26:43 +03:00
|
|
|
bilities/debts, equity, revenues/income, or expenses, their types are
|
2018-12-03 04:26:18 +03:00
|
|
|
detected automatically.
|
|
|
|
|
2019-01-23 00:36:11 +03:00
|
|
|
Account types declared with tags
|
2019-09-13 18:26:49 +03:00
|
|
|
More generally, you can declare an account's type with an account di-
|
|
|
|
rective, by writing a type: tag in a comment, followed by one of the
|
2019-01-23 00:36:11 +03:00
|
|
|
words Asset, Liability, Equity, Revenue, Expense, or one of the letters
|
|
|
|
ALERX (case insensitive):
|
|
|
|
|
|
|
|
account assets ; type:Asset
|
|
|
|
account liabilities ; type:Liability
|
|
|
|
account equity ; type:Equity
|
|
|
|
account revenues ; type:Revenue
|
|
|
|
account expenses ; type:Expenses
|
|
|
|
|
|
|
|
Account types declared with account type codes
|
2019-05-24 08:26:43 +03:00
|
|
|
Or, you can write one of those letters separated from the account name
|
|
|
|
by two or more spaces, but this should probably be considered depre-
|
2019-01-23 00:36:11 +03:00
|
|
|
cated as of hledger 1.13:
|
2018-12-03 04:26:18 +03:00
|
|
|
|
|
|
|
account assets A
|
|
|
|
account liabilities L
|
|
|
|
account equity E
|
|
|
|
account revenues R
|
|
|
|
account expenses X
|
2018-01-24 03:41:19 +03:00
|
|
|
|
2019-01-23 00:36:11 +03:00
|
|
|
Overriding auto-detected types
|
2019-05-24 08:26:43 +03:00
|
|
|
If you ever override the types of those auto-detected english account
|
2019-01-23 00:36:11 +03:00
|
|
|
names mentioned above, you might need to help the reports a bit. Eg:
|
2018-01-24 03:41:19 +03:00
|
|
|
|
2019-01-23 00:36:11 +03:00
|
|
|
; make "liabilities" not have the liability type - who knows why
|
2019-09-01 07:02:00 +03:00
|
|
|
account liabilities ; type:E
|
2018-12-03 04:26:18 +03:00
|
|
|
|
2019-01-23 00:36:11 +03:00
|
|
|
; we need to ensure some other account has the liability type,
|
2018-12-03 04:26:18 +03:00
|
|
|
; otherwise balancesheet would still show "liabilities" under Liabilities
|
2019-09-01 07:02:00 +03:00
|
|
|
account - ; type:L
|
2018-07-01 00:08:48 +03:00
|
|
|
|
2018-12-03 04:26:18 +03:00
|
|
|
Account display order
|
2019-05-24 08:26:43 +03:00
|
|
|
Account directives also set the order in which accounts are displayed,
|
|
|
|
eg in reports, the hledger-ui accounts screen, and the hledger-web
|
2019-01-23 00:36:11 +03:00
|
|
|
sidebar. By default accounts are listed in alphabetical order. But if
|
|
|
|
you have these account directives in the journal:
|
2018-07-01 00:08:48 +03:00
|
|
|
|
2018-10-01 09:08:15 +03:00
|
|
|
account assets
|
|
|
|
account liabilities
|
|
|
|
account equity
|
|
|
|
account revenues
|
|
|
|
account expenses
|
2018-07-01 00:08:48 +03:00
|
|
|
|
2019-01-23 00:36:11 +03:00
|
|
|
you'll see those accounts displayed in declaration order, not alphabet-
|
|
|
|
ically:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-12-03 04:26:18 +03:00
|
|
|
$ hledger accounts -1
|
2018-10-01 09:08:15 +03:00
|
|
|
assets
|
|
|
|
liabilities
|
|
|
|
equity
|
|
|
|
revenues
|
|
|
|
expenses
|
2018-01-24 03:41:19 +03:00
|
|
|
|
2018-12-03 04:26:18 +03:00
|
|
|
Undeclared accounts, if any, are displayed last, in alphabetical order.
|
2018-01-24 03:41:19 +03:00
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
Note that sorting is done at each level of the account tree (within
|
|
|
|
each group of sibling accounts under the same parent). And currently,
|
2018-12-03 04:26:18 +03:00
|
|
|
this directive:
|
2018-10-01 09:08:15 +03:00
|
|
|
|
|
|
|
account other:zoo
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
would influence the position of zoo among other's subaccounts, but not
|
|
|
|
the position of other among the top-level accounts. This means: - you
|
|
|
|
will sometimes declare parent accounts (eg account other above) that
|
|
|
|
you don't intend to post to, just to customize their display order -
|
2018-12-03 04:26:18 +03:00
|
|
|
sibling accounts stay together (you couldn't display x:y in between a:b
|
|
|
|
and a:c).
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
Rewriting accounts
|
2018-07-01 00:08:48 +03:00
|
|
|
You can define account alias rules which rewrite your account names, or
|
|
|
|
parts of them, before generating reports. This can be useful for:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
o expanding shorthand account names to their full form, allowing easier
|
|
|
|
data entry and a less verbose journal
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
o adapting old journals to your current chart of accounts
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
o experimenting with new account organisations, like a new hierarchy or
|
|
|
|
combining two accounts into one
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
o customising reports
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-07-01 00:08:48 +03:00
|
|
|
Account aliases also rewrite account names in account directives. They
|
2019-09-02 21:11:56 +03:00
|
|
|
do not affect account names being entered via hledger add or hledger-
|
2019-05-24 08:26:43 +03:00
|
|
|
web.
|
2018-07-01 00:08:48 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
See also Cookbook: Rewrite account names.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
Basic aliases
|
2019-09-02 21:11:56 +03:00
|
|
|
To set an account alias, use the alias directive in your journal file.
|
|
|
|
This affects all subsequent journal entries in the current file or its
|
2018-04-30 04:04:59 +03:00
|
|
|
included files. The spaces around the = are optional:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
alias OLD = NEW
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
Or, you can use the --alias 'OLD=NEW' option on the command line. This
|
|
|
|
affects all entries. It's useful for trying out aliases interactively.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-13 18:26:49 +03:00
|
|
|
OLD and NEW are case sensitive full account names. hledger will re-
|
|
|
|
place any occurrence of the old account name with the new one. Subac-
|
|
|
|
counts are also affected. Eg:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
alias checking = assets:bank:wells fargo:checking
|
2019-09-02 21:11:56 +03:00
|
|
|
; rewrites "checking" to "assets:bank:wells fargo:checking", or "checking:a" to "assets:bank:wells fargo:checking:a"
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
Regex aliases
|
2019-05-24 08:26:43 +03:00
|
|
|
There is also a more powerful variant that uses a regular expression,
|
2018-04-30 04:04:59 +03:00
|
|
|
indicated by the forward slashes:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
alias /REGEX/ = REPLACEMENT
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
or --alias '/REGEX/=REPLACEMENT'.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
REGEX is a case-insensitive regular expression. Anywhere it matches
|
|
|
|
inside an account name, the matched part will be replaced by REPLACE-
|
|
|
|
MENT. If REGEX contains parenthesised match groups, these can be ref-
|
2018-04-30 04:04:59 +03:00
|
|
|
erenced by the usual numeric backreferences in REPLACEMENT. Eg:
|
2016-05-28 22:58:30 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
alias /^(.+):bank:([^:]+)(.*)/ = \1:\2 \3
|
2019-09-02 21:11:56 +03:00
|
|
|
; rewrites "assets:bank:wells fargo:checking" to "assets:wells fargo checking"
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
Also note that REPLACEMENT continues to the end of line (or on command
|
|
|
|
line, to end of option argument), so it can contain trailing white-
|
2018-04-30 04:04:59 +03:00
|
|
|
space.
|
2018-04-26 03:43:34 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
Combining aliases
|
|
|
|
You can define as many aliases as you like, using journal directives
|
|
|
|
and/or command line options.
|
|
|
|
|
|
|
|
Recursive aliases - where an account name is rewritten by one alias,
|
|
|
|
then by another alias, and so on - are allowed. Each alias sees the
|
|
|
|
effect of previously applied aliases.
|
|
|
|
|
|
|
|
In such cases it can be important to understand which aliases will be
|
|
|
|
applied and in which order. For (each account name in) each journal
|
|
|
|
entry, we apply:
|
|
|
|
|
|
|
|
1. alias directives preceding the journal entry, most recently parsed
|
|
|
|
first (ie, reading upward from the journal entry, bottom to top)
|
|
|
|
|
|
|
|
2. --alias options, in the order they appeared on the command line
|
|
|
|
(left to right).
|
2016-09-13 19:11:08 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
In other words, for (an account name in) a given journal entry:
|
2016-09-13 19:11:08 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
o the nearest alias declaration before/above the entry is applied first
|
|
|
|
|
|
|
|
o the next alias before/above that will be be applied next, and so on
|
|
|
|
|
|
|
|
o aliases defined after/below the entry do not affect it.
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
This gives nearby aliases precedence over distant ones, and helps pro-
|
|
|
|
vide semantic stability - aliases will keep working the same way inde-
|
2019-09-01 07:02:00 +03:00
|
|
|
pendent of which files are being read and in which order.
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
In case of trouble, adding --debug=6 to the command line will show
|
2019-09-01 07:02:00 +03:00
|
|
|
which aliases are being applied when.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
end aliases
|
2019-09-02 21:11:56 +03:00
|
|
|
You can clear (forget) all currently defined aliases with the end
|
2019-05-24 08:26:43 +03:00
|
|
|
aliases directive:
|
2018-04-26 03:43:34 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
end aliases
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
Default parent account
|
2019-09-13 18:26:49 +03:00
|
|
|
You can specify a parent account which will be prepended to all ac-
|
|
|
|
counts within a section of the journal. Use the apply account and end
|
|
|
|
apply account directives like so:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
apply account home
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
2010/1/1
|
|
|
|
food $10
|
|
|
|
cash
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
end apply account
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
which is equivalent to:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
2010/01/01
|
|
|
|
home:food $10
|
|
|
|
home:cash $-10
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
If end apply account is omitted, the effect lasts to the end of the
|
2018-04-30 04:04:59 +03:00
|
|
|
file. Included files are also affected, eg:
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
apply account business
|
|
|
|
include biz.journal
|
|
|
|
end apply account
|
|
|
|
apply account personal
|
|
|
|
include personal.journal
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
Prior to hledger 1.0, legacy account and end spellings were also sup-
|
2018-04-30 04:04:59 +03:00
|
|
|
ported.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
A default parent account also affects account directives. It does not
|
|
|
|
affect account names being entered via hledger add or hledger-web. If
|
|
|
|
account aliases are present, they are applied after the default parent
|
2018-07-01 00:08:48 +03:00
|
|
|
account.
|
|
|
|
|
2018-04-30 04:04:59 +03:00
|
|
|
Periodic transactions
|
2019-09-13 18:26:49 +03:00
|
|
|
Periodic transaction rules describe transactions that recur. They al-
|
|
|
|
low hledger to generate temporary future transactions to help with
|
2019-09-09 18:02:49 +03:00
|
|
|
forecasting, so you don't have to write out each one in the journal,
|
|
|
|
and it's easy to try out different forecasts. Secondly, they are also
|
|
|
|
used to define the budgets shown in budget reports.
|
2018-06-09 05:52:45 +03:00
|
|
|
|
2019-09-09 18:02:49 +03:00
|
|
|
Periodic transactions can be a little tricky, so before you use them,
|
|
|
|
read this whole section - or at least these tips:
|
|
|
|
|
|
|
|
1. Two spaces accidentally added or omitted will cause you trouble -
|
|
|
|
read about this below.
|
|
|
|
|
|
|
|
2. For troubleshooting, show the generated transactions with hledger
|
|
|
|
print --forecast tag:generated or hledger register --forecast
|
|
|
|
tag:generated.
|
|
|
|
|
|
|
|
3. Forecasted transactions will begin only after the last non-fore-
|
|
|
|
casted transaction's date.
|
|
|
|
|
|
|
|
4. Forecasted transactions will end 6 months from today, by default.
|
|
|
|
See below for the exact start/end rules.
|
|
|
|
|
2019-09-13 18:26:49 +03:00
|
|
|
5. period expressions can be tricky. Their documentation needs im-
|
|
|
|
provement, but is worth studying.
|
2019-09-09 18:02:49 +03:00
|
|
|
|
|
|
|
6. Some period expressions with a repeating interval must begin on a
|
|
|
|
natural boundary of that interval. Eg in weekly from DATE, DATE
|
|
|
|
must be a monday. ~ weekly from 2019/10/1 (a tuesday) will give an
|
|
|
|
error.
|
|
|
|
|
|
|
|
7. Other period expressions with an interval are automatically expanded
|
|
|
|
to cover a whole number of that interval. (This is done to improve
|
|
|
|
reports, but it also affects periodic transactions. Yes, it's a bit
|
|
|
|
inconsistent with the above.) Eg: ~ every 10th day of month from
|
|
|
|
2020/01, which is equivalent to ~ every 10th day of month from
|
|
|
|
2020/01/01, will be adjusted to start on 2019/12/10.
|
|
|
|
|
|
|
|
Periodic rule syntax
|
2018-07-01 00:08:48 +03:00
|
|
|
A periodic transaction rule looks like a normal journal entry, with the
|
|
|
|
date replaced by a tilde (~) followed by a period expression (mnemonic:
|
2018-07-31 18:02:51 +03:00
|
|
|
~ looks like a recurring sine wave.):
|
2018-06-09 05:52:45 +03:00
|
|
|
|
|
|
|
~ monthly
|
|
|
|
expenses:rent $2000
|
|
|
|
assets:bank:checking
|
2018-04-30 04:04:59 +03:00
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
There is an additional constraint on the period expression: the start
|
|
|
|
date must fall on a natural boundary of the interval. Eg monthly from
|
|
|
|
2018/1/1 is valid, but monthly from 2018/1/15 is not.
|
2018-04-30 04:04:59 +03:00
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
Partial or relative dates (M/D, D, tomorrow, last week) in the period
|
|
|
|
expression can work (useful or not). They will be relative to today's
|
|
|
|
date, unless a Y default year directive is in effect, in which case
|
2018-12-03 04:26:18 +03:00
|
|
|
they will be relative to Y/1/1.
|
|
|
|
|
2019-09-09 18:02:49 +03:00
|
|
|
Two spaces between period expression and description!
|
2019-05-24 08:26:43 +03:00
|
|
|
If the period expression is followed by a transaction description,
|
2019-01-20 02:29:23 +03:00
|
|
|
these must be separated by two or more spaces. This helps hledger know
|
|
|
|
where the period expression ends, so that descriptions can not acciden-
|
|
|
|
tally alter their meaning, as in this example:
|
|
|
|
|
|
|
|
; 2 or more spaces needed here, so the period is not understood as "every 2 months in 2020"
|
|
|
|
; ||
|
|
|
|
; vv
|
|
|
|
~ every 2 months in 2020, we will review
|
2018-06-09 05:52:45 +03:00
|
|
|
assets:bank:checking $1500
|
|
|
|
income:acme inc
|
|
|
|
|
2019-09-09 18:02:49 +03:00
|
|
|
So,
|
|
|
|
|
|
|
|
o Do write two spaces between your period expression and your transac-
|
|
|
|
tion description, if any.
|
|
|
|
|
2019-09-13 18:26:49 +03:00
|
|
|
o Don't accidentally write two spaces in the middle of your period ex-
|
|
|
|
pression.
|
2019-09-09 18:02:49 +03:00
|
|
|
|
2018-07-01 00:08:48 +03:00
|
|
|
Forecasting with periodic transactions
|
2019-09-13 18:26:49 +03:00
|
|
|
With the --forecast flag, each periodic transaction rule generates fu-
|
|
|
|
ture transactions recurring at the specified interval. These are not
|
2019-05-24 08:26:43 +03:00
|
|
|
saved in the journal, but appear in all reports. They will look like
|
2019-09-01 07:02:00 +03:00
|
|
|
normal transactions, but with an extra tag:
|
|
|
|
|
|
|
|
o generated-transaction:~ PERIODICEXPR - shows that this was generated
|
|
|
|
by a periodic transaction rule, and the period
|
|
|
|
|
|
|
|
There is also a hidden tag, with an underscore prefix, which does not
|
|
|
|
appear in hledger's output:
|
|
|
|
|
|
|
|
o _generated-transaction:~ PERIODICEXPR
|
|
|
|
|
|
|
|
This can be used to match transactions generated "just now", rather
|
|
|
|
than generated in the past and saved to the journal.
|
2018-07-01 00:08:48 +03:00
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
Forecast transactions start on the first occurrence, and end on the
|
|
|
|
last occurrence, of their interval within the forecast period. The
|
2018-07-04 14:51:10 +03:00
|
|
|
forecast period:
|
2018-07-01 00:08:48 +03:00
|
|
|
|
2018-07-04 14:51:10 +03:00
|
|
|
o begins on the later of
|
2018-07-01 00:08:48 +03:00
|
|
|
|
2018-07-04 14:51:10 +03:00
|
|
|
o the report start date if specified with -b/-p/date:
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
o the day after the latest normal (non-periodic) transaction in the
|
2018-07-04 14:51:10 +03:00
|
|
|
journal, or today if there are no normal transactions.
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
o ends on the report end date if specified with -e/-p/date:, or 180
|
2018-07-04 14:51:10 +03:00
|
|
|
days from today.
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
where "today" means the current date at report time. The "later of"
|
|
|
|
rule ensures that forecast transactions do not overlap normal transac-
|
2018-07-04 14:51:10 +03:00
|
|
|
tions in time; they will begin only after normal transactions end.
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
Forecasting can be useful for estimating balances into the future, and
|
|
|
|
experimenting with different scenarios. Note the start date logic
|
2018-07-01 00:08:48 +03:00
|
|
|
means that forecasted transactions are automatically replaced by normal
|
|
|
|
transactions as you add those.
|
|
|
|
|
|
|
|
Forecasting can also help with data entry: describe most of your trans-
|
2019-05-24 08:26:43 +03:00
|
|
|
actions with periodic rules, and every so often copy the output of
|
2018-07-01 00:08:48 +03:00
|
|
|
print --forecast to the journal.
|
|
|
|
|
|
|
|
You can generate one-time transactions too: just write a period expres-
|
2019-05-24 08:26:43 +03:00
|
|
|
sion specifying a date with no report interval. (You could also write
|
|
|
|
a normal transaction with a future date, but remember this disables
|
2018-07-01 00:08:48 +03:00
|
|
|
forecast transactions on previous dates.)
|
|
|
|
|
|
|
|
Budgeting with periodic transactions
|
2019-05-24 08:26:43 +03:00
|
|
|
With the --budget flag, currently supported by the balance command,
|
|
|
|
each periodic transaction rule declares recurring budget goals for the
|
|
|
|
specified accounts. Eg the first example above declares a goal of
|
|
|
|
spending $2000 on rent (and also, a goal of depositing $2000 into
|
|
|
|
checking) every month. Goals and actual performance can then be com-
|
2018-06-09 05:52:45 +03:00
|
|
|
pared in budget reports.
|
2018-02-16 22:09:37 +03:00
|
|
|
|
2019-09-09 18:02:49 +03:00
|
|
|
For more details, see: balance: Budget report and Budgeting and Fore-
|
|
|
|
casting.
|
2018-02-16 22:09:37 +03:00
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
Auto postings / transaction modifiers
|
2019-09-01 07:02:00 +03:00
|
|
|
Transaction modifier rules, AKA auto posting rules, describe changes to
|
|
|
|
be applied automatically to certain matched transactions. Currently
|
|
|
|
just one kind of change is possible - adding extra postings, which we
|
|
|
|
call "automated postings" or just "auto postings". These rules become
|
|
|
|
active when you use the --auto flag.
|
2019-02-02 03:06:09 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
A transaction modifier rule looks much like a normal transaction except
|
|
|
|
the first line is an equals sign followed by a query that matches cer-
|
|
|
|
tain postings (mnemonic: = suggests matching). And each "posting" is
|
|
|
|
actually a posting-generating rule:
|
2017-12-15 05:20:07 +03:00
|
|
|
|
2018-12-03 04:26:18 +03:00
|
|
|
= QUERY
|
|
|
|
ACCT AMT
|
|
|
|
ACCT [AMT]
|
|
|
|
...
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
These posting-generating rules look like normal postings, except the
|
|
|
|
amount can be:
|
2017-12-15 05:20:07 +03:00
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
o a normal amount with a commodity symbol, eg $2. This will be used
|
2018-12-03 04:26:18 +03:00
|
|
|
as-is.
|
2017-12-15 05:20:07 +03:00
|
|
|
|
2018-12-03 04:26:18 +03:00
|
|
|
o a number, eg 2. The commodity symbol (if any) from the matched post-
|
|
|
|
ing will be added to this.
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
o a numeric multiplier, eg *2 (a star followed by a number N). The
|
2018-12-03 04:26:18 +03:00
|
|
|
matched posting's amount (and total price, if any) will be multiplied
|
|
|
|
by N.
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
o a multiplier with a commodity symbol, eg *$2 (a star, number N, and
|
2018-12-03 04:26:18 +03:00
|
|
|
symbol S). The matched posting's amount will be multiplied by N, and
|
|
|
|
its commodity symbol will be replaced with S.
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
These rules have global effect - a rule appearing anywhere in your data
|
|
|
|
can potentially affect any transaction, including transactions recorded
|
|
|
|
above it or in another file.
|
|
|
|
|
2018-12-03 04:26:18 +03:00
|
|
|
Some examples:
|
2017-12-15 05:20:07 +03:00
|
|
|
|
2018-12-03 04:26:18 +03:00
|
|
|
; every time I buy food, schedule a dollar donation
|
|
|
|
= expenses:food
|
|
|
|
(liabilities:charity) $-1
|
|
|
|
|
|
|
|
; when I buy a gift, also deduct that amount from a budget envelope subaccount
|
2018-02-16 22:09:37 +03:00
|
|
|
= expenses:gifts
|
2018-12-03 04:26:18 +03:00
|
|
|
assets:checking:gifts *-1
|
|
|
|
assets:checking *1
|
2017-12-15 05:20:07 +03:00
|
|
|
|
2018-12-03 04:26:18 +03:00
|
|
|
2017/12/1
|
|
|
|
expenses:food $10
|
|
|
|
assets:checking
|
|
|
|
|
|
|
|
2017/12/14
|
|
|
|
expenses:gifts $20
|
|
|
|
assets:checking
|
2017-12-15 05:20:07 +03:00
|
|
|
|
2018-02-16 22:09:37 +03:00
|
|
|
$ hledger print --auto
|
2018-12-03 04:26:18 +03:00
|
|
|
2017/12/01
|
|
|
|
expenses:food $10
|
|
|
|
assets:checking
|
|
|
|
(liabilities:charity) $-1
|
|
|
|
|
2017-12-15 05:20:07 +03:00
|
|
|
2017/12/14
|
|
|
|
expenses:gifts $20
|
2018-12-03 04:26:18 +03:00
|
|
|
assets:checking
|
|
|
|
assets:checking:gifts -$20
|
|
|
|
assets:checking $20
|
2018-04-20 16:48:26 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
Auto postings and dates
|
|
|
|
A posting date (or secondary date) in the matched posting, or (taking
|
|
|
|
precedence) a posting date in the auto posting rule itself, will also
|
|
|
|
be used in the generated posting.
|
|
|
|
|
2019-05-24 08:26:43 +03:00
|
|
|
Auto postings and transaction balancing / inferred amounts / balance asser-
|
|
|
|
tions
|
2019-02-02 03:06:09 +03:00
|
|
|
Currently, transaction modifiers are applied / auto postings are added:
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
o after missing amounts are inferred, and transactions are checked for
|
2019-02-02 03:06:09 +03:00
|
|
|
balancedness,
|
|
|
|
|
|
|
|
o but before balance assertions are checked.
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
Note this means that journal entries must be balanced both before and
|
2019-02-02 04:23:12 +03:00
|
|
|
after auto postings are added. This changed in hledger 1.12+; see #893
|
|
|
|
for background.
|
2017-12-15 05:20:07 +03:00
|
|
|
|
2019-09-01 07:02:00 +03:00
|
|
|
Auto posting tags
|
|
|
|
Postings added by transaction modifiers will have some extra tags:
|
|
|
|
|
|
|
|
o generated-posting:= QUERY - shows this was generated by an auto post-
|
|
|
|
ing rule, and the query
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
o _generated-posting:= QUERY - a hidden tag, which does not appear in
|
2019-09-01 07:02:00 +03:00
|
|
|
hledger's output. This can be used to match postings generated "just
|
|
|
|
now", rather than generated in the past and saved to the journal.
|
|
|
|
|
2019-09-02 21:11:56 +03:00
|
|
|
Also, any transaction that has been changed by transaction modifier
|
2019-09-01 07:02:00 +03:00
|
|
|
rules will have these tags added:
|
|
|
|
|
|
|
|
o modified: - this transaction was modified
|
|
|
|
|
|
|
|
o _modified: - a hidden tag not appearing in the comment; this transac-
|
|
|
|
tion was modified "just now".
|
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
EDITOR SUPPORT
|
2019-09-02 21:11:56 +03:00
|
|
|
Helper modes exist for popular text editors, which make working with
|
2019-02-14 15:12:25 +03:00
|
|
|
journal files easier. They add colour, formatting, tab completion, and
|
2019-09-02 21:11:56 +03:00
|
|
|
helpful commands, and are quite recommended if you edit your journal
|
|
|
|
with a text editor. They include ledger-mode or hledger-mode for
|
|
|
|
Emacs, vim-ledger for Vim, hledger-vscode for Visual Studio Code, and
|
|
|
|
others. See the [[Cookbook]] at hledger.org for the latest informa-
|
2019-02-14 15:12:25 +03:00
|
|
|
tion.
|
2016-04-14 08:29:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
REPORTING BUGS
|
2019-09-02 21:11:56 +03:00
|
|
|
Report bugs at http://bugs.hledger.org (or on the #hledger IRC channel
|
2016-04-14 08:29:16 +03:00
|
|
|
or hledger mail list)
|
|
|
|
|
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
AUTHORS
|
2016-04-14 08:29:16 +03:00
|
|
|
Simon Michael <simon@joyful.com> and contributors
|
|
|
|
|
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
COPYRIGHT
|
2019-09-13 18:26:49 +03:00
|
|
|
Copyright (C) 2007-2019 Simon Michael.
|
2016-04-14 08:29:16 +03:00
|
|
|
Released under GNU GPL v3 or later.
|
|
|
|
|
|
|
|
|
2016-06-12 07:34:20 +03:00
|
|
|
SEE ALSO
|
2019-09-02 21:11:56 +03:00
|
|
|
hledger(1), hledger-ui(1), hledger-web(1), hledger-api(1),
|
2016-04-14 08:29:16 +03:00
|
|
|
hledger_csv(5), hledger_journal(5), hledger_timeclock(5), hledger_time-
|
|
|
|
dot(5), ledger(1)
|
|
|
|
|
|
|
|
http://hledger.org
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-13 21:00:03 +03:00
|
|
|
hledger 1.15.99 September 2019 hledger_journal(5)
|