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

Sign up to get free protection for your applications and to get access to all the features.
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,123 @@
1
+ import {
2
+ CreateDateColumn,
3
+ UpdateDateColumn,
4
+ DeleteDateColumn,
5
+ Entity,
6
+ Index,
7
+ Column,
8
+ RelationId,
9
+ ManyToOne,
10
+ VersionColumn,
11
+ PrimaryGeneratedColumn
12
+ } from 'typeorm'
13
+ import { ObjectType, Field, ID, registerEnumType } from 'type-graphql'
14
+
15
+ import { Domain } from '@things-factory/shell'
16
+ import { User } from '@things-factory/auth-base'
17
+ import { Transaction } from '../transaction/transaction'
18
+
19
+ export enum PaymentDirection {
20
+ Incoming = 'Incoming', // 수금
21
+ Outgoing = 'Outgoing' // 지출
22
+ }
23
+
24
+ registerEnumType(PaymentDirection, {
25
+ name: 'PaymentDirection',
26
+ description: 'Indicates whether the payment is incoming (received) or outgoing (paid)' // 결제 방향을 나타냅니다 (수금 또는 지출)
27
+ })
28
+
29
+ @Entity()
30
+ @Index('ix_payment_0', (payment: Payment) => [payment.domain, payment.transaction, payment.paidAt], {
31
+ where: '"deleted_at" IS NULL',
32
+ unique: true
33
+ })
34
+ @Index(
35
+ 'ix_payment_1',
36
+ (payment: Payment) => [payment.domain, payment.year, payment.quarter, payment.month, payment.paidAt],
37
+ {
38
+ unique: true,
39
+ where: '"deleted_at" IS NULL'
40
+ }
41
+ )
42
+ @ObjectType({ description: 'Entity representing a Payment record in the system' }) // 시스템 내에서 결제 기록을 나타내는 엔티티
43
+ export class Payment {
44
+ @PrimaryGeneratedColumn('uuid')
45
+ @Field(type => ID, { description: 'Unique identifier for the payment record' })
46
+ readonly id: string // 고유 식별자 (UUID)
47
+
48
+ @VersionColumn()
49
+ @Field({ nullable: true, description: 'Version number used for optimistic locking' })
50
+ version?: number = 1 // 낙관적 잠금을 위한 버전 관리 필드
51
+
52
+ @ManyToOne(type => Domain)
53
+ @Field({ nullable: true, description: 'The domain to which this payment belongs' })
54
+ domain?: Domain // 결제가 속한 도메인
55
+
56
+ @RelationId((payment: Payment) => payment.domain)
57
+ domainId?: string // 도메인의 ID
58
+
59
+ @ManyToOne(type => Transaction, transaction => transaction.payments)
60
+ @Field(type => Transaction, { description: 'The transaction associated with this payment' })
61
+ transaction: Transaction // 결제와 연결된 트랜잭션
62
+
63
+ @RelationId((payment: Payment) => payment.transaction)
64
+ transactionId: string // 연결된 트랜잭션의 ID
65
+
66
+ @Column({ nullable: true })
67
+ @Field({ nullable: true, description: 'The currency used in the payment' })
68
+ currency?: string // 결제에 사용된 통화
69
+
70
+ @Column({ nullable: false })
71
+ @Field({ nullable: false, description: 'The amount of money involved in the payment' })
72
+ amount: number // 결제된 금액
73
+
74
+ @Column({ nullable: true })
75
+ @Field({ nullable: true, description: 'Fiscal year in which the payment was made' })
76
+ year?: number // 결제가 발생한 회계 연도
77
+
78
+ @Column({ nullable: true })
79
+ @Field({ nullable: true, description: 'Fiscal quarter in which the payment was made' })
80
+ quarter?: number // 결제가 발생한 회계 분기
81
+
82
+ @Column({ nullable: true })
83
+ @Field({ nullable: true, description: 'Fiscal month in which the payment was made' })
84
+ month?: number // 결제가 발생한 회계 월
85
+
86
+ @Column({ nullable: false })
87
+ @Field({ nullable: false, description: 'The date and time when the payment was made' })
88
+ paidAt: Date // 결제가 이루어진 날짜 및 시간
89
+
90
+ @Column({ nullable: false })
91
+ @Field(type => PaymentDirection, { description: 'Direction of the payment (Incoming or Outgoing)' })
92
+ direction: PaymentDirection // 결제 방향 (수금 또는 지출)
93
+
94
+ @Column({ nullable: true })
95
+ @Field({ nullable: true, description: 'Additional notes or comments about the payment' })
96
+ note?: string // 결제에 대한 추가 설명 또는 메모
97
+
98
+ @CreateDateColumn()
99
+ @Field({ nullable: true, description: 'The date and time when the payment record was created' })
100
+ createdAt?: Date // 결제 레코드가 생성된 날짜 및 시간
101
+
102
+ @UpdateDateColumn()
103
+ @Field({ nullable: true, description: 'The date and time when the payment record was last updated' })
104
+ updatedAt?: Date // 결제 레코드가 마지막으로 업데이트된 날짜 및 시간
105
+
106
+ @DeleteDateColumn()
107
+ @Field({ nullable: true, description: 'The date and time when the payment record was deleted' })
108
+ deletedAt?: Date // 결제 레코드가 삭제된 날짜 및 시간
109
+
110
+ @ManyToOne(type => User, { nullable: true })
111
+ @Field(type => User, { nullable: true, description: 'The user who created the payment record' })
112
+ creator?: User // 결제 레코드를 생성한 사용자
113
+
114
+ @RelationId((payment: Payment) => payment.creator)
115
+ creatorId?: string // 결제 레코드를 생성한 사용자의 ID
116
+
117
+ @ManyToOne(type => User, { nullable: true })
118
+ @Field(type => User, { nullable: true, description: 'The user who last updated the payment record' })
119
+ updater?: User // 결제 레코드를 마지막으로 업데이트한 사용자
120
+
121
+ @RelationId((payment: Payment) => payment.updater)
122
+ updaterId?: string // 결제 레코드를 업데이트한 사용자의 ID
123
+ }
@@ -0,0 +1,17 @@
1
+ import { EventSubscriber } from 'typeorm'
2
+
3
+ import { HistoryEntitySubscriber } from '@operato/typeorm-history'
4
+
5
+ import { Transaction } from './transaction'
6
+ import { TransactionHistory } from './transaction-history'
7
+
8
+ @EventSubscriber()
9
+ export class TransactionHistoryEntitySubscriber extends HistoryEntitySubscriber<Transaction, TransactionHistory> {
10
+ public get entity() {
11
+ return Transaction
12
+ }
13
+
14
+ public get historyEntity() {
15
+ return TransactionHistory
16
+ }
17
+ }
@@ -0,0 +1,9 @@
1
+ import { Transaction } from './transaction'
2
+ import { TransactionHistory } from './transaction-history'
3
+ import { TransactionQuery } from './transaction-query'
4
+ import { TransactionMutation } from './transaction-mutation'
5
+ import { TransactionHistoryEntitySubscriber } from './event-subscriber'
6
+
7
+ export const entities = [Transaction, TransactionHistory]
8
+ export const resolvers = [TransactionQuery, TransactionMutation]
9
+ export const subscribers = [TransactionHistoryEntitySubscriber]
@@ -0,0 +1,161 @@
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 { Transaction, TransactionCategory, TransactionStatus, TransactionType } from './transaction'
15
+ import { Account } from '../account/account'
16
+
17
+ const ORMCONFIG = config.get('ormconfig', {})
18
+ const DATABASE_TYPE = ORMCONFIG.type
19
+
20
+ @Entity()
21
+ @Index(
22
+ 'ix_transaction_history_0',
23
+ (transactionHistory: TransactionHistory) => [transactionHistory.originalId, transactionHistory.version],
24
+ { unique: true }
25
+ )
26
+ @Index(
27
+ 'ix_transaction_history_1',
28
+ (transactionHistory: TransactionHistory) => [
29
+ transactionHistory.domain,
30
+ transactionHistory.originalId,
31
+ transactionHistory.version
32
+ ],
33
+ { unique: true }
34
+ )
35
+ @ObjectType({ description: 'History Entity of Transaction' })
36
+ export class TransactionHistory implements HistoryEntityInterface<Transaction> {
37
+ @PrimaryGeneratedColumn('uuid')
38
+ @Field(type => ID)
39
+ readonly id: string
40
+
41
+ @Column({ nullable: true, default: 1 })
42
+ @Field({ nullable: true })
43
+ version?: number = 1
44
+
45
+ @ManyToOne(type => Domain)
46
+ @Field({ nullable: true })
47
+ domain?: Domain
48
+
49
+ @RelationId((transactionHistory: TransactionHistory) => transactionHistory.domain)
50
+ domainId?: string
51
+
52
+ @Column()
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
+ currency?: string
63
+
64
+ @Column({ nullable: true })
65
+ @Field({ nullable: true })
66
+ amount?: number = 0
67
+
68
+ @Column({ nullable: true })
69
+ @Field({ nullable: true })
70
+ active?: boolean
71
+
72
+ @Column({ nullable: true })
73
+ @Field({ nullable: true })
74
+ type?: TransactionType
75
+
76
+ @Column({ nullable: false })
77
+ @Field(type => TransactionCategory, { nullable: false })
78
+ category: TransactionCategory // 트랜잭션의 카테고리 (확정, 전망)
79
+
80
+ @Column({ nullable: false })
81
+ @Field(type => TransactionStatus, { nullable: false })
82
+ status: TransactionStatus // 트랜잭션의 상태 (예: Paid, Delayed 등)
83
+
84
+ @Column({ nullable: true })
85
+ @Field({ nullable: true, description: 'The probability of the forecast being realized (0 to 100)' })
86
+ probability?: number // 예측이 실현될 확률 (0 ~ 100)
87
+
88
+ @Column({ nullable: true })
89
+ @Field({ nullable: true, description: 'Additional notes or comments about the forecast' })
90
+ forecastNotes?: string // 전망에 대한 추가 설명이나 메모
91
+
92
+ @ManyToOne(type => Account)
93
+ @Field({ nullable: true })
94
+ account?: Account
95
+
96
+ @RelationId((transactionHistory: TransactionHistory) => transactionHistory.account)
97
+ accountId?: string
98
+
99
+ @Column({ nullable: true })
100
+ @Field({ nullable: true, description: 'fiscal year' })
101
+ year?: number
102
+
103
+ @Column({ nullable: true })
104
+ @Field({ nullable: true, description: 'fiscal quarter' })
105
+ quarter?: number
106
+
107
+ @Column({ nullable: true })
108
+ @Field({ nullable: true, description: 'fiscal month' })
109
+ month?: number
110
+
111
+ @Column({ nullable: false })
112
+ @Field({ nullable: false, description: 'The date the transaction occurs or is scheduled (in string format)' })
113
+ transactionDate: string // 트랜잭션이 발생하거나 발생할 날짜
114
+
115
+ @Column()
116
+ @Field({ nullable: true })
117
+ createdAt?: Date
118
+
119
+ @Column()
120
+ @Field({ nullable: true })
121
+ updatedAt?: Date
122
+
123
+ @Column()
124
+ @Field({ nullable: true })
125
+ deletedAt?: Date
126
+
127
+ @ManyToOne(type => User, { nullable: true })
128
+ @Field(type => User, { nullable: true })
129
+ creator?: User
130
+
131
+ @RelationId((transactionHistory: TransactionHistory) => transactionHistory.creator)
132
+ creatorId?: string
133
+
134
+ @ManyToOne(type => User, { nullable: true })
135
+ @Field(type => User, { nullable: true })
136
+ updater?: User
137
+
138
+ @RelationId((transactionHistory: TransactionHistory) => transactionHistory.updater)
139
+ updaterId?: string
140
+
141
+ @HistoryOriginalIdColumn()
142
+ public originalId!: string
143
+
144
+ @HistoryActionColumn({
145
+ nullable: false,
146
+ type:
147
+ DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
148
+ ? 'enum'
149
+ : DATABASE_TYPE == 'oracle'
150
+ ? 'varchar2'
151
+ : DATABASE_TYPE == 'mssql'
152
+ ? 'nvarchar'
153
+ : 'varchar',
154
+ enum:
155
+ DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
156
+ ? HistoryActionType
157
+ : undefined,
158
+ length: DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb' ? undefined : 10
159
+ })
160
+ public action!: HistoryActionType
161
+ }
@@ -0,0 +1,146 @@
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 { Transaction } from './transaction'
7
+ import { NewTransaction, TransactionPatch } from './transaction-type'
8
+
9
+ @Resolver(Transaction)
10
+ export class TransactionMutation {
11
+ @Directive('@transaction')
12
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
13
+ @Mutation(returns => Transaction, { description: 'To create new Transaction' })
14
+ async createTransaction(
15
+ @Arg('transaction') transaction: NewTransaction,
16
+ @Ctx() context: ResolverContext
17
+ ): Promise<Transaction> {
18
+ const { domain, user, tx } = context.state
19
+
20
+ const result = await getRepository(Transaction, tx).save({
21
+ ...transaction,
22
+ domain,
23
+ creator: user,
24
+ updater: user
25
+ })
26
+
27
+ return result
28
+ }
29
+
30
+ @Directive('@transaction')
31
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
32
+ @Mutation(returns => Transaction, { description: 'To modify Transaction information' })
33
+ async updateTransaction(
34
+ @Arg('id') id: string,
35
+ @Arg('patch') patch: TransactionPatch,
36
+ @Ctx() context: ResolverContext
37
+ ): Promise<Transaction> {
38
+ const { domain, user, tx } = context.state
39
+
40
+ const repository = getRepository(Transaction, tx)
41
+ const transaction = await repository.findOne({
42
+ where: { domain: { id: domain.id }, id }
43
+ })
44
+
45
+ const result = await repository.save({
46
+ ...transaction,
47
+ ...patch,
48
+ updater: user
49
+ })
50
+
51
+ return result
52
+ }
53
+
54
+ @Directive('@transaction')
55
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
56
+ @Mutation(returns => [Transaction], { description: "To modify multiple Transactions' information" })
57
+ async updateMultipleTransaction(
58
+ @Arg('patches', type => [TransactionPatch]) patches: TransactionPatch[],
59
+ @Ctx() context: ResolverContext
60
+ ): Promise<Transaction[]> {
61
+ const { domain, user, tx } = context.state
62
+
63
+ let results = []
64
+ const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
65
+ const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
66
+ const transactionRepo = getRepository(Transaction, tx)
67
+
68
+ if (_createRecords.length > 0) {
69
+ for (let i = 0; i < _createRecords.length; i++) {
70
+ const newRecord = _createRecords[i]
71
+
72
+ const result = await transactionRepo.save({
73
+ ...newRecord,
74
+ domain,
75
+ creator: user,
76
+ updater: user
77
+ })
78
+
79
+ results.push({ ...result, cuFlag: '+' })
80
+ }
81
+ }
82
+
83
+ if (_updateRecords.length > 0) {
84
+ for (let i = 0; i < _updateRecords.length; i++) {
85
+ const updateRecord = _updateRecords[i]
86
+ const transaction = await transactionRepo.findOneBy({ id: updateRecord.id })
87
+
88
+ const result = await transactionRepo.save({
89
+ ...transaction,
90
+ ...updateRecord,
91
+ updater: user
92
+ })
93
+
94
+ results.push({ ...result, cuFlag: 'M' })
95
+ }
96
+ }
97
+
98
+ return results
99
+ }
100
+
101
+ @Directive('@transaction')
102
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
103
+ @Mutation(returns => Boolean, { description: 'To delete Transaction' })
104
+ async deleteTransaction(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
105
+ const { domain, tx } = context.state
106
+
107
+ await getRepository(Transaction, tx).delete({ domain: { id: domain.id }, id })
108
+
109
+ return true
110
+ }
111
+
112
+ @Directive('@transaction')
113
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
114
+ @Mutation(returns => Boolean, { description: 'To delete multiple Transactions' })
115
+ async deleteTransactions(
116
+ @Arg('ids', type => [String]) ids: string[],
117
+ @Ctx() context: ResolverContext
118
+ ): Promise<boolean> {
119
+ const { domain, tx } = context.state
120
+
121
+ await getRepository(Transaction, tx).delete({
122
+ domain: { id: domain.id },
123
+ id: In(ids)
124
+ })
125
+
126
+ return true
127
+ }
128
+
129
+ @Directive('@transaction')
130
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
131
+ @Mutation(returns => Boolean, { description: 'To import multiple Transactions' })
132
+ async importTransactions(
133
+ @Arg('transactions', type => [TransactionPatch]) transactions: TransactionPatch[],
134
+ @Ctx() context: ResolverContext
135
+ ): Promise<boolean> {
136
+ const { domain, tx } = context.state
137
+
138
+ await Promise.all(
139
+ transactions.map(async (transaction: TransactionPatch) => {
140
+ const createdTransaction: Transaction = await getRepository(Transaction, tx).save({ domain, ...transaction })
141
+ })
142
+ )
143
+
144
+ return true
145
+ }
146
+ }
@@ -0,0 +1,50 @@
1
+ import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
2
+ import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
3
+ import { User } from '@things-factory/auth-base'
4
+ import { Transaction } from './transaction'
5
+ import { TransactionList } from './transaction-type'
6
+
7
+ @Resolver(Transaction)
8
+ export class TransactionQuery {
9
+ @Directive('@privilege(category: "accounting", privilege: "query")')
10
+ @Query(returns => Transaction!, { nullable: true, description: 'To fetch a Transaction' })
11
+ async transaction(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Transaction> {
12
+ const { domain } = context.state
13
+
14
+ return await getRepository(Transaction).findOne({
15
+ where: { domain: { id: domain.id }, id }
16
+ })
17
+ }
18
+
19
+ @Directive('@privilege(category: "accounting", privilege: "query")')
20
+ @Query(returns => TransactionList, { description: 'To fetch multiple Transactions' })
21
+ async transactions(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<TransactionList> {
22
+ const { domain } = context.state
23
+
24
+ const queryBuilder = getQueryBuilderFromListParams({
25
+ domain,
26
+ params,
27
+ repository: await getRepository(Transaction),
28
+ searchables: ['name', 'description']
29
+ })
30
+
31
+ const [items, total] = await queryBuilder.getManyAndCount()
32
+
33
+ return { items, total }
34
+ }
35
+
36
+ @FieldResolver(type => Domain)
37
+ async domain(@Root() transaction: Transaction): Promise<Domain> {
38
+ return await getRepository(Domain).findOneBy({ id: transaction.domainId })
39
+ }
40
+
41
+ @FieldResolver(type => User)
42
+ async updater(@Root() transaction: Transaction): Promise<User> {
43
+ return await getRepository(User).findOneBy({ id: transaction.updaterId })
44
+ }
45
+
46
+ @FieldResolver(type => User)
47
+ async creator(@Root() transaction: Transaction): Promise<User> {
48
+ return await getRepository(User).findOneBy({ id: transaction.creatorId })
49
+ }
50
+ }
@@ -0,0 +1,48 @@
1
+ import { ObjectType, Field, InputType, Int, ID, registerEnumType } from 'type-graphql'
2
+
3
+ import { Transaction, TransactionType } from './transaction'
4
+
5
+ @InputType()
6
+ export class NewTransaction {
7
+ @Field()
8
+ name: string
9
+
10
+ @Field({ nullable: true })
11
+ description?: string
12
+
13
+ @Field(type => TransactionType, { nullable: true })
14
+ type?: TransactionType
15
+
16
+ @Field({ nullable: true })
17
+ active?: boolean
18
+ }
19
+
20
+ @InputType()
21
+ export class TransactionPatch {
22
+ @Field(type => ID, { nullable: true })
23
+ id?: string
24
+
25
+ @Field({ nullable: true })
26
+ name?: string
27
+
28
+ @Field({ nullable: true })
29
+ description?: string
30
+
31
+ @Field(type => TransactionType, { nullable: true })
32
+ type?: TransactionType
33
+
34
+ @Field({ nullable: true })
35
+ active?: boolean
36
+
37
+ @Field({ nullable: true })
38
+ cuFlag?: string
39
+ }
40
+
41
+ @ObjectType()
42
+ export class TransactionList {
43
+ @Field(type => [Transaction])
44
+ items: Transaction[]
45
+
46
+ @Field(type => Int)
47
+ total: number
48
+ }