@things-factory/accounting 10.1.134 → 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.
Files changed (234) 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-type.d.ts +16 -0
  14. package/dist-server/service/account/account-type.js +71 -13
  15. package/dist-server/service/account/account-type.js.map +1 -1
  16. package/dist-server/service/account/account.d.ts +9 -3
  17. package/dist-server/service/account/account.js +34 -8
  18. package/dist-server/service/account/account.js.map +1 -1
  19. package/dist-server/service/accounting-category/accounting-category-mutation.js +2 -2
  20. package/dist-server/service/accounting-category/accounting-category-mutation.js.map +1 -1
  21. package/dist-server/service/accounting-document/accounting-document-mutation.js +12 -3
  22. package/dist-server/service/accounting-document/accounting-document-mutation.js.map +1 -1
  23. package/dist-server/service/accounting-document/accounting-document-query.js +2 -0
  24. package/dist-server/service/accounting-document/accounting-document-query.js.map +1 -1
  25. package/dist-server/service/bank-account/bank-account-history.d.ts +11 -14
  26. package/dist-server/service/bank-account/bank-account-history.js +46 -59
  27. package/dist-server/service/bank-account/bank-account-history.js.map +1 -1
  28. package/dist-server/service/bank-account/bank-account-mutation.d.ts +1 -2
  29. package/dist-server/service/bank-account/bank-account-mutation.js +25 -69
  30. package/dist-server/service/bank-account/bank-account-mutation.js.map +1 -1
  31. package/dist-server/service/bank-account/bank-account-query.js +2 -0
  32. package/dist-server/service/bank-account/bank-account-query.js.map +1 -1
  33. package/dist-server/service/bank-account/bank-account-service.d.ts +5 -0
  34. package/dist-server/service/bank-account/bank-account-service.js +21 -0
  35. package/dist-server/service/bank-account/bank-account-service.js.map +1 -0
  36. package/dist-server/service/bank-account/bank-account-type.d.ts +13 -19
  37. package/dist-server/service/bank-account/bank-account-type.js +45 -69
  38. package/dist-server/service/bank-account/bank-account-type.js.map +1 -1
  39. package/dist-server/service/bank-account/bank-account.d.ts +14 -17
  40. package/dist-server/service/bank-account/bank-account.js +45 -57
  41. package/dist-server/service/bank-account/bank-account.js.map +1 -1
  42. package/dist-server/service/bank-statement/bank-statement-query.d.ts +14 -0
  43. package/dist-server/service/bank-statement/bank-statement-query.js +92 -0
  44. package/dist-server/service/bank-statement/bank-statement-query.js.map +1 -0
  45. package/dist-server/service/bank-statement/bank-statement.d.ts +26 -0
  46. package/dist-server/service/bank-statement/bank-statement.js +109 -0
  47. package/dist-server/service/bank-statement/bank-statement.js.map +1 -0
  48. package/dist-server/service/bank-statement/index.d.ts +5 -0
  49. package/dist-server/service/bank-statement/index.js +9 -0
  50. package/dist-server/service/bank-statement/index.js.map +1 -0
  51. package/dist-server/service/cash-flow-type.d.ts +5 -0
  52. package/dist-server/service/cash-flow-type.js +15 -0
  53. package/dist-server/service/cash-flow-type.js.map +1 -0
  54. package/dist-server/service/financial-institution/financial-institution-mutation.js +10 -1
  55. package/dist-server/service/financial-institution/financial-institution-mutation.js.map +1 -1
  56. package/dist-server/service/financial-institution/financial-institution-query.js +14 -6
  57. package/dist-server/service/financial-institution/financial-institution-query.js.map +1 -1
  58. package/dist-server/service/financial-institution/index.d.ts +1 -1
  59. package/dist-server/service/financial-statement/financial-statement-history.d.ts +11 -9
  60. package/dist-server/service/financial-statement/financial-statement-history.js +47 -36
  61. package/dist-server/service/financial-statement/financial-statement-history.js.map +1 -1
  62. package/dist-server/service/financial-statement/financial-statement-line.d.ts +24 -0
  63. package/dist-server/service/financial-statement/financial-statement-line.js +108 -0
  64. package/dist-server/service/financial-statement/financial-statement-line.js.map +1 -0
  65. package/dist-server/service/financial-statement/financial-statement-mutation.d.ts +1 -8
  66. package/dist-server/service/financial-statement/financial-statement-mutation.js +10 -135
  67. package/dist-server/service/financial-statement/financial-statement-mutation.js.map +1 -1
  68. package/dist-server/service/financial-statement/financial-statement-query.d.ts +8 -7
  69. package/dist-server/service/financial-statement/financial-statement-query.js +40 -30
  70. package/dist-server/service/financial-statement/financial-statement-query.js.map +1 -1
  71. package/dist-server/service/financial-statement/financial-statement-service.d.ts +33 -0
  72. package/dist-server/service/financial-statement/financial-statement-service.js +44 -0
  73. package/dist-server/service/financial-statement/financial-statement-service.js.map +1 -0
  74. package/dist-server/service/financial-statement/financial-statement.d.ts +19 -11
  75. package/dist-server/service/financial-statement/financial-statement.js +73 -65
  76. package/dist-server/service/financial-statement/financial-statement.js.map +1 -1
  77. package/dist-server/service/financial-statement/index.d.ts +3 -2
  78. package/dist-server/service/financial-statement/index.js +2 -2
  79. package/dist-server/service/financial-statement/index.js.map +1 -1
  80. package/dist-server/service/index.d.ts +15 -3
  81. package/dist-server/service/index.js +30 -13
  82. package/dist-server/service/index.js.map +1 -1
  83. package/dist-server/service/payment/index.d.ts +1 -0
  84. package/dist-server/service/payment/index.js +1 -0
  85. package/dist-server/service/payment/index.js.map +1 -1
  86. package/dist-server/service/payment/payment-history.d.ts +9 -16
  87. package/dist-server/service/payment/payment-history.js +36 -70
  88. package/dist-server/service/payment/payment-history.js.map +1 -1
  89. package/dist-server/service/payment/payment-mutation.d.ts +0 -1
  90. package/dist-server/service/payment/payment-mutation.js +14 -79
  91. package/dist-server/service/payment/payment-mutation.js.map +1 -1
  92. package/dist-server/service/payment/payment-query.d.ts +3 -0
  93. package/dist-server/service/payment/payment-query.js +30 -1
  94. package/dist-server/service/payment/payment-query.js.map +1 -1
  95. package/dist-server/service/payment/payment-service.d.ts +16 -0
  96. package/dist-server/service/payment/payment-service.js +140 -0
  97. package/dist-server/service/payment/payment-service.js.map +1 -0
  98. package/dist-server/service/payment/payment-targets.d.ts +31 -0
  99. package/dist-server/service/payment/payment-targets.js +19 -0
  100. package/dist-server/service/payment/payment-targets.js.map +1 -0
  101. package/dist-server/service/payment/payment-type.d.ts +13 -17
  102. package/dist-server/service/payment/payment-type.js +35 -51
  103. package/dist-server/service/payment/payment-type.js.map +1 -1
  104. package/dist-server/service/payment/payment.d.ts +23 -22
  105. package/dist-server/service/payment/payment.js +66 -94
  106. package/dist-server/service/payment/payment.js.map +1 -1
  107. package/dist-server/service/payment/transfer-target.d.ts +1 -0
  108. package/dist-server/service/payment/transfer-target.js +43 -0
  109. package/dist-server/service/payment/transfer-target.js.map +1 -0
  110. package/dist-server/service/recurring-cash-item/index.d.ts +6 -0
  111. package/dist-server/service/recurring-cash-item/index.js +10 -0
  112. package/dist-server/service/recurring-cash-item/index.js.map +1 -0
  113. package/dist-server/service/recurring-cash-item/recurring-cash-item-mutation.d.ts +7 -0
  114. package/dist-server/service/recurring-cash-item/recurring-cash-item-mutation.js +63 -0
  115. package/dist-server/service/recurring-cash-item/recurring-cash-item-mutation.js.map +1 -0
  116. package/dist-server/service/recurring-cash-item/recurring-cash-item-query.d.ts +15 -0
  117. package/dist-server/service/recurring-cash-item/recurring-cash-item-query.js +101 -0
  118. package/dist-server/service/recurring-cash-item/recurring-cash-item-query.js.map +1 -0
  119. package/dist-server/service/recurring-cash-item/recurring-cash-item-service.d.ts +23 -0
  120. package/dist-server/service/recurring-cash-item/recurring-cash-item-service.js +91 -0
  121. package/dist-server/service/recurring-cash-item/recurring-cash-item-service.js.map +1 -0
  122. package/dist-server/service/recurring-cash-item/recurring-cash-item-type.d.ts +23 -0
  123. package/dist-server/service/recurring-cash-item/recurring-cash-item-type.js +85 -0
  124. package/dist-server/service/recurring-cash-item/recurring-cash-item-type.js.map +1 -0
  125. package/dist-server/service/recurring-cash-item/recurring-cash-item.d.ts +35 -0
  126. package/dist-server/service/recurring-cash-item/recurring-cash-item.js +142 -0
  127. package/dist-server/service/recurring-cash-item/recurring-cash-item.js.map +1 -0
  128. package/dist-server/service/recurring-cash-item/recurring-schedule.d.ts +36 -0
  129. package/dist-server/service/recurring-cash-item/recurring-schedule.js +41 -0
  130. package/dist-server/service/recurring-cash-item/recurring-schedule.js.map +1 -0
  131. package/dist-server/service/transaction/transaction-history.d.ts +42 -15
  132. package/dist-server/service/transaction/transaction-history.js +160 -54
  133. package/dist-server/service/transaction/transaction-history.js.map +1 -1
  134. package/dist-server/service/transaction/transaction-mutation.d.ts +0 -1
  135. package/dist-server/service/transaction/transaction-mutation.js +13 -78
  136. package/dist-server/service/transaction/transaction-mutation.js.map +1 -1
  137. package/dist-server/service/transaction/transaction-period.d.ts +16 -0
  138. package/dist-server/service/transaction/transaction-period.js +49 -0
  139. package/dist-server/service/transaction/transaction-period.js.map +1 -0
  140. package/dist-server/service/transaction/transaction-query.d.ts +12 -0
  141. package/dist-server/service/transaction/transaction-query.js +84 -2
  142. package/dist-server/service/transaction/transaction-query.js.map +1 -1
  143. package/dist-server/service/transaction/transaction-service.d.ts +30 -0
  144. package/dist-server/service/transaction/transaction-service.js +130 -0
  145. package/dist-server/service/transaction/transaction-service.js.map +1 -0
  146. package/dist-server/service/transaction/transaction-type.d.ts +39 -7
  147. package/dist-server/service/transaction/transaction-type.js +145 -23
  148. package/dist-server/service/transaction/transaction-type.js.map +1 -1
  149. package/dist-server/service/transaction/transaction.d.ts +58 -31
  150. package/dist-server/service/transaction/transaction.js +216 -102
  151. package/dist-server/service/transaction/transaction.js.map +1 -1
  152. package/dist-server/tsconfig.tsbuildinfo +1 -1
  153. package/package.json +5 -3
  154. package/things-factory.config.js +0 -4
  155. package/translations/en.json +34 -2
  156. package/translations/ja.json +0 -1
  157. package/translations/ko.json +34 -2
  158. package/translations/ms.json +0 -1
  159. package/translations/zh.json +0 -1
  160. package/dist-client/pages/account/account-importer.d.ts +0 -22
  161. package/dist-client/pages/account/account-importer.js +0 -99
  162. package/dist-client/pages/account/account-importer.js.map +0 -1
  163. package/dist-client/pages/account/account-list-page.d.ts +0 -57
  164. package/dist-client/pages/account/account-list-page.js +0 -306
  165. package/dist-client/pages/account/account-list-page.js.map +0 -1
  166. package/dist-client/pages/bank-account/bank-account-importer.d.ts +0 -23
  167. package/dist-client/pages/bank-account/bank-account-importer.js +0 -92
  168. package/dist-client/pages/bank-account/bank-account-importer.js.map +0 -1
  169. package/dist-client/pages/bank-account/bank-account-list-page.d.ts +0 -60
  170. package/dist-client/pages/bank-account/bank-account-list-page.js +0 -317
  171. package/dist-client/pages/bank-account/bank-account-list-page.js.map +0 -1
  172. package/dist-client/pages/financial-statement/financial-statement-importer.d.ts +0 -22
  173. package/dist-client/pages/financial-statement/financial-statement-importer.js +0 -99
  174. package/dist-client/pages/financial-statement/financial-statement-importer.js.map +0 -1
  175. package/dist-client/pages/financial-statement/financial-statement-list-page.d.ts +0 -57
  176. package/dist-client/pages/financial-statement/financial-statement-list-page.js +0 -280
  177. package/dist-client/pages/financial-statement/financial-statement-list-page.js.map +0 -1
  178. package/dist-client/pages/income-statement/income-statement-importer.d.ts +0 -22
  179. package/dist-client/pages/income-statement/income-statement-importer.js +0 -99
  180. package/dist-client/pages/income-statement/income-statement-importer.js.map +0 -1
  181. package/dist-client/pages/income-statement/income-statement-list-page.d.ts +0 -57
  182. package/dist-client/pages/income-statement/income-statement-list-page.js +0 -280
  183. package/dist-client/pages/income-statement/income-statement-list-page.js.map +0 -1
  184. package/dist-client/pages/payment/payment-importer.d.ts +0 -23
  185. package/dist-client/pages/payment/payment-importer.js +0 -92
  186. package/dist-client/pages/payment/payment-importer.js.map +0 -1
  187. package/dist-client/pages/payment/payment-list-page.d.ts +0 -60
  188. package/dist-client/pages/payment/payment-list-page.js +0 -317
  189. package/dist-client/pages/payment/payment-list-page.js.map +0 -1
  190. package/dist-client/pages/transaction/transaction-importer.d.ts +0 -22
  191. package/dist-client/pages/transaction/transaction-importer.js +0 -99
  192. package/dist-client/pages/transaction/transaction-importer.js.map +0 -1
  193. package/dist-client/pages/transaction/transaction-list-page.d.ts +0 -57
  194. package/dist-client/pages/transaction/transaction-list-page.js +0 -280
  195. package/dist-client/pages/transaction/transaction-list-page.js.map +0 -1
  196. package/dist-server/controllers/index.d.ts +0 -1
  197. package/dist-server/controllers/index.js +0 -5
  198. package/dist-server/controllers/index.js.map +0 -1
  199. package/dist-server/controllers/summary-statements.d.ts +0 -4
  200. package/dist-server/controllers/summary-statements.js +0 -149
  201. package/dist-server/controllers/summary-statements.js.map +0 -1
  202. package/dist-server/migrations/1725201567284-seed-country-codes.d.ts +0 -5
  203. package/dist-server/migrations/1725201567284-seed-country-codes.js +0 -255
  204. package/dist-server/migrations/1725201567284-seed-country-codes.js.map +0 -1
  205. package/dist-server/service/financial-statement/financial-statement-line-item.d.ts +0 -19
  206. package/dist-server/service/financial-statement/financial-statement-line-item.js +0 -95
  207. package/dist-server/service/financial-statement/financial-statement-line-item.js.map +0 -1
  208. package/dist-server/service/financial-statement/financial-statement-type.d.ts +0 -20
  209. package/dist-server/service/financial-statement/financial-statement-type.js +0 -77
  210. package/dist-server/service/financial-statement/financial-statement-type.js.map +0 -1
  211. package/dist-server/service/income-statement/event-subscriber.d.ts +0 -7
  212. package/dist-server/service/income-statement/event-subscriber.js +0 -21
  213. package/dist-server/service/income-statement/event-subscriber.js.map +0 -1
  214. package/dist-server/service/income-statement/income-statement-history.d.ts +0 -28
  215. package/dist-server/service/income-statement/income-statement-history.js +0 -146
  216. package/dist-server/service/income-statement/income-statement-history.js.map +0 -1
  217. package/dist-server/service/income-statement/income-statement-line-item.d.ts +0 -19
  218. package/dist-server/service/income-statement/income-statement-line-item.js +0 -97
  219. package/dist-server/service/income-statement/income-statement-line-item.js.map +0 -1
  220. package/dist-server/service/income-statement/income-statement-mutation.d.ts +0 -10
  221. package/dist-server/service/income-statement/income-statement-mutation.js +0 -159
  222. package/dist-server/service/income-statement/income-statement-mutation.js.map +0 -1
  223. package/dist-server/service/income-statement/income-statement-query.d.ts +0 -11
  224. package/dist-server/service/income-statement/income-statement-query.js +0 -81
  225. package/dist-server/service/income-statement/income-statement-query.js.map +0 -1
  226. package/dist-server/service/income-statement/income-statement-type.d.ts +0 -20
  227. package/dist-server/service/income-statement/income-statement-type.js +0 -77
  228. package/dist-server/service/income-statement/income-statement-type.js.map +0 -1
  229. package/dist-server/service/income-statement/income-statement.d.ts +0 -28
  230. package/dist-server/service/income-statement/income-statement.js +0 -137
  231. package/dist-server/service/income-statement/income-statement.js.map +0 -1
  232. package/dist-server/service/income-statement/index.d.ts +0 -8
  233. package/dist-server/service/income-statement/index.js +0 -13
  234. package/dist-server/service/income-statement/index.js.map +0 -1
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkPaymentsWithin = checkPaymentsWithin;
4
+ exports.savePayments = savePayments;
5
+ const typeorm_1 = require("typeorm");
6
+ const shell_1 = require("@things-factory/shell");
7
+ const transaction_1 = require("../transaction/transaction");
8
+ const payment_1 = require("./payment");
9
+ const payment_targets_1 = require("./payment-targets");
10
+ /** Amounts are decimals; a sum within half a cent of the transaction is the transaction. */
11
+ const CENT = 0.005;
12
+ /**
13
+ * Within one purpose a transaction pays no more than itself. Run after its payments or its amount change.
14
+ */
15
+ async function checkPaymentsWithin(tx, domain, transactionIds) {
16
+ const ids = [...new Set(transactionIds)];
17
+ if (!ids.length)
18
+ return;
19
+ const transactions = await tx
20
+ .getRepository(transaction_1.Transaction)
21
+ .find({ where: { domain: { id: domain.id }, id: (0, typeorm_1.In)(ids) }, select: ['id', 'amount'] });
22
+ const payments = await tx
23
+ .getRepository(payment_1.Payment)
24
+ .find({ where: { domain: { id: domain.id }, transaction: { id: (0, typeorm_1.In)(ids) } }, relations: ['transaction'] });
25
+ const paid = new Map();
26
+ for (const payment of payments) {
27
+ const key = `${payment.transaction.id}|${payment.purpose}`;
28
+ paid.set(key, (paid.get(key) ?? 0) + Number(payment.amount));
29
+ }
30
+ for (const transaction of transactions) {
31
+ for (const [key, sum] of paid) {
32
+ const [id, purpose] = key.split('|');
33
+ if (id !== transaction.id)
34
+ continue;
35
+ const amount = Math.abs(Number(transaction.amount));
36
+ if (sum > amount + CENT) {
37
+ throw new shell_1.Refusal('payment-over-transaction', { purpose, paid: sum, amount }, `${purpose}: ${sum} put on a transaction of ${amount}`);
38
+ }
39
+ }
40
+ }
41
+ }
42
+ /** A patch as the row it writes: the target kind known, the amount more than zero, the purpose the kind's. */
43
+ function rowOf(patch, isNew) {
44
+ const row = {};
45
+ const transactionId = patch.transaction?.id;
46
+ if (isNew && !transactionId)
47
+ throw new shell_1.Refusal('payment-transaction-required', {}, 'a payment needs the transaction it is a part of');
48
+ if (transactionId)
49
+ row.transactionId = transactionId;
50
+ if (patch.targetType !== undefined || isNew) {
51
+ const target = (0, payment_targets_1.paymentTargetOf)(String(patch.targetType ?? ''));
52
+ if (!target)
53
+ throw new shell_1.Refusal('payment-target-unknown', { targetType: patch.targetType }, `'${patch.targetType}' is not a kind of target any module registered`);
54
+ row.targetType = patch.targetType;
55
+ row.purpose = target.purpose;
56
+ }
57
+ if (patch.targetId !== undefined || isNew) {
58
+ if (!patch.targetId)
59
+ throw new shell_1.Refusal('payment-target-required', {}, 'a payment needs what it paid');
60
+ row.targetId = patch.targetId;
61
+ }
62
+ if (patch.amount !== undefined || isNew) {
63
+ const amount = Number(patch.amount);
64
+ if (!(amount > 0))
65
+ throw new shell_1.Refusal('payment-amount-not-positive', {}, 'amount: must be more than zero');
66
+ row.amount = amount;
67
+ }
68
+ if (patch.method !== undefined)
69
+ row.method = patch.method ?? payment_1.PaymentMethod.PERSON;
70
+ if (patch.basis !== undefined)
71
+ row.basis = patch.basis || null;
72
+ if (patch.notes !== undefined)
73
+ row.notes = patch.notes || null;
74
+ return row;
75
+ }
76
+ /**
77
+ * Apply rows to a domain's payments: `+` (or no id) adds, `M` changes, `-` deletes (softly). Then the general rule
78
+ * (§`checkPaymentsWithin`) and each touched kind's own rules run, in the same database transaction.
79
+ */
80
+ async function savePayments(tx, domain, user, patches) {
81
+ const repo = tx.getRepository(payment_1.Payment);
82
+ const transactions = tx.getRepository(transaction_1.Transaction);
83
+ const touched = new Map();
84
+ const touch = (payment) => {
85
+ const kind = touched.get(payment.targetType) ?? { targetIds: new Set(), transactionIds: new Set() };
86
+ kind.targetIds.add(payment.targetId);
87
+ if (payment.transactionId)
88
+ kind.transactionIds.add(payment.transactionId);
89
+ touched.set(payment.targetType, kind);
90
+ };
91
+ const deletes = patches.filter(one => one.cuFlag === '-' && one.id).map(one => one.id);
92
+ if (deletes.length) {
93
+ const owned = await repo.find({ where: { domain: { id: domain.id }, id: (0, typeorm_1.In)(deletes) }, relations: ['transaction'] });
94
+ if (owned.length !== new Set(deletes).size)
95
+ throw new shell_1.Refusal('payment-not-found', {}, 'a payment was not found - reload and try again');
96
+ for (const one of owned)
97
+ touch({ ...one, transactionId: one.transaction.id });
98
+ await repo.softDelete({ id: (0, typeorm_1.In)(deletes) });
99
+ }
100
+ const saved = [];
101
+ for (const patch of patches.filter(one => one.cuFlag !== '-')) {
102
+ const isNew = !patch.id || patch.cuFlag === '+';
103
+ const { transactionId, ...row } = rowOf(patch, isNew);
104
+ const current = isNew
105
+ ? undefined
106
+ : await repo.findOne({ where: { domain: { id: domain.id }, id: patch.id }, relations: ['transaction'] });
107
+ if (!isNew && !current)
108
+ throw new shell_1.Refusal('payment-not-found', {}, 'a payment was not found - reload and try again');
109
+ const transactionOf = transactionId ?? current.transaction.id;
110
+ const transaction = await transactions.findOne({ where: { domain: { id: domain.id }, id: transactionOf } });
111
+ if (!transaction)
112
+ throw new shell_1.Refusal('payment-transaction-not-found', {}, 'the transaction was not found - reload and try again');
113
+ const targetType = row.targetType ?? current.targetType;
114
+ const targetId = row.targetId ?? current.targetId;
115
+ const twin = await repo.findOne({
116
+ where: { domain: { id: domain.id }, transaction: { id: transaction.id }, targetType, targetId }
117
+ });
118
+ if (twin && twin.id !== current?.id)
119
+ throw new shell_1.Refusal('payment-twice', { targetType, targetId }, 'the transaction already pays this - change that payment instead');
120
+ if (current)
121
+ touch({ ...current, transactionId: current.transaction.id });
122
+ const written = await repo.save({
123
+ ...(current ?? { domain, creator: user }),
124
+ ...row,
125
+ transaction,
126
+ updater: user
127
+ });
128
+ touch({ targetType: written.targetType, targetId: written.targetId, transactionId: transaction.id });
129
+ saved.push(written);
130
+ }
131
+ await checkPaymentsWithin(tx, domain, [...touched.values()].flatMap(kind => [...kind.transactionIds]));
132
+ for (const [targetType, kind] of touched) {
133
+ await (0, payment_targets_1.paymentTargetOf)(targetType)?.validate?.(tx, domain, {
134
+ targetIds: [...kind.targetIds],
135
+ transactionIds: [...kind.transactionIds]
136
+ });
137
+ }
138
+ return saved;
139
+ }
140
+ //# sourceMappingURL=payment-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment-service.js","sourceRoot":"","sources":["../../../server/service/payment/payment-service.ts"],"names":[],"mappings":";;AAeA,kDAiCC;AAwCD,oCA2EC;AAnKD,qCAA2C;AAE3C,iDAA+C;AAE/C,4DAAwD;AACxD,uCAAkD;AAClD,uDAAmD;AAGnD,4FAA4F;AAC5F,MAAM,IAAI,GAAG,KAAK,CAAA;AAElB;;GAEG;AACI,KAAK,UAAU,mBAAmB,CACvC,EAAiB,EACjB,MAAsB,EACtB,cAAwB;IAExB,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC,CAAA;IACxC,IAAI,CAAC,GAAG,CAAC,MAAM;QAAE,OAAM;IAEvB,MAAM,YAAY,GAAG,MAAM,EAAE;SAC1B,aAAa,CAAC,yBAAW,CAAC;SAC1B,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,IAAA,YAAE,EAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAA;IACxF,MAAM,QAAQ,GA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usal } from '@things-factory/shell'\n\nimport { Transaction } from '../transaction/transaction'\nimport { Payment, PaymentMethod } from './payment'\nimport { paymentTargetOf } from './payment-targets'\nimport { PaymentPatch } from './payment-type'\n\n/** Amounts are decimals; a sum within half a cent of the transaction is the transaction. */\nconst CENT = 0.005\n\n/**\n * Within one purpose a transaction pays no more than itself. Run after its payments or its amount change.\n */\nexport async function checkPaymentsWithin(\n tx: EntityManager,\n domain: { id: string },\n transactionIds: string[]\n): Promise<void> {\n const ids = [...new Set(transactionIds)]\n if (!ids.length) return\n\n const transactions = await tx\n .getRepository(Transaction)\n .find({ where: { domain: { id: domain.id }, id: In(ids) }, select: ['id', 'amount'] })\n const payments = await tx\n .getRepository(Payment)\n .find({ where: { domain: { id: domain.id }, transaction: { id: In(ids) } }, relations: ['transaction'] })\n const paid = new Map<string, number>()\n for (const payment of payments) {\n const key = `${payment.transaction.id}|${payment.purpose}`\n paid.set(key, (paid.get(key) ?? 0) + Number(payment.amount))\n }\n for (const transaction of transactions) {\n for (const [key, sum] of paid) {\n const [id, purpose] = key.split('|')\n if (id !== transaction.id) continue\n const amount = Math.abs(Number(transaction.amount))\n if (sum > amount + CENT) {\n throw new Refusal(\n 'payment-over-transaction',\n { purpose, paid: sum, amount },\n `${purpose}: ${sum} put on a transaction of ${amount}`\n )\n }\n }\n }\n}\n\n/** A patch as the row it writes: the target kind known, the amount more than zero, the purpose the kind's. */\nfunction rowOf(patch: PaymentPatch, isNew: boolean): Partial<Payment> & { transactionId?: string } {\n const row: Record<string, any> = {}\n const transactionId = patch.transaction?.id\n if (isNew && !transactionId)\n throw new Refusal('payment-transaction-required', {}, 'a payment needs the transaction it is a part of')\n if (transactionId) row.transactionId = transactionId\n\n if (patch.targetType !== undefined || isNew) {\n const target = paymentTargetOf(String(patch.targetType ?? ''))\n if (!target)\n throw new Refusal(\n 'payment-target-unknown',\n { targetType: patch.targetType },\n `'${patch.targetType}' is not a kind of target any module registered`\n )\n row.targetType = patch.targetType\n row.purpose = target.purpose\n }\n if (patch.targetId !== undefined || isNew) {\n if (!patch.targetId) throw new Refusal('payment-target-required', {}, 'a payment needs what it paid')\n row.targetId = patch.targetId\n }\n if (patch.amount !== undefined || isNew) {\n const amount = Number(patch.amount)\n if (!(amount > 0)) throw new Refusal('payment-amount-not-positive', {}, 'amount: must be more than zero')\n row.amount = amount\n }\n if (patch.method !== undefined) row.method = patch.method ?? PaymentMethod.PERSON\n if (patch.basis !== undefined) row.basis = patch.basis || null\n if (patch.notes !== undefined) row.notes = patch.notes || null\n return row\n}\n\n/**\n * Apply rows to a domain's payments: `+` (or no id) adds, `M` changes, `-` deletes (softly). Then the general rule\n * (§`checkPaymentsWithin`) and each touched kind's own rules run, in the same database transaction.\n */\nexport async function savePayments(\n tx: EntityManager,\n domain: { id: string },\n user: any,\n patches: PaymentPatch[]\n): Promise<Payment[]> {\n const repo = tx.getRepository(Payment)\n const transactions = tx.getRepository(Transaction)\n const touched = new Map<string, { targetIds: Set<string>; transactionIds: Set<string> }>()\n const touch = (payment: { targetType: string; targetId: string; transactionId?: string }) => {\n const kind = touched.get(payment.targetType) ?? { targetIds: new Set<string>(), transactionIds: new Set<string>() }\n kind.targetIds.add(payment.targetId)\n if (payment.transactionId) kind.transactionIds.add(payment.transactionId)\n touched.set(payment.targetType, kind)\n }\n\n const deletes = patches.filter(one => one.cuFlag === '-' && one.id).map(one => one.id!)\n if (deletes.length) {\n const owned = await repo.find({ where: { domain: { id: domain.id }, id: In(deletes) }, relations: ['transaction'] })\n if (owned.length !== new Set(deletes).size)\n throw new Refusal('payment-not-found', {}, 'a payment was not found - reload and try again')\n for (const one of owned) touch({ ...one, transactionId: one.transaction.id })\n await repo.softDelete({ id: In(deletes) })\n }\n\n const saved: Payment[] = []\n for (const patch of patches.filter(one => one.cuFlag !== '-')) {\n const isNew = !patch.id || patch.cuFlag === '+'\n const { transactionId, ...row } = rowOf(patch, isNew)\n const current = isNew\n ? undefined\n : await repo.findOne({ where: { domain: { id: domain.id }, id: patch.id }, relations: ['transaction'] })\n if (!isNew && !current) throw new Refusal('payment-not-found', {}, 'a payment was not found - reload and try again')\n\n const transactionOf = transactionId ?? current!.transaction.id\n const transaction = await transactions.findOne({ where: { domain: { id: domain.id }, id: transactionOf } })\n if (!transaction)\n throw new Refusal('payment-transaction-not-found', {}, 'the transaction was not found - reload and try again')\n\n const targetType = row.targetType ?? current!.targetType\n const targetId = row.targetId ?? current!.targetId\n const twin = await repo.findOne({\n where: { domain: { id: domain.id }, transaction: { id: transaction.id }, targetType, targetId }\n })\n if (twin && twin.id !== current?.id)\n throw new Refusal(\n 'payment-twice',\n { targetType, targetId },\n 'the transaction already pays this - change that payment instead'\n )\n\n if (current) touch({ ...current, transactionId: current.transaction.id })\n const written = await repo.save({\n ...(current ?? { domain, creator: user }),\n ...row,\n transaction,\n updater: user\n } as Payment)\n touch({ targetType: written.targetType, targetId: written.targetId, transactionId: transaction.id })\n saved.push(written)\n }\n\n await checkPaymentsWithin(\n tx,\n domain,\n [...touched.values()].flatMap(kind => [...kind.transactionIds])\n )\n for (const [targetType, kind] of touched) {\n await paymentTargetOf(targetType)?.validate?.(tx, domain, {\n targetIds: [...kind.targetIds],\n transactionIds: [...kind.transactionIds]\n })\n }\n\n return saved\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import { EntityManager } from 'typeorm';
2
+ import { PaymentPurpose } from './payment';
3
+ /**
4
+ * The kinds of thing a transaction can pay, registered by the module that owns them.
5
+ *
6
+ * accounting keeps the general rules - the target kind is known, a transaction pays no more than itself within one
7
+ * purpose. What a target may take (a contract round's capacity, one VAT period per withdrawal) is the owner's rule,
8
+ * run in the same database transaction after the payments are written.
9
+ */
10
+ export interface PaymentTarget {
11
+ /** What a payment on this kind tells of its transaction. */
12
+ purpose: PaymentPurpose;
13
+ /** What people call each target - 「H2026021 3차」 - for the screens that list what a transaction paid. */
14
+ label?: (tx: EntityManager, domain: {
15
+ id: string;
16
+ }, targetIds: string[]) => Promise<Map<string, string>>;
17
+ /**
18
+ * The owner's rules on the payments of its targets, given the targets and transactions a save touched. Throw a
19
+ * `Refusal` to refuse the save.
20
+ */
21
+ validate?: (tx: EntityManager, domain: {
22
+ id: string;
23
+ }, touched: {
24
+ targetIds: string[];
25
+ transactionIds: string[];
26
+ }) => Promise<void>;
27
+ }
28
+ /** Register a kind of target. A kind is registered once; registering it again is a mistake in the app. */
29
+ export declare function registerPaymentTarget(targetType: string, target: PaymentTarget): void;
30
+ export declare function paymentTargetOf(targetType: string): PaymentTarget | undefined;
31
+ export declare function registeredPaymentTargets(): string[];
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerPaymentTarget = registerPaymentTarget;
4
+ exports.paymentTargetOf = paymentTargetOf;
5
+ exports.registeredPaymentTargets = registeredPaymentTargets;
6
+ const targets = new Map();
7
+ /** Register a kind of target. A kind is registered once; registering it again is a mistake in the app. */
8
+ function registerPaymentTarget(targetType, target) {
9
+ if (targets.has(targetType))
10
+ throw new Error(`payment target '${targetType}' is registered twice`);
11
+ targets.set(targetType, target);
12
+ }
13
+ function paymentTargetOf(targetType) {
14
+ return targets.get(targetType);
15
+ }
16
+ function registeredPaymentTargets() {
17
+ return [...targets.keys()];
18
+ }
19
+ //# sourceMappingURL=payment-targets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment-targets.js","sourceRoot":"","sources":["../../../server/service/payment/payment-targets.ts"],"names":[],"mappings":";;AA8BA,sDAGC;AAED,0CAEC;AAED,4DAEC;AAdD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAA;AAEhD,0GAA0G;AAC1G,SAAgB,qBAAqB,CAAC,UAAkB,EAAE,MAAqB;IAC7E,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,UAAU,uBAAuB,CAAC,CAAA;IAClG,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;AACjC,CAAC;AAED,SAAgB,eAAe,CAAC,UAAkB;IAChD,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;AAChC,CAAC;AAED,SAAgB,wBAAwB;IACtC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;AAC5B,CAAC","sourcesContent":["import { EntityManager } from 'typeorm'\n\nimport { PaymentPurpose } from './payment'\n\n/**\n * The kinds of thing a transaction can pay, registered by the module that owns them.\n *\n * accounting keeps the general rules - the target kind is known, a transaction pays no more than itself within one\n * purpose. What a target may take (a contract round's capacity, one VAT period per withdrawal) is the owner's rule,\n * run in the same database transaction after the payments are written.\n */\nexport interface PaymentTarget {\n /** What a payment on this kind tells of its transaction. */\n purpose: PaymentPurpose\n /** What people call each target - 「H2026021 3차」 - for the screens that list what a transaction paid. */\n label?: (tx: EntityManager, domain: { id: string }, targetIds: string[]) => Promise<Map<string, string>>\n /**\n * The owner's rules on the payments of its targets, given the targets and transactions a save touched. Throw a\n * `Refusal` to refuse the save.\n */\n validate?: (\n tx: EntityManager,\n domain: { id: string },\n touched: { targetIds: string[]; transactionIds: string[] }\n ) => Promise<void>\n}\n\nconst targets = new Map<string, PaymentTarget>()\n\n/** Register a kind of target. A kind is registered once; registering it again is a mistake in the app. */\nexport function registerPaymentTarget(targetType: string, target: PaymentTarget): void {\n if (targets.has(targetType)) throw new Error(`payment target '${targetType}' is registered twice`)\n targets.set(targetType, target)\n}\n\nexport function paymentTargetOf(targetType: string): PaymentTarget | undefined {\n return targets.get(targetType)\n}\n\nexport function registeredPaymentTargets(): string[] {\n return [...targets.keys()]\n}\n"]}
@@ -1,27 +1,23 @@
1
1
  import { ObjectRef } from '@things-factory/shell';
2
- import { Payment, PaymentDirection, PaymentType } from './payment';
2
+ import { Payment, PaymentMethod } from './payment';
3
3
  export declare class NewPayment {
4
4
  transaction: ObjectRef;
5
- currency?: string;
5
+ targetType: string;
6
+ targetId: string;
6
7
  amount: number;
7
- paidAt: Date;
8
- direction: PaymentDirection;
9
- paymentType: PaymentType;
10
- sourceBankAccount?: ObjectRef;
11
- destinationBankAccount?: ObjectRef;
12
- note?: string;
8
+ method?: PaymentMethod;
9
+ basis?: string;
10
+ notes?: string;
13
11
  }
14
12
  export declare class PaymentPatch {
15
13
  id?: string;
16
- transaction: ObjectRef;
17
- currency?: string;
18
- amount: number;
19
- paidAt: Date;
20
- direction: PaymentDirection;
21
- paymentType: PaymentType;
22
- sourceBankAccount?: ObjectRef;
23
- destinationBankAccount?: ObjectRef;
24
- note?: string;
14
+ transaction?: ObjectRef;
15
+ targetType?: string;
16
+ targetId?: string;
17
+ amount?: number;
18
+ method?: PaymentMethod;
19
+ basis?: string;
20
+ notes?: string;
25
21
  cuFlag?: string;
26
22
  }
27
23
  export declare class PaymentList {
@@ -9,106 +9,90 @@ let NewPayment = class NewPayment {
9
9
  };
10
10
  exports.NewPayment = NewPayment;
11
11
  tslib_1.__decorate([
12
- (0, type_graphql_1.Field)(type => shell_1.ObjectRef),
12
+ (0, type_graphql_1.Field)(type => shell_1.ObjectRef, { description: 'The transaction a part of which this is' }),
13
13
  tslib_1.__metadata("design:type", shell_1.ObjectRef)
14
14
  ], NewPayment.prototype, "transaction", void 0);
15
15
  tslib_1.__decorate([
16
- (0, type_graphql_1.Field)({ nullable: true }),
16
+ (0, type_graphql_1.Field)({ description: 'The kind of what was paid, as registered' }),
17
17
  tslib_1.__metadata("design:type", String)
18
- ], NewPayment.prototype, "currency", void 0);
18
+ ], NewPayment.prototype, "targetType", void 0);
19
19
  tslib_1.__decorate([
20
- (0, type_graphql_1.Field)({ nullable: false }),
20
+ (0, type_graphql_1.Field)({ description: 'The id of what was paid' }),
21
+ tslib_1.__metadata("design:type", String)
22
+ ], NewPayment.prototype, "targetId", void 0);
23
+ tslib_1.__decorate([
24
+ (0, type_graphql_1.Field)(type => type_graphql_1.Float, { description: 'The part of the transaction put on the target' }),
21
25
  tslib_1.__metadata("design:type", Number)
22
26
  ], NewPayment.prototype, "amount", void 0);
23
27
  tslib_1.__decorate([
24
- (0, type_graphql_1.Field)({ nullable: false }),
25
- tslib_1.__metadata("design:type", Date)
26
- ], NewPayment.prototype, "paidAt", void 0);
27
- tslib_1.__decorate([
28
- (0, type_graphql_1.Field)(type => payment_1.PaymentDirection),
28
+ (0, type_graphql_1.Field)(type => payment_1.PaymentMethod, { nullable: true, description: 'Who made the link - a person when not given' }),
29
29
  tslib_1.__metadata("design:type", String)
30
- ], NewPayment.prototype, "direction", void 0);
30
+ ], NewPayment.prototype, "method", void 0);
31
31
  tslib_1.__decorate([
32
- (0, type_graphql_1.Field)(type => payment_1.PaymentType, { description: 'Type of the payment' }),
32
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Why a rule made the link' }),
33
33
  tslib_1.__metadata("design:type", String)
34
- ], NewPayment.prototype, "paymentType", void 0);
35
- tslib_1.__decorate([
36
- (0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'Source bank account for the payment' }),
37
- tslib_1.__metadata("design:type", shell_1.ObjectRef)
38
- ], NewPayment.prototype, "sourceBankAccount", void 0);
39
- tslib_1.__decorate([
40
- (0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'Destination bank account for the payment' }),
41
- tslib_1.__metadata("design:type", shell_1.ObjectRef)
42
- ], NewPayment.prototype, "destinationBankAccount", void 0);
34
+ ], NewPayment.prototype, "basis", void 0);
43
35
  tslib_1.__decorate([
44
- (0, type_graphql_1.Field)({ nullable: true }),
36
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Notes' }),
45
37
  tslib_1.__metadata("design:type", String)
46
- ], NewPayment.prototype, "note", void 0);
38
+ ], NewPayment.prototype, "notes", void 0);
47
39
  exports.NewPayment = NewPayment = tslib_1.__decorate([
48
- (0, type_graphql_1.InputType)()
40
+ (0, type_graphql_1.InputType)({ description: 'A new part of a transaction put on what it paid' })
49
41
  ], NewPayment);
50
42
  let PaymentPatch = class PaymentPatch {
51
43
  };
52
44
  exports.PaymentPatch = PaymentPatch;
53
45
  tslib_1.__decorate([
54
- (0, type_graphql_1.Field)(type => type_graphql_1.ID, { nullable: true }),
46
+ (0, type_graphql_1.Field)(type => type_graphql_1.ID, { nullable: true, description: 'The payment to change or delete' }),
55
47
  tslib_1.__metadata("design:type", String)
56
48
  ], PaymentPatch.prototype, "id", void 0);
57
49
  tslib_1.__decorate([
58
- (0, type_graphql_1.Field)(type => shell_1.ObjectRef),
50
+ (0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'The transaction a part of which this is' }),
59
51
  tslib_1.__metadata("design:type", shell_1.ObjectRef)
60
52
  ], PaymentPatch.prototype, "transaction", void 0);
61
53
  tslib_1.__decorate([
62
- (0, type_graphql_1.Field)({ nullable: true }),
54
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The kind of what was paid, as registered' }),
63
55
  tslib_1.__metadata("design:type", String)
64
- ], PaymentPatch.prototype, "currency", void 0);
56
+ ], PaymentPatch.prototype, "targetType", void 0);
65
57
  tslib_1.__decorate([
66
- (0, type_graphql_1.Field)({ nullable: false }),
58
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The id of what was paid' }),
59
+ tslib_1.__metadata("design:type", String)
60
+ ], PaymentPatch.prototype, "targetId", void 0);
61
+ tslib_1.__decorate([
62
+ (0, type_graphql_1.Field)(type => type_graphql_1.Float, { nullable: true, description: 'The part of the transaction put on the target' }),
67
63
  tslib_1.__metadata("design:type", Number)
68
64
  ], PaymentPatch.prototype, "amount", void 0);
69
65
  tslib_1.__decorate([
70
- (0, type_graphql_1.Field)({ nullable: false }),
71
- tslib_1.__metadata("design:type", Date)
72
- ], PaymentPatch.prototype, "paidAt", void 0);
73
- tslib_1.__decorate([
74
- (0, type_graphql_1.Field)(type => payment_1.PaymentDirection),
66
+ (0, type_graphql_1.Field)(type => payment_1.PaymentMethod, { nullable: true, description: 'Who made the link' }),
75
67
  tslib_1.__metadata("design:type", String)
76
- ], PaymentPatch.prototype, "direction", void 0);
68
+ ], PaymentPatch.prototype, "method", void 0);
77
69
  tslib_1.__decorate([
78
- (0, type_graphql_1.Field)(type => payment_1.PaymentType, { description: 'Type of the payment' }),
70
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Why a rule made the link' }),
79
71
  tslib_1.__metadata("design:type", String)
80
- ], PaymentPatch.prototype, "paymentType", void 0);
81
- tslib_1.__decorate([
82
- (0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'Source bank account for the payment' }),
83
- tslib_1.__metadata("design:type", shell_1.ObjectRef)
84
- ], PaymentPatch.prototype, "sourceBankAccount", void 0);
85
- tslib_1.__decorate([
86
- (0, type_graphql_1.Field)(type => shell_1.ObjectRef, { nullable: true, description: 'Destination bank account for the payment' }),
87
- tslib_1.__metadata("design:type", shell_1.ObjectRef)
88
- ], PaymentPatch.prototype, "destinationBankAccount", void 0);
72
+ ], PaymentPatch.prototype, "basis", void 0);
89
73
  tslib_1.__decorate([
90
- (0, type_graphql_1.Field)({ nullable: true }),
74
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Notes' }),
91
75
  tslib_1.__metadata("design:type", String)
92
- ], PaymentPatch.prototype, "note", void 0);
76
+ ], PaymentPatch.prototype, "notes", void 0);
93
77
  tslib_1.__decorate([
94
- (0, type_graphql_1.Field)({ nullable: true }),
78
+ (0, type_graphql_1.Field)({ nullable: true, description: '+ adds, M changes, - deletes' }),
95
79
  tslib_1.__metadata("design:type", String)
96
80
  ], PaymentPatch.prototype, "cuFlag", void 0);
97
81
  exports.PaymentPatch = PaymentPatch = tslib_1.__decorate([
98
- (0, type_graphql_1.InputType)()
82
+ (0, type_graphql_1.InputType)({ description: 'A change to a payment, or a grid row: cuFlag + adds, M changes, - deletes' })
99
83
  ], PaymentPatch);
100
84
  let PaymentList = class PaymentList {
101
85
  };
102
86
  exports.PaymentList = PaymentList;
103
87
  tslib_1.__decorate([
104
- (0, type_graphql_1.Field)(type => [payment_1.Payment]),
88
+ (0, type_graphql_1.Field)(type => [payment_1.Payment], { description: 'The payments on this page' }),
105
89
  tslib_1.__metadata("design:type", Array)
106
90
  ], PaymentList.prototype, "items", void 0);
107
91
  tslib_1.__decorate([
108
- (0, type_graphql_1.Field)(type => type_graphql_1.Int),
92
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int, { description: 'How many there are in all' }),
109
93
  tslib_1.__metadata("design:type", Number)
110
94
  ], PaymentList.prototype, "total", void 0);
111
95
  exports.PaymentList = PaymentList = tslib_1.__decorate([
112
- (0, type_graphql_1.ObjectType)()
96
+ (0, type_graphql_1.ObjectType)({ description: 'A page of payments' })
113
97
  ], PaymentList);
114
98
  //# sourceMappingURL=payment-type.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"payment-type.js","sourceRoot":"","sources":["../../../server/service/payment/payment-type.ts"],"names":[],"mappings":";;;;AAEA,+CAAsF;AAEtF,iDAA+D;AAE/D,uCAAkE;AAG3D,IAAM,UAAU,GAAhB,MAAM,UAAU;CA2BtB,CAAA;AA3BY,gCAAU;AAErB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAS,CAAC;sCACZ,iBAAS;+CAAA;AAGtB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;4CACT;AAGjB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;;0CACb;AAGd;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;sCACnB,IAAI;0CAAA;AAGZ;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,0BAAgB,CAAC;;6CACL;AAG3B;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,qBAAW,EAAE,EAAE,WAAW,EAAE,qBAAqB,EAAE,CAAC;;+CAC3C;AAGxB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAS,EAAE,EAAE,QAAQ,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C,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAS,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,0CAA0C,EAAE,CAAC;sCAC7E,iBAAS;4DAAA;AAGlC;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;0CACb;AAGb;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;4CACX;uBAhCJ,YAAY;IADxB,IAAA,wBAAS,GAAE;GACC,YAAY,CAiCxB;AAGM,IAAM,WAAW,GAAjB,MAAM,WAAW;CAMvB,CAAA;AANY,kCAAW;AAEtB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,iBAAO,CAAC,CAAC;;0CACT;AAGhB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,CAAC;;0CACN;sBALF,WAAW;IADvB,IAAA,yBAAU,GAAE;GACA,WAAW,CAMvB","sourcesContent":["import type { FileUpload } from 'graphql-upload/GraphQLUpload.js'\nimport GraphQLUpload from 'graphql-upload/GraphQLUpload.js'\nimport { ObjectType, Field, InputType, Int, ID, registerEnumType } from 'type-graphql'\n\nimport { ObjectRef, ScalarObject } from '@things-factory/shell'\n\nimport { Payment, PaymentDirection, PaymentType } from './payment'\n\n@InputType()\nexport class NewPayment {\n @Field(type => ObjectRef)\n transaction: ObjectRef\n\n @Field({ nullable: true })\n currency?: string\n\n @Field({ nullable: false })\n amount: number\n\n @Field({ nullable: false })\n paidAt: Date\n\n @Field(type => PaymentDirection)\n direction: PaymentDirection\n\n @Field(type => PaymentType, { description: 'Type of the payment' })\n paymentType: PaymentType // 결제 유형\n\n @Field(type => ObjectRef, { nullable: true, description: 'Source bank account for the payment' })\n sourceBankAccount?: ObjectRef\n\n @Field(type => ObjectRef, { nullable: true, description: 'Destination bank account for the payment' })\n destinationBankAccount?: ObjectRef\n\n @Field({ nullable: true })\n note?: string\n}\n\n@InputType()\nexport class PaymentPatch {\n @Field(type => ID, { nullable: true })\n id?: string\n\n @Field(type => ObjectRef)\n transaction: ObjectRef\n\n @Field({ nullable: true })\n currency?: string\n\n @Field({ nullable: false })\n amount: number\n\n @Field({ nullable: false })\n paidAt: Date\n\n @Field(type => PaymentDirection)\n direction: PaymentDirection\n\n @Field(type => PaymentType, { description: 'Type of the payment' })\n paymentType: PaymentType // 결제 유형\n\n @Field(type => ObjectRef, { nullable: true, description: 'Source bank account for the payment' })\n sourceBankAccount?: ObjectRef\n\n @Field(type => ObjectRef, { nullable: true, description: 'Destination bank account for the payment' })\n destinationBankAccount?: ObjectRef\n\n @Field({ nullable: true })\n note?: string\n\n @Field({ nullable: true })\n cuFlag?: string\n}\n\n@ObjectType()\nexport class PaymentList {\n @Field(type => [Payment])\n items: Payment[]\n\n @Field(type => Int)\n total: number\n}\n"]}
1
+ {"version":3,"file":"payment-type.js","sourceRoot":"","sources":["../../../server/service/payment/payment-type.ts"],"names":[],"mappings":";;;;AAAA,+CAA2E;AAE3E,iDAAiD;AAEjD,uCAAkD;AAG3C,IAAM,UAAU,GAAhB,MAAM,UAAU;CAqBtB,CAAA;AArBY,gCAAU;AAErB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAS,EAAE,EAAE,WAAW,EAAE,yCAAyC,EAAE,CAAC;sCACxE,iBAAS;+CAAA;AAGtB;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,0CAA0C,EAAE,CAAC;;8CACjD;AAGlB;IADC,IAAA,oBAAK,EAAC,EAAE,WAAW,EAAE,yBAAyB,EAAE,CAAC;;4CAClC;AAGhB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,oBAAK,EAAE,EAAE,WAAW,EAAE,+CAA+C,EAAE,CAAC;;0CACzE;AAGd;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,uBAAa,EAAE,EAAE,QAAQ,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K,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,0BAA0B,EAAE,CAAC;;2CACrD;AAGd;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;;2CAClC;AAGd;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,8BAA8B,EAAE,CAAC;;4CACxD;uBA1BJ,YAAY;IADxB,IAAA,wBAAS,EAAC,EAAE,WAAW,EAAE,2EAA2E,EAAE,CAAC;GAC3F,YAAY,CA2BxB;AAGM,IAAM,WAAW,GAAjB,MAAM,WAAW;CAMvB,CAAA;AANY,kCAAW;AAEtB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,iBAAO,CAAC,EAAE,EAAE,WAAW,EAAE,2BAA2B,EAAE,CAAC;;0CACvD;AAGhB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,EAAE,EAAE,WAAW,EAAE,2BAA2B,EAAE,CAAC;;0CACpD;sBALF,WAAW;IADvB,IAAA,yBAAU,EAAC,EAAE,WAAW,EAAE,oBAAoB,EAAE,CAAC;GACrC,WAAW,CAMvB","sourcesContent":["import { ObjectType, Field, Float, InputType, Int, ID } from 'type-graphql'\n\nimport { ObjectRef } from '@things-factory/shell'\n\nimport { Payment, PaymentMethod } from './payment'\n\n@InputType({ description: 'A new part of a transaction put on what it paid' })\nexport class NewPayment {\n @Field(type => ObjectRef, { description: 'The transaction a part of which this is' })\n transaction: ObjectRef\n\n @Field({ description: 'The kind of what was paid, as registered' })\n targetType: string\n\n @Field({ description: 'The id of what was paid' })\n targetId: string\n\n @Field(type => Float, { description: 'The part of the transaction put on the target' })\n amount: number\n\n @Field(type => PaymentMethod, { nullable: true, description: 'Who made the link - a person when not given' })\n method?: PaymentMethod\n\n @Field({ nullable: true, description: 'Why a rule made the link' })\n basis?: string\n\n @Field({ nullable: true, description: 'Notes' })\n notes?: string\n}\n\n@InputType({ description: 'A change to a payment, or a grid row: cuFlag + adds, M changes, - deletes' })\nexport class PaymentPatch {\n @Field(type => ID, { nullable: true, description: 'The payment to change or delete' })\n id?: string\n\n @Field(type => ObjectRef, { nullable: true, description: 'The transaction a part of which this is' })\n transaction?: ObjectRef\n\n @Field({ nullable: true, description: 'The kind of what was paid, as registered' })\n targetType?: string\n\n @Field({ nullable: true, description: 'The id of what was paid' })\n targetId?: string\n\n @Field(type => Float, { nullable: true, description: 'The part of the transaction put on the target' })\n amount?: number\n\n @Field(type => PaymentMethod, { nullable: true, description: 'Who made the link' })\n method?: PaymentMethod\n\n @Field({ nullable: true, description: 'Why a rule made the link' })\n basis?: string\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 payments' })\nexport class PaymentList {\n @Field(type => [Payment], { description: 'The payments on this page' })\n items: Payment[]\n\n @Field(type => Int, { description: 'How many there are in all' })\n total: number\n}\n"]}
@@ -1,37 +1,38 @@
1
1
  import { Domain } from '@things-factory/shell';
2
2
  import { User } from '@things-factory/auth-base';
3
3
  import { Transaction } from '../transaction/transaction';
4
- import { BankAccount } from '../bank-account/bank-account';
5
- export declare enum PaymentDirection {
6
- Incoming = "Incoming",// 수금
7
- Outgoing = "Outgoing"
4
+ export declare enum PaymentPurpose {
5
+ SETTLEMENT = "SETTLEMENT",
6
+ EVIDENCE = "EVIDENCE",
7
+ TRANSFER = "TRANSFER"
8
8
  }
9
- export declare enum PaymentType {
10
- Transfer = "Transfer",// 계좌 이체
11
- Cash = "Cash",// 현금
12
- CreditCard = "CreditCard",// 신용카드
13
- DebitCard = "DebitCard"
9
+ export declare enum PaymentMethod {
10
+ RULE = "RULE",
11
+ PERSON = "PERSON"
14
12
  }
13
+ /**
14
+ * What a transaction paid: a part of it, put on one target - a contract round, a tax invoice, a VAT period, the other
15
+ * line of a transfer between our own accounts. One transaction may pay several targets, and one target be paid by
16
+ * several transactions.
17
+ *
18
+ * The kinds of target are registered by the apps that own them (§`registerPaymentTarget`), each with its purpose.
19
+ * Within one purpose the payments of a transaction add up to no more than the transaction; across purposes the same
20
+ * money is told twice - a deposit settles a round and is evidenced by that round's tax invoice.
21
+ */
15
22
  export declare class Payment {
16
23
  readonly id: string;
17
24
  version?: number;
18
25
  domain?: Domain;
19
26
  domainId?: string;
20
27
  transaction: Transaction;
21
- transactionId: string;
22
- currency?: string;
28
+ transactionId?: string;
29
+ targetType: string;
30
+ targetId: string;
23
31
  amount: number;
24
- paymentType: PaymentType;
25
- sourceBankAccount?: BankAccount;
26
- sourceBankAccountId?: string;
27
- destinationBankAccount?: BankAccount;
28
- destinationBankAccountId?: string;
29
- year?: number;
30
- quarter?: number;
31
- month?: number;
32
- paidAt: Date;
33
- direction: PaymentDirection;
34
- note?: string;
32
+ purpose: PaymentPurpose;
33
+ method: PaymentMethod;
34
+ basis?: string;
35
+ notes?: string;
35
36
  createdAt?: Date;
36
37
  updatedAt?: Date;
37
38
  deletedAt?: Date;