diff --git a/Commands/Balance.hs b/Commands/Balance.hs index e9fac2f9e..f0789d172 100644 --- a/Commands/Balance.hs +++ b/Commands/Balance.hs @@ -1,6 +1,6 @@ -{-| +{-| -A ledger-compatible @balance@ command. +A ledger-compatible @balance@ command. ledger's balance command is easy to use but not easy to describe precisely. In the examples below we'll use sample.ledger, which has the @@ -114,7 +114,7 @@ balance opts args = putStr . showBalanceReport opts args -- | Generate a balance report with the specified options for this ledger. showBalanceReport :: [Opt] -> [String] -> Ledger -> String showBalanceReport opts _ l = acctsstr ++ totalstr - where + where acctsstr = unlines $ map showacct interestingaccts where showacct = showInterestingAccount l interestingaccts diff --git a/Commands/Stats.hs b/Commands/Stats.hs index 03d8d71ab..5aff00a0c 100644 --- a/Commands/Stats.hs +++ b/Commands/Stats.hs @@ -1,4 +1,4 @@ -{-| +{-| Print some statistics for the ledger. @@ -19,7 +19,7 @@ stats opts args l = do putStr $ showStats opts args l today showStats :: [Opt] -> [String] -> Ledger -> Day -> String -showStats _ _ l today = +showStats _ _ l today = heading ++ unlines (map (\(a,b) -> printf fmt a b) stats) where heading = underline $ printf "Ledger statistics as of %s" (show today) @@ -42,7 +42,7 @@ showStats _ _ l today = -- Days since reconciliation : %(reconcileelapsed)s -- Days since last transaction : %(recentelapsed)s ] - where + where ts = sortBy (comparing ltdate) $ ledger_txns $ rawledger l lastdate | null ts = Nothing | otherwise = Just $ ltdate $ last ts diff --git a/Ledger/RawLedger.hs b/Ledger/RawLedger.hs index 6781d592e..e458346e4 100644 --- a/Ledger/RawLedger.hs +++ b/Ledger/RawLedger.hs @@ -71,7 +71,7 @@ rawLedgerAccountNameTree = accountNameTreeFrom . rawLedgerAccountNames -- Keep only those which fall between the begin and end dates, and match -- the description pattern, and are cleared or real if those options are active. filterRawLedger :: DateSpan -> [String] -> Maybe Bool -> Bool -> RawLedger -> RawLedger -filterRawLedger span pats clearedonly realonly = +filterRawLedger span pats clearedonly realonly = filterRawLedgerPostingsByRealness realonly . filterRawLedgerTransactionsByClearedStatus clearedonly . filterRawLedgerTransactionsByDate span . @@ -79,17 +79,17 @@ filterRawLedger span pats clearedonly realonly = -- | Keep only ledger transactions whose description matches the description patterns. filterRawLedgerTransactionsByDescription :: [String] -> RawLedger -> RawLedger -filterRawLedgerTransactionsByDescription pats (RawLedger ms ps ts tls hs f fp) = +filterRawLedgerTransactionsByDescription pats (RawLedger ms ps ts tls hs f fp) = RawLedger ms ps (filter matchdesc ts) tls hs f fp where matchdesc = matchpats pats . ltdescription --- | Keep only ledger transactions which fall between begin and end dates. +-- | Keep only ledger transactions which fall between begin and end dates. -- We include transactions on the begin date and exclude transactions on the end -- date, like ledger. An empty date string means no restriction. filterRawLedgerTransactionsByDate :: DateSpan -> RawLedger -> RawLedger -filterRawLedgerTransactionsByDate (DateSpan begin end) (RawLedger ms ps ts tls hs f fp) = +filterRawLedgerTransactionsByDate (DateSpan begin end) (RawLedger ms ps ts tls hs f fp) = RawLedger ms ps (filter matchdate ts) tls hs f fp - where + where matchdate t = maybe True (ltdate t>=) begin && maybe True (ltdate t<) end -- | Keep only ledger transactions which have the requested @@ -112,7 +112,7 @@ filterRawLedgerPostingsByRealness True (RawLedger mts pts ts tls hs f fp) = filterRawLedgerPostingsByDepth :: Int -> RawLedger -> RawLedger filterRawLedgerPostingsByDepth depth (RawLedger mts pts ts tls hs f fp) = RawLedger mts pts (filter (not . null . ltpostings) $ map filtertxns ts) tls hs f fp - where filtertxns t@LedgerTransaction{ltpostings=ps} = + where filtertxns t@LedgerTransaction{ltpostings=ps} = t{ltpostings=filter ((<= depth) . accountNameLevel . paccount) ps} -- | Keep only ledger transactions which affect accounts matched by the account patterns. @@ -124,7 +124,7 @@ filterRawLedgerTransactionsByAccount apats (RawLedger ms ps ts tls hs f fp) = -- actual or effective date. rawLedgerSelectingDate :: WhichDate -> RawLedger -> RawLedger rawLedgerSelectingDate ActualDate rl = rl -rawLedgerSelectingDate EffectiveDate rl = +rawLedgerSelectingDate EffectiveDate rl = rl{ledger_txns=map (ledgerTransactionWithDate EffectiveDate) $ ledger_txns rl} -- | Give all a ledger's amounts their canonical display settings. That @@ -134,13 +134,13 @@ rawLedgerSelectingDate EffectiveDate rl = -- active. canonicaliseAmounts :: Bool -> RawLedger -> RawLedger canonicaliseAmounts costbasis l@(RawLedger ms ps ts tls hs f fp) = RawLedger ms ps (map fixledgertransaction ts) tls hs f fp - where + where fixledgertransaction (LedgerTransaction d ed s c de co ts pr) = LedgerTransaction d ed s c de co (map fixrawposting ts) pr fixrawposting (Posting s ac a c t) = Posting s ac (fixmixedamount a) c t fixmixedamount (Mixed as) = Mixed $ map fixamount as fixamount = fixcommodity . (if costbasis then costOfAmount else id) fixcommodity a = a{commodity=c} where c = canonicalcommoditymap ! symbol (commodity a) - canonicalcommoditymap = + canonicalcommoditymap = Map.fromList [(s,firstc{precision=maxp}) | s <- commoditysymbols, let cs = commoditymap ! s, let firstc = head cs, diff --git a/hledger.hs b/hledger.hs index 0bc2fe635..f08710edb 100644 --- a/hledger.hs +++ b/hledger.hs @@ -50,7 +50,7 @@ main :: IO () main = do (opts, cmd, args) <- parseArguments run cmd opts args - where + where run cmd opts args | Help `elem` opts = putStr usage | Version `elem` opts = putStrLn versionmsg