2024-12-23 16:47:07 +01:00
|
|
|
import type { Transaction } from "@/bank/sparebank1.ts"
|
2024-12-01 19:35:45 +01:00
|
|
|
import type { UUID } from "node:crypto"
|
2025-01-25 18:01:47 +01:00
|
|
|
import dayjs from "dayjs"
|
|
|
|
import { toISODateString } from "@/date.ts"
|
|
|
|
import { type ActualTransaction } from "@/actual.ts"
|
2024-11-17 22:27:29 +01:00
|
|
|
|
2024-12-01 20:48:42 +01:00
|
|
|
export function bankTransactionIntoActualTransaction(
|
2024-11-17 22:27:29 +01:00
|
|
|
transaction: Transaction,
|
2024-12-01 19:35:45 +01:00
|
|
|
accountId: UUID,
|
2025-01-25 18:01:47 +01:00
|
|
|
): ActualTransaction {
|
2024-11-17 22:27:29 +01:00
|
|
|
return {
|
|
|
|
id: transaction.id,
|
2024-12-01 20:48:42 +01:00
|
|
|
// Transactions with the same id will be ignored
|
2025-01-25 18:01:47 +01:00
|
|
|
imported_id: transaction.nonUniqueId,
|
2024-12-01 19:35:45 +01:00
|
|
|
account: accountId,
|
2024-12-01 20:48:42 +01:00
|
|
|
// The value without decimals
|
|
|
|
amount: transaction.amount * 100,
|
2025-01-25 18:01:47 +01:00
|
|
|
date: toISODateString(dayjs(transaction.date)),
|
|
|
|
payee_name: transaction.cleanedDescription,
|
2025-01-31 16:58:02 +01:00
|
|
|
// TODO if not cleared or nonUniqueId is 0, rerun later
|
2025-01-27 21:30:56 +01:00
|
|
|
cleared: transaction.bookingStatus === "BOOKED",
|
2024-11-17 22:27:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO take the account from the bank and match it to the actual account
|
|
|
|
// Use ENV
|
|
|
|
export function bankAccountIntoActualAccount(account: string): string {
|
|
|
|
throw new Error("Not implemented")
|
|
|
|
}
|