ADD negative amount lookup

This commit is contained in:
Nathan Dwarshuis 2023-05-22 23:32:39 -04:00
parent 4f44e37462
commit d7117270c9
2 changed files with 7 additions and 5 deletions

View File

@ -404,7 +404,7 @@ let EntryNumGetter =
ConstN: a constant value ConstN: a constant value
AmountN: the value of the 'Amount' column AmountN: the value of the 'Amount' column
-} -}
< LookupN : Text | ConstN : Double | AmountN > < LookupN : Text | ConstN : Double | AmountN | NegAmountN >
let EntryTextGetter = let EntryTextGetter =
{- {-

View File

@ -343,11 +343,13 @@ collectErrorsIO :: MonadUnliftIO m => [m a] -> m [a]
collectErrorsIO = mapErrorsIO id collectErrorsIO = mapErrorsIO id
resolveValue :: TxRecord -> EntryNumGetter -> InsertExcept Double resolveValue :: TxRecord -> EntryNumGetter -> InsertExcept Double
resolveValue r s = case s of resolveValue TxRecord {trOther, trAmount} s = case s of
(LookupN t) -> readDouble =<< lookupErr SplitValField t (trOther r) (LookupN t) -> readDouble =<< lookupErr SplitValField t trOther
(ConstN c) -> return c (ConstN c) -> return c
-- TODO don't coerce to rational in trAmount AmountN -> return a
AmountN -> return $ fromRational $ trAmount r NegAmountN -> return $ negate a
where
a = fromRational trAmount
resolveAcnt :: TxRecord -> SplitAcnt -> InsertExcept T.Text resolveAcnt :: TxRecord -> SplitAcnt -> InsertExcept T.Text
resolveAcnt = resolveSplitField AcntField resolveAcnt = resolveSplitField AcntField