equity-statement.scm (gnucash-5.0.tar.bz2) | : | equity-statement.scm (gnucash-5.1.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 198 | skipping to change at line 198 | |||
(define (equity-statement-renderer report-obj) | (define (equity-statement-renderer report-obj) | |||
(define (get-option pagename optname) | (define (get-option pagename optname) | |||
(gnc-optiondb-lookup-value | (gnc-optiondb-lookup-value | |||
(gnc:report-options report-obj) pagename optname)) | (gnc:report-options report-obj) pagename optname)) | |||
(gnc:report-starting reportname) | (gnc:report-starting reportname) | |||
;; get all option's values | ;; get all option's values | |||
(let* ( | (let* ( | |||
(report-title (get-option gnc:pagename-general optname-report-title)) | (report-title (get-option gnc:pagename-general optname-report-title)) | |||
(company-name (or (gnc:company-info (gnc-get-current-book) gnc:*company- | (company-name (or (gnc:company-info (gnc-get-current-book) gnc:*company | |||
name*) "")) | -name*) "")) | |||
;; this code makes the assumption that you want your equity | ;; this code makes the assumption that you want your equity | |||
;; statement to no more than daily resolution | ;; statement to no more than daily resolution | |||
(start-date-printable (gnc:date-option-absolute-time | (start-date-printable (gnc:date-option-absolute-time | |||
(get-option gnc:pagename-general | (get-option gnc:pagename-general | |||
optname-start-date))) | optname-start-date))) | |||
(start-date (gnc:time64-end-day-time | (start-date (gnc:time64-end-day-time | |||
(gnc:time64-previous-day start-date-printable))) | (gnc:time64-previous-day start-date-printable))) | |||
(end-date (gnc:time64-end-day-time | (end-date (gnc:time64-end-day-time | |||
(gnc:date-option-absolute-time | (gnc:date-option-absolute-time | |||
(get-option gnc:pagename-general | (get-option gnc:pagename-general | |||
optname-end-date)))) | optname-end-date)))) | |||
;;(end-date-printable (gnc:date-option-absolute-time | ;;(end-date-printable (gnc:date-option-absolute-time | |||
;; (get-option gnc:pagename-general | ;; (get-option gnc:pagename-general | |||
;; optname-end-date))) | ;; optname-end-date))) | |||
;; why dont we use this? why use any -printable at all? | ;; why dont we use this? why use any -printable at all? | |||
(accounts (get-option gnc:pagename-accounts | (accounts (get-option gnc:pagename-accounts | |||
optname-accounts)) | optname-accounts)) | |||
(report-commodity (get-option pagename-commodities | (report-commodity (get-option pagename-commodities | |||
optname-report-commodity)) | optname-report-commodity)) | |||
(price-source (get-option pagename-commodities | (price-source (get-option pagename-commodities | |||
optname-price-source)) | optname-price-source)) | |||
(show-rates? (get-option pagename-commodities | (show-rates? (get-option pagename-commodities | |||
optname-show-rates)) | optname-show-rates)) | |||
(use-rules? (get-option gnc:pagename-display | (use-rules? (get-option gnc:pagename-display | |||
optname-use-rules)) | optname-use-rules)) | |||
(closing-str (get-option pagename-entries | (closing-str (get-option pagename-entries | |||
optname-closing-pattern)) | optname-closing-pattern)) | |||
(closing-cased (get-option pagename-entries | (closing-cased (get-option pagename-entries | |||
optname-closing-casing)) | optname-closing-casing)) | |||
(closing-regexp (get-option pagename-entries | (closing-regexp (get-option pagename-entries | |||
optname-closing-regexp)) | optname-closing-regexp)) | |||
;; decompose the account list | ;; decompose the account list | |||
(split-up-accounts (gnc:decompose-accountlist accounts)) | (split-up-accounts (gnc:decompose-accountlist accounts)) | |||
(asset-accounts | (asset-accounts | |||
(assoc-ref split-up-accounts ACCT-TYPE-ASSET)) | (assoc-ref split-up-accounts ACCT-TYPE-ASSET)) | |||
(liability-accounts | (liability-accounts | |||
(assoc-ref split-up-accounts ACCT-TYPE-LIABILITY)) | (assoc-ref split-up-accounts ACCT-TYPE-LIABILITY)) | |||
(income-expense-accounts | (income-expense-accounts | |||
(append (assoc-ref split-up-accounts ACCT-TYPE-INCOME) | (append (assoc-ref split-up-accounts ACCT-TYPE-INCOME) | |||
(assoc-ref split-up-accounts ACCT-TYPE-EXPENSE) | (assoc-ref split-up-accounts ACCT-TYPE-EXPENSE) | |||
(assoc-ref split-up-accounts ACCT-TYPE-TRADING))) | (assoc-ref split-up-accounts ACCT-TYPE-TRADING))) | |||
(equity-accounts | (equity-accounts | |||
(assoc-ref split-up-accounts ACCT-TYPE-EQUITY)) | (assoc-ref split-up-accounts ACCT-TYPE-EQUITY)) | |||
(closing-pattern | (closing-pattern | |||
(list (list 'str closing-str) | (list (list 'str closing-str) | |||
(list 'cased closing-cased) | (list 'cased closing-cased) | |||
(list 'regexp closing-regexp) | (list 'regexp closing-regexp) | |||
(list 'positive #f) | (list 'positive #f) | |||
(list 'closing #t))) | (list 'closing #t))) | |||
(doc (gnc:make-html-document)) | (doc (gnc:make-html-document)) | |||
;; exchange rates calculation parameters | ;; exchange rates calculation parameters | |||
(start-exchange-fn | (start-exchange-fn | |||
(gnc:case-exchange-fn | (gnc:case-exchange-fn | |||
price-source report-commodity start-date)) | price-source report-commodity start-date)) | |||
(end-exchange-fn | (end-exchange-fn | |||
(gnc:case-exchange-fn | (gnc:case-exchange-fn | |||
price-source report-commodity end-date)) | price-source report-commodity end-date)) | |||
(start-price-fn (gnc:case-price-fn price-source report-commodity start- date)) | (start-price-fn (gnc:case-price-fn price-source report-commodity start- date)) | |||
(end-price-fn (gnc:case-price-fn price-source report-commodity end-date ))) | (end-price-fn (gnc:case-price-fn price-source report-commodity end-date ))) | |||
(define (unrealized-gains-at-date book-balance exchange-fn date) | (define (unrealized-gains-at-date book-balance exchange-fn date) | |||
(define cost-fn | (define cost-fn | |||
(gnc:case-exchange-fn 'average-cost report-commodity date)) | (gnc:case-exchange-fn 'average-cost report-commodity date)) | |||
(gnc:monetaries-add | (gnc:monetaries-add | |||
(gnc:sum-collector-commodity book-balance report-commodity exchange-fn) | (gnc:sum-collector-commodity book-balance report-commodity exchange-fn) | |||
(gnc:monetary-neg | (gnc:monetary-neg | |||
(gnc:sum-collector-commodity book-balance report-commodity cost-fn)))) | (gnc:sum-collector-commodity book-balance report-commodity cost-fn)))) | |||
(define (get-start-balance-fn account) | (define (get-start-balance-fn account) | |||
(gnc:account-get-comm-balance-at-date account start-date #f)) | (gnc:account-get-comm-balance-at-date account start-date #f)) | |||
(define (get-end-balance-fn account) | (define (get-end-balance-fn account) | |||
(gnc:account-get-comm-balance-at-date account end-date #f)) | (gnc:account-get-comm-balance-at-date account end-date #f)) | |||
skipping to change at line 288 | skipping to change at line 288 | |||
(gnc:html-document-set-title! | (gnc:html-document-set-title! | |||
doc (gnc:format (G_ "${company-name} ${report-title} For Period Covering ${ start} to ${end}") | doc (gnc:format (G_ "${company-name} ${report-title} For Period Covering ${ start} to ${end}") | |||
'company-name company-name | 'company-name company-name | |||
'report-title report-title | 'report-title report-title | |||
'start (qof-print-date start-date-printable) | 'start (qof-print-date start-date-printable) | |||
'end (qof-print-date end-date))) | 'end (qof-print-date end-date))) | |||
(if (null? accounts) | (if (null? accounts) | |||
;; error condition: no accounts specified is this *really* | ;; error condition: no accounts specified is this *really* | |||
;; necessary?? i'd be fine with an all-zero income statement | ;; necessary?? i'd be fine with an all-zero income statement | |||
;; that would, technically, be correct.... | ;; that would, technically, be correct.... | |||
(gnc:html-document-add-object! | (gnc:html-document-add-object! | |||
doc | doc | |||
(gnc:html-make-no-account-warning | (gnc:html-make-no-account-warning | |||
reportname (gnc:report-id report-obj))) | reportname (gnc:report-id report-obj))) | |||
;; Get all the balances for each account group. | ;; Get all the balances for each account group. | |||
(let* ((start-asset-balance | (let* ((start-asset-balance | |||
(gnc:accounts-get-comm-total-assets | (gnc:accounts-get-comm-total-assets | |||
asset-accounts get-start-balance-fn)) | asset-accounts get-start-balance-fn)) | |||
(end-asset-balance | (end-asset-balance | |||
(gnc:accounts-get-comm-total-assets | (gnc:accounts-get-comm-total-assets | |||
asset-accounts get-end-balance-fn)) | asset-accounts get-end-balance-fn)) | |||
(neg-start-liability-balance | (neg-start-liability-balance | |||
(gnc:accounts-get-comm-total-assets | (gnc:accounts-get-comm-total-assets | |||
liability-accounts get-start-balance-fn)) | liability-accounts get-start-balance-fn)) | |||
(neg-end-liability-balance | (neg-end-liability-balance | |||
(gnc:accounts-get-comm-total-assets | (gnc:accounts-get-comm-total-assets | |||
liability-accounts get-end-balance-fn)) | liability-accounts get-end-balance-fn)) | |||
(neg-pre-start-retained-earnings | (neg-pre-start-retained-earnings | |||
(gnc:accountlist-get-comm-balance-at-date-with-closing | (gnc:accountlist-get-comm-balance-at-date-with-closing | |||
income-expense-accounts start-date)) | income-expense-accounts start-date)) | |||
(neg-pre-end-retained-earnings | (neg-pre-end-retained-earnings | |||
(gnc:accountlist-get-comm-balance-at-date-with-closing | (gnc:accountlist-get-comm-balance-at-date-with-closing | |||
income-expense-accounts end-date)) | income-expense-accounts end-date)) | |||
(income-expense-closing | (income-expense-closing | |||
(gnc:account-get-trans-type-balance-interval-with-closing | (gnc:account-get-trans-type-balance-interval-with-closing | |||
income-expense-accounts closing-pattern start-date end-date)) | income-expense-accounts closing-pattern start-date end-date)) | |||
(net-income | (net-income | |||
(gnc:collector- | (gnc:collector- | |||
income-expense-closing | income-expense-closing | |||
(gnc:accountlist-get-comm-balance-interval-with-closing | (gnc:accountlist-get-comm-balance-interval-with-closing | |||
income-expense-accounts start-date end-date))) | income-expense-accounts start-date end-date))) | |||
(neg-start-equity-balance | (neg-start-equity-balance | |||
(gnc:accounts-get-comm-total-assets | (gnc:accounts-get-comm-total-assets | |||
equity-accounts get-start-balance-fn)) | equity-accounts get-start-balance-fn)) | |||
(neg-end-equity-balance | (neg-end-equity-balance | |||
(gnc:accounts-get-comm-total-assets | (gnc:accounts-get-comm-total-assets | |||
equity-accounts get-end-balance-fn)) | equity-accounts get-end-balance-fn)) | |||
(start-book-balance | (start-book-balance | |||
(gnc:collector+ start-asset-balance | (gnc:collector+ start-asset-balance | |||
neg-start-liability-balance | neg-start-liability-balance | |||
neg-start-equity-balance | neg-start-equity-balance | |||
neg-pre-start-retained-earnings)) | neg-pre-start-retained-earnings)) | |||
(end-book-balance | (end-book-balance | |||
(gnc:collector+ end-asset-balance | (gnc:collector+ end-asset-balance | |||
neg-end-liability-balance | neg-end-liability-balance | |||
neg-end-equity-balance | neg-end-equity-balance | |||
neg-pre-end-retained-earnings)) | neg-pre-end-retained-earnings)) | |||
(start-unrealized-gains | (start-unrealized-gains | |||
(unrealized-gains-at-date start-book-balance | (unrealized-gains-at-date start-book-balance | |||
start-exchange-fn | start-exchange-fn | |||
start-date)) | start-date)) | |||
(net-unrealized-gains | (net-unrealized-gains | |||
(gnc:collector- (unrealized-gains-at-date end-book-balance | (gnc:collector- (unrealized-gains-at-date end-book-balance | |||
end-exchange-fn | end-exchange-fn | |||
end-date) | end-date) | |||
start-unrealized-gains)) | start-unrealized-gains)) | |||
(equity-closing | (equity-closing | |||
(gnc:account-get-trans-type-balance-interval-with-closing | (gnc:account-get-trans-type-balance-interval-with-closing | |||
equity-accounts closing-pattern start-date end-date)) | equity-accounts closing-pattern start-date end-date)) | |||
(neg-pre-closing-equity | (neg-pre-closing-equity | |||
(gnc:collector- neg-end-equity-balance | (gnc:collector- neg-end-equity-balance | |||
equity-closing)) | equity-closing)) | |||
(net-investment | (net-investment | |||
(gnc:collector- neg-start-equity-balance | (gnc:collector- neg-start-equity-balance | |||
neg-pre-closing-equity)) | neg-pre-closing-equity)) | |||
;; calculate investments & draws... | ;; calculate investments & draws... | |||
;; do a transaction query and classify the splits by dr/cr. | ;; do a transaction query and classify the splits by dr/cr. | |||
;; assume that positive shares on an equity account are debits | ;; assume that positive shares on an equity account are debits | |||
;; withdrawals = investments - (investments - withdrawals) | ;; withdrawals = investments - (investments - withdrawals) | |||
;; investments = withdrawals + (investments - withdrawals) | ;; investments = withdrawals + (investments - withdrawals) | |||
(withdrawals | (withdrawals | |||
(account-get-total-flow 'in equity-accounts start-date end-date) ) | (account-get-total-flow 'in equity-accounts start-date end-date) ) | |||
(investments | (investments | |||
(gnc:collector+ net-investment withdrawals)) | (gnc:collector+ net-investment withdrawals)) | |||
(capital-increase | (capital-increase | |||
(gnc:collector+ net-income | (gnc:collector+ net-income | |||
investments | investments | |||
net-unrealized-gains | net-unrealized-gains | |||
(gnc:collector- withdrawals))) | (gnc:collector- withdrawals))) | |||
(start-total-equity | (start-total-equity | |||
(gnc:collector- start-unrealized-gains | (gnc:collector- start-unrealized-gains | |||
neg-start-equity-balance | neg-start-equity-balance | |||
neg-pre-start-retained-earnings)) | neg-pre-start-retained-earnings)) | |||
(end-total-equity | (end-total-equity | |||
(gnc:collector+ start-total-equity | (gnc:collector+ start-total-equity | |||
capital-increase)) | capital-increase)) | |||
;; Create the account table below where its | ;; Create the account table below where its | |||
;; percentage time can be tracked. | ;; percentage time can be tracked. | |||
(build-table (gnc:make-html-table)) ;; gnc:html-table | (build-table (gnc:make-html-table)) ;; gnc:html-table | |||
(period-for (string-append " " (G_ "for Period")))) | (period-for (string-append " " (G_ "for Period")))) | |||
;; a helper to add a line to our report | ;; a helper to add a line to our report | |||
(define (add-report-line | (define (add-report-line | |||
table pos-label neg-label amount col | table pos-label neg-label amount col | |||
exchange-fn rule? row-style) | exchange-fn rule? row-style) | |||
(let* ((neg? (and amount neg-label | (let* ((neg? (and amount neg-label | |||
(negative? | (negative? | |||
(gnc:gnc-monetary-amount | (gnc:gnc-monetary-amount | |||
(gnc:sum-collector-commodity | (gnc:sum-collector-commodity | |||
amount report-commodity exchange-fn))))) | amount report-commodity exchange-fn))))) | |||
(label (if neg? (or neg-label pos-label) pos-label)) | (label (if neg? (or neg-label pos-label) pos-label)) | |||
(pos-bal (if neg? (gnc:collector- amount) amount))) | (pos-bal (if neg? (gnc:collector- amount) amount))) | |||
(gnc:html-table-add-labeled-amount-line! | (gnc:html-table-add-labeled-amount-line! | |||
table 3 row-style rule? label 0 1 "text-cell" | table 3 row-style rule? label 0 1 "text-cell" | |||
(gnc:sum-collector-commodity pos-bal report-commodity exchange-fn) | (gnc:sum-collector-commodity pos-bal report-commodity exchange-fn ) | |||
(1+ col) 1 "number-cell"))) | (1+ col) 1 "number-cell"))) | |||
(gnc:report-percent-done 30) | (gnc:report-percent-done 30) | |||
(gnc:html-table-append-row! | (gnc:html-table-append-row! | |||
build-table (make-list 2 (gnc:make-html-table-cell/min-width 60))) | build-table (make-list 2 (gnc:make-html-table-cell/min-width 60))) | |||
(gnc:report-percent-done 80) | (gnc:report-percent-done 80) | |||
(add-report-line | (add-report-line | |||
build-table | build-table | |||
(string-append (G_ "Capital") ", " (qof-print-date start-date-printab le)) | (string-append (G_ "Capital") ", " (qof-print-date start-date-printab le)) | |||
#f start-total-equity 1 start-exchange-fn #f "primary-subheading") | #f start-total-equity 1 start-exchange-fn #f "primary-subheading") | |||
skipping to change at line 472 | skipping to change at line 472 | |||
(add-report-line | (add-report-line | |||
build-table | build-table | |||
(string-append (G_ "Capital") ", " (qof-print-date end-date)) #f | (string-append (G_ "Capital") ", " (qof-print-date end-date)) #f | |||
end-total-equity | end-total-equity | |||
1 end-exchange-fn #f "primary-subheading") | 1 end-exchange-fn #f "primary-subheading") | |||
(gnc:html-document-add-object! doc build-table) | (gnc:html-document-add-object! doc build-table) | |||
;; add currency information if requested | ;; add currency information if requested | |||
(gnc:report-percent-done 90) | (gnc:report-percent-done 90) | |||
(when show-rates? | (when show-rates? | |||
(let* ((curr-tbl (gnc:make-html-table)) | (let* ((curr-tbl (gnc:make-html-table)) | |||
(headers (list | (headers (list | |||
(qof-print-date start-date-printable) | (qof-print-date start-date-printable) | |||
(qof-print-date end-date))) | (qof-print-date end-date))) | |||
(then (gnc:html-make-rates-table | (then (gnc:html-make-rates-table | |||
report-commodity start-price-fn accounts)) | report-commodity start-price-fn accounts)) | |||
(now (gnc:html-make-rates-table | (now (gnc:html-make-rates-table | |||
report-commodity end-price-fn accounts))) | report-commodity end-price-fn accounts))) | |||
(gnc:html-table-set-col-headers! curr-tbl headers) | (gnc:html-table-set-col-headers! curr-tbl headers) | |||
(gnc:html-table-set-style! | (gnc:html-table-set-style! | |||
curr-tbl "table" 'attribute '("border" "1")) | curr-tbl "table" 'attribute '("border" "1")) | |||
(gnc:html-table-set-style! | (gnc:html-table-set-style! | |||
then "table" 'attribute '("border" "0")) | then "table" 'attribute '("border" "0")) | |||
(gnc:html-table-set-style! | (gnc:html-table-set-style! | |||
now "table" 'attribute '("border" "0")) | now "table" 'attribute '("border" "0")) | |||
(gnc:html-table-append-ruler! build-table 3) | (gnc:html-table-append-ruler! build-table 3) | |||
(gnc:html-table-append-row! curr-tbl (list then now)) | (gnc:html-table-append-row! curr-tbl (list then now)) | |||
(gnc:html-document-add-object! doc curr-tbl))) | (gnc:html-document-add-object! doc curr-tbl))) | |||
(gnc:report-percent-done 100))) | (gnc:report-percent-done 100))) | |||
(gnc:report-finished) | (gnc:report-finished) | |||
doc | doc | |||
) | ) | |||
) | ) | |||
(gnc:define-report | (gnc:define-report | |||
'version 1 | 'version 1 | |||
'name reportname | 'name reportname | |||
End of changes. 32 change blocks. | ||||
90 lines changed or deleted | 90 lines changed or added |