30 lines
967 B
TypeScript
Raw Normal View History

import type { Transaction } from "@/bank/sparebank1.ts"
import type { UUID } from "node:crypto"
import dayjs from "dayjs"
import { toISODateString } from "@/date.ts"
import { type ActualTransaction } from "@/actual.ts"
export function bankTransactionIntoActualTransaction(
transaction: Transaction,
accountId: UUID,
): ActualTransaction {
return {
id: transaction.id,
// Transactions with the same id will be ignored
imported_id: transaction.nonUniqueId,
account: accountId,
// The value without decimals
amount: transaction.amount * 100,
date: toISODateString(dayjs(transaction.date)),
payee_name: transaction.cleanedDescription,
// TODO if not cleared, rerun later
cleared: transaction.bookingStatus === "BOOKED",
}
}
// 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")
}