Merge branch 'ledger-mode-automatic-transactions'
Conflicts: lisp/ledger-post.el
This commit is contained in:
commit
fc716a5ca1
13 changed files with 620 additions and 611 deletions
|
|
@ -89,6 +89,7 @@ reports and much more...
|
|||
* The Ledger Buffer::
|
||||
* The Reconcile Buffer::
|
||||
* The Report Buffer::
|
||||
* Scheduling Transactions::
|
||||
* Customizing Ledger-mode::
|
||||
* Generating Ledger Regression Tests::
|
||||
* Embedding Example results in Ledger Documentation::
|
||||
|
|
@ -592,7 +593,7 @@ the ledger buffer are left in that state when the account is switched.
|
|||
If for some reason during reconciliation your target amount changes,
|
||||
type @kbd{t} and enter the new target value.
|
||||
|
||||
@node The Report Buffer, Customizing Ledger-mode, The Reconcile Buffer, Top
|
||||
@node The Report Buffer, Scheduling Transactions, The Reconcile Buffer, Top
|
||||
@chapter The Report Buffer
|
||||
|
||||
@menu
|
||||
|
|
@ -738,9 +739,32 @@ recent transactions at the top, type @kbd{R} in the @file{*Ledger
|
|||
Report*} buffer and it will reverse the order of the transactions and
|
||||
maintain the proper mathematical sense.
|
||||
|
||||
@node Customizing Ledger-mode, Generating Ledger Regression Tests, The Report Buffer, Top
|
||||
@node Scheduling Transactions, Customizing Ledger-mode, The Report Buffer, Top
|
||||
@chapter Scheduling Transactions
|
||||
|
||||
@node Customizing Ledger-mode, Generating Ledger Regression Tests, Scheduling Transactions, Top
|
||||
@chapter Customizing Ledger-mode
|
||||
|
||||
The Ledger program provide for automating transactions but these
|
||||
transaction aren't ``real'', they only exist inside a ledger session and
|
||||
are not reflected in the actual data file. Many transactions are very
|
||||
repetitive, but may vary slightly in the date they occur on, or the
|
||||
amount. Some transactions are weekly, monthly, quarterly or annually.
|
||||
Ledger mode provides a way to schedule upcoming transaction with a
|
||||
flexible scheduler that allows you to specify the transactions in a
|
||||
separate ledger file and calculate the upcoming occurences of those
|
||||
transactions. You can then copy the transactions into your live data
|
||||
file.
|
||||
|
||||
@node Specifying Upcming Transactions
|
||||
@section Specifying Upcming Transactions
|
||||
|
||||
The format for specifying transactions is identical to Ledger's file
|
||||
format with the exception of the date field. The data field is modified
|
||||
by surrounding it with brackets and using wild cards to specity free
|
||||
months or years.
|
||||
|
||||
|
||||
@menu
|
||||
* Ledger-mode Customization::
|
||||
* Customization Variables::
|
||||
|
|
|
|||
|
|
@ -85,8 +85,10 @@ Returns a list with (value commodity)."
|
|||
(defun -commodity (c1 c2)
|
||||
"Subtract C2 from C1, ensuring their commodities match."
|
||||
(if (string= (cadr c1) (cadr c2))
|
||||
; the scaling below is to get around inexact subtraction results where, for example
|
||||
; 1.23 - 4.56 = -3.3299999999999996 instead of -3.33
|
||||
; the scaling below is to get around inexact
|
||||
; subtraction results where, for example 1.23
|
||||
; - 4.56 = -3.3299999999999996 instead of
|
||||
; -3.33
|
||||
(list (/ (- (* ledger-scale (car c1)) (* ledger-scale (car c2))) ledger-scale) (cadr c1))
|
||||
(error "Can't subtract different commodities %S from %S" c2 c1)))
|
||||
|
||||
|
|
|
|||
|
|
@ -172,6 +172,7 @@ Can indent, complete or align depending on context."
|
|||
(define-derived-mode ledger-mode text-mode "Ledger"
|
||||
"A mode for editing ledger data files."
|
||||
(ledger-check-version)
|
||||
(ledger-schedule-check-available)
|
||||
(ledger-post-setup)
|
||||
|
||||
(set (make-local-variable 'comment-start) "; ")
|
||||
|
|
@ -270,6 +271,7 @@ Can indent, complete or align depending on context."
|
|||
(define-key map [delete-xact] '(menu-item "Delete Transaction" ledger-delete-current-transaction))
|
||||
(define-key map [cmp-xact] '(menu-item "Complete Transaction" ledger-fully-complete-xact))
|
||||
(define-key map [add-xact] '(menu-item "Add Transaction (ledger xact)" ledger-add-transaction :enable ledger-works))
|
||||
(define-key map [add-xact] '(menu-item "Show upcoming transactions" ledger-schedule-upcoming :enable ledger-schedule-available))
|
||||
(define-key map [sep3] '(menu-item "--"))
|
||||
(define-key map [stats] '(menu-item "Ledger Statistics" ledger-display-ledger-stats :enable ledger-works))
|
||||
(define-key map [fold-buffer] '(menu-item "Narrow to REGEX" ledger-occur))))
|
||||
|
|
|
|||
|
|
@ -49,14 +49,20 @@
|
|||
:type 'integer
|
||||
:group 'ledger-schedule)
|
||||
|
||||
(defcustom ledger-schedule-file "~/FinanceData/ledger-schedule.ledger"
|
||||
(defcustom ledger-schedule-file "~/ledger-schedule.ledger"
|
||||
"File to find scheduled transactions."
|
||||
:type 'file
|
||||
:group 'ledger-schedule)
|
||||
|
||||
(defvar ledger-schedule-available nil)
|
||||
|
||||
(defsubst between (val low high)
|
||||
(and (>= val low) (<= val high)))
|
||||
|
||||
(defun ledger-schedule-check-available ()
|
||||
(setq ledger-schedule-available (and ledger-schedule-file
|
||||
(file-exists-p ledger-schedule-file))))
|
||||
|
||||
(defun ledger-schedule-days-in-month (month year)
|
||||
"Return number of days in the MONTH, MONTH is from 1 to 12.
|
||||
If year is nil, assume it is not a leap year"
|
||||
|
|
@ -291,31 +297,6 @@ returns true if the date meets the requirements"
|
|||
(ledger-mode))
|
||||
(length candidates)))
|
||||
|
||||
|
||||
;;
|
||||
;; Test harnesses for use in ielm
|
||||
;;
|
||||
(defvar auto-items)
|
||||
|
||||
(defun ledger-schedule-test ( early horizon)
|
||||
(ledger-schedule-create-auto-buffer
|
||||
(ledger-schedule-scan-transactions ledger-schedule-file)
|
||||
early
|
||||
horizon
|
||||
(get-buffer "2013.ledger")))
|
||||
|
||||
|
||||
(defun ledger-schedule-test-predict ()
|
||||
(let ((today (current-time))
|
||||
test-date items)
|
||||
|
||||
(loop for day from 0 to ledger-schedule-look-forward by 1 do
|
||||
(setq test-date (time-add today (days-to-time day)))
|
||||
(dolist (item auto-items items)
|
||||
(if (funcall (car item) test-date)
|
||||
(setq items (append items (list (decode-time test-date) (cdr item)))))))
|
||||
items))
|
||||
|
||||
(defun ledger-schedule-upcoming ()
|
||||
(interactive)
|
||||
(ledger-schedule-create-auto-buffer
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue