From mboxrd@z Thu Jan 1 00:00:00 1970 From: ST Subject: Re: Multi-step ledger org-capture template Date: Mon, 27 Aug 2018 11:05:32 +0300 Message-ID: <1535357132.1856.42.camel@gmail.com> References: <876004kkor.fsf@mail.de> <87sh36j9vt.fsf@mail.de> <87o9dtjov4.fsf@mail.de> <87wosciyl4.fsf@mail.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47116) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fuCiI-0001Mi-DQ for emacs-orgmode@gnu.org; Mon, 27 Aug 2018 04:17:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fuCXC-0001dg-I8 for emacs-orgmode@gnu.org; Mon, 27 Aug 2018 04:06:06 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:35164) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fuCXC-0001dU-Bd for emacs-orgmode@gnu.org; Mon, 27 Aug 2018 04:06:02 -0400 Received: by mail-wr1-x42f.google.com with SMTP id j26-v6so12732140wre.2 for ; Mon, 27 Aug 2018 01:06:02 -0700 (PDT) In-Reply-To: <87wosciyl4.fsf@mail.de> 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" To: Stefan Huchler Cc: emacs-orgmode@gnu.org 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. > > > > > >