Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonmichael/1345b5b95992bdafc21d to your computer and use it in GitHub Desktop.
Save simonmichael/1345b5b95992bdafc21d to your computer and use it in GitHub Desktop.
"semi-automated transactions" - adding postings with hledger-rewrite (https://github.com/simonmichael/hledger/blob/master/extra/hledger-rewrite.hs)
$ git clone http://code.hledger.org hledger
$ cd hledger
$ stack build hledger
$ stack ghc extra/hledger-rewrite.hs
$ mv extra/hledger-rewrite ~/.local/bin
$ cd ..
$ hledger-rewrite --help
hledger-rewrite [OPTIONS] [PATTERNS] --add-posting "ACCT AMTEXPR" ...
print all journal entries, with custom postings added to the matched ones
Flags:
--add-posting='ACCT AMTEXPR' add a posting to ACCT, which may be
parenthesised. AMTEXPR is either a literal
amount, or *N which means the transaction's
first matched amount multiplied by N (a
decimal number). Two spaces separate ACCT
and AMTEXPR.
...
2016/3/2 payment received
revenues:business $-1000
assets:business:bank:wf:bchecking:available
$ hledger-rewrite -f t.j revenues \
--add-posting '(assets:business:accounts receivable:client1) *-1' \ ; a. decrease receivable by revenues amount
--add-posting '(liabilities:personal:tax:federal:2016) *.25' \ ; b. increase taxes owed, by 25%
--add-posting '(liabilities:personal:tax:state:2016) *.02' \ ; and 2% of revenues amount
--add-posting 'assets:business:bank:wf:bchecking:year:tax:2016 *-.27' \ ; c. save that amount to the
--add-posting 'assets:business:bank:wf:bchecking:available *.27' ; tax envelope
2016/03/02 payment received
revenues:business $-1000
assets:business:bank:wf:bchecking:available $1000
(assets:business:accounts receivable:clearview) $1000
(liabilities:personal:tax:federal:2016) $-250
(liabilities:personal:tax:state:2016) $-20
assets:business:bank:wf:bchecking:year:tax:2016 $270
assets:business:bank:wf:bchecking:available $-270
select transaction(s), C-u M-S-| hledger-rewrite -f- ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment