{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
module Hledger.Reports.AccountTransactionsReport (
AccountTransactionsReport,
AccountTransactionsReportItem,
accountTransactionsReport,
accountTransactionsReportWithStart,
accountTransactionsReportItems,
transactionRegisterDate,
transactionRegisterDateExtra,
triOrigTransaction,
triDate,
triAmount,
triBalance,
triCommodityAmount,
triCommodityBalance,
accountTransactionsReportByCommodity,
filterAccountTransactionsReportByCommodity,
tests_AccountTransactionsReport
)
where
import Data.Foldable (asum)
import Data.List (mapAccumR, nub, partition, sortBy)
import Data.List.Extra (nubSort)
import Data.Maybe (catMaybes, fromMaybe)
import Data.Ord (Down(..), comparing)
import Data.Text qualified as T
import Data.Time.Calendar (Day, fromGregorian)
import Hledger.Data
import Hledger.Query
import Hledger.Reports.PostingsReport (registerRunningCalculationFn)
import Hledger.Reports.ReportOptions
import Hledger.Utils
type AccountTransactionsReport = [AccountTransactionsReportItem]
type AccountTransactionsReportItem =
(
Transaction
,Transaction
,Bool
,[AccountName]
,MixedAmount
,MixedAmount
)
instance HasAmounts AccountTransactionsReportItem where
styleAmounts :: Map CommoditySymbol AmountStyle
-> AccountTransactionsReportItem -> AccountTransactionsReportItem
styleAmounts Map CommoditySymbol AmountStyle
styles (Transaction
torig,Transaction
tacct,Bool
b,[CommoditySymbol]
c,MixedAmount
a1,MixedAmount
a2) =
(Map CommoditySymbol AmountStyle -> Transaction -> Transaction
forall a. HasAmounts a => Map CommoditySymbol AmountStyle -> a -> a
styleAmounts Map CommoditySymbol AmountStyle
styles Transaction
torig,Map CommoditySymbol AmountStyle -> Transaction -> Transaction
forall a. HasAmounts a => Map CommoditySymbol AmountStyle -> a -> a
styleAmounts Map CommoditySymbol AmountStyle
styles Transaction
tacct,Bool
b,[CommoditySymbol]
c,Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount
forall a. HasAmounts a => Map CommoditySymbol AmountStyle -> a -> a
styleAmounts Map CommoditySymbol AmountStyle
styles MixedAmount
a1,Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount
forall a. HasAmounts a => Map CommoditySymbol AmountStyle -> a -> a
styleAmounts Map CommoditySymbol AmountStyle
styles MixedAmount
a2)
triOrigTransaction :: (a, b, c, d, e, f) -> a
triOrigTransaction (a
torig,b
_,c
_,d
_,e
_,f
_) = a
torig
triDate :: (a, Transaction, c, d, e, f) -> Day
triDate (a
_,Transaction
tacct,c
_,d
_,e
_,f
_) = Transaction -> Day
tdate Transaction
tacct
triAmount :: (a, b, c, d, e, f) -> e
triAmount (a
_,b
_,c
_,d
_,e
a,f
_) = e
a
triBalance :: (a, b, c, d, e, f) -> f
triBalance (a
_,b
_,c
_,d
_,e
_,f
a) = f
a
triCommodityAmount :: CommoditySymbol -> (a, b, c, d, MixedAmount, f) -> MixedAmount
triCommodityAmount CommoditySymbol
c = CommoditySymbol -> MixedAmount -> MixedAmount
filterMixedAmountByCommodity CommoditySymbol
c (MixedAmount -> MixedAmount)
-> ((a, b, c, d, MixedAmount, f) -> MixedAmount)
-> (a, b, c, d, MixedAmount, f)
-> MixedAmount
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, b, c, d, MixedAmount, f) -> MixedAmount
forall {a} {b} {c} {d} {e} {f}. (a, b, c, d, e, f) -> e
triAmount
triCommodityBalance :: CommoditySymbol -> (a, b, c, d, e, MixedAmount) -> MixedAmount
triCommodityBalance CommoditySymbol
c = CommoditySymbol -> MixedAmount -> MixedAmount
filterMixedAmountByCommodity CommoditySymbol
c (MixedAmount -> MixedAmount)
-> ((a, b, c, d, e, MixedAmount) -> MixedAmount)
-> (a, b, c, d, e, MixedAmount)
-> MixedAmount
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, b, c, d, e, MixedAmount) -> MixedAmount
forall {a} {b} {c} {d} {e} {f}. (a, b, c, d, e, f) -> f
triBalance
accountTransactionsReport :: ReportSpec -> Journal -> Query -> AccountTransactionsReport
accountTransactionsReport :: ReportSpec -> Journal -> Query -> AccountTransactionsReport
accountTransactionsReport ReportSpec
rspec Journal
j = (MixedAmount, AccountTransactionsReport)
-> AccountTransactionsReport
forall a b. (a, b) -> b
snd ((MixedAmount, AccountTransactionsReport)
-> AccountTransactionsReport)
-> (Query -> (MixedAmount, AccountTransactionsReport))
-> Query
-> AccountTransactionsReport
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReportSpec
-> Journal -> Query -> (MixedAmount, AccountTransactionsReport)
accountTransactionsReportWithStart ReportSpec
rspec Journal
j
accountTransactionsReportWithStart :: ReportSpec -> Journal -> Query -> (MixedAmount, AccountTransactionsReport)
accountTransactionsReportWithStart :: ReportSpec
-> Journal -> Query -> (MixedAmount, AccountTransactionsReport)
accountTransactionsReportWithStart rspec :: ReportSpec
rspec@ReportSpec{_rsReportOpts :: ReportSpec -> ReportOpts
_rsReportOpts=ReportOpts
ropts} Journal
j Query
thisacctq = (MixedAmount
startbal, AccountTransactionsReport
items)
where
reportq :: Query
reportq = Query -> Query
simplifyQuery (Query -> Query) -> Query -> Query
forall a b. (a -> b) -> a -> b
$ [Query] -> Query
And [Query
aregisterq, Query
periodq]
where
aregisterq :: Query
aregisterq = (Query -> Bool) -> Query -> Query
filterQuery (Bool -> Bool
not (Bool -> Bool) -> (Query -> Bool) -> Query -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Query -> Bool
queryIsCurOrAmt) (Query -> Query) -> (Query -> Query) -> Query -> Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Query -> Bool) -> Query -> Query
filterQuery (Bool -> Bool
not (Bool -> Bool) -> (Query -> Bool) -> Query -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Query -> Bool
queryIsDepth) (Query -> Query) -> Query -> Query
forall a b. (a -> b) -> a -> b
$ ReportSpec -> Query
_rsQuery ReportSpec
rspec
periodq :: Query
periodq = DateSpan -> Query
Date (DateSpan -> Query) -> (Period -> DateSpan) -> Period -> Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Period -> DateSpan
periodAsDateSpan (Period -> Query) -> Period -> Query
forall a b. (a -> b) -> a -> b
$ ReportOpts -> Period
period_ ReportOpts
ropts
amtq :: Query
amtq = (Query -> Bool) -> Query -> Query
filterQuery Query -> Bool
queryIsCurOrAmt (Query -> Query) -> Query -> Query
forall a b. (a -> b) -> a -> b
$ ReportSpec -> Query
_rsQuery ReportSpec
rspec
queryIsCurOrAmt :: Query -> Bool
queryIsCurOrAmt Query
q = Query -> Bool
queryIsCur Query
q Bool -> Bool -> Bool
|| Query -> Bool
queryIsAmt Query
q
wd :: WhichDate
wd = ReportOpts -> WhichDate
whichDate ReportOpts
ropts
acctJournal :: Journal
acctJournal =
(if ReportOpts -> Bool
show_costs_ ReportOpts
ropts then Journal -> Journal
forall a. a -> a
id else (MixedAmount -> MixedAmount) -> Journal -> Journal
journalMapPostingAmounts MixedAmount -> MixedAmount
mixedAmountStripCosts)
(Journal -> Journal) -> (Journal -> Journal) -> Journal -> Journal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Journal -> String) -> Journal -> Journal
forall a. (a -> String) -> a -> a
dbg5With ((String
"ts3:\n"String -> String -> String
forall a. [a] -> [a] -> [a]
++)(String -> String) -> (Journal -> String) -> Journal -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.[Transaction] -> String
pshowTransactions([Transaction] -> String)
-> (Journal -> [Transaction]) -> Journal -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Journal -> [Transaction]
jtxns)
(Journal -> Journal) -> (Journal -> Journal) -> Journal -> Journal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReportSpec -> Journal -> Journal
journalApplyValuationFromOpts ReportSpec
rspec
(Journal -> Journal) -> (Journal -> Journal) -> Journal -> Journal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Journal -> String) -> Journal -> Journal
forall a. (a -> String) -> a -> a
dbg5With ((String
"ts2:\n"String -> String -> String
forall a. [a] -> [a] -> [a]
++)(String -> String) -> (Journal -> String) -> Journal -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.[Transaction] -> String
pshowTransactions([Transaction] -> String)
-> (Journal -> [Transaction]) -> Journal -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Journal -> [Transaction]
jtxns)
(Journal -> Journal) -> (Journal -> Journal) -> Journal -> Journal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (if Query -> Bool
queryIsNull Query
amtq then Journal -> Journal
forall a. a -> a
id else Query -> Journal -> Journal
filterJournalAmounts Query
amtq)
(Journal -> Journal) -> (Journal -> Journal) -> Journal -> Journal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Journal -> Journal
forall a. String -> a -> a
dbg3Msg (String
"thisacctq: "String -> String -> String
forall a. [a] -> [a] -> [a]
++Query -> String
forall a. Show a => a -> String
show Query
thisacctq)
(Journal -> Journal) -> Journal -> Journal
forall a b. (a -> b) -> a -> b
$ (Journal -> String) -> Journal -> Journal
forall a. (a -> String) -> a -> a
dbg5With ((String
"ts1:\n"String -> String -> String
forall a. [a] -> [a] -> [a]
++)(String -> String) -> (Journal -> String) -> Journal -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.[Transaction] -> String
pshowTransactions([Transaction] -> String)
-> (Journal -> [Transaction]) -> Journal -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Journal -> [Transaction]
jtxns)
Journal
j{jtxns = filter (matchesTransaction thisacctq . relevantPostings) $ jtxns j}
where
relevantPostings :: Transaction -> Transaction
relevantPostings
| Query -> Bool
queryIsNull Query
realq Bool -> Bool -> Bool
&& Query -> Bool
queryIsNull Query
statusq = Transaction -> Transaction
forall a. a -> a
id
| Bool
otherwise = Query -> Transaction -> Transaction
filterTransactionPostings (Query -> Transaction -> Transaction)
-> (Query -> Query) -> Query -> Transaction -> Transaction
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Query -> Query
simplifyQuery (Query -> Transaction -> Transaction)
-> Query -> Transaction -> Transaction
forall a b. (a -> b) -> a -> b
$ [Query] -> Query
And [Query
realq, Query
statusq]
realq :: Query
realq = (Query -> Bool) -> Query -> Query
filterQuery Query -> Bool
queryIsReal Query
reportq
statusq :: Query
statusq = (Query -> Bool) -> Query -> Query
filterQuery Query -> Bool
queryIsStatus Query
reportq
(Int
startnum, MixedAmount
startbal)
| ReportOpts -> BalanceAccumulation
balanceaccum_ ReportOpts
ropts BalanceAccumulation -> BalanceAccumulation -> Bool
forall a. Eq a => a -> a -> Bool
/= BalanceAccumulation
Historical = (Int
1, MixedAmount
nullmixedamt)
| ReportOpts -> Bool
average_ ReportOpts
ropts = (Int
numpriorts Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1, Quantity -> MixedAmount -> MixedAmount
divideMixedAmount (Int -> Quantity
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
numpriorts) MixedAmount
priorsum)
| Bool
otherwise = (Int
numpriorts Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1, MixedAmount
priorsum)
priorpss :: [[Posting]]
priorpss = String -> [[Posting]] -> [[Posting]]
forall a. Show a => String -> a -> a
dbg5 String
"priorpss" ([[Posting]] -> [[Posting]])
-> (Journal -> [[Posting]]) -> Journal -> [[Posting]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Posting] -> Bool) -> [[Posting]] -> [[Posting]]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> ([Posting] -> Bool) -> [Posting] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Posting] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null) ([[Posting]] -> [[Posting]])
-> (Journal -> [[Posting]]) -> Journal -> [[Posting]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Transaction -> [Posting]) -> [Transaction] -> [[Posting]]
forall a b. (a -> b) -> [a] -> [b]
map ((Posting -> Bool) -> [Posting] -> [Posting]
forall a. (a -> Bool) -> [a] -> [a]
filter Posting -> Bool
hasAmount ([Posting] -> [Posting])
-> (Transaction -> [Posting]) -> Transaction -> [Posting]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transaction -> [Posting]
tpostings) ([Transaction] -> [[Posting]])
-> (Journal -> [Transaction]) -> Journal -> [[Posting]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Journal -> [Transaction]
jtxns (Journal -> [[Posting]]) -> Journal -> [[Posting]]
forall a b. (a -> b) -> a -> b
$
Query -> Journal -> Journal
filterJournalPostings Query
priorq Journal
acctJournal
numpriorts :: Int
numpriorts = [[Posting]] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [[Posting]]
priorpss
priorsum :: MixedAmount
priorsum = [Posting] -> MixedAmount
sumPostings ([Posting] -> MixedAmount) -> [Posting] -> MixedAmount
forall a b. (a -> b) -> a -> b
$ [[Posting]] -> [Posting]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Posting]]
priorpss
priorq :: Query
priorq = String -> Query -> Query
forall a. Show a => String -> a -> a
dbg5 String
"priorq" (Query -> Query) -> Query -> Query
forall a b. (a -> b) -> a -> b
$ [Query] -> Query
And [Query
thisacctq, Query
tostartdateq, Query
datelessreportq]
where
tostartdateq :: Query
tostartdateq = Query -> Maybe Query -> Query
forall a. a -> Maybe a -> a
fromMaybe Query
None (Maybe Query -> Query) -> Maybe Query -> Query
forall a b. (a -> b) -> a -> b
$ [Maybe Query] -> Maybe Query
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum [Bool -> Maybe Query
cutoff (ReportOpts -> Bool
date2_ ReportOpts
ropts), Bool -> Maybe Query
cutoff (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ ReportOpts -> Bool
date2_ ReportOpts
ropts)]
cutoff :: Bool -> Maybe Query
cutoff Bool
secondary =
(if Bool
secondary then DateSpan -> Query
Date2 else DateSpan -> Query
Date) (DateSpan -> Query) -> (Day -> DateSpan) -> Day -> Query
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe EFDay -> Maybe EFDay -> DateSpan
DateSpan Maybe EFDay
forall a. Maybe a
Nothing (Maybe EFDay -> DateSpan)
-> (Day -> Maybe EFDay) -> Day -> DateSpan
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EFDay -> Maybe EFDay
forall a. a -> Maybe a
Just (EFDay -> Maybe EFDay) -> (Day -> EFDay) -> Day -> Maybe EFDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Day -> EFDay
Exact
(Day -> Query) -> Maybe Day -> Maybe Query
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> Query -> Maybe Day
queryStartDate Bool
secondary Query
reportq
datelessreportq :: Query
datelessreportq = (Query -> Bool) -> Query -> Query
filterQuery (Bool -> Bool
not (Bool -> Bool) -> (Query -> Bool) -> Query -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Query -> Bool
queryIsDateOrDate2) Query
reportq
items :: AccountTransactionsReport
items =
Query
-> Query
-> Query
-> (Int -> MixedAmount -> MixedAmount -> MixedAmount)
-> Int
-> MixedAmount
-> MixedAmount
-> (MixedAmount -> MixedAmount)
-> (CommoditySymbol -> Maybe AccountType)
-> [(Day, Transaction)]
-> AccountTransactionsReport
accountTransactionsReportItems Query
reportq (ReportSpec -> Query
_rsRowQuery ReportSpec
rspec) Query
thisacctq (ReportOpts -> Int -> MixedAmount -> MixedAmount -> MixedAmount
registerRunningCalculationFn ReportOpts
ropts) Int
startnum MixedAmount
startbal MixedAmount
priorsum MixedAmount -> MixedAmount
maNegate (Journal -> CommoditySymbol -> Maybe AccountType
journalAccountType Journal
j)
([(Day, Transaction)] -> AccountTransactionsReport)
-> ([Transaction] -> [(Day, Transaction)])
-> [Transaction]
-> AccountTransactionsReport
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([(Day, Transaction)] -> String)
-> [(Day, Transaction)] -> [(Day, Transaction)]
forall a. (a -> String) -> a -> a
dbg5With ((String
"ts4:\n"String -> String -> String
forall a. [a] -> [a] -> [a]
++)(String -> String)
-> ([(Day, Transaction)] -> String)
-> [(Day, Transaction)]
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.[Transaction] -> String
pshowTransactions([Transaction] -> String)
-> ([(Day, Transaction)] -> [Transaction])
-> [(Day, Transaction)]
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.((Day, Transaction) -> Transaction)
-> [(Day, Transaction)] -> [Transaction]
forall a b. (a -> b) -> [a] -> [b]
map (Day, Transaction) -> Transaction
forall a b. (a, b) -> b
snd)
([(Day, Transaction)] -> [(Day, Transaction)])
-> ([Transaction] -> [(Day, Transaction)])
-> [Transaction]
-> [(Day, Transaction)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Day, Transaction) -> (Day, Transaction) -> Ordering)
-> [(Day, Transaction)] -> [(Day, Transaction)]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (((Day, Transaction) -> Down Day)
-> (Day, Transaction) -> (Day, Transaction) -> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing (Day -> Down Day
forall a. a -> Down a
Down (Day -> Down Day)
-> ((Day, Transaction) -> Day) -> (Day, Transaction) -> Down Day
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Day, Transaction) -> Day
forall a b. (a, b) -> a
fst) ((Day, Transaction) -> (Day, Transaction) -> Ordering)
-> ((Day, Transaction) -> (Day, Transaction) -> Ordering)
-> (Day, Transaction)
-> (Day, Transaction)
-> Ordering
forall a. Semigroup a => a -> a -> a
<> ((Day, Transaction) -> Down Integer)
-> (Day, Transaction) -> (Day, Transaction) -> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing (Integer -> Down Integer
forall a. a -> Down a
Down (Integer -> Down Integer)
-> ((Day, Transaction) -> Integer)
-> (Day, Transaction)
-> Down Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transaction -> Integer
tindex (Transaction -> Integer)
-> ((Day, Transaction) -> Transaction)
-> (Day, Transaction)
-> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Day, Transaction) -> Transaction
forall a b. (a, b) -> b
snd))
([(Day, Transaction)] -> [(Day, Transaction)])
-> ([Transaction] -> [(Day, Transaction)])
-> [Transaction]
-> [(Day, Transaction)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Transaction -> (Day, Transaction))
-> [Transaction] -> [(Day, Transaction)]
forall a b. (a -> b) -> [a] -> [b]
map (\Transaction
t -> ((CommoditySymbol -> Maybe AccountType)
-> WhichDate -> Query -> Query -> Transaction -> Day
transactionRegisterDateExtra (Journal -> CommoditySymbol -> Maybe AccountType
journalAccountType Journal
j) WhichDate
wd Query
reportq Query
thisacctq Transaction
t, Transaction
t))
([Transaction] -> [(Day, Transaction)])
-> ([Transaction] -> [Transaction])
-> [Transaction]
-> [(Day, Transaction)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Transaction -> Transaction) -> [Transaction] -> [Transaction]
forall a b. (a -> b) -> [a] -> [b]
map (if ReportOpts -> Bool
invert_ ReportOpts
ropts then (\Transaction
t -> Transaction
t{tpostings = map postingNegateMainAmount $ tpostings t}) else Transaction -> Transaction
forall a. a -> a
id)
([Transaction] -> AccountTransactionsReport)
-> [Transaction] -> AccountTransactionsReport
forall a b. (a -> b) -> a -> b
$ Journal -> [Transaction]
jtxns Journal
acctJournal
pshowTransactions :: [Transaction] -> String
pshowTransactions :: [Transaction] -> String
pshowTransactions = [String] -> String
forall a. Show a => a -> String
pshow ([String] -> String)
-> ([Transaction] -> [String]) -> [Transaction] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Transaction -> String) -> [Transaction] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (\Transaction
t -> [String] -> String
unwords [Day -> String
forall a. Show a => a -> String
show (Day -> String) -> Day -> String
forall a b. (a -> b) -> a -> b
$ Transaction -> Day
tdate Transaction
t, CommoditySymbol -> String
T.unpack (CommoditySymbol -> String) -> CommoditySymbol -> String
forall a b. (a -> b) -> a -> b
$ Transaction -> CommoditySymbol
tdescription Transaction
t])
accountTransactionsReportItems :: Query -> Query -> Query -> (Int -> MixedAmount -> MixedAmount -> MixedAmount)
-> Int -> MixedAmount -> MixedAmount -> (MixedAmount -> MixedAmount)
-> (AccountName -> Maybe AccountType) -> [(Day, Transaction)]
-> [AccountTransactionsReportItem]
accountTransactionsReportItems :: Query
-> Query
-> Query
-> (Int -> MixedAmount -> MixedAmount -> MixedAmount)
-> Int
-> MixedAmount
-> MixedAmount
-> (MixedAmount -> MixedAmount)
-> (CommoditySymbol -> Maybe AccountType)
-> [(Day, Transaction)]
-> AccountTransactionsReport
accountTransactionsReportItems Query
reportq Query
rowq Query
thisacctq Int -> MixedAmount -> MixedAmount -> MixedAmount
runningcalc Int
i MixedAmount
bal MixedAmount
realbal MixedAmount -> MixedAmount
signfn CommoditySymbol -> Maybe AccountType
accttypefn =
[Maybe AccountTransactionsReportItem] -> AccountTransactionsReport
forall a. [Maybe a] -> [a]
catMaybes ([Maybe AccountTransactionsReportItem]
-> AccountTransactionsReport)
-> ([(Day, Transaction)] -> [Maybe AccountTransactionsReportItem])
-> [(Day, Transaction)]
-> AccountTransactionsReport
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Int, MixedAmount, MixedAmount),
[Maybe AccountTransactionsReportItem])
-> [Maybe AccountTransactionsReportItem]
forall a b. (a, b) -> b
snd (((Int, MixedAmount, MixedAmount),
[Maybe AccountTransactionsReportItem])
-> [Maybe AccountTransactionsReportItem])
-> ([(Day, Transaction)]
-> ((Int, MixedAmount, MixedAmount),
[Maybe AccountTransactionsReportItem]))
-> [(Day, Transaction)]
-> [Maybe AccountTransactionsReportItem]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Int, MixedAmount, MixedAmount)
-> (Day, Transaction)
-> ((Int, MixedAmount, MixedAmount),
Maybe AccountTransactionsReportItem))
-> (Int, MixedAmount, MixedAmount)
-> [(Day, Transaction)]
-> ((Int, MixedAmount, MixedAmount),
[Maybe AccountTransactionsReportItem])
forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumR (Query
-> Query
-> Query
-> (Int -> MixedAmount -> MixedAmount -> MixedAmount)
-> (MixedAmount -> MixedAmount)
-> (CommoditySymbol -> Maybe AccountType)
-> (Int, MixedAmount, MixedAmount)
-> (Day, Transaction)
-> ((Int, MixedAmount, MixedAmount),
Maybe AccountTransactionsReportItem)
accountTransactionsReportItem Query
reportq Query
rowq Query
thisacctq Int -> MixedAmount -> MixedAmount -> MixedAmount
runningcalc MixedAmount -> MixedAmount
signfn CommoditySymbol -> Maybe AccountType
accttypefn) (Int
i, MixedAmount
bal, MixedAmount
realbal)
accountTransactionsReportItem :: Query -> Query -> Query -> (Int -> MixedAmount -> MixedAmount -> MixedAmount)
-> (MixedAmount -> MixedAmount)
-> (AccountName -> Maybe AccountType) -> (Int, MixedAmount, MixedAmount) -> (Day, Transaction)
-> ((Int, MixedAmount, MixedAmount), Maybe AccountTransactionsReportItem)
accountTransactionsReportItem :: Query
-> Query
-> Query
-> (Int -> MixedAmount -> MixedAmount -> MixedAmount)
-> (MixedAmount -> MixedAmount)
-> (CommoditySymbol -> Maybe AccountType)
-> (Int, MixedAmount, MixedAmount)
-> (Day, Transaction)
-> ((Int, MixedAmount, MixedAmount),
Maybe AccountTransactionsReportItem)
accountTransactionsReportItem Query
reportq Query
rowq Query
thisacctq Int -> MixedAmount -> MixedAmount -> MixedAmount
runningcalc MixedAmount -> MixedAmount
signfn CommoditySymbol -> Maybe AccountType
accttypefn (Int
i, MixedAmount
bal, MixedAmount
realbal) (Day
d, Transaction
t)
| [Posting] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Posting]
reportps = ((Int
i, MixedAmount
bal, MixedAmount
realbal), Maybe AccountTransactionsReportItem
forall a. Maybe a
Nothing)
| Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Query -> MixedAmount -> MixedAmount -> Bool
matchesRowAmounts Query
rowq MixedAmount
amt MixedAmount
realbal' = ((Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1, MixedAmount
bal', MixedAmount
realbal'), Maybe AccountTransactionsReportItem
forall a. Maybe a
Nothing)
| Bool
otherwise = ((Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1, MixedAmount
bal', MixedAmount
realbal'), AccountTransactionsReportItem
-> Maybe AccountTransactionsReportItem
forall a. a -> Maybe a
Just (Transaction
t, Transaction
tacct{tdate=d}, Int
numotheraccts Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1, [CommoditySymbol]
otheraccts, MixedAmount
amt, MixedAmount
bal'))
where
tacct :: Transaction
tacct@Transaction{tpostings :: Transaction -> [Posting]
tpostings=[Posting]
reportps} = (CommoditySymbol -> Maybe AccountType)
-> Query -> Transaction -> Transaction
filterTransactionPostingsExtra CommoditySymbol -> Maybe AccountType
accttypefn Query
reportq Transaction
t
([Posting]
thisacctps, [Posting]
otheracctps) = (Posting -> Bool) -> [Posting] -> ([Posting], [Posting])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (Query -> Posting -> Bool
matchesPosting Query
thisacctq) [Posting]
reportps
numotheraccts :: Int
numotheraccts = [CommoditySymbol] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length ([CommoditySymbol] -> Int) -> [CommoditySymbol] -> Int
forall a b. (a -> b) -> a -> b
$ [CommoditySymbol] -> [CommoditySymbol]
forall a. Eq a => [a] -> [a]
nub ([CommoditySymbol] -> [CommoditySymbol])
-> [CommoditySymbol] -> [CommoditySymbol]
forall a b. (a -> b) -> a -> b
$ (Posting -> CommoditySymbol) -> [Posting] -> [CommoditySymbol]
forall a b. (a -> b) -> [a] -> [b]
map Posting -> CommoditySymbol
paccount [Posting]
otheracctps
otheraccts :: [CommoditySymbol]
otheraccts | Query
thisacctq Query -> Query -> Bool
forall a. Eq a => a -> a -> Bool
== Query
None = [Posting] -> [CommoditySymbol]
summarisePostingAccounts [Posting]
reportps
| Int
numotheraccts Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = [Posting] -> [CommoditySymbol]
summarisePostingAccounts [Posting]
thisacctps
| Bool
otherwise = [Posting] -> [CommoditySymbol]
summarisePostingAccounts [Posting]
otheracctps
amt :: MixedAmount
amt
| [Posting] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Posting]
thisacctps = MixedAmount -> MixedAmount
signfn (MixedAmount -> MixedAmount) -> MixedAmount -> MixedAmount
forall a b. (a -> b) -> a -> b
$ [Posting] -> MixedAmount
sumPostings [Posting]
otheracctps
| Bool
otherwise = MixedAmount -> MixedAmount
signfn (MixedAmount -> MixedAmount)
-> (MixedAmount -> MixedAmount) -> MixedAmount -> MixedAmount
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MixedAmount -> MixedAmount
maNegate (MixedAmount -> MixedAmount) -> MixedAmount -> MixedAmount
forall a b. (a -> b) -> a -> b
$ [Posting] -> MixedAmount
sumPostings [Posting]
thisacctps
bal' :: MixedAmount
bal' = Int -> MixedAmount -> MixedAmount -> MixedAmount
runningcalc Int
i MixedAmount
bal MixedAmount
amt
realbal' :: MixedAmount
realbal' = if Query -> Bool
queryHasBalance Query
rowq then MixedAmount -> MixedAmount -> MixedAmount
maPlus MixedAmount
realbal MixedAmount
amt else MixedAmount
nullmixedamt
transactionRegisterDate :: WhichDate -> Query -> Query -> Transaction -> Day
transactionRegisterDate :: WhichDate -> Query -> Query -> Transaction -> Day
transactionRegisterDate = (CommoditySymbol -> Maybe AccountType)
-> WhichDate -> Query -> Query -> Transaction -> Day
transactionRegisterDateExtra (Maybe AccountType -> CommoditySymbol -> Maybe AccountType
forall a b. a -> b -> a
const Maybe AccountType
forall a. Maybe a
Nothing)
transactionRegisterDateExtra :: (AccountName -> Maybe AccountType) -> WhichDate -> Query -> Query -> Transaction -> Day
CommoditySymbol -> Maybe AccountType
accttypefn WhichDate
wd Query
reportq Query
thisacctq Transaction
t
| Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [Posting] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Posting]
thisacctps = [Day] -> Day
forall a. Ord a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum ([Day] -> Day) -> [Day] -> Day
forall a b. (a -> b) -> a -> b
$ (Posting -> Day) -> [Posting] -> [Day]
forall a b. (a -> b) -> [a] -> [b]
map (WhichDate -> Posting -> Day
postingDateOrDate2 WhichDate
wd) [Posting]
thisacctps
| Bool
otherwise = WhichDate -> Transaction -> Day
transactionDateOrDate2 WhichDate
wd Transaction
t
where
reportps :: [Posting]
reportps = Transaction -> [Posting]
tpostings (Transaction -> [Posting]) -> Transaction -> [Posting]
forall a b. (a -> b) -> a -> b
$ (CommoditySymbol -> Maybe AccountType)
-> Query -> Transaction -> Transaction
filterTransactionPostingsExtra CommoditySymbol -> Maybe AccountType
accttypefn Query
reportq Transaction
t
thisacctps :: [Posting]
thisacctps = (Posting -> Bool) -> [Posting] -> [Posting]
forall a. (a -> Bool) -> [a] -> [a]
filter (Query -> Posting -> Bool
matchesPosting Query
thisacctq) [Posting]
reportps
summarisePostingAccounts :: [Posting] -> [AccountName]
summarisePostingAccounts :: [Posting] -> [CommoditySymbol]
summarisePostingAccounts [Posting]
ps = (Posting -> CommoditySymbol) -> [Posting] -> [CommoditySymbol]
forall a b. (a -> b) -> [a] -> [b]
map Posting -> CommoditySymbol
paccount [Posting]
displayps
where
realps :: [Posting]
realps = (Posting -> Bool) -> [Posting] -> [Posting]
forall a. (a -> Bool) -> [a] -> [a]
filter Posting -> Bool
isReal [Posting]
ps
displayps :: [Posting]
displayps | [Posting] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Posting]
realps = [Posting]
ps
| Bool
otherwise = [Posting]
realps
accountTransactionsReportByCommodity :: AccountTransactionsReport -> [(CommoditySymbol, AccountTransactionsReport)]
accountTransactionsReportByCommodity :: AccountTransactionsReport
-> [(CommoditySymbol, AccountTransactionsReport)]
accountTransactionsReportByCommodity AccountTransactionsReport
tr =
[(CommoditySymbol
c, CommoditySymbol
-> AccountTransactionsReport -> AccountTransactionsReport
filterAccountTransactionsReportByCommodity CommoditySymbol
c AccountTransactionsReport
tr) | CommoditySymbol
c <- AccountTransactionsReport -> [CommoditySymbol]
forall {a} {b} {c} {d} {f}.
[(a, b, c, d, MixedAmount, f)] -> [CommoditySymbol]
commodities AccountTransactionsReport
tr]
where
commodities :: [(a, b, c, d, MixedAmount, f)] -> [CommoditySymbol]
commodities = [CommoditySymbol] -> [CommoditySymbol]
forall a. Ord a => [a] -> [a]
nubSort ([CommoditySymbol] -> [CommoditySymbol])
-> ([(a, b, c, d, MixedAmount, f)] -> [CommoditySymbol])
-> [(a, b, c, d, MixedAmount, f)]
-> [CommoditySymbol]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Amount -> CommoditySymbol) -> [Amount] -> [CommoditySymbol]
forall a b. (a -> b) -> [a] -> [b]
map Amount -> CommoditySymbol
acommodity ([Amount] -> [CommoditySymbol])
-> ([(a, b, c, d, MixedAmount, f)] -> [Amount])
-> [(a, b, c, d, MixedAmount, f)]
-> [CommoditySymbol]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a, b, c, d, MixedAmount, f) -> [Amount])
-> [(a, b, c, d, MixedAmount, f)] -> [Amount]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (MixedAmount -> [Amount]
amounts (MixedAmount -> [Amount])
-> ((a, b, c, d, MixedAmount, f) -> MixedAmount)
-> (a, b, c, d, MixedAmount, f)
-> [Amount]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, b, c, d, MixedAmount, f) -> MixedAmount
forall {a} {b} {c} {d} {e} {f}. (a, b, c, d, e, f) -> e
triAmount)
filterAccountTransactionsReportByCommodity :: CommoditySymbol -> AccountTransactionsReport -> AccountTransactionsReport
filterAccountTransactionsReportByCommodity :: CommoditySymbol
-> AccountTransactionsReport -> AccountTransactionsReport
filterAccountTransactionsReportByCommodity CommoditySymbol
comm =
AccountTransactionsReport -> AccountTransactionsReport
forall {a} {b} {c} {d}.
[(a, b, c, d, MixedAmount, MixedAmount)]
-> [(a, b, c, d, MixedAmount, MixedAmount)]
fixTransactionsReportItemBalances (AccountTransactionsReport -> AccountTransactionsReport)
-> (AccountTransactionsReport -> AccountTransactionsReport)
-> AccountTransactionsReport
-> AccountTransactionsReport
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AccountTransactionsReportItem -> AccountTransactionsReport)
-> AccountTransactionsReport -> AccountTransactionsReport
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (CommoditySymbol
-> AccountTransactionsReportItem -> AccountTransactionsReport
forall {a} {b} {c} {d} {f}.
CommoditySymbol
-> (a, b, c, d, MixedAmount, f) -> [(a, b, c, d, MixedAmount, f)]
filterTransactionsReportItemByCommodity CommoditySymbol
comm)
where
filterTransactionsReportItemByCommodity :: CommoditySymbol
-> (a, b, c, d, MixedAmount, f) -> [(a, b, c, d, MixedAmount, f)]
filterTransactionsReportItemByCommodity CommoditySymbol
c (a
t,b
t2,c
s,d
o,MixedAmount
a,f
bal)
| CommoditySymbol
c CommoditySymbol -> [CommoditySymbol] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [CommoditySymbol]
cs = [(a, b, c, d, MixedAmount, f)
item']
| Bool
otherwise = []
where
cs :: [CommoditySymbol]
cs = (Amount -> CommoditySymbol) -> [Amount] -> [CommoditySymbol]
forall a b. (a -> b) -> [a] -> [b]
map Amount -> CommoditySymbol
acommodity ([Amount] -> [CommoditySymbol]) -> [Amount] -> [CommoditySymbol]
forall a b. (a -> b) -> a -> b
$ MixedAmount -> [Amount]
amounts MixedAmount
a
item' :: (a, b, c, d, MixedAmount, f)
item' = (a
t,b
t2,c
s,d
o,MixedAmount
a',f
bal)
a' :: MixedAmount
a' = CommoditySymbol -> MixedAmount -> MixedAmount
filterMixedAmountByCommodity CommoditySymbol
c MixedAmount
a
fixTransactionsReportItemBalances :: [(a, b, c, d, MixedAmount, MixedAmount)]
-> [(a, b, c, d, MixedAmount, MixedAmount)]
fixTransactionsReportItemBalances [] = []
fixTransactionsReportItemBalances [(a, b, c, d, MixedAmount, MixedAmount)
i] = [(a, b, c, d, MixedAmount, MixedAmount)
i]
fixTransactionsReportItemBalances [(a, b, c, d, MixedAmount, MixedAmount)]
items = [(a, b, c, d, MixedAmount, MixedAmount)]
-> [(a, b, c, d, MixedAmount, MixedAmount)]
forall a. [a] -> [a]
reverse ([(a, b, c, d, MixedAmount, MixedAmount)]
-> [(a, b, c, d, MixedAmount, MixedAmount)])
-> [(a, b, c, d, MixedAmount, MixedAmount)]
-> [(a, b, c, d, MixedAmount, MixedAmount)]
forall a b. (a -> b) -> a -> b
$ (a, b, c, d, MixedAmount, MixedAmount)
i(a, b, c, d, MixedAmount, MixedAmount)
-> [(a, b, c, d, MixedAmount, MixedAmount)]
-> [(a, b, c, d, MixedAmount, MixedAmount)]
forall a. a -> [a] -> [a]
:(MixedAmount
-> [(a, b, c, d, MixedAmount, MixedAmount)]
-> [(a, b, c, d, MixedAmount, MixedAmount)]
forall {a} {b} {c} {d} {f}.
MixedAmount
-> [(a, b, c, d, MixedAmount, f)]
-> [(a, b, c, d, MixedAmount, MixedAmount)]
go MixedAmount
startbal [(a, b, c, d, MixedAmount, MixedAmount)]
is)
where
(a, b, c, d, MixedAmount, MixedAmount)
i:[(a, b, c, d, MixedAmount, MixedAmount)]
is = [(a, b, c, d, MixedAmount, MixedAmount)]
-> [(a, b, c, d, MixedAmount, MixedAmount)]
forall a. [a] -> [a]
reverse [(a, b, c, d, MixedAmount, MixedAmount)]
items
startbal :: MixedAmount
startbal = CommoditySymbol -> MixedAmount -> MixedAmount
filterMixedAmountByCommodity CommoditySymbol
comm (MixedAmount -> MixedAmount) -> MixedAmount -> MixedAmount
forall a b. (a -> b) -> a -> b
$ (a, b, c, d, MixedAmount, MixedAmount) -> MixedAmount
forall {a} {b} {c} {d} {e} {f}. (a, b, c, d, e, f) -> f
triBalance (a, b, c, d, MixedAmount, MixedAmount)
i
go :: MixedAmount
-> [(a, b, c, d, MixedAmount, f)]
-> [(a, b, c, d, MixedAmount, MixedAmount)]
go MixedAmount
_ [] = []
go MixedAmount
bal ((a
t,b
t2,c
s,d
o,MixedAmount
amt,f
_):[(a, b, c, d, MixedAmount, f)]
is') = (a
t,b
t2,c
s,d
o,MixedAmount
amt,MixedAmount
bal')(a, b, c, d, MixedAmount, MixedAmount)
-> [(a, b, c, d, MixedAmount, MixedAmount)]
-> [(a, b, c, d, MixedAmount, MixedAmount)]
forall a. a -> [a] -> [a]
:MixedAmount
-> [(a, b, c, d, MixedAmount, f)]
-> [(a, b, c, d, MixedAmount, MixedAmount)]
go MixedAmount
bal' [(a, b, c, d, MixedAmount, f)]
is'
where bal' :: MixedAmount
bal' = MixedAmount
bal MixedAmount -> MixedAmount -> MixedAmount
`maPlus` MixedAmount
amt
tests_AccountTransactionsReport :: TestTree
tests_AccountTransactionsReport = String -> [TestTree] -> TestTree
testGroup String
"AccountTransactionsReport" [
String -> Assertion -> TestTree
testCase String
"accountTransactionsReportWithStart" (Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ do
let checking :: Query
checking = Regexp -> Query
Acct (Regexp -> Query) -> Regexp -> Query
forall a b. (a -> b) -> a -> b
$ CommoditySymbol -> Regexp
toRegex' CommoditySymbol
"assets:bank:checking"
fromJune :: Query
fromJune = DateSpan -> Query
Date (DateSpan -> Query) -> DateSpan -> Query
forall a b. (a -> b) -> a -> b
$ Maybe EFDay -> Maybe EFDay -> DateSpan
DateSpan (EFDay -> Maybe EFDay
forall a. a -> Maybe a
Just (EFDay -> Maybe EFDay) -> EFDay -> Maybe EFDay
forall a b. (a -> b) -> a -> b
$ Day -> EFDay
Exact (Day -> EFDay) -> Day -> EFDay
forall a b. (a -> b) -> a -> b
$ Integer -> Int -> Int -> Day
fromGregorian Integer
2008 Int
6 Int
1) Maybe EFDay
forall a. Maybe a
Nothing
rspec :: BalanceAccumulation -> ReportSpec
rspec BalanceAccumulation
accum = ReportSpec
defreportspec{_rsQuery=fromJune, _rsReportOpts=defreportopts{balanceaccum_=accum}}
(MixedAmount
histstart, AccountTransactionsReport
histitems) = ReportSpec
-> Journal -> Query -> (MixedAmount, AccountTransactionsReport)
accountTransactionsReportWithStart (BalanceAccumulation -> ReportSpec
rspec BalanceAccumulation
Historical) Journal
samplejournal Query
checking
(MixedAmount
start, AccountTransactionsReport
items) = ReportSpec
-> Journal -> Query -> (MixedAmount, AccountTransactionsReport)
accountTransactionsReportWithStart (BalanceAccumulation -> ReportSpec
rspec BalanceAccumulation
PerPeriod) Journal
samplejournal Query
checking
MixedAmount -> String
showMixedAmount MixedAmount
histstart String -> String -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= String
"$1.00"
(AccountTransactionsReportItem -> String)
-> AccountTransactionsReport -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (MixedAmount -> String
showMixedAmount (MixedAmount -> String)
-> (AccountTransactionsReportItem -> MixedAmount)
-> AccountTransactionsReportItem
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AccountTransactionsReportItem -> MixedAmount
forall {a} {b} {c} {d} {e} {f}. (a, b, c, d, e, f) -> f
triBalance) AccountTransactionsReport
histitems [String] -> [String] -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= [String
"$1.00", String
"$2.00", String
"$1.00", String
"$2.00"]
MixedAmount -> String
showMixedAmount MixedAmount
start String -> String -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= String
"0"
(AccountTransactionsReportItem -> String)
-> AccountTransactionsReport -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (MixedAmount -> String
showMixedAmount (MixedAmount -> String)
-> (AccountTransactionsReportItem -> MixedAmount)
-> AccountTransactionsReportItem
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AccountTransactionsReportItem -> MixedAmount
forall {a} {b} {c} {d} {e} {f}. (a, b, c, d, e, f) -> f
triBalance) AccountTransactionsReport
items [String] -> [String] -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= [String
"0", String
"$1.00", String
"0", String
"$1.00"]
let fromJune2 :: Query
fromJune2 = DateSpan -> Query
Date2 (DateSpan -> Query) -> DateSpan -> Query
forall a b. (a -> b) -> a -> b
$ Maybe EFDay -> Maybe EFDay -> DateSpan
DateSpan (EFDay -> Maybe EFDay
forall a. a -> Maybe a
Just (EFDay -> Maybe EFDay) -> EFDay -> Maybe EFDay
forall a b. (a -> b) -> a -> b
$ Day -> EFDay
Exact (Day -> EFDay) -> Day -> EFDay
forall a b. (a -> b) -> a -> b
$ Integer -> Int -> Int -> Day
fromGregorian Integer
2008 Int
6 Int
1) Maybe EFDay
forall a. Maybe a
Nothing
(MixedAmount
histstart2, AccountTransactionsReport
_) = ReportSpec
-> Journal -> Query -> (MixedAmount, AccountTransactionsReport)
accountTransactionsReportWithStart (BalanceAccumulation -> ReportSpec
rspec BalanceAccumulation
Historical){_rsQuery=fromJune2} Journal
samplejournal Query
checking
MixedAmount -> String
showMixedAmount MixedAmount
histstart2 String -> String -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= String
"$1.00"
,String -> Assertion -> TestTree
testCase String
"transactionRegisterDateExtra" (Assertion -> TestTree) -> Assertion -> TestTree
forall a b. (a -> b) -> a -> b
$ do
let t :: Transaction
t = Transaction
nulltransaction{tdate=fromGregorian 2008 1 1, tpostings=[
("assets:bank:checking" `post` usd 1){pdate=Just $ fromGregorian 2008 1 5}
,"income:salary" `post` usd (-1)]}
checking :: Query
checking = Regexp -> Query
Acct (Regexp -> Query) -> Regexp -> Query
forall a b. (a -> b) -> a -> b
$ CommoditySymbol -> Regexp
toRegex' CommoditySymbol
"assets:bank:checking"
assettypes :: CommoditySymbol -> Maybe AccountType
assettypes CommoditySymbol
a = if CommoditySymbol
"assets" CommoditySymbol -> CommoditySymbol -> Bool
`T.isPrefixOf` CommoditySymbol
a then AccountType -> Maybe AccountType
forall a. a -> Maybe a
Just AccountType
Asset else Maybe AccountType
forall a. Maybe a
Nothing
WhichDate -> Query -> Query -> Transaction -> Day
transactionRegisterDate WhichDate
PrimaryDate ([AccountType] -> Query
Type [AccountType
Asset]) Query
checking Transaction
t Day -> Day -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Integer -> Int -> Int -> Day
fromGregorian Integer
2008 Int
1 Int
1
(CommoditySymbol -> Maybe AccountType)
-> WhichDate -> Query -> Query -> Transaction -> Day
transactionRegisterDateExtra CommoditySymbol -> Maybe AccountType
assettypes WhichDate
PrimaryDate ([AccountType] -> Query
Type [AccountType
Asset]) Query
checking Transaction
t Day -> Day -> Assertion
forall a. (Eq a, Show a, HasCallStack) => a -> a -> Assertion
@?= Integer -> Int -> Int -> Day
fromGregorian Integer
2008 Int
1 Int
5
]