blob: b270042e3c099f7de3bb3fcfa496325f84d75839 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Ledger
;; Maybe later add this to the expense repo once it settles
(add-to-list 'load-path "/home/adamsrl/.emacs.d/addons/ledger")
(add-to-list 'load-path "/home/adamsrl/AdamsInfoServ/BusinessDocuments/Ledger/AdamsRussell/bin")
(autoload 'ledger-mode "ldg-new" nil t)
(add-to-list 'auto-mode-alist '("\\.dat$" . ledger-mode))
(add-hook 'ledger-mode-hook
(lambda ()
(setq truncate-lines 1)
(url-handler-mode 1) ; Enable hyperlinks
(require 'ledger-matching) ; Requires ldg-report anyway
(load-file "/home/adamsrl/.emacs.d/addons/ledger/ldg-xact.el")
(let ((map (current-local-map)))
(define-key map (kbd "\C-c o") 'find-file-at-point) ; Open images
(define-key map (kbd "<f8>") 'ledger-expense-shortcut)
(define-key map (kbd "M-i") 'ledger-expense-internal)
(define-key map (kbd "M-o") 'ledger-expense-personal)
(define-key map (kbd "M-'") 'ledger-expense-split)
(define-key map (kbd "M-n") '(lambda ()
(interactive)
(ledger-post-next-xact)
(recenter)
(when (get-buffer "*Receipt*")
(ledger-expense-show-receipt))))
(define-key map (kbd "M-p") '(lambda () (interactive)
(ledger-post-prev-xact)
(recenter)
(when (get-buffer "*Receipt*")
(ledger-expense-show-receipt))))
(local-unset-key [tab]) ; Ideally this turns off pcomplete
(local-unset-key [(control ?i)]) ; Ideally this turns off pcomplete
)
;(defface ledger-report-face-account-ok '((t (:foreground "Cyan"))) "Derp")
;(defface ledger-report-face-account-bad '((t (:foreground "Red"))) "Derp")
(font-lock-add-keywords
'ledger-mode
'(("Unassigned\\|Unknown\\|; RECEIPT:$" 0 'highlight prepend))) ))
;; My customizations to make receipt image matching work with ledger-report mode
(add-hook 'ledger-report-mode-hook
(lambda ()
(hl-line-mode 1)
(local-set-key (kbd "<RET>") 'ledger-report-visit-source) ; Make return jump to the right txn
(local-set-key (kbd "<tab>") 'ledger-report-visit-source) ; Make tab jump to the right txn
(local-set-key (kbd "n") '(lambda ()
(interactive)
(save-selected-window
(next-line)
(ledger-report-visit-source)))) ; Update a txn window but keep focus
(local-set-key (kbd "p") '(lambda ()
(interactive)
(save-selected-window
(previous-line)
(ledger-report-visit-source)))) ; Update a txn window but keep focus
(local-set-key (kbd "M-r") 'ledger-receipt-matching) ; Link receipt to current item
(local-set-key (kbd "M-l") 'ledger-matching-tie-receipt-to-txn) ; Link receipt to current item
(local-set-key (kbd "M-n") '(lambda ()
(interactive)
(ledger-matching-image-offset-adjust 1))) ; Next receipt image
(local-set-key (kbd "M-p") '(lambda ()
(interactive)
(ledger-matching-image-offset-adjust -1))) ; prev receipt image
(local-set-key (kbd "M-s") '(lambda ()
(interactive)
(ledger-receipt-skip))) ; Skip receipt image
(local-set-key (kbd "C-c C-e") '(lambda () (interactive)
(save-selected-window
(ledger-report-visit-source)
(ledger-toggle-current-entry) ))) ; Toggle entry
))
(defvar *ledger-expense-shortcut-ER*
"Current expense report number, just last four digits (ie: 1234 results in AISER1234).")
(defvar *ledger-expense-shortcut-split-ER*
"Split (ie: internal) expense report number, just last four digits (ie: 1234 results in AISER1234).")
(defvar *ledger-expense-shortcut-Proj* ""
"Current export report project code (ie: AGIL1292)")
(defun ledger-expense-shortcut-ER-format-specifier () *ledger-expense-shortcut-ER*)
(defun ledger-expense-shortcut-setup (ER Split Proj)
"Sets the variables expanded into the transaction."
(interactive "MER Number (4 digit number only): \nMSplit ER Number (4 digit number only): \nMProject: ")
(setq *ledger-expense-shortcut-ER*
(concatenate 'string "AISER" ER))
(setq *ledger-expense-shortcut-split-ER*
(concatenate 'string "AISER" Split))
(setq *ledger-expense-shortcut-Proj* Proj)
(setq ledger-matching-project Proj)
(message "Set Proj to %s and ER to %s, split to %s"
*ledger-expense-shortcut-Proj*
*ledger-expense-shortcut-ER*
*ledger-expense-shortcut-split-ER*))
(defun ledger-expense-shortcut ()
"Updates the ER and Project metadata with the current values of the shortcut variables."
(interactive)
(when (eq major-mode 'ledger-mode)
(if (or (eql *ledger-expense-shortcut-ER* "")
(eql *ledger-expense-shortcut-Proj* ""))
(message "Run ledger-expense-shortcut-setup first.")
(save-excursion
(search-forward "; ER:")
(kill-line nil)
(insert " " *ledger-expense-shortcut-ER*))
(save-excursion
(search-forward "; PROJECT:")
(kill-line nil)
(insert " " *ledger-expense-shortcut-Proj*)))))
(defun ledger-expense-split ()
"Splits the current transaction between internal and projects."
(interactive)
(when (eq major-mode 'ledger-mode) ; I made this local now, should only trigger in ldg-mode
(save-excursion
(end-of-line)
(re-search-backward "^[0-9]\\{4\\}/")
(re-search-forward "^ +Dest:Projects")
(move-beginning-of-line nil)
(let ((begin (point))
(end (re-search-forward "^$")))
(goto-char end)
(insert (buffer-substring begin end))
(goto-char end)
(re-search-forward "^ Dest:Projects")
(replace-match " Dest:Internal")
(re-search-forward "; ER: +[A-Za-z0-9]+")
(replace-match (concat "; ER: " *ledger-expense-shortcut-split-ER*) t)
(when (re-search-forward "; CATEGORY: Meals" (save-excursion (re-search-forward "^$")) t)
(replace-match "; CATEGORY: Travel" t))))
(re-search-backward "^[0-9]\\{4\\}/")
(re-search-forward "^ +Dest:Projects")
(insert-string " $") ))
(defun ledger-expense-internal ()
"Makes the expense an internal one."
(interactive)
(when (eq major-mode 'ledger-mode) ; I made this local now, should only trigger in ldg-mode
(save-excursion
(end-of-line)
(re-search-backward "^[0-9]\\{4\\}/")
(let ((begin (point))
(end (save-excursion (re-search-forward "^$"))))
(when (re-search-forward "^ Dest:Projects" end t)
(replace-match " Dest:Internal") )
(when (re-search-forward "; CATEGORY: Meals" (save-excursion (re-search-forward "^$")) t)
(replace-match "; CATEGORY: Travel" t))))))
(defun ledger-expense-personal ()
"Makes the expense an personal one, eliminating metadata and receipts."
(interactive)
(when (eq major-mode 'ledger-mode) ; I made this local now, should only trigger in ldg-mode
(save-excursion
(end-of-line)
(re-search-backward "^[0-9]\\{4\\}/")
(let ((begin (point))
(end (save-excursion (re-search-forward "^$"))))
(when (re-search-forward "^ Dest:Projects" end t)
(replace-match " Other:Personal"))
(goto-char begin)
(save-excursion
(when (re-search-forward "^ +; ER:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; PROJECT:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; CATEGORY:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; RECEIPT:" end t)
(beginning-of-line)
(kill-line 1)))
(ledger-toggle-current-entry)))))
(defun ledger-expense-show-receipt ()
"Uses the Receipt buffer to show the receipt of the txn we're on."
(when (eq major-mode 'ledger-mode) ; I made this local now, should only trigger in ldg-mode
(save-excursion
(end-of-line)
(re-search-backward "^[0-9]\\{4\\}/")
(let ((begin (point))
(end (save-excursion (re-search-forward "^$"))))
(save-excursion
(when (re-search-forward "^\\( +; RECEIPT: +\\)\\([^,]+?.jpg\\).*$" end t)
(ledger-matching-display-image
(concat "/home/adamsrl/AdamsInfoServ/BusinessDocuments/Ledger/AdamsRussell/"
(match-string 2))) ))))))
|