summaryrefslogtreecommitdiffstats
path: root/app/Import/Ing
diff options
context:
space:
mode:
Diffstat (limited to 'app/Import/Ing')
-rw-r--r--app/Import/Ing/Convert.hs140
1 files changed, 125 insertions, 15 deletions
diff --git a/app/Import/Ing/Convert.hs b/app/Import/Ing/Convert.hs
index 712c8a4..36ce99f 100644
--- a/app/Import/Ing/Convert.hs
+++ b/app/Import/Ing/Convert.hs
@@ -12,11 +12,14 @@ import Data.Text qualified as T
12import Import.Ing.CurrentAccountCsv as C 12import Import.Ing.CurrentAccountCsv as C
13import Import.Ing.SavingsAccountCsv as S 13import Import.Ing.SavingsAccountCsv as S
14 14
15virtCheckingAccount :: Iban.Iban -> L.AccountId 15virtCheckingAcc :: L.AccountId
16virtCheckingAccount iban = AccountId ["Unfiled", "Asset", "Current", "Checking", "Iban", Iban.toText iban] 16virtCheckingAcc = AccountId ["Unfiled", "Checking"]
17 17
18virtCounterparty :: T.Text -> L.AccountId 18virtSavingsAcc :: L.AccountId
19virtCounterparty name = AccountId ["Unfiled", "Expenses", "Counterparty", "Name", name] 19virtSavingsAcc = AccountId ["Unfiled", "Savings"]
20
21virtCounterparty :: L.AccountId
22virtCounterparty = AccountId ["Unfiled", "Counterparty"]
20 23
21toCents :: Decimal -> Either String L.Money 24toCents :: Decimal -> Either String L.Money
22toCents m 25toCents m
@@ -31,9 +34,8 @@ condUnitLabel :: UnitTag -> Bool -> L.Labels
31condUnitLabel _ False = empty 34condUnitLabel _ False = empty
32condUnitLabel t True = singleton (UnitLabel t) (Identity ()) 35condUnitLabel t True = singleton (UnitLabel t) (Identity ())
33 36
34fromCurrentAccountTx :: CommodityId -> C.Tx -> Either String L.Tx 37fromCurrentAccTx :: CommodityId -> C.Tx -> Either String L.Tx
35fromCurrentAccountTx eucId (C.Tx base spec) = do 38fromCurrentAccTx eucId (C.Tx base spec) = do
36 let acc = virtCheckingAccount base.account
37 when (base.amount < 0) $ 39 when (base.amount < 0) $
38 Left "Transaction amount may not be lower than zero" 40 Left "Transaction amount may not be lower than zero"
39 amount <- L.Amount <$> toCents base.amount 41 amount <- L.Amount <$> toCents base.amount
@@ -50,11 +52,12 @@ fromCurrentAccountTx eucId (C.Tx base spec) = do
50 L.Tx 52 L.Tx
51 { cleared = Just base.date, 53 { cleared = Just base.date,
52 commodityId = eucId, 54 commodityId = eucId,
53 credit = M.singleton acc amount, 55 credit = M.singleton virtCheckingAcc amount,
54 debit = M.singleton (virtCounterparty counterpartyName) amount, 56 debit = M.singleton virtCounterparty amount,
55 labels = 57 labels =
56 fromList 58 fromList
57 [ IbanLabel AccountTag ==> base.account, 59 [ IbanLabel AccountTag ==> base.account,
60 TextLabel CounterpartyNameTag ==> counterpartyName,
58 TextLabel CardSeqNoTag ==> cardSequenceNo, 61 TextLabel CardSeqNoTag ==> cardSequenceNo,
59 TextLabel TerminalTag ==> terminal, 62 TextLabel TerminalTag ==> terminal,
60 TextLabel TransactionTag ==> transaction, 63 TextLabel TransactionTag ==> transaction,
@@ -73,11 +76,12 @@ fromCurrentAccountTx eucId (C.Tx base spec) = do
73 L.Tx 76 L.Tx
74 { cleared = Just base.date, 77 { cleared = Just base.date,
75 commodityId = eucId, 78 commodityId = eucId,
76 debit = M.singleton acc amount, 79 debit = M.singleton virtCheckingAcc amount,
77 credit = M.singleton (virtCounterparty counterpartyName) amount, 80 credit = M.singleton virtCounterparty amount,
78 labels = 81 labels =
79 fromList 82 fromList
80 [ IbanLabel AccountTag ==> base.account, 83 [ IbanLabel AccountTag ==> base.account,
84 TextLabel CounterpartyNameTag ==> counterpartyName,
81 TextLabel CardSeqNoTag ==> cardSequenceNo, 85 TextLabel CardSeqNoTag ==> cardSequenceNo,
82 TextLabel TerminalTag ==> terminal, 86 TextLabel TerminalTag ==> terminal,
83 TextLabel TransactionTag ==> transaction, 87 TextLabel TransactionTag ==> transaction,
@@ -94,11 +98,12 @@ fromCurrentAccountTx eucId (C.Tx base spec) = do
94 L.Tx 98 L.Tx
95 { cleared = Just base.date, 99 { cleared = Just base.date,
96 commodityId = eucId, 100 commodityId = eucId,
97 debit = M.singleton acc amount, 101 debit = M.singleton virtCheckingAcc amount,
98 credit = M.singleton (virtCounterparty counterpartyName) amount, 102 credit = M.singleton virtCounterparty amount,
99 labels = 103 labels =
100 fromList 104 fromList
101 [ IbanLabel AccountTag ==> base.account, 105 [ IbanLabel AccountTag ==> base.account,
106 TextLabel CounterpartyNameTag ==> counterpartyName,
102 IbanLabel CounterpartyIbanTag ==> counterpartyIban, 107 IbanLabel CounterpartyIbanTag ==> counterpartyIban,
103 TextLabel DescTag ==> description, 108 TextLabel DescTag ==> description,
104 TimestampLabel ==> timestamp 109 TimestampLabel ==> timestamp
@@ -114,13 +119,118 @@ fromCurrentAccountTx eucId (C.Tx base spec) = do
114 L.Tx 119 L.Tx
115 { cleared = Just base.date, 120 { cleared = Just base.date,
116 commodityId = eucId, 121 commodityId = eucId,
117 debit = M.singleton (virtCounterparty counterpartyName) amount, 122 debit = M.singleton virtCounterparty amount,
118 credit = M.singleton acc amount, 123 credit = M.singleton virtCheckingAcc amount,
119 labels = 124 labels =
120 fromList 125 fromList
121 [ IbanLabel AccountTag ==> base.account, 126 [ IbanLabel AccountTag ==> base.account,
127 TextLabel CounterpartyNameTag ==> counterpartyName,
122 IbanLabel CounterpartyIbanTag ==> counterpartyIban, 128 IbanLabel CounterpartyIbanTag ==> counterpartyIban,
123 TextLabel DescTag ==> description 129 TextLabel DescTag ==> description
124 ] 130 ]
125 `union` (maybe empty (singleton TimestampLabel . Identity) mtimestamp) 131 `union` (maybe empty (singleton TimestampLabel . Identity) mtimestamp)
126 } 132 }
133 RecurrentDirectDebit
134 { counterpartyName,
135 counterpartyIban,
136 description,
137 reference,
138 mandateId,
139 creditorId,
140 otherParty
141 } ->
142 return $
143 L.Tx
144 { cleared = Just base.date,
145 commodityId = eucId,
146 credit = M.singleton virtCheckingAcc amount,
147 debit = M.singleton virtCounterparty amount,
148 labels =
149 fromList
150 [ IbanLabel AccountTag ==> base.account,
151 IbanLabel CounterpartyIbanTag ==> counterpartyIban,
152 TextLabel CounterpartyNameTag ==> counterpartyName,
153 TextLabel DescTag ==> description,
154 TextLabel ReferenceTag ==> reference,
155 TextLabel MandateIdTag ==> mandateId,
156 TextLabel CreditorIdTag ==> creditorId
157 ]
158 `union` (maybe empty (singleton (TextLabel OtherPartyTag) . Identity) otherParty)
159 }
160 RoundingSavingsDeposit
161 { savingsAccount
162 } ->
163 return $
164 L.Tx
165 { cleared = Just base.date,
166 commodityId = eucId,
167 credit = M.singleton virtCheckingAcc amount,
168 debit = M.singleton virtSavingsAcc amount,
169 labels =
170 fromList
171 [ UnitLabel AutoRoundSavingsTag ==> (),
172 TextLabel SavingsAccountTag ==> savingsAccount
173 ]
174 }
175 DepositTransfer
176 { counterpartyName,
177 counterpartyIban,
178 description,
179 reference
180 } ->
181 return $
182 L.Tx
183 { cleared = Just base.date,
184 commodityId = eucId,
185 debit = M.singleton virtCheckingAcc amount,
186 credit = M.singleton virtCounterparty amount,
187 labels =
188 fromList
189 [ IbanLabel CounterpartyIbanTag ==> counterpartyIban,
190 TextLabel CounterpartyNameTag ==> counterpartyName,
191 TextLabel DescTag ==> description,
192 TextLabel ReferenceTag ==> reference
193 ]
194 }
195 IdealDebit
196 { counterpartyName,
197 counterpartyIban,
198 description,
199 timestamp,
200 reference
201 } ->
202 return $
203 L.Tx
204 { cleared = Just base.date,
205 commodityId = eucId,
206 debit = M.singleton virtCheckingAcc amount,
207 credit = M.singleton virtCounterparty amount,
208 labels =
209 fromList
210 [ IbanLabel CounterpartyIbanTag ==> counterpartyIban,
211 TextLabel CounterpartyNameTag ==> counterpartyName,
212 TextLabel DescTag ==> description,
213 TextLabel ReferenceTag ==> reference,
214 TimestampLabel ==> timestamp
215 ]
216 }
217 BatchPayment
218 { counterpartyName,
219 counterpartyIban,
220 description,
221 reference
222 } ->
223 return $
224 L.Tx
225 { cleared = Just base.date,
226 commodityId = eucId,
227 debit = M.singleton virtCheckingAcc amount,
228 credit = M.singleton virtCounterparty amount,
229 labels =
230 fromList
231 [ IbanLabel CounterpartyIbanTag ==> counterpartyIban,
232 TextLabel CounterpartyNameTag ==> counterpartyName,
233 TextLabel DescTag ==> description,
234 TextLabel ReferenceTag ==> reference
235 ]
236 }