2001-05-12 Christian Stimming <stimming@tuhh.de>

* src/scm/report/pnl.scm, account-piecharts.scm,
	account-summary.scm: Added price-source option. Use new function
	gnc:case-exchange-fn.

	* src/scm/date-utilities.scm (gnc:get-end-cur-fin-year): added
	function.

	* src/scm/options-utilities.scm (gnc:options-add-date-interval!):
	changed the order of relative dates - which order is best?

	* src/scm/report/balance-sheet.scm: use new function
	gnc:case-exchange-fn.

	* src/scm/commodity-utilities.scm (gnc:case-exchange-fn): add
	function.

	* src/scm/report/price-scatter.scm: adapted helper function name
	to other reports.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4171 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2001-05-12 08:41:01 +00:00
parent df5b1cf465
commit 455cc47410
9 changed files with 190 additions and 92 deletions

View File

@ -1,5 +1,24 @@
2001-05-12 Christian Stimming <stimming@tuhh.de>
* src/scm/report/pnl.scm, account-piecharts.scm,
account-summary.scm: Added price-source option. Use new function
gnc:case-exchange-fn.
* src/scm/date-utilities.scm (gnc:get-end-cur-fin-year): added
function.
* src/scm/options-utilities.scm (gnc:options-add-date-interval!):
changed the order of relative dates - which order is best?
* src/scm/report/balance-sheet.scm: use new function
gnc:case-exchange-fn.
* src/scm/commodity-utilities.scm (gnc:case-exchange-fn): add
function.
* src/scm/report/price-scatter.scm: adapted helper function name
to other reports.
* src/scm/report/price-scatter.scm: Extended option to use the
pricedb as a price source.

View File

@ -543,6 +543,22 @@
domestic date))
#f))
;; Return a ready-to-use function. Which one is determined by the
;; value of 'source-option', whose possible values are set in
;; gnc:options-add-price-source!.
(define (gnc:case-exchange-fn
source-option report-currency to-date-tp)
(case source-option
('weighted-average (gnc:make-exchange-function
(gnc:make-exchange-alist
report-currency to-date-tp)))
('pricedb-latest gnc:exchange-by-pricedb-latest)
('pricedb-nearest (lambda (foreign domestic)
(gnc:exchange-by-pricedb-nearest
foreign domestic to-date-tp)))
(else (gnc:warn "gnc:case-exchange-gn: bad price-source value"))))
;; Adds all different commodities in the commodity-collector <foreign>
;; by using the exchange rates of <exchange-fn> to calculate the

View File

@ -467,6 +467,27 @@
(set-tm:isdst now -1)
(gnc:date->timepair now)))))
(define (gnc:get-end-cur-fin-year)
(let ((now (localtime (current-time))))
(if (< (tm:mon now) 6)
(begin
(set-tm:sec now 59)
(set-tm:min now 59)
(set-tm:hour now 23)
(set-tm:mday now 30)
(set-tm:mon now 5)
(set-tm:isdst now -1)
(gnc:date->timepair now))
(begin
(set-tm:sec now 59)
(set-tm:min now 59)
(set-tm:hour now 23)
(set-tm:mday now 30)
(set-tm:mon now 5)
(set-tm:year now (+ (tm:year now) 1))
(set-tm:isdst now -1)
(gnc:date->timepair now)))))
(define (gnc:get-start-this-month)
(let ((now (localtime (current-time))))
(set-tm:sec now 0)
@ -685,6 +706,13 @@
'store 'end-prev-fin-year-desc
(N_ "End of the previous Financial year/Accounting Period"))
(gnc:reldate-string-db
'store 'end-cur-fin-year-string
(N_ "End Current Financial Year"))
(gnc:reldate-string-db
'store 'end-cur-fin-year-desc
(N_ "End of the current Financial year/Accounting Period"))
(gnc:reldate-string-db
'store 'start-this-month-string
(N_ "Start of this month"))
@ -806,6 +834,10 @@
(gnc:reldate-string-db 'lookup 'end-prev-fin-year-string)
(gnc:reldate-string-db 'lookup 'end-prev-fin-year-desc)
gnc:get-end-prev-fin-year)
(vector 'end-cur-fin-year
(gnc:reldate-string-db 'lookup 'end-cur-fin-year-string)
(gnc:reldate-string-db 'lookup 'end-cur-fin-year-desc)
gnc:get-end-cur-fin-year)
(vector 'start-this-month
(gnc:reldate-string-db 'lookup 'start-this-month-string)
(gnc:reldate-string-db 'lookup 'start-this-month-desc)

View File

@ -37,15 +37,19 @@
pagename optname
sort-tag (N_ "Select a date to report on")
(lambda ()
; (cons 'absolute
; (gnc:secs->timepair
; (car (mktime (localtime (current-time)))))))
(cons 'relative 'today))
#f 'both
'(end-cal-year end-current-quarter end-this-month
today end-prev-month end-prev-quarter
end-prev-year ;;end-prev-fin-year
))))
'(
today
end-this-month
end-prev-month
end-current-quarter
end-prev-quarter
end-cal-year
end-prev-year
end-cur-fin-year
end-prev-fin-year
))))
;; This is a date-interval for a report.
@ -59,12 +63,16 @@
(N_ "Start of reporting period")
(lambda () (cons 'relative 'start-cal-year))
#f 'both
'(start-this-month start-prev-month start-current-quarter
start-prev-quarter start-cal-year
;;start-cur-fin-year
start-prev-year
;;start-prev-fin-year
)))
'(
start-this-month
start-prev-month
start-current-quarter
start-prev-quarter
start-cal-year
start-prev-year
start-cur-fin-year
start-prev-fin-year
)))
(gnc:register-option
options
(gnc:make-date-option
@ -73,10 +81,17 @@
(N_ "End of reporting period")
(lambda () (cons 'relative 'today))
#f 'both
'(end-cal-year end-current-quarter end-this-month
today end-prev-month end-prev-quarter end-prev-year
;;end-prev-fin-year
))))
'(
today
end-this-month
end-prev-month
end-current-quarter
end-prev-quarter
end-cal-year
end-prev-year
end-cur-fin-year
end-prev-fin-year
))))
;; A date interval multichoice option.
(define (gnc:options-add-interval-choice!

View File

@ -55,6 +55,7 @@ balance at a given time"))
(optname-from-date (N_ "From"))
(optname-to-date (N_ "To"))
(optname-report-currency (N_ "Report's currency"))
(optname-price-source (N_ "Price Source"))
(optname-accounts (N_ "Accounts"))
(optname-levels (N_ "Show Accounts until level"))
@ -85,6 +86,10 @@ balance at a given time"))
(gnc:options-add-currency!
options gnc:pagename-general optname-report-currency "b")
(gnc:options-add-price-source!
options gnc:pagename-general
optname-price-source "c" 'weighted-average)
(add-option
(gnc:make-account-list-option
gnc:pagename-accounts optname-accounts
@ -139,7 +144,7 @@ balance at a given time"))
account-types do-intervals?)
;; This is a helper function for looking up option values.
(define (op-value section name)
(define (get-option section name)
(gnc:option-value
(gnc:lookup-option
(gnc:report-options report-obj) section name)))
@ -147,25 +152,27 @@ balance at a given time"))
;; Get all options
(let ((to-date-tp (gnc:timepair-end-day-time
(gnc:date-option-absolute-time
(op-value gnc:pagename-general optname-to-date))))
(get-option gnc:pagename-general optname-to-date))))
(from-date-tp (if do-intervals?
(gnc:timepair-start-day-time
(gnc:date-option-absolute-time
(op-value gnc:pagename-general
(get-option gnc:pagename-general
optname-from-date)))
'()))
(accounts (op-value gnc:pagename-accounts optname-accounts))
(account-levels (op-value gnc:pagename-accounts optname-levels))
(report-currency (op-value gnc:pagename-general
(accounts (get-option gnc:pagename-accounts optname-accounts))
(account-levels (get-option gnc:pagename-accounts optname-levels))
(report-currency (get-option gnc:pagename-general
optname-report-currency))
(report-title (op-value gnc:pagename-general
(price-source (get-option gnc:pagename-general
optname-price-source))
(report-title (get-option gnc:pagename-general
gnc:optname-reportname))
(show-fullname? (op-value gnc:pagename-display optname-fullname))
(show-total? (op-value gnc:pagename-display optname-show-total))
(max-slices (op-value gnc:pagename-display optname-slices))
(height (op-value gnc:pagename-display optname-plot-height))
(width (op-value gnc:pagename-display optname-plot-width))
(show-fullname? (get-option gnc:pagename-display optname-fullname))
(show-total? (get-option gnc:pagename-display optname-show-total))
(max-slices (get-option gnc:pagename-display optname-slices))
(height (get-option gnc:pagename-display optname-plot-height))
(width (get-option gnc:pagename-display optname-plot-width))
(document (gnc:make-html-document))
(chart (gnc:make-html-piechart))
@ -191,10 +198,8 @@ balance at a given time"))
account to-date-tp subaccts?)))
;; Define more helper variables.
(let* ((exchange-alist (gnc:make-exchange-alist
report-currency to-date-tp))
(exchange-fn-internal
(gnc:make-exchange-function exchange-alist))
(let* ((exchange-fn (gnc:case-exchange-fn
price-source report-currency to-date-tp))
(tree-depth (if (equal? account-levels 'all)
(gnc:get-current-group-depth)
account-levels))
@ -204,7 +209,7 @@ balance at a given time"))
;; Converts a commodity-collector into one single double
;; number, depending on the report currency and the
;; exchange-alist calculated above. Returns the absolute value
;; exchange-fn calculated above. Returns the absolute value
;; as double.
(define (collector->double c)
;; Future improvement: Let the user choose which kind of
@ -216,7 +221,7 @@ balance at a given time"))
(gnc:gnc-monetary-amount
(gnc:sum-collector-commodity
c report-currency
exchange-fn-internal)))))
exchange-fn)))))
;; Calculates all account's balances. Returns a list of
;; balance <=> account pairs, like '((10.0 Earnings) (142.5

View File

@ -35,21 +35,20 @@
;; first define all option's names such that typos etc. are no longer
;; possible.
(let ((pagename-general (N_ "General"))
(optname-date (N_ "Date"))
(let ((optname-date (N_ "Date"))
(optname-display-depth (N_ "Account Display Depth"))
(optname-show-foreign (N_ "Show Foreign Currencies/Shares of Stock"))
(optname-report-currency (N_ "Report's currency"))
(optname-price-source (N_ "Price Source"))
(pagename-accounts (N_ "Accounts"))
(optname-show-subaccounts (N_ "Always show sub-accounts"))
(optname-accounts (N_ "Account"))
(pagename-display (N_ "Display"))
(optname-group-accounts (N_ "Group the accounts"))
(optname-show-parent-balance (N_ "Show balances for parent accounts"))
(optname-show-parent-total (N_ "Show subtotals")))
(optname-show-parent-total (N_ "Show subtotals"))
(optname-show-rates (N_ "Show Exchange Rates")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; options generator
@ -62,16 +61,20 @@
(let* ((options (gnc:new-options)))
;; date at which to report balance
(gnc:options-add-report-date!
options pagename-general optname-date "a")
options gnc:pagename-general optname-date "a")
;; all about currencies
(gnc:options-add-currency!
options pagename-general
options gnc:pagename-general
optname-report-currency "b")
(gnc:options-add-price-source!
options gnc:pagename-general
optname-price-source "c" 'weighted-average)
;; accounts to work on
(gnc:options-add-account-selection!
options pagename-accounts
options gnc:pagename-accounts
optname-display-depth optname-show-subaccounts
optname-accounts "a" 1
(lambda ()
@ -83,19 +86,19 @@
;; with or without grouping
(gnc:options-add-group-accounts!
options pagename-display optname-group-accounts "b" #t)
options gnc:pagename-display optname-group-accounts "b" #t)
;; new options here
(gnc:register-option
options
(gnc:make-simple-boolean-option
pagename-display optname-show-parent-balance
gnc:pagename-display optname-show-parent-balance
"c" (N_ "Show balances for parent accounts") #t))
(gnc:register-option
options
(gnc:make-simple-boolean-option
pagename-display optname-show-parent-total
gnc:pagename-display optname-show-parent-total
"d" (N_ "Show subtotals for parent accounts") #t))
(gnc:register-option
@ -104,8 +107,14 @@
gnc:pagename-display optname-show-foreign
"e" (N_ "Display the account's foreign currency amount?") #f))
(gnc:register-option
options
(gnc:make-simple-boolean-option
gnc:pagename-display optname-show-rates
"f" (N_ "Show the exchange rates used") #t))
;; Set the general page as default option tab
(gnc:options-set-default-section options pagename-general)
(gnc:options-set-default-section options gnc:pagename-general)
options))
@ -120,23 +129,27 @@
(gnc:lookup-option
(gnc:report-options report-obj) pagename optname)))
(let ((display-depth (get-option pagename-accounts
(let ((display-depth (get-option gnc:pagename-accounts
optname-display-depth ))
(show-subaccts? (get-option pagename-accounts
(show-subaccts? (get-option gnc:pagename-accounts
optname-show-subaccounts))
(accounts (get-option pagename-accounts optname-accounts))
(do-grouping? (get-option pagename-display
(accounts (get-option gnc:pagename-accounts optname-accounts))
(do-grouping? (get-option gnc:pagename-display
optname-group-accounts))
(show-parent-balance? (get-option pagename-display
(show-parent-balance? (get-option gnc:pagename-display
optname-show-parent-balance))
(show-parent-total? (get-option pagename-display
(show-parent-total? (get-option gnc:pagename-display
optname-show-parent-total))
(show-fcur? (get-option pagename-display optname-show-foreign))
(report-currency (get-option pagename-general
(show-fcur? (get-option gnc:pagename-display optname-show-foreign))
(report-currency (get-option gnc:pagename-general
optname-report-currency))
(price-source (get-option gnc:pagename-general
optname-price-source))
(show-rates? (get-option gnc:pagename-display
optname-show-rates))
(date-tp (gnc:timepair-end-day-time
(gnc:date-option-absolute-time
(get-option pagename-general
(get-option gnc:pagename-general
optname-date))))
(doc (gnc:make-html-document))
(txt (gnc:make-html-text)))
@ -149,9 +162,8 @@
(gnc:get-current-group-depth)
display-depth)
(if do-grouping? 1 0)))
(exchange-alist (gnc:make-exchange-alist
report-currency date-tp))
(exchange-fn (gnc:make-exchange-function exchange-alist))
(exchange-fn (gnc:case-exchange-fn
price-source report-currency date-tp))
;; do the processing here
(table (gnc:html-build-acct-table
#f date-tp
@ -165,16 +177,18 @@
;; add the table
(gnc:html-document-add-object! doc table)
;; add the currency information
;(gnc:html-print-exchangerates!
; txt report-currency exchange-alist)
;; add currency information
(if show-rates?
(gnc:html-document-add-object!
doc ;;(gnc:html-markup-p
(gnc:html-make-exchangerates
report-currency exchange-fn
(append-map
(lambda (a)
(gnc:group-get-subaccounts
(gnc:account-get-children a)))
accounts)))))
;;(if show-fcur?
(gnc:html-document-add-object!
doc ;;(gnc:html-markup-p
(gnc:html-make-exchangerates
report-currency exchange-fn accounts)));;)
;; error condition: no accounts specified
(gnc:html-document-add-object!
doc

View File

@ -180,16 +180,8 @@
(gnc:get-current-group-depth)
display-depth))
;; calculate the exchange rates
(exchange-fn
(case price-source
('weighted-average (gnc:make-exchange-function
(gnc:make-exchange-alist
report-currency to-date-tp)))
('pricedb-latest gnc:exchange-by-pricedb-latest)
('pricedb-nearest (lambda (foreign domestic)
(gnc:exchange-by-pricedb-nearest
foreign domestic to-date-tp)))
(else (gnc:warn "balance-sheet: bad price-source value"))))
(exchange-fn (gnc:case-exchange-fn
price-source report-currency to-date-tp))
(totals-get-balance (lambda (account)
(gnc:account-get-comm-balance-at-date
account to-date-tp #f))))

View File

@ -61,6 +61,10 @@
options gnc:pagename-general
optname-report-currency "b")
(gnc:options-add-price-source!
options gnc:pagename-general
optname-price-source "c" 'weighted-average)
;; accounts to work on
(gnc:options-add-account-selection!
options gnc:pagename-accounts
@ -135,6 +139,8 @@
optname-show-foreign))
(report-currency (get-option gnc:pagename-general
optname-report-currency))
(price-source (get-option gnc:pagename-general
optname-price-source))
(show-rates? (get-option gnc:pagename-display
optname-show-rates))
(to-date-tp (gnc:timepair-end-day-time
@ -160,9 +166,8 @@
display-depth)
(if do-grouping? 1 0)))
;; calculate the exchange rates
(exchange-alist (gnc:make-exchange-alist
report-currency to-date-tp))
(exchange-fn (gnc:make-exchange-function exchange-alist))
(exchange-fn (gnc:case-exchange-fn
price-source report-currency to-date-tp))
;; do the processing here
(table (gnc:html-build-acct-table
from-date-tp to-date-tp

View File

@ -113,7 +113,7 @@
(define (renderer report-obj)
;; This is a helper function for looking up option values.
(define (op-value section name)
(define (get-option section name)
(gnc:option-value
(gnc:lookup-option (gnc:report-options report-obj) section name)))
@ -125,29 +125,29 @@
(let* ((to-date-tp (gnc:timepair-end-day-time
(gnc:date-option-absolute-time
(op-value gnc:pagename-general
(get-option gnc:pagename-general
optname-to-date))))
(from-date-tp (gnc:timepair-start-day-time
(gnc:date-option-absolute-time
(op-value gnc:pagename-general
(get-option gnc:pagename-general
optname-from-date))))
(interval (op-value gnc:pagename-general optname-stepsize))
(report-title (op-value gnc:pagename-general
(interval (get-option gnc:pagename-general optname-stepsize))
(report-title (get-option gnc:pagename-general
gnc:optname-reportname))
(height (op-value gnc:pagename-display optname-plot-height))
(width (op-value gnc:pagename-display optname-plot-width))
(marker (op-value gnc:pagename-display optname-marker))
(height (get-option gnc:pagename-display optname-plot-height))
(width (get-option gnc:pagename-display optname-plot-width))
(marker (get-option gnc:pagename-display optname-marker))
(mcolor
(gnc:color-option->hex-string
(gnc:lookup-option (gnc:report-options report-obj)
gnc:pagename-display optname-markercolor)))
(report-currency (op-value pagename-price
(report-currency (get-option pagename-price
optname-report-currency))
(price-commodity (op-value pagename-price
(price-commodity (get-option pagename-price
optname-price-commodity))
(price-source (op-value pagename-price
(price-source (get-option pagename-price
optname-price-source))
(dates-list (gnc:make-date-list