@things-factory/accounting 10.1.208 → 10.1.210
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/service/account/account-match.d.ts +4 -5
- package/dist-server/service/account/account-match.js +7 -8
- package/dist-server/service/account/account-match.js.map +1 -1
- package/dist-server/service/expenditure-request/expenditure-request-mutation.d.ts +1 -1
- package/dist-server/service/expenditure-request/expenditure-request-mutation.js +5 -4
- package/dist-server/service/expenditure-request/expenditure-request-mutation.js.map +1 -1
- package/dist-server/service/expenditure-request/expenditure-request-service.d.ts +2 -0
- package/dist-server/service/expenditure-request/expenditure-request-service.js +17 -0
- package/dist-server/service/expenditure-request/expenditure-request-service.js.map +1 -1
- package/dist-server/service/expenditure-request/index.d.ts +2 -2
- package/dist-server/service/financial-statement/index.d.ts +1 -1
- package/dist-server/service/index.d.ts +1 -1
- package/dist-server/service/recurring-cash-item/recurring-cash-item-mutation.d.ts +0 -1
- package/dist-server/service/recurring-cash-item/recurring-cash-item-mutation.js +0 -17
- package/dist-server/service/recurring-cash-item/recurring-cash-item-mutation.js.map +1 -1
- package/dist-server/service/recurring-cash-item/recurring-cash-item-service.d.ts +2 -9
- package/dist-server/service/recurring-cash-item/recurring-cash-item-service.js +2 -39
- package/dist-server/service/recurring-cash-item/recurring-cash-item-service.js.map +1 -1
- package/dist-server/service/recurring-cash-item/recurring-cash-item-type.js +1 -1
- package/dist-server/service/recurring-cash-item/recurring-cash-item-type.js.map +1 -1
- package/dist-server/service/recurring-cash-item/recurring-cash-item.d.ts +2 -2
- package/dist-server/service/recurring-cash-item/recurring-cash-item.js +5 -5
- package/dist-server/service/recurring-cash-item/recurring-cash-item.js.map +1 -1
- package/dist-server/service/recurring-cash-item/recurring-schedule.d.ts +6 -18
- package/dist-server/service/recurring-cash-item/recurring-schedule.js +13 -26
- package/dist-server/service/recurring-cash-item/recurring-schedule.js.map +1 -1
- package/dist-server/service/transaction/transaction-history.d.ts +1 -7
- package/dist-server/service/transaction/transaction-history.js +0 -25
- package/dist-server/service/transaction/transaction-history.js.map +1 -1
- package/dist-server/service/transaction/transaction-period.d.ts +0 -8
- package/dist-server/service/transaction/transaction-period.js +0 -30
- package/dist-server/service/transaction/transaction-period.js.map +1 -1
- package/dist-server/service/transaction/transaction-query.d.ts +0 -2
- package/dist-server/service/transaction/transaction-query.js +2 -16
- package/dist-server/service/transaction/transaction-query.js.map +1 -1
- package/dist-server/service/transaction/transaction-service.d.ts +1 -4
- package/dist-server/service/transaction/transaction-service.js +6 -31
- package/dist-server/service/transaction/transaction-service.js.map +1 -1
- package/dist-server/service/transaction/transaction-type.d.ts +1 -15
- package/dist-server/service/transaction/transaction-type.js +2 -58
- package/dist-server/service/transaction/transaction-type.js.map +1 -1
- package/dist-server/service/transaction/transaction.d.ts +6 -15
- package/dist-server/service/transaction/transaction.js +13 -52
- package/dist-server/service/transaction/transaction.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/translations/en.json +4 -5
- package/translations/es.json +4 -5
- package/translations/ja.json +4 -1
- package/translations/ko.json +4 -5
- package/translations/ms.json +4 -1
- package/translations/zh.json +4 -1
|
@@ -8,7 +8,6 @@ const biz_base_1 = require("@things-factory/biz-base");
|
|
|
8
8
|
const account_1 = require("../account/account");
|
|
9
9
|
const bank_account_1 = require("../bank-account/bank-account");
|
|
10
10
|
const bank_statement_1 = require("../bank-statement/bank-statement");
|
|
11
|
-
const recurring_cash_item_1 = require("../recurring-cash-item/recurring-cash-item");
|
|
12
11
|
const cash_flow_type_1 = require("../cash-flow-type");
|
|
13
12
|
const payment_1 = require("../payment/payment");
|
|
14
13
|
const payment_currency_1 = require("../payment/payment-currency");
|
|
@@ -38,21 +37,16 @@ function protectBankFacts(current, patch) {
|
|
|
38
37
|
const REFERENCES = [
|
|
39
38
|
['account', () => account_1.Account],
|
|
40
39
|
['counterparty', () => biz_base_1.Counterparty],
|
|
41
|
-
['recurringItem', () => recurring_cash_item_1.RecurringCashItem],
|
|
42
40
|
['bankStatement', () => bank_statement_1.BankStatement]
|
|
43
41
|
];
|
|
44
42
|
/** What its payments depend on - they are checked again, and their owners follow, when one of these changes. */
|
|
45
43
|
const FACTS = ['amount', 'type', 'currency', 'transactionDate'];
|
|
46
|
-
/**
|
|
47
|
-
* The row a patch writes over the current one: a confirmed transaction has a day and takes its year and month from it;
|
|
48
|
-
* a forecast has a year and a month, and the day its timing names.
|
|
49
|
-
*/
|
|
44
|
+
/** The row a patch writes over the current one: a transaction has a day and takes its year and month from it. */
|
|
50
45
|
function rowOf(input, current) {
|
|
51
46
|
const { id, cuFlag, ...fields } = input;
|
|
52
47
|
const row = { ...fields };
|
|
53
48
|
const merged = { ...current, ...row };
|
|
54
|
-
|
|
55
|
-
row.category = category;
|
|
49
|
+
row.category = transaction_1.TransactionCategory.CONFIRMED;
|
|
56
50
|
if (!current && !row.type)
|
|
57
51
|
throw new shell_1.Refusal('transaction-type-required', {}, 'type: money in or money out');
|
|
58
52
|
if (row.type !== undefined && !Object.values(cash_flow_type_1.CashFlowType).includes(row.type))
|
|
@@ -62,29 +56,10 @@ function rowOf(input, current) {
|
|
|
62
56
|
/* An emptied currency is won, the column's own default - a row is never without one. */
|
|
63
57
|
if ('currency' in row && !row.currency)
|
|
64
58
|
row.currency = 'KRW';
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
Object.assign(row, period, { status: null });
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
const [year, month] = [Number(merged.year), Number(merged.month)];
|
|
73
|
-
if (!year)
|
|
74
|
-
throw new shell_1.Refusal('forecast-year-required', {}, 'year: the year it is planned in');
|
|
75
|
-
if (!(month >= 1 && month <= 12))
|
|
76
|
-
throw new shell_1.Refusal('month-out-of-range', { month: merged.month ?? '' }, 'month: must be 1 to 12');
|
|
77
|
-
if (!String(merged.description ?? '').trim())
|
|
78
|
-
throw new shell_1.Refusal('forecast-description-required', {}, 'description: what is planned');
|
|
79
|
-
Object.assign(row, { year, month, transactionDate: (0, transaction_period_1.forecastDay)(year, month, merged.timing) });
|
|
80
|
-
if (!merged.status)
|
|
81
|
-
row.status = transaction_1.ForecastStatus.PLANNED;
|
|
82
|
-
}
|
|
83
|
-
if (merged.probability !== undefined &&
|
|
84
|
-
merged.probability !== null &&
|
|
85
|
-
!(merged.probability >= 0 && merged.probability <= 100)) {
|
|
86
|
-
throw new shell_1.Refusal('probability-out-of-range', {}, 'probability: must be 0 to 100');
|
|
87
|
-
}
|
|
59
|
+
const period = (0, transaction_period_1.yearMonthOf)(merged.transactionDate);
|
|
60
|
+
if (!period)
|
|
61
|
+
throw new shell_1.Refusal('transaction-date-required', { value: merged.transactionDate ?? '' }, 'transactionDate: YYYY-MM-DD');
|
|
62
|
+
Object.assign(row, period);
|
|
88
63
|
return row;
|
|
89
64
|
}
|
|
90
65
|
/** The payments on these transactions, and the transfers into them, by target kind. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-service.js","sourceRoot":"","sources":["../../../server/service/transaction/transaction-service.ts"],"names":[],"mappings":";;AAmCA,4CAYC;AAqFD,4CAmFC;AAvND,qCAA2C;AAE3C,iDAA+D;AAE/D,uDAAuD;AAEvD,gDAA4C;AAC5C,+DAA0D;AAC1D,qEAAgE;AAChE,oFAA8E;AAC9E,sDAAgD;AAChD,gDAA4C;AAC5C,kEAAoE;AACpE,gEAAgE;AAChE,gEAA0E;AAC1E,+CAAmG;AACnG,6DAA+D;AAe/D,uHAAuH;AACvH,MAAM,UAAU,GAAG,CAAC,iBAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,CAAU,CAAA;AAEvG,0FAA0F;AAC1F,SAAgB,gBAAgB,CAAC,OAA0D,EAAE,KAA0B;IACrH,IAAI,OAAO,CAAC,MAAM,KAAK,+BAAiB,CAAC,cAAc;QAAE,OAA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,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;IAC/E,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import { EntityManager, In } from 'typeorm'\n\nimport { Refusal, refuseTiedRows } from '@things-factory/shell'\n\nimport { Counterparty } from '@things-factory/biz-base'\n\nimport { Account } from '../account/account'\nimport { BankAccount } from '../bank-account/bank-account'\nimport { BankStatement } from '../bank-statement/bank-statement'\nimport { RecurringCashItem } from '../recurring-cash-item/recurring-cash-item'\nimport { CashFlowType } from '../cash-flow-type'\nimport { Payment } from '../payment/payment'\nimport { checkPaymentCurrencies } from '../payment/payment-currency'\nimport { checkPaymentsWithin } from '../payment/payment-service'\nimport { paymentRules, paymentTargetOf } from '../payment/payment-targets'\nimport { ForecastStatus, Transaction, TransactionCategory, TransactionSource } from './transaction'\nimport { forecastDay, yearMonthOf } from './transaction-period'\n\n/** A transaction as a module writes it: what a person may write, and the facts a bank statement gives. */\nexport type TransactionInput = Partial<\n Omit<Transaction, 'bankAccount' | 'account' | 'counterparty' | 'recurringItem' | 'bankStatement'>\n> & {\n id?: string\n cuFlag?: string\n bankAccount?: { id: string } | null\n account?: { id: string } | null\n counterparty?: { id: string } | null\n recurringItem?: { id: string } | null\n bankStatement?: { id: string } | null\n}\n\n/** What a bank statement says of a line - changed only by a statement; what a person writes beside them stays open. */\nconst BANK_FACTS = ['transactionDate', 'type', 'amount', 'balance', 'currency', 'bankAccount'] as const\n\n/** A line that came from a bank statement keeps the statement's facts (§`BANK_FACTS`). */\nexport function protectBankFacts(current: Partial<Transaction> & { bankAccountId?: string }, patch: Record<string, any>): void {\n if (current.source !== TransactionSource.BANK_STATEMENT) return\n for (const field of BANK_FACTS) {\n if (!(field in patch)) continue\n const before = field === 'bankAccount' ? current.bankAccountId ?? current.bankAccount?.id : (current as any)[field]\n const after = field === 'bankAccount' ? patch.bankAccount?.id : patch[field]\n const equal = ['amount', 'balance'].includes(field)\n ? (before == null && after == null) || (before != null && after != null && Number(before) === Number(after))\n : before === after\n if (!equal)\n throw new Refusal('bank-facts-locked', {}, 'Bank facts can only be updated from a statement; annotations remain editable')\n }\n}\n\n/** The rows a transaction names besides its bank account, each of the caller's domain. */\nconst REFERENCES: [string, () => any][] = [\n ['account', () => Account],\n ['counterparty', () => Counterparty],\n ['recurringItem', () => RecurringCashItem],\n ['bankStatement', () => BankStatement]\n]\n\n/** What its payments depend on - they are checked again, and their owners follow, when one of these changes. */\nconst FACTS = ['amount', 'type', 'currency', 'transactionDate'] as const\n\n/**\n * The row a patch writes over the current one: a confirmed transaction has a day and takes its year and month from it;\n * a forecast has a year and a month, and the day its timing names.\n */\nfunction rowOf(input: TransactionInput, current: Transaction | undefined): Record<string, any> {\n const { id, cuFlag, ...fields } = input\n const row: Record<string, any> = { ...fields }\n const merged = { ...current, ...row }\n const category = merged.category ?? TransactionCategory.CONFIRMED\n row.category = category\n\n if (!current && !row.type) throw new Refusal('transaction-type-required', {}, 'type: money in or money out')\n if (row.type !== undefined && !Object.values(CashFlowType).includes(row.type))\n throw new Refusal('transaction-type-required', {}, 'type: money in or money out')\n if (!current && (row.amount === undefined || row.amount === null)) row.amount = 0\n /* An emptied currency is won, the column's own default - a row is never without one. */\n if ('currency' in row && !row.currency) row.currency = 'KRW'\n\n if (category === TransactionCategory.CONFIRMED) {\n const period = yearMonthOf(merged.transactionDate)\n if (!period)\n throw new Refusal(\n 'transaction-date-required',\n { value: merged.transactionDate ?? '' },\n 'transactionDate: YYYY-MM-DD'\n )\n Object.assign(row, period, { status: null })\n } else {\n const [year, month] = [Number(merged.year), Number(merged.month)]\n if (!year) throw new Refusal('forecast-year-required', {}, 'year: the year it is planned in')\n if (!(month >= 1 && month <= 12))\n throw new Refusal('month-out-of-range', { month: merged.month ?? '' }, 'month: must be 1 to 12')\n if (!String(merged.description ?? '').trim())\n throw new Refusal('forecast-description-required', {}, 'description: what is planned')\n Object.assign(row, { year, month, transactionDate: forecastDay(year, month, merged.timing) })\n if (!merged.status) row.status = ForecastStatus.PLANNED\n }\n\n if (\n merged.probability !== undefined &&\n merged.probability !== null &&\n !(merged.probability >= 0 && merged.probability <= 100)\n ) {\n throw new Refusal('probability-out-of-range', {}, 'probability: must be 0 to 100')\n }\n\n return row\n}\n\n/** The payments on these transactions, and the transfers into them, by target kind. */\nasync function paymentsOn(tx: EntityManager, domain: { id: string }, ids: string[]): Promise<Payment[]> {\n if (!ids.length) return []\n const repo = tx.getRepository(Payment)\n return [\n ...(await repo.find({\n where: { domain: { id: domain.id }, transaction: { id: In(ids) } },\n relations: ['transaction']\n })),\n ...(await repo.find({\n where: { domain: { id: domain.id }, targetType: 'Transaction', targetId: In(ids) },\n relations: ['transaction']\n }))\n ]\n}\n\n/**\n * Apply rows to a domain's transactions: `+` (or no id) adds, `M` changes, `-` deletes (softly - a financial row\n * that was deleted stays readable). A transaction that pays something, is paid, or is named by another row is unlinked\n * before it is deleted (§`refuseTiedRows`); when its money changes, its payments are checked again - the general rule\n * and each target kind's own.\n * A line from a bank statement keeps the statement's facts (§`protectBankFacts`).\n */\nexport async function saveTransactions(\n tx: EntityManager,\n domain: { id: string },\n user: any,\n inputs: TransactionInput[]\n): Promise<Transaction[]> {\n const repo = tx.getRepository(Transaction)\n\n const deletes = [...new Set(inputs.filter(one => one.cuFlag === '-' && one.id).map(one => one.id!))]\n if (deletes.length) {\n const found = await repo.find({ where: { domain: { id: domain.id }, id: In(deletes) } })\n if (found.length !== deletes.length)\n throw new Refusal('transaction-not-found', {}, 'a transaction was not found - reload and try again')\n await refuseTiedRows(tx, Transaction, deletes)\n await repo.softRemove(found)\n }\n\n const saved: Transaction[] = []\n const factsChanged: string[] = []\n for (const input of inputs.filter(one => one.cuFlag !== '-')) {\n const isNew = !input.id || input.cuFlag === '+'\n const current = isNew ? undefined : await repo.findOne({ where: { domain: { id: domain.id }, id: input.id } })\n if (!isNew && !current)\n throw new Refusal('transaction-not-found', {}, 'a transaction was not found - reload and try again')\n\n if (current) protectBankFacts(current, input)\n const row = rowOf(input, current)\n if (row.bankAccount?.id && !('currency' in input)) {\n const account = await tx\n .getRepository(BankAccount)\n .findOne({ where: { domain: { id: domain.id }, id: row.bankAccount.id } })\n if (!account)\n throw new Refusal('bank-account-not-found', {}, 'the bank account was not found - reload and try again')\n if (account.currency) row.currency = account.currency\n }\n\n /* What a row names is the caller's own - never another domain's account, counterparty, item or statement. */\n for (const [field, entity] of REFERENCES)\n if (row[field]?.id && !(await tx.getRepository(entity()).findOne({ where: { domain: { id: domain.id }, id: row[field].id } as any, withDeleted: true })))\n throw new Refusal('transaction-reference-not-found', { field }, `${field} was not found - reload and try again`)\n\n if (row.bankFingerprint) {\n const twin = await repo.findOne({ where: { domain: { id: domain.id }, bankFingerprint: row.bankFingerprint } })\n if (twin && twin.id !== current?.id)\n throw new Refusal(\n 'bank-line-twice',\n { day: twin.transactionDate ?? '' },\n 'this bank line is already in the books'\n )\n }\n\n const written = await repo.save({ ...(current ?? { domain, creator: user }), ...row, updater: user } as Transaction)\n if (current && FACTS.some(field => field in row && row[field] !== (current as any)[field]))\n factsChanged.push(current.id)\n saved.push(written)\n }\n\n if (factsChanged.length) {\n const payments = await paymentsOn(tx, domain, factsChanged)\n await checkPaymentsWithin(\n tx,\n domain,\n payments.map(one => one.transaction.id)\n )\n await checkPaymentCurrencies(\n tx,\n domain,\n payments.map(one => one.transaction.id)\n )\n const kinds = new Map<string, Payment[]>()\n for (const payment of payments) kinds.set(payment.targetType, [...(kinds.get(payment.targetType) ?? []), payment])\n const touchedOf = (ofKind: Payment[]) => ({\n targetIds: [...new Set(ofKind.map(one => one.targetId))],\n transactionIds: [...new Set(ofKind.map(one => one.transaction.id))]\n })\n for (const [targetType, ofKind] of kinds)\n await paymentTargetOf(targetType)?.validate?.(tx, domain, touchedOf(ofKind))\n for (const rule of paymentRules()) await rule(tx, domain, { transactionIds: [...new Set(payments.map(one => one.transaction.id))] })\n for (const [targetType, ofKind] of kinds)\n await paymentTargetOf(targetType)?.onSaved?.(tx, domain, touchedOf(ofKind))\n }\n\n return saved\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transaction-service.js","sourceRoot":"","sources":["../../../server/service/transaction/transaction-service.ts"],"names":[],"mappings":";;AAkCA,4CAYC;AAyDD,4CAmFC;AA1LD,qCAA2C;AAE3C,iDAA+D;AAE/D,uDAAuD;AAEvD,gDAA4C;AAC5C,+DAA0D;AAC1D,qEAAgE;AAEhE,sDAAgD;AAChD,gDAA4C;AAC5C,kEAAoE;AACpE,gEAAgE;AAChE,gEAA0E;AAC1E,+CAAmF;AACnF,6DAAkD;AAclD,uHAAuH;AACvH,MAAM,UAAU,GAAG,CAAC,iBAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,CAAU,CAAA;AAEvG,0FAA0F;AAC1F,SAAgB,gBAAgB,CAAC,OAA0D,EAAE,KAA0B;IACrH,IAAI,OAAO,CAAC,MAAM,KAAK,+BAAiB,CAAC,cAAc;QAAE,OAAM;IAC/D,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;QAC/B,IAAI,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC;YAAE,SAAQ;QAC/B,MAAM,MAAM,GAAG,KAAK,KAAK,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAE,OAAe,CAAC,KAAK,CAAC,CAAA;QACnH,MAAM,KAAK,GAAG,KAAK,KAAK,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC5E,MAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;YACjD,CAAC,CAAC,CAAC,MAAM,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,IA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,EAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;QAC9E,KAAK,MAAM,IAAI,IAAI,IAAA,8BAAY,GAAE;YAAE,MAAM,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,cAAc,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QACpI,KAAK,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,KAAK;YACtC,MAAM,IAAA,iCAAe,EAAC,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;IAC/E,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import { EntityManager, In } from 'typeorm'\n\nimport { Refusal, refuseTiedRows } from '@things-factory/shell'\n\nimport { Counterparty } from '@things-factory/biz-base'\n\nimport { Account } from '../account/account'\nimport { BankAccount } from '../bank-account/bank-account'\nimport { BankStatement } from '../bank-statement/bank-statement'\nimport { RecurringCashItem } from '../recurring-cash-item/recurring-cash-item'\nimport { CashFlowType } from '../cash-flow-type'\nimport { Payment } from '../payment/payment'\nimport { checkPaymentCurrencies } from '../payment/payment-currency'\nimport { checkPaymentsWithin } from '../payment/payment-service'\nimport { paymentRules, paymentTargetOf } from '../payment/payment-targets'\nimport { Transaction, TransactionCategory, TransactionSource } from './transaction'\nimport { yearMonthOf } from './transaction-period'\n\n/** A transaction as a module writes it: what a person may write, and the facts a bank statement gives. */\nexport type TransactionInput = Partial<\n Omit<Transaction, 'bankAccount' | 'account' | 'counterparty' | 'bankStatement'>\n> & {\n id?: string\n cuFlag?: string\n bankAccount?: { id: string } | null\n account?: { id: string } | null\n counterparty?: { id: string } | null\n bankStatement?: { id: string } | null\n}\n\n/** What a bank statement says of a line - changed only by a statement; what a person writes beside them stays open. */\nconst BANK_FACTS = ['transactionDate', 'type', 'amount', 'balance', 'currency', 'bankAccount'] as const\n\n/** A line that came from a bank statement keeps the statement's facts (§`BANK_FACTS`). */\nexport function protectBankFacts(current: Partial<Transaction> & { bankAccountId?: string }, patch: Record<string, any>): void {\n if (current.source !== TransactionSource.BANK_STATEMENT) return\n for (const field of BANK_FACTS) {\n if (!(field in patch)) continue\n const before = field === 'bankAccount' ? current.bankAccountId ?? current.bankAccount?.id : (current as any)[field]\n const after = field === 'bankAccount' ? patch.bankAccount?.id : patch[field]\n const equal = ['amount', 'balance'].includes(field)\n ? (before == null && after == null) || (before != null && after != null && Number(before) === Number(after))\n : before === after\n if (!equal)\n throw new Refusal('bank-facts-locked', {}, 'Bank facts can only be updated from a statement; annotations remain editable')\n }\n}\n\n/** The rows a transaction names besides its bank account, each of the caller's domain. */\nconst REFERENCES: [string, () => any][] = [\n ['account', () => Account],\n ['counterparty', () => Counterparty],\n ['bankStatement', () => BankStatement]\n]\n\n/** What its payments depend on - they are checked again, and their owners follow, when one of these changes. */\nconst FACTS = ['amount', 'type', 'currency', 'transactionDate'] as const\n\n/** The row a patch writes over the current one: a transaction has a day and takes its year and month from it. */\nfunction rowOf(input: TransactionInput, current: Transaction | undefined): Record<string, any> {\n const { id, cuFlag, ...fields } = input\n const row: Record<string, any> = { ...fields }\n const merged = { ...current, ...row }\n row.category = TransactionCategory.CONFIRMED\n\n if (!current && !row.type) throw new Refusal('transaction-type-required', {}, 'type: money in or money out')\n if (row.type !== undefined && !Object.values(CashFlowType).includes(row.type))\n throw new Refusal('transaction-type-required', {}, 'type: money in or money out')\n if (!current && (row.amount === undefined || row.amount === null)) row.amount = 0\n /* An emptied currency is won, the column's own default - a row is never without one. */\n if ('currency' in row && !row.currency) row.currency = 'KRW'\n\n const period = yearMonthOf(merged.transactionDate)\n if (!period)\n throw new Refusal('transaction-date-required', { value: merged.transactionDate ?? '' }, 'transactionDate: YYYY-MM-DD')\n Object.assign(row, period)\n\n return row\n}\n\n/** The payments on these transactions, and the transfers into them, by target kind. */\nasync function paymentsOn(tx: EntityManager, domain: { id: string }, ids: string[]): Promise<Payment[]> {\n if (!ids.length) return []\n const repo = tx.getRepository(Payment)\n return [\n ...(await repo.find({\n where: { domain: { id: domain.id }, transaction: { id: In(ids) } },\n relations: ['transaction']\n })),\n ...(await repo.find({\n where: { domain: { id: domain.id }, targetType: 'Transaction', targetId: In(ids) },\n relations: ['transaction']\n }))\n ]\n}\n\n/**\n * Apply rows to a domain's transactions: `+` (or no id) adds, `M` changes, `-` deletes (softly - a financial row\n * that was deleted stays readable). A transaction that pays something, is paid, or is named by another row is unlinked\n * before it is deleted (§`refuseTiedRows`); when its money changes, its payments are checked again - the general rule\n * and each target kind's own.\n * A line from a bank statement keeps the statement's facts (§`protectBankFacts`).\n */\nexport async function saveTransactions(\n tx: EntityManager,\n domain: { id: string },\n user: any,\n inputs: TransactionInput[]\n): Promise<Transaction[]> {\n const repo = tx.getRepository(Transaction)\n\n const deletes = [...new Set(inputs.filter(one => one.cuFlag === '-' && one.id).map(one => one.id!))]\n if (deletes.length) {\n const found = await repo.find({ where: { domain: { id: domain.id }, id: In(deletes) } })\n if (found.length !== deletes.length)\n throw new Refusal('transaction-not-found', {}, 'a transaction was not found - reload and try again')\n await refuseTiedRows(tx, Transaction, deletes)\n await repo.softRemove(found)\n }\n\n const saved: Transaction[] = []\n const factsChanged: string[] = []\n for (const input of inputs.filter(one => one.cuFlag !== '-')) {\n const isNew = !input.id || input.cuFlag === '+'\n const current = isNew ? undefined : await repo.findOne({ where: { domain: { id: domain.id }, id: input.id } })\n if (!isNew && !current)\n throw new Refusal('transaction-not-found', {}, 'a transaction was not found - reload and try again')\n\n if (current) protectBankFacts(current, input)\n const row = rowOf(input, current)\n if (row.bankAccount?.id && !('currency' in input)) {\n const account = await tx\n .getRepository(BankAccount)\n .findOne({ where: { domain: { id: domain.id }, id: row.bankAccount.id } })\n if (!account)\n throw new Refusal('bank-account-not-found', {}, 'the bank account was not found - reload and try again')\n if (account.currency) row.currency = account.currency\n }\n\n /* What a row names is the caller's own - never another domain's account, counterparty, item or statement. */\n for (const [field, entity] of REFERENCES)\n if (row[field]?.id && !(await tx.getRepository(entity()).findOne({ where: { domain: { id: domain.id }, id: row[field].id } as any, withDeleted: true })))\n throw new Refusal('transaction-reference-not-found', { field }, `${field} was not found - reload and try again`)\n\n if (row.bankFingerprint) {\n const twin = await repo.findOne({ where: { domain: { id: domain.id }, bankFingerprint: row.bankFingerprint } })\n if (twin && twin.id !== current?.id)\n throw new Refusal(\n 'bank-line-twice',\n { day: twin.transactionDate ?? '' },\n 'this bank line is already in the books'\n )\n }\n\n const written = await repo.save({ ...(current ?? { domain, creator: user }), ...row, updater: user } as Transaction)\n if (current && FACTS.some(field => field in row && row[field] !== (current as any)[field]))\n factsChanged.push(current.id)\n saved.push(written)\n }\n\n if (factsChanged.length) {\n const payments = await paymentsOn(tx, domain, factsChanged)\n await checkPaymentsWithin(\n tx,\n domain,\n payments.map(one => one.transaction.id)\n )\n await checkPaymentCurrencies(\n tx,\n domain,\n payments.map(one => one.transaction.id)\n )\n const kinds = new Map<string, Payment[]>()\n for (const payment of payments) kinds.set(payment.targetType, [...(kinds.get(payment.targetType) ?? []), payment])\n const touchedOf = (ofKind: Payment[]) => ({\n targetIds: [...new Set(ofKind.map(one => one.targetId))],\n transactionIds: [...new Set(ofKind.map(one => one.transaction.id))]\n })\n for (const [targetType, ofKind] of kinds)\n await paymentTargetOf(targetType)?.validate?.(tx, domain, touchedOf(ofKind))\n for (const rule of paymentRules()) await rule(tx, domain, { transactionIds: [...new Set(payments.map(one => one.transaction.id))] })\n for (const [targetType, ofKind] of kinds)\n await paymentTargetOf(targetType)?.onSaved?.(tx, domain, touchedOf(ofKind))\n }\n\n return saved\n}\n"]}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { ObjectRef } from '@things-factory/shell';
|
|
2
2
|
import { CashFlowType } from '../cash-flow-type';
|
|
3
|
-
import {
|
|
3
|
+
import { Transaction } from './transaction';
|
|
4
4
|
export declare class NewTransaction {
|
|
5
|
-
category?: TransactionCategory;
|
|
6
5
|
type: CashFlowType;
|
|
7
6
|
bankAccount?: ObjectRef;
|
|
8
7
|
transactionDate?: string;
|
|
9
|
-
year?: number;
|
|
10
|
-
month?: number;
|
|
11
8
|
amount?: number;
|
|
12
9
|
currency?: string;
|
|
13
10
|
balance?: number;
|
|
@@ -16,20 +13,13 @@ export declare class NewTransaction {
|
|
|
16
13
|
ledgerCategory?: string;
|
|
17
14
|
counterpartyName?: string;
|
|
18
15
|
counterparty?: ObjectRef;
|
|
19
|
-
timing?: string;
|
|
20
|
-
status?: ForecastStatus;
|
|
21
|
-
probability?: number;
|
|
22
16
|
notes?: string;
|
|
23
|
-
recurringItem?: ObjectRef;
|
|
24
17
|
}
|
|
25
18
|
export declare class TransactionPatch {
|
|
26
19
|
id?: string;
|
|
27
|
-
category?: TransactionCategory;
|
|
28
20
|
type?: CashFlowType;
|
|
29
21
|
bankAccount?: ObjectRef;
|
|
30
22
|
transactionDate?: string;
|
|
31
|
-
year?: number;
|
|
32
|
-
month?: number;
|
|
33
23
|
amount?: number;
|
|
34
24
|
currency?: string;
|
|
35
25
|
balance?: number;
|
|
@@ -38,11 +28,7 @@ export declare class TransactionPatch {
|
|
|
38
28
|
ledgerCategory?: string;
|
|
39
29
|
counterpartyName?: string;
|
|
40
30
|
counterparty?: ObjectRef;
|
|
41
|
-
timing?: string;
|
|
42
|
-
status?: ForecastStatus;
|
|
43
|
-
probability?: number;
|
|
44
31
|
notes?: string;
|
|
45
|
-
recurringItem?: ObjectRef;
|
|
46
32
|
cuFlag?: string;
|
|
47
33
|
}
|
|
48
34
|
export declare class TransactionList {
|
|
@@ -9,10 +9,6 @@ const transaction_1 = require("./transaction");
|
|
|
9
9
|
let NewTransaction = class NewTransaction {
|
|
10
10
|
};
|
|
11
11
|
exports.NewTransaction = NewTransaction;
|
|
12
|
-
tslib_1.__decorate([
|
|
13
|
-
(0, type_graphql_1.Field)(type => transaction_1.TransactionCategory, { nullable: true, description: 'Confirmed when not given' }),
|
|
14
|
-
tslib_1.__metadata("design:type", String)
|
|
15
|
-
], NewTransaction.prototype, "category", void 0);
|
|
16
12
|
tslib_1.__decorate([
|
|
17
13
|
(0, type_graphql_1.Field)(type => cash_flow_type_1.CashFlowType, { description: 'Money in or money out' }),
|
|
18
14
|
tslib_1.__metadata("design:type", String)
|
|
@@ -22,17 +18,9 @@ tslib_1.__decorate([
|
|
|
22
18
|
tslib_1.__metadata("design:type", shell_1.ObjectRef)
|
|
23
19
|
], NewTransaction.prototype, "bankAccount", void 0);
|
|
24
20
|
tslib_1.__decorate([
|
|
25
|
-
(0, type_graphql_1.Field)({ nullable: true, description: 'YYYY-MM-DD - required
|
|
21
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'YYYY-MM-DD - required' }),
|
|
26
22
|
tslib_1.__metadata("design:type", String)
|
|
27
23
|
], NewTransaction.prototype, "transactionDate", void 0);
|
|
28
|
-
tslib_1.__decorate([
|
|
29
|
-
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'The year a forecast is planned in' }),
|
|
30
|
-
tslib_1.__metadata("design:type", Number)
|
|
31
|
-
], NewTransaction.prototype, "year", void 0);
|
|
32
|
-
tslib_1.__decorate([
|
|
33
|
-
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'The month a forecast is planned in' }),
|
|
34
|
-
tslib_1.__metadata("design:type", Number)
|
|
35
|
-
], NewTransaction.prototype, "month", void 0);
|
|
36
24
|
tslib_1.__decorate([
|
|
37
25
|
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { nullable: true, description: 'Amount - zero when not given' }),
|
|
38
26
|
tslib_1.__metadata("design:type", Number)
|
|
@@ -65,28 +53,12 @@ tslib_1.__decorate([
|
|
|
65
53
|
(0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'The registered counterparty' }),
|
|
66
54
|
tslib_1.__metadata("design:type", shell_1.ObjectRef)
|
|
67
55
|
], NewTransaction.prototype, "counterparty", void 0);
|
|
68
|
-
tslib_1.__decorate([
|
|
69
|
-
(0, type_graphql_1.Field)({ nullable: true, description: 'When in the month a forecast falls' }),
|
|
70
|
-
tslib_1.__metadata("design:type", String)
|
|
71
|
-
], NewTransaction.prototype, "timing", void 0);
|
|
72
|
-
tslib_1.__decorate([
|
|
73
|
-
(0, type_graphql_1.Field)(type => transaction_1.ForecastStatus, { nullable: true, description: 'State of a forecast' }),
|
|
74
|
-
tslib_1.__metadata("design:type", String)
|
|
75
|
-
], NewTransaction.prototype, "status", void 0);
|
|
76
|
-
tslib_1.__decorate([
|
|
77
|
-
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'The probability of a forecast being realized (0 to 100)' }),
|
|
78
|
-
tslib_1.__metadata("design:type", Number)
|
|
79
|
-
], NewTransaction.prototype, "probability", void 0);
|
|
80
56
|
tslib_1.__decorate([
|
|
81
57
|
(0, type_graphql_1.Field)({ nullable: true, description: 'Notes' }),
|
|
82
58
|
tslib_1.__metadata("design:type", String)
|
|
83
59
|
], NewTransaction.prototype, "notes", void 0);
|
|
84
|
-
tslib_1.__decorate([
|
|
85
|
-
(0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'The recurring item a forecast was made from' }),
|
|
86
|
-
tslib_1.__metadata("design:type", shell_1.ObjectRef)
|
|
87
|
-
], NewTransaction.prototype, "recurringItem", void 0);
|
|
88
60
|
exports.NewTransaction = NewTransaction = tslib_1.__decorate([
|
|
89
|
-
(0, type_graphql_1.InputType)({ description: 'A
|
|
61
|
+
(0, type_graphql_1.InputType)({ description: 'A bank line someone writes by hand' })
|
|
90
62
|
], NewTransaction);
|
|
91
63
|
let TransactionPatch = class TransactionPatch {
|
|
92
64
|
};
|
|
@@ -95,10 +67,6 @@ tslib_1.__decorate([
|
|
|
95
67
|
(0, type_graphql_1.Field)(type => type_graphql_1.ID, { nullable: true, description: 'The transaction to change or delete' }),
|
|
96
68
|
tslib_1.__metadata("design:type", String)
|
|
97
69
|
], TransactionPatch.prototype, "id", void 0);
|
|
98
|
-
tslib_1.__decorate([
|
|
99
|
-
(0, type_graphql_1.Field)(type => transaction_1.TransactionCategory, { nullable: true, description: 'Confirmed or forecast' }),
|
|
100
|
-
tslib_1.__metadata("design:type", String)
|
|
101
|
-
], TransactionPatch.prototype, "category", void 0);
|
|
102
70
|
tslib_1.__decorate([
|
|
103
71
|
(0, type_graphql_1.Field)(type => cash_flow_type_1.CashFlowType, { nullable: true, description: 'Money in or money out' }),
|
|
104
72
|
tslib_1.__metadata("design:type", String)
|
|
@@ -111,14 +79,6 @@ tslib_1.__decorate([
|
|
|
111
79
|
(0, type_graphql_1.Field)({ nullable: true, description: 'YYYY-MM-DD' }),
|
|
112
80
|
tslib_1.__metadata("design:type", String)
|
|
113
81
|
], TransactionPatch.prototype, "transactionDate", void 0);
|
|
114
|
-
tslib_1.__decorate([
|
|
115
|
-
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'The year a forecast is planned in' }),
|
|
116
|
-
tslib_1.__metadata("design:type", Number)
|
|
117
|
-
], TransactionPatch.prototype, "year", void 0);
|
|
118
|
-
tslib_1.__decorate([
|
|
119
|
-
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'The month a forecast is planned in' }),
|
|
120
|
-
tslib_1.__metadata("design:type", Number)
|
|
121
|
-
], TransactionPatch.prototype, "month", void 0);
|
|
122
82
|
tslib_1.__decorate([
|
|
123
83
|
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { nullable: true, description: 'Amount' }),
|
|
124
84
|
tslib_1.__metadata("design:type", Number)
|
|
@@ -151,26 +111,10 @@ tslib_1.__decorate([
|
|
|
151
111
|
(0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'The registered counterparty' }),
|
|
152
112
|
tslib_1.__metadata("design:type", shell_1.ObjectRef)
|
|
153
113
|
], TransactionPatch.prototype, "counterparty", void 0);
|
|
154
|
-
tslib_1.__decorate([
|
|
155
|
-
(0, type_graphql_1.Field)({ nullable: true, description: 'When in the month a forecast falls' }),
|
|
156
|
-
tslib_1.__metadata("design:type", String)
|
|
157
|
-
], TransactionPatch.prototype, "timing", void 0);
|
|
158
|
-
tslib_1.__decorate([
|
|
159
|
-
(0, type_graphql_1.Field)(type => transaction_1.ForecastStatus, { nullable: true, description: 'State of a forecast' }),
|
|
160
|
-
tslib_1.__metadata("design:type", String)
|
|
161
|
-
], TransactionPatch.prototype, "status", void 0);
|
|
162
|
-
tslib_1.__decorate([
|
|
163
|
-
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'The probability of a forecast being realized (0 to 100)' }),
|
|
164
|
-
tslib_1.__metadata("design:type", Number)
|
|
165
|
-
], TransactionPatch.prototype, "probability", void 0);
|
|
166
114
|
tslib_1.__decorate([
|
|
167
115
|
(0, type_graphql_1.Field)({ nullable: true, description: 'Notes' }),
|
|
168
116
|
tslib_1.__metadata("design:type", String)
|
|
169
117
|
], TransactionPatch.prototype, "notes", void 0);
|
|
170
|
-
tslib_1.__decorate([
|
|
171
|
-
(0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'The recurring item a forecast was made from' }),
|
|
172
|
-
tslib_1.__metadata("design:type", shell_1.ObjectRef)
|
|
173
|
-
], TransactionPatch.prototype, "recurringItem", void 0);
|
|
174
118
|
tslib_1.__decorate([
|
|
175
119
|
(0, type_graphql_1.Field)({ nullable: true, description: '+ adds, M changes, - deletes' }),
|
|
176
120
|
tslib_1.__metadata("design:type", String)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-type.js","sourceRoot":"","sources":["../../../server/service/transaction/transaction-type.ts"],"names":[],"mappings":";;;;AAAA,+CAA2E;AAE3E,iDAAiD;AAEjD,sDAAg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AAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,yDAAyD,EAAE,CAAC;;qDAC3F;AAGpB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;;+CAClC;AAGd;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAS,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,6CAA6C,EAAE,CAAC;sCACzF,iBAAS;uDAAA;AAGzB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,8BAA8B,EAAE,CAAC;;gDACxD;2BA9DJ,gBAAgB;IAD5B,IAAA,wBAAS,EAAC,EAAE,WAAW,EAAE,+EAA+E,EAAE,CAAC;GAC/F,gBAAgB,CA+D5B;AAGM,IAAM,eAAe,GAArB,MAAM,eAAe;CAM3B,CAAA;AANY,0CAAe;AAE1B;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,yBAAW,CAAC,EAAE,EAAE,WAAW,EAAE,+BAA+B,EAAE,CAAC;;8CAC3D;AAGpB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,EAAE,EAAE,WAAW,EAAE,2BAA2B,EAAE,CAAC;;8CACpD;0BALF,eAAe;IAD3B,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,wBAAwB,EAAE,CAAC;GACzC,eAAe,CAM3B","sourcesContent":["import { ObjectType, Field, Float, InputType, Int, ID } from 'type-graphql'\n\nimport { ObjectRef } from '@things-factory/shell'\n\nimport { CashFlowType } from '../cash-flow-type'\nimport { ForecastStatus, Transaction, TransactionCategory } from './transaction'\n\n@InputType({ description: 'A transaction someone writes - a bank line by hand, or a forecast' })\nexport class NewTransaction {\n @Field(type => TransactionCategory, { nullable: true, description: 'Confirmed when not given' })\n category?: TransactionCategory\n\n @Field(type => CashFlowType, { description: 'Money in or money out' })\n type: CashFlowType\n\n @Field(type => ObjectRef, { nullable: true, description: 'The account the money moved in or out of' })\n bankAccount?: ObjectRef\n\n @Field({ nullable: true, description: 'YYYY-MM-DD - required for a confirmed transaction' })\n transactionDate?: string\n\n @Field(type => Int, { nullable: true, description: 'The year a forecast is planned in' })\n year?: number\n\n @Field(type => Int, { nullable: true, description: 'The month a forecast is planned in' })\n month?: number\n\n @Field(type => Float, { nullable: true, description: 'Amount - zero when not given' })\n amount?: number\n\n @Field({ nullable: true, description: \"ISO 4217 code - the bank account's when not given\" })\n currency?: string\n\n @Field(type => Float, { nullable: true, description: 'Account balance after it' })\n balance?: number\n\n @Field(type => ObjectRef, { nullable: true, description: 'The account subject it is booked to' })\n account?: ObjectRef\n\n @Field({ nullable: true, description: 'What a person wrote about it' })\n description?: string\n\n @Field({ nullable: true, description: 'The classifying word of the ledger it was kept in' })\n ledgerCategory?: string\n\n @Field({ nullable: true, description: 'The counterparty name as a person wrote it' })\n counterpartyName?: string\n\n @Field(type => ObjectRef, { nullable: true, description: 'The registered counterparty' })\n counterparty?: ObjectRef\n\n @Field({ nullable: true, description: 'When in the month a forecast falls' })\n timing?: string\n\n @Field(type => ForecastStatus, { nullable: true, description: 'State of a forecast' })\n status?: ForecastStatus\n\n @Field(type => Int, { nullable: true, description: 'The probability of a forecast being realized (0 to 100)' })\n probability?: number\n\n @Field({ nullable: true, description: 'Notes' })\n notes?: string\n\n @Field(type => ObjectRef, { nullable: true, description: 'The recurring item a forecast was made from' })\n recurringItem?: ObjectRef\n}\n\n@InputType({ description: 'A change to a transaction, or a grid row: cuFlag + adds, M changes, - deletes' })\nexport class TransactionPatch {\n @Field(type => ID, { nullable: true, description: 'The transaction to change or delete' })\n id?: string\n\n @Field(type => TransactionCategory, { nullable: true, description: 'Confirmed or forecast' })\n category?: TransactionCategory\n\n @Field(type => CashFlowType, { nullable: true, description: 'Money in or money out' })\n type?: CashFlowType\n\n @Field(type => ObjectRef, { nullable: true, description: 'The account the money moved in or out of' })\n bankAccount?: ObjectRef\n\n @Field({ nullable: true, description: 'YYYY-MM-DD' })\n transactionDate?: string\n\n @Field(type => Int, { nullable: true, description: 'The year a forecast is planned in' })\n year?: number\n\n @Field(type => Int, { nullable: true, description: 'The month a forecast is planned in' })\n month?: number\n\n @Field(type => Float, { nullable: true, description: 'Amount' })\n amount?: number\n\n @Field({ nullable: true, description: 'ISO 4217 code' })\n currency?: string\n\n @Field(type => Float, { nullable: true, description: 'Account balance after it' })\n balance?: number\n\n @Field(type => ObjectRef, { nullable: true, description: 'The account subject it is booked to' })\n account?: ObjectRef\n\n @Field({ nullable: true, description: 'What a person wrote about it' })\n description?: string\n\n @Field({ nullable: true, description: 'The classifying word of the ledger it was kept in' })\n ledgerCategory?: string\n\n @Field({ nullable: true, description: 'The counterparty name as a person wrote it' })\n counterpartyName?: string\n\n @Field(type => ObjectRef, { nullable: true, description: 'The registered counterparty' })\n counterparty?: ObjectRef\n\n @Field({ nullable: true, description: 'When in the month a forecast falls' })\n timing?: string\n\n @Field(type => ForecastStatus, { nullable: true, description: 'State of a forecast' })\n status?: ForecastStatus\n\n @Field(type => Int, { nullable: true, description: 'The probability of a forecast being realized (0 to 100)' })\n probability?: number\n\n @Field({ nullable: true, description: 'Notes' })\n notes?: string\n\n @Field(type => ObjectRef, { nullable: true, description: 'The recurring item a forecast was made from' })\n recurringItem?: ObjectRef\n\n @Field({ nullable: true, description: '+ adds, M changes, - deletes' })\n cuFlag?: string\n}\n\n@ObjectType({ description: 'A page of transactions' })\nexport class TransactionList {\n @Field(type => [Transaction], { description: 'The transactions on this page' })\n items: Transaction[]\n\n @Field(type => Int, { description: 'How many there are in all' })\n total: number\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transaction-type.js","sourceRoot":"","sources":["../../../server/service/transaction/transaction-type.ts"],"names":[],"mappings":";;;;AAAA,+CAA2E;AAE3E,iDAAiD;AAEjD,sDA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CAAC,CAAC,yBAAW,CAAC,EAAE,EAAE,WAAW,EAAE,+BAA+B,EAAE,CAAC;;8CAC3D;AAGpB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,EAAE,EAAE,WAAW,EAAE,2BAA2B,EAAE,CAAC;;8CACpD;0BALF,eAAe;IAD3B,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,wBAAwB,EAAE,CAAC;GACzC,eAAe,CAM3B","sourcesContent":["import { ObjectType, Field, Float, InputType, Int, ID } from 'type-graphql'\n\nimport { ObjectRef } from '@things-factory/shell'\n\nimport { CashFlowType } from '../cash-flow-type'\nimport { Transaction } from './transaction'\n\n@InputType({ description: 'A bank line someone writes by hand' })\nexport class NewTransaction {\n @Field(type => CashFlowType, { description: 'Money in or money out' })\n type: CashFlowType\n\n @Field(type => ObjectRef, { nullable: true, description: 'The account the money moved in or out of' })\n bankAccount?: ObjectRef\n\n @Field({ nullable: true, description: 'YYYY-MM-DD - required' })\n transactionDate?: string\n\n @Field(type => Float, { nullable: true, description: 'Amount - zero when not given' })\n amount?: number\n\n @Field({ nullable: true, description: \"ISO 4217 code - the bank account's when not given\" })\n currency?: string\n\n @Field(type => Float, { nullable: true, description: 'Account balance after it' })\n balance?: number\n\n @Field(type => ObjectRef, { nullable: true, description: 'The account subject it is booked to' })\n account?: ObjectRef\n\n @Field({ nullable: true, description: 'What a person wrote about it' })\n description?: string\n\n @Field({ nullable: true, description: 'The classifying word of the ledger it was kept in' })\n ledgerCategory?: string\n\n @Field({ nullable: true, description: 'The counterparty name as a person wrote it' })\n counterpartyName?: string\n\n @Field(type => ObjectRef, { nullable: true, description: 'The registered counterparty' })\n counterparty?: ObjectRef\n\n @Field({ nullable: true, description: 'Notes' })\n notes?: string\n}\n\n@InputType({ description: 'A change to a transaction, or a grid row: cuFlag + adds, M changes, - deletes' })\nexport class TransactionPatch {\n @Field(type => ID, { nullable: true, description: 'The transaction to change or delete' })\n id?: string\n\n @Field(type => CashFlowType, { nullable: true, description: 'Money in or money out' })\n type?: CashFlowType\n\n @Field(type => ObjectRef, { nullable: true, description: 'The account the money moved in or out of' })\n bankAccount?: ObjectRef\n\n @Field({ nullable: true, description: 'YYYY-MM-DD' })\n transactionDate?: string\n\n @Field(type => Float, { nullable: true, description: 'Amount' })\n amount?: number\n\n @Field({ nullable: true, description: 'ISO 4217 code' })\n currency?: string\n\n @Field(type => Float, { nullable: true, description: 'Account balance after it' })\n balance?: number\n\n @Field(type => ObjectRef, { nullable: true, description: 'The account subject it is booked to' })\n account?: ObjectRef\n\n @Field({ nullable: true, description: 'What a person wrote about it' })\n description?: string\n\n @Field({ nullable: true, description: 'The classifying word of the ledger it was kept in' })\n ledgerCategory?: string\n\n @Field({ nullable: true, description: 'The counterparty name as a person wrote it' })\n counterpartyName?: string\n\n @Field(type => ObjectRef, { nullable: true, description: 'The registered counterparty' })\n counterparty?: ObjectRef\n\n @Field({ nullable: true, description: 'Notes' })\n notes?: string\n\n @Field({ nullable: true, description: '+ adds, M changes, - deletes' })\n cuFlag?: string\n}\n\n@ObjectType({ description: 'A page of transactions' })\nexport class TransactionList {\n @Field(type => [Transaction], { description: 'The transactions on this page' })\n items: Transaction[]\n\n @Field(type => Int, { description: 'How many there are in all' })\n total: number\n}\n"]}
|
|
@@ -7,24 +7,20 @@ import { BankStatement } from '../bank-statement/bank-statement';
|
|
|
7
7
|
import { CashFlowType } from '../cash-flow-type';
|
|
8
8
|
import { Payment } from '../payment/payment';
|
|
9
9
|
import { AccountingDocument } from '../accounting-document/accounting-document';
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* What a transaction is: a line that happened on the bank account. Money still to come is read from the records that
|
|
12
|
+
* owe it, never written as a transaction (ADR-0157) - the category is the one kind left.
|
|
13
|
+
*/
|
|
11
14
|
export declare enum TransactionCategory {
|
|
12
|
-
CONFIRMED = "CONFIRMED"
|
|
13
|
-
FORECAST = "FORECAST"
|
|
15
|
+
CONFIRMED = "CONFIRMED"
|
|
14
16
|
}
|
|
15
17
|
export declare enum TransactionSource {
|
|
16
18
|
BANK_STATEMENT = "BANK_STATEMENT",
|
|
17
19
|
LEGACY = "LEGACY",
|
|
18
20
|
MANUAL = "MANUAL"
|
|
19
21
|
}
|
|
20
|
-
export declare enum ForecastStatus {
|
|
21
|
-
PLANNED = "PLANNED",
|
|
22
|
-
DONE = "DONE",
|
|
23
|
-
CANCELLED = "CANCELLED"
|
|
24
|
-
}
|
|
25
22
|
/**
|
|
26
|
-
* Money that
|
|
27
|
-
* still to come or go (forecast).
|
|
23
|
+
* Money that moved in or out of the business: a line on a bank account.
|
|
28
24
|
*
|
|
29
25
|
* What a transaction paid - a contract round, a tax invoice, a VAT period - is its payments (§`Payment`). The facts
|
|
30
26
|
* of a bank line are kept as the bank gave them, beside what a person wrote about it.
|
|
@@ -66,12 +62,7 @@ export declare class Transaction {
|
|
|
66
62
|
bankCounterpartyAccount?: string;
|
|
67
63
|
bankCounterpartyBank?: string;
|
|
68
64
|
bankMemo?: string;
|
|
69
|
-
timing?: string;
|
|
70
|
-
status?: ForecastStatus;
|
|
71
|
-
probability?: number;
|
|
72
65
|
notes?: string;
|
|
73
|
-
recurringItem?: RecurringCashItem;
|
|
74
|
-
recurringItemId?: string;
|
|
75
66
|
payments?: Payment[];
|
|
76
67
|
documents?: AccountingDocument[];
|
|
77
68
|
createdAt?: Date;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Transaction = exports.
|
|
3
|
+
exports.Transaction = exports.TransactionSource = exports.TransactionCategory = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const typeorm_1 = require("typeorm");
|
|
6
6
|
const type_graphql_1 = require("type-graphql");
|
|
@@ -13,15 +13,17 @@ const bank_statement_1 = require("../bank-statement/bank-statement");
|
|
|
13
13
|
const cash_flow_type_1 = require("../cash-flow-type");
|
|
14
14
|
const payment_1 = require("../payment/payment");
|
|
15
15
|
const accounting_document_1 = require("../accounting-document/accounting-document");
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* What a transaction is: a line that happened on the bank account. Money still to come is read from the records that
|
|
18
|
+
* owe it, never written as a transaction (ADR-0157) - the category is the one kind left.
|
|
19
|
+
*/
|
|
17
20
|
var TransactionCategory;
|
|
18
21
|
(function (TransactionCategory) {
|
|
19
22
|
TransactionCategory["CONFIRMED"] = "CONFIRMED";
|
|
20
|
-
TransactionCategory["FORECAST"] = "FORECAST";
|
|
21
23
|
})(TransactionCategory || (exports.TransactionCategory = TransactionCategory = {}));
|
|
22
24
|
(0, type_graphql_1.registerEnumType)(TransactionCategory, {
|
|
23
25
|
name: 'TransactionCategory',
|
|
24
|
-
description: '
|
|
26
|
+
description: 'That a transaction happened on the bank account (confirmed)'
|
|
25
27
|
});
|
|
26
28
|
var TransactionSource;
|
|
27
29
|
(function (TransactionSource) {
|
|
@@ -33,19 +35,8 @@ var TransactionSource;
|
|
|
33
35
|
name: 'TransactionSource',
|
|
34
36
|
description: 'Where the facts of a confirmed transaction come from - a bank statement file, an old ledger, or a person'
|
|
35
37
|
});
|
|
36
|
-
var ForecastStatus;
|
|
37
|
-
(function (ForecastStatus) {
|
|
38
|
-
ForecastStatus["PLANNED"] = "PLANNED";
|
|
39
|
-
ForecastStatus["DONE"] = "DONE";
|
|
40
|
-
ForecastStatus["CANCELLED"] = "CANCELLED";
|
|
41
|
-
})(ForecastStatus || (exports.ForecastStatus = ForecastStatus = {}));
|
|
42
|
-
(0, type_graphql_1.registerEnumType)(ForecastStatus, {
|
|
43
|
-
name: 'ForecastStatus',
|
|
44
|
-
description: 'State of a forecast - still expected, happened, dropped'
|
|
45
|
-
});
|
|
46
38
|
/**
|
|
47
|
-
* Money that
|
|
48
|
-
* still to come or go (forecast).
|
|
39
|
+
* Money that moved in or out of the business: a line on a bank account.
|
|
49
40
|
*
|
|
50
41
|
* What a transaction paid - a contract round, a tax invoice, a VAT period - is its payments (§`Payment`). The facts
|
|
51
42
|
* of a bank line are kept as the bank gave them, beside what a person wrote about it.
|
|
@@ -77,7 +68,7 @@ tslib_1.__decorate([
|
|
|
77
68
|
], Transaction.prototype, "domainId", void 0);
|
|
78
69
|
tslib_1.__decorate([
|
|
79
70
|
(0, typeorm_1.Column)({ default: TransactionCategory.CONFIRMED }),
|
|
80
|
-
(0, type_graphql_1.Field)(type => TransactionCategory, { description: 'Confirmed
|
|
71
|
+
(0, type_graphql_1.Field)(type => TransactionCategory, { description: 'Confirmed - on the bank account' }),
|
|
81
72
|
tslib_1.__metadata("design:type", String)
|
|
82
73
|
], Transaction.prototype, "category", void 0);
|
|
83
74
|
tslib_1.__decorate([
|
|
@@ -98,7 +89,7 @@ tslib_1.__decorate([
|
|
|
98
89
|
(0, typeorm_1.Column)({ nullable: true }),
|
|
99
90
|
(0, type_graphql_1.Field)({
|
|
100
91
|
nullable: true,
|
|
101
|
-
description: "YYYY-MM-DD - the day in the account's time zone
|
|
92
|
+
description: "YYYY-MM-DD - the day in the account's time zone"
|
|
102
93
|
}),
|
|
103
94
|
tslib_1.__metadata("design:type", String)
|
|
104
95
|
], Transaction.prototype, "transactionDate", void 0);
|
|
@@ -109,12 +100,12 @@ tslib_1.__decorate([
|
|
|
109
100
|
], Transaction.prototype, "transactionAt", void 0);
|
|
110
101
|
tslib_1.__decorate([
|
|
111
102
|
(0, typeorm_1.Column)({ type: 'int' }),
|
|
112
|
-
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { description: 'Year of the transaction date
|
|
103
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { description: 'Year of the transaction date' }),
|
|
113
104
|
tslib_1.__metadata("design:type", Number)
|
|
114
105
|
], Transaction.prototype, "year", void 0);
|
|
115
106
|
tslib_1.__decorate([
|
|
116
107
|
(0, typeorm_1.Column)({ type: 'int' }),
|
|
117
|
-
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { description: 'Month of the transaction date
|
|
108
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { description: 'Month of the transaction date' }),
|
|
118
109
|
tslib_1.__metadata("design:type", Number)
|
|
119
110
|
], Transaction.prototype, "month", void 0);
|
|
120
111
|
tslib_1.__decorate([
|
|
@@ -146,7 +137,7 @@ tslib_1.__decorate([
|
|
|
146
137
|
], Transaction.prototype, "accountId", void 0);
|
|
147
138
|
tslib_1.__decorate([
|
|
148
139
|
(0, typeorm_1.Column)({ type: 'text', nullable: true }),
|
|
149
|
-
(0, type_graphql_1.Field)({ nullable: true, description: 'What a person wrote about it
|
|
140
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'What a person wrote about it' }),
|
|
150
141
|
tslib_1.__metadata("design:type", String)
|
|
151
142
|
], Transaction.prototype, "description", void 0);
|
|
152
143
|
tslib_1.__decorate([
|
|
@@ -242,41 +233,11 @@ tslib_1.__decorate([
|
|
|
242
233
|
(0, type_graphql_1.Field)({ nullable: true, description: 'Memo as the bank wrote it' }),
|
|
243
234
|
tslib_1.__metadata("design:type", String)
|
|
244
235
|
], Transaction.prototype, "bankMemo", void 0);
|
|
245
|
-
tslib_1.__decorate([
|
|
246
|
-
(0, typeorm_1.Column)({ nullable: true }),
|
|
247
|
-
(0, type_graphql_1.Field)({
|
|
248
|
-
nullable: true,
|
|
249
|
-
description: 'When in the month a forecast falls, as a person wrote it - 15th, end of month'
|
|
250
|
-
}),
|
|
251
|
-
tslib_1.__metadata("design:type", String)
|
|
252
|
-
], Transaction.prototype, "timing", void 0);
|
|
253
|
-
tslib_1.__decorate([
|
|
254
|
-
(0, typeorm_1.Column)({ nullable: true }),
|
|
255
|
-
(0, type_graphql_1.Field)(type => ForecastStatus, {
|
|
256
|
-
nullable: true,
|
|
257
|
-
description: 'State of a forecast; empty on a confirmed transaction'
|
|
258
|
-
}),
|
|
259
|
-
tslib_1.__metadata("design:type", String)
|
|
260
|
-
], Transaction.prototype, "status", void 0);
|
|
261
|
-
tslib_1.__decorate([
|
|
262
|
-
(0, typeorm_1.Column)({ type: 'int', nullable: true }),
|
|
263
|
-
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'The probability of a forecast being realized (0 to 100)' }),
|
|
264
|
-
tslib_1.__metadata("design:type", Number)
|
|
265
|
-
], Transaction.prototype, "probability", void 0);
|
|
266
236
|
tslib_1.__decorate([
|
|
267
237
|
(0, typeorm_1.Column)({ type: 'text', nullable: true }),
|
|
268
238
|
(0, type_graphql_1.Field)({ nullable: true, description: 'Notes' }),
|
|
269
239
|
tslib_1.__metadata("design:type", String)
|
|
270
240
|
], Transaction.prototype, "notes", void 0);
|
|
271
|
-
tslib_1.__decorate([
|
|
272
|
-
(0, typeorm_1.ManyToOne)(type => recurring_cash_item_1.RecurringCashItem, { nullable: true, onDelete: 'SET NULL' }),
|
|
273
|
-
(0, type_graphql_1.Field)(type => recurring_cash_item_1.RecurringCashItem, { nullable: true, description: 'The recurring item a forecast was made from' }),
|
|
274
|
-
tslib_1.__metadata("design:type", recurring_cash_item_1.RecurringCashItem)
|
|
275
|
-
], Transaction.prototype, "recurringItem", void 0);
|
|
276
|
-
tslib_1.__decorate([
|
|
277
|
-
(0, typeorm_1.RelationId)((transaction) => transaction.recurringItem),
|
|
278
|
-
tslib_1.__metadata("design:type", String)
|
|
279
|
-
], Transaction.prototype, "recurringItemId", void 0);
|
|
280
241
|
tslib_1.__decorate([
|
|
281
242
|
(0, typeorm_1.OneToMany)(type => payment_1.Payment, payment => payment.transaction),
|
|
282
243
|
(0, type_graphql_1.Field)(type => [payment_1.Payment], { nullable: true, description: 'What this transaction paid' }),
|
|
@@ -321,7 +282,7 @@ tslib_1.__decorate([
|
|
|
321
282
|
tslib_1.__metadata("design:type", String)
|
|
322
283
|
], Transaction.prototype, "updaterId", void 0);
|
|
323
284
|
exports.Transaction = Transaction = tslib_1.__decorate([
|
|
324
|
-
(0, type_graphql_1.ObjectType)({ description: 'Money
|
|
285
|
+
(0, type_graphql_1.ObjectType)({ description: 'Money that moved in or out - a bank line' }),
|
|
325
286
|
(0, typeorm_1.Entity)(),
|
|
326
287
|
(0, typeorm_1.Index)('ix_transaction_0', (transaction) => [transaction.domain, transaction.bankFingerprint], {
|
|
327
288
|
unique: true,
|