Hello,

I was trying hacking on a budget reporting feature in the svn trunk
for my own curiosity.  Unfortunately, I apparently suck at Scheme.  I
thought the code looked intuitive enough that I could hack up
something simple without much pain but I was wrong.  In fact, now I am
frustrated because I seem to be stuck on initializing a variable of
all things.

I was hoping someone who knew Scheme could point out my error for me.
I have never ever touched Scheme before last weekend.

The following snippet of code seems to be the source of my problems:

@@ -140,6 +147,7 @@
     (let* ((num-periods (gnc-budget-get-num-periods budget))
            (period 0)
            (current-col (+ colnum 1))
+           (tdif-dif-total (gnc-numeric-zero))
            )
       (while (< period num-periods)
              (let* (
@@ -170,6 +178,13 @@
                                  (gnc:make-gnc-monetary comm dif-numeric-val)))
                     )

+                    ;; total difference (total period budget to total
period actual)
+                    (tdif-dif-total (gnc-numeric-add dif-numeric-val
+                                 tdif-dif-total GNC-DENOM-AUTO
+                                 (+ GNC-DENOM-LCD GNC-RND-NEVER)))
+                    (tdif-val (if bgt-unset? "."
+                                 (gnc:make-gnc-monetary comm tdif-dif-total)))
+
                (if show-budget?
                  (begin
                    (gnc:html-table-set-cell!

With the following error message:

In unknown file:
    ...
   ?: 35  [while-helper #<procedure #f (break continue)>]
   ?: 36  (do ((key (make-symbol "while-key"))) ((catch key (lambda () #) ...)))
   ?: 37* [catch #<uninterned-symbol while-key b5742cd0> #<procedure #f ()> ...]
   ?: 38* [#<procedure #f ()>]
   ?: 39* [#<procedure #f (break continue)> #<procedure #f ()>
#<procedure #f ()>]
   ?: 40* (do () ((#<primitive-procedure not> (< period num-periods))) ...)
In /opt/gnucash/trunk/share/gnucash/guile-modules/gnucash/report/budget.scm:
 153: 41* (let* (# # # # ...) (tdif-dif-total #) (tdif-val #) ...)
 182: 42* [#<<gnc-numeric> num: 0 denom: 1> #<<gnc-numeric> num:
-542131 denom: 100>]
/opt/gnucash/trunk/share/gnucash/guile-modules/gnucash/report/budget.scm:182:21:
In expression (tdif-dif-total (gnc-numeric-add dif-numeric-val
tdif-dif-total ...)):
/opt/gnucash/trunk/share/gnucash/guile-modules/gnucash/report/budget.scm:182:21:
Wrong type to apply: #<<gnc-numeric> num: 0denom: 1>

I have also attached the whole patch, in case that matters.  Thanks in advance.

Cheers,
Don

ps - please cc me as I am not subscribed to the list
--- budget.scm.orig	2009-01-25 13:27:35.000000000 -0500
+++ budget.scm	2009-01-27 21:28:22.000000000 -0500
@@ -53,9 +53,11 @@
 (define optname-show-budget (N_ "Show Budget"))
 (define optname-show-actual (N_ "Show Actual"))
 (define optname-show-difference (N_ "Show Difference"))
+(define optname-show-total-difference (N_ "Show Total Difference"))
 (define opthelp-show-budget (N_ "Display a column for the budget values"))
 (define opthelp-show-actual (N_ "Display a column for the actual values"))
 (define opthelp-show-difference (N_ "Display the difference as budget - actual"))
+(define opthelp-show-total-difference (N_ "Display the total difference as total period budget - total period actual"))
 
 (define optname-budget (N_ "Budget"))
 
@@ -117,6 +119,10 @@
      (gnc:make-simple-boolean-option
       gnc:pagename-display optname-show-difference
       "s3" opthelp-show-difference #f))
+    (add-option
+     (gnc:make-simple-boolean-option
+      gnc:pagename-display optname-show-total-difference
+      "s3" opthelp-show-total-difference #f))
 
       ;; Set the general page as default option tab
     (gnc:options-set-default-section options gnc:pagename-general)
@@ -132,6 +138,7 @@
          (show-actual? (get-val params 'show-actual))
          (show-budget? (get-val params 'show-budget))
          (show-diff? (get-val params 'show-difference))
+         (show-total-diff? (get-val params 'show-total-difference))
         )
   
   (define (gnc:html-table-add-budget-line!
@@ -140,6 +147,7 @@
     (let* ((num-periods (gnc-budget-get-num-periods budget))
            (period 0)
            (current-col (+ colnum 1))
+           (tdif-dif-total (gnc-numeric-zero))
            )
       (while (< period num-periods)
              (let* (
@@ -170,6 +178,13 @@
                                  (gnc:make-gnc-monetary comm dif-numeric-val)))
                     )
 
+                    ;; total difference (total period budget to total period actual)
+                    (tdif-dif-total (gnc-numeric-add dif-numeric-val
+                                 tdif-dif-total GNC-DENOM-AUTO
+                                 (+ GNC-DENOM-LCD GNC-RND-NEVER)))
+                    (tdif-val (if bgt-unset? "."
+                                 (gnc:make-gnc-monetary comm tdif-dif-total)))
+
                (if show-budget?
                  (begin
                    (gnc:html-table-set-cell!
@@ -191,6 +206,13 @@
                    (set! current-col (+ current-col 1))
                  )
                )
+               (if show-total-diff?
+                 (begin
+                   (gnc:html-table-set-cell!
+                    html-table rownum current-col tdif-val)
+                   (set! current-col (+ current-col 1))
+                 )
+               )
                (set! period (+ period 1))
              )
         )
@@ -236,6 +258,14 @@
                    (set! current-col (+ current-col 1))
                  )
                )
+               (if show-total-diff?
+                 (begin 
+                   (gnc:html-table-set-cell!
+                    html-table 1
+                    current-col (_ "Total")) ;; Translators: Abbrevation for "Total Period Difference"
+                   (set! current-col (+ current-col 1))
+                 )
+               )
                (set! period (+ period 1))
                )
              )
@@ -387,6 +417,8 @@
                        (get-option gnc:pagename-display optname-show-budget))
                  (list 'show-difference
                        (get-option gnc:pagename-display optname-show-difference))
+                 (list 'show-total-difference
+                       (get-option gnc:pagename-display optname-show-total-difference))
                 )
                )
                (report-name (get-option gnc:pagename-general
_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to