From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sharon Kimble Subject: Re: Org and ledger Date: Fri, 07 Nov 2014 13:19:10 +0000 Message-ID: <87oasj173l.fsf@skimble.plus.com> References: <4AA4F46C-5ABD-481A-8F95-2401FC407E03@agrarianresearch.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XmjRo-00062M-SO for emacs-orgmode@gnu.org; Fri, 07 Nov 2014 08:19:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XmjRk-0005tO-MR for emacs-orgmode@gnu.org; Fri, 07 Nov 2014 08:19:28 -0500 Received: from avasout06.plus.net ([212.159.14.18]:51744) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XmjRk-0005t2-DY for emacs-orgmode@gnu.org; Fri, 07 Nov 2014 08:19:24 -0500 In-Reply-To: (Alan Schmitt's message of "Thu, 06 Nov 2014 18:27:32 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Alan Schmitt Cc: org-mode mailing list , Vikas Rawal --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Alan Schmitt 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 - =2D-8<---------------cut here---------------start------------->8--- ledger add -f ~/.emacs.d/ledger/ledger.journal Error: Unrecognized command 'add' =2D-8<---------------cut here---------------end--------------->8--- So now I'm stumped! Sharon. > On 2014-10-31 12:32, Vikas Rawal writes: . > > 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=3D"bal" :var bucket=3D"Quotidien" :var p= refix=3D"Expenses:" :var period=3D() > (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=20 > (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=3D"2014-03-01" :var amount=3D100 > (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=3D2014 :var startm=3D3 :var amount=3D1= 00=20 > (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=3D"Quotidien" :var sy=3D2014 :var sm=3D3 := var sd=3D"2014-03-01" :var p=3D"Expenses:" > (let* ((per (format "from %d-%d-01 to this month" sy sm)) > (a (org-sbe call_ledger (bucket (eval b)) (prefix (eval p)) (per= iod (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=3Dbudget :var year=3D20= 14 :var month=3D04 > (princ (format "%d-%02d-01 * Budget %d %02d\n" year month year month)) > (mapcar > (lambda (tuple) > (princ (format " Bucket:Expenses:%s %d =E2=82=AC\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=3D'(org-sbe call_ledger (bucket (concat "\"" $1 "\""= )) (prefix "\"Bucket:Expenses:\"")) > #+TBLFM: @2$4..@>>$4=3D'(org-sbe call_ledger (bucket (concat "\"" $1 "\""= )) (period "\"this month\"")) > #+TBLFM: @2$5..@>>$5=3D'(org-sbe call_ledger (bucket (concat "\"" $1 "\""= )) (period "\"last month\"")) > #+TBLFM: @2$6..@>>$6=3D'(org-sbe ledger_average (b (concat "\"" $1 "\""))) > #+TBLFM: @>$2..@>$6=3Dvsum(@2..@-1) > #+end_src > > Best, > > Alan =2D-=20 A taste of linux =3D http://www.sharons.org.uk my git repo =3D https://bitbucket.org/boudiccas/dots TGmeds =3D http://www.tgmeds.org.uk Debian testing, fluxbox 1.3.5, emacs 24.4.1.0 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJUXMbPAAoJEDaBgBkK+INbYhEP/1Wp6Y58yzJj0331t1tQcE2m Lh6vsiywnC9Ect7iI9FGv4nTy0I16bQgN0xZRO7E3+UlYB+fVlLGYMps62fq8/br Fb0yNPZuCNTI+3PjZGMKJmQHBtfWUhsQclxWpYG7B0AEMDmdHWQkYDwEUhJ+HVUr sALEEVgLZY50K/6q3jFw2mepa1ZcF4OJZUx1Tlq4VYiSXUpNKipKCbbzWO17WTYZ BxNuyV9e4PDc249czoXdmKVjYPmE9O4ZfBbQvsvgY2ye6SJHRfaQ2AkHvA+++NGF Kbx5LtTtrCsoNDaWGJrFvS3/bsgHJ+sge0ALqOgZVYx7jY7ePOVOCpEdGV8l3yUb gPcQZqKA3/yIp78h9YUhjRykqsmjiEej+VxBQIfj71TgBMWz7PjNTPjpjaTNiBQ2 0X0dl13cdvn/wNWNWlF/d522zqpePr0fmbk2gKdhaTqDZmDhBTrcPG68DgrpthVi H3zqCwJZgQ5aocjWGV3ccmrvzgS6bcxCka+dE8U6xs0bK5EgN2p1kv/JEZm2YZ21 364M2zAaUSdq3cFIpQ01je24Akfsk1mSyJ3V9XoAqeoHs9+uzrIvDSWZq+Wod/H0 U0iopaWWmPeP4XbDTQ0SUbFrqQqtHEdbXd3Udh3Hr8U0vgmDlCSm6MX+nPndKEcz eJyrpvk2Fxv77fLI02bK =xb2r -----END PGP SIGNATURE----- --=-=-=--