diff --git a/gnucash/report/commodity-utilities.scm b/gnucash/report/commodity-utilities.scm index c6c87efa2d..e777a2a842 100644 --- a/gnucash/report/commodity-utilities.scm +++ b/gnucash/report/commodity-utilities.scm @@ -21,6 +21,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (use-modules (ice-9 match)) +(use-modules (srfi srfi-26)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Functions to get splits with interesting data from accounts. @@ -764,6 +765,18 @@ (gnc:exchange-by-pricedb-nearest foreign domestic to-date-tp)))))) +(define (gnc:case-price-fn source target-curr date) + (define pdb (gnc-pricedb-get-db (gnc-get-current-book))) + (case source + ((pricedb-nearest) (cut gnc-pricedb-get-nearest-price pdb <> target-curr date)) + ((pricedb-latest) (cut gnc-pricedb-get-latest-price pdb <> target-curr)) + (else + (lambda (commodity) + (let* ((exchange-fn (gnc:case-exchange-fn source target-curr date)) + (foreign-mon (gnc:make-gnc-monetary commodity 1)) + (domestic-mon (exchange-fn foreign-mon target-curr))) + (gnc:gnc-monetary-amount domestic-mon)))))) + ;; Return a ready-to-use function. Which one to use is determined by ;; the value of 'source-option', whose possible values are set in ;; gnc:options-add-price-source!. diff --git a/gnucash/report/html-utilities.scm b/gnucash/report/html-utilities.scm index d536201e06..fb46b6a34f 100644 --- a/gnucash/report/html-utilities.scm +++ b/gnucash/report/html-utilities.scm @@ -228,6 +228,30 @@ (G_ "Exchange rates")))))) table)) +;; Create a html-table of all prices. The report-currency is +;; 'currency', The prices are given through the function 'price-fn' +;; and the 'accounts' determine which commodities to show. Returns a +;; html-object, a . price-fn is easily obtained from +;; gnc:case-price-fn +(define (gnc:html-make-rates-table currency price-fn accounts) + (define (cell c) (gnc:make-html-table-cell/markup "number-cell" c)) + (define table (gnc:make-html-table)) + (let lp ((comm-list (gnc:accounts-get-commodities accounts currency)) (entries 0)) + (match comm-list + (() + (unless (zero? entries) + (gnc:html-table-set-col-headers! + table (list (gnc:make-html-table-header-cell/size + 1 2 (if (= entries 1) (G_ "Exchange rate") + (G_ "Exchange rates")))))) + table) + ((comm . rest) + (gnc:html-table-append-row! + table + (list (cell (gnc:make-gnc-monetary comm 1)) + (cell (gnc:default-price-renderer currency (price-fn comm))))) + (lp rest (1+ entries)))))) + (define (gnc:html-make-generic-budget-warning report-title-string) (gnc:html-make-generic-simple-warning diff --git a/gnucash/report/report.scm b/gnucash/report/report.scm index 7791d969e3..8444da85c0 100644 --- a/gnucash/report/report.scm +++ b/gnucash/report/report.scm @@ -58,6 +58,7 @@ (export gnc:exchange-by-pricealist-nearest) (export gnc:case-exchange-fn) (export gnc:case-exchange-time-fn) +(export gnc:case-price-fn) (export gnc:sum-collector-commodity) ;; options-utilities.scm @@ -104,6 +105,7 @@ (export gnc:assign-colors) (export gnc:html-table-append-ruler!) (export gnc:html-make-exchangerates) +(export gnc:html-make-rates-table) (export gnc:html-render-options-changed) (export gnc:html-make-generic-warning) (export gnc:html-make-no-account-warning)