mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-10 05:39:31 +03:00
web: make register item display a bit more consistent
This commit is contained in:
parent
c572addaa0
commit
918b3b45a5
@ -1,8 +1,8 @@
|
||||
<tr.item.#{evenodd}.#{firstposting}.#{datetransition}
|
||||
<td.date>#{date}
|
||||
<td.description title="#{show t}">#{elideRight 30 desc}
|
||||
<td.account>
|
||||
$if split
|
||||
<td.account title="#{show t}>
|
||||
$if True
|
||||
<a title="#{acct}"
|
||||
#{elideRight 40 acct}
|
||||
|
||||
@ -14,8 +14,8 @@
|
||||
$if showamt
|
||||
#{mixedAmountAsHtml amt}
|
||||
<td.balance align=right>#{mixedAmountAsHtml bal}
|
||||
$if split
|
||||
$forall p <- tpostings t'
|
||||
$if True
|
||||
$forall p <- tpostings t
|
||||
<tr.item.#{evenodd}.posting.#{displayclass}
|
||||
<td.date
|
||||
<td.description
|
||||
|
@ -183,7 +183,7 @@ journalRegisterReport :: [Opt] -> Journal -> Matcher -> AccountRegisterReport
|
||||
journalRegisterReport _ Journal{jtxns=ts} m = (totallabel, items)
|
||||
where
|
||||
ts' = sortBy (comparing tdate) $ filter (not . null . tpostings) $ map (filterTransactionPostings m) ts
|
||||
items = reverse $ accountRegisterReportItems m MatchNone nullmixedamt (+) ts'
|
||||
items = reverse $ accountRegisterReportItems m MatchNone nullmixedamt id (+) ts'
|
||||
|
||||
-- | Get a conventional account register report, with the specified
|
||||
-- options, for the currently focussed account (or possibly the focussed
|
||||
@ -209,9 +209,9 @@ accountRegisterReport opts j m thisacctmatcher = (label, items)
|
||||
ts = sortBy (comparing tdate) $ filter (matchesTransaction thisacctmatcher) $ jtxns j
|
||||
-- starting balance: if we are filtering by a start date and nothing else,
|
||||
-- the sum of postings to this account before that date; otherwise zero.
|
||||
(startbal,label, sumfn) | matcherIsNull m = (nullmixedamt, balancelabel, (-))
|
||||
| matcherIsStartDateOnly effective m = (sumPostings priorps, balancelabel, (-))
|
||||
| otherwise = (nullmixedamt, totallabel, (+))
|
||||
(startbal,label, sumfn) | matcherIsNull m = (nullmixedamt, balancelabel, (+))
|
||||
| matcherIsStartDateOnly effective m = (sumPostings priorps, balancelabel, (+))
|
||||
| otherwise = (nullmixedamt, totallabel, (-))
|
||||
where
|
||||
priorps = -- ltrace "priorps" $
|
||||
filter (matchesPosting
|
||||
@ -221,14 +221,14 @@ accountRegisterReport opts j m thisacctmatcher = (label, items)
|
||||
tostartdatematcher = MatchDate True (DateSpan Nothing startdate)
|
||||
startdate = matcherStartDate effective m
|
||||
effective = Effective `elem` opts
|
||||
items = reverse $ accountRegisterReportItems m thisacctmatcher startbal sumfn ts
|
||||
items = reverse $ accountRegisterReportItems m thisacctmatcher startbal negate sumfn ts
|
||||
|
||||
-- | Generate account register line items from a list of transactions,
|
||||
-- using the provided query and "this account" matchers, starting balance,
|
||||
-- and balance summing function.
|
||||
accountRegisterReportItems :: Matcher -> Matcher -> MixedAmount -> (MixedAmount -> MixedAmount -> MixedAmount) -> [Transaction] -> [AccountRegisterReportItem]
|
||||
accountRegisterReportItems _ _ _ _ [] = []
|
||||
accountRegisterReportItems matcher thisacctmatcher bal sumfn (t:ts) =
|
||||
-- sign-setting function and balance-summing function.
|
||||
accountRegisterReportItems :: Matcher -> Matcher -> MixedAmount -> (MixedAmount -> MixedAmount) -> (MixedAmount -> MixedAmount -> MixedAmount) -> [Transaction] -> [AccountRegisterReportItem]
|
||||
accountRegisterReportItems _ _ _ _ _ [] = []
|
||||
accountRegisterReportItems matcher thisacctmatcher bal signfn sumfn (t:ts) =
|
||||
case i of Just i' -> i':is
|
||||
Nothing -> is
|
||||
where
|
||||
@ -237,26 +237,29 @@ accountRegisterReportItems matcher thisacctmatcher bal sumfn (t:ts) =
|
||||
displaymatcher | numthisacctsposted > 1 = matcher
|
||||
| otherwise = MatchAnd [negateMatcher thisacctmatcher, matcher]
|
||||
t'@Transaction{tpostings=ps'} = filterTransactionPostings displaymatcher t
|
||||
acct = summarisePostings $ tpostings t
|
||||
(i,bal'') = case ps' of
|
||||
[] -> (Nothing,bal) -- maybe a virtual transaction, or transfer to self
|
||||
[p] -> (Just (t, t', False, acct, amt, bal'), bal')
|
||||
where
|
||||
acct = paccount p
|
||||
amt = pamount p
|
||||
amt = signfn $ pamount p
|
||||
bal' = bal `sumfn` amt
|
||||
ps' -> (Just (t, t', True, acct, amt, bal'), bal')
|
||||
ps'' -> (Just (t, t', True, acct, amt, bal'), bal')
|
||||
where
|
||||
-- describe split as from ..., to ... (not always right)
|
||||
acct = case (simplify tos, simplify froms) of
|
||||
([],ts) -> "to "++commafy ts
|
||||
(fs,[]) -> "from "++commafy fs
|
||||
(fs,ts) -> "to "++commafy ts++" from "++commafy fs
|
||||
where (tos,froms) = partition (fromMaybe False . isNegativeMixedAmount . pamount) ps'
|
||||
simplify = nub . map (accountLeafName . paccount)
|
||||
commafy = intercalate ", "
|
||||
amt = sum $ map pamount ps'
|
||||
amt = signfn $ sum $ map pamount ps''
|
||||
bal' = bal `sumfn` amt
|
||||
is = accountRegisterReportItems matcher thisacctmatcher bal'' sumfn ts
|
||||
is = accountRegisterReportItems matcher thisacctmatcher bal'' signfn sumfn ts
|
||||
|
||||
-- | Generate a short readable summary of a transaction's postings.
|
||||
summarisePostings ps =
|
||||
case (simplify tos, simplify froms) of
|
||||
([],ts) -> "to "++commafy ts
|
||||
(fs,[]) -> "from "++commafy fs
|
||||
(fs,ts) -> "from "++commafy fs++" to "++commafy ts
|
||||
where
|
||||
(tos,froms) = partition (fromMaybe False . isNegativeMixedAmount . pamount) ps
|
||||
simplify = nub . map (accountLeafName . paccount)
|
||||
commafy = intercalate ", "
|
||||
|
||||
filterTransactionPostings :: Matcher -> Transaction -> Transaction
|
||||
filterTransactionPostings m t@Transaction{tpostings=ps} = t{tpostings=filter (m `matchesPosting`) ps}
|
||||
|
Loading…
Reference in New Issue
Block a user