@things-factory/accounting 10.1.134 → 10.1.136

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.
Files changed (240) hide show
  1. package/dist-client/route.d.ts +1 -1
  2. package/dist-client/route.js +0 -12
  3. package/dist-client/route.js.map +1 -1
  4. package/dist-client/tsconfig.tsbuildinfo +1 -1
  5. package/dist-server/index.d.ts +0 -1
  6. package/dist-server/index.js +0 -1
  7. package/dist-server/index.js.map +1 -1
  8. package/dist-server/service/account/account-history.d.ts +13 -6
  9. package/dist-server/service/account/account-history.js +44 -17
  10. package/dist-server/service/account/account-history.js.map +1 -1
  11. package/dist-server/service/account/account-mutation.js +2 -2
  12. package/dist-server/service/account/account-mutation.js.map +1 -1
  13. package/dist-server/service/account/account-query.d.ts +2 -0
  14. package/dist-server/service/account/account-query.js +12 -1
  15. package/dist-server/service/account/account-query.js.map +1 -1
  16. package/dist-server/service/account/account-type.d.ts +16 -0
  17. package/dist-server/service/account/account-type.js +71 -13
  18. package/dist-server/service/account/account-type.js.map +1 -1
  19. package/dist-server/service/account/account.d.ts +9 -3
  20. package/dist-server/service/account/account.js +34 -8
  21. package/dist-server/service/account/account.js.map +1 -1
  22. package/dist-server/service/accounting-category/accounting-category-mutation.js +2 -2
  23. package/dist-server/service/accounting-category/accounting-category-mutation.js.map +1 -1
  24. package/dist-server/service/accounting-category/accounting-category-query.d.ts +1 -0
  25. package/dist-server/service/accounting-category/accounting-category-query.js +10 -0
  26. package/dist-server/service/accounting-category/accounting-category-query.js.map +1 -1
  27. package/dist-server/service/accounting-document/accounting-document-mutation.js +12 -3
  28. package/dist-server/service/accounting-document/accounting-document-mutation.js.map +1 -1
  29. package/dist-server/service/accounting-document/accounting-document-query.js +2 -0
  30. package/dist-server/service/accounting-document/accounting-document-query.js.map +1 -1
  31. package/dist-server/service/bank-account/bank-account-history.d.ts +11 -14
  32. package/dist-server/service/bank-account/bank-account-history.js +46 -59
  33. package/dist-server/service/bank-account/bank-account-history.js.map +1 -1
  34. package/dist-server/service/bank-account/bank-account-mutation.d.ts +1 -2
  35. package/dist-server/service/bank-account/bank-account-mutation.js +25 -69
  36. package/dist-server/service/bank-account/bank-account-mutation.js.map +1 -1
  37. package/dist-server/service/bank-account/bank-account-query.js +3 -1
  38. package/dist-server/service/bank-account/bank-account-query.js.map +1 -1
  39. package/dist-server/service/bank-account/bank-account-service.d.ts +5 -0
  40. package/dist-server/service/bank-account/bank-account-service.js +21 -0
  41. package/dist-server/service/bank-account/bank-account-service.js.map +1 -0
  42. package/dist-server/service/bank-account/bank-account-type.d.ts +13 -19
  43. package/dist-server/service/bank-account/bank-account-type.js +45 -69
  44. package/dist-server/service/bank-account/bank-account-type.js.map +1 -1
  45. package/dist-server/service/bank-account/bank-account.d.ts +14 -17
  46. package/dist-server/service/bank-account/bank-account.js +45 -57
  47. package/dist-server/service/bank-account/bank-account.js.map +1 -1
  48. package/dist-server/service/bank-statement/bank-statement-query.d.ts +14 -0
  49. package/dist-server/service/bank-statement/bank-statement-query.js +92 -0
  50. package/dist-server/service/bank-statement/bank-statement-query.js.map +1 -0
  51. package/dist-server/service/bank-statement/bank-statement.d.ts +26 -0
  52. package/dist-server/service/bank-statement/bank-statement.js +109 -0
  53. package/dist-server/service/bank-statement/bank-statement.js.map +1 -0
  54. package/dist-server/service/bank-statement/index.d.ts +5 -0
  55. package/dist-server/service/bank-statement/index.js +9 -0
  56. package/dist-server/service/bank-statement/index.js.map +1 -0
  57. package/dist-server/service/cash-flow-type.d.ts +5 -0
  58. package/dist-server/service/cash-flow-type.js +15 -0
  59. package/dist-server/service/cash-flow-type.js.map +1 -0
  60. package/dist-server/service/financial-institution/financial-institution-mutation.js +10 -1
  61. package/dist-server/service/financial-institution/financial-institution-mutation.js.map +1 -1
  62. package/dist-server/service/financial-institution/financial-institution-query.js +14 -6
  63. package/dist-server/service/financial-institution/financial-institution-query.js.map +1 -1
  64. package/dist-server/service/financial-institution/index.d.ts +1 -1
  65. package/dist-server/service/financial-statement/financial-statement-history.d.ts +11 -9
  66. package/dist-server/service/financial-statement/financial-statement-history.js +47 -36
  67. package/dist-server/service/financial-statement/financial-statement-history.js.map +1 -1
  68. package/dist-server/service/financial-statement/financial-statement-line.d.ts +24 -0
  69. package/dist-server/service/financial-statement/financial-statement-line.js +108 -0
  70. package/dist-server/service/financial-statement/financial-statement-line.js.map +1 -0
  71. package/dist-server/service/financial-statement/financial-statement-mutation.d.ts +1 -8
  72. package/dist-server/service/financial-statement/financial-statement-mutation.js +10 -135
  73. package/dist-server/service/financial-statement/financial-statement-mutation.js.map +1 -1
  74. package/dist-server/service/financial-statement/financial-statement-query.d.ts +14 -7
  75. package/dist-server/service/financial-statement/financial-statement-query.js +87 -31
  76. package/dist-server/service/financial-statement/financial-statement-query.js.map +1 -1
  77. package/dist-server/service/financial-statement/financial-statement-service.d.ts +33 -0
  78. package/dist-server/service/financial-statement/financial-statement-service.js +44 -0
  79. package/dist-server/service/financial-statement/financial-statement-service.js.map +1 -0
  80. package/dist-server/service/financial-statement/financial-statement.d.ts +19 -11
  81. package/dist-server/service/financial-statement/financial-statement.js +73 -65
  82. package/dist-server/service/financial-statement/financial-statement.js.map +1 -1
  83. package/dist-server/service/financial-statement/index.d.ts +5 -4
  84. package/dist-server/service/financial-statement/index.js +3 -3
  85. package/dist-server/service/financial-statement/index.js.map +1 -1
  86. package/dist-server/service/index.d.ts +15 -3
  87. package/dist-server/service/index.js +30 -13
  88. package/dist-server/service/index.js.map +1 -1
  89. package/dist-server/service/payment/index.d.ts +1 -0
  90. package/dist-server/service/payment/index.js +1 -0
  91. package/dist-server/service/payment/index.js.map +1 -1
  92. package/dist-server/service/payment/payment-history.d.ts +9 -16
  93. package/dist-server/service/payment/payment-history.js +36 -70
  94. package/dist-server/service/payment/payment-history.js.map +1 -1
  95. package/dist-server/service/payment/payment-mutation.d.ts +0 -1
  96. package/dist-server/service/payment/payment-mutation.js +14 -79
  97. package/dist-server/service/payment/payment-mutation.js.map +1 -1
  98. package/dist-server/service/payment/payment-query.d.ts +3 -0
  99. package/dist-server/service/payment/payment-query.js +30 -1
  100. package/dist-server/service/payment/payment-query.js.map +1 -1
  101. package/dist-server/service/payment/payment-service.d.ts +16 -0
  102. package/dist-server/service/payment/payment-service.js +140 -0
  103. package/dist-server/service/payment/payment-service.js.map +1 -0
  104. package/dist-server/service/payment/payment-targets.d.ts +31 -0
  105. package/dist-server/service/payment/payment-targets.js +19 -0
  106. package/dist-server/service/payment/payment-targets.js.map +1 -0
  107. package/dist-server/service/payment/payment-type.d.ts +13 -17
  108. package/dist-server/service/payment/payment-type.js +35 -51
  109. package/dist-server/service/payment/payment-type.js.map +1 -1
  110. package/dist-server/service/payment/payment.d.ts +23 -22
  111. package/dist-server/service/payment/payment.js +66 -94
  112. package/dist-server/service/payment/payment.js.map +1 -1
  113. package/dist-server/service/payment/transfer-target.d.ts +1 -0
  114. package/dist-server/service/payment/transfer-target.js +43 -0
  115. package/dist-server/service/payment/transfer-target.js.map +1 -0
  116. package/dist-server/service/recurring-cash-item/index.d.ts +6 -0
  117. package/dist-server/service/recurring-cash-item/index.js +10 -0
  118. package/dist-server/service/recurring-cash-item/index.js.map +1 -0
  119. package/dist-server/service/recurring-cash-item/recurring-cash-item-mutation.d.ts +7 -0
  120. package/dist-server/service/recurring-cash-item/recurring-cash-item-mutation.js +63 -0
  121. package/dist-server/service/recurring-cash-item/recurring-cash-item-mutation.js.map +1 -0
  122. package/dist-server/service/recurring-cash-item/recurring-cash-item-query.d.ts +15 -0
  123. package/dist-server/service/recurring-cash-item/recurring-cash-item-query.js +101 -0
  124. package/dist-server/service/recurring-cash-item/recurring-cash-item-query.js.map +1 -0
  125. package/dist-server/service/recurring-cash-item/recurring-cash-item-service.d.ts +23 -0
  126. package/dist-server/service/recurring-cash-item/recurring-cash-item-service.js +91 -0
  127. package/dist-server/service/recurring-cash-item/recurring-cash-item-service.js.map +1 -0
  128. package/dist-server/service/recurring-cash-item/recurring-cash-item-type.d.ts +23 -0
  129. package/dist-server/service/recurring-cash-item/recurring-cash-item-type.js +85 -0
  130. package/dist-server/service/recurring-cash-item/recurring-cash-item-type.js.map +1 -0
  131. package/dist-server/service/recurring-cash-item/recurring-cash-item.d.ts +35 -0
  132. package/dist-server/service/recurring-cash-item/recurring-cash-item.js +142 -0
  133. package/dist-server/service/recurring-cash-item/recurring-cash-item.js.map +1 -0
  134. package/dist-server/service/recurring-cash-item/recurring-schedule.d.ts +36 -0
  135. package/dist-server/service/recurring-cash-item/recurring-schedule.js +41 -0
  136. package/dist-server/service/recurring-cash-item/recurring-schedule.js.map +1 -0
  137. package/dist-server/service/transaction/transaction-history.d.ts +42 -15
  138. package/dist-server/service/transaction/transaction-history.js +160 -54
  139. package/dist-server/service/transaction/transaction-history.js.map +1 -1
  140. package/dist-server/service/transaction/transaction-mutation.d.ts +0 -1
  141. package/dist-server/service/transaction/transaction-mutation.js +13 -78
  142. package/dist-server/service/transaction/transaction-mutation.js.map +1 -1
  143. package/dist-server/service/transaction/transaction-period.d.ts +16 -0
  144. package/dist-server/service/transaction/transaction-period.js +49 -0
  145. package/dist-server/service/transaction/transaction-period.js.map +1 -0
  146. package/dist-server/service/transaction/transaction-query.d.ts +12 -0
  147. package/dist-server/service/transaction/transaction-query.js +84 -2
  148. package/dist-server/service/transaction/transaction-query.js.map +1 -1
  149. package/dist-server/service/transaction/transaction-service.d.ts +30 -0
  150. package/dist-server/service/transaction/transaction-service.js +130 -0
  151. package/dist-server/service/transaction/transaction-service.js.map +1 -0
  152. package/dist-server/service/transaction/transaction-type.d.ts +39 -7
  153. package/dist-server/service/transaction/transaction-type.js +145 -23
  154. package/dist-server/service/transaction/transaction-type.js.map +1 -1
  155. package/dist-server/service/transaction/transaction.d.ts +58 -31
  156. package/dist-server/service/transaction/transaction.js +216 -102
  157. package/dist-server/service/transaction/transaction.js.map +1 -1
  158. package/dist-server/tsconfig.tsbuildinfo +1 -1
  159. package/package.json +5 -3
  160. package/things-factory.config.js +0 -4
  161. package/translations/en.json +34 -2
  162. package/translations/ja.json +0 -1
  163. package/translations/ko.json +34 -2
  164. package/translations/ms.json +0 -1
  165. package/translations/zh.json +0 -1
  166. package/dist-client/pages/account/account-importer.d.ts +0 -22
  167. package/dist-client/pages/account/account-importer.js +0 -99
  168. package/dist-client/pages/account/account-importer.js.map +0 -1
  169. package/dist-client/pages/account/account-list-page.d.ts +0 -57
  170. package/dist-client/pages/account/account-list-page.js +0 -306
  171. package/dist-client/pages/account/account-list-page.js.map +0 -1
  172. package/dist-client/pages/bank-account/bank-account-importer.d.ts +0 -23
  173. package/dist-client/pages/bank-account/bank-account-importer.js +0 -92
  174. package/dist-client/pages/bank-account/bank-account-importer.js.map +0 -1
  175. package/dist-client/pages/bank-account/bank-account-list-page.d.ts +0 -60
  176. package/dist-client/pages/bank-account/bank-account-list-page.js +0 -317
  177. package/dist-client/pages/bank-account/bank-account-list-page.js.map +0 -1
  178. package/dist-client/pages/financial-statement/financial-statement-importer.d.ts +0 -22
  179. package/dist-client/pages/financial-statement/financial-statement-importer.js +0 -99
  180. package/dist-client/pages/financial-statement/financial-statement-importer.js.map +0 -1
  181. package/dist-client/pages/financial-statement/financial-statement-list-page.d.ts +0 -57
  182. package/dist-client/pages/financial-statement/financial-statement-list-page.js +0 -280
  183. package/dist-client/pages/financial-statement/financial-statement-list-page.js.map +0 -1
  184. package/dist-client/pages/income-statement/income-statement-importer.d.ts +0 -22
  185. package/dist-client/pages/income-statement/income-statement-importer.js +0 -99
  186. package/dist-client/pages/income-statement/income-statement-importer.js.map +0 -1
  187. package/dist-client/pages/income-statement/income-statement-list-page.d.ts +0 -57
  188. package/dist-client/pages/income-statement/income-statement-list-page.js +0 -280
  189. package/dist-client/pages/income-statement/income-statement-list-page.js.map +0 -1
  190. package/dist-client/pages/payment/payment-importer.d.ts +0 -23
  191. package/dist-client/pages/payment/payment-importer.js +0 -92
  192. package/dist-client/pages/payment/payment-importer.js.map +0 -1
  193. package/dist-client/pages/payment/payment-list-page.d.ts +0 -60
  194. package/dist-client/pages/payment/payment-list-page.js +0 -317
  195. package/dist-client/pages/payment/payment-list-page.js.map +0 -1
  196. package/dist-client/pages/transaction/transaction-importer.d.ts +0 -22
  197. package/dist-client/pages/transaction/transaction-importer.js +0 -99
  198. package/dist-client/pages/transaction/transaction-importer.js.map +0 -1
  199. package/dist-client/pages/transaction/transaction-list-page.d.ts +0 -57
  200. package/dist-client/pages/transaction/transaction-list-page.js +0 -280
  201. package/dist-client/pages/transaction/transaction-list-page.js.map +0 -1
  202. package/dist-server/controllers/index.d.ts +0 -1
  203. package/dist-server/controllers/index.js +0 -5
  204. package/dist-server/controllers/index.js.map +0 -1
  205. package/dist-server/controllers/summary-statements.d.ts +0 -4
  206. package/dist-server/controllers/summary-statements.js +0 -149
  207. package/dist-server/controllers/summary-statements.js.map +0 -1
  208. package/dist-server/migrations/1725201567284-seed-country-codes.d.ts +0 -5
  209. package/dist-server/migrations/1725201567284-seed-country-codes.js +0 -255
  210. package/dist-server/migrations/1725201567284-seed-country-codes.js.map +0 -1
  211. package/dist-server/service/financial-statement/financial-statement-line-item.d.ts +0 -19
  212. package/dist-server/service/financial-statement/financial-statement-line-item.js +0 -95
  213. package/dist-server/service/financial-statement/financial-statement-line-item.js.map +0 -1
  214. package/dist-server/service/financial-statement/financial-statement-type.d.ts +0 -20
  215. package/dist-server/service/financial-statement/financial-statement-type.js +0 -77
  216. package/dist-server/service/financial-statement/financial-statement-type.js.map +0 -1
  217. package/dist-server/service/income-statement/event-subscriber.d.ts +0 -7
  218. package/dist-server/service/income-statement/event-subscriber.js +0 -21
  219. package/dist-server/service/income-statement/event-subscriber.js.map +0 -1
  220. package/dist-server/service/income-statement/income-statement-history.d.ts +0 -28
  221. package/dist-server/service/income-statement/income-statement-history.js +0 -146
  222. package/dist-server/service/income-statement/income-statement-history.js.map +0 -1
  223. package/dist-server/service/income-statement/income-statement-line-item.d.ts +0 -19
  224. package/dist-server/service/income-statement/income-statement-line-item.js +0 -97
  225. package/dist-server/service/income-statement/income-statement-line-item.js.map +0 -1
  226. package/dist-server/service/income-statement/income-statement-mutation.d.ts +0 -10
  227. package/dist-server/service/income-statement/income-statement-mutation.js +0 -159
  228. package/dist-server/service/income-statement/income-statement-mutation.js.map +0 -1
  229. package/dist-server/service/income-statement/income-statement-query.d.ts +0 -11
  230. package/dist-server/service/income-statement/income-statement-query.js +0 -81
  231. package/dist-server/service/income-statement/income-statement-query.js.map +0 -1
  232. package/dist-server/service/income-statement/income-statement-type.d.ts +0 -20
  233. package/dist-server/service/income-statement/income-statement-type.js +0 -77
  234. package/dist-server/service/income-statement/income-statement-type.js.map +0 -1
  235. package/dist-server/service/income-statement/income-statement.d.ts +0 -28
  236. package/dist-server/service/income-statement/income-statement.js +0 -137
  237. package/dist-server/service/income-statement/income-statement.js.map +0 -1
  238. package/dist-server/service/income-statement/index.d.ts +0 -8
  239. package/dist-server/service/income-statement/index.js +0 -13
  240. package/dist-server/service/income-statement/index.js.map +0 -1
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-service.js","sourceRoot":"","sources":["../../../server/service/transaction/transaction-service.ts"],"names":[],"mappings":";;AAgGA,4CAsEC;AAtKD,qCAA2C;AAE3C,iDAA+C;AAE/C,+DAA0D;AAC1D,sDAAgD;AAChD,gDAA4C;AAC5C,gEAAgE;AAChE,gEAA4D;AAC5D,+CAAgF;AAChF,6DAA+D;AAe/D,0GAA0G;AAC1G,MAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAU,CAAA;AAErD;;;GAGG;AACH,SAAS,KAAK,CAAC,KAAuB,EAAE,OAAgC;IACtE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,KAAK,CAAA;IACvC,MAAM,GAAG,GAAwB,EAAE,GAAG,MAAM,EAAE,CAAA;IAC9C,MAAM,MAAM,GAAG,E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,CAAC,OAAO,CAAC,CAAA;IACrB,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,EAAE,CAAC;QACxB,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,CAAC,CAAA;QAC3D,MAAM,IAAA,qCAAmB,EACvB,EAAE,EACF,MAAM,EACN,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CACxC,CAAA;QACD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAqB,CAAA;QAC1C,KAAK,MAAM,OAAO,IAAI,QAAQ;YAAE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAA;QAClH,KAAK,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACzC,MAAM,IAAA,iCAAe,EAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE;gBACxD,SAAS,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACxD,cAAc,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;aACpE,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import { EntityManager, In } from 'typeorm'\n\nimport { Refusal } from '@things-factory/shell'\n\nimport { BankAccount } from '../bank-account/bank-account'\nimport { CashFlowType } from '../cash-flow-type'\nimport { Payment } from '../payment/payment'\nimport { checkPaymentsWithin } from '../payment/payment-service'\nimport { paymentTargetOf } from '../payment/payment-targets'\nimport { ForecastStatus, Transaction, TransactionCategory } from './transaction'\nimport { forecastDay, yearMonthOf } from './transaction-period'\n\n/** A transaction as a module writes it: what a person may write, and the facts a bank statement gives. */\nexport type TransactionInput = Partial<\n Omit<Transaction, 'bankAccount' | 'account' | 'counterparty' | 'recurringItem' | 'bankStatement'>\n> & {\n id?: string\n cuFlag?: string\n bankAccount?: { id: string } | null\n account?: { id: string } | null\n counterparty?: { id: string } | null\n recurringItem?: { id: string } | null\n bankStatement?: { id: string } | null\n}\n\n/** What changes the money of a transaction - its payments are checked again when one of these changes. */\nconst MONEY = ['amount', 'type', 'currency'] as const\n\n/**\n * The row a patch writes over the current one: a confirmed transaction has a day and takes its year and month from it;\n * a forecast has a year and a month, and the day its timing names.\n */\nfunction rowOf(input: TransactionInput, current: Transaction | undefined): Record<string, any> {\n const { id, cuFlag, ...fields } = input\n const row: Record<string, any> = { ...fields }\n const merged = { ...current, ...row }\n const category = merged.category ?? TransactionCategory.CONFIRMED\n row.category = category\n\n if (!current && !row.type) throw new Refusal('transaction-type-required', {}, 'type: money in or money out')\n if (row.type !== undefined && !Object.values(CashFlowType).includes(row.type))\n throw new Refusal('transaction-type-required', {}, 'type: money in or money out')\n if (!current && (row.amount === undefined || row.amount === null)) row.amount = 0\n\n if (category === TransactionCategory.CONFIRMED) {\n const period = yearMonthOf(merged.transactionDate)\n if (!period)\n throw new Refusal(\n 'transaction-date-required',\n { value: merged.transactionDate ?? '' },\n 'transactionDate: YYYY-MM-DD'\n )\n Object.assign(row, period, { status: null })\n } else {\n const [year, month] = [Number(merged.year), Number(merged.month)]\n if (!year) throw new Refusal('forecast-year-required', {}, 'year: the year it is planned in')\n if (!(month >= 1 && month <= 12))\n throw new Refusal('month-out-of-range', { month: merged.month ?? '' }, 'month: must be 1 to 12')\n if (!String(merged.description ?? '').trim())\n throw new Refusal('forecast-description-required', {}, 'description: what is planned')\n Object.assign(row, { year, month, transactionDate: forecastDay(year, month, merged.timing) })\n if (!merged.status) row.status = ForecastStatus.PLANNED\n }\n\n if (\n merged.probability !== undefined &&\n merged.probability !== null &&\n !(merged.probability >= 0 && merged.probability <= 100)\n ) {\n throw new Refusal('probability-out-of-range', {}, 'probability: must be 0 to 100')\n }\n\n return row\n}\n\n/** The payments on these transactions, and the transfers into them, by target kind. */\nasync function paymentsOn(tx: EntityManager, domain: { id: string }, ids: string[]): Promise<Payment[]> {\n if (!ids.length) return []\n const repo = tx.getRepository(Payment)\n return [\n ...(await repo.find({\n where: { domain: { id: domain.id }, transaction: { id: In(ids) } },\n relations: ['transaction']\n })),\n ...(await repo.find({\n where: { domain: { id: domain.id }, targetType: 'Transaction', targetId: In(ids) },\n relations: ['transaction']\n }))\n ]\n}\n\n/**\n * Apply rows to a domain's transactions: `+` (or no id) adds, `M` changes, `-` deletes (softly - a financial row\n * that was deleted stays readable). A transaction that pays something, or is paid, is unlinked before it is\n * deleted; when its money changes, its payments are checked again - the general rule and each target kind's own.\n */\nexport async function saveTransactions(\n tx: EntityManager,\n domain: { id: string },\n user: any,\n inputs: TransactionInput[]\n): Promise<Transaction[]> {\n const repo = tx.getRepository(Transaction)\n\n const deletes = [...new Set(inputs.filter(one => one.cuFlag === '-' && one.id).map(one => one.id!))]\n if (deletes.length) {\n const found = await repo.find({ where: { domain: { id: domain.id }, id: In(deletes) } })\n if (found.length !== deletes.length)\n throw new Refusal('transaction-not-found', {}, 'a transaction was not found - reload and try again')\n if ((await paymentsOn(tx, domain, deletes)).length)\n throw new Refusal('transaction-has-payments', {}, 'unlink what the transaction paid before deleting it')\n await repo.softRemove(found)\n }\n\n const saved: Transaction[] = []\n const moneyChanged: string[] = []\n for (const input of inputs.filter(one => one.cuFlag !== '-')) {\n const isNew = !input.id || input.cuFlag === '+'\n const current = isNew ? undefined : await repo.findOne({ where: { domain: { id: domain.id }, id: input.id } })\n if (!isNew && !current)\n throw new Refusal('transaction-not-found', {}, 'a transaction was not found - reload and try again')\n\n const row = rowOf(input, current)\n if (row.bankAccount?.id && !('currency' in input)) {\n const account = await tx\n .getRepository(BankAccount)\n .findOne({ where: { domain: { id: domain.id }, id: row.bankAccount.id } })\n if (!account)\n throw new Refusal('bank-account-not-found', {}, 'the bank account was not found - reload and try again')\n if (account.currency) row.currency = account.currency\n }\n\n if (row.bankFingerprint) {\n const twin = await repo.findOne({ where: { domain: { id: domain.id }, bankFingerprint: row.bankFingerprint } })\n if (twin && twin.id !== current?.id)\n throw new Refusal(\n 'bank-line-twice',\n { day: twin.transactionDate ?? '' },\n 'this bank line is already in the books'\n )\n }\n\n const written = await repo.save({ ...(current ?? { domain, creator: user }), ...row, updater: user } as Transaction)\n if (current && MONEY.some(field => field in row && row[field] !== (current as any)[field]))\n moneyChanged.push(current.id)\n saved.push(written)\n }\n\n if (moneyChanged.length) {\n const payments = await paymentsOn(tx, domain, moneyChanged)\n await checkPaymentsWithin(\n tx,\n domain,\n payments.map(one => one.transaction.id)\n )\n const kinds = new Map<string, Payment[]>()\n for (const payment of payments) kinds.set(payment.targetType, [...(kinds.get(payment.targetType) ?? []), payment])\n for (const [targetType, ofKind] of kinds) {\n await paymentTargetOf(targetType)?.validate?.(tx, domain, {\n targetIds: [...new Set(ofKind.map(one => one.targetId))],\n transactionIds: [...new Set(ofKind.map(one => one.transaction.id))]\n })\n }\n }\n\n return saved\n}\n"]}
@@ -1,16 +1,48 @@
1
- import { Transaction, TransactionType } from './transaction';
1
+ import { ObjectRef } from '@things-factory/shell';
2
+ import { CashFlowType } from '../cash-flow-type';
3
+ import { ForecastStatus, Transaction, TransactionCategory } from './transaction';
2
4
  export declare class NewTransaction {
3
- name: string;
5
+ category?: TransactionCategory;
6
+ type: CashFlowType;
7
+ bankAccount?: ObjectRef;
8
+ transactionDate?: string;
9
+ year?: number;
10
+ month?: number;
11
+ amount?: number;
12
+ currency?: string;
13
+ balance?: number;
14
+ account?: ObjectRef;
4
15
  description?: string;
5
- type?: TransactionType;
6
- active?: boolean;
16
+ ledgerCategory?: string;
17
+ counterpartyName?: string;
18
+ counterparty?: ObjectRef;
19
+ timing?: string;
20
+ status?: ForecastStatus;
21
+ probability?: number;
22
+ notes?: string;
23
+ recurringItem?: ObjectRef;
7
24
  }
8
25
  export declare class TransactionPatch {
9
26
  id?: string;
10
- name?: string;
27
+ category?: TransactionCategory;
28
+ type?: CashFlowType;
29
+ bankAccount?: ObjectRef;
30
+ transactionDate?: string;
31
+ year?: number;
32
+ month?: number;
33
+ amount?: number;
34
+ currency?: string;
35
+ balance?: number;
36
+ account?: ObjectRef;
11
37
  description?: string;
12
- type?: TransactionType;
13
- active?: boolean;
38
+ ledgerCategory?: string;
39
+ counterpartyName?: string;
40
+ counterparty?: ObjectRef;
41
+ timing?: string;
42
+ status?: ForecastStatus;
43
+ probability?: number;
44
+ notes?: string;
45
+ recurringItem?: ObjectRef;
14
46
  cuFlag?: string;
15
47
  }
16
48
  export declare class TransactionList {
@@ -3,71 +3,193 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TransactionList = exports.TransactionPatch = exports.NewTransaction = void 0;
4
4
  const tslib_1 = require("tslib");
5
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");
6
8
  const transaction_1 = require("./transaction");
7
9
  let NewTransaction = class NewTransaction {
8
10
  };
9
11
  exports.NewTransaction = NewTransaction;
10
12
  tslib_1.__decorate([
11
- (0, type_graphql_1.Field)(),
13
+ (0, type_graphql_1.Field)(type => transaction_1.TransactionCategory, { nullable: true, description: 'Confirmed when not given' }),
12
14
  tslib_1.__metadata("design:type", String)
13
- ], NewTransaction.prototype, "name", void 0);
15
+ ], NewTransaction.prototype, "category", void 0);
14
16
  tslib_1.__decorate([
15
- (0, type_graphql_1.Field)({ nullable: true }),
17
+ (0, type_graphql_1.Field)(type => cash_flow_type_1.CashFlowType, { description: 'Money in or money out' }),
18
+ tslib_1.__metadata("design:type", String)
19
+ ], NewTransaction.prototype, "type", void 0);
20
+ tslib_1.__decorate([
21
+ (0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'The account the money moved in or out of' }),
22
+ tslib_1.__metadata("design:type", shell_1.ObjectRef)
23
+ ], NewTransaction.prototype, "bankAccount", void 0);
24
+ tslib_1.__decorate([
25
+ (0, type_graphql_1.Field)({ nullable: true, description: 'YYYY-MM-DD - required for a confirmed transaction' }),
26
+ tslib_1.__metadata("design:type", String)
27
+ ], NewTransaction.prototype, "transactionDate", void 0);
28
+ tslib_1.__decorate([
29
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'The year a forecast is planned in' }),
30
+ tslib_1.__metadata("design:type", Number)
31
+ ], NewTransaction.prototype, "year", void 0);
32
+ tslib_1.__decorate([
33
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'The month a forecast is planned in' }),
34
+ tslib_1.__metadata("design:type", Number)
35
+ ], NewTransaction.prototype, "month", void 0);
36
+ tslib_1.__decorate([
37
+ (0, type_graphql_1.Field)(type => type_graphql_1.Float, { nullable: true, description: 'Amount - zero when not given' }),
38
+ tslib_1.__metadata("design:type", Number)
39
+ ], NewTransaction.prototype, "amount", void 0);
40
+ tslib_1.__decorate([
41
+ (0, type_graphql_1.Field)({ nullable: true, description: "ISO 4217 code - the bank account's when not given" }),
42
+ tslib_1.__metadata("design:type", String)
43
+ ], NewTransaction.prototype, "currency", void 0);
44
+ tslib_1.__decorate([
45
+ (0, type_graphql_1.Field)(type => type_graphql_1.Float, { nullable: true, description: 'Account balance after it' }),
46
+ tslib_1.__metadata("design:type", Number)
47
+ ], NewTransaction.prototype, "balance", void 0);
48
+ tslib_1.__decorate([
49
+ (0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'The account subject it is booked to' }),
50
+ tslib_1.__metadata("design:type", shell_1.ObjectRef)
51
+ ], NewTransaction.prototype, "account", void 0);
52
+ tslib_1.__decorate([
53
+ (0, type_graphql_1.Field)({ nullable: true, description: 'What a person wrote about it' }),
16
54
  tslib_1.__metadata("design:type", String)
17
55
  ], NewTransaction.prototype, "description", void 0);
18
56
  tslib_1.__decorate([
19
- (0, type_graphql_1.Field)(type => transaction_1.TransactionType, { nullable: true }),
57
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The classifying word of the ledger it was kept in' }),
58
+ tslib_1.__metadata("design:type", String)
59
+ ], NewTransaction.prototype, "ledgerCategory", void 0);
60
+ tslib_1.__decorate([
61
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The counterparty name as a person wrote it' }),
62
+ tslib_1.__metadata("design:type", String)
63
+ ], NewTransaction.prototype, "counterpartyName", void 0);
64
+ tslib_1.__decorate([
65
+ (0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'The registered counterparty' }),
66
+ tslib_1.__metadata("design:type", shell_1.ObjectRef)
67
+ ], NewTransaction.prototype, "counterparty", void 0);
68
+ tslib_1.__decorate([
69
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When in the month a forecast falls' }),
70
+ tslib_1.__metadata("design:type", String)
71
+ ], NewTransaction.prototype, "timing", void 0);
72
+ tslib_1.__decorate([
73
+ (0, type_graphql_1.Field)(type => transaction_1.ForecastStatus, { nullable: true, description: 'State of a forecast' }),
74
+ tslib_1.__metadata("design:type", String)
75
+ ], NewTransaction.prototype, "status", void 0);
76
+ tslib_1.__decorate([
77
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'The probability of a forecast being realized (0 to 100)' }),
20
78
  tslib_1.__metadata("design:type", Number)
21
- ], NewTransaction.prototype, "type", void 0);
79
+ ], NewTransaction.prototype, "probability", void 0);
80
+ tslib_1.__decorate([
81
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Notes' }),
82
+ tslib_1.__metadata("design:type", String)
83
+ ], NewTransaction.prototype, "notes", void 0);
22
84
  tslib_1.__decorate([
23
- (0, type_graphql_1.Field)({ nullable: true }),
24
- tslib_1.__metadata("design:type", Boolean)
25
- ], NewTransaction.prototype, "active", void 0);
85
+ (0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'The recurring item a forecast was made from' }),
86
+ tslib_1.__metadata("design:type", shell_1.ObjectRef)
87
+ ], NewTransaction.prototype, "recurringItem", void 0);
26
88
  exports.NewTransaction = NewTransaction = tslib_1.__decorate([
27
- (0, type_graphql_1.InputType)()
89
+ (0, type_graphql_1.InputType)({ description: 'A transaction someone writes - a bank line by hand, or a forecast' })
28
90
  ], NewTransaction);
29
91
  let TransactionPatch = class TransactionPatch {
30
92
  };
31
93
  exports.TransactionPatch = TransactionPatch;
32
94
  tslib_1.__decorate([
33
- (0, type_graphql_1.Field)(type => type_graphql_1.ID, { nullable: true }),
95
+ (0, type_graphql_1.Field)(type => type_graphql_1.ID, { nullable: true, description: 'The transaction to change or delete' }),
34
96
  tslib_1.__metadata("design:type", String)
35
97
  ], TransactionPatch.prototype, "id", void 0);
36
98
  tslib_1.__decorate([
37
- (0, type_graphql_1.Field)({ nullable: true }),
99
+ (0, type_graphql_1.Field)(type => transaction_1.TransactionCategory, { nullable: true, description: 'Confirmed or forecast' }),
38
100
  tslib_1.__metadata("design:type", String)
39
- ], TransactionPatch.prototype, "name", void 0);
101
+ ], TransactionPatch.prototype, "category", void 0);
40
102
  tslib_1.__decorate([
41
- (0, type_graphql_1.Field)({ nullable: true }),
103
+ (0, type_graphql_1.Field)(type => cash_flow_type_1.CashFlowType, { nullable: true, description: 'Money in or money out' }),
104
+ tslib_1.__metadata("design:type", String)
105
+ ], TransactionPatch.prototype, "type", void 0);
106
+ tslib_1.__decorate([
107
+ (0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'The account the money moved in or out of' }),
108
+ tslib_1.__metadata("design:type", shell_1.ObjectRef)
109
+ ], TransactionPatch.prototype, "bankAccount", void 0);
110
+ tslib_1.__decorate([
111
+ (0, type_graphql_1.Field)({ nullable: true, description: 'YYYY-MM-DD' }),
112
+ tslib_1.__metadata("design:type", String)
113
+ ], TransactionPatch.prototype, "transactionDate", void 0);
114
+ tslib_1.__decorate([
115
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'The year a forecast is planned in' }),
116
+ tslib_1.__metadata("design:type", Number)
117
+ ], TransactionPatch.prototype, "year", void 0);
118
+ tslib_1.__decorate([
119
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'The month a forecast is planned in' }),
120
+ tslib_1.__metadata("design:type", Number)
121
+ ], TransactionPatch.prototype, "month", void 0);
122
+ tslib_1.__decorate([
123
+ (0, type_graphql_1.Field)(type => type_graphql_1.Float, { nullable: true, description: 'Amount' }),
124
+ tslib_1.__metadata("design:type", Number)
125
+ ], TransactionPatch.prototype, "amount", void 0);
126
+ tslib_1.__decorate([
127
+ (0, type_graphql_1.Field)({ nullable: true, description: 'ISO 4217 code' }),
128
+ tslib_1.__metadata("design:type", String)
129
+ ], TransactionPatch.prototype, "currency", void 0);
130
+ tslib_1.__decorate([
131
+ (0, type_graphql_1.Field)(type => type_graphql_1.Float, { nullable: true, description: 'Account balance after it' }),
132
+ tslib_1.__metadata("design:type", Number)
133
+ ], TransactionPatch.prototype, "balance", void 0);
134
+ tslib_1.__decorate([
135
+ (0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'The account subject it is booked to' }),
136
+ tslib_1.__metadata("design:type", shell_1.ObjectRef)
137
+ ], TransactionPatch.prototype, "account", void 0);
138
+ tslib_1.__decorate([
139
+ (0, type_graphql_1.Field)({ nullable: true, description: 'What a person wrote about it' }),
42
140
  tslib_1.__metadata("design:type", String)
43
141
  ], TransactionPatch.prototype, "description", void 0);
44
142
  tslib_1.__decorate([
45
- (0, type_graphql_1.Field)(type => transaction_1.TransactionType, { nullable: true }),
143
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The classifying word of the ledger it was kept in' }),
144
+ tslib_1.__metadata("design:type", String)
145
+ ], TransactionPatch.prototype, "ledgerCategory", void 0);
146
+ tslib_1.__decorate([
147
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The counterparty name as a person wrote it' }),
148
+ tslib_1.__metadata("design:type", String)
149
+ ], TransactionPatch.prototype, "counterpartyName", void 0);
150
+ tslib_1.__decorate([
151
+ (0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'The registered counterparty' }),
152
+ tslib_1.__metadata("design:type", shell_1.ObjectRef)
153
+ ], TransactionPatch.prototype, "counterparty", void 0);
154
+ tslib_1.__decorate([
155
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When in the month a forecast falls' }),
156
+ tslib_1.__metadata("design:type", String)
157
+ ], TransactionPatch.prototype, "timing", void 0);
158
+ tslib_1.__decorate([
159
+ (0, type_graphql_1.Field)(type => transaction_1.ForecastStatus, { nullable: true, description: 'State of a forecast' }),
160
+ tslib_1.__metadata("design:type", String)
161
+ ], TransactionPatch.prototype, "status", void 0);
162
+ tslib_1.__decorate([
163
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'The probability of a forecast being realized (0 to 100)' }),
46
164
  tslib_1.__metadata("design:type", Number)
47
- ], TransactionPatch.prototype, "type", void 0);
165
+ ], TransactionPatch.prototype, "probability", void 0);
166
+ tslib_1.__decorate([
167
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Notes' }),
168
+ tslib_1.__metadata("design:type", String)
169
+ ], TransactionPatch.prototype, "notes", void 0);
48
170
  tslib_1.__decorate([
49
- (0, type_graphql_1.Field)({ nullable: true }),
50
- tslib_1.__metadata("design:type", Boolean)
51
- ], TransactionPatch.prototype, "active", void 0);
171
+ (0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'The recurring item a forecast was made from' }),
172
+ tslib_1.__metadata("design:type", shell_1.ObjectRef)
173
+ ], TransactionPatch.prototype, "recurringItem", void 0);
52
174
  tslib_1.__decorate([
53
- (0, type_graphql_1.Field)({ nullable: true }),
175
+ (0, type_graphql_1.Field)({ nullable: true, description: '+ adds, M changes, - deletes' }),
54
176
  tslib_1.__metadata("design:type", String)
55
177
  ], TransactionPatch.prototype, "cuFlag", void 0);
56
178
  exports.TransactionPatch = TransactionPatch = tslib_1.__decorate([
57
- (0, type_graphql_1.InputType)()
179
+ (0, type_graphql_1.InputType)({ description: 'A change to a transaction, or a grid row: cuFlag + adds, M changes, - deletes' })
58
180
  ], TransactionPatch);
59
181
  let TransactionList = class TransactionList {
60
182
  };
61
183
  exports.TransactionList = TransactionList;
62
184
  tslib_1.__decorate([
63
- (0, type_graphql_1.Field)(type => [transaction_1.Transaction]),
185
+ (0, type_graphql_1.Field)(type => [transaction_1.Transaction], { description: 'The transactions on this page' }),
64
186
  tslib_1.__metadata("design:type", Array)
65
187
  ], TransactionList.prototype, "items", void 0);
66
188
  tslib_1.__decorate([
67
- (0, type_graphql_1.Field)(type => type_graphql_1.Int),
189
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int, { description: 'How many there are in all' }),
68
190
  tslib_1.__metadata("design:type", Number)
69
191
  ], TransactionList.prototype, "total", void 0);
70
192
  exports.TransactionList = TransactionList = tslib_1.__decorate([
71
- (0, type_graphql_1.ObjectType)()
193
+ (0, type_graphql_1.ObjectType)({ description: 'A page of transactions' })
72
194
  ], TransactionList);
73
195
  //# sourceMappingURL=transaction-type.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"transaction-type.js","sourceRoot":"","sources":["../../../server/service/transaction/transaction-type.ts"],"names":[],"mappings":";;;;AAAA,+CAAsF;AAEtF,+CAA4D;AAGrD,IAAM,cAAc,GAApB,MAAM,cAAc;CAY1B,CAAA;AAZY,wCAAc;AAEzB;IADC,IAAA,oBAAK,GAAE;;4CACI;AAGZ;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;mDACN;AAGpB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,6BAAe,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;4CAC7B;AAGtB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;8CACV;yBAXL,cAAc;IAD1B,IAAA,wBAAS,GAAE;GACC,cAAc,CAY1B;AAGM,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAkB5B,CAAA;AAlBY,4CAAgB;AAE3B;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;4CAC3B;AAGX;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;8CACb;AAGb;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;qDACN;AAGpB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,6BAAe,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;8CAC7B;AAGtB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;gDACV;AAGhB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;gDACX;2BAjBJ,gBAAgB;IAD5B,IAAA,wBAAS,GAAE;GACC,gBAAgB,CAkB5B;AAGM,IAAM,eAAe,GAArB,MAAM,eAAe;CAM3B,CAAA;AANY,0CAAe;AAE1B;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,yBAAW,CAAC,CAAC;;8CACT;AAGpB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,CAAC;;8CACN;0BALF,eAAe;IAD3B,IAAA,yBAAU,GAAE;GACA,eAAe,CAM3B","sourcesContent":["import { ObjectType, Field, InputType, Int, ID, registerEnumType } from 'type-graphql'\n\nimport { Transaction, TransactionType } from './transaction'\n\n@InputType()\nexport class NewTransaction {\n @Field()\n name: string\n\n @Field({ nullable: true })\n description?: string\n\n @Field(type => TransactionType, { nullable: true })\n type?: TransactionType\n\n @Field({ nullable: true })\n active?: boolean\n}\n\n@InputType()\nexport class TransactionPatch {\n @Field(type => ID, { nullable: true })\n id?: string\n\n @Field({ nullable: true })\n name?: string\n\n @Field({ nullable: true })\n description?: string\n\n @Field(type => TransactionType, { nullable: true })\n type?: TransactionType\n\n @Field({ nullable: true })\n active?: boolean\n\n @Field({ nullable: true })\n cuFlag?: string\n}\n\n@ObjectType()\nexport class TransactionList {\n @Field(type => [Transaction])\n items: Transaction[]\n\n @Field(type => Int)\n total: number\n}\n"]}
1
+ {"version":3,"file":"transaction-type.js","sourceRoot":"","sources":["../../../server/service/transaction/transaction-type.ts"],"names":[],"mappings":";;;;AAAA,+CAA2E;AAE3E,iDAAiD;AAEjD,sDAAgD;AAChD,+CAAgF;AAGzE,IAAM,cAAc,GAApB,MAAM,cAAc;CAyD1B,CAAA;AAzDY,wCAAc;AAEzB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iCAAmB,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,0BAA0B,EAAE,CAAC;;gDAClE;AAG9B;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,6BAAY,EAAE,EAAE,WAAW,EAAE,uBAAuB,EAAE,CAAC;;4CACpD;AAGlB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAS,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,0CAA0C,EAAE,CAAC;sCACxF,iBAAS;mDAAA;AAGvB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,mDAAmD,EAAE,CAAC;;uDACpE;AAGxB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAA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,yBAAW,CAAC,EAAE,EAAE,WAAW,EAAE,+BAA+B,EAAE,CAAC;;8CAC3D;AAGpB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,EAAE,EAAE,WAAW,EAAE,2BAA2B,EAAE,CAAC;;8CACpD;0BALF,eAAe;IAD3B,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,wBAAwB,EAAE,CAAC;GACzC,eAAe,CAM3B","sourcesContent":["import { ObjectType, Field, Float, InputType, Int, ID } from 'type-graphql'\n\nimport { ObjectRef } from '@things-factory/shell'\n\nimport { CashFlowType } from '../cash-flow-type'\nimport { ForecastStatus, Transaction, TransactionCategory } from './transaction'\n\n@InputType({ description: 'A transaction someone writes - a bank line by hand, or a forecast' })\nexport class NewTransaction {\n @Field(type => TransactionCategory, { nullable: true, description: 'Confirmed when not given' })\n category?: TransactionCategory\n\n @Field(type => CashFlowType, { description: 'Money in or money out' })\n type: CashFlowType\n\n @Field(type => ObjectRef, { nullable: true, description: 'The account the money moved in or out of' })\n bankAccount?: ObjectRef\n\n @Field({ nullable: true, description: 'YYYY-MM-DD - required for a confirmed transaction' })\n transactionDate?: string\n\n @Field(type => Int, { nullable: true, description: 'The year a forecast is planned in' })\n year?: number\n\n @Field(type => Int, { nullable: true, description: 'The month a forecast is planned in' })\n month?: number\n\n @Field(type => Float, { nullable: true, description: 'Amount - zero when not given' })\n amount?: number\n\n @Field({ nullable: true, description: \"ISO 4217 code - the bank account's when not given\" })\n currency?: string\n\n @Field(type => Float, { nullable: true, description: 'Account balance after it' })\n balance?: number\n\n @Field(type => ObjectRef, { nullable: true, description: 'The account subject it is booked to' })\n account?: ObjectRef\n\n @Field({ nullable: true, description: 'What a person wrote about it' })\n description?: string\n\n @Field({ nullable: true, description: 'The classifying word of the ledger it was kept in' })\n ledgerCategory?: string\n\n @Field({ nullable: true, description: 'The counterparty name as a person wrote it' })\n counterpartyName?: string\n\n @Field(type => ObjectRef, { nullable: true, description: 'The registered counterparty' })\n counterparty?: ObjectRef\n\n @Field({ nullable: true, description: 'When in the month a forecast falls' })\n timing?: string\n\n @Field(type => ForecastStatus, { nullable: true, description: 'State of a forecast' })\n status?: ForecastStatus\n\n @Field(type => Int, { nullable: true, description: 'The probability of a forecast being realized (0 to 100)' })\n probability?: number\n\n @Field({ nullable: true, description: 'Notes' })\n notes?: string\n\n @Field(type => ObjectRef, { nullable: true, description: 'The recurring item a forecast was made from' })\n recurringItem?: ObjectRef\n}\n\n@InputType({ description: 'A change to a transaction, or a grid row: cuFlag + adds, M changes, - deletes' })\nexport class TransactionPatch {\n @Field(type => ID, { nullable: true, description: 'The transaction to change or delete' })\n id?: string\n\n @Field(type => TransactionCategory, { nullable: true, description: 'Confirmed or forecast' })\n category?: TransactionCategory\n\n @Field(type => CashFlowType, { nullable: true, description: 'Money in or money out' })\n type?: CashFlowType\n\n @Field(type => ObjectRef, { nullable: true, description: 'The account the money moved in or out of' })\n bankAccount?: ObjectRef\n\n @Field({ nullable: true, description: 'YYYY-MM-DD' })\n transactionDate?: string\n\n @Field(type => Int, { nullable: true, description: 'The year a forecast is planned in' })\n year?: number\n\n @Field(type => Int, { nullable: true, description: 'The month a forecast is planned in' })\n month?: number\n\n @Field(type => Float, { nullable: true, description: 'Amount' })\n amount?: number\n\n @Field({ nullable: true, description: 'ISO 4217 code' })\n currency?: string\n\n @Field(type => Float, { nullable: true, description: 'Account balance after it' })\n balance?: number\n\n @Field(type => ObjectRef, { nullable: true, description: 'The account subject it is booked to' })\n account?: ObjectRef\n\n @Field({ nullable: true, description: 'What a person wrote about it' })\n description?: string\n\n @Field({ nullable: true, description: 'The classifying word of the ledger it was kept in' })\n ledgerCategory?: string\n\n @Field({ nullable: true, description: 'The counterparty name as a person wrote it' })\n counterpartyName?: string\n\n @Field(type => ObjectRef, { nullable: true, description: 'The registered counterparty' })\n counterparty?: ObjectRef\n\n @Field({ nullable: true, description: 'When in the month a forecast falls' })\n timing?: string\n\n @Field(type => ForecastStatus, { nullable: true, description: 'State of a forecast' })\n status?: ForecastStatus\n\n @Field(type => Int, { nullable: true, description: 'The probability of a forecast being realized (0 to 100)' })\n probability?: number\n\n @Field({ nullable: true, description: 'Notes' })\n notes?: string\n\n @Field(type => ObjectRef, { nullable: true, description: 'The recurring item a forecast was made from' })\n recurringItem?: ObjectRef\n\n @Field({ nullable: true, description: '+ adds, M changes, - deletes' })\n cuFlag?: string\n}\n\n@ObjectType({ description: 'A page of transactions' })\nexport class TransactionList {\n @Field(type => [Transaction], { description: 'The transactions on this page' })\n items: Transaction[]\n\n @Field(type => Int, { description: 'How many there are in all' })\n total: number\n}\n"]}
@@ -1,50 +1,77 @@
1
1
  import { Domain } from '@things-factory/shell';
2
2
  import { User } from '@things-factory/auth-base';
3
+ import { Counterparty } from '@things-factory/biz-base';
3
4
  import { Account } from '../account/account';
5
+ import { BankAccount } from '../bank-account/bank-account';
6
+ import { BankStatement } from '../bank-statement/bank-statement';
7
+ import { CashFlowType } from '../cash-flow-type';
4
8
  import { Payment } from '../payment/payment';
5
9
  import { AccountingDocument } from '../accounting-document/accounting-document';
6
- export declare enum TransactionType {
7
- SalesIncome = 0,// 매출
8
- PurchaseExpense = 1,// 매입
9
- Asset = 2,// 자산
10
- Liability = 3,// 부채
11
- Equity = 4,// 자본
12
- OtherIncome = 5,// 기타 수익
13
- OtherExpense = 6
14
- }
10
+ import { RecurringCashItem } from '../recurring-cash-item/recurring-cash-item';
15
11
  export declare enum TransactionCategory {
16
- Confirmed = "Confirmed",// 확정된 건
17
- Forecast = "Forecast"
12
+ CONFIRMED = "CONFIRMED",
13
+ FORECAST = "FORECAST"
14
+ }
15
+ export declare enum TransactionSource {
16
+ BANK_STATEMENT = "BANK_STATEMENT",
17
+ LEGACY = "LEGACY",
18
+ MANUAL = "MANUAL"
18
19
  }
19
- export declare enum TransactionStatus {
20
- Pending = "Pending",// 처리 대기 중
21
- Paid = "Paid",// 전액 결제됨
22
- PartiallyPaid = "PartiallyPaid",// 일부만 결제됨
23
- Cancelled = "Cancelled",// 취소됨
24
- Delayed = "Delayed",// 지연됨
25
- ForecastFailed = "ForecastFailed"
20
+ export declare enum ForecastStatus {
21
+ PLANNED = "PLANNED",
22
+ DONE = "DONE",
23
+ CANCELLED = "CANCELLED"
26
24
  }
25
+ /**
26
+ * Money that moves in or out of the business: a line on a bank account (confirmed), or a plan someone made of money
27
+ * still to come or go (forecast).
28
+ *
29
+ * What a transaction paid - a contract round, a tax invoice, a VAT period - is its payments (§`Payment`). The facts
30
+ * of a bank line are kept as the bank gave them, beside what a person wrote about it.
31
+ */
27
32
  export declare class Transaction {
28
33
  readonly id: string;
29
34
  version?: number;
30
35
  domain?: Domain;
31
36
  domainId?: string;
32
- name?: string;
33
- description?: string;
34
- currency?: string;
35
- amount?: number;
36
- active?: boolean;
37
- type?: TransactionType;
38
37
  category: TransactionCategory;
39
- status: TransactionStatus;
40
- probability?: number;
41
- forecastNotes?: string;
38
+ type: CashFlowType;
39
+ bankAccount?: BankAccount;
40
+ bankAccountId?: string;
41
+ transactionDate?: string;
42
+ transactionAt?: string;
43
+ year: number;
44
+ month: number;
45
+ amount: number;
46
+ currency: string;
47
+ balance?: number;
42
48
  account?: Account;
43
49
  accountId?: string;
44
- year?: number;
45
- quarter?: number;
46
- month?: number;
47
- transactionDate: string;
50
+ description?: string;
51
+ ledgerCategory?: string;
52
+ counterpartyName?: string;
53
+ counterparty?: Counterparty;
54
+ counterpartyId?: string;
55
+ source: TransactionSource;
56
+ bankStatement?: BankStatement;
57
+ bankStatementId?: string;
58
+ sourceFile?: string;
59
+ sourceRow?: number;
60
+ bankSequence?: number;
61
+ bankFingerprint?: string;
62
+ bankReconciliationBefore?: Record<string, any>;
63
+ bankDescription?: string;
64
+ bankKind?: string;
65
+ bankCounterpartyName?: string;
66
+ bankCounterpartyAccount?: string;
67
+ bankCounterpartyBank?: string;
68
+ bankMemo?: string;
69
+ timing?: string;
70
+ status?: ForecastStatus;
71
+ probability?: number;
72
+ notes?: string;
73
+ recurringItem?: RecurringCashItem;
74
+ recurringItemId?: string;
48
75
  payments?: Payment[];
49
76
  documents?: AccountingDocument[];
50
77
  createdAt?: Date;