From d7117270c9abf1678a69ac0355843e3ceca2f728 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Mon, 22 May 2023 23:32:39 -0400 Subject: [PATCH] ADD negative amount lookup --- dhall/Types.dhall | 2 +- lib/Internal/Utils.hs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dhall/Types.dhall b/dhall/Types.dhall index 063c7c2..9f00d4a 100644 --- a/dhall/Types.dhall +++ b/dhall/Types.dhall @@ -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 = {- diff --git a/lib/Internal/Utils.hs b/lib/Internal/Utils.hs index 76db251..7bc8421 100644 --- a/lib/Internal/Utils.hs +++ b/lib/Internal/Utils.hs @@ -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