From: ST <smntov@gmail.com>
To: Stefan Huchler <stefan.huchler@mail.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: Multi-step ledger org-capture template
Date: Mon, 27 Aug 2018 11:05:32 +0300 [thread overview]
Message-ID: <1535357132.1856.42.camel@gmail.com> (raw)
In-Reply-To: <87wosciyl4.fsf@mail.de>
Thank you for sharing!
It would be nice to be able to generate a .pdf invoice based on a
predefined template (in .org/.tex/etc formats; maybe utilizing org-mode
exporter) for certain ledger transaction (by default the current one,
highlighted by cursor in ledger-mode).
Did anybody wrote something similar in the past?
On Sun, 2018-08-26 at 23:53 +0200, Stefan Huchler wrote:
> In case somebody wants something similar, I post my solution I came up
> with here:
>
> %(progn
> (defun get-table-content (&optional start end)
> (let* ((start (or start (buffer-end -1)))
> (end (or end (buffer-end 1)))
> (lines
> (s-split "\n" (buffer-substring-no-properties
> start end))))
> (remove nil
> (mapcar
> (lambda (line)
> (mapcar
> (lambda (elem)
> (string-trim elem))
> (remove "" (split-string
> line "|"))))
> lines))))
> (with-current-buffer (org-capture-get :original-buffer)
> (call-interactively 'copy-region-as-kill))
> (let* (mapping)
> (with-temp-buffer
> "*shop-name-mapping*"
> (erase-buffer)
> (insert-file-contents "capture-templates/products-mapping.org")
> (let* ((start (progn (goto-char (point-min))
> (forward-line 1) (point))))
> (setq mapping (mapcar (lambda (x) (cons (nth 1 x) (car x)))
> (get-table-content start)))))
> (with-temp-buffer
> "*shop-import-temp*"
> (erase-buffer)
> (yank)
> (org-table-convert-region (buffer-end -1) (buffer-end 1) 2)
> (let* ((data (get-table-content)))
> (erase-buffer)
> (insert
> (concat " " (org-read-date nil nil) " * Shop-name\n"
> (mapconcat
> (lambda (line) (format " %s \t\t%s St {=€%s}"
> (assoc-default (nth 1 line) mapping)
> (nth 0 line) (nth 4 line)))
> data "\n")
> "\n assets:bank:chequing"))
> (ledger-mode)
> (let ((start (progn
> (goto-char (point-min))
> (forward-line 1) (point)))
> (end (progn
> (goto-char (point-max))
> (forward-line -1) (point))))
> (ledger-post-align-postings start end))
> (buffer-string)))))
>
> products-mapping would like like that:
>
> #+NAME: food
> | expenses:food:spice:Basilikum | Basilikum bio Sonnentor, 15g |
> | expenses:food:spice:Oregano | Oregano bio Sonnentor, 20g |
>
> Of course it asumes that you have some html or email bill with a table
> selected and you would have to change the (nth x line) depending where
> in the bill the name, amount and price is listed, and maybe change the
> currency.
>
>
>
>
>
>
next prev parent reply other threads:[~2018-08-27 8:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-21 11:45 Multi-step ledger org-capture template Stefan Huchler
2018-08-22 22:48 ` Stefan Huchler
2018-08-23 11:37 ` Stefan Huchler
2018-08-26 21:53 ` Stefan Huchler
2018-08-27 8:05 ` ST [this message]
2018-08-28 8:24 ` Neil Jerram
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=1535357132.1856.42.camel@gmail.com \
--to=smntov@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=stefan.huchler@mail.de \
/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).