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
AmountN: the value of the 'Amount' column
-}
< LookupN : Text | ConstN : Double | AmountN >
< LookupN : Text | ConstN : Double | AmountN | NegAmountN >
let EntryTextGetter =
{-

View File

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