ENH check all income accounts
This commit is contained in:
parent
1555e9071f
commit
b586f958cb
|
@ -134,6 +134,9 @@ sortAllo a@Allocation {alloAmts = as} = do
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Income
|
-- Income
|
||||||
|
|
||||||
|
-- TODO this will scan the interval allocations fully each time
|
||||||
|
-- iteration which is a total waste, but the fix requires turning this
|
||||||
|
-- loop into a fold which I don't feel like doing now :(
|
||||||
insertIncome
|
insertIncome
|
||||||
:: (MonadInsertError m, MonadFinance m)
|
:: (MonadInsertError m, MonadFinance m)
|
||||||
=> CommitRId
|
=> CommitRId
|
||||||
|
@ -157,18 +160,23 @@ insertIncome
|
||||||
, incToBal
|
, incToBal
|
||||||
, incGross
|
, incGross
|
||||||
, incPayPeriod
|
, incPayPeriod
|
||||||
} = do
|
} =
|
||||||
-- TODO check that the other accounts are not income somewhere here
|
combineErrorM
|
||||||
_ <- checkAcntType IncomeT $ taAcnt incFrom
|
(combineError incRes nonIncRes (,))
|
||||||
precision <- lookupCurrencyPrec incCurrency
|
(combineError precRes dayRes (,))
|
||||||
let gross = roundPrecision precision incGross
|
$ \_ (precision, days) -> do
|
||||||
-- TODO this will scan the interval allocations fully each time
|
let gross = roundPrecision precision incGross
|
||||||
-- iteration which is a total waste, but the fix requires turning this
|
concat <$> foldDays (allocate precision gross) start days
|
||||||
-- loop into a fold which I don't feel like doing now :(
|
|
||||||
days <- askDays incWhen localInterval
|
|
||||||
res <- foldDays (allocate precision gross) start days
|
|
||||||
return $ concat res
|
|
||||||
where
|
where
|
||||||
|
incRes = isIncomeAcnt $ taAcnt incFrom
|
||||||
|
nonIncRes =
|
||||||
|
mapErrors isNotIncomeAcnt $
|
||||||
|
taAcnt incToBal
|
||||||
|
: (alloAcnt <$> incPretax)
|
||||||
|
++ (alloAcnt <$> incTaxes)
|
||||||
|
++ (alloAcnt <$> incPosttax)
|
||||||
|
precRes = lookupCurrencyPrec incCurrency
|
||||||
|
dayRes = askDays incWhen localInterval
|
||||||
start = fromGregorian' $ pStart incPayPeriod
|
start = fromGregorian' $ pStart incPayPeriod
|
||||||
pType' = pType incPayPeriod
|
pType' = pType incPayPeriod
|
||||||
meta = BudgetMeta key name
|
meta = BudgetMeta key name
|
||||||
|
@ -254,19 +262,25 @@ foldDays f start days = case NE.nonEmpty days of
|
||||||
snd $
|
snd $
|
||||||
L.mapAccumL (\prevDay day -> (day, f prevDay day)) start days
|
L.mapAccumL (\prevDay day -> (day, f prevDay day)) start days
|
||||||
|
|
||||||
|
isIncomeAcnt :: (MonadInsertError m, MonadFinance m) => AcntID -> m ()
|
||||||
|
isIncomeAcnt = checkAcntType IncomeT
|
||||||
|
|
||||||
|
isNotIncomeAcnt :: (MonadInsertError m, MonadFinance m) => AcntID -> m ()
|
||||||
|
isNotIncomeAcnt = checkAcntTypes (AssetT :| [EquityT, ExpenseT, LiabilityT])
|
||||||
|
|
||||||
checkAcntType
|
checkAcntType
|
||||||
:: (MonadInsertError m, MonadFinance m)
|
:: (MonadInsertError m, MonadFinance m)
|
||||||
=> AcntType
|
=> AcntType
|
||||||
-> AcntID
|
-> AcntID
|
||||||
-> m AcntID
|
-> m ()
|
||||||
checkAcntType t = checkAcntTypes (t :| [])
|
checkAcntType t = checkAcntTypes (t :| [])
|
||||||
|
|
||||||
checkAcntTypes
|
checkAcntTypes
|
||||||
:: (MonadInsertError m, MonadFinance m)
|
:: (MonadInsertError m, MonadFinance m)
|
||||||
=> NE.NonEmpty AcntType
|
=> NE.NonEmpty AcntType
|
||||||
-> AcntID
|
-> AcntID
|
||||||
-> m AcntID
|
-> m ()
|
||||||
checkAcntTypes ts i = go =<< lookupAccountType i
|
checkAcntTypes ts i = void $ go =<< lookupAccountType i
|
||||||
where
|
where
|
||||||
go t
|
go t
|
||||||
| t `L.elem` ts = return i
|
| t `L.elem` ts = return i
|
||||||
|
@ -499,6 +513,9 @@ initialCurrency :: BudgetCurrency -> CurID
|
||||||
initialCurrency (NoX c) = c
|
initialCurrency (NoX c) = c
|
||||||
initialCurrency (X Exchange {xFromCur = c}) = c
|
initialCurrency (X Exchange {xFromCur = c}) = c
|
||||||
|
|
||||||
|
alloAcnt :: Allocation w v -> AcntID
|
||||||
|
alloAcnt = taAcnt . alloTo
|
||||||
|
|
||||||
data UnbalancedValue = UnbalancedValue
|
data UnbalancedValue = UnbalancedValue
|
||||||
{ cvType :: !BudgetTransferType
|
{ cvType :: !BudgetTransferType
|
||||||
, cvValue :: !Rational
|
, cvValue :: !Rational
|
||||||
|
|
Loading…
Reference in New Issue