|
| 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: ['SEB_KORT_AB_SE_SKHSFI21'], |
| 10 | + |
| 11 | + normalizeAccount(account) { |
| 12 | + return { |
| 13 | + account_id: account.id, |
| 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 | + * Sign of transaction amount needs to be flipped for SEB credit cards |
| 25 | + */ |
| 26 | + normalizeTransaction(transaction, _booked) { |
| 27 | + return { |
| 28 | + ...transaction, |
| 29 | + // Creditor name is stored in additionInformation for SEB |
| 30 | + creditorName: transaction.additionalInformation, |
| 31 | + date: transaction.valueDate, |
| 32 | + transactionAmount: { |
| 33 | + // Flip transaction amount sign |
| 34 | + amount: (-parseFloat(transaction.transactionAmount.amount)).toString(), |
| 35 | + currency: transaction.transactionAmount.currency, |
| 36 | + }, |
| 37 | + }; |
| 38 | + }, |
| 39 | + |
| 40 | + sortTransactions(transactions = []) { |
| 41 | + return sortByBookingDateOrValueDate(transactions); |
| 42 | + }, |
| 43 | + |
| 44 | + /** |
| 45 | + * For SEB_KORT_AB_SE_SKHSFI21 we don't know what balance was |
| 46 | + * after each transaction so we have to calculate it by getting |
| 47 | + * current balance from the account and subtract all the transactions |
| 48 | + * |
| 49 | + * As a current balance we use `expected` balance type because it |
| 50 | + * corresponds to the current running balance, whereas `interimAvailable` |
| 51 | + * holds the remaining credit limit. |
| 52 | + */ |
| 53 | + calculateStartingBalance(sortedTransactions = [], balances = []) { |
| 54 | + const currentBalance = balances.find( |
| 55 | + (balance) => 'expected' === balance.balanceType, |
| 56 | + ); |
| 57 | + |
| 58 | + return sortedTransactions.reduce((total, trans) => { |
| 59 | + return total - amountToInteger(trans.transactionAmount.amount); |
| 60 | + }, -amountToInteger(currentBalance.balanceAmount.amount)); |
| 61 | + }, |
| 62 | +}; |
0 commit comments