1
+ import {
2
+ printIban ,
3
+ amountToInteger ,
4
+ sortByBookingDateOrValueDate ,
5
+ } from '../utils.js' ;
6
+
7
+ /** @type {import('./bank.interface.js').IBank } */
8
+ export default {
9
+ institutionIds : [ 'ANDELSKASSEN_FALLESKASSEN_FAELDKK1' ] ,
10
+
11
+ normalizeAccount ( account ) {
12
+ return {
13
+ account_id : account . resourceId ,
14
+ institution : account . institution ,
15
+ mask : account . iban . slice ( - 4 ) ,
16
+ iban : account . iban ,
17
+ name : [ account . name , printIban ( account ) ] . join ( ' ' ) ,
18
+ official_name : account . product ,
19
+ type : 'checking' ,
20
+ } ;
21
+ } ,
22
+
23
+ /**
24
+ * Following the GoCardless documentation[0] we should prefer `bookingDate`
25
+ * here, though some of their bank integrations uses the date field
26
+ * differently from what's describen in their documentation and so it's
27
+ * sometimes necessary to use `valueDate` instead.
28
+ *
29
+ * [0]: https://nordigen.zendesk.com/hc/en-gb/articles/7899367372829-valueDate-and-bookingDate-for-transactions
30
+ */
31
+ normalizeTransaction ( transaction , _booked ) {
32
+ return {
33
+ ...transaction ,
34
+ date : transaction . bookingDate ,
35
+ remittanceInformationUnstructured : transaction . additionalInformation ,
36
+ } ;
37
+ } ,
38
+
39
+ sortTransactions ( transactions = [ ] ) {
40
+ return sortByBookingDateOrValueDate ( transactions ) ;
41
+ } ,
42
+
43
+ /**
44
+ * For SANDBOXFINANCE_SFIN0000 we don't know what balance was
45
+ * after each transaction so we have to calculate it by getting
46
+ * current balance from the account and subtract all the transactions
47
+ *
48
+ * As a current balance we use `interimBooked` balance type because
49
+ * it includes transaction placed during current day
50
+ */
51
+ calculateStartingBalance ( sortedTransactions = [ ] , balances = [ ] ) {
52
+ const currentBalance = balances . find (
53
+ ( balance ) => 'closingBooked' === balance . balanceType ,
54
+ ) ;
55
+
56
+ return sortedTransactions . reduce ( ( total , trans ) => {
57
+ return total - amountToInteger ( trans . transactionAmount . amount ) ;
58
+ } , amountToInteger ( currentBalance . balanceAmount . amount ) ) ;
59
+ } ,
60
+ } ;
0 commit comments