Index: src/report/standard-reports/budget.scm =================================================================== --- src/report/standard-reports/budget.scm (revision 18277) +++ src/report/standard-reports/budget.scm (working copy) @@ -60,6 +60,8 @@ (define opthelp-show-totalcol (N_ "Display a column with the row totals")) (define optname-rollup-budget (N_ "Roll up budget amounts to parent")) (define opthelp-rollup-budget (N_ "If parent account does not have its own budget value, use the sum of the child account budget values")) +(define optname-show-zb-accounts (N_ "Include accounts with zero total balances and budget values")) +(define opthelp-show-zb-accounts (N_ "Include accounts with zero total (recursive) balances and budget values in this report")) (define optname-compress-periods (N_ "Compress prior/later periods")) (define opthelp-compress-periods (N_ "Accumulate columns for periods before and after the current period to allow focus on the current period.")) (define optname-bottom-behavior (N_ "Flatten list to depth limit")) @@ -138,6 +140,10 @@ (gnc:make-simple-boolean-option gnc:pagename-display optname-rollup-budget "s4" opthelp-rollup-budget #f)) + (add-option + (gnc:make-simple-boolean-option + gnc:pagename-display optname-show-zb-accounts + "s5" opthelp-show-zb-accounts #t)) ;; Set the general page as default option tab (gnc:options-set-default-section options gnc:pagename-general) @@ -175,53 +181,7 @@ (colnum (quotient numcolumns 2)) ) - - ;; Calculate the sum of all budgets of all children of an account for a specific period - ;; - ;; Parameters: - ;; budget - budget to use - ;; children - list of children - ;; period - budget period to use - ;; - ;; Return value: - ;; budget value to use for account for specified period. - (define (budget-account-sum budget children period) - (let* ((sum - (cond - ((null? children) (gnc-numeric-zero)) - (else - (gnc-numeric-add - (gnc:get-account-period-rolledup-budget-value budget (car children) period) - (budget-account-sum budget (cdr children) period) - GNC-DENOM-AUTO GNC-RND-ROUND)) - ) - )) - sum) - ) - ;; Calculate the value to use for the budget of an account for a specific period. - ;; - If the account has a budget value set for the period, use it - ;; - If the account has children, use the sum of budget values for the children - ;; - Otherwise, use 0. - ;; - ;; Parameters: - ;; budget - budget to use - ;; acct - account - ;; period - budget period to use - ;; - ;; Return value: - ;; sum of all budgets for list of children for specified period. - (define (gnc:get-account-period-rolledup-budget-value budget acct period) - (let* ((bgt-set? (gnc-budget-is-account-period-value-set budget acct period)) - (children (gnc-account-get-children acct)) - (amount (cond - (bgt-set? (gnc-budget-get-account-period-value budget acct period)) - ((not (null? children)) (budget-account-sum budget children period)) - (else (gnc-numeric-zero))) - )) - amount) - ) - (define (negative-numeric-p x) (if (gnc-numeric-p x) (gnc-numeric-negative-p x) #f)) (define (number-cell-tag x) @@ -583,6 +543,8 @@ (bottom-behavior (get-option gnc:pagename-accounts optname-bottom-behavior)) (rollup-budget? (get-option gnc:pagename-display optname-rollup-budget)) + (show-zb-accts? (get-option gnc:pagename-display + optname-show-zb-accounts)) (row-num 0) ;; ??? (work-done 0) (work-to-do 0) @@ -666,10 +628,15 @@ ;; Things seem to crash if I don't set 'end-date to ;; _something_ but the actual value isn't used. - (env (list (list 'end-date (gnc:get-today)) - (list 'display-tree-depth tree-depth) + (env (list + (list 'start-date (gnc:budget-get-start-date budget)) + (list 'end-date (gnc:budget-get-end-date budget)) + (list 'display-tree-depth tree-depth) (list 'depth-limit-behavior - (if bottom-behavior 'flatten 'summarize)) + (if bottom-behavior 'flatten 'summarize)) + (list 'zero-balance-mode + (if show-zb-accts? 'show-leaf-acct 'omit-leaf-acct)) + (list 'report-budget budget) )) (acct-table #f) (html-table (gnc:make-html-table)) Index: src/report/report-system/html-acct-table.scm =================================================================== --- src/report/report-system/html-acct-table.scm (revision 18277) +++ src/report/report-system/html-acct-table.scm (working copy) @@ -247,6 +247,11 @@ ;; gnc:account-get-trans-type-balance-interval, matching ;; closing transactions to be ignored when balance-mode is ;; 'pre-closing. +;; +;; report-budget: budget +;; +;; (optional) a budget used to ignore accounts with zero +;; budget or balance (if zb-balance-mode is set to omit). ;; ;; account-type: unimplemented ;; account-class: unimplemented @@ -628,6 +633,7 @@ (list 'regexp #f) ) )) + (report-budget (or (get-val env 'report-budget) #f)) ;; local variables (toplvl-accts (gnc-account-get-children-sorted (gnc-get-current-root-account))) @@ -828,10 +834,15 @@ (set! acct-depth-reached (max acct-depth-reached acct-depth)) (set! logi-depth-reached (max logi-depth-reached logi-depth)) (set! disp-depth-reached (max disp-depth-reached disp-depth)) + (or (not (use-acct? acct)) ;; ok, so we'll consider parent accounts with zero ;; recursive-bal to be zero balance leaf accounts (and (gnc-commodity-collector-allzero? recursive-bal) + (or (not report-budget) + (gnc-numeric-zero-p + (gnc:budget-account-get-rolledup-net + report-budget account #f #f))) (equal? zero-mode 'omit-leaf-acct)) (begin (set! row-env Index: src/report/report-system/report-utilities.scm =================================================================== --- src/report/report-system/report-utilities.scm (revision 18277) +++ src/report/report-system/report-utilities.scm (working copy) @@ -863,6 +863,11 @@ (define (gnc:budget-get-start-date budget) (gnc-budget-get-period-start-date budget 0)) +;; Returns the end date of the last period of the budget. +(define (gnc:budget-get-end-date budget) + (gnc-budget-get-period-start-date budget (gnc-budget-get-num-periods budget))) + + (define (gnc:budget-accountlist-helper accountlist get-fn) (let ( @@ -930,6 +935,77 @@ (gnc:budget-accountlist-helper accountlist (lambda (account) (gnc:budget-account-get-initial-balance budget account)))) +;; Calculate the sum of all budgets of all children of an account for a specific period +;; +;; Parameters: +;; budget - budget to use +;; children - list of children +;; period - budget period to use +;; +;; Return value: +;; budget value to use for account for specified period. +(define (budget-account-sum budget children period) + (let* ((sum + (cond + ((null? children) (gnc-numeric-zero)) + (else + (gnc-numeric-add + (gnc:get-account-period-rolledup-budget-value budget (car children) period) + (budget-account-sum budget (cdr children) period) + GNC-DENOM-AUTO GNC-RND-ROUND)) + ) + )) + sum) +) + +;; Calculate the value to use for the budget of an account for a specific period. +;; - If the account has a budget value set for the period, use it +;; - If the account has children, use the sum of budget values for the children +;; - Otherwise, use 0. +;; +;; Parameters: +;; budget - budget to use +;; acct - account +;; period - budget period to use +;; +;; Return value: +;; sum of all budgets for list of children for specified period. +(define (gnc:get-account-period-rolledup-budget-value budget acct period) + (let* ((bgt-set? (gnc-budget-is-account-period-value-set budget acct period)) + (children (gnc-account-get-children acct)) + (amount (cond + (bgt-set? (gnc-budget-get-account-period-value budget acct period)) + ((not (null? children)) (budget-account-sum budget children period)) + (else (gnc-numeric-zero))) + )) + amount) +) + +;; Sums rolled-up budget values for a single account from start-period (inclusive) to +;; end-period (exclusive). +;; - If the account has a budget value set for the period, use it +;; - If the account has children, use the sum of budget values for the children +;; - Otherwise, use 0. +;; +;; start-period may be #f to specify the start of the budget +;; end-period may be #f to specify the end of the budget +;; +;; Returns a gnc-numeric value +(define (gnc:budget-account-get-rolledup-net budget account start-period end-period) + (if (not start-period) (set! start-period 0)) + (if (not end-period) (set! end-period (gnc-budget-get-num-periods budget))) + (let* + ( + (period start-period) + (net (gnc-numeric-zero)) + (acct-comm (xaccAccountGetCommodity account))) + (while (< period end-period) + (set! net (gnc-numeric-add net + (gnc:get-account-period-rolledup-budget-value budget account period) + GNC-DENOM-AUTO GNC-RND-ROUND)) + (set! period (+ period 1))) + net)) + (define (gnc:get-assoc-account-balances accounts get-balance-fn) (let* ( Index: src/report/report-system/report-system.scm =================================================================== --- src/report/report-system/report-system.scm (revision 18277) +++ src/report/report-system/report-system.scm (working copy) @@ -672,10 +672,14 @@ (export gnc:account-get-trans-type-splits-interval) (export gnc:double-col) (export gnc:budget-get-start-date) +(export gnc:budget-get-end-date) (export gnc:budget-account-get-net) (export gnc:budget-accountlist-get-net) (export gnc:budget-account-get-initial-balance) (export gnc:budget-accountlist-get-initial-balance) +(export budget-account-sum budget) +(export gnc:get-account-period-rolledup-budget-value) +(export gnc:budget-account-get-rolledup-net) (export gnc:get-assoc-account-balances) (export gnc:select-assoc-account-balance) (export gnc:get-assoc-account-balances-total)