{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NamedFieldPuns #-}
module Hledger.UI.UIScreens
(screenUpdate
,esNew
,esUpdate
,msNew
,msUpdate
,asNew
,asUpdate
,asItemIndex
,csNew
,csUpdate
,csItemIndex
,bsNew
,bsUpdate
,bsItemIndex
,isNew
,isUpdate
,isItemIndex
,rsNew
,rsUpdate
,tsNew
,tsUpdate
)
where
import Brick.Widgets.List (listMoveTo, listSelectedElement, list)
import Data.List
import Data.Maybe
import Data.Time.Calendar (Day, diffDays)
import Safe
import qualified Data.Vector as V
import Hledger.Cli hiding (mode, progname,prognameandversion)
import Hledger.UI.UIOptions
import Hledger.UI.UITypes
import Hledger.UI.UIUtils
import Data.Function ((&))
screenUpdate :: UIOpts -> Day -> Journal -> Screen -> Screen
screenUpdate :: UIOpts -> Day -> Journal -> Screen -> Screen
screenUpdate UIOpts
opts Day
d Journal
j = \case
MS MenuScreenState
sst -> MenuScreenState -> Screen
MS forall a b. (a -> b) -> a -> b
$ MenuScreenState -> MenuScreenState
msUpdate MenuScreenState
sst
AS AccountsScreenState
sst -> AccountsScreenState -> Screen
AS forall a b. (a -> b) -> a -> b
$ UIOpts
-> Day -> Journal -> AccountsScreenState -> AccountsScreenState
asUpdate UIOpts
opts Day
d Journal
j AccountsScreenState
sst
CS AccountsScreenState
sst -> AccountsScreenState -> Screen
CS forall a b. (a -> b) -> a -> b
$ UIOpts
-> Day -> Journal -> AccountsScreenState -> AccountsScreenState
csUpdate UIOpts
opts Day
d Journal
j AccountsScreenState
sst
BS AccountsScreenState
sst -> AccountsScreenState -> Screen
BS forall a b. (a -> b) -> a -> b
$ UIOpts
-> Day -> Journal -> AccountsScreenState -> AccountsScreenState
bsUpdate UIOpts
opts Day
d Journal
j AccountsScreenState
sst
IS AccountsScreenState
sst -> AccountsScreenState -> Screen
IS forall a b. (a -> b) -> a -> b
$ UIOpts
-> Day -> Journal -> AccountsScreenState -> AccountsScreenState
isUpdate UIOpts
opts Day
d Journal
j AccountsScreenState
sst
RS RegisterScreenState
sst -> RegisterScreenState -> Screen
RS forall a b. (a -> b) -> a -> b
$ UIOpts
-> Day -> Journal -> RegisterScreenState -> RegisterScreenState
rsUpdate UIOpts
opts Day
d Journal
j RegisterScreenState
sst
TS TransactionScreenState
sst -> TransactionScreenState -> Screen
TS forall a b. (a -> b) -> a -> b
$ TransactionScreenState -> TransactionScreenState
tsUpdate TransactionScreenState
sst
ES ErrorScreenState
sst -> ErrorScreenState -> Screen
ES forall a b. (a -> b) -> a -> b
$ ErrorScreenState -> ErrorScreenState
esUpdate ErrorScreenState
sst
esNew :: String -> Screen
esNew :: String -> Screen
esNew String
msg =
forall a. String -> a -> a
dbgui String
"esNew" forall a b. (a -> b) -> a -> b
$
ErrorScreenState -> Screen
ES ESS {
_essError :: String
_essError = String
msg
,_essUnused :: ()
_essUnused = ()
}
esUpdate :: ErrorScreenState -> ErrorScreenState
esUpdate :: ErrorScreenState -> ErrorScreenState
esUpdate = forall a. String -> a -> a
dbgui String
"esUpdate`"
msNew :: Screen
msNew :: Screen
msNew =
forall a. String -> a -> a
dbgui String
"msNew" forall a b. (a -> b) -> a -> b
$
MenuScreenState -> Screen
MS MSS { _mssList :: List Name MenuScreenItem
_mssList = forall (t :: * -> *) n e.
Foldable t =>
n -> t e -> Int -> GenericList n t e
list Name
MenuList (forall a. [a] -> Vector a
V.fromList [MenuScreenItem]
items ) Int
1, _mssUnused :: ()
_mssUnused = () }
where
items :: [MenuScreenItem]
items = [
AccountName -> ScreenName -> MenuScreenItem
MenuScreenItem AccountName
"Cash accounts" ScreenName
CashScreen
,AccountName -> ScreenName -> MenuScreenItem
MenuScreenItem AccountName
"Balance sheet accounts" ScreenName
Balancesheet
,AccountName -> ScreenName -> MenuScreenItem
MenuScreenItem AccountName
"Income statement accounts" ScreenName
Incomestatement
,AccountName -> ScreenName -> MenuScreenItem
MenuScreenItem AccountName
"All accounts" ScreenName
Accounts
]
[
Int
csItemIndex,
Int
bsItemIndex,
Int
isItemIndex,
Int
asItemIndex
] = [Int
0..Int
3] :: [Int]
msUpdate :: MenuScreenState -> MenuScreenState
msUpdate :: MenuScreenState -> MenuScreenState
msUpdate = forall a. String -> a -> a
dbgui String
"msUpdate"
nullass :: Maybe AccountName -> AccountsScreenState
nullass Maybe AccountName
macct = ASS {
_assSelectedAccount :: AccountName
_assSelectedAccount = forall a. a -> Maybe a -> a
fromMaybe AccountName
"" Maybe AccountName
macct
,_assList :: List Name AccountsScreenItem
_assList = forall (t :: * -> *) n e.
Foldable t =>
n -> t e -> Int -> GenericList n t e
list Name
AccountsList (forall a. [a] -> Vector a
V.fromList []) Int
1
}
asNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen
asNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen
asNew UIOpts
uopts Day
d Journal
j Maybe AccountName
macct = forall a. String -> a -> a
dbgui String
"asNew" forall a b. (a -> b) -> a -> b
$ AccountsScreenState -> Screen
AS forall a b. (a -> b) -> a -> b
$ UIOpts
-> Day -> Journal -> AccountsScreenState -> AccountsScreenState
asUpdate UIOpts
uopts Day
d Journal
j forall a b. (a -> b) -> a -> b
$ Maybe AccountName -> AccountsScreenState
nullass Maybe AccountName
macct
asUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState
asUpdate :: UIOpts
-> Day -> Journal -> AccountsScreenState -> AccountsScreenState
asUpdate UIOpts
uopts Day
d = forall a. String -> a -> a
dbgui String
"asUpdate" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
ReportSpec
-> Day
-> CliOpts
-> (ReportOpts -> ReportOpts)
-> Query
-> Journal
-> AccountsScreenState
-> AccountsScreenState
asUpdateHelper ReportSpec
rspec Day
d CliOpts
copts forall {a}. a -> a
roptsmod Query
extraquery
where
UIOpts{uoCliOpts :: UIOpts -> CliOpts
uoCliOpts=copts :: CliOpts
copts@CliOpts{reportspec_ :: CliOpts -> ReportSpec
reportspec_=ReportSpec
rspec}} = UIOpts
uopts
roptsmod :: a -> a
roptsmod = forall {a}. a -> a
id
extraquery :: Query
extraquery = Query
Any
asUpdateHelper :: ReportSpec -> Day -> CliOpts -> (ReportOpts -> ReportOpts) -> Query -> Journal -> AccountsScreenState -> AccountsScreenState
asUpdateHelper :: ReportSpec
-> Day
-> CliOpts
-> (ReportOpts -> ReportOpts)
-> Query
-> Journal
-> AccountsScreenState
-> AccountsScreenState
asUpdateHelper ReportSpec
rspec0 Day
d CliOpts
copts ReportOpts -> ReportOpts
roptsModify Query
extraquery Journal
j AccountsScreenState
ass = forall a. String -> a -> a
dbgui String
"asUpdateHelper"
AccountsScreenState
ass{_assList :: List Name AccountsScreenItem
_assList=List Name AccountsScreenItem
l}
where
ropts :: ReportOpts
ropts = ReportOpts -> ReportOpts
roptsModify forall a b. (a -> b) -> a -> b
$ ReportSpec -> ReportOpts
_rsReportOpts ReportSpec
rspec0
rspec :: ReportSpec
rspec =
ReportOpts -> ReportSpec -> Either String ReportSpec
updateReportSpec
ReportOpts
ropts
ReportSpec
rspec0{_rsDay :: Day
_rsDay=Day
d}
forall a b. a -> (a -> b) -> b
& forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a. HasCallStack => String -> a
error String
"asUpdateHelper: adjusting the query, should not have failed") forall {a}. a -> a
id
forall a b. a -> (a -> b) -> b
& Maybe DateSpan -> ReportSpec -> ReportSpec
reportSpecSetFutureAndForecast (InputOpts -> Maybe DateSpan
forecast_ forall a b. (a -> b) -> a -> b
$ CliOpts -> InputOpts
inputopts_ CliOpts
copts)
forall a b. a -> (a -> b) -> b
& Query -> ReportSpec -> ReportSpec
reportSpecAddQuery Query
extraquery
l :: List Name AccountsScreenItem
l = forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveTo Int
selidx forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) n e.
Foldable t =>
n -> t e -> Int -> GenericList n t e
list Name
AccountsList (forall a. [a] -> Vector a
V.fromList forall a b. (a -> b) -> a -> b
$ [AccountsScreenItem]
displayitems forall a. [a] -> [a] -> [a]
++ [AccountsScreenItem]
blankitems) Int
1
where
selidx :: Int
selidx = forall a. a -> [a] -> a
headDef Int
0 forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
catMaybes [
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex AccountName
a [AccountName]
as
,forall a. (a -> Bool) -> [a] -> Maybe Int
findIndex (AccountName
a AccountName -> AccountName -> Bool
`isAccountNamePrefixOf`) [AccountName]
as
,forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. Ord a => a -> a -> a
max Int
0 (forall (t :: * -> *) a. Foldable t => t a -> Int
length (forall a. (a -> Bool) -> [a] -> [a]
filter (forall a. Ord a => a -> a -> Bool
< AccountName
a) [AccountName]
as) forall a. Num a => a -> a -> a
- Int
1)
]
where
a :: AccountName
a = AccountsScreenState -> AccountName
_assSelectedAccount AccountsScreenState
ass
as :: [AccountName]
as = forall a b. (a -> b) -> [a] -> [b]
map AccountsScreenItem -> AccountName
asItemAccountName [AccountsScreenItem]
displayitems
displayitems :: [AccountsScreenItem]
displayitems = forall a b. (a -> b) -> [a] -> [b]
map (AccountName, AccountName, Int, MixedAmount) -> AccountsScreenItem
displayitem [(AccountName, AccountName, Int, MixedAmount)]
items
where
([(AccountName, AccountName, Int, MixedAmount)]
items, MixedAmount
_) = forall a. HasAmounts a => Map AccountName AmountStyle -> a -> a
styleAmounts Map AccountName AmountStyle
styles forall a b. (a -> b) -> a -> b
$ ReportSpec -> Journal -> BalanceReport
balanceReport ReportSpec
rspec Journal
j
where
styles :: Map AccountName AmountStyle
styles = Rounding -> Journal -> Map AccountName AmountStyle
journalCommodityStylesWith Rounding
HardRounding Journal
j
displayitem :: (AccountName, AccountName, Int, MixedAmount) -> AccountsScreenItem
displayitem (AccountName
fullacct, AccountName
shortacct, Int
indent, MixedAmount
bal) =
AccountsScreenItem{asItemIndentLevel :: Int
asItemIndentLevel = Int
indent
,asItemAccountName :: AccountName
asItemAccountName = AccountName
fullacct
,asItemDisplayAccountName :: AccountName
asItemDisplayAccountName = AccountName -> AccountName -> AccountName
replaceHiddenAccountsNameWith AccountName
"All" forall a b. (a -> b) -> a -> b
$ if ReportOpts -> Bool
tree_ ReportOpts
ropts then AccountName
shortacct else AccountName
fullacct
,asItemMixedAmount :: Maybe MixedAmount
asItemMixedAmount = forall a. a -> Maybe a
Just MixedAmount
bal
}
blankitems :: [AccountsScreenItem]
blankitems = forall a. Int -> a -> [a]
replicate Int
uiNumBlankItems
AccountsScreenItem{asItemIndentLevel :: Int
asItemIndentLevel = Int
0
,asItemAccountName :: AccountName
asItemAccountName = AccountName
""
,asItemDisplayAccountName :: AccountName
asItemDisplayAccountName = AccountName
""
,asItemMixedAmount :: Maybe MixedAmount
asItemMixedAmount = forall a. Maybe a
Nothing
}
bsNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen
bsNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen
bsNew UIOpts
uopts Day
d Journal
j Maybe AccountName
macct = forall a. String -> a -> a
dbgui String
"bsNew" forall a b. (a -> b) -> a -> b
$ AccountsScreenState -> Screen
BS forall a b. (a -> b) -> a -> b
$ UIOpts
-> Day -> Journal -> AccountsScreenState -> AccountsScreenState
bsUpdate UIOpts
uopts Day
d Journal
j forall a b. (a -> b) -> a -> b
$ Maybe AccountName -> AccountsScreenState
nullass Maybe AccountName
macct
bsUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState
bsUpdate :: UIOpts
-> Day -> Journal -> AccountsScreenState -> AccountsScreenState
bsUpdate UIOpts
uopts Day
d = forall a. String -> a -> a
dbgui String
"bsUpdate" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
ReportSpec
-> Day
-> CliOpts
-> (ReportOpts -> ReportOpts)
-> Query
-> Journal
-> AccountsScreenState
-> AccountsScreenState
asUpdateHelper ReportSpec
rspec Day
d CliOpts
copts ReportOpts -> ReportOpts
roptsmod Query
extraquery
where
UIOpts{uoCliOpts :: UIOpts -> CliOpts
uoCliOpts=copts :: CliOpts
copts@CliOpts{reportspec_ :: CliOpts -> ReportSpec
reportspec_=ReportSpec
rspec}} = UIOpts
uopts
roptsmod :: ReportOpts -> ReportOpts
roptsmod ReportOpts
ropts = ReportOpts
ropts{balanceaccum_ :: BalanceAccumulation
balanceaccum_=BalanceAccumulation
Historical}
extraquery :: Query
extraquery = [AccountType] -> Query
Type [AccountType
Asset,AccountType
Liability,AccountType
Equity]
csNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen
csNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen
csNew UIOpts
uopts Day
d Journal
j Maybe AccountName
macct = forall a. String -> a -> a
dbgui String
"csNew" forall a b. (a -> b) -> a -> b
$ AccountsScreenState -> Screen
CS forall a b. (a -> b) -> a -> b
$ UIOpts
-> Day -> Journal -> AccountsScreenState -> AccountsScreenState
csUpdate UIOpts
uopts Day
d Journal
j forall a b. (a -> b) -> a -> b
$ Maybe AccountName -> AccountsScreenState
nullass Maybe AccountName
macct
csUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState
csUpdate :: UIOpts
-> Day -> Journal -> AccountsScreenState -> AccountsScreenState
csUpdate UIOpts
uopts Day
d = forall a. String -> a -> a
dbgui String
"csUpdate" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
ReportSpec
-> Day
-> CliOpts
-> (ReportOpts -> ReportOpts)
-> Query
-> Journal
-> AccountsScreenState
-> AccountsScreenState
asUpdateHelper ReportSpec
rspec Day
d CliOpts
copts ReportOpts -> ReportOpts
roptsmod Query
extraquery
where
UIOpts{uoCliOpts :: UIOpts -> CliOpts
uoCliOpts=copts :: CliOpts
copts@CliOpts{reportspec_ :: CliOpts -> ReportSpec
reportspec_=ReportSpec
rspec}} = UIOpts
uopts
roptsmod :: ReportOpts -> ReportOpts
roptsmod ReportOpts
ropts = ReportOpts
ropts{balanceaccum_ :: BalanceAccumulation
balanceaccum_=BalanceAccumulation
Historical}
extraquery :: Query
extraquery = [AccountType] -> Query
Type [AccountType
Cash]
isNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen
isNew :: UIOpts -> Day -> Journal -> Maybe AccountName -> Screen
isNew UIOpts
uopts Day
d Journal
j Maybe AccountName
macct = forall a. String -> a -> a
dbgui String
"isNew" forall a b. (a -> b) -> a -> b
$ AccountsScreenState -> Screen
IS forall a b. (a -> b) -> a -> b
$ UIOpts
-> Day -> Journal -> AccountsScreenState -> AccountsScreenState
isUpdate UIOpts
uopts Day
d Journal
j forall a b. (a -> b) -> a -> b
$ Maybe AccountName -> AccountsScreenState
nullass Maybe AccountName
macct
isUpdate :: UIOpts -> Day -> Journal -> AccountsScreenState -> AccountsScreenState
isUpdate :: UIOpts
-> Day -> Journal -> AccountsScreenState -> AccountsScreenState
isUpdate UIOpts
uopts Day
d = forall a. String -> a -> a
dbgui String
"isUpdate" forall b c a. (b -> c) -> (a -> b) -> a -> c
.
ReportSpec
-> Day
-> CliOpts
-> (ReportOpts -> ReportOpts)
-> Query
-> Journal
-> AccountsScreenState
-> AccountsScreenState
asUpdateHelper ReportSpec
rspec Day
d CliOpts
copts ReportOpts -> ReportOpts
roptsmod Query
extraquery
where
UIOpts{uoCliOpts :: UIOpts -> CliOpts
uoCliOpts=copts :: CliOpts
copts@CliOpts{reportspec_ :: CliOpts -> ReportSpec
reportspec_=ReportSpec
rspec}} = UIOpts
uopts
roptsmod :: ReportOpts -> ReportOpts
roptsmod ReportOpts
ropts = ReportOpts
ropts{balanceaccum_ :: BalanceAccumulation
balanceaccum_=BalanceAccumulation
PerPeriod}
extraquery :: Query
extraquery = [AccountType] -> Query
Type [AccountType
Revenue, AccountType
Expense]
rsNew :: UIOpts -> Day -> Journal -> AccountName -> Bool -> Screen
rsNew :: UIOpts -> Day -> Journal -> AccountName -> Bool -> Screen
rsNew UIOpts
uopts Day
d Journal
j AccountName
acct Bool
forceinclusive =
forall a. String -> a -> a
dbgui String
"rsNew" forall a b. (a -> b) -> a -> b
$
RegisterScreenState -> Screen
RS forall a b. (a -> b) -> a -> b
$
UIOpts
-> Day -> Journal -> RegisterScreenState -> RegisterScreenState
rsUpdate UIOpts
uopts Day
d Journal
j forall a b. (a -> b) -> a -> b
$
RSS {
_rssAccount :: AccountName
_rssAccount = AccountName -> AccountName -> AccountName
replaceHiddenAccountsNameWith AccountName
"*" AccountName
acct
,_rssForceInclusive :: Bool
_rssForceInclusive = Bool
forceinclusive
,_rssList :: List Name RegisterScreenItem
_rssList = forall (t :: * -> *) n e.
Foldable t =>
n -> t e -> Int -> GenericList n t e
list Name
RegisterList (forall a. [a] -> Vector a
V.fromList []) Int
1
}
rsUpdate :: UIOpts -> Day -> Journal -> RegisterScreenState -> RegisterScreenState
rsUpdate :: UIOpts
-> Day -> Journal -> RegisterScreenState -> RegisterScreenState
rsUpdate UIOpts
uopts Day
d Journal
j rss :: RegisterScreenState
rss@RSS{AccountName
_rssAccount :: AccountName
_rssAccount :: RegisterScreenState -> AccountName
_rssAccount, Bool
_rssForceInclusive :: Bool
_rssForceInclusive :: RegisterScreenState -> Bool
_rssForceInclusive, _rssList :: RegisterScreenState -> List Name RegisterScreenItem
_rssList=List Name RegisterScreenItem
oldlist} =
forall a. String -> a -> a
dbgui String
"rsUpdate"
RegisterScreenState
rss{_rssList :: List Name RegisterScreenItem
_rssList=List Name RegisterScreenItem
l'}
where
UIOpts{uoCliOpts :: UIOpts -> CliOpts
uoCliOpts=copts :: CliOpts
copts@CliOpts{reportspec_ :: CliOpts -> ReportSpec
reportspec_=rspec :: ReportSpec
rspec@ReportSpec{_rsReportOpts :: ReportSpec -> ReportOpts
_rsReportOpts=ReportOpts
ropts}}} = UIOpts
uopts
inclusive :: Bool
inclusive = ReportOpts -> Bool
tree_ ReportOpts
ropts Bool -> Bool -> Bool
|| Bool
_rssForceInclusive
thisacctq :: Query
thisacctq = Regexp -> Query
Acct forall a b. (a -> b) -> a -> b
$ AccountName -> Regexp
mkregex AccountName
_rssAccount
where
mkregex :: AccountName -> Regexp
mkregex = if Bool
inclusive then AccountName -> Regexp
accountNameToAccountRegex else AccountName -> Regexp
accountNameToAccountOnlyRegex
ropts' :: ReportOpts
ropts' = ReportOpts
ropts {
depth_ :: Maybe Int
depth_=forall a. Maybe a
Nothing
, show_costs_ :: Bool
show_costs_=Bool
True
}
rspec' :: ReportSpec
rspec' =
ReportOpts -> ReportSpec -> Either String ReportSpec
updateReportSpec ReportOpts
ropts' ReportSpec
rspec{_rsDay :: Day
_rsDay=Day
d}
forall a b. a -> (a -> b) -> b
& forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall a. HasCallStack => String -> a
error String
"rsUpdate: adjusting the query for register, should not have failed") forall {a}. a -> a
id
forall a b. a -> (a -> b) -> b
& Maybe DateSpan -> ReportSpec -> ReportSpec
reportSpecSetFutureAndForecast (InputOpts -> Maybe DateSpan
forecast_ forall a b. (a -> b) -> a -> b
$ CliOpts -> InputOpts
inputopts_ CliOpts
copts)
items :: AccountTransactionsReport
items = forall a. HasAmounts a => Map AccountName AmountStyle -> a -> a
styleAmounts Map AccountName AmountStyle
styles forall a b. (a -> b) -> a -> b
$ ReportSpec -> Journal -> Query -> AccountTransactionsReport
accountTransactionsReport ReportSpec
rspec' Journal
j Query
thisacctq
where
styles :: Map AccountName AmountStyle
styles = Rounding -> Journal -> Map AccountName AmountStyle
journalCommodityStylesWith Rounding
HardRounding Journal
j
items' :: AccountTransactionsReport
items' =
(if ReportOpts -> Bool
empty_ ReportOpts
ropts then forall {a}. a -> a
id else forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. MixedAmount -> Bool
mixedAmountLooksZero forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {b} {c} {d} {e} {f}. (a, b, c, d, e, f) -> e
fifth6)) forall a b. (a -> b) -> a -> b
$
forall a. [a] -> [a]
reverse
AccountTransactionsReport
items
displayitems :: [RegisterScreenItem]
displayitems = forall a b. (a -> b) -> [a] -> [b]
map forall {b} {c}.
(Transaction, b, c, AccountName, MixedAmount, MixedAmount)
-> RegisterScreenItem
displayitem AccountTransactionsReport
items'
where
displayitem :: (Transaction, b, c, AccountName, MixedAmount, MixedAmount)
-> RegisterScreenItem
displayitem (Transaction
t, b
_, c
_issplit, AccountName
otheracctsstr, MixedAmount
change, MixedAmount
bal) =
RegisterScreenItem{rsItemDate :: AccountName
rsItemDate = Day -> AccountName
showDate forall a b. (a -> b) -> a -> b
$ WhichDate -> Query -> Query -> Transaction -> Day
transactionRegisterDate WhichDate
wd (ReportSpec -> Query
_rsQuery ReportSpec
rspec') Query
thisacctq Transaction
t
,rsItemStatus :: Status
rsItemStatus = Transaction -> Status
tstatus Transaction
t
,rsItemDescription :: AccountName
rsItemDescription = Transaction -> AccountName
tdescription Transaction
t
,rsItemOtherAccounts :: AccountName
rsItemOtherAccounts = AccountName
otheracctsstr
,rsItemChangeAmount :: WideBuilder
rsItemChangeAmount = MixedAmount -> WideBuilder
showamt MixedAmount
change
,rsItemBalanceAmount :: WideBuilder
rsItemBalanceAmount = MixedAmount -> WideBuilder
showamt MixedAmount
bal
,rsItemTransaction :: Transaction
rsItemTransaction = Transaction
t
}
where
showamt :: MixedAmount -> WideBuilder
showamt = AmountDisplayOpts -> MixedAmount -> WideBuilder
showMixedAmountB AmountDisplayOpts
oneLine{displayMaxWidth :: Maybe Int
displayMaxWidth=forall a. a -> Maybe a
Just Int
3}
wd :: WhichDate
wd = ReportOpts -> WhichDate
whichDate ReportOpts
ropts'
blankitems :: [RegisterScreenItem]
blankitems = forall a. Int -> a -> [a]
replicate Int
uiNumBlankItems
RegisterScreenItem{rsItemDate :: AccountName
rsItemDate = AccountName
""
,rsItemStatus :: Status
rsItemStatus = Status
Unmarked
,rsItemDescription :: AccountName
rsItemDescription = AccountName
""
,rsItemOtherAccounts :: AccountName
rsItemOtherAccounts = AccountName
""
,rsItemChangeAmount :: WideBuilder
rsItemChangeAmount = forall a. Monoid a => a
mempty
,rsItemBalanceAmount :: WideBuilder
rsItemBalanceAmount = forall a. Monoid a => a
mempty
,rsItemTransaction :: Transaction
rsItemTransaction = Transaction
nulltransaction
}
l :: List Name RegisterScreenItem
l = forall (t :: * -> *) n e.
Foldable t =>
n -> t e -> Int -> GenericList n t e
list Name
RegisterList (forall a. [a] -> Vector a
V.fromList forall a b. (a -> b) -> a -> b
$ [RegisterScreenItem]
displayitems forall a. [a] -> [a] -> [a]
++ [RegisterScreenItem]
blankitems) Int
1
l' :: List Name RegisterScreenItem
l' = forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveTo Int
newselidx List Name RegisterScreenItem
l
where
endidx :: Int
endidx = forall a. Ord a => a -> a -> a
max Int
0 forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> Int
length [RegisterScreenItem]
displayitems forall a. Num a => a -> a -> a
- Int
1
newselidx :: Int
newselidx =
case forall (t :: * -> *) e n.
(Splittable t, Traversable t, Semigroup (t e)) =>
GenericList n t e -> Maybe (Int, e)
listSelectedElement List Name RegisterScreenItem
oldlist of
Maybe (Int, RegisterScreenItem)
Nothing -> Int
endidx
Just (Int
_, RegisterScreenItem{rsItemTransaction :: RegisterScreenItem -> Transaction
rsItemTransaction=Transaction{tindex :: Transaction -> Integer
tindex=Integer
prevselidx, tdate :: Transaction -> Day
tdate=Day
prevseld}}) ->
forall a. a -> [a] -> a
headDef Int
endidx forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
catMaybes [
forall a. (a -> Bool) -> [a] -> Maybe Int
findIndex ((forall a. Eq a => a -> a -> Bool
==Integer
prevselidx) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transaction -> Integer
tindex forall b c a. (b -> c) -> (a -> b) -> a -> c
. RegisterScreenItem -> Transaction
rsItemTransaction) [RegisterScreenItem]
displayitems
,forall a. (a -> Bool) -> [a] -> Maybe Int
findIndex ((forall a. Eq a => a -> a -> Bool
==Maybe Integer
nearestidbydatethenid) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transaction -> Integer
tindex forall b c a. (b -> c) -> (a -> b) -> a -> c
. RegisterScreenItem -> Transaction
rsItemTransaction) [RegisterScreenItem]
displayitems
]
where
nearestidbydatethenid :: Maybe Integer
nearestidbydatethenid = forall {a} {b} {c}. (a, b, c) -> c
third3 forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall a. [a] -> Maybe a
headMay forall a b. (a -> b) -> a -> b
$ forall a. Ord a => [a] -> [a]
sort
[(forall a. Num a => a -> a
abs forall a b. (a -> b) -> a -> b
$ Day -> Day -> Integer
diffDays (Transaction -> Day
tdate Transaction
t) Day
prevseld, forall a. Num a => a -> a
abs (Transaction -> Integer
tindex Transaction
t forall a. Num a => a -> a -> a
- Integer
prevselidx), Transaction -> Integer
tindex Transaction
t) | Transaction
t <- [Transaction]
ts])
ts :: [Transaction]
ts = forall a b. (a -> b) -> [a] -> [b]
map RegisterScreenItem -> Transaction
rsItemTransaction [RegisterScreenItem]
displayitems
tsNew :: AccountName -> [NumberedTransaction] -> NumberedTransaction -> Screen
tsNew :: AccountName
-> [NumberedTransaction] -> NumberedTransaction -> Screen
tsNew AccountName
acct [NumberedTransaction]
nts NumberedTransaction
nt =
forall a. String -> a -> a
dbgui String
"tsNew" forall a b. (a -> b) -> a -> b
$
TransactionScreenState -> Screen
TS TSS{
_tssAccount :: AccountName
_tssAccount = AccountName
acct
,_tssTransactions :: [NumberedTransaction]
_tssTransactions = [NumberedTransaction]
nts
,_tssTransaction :: NumberedTransaction
_tssTransaction = NumberedTransaction
nt
}
tsUpdate :: TransactionScreenState -> TransactionScreenState
tsUpdate :: TransactionScreenState -> TransactionScreenState
tsUpdate = forall a. String -> a -> a
dbgui String
"tsUpdate"