Accounting in Emacs with Ledger Mode - System Crafters Live!

2025-04-11T15:00:00Z

1 Like

Here the org-file I mentioned in the stream.

It allows me to have an eye on how many service hours I have left in my budget with my external partner.

* Example
#+NAME: LedgerCli
#+begin_src ledger :results raw :cmdline reg "Assets:4501580666" --exchange h --format='| %D | %T | \n'
  P 2024/01/01 00:00:00 h CHF 180

  2024/01/01 * Opening Balance
      Assets:4501580666                      CHF 30000  ; Kostendach
      Equity:Opening Balance

  2024/01/08 * LFI-005977
      Spending:monatliche Grundgebühr  "SnS v3: Bronze" 12 @ CHF 200
      Assets:4501580666                   CHF -2400.00

  2024/02/01 * LFI-005996
      Spending:SH                                h 0.5 ;
      Spending:SH                               h 1.25 ;
      Spending:SH                               h 1.25 ;
      Spending:SH                                  h 1 ;
      Assets:4501580666                    CHF -720

  
#+end_src

#+Name: ledgercli-table
#+RESULTS: LedgerCli


#+begin_src python :var t=ledgercli-table :results output drawer
  print("#+Name: ledger-cli-table-no-currency")
  for l in t:
    if l[1] == 0:
      l[1] = '0.0 h'
    if l[1] == '50.8m':
      l[1] = '0.846 h'
    print(("| {col1} | {col2} |").format( col1=l[0], col2=l[1].split(' ')[0] ))
#+end_src

#+RESULTS:
:results:
#+Name: ledger-cli-table-no-currency
:end:


#+begin_src gnuplot :var data=ledger-cli-table-no-currency :file gnuplot.sh.png :exports results output
  set term pngcairo font 'arial,11' size 1200,600
  set xdata time
  set style data linespoints
  set timefmt "%Y/%m/%d"
  set xrange ['2024/01/01':'2025/01/103']
  set format x "%d.%m"
  set yrange [-10:170]

  set style line 100 lt 1 lc rgb "gray" lw 1
  set style line 101 lt 0.5 lc rgb "gray" lw 1

  set grid mytics ytics ls 100, ls 101
  set grid mxtics xtics ls 100, ls 101
  set offset 1,1,1,1

  set title "Service und Support Bronze 2024" font 'arial,16'
  plot data u 1:2 lw 2 with fillsteps notitle,\
       data u 1:2:(sprintf("%3.2f h", $2)) with labels point pt 11 offset char 4,2 rotate by 45 notitle
#+end_src

#+RESULTS:

In the end I upload both files to the internal wiki so others without Emacs can also access the information.

I don’t know if that has come around to distributions, yet. But I implemented GPG file support for ledger quite awhile ago. If you build ledger with GPGME support, you will not only enjoy transparent encryption/decryption of ledger files in Emacs (which you can do already), but your actual accounting and reporting functions will also transparently work on encrypted ledger files.

1 Like