import { ICurrency } from '~src/models/market/currency'; export interface ITransaction { id?: number; externalId: number; description: string | null; type: string | null; subtype: string | null; units: number | null; date: Date | null; sharePrice: number | null; shares: number | null; cost: number | null; value: number | null; holdingId: number | null; eventId: number | null; currency: ICurrency | null; status: ITransactionStatus | null; } export enum ITransactionStatus { confirmed, expected, cancelled, } export function parseTransaction(transaction: ITransaction): ITransaction { transaction.id = +transaction.id; transaction.externalId = +transaction.externalId; transaction.date = new Date(transaction.date); transaction.value = +transaction.value; transaction.shares = +transaction.shares; transaction.sharePrice = +transaction.sharePrice; transaction.cost = +transaction.cost; transaction.status = +transaction.status; return transaction; } export const transactionTypes: string[] = [ 'buy', 'sell', 'dividend', 'dividendReinvest', 'sharesAdd', 'sharesRemove', 'splitShares', 'withdrawal', 'deposit', 'interest', 'cost', 'wrongPayment', 'revenueFee', ]; export const transactionSubtypes: string[] = [ 'accountingCost', 'adminCost', 'bankCost', 'businessCost', 'externalCost', 'legalCost', 'mealCost', 'officeCost', 'salaryCost', 'taxCost', ]; export interface ITransactionProperties { id?: boolean; externalId?: boolean; description?: boolean; date?: boolean; type?: boolean; subtype?: boolean; value?: boolean; sharePrice?: boolean; shares?: boolean; cost?: boolean; units?: boolean; currency?: boolean; status?: boolean; holdingId?: boolean; } export interface ITransactionPropertiesConfig { properties: ITransactionProperties; relationProperties?: {}; } export function defaultTransactionProperties(): ITransactionProperties { return { id: true, externalId: true, description: true, date: true, type: true, subtype: true, value: true, sharePrice: true, shares: true, cost: true, units: true, currency: true, status: true, holdingId: true, }; } export function defaultTransactionPropertiesConfig(): ITransactionPropertiesConfig { return { properties: defaultTransactionProperties(), }; }