@things-factory/accounting 6.0.46

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 (227) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +31 -0
  3. package/assets/images/book-activity.jpg +0 -0
  4. package/assets/images/expense-activity.jpg +0 -0
  5. package/assets/images/hatiolab-logo.png +0 -0
  6. package/client/activities/activity-book-edit.ts +88 -0
  7. package/client/activities/activity-book-view.ts +88 -0
  8. package/client/activities/activity-expense-edit.ts +88 -0
  9. package/client/activities/activity-expense-view.ts +88 -0
  10. package/client/bootstrap.ts +1 -0
  11. package/client/index.ts +0 -0
  12. package/client/pages/account/account-importer.ts +97 -0
  13. package/client/pages/account/account-list-page.ts +348 -0
  14. package/client/pages/accounting-category/accounting-category-importer.ts +97 -0
  15. package/client/pages/accounting-category/accounting-category-list-page.ts +348 -0
  16. package/client/pages/financial-statement/financial-statement-importer.ts +97 -0
  17. package/client/pages/financial-statement/financial-statement-list-page.ts +348 -0
  18. package/client/pages/income-statement/income-statement-importer.ts +97 -0
  19. package/client/pages/income-statement/income-statement-list-page.ts +348 -0
  20. package/client/pages/ledger/ledger-importer.ts +97 -0
  21. package/client/pages/ledger/ledger-list-page.ts +332 -0
  22. package/client/pages/main.ts +24 -0
  23. package/client/pages/transaction/transaction-importer.ts +97 -0
  24. package/client/pages/transaction/transaction-list-page.ts +348 -0
  25. package/client/route.ts +27 -0
  26. package/client/tsconfig.json +11 -0
  27. package/dist-client/activities/activity-book-edit.d.ts +14 -0
  28. package/dist-client/activities/activity-book-edit.js +85 -0
  29. package/dist-client/activities/activity-book-edit.js.map +1 -0
  30. package/dist-client/activities/activity-book-view.d.ts +14 -0
  31. package/dist-client/activities/activity-book-view.js +85 -0
  32. package/dist-client/activities/activity-book-view.js.map +1 -0
  33. package/dist-client/activities/activity-expense-edit.d.ts +14 -0
  34. package/dist-client/activities/activity-expense-edit.js +85 -0
  35. package/dist-client/activities/activity-expense-edit.js.map +1 -0
  36. package/dist-client/activities/activity-expense-view.d.ts +14 -0
  37. package/dist-client/activities/activity-expense-view.js +85 -0
  38. package/dist-client/activities/activity-expense-view.js.map +1 -0
  39. package/dist-client/bootstrap.d.ts +1 -0
  40. package/dist-client/bootstrap.js +2 -0
  41. package/dist-client/bootstrap.js.map +1 -0
  42. package/dist-client/index.d.ts +0 -0
  43. package/dist-client/index.js +2 -0
  44. package/dist-client/index.js.map +1 -0
  45. package/dist-client/pages/account/account-importer.d.ts +22 -0
  46. package/dist-client/pages/account/account-importer.js +100 -0
  47. package/dist-client/pages/account/account-importer.js.map +1 -0
  48. package/dist-client/pages/account/account-list-page.d.ts +62 -0
  49. package/dist-client/pages/account/account-list-page.js +326 -0
  50. package/dist-client/pages/account/account-list-page.js.map +1 -0
  51. package/dist-client/pages/accounting-category/accounting-category-importer.d.ts +22 -0
  52. package/dist-client/pages/accounting-category/accounting-category-importer.js +100 -0
  53. package/dist-client/pages/accounting-category/accounting-category-importer.js.map +1 -0
  54. package/dist-client/pages/accounting-category/accounting-category-list-page.d.ts +62 -0
  55. package/dist-client/pages/accounting-category/accounting-category-list-page.js +326 -0
  56. package/dist-client/pages/accounting-category/accounting-category-list-page.js.map +1 -0
  57. package/dist-client/pages/financial-statement/financial-statement-importer.d.ts +22 -0
  58. package/dist-client/pages/financial-statement/financial-statement-importer.js +100 -0
  59. package/dist-client/pages/financial-statement/financial-statement-importer.js.map +1 -0
  60. package/dist-client/pages/financial-statement/financial-statement-list-page.d.ts +62 -0
  61. package/dist-client/pages/financial-statement/financial-statement-list-page.js +326 -0
  62. package/dist-client/pages/financial-statement/financial-statement-list-page.js.map +1 -0
  63. package/dist-client/pages/income-statement/income-statement-importer.d.ts +22 -0
  64. package/dist-client/pages/income-statement/income-statement-importer.js +100 -0
  65. package/dist-client/pages/income-statement/income-statement-importer.js.map +1 -0
  66. package/dist-client/pages/income-statement/income-statement-list-page.d.ts +62 -0
  67. package/dist-client/pages/income-statement/income-statement-list-page.js +326 -0
  68. package/dist-client/pages/income-statement/income-statement-list-page.js.map +1 -0
  69. package/dist-client/pages/ledger/ledger-importer.d.ts +22 -0
  70. package/dist-client/pages/ledger/ledger-importer.js +100 -0
  71. package/dist-client/pages/ledger/ledger-importer.js.map +1 -0
  72. package/dist-client/pages/ledger/ledger-list-page.d.ts +62 -0
  73. package/dist-client/pages/ledger/ledger-list-page.js +317 -0
  74. package/dist-client/pages/ledger/ledger-list-page.js.map +1 -0
  75. package/dist-client/pages/main.d.ts +1 -0
  76. package/dist-client/pages/main.js +27 -0
  77. package/dist-client/pages/main.js.map +1 -0
  78. package/dist-client/pages/transaction/transaction-importer.d.ts +22 -0
  79. package/dist-client/pages/transaction/transaction-importer.js +100 -0
  80. package/dist-client/pages/transaction/transaction-importer.js.map +1 -0
  81. package/dist-client/pages/transaction/transaction-list-page.d.ts +62 -0
  82. package/dist-client/pages/transaction/transaction-list-page.js +326 -0
  83. package/dist-client/pages/transaction/transaction-list-page.js.map +1 -0
  84. package/dist-client/route.d.ts +1 -0
  85. package/dist-client/route.js +23 -0
  86. package/dist-client/route.js.map +1 -0
  87. package/dist-client/tsconfig.tsbuildinfo +1 -0
  88. package/dist-server/activities/activity-book.js +150 -0
  89. package/dist-server/activities/activity-book.js.map +1 -0
  90. package/dist-server/activities/activity-expense.js +150 -0
  91. package/dist-server/activities/activity-expense.js.map +1 -0
  92. package/dist-server/activities/index.js +19 -0
  93. package/dist-server/activities/index.js.map +1 -0
  94. package/dist-server/controllers/index.js +1 -0
  95. package/dist-server/controllers/index.js.map +1 -0
  96. package/dist-server/index.js +7 -0
  97. package/dist-server/index.js.map +1 -0
  98. package/dist-server/middlewares/index.js +8 -0
  99. package/dist-server/middlewares/index.js.map +1 -0
  100. package/dist-server/migrations/index.js +12 -0
  101. package/dist-server/migrations/index.js.map +1 -0
  102. package/dist-server/routes.js +25 -0
  103. package/dist-server/routes.js.map +1 -0
  104. package/dist-server/service/account/account-history.js +113 -0
  105. package/dist-server/service/account/account-history.js.map +1 -0
  106. package/dist-server/service/account/account-mutation.js +130 -0
  107. package/dist-server/service/account/account-mutation.js.map +1 -0
  108. package/dist-server/service/account/account-query.js +79 -0
  109. package/dist-server/service/account/account-query.js.map +1 -0
  110. package/dist-server/service/account/account-type.js +65 -0
  111. package/dist-server/service/account/account-type.js.map +1 -0
  112. package/dist-server/service/account/account.js +102 -0
  113. package/dist-server/service/account/account.js.map +1 -0
  114. package/dist-server/service/account/event-subscriber.js +21 -0
  115. package/dist-server/service/account/event-subscriber.js.map +1 -0
  116. package/dist-server/service/account/index.js +12 -0
  117. package/dist-server/service/account/index.js.map +1 -0
  118. package/dist-server/service/accounting-category/accounting-category-mutation.js +132 -0
  119. package/dist-server/service/accounting-category/accounting-category-mutation.js.map +1 -0
  120. package/dist-server/service/accounting-category/accounting-category-query.js +79 -0
  121. package/dist-server/service/accounting-category/accounting-category-query.js.map +1 -0
  122. package/dist-server/service/accounting-category/accounting-category-type.js +65 -0
  123. package/dist-server/service/accounting-category/accounting-category-type.js.map +1 -0
  124. package/dist-server/service/accounting-category/accounting-category.js +89 -0
  125. package/dist-server/service/accounting-category/accounting-category.js.map +1 -0
  126. package/dist-server/service/accounting-category/index.js +10 -0
  127. package/dist-server/service/accounting-category/index.js.map +1 -0
  128. package/dist-server/service/financial-statement/event-subscriber.js +21 -0
  129. package/dist-server/service/financial-statement/event-subscriber.js.map +1 -0
  130. package/dist-server/service/financial-statement/financial-statement-history.js +126 -0
  131. package/dist-server/service/financial-statement/financial-statement-history.js.map +1 -0
  132. package/dist-server/service/financial-statement/financial-statement-mutation.js +132 -0
  133. package/dist-server/service/financial-statement/financial-statement-mutation.js.map +1 -0
  134. package/dist-server/service/financial-statement/financial-statement-query.js +79 -0
  135. package/dist-server/service/financial-statement/financial-statement-query.js.map +1 -0
  136. package/dist-server/service/financial-statement/financial-statement-type.js +77 -0
  137. package/dist-server/service/financial-statement/financial-statement-type.js.map +1 -0
  138. package/dist-server/service/financial-statement/financial-statement.js +111 -0
  139. package/dist-server/service/financial-statement/financial-statement.js.map +1 -0
  140. package/dist-server/service/financial-statement/index.js +12 -0
  141. package/dist-server/service/financial-statement/index.js.map +1 -0
  142. package/dist-server/service/income-statement/event-subscriber.js +21 -0
  143. package/dist-server/service/income-statement/event-subscriber.js.map +1 -0
  144. package/dist-server/service/income-statement/income-statement-history.js +126 -0
  145. package/dist-server/service/income-statement/income-statement-history.js.map +1 -0
  146. package/dist-server/service/income-statement/income-statement-mutation.js +132 -0
  147. package/dist-server/service/income-statement/income-statement-mutation.js.map +1 -0
  148. package/dist-server/service/income-statement/income-statement-query.js +79 -0
  149. package/dist-server/service/income-statement/income-statement-query.js.map +1 -0
  150. package/dist-server/service/income-statement/income-statement-type.js +77 -0
  151. package/dist-server/service/income-statement/income-statement-type.js.map +1 -0
  152. package/dist-server/service/income-statement/income-statement.js +117 -0
  153. package/dist-server/service/income-statement/income-statement.js.map +1 -0
  154. package/dist-server/service/income-statement/index.js +12 -0
  155. package/dist-server/service/income-statement/index.js.map +1 -0
  156. package/dist-server/service/index.js +43 -0
  157. package/dist-server/service/index.js.map +1 -0
  158. package/dist-server/service/transaction/event-subscriber.js +21 -0
  159. package/dist-server/service/transaction/event-subscriber.js.map +1 -0
  160. package/dist-server/service/transaction/index.js +12 -0
  161. package/dist-server/service/transaction/index.js.map +1 -0
  162. package/dist-server/service/transaction/transaction-history.js +123 -0
  163. package/dist-server/service/transaction/transaction-history.js.map +1 -0
  164. package/dist-server/service/transaction/transaction-mutation.js +130 -0
  165. package/dist-server/service/transaction/transaction-mutation.js.map +1 -0
  166. package/dist-server/service/transaction/transaction-query.js +79 -0
  167. package/dist-server/service/transaction/transaction-query.js.map +1 -0
  168. package/dist-server/service/transaction/transaction-type.js +73 -0
  169. package/dist-server/service/transaction/transaction-type.js.map +1 -0
  170. package/dist-server/service/transaction/transaction.js +130 -0
  171. package/dist-server/service/transaction/transaction.js.map +1 -0
  172. package/dist-server/tsconfig.tsbuildinfo +1 -0
  173. package/helps/accounting/account.md +160 -0
  174. package/helps/accounting/accounting-category.md +160 -0
  175. package/helps/accounting/financial-accounting.md +53 -0
  176. package/helps/accounting/financial-statement.md +160 -0
  177. package/helps/accounting/income-statement.md +160 -0
  178. package/helps/accounting/transaction.md +160 -0
  179. package/package.json +36 -0
  180. package/server/activities/activity-book.ts +149 -0
  181. package/server/activities/activity-expense.ts +149 -0
  182. package/server/activities/index.ts +19 -0
  183. package/server/controllers/index.ts +0 -0
  184. package/server/index.ts +4 -0
  185. package/server/middlewares/index.ts +3 -0
  186. package/server/migrations/index.ts +9 -0
  187. package/server/routes.ts +28 -0
  188. package/server/service/account/account-history.ts +103 -0
  189. package/server/service/account/account-mutation.ts +137 -0
  190. package/server/service/account/account-query.ts +49 -0
  191. package/server/service/account/account-type.ts +44 -0
  192. package/server/service/account/account.ts +86 -0
  193. package/server/service/account/event-subscriber.ts +17 -0
  194. package/server/service/account/index.ts +9 -0
  195. package/server/service/accounting-category/accounting-category-mutation.ts +145 -0
  196. package/server/service/accounting-category/accounting-category-query.ts +51 -0
  197. package/server/service/accounting-category/accounting-category-type.ts +42 -0
  198. package/server/service/accounting-category/accounting-category.ts +80 -0
  199. package/server/service/accounting-category/index.ts +7 -0
  200. package/server/service/financial-statement/event-subscriber.ts +17 -0
  201. package/server/service/financial-statement/financial-statement-history.ts +114 -0
  202. package/server/service/financial-statement/financial-statement-mutation.ts +145 -0
  203. package/server/service/financial-statement/financial-statement-query.ts +51 -0
  204. package/server/service/financial-statement/financial-statement-type.ts +51 -0
  205. package/server/service/financial-statement/financial-statement.ts +100 -0
  206. package/server/service/financial-statement/index.ts +9 -0
  207. package/server/service/income-statement/event-subscriber.ts +17 -0
  208. package/server/service/income-statement/income-statement-history.ts +114 -0
  209. package/server/service/income-statement/income-statement-mutation.ts +145 -0
  210. package/server/service/income-statement/income-statement-query.ts +48 -0
  211. package/server/service/income-statement/income-statement-type.ts +51 -0
  212. package/server/service/income-statement/income-statement.ts +105 -0
  213. package/server/service/income-statement/index.ts +9 -0
  214. package/server/service/index.ts +62 -0
  215. package/server/service/transaction/event-subscriber.ts +17 -0
  216. package/server/service/transaction/index.ts +9 -0
  217. package/server/service/transaction/transaction-history.ts +111 -0
  218. package/server/service/transaction/transaction-mutation.ts +143 -0
  219. package/server/service/transaction/transaction-query.ts +48 -0
  220. package/server/service/transaction/transaction-type.ts +48 -0
  221. package/server/service/transaction/transaction.ts +115 -0
  222. package/server/tsconfig.json +10 -0
  223. package/things-factory.config.js +16 -0
  224. package/translations/en.json +1 -0
  225. package/translations/ko.json +1 -0
  226. package/translations/ms.json +1 -0
  227. package/translations/zh.json +1 -0
@@ -0,0 +1,114 @@
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 { FinancialStatement, FinancialStatementStatus } from './financial-statement'
15
+
16
+ const ORMCONFIG = config.get('ormconfig', {})
17
+ const DATABASE_TYPE = ORMCONFIG.type
18
+
19
+ @Entity()
20
+ @Index(
21
+ 'ix_financial-statement_history_0',
22
+ (financialStatementHistory: FinancialStatementHistory) => [
23
+ financialStatementHistory.originalId,
24
+ financialStatementHistory.version
25
+ ],
26
+ { unique: true }
27
+ )
28
+ @Index(
29
+ 'ix_financial-statement_history_1',
30
+ (financialStatementHistory: FinancialStatementHistory) => [
31
+ financialStatementHistory.domain,
32
+ financialStatementHistory.originalId,
33
+ financialStatementHistory.version
34
+ ],
35
+ { unique: true }
36
+ )
37
+ @ObjectType({ description: 'History Entity of FinancialStatement' })
38
+ export class FinancialStatementHistory implements HistoryEntityInterface<FinancialStatement> {
39
+ @PrimaryGeneratedColumn('uuid')
40
+ @Field(type => ID)
41
+ readonly id: string
42
+
43
+ @Column({ nullable: true, default: 1 })
44
+ @Field({ nullable: true })
45
+ version?: number = 1
46
+
47
+ @ManyToOne(type => Domain)
48
+ @Field({ nullable: true })
49
+ domain?: Domain
50
+
51
+ @RelationId((financialStatement: FinancialStatement) => financialStatement.domain)
52
+ domainId?: string
53
+
54
+ @Column()
55
+ @Field()
56
+ name: string
57
+
58
+ @Column({ nullable: true })
59
+ @Field({ nullable: true })
60
+ description?: string
61
+
62
+ @Column({ nullable: true })
63
+ @Field({ nullable: true })
64
+ active?: boolean
65
+
66
+ @Column({ nullable: true })
67
+ @Field({ nullable: true })
68
+ state?: FinancialStatementStatus
69
+
70
+ @Column({ nullable: true })
71
+ @Field({ nullable: true })
72
+ params?: string
73
+
74
+ @Column({ nullable: true })
75
+ @Field({ nullable: true })
76
+ createdAt?: Date
77
+
78
+ @Column({ nullable: true })
79
+ @Field({ nullable: true })
80
+ updatedAt?: Date
81
+
82
+ @Column({ nullable: true })
83
+ @Field({ nullable: true })
84
+ deletedAt?: Date
85
+
86
+ @ManyToOne(type => User, { nullable: true })
87
+ @Field({ nullable: true })
88
+ creator?: User
89
+
90
+ @RelationId((financialStatement: FinancialStatement) => financialStatement.creator)
91
+ creatorId?: string
92
+
93
+ @ManyToOne(type => User, { nullable: true })
94
+ @Field({ nullable: true })
95
+ updater?: User
96
+
97
+ @RelationId((financialStatement: FinancialStatement) => financialStatement.updater)
98
+ updaterId?: string
99
+
100
+ @HistoryOriginalIdColumn()
101
+ public originalId!: string
102
+
103
+ @HistoryActionColumn({
104
+ nullable: false,
105
+ type:
106
+ DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
107
+ ? 'enum'
108
+ : DATABASE_TYPE == 'oracle'
109
+ ? 'varchar2'
110
+ : 'smallint',
111
+ enum: HistoryActionType
112
+ })
113
+ public action!: HistoryActionType
114
+ }
@@ -0,0 +1,145 @@
1
+ import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
2
+ import { In } from 'typeorm'
3
+
4
+ import { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'
5
+
6
+ import { FinancialStatement } from './financial-statement'
7
+ import { NewFinancialStatement, FinancialStatementPatch } from './financial-statement-type'
8
+
9
+ @Resolver(FinancialStatement)
10
+ export class FinancialStatementMutation {
11
+ @Directive('@transaction')
12
+ @Mutation(returns => FinancialStatement, { description: 'To create new FinancialStatement' })
13
+ async createFinancialStatement(
14
+ @Arg('financialStatement') financialStatement: NewFinancialStatement,
15
+ @Ctx() context: ResolverContext
16
+ ): Promise<FinancialStatement> {
17
+ const { domain, user, tx } = context.state
18
+
19
+ const result = await tx.getRepository(FinancialStatement).save({
20
+ ...financialStatement,
21
+ domain,
22
+ creator: user,
23
+ updater: user
24
+ })
25
+
26
+ return result
27
+ }
28
+
29
+ @Directive('@transaction')
30
+ @Mutation(returns => FinancialStatement, { description: 'To modify FinancialStatement information' })
31
+ async updateFinancialStatement(
32
+ @Arg('id') id: string,
33
+ @Arg('patch') patch: FinancialStatementPatch,
34
+ @Ctx() context: ResolverContext
35
+ ): Promise<FinancialStatement> {
36
+ const { domain, user, tx } = context.state
37
+
38
+ const repository = tx.getRepository(FinancialStatement)
39
+ const financialStatement = await repository.findOne({
40
+ where: { domain: { id: domain.id }, id }
41
+ })
42
+
43
+ const result = await repository.save({
44
+ ...financialStatement,
45
+ ...patch,
46
+ updater: user
47
+ })
48
+
49
+ return result
50
+ }
51
+
52
+ @Directive('@transaction')
53
+ @Mutation(returns => [FinancialStatement], { description: "To modify multiple FinancialStatements' information" })
54
+ async updateMultipleFinancialStatement(
55
+ @Arg('patches', type => [FinancialStatementPatch]) patches: FinancialStatementPatch[],
56
+ @Ctx() context: ResolverContext
57
+ ): Promise<FinancialStatement[]> {
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 financialStatementRepo = tx.getRepository(FinancialStatement)
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 financialStatementRepo.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 financialStatement = await financialStatementRepo.findOneBy({ id: updateRecord.id })
84
+
85
+ const result = await financialStatementRepo.save({
86
+ ...financialStatement,
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
+ @Mutation(returns => Boolean, { description: 'To delete FinancialStatement' })
100
+ async deleteFinancialStatement(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
101
+ const { domain, tx } = context.state
102
+
103
+ await tx.getRepository(FinancialStatement).delete({ domain: { id: domain.id }, id })
104
+ await deleteAttachmentsByRef(null, { refBys: [id] }, context)
105
+
106
+ return true
107
+ }
108
+
109
+ @Directive('@transaction')
110
+ @Mutation(returns => Boolean, { description: 'To delete multiple FinancialStatements' })
111
+ async deleteFinancialStatements(
112
+ @Arg('ids', type => [String]) ids: string[],
113
+ @Ctx() context: ResolverContext
114
+ ): Promise<boolean> {
115
+ const { domain, tx } = context.state
116
+
117
+ await tx.getRepository(FinancialStatement).delete({
118
+ domain: { id: domain.id },
119
+ id: In(ids)
120
+ })
121
+
122
+ await deleteAttachmentsByRef(null, { refBys: ids }, context)
123
+
124
+ return true
125
+ }
126
+
127
+ @Directive('@transaction')
128
+ @Mutation(returns => Boolean, { description: 'To import multiple FinancialStatements' })
129
+ async importFinancialStatements(
130
+ @Arg('financialStatements', type => [FinancialStatementPatch]) financialStatements: FinancialStatementPatch[],
131
+ @Ctx() context: ResolverContext
132
+ ): Promise<boolean> {
133
+ const { domain, tx } = context.state
134
+
135
+ await Promise.all(
136
+ financialStatements.map(async (financialStatement: FinancialStatementPatch) => {
137
+ const createdFinancialStatement: FinancialStatement = await tx
138
+ .getRepository(FinancialStatement)
139
+ .save({ domain, ...financialStatement })
140
+ })
141
+ )
142
+
143
+ return true
144
+ }
145
+ }
@@ -0,0 +1,51 @@
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 { FinancialStatement } from './financial-statement'
5
+ import { FinancialStatementList } from './financial-statement-type'
6
+
7
+ @Resolver(FinancialStatement)
8
+ export class FinancialStatementQuery {
9
+ @Query(returns => FinancialStatement!, { nullable: true, description: 'To fetch a FinancialStatement' })
10
+ async financialStatement(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<FinancialStatement> {
11
+ const { domain } = context.state
12
+
13
+ return await getRepository(FinancialStatement).findOne({
14
+ where: { domain: { id: domain.id }, id }
15
+ })
16
+ }
17
+
18
+ @Query(returns => FinancialStatementList, { description: 'To fetch multiple FinancialStatements' })
19
+ async financialStatements(
20
+ @Args() params: ListParam,
21
+ @Ctx() context: ResolverContext
22
+ ): Promise<FinancialStatementList> {
23
+ const { domain } = context.state
24
+
25
+ const queryBuilder = getQueryBuilderFromListParams({
26
+ domain,
27
+ params,
28
+ repository: await getRepository(FinancialStatement),
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() financialStatement: FinancialStatement): Promise<Domain> {
39
+ return await getRepository(Domain).findOneBy({ id: financialStatement.domainId })
40
+ }
41
+
42
+ @FieldResolver(type => User)
43
+ async updater(@Root() financialStatement: FinancialStatement): Promise<User> {
44
+ return await getRepository(User).findOneBy({ id: financialStatement.updaterId })
45
+ }
46
+
47
+ @FieldResolver(type => User)
48
+ async creator(@Root() financialStatement: FinancialStatement): Promise<User> {
49
+ return await getRepository(User).findOneBy({ id: financialStatement.creatorId })
50
+ }
51
+ }
@@ -0,0 +1,51 @@
1
+ import { ObjectType, Field, InputType, Int, ID, registerEnumType } from 'type-graphql'
2
+
3
+ import { FinancialStatement, FinancialStatementStatus } from './financial-statement'
4
+
5
+ @InputType()
6
+ export class NewFinancialStatement {
7
+ @Field()
8
+ name: string
9
+
10
+ @Field({ nullable: true })
11
+ description?: string
12
+
13
+ @Field(type => FinancialStatementStatus, { nullable: true })
14
+ state?: FinancialStatementStatus
15
+
16
+ @Field({ nullable: true })
17
+ active?: boolean
18
+
19
+ @Field({ nullable: true })
20
+ params?: string
21
+ }
22
+
23
+ @InputType()
24
+ export class FinancialStatementPatch {
25
+ @Field(type => ID, { nullable: true })
26
+ id?: string
27
+
28
+ @Field({ nullable: true })
29
+ name?: string
30
+
31
+ @Field({ nullable: true })
32
+ description?: string
33
+
34
+ @Field(type => FinancialStatementStatus, { nullable: true })
35
+ state?: FinancialStatementStatus
36
+
37
+ @Field({ nullable: true })
38
+ active?: boolean
39
+
40
+ @Field({ nullable: true })
41
+ cuFlag?: string
42
+ }
43
+
44
+ @ObjectType()
45
+ export class FinancialStatementList {
46
+ @Field(type => [FinancialStatement])
47
+ items: FinancialStatement[]
48
+
49
+ @Field(type => Int)
50
+ total: number
51
+ }
@@ -0,0 +1,100 @@
1
+ import {
2
+ CreateDateColumn,
3
+ UpdateDateColumn,
4
+ DeleteDateColumn,
5
+ Entity,
6
+ Index,
7
+ Column,
8
+ RelationId,
9
+ ManyToOne,
10
+ PrimaryGeneratedColumn,
11
+ VersionColumn
12
+ } from 'typeorm'
13
+ import { ObjectType, Field, Int, ID, registerEnumType } from 'type-graphql'
14
+
15
+ import { Domain } from '@things-factory/shell'
16
+ import { User } from '@things-factory/auth-base'
17
+
18
+ export enum FinancialStatementStatus {
19
+ STATUS_A = 'STATUS_A',
20
+ STATUS_B = 'STATUS_B'
21
+ }
22
+
23
+ registerEnumType(FinancialStatementStatus, {
24
+ name: 'FinancialStatementStatus',
25
+ description: 'state enumeration of a financialStatement'
26
+ })
27
+
28
+ @Entity()
29
+ @Index(
30
+ 'ix_financial_statement_0',
31
+ (financialStatement: FinancialStatement) => [financialStatement.domain, financialStatement.deletedAt],
32
+ { unique: true }
33
+ )
34
+ @ObjectType({ description: 'Entity for FinancialStatement' })
35
+ export class FinancialStatement {
36
+ @PrimaryGeneratedColumn('uuid')
37
+ @Field(type => ID)
38
+ readonly id: string
39
+
40
+ @VersionColumn()
41
+ @Field({ nullable: true })
42
+ version?: number = 1
43
+
44
+ @ManyToOne(type => Domain)
45
+ @Field({ nullable: true })
46
+ domain?: Domain
47
+
48
+ @RelationId((financialStatement: FinancialStatement) => financialStatement.domain)
49
+ domainId?: string
50
+
51
+ @Column({ nullable: true })
52
+ @Field({ nullable: true, description: 'fiscal year' })
53
+ year?: number
54
+
55
+ @Column({ nullable: true })
56
+ @Field({ nullable: true, description: 'fiscal quarter' })
57
+ quarter?: number
58
+
59
+ @Column({ nullable: true })
60
+ @Field({ nullable: true })
61
+ month?: number
62
+
63
+ @Column({ nullable: true })
64
+ @Field({ nullable: true })
65
+ asset?: number
66
+
67
+ @Column({ nullable: true })
68
+ @Field({ nullable: true })
69
+ liability?: number
70
+
71
+ @Column({ nullable: true })
72
+ @Field({ nullable: true })
73
+ equity?: number
74
+
75
+ @CreateDateColumn()
76
+ @Field({ nullable: true })
77
+ createdAt?: Date
78
+
79
+ @UpdateDateColumn()
80
+ @Field({ nullable: true })
81
+ updatedAt?: Date
82
+
83
+ @DeleteDateColumn()
84
+ @Field({ nullable: true })
85
+ deletedAt?: Date
86
+
87
+ @ManyToOne(type => User, { nullable: true })
88
+ @Field(type => User, { nullable: true })
89
+ creator?: User
90
+
91
+ @RelationId((financialStatement: FinancialStatement) => financialStatement.creator)
92
+ creatorId?: string
93
+
94
+ @ManyToOne(type => User, { nullable: true })
95
+ @Field(type => User, { nullable: true })
96
+ updater?: User
97
+
98
+ @RelationId((financialStatement: FinancialStatement) => financialStatement.updater)
99
+ updaterId?: string
100
+ }
@@ -0,0 +1,9 @@
1
+ import { FinancialStatement } from './financial-statement'
2
+ import { FinancialStatementHistory } from './financial-statement-history'
3
+ import { FinancialStatementQuery } from './financial-statement-query'
4
+ import { FinancialStatementMutation } from './financial-statement-mutation'
5
+ import { FinancialStatementHistoryEntitySubscriber } from './event-subscriber'
6
+
7
+ export const entities = [FinancialStatement, FinancialStatementHistory]
8
+ export const resolvers = [FinancialStatementQuery, FinancialStatementMutation]
9
+ export const subscribers = [FinancialStatementHistoryEntitySubscriber]
@@ -0,0 +1,17 @@
1
+ import { EventSubscriber } from 'typeorm'
2
+
3
+ import { HistoryEntitySubscriber } from '@operato/typeorm-history'
4
+
5
+ import { IncomeStatement } from './income-statement'
6
+ import { IncomeStatementHistory } from './income-statement-history'
7
+
8
+ @EventSubscriber()
9
+ export class IncomeStatementHistoryEntitySubscriber extends HistoryEntitySubscriber<IncomeStatement, IncomeStatementHistory> {
10
+ public get entity() {
11
+ return IncomeStatement
12
+ }
13
+
14
+ public get historyEntity() {
15
+ return IncomeStatementHistory
16
+ }
17
+ }
@@ -0,0 +1,114 @@
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 { IncomeStatement, IncomeStatementStatus } from './income-statement'
15
+
16
+ const ORMCONFIG = config.get('ormconfig', {})
17
+ const DATABASE_TYPE = ORMCONFIG.type
18
+
19
+ @Entity()
20
+ @Index(
21
+ 'ix_income-statement_history_0',
22
+ (incomeStatementHistory: IncomeStatementHistory) => [
23
+ incomeStatementHistory.originalId,
24
+ incomeStatementHistory.version
25
+ ],
26
+ { unique: true }
27
+ )
28
+ @Index(
29
+ 'ix_income-statement_history_1',
30
+ (incomeStatementHistory: IncomeStatementHistory) => [
31
+ incomeStatementHistory.domain,
32
+ incomeStatementHistory.originalId,
33
+ incomeStatementHistory.version
34
+ ],
35
+ { unique: true }
36
+ )
37
+ @ObjectType({ description: 'History Entity of IncomeStatement' })
38
+ export class IncomeStatementHistory implements HistoryEntityInterface<IncomeStatement> {
39
+ @PrimaryGeneratedColumn('uuid')
40
+ @Field(type => ID)
41
+ readonly id: string
42
+
43
+ @Column({ nullable: true, default: 1 })
44
+ @Field({ nullable: true })
45
+ version?: number = 1
46
+
47
+ @ManyToOne(type => Domain)
48
+ @Field({ nullable: true })
49
+ domain?: Domain
50
+
51
+ @RelationId((incomeStatement: IncomeStatement) => incomeStatement.domain)
52
+ domainId?: string
53
+
54
+ @Column()
55
+ @Field()
56
+ name: string
57
+
58
+ @Column({ nullable: true })
59
+ @Field({ nullable: true })
60
+ description?: string
61
+
62
+ @Column({ nullable: true })
63
+ @Field({ nullable: true })
64
+ active?: boolean
65
+
66
+ @Column({ nullable: true })
67
+ @Field({ nullable: true })
68
+ state?: IncomeStatementStatus
69
+
70
+ @Column({ nullable: true })
71
+ @Field({ nullable: true })
72
+ params?: string
73
+
74
+ @Column({ nullable: true })
75
+ @Field({ nullable: true })
76
+ createdAt?: Date
77
+
78
+ @Column({ nullable: true })
79
+ @Field({ nullable: true })
80
+ updatedAt?: Date
81
+
82
+ @Column({ nullable: true })
83
+ @Field({ nullable: true })
84
+ deletedAt?: Date
85
+
86
+ @ManyToOne(type => User, { nullable: true })
87
+ @Field({ nullable: true })
88
+ creator?: User
89
+
90
+ @RelationId((incomeStatement: IncomeStatement) => incomeStatement.creator)
91
+ creatorId?: string
92
+
93
+ @ManyToOne(type => User, { nullable: true })
94
+ @Field({ nullable: true })
95
+ updater?: User
96
+
97
+ @RelationId((incomeStatement: IncomeStatement) => incomeStatement.updater)
98
+ updaterId?: string
99
+
100
+ @HistoryOriginalIdColumn()
101
+ public originalId!: string
102
+
103
+ @HistoryActionColumn({
104
+ nullable: false,
105
+ type:
106
+ DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
107
+ ? 'enum'
108
+ : DATABASE_TYPE == 'oracle'
109
+ ? 'varchar2'
110
+ : 'smallint',
111
+ enum: HistoryActionType
112
+ })
113
+ public action!: HistoryActionType
114
+ }