From 7d546af6577986875f8418a45993c9feda01a549 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Wed, 7 Feb 2001 09:27:30 +0000 Subject: [PATCH] Christian Stimming's report patch. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3614 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/scm/gnc-numeric.scm | 22 ++++++++++++++++++++-- src/scm/html-style-info.scm | 5 +++++ src/scm/html-style-sheet.scm | 4 ++++ src/scm/report-utilities.scm | 13 ++++++++++--- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/scm/gnc-numeric.scm b/src/scm/gnc-numeric.scm index 36a53fe1fd..e994ba9f2d 100644 --- a/src/scm/gnc-numeric.scm +++ b/src/scm/gnc-numeric.scm @@ -1,6 +1,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; gnc-numeric.scm : rational number representation for gnucash ;; Copyright 2000 Bill Gribble +;; Copyright 2001 Christian Stimming ;; ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as @@ -64,6 +65,23 @@ (- arg)) - - + +(define + (make-record-type "" + '(commodity amount))) + +;; Constructor; takes one and one +(define (gnc:make-gnc-monetary c a) + (if (and (gw:wcp-is-of-type? c) (gnc:gnc-numeric? a)) + ((record-constructor ) c a) + #f)) + +(define gnc:gnc-monetary? + (record-predicate )) + +(define gnc:gnc-monetary-commodity + (record-accessor 'commodity)) + +(define gnc:gnc-monetary-amount + (record-accessor 'amount)) diff --git a/src/scm/html-style-info.scm b/src/scm/html-style-info.scm index fc90839a6f..ebbf65de86 100644 --- a/src/scm/html-style-info.scm +++ b/src/scm/html-style-info.scm @@ -221,6 +221,11 @@ ; (gnc:numeric-to-string datum)) (sprintf #f "%.2f" (gnc:numeric-to-double datum))) +(define (gnc:default-html-gnc-monetary-renderer datum params) + (gnc:amount->string-helper + (gnc:gnc-monetary-amount datum) + (gnc:commodity-print-info (gnc:gnc-monetary-amount datum) #t))) + (define (gnc:default-html-number-renderer datum params) (sprintf #f "%.2f" datum)) diff --git a/src/scm/html-style-sheet.scm b/src/scm/html-style-sheet.scm index d21e7056f7..82cbc33b06 100644 --- a/src/scm/html-style-sheet.scm +++ b/src/scm/html-style-sheet.scm @@ -151,6 +151,10 @@ rv "" gnc:default-html-number-renderer #f) + (gnc:html-style-sheet-set-style! + rv "" + gnc:default-html-gnc-monetary-renderer #f) + ;; store it in the style sheet hash (hash-set! *gnc:_style-sheets_* style-sheet-name rv) rv) diff --git a/src/scm/report-utilities.scm b/src/scm/report-utilities.scm index eaa49cdd00..6b1b0e56fb 100644 --- a/src/scm/report-utilities.scm +++ b/src/scm/report-utilities.scm @@ -26,13 +26,20 @@ (define (gnc:commodity-amount->string amount info) (gnc:amount->string-helper amount info)) -;; pair is a list of one gnc:commodity and one gnc:numeric value. This -;; function should disappear once this is an "official" data type, so -;; that the data type will be accepted by the html-renderer. +;; pair is a list of one gnc:commodity and one gnc:numeric +;; value. Deprecated -- use instead. (define (gnc:commodity-value->string pair) (gnc:commodity-amount->string (cadr pair) (gnc:commodity-print-info (car pair) #t))) +;; Just for convenience. But in reports you should rather stick to the +;; style-info mechanism and simple plug the into the +;; html-renderer. +(define (gnc:monetary->string value) + (gnc:amount->string-helper + (gnc:gnc-monetary-amount value) + (gnc:commodity-print-info (gnc:gnc-monetary-amount value) #t))) + ;; True if the account is of type currency, stock, or mutual-fund (define (gnc:account-has-shares? account) ;; FYI: The val->sym function used to be called