@things-factory/accounting 8.0.0-beta.9 → 8.0.2

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 (196) hide show
  1. package/client/activities/activity-book-edit.ts +88 -0
  2. package/client/activities/activity-book-view.ts +88 -0
  3. package/client/activities/activity-expense-edit.ts +88 -0
  4. package/client/activities/activity-expense-view.ts +88 -0
  5. package/client/bootstrap.ts +10 -0
  6. package/client/components/accounting-category-selector.ts +136 -0
  7. package/client/components/accounting-category-view.ts +75 -0
  8. package/client/grist-editors/grist-editor-accounting-category-object.ts +83 -0
  9. package/client/grist-editors/grist-renderer-accounting-category-object.ts +13 -0
  10. package/client/index.ts +0 -0
  11. package/client/pages/account/account-importer.ts +97 -0
  12. package/client/pages/account/account-list-page.ts +364 -0
  13. package/client/pages/accounting-category/accounting-category-importer.ts +97 -0
  14. package/client/pages/accounting-category/accounting-category-list-page.ts +368 -0
  15. package/client/pages/accounting-category/accounting-category-tree-page.ts +338 -0
  16. package/client/pages/accounting-document/accounting-document-importer.ts +90 -0
  17. package/client/pages/accounting-document/accounting-document-list-page.ts +398 -0
  18. package/client/pages/financial-statement/financial-statement-importer.ts +97 -0
  19. package/client/pages/financial-statement/financial-statement-list-page.ts +338 -0
  20. package/client/pages/fiscal-month/fiscal-month-importer.ts +90 -0
  21. package/client/pages/fiscal-month/fiscal-month-list-page.ts +398 -0
  22. package/client/pages/fiscal-quarter/fiscal-quarter-importer.ts +90 -0
  23. package/client/pages/fiscal-quarter/fiscal-quarter-list-page.ts +398 -0
  24. package/client/pages/fiscal-year/fiscal-year-importer.ts +90 -0
  25. package/client/pages/fiscal-year/fiscal-year-list-page.ts +398 -0
  26. package/client/pages/income-statement/income-statement-importer.ts +97 -0
  27. package/client/pages/income-statement/income-statement-list-page.ts +338 -0
  28. package/client/pages/payment/payment-importer.ts +90 -0
  29. package/client/pages/payment/payment-list-page.ts +398 -0
  30. package/client/pages/transaction/transaction-importer.ts +97 -0
  31. package/client/pages/transaction/transaction-list-page.ts +338 -0
  32. package/client/route.ts +35 -0
  33. package/client/tsconfig.json +13 -0
  34. package/client/types/accounting-category.ts +23 -0
  35. package/client/types/index.ts +1 -0
  36. package/dist-client/pages/accounting-category/accounting-category-tree-page.js +1 -1
  37. package/dist-client/pages/accounting-category/accounting-category-tree-page.js.map +1 -1
  38. package/dist-client/tsconfig.tsbuildinfo +1 -1
  39. package/dist-server/service/index.d.ts +2 -3
  40. package/dist-server/service/index.js +0 -5
  41. package/dist-server/service/index.js.map +1 -1
  42. package/dist-server/service/payment/index.d.ts +2 -1
  43. package/dist-server/service/payment/payment-history.d.ts +1 -8
  44. package/dist-server/service/payment/payment-history.js +10 -41
  45. package/dist-server/service/payment/payment-history.js.map +1 -1
  46. package/dist-server/service/payment/payment-type.d.ts +1 -7
  47. package/dist-server/service/payment/payment-type.js +0 -24
  48. package/dist-server/service/payment/payment-type.js.map +1 -1
  49. package/dist-server/service/payment/payment.d.ts +0 -12
  50. package/dist-server/service/payment/payment.js +1 -36
  51. package/dist-server/service/payment/payment.js.map +1 -1
  52. package/dist-server/tsconfig.tsbuildinfo +1 -1
  53. package/package.json +7 -7
  54. package/server/activities/activity-book.ts +172 -0
  55. package/server/activities/activity-expense.ts +149 -0
  56. package/server/activities/index.ts +18 -0
  57. package/server/controllers/index.ts +1 -0
  58. package/server/controllers/summary-statements.ts +166 -0
  59. package/server/index.ts +6 -0
  60. package/server/middlewares/index.ts +3 -0
  61. package/server/migrations/1725200507196-seed-fiscal-entities.ts +106 -0
  62. package/server/migrations/1725201467183-seed-accounts.ts +339 -0
  63. package/server/migrations/index.ts +9 -0
  64. package/server/routes.ts +26 -0
  65. package/server/service/account/account-history.ts +117 -0
  66. package/server/service/account/account-mutation.ts +140 -0
  67. package/server/service/account/account-query.ts +51 -0
  68. package/server/service/account/account-type.ts +44 -0
  69. package/server/service/account/account.ts +97 -0
  70. package/server/service/account/event-subscriber.ts +17 -0
  71. package/server/service/account/index.ts +9 -0
  72. package/server/service/accounting-category/accounting-category-history.ts +129 -0
  73. package/server/service/accounting-category/accounting-category-mutation.ts +148 -0
  74. package/server/service/accounting-category/accounting-category-query.ts +74 -0
  75. package/server/service/accounting-category/accounting-category-type.ts +48 -0
  76. package/server/service/accounting-category/accounting-category.ts +100 -0
  77. package/server/service/accounting-category/event-subscriber.ts +20 -0
  78. package/server/service/accounting-category/index.ts +9 -0
  79. package/server/service/accounting-document/accounting-document-history.ts +123 -0
  80. package/server/service/accounting-document/accounting-document-mutation.ts +137 -0
  81. package/server/service/accounting-document/accounting-document-query.ts +48 -0
  82. package/server/service/accounting-document/accounting-document-type.ts +52 -0
  83. package/server/service/accounting-document/accounting-document.ts +93 -0
  84. package/server/service/accounting-document/event-subscriber.ts +17 -0
  85. package/server/service/accounting-document/index.ts +9 -0
  86. package/server/service/common-type.ts +12 -0
  87. package/server/service/financial-statement/event-subscriber.ts +17 -0
  88. package/server/service/financial-statement/financial-statement-history.ts +129 -0
  89. package/server/service/financial-statement/financial-statement-line-item.ts +82 -0
  90. package/server/service/financial-statement/financial-statement-mutation.ts +148 -0
  91. package/server/service/financial-statement/financial-statement-query.ts +53 -0
  92. package/server/service/financial-statement/financial-statement-type.ts +51 -0
  93. package/server/service/financial-statement/financial-statement.ts +116 -0
  94. package/server/service/financial-statement/index.ts +10 -0
  95. package/server/service/fiscal-month/fiscal-month-mutation.ts +145 -0
  96. package/server/service/fiscal-month/fiscal-month-query.ts +58 -0
  97. package/server/service/fiscal-month/fiscal-month-type.ts +66 -0
  98. package/server/service/fiscal-month/fiscal-month.ts +84 -0
  99. package/server/service/fiscal-month/index.ts +7 -0
  100. package/server/service/fiscal-quarter/fiscal-quarter-mutation.ts +148 -0
  101. package/server/service/fiscal-quarter/fiscal-quarter-query.ts +60 -0
  102. package/server/service/fiscal-quarter/fiscal-quarter-type.ts +60 -0
  103. package/server/service/fiscal-quarter/fiscal-quarter.ts +80 -0
  104. package/server/service/fiscal-quarter/index.ts +7 -0
  105. package/server/service/fiscal-year/fiscal-year-mutation.ts +145 -0
  106. package/server/service/fiscal-year/fiscal-year-query.ts +53 -0
  107. package/server/service/fiscal-year/fiscal-year-type.ts +54 -0
  108. package/server/service/fiscal-year/fiscal-year.ts +76 -0
  109. package/server/service/fiscal-year/index.ts +7 -0
  110. package/server/service/income-statement/event-subscriber.ts +17 -0
  111. package/server/service/income-statement/income-statement-history.ts +133 -0
  112. package/server/service/income-statement/income-statement-line-item.ts +84 -0
  113. package/server/service/income-statement/income-statement-mutation.ts +147 -0
  114. package/server/service/income-statement/income-statement-query.ts +50 -0
  115. package/server/service/income-statement/income-statement-type.ts +51 -0
  116. package/server/service/income-statement/income-statement.ts +120 -0
  117. package/server/service/income-statement/index.ts +10 -0
  118. package/server/service/index.ts +108 -0
  119. package/server/service/payment/event-subscriber.ts +17 -0
  120. package/server/service/payment/index.ts +9 -0
  121. package/server/service/payment/payment-history.ts +132 -0
  122. package/server/service/payment/payment-mutation.ts +139 -0
  123. package/server/service/payment/payment-query.ts +50 -0
  124. package/server/service/payment/payment-type.ts +64 -0
  125. package/server/service/payment/payment.ts +123 -0
  126. package/server/service/transaction/event-subscriber.ts +17 -0
  127. package/server/service/transaction/index.ts +9 -0
  128. package/server/service/transaction/transaction-history.ts +161 -0
  129. package/server/service/transaction/transaction-mutation.ts +146 -0
  130. package/server/service/transaction/transaction-query.ts +50 -0
  131. package/server/service/transaction/transaction-type.ts +48 -0
  132. package/server/service/transaction/transaction.ts +230 -0
  133. package/server/tsconfig.json +10 -0
  134. package/dist-client/pages/bank/bank-importer.d.ts +0 -23
  135. package/dist-client/pages/bank/bank-importer.js +0 -93
  136. package/dist-client/pages/bank/bank-importer.js.map +0 -1
  137. package/dist-client/pages/bank/bank-list-page.d.ts +0 -66
  138. package/dist-client/pages/bank/bank-list-page.js +0 -370
  139. package/dist-client/pages/bank/bank-list-page.js.map +0 -1
  140. package/dist-client/pages/bank-account/bank-account-importer.d.ts +0 -23
  141. package/dist-client/pages/bank-account/bank-account-importer.js +0 -93
  142. package/dist-client/pages/bank-account/bank-account-importer.js.map +0 -1
  143. package/dist-client/pages/bank-account/bank-account-list-page.d.ts +0 -66
  144. package/dist-client/pages/bank-account/bank-account-list-page.js +0 -370
  145. package/dist-client/pages/bank-account/bank-account-list-page.js.map +0 -1
  146. package/dist-client/pages/financial-institution/financial-institution-importer.d.ts +0 -23
  147. package/dist-client/pages/financial-institution/financial-institution-importer.js +0 -93
  148. package/dist-client/pages/financial-institution/financial-institution-importer.js.map +0 -1
  149. package/dist-client/pages/financial-institution/financial-institution-list-page.d.ts +0 -66
  150. package/dist-client/pages/financial-institution/financial-institution-list-page.js +0 -370
  151. package/dist-client/pages/financial-institution/financial-institution-list-page.js.map +0 -1
  152. package/dist-server/migrations/1725201567284-seed-country-codes.d.ts +0 -5
  153. package/dist-server/migrations/1725201567284-seed-country-codes.js +0 -248
  154. package/dist-server/migrations/1725201567284-seed-country-codes.js.map +0 -1
  155. package/dist-server/migrations/1725201667385-seed-financial-institutions.d.ts +0 -5
  156. package/dist-server/migrations/1725201667385-seed-financial-institutions.js +0 -348
  157. package/dist-server/migrations/1725201667385-seed-financial-institutions.js.map +0 -1
  158. package/dist-server/service/bank-account/bank-account-history.d.ts +0 -34
  159. package/dist-server/service/bank-account/bank-account-history.js +0 -172
  160. package/dist-server/service/bank-account/bank-account-history.js.map +0 -1
  161. package/dist-server/service/bank-account/bank-account-mutation.d.ts +0 -10
  162. package/dist-server/service/bank-account/bank-account-mutation.js +0 -128
  163. package/dist-server/service/bank-account/bank-account-mutation.js.map +0 -1
  164. package/dist-server/service/bank-account/bank-account-query.d.ts +0 -11
  165. package/dist-server/service/bank-account/bank-account-query.js +0 -79
  166. package/dist-server/service/bank-account/bank-account-query.js.map +0 -1
  167. package/dist-server/service/bank-account/bank-account-type.d.ts +0 -39
  168. package/dist-server/service/bank-account/bank-account-type.js +0 -153
  169. package/dist-server/service/bank-account/bank-account-type.js.map +0 -1
  170. package/dist-server/service/bank-account/bank-account.d.ts +0 -38
  171. package/dist-server/service/bank-account/bank-account.js +0 -164
  172. package/dist-server/service/bank-account/bank-account.js.map +0 -1
  173. package/dist-server/service/bank-account/event-subscriber.d.ts +0 -7
  174. package/dist-server/service/bank-account/event-subscriber.js +0 -21
  175. package/dist-server/service/bank-account/event-subscriber.js.map +0 -1
  176. package/dist-server/service/bank-account/index.d.ts +0 -7
  177. package/dist-server/service/bank-account/index.js +0 -12
  178. package/dist-server/service/bank-account/index.js.map +0 -1
  179. package/dist-server/service/financial-institution/financial-institution-mutation.d.ts +0 -10
  180. package/dist-server/service/financial-institution/financial-institution-mutation.js +0 -169
  181. package/dist-server/service/financial-institution/financial-institution-mutation.js.map +0 -1
  182. package/dist-server/service/financial-institution/financial-institution-query.d.ts +0 -12
  183. package/dist-server/service/financial-institution/financial-institution-query.js +0 -97
  184. package/dist-server/service/financial-institution/financial-institution-query.js.map +0 -1
  185. package/dist-server/service/financial-institution/financial-institution-type.d.ts +0 -32
  186. package/dist-server/service/financial-institution/financial-institution-type.js +0 -126
  187. package/dist-server/service/financial-institution/financial-institution-type.js.map +0 -1
  188. package/dist-server/service/financial-institution/financial-institution.d.ts +0 -34
  189. package/dist-server/service/financial-institution/financial-institution.js +0 -137
  190. package/dist-server/service/financial-institution/financial-institution.js.map +0 -1
  191. package/dist-server/service/financial-institution/index.d.ts +0 -6
  192. package/dist-server/service/financial-institution/index.js +0 -10
  193. package/dist-server/service/financial-institution/index.js.map +0 -1
  194. package/helps/accounting/bank-account.md +0 -160
  195. package/helps/accounting/bank.md +0 -160
  196. package/helps/accounting/financial-institution.md +0 -160
@@ -0,0 +1,339 @@
1
+ import { MigrationInterface, QueryRunner } from 'typeorm'
2
+ import { Domain, getRepository } from '@things-factory/shell'
3
+ import { User } from '@things-factory/auth-base'
4
+ import { Account } from '../service/account/account'
5
+ import { AccountingCategory } from '../service/accounting-category/accounting-category'
6
+
7
+ export class SeedAccounts1725201467183 implements MigrationInterface {
8
+ public async up(queryRunner: QueryRunner): Promise<void> {
9
+ const domainRepository = getRepository(Domain)
10
+ const userRepository = getRepository(User)
11
+ const accountingCategoryRepository = getRepository(AccountingCategory)
12
+ const accountRepository = getRepository(Account)
13
+
14
+ const domain: Domain | null = await domainRepository.findOne({
15
+ where: { name: 'SYSTEM' }
16
+ })
17
+
18
+ if (!domain) {
19
+ throw new Error('SYSTEM domain not found')
20
+ }
21
+
22
+ const user = await userRepository.findOne({ where: { id: domain.owner } })
23
+
24
+ if (!user) {
25
+ throw new Error('Domain owner not found')
26
+ }
27
+
28
+ try {
29
+ // 최상위 카테고리 생성
30
+ const topLevelCategories = {
31
+ 자산: await accountingCategoryRepository.save({
32
+ domain,
33
+ code: 'ASSET',
34
+ name: '자산',
35
+ description: '기업이 소유하고 있는 자산',
36
+ creator: user,
37
+ updater: user
38
+ }),
39
+ 부채: await accountingCategoryRepository.save({
40
+ domain,
41
+ code: 'LIABILITY',
42
+ name: '부채',
43
+ description: '기업이 갚아야 할 빚',
44
+ creator: user,
45
+ updater: user
46
+ }),
47
+ 자본: await accountingCategoryRepository.save({
48
+ domain,
49
+ code: 'EQUITY',
50
+ name: '자본',
51
+ description: '기업 소유주의 자산',
52
+ creator: user,
53
+ updater: user
54
+ }),
55
+ 수익: await accountingCategoryRepository.save({
56
+ domain,
57
+ code: 'REVENUE',
58
+ name: '수익',
59
+ description: '기업이 벌어들인 돈',
60
+ creator: user,
61
+ updater: user
62
+ }),
63
+ 비용: await accountingCategoryRepository.save({
64
+ domain,
65
+ code: 'EXPENSE',
66
+ name: '비용',
67
+ description: '기업 운영에 사용된 돈',
68
+ creator: user,
69
+ updater: user
70
+ })
71
+ }
72
+
73
+ // 유동자산 및 비유동자산과 같은 하위 카테고리 생성
74
+ const subCategories = {
75
+ 유동자산: await accountingCategoryRepository.save({
76
+ domain,
77
+ code: 'CURRENT_ASSET',
78
+ name: '유동자산',
79
+ description: '쉽게 현금화할 수 있는 자산',
80
+ parent: topLevelCategories.자산,
81
+ creator: user,
82
+ updater: user
83
+ }),
84
+ 비유동자산: await accountingCategoryRepository.save({
85
+ domain,
86
+ code: 'NON_CURRENT_ASSET',
87
+ name: '비유동자산',
88
+ description: '장기 보유 자산',
89
+ parent: topLevelCategories.자산,
90
+ creator: user,
91
+ updater: user
92
+ }),
93
+ 유동부채: await accountingCategoryRepository.save({
94
+ domain,
95
+ code: 'CURRENT_LIABILITY',
96
+ name: '유동부채',
97
+ description: '단기간에 상환해야 하는 부채',
98
+ parent: topLevelCategories.부채,
99
+ creator: user,
100
+ updater: user
101
+ }),
102
+ 비유동부채: await accountingCategoryRepository.save({
103
+ domain,
104
+ code: 'NON_CURRENT_LIABILITY',
105
+ name: '비유동부채',
106
+ description: '장기 부채',
107
+ parent: topLevelCategories.부채,
108
+ creator: user,
109
+ updater: user
110
+ })
111
+ }
112
+
113
+ // 이제 유형자산, 무형자산, 단기금융부채 같은 하위 카테고리를 subCategories 객체를 사용하여 생성합니다.
114
+ const furtherSubCategories = {
115
+ 유형자산: await accountingCategoryRepository.save({
116
+ domain,
117
+ code: 'TANGIBLE_ASSET',
118
+ name: '유형자산',
119
+ description: '물리적 형태가 있는 자산',
120
+ parent: subCategories.비유동자산,
121
+ creator: user,
122
+ updater: user
123
+ }),
124
+ 무형자산: await accountingCategoryRepository.save({
125
+ domain,
126
+ code: 'INTANGIBLE_ASSET',
127
+ name: '무형자산',
128
+ description: '물리적 형태가 없는 자산',
129
+ parent: subCategories.비유동자산,
130
+ creator: user,
131
+ updater: user
132
+ }),
133
+ 단기금융부채: await accountingCategoryRepository.save({
134
+ domain,
135
+ code: 'SHORT_TERM_FINANCIAL_LIABILITY',
136
+ name: '단기금융부채',
137
+ description: '단기적으로 갚아야 할 금융부채',
138
+ parent: subCategories.유동부채,
139
+ creator: user,
140
+ updater: user
141
+ })
142
+ }
143
+
144
+ // 계정 생성 및 하위 카테고리 연결
145
+ const accounts = [
146
+ // 유동자산 계정
147
+ {
148
+ code: '101',
149
+ name: '현금 및 현금성 자산',
150
+ description: '현금, 예금 및 기타 현금성 자산',
151
+ category: subCategories.유동자산
152
+ },
153
+ {
154
+ code: '102',
155
+ name: '매출채권',
156
+ description: '상품 또는 서비스의 판매로 인해 발생한 채권',
157
+ category: subCategories.유동자산
158
+ },
159
+ {
160
+ code: '103',
161
+ name: '재고자산',
162
+ description: '판매를 목적으로 보유한 상품, 제품, 원재료 등',
163
+ category: subCategories.유동자산
164
+ },
165
+ {
166
+ code: '104',
167
+ name: '단기금융상품',
168
+ description: '단기투자 목적으로 보유한 금융상품',
169
+ category: subCategories.유동자산
170
+ },
171
+ {
172
+ code: '105',
173
+ name: '선급금',
174
+ description: '상품, 서비스 제공을 위해 미리 지급한 금액',
175
+ category: subCategories.유동자산
176
+ },
177
+
178
+ // 비유동자산 계정
179
+ {
180
+ code: '201',
181
+ name: '건물',
182
+ description: '기업이 소유한 건물',
183
+ category: furtherSubCategories.유형자산
184
+ },
185
+ {
186
+ code: '202',
187
+ name: '토지',
188
+ description: '기업이 소유한 토지',
189
+ category: furtherSubCategories.유형자산
190
+ },
191
+ {
192
+ code: '203',
193
+ name: '기계장치',
194
+ description: '생산을 위해 사용되는 기계 및 장치',
195
+ category: furtherSubCategories.유형자산
196
+ },
197
+ {
198
+ code: '204',
199
+ name: '무형자산',
200
+ description: '특허권, 상표권 등의 무형자산',
201
+ category: furtherSubCategories.무형자산
202
+ },
203
+
204
+ // 유동부채 계정
205
+ {
206
+ code: '301',
207
+ name: '매입채무',
208
+ description: '상품 또는 서비스의 구매로 인해 발생한 채무',
209
+ category: subCategories.유동부채
210
+ },
211
+ {
212
+ code: '302',
213
+ name: '단기차입금',
214
+ description: '단기 대출금',
215
+ category: furtherSubCategories.단기금융부채
216
+ },
217
+ {
218
+ code: '303',
219
+ name: '미지급금',
220
+ description: '이미 발생한 비용에 대한 지급할 금액',
221
+ category: subCategories.유동부채
222
+ },
223
+ {
224
+ code: '304',
225
+ name: '선수금',
226
+ description: '고객으로부터 미리 받은 금액',
227
+ category: subCategories.유동부채
228
+ },
229
+
230
+ // 비유동부채 계정
231
+ { code: '401', name: '장기차입금', description: '장기 대출금', category: subCategories.비유동부채 },
232
+ {
233
+ code: '402',
234
+ name: '퇴직급여충당부채',
235
+ description: '퇴직급여 지급을 위해 설정한 부채',
236
+ category: subCategories.비유동부채
237
+ },
238
+
239
+ // 자본 계정
240
+ { code: '501', name: '자본금', description: '주주가 납입한 자본', category: topLevelCategories.자본 },
241
+ { code: '502', name: '이익잉여금', description: '이익의 축적', category: topLevelCategories.자본 },
242
+
243
+ // 수익 계정
244
+ {
245
+ code: '601',
246
+ name: '제품매출',
247
+ description: '제품의 판매로 인한 수익',
248
+ category: topLevelCategories.수익
249
+ },
250
+ {
251
+ code: '602',
252
+ name: '상품매출',
253
+ description: '상품의 판매로 인한 수익',
254
+ category: topLevelCategories.수익
255
+ },
256
+ {
257
+ code: '603',
258
+ name: '용역매출',
259
+ description: '용역 제공으로 인한 수익',
260
+ category: topLevelCategories.수익
261
+ },
262
+ {
263
+ code: '604',
264
+ name: '이자수익',
265
+ description: '금융 자산에서 발생한 이자수익',
266
+ category: topLevelCategories.수익
267
+ },
268
+ {
269
+ code: '605',
270
+ name: '배당금수익',
271
+ description: '주식 투자로 인한 배당금 수익',
272
+ category: topLevelCategories.수익
273
+ },
274
+
275
+ // 비용 계정
276
+ {
277
+ code: '701',
278
+ name: '매출원가',
279
+ description: '제품, 상품, 용역 제공에 대한 원가',
280
+ category: topLevelCategories.비용
281
+ },
282
+ { code: '702', name: '급여', description: '직원 급여 비용', category: topLevelCategories.비용 },
283
+ { code: '703', name: '임대료', description: '건물 및 설비 임차료', category: topLevelCategories.비용 },
284
+ {
285
+ code: '704',
286
+ name: '감가상각비',
287
+ description: '유형자산의 감가상각비용',
288
+ category: topLevelCategories.비용
289
+ },
290
+ {
291
+ code: '705',
292
+ name: '이자비용',
293
+ description: '차입금에 대한 이자비용',
294
+ category: topLevelCategories.비용
295
+ },
296
+ {
297
+ code: '706',
298
+ name: '판매비 및 관리비',
299
+ description: '기업 운영에 필요한 비용',
300
+ category: topLevelCategories.비용
301
+ },
302
+ { code: '707', name: '법인세비용', description: '법인세 납부 비용', category: topLevelCategories.비용 }
303
+ ]
304
+
305
+ // 계정 저장
306
+ for (const account of accounts) {
307
+ await accountRepository.save({
308
+ domain,
309
+ ...account,
310
+ creator: user,
311
+ updater: user
312
+ })
313
+ }
314
+ } catch (error) {
315
+ console.error('Failed to seed accounting categories and accounts:', error)
316
+ throw error
317
+ }
318
+ }
319
+
320
+ public async down(queryRunner: QueryRunner): Promise<void> {
321
+ const domainRepository = getRepository(Domain)
322
+ const accountingCategoryRepository = getRepository(AccountingCategory)
323
+ const accountRepository = getRepository(Account)
324
+
325
+ const domain: Domain | null = await domainRepository.findOne({
326
+ where: { name: 'SYSTEM' }
327
+ })
328
+
329
+ if (!domain) {
330
+ throw new Error('SYSTEM domain not found')
331
+ }
332
+
333
+ // Accounts 삭제
334
+ await accountRepository.softDelete({ domain: { id: domain.id } })
335
+
336
+ // AccountingCategories 삭제
337
+ await accountingCategoryRepository.softDelete({ domain: { id: domain.id } })
338
+ }
339
+ }
@@ -0,0 +1,9 @@
1
+ const glob = require('glob')
2
+ const path = require('path')
3
+
4
+ export var migrations = []
5
+
6
+ glob.sync(path.resolve(__dirname, '.', '**', '*.js')).forEach(function(file) {
7
+ if (file.indexOf('index.js') !== -1) return
8
+ migrations = migrations.concat(Object.values(require(path.resolve(file))) || [])
9
+ })
@@ -0,0 +1,26 @@
1
+ process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
2
+ /*
3
+ * can add global public routes to application (auth not required, tenancy not required)
4
+ *
5
+ * ex) routes.get('/path', async(context, next) => {})
6
+ * ex) routes.post('/path', async(context, next) => {})
7
+ */
8
+ })
9
+
10
+ process.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {
11
+ /*
12
+ * can add global private routes to application (auth required, tenancy not required)
13
+ */
14
+ })
15
+
16
+ process.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {
17
+ /*
18
+ * can add domain public routes to application (auth not required, tenancy required)
19
+ */
20
+ })
21
+
22
+ process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
23
+ /*
24
+ * can add domain private routes to application (auth required, tenancy required)
25
+ */
26
+ })
@@ -0,0 +1,117 @@
1
+ import { Field, ID, ObjectType } from 'type-graphql'
2
+ import { Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId } from 'typeorm'
3
+
4
+ import {
5
+ HistoryActionColumn,
6
+ HistoryActionType,
7
+ HistoryEntityInterface,
8
+ HistoryOriginalIdColumn
9
+ } from '@operato/typeorm-history'
10
+ import { Role, User } from '@things-factory/auth-base'
11
+ import { config } from '@things-factory/env'
12
+ import { Domain } from '@things-factory/shell'
13
+
14
+ import { Account } from './account'
15
+ import { AccountingCategory } from '../accounting-category/accounting-category'
16
+
17
+ const ORMCONFIG = config.get('ormconfig', {})
18
+ const DATABASE_TYPE = ORMCONFIG.type
19
+
20
+ @Entity()
21
+ @Index(
22
+ 'ix_account_history_0',
23
+ (accountHistory: AccountHistory) => [accountHistory.originalId, accountHistory.version],
24
+ { unique: true }
25
+ )
26
+ @Index(
27
+ 'ix_account_history_1',
28
+ (accountHistory: AccountHistory) => [accountHistory.domain, accountHistory.originalId, accountHistory.version],
29
+ { unique: true }
30
+ )
31
+ @ObjectType({ description: 'History Entity of Account' })
32
+ export class AccountHistory implements HistoryEntityInterface<Account> {
33
+ @PrimaryGeneratedColumn('uuid')
34
+ @Field(type => ID)
35
+ readonly id: string
36
+
37
+ @Column({ nullable: true, default: 1 })
38
+ @Field({ nullable: true })
39
+ version?: number = 1
40
+
41
+ @ManyToOne(type => Domain)
42
+ @Field({ nullable: true })
43
+ domain?: Domain
44
+
45
+ @RelationId((accountHistory: AccountHistory) => accountHistory.domain)
46
+ domainId?: string
47
+
48
+ @Column({ nullable: true })
49
+ @Field({ nullable: true })
50
+ code?: string
51
+
52
+ @Column({ nullable: true })
53
+ @Field({ nullable: true })
54
+ name?: string
55
+
56
+ @Column({ nullable: true })
57
+ @Field({ nullable: true })
58
+ description?: string
59
+
60
+ @Column({ nullable: true })
61
+ @Field({ nullable: true })
62
+ active?: boolean
63
+
64
+ @ManyToOne(type => AccountingCategory)
65
+ @Field(type => AccountingCategory, { nullable: true })
66
+ category?: AccountingCategory
67
+
68
+ @RelationId((accountHistory: AccountHistory) => accountHistory.category)
69
+ categoryId?: string
70
+
71
+ @Column({ nullable: true })
72
+ @Field({ nullable: true })
73
+ createdAt?: Date
74
+
75
+ @Column({ nullable: true })
76
+ @Field({ nullable: true })
77
+ updatedAt?: Date
78
+
79
+ @Column({ nullable: true })
80
+ @Field({ nullable: true })
81
+ deletedAt?: Date
82
+
83
+ @ManyToOne(type => User, { nullable: true })
84
+ @Field({ nullable: true })
85
+ creator?: User
86
+
87
+ @RelationId((accountHistory: AccountHistory) => accountHistory.creator)
88
+ creatorId?: string
89
+
90
+ @ManyToOne(type => User, { nullable: true })
91
+ @Field({ nullable: true })
92
+ updater?: User
93
+
94
+ @RelationId((accountHistory: AccountHistory) => accountHistory.updater)
95
+ updaterId?: string
96
+
97
+ @HistoryOriginalIdColumn()
98
+ public originalId!: string
99
+
100
+ @HistoryActionColumn({
101
+ nullable: false,
102
+ type:
103
+ DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
104
+ ? 'enum'
105
+ : DATABASE_TYPE == 'oracle'
106
+ ? 'varchar2'
107
+ : DATABASE_TYPE == 'mssql'
108
+ ? 'nvarchar'
109
+ : 'varchar',
110
+ enum:
111
+ DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
112
+ ? HistoryActionType
113
+ : undefined,
114
+ length: DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb' ? undefined : 10
115
+ })
116
+ public action!: HistoryActionType
117
+ }
@@ -0,0 +1,140 @@
1
+ import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
2
+ import { In } from 'typeorm'
3
+
4
+ import { getRepository } from '@things-factory/shell'
5
+
6
+ import { Account } from './account'
7
+ import { NewAccount, AccountPatch } from './account-type'
8
+
9
+ @Resolver(Account)
10
+ export class AccountMutation {
11
+ @Directive('@transaction')
12
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
13
+ @Mutation(returns => Account, { description: 'To create new Account' })
14
+ async createAccount(@Arg('account') account: NewAccount, @Ctx() context: ResolverContext): Promise<Account> {
15
+ const { domain, user, tx } = context.state
16
+
17
+ const result = await getRepository(Account, tx).save({
18
+ ...account,
19
+ domain,
20
+ creator: user,
21
+ updater: user
22
+ })
23
+
24
+ return result
25
+ }
26
+
27
+ @Directive('@transaction')
28
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
29
+ @Mutation(returns => Account, { description: 'To modify Account information' })
30
+ async updateAccount(
31
+ @Arg('id') id: string,
32
+ @Arg('patch') patch: AccountPatch,
33
+ @Ctx() context: ResolverContext
34
+ ): Promise<Account> {
35
+ const { domain, user, tx } = context.state
36
+
37
+ const repository = getRepository(Account, tx)
38
+ const account = await repository.findOne({
39
+ where: { domain: { id: domain.id }, id }
40
+ })
41
+
42
+ const result = await repository.save({
43
+ ...account,
44
+ ...patch,
45
+ updater: user
46
+ })
47
+
48
+ return result
49
+ }
50
+
51
+ @Directive('@transaction')
52
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
53
+ @Mutation(returns => [Account], { description: "To modify multiple Accounts' information" })
54
+ async updateMultipleAccount(
55
+ @Arg('patches', type => [AccountPatch]) patches: AccountPatch[],
56
+ @Ctx() context: ResolverContext
57
+ ): Promise<Account[]> {
58
+ const { domain, user, tx } = context.state
59
+
60
+ let results = []
61
+ const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
62
+ const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
63
+ const accountRepo = getRepository(Account, tx)
64
+
65
+ if (_createRecords.length > 0) {
66
+ for (let i = 0; i < _createRecords.length; i++) {
67
+ const newRecord = _createRecords[i]
68
+
69
+ const result = await accountRepo.save({
70
+ ...newRecord,
71
+ domain,
72
+ creator: user,
73
+ updater: user
74
+ })
75
+
76
+ results.push({ ...result, cuFlag: '+' })
77
+ }
78
+ }
79
+
80
+ if (_updateRecords.length > 0) {
81
+ for (let i = 0; i < _updateRecords.length; i++) {
82
+ const updateRecord = _updateRecords[i]
83
+ const account = await accountRepo.findOneBy({ id: updateRecord.id })
84
+
85
+ const result = await accountRepo.save({
86
+ ...account,
87
+ ...updateRecord,
88
+ updater: user
89
+ })
90
+
91
+ results.push({ ...result, cuFlag: 'M' })
92
+ }
93
+ }
94
+
95
+ return results
96
+ }
97
+
98
+ @Directive('@transaction')
99
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
100
+ @Mutation(returns => Boolean, { description: 'To delete Account' })
101
+ async deleteAccount(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
102
+ const { domain, tx } = context.state
103
+
104
+ await getRepository(Account, tx).delete({ domain: { id: domain.id }, id })
105
+
106
+ return true
107
+ }
108
+
109
+ @Directive('@transaction')
110
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
111
+ @Mutation(returns => Boolean, { description: 'To delete multiple Accounts' })
112
+ async deleteAccounts(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<boolean> {
113
+ const { domain, tx } = context.state
114
+
115
+ await getRepository(Account, tx).delete({
116
+ domain: { id: domain.id },
117
+ id: In(ids)
118
+ })
119
+
120
+ return true
121
+ }
122
+
123
+ @Directive('@transaction')
124
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
125
+ @Mutation(returns => Boolean, { description: 'To import multiple Accounts' })
126
+ async importAccounts(
127
+ @Arg('accounts', type => [AccountPatch]) accounts: AccountPatch[],
128
+ @Ctx() context: ResolverContext
129
+ ): Promise<boolean> {
130
+ const { domain, tx } = context.state
131
+
132
+ await Promise.all(
133
+ accounts.map(async (account: AccountPatch) => {
134
+ const createdAccount: Account = await getRepository(Account, tx).save({ domain, ...account })
135
+ })
136
+ )
137
+
138
+ return true
139
+ }
140
+ }
@@ -0,0 +1,51 @@
1
+ import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
2
+
3
+ import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
4
+ import { User } from '@things-factory/auth-base'
5
+ import { Account } from './account'
6
+ import { AccountList } from './account-type'
7
+
8
+ @Resolver(Account)
9
+ export class AccountQuery {
10
+ @Directive('@privilege(category: "accounting", privilege: "query")')
11
+ @Query(returns => Account!, { nullable: true, description: 'To fetch a Account' })
12
+ async account(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Account> {
13
+ const { domain } = context.state
14
+
15
+ return await getRepository(Account).findOne({
16
+ where: { domain: { id: domain.id }, id }
17
+ })
18
+ }
19
+
20
+ @Directive('@privilege(category: "accounting", privilege: "query")')
21
+ @Query(returns => AccountList, { description: 'To fetch multiple Accounts' })
22
+ async accounts(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<AccountList> {
23
+ const { domain } = context.state
24
+
25
+ const queryBuilder = getQueryBuilderFromListParams({
26
+ domain,
27
+ params,
28
+ repository: await getRepository(Account),
29
+ searchables: ['name', 'description']
30
+ })
31
+
32
+ const [items, total] = await queryBuilder.getManyAndCount()
33
+
34
+ return { items, total }
35
+ }
36
+
37
+ @FieldResolver(type => Domain)
38
+ async domain(@Root() account: Account): Promise<Domain> {
39
+ return await getRepository(Domain).findOneBy({ id: account.domainId })
40
+ }
41
+
42
+ @FieldResolver(type => User)
43
+ async updater(@Root() account: Account): Promise<User> {
44
+ return await getRepository(User).findOneBy({ id: account.updaterId })
45
+ }
46
+
47
+ @FieldResolver(type => User)
48
+ async creator(@Root() account: Account): Promise<User> {
49
+ return await getRepository(User).findOneBy({ id: account.creatorId })
50
+ }
51
+ }