;bin: register-max: show multiple postings, better layou
This commit is contained in:
parent
7f8f98707d
commit
173985dbfc
@ -1,17 +1,17 @@
|
|||||||
#!/usr/bin/env stack
|
#!/usr/bin/env stack
|
||||||
-- stack script --compile --resolver lts-20.8 --verbosity error --package hledger-lib --package hledger --package text
|
-- stack script --compile --resolver lts-20.8 --verbosity error --package hledger-lib --package hledger --package text --package safe
|
||||||
|
|
||||||
-- hledger-register-max - runs "hledger register" and prints the posting with largest running total/balance.
|
-- hledger-register-max - runs "hledger register" and prints the posting with largest running total/balance.
|
||||||
-- Usage:
|
-- Usage:
|
||||||
-- hledger-register-max [REGISTERARGS]
|
-- hledger-register-max [REGISTERARGS]
|
||||||
-- hledger register-max -- [REGISTERARGS]
|
-- hledger register-max -- [REGISTERARGS]
|
||||||
-- For historical balances, add -H. For negative balances, add --invert.
|
-- For historical balances, add -H. For negative balances, add --invert. For value, add -V --infer-market-prices, etc.
|
||||||
|
|
||||||
-- Examples:
|
-- Examples:
|
||||||
-- $ hledger-register-max -f examples/bcexample.hledger -H checking
|
-- $ hledger-register-max -f examples/bcexample.hledger -H checking
|
||||||
-- 2013-01-03 Hoogle | Payroll Assets:US:BofA:Checking 1350.60 USD 8799.22 USD
|
-- 2013-01-03 Hoogle | Payroll Assets:US:BofA:Checking 1350.60 USD 8799.22 USD
|
||||||
-- $ hledger register-max -- -f examples/bcexample.hledger -H checking
|
-- $ hledger register-max -- -f examples/bcexample.hledger income --invert
|
||||||
-- 2013-01-03 Hoogle | Payroll Assets:US:BofA:Checking 1350.60 USD 8799.22 USD
|
-- 2014-10-09 Hoogle | Payroll Income:US:Hoogle:Vacation 4.62 VACHR 52000.00 IRAUSD, 365071.44 USD, 337.26 VACHR
|
||||||
|
|
||||||
|
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
@ -23,24 +23,33 @@ import Data.Maybe
|
|||||||
import Data.Ord
|
import Data.Ord
|
||||||
import qualified "text" Data.Text as T
|
import qualified "text" Data.Text as T
|
||||||
import qualified Data.Text.IO as T
|
import qualified Data.Text.IO as T
|
||||||
|
import Safe
|
||||||
import System.Environment
|
import System.Environment
|
||||||
import Hledger
|
import Hledger
|
||||||
import Hledger.Cli
|
import Hledger.Cli
|
||||||
import Hledger.Cli.Main (argsToCliOpts)
|
import Hledger.Cli.Main (argsToCliOpts)
|
||||||
|
|
||||||
-- XXX needs --help, see hledger-addon-example.hs
|
-- XXX needs --help, see hledger-addon-example.hs
|
||||||
-- XXX shows only one posting when multiple have same balance
|
|
||||||
|
|
||||||
main = do
|
main = do
|
||||||
args <- getArgs
|
args <- getArgs
|
||||||
opts <- argsToCliOpts ("register" : args) []
|
opts <- argsToCliOpts ("register" : args) []
|
||||||
withJournalDo opts $ \j -> do
|
withJournalDo opts $ \j -> do
|
||||||
let r = postingsReport (reportspec_ opts) j
|
let
|
||||||
unless (null r) $ do
|
r = postingsReport (reportspec_ opts) j
|
||||||
let
|
maxbal = fifth5 $ maximumBy (comparing fifth5) r
|
||||||
(_, _, mdesc, p, bal) = maximumBy (comparing fifth5) r
|
is = filter ((== maxbal).fifth5) r
|
||||||
d = postingDate p
|
mapM_ printItem is
|
||||||
desc = fromMaybe "" mdesc
|
|
||||||
ptxt = T.strip $ T.unlines $ first3 $ postingAsLines False True 20 15 p
|
printItem (_, _, _, p, bal) = do
|
||||||
baltxt = T.pack $ showMixedAmountOneLine bal
|
let
|
||||||
T.putStrLn $ T.unwords [showDate d, desc, "", ptxt, "", baltxt]
|
d = postingDate p
|
||||||
|
mt = ptransaction p
|
||||||
|
desc = fmt 30 $ maybe "-" tdescription mt
|
||||||
|
acct = fmt 40 $ paccount p
|
||||||
|
amt = fmta 12 $ T.pack $ showMixedAmountOneLine $ pamount p
|
||||||
|
baltxt = fmta 12 $ T.pack $ showMixedAmountOneLine bal
|
||||||
|
T.putStrLn $ T.unwords [showDate d, desc, "", acct, "", amt, " ", baltxt]
|
||||||
|
where
|
||||||
|
fmt w = formatText True (Just w) (Just w) . textElideRight (w-2)
|
||||||
|
fmta w = formatText False (Just w) Nothing
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user