diff options
author | Rutger Broekhoff | 2025-08-25 19:48:19 +0200 |
---|---|---|
committer | Rutger Broekhoff | 2025-08-25 19:48:19 +0200 |
commit | 95d50b25c990e8c945ce2507b16ff3c8b039d286 (patch) | |
tree | c1ff4c7f9601c6980eed1a7235ba336c5c6f6106 /app/Import/Ing/Convert.hs | |
parent | 29b26dcbc1404925bbf12cddd66f7fcd3c57cfe7 (diff) | |
download | rdcapsis-95d50b25c990e8c945ce2507b16ff3c8b039d286.tar.gz rdcapsis-95d50b25c990e8c945ce2507b16ff3c8b039d286.zip |
OCaml
Diffstat (limited to 'app/Import/Ing/Convert.hs')
-rw-r--r-- | app/Import/Ing/Convert.hs | 257 |
1 files changed, 0 insertions, 257 deletions
diff --git a/app/Import/Ing/Convert.hs b/app/Import/Ing/Convert.hs deleted file mode 100644 index 5dcda0b..0000000 --- a/app/Import/Ing/Convert.hs +++ /dev/null | |||
@@ -1,257 +0,0 @@ | |||
1 | module Import.Ing.Convert where | ||
2 | |||
3 | import Control.Monad (when) | ||
4 | import Data.Decimal | ||
5 | import Data.Dependent.Map | ||
6 | import Data.Dependent.Sum ((==>)) | ||
7 | import Data.Functor.Identity | ||
8 | import Data.Iban qualified as Iban | ||
9 | import Data.Ledger as L | ||
10 | import Data.Map qualified as M | ||
11 | import Data.Res | ||
12 | import Data.Text qualified as T | ||
13 | import Import.Ing.CurrentAccountCsv as C | ||
14 | import Import.Ing.SavingsAccountCsv as S | ||
15 | |||
16 | virtCheckingAcc :: L.AccountId | ||
17 | virtCheckingAcc = AccountId ["Unfiled", "Checking"] | ||
18 | |||
19 | virtSavingsAcc :: L.AccountId | ||
20 | virtSavingsAcc = AccountId ["Unfiled", "Savings"] | ||
21 | |||
22 | virtCounterparty :: L.AccountId | ||
23 | virtCounterparty = AccountId ["Unfiled", "Counterparty"] | ||
24 | |||
25 | toCents :: Decimal -> Res String L.Money | ||
26 | toCents m | ||
27 | | f == 0 = | ||
28 | return (L.Money m') | ||
29 | | otherwise = | ||
30 | fail "Cannot convert to whole cents: amount of money is more specific" | ||
31 | where | ||
32 | (m', f) = properFraction (m * 100) | ||
33 | |||
34 | condUnitLabel :: UnitTag -> Bool -> L.Labels | ||
35 | condUnitLabel _ False = empty | ||
36 | condUnitLabel t True = singleton (UnitLabel t) (Identity ()) | ||
37 | |||
38 | lesFromCurrentAcc :: CommodityId -> C.Tx -> Res String [L.Entry] | ||
39 | lesFromCurrentAcc eucId tx@(C.Tx base _) = do | ||
40 | tx' <- txFromCurrentAcc eucId tx | ||
41 | ba <- baFromCurrentAccBase base | ||
42 | return [BalAssertEntry ba, TxEntry tx'] | ||
43 | |||
44 | baFromCurrentAccBase :: C.TxBase -> Res String L.BalAssert | ||
45 | baFromCurrentAccBase 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 | |||
55 | baFromCurrentAcc :: C.Tx -> Res String L.BalAssert | ||
56 | baFromCurrentAcc (C.Tx base _) = baFromCurrentAccBase base | ||
57 | |||
58 | txFromCurrentAcc :: CommodityId -> C.Tx -> Res String L.Tx | ||
59 | txFromCurrentAcc eucId (C.Tx base spec) = do | ||
60 | when (base.amount < 0) $ | ||
61 | fail "Transaction amount may not be lower than zero" | ||
62 | amount <- L.Amount <$> toCents base.amount | ||
63 | case spec of | ||
64 | PaymentTerminalPayment | ||
65 | { counterpartyName, | ||
66 | cardSequenceNo, | ||
67 | timestamp, | ||
68 | transaction, | ||
69 | terminal, | ||
70 | googlePay | ||
71 | } -> | ||
72 | return $ | ||
73 | L.Tx | ||
74 | { cleared = Just base.date, | ||
75 | commodityId = eucId, | ||
76 | credit = M.singleton virtCheckingAcc amount, | ||
77 | debit = M.singleton virtCounterparty amount, | ||
78 | labels = | ||
79 | fromList | ||
80 | [ IbanLabel AccountTag ==> base.account, | ||
81 | TextLabel CounterpartyNameTag ==> counterpartyName, | ||
82 | TextLabel CardSeqNoTag ==> cardSequenceNo, | ||
83 | TextLabel TerminalTag ==> terminal, | ||
84 | TextLabel TransactionTag ==> transaction, | ||
85 | TimestampLabel ==> timestamp | ||
86 | ] | ||
87 | `union` condUnitLabel GooglePayTag googlePay | ||
88 | } | ||
89 | PaymentTerminalCashback | ||
90 | { counterpartyName, | ||
91 | cardSequenceNo, | ||
92 | timestamp, | ||
93 | transaction, | ||
94 | terminal | ||
95 | } -> | ||
96 | return $ | ||
97 | L.Tx | ||
98 | { cleared = Just base.date, | ||
99 | commodityId = eucId, | ||
100 | debit = M.singleton virtCheckingAcc amount, | ||
101 | credit = M.singleton virtCounterparty amount, | ||
102 | labels = | ||
103 | fromList | ||
104 | [ IbanLabel AccountTag ==> base.account, | ||
105 | TextLabel CounterpartyNameTag ==> counterpartyName, | ||
106 | TextLabel CardSeqNoTag ==> cardSequenceNo, | ||
107 | TextLabel TerminalTag ==> terminal, | ||
108 | TextLabel TransactionTag ==> transaction, | ||
109 | TimestampLabel ==> timestamp | ||
110 | ] | ||
111 | } | ||
112 | OnlineBankingCredit | ||
113 | { counterpartyName, | ||
114 | counterpartyIban, | ||
115 | description, | ||
116 | timestamp | ||
117 | } -> | ||
118 | return $ | ||
119 | L.Tx | ||
120 | { cleared = Just base.date, | ||
121 | commodityId = eucId, | ||
122 | debit = M.singleton virtCheckingAcc amount, | ||
123 | credit = M.singleton virtCounterparty amount, | ||
124 | labels = | ||
125 | fromList | ||
126 | [ IbanLabel AccountTag ==> base.account, | ||
127 | TextLabel CounterpartyNameTag ==> counterpartyName, | ||
128 | IbanLabel CounterpartyIbanTag ==> counterpartyIban, | ||
129 | TextLabel DescTag ==> description, | ||
130 | TimestampLabel ==> timestamp | ||
131 | ] | ||
132 | } | ||
133 | OnlineBankingDebit | ||
134 | { counterpartyName, | ||
135 | counterpartyIban, | ||
136 | description, | ||
137 | mtimestamp | ||
138 | } -> | ||
139 | return $ | ||
140 | L.Tx | ||
141 | { cleared = Just base.date, | ||
142 | commodityId = eucId, | ||
143 | debit = M.singleton virtCounterparty amount, | ||
144 | credit = M.singleton virtCheckingAcc amount, | ||
145 | labels = | ||
146 | fromList | ||
147 | [ IbanLabel AccountTag ==> base.account, | ||
148 | TextLabel CounterpartyNameTag ==> counterpartyName, | ||
149 | IbanLabel CounterpartyIbanTag ==> counterpartyIban, | ||
150 | TextLabel DescTag ==> description | ||
151 | ] | ||
152 | `union` (maybe empty (singleton TimestampLabel . Identity) mtimestamp) | ||
153 | } | ||
154 | RecurrentDirectDebit | ||
155 | { counterpartyName, | ||
156 | counterpartyIban, | ||
157 | description, | ||
158 | reference, | ||
159 | mandateId, | ||
160 | creditorId, | ||
161 | otherParty | ||
162 | } -> | ||
163 | return $ | ||
164 | L.Tx | ||
165 | { cleared = Just base.date, | ||
166 | commodityId = eucId, | ||
167 | credit = M.singleton virtCheckingAcc amount, | ||
168 | debit = M.singleton virtCounterparty amount, | ||
169 | labels = | ||
170 | fromList | ||
171 | [ IbanLabel AccountTag ==> base.account, | ||
172 | IbanLabel CounterpartyIbanTag ==> counterpartyIban, | ||
173 | TextLabel CounterpartyNameTag ==> counterpartyName, | ||
174 | TextLabel DescTag ==> description, | ||
175 | TextLabel ReferenceTag ==> reference, | ||
176 | TextLabel MandateIdTag ==> mandateId, | ||
177 | TextLabel CreditorIdTag ==> creditorId | ||
178 | ] | ||
179 | `union` (maybe empty (singleton (TextLabel OtherPartyTag) . Identity) otherParty) | ||
180 | } | ||
181 | RoundingSavingsDeposit | ||
182 | { savingsAccount | ||
183 | } -> | ||
184 | return $ | ||
185 | L.Tx | ||
186 | { cleared = Just base.date, | ||
187 | commodityId = eucId, | ||
188 | credit = M.singleton virtCheckingAcc amount, | ||
189 | debit = M.singleton virtSavingsAcc amount, | ||
190 | labels = | ||
191 | fromList | ||
192 | [ UnitLabel AutoRoundSavingsTag ==> (), | ||
193 | TextLabel SavingsAccountTag ==> savingsAccount | ||
194 | ] | ||
195 | } | ||
196 | DepositTransfer | ||
197 | { counterpartyName, | ||
198 | counterpartyIban, | ||
199 | description, | ||
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 | ] | ||
215 | } | ||
216 | IdealDebit | ||
217 | { counterpartyName, | ||
218 | counterpartyIban, | ||
219 | description, | ||
220 | timestamp, | ||
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 | TimestampLabel ==> timestamp | ||
236 | ] | ||
237 | } | ||
238 | BatchPayment | ||
239 | { counterpartyName, | ||
240 | counterpartyIban, | ||
241 | description, | ||
242 | reference | ||
243 | } -> | ||
244 | return $ | ||
245 | L.Tx | ||
246 | { cleared = Just base.date, | ||
247 | commodityId = eucId, | ||
248 | debit = M.singleton virtCheckingAcc amount, | ||
249 | credit = M.singleton virtCounterparty amount, | ||
250 | labels = | ||
251 | fromList | ||
252 | [ IbanLabel CounterpartyIbanTag ==> counterpartyIban, | ||
253 | TextLabel CounterpartyNameTag ==> counterpartyName, | ||
254 | TextLabel DescTag ==> description, | ||
255 | TextLabel ReferenceTag ==> reference | ||
256 | ] | ||
257 | } | ||