@things-factory/accounting 10.1.124 → 10.1.135
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/route.d.ts +1 -1
- package/dist-client/route.js +0 -12
- package/dist-client/route.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/index.d.ts +0 -1
- package/dist-server/index.js +0 -1
- package/dist-server/index.js.map +1 -1
- package/dist-server/service/account/account-history.d.ts +13 -6
- package/dist-server/service/account/account-history.js +44 -17
- package/dist-server/service/account/account-history.js.map +1 -1
- package/dist-server/service/account/account-mutation.js +8 -8
- package/dist-server/service/account/account-mutation.js.map +1 -1
- package/dist-server/service/account/account-query.js +2 -2
- package/dist-server/service/account/account-query.js.map +1 -1
- package/dist-server/service/account/account-type.d.ts +16 -0
- package/dist-server/service/account/account-type.js +71 -13
- package/dist-server/service/account/account-type.js.map +1 -1
- package/dist-server/service/account/account.d.ts +9 -3
- package/dist-server/service/account/account.js +34 -8
- package/dist-server/service/account/account.js.map +1 -1
- package/dist-server/service/account/index.d.ts +1 -1
- package/dist-server/service/accounting-category/accounting-category-mutation.js +8 -8
- package/dist-server/service/accounting-category/accounting-category-mutation.js.map +1 -1
- package/dist-server/service/accounting-category/accounting-category-query.js +2 -2
- package/dist-server/service/accounting-category/accounting-category-query.js.map +1 -1
- package/dist-server/service/accounting-category/index.d.ts +1 -1
- package/dist-server/service/accounting-document/accounting-document-mutation.js +12 -3
- package/dist-server/service/accounting-document/accounting-document-mutation.js.map +1 -1
- package/dist-server/service/accounting-document/accounting-document-query.js +2 -0
- package/dist-server/service/accounting-document/accounting-document-query.js.map +1 -1
- package/dist-server/service/accounting-document/index.d.ts +1 -1
- package/dist-server/service/bank-account/bank-account-history.d.ts +11 -14
- package/dist-server/service/bank-account/bank-account-history.js +46 -59
- package/dist-server/service/bank-account/bank-account-history.js.map +1 -1
- package/dist-server/service/bank-account/bank-account-mutation.d.ts +1 -2
- package/dist-server/service/bank-account/bank-account-mutation.js +25 -69
- package/dist-server/service/bank-account/bank-account-mutation.js.map +1 -1
- package/dist-server/service/bank-account/bank-account-query.js +2 -0
- package/dist-server/service/bank-account/bank-account-query.js.map +1 -1
- package/dist-server/service/bank-account/bank-account-service.d.ts +5 -0
- package/dist-server/service/bank-account/bank-account-service.js +21 -0
- package/dist-server/service/bank-account/bank-account-service.js.map +1 -0
- package/dist-server/service/bank-account/bank-account-type.d.ts +13 -19
- package/dist-server/service/bank-account/bank-account-type.js +45 -69
- package/dist-server/service/bank-account/bank-account-type.js.map +1 -1
- package/dist-server/service/bank-account/bank-account.d.ts +14 -17
- package/dist-server/service/bank-account/bank-account.js +45 -57
- package/dist-server/service/bank-account/bank-account.js.map +1 -1
- package/dist-server/service/bank-account/index.d.ts +1 -1
- package/dist-server/service/bank-statement/bank-statement-query.d.ts +14 -0
- package/dist-server/service/bank-statement/bank-statement-query.js +92 -0
- package/dist-server/service/bank-statement/bank-statement-query.js.map +1 -0
- package/dist-server/service/bank-statement/bank-statement.d.ts +26 -0
- package/dist-server/service/bank-statement/bank-statement.js +109 -0
- package/dist-server/service/bank-statement/bank-statement.js.map +1 -0
- package/dist-server/service/bank-statement/index.d.ts +5 -0
- package/dist-server/service/bank-statement/index.js +9 -0
- package/dist-server/service/bank-statement/index.js.map +1 -0
- package/dist-server/service/cash-flow-type.d.ts +5 -0
- package/dist-server/service/cash-flow-type.js +15 -0
- package/dist-server/service/cash-flow-type.js.map +1 -0
- package/dist-server/service/financial-institution/financial-institution-mutation.js +10 -1
- package/dist-server/service/financial-institution/financial-institution-mutation.js.map +1 -1
- package/dist-server/service/financial-institution/financial-institution-query.js +14 -6
- package/dist-server/service/financial-institution/financial-institution-query.js.map +1 -1
- package/dist-server/service/financial-statement/financial-statement-history.d.ts +11 -9
- package/dist-server/service/financial-statement/financial-statement-history.js +44 -33
- package/dist-server/service/financial-statement/financial-statement-history.js.map +1 -1
- package/dist-server/service/financial-statement/financial-statement-line.d.ts +24 -0
- package/dist-server/service/financial-statement/financial-statement-line.js +108 -0
- package/dist-server/service/financial-statement/financial-statement-line.js.map +1 -0
- package/dist-server/service/financial-statement/financial-statement-mutation.d.ts +1 -8
- package/dist-server/service/financial-statement/financial-statement-mutation.js +11 -136
- package/dist-server/service/financial-statement/financial-statement-mutation.js.map +1 -1
- package/dist-server/service/financial-statement/financial-statement-query.d.ts +8 -7
- package/dist-server/service/financial-statement/financial-statement-query.js +42 -32
- package/dist-server/service/financial-statement/financial-statement-query.js.map +1 -1
- package/dist-server/service/financial-statement/financial-statement-service.d.ts +33 -0
- package/dist-server/service/financial-statement/financial-statement-service.js +44 -0
- package/dist-server/service/financial-statement/financial-statement-service.js.map +1 -0
- package/dist-server/service/financial-statement/financial-statement.d.ts +19 -11
- package/dist-server/service/financial-statement/financial-statement.js +70 -62
- package/dist-server/service/financial-statement/financial-statement.js.map +1 -1
- package/dist-server/service/financial-statement/index.d.ts +4 -3
- package/dist-server/service/financial-statement/index.js +2 -2
- package/dist-server/service/financial-statement/index.js.map +1 -1
- package/dist-server/service/fiscal-month/fiscal-month-mutation.js +6 -6
- package/dist-server/service/fiscal-month/fiscal-month-mutation.js.map +1 -1
- package/dist-server/service/fiscal-month/fiscal-month-query.js +2 -2
- package/dist-server/service/fiscal-month/fiscal-month-query.js.map +1 -1
- package/dist-server/service/fiscal-month/index.d.ts +1 -1
- package/dist-server/service/fiscal-quarter/fiscal-quarter-mutation.js +6 -6
- package/dist-server/service/fiscal-quarter/fiscal-quarter-mutation.js.map +1 -1
- package/dist-server/service/fiscal-quarter/fiscal-quarter-query.js +2 -2
- package/dist-server/service/fiscal-quarter/fiscal-quarter-query.js.map +1 -1
- package/dist-server/service/fiscal-quarter/index.d.ts +1 -1
- package/dist-server/service/fiscal-year/fiscal-year-mutation.js +6 -6
- package/dist-server/service/fiscal-year/fiscal-year-mutation.js.map +1 -1
- package/dist-server/service/fiscal-year/fiscal-year-query.js +2 -2
- package/dist-server/service/fiscal-year/fiscal-year-query.js.map +1 -1
- package/dist-server/service/fiscal-year/index.d.ts +1 -1
- package/dist-server/service/index.d.ts +15 -3
- package/dist-server/service/index.js +30 -13
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/payment/index.d.ts +2 -1
- package/dist-server/service/payment/index.js +1 -0
- package/dist-server/service/payment/index.js.map +1 -1
- package/dist-server/service/payment/payment-history.d.ts +9 -16
- package/dist-server/service/payment/payment-history.js +36 -70
- package/dist-server/service/payment/payment-history.js.map +1 -1
- package/dist-server/service/payment/payment-mutation.d.ts +0 -1
- package/dist-server/service/payment/payment-mutation.js +19 -84
- package/dist-server/service/payment/payment-mutation.js.map +1 -1
- package/dist-server/service/payment/payment-query.d.ts +3 -0
- package/dist-server/service/payment/payment-query.js +32 -3
- package/dist-server/service/payment/payment-query.js.map +1 -1
- package/dist-server/service/payment/payment-service.d.ts +16 -0
- package/dist-server/service/payment/payment-service.js +140 -0
- package/dist-server/service/payment/payment-service.js.map +1 -0
- package/dist-server/service/payment/payment-targets.d.ts +31 -0
- package/dist-server/service/payment/payment-targets.js +19 -0
- package/dist-server/service/payment/payment-targets.js.map +1 -0
- package/dist-server/service/payment/payment-type.d.ts +13 -17
- package/dist-server/service/payment/payment-type.js +35 -51
- package/dist-server/service/payment/payment-type.js.map +1 -1
- package/dist-server/service/payment/payment.d.ts +23 -22
- package/dist-server/service/payment/payment.js +65 -95
- package/dist-server/service/payment/payment.js.map +1 -1
- package/dist-server/service/payment/transfer-target.d.ts +1 -0
- package/dist-server/service/payment/transfer-target.js +43 -0
- package/dist-server/service/payment/transfer-target.js.map +1 -0
- package/dist-server/service/recurring-cash-item/index.d.ts +6 -0
- package/dist-server/service/recurring-cash-item/index.js +10 -0
- package/dist-server/service/recurring-cash-item/index.js.map +1 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item-mutation.d.ts +7 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item-mutation.js +63 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item-mutation.js.map +1 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item-query.d.ts +15 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item-query.js +101 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item-query.js.map +1 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item-service.d.ts +23 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item-service.js +91 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item-service.js.map +1 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item-type.d.ts +23 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item-type.js +85 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item-type.js.map +1 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item.d.ts +35 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item.js +142 -0
- package/dist-server/service/recurring-cash-item/recurring-cash-item.js.map +1 -0
- package/dist-server/service/recurring-cash-item/recurring-schedule.d.ts +36 -0
- package/dist-server/service/recurring-cash-item/recurring-schedule.js +41 -0
- package/dist-server/service/recurring-cash-item/recurring-schedule.js.map +1 -0
- package/dist-server/service/transaction/index.d.ts +2 -2
- package/dist-server/service/transaction/transaction-history.d.ts +42 -15
- package/dist-server/service/transaction/transaction-history.js +160 -54
- package/dist-server/service/transaction/transaction-history.js.map +1 -1
- package/dist-server/service/transaction/transaction-mutation.d.ts +0 -1
- package/dist-server/service/transaction/transaction-mutation.js +18 -83
- package/dist-server/service/transaction/transaction-mutation.js.map +1 -1
- package/dist-server/service/transaction/transaction-period.d.ts +16 -0
- package/dist-server/service/transaction/transaction-period.js +49 -0
- package/dist-server/service/transaction/transaction-period.js.map +1 -0
- package/dist-server/service/transaction/transaction-query.d.ts +12 -0
- package/dist-server/service/transaction/transaction-query.js +86 -4
- package/dist-server/service/transaction/transaction-query.js.map +1 -1
- package/dist-server/service/transaction/transaction-service.d.ts +30 -0
- package/dist-server/service/transaction/transaction-service.js +130 -0
- package/dist-server/service/transaction/transaction-service.js.map +1 -0
- package/dist-server/service/transaction/transaction-type.d.ts +39 -7
- package/dist-server/service/transaction/transaction-type.js +145 -23
- package/dist-server/service/transaction/transaction-type.js.map +1 -1
- package/dist-server/service/transaction/transaction.d.ts +58 -31
- package/dist-server/service/transaction/transaction.js +213 -111
- package/dist-server/service/transaction/transaction.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -4
- package/things-factory.config.js +0 -4
- package/translations/en.json +34 -2
- package/translations/ja.json +0 -1
- package/translations/ko.json +34 -2
- package/translations/ms.json +0 -1
- package/translations/zh.json +0 -1
- package/dist-client/pages/account/account-importer.d.ts +0 -22
- package/dist-client/pages/account/account-importer.js +0 -99
- package/dist-client/pages/account/account-importer.js.map +0 -1
- package/dist-client/pages/account/account-list-page.d.ts +0 -57
- package/dist-client/pages/account/account-list-page.js +0 -306
- package/dist-client/pages/account/account-list-page.js.map +0 -1
- package/dist-client/pages/bank-account/bank-account-importer.d.ts +0 -23
- package/dist-client/pages/bank-account/bank-account-importer.js +0 -92
- package/dist-client/pages/bank-account/bank-account-importer.js.map +0 -1
- package/dist-client/pages/bank-account/bank-account-list-page.d.ts +0 -60
- package/dist-client/pages/bank-account/bank-account-list-page.js +0 -317
- package/dist-client/pages/bank-account/bank-account-list-page.js.map +0 -1
- package/dist-client/pages/financial-statement/financial-statement-importer.d.ts +0 -22
- package/dist-client/pages/financial-statement/financial-statement-importer.js +0 -99
- package/dist-client/pages/financial-statement/financial-statement-importer.js.map +0 -1
- package/dist-client/pages/financial-statement/financial-statement-list-page.d.ts +0 -57
- package/dist-client/pages/financial-statement/financial-statement-list-page.js +0 -280
- package/dist-client/pages/financial-statement/financial-statement-list-page.js.map +0 -1
- package/dist-client/pages/income-statement/income-statement-importer.d.ts +0 -22
- package/dist-client/pages/income-statement/income-statement-importer.js +0 -99
- package/dist-client/pages/income-statement/income-statement-importer.js.map +0 -1
- package/dist-client/pages/income-statement/income-statement-list-page.d.ts +0 -57
- package/dist-client/pages/income-statement/income-statement-list-page.js +0 -280
- package/dist-client/pages/income-statement/income-statement-list-page.js.map +0 -1
- package/dist-client/pages/payment/payment-importer.d.ts +0 -23
- package/dist-client/pages/payment/payment-importer.js +0 -92
- package/dist-client/pages/payment/payment-importer.js.map +0 -1
- package/dist-client/pages/payment/payment-list-page.d.ts +0 -60
- package/dist-client/pages/payment/payment-list-page.js +0 -317
- package/dist-client/pages/payment/payment-list-page.js.map +0 -1
- package/dist-client/pages/transaction/transaction-importer.d.ts +0 -22
- package/dist-client/pages/transaction/transaction-importer.js +0 -99
- package/dist-client/pages/transaction/transaction-importer.js.map +0 -1
- package/dist-client/pages/transaction/transaction-list-page.d.ts +0 -57
- package/dist-client/pages/transaction/transaction-list-page.js +0 -280
- package/dist-client/pages/transaction/transaction-list-page.js.map +0 -1
- package/dist-server/controllers/index.d.ts +0 -1
- package/dist-server/controllers/index.js +0 -5
- package/dist-server/controllers/index.js.map +0 -1
- package/dist-server/controllers/summary-statements.d.ts +0 -4
- package/dist-server/controllers/summary-statements.js +0 -149
- package/dist-server/controllers/summary-statements.js.map +0 -1
- package/dist-server/migrations/1725201567284-seed-country-codes.d.ts +0 -5
- package/dist-server/migrations/1725201567284-seed-country-codes.js +0 -255
- package/dist-server/migrations/1725201567284-seed-country-codes.js.map +0 -1
- package/dist-server/service/financial-statement/financial-statement-line-item.d.ts +0 -19
- package/dist-server/service/financial-statement/financial-statement-line-item.js +0 -94
- package/dist-server/service/financial-statement/financial-statement-line-item.js.map +0 -1
- package/dist-server/service/financial-statement/financial-statement-type.d.ts +0 -20
- package/dist-server/service/financial-statement/financial-statement-type.js +0 -77
- package/dist-server/service/financial-statement/financial-statement-type.js.map +0 -1
- package/dist-server/service/income-statement/event-subscriber.d.ts +0 -7
- package/dist-server/service/income-statement/event-subscriber.js +0 -21
- package/dist-server/service/income-statement/event-subscriber.js.map +0 -1
- package/dist-server/service/income-statement/income-statement-history.d.ts +0 -28
- package/dist-server/service/income-statement/income-statement-history.js +0 -146
- package/dist-server/service/income-statement/income-statement-history.js.map +0 -1
- package/dist-server/service/income-statement/income-statement-line-item.d.ts +0 -19
- package/dist-server/service/income-statement/income-statement-line-item.js +0 -96
- package/dist-server/service/income-statement/income-statement-line-item.js.map +0 -1
- package/dist-server/service/income-statement/income-statement-mutation.d.ts +0 -10
- package/dist-server/service/income-statement/income-statement-mutation.js +0 -159
- package/dist-server/service/income-statement/income-statement-mutation.js.map +0 -1
- package/dist-server/service/income-statement/income-statement-query.d.ts +0 -11
- package/dist-server/service/income-statement/income-statement-query.js +0 -81
- package/dist-server/service/income-statement/income-statement-query.js.map +0 -1
- package/dist-server/service/income-statement/income-statement-type.d.ts +0 -20
- package/dist-server/service/income-statement/income-statement-type.js +0 -77
- package/dist-server/service/income-statement/income-statement-type.js.map +0 -1
- package/dist-server/service/income-statement/income-statement.d.ts +0 -28
- package/dist-server/service/income-statement/income-statement.js +0 -137
- package/dist-server/service/income-statement/income-statement.js.map +0 -1
- package/dist-server/service/income-statement/index.d.ts +0 -8
- package/dist-server/service/income-statement/index.js +0 -13
- package/dist-server/service/income-statement/index.js.map +0 -1
|
@@ -3,96 +3,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TransactionMutation = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const type_graphql_1 = require("type-graphql");
|
|
6
|
-
const typeorm_1 = require("typeorm");
|
|
7
6
|
const shell_1 = require("@things-factory/shell");
|
|
8
7
|
const transaction_1 = require("./transaction");
|
|
8
|
+
const transaction_service_1 = require("./transaction-service");
|
|
9
9
|
const transaction_type_1 = require("./transaction-type");
|
|
10
10
|
let TransactionMutation = class TransactionMutation {
|
|
11
11
|
async createTransaction(transaction, context) {
|
|
12
12
|
const { domain, user, tx } = context.state;
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
domain,
|
|
16
|
-
creator: user,
|
|
17
|
-
updater: user
|
|
18
|
-
});
|
|
19
|
-
return result;
|
|
13
|
+
const [saved] = await (0, transaction_service_1.saveTransactions)(tx, domain, user, [{ ...transaction, cuFlag: '+' }]);
|
|
14
|
+
return saved;
|
|
20
15
|
}
|
|
21
16
|
async updateTransaction(id, patch, context) {
|
|
22
17
|
const { domain, user, tx } = context.state;
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
where: { domain: { id: domain.id }, id }
|
|
26
|
-
});
|
|
27
|
-
const result = await repository.save({
|
|
28
|
-
...transaction,
|
|
29
|
-
...patch,
|
|
30
|
-
updater: user
|
|
31
|
-
});
|
|
32
|
-
return result;
|
|
18
|
+
const [saved] = await (0, transaction_service_1.saveTransactions)(tx, domain, user, [{ ...patch, id, cuFlag: 'M' }]);
|
|
19
|
+
return saved;
|
|
33
20
|
}
|
|
34
21
|
async updateMultipleTransaction(patches, context) {
|
|
35
22
|
const { domain, user, tx } = context.state;
|
|
36
|
-
|
|
37
|
-
const _createRecords = patches.filter((patch) => patch.cuFlag.toUpperCase() === '+');
|
|
38
|
-
const _updateRecords = patches.filter((patch) => patch.cuFlag.toUpperCase() === 'M');
|
|
39
|
-
const transactionRepo = (0, shell_1.getRepository)(transaction_1.Transaction, tx);
|
|
40
|
-
if (_createRecords.length > 0) {
|
|
41
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
42
|
-
const newRecord = _createRecords[i];
|
|
43
|
-
const result = await transactionRepo.save({
|
|
44
|
-
...newRecord,
|
|
45
|
-
domain,
|
|
46
|
-
creator: user,
|
|
47
|
-
updater: user
|
|
48
|
-
});
|
|
49
|
-
results.push({ ...result, cuFlag: '+' });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
if (_updateRecords.length > 0) {
|
|
53
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
54
|
-
const updateRecord = _updateRecords[i];
|
|
55
|
-
const transaction = await transactionRepo.findOne({
|
|
56
|
-
where: { domain: { id: domain.id }, id: updateRecord.id }
|
|
57
|
-
});
|
|
58
|
-
if (!transaction) {
|
|
59
|
-
throw new Error(`failed to find transaction to update: ${updateRecord.id}`);
|
|
60
|
-
}
|
|
61
|
-
const result = await transactionRepo.save({
|
|
62
|
-
...transaction,
|
|
63
|
-
...updateRecord,
|
|
64
|
-
updater: user
|
|
65
|
-
});
|
|
66
|
-
results.push({ ...result, cuFlag: 'M' });
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return results;
|
|
23
|
+
return await (0, transaction_service_1.saveTransactions)(tx, domain, user, patches);
|
|
70
24
|
}
|
|
71
25
|
async deleteTransaction(id, context) {
|
|
72
|
-
const { domain, tx } = context.state;
|
|
73
|
-
await (0,
|
|
26
|
+
const { domain, user, tx } = context.state;
|
|
27
|
+
await (0, transaction_service_1.saveTransactions)(tx, domain, user, [{ id, cuFlag: '-' }]);
|
|
74
28
|
return true;
|
|
75
29
|
}
|
|
76
30
|
async deleteTransactions(ids, context) {
|
|
77
|
-
const { domain, tx } = context.state;
|
|
78
|
-
await (0,
|
|
79
|
-
domain: { id: domain.id },
|
|
80
|
-
id: (0, typeorm_1.In)(ids)
|
|
81
|
-
});
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
async importTransactions(transactions, context) {
|
|
85
|
-
const { domain, tx } = context.state;
|
|
86
|
-
await Promise.all(transactions.map(async (transaction) => {
|
|
87
|
-
const createdTransaction = await (0, shell_1.getRepository)(transaction_1.Transaction, tx).save({ domain, ...transaction });
|
|
88
|
-
}));
|
|
31
|
+
const { domain, user, tx } = context.state;
|
|
32
|
+
await (0, transaction_service_1.saveTransactions)(tx, domain, user, ids.map(id => ({ id, cuFlag: '-' })));
|
|
89
33
|
return true;
|
|
90
34
|
}
|
|
91
35
|
};
|
|
92
36
|
exports.TransactionMutation = TransactionMutation;
|
|
93
37
|
tslib_1.__decorate([
|
|
94
38
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
95
|
-
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "mutation")'),
|
|
39
|
+
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "mutation", domainOwnerGranted: true)'),
|
|
96
40
|
(0, type_graphql_1.Mutation)(returns => transaction_1.Transaction, { description: 'To create new Transaction' }),
|
|
97
41
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('transaction')),
|
|
98
42
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
@@ -102,7 +46,7 @@ tslib_1.__decorate([
|
|
|
102
46
|
], TransactionMutation.prototype, "createTransaction", null);
|
|
103
47
|
tslib_1.__decorate([
|
|
104
48
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
105
|
-
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "mutation")'),
|
|
49
|
+
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "mutation", domainOwnerGranted: true)'),
|
|
106
50
|
(0, type_graphql_1.Mutation)(returns => transaction_1.Transaction, { description: 'To modify Transaction information' }),
|
|
107
51
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
108
52
|
tslib_1.__param(1, (0, type_graphql_1.Arg)('patch')),
|
|
@@ -113,8 +57,8 @@ tslib_1.__decorate([
|
|
|
113
57
|
], TransactionMutation.prototype, "updateTransaction", null);
|
|
114
58
|
tslib_1.__decorate([
|
|
115
59
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
116
|
-
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "mutation")'),
|
|
117
|
-
(0, type_graphql_1.Mutation)(returns => [transaction_1.Transaction], { description:
|
|
60
|
+
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "mutation", domainOwnerGranted: true)'),
|
|
61
|
+
(0, type_graphql_1.Mutation)(returns => [transaction_1.Transaction], { description: 'To add, modify and delete multiple Transactions' }),
|
|
118
62
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('patches', type => [transaction_type_1.TransactionPatch])),
|
|
119
63
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
120
64
|
tslib_1.__metadata("design:type", Function),
|
|
@@ -123,7 +67,7 @@ tslib_1.__decorate([
|
|
|
123
67
|
], TransactionMutation.prototype, "updateMultipleTransaction", null);
|
|
124
68
|
tslib_1.__decorate([
|
|
125
69
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
126
|
-
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "mutation")'),
|
|
70
|
+
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "mutation", domainOwnerGranted: true)'),
|
|
127
71
|
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete Transaction' }),
|
|
128
72
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
129
73
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
@@ -133,7 +77,7 @@ tslib_1.__decorate([
|
|
|
133
77
|
], TransactionMutation.prototype, "deleteTransaction", null);
|
|
134
78
|
tslib_1.__decorate([
|
|
135
79
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
136
|
-
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "mutation")'),
|
|
80
|
+
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "mutation", domainOwnerGranted: true)'),
|
|
137
81
|
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete multiple Transactions' }),
|
|
138
82
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('ids', type => [String])),
|
|
139
83
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
@@ -141,17 +85,8 @@ tslib_1.__decorate([
|
|
|
141
85
|
tslib_1.__metadata("design:paramtypes", [Array, Object]),
|
|
142
86
|
tslib_1.__metadata("design:returntype", Promise)
|
|
143
87
|
], TransactionMutation.prototype, "deleteTransactions", null);
|
|
144
|
-
tslib_1.__decorate([
|
|
145
|
-
(0, type_graphql_1.Directive)('@transaction'),
|
|
146
|
-
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "mutation")'),
|
|
147
|
-
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To import multiple Transactions' }),
|
|
148
|
-
tslib_1.__param(0, (0, type_graphql_1.Arg)('transactions', type => [transaction_type_1.TransactionPatch])),
|
|
149
|
-
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
150
|
-
tslib_1.__metadata("design:type", Function),
|
|
151
|
-
tslib_1.__metadata("design:paramtypes", [Array, Object]),
|
|
152
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
153
|
-
], TransactionMutation.prototype, "importTransactions", null);
|
|
154
88
|
exports.TransactionMutation = TransactionMutation = tslib_1.__decorate([
|
|
155
|
-
(0, type_graphql_1.Resolver)(transaction_1.Transaction)
|
|
89
|
+
(0, type_graphql_1.Resolver)(transaction_1.Transaction),
|
|
90
|
+
(0, type_graphql_1.UseMiddleware)(shell_1.SpeakRefusals)
|
|
156
91
|
], TransactionMutation);
|
|
157
92
|
//# sourceMappingURL=transaction-mutation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-mutation.js","sourceRoot":"","sources":["../../../server/service/transaction/transaction-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,iDAAqD;AAErD,+CAA2C;AAC3C,yDAAqE;AAG9D,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAIxB,AAAN,KAAK,CAAC,iBAAiB,CACD,WAA2B,EACxC,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAa,EAAC,yBAAW,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC;YACvD,GAAG,WAAW;YACd,MAAM;YACN,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC;IAKK,AAAN,KAAK,CAAC,iBAAiB,CACV,EAAU,EACP,KAAuB,EAC9B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C,OAAO,EAAE,EAAE,WAAW,EAAE,iCAAiC,EAAE,CAAC;IAE9E,mBAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;6DAUP;AAKK;IAHL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EAAC,2DAA2D,CAAC;IACtE,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,iCAAiC,EAAE,CAAC;IAE9E,mBAAA,IAAA,kBAAG,EAAC,cAAc,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,mCAAgB,CAAC,CAAC,CAAA;IAC/C,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;6DAWP;8BA7IU,mBAAmB;IAD/B,IAAA,uBAAQ,EAAC,yBAAW,CAAC;GACT,mBAAmB,CA8I/B","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { getRepository } from '@things-factory/shell'\n\nimport { Transaction } from './transaction'\nimport { NewTransaction, TransactionPatch } from './transaction-type'\n\n@Resolver(Transaction)\nexport class TransactionMutation {\n @Directive('@transaction')\n @Directive('@privilege(category: \"accounting\", privilege: \"mutation\")')\n @Mutation(returns => Transaction, { description: 'To create new Transaction' })\n async createTransaction(\n @Arg('transaction') transaction: NewTransaction,\n @Ctx() context: ResolverContext\n ): Promise<Transaction> {\n const { domain, user, tx } = context.state\n\n const result = await getRepository(Transaction, tx).save({\n ...transaction,\n domain,\n creator: user,\n updater: user\n })\n\n return result\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"accounting\", privilege: \"mutation\")')\n @Mutation(returns => Transaction, { description: 'To modify Transaction information' })\n async updateTransaction(\n @Arg('id') id: string,\n @Arg('patch') patch: TransactionPatch,\n @Ctx() context: ResolverContext\n ): Promise<Transaction> {\n const { domain, user, tx } = context.state\n\n const repository = getRepository(Transaction, tx)\n const transaction = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const result = await repository.save({\n ...transaction,\n ...patch,\n updater: user\n })\n\n return result\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"accounting\", privilege: \"mutation\")')\n @Mutation(returns => [Transaction], { description: \"To modify multiple Transactions' information\" })\n async updateMultipleTransaction(\n @Arg('patches', type => [TransactionPatch]) patches: TransactionPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Transaction[]> {\n const { domain, user, tx } = context.state\n\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n const transactionRepo = getRepository(Transaction, tx)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await transactionRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\n })\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updateRecord = _updateRecords[i]\n const transaction = await transactionRepo.findOne({\n where: { domain: { id: domain.id }, id: updateRecord.id }\n })\n\n if (!transaction) {\n throw new Error(`failed to find transaction to update: ${updateRecord.id}`)\n }\n\n const result = await transactionRepo.save({\n ...transaction,\n ...updateRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"accounting\", privilege: \"mutation\")')\n @Mutation(returns => Boolean, { description: 'To delete Transaction' })\n async deleteTransaction(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await getRepository(Transaction, tx).delete({ domain: { id: domain.id }, id })\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"accounting\", privilege: \"mutation\")')\n @Mutation(returns => Boolean, { description: 'To delete multiple Transactions' })\n async deleteTransactions(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await getRepository(Transaction, tx).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"accounting\", privilege: \"mutation\")')\n @Mutation(returns => Boolean, { description: 'To import multiple Transactions' })\n async importTransactions(\n @Arg('transactions', type => [TransactionPatch]) transactions: TransactionPatch[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await Promise.all(\n transactions.map(async (transaction: TransactionPatch) => {\n const createdTransaction: Transaction = await getRepository(Transaction, tx).save({ domain, ...transaction })\n })\n )\n\n return true\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transaction-mutation.js","sourceRoot":"","sources":["../../../server/service/transaction/transaction-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAqF;AAErF,iDAAqD;AAErD,+CAA2C;AAC3C,+DAAwD;AACxD,yDAAqE;AAI9D,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAIxB,AAAN,KAAK,CAAC,iBAAiB,CACD,WAA2B,EACxC,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1C,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,IAAA,sCAAgB,EAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;QAE3F,OAAO,KAAK,CAAA;IACd,CAAC;IAKK,AAAN,KAAK,CAAC,iBAAiB,CACV,EAAU,EACP,KAAuB,EAC9B,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,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A;;;;4DAKpD;AAKK;IAHL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EAAC,qFAAqF,CAAC;IAChG,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,iCAAiC,EAAE,CAAC;IAE9E,mBAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;6DAWP;8BAlEU,mBAAmB;IAF/B,IAAA,uBAAQ,EAAC,yBAAW,CAAC;IACrB,IAAA,4BAAa,EAAC,qBAAa,CAAC;GAChB,mBAAmB,CAmE/B","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive, UseMiddleware } from 'type-graphql'\n\nimport { SpeakRefusals } from '@things-factory/shell'\n\nimport { Transaction } from './transaction'\nimport { saveTransactions } from './transaction-service'\nimport { NewTransaction, TransactionPatch } from './transaction-type'\n\n@Resolver(Transaction)\n@UseMiddleware(SpeakRefusals)\nexport class TransactionMutation {\n @Directive('@transaction')\n @Directive('@privilege(category: \"accounting\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Transaction, { description: 'To create new Transaction' })\n async createTransaction(\n @Arg('transaction') transaction: NewTransaction,\n @Ctx() context: ResolverContext\n ): Promise<Transaction> {\n const { domain, user, tx } = context.state\n const [saved] = await saveTransactions(tx, domain, user, [{ ...transaction, cuFlag: '+' }])\n\n return saved\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"accounting\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Transaction, { description: 'To modify Transaction information' })\n async updateTransaction(\n @Arg('id') id: string,\n @Arg('patch') patch: TransactionPatch,\n @Ctx() context: ResolverContext\n ): Promise<Transaction> {\n const { domain, user, tx } = context.state\n const [saved] = await saveTransactions(tx, domain, user, [{ ...patch, id, cuFlag: 'M' }])\n\n return saved\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"accounting\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => [Transaction], { description: 'To add, modify and delete multiple Transactions' })\n async updateMultipleTransaction(\n @Arg('patches', type => [TransactionPatch]) patches: TransactionPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Transaction[]> {\n const { domain, user, tx } = context.state\n\n return await saveTransactions(tx, domain, user, patches)\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"accounting\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To delete Transaction' })\n async deleteTransaction(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, user, tx } = context.state\n await saveTransactions(tx, domain, user, [{ id, cuFlag: '-' }])\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"accounting\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To delete multiple Transactions' })\n async deleteTransactions(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, user, tx } = context.state\n await saveTransactions(\n tx,\n domain,\n user,\n ids.map(id => ({ id, cuFlag: '-' }))\n )\n\n return true\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The year, month and day of a transaction. Pure: the save service and the tests call it.
|
|
3
|
+
*/
|
|
4
|
+
/** The year and month of a `YYYY-MM-DD` day, or undefined when it is not one. */
|
|
5
|
+
export declare function yearMonthOf(day: string | null | undefined): {
|
|
6
|
+
year: number;
|
|
7
|
+
month: number;
|
|
8
|
+
} | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* The day a forecast's timing names, or null when it names none.
|
|
11
|
+
*
|
|
12
|
+
* `15일` · `15` · `매월 15일` → the 15th; `말일` · `월말` · `말` → the last day; a full
|
|
13
|
+
* `YYYY-MM-DD` inside the same month → that day. A day past the month's end (`31일` in
|
|
14
|
+
* September) is the last day — that is what a ledger means by it.
|
|
15
|
+
*/
|
|
16
|
+
export declare function forecastDay(year: number, month: number, timing: string | null | undefined): string | null;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The year, month and day of a transaction. Pure: the save service and the tests call it.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.yearMonthOf = yearMonthOf;
|
|
7
|
+
exports.forecastDay = forecastDay;
|
|
8
|
+
const ISO_DAY = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
9
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
10
|
+
const lastDay = (year, month) => new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
11
|
+
/** The year and month of a `YYYY-MM-DD` day, or undefined when it is not one. */
|
|
12
|
+
function yearMonthOf(day) {
|
|
13
|
+
const match = day ? ISO_DAY.exec(day) : null;
|
|
14
|
+
if (!match)
|
|
15
|
+
return undefined;
|
|
16
|
+
const [year, month, date] = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
17
|
+
if (month < 1 || month > 12 || date < 1 || date > lastDay(year, month))
|
|
18
|
+
return undefined;
|
|
19
|
+
return { year, month };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The day a forecast's timing names, or null when it names none.
|
|
23
|
+
*
|
|
24
|
+
* `15일` · `15` · `매월 15일` → the 15th; `말일` · `월말` · `말` → the last day; a full
|
|
25
|
+
* `YYYY-MM-DD` inside the same month → that day. A day past the month's end (`31일` in
|
|
26
|
+
* September) is the last day — that is what a ledger means by it.
|
|
27
|
+
*/
|
|
28
|
+
function forecastDay(year, month, timing) {
|
|
29
|
+
const text = String(timing ?? '').trim();
|
|
30
|
+
if (!text || !year || !month)
|
|
31
|
+
return null;
|
|
32
|
+
const full = text.match(/(\d{4})[-./](\d{1,2})[-./](\d{1,2})/);
|
|
33
|
+
if (full) {
|
|
34
|
+
const [y, m, d] = [Number(full[1]), Number(full[2]), Number(full[3])];
|
|
35
|
+
if (y === year && m === month && d >= 1 && d <= lastDay(y, m))
|
|
36
|
+
return `${y}-${pad(m)}-${pad(d)}`;
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (/말/.test(text))
|
|
40
|
+
return `${year}-${pad(month)}-${pad(lastDay(year, month))}`;
|
|
41
|
+
const day = text.match(/^(?:매월\s*)?(\d{1,2})\s*일?$/);
|
|
42
|
+
if (day) {
|
|
43
|
+
const d = Math.min(Number(day[1]), lastDay(year, month));
|
|
44
|
+
if (d >= 1)
|
|
45
|
+
return `${year}-${pad(month)}-${pad(d)}`;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=transaction-period.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-period.js","sourceRoot":"","sources":["../../../server/service/transaction/transaction-period.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAOH,kCAMC;AASD,kCAoBC;AAxCD,MAAM,OAAO,GAAG,2BAA2B,CAAA;AAC3C,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AACrD,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAA;AAEhG,iFAAiF;AACjF,SAAgB,WAAW,CAAC,GAA8B;IACxD,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAC5C,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAA;IAC5B,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AAA;IACb,CAAC;IAED,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,GAAG,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,CAAA;IAE/E,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAA;IACpD,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;QACxD,IAAI,CAAC,IAAI,CAAC;YAAE,OAAO,GAAG,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;IACtD,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["/**\n * The year, month and day of a transaction. Pure: the save service and the tests call it.\n */\n\nconst ISO_DAY = /^(\\d{4})-(\\d{2})-(\\d{2})$/\nconst pad = (n: number) => String(n).padStart(2, '0')\nconst lastDay = (year: number, month: number) => new Date(Date.UTC(year, month, 0)).getUTCDate()\n\n/** The year and month of a `YYYY-MM-DD` day, or undefined when it is not one. */\nexport function yearMonthOf(day: string | null | undefined): { year: number; month: number } | undefined {\n const match = day ? ISO_DAY.exec(day) : null\n if (!match) return undefined\n const [year, month, date] = [Number(match[1]), Number(match[2]), Number(match[3])]\n if (month < 1 || month > 12 || date < 1 || date > lastDay(year, month)) return undefined\n return { year, month }\n}\n\n/**\n * The day a forecast's timing names, or null when it names none.\n *\n * `15일` · `15` · `매월 15일` → the 15th; `말일` · `월말` · `말` → the last day; a full\n * `YYYY-MM-DD` inside the same month → that day. A day past the month's end (`31일` in\n * September) is the last day — that is what a ledger means by it.\n */\nexport function forecastDay(year: number, month: number, timing: string | null | undefined): string | null {\n const text = String(timing ?? '').trim()\n if (!text || !year || !month) return null\n\n const full = text.match(/(\\d{4})[-./](\\d{1,2})[-./](\\d{1,2})/)\n if (full) {\n const [y, m, d] = [Number(full[1]), Number(full[2]), Number(full[3])]\n if (y === year && m === month && d >= 1 && d <= lastDay(y, m)) return `${y}-${pad(m)}-${pad(d)}`\n return null\n }\n\n if (/말/.test(text)) return `${year}-${pad(month)}-${pad(lastDay(year, month))}`\n\n const day = text.match(/^(?:매월\\s*)?(\\d{1,2})\\s*일?$/)\n if (day) {\n const d = Math.min(Number(day[1]), lastDay(year, month))\n if (d >= 1) return `${year}-${pad(month)}-${pad(d)}`\n }\n\n return null\n}\n"]}
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { Domain, ListParam } from '@things-factory/shell';
|
|
2
2
|
import { User } from '@things-factory/auth-base';
|
|
3
|
+
import { Counterparty } from '@things-factory/biz-base';
|
|
4
|
+
import { Account } from '../account/account';
|
|
5
|
+
import { BankAccount } from '../bank-account/bank-account';
|
|
6
|
+
import { BankStatement } from '../bank-statement/bank-statement';
|
|
7
|
+
import { Payment } from '../payment/payment';
|
|
8
|
+
import { RecurringCashItem } from '../recurring-cash-item/recurring-cash-item';
|
|
3
9
|
import { Transaction } from './transaction';
|
|
4
10
|
import { TransactionList } from './transaction-type';
|
|
5
11
|
export declare class TransactionQuery {
|
|
6
12
|
transaction(id: string, context: ResolverContext): Promise<Transaction>;
|
|
7
13
|
transactions(params: ListParam, context: ResolverContext): Promise<TransactionList>;
|
|
14
|
+
bankAccount(transaction: Transaction): Promise<BankAccount | null>;
|
|
15
|
+
account(transaction: Transaction): Promise<Account | null>;
|
|
16
|
+
counterparty(transaction: Transaction): Promise<Counterparty | null>;
|
|
17
|
+
bankStatement(transaction: Transaction): Promise<BankStatement | null>;
|
|
18
|
+
recurringItem(transaction: Transaction): Promise<RecurringCashItem | null>;
|
|
19
|
+
payments(transaction: Transaction): Promise<Payment[]>;
|
|
8
20
|
domain(transaction: Transaction): Promise<Domain>;
|
|
9
21
|
updater(transaction: Transaction): Promise<User>;
|
|
10
22
|
creator(transaction: Transaction): Promise<User>;
|
|
@@ -5,6 +5,12 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const type_graphql_1 = require("type-graphql");
|
|
6
6
|
const shell_1 = require("@things-factory/shell");
|
|
7
7
|
const auth_base_1 = require("@things-factory/auth-base");
|
|
8
|
+
const biz_base_1 = require("@things-factory/biz-base");
|
|
9
|
+
const account_1 = require("../account/account");
|
|
10
|
+
const bank_account_1 = require("../bank-account/bank-account");
|
|
11
|
+
const bank_statement_1 = require("../bank-statement/bank-statement");
|
|
12
|
+
const payment_1 = require("../payment/payment");
|
|
13
|
+
const recurring_cash_item_1 = require("../recurring-cash-item/recurring-cash-item");
|
|
8
14
|
const transaction_1 = require("./transaction");
|
|
9
15
|
const transaction_type_1 = require("./transaction-type");
|
|
10
16
|
let TransactionQuery = class TransactionQuery {
|
|
@@ -20,11 +26,45 @@ let TransactionQuery = class TransactionQuery {
|
|
|
20
26
|
domain,
|
|
21
27
|
params,
|
|
22
28
|
repository: await (0, shell_1.getRepository)(transaction_1.Transaction),
|
|
23
|
-
searchables: [
|
|
29
|
+
searchables: [
|
|
30
|
+
'description',
|
|
31
|
+
'counterpartyName',
|
|
32
|
+
'ledgerCategory',
|
|
33
|
+
'bankDescription',
|
|
34
|
+
'bankCounterpartyName',
|
|
35
|
+
'bankMemo',
|
|
36
|
+
'notes'
|
|
37
|
+
]
|
|
24
38
|
});
|
|
25
39
|
const [items, total] = await queryBuilder.getManyAndCount();
|
|
26
40
|
return { items, total };
|
|
27
41
|
}
|
|
42
|
+
async bankAccount(transaction) {
|
|
43
|
+
return transaction.bankAccountId
|
|
44
|
+
? await (0, shell_1.getRepository)(bank_account_1.BankAccount).findOneBy({ id: transaction.bankAccountId })
|
|
45
|
+
: null;
|
|
46
|
+
}
|
|
47
|
+
async account(transaction) {
|
|
48
|
+
return transaction.accountId ? await (0, shell_1.getRepository)(account_1.Account).findOneBy({ id: transaction.accountId }) : null;
|
|
49
|
+
}
|
|
50
|
+
async counterparty(transaction) {
|
|
51
|
+
return transaction.counterpartyId
|
|
52
|
+
? await (0, shell_1.getRepository)(biz_base_1.Counterparty).findOneBy({ id: transaction.counterpartyId })
|
|
53
|
+
: null;
|
|
54
|
+
}
|
|
55
|
+
async bankStatement(transaction) {
|
|
56
|
+
return transaction.bankStatementId
|
|
57
|
+
? await (0, shell_1.getRepository)(bank_statement_1.BankStatement).findOneBy({ id: transaction.bankStatementId })
|
|
58
|
+
: null;
|
|
59
|
+
}
|
|
60
|
+
async recurringItem(transaction) {
|
|
61
|
+
return transaction.recurringItemId
|
|
62
|
+
? await (0, shell_1.getRepository)(recurring_cash_item_1.RecurringCashItem).findOneBy({ id: transaction.recurringItemId })
|
|
63
|
+
: null;
|
|
64
|
+
}
|
|
65
|
+
async payments(transaction) {
|
|
66
|
+
return await (0, shell_1.getRepository)(payment_1.Payment).find({ where: { transaction: { id: transaction.id } } });
|
|
67
|
+
}
|
|
28
68
|
async domain(transaction) {
|
|
29
69
|
return await (0, shell_1.getRepository)(shell_1.Domain).findOneBy({ id: transaction.domainId });
|
|
30
70
|
}
|
|
@@ -37,7 +77,7 @@ let TransactionQuery = class TransactionQuery {
|
|
|
37
77
|
};
|
|
38
78
|
exports.TransactionQuery = TransactionQuery;
|
|
39
79
|
tslib_1.__decorate([
|
|
40
|
-
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "query")'),
|
|
80
|
+
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "query", domainOwnerGranted: true)'),
|
|
41
81
|
(0, type_graphql_1.Query)(returns => transaction_1.Transaction, { nullable: true, description: 'To fetch a Transaction' }),
|
|
42
82
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
43
83
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
@@ -46,14 +86,56 @@ tslib_1.__decorate([
|
|
|
46
86
|
tslib_1.__metadata("design:returntype", Promise)
|
|
47
87
|
], TransactionQuery.prototype, "transaction", null);
|
|
48
88
|
tslib_1.__decorate([
|
|
49
|
-
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "query")'),
|
|
89
|
+
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "query", domainOwnerGranted: true)'),
|
|
50
90
|
(0, type_graphql_1.Query)(returns => transaction_type_1.TransactionList, { description: 'To fetch multiple Transactions' }),
|
|
51
|
-
tslib_1.__param(0, (0, type_graphql_1.Args)()),
|
|
91
|
+
tslib_1.__param(0, (0, type_graphql_1.Args)(type => shell_1.ListParam)),
|
|
52
92
|
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
53
93
|
tslib_1.__metadata("design:type", Function),
|
|
54
94
|
tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
|
|
55
95
|
tslib_1.__metadata("design:returntype", Promise)
|
|
56
96
|
], TransactionQuery.prototype, "transactions", null);
|
|
97
|
+
tslib_1.__decorate([
|
|
98
|
+
(0, type_graphql_1.FieldResolver)(type => bank_account_1.BankAccount, { nullable: true }),
|
|
99
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
100
|
+
tslib_1.__metadata("design:type", Function),
|
|
101
|
+
tslib_1.__metadata("design:paramtypes", [transaction_1.Transaction]),
|
|
102
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
103
|
+
], TransactionQuery.prototype, "bankAccount", null);
|
|
104
|
+
tslib_1.__decorate([
|
|
105
|
+
(0, type_graphql_1.FieldResolver)(type => account_1.Account, { nullable: true }),
|
|
106
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
107
|
+
tslib_1.__metadata("design:type", Function),
|
|
108
|
+
tslib_1.__metadata("design:paramtypes", [transaction_1.Transaction]),
|
|
109
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
110
|
+
], TransactionQuery.prototype, "account", null);
|
|
111
|
+
tslib_1.__decorate([
|
|
112
|
+
(0, type_graphql_1.FieldResolver)(type => biz_base_1.Counterparty, { nullable: true }),
|
|
113
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
114
|
+
tslib_1.__metadata("design:type", Function),
|
|
115
|
+
tslib_1.__metadata("design:paramtypes", [transaction_1.Transaction]),
|
|
116
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
117
|
+
], TransactionQuery.prototype, "counterparty", null);
|
|
118
|
+
tslib_1.__decorate([
|
|
119
|
+
(0, type_graphql_1.FieldResolver)(type => bank_statement_1.BankStatement, { nullable: true }),
|
|
120
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
121
|
+
tslib_1.__metadata("design:type", Function),
|
|
122
|
+
tslib_1.__metadata("design:paramtypes", [transaction_1.Transaction]),
|
|
123
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
124
|
+
], TransactionQuery.prototype, "bankStatement", null);
|
|
125
|
+
tslib_1.__decorate([
|
|
126
|
+
(0, type_graphql_1.FieldResolver)(type => recurring_cash_item_1.RecurringCashItem, { nullable: true }),
|
|
127
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
128
|
+
tslib_1.__metadata("design:type", Function),
|
|
129
|
+
tslib_1.__metadata("design:paramtypes", [transaction_1.Transaction]),
|
|
130
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
131
|
+
], TransactionQuery.prototype, "recurringItem", null);
|
|
132
|
+
tslib_1.__decorate([
|
|
133
|
+
(0, type_graphql_1.FieldResolver)(type => [payment_1.Payment]),
|
|
134
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
135
|
+
tslib_1.__metadata("design:type", Function),
|
|
136
|
+
tslib_1.__metadata("design:paramtypes", [transaction_1.Transaction]),
|
|
137
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
138
|
+
], TransactionQuery.prototype, "payments", null);
|
|
57
139
|
tslib_1.__decorate([
|
|
58
140
|
(0, type_graphql_1.FieldResolver)(type => shell_1.Domain),
|
|
59
141
|
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-query.js","sourceRoot":"","sources":["../../../server/service/transaction/transaction-query.ts"],"names":[],"mappings":";;;;AAAA,+CAA8F;
|
|
1
|
+
{"version":3,"file":"transaction-query.js","sourceRoot":"","sources":["../../../server/service/transaction/transaction-query.ts"],"names":[],"mappings":";;;;AAAA,+CAA8F;AAE9F,iDAAuG;AACvG,yDAAgD;AAChD,uDAAuD;AAEvD,gDAA4C;AAC5C,+DAA0D;AAC1D,qEAAgE;AAChE,gDAA4C;AAC5C,oFAA8E;AAC9E,+CAA2C;AAC3C,yDAAoD;AAG7C,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAGrB,AAAN,KAAK,CAAC,WAAW,CAAY,EAAU,EAAS,OAAwB;QACtE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhC,OAAO,MAAM,IAAA,qBAAa,EAAC,yBAAW,CAAC,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE;SACzC,CAAC,CAAA;IACJ,CAAC;IAIK,AAAN,KAAK,CAAC,YAAY,CACS,MAAiB,EACnC,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhC,MAAM,YAAY,GAAG,IAAA,qCAA6B,EAAC;YACjD,MAAM;YACN,MAAM;YACN,UAAU,EAAE,MAAM,IAAA,qBAAa,EAAC,yBAAW,CAAC;YAC5C,WAAW,EAAE;gBACX,aAAa;gBACb,kBAAkB;gBAClB,gBAAgB;gBAChB,iBAAiB;gBACjB,sBAAsB;gBACtB,UAAU;gBACV,OAAO;aACR;SACF,CAAC,CAAA;QAEF,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,YAAY,CAAC,eAAe,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AA,mBAAI,GAAE,CAAA;;6CAAc,yBAAW;;8CAE5C;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAc,yBAAW;;+CAE7C;AAGK;IADL,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,CAAC;IACb,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAc,yBAAW;;+CAE7C;2BA1FU,gBAAgB;IAD5B,IAAA,uBAAQ,EAAC,yBAAW,CAAC;GACT,gBAAgB,CA2F5B","sourcesContent":["import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'\n\nimport { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'\nimport { User } from '@things-factory/auth-base'\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 { Payment } from '../payment/payment'\nimport { RecurringCashItem } from '../recurring-cash-item/recurring-cash-item'\nimport { Transaction } from './transaction'\nimport { TransactionList } from './transaction-type'\n\n@Resolver(Transaction)\nexport class TransactionQuery {\n @Directive('@privilege(category: \"accounting\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => Transaction!, { nullable: true, description: 'To fetch a Transaction' })\n async transaction(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Transaction> {\n const { domain } = context.state\n\n return await getRepository(Transaction).findOne({\n where: { domain: { id: domain.id }, id }\n })\n }\n\n @Directive('@privilege(category: \"accounting\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => TransactionList, { description: 'To fetch multiple Transactions' })\n async transactions(\n @Args(type => ListParam) params: ListParam,\n @Ctx() context: ResolverContext\n ): Promise<TransactionList> {\n const { domain } = context.state\n\n const queryBuilder = getQueryBuilderFromListParams({\n domain,\n params,\n repository: await getRepository(Transaction),\n searchables: [\n 'description',\n 'counterpartyName',\n 'ledgerCategory',\n 'bankDescription',\n 'bankCounterpartyName',\n 'bankMemo',\n 'notes'\n ]\n })\n\n const [items, total] = await queryBuilder.getManyAndCount()\n\n return { items, total }\n }\n\n @FieldResolver(type => BankAccount, { nullable: true })\n async bankAccount(@Root() transaction: Transaction): Promise<BankAccount | null> {\n return transaction.bankAccountId\n ? await getRepository(BankAccount).findOneBy({ id: transaction.bankAccountId })\n : null\n }\n\n @FieldResolver(type => Account, { nullable: true })\n async account(@Root() transaction: Transaction): Promise<Account | null> {\n return transaction.accountId ? await getRepository(Account).findOneBy({ id: transaction.accountId }) : null\n }\n\n @FieldResolver(type => Counterparty, { nullable: true })\n async counterparty(@Root() transaction: Transaction): Promise<Counterparty | null> {\n return transaction.counterpartyId\n ? await getRepository(Counterparty).findOneBy({ id: transaction.counterpartyId })\n : null\n }\n\n @FieldResolver(type => BankStatement, { nullable: true })\n async bankStatement(@Root() transaction: Transaction): Promise<BankStatement | null> {\n return transaction.bankStatementId\n ? await getRepository(BankStatement).findOneBy({ id: transaction.bankStatementId })\n : null\n }\n\n @FieldResolver(type => RecurringCashItem, { nullable: true })\n async recurringItem(@Root() transaction: Transaction): Promise<RecurringCashItem | null> {\n return transaction.recurringItemId\n ? await getRepository(RecurringCashItem).findOneBy({ id: transaction.recurringItemId })\n : null\n }\n\n @FieldResolver(type => [Payment])\n async payments(@Root() transaction: Transaction): Promise<Payment[]> {\n return await getRepository(Payment).find({ where: { transaction: { id: transaction.id } } })\n }\n\n @FieldResolver(type => Domain)\n async domain(@Root() transaction: Transaction): Promise<Domain> {\n return await getRepository(Domain).findOneBy({ id: transaction.domainId })\n }\n\n @FieldResolver(type => User)\n async updater(@Root() transaction: Transaction): Promise<User> {\n return await getRepository(User).findOneBy({ id: transaction.updaterId })\n }\n\n @FieldResolver(type => User)\n async creator(@Root() transaction: Transaction): Promise<User> {\n return await getRepository(User).findOneBy({ id: transaction.creatorId })\n }\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EntityManager } from 'typeorm';
|
|
2
|
+
import { Transaction } from './transaction';
|
|
3
|
+
/** A transaction as a module writes it: what a person may write, and the facts a bank statement gives. */
|
|
4
|
+
export type TransactionInput = Partial<Omit<Transaction, 'bankAccount' | 'account' | 'counterparty' | 'recurringItem' | 'bankStatement'>> & {
|
|
5
|
+
id?: string;
|
|
6
|
+
cuFlag?: string;
|
|
7
|
+
bankAccount?: {
|
|
8
|
+
id: string;
|
|
9
|
+
} | null;
|
|
10
|
+
account?: {
|
|
11
|
+
id: string;
|
|
12
|
+
} | null;
|
|
13
|
+
counterparty?: {
|
|
14
|
+
id: string;
|
|
15
|
+
} | null;
|
|
16
|
+
recurringItem?: {
|
|
17
|
+
id: string;
|
|
18
|
+
} | null;
|
|
19
|
+
bankStatement?: {
|
|
20
|
+
id: string;
|
|
21
|
+
} | null;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Apply rows to a domain's transactions: `+` (or no id) adds, `M` changes, `-` deletes (softly - a financial row
|
|
25
|
+
* that was deleted stays readable). A transaction that pays something, or is paid, is unlinked before it is
|
|
26
|
+
* deleted; when its money changes, its payments are checked again - the general rule and each target kind's own.
|
|
27
|
+
*/
|
|
28
|
+
export declare function saveTransactions(tx: EntityManager, domain: {
|
|
29
|
+
id: string;
|
|
30
|
+
}, user: any, inputs: TransactionInput[]): Promise<Transaction[]>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.saveTransactions = saveTransactions;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const shell_1 = require("@things-factory/shell");
|
|
6
|
+
const bank_account_1 = require("../bank-account/bank-account");
|
|
7
|
+
const cash_flow_type_1 = require("../cash-flow-type");
|
|
8
|
+
const payment_1 = require("../payment/payment");
|
|
9
|
+
const payment_service_1 = require("../payment/payment-service");
|
|
10
|
+
const payment_targets_1 = require("../payment/payment-targets");
|
|
11
|
+
const transaction_1 = require("./transaction");
|
|
12
|
+
const transaction_period_1 = require("./transaction-period");
|
|
13
|
+
/** What changes the money of a transaction - its payments are checked again when one of these changes. */
|
|
14
|
+
const MONEY = ['amount', 'type', 'currency'];
|
|
15
|
+
/**
|
|
16
|
+
* The row a patch writes over the current one: a confirmed transaction has a day and takes its year and month from it;
|
|
17
|
+
* a forecast has a year and a month, and the day its timing names.
|
|
18
|
+
*/
|
|
19
|
+
function rowOf(input, current) {
|
|
20
|
+
const { id, cuFlag, ...fields } = input;
|
|
21
|
+
const row = { ...fields };
|
|
22
|
+
const merged = { ...current, ...row };
|
|
23
|
+
const category = merged.category ?? transaction_1.TransactionCategory.CONFIRMED;
|
|
24
|
+
row.category = category;
|
|
25
|
+
if (!current && !row.type)
|
|
26
|
+
throw new shell_1.Refusal('transaction-type-required', {}, 'type: money in or money out');
|
|
27
|
+
if (row.type !== undefined && !Object.values(cash_flow_type_1.CashFlowType).includes(row.type))
|
|
28
|
+
throw new shell_1.Refusal('transaction-type-required', {}, 'type: money in or money out');
|
|
29
|
+
if (!current && (row.amount === undefined || row.amount === null))
|
|
30
|
+
row.amount = 0;
|
|
31
|
+
if (category === transaction_1.TransactionCategory.CONFIRMED) {
|
|
32
|
+
const period = (0, transaction_period_1.yearMonthOf)(merged.transactionDate);
|
|
33
|
+
if (!period)
|
|
34
|
+
throw new shell_1.Refusal('transaction-date-required', { value: merged.transactionDate ?? '' }, 'transactionDate: YYYY-MM-DD');
|
|
35
|
+
Object.assign(row, period, { status: null });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const [year, month] = [Number(merged.year), Number(merged.month)];
|
|
39
|
+
if (!year)
|
|
40
|
+
throw new shell_1.Refusal('forecast-year-required', {}, 'year: the year it is planned in');
|
|
41
|
+
if (!(month >= 1 && month <= 12))
|
|
42
|
+
throw new shell_1.Refusal('month-out-of-range', { month: merged.month ?? '' }, 'month: must be 1 to 12');
|
|
43
|
+
if (!String(merged.description ?? '').trim())
|
|
44
|
+
throw new shell_1.Refusal('forecast-description-required', {}, 'description: what is planned');
|
|
45
|
+
Object.assign(row, { year, month, transactionDate: (0, transaction_period_1.forecastDay)(year, month, merged.timing) });
|
|
46
|
+
if (!merged.status)
|
|
47
|
+
row.status = transaction_1.ForecastStatus.PLANNED;
|
|
48
|
+
}
|
|
49
|
+
if (merged.probability !== undefined &&
|
|
50
|
+
merged.probability !== null &&
|
|
51
|
+
!(merged.probability >= 0 && merged.probability <= 100)) {
|
|
52
|
+
throw new shell_1.Refusal('probability-out-of-range', {}, 'probability: must be 0 to 100');
|
|
53
|
+
}
|
|
54
|
+
return row;
|
|
55
|
+
}
|
|
56
|
+
/** The payments on these transactions, and the transfers into them, by target kind. */
|
|
57
|
+
async function paymentsOn(tx, domain, ids) {
|
|
58
|
+
if (!ids.length)
|
|
59
|
+
return [];
|
|
60
|
+
const repo = tx.getRepository(payment_1.Payment);
|
|
61
|
+
return [
|
|
62
|
+
...(await repo.find({
|
|
63
|
+
where: { domain: { id: domain.id }, transaction: { id: (0, typeorm_1.In)(ids) } },
|
|
64
|
+
relations: ['transaction']
|
|
65
|
+
})),
|
|
66
|
+
...(await repo.find({
|
|
67
|
+
where: { domain: { id: domain.id }, targetType: 'Transaction', targetId: (0, typeorm_1.In)(ids) },
|
|
68
|
+
relations: ['transaction']
|
|
69
|
+
}))
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Apply rows to a domain's transactions: `+` (or no id) adds, `M` changes, `-` deletes (softly - a financial row
|
|
74
|
+
* that was deleted stays readable). A transaction that pays something, or is paid, is unlinked before it is
|
|
75
|
+
* deleted; when its money changes, its payments are checked again - the general rule and each target kind's own.
|
|
76
|
+
*/
|
|
77
|
+
async function saveTransactions(tx, domain, user, inputs) {
|
|
78
|
+
const repo = tx.getRepository(transaction_1.Transaction);
|
|
79
|
+
const deletes = [...new Set(inputs.filter(one => one.cuFlag === '-' && one.id).map(one => one.id))];
|
|
80
|
+
if (deletes.length) {
|
|
81
|
+
const found = await repo.find({ where: { domain: { id: domain.id }, id: (0, typeorm_1.In)(deletes) } });
|
|
82
|
+
if (found.length !== deletes.length)
|
|
83
|
+
throw new shell_1.Refusal('transaction-not-found', {}, 'a transaction was not found - reload and try again');
|
|
84
|
+
if ((await paymentsOn(tx, domain, deletes)).length)
|
|
85
|
+
throw new shell_1.Refusal('transaction-has-payments', {}, 'unlink what the transaction paid before deleting it');
|
|
86
|
+
await repo.softRemove(found);
|
|
87
|
+
}
|
|
88
|
+
const saved = [];
|
|
89
|
+
const moneyChanged = [];
|
|
90
|
+
for (const input of inputs.filter(one => one.cuFlag !== '-')) {
|
|
91
|
+
const isNew = !input.id || input.cuFlag === '+';
|
|
92
|
+
const current = isNew ? undefined : await repo.findOne({ where: { domain: { id: domain.id }, id: input.id } });
|
|
93
|
+
if (!isNew && !current)
|
|
94
|
+
throw new shell_1.Refusal('transaction-not-found', {}, 'a transaction was not found - reload and try again');
|
|
95
|
+
const row = rowOf(input, current);
|
|
96
|
+
if (row.bankAccount?.id && !('currency' in input)) {
|
|
97
|
+
const account = await tx
|
|
98
|
+
.getRepository(bank_account_1.BankAccount)
|
|
99
|
+
.findOne({ where: { domain: { id: domain.id }, id: row.bankAccount.id } });
|
|
100
|
+
if (!account)
|
|
101
|
+
throw new shell_1.Refusal('bank-account-not-found', {}, 'the bank account was not found - reload and try again');
|
|
102
|
+
if (account.currency)
|
|
103
|
+
row.currency = account.currency;
|
|
104
|
+
}
|
|
105
|
+
if (row.bankFingerprint) {
|
|
106
|
+
const twin = await repo.findOne({ where: { domain: { id: domain.id }, bankFingerprint: row.bankFingerprint } });
|
|
107
|
+
if (twin && twin.id !== current?.id)
|
|
108
|
+
throw new shell_1.Refusal('bank-line-twice', { day: twin.transactionDate ?? '' }, 'this bank line is already in the books');
|
|
109
|
+
}
|
|
110
|
+
const written = await repo.save({ ...(current ?? { domain, creator: user }), ...row, updater: user });
|
|
111
|
+
if (current && MONEY.some(field => field in row && row[field] !== current[field]))
|
|
112
|
+
moneyChanged.push(current.id);
|
|
113
|
+
saved.push(written);
|
|
114
|
+
}
|
|
115
|
+
if (moneyChanged.length) {
|
|
116
|
+
const payments = await paymentsOn(tx, domain, moneyChanged);
|
|
117
|
+
await (0, payment_service_1.checkPaymentsWithin)(tx, domain, payments.map(one => one.transaction.id));
|
|
118
|
+
const kinds = new Map();
|
|
119
|
+
for (const payment of payments)
|
|
120
|
+
kinds.set(payment.targetType, [...(kinds.get(payment.targetType) ?? []), payment]);
|
|
121
|
+
for (const [targetType, ofKind] of kinds) {
|
|
122
|
+
await (0, payment_targets_1.paymentTargetOf)(targetType)?.validate?.(tx, domain, {
|
|
123
|
+
targetIds: [...new Set(ofKind.map(one => one.targetId))],
|
|
124
|
+
transactionIds: [...new Set(ofKind.map(one => one.transaction.id))]
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return saved;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=transaction-service.js.map
|