mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
2001-04-26 Christian Stimming <stimming@tuhh.de>
* src/scm/commodity-utilities.scm (gnc:exchange-by-pricedb-{latest,nearest}): new functions. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4057 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
133d9aa2fc
commit
2ccf12241d
@ -1,3 +1,8 @@
|
||||
2001-04-26 Christian Stimming <stimming@tuhh.de>
|
||||
|
||||
* src/scm/commodity-utilities.scm
|
||||
(gnc:exchange-by-pricedb-{latest,nearest}): new functions.
|
||||
|
||||
2001-04-26 Dave Peticolas <dave@krondo.com>
|
||||
|
||||
* src/gnome/window-main.c: handle scm parsing errors
|
||||
|
@ -274,7 +274,7 @@
|
||||
|
||||
;; This one returns the ready-to-use function for calculation of the
|
||||
;; exchange rates. The returned function takes a <gnc-monetary> and
|
||||
;; the domestic-commodity, exchanges the amount in the domestic
|
||||
;; the domestic-commodity, exchanges the amount into the domestic
|
||||
;; currency and returns a <gnc-monetary>.
|
||||
(define (gnc:make-exchange-function exchange-alist)
|
||||
(let ((exchangelist exchange-alist))
|
||||
@ -292,6 +292,66 @@
|
||||
GNC-RND-ROUND))))
|
||||
#f))))
|
||||
|
||||
;; Helper for gnc:exchange-by-pricedb-* below. 'price' gets tested for
|
||||
;; #f here, and gets unref'd here too. Returns a <gnc:monetary>.
|
||||
(define (gnc:exchange-by-price-helper
|
||||
foreign domestic price)
|
||||
(if (gnc:gnc-monetary? foreign)
|
||||
(gnc:make-gnc-monetary
|
||||
domestic
|
||||
(if price
|
||||
(let ((result
|
||||
(gnc:numeric-mul (gnc:gnc-monetary-amount foreign)
|
||||
(gnc:price-get-value price)
|
||||
(gnc:commodity-get-fraction domestic)
|
||||
GNC-RND-ROUND)))
|
||||
(gnc:price-unref price)
|
||||
result)
|
||||
(begin
|
||||
(warn "gnc:exchange-by-price-helper: No price found for "
|
||||
(gnc:commodity-value->string foreign) " into "
|
||||
(gnc:commodity-value->string
|
||||
(list domestic (gnc:numeric-zero))))
|
||||
(gnc:numeric-zero))))
|
||||
#f))
|
||||
|
||||
;; This is another ready-to-use function for calculation of exchange
|
||||
;; rates. (Note that this is already the function itself. It doesn't
|
||||
;; return a function as opposed to make-exchange-function.) It takes
|
||||
;; the <gnc-monetary> 'foreign' amount and the <gnc:commodity*>
|
||||
;; 'domestic' commodity. It exchanges the amount into the domestic
|
||||
;; currency, using the latest price from the pricedb. The function
|
||||
;; returns a <gnc-monetary>.
|
||||
(define (gnc:exchange-by-pricedb-latest
|
||||
foreign domestic)
|
||||
(if (and (record? foreign) (gnc:gnc-monetary? foreign))
|
||||
(gnc:exchange-by-price-helper
|
||||
foreign domestic
|
||||
(gnc:pricedb-lookup-latest
|
||||
(gnc:gnc-monetary-commodity foreign)
|
||||
domestic))
|
||||
#f))
|
||||
|
||||
;; Yet another ready-to-use function for calculation of exchange
|
||||
;; rates. (Note that this is already the function itself. It doesn't
|
||||
;; return a function as opposed to make-exchange-function.) It takes
|
||||
;; the <gnc-monetary> 'foreign' amount, the <gnc:commodity*>
|
||||
;; 'domestic' commodity *and* a <gnc:time-pair> 'date'. It exchanges
|
||||
;; the amount into the domestic currency, using a price from the
|
||||
;; pricedb according to the given date. The function returns a
|
||||
;; <gnc-monetary>.
|
||||
(define (gnc:exchange-by-pricedb-nearest
|
||||
foreign domestic date)
|
||||
(if (and (record? foreign) (gnc:gnc-monetary? foreign)
|
||||
date)
|
||||
(gnc:exchange-by-price-helper
|
||||
foreign domestic
|
||||
(gnc:pricedb-lookup-nearest-in-time
|
||||
(gnc:gnc-monetary-commodity foreign)
|
||||
domestic date))
|
||||
#f))
|
||||
|
||||
|
||||
;; Adds all different commodities in the commodity-collector <foreign>
|
||||
;; by using the exchange rates of <exchange-fn> to calculate the
|
||||
;; exchange rates to the commodity <domestic>. Returns a
|
||||
|
Loading…
Reference in New Issue
Block a user