Skip to content

Commit 4ccb5ad

Browse files
committed
;examples:multi-year: expand, show equity & accounting equation [#2151]
1 parent e61c9ba commit 4ccb5ad

File tree

7 files changed

+200
-27
lines changed

7 files changed

+200
-27
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; 2021-closed.journal
2+
3+
2021-06-01 opening balances ; start:2021
4+
assets 20 = 20
5+
equity:opening/closing balances
6+
7+
2021-07-01 income
8+
income
9+
assets 1
10+
11+
2021-08-01 currency conversion
12+
income -1 A
13+
equity:conversion:A-B:A 1 A
14+
equity:conversion:A-B:B -1 B
15+
expenses 1 B
16+
17+
2021-12-31 retain earnings
18+
expenses -1 B = 0 B
19+
income 1 = 0
20+
income 1 A = 0 A
21+
equity:retained earnings
22+
23+
2021-12-31 closing balances ; start:2022
24+
assets -21 = 0
25+
equity:opening/closing balances
26+

examples/multi-year/2021.journal

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
2021-06-01 opening balances ; start:2021
44
assets 20 = 20
5-
equity:start
5+
equity:opening/closing balances
66

77
2021-07-01 income
88
income
99
assets 1
1010

11-
2021-12-31 closing balances ; start:2022
12-
assets -21 = 0
13-
equity:start
11+
2021-08-01 currency conversion
12+
income -1 A
13+
expenses 1 B
1414

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; 2022-closed.journal
2+
3+
2022-01-01 opening balances ; start:2022
4+
assets 21 = 21
5+
equity:opening/closing balances
6+
7+
2022-07-01 income
8+
income
9+
assets 1
10+
11+
2022-08-01 currency conversion
12+
income -1 A
13+
equity:conversion:A-B:A 1 A
14+
equity:conversion:A-B:B -1 B
15+
expenses 1 B
16+
17+
2022-12-31 retain earnings
18+
expenses -1 B = 0 B
19+
income 1 = 0
20+
income 1 A = 0 A
21+
equity:retained earnings
22+
23+
2022-12-31 closing balances ; start:2023
24+
assets -22 = 0
25+
equity:opening/closing balances
26+

examples/multi-year/2022.journal

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
2022-01-01 opening balances ; start:2022
44
assets 21 = 21
5-
equity:start
5+
equity:opening/closing balances
66

77
2022-07-01 income
88
income
99
assets 1
1010

11-
2022-12-31 closing balances ; start:2023
12-
assets -22 = 0
13-
equity:start
11+
2022-08-01 currency conversion
12+
income -1 A
13+
expenses 1 B
1414

examples/multi-year/2023.journal

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
2023-01-01 opening balances ; start:2023
44
assets 22 = 22
5-
equity:start
5+
equity:opening/closing balances
66

77
2023-07-01 income
88
income
99
assets 1
1010

11+
2023-08-01 currency conversion
12+
income -1 A
13+
expenses 1 B
14+

examples/multi-year/README.md

Lines changed: 135 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,135 @@
1-
Multiple yearly journal files, demonstrating the tags and commands
2-
suggested in the [close command's doc](https://hledger.org/dev/hledger.html#example-exclude-openingclosing-transactions>)
3-
for flexible multi-year reporting.
4-
See `reports`.
1+
Here are some yearly journal files demonstrating issues and techniques
2+
discussed in the [close docs](https://hledger.org/dev/hledger.html>).
3+
4+
`2021.journal`, `2022.journal` and `2023.journal` each have
5+
only an opening balances transaction and some ordinary transactions.
6+
These are what you'd get if you started a new file each year
7+
using hledger's `close --open` command or Ledger's `equity` command.
8+
These files show correct balances when used individually, but they can't be combined for a multi-year report;
9+
their opening transactions are redundant and will produce nonsense balances.
10+
11+
To solve this, whenever we transition to a new file we can
12+
13+
- add a counterbalancing [closing transaction](https://hledger.org/hledger.html#close) using `close`.
14+
15+
Also (not necessary for basic personal accounting, but if we want to be fully correct), we should ensure all equity is accounted for:
16+
17+
- where we have used @/@@ notation to convert between commodities, add [equivalent equity postings](https://hledger.org/hledger.html#equity-conversion-postings)
18+
- and consolidate revenues and expenses into equity (AKA [retain earnings](https://hledger.org/hledger.html#close)).
19+
20+
Combining all of these in the right sequence is tricky, so here's an example of fully migrating to a new file at the end of 2021/start of 2022.
21+
`2021-closed.journal` and `2022-closed.journal` are the result of applying this procedure to the 2021 and 2022 journals.
22+
(They are given a different name here for clarity; normally you probably wouldn't change the name.)
23+
24+
First ensure all equity changes are recorded:
25+
26+
```cli
27+
$ hledger -f 2021.journal print --infer-equity > 2021-closed.journal # add explicit equity:conversion postings where needed
28+
$ hledger -f 2021-closed.journal close --retain -e 2022 >> 2021-closed.journal # retain earnings (transfer RX to E)
29+
```
30+
31+
Next migrate asset/liability balances from old file to new file.
32+
(If you want to preserve equity balances too, add a [`type:ALE` argument](https://hledger.org/hledger.html#account-types).)
33+
Note how --open is done first and --close second; or you could --close first and `--open not:desc:closing` second:
34+
35+
```cli
36+
$ hledger -f 2021-closed.journal close --open -e 2022 >> 2022.journal # migrate balances (add opening txn to 2022.journal)
37+
$ hledger -f 2021-closed.journal close --close -e 2022 >> 2021-closed.journal # migrate balances (add closing txn to 2021.journal)
38+
```
39+
40+
Finally, add a tag like this (manually) to the closing and opening transactions to make them easier to exclude from reports:
41+
42+
```journal
43+
2021-12-31 closing balances ; start:2022
44+
...
45+
```
46+
```journal
47+
2022-01-01 opening balances ; start:2022
48+
...
49+
```
50+
51+
Now we can confirm that the accounting equation was preserved in 2021 (Net: is 0).
52+
We must exclude the closing balances transaction to see the end balances:
53+
54+
```cli
55+
$ hledger -f 2021-closed.journal bse not:tag:start=2022
56+
Balance Sheet With Equity 2021-12-31
57+
58+
|| 2021-12-31
59+
=================================++==============
60+
Assets ||
61+
---------------------------------++--------------
62+
assets || 21
63+
---------------------------------++--------------
64+
|| 21
65+
=================================++==============
66+
Liabilities ||
67+
---------------------------------++--------------
68+
---------------------------------++--------------
69+
||
70+
=================================++==============
71+
Equity ||
72+
---------------------------------++--------------
73+
equity:conversion:A-B:A || -1 A
74+
equity:conversion:A-B:B || 1 B
75+
equity:opening/closing balances || 20
76+
equity:retained earnings || 1, 1 A, -1 B
77+
---------------------------------++--------------
78+
|| 21
79+
=================================++==============
80+
Net: || 0
81+
```
82+
83+
We can check the accounting equation for 2022 too, after adding all equity changes:
84+
85+
```cli
86+
$ (hledger -f 2022.journal print --infer-equity; hledger -f 2022.journal close --retain) | hledger -f- bse
87+
Balance Sheet With Equity 2024-01-19
88+
89+
|| 2024-01-19
90+
==========================++==============
91+
Assets ||
92+
--------------------------++--------------
93+
assets || 22
94+
--------------------------++--------------
95+
|| 22
96+
==========================++==============
97+
Liabilities ||
98+
--------------------------++--------------
99+
--------------------------++--------------
100+
||
101+
==========================++==============
102+
Equity ||
103+
--------------------------++--------------
104+
equity:conversion:A-B:A || -1 A
105+
equity:conversion:A-B:B || 1 B
106+
equity:retained earnings || 1, 1 A, -1 B
107+
equity:start || 21
108+
--------------------------++--------------
109+
|| 22
110+
==========================++==============
111+
Net: || 0
112+
```
113+
114+
We can see correct balance sheets from any range of files if we exclude all opening/closing transactions except the first:
115+
116+
```cli
117+
$ hledger bs -Y -f 2021-closed.journal -f 2022-closed.journal -f 2023.journal expr:'tag:start=2021 or not tag:start'
118+
$ hledger bs -Y -f 2021-closed.journal -f 2022-closed.journal expr:'tag:start=2021 or not tag:start'
119+
$ hledger bs -Y -f 2022-closed.journal -f 2023.journal expr:'tag:start=2022 or not tag:start'
120+
$ hledger bs -Y -f 2021-closed.journal expr:'tag:start=2021 or not tag:start'
121+
$ hledger bs -Y -f 2022-closed.journal expr:'tag:start=2022 or not tag:start'
122+
$ hledger bs -Y -f 2023.journal # unclosed file, no query needed
123+
```
124+
125+
And we can see correct income statements from any range of files if we exclude retain earnings transactions:
126+
127+
```cli
128+
$ hledger is -Y -f 2021-closed.journal -f 2022-closed.journal -f 2023.journal not:desc:retain
129+
$ hledger is -Y -f 2021-closed.journal -f 2022-closed.journal not:desc:retain
130+
$ hledger is -Y -f 2022-closed.journal -f 2023.journal not:desc:retain
131+
$ hledger is -Y -f 2021-closed.journal not:desc:retain
132+
$ hledger is -Y -f 2022-closed.journal not:desc:retain
133+
$ hledger is -Y -f 2023.journal # unclosed file, no query needed
134+
```
135+

examples/multi-year/reports

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)