@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
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecurringCashItemQuery = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const type_graphql_1 = require("type-graphql");
|
|
6
|
+
const shell_1 = require("@things-factory/shell");
|
|
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 recurring_cash_item_1 = require("./recurring-cash-item");
|
|
11
|
+
const recurring_cash_item_type_1 = require("./recurring-cash-item-type");
|
|
12
|
+
let RecurringCashItemQuery = class RecurringCashItemQuery {
|
|
13
|
+
async recurringCashItem(id, context) {
|
|
14
|
+
const { domain } = context.state;
|
|
15
|
+
return await (0, shell_1.getRepository)(recurring_cash_item_1.RecurringCashItem).findOne({ where: { domain: { id: domain.id }, id } });
|
|
16
|
+
}
|
|
17
|
+
async recurringCashItems(params, context) {
|
|
18
|
+
const { domain } = context.state;
|
|
19
|
+
const queryBuilder = (0, shell_1.getQueryBuilderFromListParams)({
|
|
20
|
+
domain,
|
|
21
|
+
params,
|
|
22
|
+
repository: (0, shell_1.getRepository)(recurring_cash_item_1.RecurringCashItem),
|
|
23
|
+
searchables: ['name', 'notes']
|
|
24
|
+
});
|
|
25
|
+
const [items, total] = await queryBuilder.getManyAndCount();
|
|
26
|
+
return { items, total };
|
|
27
|
+
}
|
|
28
|
+
async account(item) {
|
|
29
|
+
return item.accountId ? await (0, shell_1.getRepository)(account_1.Account).findOneBy({ id: item.accountId }) : null;
|
|
30
|
+
}
|
|
31
|
+
async counterparty(item) {
|
|
32
|
+
return item.counterpartyId ? await (0, shell_1.getRepository)(biz_base_1.Counterparty).findOneBy({ id: item.counterpartyId }) : null;
|
|
33
|
+
}
|
|
34
|
+
async domain(item) {
|
|
35
|
+
return await (0, shell_1.getRepository)(shell_1.Domain).findOneBy({ id: item.domainId });
|
|
36
|
+
}
|
|
37
|
+
async creator(item) {
|
|
38
|
+
return item.creatorId ? await (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: item.creatorId }) : null;
|
|
39
|
+
}
|
|
40
|
+
async updater(item) {
|
|
41
|
+
return item.updaterId ? await (0, shell_1.getRepository)(auth_base_1.User).findOneBy({ id: item.updaterId }) : null;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.RecurringCashItemQuery = RecurringCashItemQuery;
|
|
45
|
+
tslib_1.__decorate([
|
|
46
|
+
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "query", domainOwnerGranted: true)'),
|
|
47
|
+
(0, type_graphql_1.Query)(returns => recurring_cash_item_1.RecurringCashItem, { nullable: true, description: 'To fetch a RecurringCashItem' }),
|
|
48
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
49
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
50
|
+
tslib_1.__metadata("design:type", Function),
|
|
51
|
+
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
52
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
53
|
+
], RecurringCashItemQuery.prototype, "recurringCashItem", null);
|
|
54
|
+
tslib_1.__decorate([
|
|
55
|
+
(0, type_graphql_1.Directive)('@privilege(category: "accounting", privilege: "query", domainOwnerGranted: true)'),
|
|
56
|
+
(0, type_graphql_1.Query)(returns => recurring_cash_item_type_1.RecurringCashItemList, { description: 'To fetch multiple RecurringCashItems' }),
|
|
57
|
+
tslib_1.__param(0, (0, type_graphql_1.Args)(type => shell_1.ListParam)),
|
|
58
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
59
|
+
tslib_1.__metadata("design:type", Function),
|
|
60
|
+
tslib_1.__metadata("design:paramtypes", [shell_1.ListParam, Object]),
|
|
61
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
62
|
+
], RecurringCashItemQuery.prototype, "recurringCashItems", null);
|
|
63
|
+
tslib_1.__decorate([
|
|
64
|
+
(0, type_graphql_1.FieldResolver)(type => account_1.Account, { nullable: true }),
|
|
65
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
66
|
+
tslib_1.__metadata("design:type", Function),
|
|
67
|
+
tslib_1.__metadata("design:paramtypes", [recurring_cash_item_1.RecurringCashItem]),
|
|
68
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
69
|
+
], RecurringCashItemQuery.prototype, "account", null);
|
|
70
|
+
tslib_1.__decorate([
|
|
71
|
+
(0, type_graphql_1.FieldResolver)(type => biz_base_1.Counterparty, { nullable: true }),
|
|
72
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
73
|
+
tslib_1.__metadata("design:type", Function),
|
|
74
|
+
tslib_1.__metadata("design:paramtypes", [recurring_cash_item_1.RecurringCashItem]),
|
|
75
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
76
|
+
], RecurringCashItemQuery.prototype, "counterparty", null);
|
|
77
|
+
tslib_1.__decorate([
|
|
78
|
+
(0, type_graphql_1.FieldResolver)(type => shell_1.Domain),
|
|
79
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
80
|
+
tslib_1.__metadata("design:type", Function),
|
|
81
|
+
tslib_1.__metadata("design:paramtypes", [recurring_cash_item_1.RecurringCashItem]),
|
|
82
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
83
|
+
], RecurringCashItemQuery.prototype, "domain", null);
|
|
84
|
+
tslib_1.__decorate([
|
|
85
|
+
(0, type_graphql_1.FieldResolver)(type => auth_base_1.User, { nullable: true }),
|
|
86
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
87
|
+
tslib_1.__metadata("design:type", Function),
|
|
88
|
+
tslib_1.__metadata("design:paramtypes", [recurring_cash_item_1.RecurringCashItem]),
|
|
89
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
90
|
+
], RecurringCashItemQuery.prototype, "creator", null);
|
|
91
|
+
tslib_1.__decorate([
|
|
92
|
+
(0, type_graphql_1.FieldResolver)(type => auth_base_1.User, { nullable: true }),
|
|
93
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
94
|
+
tslib_1.__metadata("design:type", Function),
|
|
95
|
+
tslib_1.__metadata("design:paramtypes", [recurring_cash_item_1.RecurringCashItem]),
|
|
96
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
97
|
+
], RecurringCashItemQuery.prototype, "updater", null);
|
|
98
|
+
exports.RecurringCashItemQuery = RecurringCashItemQuery = tslib_1.__decorate([
|
|
99
|
+
(0, type_graphql_1.Resolver)(recurring_cash_item_1.RecurringCashItem)
|
|
100
|
+
], RecurringCashItemQuery);
|
|
101
|
+
//# sourceMappingURL=recurring-cash-item-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recurring-cash-item-query.js","sourceRoot":"","sources":["../../../server/service/recurring-cash-item/recurring-cash-item-query.ts"],"names":[],"mappings":";;;;AAAA,+CAA8F;AAE9F,iDAAuG;AACvG,yDAAgD;AAChD,uDAAuD;AAEvD,gDAA4C;AAC5C,+DAAyD;AACzD,yEAAkE;AAG3D,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAG3B,AAAN,KAAK,CAAC,iBAAiB,CAAY,EAAU,EAAS,OAAwB;QAC5E,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEhC,OAAO,MAAM,IAAA,qBAAa,EAAC,uCAAiB,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;IACrG,CAAC;IAIK,AAAN,KAAK,CAAC,kBAAkB,CACG,MAAiB,EACnC,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAChC,MAAM,YAAY,GAAG,IAAA,qCAA6B,EAAC;YACjD,MAAM;YACN,MAAM;YACN,UAAU,EAAE,IAAA,qBAAa,EAAC,uCAAiB,CAAC;YAC5C,WAAW,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;SAC/B,CAAC,CAAA;QACF,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,YAAY,CAAC,eAAe,EAAE,CAAA;QAE3D,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;IACzB,CAAC;IAGK,AAAN,KAAK,CAAC,OAAO,CAAS,IAAuB;QAC3C,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,IAAA,qBAAa,EAAC,iBAAO,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,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 '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 { RecurringCashItem } from './recurring-cash-item'\nimport { RecurringCashItemList } from './recurring-cash-item-type'\n\n@Resolver(RecurringCashItem)\nexport class RecurringCashItemQuery {\n @Directive('@privilege(category: \"accounting\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => RecurringCashItem, { nullable: true, description: 'To fetch a RecurringCashItem' })\n async recurringCashItem(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<RecurringCashItem | null> {\n const { domain } = context.state\n\n return await getRepository(RecurringCashItem).findOne({ where: { domain: { id: domain.id }, id } })\n }\n\n @Directive('@privilege(category: \"accounting\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => RecurringCashItemList, { description: 'To fetch multiple RecurringCashItems' })\n async recurringCashItems(\n @Args(type => ListParam) params: ListParam,\n @Ctx() context: ResolverContext\n ): Promise<RecurringCashItemList> {\n const { domain } = context.state\n const queryBuilder = getQueryBuilderFromListParams({\n domain,\n params,\n repository: getRepository(RecurringCashItem),\n searchables: ['name', 'notes']\n })\n const [items, total] = await queryBuilder.getManyAndCount()\n\n return { items, total }\n }\n\n @FieldResolver(type => Account, { nullable: true })\n async account(@Root() item: RecurringCashItem): Promise<Account | null> {\n return item.accountId ? await getRepository(Account).findOneBy({ id: item.accountId }) : null\n }\n\n @FieldResolver(type => Counterparty, { nullable: true })\n async counterparty(@Root() item: RecurringCashItem): Promise<Counterparty | null> {\n return item.counterpartyId ? await getRepository(Counterparty).findOneBy({ id: item.counterpartyId }) : null\n }\n\n @FieldResolver(type => Domain)\n async domain(@Root() item: RecurringCashItem): Promise<Domain> {\n return await getRepository(Domain).findOneBy({ id: item.domainId })\n }\n\n @FieldResolver(type => User, { nullable: true })\n async creator(@Root() item: RecurringCashItem): Promise<User | null> {\n return item.creatorId ? await getRepository(User).findOneBy({ id: item.creatorId }) : null\n }\n\n @FieldResolver(type => User, { nullable: true })\n async updater(@Root() item: RecurringCashItem): Promise<User | null> {\n return item.updaterId ? await getRepository(User).findOneBy({ id: item.updaterId }) : null\n }\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EntityManager } from 'typeorm';
|
|
2
|
+
import { RecurringCashItem } from './recurring-cash-item';
|
|
3
|
+
export type RecurringCashItemInput = Partial<Omit<RecurringCashItem, 'account' | 'counterparty'>> & {
|
|
4
|
+
id?: string;
|
|
5
|
+
cuFlag?: string;
|
|
6
|
+
account?: {
|
|
7
|
+
id: string;
|
|
8
|
+
} | null;
|
|
9
|
+
counterparty?: {
|
|
10
|
+
id: string;
|
|
11
|
+
} | null;
|
|
12
|
+
};
|
|
13
|
+
/** Apply rows to a domain's recurring items: `+` (or no id) adds, `M` changes, `-` deletes (softly). */
|
|
14
|
+
export declare function saveRecurringCashItems(tx: EntityManager, domain: {
|
|
15
|
+
id: string;
|
|
16
|
+
}, user: any, inputs: RecurringCashItemInput[]): Promise<RecurringCashItem[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Make the month's forecasts from the recurring items. A forecast already made from an item for that month is not
|
|
19
|
+
* made again, so running it twice changes nothing. Returns how many were made.
|
|
20
|
+
*/
|
|
21
|
+
export declare function makeForecasts(tx: EntityManager, domain: {
|
|
22
|
+
id: string;
|
|
23
|
+
}, user: any, year: number, month: number): Promise<number>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.saveRecurringCashItems = saveRecurringCashItems;
|
|
4
|
+
exports.makeForecasts = makeForecasts;
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const shell_1 = require("@things-factory/shell");
|
|
7
|
+
const transaction_1 = require("../transaction/transaction");
|
|
8
|
+
const transaction_service_1 = require("../transaction/transaction-service");
|
|
9
|
+
const recurring_cash_item_1 = require("./recurring-cash-item");
|
|
10
|
+
const recurring_schedule_1 = require("./recurring-schedule");
|
|
11
|
+
const MONTH = /^\d{4}-(0[1-9]|1[0-2])$/;
|
|
12
|
+
function rowOf(input, current) {
|
|
13
|
+
const { id, cuFlag, ...row } = input;
|
|
14
|
+
const merged = { ...current, ...row };
|
|
15
|
+
if (!String(merged.name ?? '').trim())
|
|
16
|
+
throw new shell_1.Refusal('recurring-name-required', {}, 'name: what it is');
|
|
17
|
+
if (!merged.type)
|
|
18
|
+
throw new shell_1.Refusal('transaction-type-required', {}, 'type: money in or money out');
|
|
19
|
+
if (!MONTH.test(String(merged.startMonth ?? '')))
|
|
20
|
+
throw new shell_1.Refusal('recurring-start-required', {}, 'startMonth: YYYY-MM');
|
|
21
|
+
if (merged.endMonth && !MONTH.test(merged.endMonth))
|
|
22
|
+
throw new shell_1.Refusal('recurring-end-not-a-month', {}, 'endMonth: YYYY-MM');
|
|
23
|
+
if (merged.endMonth && merged.endMonth < merged.startMonth)
|
|
24
|
+
throw new shell_1.Refusal('recurring-end-before-start', {}, 'endMonth: before startMonth');
|
|
25
|
+
if (merged.dayOfMonth !== null &&
|
|
26
|
+
merged.dayOfMonth !== undefined &&
|
|
27
|
+
!(merged.dayOfMonth >= 1 && merged.dayOfMonth <= 31)) {
|
|
28
|
+
throw new shell_1.Refusal('day-of-month-out-of-range', {}, 'dayOfMonth: must be 1 to 31');
|
|
29
|
+
}
|
|
30
|
+
if (!current && (row.amount === undefined || row.amount === null))
|
|
31
|
+
throw new shell_1.Refusal('recurring-amount-required', {}, 'amount: every month');
|
|
32
|
+
return row;
|
|
33
|
+
}
|
|
34
|
+
/** Apply rows to a domain's recurring items: `+` (or no id) adds, `M` changes, `-` deletes (softly). */
|
|
35
|
+
async function saveRecurringCashItems(tx, domain, user, inputs) {
|
|
36
|
+
const repo = tx.getRepository(recurring_cash_item_1.RecurringCashItem);
|
|
37
|
+
const deletes = [...new Set(inputs.filter(one => one.cuFlag === '-' && one.id).map(one => one.id))];
|
|
38
|
+
if (deletes.length) {
|
|
39
|
+
const found = await repo.find({ where: { domain: { id: domain.id }, id: (0, typeorm_1.In)(deletes) } });
|
|
40
|
+
if (found.length !== deletes.length)
|
|
41
|
+
throw new shell_1.Refusal('recurring-not-found', {}, 'a recurring item was not found - reload and try again');
|
|
42
|
+
await repo.softRemove(found);
|
|
43
|
+
}
|
|
44
|
+
const saved = [];
|
|
45
|
+
for (const input of inputs.filter(one => one.cuFlag !== '-')) {
|
|
46
|
+
const isNew = !input.id || input.cuFlag === '+';
|
|
47
|
+
const current = isNew ? undefined : await repo.findOne({ where: { domain: { id: domain.id }, id: input.id } });
|
|
48
|
+
if (!isNew && !current)
|
|
49
|
+
throw new shell_1.Refusal('recurring-not-found', {}, 'a recurring item was not found - reload and try again');
|
|
50
|
+
saved.push(await repo.save({
|
|
51
|
+
...(current ?? { domain, creator: user }),
|
|
52
|
+
...rowOf(input, current),
|
|
53
|
+
updater: user
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
return saved;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Make the month's forecasts from the recurring items. A forecast already made from an item for that month is not
|
|
60
|
+
* made again, so running it twice changes nothing. Returns how many were made.
|
|
61
|
+
*/
|
|
62
|
+
async function makeForecasts(tx, domain, user, year, month) {
|
|
63
|
+
if (!(month >= 1 && month <= 12))
|
|
64
|
+
throw new shell_1.Refusal('month-out-of-range', { month }, 'month: must be 1 to 12');
|
|
65
|
+
const items = await tx.getRepository(recurring_cash_item_1.RecurringCashItem).find({ where: { domain: { id: domain.id } } });
|
|
66
|
+
const made = await tx
|
|
67
|
+
.getRepository(transaction_1.Transaction)
|
|
68
|
+
.find({
|
|
69
|
+
where: { domain: { id: domain.id }, category: transaction_1.TransactionCategory.FORECAST, year, month },
|
|
70
|
+
relations: ['recurringItem']
|
|
71
|
+
});
|
|
72
|
+
const already = new Set(made.map(one => one.recurringItem?.id).filter(Boolean));
|
|
73
|
+
const lines = (0, recurring_schedule_1.linesFor)(items, year, month, already);
|
|
74
|
+
await (0, transaction_service_1.saveTransactions)(tx, domain, user, lines.map(line => {
|
|
75
|
+
return {
|
|
76
|
+
cuFlag: '+',
|
|
77
|
+
category: transaction_1.TransactionCategory.FORECAST,
|
|
78
|
+
type: line.type,
|
|
79
|
+
year: line.year,
|
|
80
|
+
month: line.month,
|
|
81
|
+
description: line.name,
|
|
82
|
+
amount: line.amount,
|
|
83
|
+
currency: line.currency,
|
|
84
|
+
timing: line.timing ?? undefined,
|
|
85
|
+
status: transaction_1.ForecastStatus.PLANNED,
|
|
86
|
+
recurringItem: { id: line.recurringItemId }
|
|
87
|
+
};
|
|
88
|
+
}));
|
|
89
|
+
return lines.length;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=recurring-cash-item-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recurring-cash-item-service.js","sourceRoot":"","sources":["../../../server/service/recurring-cash-item/recurring-cash-item-service.ts"],"names":[],"mappings":";;AA0CA,wDA8BC;AAMD,sCAyCC;AAvHD,qCAA2C;AAE3C,iDAA+C;AAE/C,4DAA6F;AAC7F,4EAAqE;AACrE,+DAAyD;AACzD,6DAA+C;AAE/C,MAAM,KAAK,GAAG,yBAAyB,CAAA;AASvC,SAAS,KAAK,CAAC,KAA6B,EAAE,OAAsC;IAClF,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,GAAG,EAAE,GAAG,KAA4B,CAAA;IAC3D,MAAM,MAAM,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,GAAG,EAAE,CAAA;IACrC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;QAAE,MAAM,IAAI,eAAO,CAAC,yBAAyB,EAAE,EAAE,EAAE,kBAAkB,CAAC,CAAA;IAC3G,IAAI,CAAC,MAAM,CAAC,IAAI;QAAE,MAAM,IAAI,eAAO,CAA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;IAE3F,MAAM,KAAK,GAAG,IAAA,6BAAQ,EAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;IACnD,MAAM,IAAA,sCAAgB,EACpB,EAAE,EACF,MAAM,EACN,IAAI,EACJ,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACf,OAAO;YACL,MAAM,EAAE,GAAG;YACX,QAAQ,EAAE,iCAAmB,CAAC,QAAQ;YACtC,IAAI,EAAE,IAAI,CAAC,IAAW;YACtB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,WAAW,EAAE,IAAI,CAAC,IAAI;YACtB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,SAAS;YAChC,MAAM,EAAE,4BAAc,CAAC,OAAO;YAC9B,aAAa,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,eAAe,EAAE;SAC5C,CAAA;IACH,CAAC,CAAC,CACH,CAAA;IAED,OAAO,KAAK,CAAC,MAAM,CAAA;AACrB,CAAC","sourcesContent":["import { EntityManager, In } from 'typeorm'\n\nimport { Refusal } from '@things-factory/shell'\n\nimport { ForecastStatus, Transaction, TransactionCategory } from '../transaction/transaction'\nimport { saveTransactions } from '../transaction/transaction-service'\nimport { RecurringCashItem } from './recurring-cash-item'\nimport { linesFor } from './recurring-schedule'\n\nconst MONTH = /^\\d{4}-(0[1-9]|1[0-2])$/\n\nexport type RecurringCashItemInput = Partial<Omit<RecurringCashItem, 'account' | 'counterparty'>> & {\n id?: string\n cuFlag?: string\n account?: { id: string } | null\n counterparty?: { id: string } | null\n}\n\nfunction rowOf(input: RecurringCashItemInput, current: RecurringCashItem | undefined): Record<string, any> {\n const { id, cuFlag, ...row } = input as Record<string, any>\n const merged = { ...current, ...row }\n if (!String(merged.name ?? '').trim()) throw new Refusal('recurring-name-required', {}, 'name: what it is')\n if (!merged.type) throw new Refusal('transaction-type-required', {}, 'type: money in or money out')\n if (!MONTH.test(String(merged.startMonth ?? '')))\n throw new Refusal('recurring-start-required', {}, 'startMonth: YYYY-MM')\n if (merged.endMonth && !MONTH.test(merged.endMonth))\n throw new Refusal('recurring-end-not-a-month', {}, 'endMonth: YYYY-MM')\n if (merged.endMonth && merged.endMonth < merged.startMonth)\n throw new Refusal('recurring-end-before-start', {}, 'endMonth: before startMonth')\n if (\n merged.dayOfMonth !== null &&\n merged.dayOfMonth !== undefined &&\n !(merged.dayOfMonth >= 1 && merged.dayOfMonth <= 31)\n ) {\n throw new Refusal('day-of-month-out-of-range', {}, 'dayOfMonth: must be 1 to 31')\n }\n if (!current && (row.amount === undefined || row.amount === null))\n throw new Refusal('recurring-amount-required', {}, 'amount: every month')\n return row\n}\n\n/** Apply rows to a domain's recurring items: `+` (or no id) adds, `M` changes, `-` deletes (softly). */\nexport async function saveRecurringCashItems(\n tx: EntityManager,\n domain: { id: string },\n user: any,\n inputs: RecurringCashItemInput[]\n): Promise<RecurringCashItem[]> {\n const repo = tx.getRepository(RecurringCashItem)\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('recurring-not-found', {}, 'a recurring item was not found - reload and try again')\n await repo.softRemove(found)\n }\n\n const saved: RecurringCashItem[] = []\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('recurring-not-found', {}, 'a recurring item was not found - reload and try again')\n saved.push(\n await repo.save({\n ...(current ?? { domain, creator: user }),\n ...rowOf(input, current),\n updater: user\n } as RecurringCashItem)\n )\n }\n return saved\n}\n\n/**\n * Make the month's forecasts from the recurring items. A forecast already made from an item for that month is not\n * made again, so running it twice changes nothing. Returns how many were made.\n */\nexport async function makeForecasts(\n tx: EntityManager,\n domain: { id: string },\n user: any,\n year: number,\n month: number\n): Promise<number> {\n if (!(month >= 1 && month <= 12)) throw new Refusal('month-out-of-range', { month }, 'month: must be 1 to 12')\n\n const items = await tx.getRepository(RecurringCashItem).find({ where: { domain: { id: domain.id } } })\n const made = await tx\n .getRepository(Transaction)\n .find({\n where: { domain: { id: domain.id }, category: TransactionCategory.FORECAST, year, month },\n relations: ['recurringItem']\n })\n const already = new Set(made.map(one => one.recurringItem?.id).filter(Boolean) as string[])\n\n const lines = linesFor(items, year, month, already)\n await saveTransactions(\n tx,\n domain,\n user,\n lines.map(line => {\n return {\n cuFlag: '+',\n category: TransactionCategory.FORECAST,\n type: line.type as any,\n year: line.year,\n month: line.month,\n description: line.name,\n amount: line.amount,\n currency: line.currency,\n timing: line.timing ?? undefined,\n status: ForecastStatus.PLANNED,\n recurringItem: { id: line.recurringItemId }\n }\n })\n )\n\n return lines.length\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ObjectRef } from '@things-factory/shell';
|
|
2
|
+
import { CashFlowType } from '../cash-flow-type';
|
|
3
|
+
import { RecurringCashItem } from './recurring-cash-item';
|
|
4
|
+
export declare class RecurringCashItemPatch {
|
|
5
|
+
id?: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
account?: ObjectRef;
|
|
8
|
+
type?: CashFlowType;
|
|
9
|
+
amount?: number;
|
|
10
|
+
currency?: string;
|
|
11
|
+
dayOfMonth?: number;
|
|
12
|
+
lastDayOfMonth?: boolean;
|
|
13
|
+
startMonth?: string;
|
|
14
|
+
endMonth?: string;
|
|
15
|
+
counterparty?: ObjectRef;
|
|
16
|
+
active?: boolean;
|
|
17
|
+
notes?: string;
|
|
18
|
+
cuFlag?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class RecurringCashItemList {
|
|
21
|
+
items: RecurringCashItem[];
|
|
22
|
+
total: number;
|
|
23
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecurringCashItemList = exports.RecurringCashItemPatch = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const type_graphql_1 = require("type-graphql");
|
|
6
|
+
const shell_1 = require("@things-factory/shell");
|
|
7
|
+
const cash_flow_type_1 = require("../cash-flow-type");
|
|
8
|
+
const recurring_cash_item_1 = require("./recurring-cash-item");
|
|
9
|
+
let RecurringCashItemPatch = class RecurringCashItemPatch {
|
|
10
|
+
};
|
|
11
|
+
exports.RecurringCashItemPatch = RecurringCashItemPatch;
|
|
12
|
+
tslib_1.__decorate([
|
|
13
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.ID, { nullable: true, description: 'The item to change or delete' }),
|
|
14
|
+
tslib_1.__metadata("design:type", String)
|
|
15
|
+
], RecurringCashItemPatch.prototype, "id", void 0);
|
|
16
|
+
tslib_1.__decorate([
|
|
17
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'What it is' }),
|
|
18
|
+
tslib_1.__metadata("design:type", String)
|
|
19
|
+
], RecurringCashItemPatch.prototype, "name", void 0);
|
|
20
|
+
tslib_1.__decorate([
|
|
21
|
+
(0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'The account subject it is booked to' }),
|
|
22
|
+
tslib_1.__metadata("design:type", shell_1.ObjectRef)
|
|
23
|
+
], RecurringCashItemPatch.prototype, "account", void 0);
|
|
24
|
+
tslib_1.__decorate([
|
|
25
|
+
(0, type_graphql_1.Field)(type => cash_flow_type_1.CashFlowType, { nullable: true, description: 'Money in or money out' }),
|
|
26
|
+
tslib_1.__metadata("design:type", String)
|
|
27
|
+
], RecurringCashItemPatch.prototype, "type", void 0);
|
|
28
|
+
tslib_1.__decorate([
|
|
29
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { nullable: true, description: 'Amount every month' }),
|
|
30
|
+
tslib_1.__metadata("design:type", Number)
|
|
31
|
+
], RecurringCashItemPatch.prototype, "amount", void 0);
|
|
32
|
+
tslib_1.__decorate([
|
|
33
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'ISO 4217 code' }),
|
|
34
|
+
tslib_1.__metadata("design:type", String)
|
|
35
|
+
], RecurringCashItemPatch.prototype, "currency", void 0);
|
|
36
|
+
tslib_1.__decorate([
|
|
37
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: '1-31' }),
|
|
38
|
+
tslib_1.__metadata("design:type", Number)
|
|
39
|
+
], RecurringCashItemPatch.prototype, "dayOfMonth", void 0);
|
|
40
|
+
tslib_1.__decorate([
|
|
41
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Falls on the last day of every month' }),
|
|
42
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
43
|
+
], RecurringCashItemPatch.prototype, "lastDayOfMonth", void 0);
|
|
44
|
+
tslib_1.__decorate([
|
|
45
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'First month - YYYY-MM' }),
|
|
46
|
+
tslib_1.__metadata("design:type", String)
|
|
47
|
+
], RecurringCashItemPatch.prototype, "startMonth", void 0);
|
|
48
|
+
tslib_1.__decorate([
|
|
49
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Last month - YYYY-MM' }),
|
|
50
|
+
tslib_1.__metadata("design:type", String)
|
|
51
|
+
], RecurringCashItemPatch.prototype, "endMonth", void 0);
|
|
52
|
+
tslib_1.__decorate([
|
|
53
|
+
(0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'Who it is paid to or received from' }),
|
|
54
|
+
tslib_1.__metadata("design:type", shell_1.ObjectRef)
|
|
55
|
+
], RecurringCashItemPatch.prototype, "counterparty", void 0);
|
|
56
|
+
tslib_1.__decorate([
|
|
57
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Whether it still makes forecasts' }),
|
|
58
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
59
|
+
], RecurringCashItemPatch.prototype, "active", void 0);
|
|
60
|
+
tslib_1.__decorate([
|
|
61
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Notes' }),
|
|
62
|
+
tslib_1.__metadata("design:type", String)
|
|
63
|
+
], RecurringCashItemPatch.prototype, "notes", void 0);
|
|
64
|
+
tslib_1.__decorate([
|
|
65
|
+
(0, type_graphql_1.Field)({ nullable: true, description: '+ adds, M changes, - deletes' }),
|
|
66
|
+
tslib_1.__metadata("design:type", String)
|
|
67
|
+
], RecurringCashItemPatch.prototype, "cuFlag", void 0);
|
|
68
|
+
exports.RecurringCashItemPatch = RecurringCashItemPatch = tslib_1.__decorate([
|
|
69
|
+
(0, type_graphql_1.InputType)({ description: 'A recurring item, or a grid row: cuFlag + adds, M changes, - deletes' })
|
|
70
|
+
], RecurringCashItemPatch);
|
|
71
|
+
let RecurringCashItemList = class RecurringCashItemList {
|
|
72
|
+
};
|
|
73
|
+
exports.RecurringCashItemList = RecurringCashItemList;
|
|
74
|
+
tslib_1.__decorate([
|
|
75
|
+
(0, type_graphql_1.Field)(type => [recurring_cash_item_1.RecurringCashItem], { description: 'The items on this page' }),
|
|
76
|
+
tslib_1.__metadata("design:type", Array)
|
|
77
|
+
], RecurringCashItemList.prototype, "items", void 0);
|
|
78
|
+
tslib_1.__decorate([
|
|
79
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Int, { description: 'How many there are in all' }),
|
|
80
|
+
tslib_1.__metadata("design:type", Number)
|
|
81
|
+
], RecurringCashItemList.prototype, "total", void 0);
|
|
82
|
+
exports.RecurringCashItemList = RecurringCashItemList = tslib_1.__decorate([
|
|
83
|
+
(0, type_graphql_1.ObjectType)({ description: 'A page of recurring items' })
|
|
84
|
+
], RecurringCashItemList);
|
|
85
|
+
//# sourceMappingURL=recurring-cash-item-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recurring-cash-item-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'\n\nimport { ObjectRef } from '@things-factory/shell'\n\nimport { CashFlowType } from '../cash-flow-type'\nimport { RecurringCashItem } from './recurring-cash-item'\n\n@InputType({ description: 'A recurring item, or a grid row: cuFlag + adds, M changes, - deletes' })\nexport class RecurringCashItemPatch {\n @Field(type => ID, { nullable: true, description: 'The item to change or delete' })\n id?: string\n\n @Field({ nullable: true, description: 'What it is' })\n name?: string\n\n @Field(type => ObjectRef, { nullable: true, description: 'The account subject it is booked to' })\n account?: ObjectRef\n\n @Field(type => CashFlowType, { nullable: true, description: 'Money in or money out' })\n type?: CashFlowType\n\n @Field(type => Float, { nullable: true, description: 'Amount every month' })\n amount?: number\n\n @Field({ nullable: true, description: 'ISO 4217 code' })\n currency?: string\n\n @Field(type => Int, { nullable: true, description: '1-31' })\n dayOfMonth?: number\n\n @Field({ nullable: true, description: 'Falls on the last day of every month' })\n lastDayOfMonth?: boolean\n\n @Field({ nullable: true, description: 'First month - YYYY-MM' })\n startMonth?: string\n\n @Field({ nullable: true, description: 'Last month - YYYY-MM' })\n endMonth?: string\n\n @Field(type => ObjectRef, { nullable: true, description: 'Who it is paid to or received from' })\n counterparty?: ObjectRef\n\n @Field({ nullable: true, description: 'Whether it still makes forecasts' })\n active?: boolean\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 recurring items' })\nexport class RecurringCashItemList {\n @Field(type => [RecurringCashItem], { description: 'The items on this page' })\n items: RecurringCashItem[]\n\n @Field(type => Int, { description: 'How many there are in all' })\n total: number\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Domain } from '@things-factory/shell';
|
|
2
|
+
import { User } from '@things-factory/auth-base';
|
|
3
|
+
import { Counterparty } from '@things-factory/biz-base';
|
|
4
|
+
import { Account } from '../account/account';
|
|
5
|
+
import { CashFlowType } from '../cash-flow-type';
|
|
6
|
+
/**
|
|
7
|
+
* Money that comes in or goes out every month on a known day - rent, a subscription, a loan's interest. Each month it
|
|
8
|
+
* falls in, it makes a forecast (§`Transaction.recurringItem`).
|
|
9
|
+
*/
|
|
10
|
+
export declare class RecurringCashItem {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
domain?: Domain;
|
|
13
|
+
domainId?: string;
|
|
14
|
+
name: string;
|
|
15
|
+
account?: Account;
|
|
16
|
+
accountId?: string;
|
|
17
|
+
type: CashFlowType;
|
|
18
|
+
amount: number;
|
|
19
|
+
currency: string;
|
|
20
|
+
dayOfMonth?: number;
|
|
21
|
+
lastDayOfMonth: boolean;
|
|
22
|
+
startMonth: string;
|
|
23
|
+
endMonth?: string;
|
|
24
|
+
counterparty?: Counterparty;
|
|
25
|
+
counterpartyId?: string;
|
|
26
|
+
active: boolean;
|
|
27
|
+
notes?: string;
|
|
28
|
+
createdAt?: Date;
|
|
29
|
+
updatedAt?: Date;
|
|
30
|
+
deletedAt?: Date;
|
|
31
|
+
creator?: User;
|
|
32
|
+
creatorId?: string;
|
|
33
|
+
updater?: User;
|
|
34
|
+
updaterId?: string;
|
|
35
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecurringCashItem = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const type_graphql_1 = require("type-graphql");
|
|
7
|
+
const shell_1 = require("@things-factory/shell");
|
|
8
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
9
|
+
const biz_base_1 = require("@things-factory/biz-base");
|
|
10
|
+
const account_1 = require("../account/account");
|
|
11
|
+
const cash_flow_type_1 = require("../cash-flow-type");
|
|
12
|
+
/**
|
|
13
|
+
* Money that comes in or goes out every month on a known day - rent, a subscription, a loan's interest. Each month it
|
|
14
|
+
* falls in, it makes a forecast (§`Transaction.recurringItem`).
|
|
15
|
+
*/
|
|
16
|
+
let RecurringCashItem = class RecurringCashItem {
|
|
17
|
+
};
|
|
18
|
+
exports.RecurringCashItem = RecurringCashItem;
|
|
19
|
+
tslib_1.__decorate([
|
|
20
|
+
(0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
|
|
21
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.ID, { description: 'Unique identifier' }),
|
|
22
|
+
tslib_1.__metadata("design:type", String)
|
|
23
|
+
], RecurringCashItem.prototype, "id", void 0);
|
|
24
|
+
tslib_1.__decorate([
|
|
25
|
+
(0, typeorm_1.ManyToOne)(type => shell_1.Domain),
|
|
26
|
+
(0, type_graphql_1.Field)(type => shell_1.Domain, { nullable: true, description: 'The domain whose item it is' }),
|
|
27
|
+
tslib_1.__metadata("design:type", shell_1.Domain)
|
|
28
|
+
], RecurringCashItem.prototype, "domain", void 0);
|
|
29
|
+
tslib_1.__decorate([
|
|
30
|
+
(0, typeorm_1.RelationId)((item) => item.domain),
|
|
31
|
+
tslib_1.__metadata("design:type", String)
|
|
32
|
+
], RecurringCashItem.prototype, "domainId", void 0);
|
|
33
|
+
tslib_1.__decorate([
|
|
34
|
+
(0, typeorm_1.Column)(),
|
|
35
|
+
(0, type_graphql_1.Field)({ description: 'What it is - the forecasts it makes take this as their description' }),
|
|
36
|
+
tslib_1.__metadata("design:type", String)
|
|
37
|
+
], RecurringCashItem.prototype, "name", void 0);
|
|
38
|
+
tslib_1.__decorate([
|
|
39
|
+
(0, typeorm_1.ManyToOne)(type => account_1.Account, { nullable: true, onDelete: 'SET NULL' }),
|
|
40
|
+
(0, type_graphql_1.Field)(type => account_1.Account, { nullable: true, description: 'The account subject it is booked to' }),
|
|
41
|
+
tslib_1.__metadata("design:type", account_1.Account)
|
|
42
|
+
], RecurringCashItem.prototype, "account", void 0);
|
|
43
|
+
tslib_1.__decorate([
|
|
44
|
+
(0, typeorm_1.RelationId)((item) => item.account),
|
|
45
|
+
tslib_1.__metadata("design:type", String)
|
|
46
|
+
], RecurringCashItem.prototype, "accountId", void 0);
|
|
47
|
+
tslib_1.__decorate([
|
|
48
|
+
(0, typeorm_1.Column)({ default: cash_flow_type_1.CashFlowType.EXPENSE }),
|
|
49
|
+
(0, type_graphql_1.Field)(type => cash_flow_type_1.CashFlowType, { description: 'Money in or money out' }),
|
|
50
|
+
tslib_1.__metadata("design:type", String)
|
|
51
|
+
], RecurringCashItem.prototype, "type", void 0);
|
|
52
|
+
tslib_1.__decorate([
|
|
53
|
+
(0, typeorm_1.Column)((0, shell_1.moneyColumn)()),
|
|
54
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Float, { description: 'Amount every month' }),
|
|
55
|
+
tslib_1.__metadata("design:type", Number)
|
|
56
|
+
], RecurringCashItem.prototype, "amount", void 0);
|
|
57
|
+
tslib_1.__decorate([
|
|
58
|
+
(0, typeorm_1.Column)({ default: 'KRW' }),
|
|
59
|
+
(0, type_graphql_1.Field)({ description: 'ISO 4217 code' }),
|
|
60
|
+
tslib_1.__metadata("design:type", String)
|
|
61
|
+
], RecurringCashItem.prototype, "currency", void 0);
|
|
62
|
+
tslib_1.__decorate([
|
|
63
|
+
(0, typeorm_1.Column)({ type: 'int', nullable: true }),
|
|
64
|
+
(0, type_graphql_1.Field)(type => type_graphql_1.Int, {
|
|
65
|
+
nullable: true,
|
|
66
|
+
description: "1-31; a day past the month's end is its last day. Empty with lastDayOfMonth"
|
|
67
|
+
}),
|
|
68
|
+
tslib_1.__metadata("design:type", Number)
|
|
69
|
+
], RecurringCashItem.prototype, "dayOfMonth", void 0);
|
|
70
|
+
tslib_1.__decorate([
|
|
71
|
+
(0, typeorm_1.Column)({ default: false }),
|
|
72
|
+
(0, type_graphql_1.Field)({ description: 'Falls on the last day of every month' }),
|
|
73
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
74
|
+
], RecurringCashItem.prototype, "lastDayOfMonth", void 0);
|
|
75
|
+
tslib_1.__decorate([
|
|
76
|
+
(0, typeorm_1.Column)(),
|
|
77
|
+
(0, type_graphql_1.Field)({ description: 'First month - YYYY-MM' }),
|
|
78
|
+
tslib_1.__metadata("design:type", String)
|
|
79
|
+
], RecurringCashItem.prototype, "startMonth", void 0);
|
|
80
|
+
tslib_1.__decorate([
|
|
81
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
82
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Last month; open-ended when empty - YYYY-MM' }),
|
|
83
|
+
tslib_1.__metadata("design:type", String)
|
|
84
|
+
], RecurringCashItem.prototype, "endMonth", void 0);
|
|
85
|
+
tslib_1.__decorate([
|
|
86
|
+
(0, typeorm_1.ManyToOne)(type => biz_base_1.Counterparty, { nullable: true, onDelete: 'SET NULL' }),
|
|
87
|
+
(0, type_graphql_1.Field)(type => biz_base_1.Counterparty, { nullable: true, description: 'Who it is paid to or received from' }),
|
|
88
|
+
tslib_1.__metadata("design:type", biz_base_1.Counterparty)
|
|
89
|
+
], RecurringCashItem.prototype, "counterparty", void 0);
|
|
90
|
+
tslib_1.__decorate([
|
|
91
|
+
(0, typeorm_1.RelationId)((item) => item.counterparty),
|
|
92
|
+
tslib_1.__metadata("design:type", String)
|
|
93
|
+
], RecurringCashItem.prototype, "counterpartyId", void 0);
|
|
94
|
+
tslib_1.__decorate([
|
|
95
|
+
(0, typeorm_1.Column)({ default: true }),
|
|
96
|
+
(0, type_graphql_1.Field)({ description: 'An inactive item makes no more forecasts' }),
|
|
97
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
98
|
+
], RecurringCashItem.prototype, "active", void 0);
|
|
99
|
+
tslib_1.__decorate([
|
|
100
|
+
(0, typeorm_1.Column)({ type: 'text', nullable: true }),
|
|
101
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Notes' }),
|
|
102
|
+
tslib_1.__metadata("design:type", String)
|
|
103
|
+
], RecurringCashItem.prototype, "notes", void 0);
|
|
104
|
+
tslib_1.__decorate([
|
|
105
|
+
(0, typeorm_1.CreateDateColumn)(),
|
|
106
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'When it was created' }),
|
|
107
|
+
tslib_1.__metadata("design:type", Date)
|
|
108
|
+
], RecurringCashItem.prototype, "createdAt", void 0);
|
|
109
|
+
tslib_1.__decorate([
|
|
110
|
+
(0, typeorm_1.UpdateDateColumn)(),
|
|
111
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'When it last changed' }),
|
|
112
|
+
tslib_1.__metadata("design:type", Date)
|
|
113
|
+
], RecurringCashItem.prototype, "updatedAt", void 0);
|
|
114
|
+
tslib_1.__decorate([
|
|
115
|
+
(0, typeorm_1.DeleteDateColumn)(),
|
|
116
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'When it was deleted - the forecasts it made are kept' }),
|
|
117
|
+
tslib_1.__metadata("design:type", Date)
|
|
118
|
+
], RecurringCashItem.prototype, "deletedAt", void 0);
|
|
119
|
+
tslib_1.__decorate([
|
|
120
|
+
(0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
|
|
121
|
+
(0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true, description: 'Who created it' }),
|
|
122
|
+
tslib_1.__metadata("design:type", auth_base_1.User)
|
|
123
|
+
], RecurringCashItem.prototype, "creator", void 0);
|
|
124
|
+
tslib_1.__decorate([
|
|
125
|
+
(0, typeorm_1.RelationId)((item) => item.creator),
|
|
126
|
+
tslib_1.__metadata("design:type", String)
|
|
127
|
+
], RecurringCashItem.prototype, "creatorId", void 0);
|
|
128
|
+
tslib_1.__decorate([
|
|
129
|
+
(0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
|
|
130
|
+
(0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true, description: 'Who last changed it' }),
|
|
131
|
+
tslib_1.__metadata("design:type", auth_base_1.User)
|
|
132
|
+
], RecurringCashItem.prototype, "updater", void 0);
|
|
133
|
+
tslib_1.__decorate([
|
|
134
|
+
(0, typeorm_1.RelationId)((item) => item.updater),
|
|
135
|
+
tslib_1.__metadata("design:type", String)
|
|
136
|
+
], RecurringCashItem.prototype, "updaterId", void 0);
|
|
137
|
+
exports.RecurringCashItem = RecurringCashItem = tslib_1.__decorate([
|
|
138
|
+
(0, typeorm_1.Entity)(),
|
|
139
|
+
(0, typeorm_1.Index)('ix_recurring_cash_item_0', (item) => [item.domain, item.active]),
|
|
140
|
+
(0, type_graphql_1.ObjectType)({ description: 'Money that comes in or goes out every month on a known day' })
|
|
141
|
+
], RecurringCashItem);
|
|
142
|
+
//# sourceMappingURL=recurring-cash-item.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recurring-cash-item.js","sourceRoot":"","sources":["../../../server/service/recurring-cash-item/recurring-cash-item.ts"],"names":[],"mappings":";;;;AAAA,qCAUgB;AAChB,+CAAgE;AAEhE,iDAA2D;AAC3D,yDAAgD;AAChD,uDAAuD;AAEvD,gDAA4C;AAC5C,sDAAgD;AAEhD;;;GAGG;AAII,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;CA8F7B,CAAA;AA9FY,8CAAiB;AAGnB;IAFR,IAAA,gCAAsB,EAAC,MAAM,CAAC;IAC9B,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAE,EAAE,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC;;6CACrC;AAInB;IAFC,IAAA,mBAAS,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,CAAC;IACzB,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,cAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,6BAA6B,EAAE,CAAC;sCAC7E,cAAM;iDAAA;AAGf;IADC,IAAA,oBAAU,EAAC,CAAC,IAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC;;mDACpC;AAIjB;IAFC,IAAA,gBAAM,GAAE;IACR,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,oEAAoE,EAAE,CAAC;;+CACjF;AAIZ;IAFC,IAAA,mBAAS,E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'typeorm'\nimport { Field, Float, ID, Int, ObjectType } from 'type-graphql'\n\nimport { Domain, moneyColumn } 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 { CashFlowType } from '../cash-flow-type'\n\n/**\n * Money that comes in or goes out every month on a known day - rent, a subscription, a loan's interest. Each month it\n * falls in, it makes a forecast (§`Transaction.recurringItem`).\n */\n@Entity()\n@Index('ix_recurring_cash_item_0', (item: RecurringCashItem) => [item.domain, item.active])\n@ObjectType({ description: 'Money that comes in or goes out every month on a known day' })\nexport class RecurringCashItem {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID, { description: 'Unique identifier' })\n readonly id: string\n\n @ManyToOne(type => Domain)\n @Field(type => Domain, { nullable: true, description: 'The domain whose item it is' })\n domain?: Domain\n\n @RelationId((item: RecurringCashItem) => item.domain)\n domainId?: string\n\n @Column()\n @Field({ description: 'What it is - the forecasts it makes take this as their description' })\n name: string\n\n @ManyToOne(type => Account, { nullable: true, onDelete: 'SET NULL' })\n @Field(type => Account, { nullable: true, description: 'The account subject it is booked to' })\n account?: Account\n\n @RelationId((item: RecurringCashItem) => item.account)\n accountId?: string\n\n @Column({ default: CashFlowType.EXPENSE })\n @Field(type => CashFlowType, { description: 'Money in or money out' })\n type: CashFlowType\n\n @Column(moneyColumn())\n @Field(type => Float, { description: 'Amount every month' })\n amount: number\n\n @Column({ default: 'KRW' })\n @Field({ description: 'ISO 4217 code' })\n currency: string\n\n @Column({ type: 'int', nullable: true })\n @Field(type => Int, {\n nullable: true,\n description: \"1-31; a day past the month's end is its last day. Empty with lastDayOfMonth\"\n })\n dayOfMonth?: number\n\n @Column({ default: false })\n @Field({ description: 'Falls on the last day of every month' })\n lastDayOfMonth: boolean\n\n @Column()\n @Field({ description: 'First month - YYYY-MM' })\n startMonth: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Last month; open-ended when empty - YYYY-MM' })\n endMonth?: string\n\n @ManyToOne(type => Counterparty, { nullable: true, onDelete: 'SET NULL' })\n @Field(type => Counterparty, { nullable: true, description: 'Who it is paid to or received from' })\n counterparty?: Counterparty\n\n @RelationId((item: RecurringCashItem) => item.counterparty)\n counterpartyId?: string\n\n @Column({ default: true })\n @Field({ description: 'An inactive item makes no more forecasts' })\n active: boolean\n\n @Column({ type: 'text', nullable: true })\n @Field({ nullable: true, description: 'Notes' })\n notes?: string\n\n @CreateDateColumn()\n @Field({ nullable: true, description: 'When it was created' })\n createdAt?: Date\n\n @UpdateDateColumn()\n @Field({ nullable: true, description: 'When it last changed' })\n updatedAt?: Date\n\n @DeleteDateColumn()\n @Field({ nullable: true, description: 'When it was deleted - the forecasts it made are kept' })\n deletedAt?: Date\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true, description: 'Who created it' })\n creator?: User\n\n @RelationId((item: RecurringCashItem) => item.creator)\n creatorId?: string\n\n @ManyToOne(type => User, { nullable: true })\n @Field(type => User, { nullable: true, description: 'Who last changed it' })\n updater?: User\n\n @RelationId((item: RecurringCashItem) => item.updater)\n updaterId?: string\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which recurring items fall in a month, and the forecast line each one makes.
|
|
3
|
+
*
|
|
4
|
+
* An item falls in a month when it is active and the month lies within [startMonth, endMonth].
|
|
5
|
+
* Its timing is written the way the forecast ledger writes it — `21일`, `말일` — so the calendar
|
|
6
|
+
* places the line on that day (§`forecastDay`). An item with neither a day nor 말일 makes a line
|
|
7
|
+
* with no timing: the calendar shows it undated, as it does any line nobody gave a day.
|
|
8
|
+
*
|
|
9
|
+
* Pure.
|
|
10
|
+
*/
|
|
11
|
+
export interface RecurringItem {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
type: string;
|
|
15
|
+
amount: number;
|
|
16
|
+
currency?: string | null;
|
|
17
|
+
dayOfMonth?: number | null;
|
|
18
|
+
lastDayOfMonth?: boolean | null;
|
|
19
|
+
startMonth: string;
|
|
20
|
+
endMonth?: string | null;
|
|
21
|
+
active?: boolean | null;
|
|
22
|
+
}
|
|
23
|
+
export interface GeneratedLine {
|
|
24
|
+
recurringItemId: string;
|
|
25
|
+
year: number;
|
|
26
|
+
month: number;
|
|
27
|
+
type: string;
|
|
28
|
+
name: string;
|
|
29
|
+
amount: number;
|
|
30
|
+
currency: string;
|
|
31
|
+
timing: string | null;
|
|
32
|
+
}
|
|
33
|
+
export declare function fallsIn(item: RecurringItem, year: number, month: number): boolean;
|
|
34
|
+
export declare function timingOf(item: RecurringItem): string | null;
|
|
35
|
+
/** The lines to add for a month — leaving out items that already made one (`already`). */
|
|
36
|
+
export declare function linesFor(items: readonly RecurringItem[], year: number, month: number, already: ReadonlySet<string>): GeneratedLine[];
|