[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ledger, add-entry
From: |
Thierry Volpiatto |
Subject: |
Re: ledger, add-entry |
Date: |
Tue, 04 May 2010 20:13:11 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
henry atting <nsmp_01@online.de> writes:
> Maybe someone can answer this question here; since I have no google
> account the ledger group is inaccessible for me.
>
> When I add an entry to my ledger file (ledger-add-entry) a new entry
> will be created according to an older one with the same payee. As far as
> good but how can I suppress the price to be filled in either. As
> the price usually differs you always have to delete the old rate first.
>
> henry
Here functions i use here, they are for my personal use and work fine
here but no guarantee it will work on your side, adapt for yourself.
They use anything-comp-read that replace completing-read, so if you
don't use anything, replace anything-comp-read by completing-read.
,----
| (defun ledger-add-expense (date payee categorie type amount)
| (interactive
| (list (read-string "Date: " (tv-cur-date-string :separator "/"))
| (read-string "Payee: ")
| (anything-comp-read "Categorie: " (ledger-collect-categories))
| (anything-comp-read "Type: " '("Visa" "Check" "Tip" "Prelevement"))
| (read-string "Amount: ")))
| (let (numcheck defnumcheck)
| (with-current-buffer (find-file-noselect (getenv "LEDGER_FILE"))
| (goto-char (point-max))
| (when (string= type "Check")
| (setq defnumcheck (save-excursion
| (when
| (re-search-backward
|
"\\(^[0-9]\\{4\\}/[0-9/]*\\)\\(.*\\)\\(\([0-9]*\)\\)" nil t)
| (replace-regexp-in-string "\(\\|\)" ""
(match-string 3)))))
| (setq defnumcheck (int-to-string (1+ (string-to-number defnumcheck))))
| (setq numcheck (read-string "CheckNumber: " defnumcheck)))
| (insert (concat
| date " " payee (or (and numcheck (concat " (" numcheck ")"))
"") "\n "
| "Expenses:" categorie (make-string 8 ? ) "€ " amount "\n "
| "Liabilities:Socgen:" type "\n\n"))
| (goto-char (point-min))
| (ledger-align-device 1)
| (save-buffer))))
|
| (defun ledger-add-income (date payee categorie account amount)
| (interactive
| (list (read-string "Date: " (tv-cur-date-string :separator "/"))
| (read-string "Payee: ")
| (anything-comp-read "Categorie: " (ledger-collect-categories))
| (anything-comp-read "Account: " '("Socgen:Checking")) ;; TODO add
completion here
| (read-string "Amount: ")))
| (with-current-buffer (find-file-noselect (getenv "LEDGER_FILE"))
| (goto-char (point-max))
| (insert (concat
| date " " payee "\n "
| "Assets:" account (make-string 8 ? ) "€ " amount "\n "
| "Income:" categorie "\n\n"))
| (goto-char (point-min))
| (ledger-align-device 1)
| (save-buffer)))
|
| (defun ledger-collect-categories ()
| (let (categories result)
| (with-current-buffer (find-file-noselect (getenv "LEDGER_FILE"))
| (goto-char (point-min))
| (while
| (re-search-forward
| "\\(^ *Expenses\\|Income\\):\\([^ €0-9\n]*\\)" (point-max) t)
| (setq result (match-string 2))
| (unless (or (member result categories)
| (string= result ""))
| (push result categories))))
| categories))
`----
--
Thierry Volpiatto
Gpg key: http://pgp.mit.edu/
- ledger, add-entry, henry atting, 2010/05/04
- Re: ledger, add-entry,
Thierry Volpiatto <=