emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Sharon Kimble <boudiccas@skimble.plus.com>
To: Alan Schmitt <alan.schmitt@polytechnique.org>
Cc: org-mode mailing list <emacs-orgmode@gnu.org>,
	Vikas Rawal <vikaslists@agrarianresearch.org>
Subject: Re: Org and ledger
Date: Fri, 07 Nov 2014 13:19:10 +0000	[thread overview]
Message-ID: <87oasj173l.fsf@skimble.plus.com> (raw)
In-Reply-To: <m24mucdyt7.fsf@polytechnique.org> (Alan Schmitt's message of "Thu, 06 Nov 2014 18:27:32 +0100")

[-- Attachment #1: Type: text/plain, Size: 4288 bytes --]

Alan Schmitt <alan.schmitt@polytechnique.org> writes:

Thanks Alan for this. Ledger is something that I would dearly love to be
using, but I can't find a good tutorial [by which I mean, it works in
small steps which build on the previous steps]. I've looked at

http://lists.gnu.org/archive/html/emacs-orgmode/2014-04/msg00727.html
http://orgmode.org/worg/org-tutorials/weaving-a-budget.html
http://hledger.org/step-by-step

The last one looked the most promising until I tried "ledger add" which
replied -

--8<---------------cut here---------------start------------->8---
ledger add -f ~/.emacs.d/ledger/ledger.journal
Error: Unrecognized command 'add'
--8<---------------cut here---------------end--------------->8---

So now I'm stumped!

Sharon.

> On 2014-10-31 12:32, Vikas Rawal <vikaslists@agrarianresearch.org> writes:
<snip>.
>
> I generate reports and deal with my budget using org. I describe my
> setup here:
> http://lists.gnu.org/archive/html/emacs-orgmode/2014-04/msg00727.html
>
> Since then, I've slightly refined these functions, here is the current
> version:
>
> #+begin_src org
> #+name: call_ledger
> #+begin_src emacs-lisp :var lcmd="bal" :var bucket="Quotidien" :var prefix="Expenses:" :var period=()
>   (let* ((name (org-trim bucket))
>          (bname (concat "'^" prefix name "'"))
>          (ledger "ledger -f ~/Documents/Org/mescomptes.ledger")
>          (parg (when period (concat " -p '" period "'")))
>          (cutcmd "tail -1 | cut -d ' ' -f 2")
>          (cmd 
>           (concat ledger " -J " parg " " lcmd " " bname " | " cutcmd))
>          (res (org-trim (shell-command-to-string cmd))))
>     (if (equal res "") 0 res))
> #+end_src
> #+name: monthly_average_since
> #+begin_src emacs-lisp :var start-date="2014-03-01" :var amount=100
>   (let ((nbdays (- (time-to-days (current-time))
>                    (time-to-days (org-read-date nil t start-date)))))
>     (calc-eval "round($ / (12 * ($$ / 365.25)), 2)" nil amount nbdays))
> #+end_src
>
> #+name: monthly_average
> #+begin_src emacs-lisp :var starty=2014 :var startm=3 :var amount=100 
>   (let* ((tm (decode-time))
>          (cmonth (nth 4 tm))
>          (cyear (nth 5 tm))
>          (nbmonths (+ (* 12 (- cyear starty)) (- cmonth startm))))
>     (calc-eval "round($ / $$, 2)" nil amount nbmonths))
> #+end_src
>
> #+name: ledger_average
> #+begin_src emacs-lisp :var b="Quotidien" :var sy=2014 :var sm=3  :var sd="2014-03-01" :var p="Expenses:"
>   (let* ((per (format "from %d-%d-01 to this month" sy sm))
>          (a (org-sbe call_ledger (bucket (eval b)) (prefix (eval p)) (period (eval per)))))
>     (org-sbe monthly_average (amount (eval a)) (starty (eval sy)) (startm (eval sm))))
> #+end_src
>
> #+name: ledger_budget
> #+BEGIN_SRC emacs-lisp :results output :var table=budget :var year=2014 :var month=04
>   (princ (format "%d-%02d-01 * Budget %d %02d\n" year month year month))
>   (mapcar
>    (lambda (tuple)
>      (princ (format "    Bucket:Expenses:%s    %d €\n" (car tuple) (cadr tuple))))
>    (butlast (cdr table) 1))
>   (princ "    Bucket:Unallocated:EUR\n")
> #+END_SRC
> #+end_src
>
> The table looks like this now
>
> #+begin_src org
> #+name: budget
> | Bucket | Planned | Remaining | This Month | Last Month | Average |
> |--------+---------+-----------+------------+------------+---------|
> | Name   | &       | &         | &          | &          | &       |
> |--------+---------+-----------+------------+------------+---------|
> | Total  | &       | &         | &          | &          | &       |
> #+TBLFM: @2$3..@>>$3='(org-sbe call_ledger (bucket (concat "\"" $1 "\"")) (prefix "\"Bucket:Expenses:\""))
> #+TBLFM: @2$4..@>>$4='(org-sbe call_ledger (bucket (concat "\"" $1 "\"")) (period "\"this month\""))
> #+TBLFM: @2$5..@>>$5='(org-sbe call_ledger (bucket (concat "\"" $1 "\"")) (period "\"last month\""))
> #+TBLFM: @2$6..@>>$6='(org-sbe ledger_average (b (concat "\"" $1 "\"")))
> #+TBLFM: @>$2..@>$6=vsum(@2..@-1)
> #+end_src
>
> Best,
>
> Alan

-- 
A taste of linux = http://www.sharons.org.uk
my git repo = https://bitbucket.org/boudiccas/dots
TGmeds = http://www.tgmeds.org.uk
Debian testing, fluxbox 1.3.5, emacs 24.4.1.0

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

  reply	other threads:[~2014-11-07 13:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-31  7:02 Org and ledger Vikas Rawal
2014-10-31 18:56 ` Eric Abrahamsen
2014-11-03 16:32 ` Eric S Fraga
2014-11-06 17:27 ` Alan Schmitt
2014-11-07 13:19   ` Sharon Kimble [this message]
2014-11-07 13:36     ` Eric Abrahamsen
2014-11-07 19:53       ` Sharon Kimble
2014-11-08 15:45         ` Eric S Fraga
2014-11-10  7:37         ` Eric S Fraga
2014-11-07 18:51     ` Eric S Fraga
2014-11-09  4:34       ` Daniel Clemente
2014-11-09 13:29         ` Eric S Fraga
2014-11-10  7:08           ` Bernhard Pröll
2014-11-10  9:08             ` Daniel Clemente
  -- strict thread matches above, loose matches on Subject: below --
2008-11-26 18:01 [ANN] Org Invoice 1.0.0 Peter Jones
2008-12-06 19:36 ` Mark A. Hershberger
2008-12-06 21:34   ` Peter Jones
2008-12-07 20:23     ` Mark A. Hershberger
2008-12-07 22:25       ` Org and Ledger (was: Re: [ANN] Org Invoice 1.0.0) Carsten Dominik
2008-12-08 16:58         ` Org and Ledger Mark A. Hershberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oasj173l.fsf@skimble.plus.com \
    --to=boudiccas@skimble.plus.com \
    --cc=alan.schmitt@polytechnique.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=vikaslists@agrarianresearch.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).