From 29b26dcbc1404925bbf12cddd66f7fcd3c57cfe7 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Wed, 23 Jul 2025 20:25:55 +0200 Subject: hello --- app/Data/Ledger.hs | 10 +++++----- app/Import/Ing/Convert.hs | 31 ++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'app') diff --git a/app/Data/Ledger.hs b/app/Data/Ledger.hs index 53901cb..4aa5137 100644 --- a/app/Data/Ledger.hs +++ b/app/Data/Ledger.hs @@ -94,8 +94,8 @@ data Account = Account -- cleared and the balance of the account agrees with the amount in the -- assertion. data BalAssert = BalAssert - { account :: Account, - amount :: Integer, + { account :: AccountId, + amount :: Money, labels :: Labels } @@ -108,8 +108,8 @@ data Tx = Tx } deriving (Show, Generic) -data SeqTx = SeqTx [Integer] Tx +-- data SeqTx = SeqTx [Integer] Tx -data LedgerEntry = TxEntry SeqTx | BalAssertEntry BalAssert +data Entry = TxEntry Tx | BalAssertEntry BalAssert -data Ledger = Ledger [LedgerEntry] +data Ledger = Ledger [Entry] diff --git a/app/Import/Ing/Convert.hs b/app/Import/Ing/Convert.hs index 36ce99f..5dcda0b 100644 --- a/app/Import/Ing/Convert.hs +++ b/app/Import/Ing/Convert.hs @@ -8,6 +8,7 @@ import Data.Functor.Identity import Data.Iban qualified as Iban import Data.Ledger as L import Data.Map qualified as M +import Data.Res import Data.Text qualified as T import Import.Ing.CurrentAccountCsv as C import Import.Ing.SavingsAccountCsv as S @@ -21,12 +22,12 @@ virtSavingsAcc = AccountId ["Unfiled", "Savings"] virtCounterparty :: L.AccountId virtCounterparty = AccountId ["Unfiled", "Counterparty"] -toCents :: Decimal -> Either String L.Money +toCents :: Decimal -> Res String L.Money toCents m | f == 0 = return (L.Money m') | otherwise = - Left "Cannot convert to whole cents: amount of money is more specific" + fail "Cannot convert to whole cents: amount of money is more specific" where (m', f) = properFraction (m * 100) @@ -34,10 +35,30 @@ condUnitLabel :: UnitTag -> Bool -> L.Labels condUnitLabel _ False = empty condUnitLabel t True = singleton (UnitLabel t) (Identity ()) -fromCurrentAccTx :: CommodityId -> C.Tx -> Either String L.Tx -fromCurrentAccTx eucId (C.Tx base spec) = do +lesFromCurrentAcc :: CommodityId -> C.Tx -> Res String [L.Entry] +lesFromCurrentAcc eucId tx@(C.Tx base _) = do + tx' <- txFromCurrentAcc eucId tx + ba <- baFromCurrentAccBase base + return [BalAssertEntry ba, TxEntry tx'] + +baFromCurrentAccBase :: C.TxBase -> Res String L.BalAssert +baFromCurrentAccBase base = do + resBal <- toCents base.resBal + return $ + L.BalAssert + { account = virtCheckingAcc, + amount = resBal, + labels = + fromList [IbanLabel AccountTag ==> base.account] + } + +baFromCurrentAcc :: C.Tx -> Res String L.BalAssert +baFromCurrentAcc (C.Tx base _) = baFromCurrentAccBase base + +txFromCurrentAcc :: CommodityId -> C.Tx -> Res String L.Tx +txFromCurrentAcc eucId (C.Tx base spec) = do when (base.amount < 0) $ - Left "Transaction amount may not be lower than zero" + fail "Transaction amount may not be lower than zero" amount <- L.Amount <$> toCents base.amount case spec of PaymentTerminalPayment -- cgit v1.2.3