summaryrefslogtreecommitdiffstats
path: root/app/Import
diff options
context:
space:
mode:
Diffstat (limited to 'app/Import')
-rw-r--r--app/Import/Ing/Convert.hs31
1 files changed, 26 insertions, 5 deletions
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
8import Data.Iban qualified as Iban 8import Data.Iban qualified as Iban
9import Data.Ledger as L 9import Data.Ledger as L
10import Data.Map qualified as M 10import Data.Map qualified as M
11import Data.Res
11import Data.Text qualified as T 12import Data.Text qualified as T
12import Import.Ing.CurrentAccountCsv as C 13import Import.Ing.CurrentAccountCsv as C
13import Import.Ing.SavingsAccountCsv as S 14import Import.Ing.SavingsAccountCsv as S
@@ -21,12 +22,12 @@ virtSavingsAcc = AccountId ["Unfiled", "Savings"]
21virtCounterparty :: L.AccountId 22virtCounterparty :: L.AccountId
22virtCounterparty = AccountId ["Unfiled", "Counterparty"] 23virtCounterparty = AccountId ["Unfiled", "Counterparty"]
23 24
24toCents :: Decimal -> Either String L.Money 25toCents :: Decimal -> Res String L.Money
25toCents m 26toCents m
26 | f == 0 = 27 | f == 0 =
27 return (L.Money m') 28 return (L.Money m')
28 | otherwise = 29 | otherwise =
29 Left "Cannot convert to whole cents: amount of money is more specific" 30 fail "Cannot convert to whole cents: amount of money is more specific"
30 where 31 where
31 (m', f) = properFraction (m * 100) 32 (m', f) = properFraction (m * 100)
32 33
@@ -34,10 +35,30 @@ condUnitLabel :: UnitTag -> Bool -> L.Labels
34condUnitLabel _ False = empty 35condUnitLabel _ False = empty
35condUnitLabel t True = singleton (UnitLabel t) (Identity ()) 36condUnitLabel t True = singleton (UnitLabel t) (Identity ())
36 37
37fromCurrentAccTx :: CommodityId -> C.Tx -> Either String L.Tx 38lesFromCurrentAcc :: CommodityId -> C.Tx -> Res String [L.Entry]
38fromCurrentAccTx eucId (C.Tx base spec) = do 39lesFromCurrentAcc eucId tx@(C.Tx base _) = do
40 tx' <- txFromCurrentAcc eucId tx
41 ba <- baFromCurrentAccBase base
42 return [BalAssertEntry ba, TxEntry tx']
43
44baFromCurrentAccBase :: C.TxBase -> Res String L.BalAssert
45baFromCurrentAccBase base = do
46 resBal <- toCents base.resBal
47 return $
48 L.BalAssert
49 { account = virtCheckingAcc,
50 amount = resBal,
51 labels =
52 fromList [IbanLabel AccountTag ==> base.account]
53 }
54
55baFromCurrentAcc :: C.Tx -> Res String L.BalAssert
56baFromCurrentAcc (C.Tx base _) = baFromCurrentAccBase base
57
58txFromCurrentAcc :: CommodityId -> C.Tx -> Res String L.Tx
59txFromCurrentAcc eucId (C.Tx base spec) = do
39 when (base.amount < 0) $ 60 when (base.amount < 0) $
40 Left "Transaction amount may not be lower than zero" 61 fail "Transaction amount may not be lower than zero"
41 amount <- L.Amount <$> toCents base.amount 62 amount <- L.Amount <$> toCents base.amount
42 case spec of 63 case spec of
43 PaymentTerminalPayment 64 PaymentTerminalPayment