Browse Source

Add three report functions to elbank-report.el

* elbank-common.el: Add elbank-report--all-saved-reports,
  elbank-report--open-saved-report, elbank-report-open-by-name.

* elbank-overview.el: Adapt to new functions.
custom-labels
Damien Cassou 3 years ago
parent
commit
be0fdb04df
No known key found for this signature in database GPG Key ID: A7123815F5DCE914
2 changed files with 35 additions and 11 deletions
  1. +4
    -11
      elbank-overview.el
  2. +31
    -0
      elbank-report.el

+ 4
- 11
elbank-overview.el View File

@ -203,14 +203,12 @@ If nothing important is at point, return nil."
(defun elbank-overview--insert-saved-reports-type (type)
"Insert links to saved reports of period TYPE."
(let ((label) (reports) (time))
(let (label reports)
(pcase type
(`month (setq label "Monthly reports")
(setq reports elbank-saved-monthly-reports)
(setq time (car (last (elbank-transaction-months)))))
(setq reports elbank-saved-monthly-reports))
(`year (setq label "Yearly reports")
(setq reports elbank-saved-yearly-reports)
(setq time (car (last (elbank-transaction-years))))))
(setq reports elbank-saved-yearly-reports)))
(when reports
(insert label)
(put-text-property (point-at-bol) (point)
@ -226,12 +224,7 @@ If nothing important is at point, return nil."
(make-button beg (point)
'action
(lambda (&rest _)
(elbank-report :category (seq-elt report 1)
:group-by (seq-elt report 2)
:sort-by (seq-elt report 3)
:columns (seq-elt report 4)
:reverse-sort (seq-elt report 5)
:period (list type time))))
(elbank-report--open-saved-report report type)))
(put-text-property beg (point) 'imenu-name (car report))
(insert "\n"))))))


+ 31
- 0
elbank-report.el View File

@ -193,6 +193,37 @@ Return the report buffer."
(elbank-report-refresh)
buf))
(defun elbank-report--all-saved-reports ()
"Return a list of all saved reports, monthly and yearly."
(append elbank-saved-monthly-reports elbank-saved-yearly-reports))
(defun elbank-report--open-saved-report (report period-type)
"Open a buffer presenting REPORT.
PERIOD-TYPE is either `month' or `year'."
(let ((time (if (eq period-type 'month)
(car (last (elbank-transaction-months)))
(car (last (elbank-transaction-years))))))
(elbank-report :category (seq-elt report 1)
:group-by (seq-elt report 2)
:sort-by (seq-elt report 3)
:columns (seq-elt report 4)
:reverse-sort (seq-elt report 5)
:period (list period-type time))))
(defun elbank-report-open-by-name (name)
"Open report named NAME."
(interactive (list (completing-read
"Report: "
(seq-map (lambda (report) (seq-elt report 0))
(elbank-report--all-saved-reports)))))
(when-let* ((report (seq-find
(lambda (report) (string= (seq-elt report 0) name))
(elbank-report--all-saved-reports)))
(type (if (seq-contains elbank-saved-monthly-reports report)
'month
'year)))
(elbank-report--open-saved-report report type)))
(defun elbank-report-filter-category ()
"Prompt for a category and update the report buffer."
(interactive)


Loading…
Cancel
Save