feat: ui: add "Cash accounts" screen

This commit is contained in:
Simon Michael 2023-03-24 07:59:16 -10:00
parent 13cd01ca36
commit a4b3476e2f
7 changed files with 43 additions and 7 deletions

View File

@ -39,6 +39,7 @@ import Hledger.UI.UIState (uiState, getDepth)
import Hledger.UI.UIUtils (dbguiEv, showScreenStack, showScreenSelection)
import Hledger.UI.MenuScreen
import Hledger.UI.AccountsScreen
import Hledger.UI.CashScreen
import Hledger.UI.BalancesheetScreen
import Hledger.UI.IncomestatementScreen
import Hledger.UI.RegisterScreen
@ -298,6 +299,7 @@ uiHandle ev = do
case aScreen ui of
MS _ -> msHandle ev
AS _ -> asHandle ev
CS _ -> csHandle ev
BS _ -> bsHandle ev
IS _ -> isHandle ev
RS _ -> rsHandle ev
@ -309,6 +311,7 @@ uiDraw ui =
case aScreen ui of
MS _ -> msDraw ui
AS _ -> asDraw ui
CS _ -> csDraw ui
BS _ -> bsDraw ui
IS _ -> isDraw ui
RS _ -> rsDraw ui

View File

@ -258,6 +258,7 @@ msEnterScreen d scrname ui@UIState{ajournal=j, aopts=uopts} = do
let
scr = case scrname of
Accounts -> asNew uopts d j Nothing
CashScreen -> csNew uopts d j Nothing
Balancesheet -> bsNew uopts d j Nothing
Incomestatement -> isNew uopts d j Nothing
put' $ pushScreen scr ui

View File

@ -38,6 +38,7 @@ uiflags = [
,flagReq ["theme"] (\s opts -> Right $ setopt "theme" s opts) "THEME" ("use this custom display theme ("++intercalate ", " themeNames++")")
,flagNone ["menu"] (setboolopt "menu") "start in the menu screen"
,flagNone ["all"] (setboolopt "all") "start in the all accounts screen"
,flagNone ["cash"] (setboolopt "cash") "start in the cash accounts screen"
,flagNone ["bs"] (setboolopt "bs") "start in the balance sheet accounts screen"
,flagNone ["is"] (setboolopt "is") "start in the income statement accounts screen"
,flagReq ["register"] (\s opts -> Right $ setopt "register" s opts) "ACCTREGEX" "start in the (first matched) account's register"
@ -57,7 +58,7 @@ uiflags = [
--uimode :: Mode RawOpts
uimode = (mode "hledger-ui" (setopt "command" "ui" def)
"browse accounts, postings and entries in a full-window TUI"
(argsFlag "[--menu|--all|--bs|--is|--register=ACCT] [QUERY]") []){
(argsFlag "[--menu|--all|--cash|--bs|--is|--register=ACCT] [QUERY]") []){
modeGroupFlags = Group {
groupUnnamed = uiflags
,groupHidden = hiddenflags

View File

@ -24,6 +24,8 @@ module Hledger.UI.UIScreens
,asUpdate
,bsNew
,bsUpdate
,csNew
,csUpdate
,isNew
,isUpdate
,rsNew
@ -52,6 +54,7 @@ screenUpdate :: UIOpts -> Day -> Journal -> Screen -> Screen
screenUpdate opts d j = \case
MS sst -> MS $ msUpdate sst -- opts d j ass
AS sst -> AS $ asUpdate opts d j sst
CS sst -> CS $ csUpdate opts d j sst
BS sst -> BS $ bsUpdate opts d j sst
IS sst -> IS $ isUpdate opts d j sst
RS sst -> RS $ rsUpdate opts d j sst
@ -82,12 +85,13 @@ msNew =
_mssList = list MenuList (V.fromList [
-- keep initial screen stack setup in UI.Main synced with these
MenuScreenItem "All accounts" Accounts
,MenuScreenItem "Cash accounts" CashScreen
,MenuScreenItem "Balance sheet accounts" Balancesheet
,MenuScreenItem "Income statement accounts" Incomestatement
]) 1
& listMoveTo 1 -- select balance sheet accounts screen at startup (currently this screen is constructed only then)
& listMoveTo defaultscreenitem
,_mssUnused = ()
}
} where defaultscreenitem = 2 -- select this one at startup (currently this screen is constructed only then)
-- | Update a menu screen. Currently a no-op since menu screen
-- has unchanging content.
@ -177,6 +181,21 @@ bsUpdate uopts d = dbgui "bsUpdate" .
roptsmod ropts = ropts{balanceaccum_=Historical} -- always show historical end balances
extraquery = Type [Asset,Liability,Equity] -- restrict to balance sheet accounts
-- | Construct a cash accounts screen listing the appropriate set of accounts,
-- with the appropriate one selected.
-- Screen-specific arguments: the account to select if any.
csNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen
csNew uopts d j macct = dbgui "csNew" $ CS $ csUpdate uopts d j $ nullass macct
-- | Update a balance sheet screen's state from these options, reporting date, and journal.
csUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState
csUpdate uopts d = dbgui "csUpdate" .
asUpdateHelper rspec d copts roptsmod extraquery
where
UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec}} = uopts
roptsmod ropts = ropts{balanceaccum_=Historical} -- always show historical end balances
extraquery = Type [Cash] -- restrict to cash accounts
-- | Construct an income statement screen listing the appropriate set of accounts,
-- with the appropriate one selected.
-- Screen-specific arguments: the account to select if any.

View File

@ -101,6 +101,7 @@ data Name =
-- Unique names for screens the user can navigate to from the menu.
data ScreenName =
Accounts
| CashScreen
| Balancesheet
| Incomestatement
deriving (Ord, Show, Eq)
@ -176,6 +177,7 @@ data ScreenName =
data Screen =
MS MenuScreenState
| AS AccountsScreenState
| CS AccountsScreenState
| BS AccountsScreenState
| IS AccountsScreenState
| RS RegisterScreenState
@ -192,6 +194,7 @@ data AccountsLikeScreen = ALS (AccountsScreenState -> Screen) AccountsScreenStat
toAccountsLikeScreen :: Screen -> Maybe AccountsLikeScreen
toAccountsLikeScreen scr = case scr of
AS ass -> Just $ ALS AS ass
CS ass -> Just $ ALS CS ass
BS ass -> Just $ ALS BS ass
IS ass -> Just $ ALS IS ass
_ -> Nothing

View File

@ -497,6 +497,7 @@ showScreenId :: Screen -> String
showScreenId = \case
MS _ -> "M" -- menu
AS _ -> "A" -- all accounts
CS _ -> "C" -- cash accounts
BS _ -> "B" -- bs accounts
IS _ -> "I" -- is accounts
RS _ -> "R" -- menu
@ -516,6 +517,7 @@ showScreenSelection :: Screen -> String
showScreenSelection = \case
MS MSS{_mssList} -> "M" ++ (maybe "" show $ listSelected _mssList) -- menu
AS ASS{_assList} -> "A" ++ (maybe "" show $ listSelected _assList) -- all accounts
CS ASS{_assList} -> "C" ++ (maybe "" show $ listSelected _assList) -- cash accounts
BS ASS{_assList} -> "B" ++ (maybe "" show $ listSelected _assList) -- bs accounts
IS ASS{_assList} -> "I" ++ (maybe "" show $ listSelected _assList) -- is accounts
RS RSS{_rssList} -> "R" ++ (maybe "" show $ listSelected _rssList) -- menu

View File

@ -67,6 +67,9 @@ Any QUERYARGS are interpreted as a hledger search query which filters the data.
`--all`
: start in the all accounts screen
`--cash`
: start in the cash accounts screen
`--bs`
: start in the balance sheet accounts screen
@ -237,17 +240,21 @@ and their end balances on the date shown in the title bar
(or their balance changes in the period shown in the title bar, toggleable with `H`).
It is like the `hledger balance` command.
## Cash accounts
This screen shows "cash" (ie, liquid asset) accounts (like `hledger balancesheet type:c`),
if these can be detected (see [account types](/hledger.html#account-types)).
It always shows end balances.
## Balance sheet accounts
This screen shows asset, liability and equity accounts, if these can be detected (see [account types](/hledger.html#account-types)).
This screen shows asset, liability and equity accounts (like `hledger balancesheetequity`).
It always shows end balances.
It is like the `hledger balancesheetequity` command.
## Income statement accounts
This screen shows revenue and expense accounts.
This screen shows revenue and expense accounts (like `hledger incomestatement`).
It always shows balance changes.
It is like the `hledger incomestatement` command.
All of these accounts screens work in much the same way: