author | Fabien Ninoles <fabien@tzone.org> |
Sun, 03 Jan 2016 20:24:28 -0500 | |
changeset 2 | 64f48a8c758c |
permissions | -rw-r--r-- |
2
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1 |
;; -*-scheme-*- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
2 |
;; advanced-portfolio.scm |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
3 |
;; by Martijn van Oosterhout (kleptog@svana.org) Feb 2002 |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
4 |
;; modified for GnuCash 1.8 by Herbert Thoma (herbie@hthoma.de) Oct 2002 |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
5 |
;; |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
6 |
;; Heavily based on portfolio.scm |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
7 |
;; by Robert Merkel (rgmerk@mira.net) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
8 |
;; |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
9 |
;; This program is free software; you can redistribute it and/or |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
10 |
;; modify it under the terms of the GNU General Public License as |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
11 |
;; published by the Free Software Foundation; either version 2 of |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
12 |
;; the License, or (at your option) any later version. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
13 |
;; |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
14 |
;; This program is distributed in the hope that it will be useful, |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
15 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
16 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
17 |
;; GNU General Public License for more details. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
18 |
;; |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
19 |
;; You should have received a copy of the GNU General Public License |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
20 |
;; along with this program; if not, contact: |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
21 |
;; |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
22 |
;; Free Software Foundation Voice: +1-617-542-5942 |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
23 |
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
24 |
;; Boston, MA 02110-1301, USA gnu@gnu.org |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
25 |
;; |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
26 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
27 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
28 |
(define-module (local my-advanced-portfolio)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
29 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
30 |
(use-modules (gnucash main)) ;; FIXME: delete after we finish modularizing. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
31 |
(use-modules (srfi srfi-1)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
32 |
(use-modules (gnucash gnc-module)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
33 |
(use-modules (gnucash gettext)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
34 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
35 |
(use-modules (gnucash printf)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
36 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
37 |
(gnc:module-load "gnucash/report/report-system" 0) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
38 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
39 |
(define reportname (N_ "My Advanced Portfolio")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
40 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
41 |
(define optname-price-source (N_ "Price Source")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
42 |
(define optname-shares-digits (N_ "Share decimal places")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
43 |
(define optname-zero-shares (N_ "Include accounts with no shares")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
44 |
(define optname-show-symbol (N_ "Show ticker symbols")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
45 |
(define optname-show-listing (N_ "Show listings")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
46 |
(define optname-show-price (N_ "Show prices")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
47 |
(define optname-show-shares (N_ "Show number of shares")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
48 |
(define optname-basis-method (N_ "Basis calculation method")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
49 |
(define optname-prefer-pricelist (N_ "Set preference for price list data")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
50 |
(define optname-brokerage-fees (N_ "How to report brokerage fees")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
51 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
52 |
;; To avoid overflows in our calculations, define a denominator for prices and unit values |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
53 |
(define price-denom 100000000) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
54 |
(define units-denom 100000000) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
55 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
56 |
(define (options-generator) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
57 |
(let* ((options (gnc:new-options)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
58 |
;; This is just a helper function for making options. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
59 |
;; See gnucash/src/scm/options.scm for details. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
60 |
(add-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
61 |
(lambda (new-option) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
62 |
(gnc:register-option options new-option)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
63 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
64 |
;; General Tab |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
65 |
;; date at which to report balance |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
66 |
(gnc:options-add-report-date! |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
67 |
options gnc:pagename-general |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
68 |
(N_ "Date") "a") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
69 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
70 |
(gnc:options-add-currency! |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
71 |
options gnc:pagename-general (N_ "Report's currency") "c") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
72 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
73 |
(add-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
74 |
(gnc:make-multichoice-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
75 |
gnc:pagename-general optname-price-source |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
76 |
"d" (N_ "The source of price information.") 'pricedb-nearest |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
77 |
(list (vector 'pricedb-latest |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
78 |
(N_ "Most recent") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
79 |
(N_ "The most recent recorded price.")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
80 |
(vector 'pricedb-nearest |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
81 |
(N_ "Nearest in time") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
82 |
(N_ "The price recorded nearest in time to the report date.")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
83 |
))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
84 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
85 |
(add-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
86 |
(gnc:make-multichoice-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
87 |
gnc:pagename-general optname-basis-method |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
88 |
"e" (N_ "Basis calculation method.") 'average-basis |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
89 |
(list (vector 'average-basis |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
90 |
(N_ "Average") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
91 |
(N_ "Use average cost of all shares for basis.")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
92 |
(vector 'fifo-basis |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
93 |
(N_ "FIFO") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
94 |
(N_ "Use first-in first-out method for basis.")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
95 |
(vector 'filo-basis |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
96 |
(N_ "LIFO") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
97 |
(N_ "Use last-in first-out method for basis.")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
98 |
))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
99 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
100 |
(add-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
101 |
(gnc:make-simple-boolean-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
102 |
gnc:pagename-general optname-prefer-pricelist "f" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
103 |
(N_ "Prefer use of price editor pricing over transactions, where applicable.") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
104 |
#t)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
105 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
106 |
(add-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
107 |
(gnc:make-multichoice-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
108 |
gnc:pagename-general optname-brokerage-fees |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
109 |
"g" (N_ "How to report commissions and other brokerage fees.") 'include-in-basis |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
110 |
(list (vector 'include-in-basis |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
111 |
(N_ "Include in basis") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
112 |
(N_ "Include brokerage fees in the basis for the asset.")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
113 |
(vector 'include-in-gain |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
114 |
(N_ "Include in gain") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
115 |
(N_ "Include brokerage fees in the gain and loss but not in the basis.")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
116 |
(vector 'ignore-brokerage |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
117 |
(N_ "Ignore") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
118 |
(N_ "Ignore brokerage fees entirely.")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
119 |
))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
120 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
121 |
(gnc:register-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
122 |
options |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
123 |
(gnc:make-simple-boolean-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
124 |
gnc:pagename-display optname-show-symbol "a" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
125 |
(N_ "Display the ticker symbols.") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
126 |
#t)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
127 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
128 |
(gnc:register-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
129 |
options |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
130 |
(gnc:make-simple-boolean-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
131 |
gnc:pagename-display optname-show-listing "b" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
132 |
(N_ "Display exchange listings.") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
133 |
#t)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
134 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
135 |
(gnc:register-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
136 |
options |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
137 |
(gnc:make-simple-boolean-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
138 |
gnc:pagename-display optname-show-shares "c" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
139 |
(N_ "Display numbers of shares in accounts.") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
140 |
#t)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
141 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
142 |
(add-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
143 |
(gnc:make-number-range-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
144 |
gnc:pagename-display optname-shares-digits |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
145 |
"d" (N_ "The number of decimal places to use for share numbers.") 2 |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
146 |
0 6 0 1)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
147 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
148 |
(gnc:register-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
149 |
options |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
150 |
(gnc:make-simple-boolean-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
151 |
gnc:pagename-display optname-show-price "e" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
152 |
(N_ "Display share prices.") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
153 |
#t)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
154 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
155 |
;; Account tab |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
156 |
(add-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
157 |
(gnc:make-account-list-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
158 |
gnc:pagename-accounts (N_ "Accounts") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
159 |
"b" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
160 |
(N_ "Stock Accounts to report on.") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
161 |
(lambda () (filter gnc:account-is-stock? |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
162 |
(gnc-account-get-descendants-sorted |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
163 |
(gnc-get-current-root-account)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
164 |
(lambda (accounts) (list #t |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
165 |
(filter gnc:account-is-stock? accounts))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
166 |
#t)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
167 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
168 |
(gnc:register-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
169 |
options |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
170 |
(gnc:make-simple-boolean-option |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
171 |
gnc:pagename-accounts optname-zero-shares "e" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
172 |
(N_ "Include accounts that have a zero share balances.") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
173 |
#f)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
174 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
175 |
(gnc:options-set-default-section options gnc:pagename-general) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
176 |
options)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
177 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
178 |
;; This is the rendering function. It accepts a database of options |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
179 |
;; and generates an object of type <html-document>. See the file |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
180 |
;; report-html.txt for documentation; the file report-html.scm |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
181 |
;; includes all the relevant Scheme code. The option database passed |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
182 |
;; to the function is one created by the options-generator function |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
183 |
;; defined above. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
184 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
185 |
(define (advanced-portfolio-renderer report-obj) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
186 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
187 |
(let ((work-done 0) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
188 |
(work-to-do 0) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
189 |
(warn-no-price #f) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
190 |
(warn-price-dirty #f)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
191 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
192 |
;; These are some helper functions for looking up option values. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
193 |
(define (get-op section name) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
194 |
(gnc:lookup-option (gnc:report-options report-obj) section name)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
195 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
196 |
(define (get-option section name) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
197 |
(gnc:option-value (get-op section name))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
198 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
199 |
(define (split-account-type? split type) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
200 |
(eq? type (xaccAccountGetType (xaccSplitGetAccount split)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
201 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
202 |
(define (same-split? s1 s2) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
203 |
(equal? (gncSplitGetGUID s1) (gncSplitGetGUID s2))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
204 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
205 |
(define (same-account? a1 a2) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
206 |
(equal? (gncAccountGetGUID a1) (gncAccountGetGUID a2))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
207 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
208 |
(define (same-account-code? a1 a2) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
209 |
(equal? (xaccAccountGetCode a1) (xaccAccountGetCode a2))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
210 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
211 |
;; sum up the contents of the b-list built by basis-builder below |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
212 |
(define (sum-basis b-list currency-frac) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
213 |
(if (not (eqv? b-list '())) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
214 |
(gnc-numeric-add (gnc-numeric-mul (caar b-list) (cdar b-list) currency-frac GNC-RND-ROUND) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
215 |
(sum-basis (cdr b-list) currency-frac) currency-frac GNC-RND-ROUND) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
216 |
(gnc-numeric-zero) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
217 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
218 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
219 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
220 |
;; sum up the total number of units in the b-list built by basis-builder below |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
221 |
(define (units-basis b-list) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
222 |
(if (not (eqv? b-list '())) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
223 |
(gnc-numeric-add (caar b-list) (units-basis (cdr b-list)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
224 |
units-denom GNC-RND-ROUND) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
225 |
(gnc-numeric-zero) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
226 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
227 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
228 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
229 |
;; apply a ratio to an existing basis-list, useful for splits/mergers and spinoffs |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
230 |
;; I need to get a brain and use (map) for this. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
231 |
(define (apply-basis-ratio b-list units-ratio value-ratio) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
232 |
(if (not (eqv? b-list '())) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
233 |
(cons (cons (gnc-numeric-mul units-ratio (caar b-list) units-denom GNC-RND-ROUND) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
234 |
(gnc-numeric-mul value-ratio (cdar b-list) price-denom GNC-RND-ROUND)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
235 |
(apply-basis-ratio (cdr b-list) units-ratio value-ratio)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
236 |
'() |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
237 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
238 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
239 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
240 |
;; this builds a list for basis calculation and handles average, fifo and lifo methods |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
241 |
;; the list is cons cells of (units-of-stock . price-per-unit)... average method produces only one |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
242 |
;; cell that mutates to the new average. Need to add a date checker so that we allow for prices |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
243 |
;; coming in out of order, such as a transfer with a price adjusted to carryover the basis. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
244 |
(define (basis-builder b-list b-units b-value b-method currency-frac) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
245 |
(gnc:debug "actually in basis-builder") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
246 |
(gnc:debug "b-list is " b-list " b-units is " (gnc-numeric-to-string b-units) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
247 |
" b-value is " (gnc-numeric-to-string b-value) " b-method is " b-method) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
248 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
249 |
;; if there is no b-value, then this is a split/merger and needs special handling |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
250 |
(cond |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
251 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
252 |
;; we have value and positive units, add units to basis |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
253 |
((and (not (gnc-numeric-zero-p b-value)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
254 |
(gnc-numeric-positive-p b-units)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
255 |
(case b-method |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
256 |
((average-basis) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
257 |
(if (not (eqv? b-list '())) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
258 |
(list (cons (gnc-numeric-add b-units |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
259 |
(caar b-list) units-denom GNC-RND-ROUND) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
260 |
(gnc-numeric-div |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
261 |
(gnc-numeric-add b-value |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
262 |
(gnc-numeric-mul (caar b-list) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
263 |
(cdar b-list) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
264 |
GNC-DENOM-AUTO GNC-DENOM-REDUCE) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
265 |
GNC-DENOM-AUTO GNC-DENOM-REDUCE) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
266 |
(gnc-numeric-add b-units |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
267 |
(caar b-list) GNC-DENOM-AUTO GNC-DENOM-REDUCE) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
268 |
price-denom GNC-RND-ROUND))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
269 |
(append b-list |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
270 |
(list (cons b-units (gnc-numeric-div |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
271 |
b-value b-units price-denom GNC-RND-ROUND)))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
272 |
(else (append b-list |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
273 |
(list (cons b-units (gnc-numeric-div |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
274 |
b-value b-units price-denom GNC-RND-ROUND))))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
275 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
276 |
;; we have value and negative units, remove units from basis |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
277 |
((and (not (gnc-numeric-zero-p b-value)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
278 |
(gnc-numeric-negative-p b-units)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
279 |
(if (not (eqv? b-list '())) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
280 |
(case b-method |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
281 |
((fifo-basis) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
282 |
(case (gnc-numeric-compare (gnc-numeric-abs b-units) (caar b-list)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
283 |
((-1) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
284 |
;; Sold less than the first lot, create a new first lot from the remainder |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
285 |
(let ((new-units (gnc-numeric-add b-units (caar b-list) units-denom GNC-RND-ROUND))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
286 |
(cons (cons new-units (cdar b-list)) (cdr b-list)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
287 |
((0) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
288 |
;; Sold all of the first lot |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
289 |
(cdr b-list)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
290 |
((1) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
291 |
;; Sold more than the first lot, delete it and recurse |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
292 |
(basis-builder (cdr b-list) (gnc-numeric-add b-units (caar b-list) units-denom GNC-RND-ROUND) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
293 |
b-value ;; Only the sign of b-value matters since the new b-units is negative |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
294 |
b-method currency-frac)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
295 |
((filo-basis) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
296 |
(let ((rev-b-list (reverse b-list))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
297 |
(case (gnc-numeric-compare (gnc-numeric-abs b-units) (caar rev-b-list)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
298 |
((-1) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
299 |
;; Sold less than the last lot |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
300 |
(let ((new-units (gnc-numeric-add b-units (caar rev-b-list) units-denom GNC-RND-ROUND))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
301 |
(reverse (cons (cons new-units (cdar rev-b-list)) (cdr rev-b-list))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
302 |
((0) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
303 |
;; Sold all of the last lot |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
304 |
(reverse (cdr rev-b-list)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
305 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
306 |
((1) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
307 |
;; Sold more than the last lot |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
308 |
(basis-builder (reverse (cdr rev-b-list)) (gnc-numeric-add b-units (caar rev-b-list) units-denom GNC-RND-ROUND) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
309 |
b-value b-method currency-frac) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
310 |
)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
311 |
((average-basis) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
312 |
(list (cons (gnc-numeric-add |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
313 |
(caar b-list) b-units units-denom GNC-RND-ROUND) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
314 |
(cdar b-list))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
315 |
'() |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
316 |
)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
317 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
318 |
;; no value, just units, this is a split/merge... |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
319 |
((and (gnc-numeric-zero-p b-value) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
320 |
(not (gnc-numeric-zero-p b-units))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
321 |
(let* ((current-units (units-basis b-list)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
322 |
(units-ratio (gnc-numeric-div (gnc-numeric-add b-units current-units GNC-DENOM-AUTO GNC-DENOM-REDUCE) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
323 |
current-units GNC-DENOM-AUTO GNC-DENOM-REDUCE)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
324 |
;; If the units ratio is zero the stock is worthless and the value should be zero too |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
325 |
(value-ratio (if (gnc-numeric-zero-p units-ratio) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
326 |
(gnc-numeric-zero) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
327 |
(gnc-numeric-div (gnc:make-gnc-numeric 1 1) units-ratio GNC-DENOM-AUTO GNC-DENOM-REDUCE)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
328 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
329 |
(gnc:debug "blist is " b-list " current units is " |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
330 |
(gnc-numeric-to-string current-units) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
331 |
" value ratio is " (gnc-numeric-to-string value-ratio) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
332 |
" units ratio is " (gnc-numeric-to-string units-ratio)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
333 |
(apply-basis-ratio b-list units-ratio value-ratio) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
334 |
)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
335 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
336 |
;; If there are no units, just a value, then its a spin-off, |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
337 |
;; calculate a ratio for the values, but leave the units alone |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
338 |
;; with a ratio of 1 |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
339 |
((and (gnc-numeric-zero-p b-units) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
340 |
(not (gnc-numeric-zero-p b-value))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
341 |
(let* ((current-value (sum-basis b-list GNC-DENOM-AUTO)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
342 |
(value-ratio (gnc-numeric-div (gnc-numeric-add b-value current-value GNC-DENOM-AUTO GNC-DENOM-REDUCE) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
343 |
current-value GNC-DENOM-AUTO GNC-DENOM-REDUCE))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
344 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
345 |
(gnc:debug "this is a spinoff") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
346 |
(gnc:debug "blist is " b-list " value ratio is " (gnc-numeric-to-string value-ratio)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
347 |
(apply-basis-ratio b-list (gnc:make-gnc-numeric 1 1) value-ratio)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
348 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
349 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
350 |
;; when all else fails, just send the b-list back |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
351 |
(else |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
352 |
b-list) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
353 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
354 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
355 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
356 |
;; Given a price list and a currency find the price for that currency on the list. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
357 |
;; If there is none for the requested currency, return the first one. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
358 |
;; The price list is released but the price returned is ref counted. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
359 |
(define (find-price price-list currency) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
360 |
(if (eqv? price-list '()) #f |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
361 |
(let ((price (car price-list))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
362 |
(for-each |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
363 |
(lambda (p) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
364 |
(if (gnc-commodity-equiv currency (gnc-price-get-currency p)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
365 |
(set! price p))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
366 |
price-list) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
367 |
(gnc-price-ref price) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
368 |
(gnc-price-list-destroy price-list) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
369 |
price))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
370 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
371 |
;; Return true if either account is the parent of the other or they are siblings |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
372 |
(define (parent-or-sibling? a1 a2) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
373 |
(let ((a2parent (gnc-account-get-parent a2)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
374 |
(a1parent (gnc-account-get-parent a1))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
375 |
(or (same-account? a2parent a1) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
376 |
(same-account? a1parent a2) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
377 |
(same-account? a1parent a2parent)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
378 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
379 |
;; Test whether the given split is the source of a spin off transaction |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
380 |
;; This will be a no-units split with only one other split. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
381 |
;; xaccSplitGetOtherSplit only returns on a two-split txn. It's not a spinoff |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
382 |
;; is the other split is in an income or expense account. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
383 |
(define (spin-off? split current) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
384 |
(let ((other-split (xaccSplitGetOtherSplit split))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
385 |
(and (gnc-numeric-zero-p (xaccSplitGetAmount split)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
386 |
(same-account? current (xaccSplitGetAccount split)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
387 |
(not (null? other-split)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
388 |
(not (split-account-type? other-split ACCT-TYPE-EXPENSE)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
389 |
(not (split-account-type? other-split ACCT-TYPE-INCOME))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
390 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
391 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
392 |
(define (table-add-stock-rows table accounts to-date |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
393 |
currency price-fn exchange-fn price-source |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
394 |
include-empty show-symbol show-listing show-shares show-price |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
395 |
basis-method prefer-pricelist handle-brokerage-fees |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
396 |
total-basis total-value |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
397 |
total-moneyin total-moneyout total-income total-gain |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
398 |
total-ugain total-brokerage) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
399 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
400 |
(let ((share-print-info |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
401 |
(gnc-share-print-info-places |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
402 |
(inexact->exact (get-option gnc:pagename-display |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
403 |
optname-shares-digits))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
404 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
405 |
(define (table-add-stock-rows-internal accounts odd-row?) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
406 |
(if (null? accounts) total-value |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
407 |
(let* ((row-style (if odd-row? "normal-row" "alternate-row")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
408 |
(current (car accounts)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
409 |
(rest (cdr accounts)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
410 |
;; commodity is the actual stock/thing we are looking at |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
411 |
(commodity (xaccAccountGetCommodity current)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
412 |
(ticker-symbol (gnc-commodity-get-mnemonic commodity)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
413 |
(listing (gnc-commodity-get-namespace commodity)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
414 |
(unit-collector (gnc:account-get-comm-balance-at-date |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
415 |
current to-date #f)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
416 |
(units (cadr (unit-collector 'getpair commodity #f))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
417 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
418 |
;; Counter to keep track of stuff |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
419 |
(brokeragecoll (gnc:make-commodity-collector)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
420 |
(dividendcoll (gnc:make-commodity-collector)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
421 |
(moneyincoll (gnc:make-commodity-collector)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
422 |
(moneyoutcoll (gnc:make-commodity-collector)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
423 |
(gaincoll (gnc:make-commodity-collector)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
424 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
425 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
426 |
;; the price of the commodity at the time of the report |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
427 |
(price (price-fn commodity currency to-date)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
428 |
;; the value of the commodity, expressed in terms of |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
429 |
;; the report's currency. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
430 |
(value (gnc:make-gnc-monetary currency (gnc-numeric-zero))) ;; Set later |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
431 |
(currency-frac (gnc-commodity-get-fraction currency)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
432 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
433 |
(pricing-txn #f) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
434 |
(use-txn #f) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
435 |
(basis-list '()) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
436 |
;; setup an alist for the splits we've already seen. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
437 |
(seen_trans '()) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
438 |
;; Account used to hold remainders from income reinvestments and |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
439 |
;; running total of amount moved there |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
440 |
(drp-holding-account #f) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
441 |
(drp-holding-amount (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
442 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
443 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
444 |
(define (my-exchange-fn fromunits tocurrency) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
445 |
(if (and (gnc-commodity-equiv currency tocurrency) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
446 |
(gnc-commodity-equiv (gnc:gnc-monetary-commodity fromunits) commodity)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
447 |
;; Have a price for this commodity, but not necessarily in the report's |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
448 |
;; currency. Get the value in the commodity's currency and convert it to |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
449 |
;; report currency. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
450 |
(exchange-fn |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
451 |
;; This currency will usually be the same as tocurrency so the |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
452 |
;; call to exchange-fn below will do nothing |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
453 |
(gnc:make-gnc-monetary |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
454 |
(if use-txn |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
455 |
(gnc:gnc-monetary-commodity price) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
456 |
(gnc-price-get-currency price)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
457 |
(gnc-numeric-mul (gnc:gnc-monetary-amount fromunits) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
458 |
(if use-txn |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
459 |
(gnc:gnc-monetary-amount price) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
460 |
(gnc-price-get-value price)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
461 |
currency-frac GNC-RND-ROUND)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
462 |
tocurrency) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
463 |
(exchange-fn fromunits tocurrency))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
464 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
465 |
(gnc:debug "Starting account " (xaccAccountGetName current) ", initial price: " |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
466 |
(if price |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
467 |
(gnc-commodity-value->string |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
468 |
(list (gnc-price-get-currency price) (gnc-price-get-value price))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
469 |
#f)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
470 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
471 |
;; If we have a price that can't be converted to the report currency |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
472 |
;; don't use it |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
473 |
(if (and price (gnc-numeric-zero-p (gnc:gnc-monetary-amount |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
474 |
(exchange-fn |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
475 |
(gnc:make-gnc-monetary |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
476 |
(gnc-price-get-currency price) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
477 |
(gnc:make-gnc-numeric 100 1)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
478 |
currency)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
479 |
(set! price #f)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
480 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
481 |
;; If we are told to use a pricing transaction, or if we don't have a price |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
482 |
;; from the price DB, find a good transaction to use. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
483 |
(if (and (not use-txn) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
484 |
(or (not price) (not prefer-pricelist))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
485 |
(let ((split-list (reverse (gnc:get-match-commodity-splits-sorted |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
486 |
(list current) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
487 |
(case price-source |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
488 |
((pricedb-latest) (gnc:get-today)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
489 |
((pricedb-nearest) to-date) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
490 |
(else (gnc:get-today))) ;; error, but don't crash |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
491 |
#f)))) ;; Any currency |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
492 |
;; Find the first (most recent) one that can be converted to report currency |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
493 |
(while (and (not use-txn) (not (eqv? split-list '()))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
494 |
(let ((split (car split-list))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
495 |
(if (and (not (gnc-numeric-zero-p (xaccSplitGetAmount split))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
496 |
(not (gnc-numeric-zero-p (xaccSplitGetValue split)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
497 |
(let* ((trans (xaccSplitGetParent split)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
498 |
(trans-currency (xaccTransGetCurrency trans)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
499 |
(trans-price (exchange-fn (gnc:make-gnc-monetary |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
500 |
trans-currency |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
501 |
(xaccSplitGetSharePrice split)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
502 |
currency))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
503 |
(if (not (gnc-numeric-zero-p (gnc:gnc-monetary-amount trans-price))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
504 |
;; We can exchange the price from this transaction into the report currency |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
505 |
(begin |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
506 |
(if price (gnc-price-unref price)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
507 |
(set! pricing-txn trans) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
508 |
(set! price trans-price) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
509 |
(gnc:debug "Transaction price is " (gnc:monetary->string price)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
510 |
(set! use-txn #t)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
511 |
(set! split-list (cdr split-list)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
512 |
(set! split-list (cdr split-list))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
513 |
)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
514 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
515 |
;; If we still don't have a price, use a price of 1 and complain later |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
516 |
(if (not price) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
517 |
(begin |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
518 |
(set! price (gnc:make-gnc-monetary currency (gnc:make-gnc-numeric 1 1))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
519 |
;; If use-txn is set, but pricing-txn isn't set, it's a bogus price |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
520 |
(set! use-txn #t) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
521 |
(set! pricing-txn #f) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
522 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
523 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
524 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
525 |
;; Now that we have a pricing transaction if needed, set the value of the asset |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
526 |
(set! value (my-exchange-fn (gnc:make-gnc-monetary commodity units) currency)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
527 |
(gnc:debug "Value " (gnc:monetary->string value) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
528 |
" from " (gnc-commodity-numeric->string commodity units)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
529 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
530 |
(for-each |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
531 |
;; we're looking at each split we find in the account. these splits |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
532 |
;; could refer to the same transaction, so we have to examine each |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
533 |
;; split, determine what kind of split it is and then act accordingly. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
534 |
(lambda (split) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
535 |
(set! work-done (+ 1 work-done)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
536 |
(gnc:report-percent-done (* 100 (/ work-done work-to-do))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
537 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
538 |
(let* ((parent (xaccSplitGetParent split)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
539 |
(txn-date (gnc-transaction-get-date-posted parent)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
540 |
(commod-currency (xaccTransGetCurrency parent)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
541 |
(commod-currency-frac (gnc-commodity-get-fraction commod-currency))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
542 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
543 |
(if (and (gnc:timepair-le txn-date to-date) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
544 |
(not (assoc-ref seen_trans (gncTransGetGUID parent)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
545 |
(let ((trans-income (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
546 |
(trans-brokerage (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
547 |
(trans-shares (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
548 |
(shares-bought (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
549 |
(trans-sold (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
550 |
(trans-bought (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
551 |
(trans-spinoff (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
552 |
(trans-drp-residual (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
553 |
(trans-drp-account #f)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
554 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
555 |
(gnc:debug "Transaction " (xaccTransGetDescription parent)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
556 |
;; Add this transaction to the list of processed transactions so we don't |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
557 |
;; do it again if there is another split in it for this account |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
558 |
(set! seen_trans (acons (gncTransGetGUID parent) #t seen_trans)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
559 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
560 |
;; Go through all the splits in the transaction to get an overall idea of |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
561 |
;; what it does in terms of income, money in or out, shares bought or sold, etc. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
562 |
(for-each |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
563 |
(lambda (s) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
564 |
(let ((split-units (xaccSplitGetAmount s)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
565 |
(split-value (xaccSplitGetValue s))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
566 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
567 |
(cond |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
568 |
((and |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
569 |
(split-account-type? s ACCT-TYPE-EXPENSE) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
570 |
(same-account-code? current (xaccSplitGetAccount s))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
571 |
;; Brokerage expense unless a two split transaction with other split |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
572 |
;; in the stock account in which case it's a stock donation to charity. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
573 |
(gnc:debug "Pass 1: Expense: split units " (gnc-numeric-to-string split-units) " split-value " |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
574 |
(gnc-numeric-to-string split-value) " commod-currency " |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
575 |
(gnc-commodity-get-printname commod-currency)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
576 |
(if (not (same-account? current (xaccSplitGetAccount (xaccSplitGetOtherSplit s)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
577 |
(set! trans-brokerage |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
578 |
(gnc-numeric-add trans-brokerage split-value commod-currency-frac GNC-RND-ROUND)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
579 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
580 |
((and |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
581 |
(split-account-type? s ACCT-TYPE-INCOME) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
582 |
(same-account-code? current (xaccSplitGetAccount s))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
583 |
(gnc:debug "Pass 1: Income: split units " (gnc-numeric-to-string split-units) " split-value " |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
584 |
(gnc-numeric-to-string split-value) " commod-currency " |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
585 |
(gnc-commodity-get-printname commod-currency)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
586 |
(set! trans-income |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
587 |
(gnc-numeric-sub trans-income split-value |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
588 |
commod-currency-frac GNC-RND-ROUND))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
589 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
590 |
((same-account? current (xaccSplitGetAccount s)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
591 |
(gnc:debug "Pass 1: Same Account: split units " (gnc-numeric-to-string split-units) " split-value " |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
592 |
(gnc-numeric-to-string split-value) " commod-currency " |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
593 |
(gnc-commodity-get-printname commod-currency)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
594 |
(set! trans-shares (gnc-numeric-add trans-shares (gnc-numeric-abs split-units) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
595 |
units-denom GNC-RND-ROUND)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
596 |
(if (gnc-numeric-zero-p split-units) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
597 |
(if (spin-off? s current) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
598 |
;; Count money used in a spin off as money out |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
599 |
(if (gnc-numeric-negative-p split-value) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
600 |
(set! trans-spinoff (gnc-numeric-sub trans-spinoff split-value |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
601 |
commod-currency-frac GNC-RND-ROUND))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
602 |
(if (not (gnc-numeric-zero-p split-value)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
603 |
;; Gain/loss split (amount zero, value non-zero, and not spinoff). There will be |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
604 |
;; a corresponding income split that will incorrectly be added to trans-income |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
605 |
;; Fix that by subtracting it here |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
606 |
(set! trans-income (gnc-numeric-sub trans-income split-value |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
607 |
commod-currency-frac GNC-RND-ROUND)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
608 |
;; Non-zero amount, add the value to the sale or purchase total. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
609 |
(if (gnc-numeric-positive-p split-value) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
610 |
(begin |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
611 |
(set! trans-bought |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
612 |
(gnc-numeric-add trans-bought split-value commod-currency-frac GNC-RND-ROUND)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
613 |
(set! shares-bought |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
614 |
(gnc-numeric-add shares-bought split-units units-denom GNC-RND-ROUND))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
615 |
(set! trans-sold |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
616 |
(gnc-numeric-sub trans-sold split-value commod-currency-frac GNC-RND-ROUND))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
617 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
618 |
((and |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
619 |
(split-account-type? s ACCT-TYPE-ASSET) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
620 |
(same-account-code? current (xaccSplitGetAccount s))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
621 |
(gnc:debug "Pass 1: Assets: split units " (gnc-numeric-to-string split-units) " split-value " |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
622 |
(gnc-numeric-to-string split-value) " commod-currency " |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
623 |
(gnc-commodity-get-printname commod-currency)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
624 |
;; If all the asset accounts mentioned in the transaction are siblings of each other |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
625 |
;; keep track of the money transfered to them if it is in the correct currency |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
626 |
(if (not trans-drp-account) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
627 |
(begin |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
628 |
(set! trans-drp-account (xaccSplitGetAccount s)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
629 |
(if (gnc-commodity-equiv commod-currency (xaccAccountGetCommodity trans-drp-account)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
630 |
(set! trans-drp-residual split-value) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
631 |
(set! trans-drp-account 'none))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
632 |
(if (not (eq? trans-drp-account 'none)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
633 |
(if (parent-or-sibling? trans-drp-account (xaccSplitGetAccount s)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
634 |
(set! trans-drp-residual (gnc-numeric-add trans-drp-residual split-value |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
635 |
commod-currency-frac GNC-RND-ROUND)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
636 |
(set! trans-drp-account 'none)))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
637 |
)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
638 |
(xaccTransGetSplitList parent) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
639 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
640 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
641 |
(gnc:debug "Income: " (gnc-numeric-to-string trans-income) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
642 |
" Brokerage: " (gnc-numeric-to-string trans-brokerage) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
643 |
" Shares traded: " (gnc-numeric-to-string trans-shares) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
644 |
" Shares bought: " (gnc-numeric-to-string shares-bought)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
645 |
(gnc:debug " Value sold: " (gnc-numeric-to-string trans-sold) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
646 |
" Value purchased: " (gnc-numeric-to-string trans-bought) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
647 |
" Spinoff value " (gnc-numeric-to-string trans-spinoff) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
648 |
" Trans DRP residual: " (gnc-numeric-to-string trans-drp-residual)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
649 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
650 |
;; We need to calculate several things for this transaction: |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
651 |
;; 1. Total income: this is already in trans-income |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
652 |
;; 2. Change in basis: calculated by loop below that looks at every |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
653 |
;; that acquires or disposes of shares |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
654 |
;; 3. Realized gain: also calculated below while calculating basis |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
655 |
;; 4. Money in to the account: this is the value of shares bought |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
656 |
;; except those purchased with reinvested income |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
657 |
;; 5. Money out: the money received by disposing of shares. This |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
658 |
;; is in trans-sold plus trans-spinoff |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
659 |
;; 6. Brokerage fees: this is in trans-brokerage |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
660 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
661 |
;; Income |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
662 |
(dividendcoll 'add commod-currency trans-income) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
663 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
664 |
;; Brokerage fees. May be either ignored or part of basis, but that |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
665 |
;; will be dealt with elsewhere. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
666 |
(brokeragecoll 'add commod-currency trans-brokerage) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
667 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
668 |
;; Add brokerage fees to trans-bought if not ignoring them and there are any |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
669 |
(if (and (not (eq? handle-brokerage-fees 'ignore-brokerage)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
670 |
(gnc-numeric-positive-p trans-brokerage) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
671 |
(gnc-numeric-positive-p trans-shares)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
672 |
(let* ((fee-frac (gnc-numeric-div shares-bought trans-shares GNC-DENOM-AUTO GNC-DENOM-REDUCE)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
673 |
(fees (gnc-numeric-mul trans-brokerage fee-frac commod-currency-frac GNC-RND-ROUND))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
674 |
(set! trans-bought (gnc-numeric-add trans-bought fees commod-currency-frac GNC-RND-ROUND)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
675 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
676 |
;; Update the running total of the money in the DRP residual account. This is relevant |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
677 |
;; if this is a reinvestment transaction (both income and purchase) and there seems to |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
678 |
;; asset accounts used to hold excess income. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
679 |
(if (and trans-drp-account |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
680 |
(not (eq? trans-drp-account 'none)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
681 |
(gnc-numeric-positive-p trans-income) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
682 |
(gnc-numeric-positive-p trans-bought)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
683 |
(if (not drp-holding-account) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
684 |
(begin |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
685 |
(set! drp-holding-account trans-drp-account) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
686 |
(set! drp-holding-amount trans-drp-residual)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
687 |
(if (and (not (eq? drp-holding-account 'none)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
688 |
(parent-or-sibling? trans-drp-account drp-holding-account)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
689 |
(set! drp-holding-amount (gnc-numeric-add drp-holding-amount trans-drp-residual |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
690 |
commod-currency-frac GNC-RND-ROUND)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
691 |
(begin |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
692 |
;; Wrong account (or no account), assume there isn't a DRP holding account |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
693 |
(set! drp-holding-account 'none) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
694 |
(set trans-drp-residual (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
695 |
(set! drp-holding-amount (gnc-numeric-zero)))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
696 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
697 |
;; Set trans-bought to the amount of money moved in to the account which was used to |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
698 |
;; purchase more shares. If this is not a DRP transaction then all money used to purchase |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
699 |
;; shares is money in. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
700 |
(if (and (gnc-numeric-positive-p trans-income) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
701 |
(gnc-numeric-positive-p trans-bought)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
702 |
(begin |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
703 |
(set! trans-bought (gnc-numeric-sub trans-bought trans-income |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
704 |
commod-currency-frac GNC-RND-ROUND)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
705 |
(set! trans-bought (gnc-numeric-add trans-bought trans-drp-residual |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
706 |
commod-currency-frac GNC-RND-ROUND)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
707 |
(set! trans-bought (gnc-numeric-sub trans-bought drp-holding-amount |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
708 |
commod-currency-frac GNC-RND-ROUND)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
709 |
;; If the DRP holding account balance is negative, adjust it by the amount |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
710 |
;; used in this transaction |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
711 |
(if (and (gnc-numeric-negative-p drp-holding-amount) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
712 |
(gnc-numeric-positive-p trans-bought)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
713 |
(set! drp-holding-amount (gnc-numeric-add drp-holding-amount trans-bought |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
714 |
commod-currency-frac GNC-RND-ROUND))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
715 |
;; Money in is never more than amount spent to purchase shares |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
716 |
(if (gnc-numeric-negative-p trans-bought) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
717 |
(set! trans-bought (gnc-numeric-zero))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
718 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
719 |
(gnc:debug "Adjusted trans-bought " (gnc-numeric-to-string trans-bought) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
720 |
" DRP holding account " (gnc-numeric-to-string drp-holding-amount)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
721 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
722 |
(moneyincoll 'add commod-currency trans-bought) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
723 |
(moneyoutcoll 'add commod-currency trans-sold) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
724 |
(moneyoutcoll 'add commod-currency trans-spinoff) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
725 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
726 |
;; Look at splits again to handle changes in basis and realized gains |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
727 |
(for-each |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
728 |
(lambda (s) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
729 |
(let |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
730 |
;; get the split's units and value |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
731 |
((split-units (xaccSplitGetAmount s)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
732 |
(split-value (xaccSplitGetValue s))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
733 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
734 |
(gnc:debug "Pass 2: split units " (gnc-numeric-to-string split-units) " split-value " |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
735 |
(gnc-numeric-to-string split-value) " commod-currency " |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
736 |
(gnc-commodity-get-printname commod-currency)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
737 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
738 |
(cond |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
739 |
((and (not (gnc-numeric-zero-p split-units)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
740 |
(same-account? current (xaccSplitGetAccount s))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
741 |
;; Split into subject account with non-zero amount. This is a purchase |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
742 |
;; or a sale, adjust the basis |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
743 |
(let* ((split-value-currency (gnc:gnc-monetary-amount |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
744 |
(my-exchange-fn (gnc:make-gnc-monetary |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
745 |
commod-currency split-value) currency))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
746 |
(orig-basis (sum-basis basis-list currency-frac)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
747 |
;; proportion of the fees attributable to this split |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
748 |
(fee-ratio (gnc-numeric-div (gnc-numeric-abs split-units) trans-shares |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
749 |
GNC-DENOM-AUTO GNC-DENOM-REDUCE)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
750 |
;; Fees for this split in report currency |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
751 |
(fees-currency (gnc:gnc-monetary-amount (my-exchange-fn |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
752 |
(gnc:make-gnc-monetary commod-currency |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
753 |
(gnc-numeric-mul fee-ratio trans-brokerage |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
754 |
commod-currency-frac GNC-RND-ROUND)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
755 |
currency))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
756 |
(split-value-with-fees (if (eq? handle-brokerage-fees 'include-in-basis) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
757 |
;; Include brokerage fees in basis |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
758 |
(gnc-numeric-add split-value-currency fees-currency |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
759 |
currency-frac GNC-RND-ROUND) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
760 |
split-value-currency))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
761 |
(gnc:debug "going in to basis list " basis-list " " (gnc-numeric-to-string split-units) " " |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
762 |
(gnc-numeric-to-string split-value-with-fees)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
763 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
764 |
;; adjust the basis |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
765 |
(set! basis-list (basis-builder basis-list split-units split-value-with-fees |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
766 |
basis-method currency-frac)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
767 |
(gnc:debug "coming out of basis list " basis-list) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
768 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
769 |
;; If it's a sale or the stock is worthless, calculate the gain |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
770 |
(if (not (gnc-numeric-positive-p split-value)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
771 |
;; Split value is zero or negative. If it's zero it's either a stock split/merge |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
772 |
;; or the stock has become worthless (which looks like a merge where the number |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
773 |
;; of shares goes to zero). If the value is negative then it's a disposal of some sort. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
774 |
(let ((new-basis (sum-basis basis-list currency-frac))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
775 |
(if (or (gnc-numeric-zero-p new-basis) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
776 |
(gnc-numeric-negative-p split-value)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
777 |
;; Split value is negative or new basis is zero (stock is worthless), |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
778 |
;; Capital gain is money out minus change in basis |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
779 |
(let ((gain (gnc-numeric-sub (gnc-numeric-abs split-value-with-fees) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
780 |
(gnc-numeric-sub orig-basis new-basis |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
781 |
currency-frac GNC-RND-ROUND) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
782 |
currency-frac GNC-RND-ROUND))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
783 |
(gnc:debug "Old basis=" (gnc-numeric-to-string orig-basis) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
784 |
" New basis=" (gnc-numeric-to-string new-basis) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
785 |
" Gain=" (gnc-numeric-to-string gain)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
786 |
(gaincoll 'add currency gain))))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
787 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
788 |
;; here is where we handle a spin-off txn. This will be a no-units |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
789 |
;; split with only one other split. xaccSplitGetOtherSplit only |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
790 |
;; returns on a two-split txn. It's not a spinoff is the other split is |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
791 |
;; in an income or expense account. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
792 |
((spin-off? s current) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
793 |
(gnc:debug "before spin-off basis list " basis-list) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
794 |
(set! basis-list (basis-builder basis-list split-units (gnc:gnc-monetary-amount |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
795 |
(my-exchange-fn (gnc:make-gnc-monetary |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
796 |
commod-currency split-value) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
797 |
currency)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
798 |
basis-method |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
799 |
currency-frac)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
800 |
(gnc:debug "after spin-off basis list " basis-list)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
801 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
802 |
)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
803 |
(xaccTransGetSplitList parent) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
804 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
805 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
806 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
807 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
808 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
809 |
(xaccAccountGetSplitList current) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
810 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
811 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
812 |
;; Look for income and expense transactions that don't have a split in the |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
813 |
;; the account we're processing. We do this as follow |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
814 |
;; 1. Make sure the parent account is a currency-valued asset or bank account |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
815 |
;; 2. If so go through all the splits in that account |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
816 |
;; 3. If a split is part of a two split transaction where the other split is |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
817 |
;; to an income or expense account and the leaf name of that account is the |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
818 |
;; same as the leaf name of the account we're processing, add it to the |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
819 |
;; income or expense accumulator |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
820 |
;; |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
821 |
;; In other words with an account structure like |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
822 |
;; |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
823 |
;; Assets (type ASSET) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
824 |
;; Broker (type ASSET) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
825 |
;; Widget Stock (type STOCK) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
826 |
;; Income (type INCOME) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
827 |
;; Dividends (type INCOME) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
828 |
;; Widget Stock (type INCOME) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
829 |
;; |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
830 |
;; If you are producing a report on "Assets:Broker:Widget Stock" a |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
831 |
;; transaction that debits the Assets:Broker account and credits the |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
832 |
;; "Income:Dividends:Widget Stock" account will count as income in |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
833 |
;; the report even though it doesn't have a split in the account |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
834 |
;; being reported on. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
835 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
836 |
(let ((parent-account (gnc-account-get-parent current)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
837 |
(account-name (xaccAccountGetName current))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
838 |
(if (and (not (null? parent-account)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
839 |
(member (xaccAccountGetType parent-account) (list ACCT-TYPE-ASSET ACCT-TYPE-BANK)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
840 |
(gnc-commodity-is-currency (xaccAccountGetCommodity parent-account))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
841 |
(for-each |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
842 |
(lambda (split) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
843 |
(let* ((other-split (xaccSplitGetOtherSplit split)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
844 |
;; This is safe because xaccSplitGetAccount returns null for a null split |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
845 |
(other-acct (xaccSplitGetAccount other-split)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
846 |
(parent (xaccSplitGetParent split)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
847 |
(txn-date (gnc-transaction-get-date-posted parent))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
848 |
(if (and (not (null? other-acct)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
849 |
(gnc:timepair-le txn-date to-date) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
850 |
(string=? (xaccAccountGetName other-acct) account-name) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
851 |
(gnc-commodity-is-currency (xaccAccountGetCommodity other-acct))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
852 |
;; This is a two split transaction where the other split is to an |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
853 |
;; account with the same name as the current account. If it's an |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
854 |
;; income or expense account accumulate the value of the transaction |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
855 |
(let ((val (xaccSplitGetValue split)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
856 |
(curr (xaccAccountGetCommodity other-acct))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
857 |
(cond ((split-account-type? other-split ACCT-TYPE-INCOME) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
858 |
(gnc:debug "More income " (gnc-numeric-to-string val)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
859 |
(dividendcoll 'add curr val)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
860 |
((split-account-type? other-split ACCT-TYPE-EXPENSE) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
861 |
(gnc:debug "More expense " (gnc-numeric-to-string |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
862 |
(gnc-numeric-neg val))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
863 |
(brokeragecoll 'add curr (gnc-numeric-neg val))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
864 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
865 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
866 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
867 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
868 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
869 |
(xaccAccountGetSplitList parent-account) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
870 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
871 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
872 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
873 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
874 |
(gnc:debug "pricing txn is " pricing-txn) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
875 |
(gnc:debug "use txn is " use-txn) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
876 |
(gnc:debug "prefer-pricelist is " prefer-pricelist) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
877 |
(gnc:debug "price is " price) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
878 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
879 |
(gnc:debug "basis we're using to build rows is " (gnc-numeric-to-string (sum-basis basis-list |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
880 |
currency-frac))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
881 |
(gnc:debug "but the actual basis list is " basis-list) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
882 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
883 |
(if (eq? handle-brokerage-fees 'include-in-gain) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
884 |
(gaincoll 'minusmerge brokeragecoll #f)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
885 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
886 |
(if (or include-empty (not (gnc-numeric-zero-p units))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
887 |
(let* ((moneyin (gnc:sum-collector-commodity moneyincoll currency my-exchange-fn)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
888 |
(moneyout (gnc:sum-collector-commodity moneyoutcoll currency my-exchange-fn)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
889 |
(brokerage (gnc:sum-collector-commodity brokeragecoll currency my-exchange-fn)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
890 |
(income (gnc:sum-collector-commodity dividendcoll currency my-exchange-fn)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
891 |
;; just so you know, gain == realized gain, ugain == un-realized gain, bothgain, well.. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
892 |
(gain (gnc:sum-collector-commodity gaincoll currency my-exchange-fn)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
893 |
(ugain (gnc:make-gnc-monetary currency |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
894 |
(gnc-numeric-sub (gnc:gnc-monetary-amount (my-exchange-fn value currency)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
895 |
(sum-basis basis-list (gnc-commodity-get-fraction currency)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
896 |
currency-frac GNC-RND-ROUND))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
897 |
(bothgain (gnc:make-gnc-monetary currency (gnc-numeric-add (gnc:gnc-monetary-amount gain) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
898 |
(gnc:gnc-monetary-amount ugain) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
899 |
currency-frac GNC-RND-ROUND))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
900 |
(totalreturn (gnc:make-gnc-monetary currency (gnc-numeric-add (gnc:gnc-monetary-amount bothgain) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
901 |
(gnc:gnc-monetary-amount income) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
902 |
currency-frac GNC-RND-ROUND))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
903 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
904 |
(activecols (list (gnc:html-account-anchor current))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
905 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
906 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
907 |
;; If we're using the txn, warn the user |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
908 |
(if use-txn |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
909 |
(if pricing-txn |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
910 |
(set! warn-price-dirty #t) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
911 |
(set! warn-no-price #t) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
912 |
)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
913 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
914 |
(total-value 'add (gnc:gnc-monetary-commodity value) (gnc:gnc-monetary-amount value)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
915 |
(total-moneyin 'merge moneyincoll #f) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
916 |
(total-moneyout 'merge moneyoutcoll #f) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
917 |
(total-brokerage 'merge brokeragecoll #f) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
918 |
(total-income 'merge dividendcoll #f) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
919 |
(total-gain 'merge gaincoll #f) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
920 |
(total-ugain 'add (gnc:gnc-monetary-commodity ugain) (gnc:gnc-monetary-amount ugain)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
921 |
(total-basis 'add currency (sum-basis basis-list currency-frac)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
922 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
923 |
;; build a list for the row based on user selections |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
924 |
(if show-symbol (append! activecols (list (gnc:make-html-table-header-cell/markup "text-cell" ticker-symbol)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
925 |
(if show-listing (append! activecols (list (gnc:make-html-table-header-cell/markup "text-cell" listing)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
926 |
(if show-shares (append! activecols (list (gnc:make-html-table-header-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
927 |
"number-cell" (xaccPrintAmount units share-print-info))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
928 |
(if show-price (append! activecols (list (gnc:make-html-table-header-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
929 |
"number-cell" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
930 |
(if use-txn |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
931 |
(if pricing-txn |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
932 |
(gnc:html-transaction-anchor |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
933 |
pricing-txn |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
934 |
price |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
935 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
936 |
price |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
937 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
938 |
(gnc:html-price-anchor |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
939 |
price |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
940 |
(gnc:make-gnc-monetary |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
941 |
(gnc-price-get-currency price) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
942 |
(gnc-price-get-value price))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
943 |
))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
944 |
(append! activecols (list (if use-txn (if pricing-txn "*" "**") " ") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
945 |
(gnc:make-html-table-header-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
946 |
"number-cell" (gnc:make-gnc-monetary currency (sum-basis basis-list |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
947 |
currency-frac))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
948 |
(gnc:make-html-table-header-cell/markup "number-cell" value) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
949 |
(gnc:make-html-table-header-cell/markup "number-cell" moneyin) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
950 |
(gnc:make-html-table-header-cell/markup "number-cell" moneyout) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
951 |
(gnc:make-html-table-header-cell/markup "number-cell" gain) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
952 |
(gnc:make-html-table-header-cell/markup "number-cell" ugain) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
953 |
(gnc:make-html-table-header-cell/markup "number-cell" bothgain) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
954 |
(gnc:make-html-table-header-cell/markup "number-cell" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
955 |
(let* ((moneyinvalue (gnc-numeric-to-double |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
956 |
(gnc:gnc-monetary-amount moneyin))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
957 |
(bothgainvalue (gnc-numeric-to-double |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
958 |
(gnc:gnc-monetary-amount bothgain))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
959 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
960 |
(if (= 0.0 moneyinvalue) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
961 |
"" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
962 |
(sprintf #f "%.2f%%" (* 100 (/ bothgainvalue moneyinvalue))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
963 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
964 |
(gnc:make-html-table-header-cell/markup "number-cell" income))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
965 |
(if (not (eq? handle-brokerage-fees 'ignore-brokerage)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
966 |
(append! activecols (list (gnc:make-html-table-header-cell/markup "number-cell" brokerage)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
967 |
(append! activecols (list (gnc:make-html-table-header-cell/markup "number-cell" totalreturn) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
968 |
(gnc:make-html-table-header-cell/markup "number-cell" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
969 |
(let* ((moneyinvalue (gnc-numeric-to-double |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
970 |
(gnc:gnc-monetary-amount moneyin))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
971 |
(totalreturnvalue (gnc-numeric-to-double |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
972 |
(gnc:gnc-monetary-amount totalreturn))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
973 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
974 |
(if (= 0.0 moneyinvalue) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
975 |
"" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
976 |
(sprintf #f "%.2f%%" (* 100 (/ totalreturnvalue moneyinvalue)))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
977 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
978 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
979 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
980 |
(gnc:html-table-append-row/markup! |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
981 |
table |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
982 |
row-style |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
983 |
activecols) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
984 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
985 |
(if (and (not use-txn) price) (gnc-price-unref price)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
986 |
(table-add-stock-rows-internal rest (not odd-row?)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
987 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
988 |
(begin |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
989 |
(if (and (not use-txn) price) (gnc-price-unref price)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
990 |
(table-add-stock-rows-internal rest odd-row?) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
991 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
992 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
993 |
))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
994 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
995 |
(set! work-to-do (gnc:accounts-count-splits accounts)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
996 |
(table-add-stock-rows-internal accounts #t))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
997 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
998 |
;; Tell the user that we're starting. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
999 |
(gnc:report-starting reportname) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1000 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1001 |
;; The first thing we do is make local variables for all the specific |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1002 |
;; options in the set of options given to the function. This set will |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1003 |
;; be generated by the options generator above. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1004 |
(let ((to-date (gnc:date-option-absolute-time |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1005 |
(get-option gnc:pagename-general "Date"))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1006 |
(accounts (get-option gnc:pagename-accounts "Accounts")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1007 |
(currency (get-option gnc:pagename-general "Report's currency")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1008 |
(price-source (get-option gnc:pagename-general |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1009 |
optname-price-source)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1010 |
(report-title (get-option gnc:pagename-general |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1011 |
gnc:optname-reportname)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1012 |
(include-empty (get-option gnc:pagename-accounts |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1013 |
optname-zero-shares)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1014 |
(show-symbol (get-option gnc:pagename-display |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1015 |
optname-show-symbol)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1016 |
(show-listing (get-option gnc:pagename-display |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1017 |
optname-show-listing)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1018 |
(show-shares (get-option gnc:pagename-display |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1019 |
optname-show-shares)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1020 |
(show-price (get-option gnc:pagename-display |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1021 |
optname-show-price)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1022 |
(basis-method (get-option gnc:pagename-general |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1023 |
optname-basis-method)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1024 |
(prefer-pricelist (get-option gnc:pagename-general |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1025 |
optname-prefer-pricelist)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1026 |
(handle-brokerage-fees (get-option gnc:pagename-general |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1027 |
optname-brokerage-fees)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1028 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1029 |
(total-basis (gnc:make-commodity-collector)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1030 |
(total-value (gnc:make-commodity-collector)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1031 |
(total-moneyin (gnc:make-commodity-collector)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1032 |
(total-moneyout (gnc:make-commodity-collector)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1033 |
(total-income (gnc:make-commodity-collector)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1034 |
(total-gain (gnc:make-commodity-collector)) ;; realized gain |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1035 |
(total-ugain (gnc:make-commodity-collector)) ;; unrealized gain |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1036 |
(total-brokerage (gnc:make-commodity-collector)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1037 |
;;document will be the HTML document that we return. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1038 |
(table (gnc:make-html-table)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1039 |
(document (gnc:make-html-document))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1040 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1041 |
(gnc:html-document-set-title! |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1042 |
document (string-append |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1043 |
report-title |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1044 |
(sprintf #f " %s" (gnc-print-date to-date)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1045 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1046 |
(if (not (null? accounts)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1047 |
; at least 1 account selected |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1048 |
(let* ((exchange-fn (gnc:case-exchange-fn price-source currency to-date)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1049 |
(pricedb (gnc-pricedb-get-db (gnc-get-current-book))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1050 |
(price-fn |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1051 |
(case price-source |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1052 |
((pricedb-latest) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1053 |
(lambda (foreign domestic date) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1054 |
(find-price (gnc-pricedb-lookup-latest-any-currency pricedb foreign) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1055 |
domestic))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1056 |
((pricedb-nearest) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1057 |
(lambda (foreign domestic date) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1058 |
(find-price (gnc-pricedb-lookup-nearest-in-time-any-currency |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1059 |
pricedb foreign (timespecCanonicalDayTime date)) domestic))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1060 |
(headercols (list (_ "Account"))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1061 |
(totalscols (list (gnc:make-html-table-cell/markup "total-label-cell" (_ "Total")))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1062 |
(sum-total-moneyin (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1063 |
(sum-total-income (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1064 |
(sum-total-both-gains (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1065 |
(sum-total-gain (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1066 |
(sum-total-ugain (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1067 |
(sum-total-brokerage (gnc-numeric-zero)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1068 |
(sum-total-totalreturn (gnc-numeric-zero))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1069 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1070 |
;;begin building lists for which columns to display |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1071 |
(if show-symbol |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1072 |
(begin (append! headercols (list (_ "Symbol"))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1073 |
(append! totalscols (list " ")))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1074 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1075 |
(if show-listing |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1076 |
(begin (append! headercols (list (_ "Listing"))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1077 |
(append! totalscols (list " ")))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1078 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1079 |
(if show-shares |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1080 |
(begin (append! headercols (list (_ "Shares"))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1081 |
(append! totalscols (list " ")))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1082 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1083 |
(if show-price |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1084 |
(begin (append! headercols (list (_ "Price"))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1085 |
(append! totalscols (list " ")))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1086 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1087 |
(append! headercols (list " " |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1088 |
(_ "Basis") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1089 |
(_ "Value") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1090 |
(_ "Money In") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1091 |
(_ "Money Out") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1092 |
(_ "Realized Gain") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1093 |
(_ "Unrealized Gain") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1094 |
(_ "Total Gain") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1095 |
(_ "Rate of Gain") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1096 |
(_ "Income"))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1097 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1098 |
(if (not (eq? handle-brokerage-fees 'ignore-brokerage)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1099 |
(append! headercols (list (_ "Brokerage Fees")))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1100 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1101 |
(append! headercols (list (_ "Total Return") |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1102 |
(_ "Rate of Return"))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1103 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1104 |
(append! totalscols (list " ")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1105 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1106 |
(gnc:html-table-set-col-headers! |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1107 |
table |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1108 |
headercols) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1109 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1110 |
(table-add-stock-rows |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1111 |
table accounts to-date currency price-fn exchange-fn price-source |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1112 |
include-empty show-symbol show-listing show-shares show-price basis-method |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1113 |
prefer-pricelist handle-brokerage-fees |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1114 |
total-basis total-value total-moneyin total-moneyout |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1115 |
total-income total-gain total-ugain total-brokerage) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1116 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1117 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1118 |
(set! sum-total-moneyin (gnc:sum-collector-commodity total-moneyin currency exchange-fn)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1119 |
(set! sum-total-income (gnc:sum-collector-commodity total-income currency exchange-fn)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1120 |
(set! sum-total-gain (gnc:sum-collector-commodity total-gain currency exchange-fn)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1121 |
(set! sum-total-ugain (gnc:sum-collector-commodity total-ugain currency exchange-fn)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1122 |
(set! sum-total-both-gains (gnc:make-gnc-monetary currency (gnc-numeric-add (gnc:gnc-monetary-amount sum-total-gain) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1123 |
(gnc:gnc-monetary-amount sum-total-ugain) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1124 |
(gnc-commodity-get-fraction currency) GNC-RND-ROUND))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1125 |
(set! sum-total-brokerage (gnc:sum-collector-commodity total-brokerage currency exchange-fn)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1126 |
(set! sum-total-totalreturn (gnc:make-gnc-monetary currency (gnc-numeric-add (gnc:gnc-monetary-amount sum-total-both-gains) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1127 |
(gnc:gnc-monetary-amount sum-total-income) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1128 |
(gnc-commodity-get-fraction currency) GNC-RND-ROUND))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1129 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1130 |
(gnc:html-table-append-row/markup! |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1131 |
table |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1132 |
"grand-total" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1133 |
(list |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1134 |
(gnc:make-html-table-cell/size |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1135 |
1 17 (gnc:make-html-text (gnc:html-markup-hr))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1136 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1137 |
;; finish building the totals columns, now that totals are complete |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1138 |
(append! totalscols (list |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1139 |
(gnc:make-html-table-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1140 |
"total-number-cell" (gnc:sum-collector-commodity total-basis currency exchange-fn)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1141 |
(gnc:make-html-table-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1142 |
"total-number-cell" (gnc:sum-collector-commodity total-value currency exchange-fn)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1143 |
(gnc:make-html-table-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1144 |
"total-number-cell" sum-total-moneyin) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1145 |
(gnc:make-html-table-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1146 |
"total-number-cell" (gnc:sum-collector-commodity total-moneyout currency exchange-fn)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1147 |
(gnc:make-html-table-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1148 |
"total-number-cell" sum-total-gain) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1149 |
(gnc:make-html-table-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1150 |
"total-number-cell" sum-total-ugain) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1151 |
(gnc:make-html-table-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1152 |
"total-number-cell" sum-total-both-gains) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1153 |
(gnc:make-html-table-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1154 |
"total-number-cell" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1155 |
(let* ((totalinvalue (gnc-numeric-to-double |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1156 |
(gnc:gnc-monetary-amount sum-total-moneyin))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1157 |
(totalgainvalue (gnc-numeric-to-double |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1158 |
(gnc:gnc-monetary-amount sum-total-both-gains))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1159 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1160 |
(if (= 0.0 totalinvalue) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1161 |
"" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1162 |
(sprintf #f "%.2f%%" (* 100 (/ totalgainvalue totalinvalue)))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1163 |
(gnc:make-html-table-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1164 |
"total-number-cell" sum-total-income))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1165 |
(if (not (eq? handle-brokerage-fees 'ignore-brokerage)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1166 |
(append! totalscols (list |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1167 |
(gnc:make-html-table-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1168 |
"total-number-cell" sum-total-brokerage)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1169 |
(append! totalscols (list |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1170 |
(gnc:make-html-table-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1171 |
"total-number-cell" sum-total-totalreturn) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1172 |
(gnc:make-html-table-cell/markup |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1173 |
"total-number-cell" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1174 |
(let* ((totalinvalue (gnc-numeric-to-double |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1175 |
(gnc:gnc-monetary-amount sum-total-moneyin))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1176 |
(totalreturnvalue (gnc-numeric-to-double |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1177 |
(gnc:gnc-monetary-amount sum-total-totalreturn))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1178 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1179 |
(if (= 0.0 totalinvalue) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1180 |
"" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1181 |
(sprintf #f "%.2f%%" (* 100 (/ totalreturnvalue totalinvalue)))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1182 |
)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1183 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1184 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1185 |
(gnc:html-table-append-row/markup! |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1186 |
table |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1187 |
"grand-total" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1188 |
totalscols |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1189 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1190 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1191 |
(gnc:html-document-add-object! document table) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1192 |
(if warn-price-dirty |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1193 |
(gnc:html-document-append-objects! document |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1194 |
(list (gnc:make-html-text (_ "* this commodity data was built using transaction pricing instead of the price list.")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1195 |
(gnc:make-html-text (gnc:html-markup-br)) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1196 |
(gnc:make-html-text (_ "If you are in a multi-currency situation, the exchanges may not be correct."))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1197 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1198 |
(if warn-no-price |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1199 |
(gnc:html-document-append-objects! document |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1200 |
(list (gnc:make-html-text (if warn-price-dirty (gnc:html-markup-br) "")) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1201 |
(gnc:make-html-text (_ "** this commodity has no price and a price of 1 has been used."))))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1202 |
) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1203 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1204 |
;if no accounts selected. |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1205 |
(gnc:html-document-add-object! |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1206 |
document |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1207 |
(gnc:html-make-no-account-warning |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1208 |
report-title (gnc:report-id report-obj)))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1209 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1210 |
(gnc:report-finished) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1211 |
document))) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1212 |
|
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1213 |
(gnc:define-report |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1214 |
'version 1 |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1215 |
'report-guid "2d82e4152af845f2be434f71f8535b85" |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1216 |
'name reportname |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1217 |
'menu-path (list gnc:menuname-asset-liability) |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1218 |
'options-generator options-generator |
64f48a8c758c
New portfolio report compatible with the merge.
Fabien Ninoles <fabien@tzone.org>
parents:
diff
changeset
|
1219 |
'renderer advanced-portfolio-renderer) |