|
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 | + |
0 commit comments