@@ -103,15 +103,18 @@ accountTransactionsReport rspec@ReportSpec{_rsReportOpts=ropts} j thisacctq = it
103
103
periodq = Date . periodAsDateSpan $ period_ ropts
104
104
amtq = filterQuery queryIsCurOrAmt $ _rsQuery rspec
105
105
queryIsCurOrAmt q = queryIsSym q || queryIsAmt q
106
+ wd = whichDate ropts
106
107
107
- -- Note that within this functions , we are only allowed limited
108
+ -- Note that within this function , we are only allowed limited
108
109
-- transformation of the transaction postings: this is due to the need to
109
110
-- pass the original transactions into accountTransactionsReportItem.
110
111
-- Generally, we either include a transaction in full, or not at all.
111
112
-- Do some limited filtering and valuing of the journal's transactions:
112
113
-- - filter them by the account query if any,
113
114
-- - discard amounts not matched by the currency and amount query if any,
114
115
-- - then apply valuation if any.
116
+ -- Additional reportq filtering, such as date filtering, happens down in
117
+ -- accountTransactionsReportItem, which discards transactions with no matched postings.
115
118
acctJournal =
116
119
ptraceAtWith 5 ((" ts3:\n " ++ ). pshowTransactions. jtxns)
117
120
-- maybe convert these transactions to cost or value
@@ -149,7 +152,7 @@ accountTransactionsReport rspec@ReportSpec{_rsReportOpts=ropts} j thisacctq = it
149
152
-- sort by the transaction's register date, then index, for accurate starting balance
150
153
. ptraceAtWith 5 ((" ts4:\n " ++ ). pshowTransactions. map snd )
151
154
. sortBy (comparing (Down . fst ) <> comparing (Down . tindex . snd ))
152
- . map (\ t -> (transactionRegisterDate reportq thisacctq t, t))
155
+ . map (\ t -> (transactionRegisterDate wd reportq thisacctq t, t))
153
156
$ jtxns acctJournal
154
157
155
158
pshowTransactions :: [Transaction ] -> String
@@ -160,9 +163,8 @@ pshowTransactions = pshow . map (\t -> unwords [show $ tdate t, T.unpack $ tdesc
160
163
-- which account to use as the focus, a starting balance, and a sign-setting
161
164
-- function.
162
165
-- Each transaction is accompanied by the date that should be shown for it
163
- -- in the report, which is not necessarily the transaction date; it is
164
- -- the earliest of the posting dates which match both thisacctq and reportq,
165
- -- otherwise the transaction's date if there are no matching postings.
166
+ -- in the report. This is not necessarily the transaction date - see
167
+ -- transactionRegisterDate.
166
168
accountTransactionsReportItems :: Query -> Query -> MixedAmount -> (MixedAmount -> MixedAmount )
167
169
-> [(Day , Transaction )] -> [AccountTransactionsReportItem ]
168
170
accountTransactionsReportItems reportq thisacctq bal signfn =
@@ -176,7 +178,7 @@ accountTransactionsReportItem reportq thisacctq signfn bal (d, torig)
176
178
| null reportps = (bal, Nothing ) -- no matched postings in this transaction, skip it
177
179
| otherwise = (b, Just (torig, tacct{tdate= d}, numotheraccts > 1 , otheracctstr, a, b))
178
180
where
179
- tacct@ Transaction {tpostings= reportps} = filterTransactionPostings reportq torig
181
+ tacct@ Transaction {tpostings= reportps} = filterTransactionPostings reportq torig -- TODO needs to consider --date2, #1731
180
182
(thisacctps, otheracctps) = partition (matchesPosting thisacctq) reportps
181
183
numotheraccts = length $ nub $ map paccount otheracctps
182
184
otheracctstr | thisacctq == None = summarisePostingAccounts reportps -- no current account ? summarise all matched postings
@@ -185,16 +187,20 @@ accountTransactionsReportItem reportq thisacctq signfn bal (d, torig)
185
187
a = signfn . maNegate $ sumPostings thisacctps
186
188
b = bal `maPlus` a
187
189
188
- -- | What is the transaction's date in the context of a particular account
189
- -- (specified with a query) and report query, as in an account register ?
190
- -- It's normally the transaction's general date, but if any posting(s)
191
- -- matched by the report query and affecting the matched account(s) have
192
- -- their own earlier dates, it's the earliest of these dates.
193
- -- Secondary transaction/posting dates are ignored.
194
- transactionRegisterDate :: Query -> Query -> Transaction -> Day
195
- transactionRegisterDate reportq thisacctq t
196
- | null thisacctps = tdate t
197
- | otherwise = minimum $ map postingDate thisacctps
190
+ -- TODO needs checking, cf #1731
191
+ -- | What date should be shown for a transaction in an account register report ?
192
+ -- This will be in context of a particular account (the "this account" query)
193
+ -- and any additional report query. It could be:
194
+ --
195
+ -- - if postings are matched by both thisacctq and reportq, the earliest of those
196
+ -- matched postings' dates (or their secondary dates if --date2 was used)
197
+ --
198
+ -- - the transaction date, or its secondary date if --date2 was used.
199
+ --
200
+ transactionRegisterDate :: WhichDate -> Query -> Query -> Transaction -> Day
201
+ transactionRegisterDate wd reportq thisacctq t
202
+ | not $ null thisacctps = minimum $ map (postingDateOrDate2 wd) thisacctps
203
+ | otherwise = transactionDateOrDate2 wd t
198
204
where
199
205
reportps = tpostings $ filterTransactionPostings reportq t
200
206
thisacctps = filter (matchesPosting thisacctq) reportps
0 commit comments