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

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,120 @@
1
+ import {
2
+ CreateDateColumn,
3
+ UpdateDateColumn,
4
+ DeleteDateColumn,
5
+ Entity,
6
+ Index,
7
+ Column,
8
+ RelationId,
9
+ ManyToOne,
10
+ OneToMany,
11
+ PrimaryGeneratedColumn,
12
+ VersionColumn
13
+ } from 'typeorm'
14
+ import { ObjectType, Field, ID, registerEnumType } from 'type-graphql'
15
+
16
+ import { Domain } from '@things-factory/shell'
17
+ import { User } from '@things-factory/auth-base'
18
+
19
+ import { IncomeStatementLineItem } from './income-statement-line-item'
20
+
21
+ export enum IncomeStatementStatus {
22
+ STATUS_A = 'STATUS_A',
23
+ STATUS_B = 'STATUS_B'
24
+ }
25
+
26
+ registerEnumType(IncomeStatementStatus, {
27
+ name: 'IncomeStatementStatus',
28
+ description: 'State enumeration of an income statement' // 손익계산서의 상태 열거형
29
+ })
30
+
31
+ // 손익계산서 (Income Statement)
32
+ @Entity()
33
+ @Index(
34
+ 'ix_income_statement_0',
35
+ (incomeStatement: IncomeStatement) => [
36
+ incomeStatement.domain,
37
+ incomeStatement.year,
38
+ incomeStatement.quarter,
39
+ incomeStatement.month
40
+ ],
41
+ {
42
+ unique: true,
43
+ where: '"deleted_at" IS NULL' // 삭제되지 않은 경우에만 유니크
44
+ }
45
+ )
46
+ @ObjectType({ description: 'Entity for IncomeStatement, representing the profit and loss report' }) // 손익계산서 엔티티
47
+ export class IncomeStatement {
48
+ @PrimaryGeneratedColumn('uuid')
49
+ @Field(type => ID, { description: 'Unique identifier for the income statement' })
50
+ readonly id: string // 고유 식별자 (UUID)
51
+
52
+ @VersionColumn()
53
+ @Field({ nullable: true, description: 'Version number for optimistic locking' })
54
+ version?: number = 1 // 낙관적 잠금을 위한 버전 관리 필드
55
+
56
+ @ManyToOne(type => Domain)
57
+ @Field({ nullable: true, description: 'The domain to which this income statement belongs' })
58
+ domain?: Domain // 이 손익계산서가 속한 도메인
59
+
60
+ @RelationId((incomeStatement: IncomeStatement) => incomeStatement.domain)
61
+ domainId?: string // 도메인의 ID
62
+
63
+ @Column({ nullable: true })
64
+ @Field({ nullable: true, description: 'Fiscal year of the income statement' })
65
+ year?: number // 회계 연도
66
+
67
+ @Column({ nullable: true })
68
+ @Field({ nullable: true, description: 'Fiscal quarter of the income statement' })
69
+ quarter?: number // 회계 분기
70
+
71
+ @Column({ nullable: true })
72
+ @Field({ nullable: true, description: 'Fiscal month of the income statement' })
73
+ month?: number // 회계 월
74
+
75
+ @Column({ nullable: true })
76
+ @Field({ nullable: true, description: 'Total revenue recorded in the income statement' })
77
+ revenue?: number // 손익계산서에 기록된 총수익
78
+
79
+ @Column({ nullable: true })
80
+ @Field({ nullable: true, description: 'Total expenses recorded in the income statement' })
81
+ expense?: number // 손익계산서에 기록된 총비용
82
+
83
+ @Column({ nullable: true })
84
+ @Field({ nullable: true, description: 'Net income calculated as revenue minus expenses' })
85
+ netIncome?: number // 총수익에서 총비용을 뺀 순이익
86
+
87
+ @Column({ nullable: true })
88
+ @Field({ nullable: true, description: 'Indicates whether this income statement is active' })
89
+ active?: boolean // 이 손익계산서가 활성 상태인지 여부
90
+
91
+ @OneToMany(type => IncomeStatementLineItem, lineItem => lineItem.statement)
92
+ @Field(type => [IncomeStatementLineItem], { nullable: true })
93
+ lineItems?: IncomeStatementLineItem[] // 계정별 브레이크다운
94
+
95
+ @CreateDateColumn()
96
+ @Field({ nullable: true, description: 'The date and time when the income statement was created' })
97
+ createdAt?: Date // 손익계산서가 생성된 날짜 및 시간
98
+
99
+ @UpdateDateColumn()
100
+ @Field({ nullable: true, description: 'The date and time when the income statement was last updated' })
101
+ updatedAt?: Date // 손익계산서가 마지막으로 업데이트된 날짜 및 시간
102
+
103
+ @DeleteDateColumn()
104
+ @Field({ nullable: true, description: 'The date and time when the income statement was deleted' })
105
+ deletedAt?: Date // 손익계산서가 삭제된 날짜 및 시간
106
+
107
+ @ManyToOne(type => User, { nullable: true })
108
+ @Field(type => User, { nullable: true, description: 'The user who created the income statement' })
109
+ creator?: User // 손익계산서를 생성한 사용자
110
+
111
+ @RelationId((incomeStatement: IncomeStatement) => incomeStatement.creator)
112
+ creatorId?: string // 손익계산서를 생성한 사용자의 ID
113
+
114
+ @ManyToOne(type => User, { nullable: true })
115
+ @Field(type => User, { nullable: true, description: 'The user who last updated the income statement' })
116
+ updater?: User // 손익계산서를 마지막으로 업데이트한 사용자
117
+
118
+ @RelationId((incomeStatement: IncomeStatement) => incomeStatement.updater)
119
+ updaterId?: string // 손익계산서를 업데이트한 사용자의 ID
120
+ }
@@ -0,0 +1,10 @@
1
+ import { IncomeStatement } from './income-statement'
2
+ import { IncomeStatementLineItem } from './income-statement-line-item'
3
+ import { IncomeStatementHistory } from './income-statement-history'
4
+ import { IncomeStatementQuery } from './income-statement-query'
5
+ import { IncomeStatementMutation } from './income-statement-mutation'
6
+ import { IncomeStatementHistoryEntitySubscriber } from './event-subscriber'
7
+
8
+ export const entities = [IncomeStatement, IncomeStatementLineItem, IncomeStatementHistory]
9
+ export const resolvers = [IncomeStatementQuery, IncomeStatementMutation]
10
+ export const subscribers = [IncomeStatementHistoryEntitySubscriber]
@@ -0,0 +1,108 @@
1
+ /* EXPORT ENTITY TYPES */
2
+ export * from './income-statement/income-statement'
3
+ export * from './financial-statement/financial-statement'
4
+ export * from './accounting-category/accounting-category'
5
+ export * from './transaction/transaction'
6
+ export * from './payment/payment'
7
+ export * from './account/account'
8
+ export * from './accounting-document/accounting-document'
9
+ export * from './fiscal-month/fiscal-month'
10
+ export * from './fiscal-quarter/fiscal-quarter'
11
+ export * from './fiscal-year/fiscal-year'
12
+
13
+ /* IMPORT ENTITIES AND RESOLVERS */
14
+ import {
15
+ entities as IncomeStatementEntities,
16
+ resolvers as IncomeStatementResolvers,
17
+ subscribers as IncomeStatementSubscribers
18
+ } from './income-statement'
19
+ import {
20
+ entities as FinancialStatementEntities,
21
+ resolvers as FinancialStatementResolvers,
22
+ subscribers as FinancialStatementSubscribers
23
+ } from './financial-statement'
24
+ import {
25
+ entities as AccountingCategoryEntities,
26
+ resolvers as AccountingCategoryResolvers,
27
+ subscribers as AccountingCategorySubscribers
28
+ } from './accounting-category'
29
+ import {
30
+ entities as TransactionEntities,
31
+ resolvers as TransactionResolvers,
32
+ subscribers as TransactionSubscribers
33
+ } from './transaction'
34
+ import {
35
+ entities as PaymentEntities,
36
+ resolvers as PaymentResolvers,
37
+ subscribers as PaymentSubscribers
38
+ } from './payment'
39
+ import {
40
+ entities as AccountEntities,
41
+ resolvers as AccountResolvers,
42
+ subscribers as AccountSubscribers
43
+ } from './account'
44
+ import {
45
+ entities as AccountingDocumentEntities,
46
+ resolvers as AccountingDocumentResolvers,
47
+ subscribers as AccountingDocumentSubscribers
48
+ } from './accounting-document'
49
+ import {
50
+ entities as FiscalMonthEntities,
51
+ resolvers as FiscalMonthResolvers,
52
+ subscribers as FiscalMonthSubscribers
53
+ } from './fiscal-month'
54
+ import {
55
+ entities as FiscalQuarterEntities,
56
+ resolvers as FiscalQuarterResolvers,
57
+ subscribers as FiscalQuarterSubscribers
58
+ } from './fiscal-quarter'
59
+ import {
60
+ entities as FiscalYearEntities,
61
+ resolvers as FiscalYearResolvers,
62
+ subscribers as FiscalYearSubscribers
63
+ } from './fiscal-year'
64
+
65
+ export const entities = [
66
+ /* ENTITIES */
67
+ ...IncomeStatementEntities,
68
+ ...FinancialStatementEntities,
69
+ ...AccountingCategoryEntities,
70
+ ...TransactionEntities,
71
+ ...AccountEntities,
72
+ ...AccountingDocumentEntities,
73
+ ...PaymentEntities,
74
+ ...FiscalMonthEntities,
75
+ ...FiscalQuarterEntities,
76
+ ...FiscalYearEntities
77
+ ]
78
+
79
+ export const subscribers = [
80
+ /* SUBSCRIBERS */
81
+ ...IncomeStatementSubscribers,
82
+ ...FinancialStatementSubscribers,
83
+ ...AccountingCategorySubscribers,
84
+ ...TransactionSubscribers,
85
+ ...PaymentSubscribers,
86
+ ...AccountSubscribers,
87
+ ...AccountingDocumentSubscribers,
88
+ ...FiscalYearSubscribers,
89
+ ...FiscalMonthSubscribers,
90
+ ...FiscalQuarterSubscribers,
91
+ ...FiscalYearSubscribers
92
+ ]
93
+
94
+ export const schema = {
95
+ resolverClasses: [
96
+ /* RESOLVER CLASSES */
97
+ ...IncomeStatementResolvers,
98
+ ...FinancialStatementResolvers,
99
+ ...AccountingCategoryResolvers,
100
+ ...TransactionResolvers,
101
+ ...PaymentResolvers,
102
+ ...AccountResolvers,
103
+ ...AccountingDocumentResolvers,
104
+ ...FiscalMonthResolvers,
105
+ ...FiscalQuarterResolvers,
106
+ ...FiscalYearResolvers
107
+ ]
108
+ }
@@ -0,0 +1,17 @@
1
+ import { EventSubscriber } from 'typeorm'
2
+
3
+ import { HistoryEntitySubscriber } from '@operato/typeorm-history'
4
+
5
+ import { Payment } from './payment'
6
+ import { PaymentHistory } from './payment-history'
7
+
8
+ @EventSubscriber()
9
+ export class PaymentHistoryEntitySubscriber extends HistoryEntitySubscriber<Payment, PaymentHistory> {
10
+ public get entity() {
11
+ return Payment
12
+ }
13
+
14
+ public get historyEntity() {
15
+ return PaymentHistory
16
+ }
17
+ }
@@ -0,0 +1,9 @@
1
+ import { Payment } from './payment'
2
+ import { PaymentHistory } from './payment-history'
3
+ import { PaymentHistoryEntitySubscriber } from './event-subscriber'
4
+ import { PaymentQuery } from './payment-query'
5
+ import { PaymentMutation } from './payment-mutation'
6
+
7
+ export const entities = [Payment, PaymentHistory]
8
+ export const resolvers = [PaymentQuery, PaymentMutation]
9
+ export const subscribers = [PaymentHistoryEntitySubscriber]
@@ -0,0 +1,132 @@
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 } from '../transaction/transaction'
15
+ import { Payment, PaymentDirection } from './payment'
16
+
17
+ const ORMCONFIG = config.get('ormconfig', {})
18
+ const DATABASE_TYPE = ORMCONFIG.type
19
+
20
+ @Entity()
21
+ @Index(
22
+ 'ix_payment_history_0',
23
+ (paymentHistory: PaymentHistory) => [paymentHistory.originalId, paymentHistory.version],
24
+ { unique: true }
25
+ )
26
+ @Index(
27
+ 'ix_payment_history_1',
28
+ (paymentHistory: PaymentHistory) => [paymentHistory.domain, paymentHistory.originalId, paymentHistory.version],
29
+ { unique: true }
30
+ )
31
+ @ObjectType({ description: 'History Entity of Payment' })
32
+ export class PaymentHistory implements HistoryEntityInterface<Payment> {
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((payment: Payment) => payment.domain)
46
+ domainId?: string
47
+
48
+ @ManyToOne(type => Transaction, transaction => transaction.payments)
49
+ @Field(type => Transaction)
50
+ transaction: Transaction
51
+
52
+ @RelationId((payment: Payment) => payment.transaction)
53
+ transactionId: string
54
+
55
+ @Column({ nullable: false })
56
+ @Field({ nullable: false })
57
+ amount: number
58
+
59
+ @Column({ nullable: true })
60
+ @Field({ nullable: true, description: 'fiscal year' })
61
+ year?: number
62
+
63
+ @Column({ nullable: true })
64
+ @Field({ nullable: true, description: 'fiscal quarter' })
65
+ quarter?: number
66
+
67
+ @Column({ nullable: true })
68
+ @Field({ nullable: true, description: 'fiscal month' })
69
+ month?: number
70
+
71
+ @Column({ nullable: false })
72
+ @Field({ nullable: false })
73
+ paidAt: Date
74
+
75
+ @Column({ nullable: false })
76
+ @Field(type => PaymentDirection)
77
+ direction: PaymentDirection
78
+
79
+ @Column({ nullable: true })
80
+ @Field({ nullable: true })
81
+ note?: string
82
+
83
+ @Column({ nullable: true })
84
+ @Field({ nullable: true })
85
+ createdAt?: Date
86
+
87
+ @Column({ nullable: true })
88
+ @Field({ nullable: true })
89
+ updatedAt?: Date
90
+
91
+ @Column({ nullable: true })
92
+ @Field({ nullable: true })
93
+ deletedAt?: Date
94
+
95
+ @ManyToOne(type => User, { nullable: true })
96
+ @Field(type => User, { nullable: true })
97
+ creator?: User
98
+
99
+ @RelationId((payment: Payment) => payment.creator)
100
+ creatorId?: string
101
+
102
+ @ManyToOne(type => User, { nullable: true })
103
+ @Field(type => User, { nullable: true })
104
+ updater?: User
105
+
106
+ @RelationId((payment: Payment) => payment.updater)
107
+ updaterId?: string
108
+
109
+ @Field(type => String, { nullable: true })
110
+ thumbnail?: string
111
+
112
+ @HistoryOriginalIdColumn()
113
+ public originalId!: string
114
+
115
+ @HistoryActionColumn({
116
+ nullable: false,
117
+ type:
118
+ DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
119
+ ? 'enum'
120
+ : DATABASE_TYPE == 'oracle'
121
+ ? 'varchar2'
122
+ : DATABASE_TYPE == 'mssql'
123
+ ? 'nvarchar'
124
+ : 'varchar',
125
+ enum:
126
+ DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
127
+ ? HistoryActionType
128
+ : undefined,
129
+ length: DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb' ? undefined : 10
130
+ })
131
+ public action!: HistoryActionType
132
+ }
@@ -0,0 +1,139 @@
1
+ import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
2
+ import { In } from 'typeorm'
3
+ import { getRepository } from '@things-factory/shell'
4
+
5
+ import { Payment } from './payment'
6
+ import { NewPayment, PaymentPatch } from './payment-type'
7
+
8
+ @Resolver(Payment)
9
+ export class PaymentMutation {
10
+ @Directive('@transaction')
11
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
12
+ @Mutation(returns => Payment, { description: 'To create new Payment' })
13
+ async createPayment(@Arg('payment') payment: NewPayment, @Ctx() context: ResolverContext): Promise<Payment> {
14
+ const { domain, user, tx } = context.state
15
+
16
+ const result = await getRepository(Payment, tx).save({
17
+ ...payment,
18
+ domain,
19
+ creator: user,
20
+ updater: user
21
+ })
22
+
23
+ return result
24
+ }
25
+
26
+ @Directive('@transaction')
27
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
28
+ @Mutation(returns => Payment, { description: 'To modify Payment information' })
29
+ async updatePayment(
30
+ @Arg('id') id: string,
31
+ @Arg('patch') patch: PaymentPatch,
32
+ @Ctx() context: ResolverContext
33
+ ): Promise<Payment> {
34
+ const { domain, user, tx } = context.state
35
+
36
+ const repository = getRepository(Payment, tx)
37
+ const payment = await repository.findOne({
38
+ where: { domain: { id: domain.id }, id }
39
+ })
40
+
41
+ const result = await repository.save({
42
+ ...payment,
43
+ ...patch,
44
+ updater: user
45
+ })
46
+
47
+ return result
48
+ }
49
+
50
+ @Directive('@transaction')
51
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
52
+ @Mutation(returns => [Payment], { description: "To modify multiple Payments' information" })
53
+ async updateMultiplePayment(
54
+ @Arg('patches', type => [PaymentPatch]) patches: PaymentPatch[],
55
+ @Ctx() context: ResolverContext
56
+ ): Promise<Payment[]> {
57
+ const { domain, user, tx } = context.state
58
+
59
+ let results = []
60
+ const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
61
+ const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
62
+ const paymentRepo = getRepository(Payment, tx)
63
+
64
+ if (_createRecords.length > 0) {
65
+ for (let i = 0; i < _createRecords.length; i++) {
66
+ const newRecord = _createRecords[i]
67
+
68
+ const result = await paymentRepo.save({
69
+ ...newRecord,
70
+ domain,
71
+ creator: user,
72
+ updater: user
73
+ })
74
+
75
+ results.push({ ...result, cuFlag: '+' })
76
+ }
77
+ }
78
+
79
+ if (_updateRecords.length > 0) {
80
+ for (let i = 0; i < _updateRecords.length; i++) {
81
+ const updateRecord = _updateRecords[i]
82
+ const payment = await paymentRepo.findOneBy({ id: updateRecord.id })
83
+
84
+ const result = await paymentRepo.save({
85
+ ...payment,
86
+ ...updateRecord,
87
+ updater: user
88
+ })
89
+
90
+ results.push({ ...result, cuFlag: 'M' })
91
+ }
92
+ }
93
+
94
+ return results
95
+ }
96
+
97
+ @Directive('@transaction')
98
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
99
+ @Mutation(returns => Boolean, { description: 'To delete Payment' })
100
+ async deletePayment(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
101
+ const { domain, tx } = context.state
102
+
103
+ await getRepository(Payment, tx).delete({ domain: { id: domain.id }, id })
104
+
105
+ return true
106
+ }
107
+
108
+ @Directive('@transaction')
109
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
110
+ @Mutation(returns => Boolean, { description: 'To delete multiple Payments' })
111
+ async deletePayments(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<boolean> {
112
+ const { domain, tx } = context.state
113
+
114
+ await getRepository(Payment, tx).delete({
115
+ domain: { id: domain.id },
116
+ id: In(ids)
117
+ })
118
+
119
+ return true
120
+ }
121
+
122
+ @Directive('@transaction')
123
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
124
+ @Mutation(returns => Boolean, { description: 'To import multiple Payments' })
125
+ async importPayments(
126
+ @Arg('payments', type => [PaymentPatch]) payments: PaymentPatch[],
127
+ @Ctx() context: ResolverContext
128
+ ): Promise<boolean> {
129
+ const { domain, tx } = context.state
130
+
131
+ await Promise.all(
132
+ payments.map(async (payment: PaymentPatch) => {
133
+ const createdPayment: Payment = await getRepository(Payment, tx).save({ domain, ...payment })
134
+ })
135
+ )
136
+
137
+ return true
138
+ }
139
+ }
@@ -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 { Payment } from './payment'
5
+ import { PaymentList } from './payment-type'
6
+
7
+ @Resolver(Payment)
8
+ export class PaymentQuery {
9
+ @Directive('@privilege(category: "accounting", privilege: "query")')
10
+ @Query(returns => Payment!, { nullable: true, description: 'To fetch a Payment' })
11
+ async payment(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Payment> {
12
+ const { domain } = context.state
13
+
14
+ return await getRepository(Payment).findOne({
15
+ where: { domain: { id: domain.id }, id }
16
+ })
17
+ }
18
+
19
+ @Directive('@privilege(category: "accounting", privilege: "query")')
20
+ @Query(returns => PaymentList, { description: 'To fetch multiple Payments' })
21
+ async payments(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<PaymentList> {
22
+ const { domain } = context.state
23
+
24
+ const queryBuilder = getQueryBuilderFromListParams({
25
+ domain,
26
+ params,
27
+ repository: await getRepository(Payment),
28
+ searchables: []
29
+ })
30
+
31
+ const [items, total] = await queryBuilder.getManyAndCount()
32
+
33
+ return { items, total }
34
+ }
35
+
36
+ @FieldResolver(type => Domain)
37
+ async domain(@Root() payment: Payment): Promise<Domain> {
38
+ return payment.domainId && (await getRepository(Domain).findOneBy({ id: payment.domainId }))
39
+ }
40
+
41
+ @FieldResolver(type => User)
42
+ async updater(@Root() payment: Payment): Promise<User> {
43
+ return payment.updaterId && (await getRepository(User).findOneBy({ id: payment.updaterId }))
44
+ }
45
+
46
+ @FieldResolver(type => User)
47
+ async creator(@Root() payment: Payment): Promise<User> {
48
+ return payment.creatorId && (await getRepository(User).findOneBy({ id: payment.creatorId }))
49
+ }
50
+ }
@@ -0,0 +1,64 @@
1
+ import type { FileUpload } from 'graphql-upload/GraphQLUpload.js'
2
+ import GraphQLUpload from 'graphql-upload/GraphQLUpload.js'
3
+ import { ObjectType, Field, InputType, Int, ID, registerEnumType } from 'type-graphql'
4
+
5
+ import { ObjectRef, ScalarObject } from '@things-factory/shell'
6
+
7
+ import { Payment, PaymentDirection } from './payment'
8
+
9
+ @InputType()
10
+ export class NewPayment {
11
+ @Field(type => ObjectRef)
12
+ transaction: ObjectRef
13
+
14
+ @Field({ nullable: true })
15
+ currency?: string
16
+
17
+ @Field({ nullable: false })
18
+ amount: number
19
+
20
+ @Field({ nullable: false })
21
+ paidAt: Date
22
+
23
+ @Field(type => PaymentDirection)
24
+ direction: PaymentDirection
25
+
26
+ @Field({ nullable: true })
27
+ note?: string
28
+ }
29
+
30
+ @InputType()
31
+ export class PaymentPatch {
32
+ @Field(type => ID, { nullable: true })
33
+ id?: string
34
+
35
+ @Field(type => ObjectRef)
36
+ transaction: ObjectRef
37
+
38
+ @Field({ nullable: true })
39
+ currency?: string
40
+
41
+ @Field({ nullable: false })
42
+ amount: number
43
+
44
+ @Field({ nullable: false })
45
+ paidAt: Date
46
+
47
+ @Field(type => PaymentDirection)
48
+ direction: PaymentDirection
49
+
50
+ @Field({ nullable: true })
51
+ note?: string
52
+
53
+ @Field({ nullable: true })
54
+ cuFlag?: string
55
+ }
56
+
57
+ @ObjectType()
58
+ export class PaymentList {
59
+ @Field(type => [Payment])
60
+ items: Payment[]
61
+
62
+ @Field(type => Int)
63
+ total: number
64
+ }