import * as isoly from "isoly" import { Account } from "../Account" export interface Transaction { from: Account to: Account amount: number currency: isoly.Currency schedule: isoly.Date | "hold" reference: string merchant: string mid?: string merchantId?: string purpose?: string } export namespace Transaction { export function is(value: any | Transaction): value is Transaction { return ( typeof value == "object" && value && Account.is(value.from) && Account.is(value.to) && typeof value.amount == "number" && isoly.Currency.is(value.currency) && (isoly.Date.is(value.schedule) || value.schedule == "hold") && typeof value.reference == "string" && typeof value.merchant == "string" && (value.mid == undefined || typeof value.mid == "string") && (value.merchantId == undefined || typeof value.merchantId == "string") && (value.purpose == undefined || typeof value.purpose == "string") ) } export function toCsv(transactions: Transaction[]): string { let result = "from,to,bic,internal,local account,amount,currency,schedule,settlement,merchant,mid,merchant id,purpose\r\n" for (const value of transactions) result += [ value.from, typeof value.to == "string" ? value.to : value.to.iban, typeof value.to != "string" ? value.to.bic ?? "" : "", typeof value.to != "string" && value.to.bic == "FTCSSESS" ? "y" : "", typeof value.to != "string" ? value.to.local ?? "" : "", value.amount, value.currency, value.schedule, value.reference, value.merchant, value.mid ?? "", value.merchantId ?? "", value.purpose ?? "", ] .map(v => `"${v}"`) .join(",") + "\r\n" return result } }