@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,137 @@
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 { Account } from './account'
7
+ import { NewAccount, AccountPatch } from './account-type'
8
+
9
+ @Resolver(Account)
10
+ export class AccountMutation {
11
+ @Directive('@transaction')
12
+ @Mutation(returns => Account, { description: 'To create new Account' })
13
+ async createAccount(@Arg('account') account: NewAccount, @Ctx() context: ResolverContext): Promise<Account> {
14
+ const { domain, user, tx } = context.state
15
+
16
+ const result = await tx.getRepository(Account).save({
17
+ ...account,
18
+ domain,
19
+ creator: user,
20
+ updater: user
21
+ })
22
+
23
+ return result
24
+ }
25
+
26
+ @Directive('@transaction')
27
+ @Mutation(returns => Account, { description: 'To modify Account information' })
28
+ async updateAccount(
29
+ @Arg('id') id: string,
30
+ @Arg('patch') patch: AccountPatch,
31
+ @Ctx() context: ResolverContext
32
+ ): Promise<Account> {
33
+ const { domain, user, tx } = context.state
34
+
35
+ const repository = tx.getRepository(Account)
36
+ const account = await repository.findOne({
37
+ where: { domain: { id: domain.id }, id }
38
+ })
39
+
40
+ const result = await repository.save({
41
+ ...account,
42
+ ...patch,
43
+ updater: user
44
+ })
45
+
46
+ return result
47
+ }
48
+
49
+ @Directive('@transaction')
50
+ @Mutation(returns => [Account], { description: "To modify multiple Accounts' information" })
51
+ async updateMultipleAccount(
52
+ @Arg('patches', type => [AccountPatch]) patches: AccountPatch[],
53
+ @Ctx() context: ResolverContext
54
+ ): Promise<Account[]> {
55
+ const { domain, user, tx } = context.state
56
+
57
+ let results = []
58
+ const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
59
+ const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
60
+ const accountRepo = tx.getRepository(Account)
61
+
62
+ if (_createRecords.length > 0) {
63
+ for (let i = 0; i < _createRecords.length; i++) {
64
+ const newRecord = _createRecords[i]
65
+
66
+ const result = await accountRepo.save({
67
+ ...newRecord,
68
+ domain,
69
+ creator: user,
70
+ updater: user
71
+ })
72
+
73
+ results.push({ ...result, cuFlag: '+' })
74
+ }
75
+ }
76
+
77
+ if (_updateRecords.length > 0) {
78
+ for (let i = 0; i < _updateRecords.length; i++) {
79
+ const updateRecord = _updateRecords[i]
80
+ const account = await accountRepo.findOneBy({ id: updateRecord.id })
81
+
82
+ const result = await accountRepo.save({
83
+ ...account,
84
+ ...updateRecord,
85
+ updater: user
86
+ })
87
+
88
+ results.push({ ...result, cuFlag: 'M' })
89
+ }
90
+ }
91
+
92
+ return results
93
+ }
94
+
95
+ @Directive('@transaction')
96
+ @Mutation(returns => Boolean, { description: 'To delete Account' })
97
+ async deleteAccount(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
98
+ const { domain, tx } = context.state
99
+
100
+ await tx.getRepository(Account).delete({ domain: { id: domain.id }, id })
101
+ await deleteAttachmentsByRef(null, { refBys: [id] }, context)
102
+
103
+ return true
104
+ }
105
+
106
+ @Directive('@transaction')
107
+ @Mutation(returns => Boolean, { description: 'To delete multiple Accounts' })
108
+ async deleteAccounts(@Arg('ids', type => [String]) ids: string[], @Ctx() context: ResolverContext): Promise<boolean> {
109
+ const { domain, tx } = context.state
110
+
111
+ await tx.getRepository(Account).delete({
112
+ domain: { id: domain.id },
113
+ id: In(ids)
114
+ })
115
+
116
+ await deleteAttachmentsByRef(null, { refBys: ids }, context)
117
+
118
+ return true
119
+ }
120
+
121
+ @Directive('@transaction')
122
+ @Mutation(returns => Boolean, { description: 'To import multiple Accounts' })
123
+ async importAccounts(
124
+ @Arg('accounts', type => [AccountPatch]) accounts: AccountPatch[],
125
+ @Ctx() context: ResolverContext
126
+ ): Promise<boolean> {
127
+ const { domain, tx } = context.state
128
+
129
+ await Promise.all(
130
+ accounts.map(async (account: AccountPatch) => {
131
+ const createdAccount: Account = await tx.getRepository(Account).save({ domain, ...account })
132
+ })
133
+ )
134
+
135
+ return true
136
+ }
137
+ }
@@ -0,0 +1,49 @@
1
+ import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
2
+
3
+ import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
4
+ import { User } from '@things-factory/auth-base'
5
+ import { Account } from './account'
6
+ import { AccountList } from './account-type'
7
+
8
+ @Resolver(Account)
9
+ export class AccountQuery {
10
+ @Query(returns => Account!, { nullable: true, description: 'To fetch a Account' })
11
+ async account(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Account> {
12
+ const { domain } = context.state
13
+
14
+ return await getRepository(Account).findOne({
15
+ where: { domain: { id: domain.id }, id }
16
+ })
17
+ }
18
+
19
+ @Query(returns => AccountList, { description: 'To fetch multiple Accounts' })
20
+ async accounts(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<AccountList> {
21
+ const { domain } = context.state
22
+
23
+ const queryBuilder = getQueryBuilderFromListParams({
24
+ domain,
25
+ params,
26
+ repository: await getRepository(Account),
27
+ searchables: ['name', 'description']
28
+ })
29
+
30
+ const [items, total] = await queryBuilder.getManyAndCount()
31
+
32
+ return { items, total }
33
+ }
34
+
35
+ @FieldResolver(type => Domain)
36
+ async domain(@Root() account: Account): Promise<Domain> {
37
+ return await getRepository(Domain).findOneBy({ id: account.domainId })
38
+ }
39
+
40
+ @FieldResolver(type => User)
41
+ async updater(@Root() account: Account): Promise<User> {
42
+ return await getRepository(User).findOneBy({ id: account.updaterId })
43
+ }
44
+
45
+ @FieldResolver(type => User)
46
+ async creator(@Root() account: Account): Promise<User> {
47
+ return await getRepository(User).findOneBy({ id: account.creatorId })
48
+ }
49
+ }
@@ -0,0 +1,44 @@
1
+ import { ObjectType, Field, InputType, Int, ID, registerEnumType } from 'type-graphql'
2
+
3
+ import { ObjectRef, ScalarObject } from '@things-factory/shell'
4
+
5
+ import { Account } from './account'
6
+
7
+ @InputType()
8
+ export class NewAccount {
9
+ @Field()
10
+ name: string
11
+
12
+ @Field({ nullable: true })
13
+ description?: string
14
+
15
+ @Field({ nullable: true })
16
+ active?: boolean
17
+ }
18
+
19
+ @InputType()
20
+ export class AccountPatch {
21
+ @Field(type => ID, { nullable: true })
22
+ id?: string
23
+
24
+ @Field({ nullable: true })
25
+ name?: string
26
+
27
+ @Field({ nullable: true })
28
+ description?: string
29
+
30
+ @Field({ nullable: true })
31
+ active?: boolean
32
+
33
+ @Field({ nullable: true })
34
+ cuFlag?: string
35
+ }
36
+
37
+ @ObjectType()
38
+ export class AccountList {
39
+ @Field(type => [Account])
40
+ items: Account[]
41
+
42
+ @Field(type => Int)
43
+ total: number
44
+ }
@@ -0,0 +1,86 @@
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
+ import { AccountingCategory } from '../accounting-category/accounting-category'
18
+
19
+ @Entity()
20
+ @Index('ix_account_0', (account: Account) => [account.domain, account.name, account.deletedAt], { unique: true })
21
+ @ObjectType({ description: 'Entity for Account' })
22
+ export class Account {
23
+ @PrimaryGeneratedColumn('uuid')
24
+ @Field(type => ID)
25
+ readonly id: string
26
+
27
+ @VersionColumn()
28
+ @Field({ nullable: true })
29
+ version?: number = 1
30
+
31
+ @ManyToOne(type => Domain)
32
+ @Field({ nullable: true })
33
+ domain?: Domain
34
+
35
+ @RelationId((account: Account) => account.domain)
36
+ domainId?: string
37
+
38
+ @Column()
39
+ @Field({ nullable: true, description: 'Account control number' })
40
+ controlNumber?: string
41
+
42
+ @Column()
43
+ @Field({ nullable: true, description: 'Account name' })
44
+ name?: string
45
+
46
+ @Column({ nullable: true })
47
+ @Field({ nullable: true })
48
+ description?: string
49
+
50
+ @Column({ nullable: true })
51
+ @Field({ nullable: true })
52
+ active?: boolean
53
+
54
+ @Column({ nullable: true })
55
+ @Field(type => AccountingCategory, { nullable: true })
56
+ category?: AccountingCategory
57
+
58
+ @RelationId((account: Account) => account.category)
59
+ categoryId?: string
60
+
61
+ @CreateDateColumn()
62
+ @Field({ nullable: true })
63
+ createdAt?: Date
64
+
65
+ @UpdateDateColumn()
66
+ @Field({ nullable: true })
67
+ updatedAt?: Date
68
+
69
+ @DeleteDateColumn()
70
+ @Field({ nullable: true })
71
+ deletedAt?: Date
72
+
73
+ @ManyToOne(type => User, { nullable: true })
74
+ @Field(type => User, { nullable: true })
75
+ creator?: User
76
+
77
+ @RelationId((account: Account) => account.creator)
78
+ creatorId?: string
79
+
80
+ @ManyToOne(type => User, { nullable: true })
81
+ @Field(type => User, { nullable: true })
82
+ updater?: User
83
+
84
+ @RelationId((account: Account) => account.updater)
85
+ updaterId?: string
86
+ }
@@ -0,0 +1,17 @@
1
+ import { EventSubscriber } from 'typeorm'
2
+
3
+ import { HistoryEntitySubscriber } from '@operato/typeorm-history'
4
+
5
+ import { Account } from './account'
6
+ import { AccountHistory } from './account-history'
7
+
8
+ @EventSubscriber()
9
+ export class AccountHistoryEntitySubscriber extends HistoryEntitySubscriber<Account, AccountHistory> {
10
+ public get entity() {
11
+ return Account
12
+ }
13
+
14
+ public get historyEntity() {
15
+ return AccountHistory
16
+ }
17
+ }
@@ -0,0 +1,9 @@
1
+ import { Account } from './account'
2
+ import { AccountHistory } from './account-history'
3
+ import { AccountQuery } from './account-query'
4
+ import { AccountMutation } from './account-mutation'
5
+ import { AccountHistoryEntitySubscriber } from './event-subscriber'
6
+
7
+ export const entities = [Account, AccountHistory]
8
+ export const resolvers = [AccountQuery, AccountMutation]
9
+ export const subscribers = [AccountHistoryEntitySubscriber]
@@ -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 { AccountingCategory } from './accounting-category'
7
+ import { NewAccountingCategory, AccountingCategoryPatch } from './accounting-category-type'
8
+
9
+ @Resolver(AccountingCategory)
10
+ export class AccountingCategoryMutation {
11
+ @Directive('@transaction')
12
+ @Mutation(returns => AccountingCategory, { description: 'To create new AccountingCategory' })
13
+ async createAccountingCategory(
14
+ @Arg('accountingCategory') accountingCategory: NewAccountingCategory,
15
+ @Ctx() context: ResolverContext
16
+ ): Promise<AccountingCategory> {
17
+ const { domain, user, tx } = context.state
18
+
19
+ const result = await tx.getRepository(AccountingCategory).save({
20
+ ...accountingCategory,
21
+ domain,
22
+ creator: user,
23
+ updater: user
24
+ })
25
+
26
+ return result
27
+ }
28
+
29
+ @Directive('@transaction')
30
+ @Mutation(returns => AccountingCategory, { description: 'To modify AccountingCategory information' })
31
+ async updateAccountingCategory(
32
+ @Arg('id') id: string,
33
+ @Arg('patch') patch: AccountingCategoryPatch,
34
+ @Ctx() context: ResolverContext
35
+ ): Promise<AccountingCategory> {
36
+ const { domain, user, tx } = context.state
37
+
38
+ const repository = tx.getRepository(AccountingCategory)
39
+ const accountingCategory = await repository.findOne({
40
+ where: { domain: { id: domain.id }, id }
41
+ })
42
+
43
+ const result = await repository.save({
44
+ ...accountingCategory,
45
+ ...patch,
46
+ updater: user
47
+ })
48
+
49
+ return result
50
+ }
51
+
52
+ @Directive('@transaction')
53
+ @Mutation(returns => [AccountingCategory], { description: "To modify multiple AccountingCategories' information" })
54
+ async updateMultipleAccountingCategory(
55
+ @Arg('patches', type => [AccountingCategoryPatch]) patches: AccountingCategoryPatch[],
56
+ @Ctx() context: ResolverContext
57
+ ): Promise<AccountingCategory[]> {
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 accountingCategoryRepo = tx.getRepository(AccountingCategory)
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 accountingCategoryRepo.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 accountingCategory = await accountingCategoryRepo.findOneBy({ id: updateRecord.id })
84
+
85
+ const result = await accountingCategoryRepo.save({
86
+ ...accountingCategory,
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 AccountingCategory' })
100
+ async deleteAccountingCategory(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
101
+ const { domain, tx } = context.state
102
+
103
+ await tx.getRepository(AccountingCategory).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 AccountingCategories' })
111
+ async deleteAccountingCategories(
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(AccountingCategory).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 AccountingCategories' })
129
+ async importAccountingCategories(
130
+ @Arg('accountingCategories', type => [AccountingCategoryPatch]) accountingCategories: AccountingCategoryPatch[],
131
+ @Ctx() context: ResolverContext
132
+ ): Promise<boolean> {
133
+ const { domain, tx } = context.state
134
+
135
+ await Promise.all(
136
+ accountingCategories.map(async (accountingCategory: AccountingCategoryPatch) => {
137
+ const createdAccountingCategory: AccountingCategory = await tx
138
+ .getRepository(AccountingCategory)
139
+ .save({ domain, ...accountingCategory })
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 { AccountingCategory } from './accounting-category'
5
+ import { AccountingCategoryList } from './accounting-category-type'
6
+
7
+ @Resolver(AccountingCategory)
8
+ export class AccountingCategoryQuery {
9
+ @Query(returns => AccountingCategory!, { nullable: true, description: 'To fetch a AccountingCategory' })
10
+ async accountingCategory(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<AccountingCategory> {
11
+ const { domain } = context.state
12
+
13
+ return await getRepository(AccountingCategory).findOne({
14
+ where: { domain: { id: domain.id }, id }
15
+ })
16
+ }
17
+
18
+ @Query(returns => AccountingCategoryList, { description: 'To fetch multiple AccountingCategories' })
19
+ async accountingCategories(
20
+ @Args() params: ListParam,
21
+ @Ctx() context: ResolverContext
22
+ ): Promise<AccountingCategoryList> {
23
+ const { domain } = context.state
24
+
25
+ const queryBuilder = getQueryBuilderFromListParams({
26
+ domain,
27
+ params,
28
+ repository: await getRepository(AccountingCategory),
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() accountingCategory: AccountingCategory): Promise<Domain> {
39
+ return await getRepository(Domain).findOneBy({ id: accountingCategory.domainId })
40
+ }
41
+
42
+ @FieldResolver(type => User)
43
+ async updater(@Root() accountingCategory: AccountingCategory): Promise<User> {
44
+ return await getRepository(User).findOneBy({ id: accountingCategory.updaterId })
45
+ }
46
+
47
+ @FieldResolver(type => User)
48
+ async creator(@Root() accountingCategory: AccountingCategory): Promise<User> {
49
+ return await getRepository(User).findOneBy({ id: accountingCategory.creatorId })
50
+ }
51
+ }
@@ -0,0 +1,42 @@
1
+ import { ObjectType, Field, InputType, Int, ID, registerEnumType } from 'type-graphql'
2
+
3
+ import { AccountingCategory } from './accounting-category'
4
+
5
+ @InputType()
6
+ export class NewAccountingCategory {
7
+ @Field()
8
+ name: string
9
+
10
+ @Field({ nullable: true })
11
+ description?: string
12
+
13
+ @Field({ nullable: true })
14
+ active?: boolean
15
+ }
16
+
17
+ @InputType()
18
+ export class AccountingCategoryPatch {
19
+ @Field(type => ID, { nullable: true })
20
+ id?: string
21
+
22
+ @Field({ nullable: true })
23
+ name?: string
24
+
25
+ @Field({ nullable: true })
26
+ description?: string
27
+
28
+ @Field({ nullable: true })
29
+ active?: boolean
30
+
31
+ @Field({ nullable: true })
32
+ cuFlag?: string
33
+ }
34
+
35
+ @ObjectType()
36
+ export class AccountingCategoryList {
37
+ @Field(type => [AccountingCategory])
38
+ items: AccountingCategory[]
39
+
40
+ @Field(type => Int)
41
+ total: number
42
+ }
@@ -0,0 +1,80 @@
1
+ import {
2
+ CreateDateColumn,
3
+ UpdateDateColumn,
4
+ Entity,
5
+ Index,
6
+ Column,
7
+ RelationId,
8
+ ManyToOne,
9
+ OneToMany,
10
+ PrimaryGeneratedColumn
11
+ } from 'typeorm'
12
+ import { ObjectType, Field, Int, ID } from 'type-graphql'
13
+
14
+ import { Domain } from '@things-factory/shell'
15
+ import { User } from '@things-factory/auth-base'
16
+
17
+ @Entity()
18
+ @Index(
19
+ 'ix_accounting_category_0',
20
+ (accountingCategory: AccountingCategory) => [accountingCategory.domain, accountingCategory.name],
21
+ { unique: true }
22
+ )
23
+ @ObjectType({ description: 'Entity for AccountingCategory' })
24
+ export class AccountingCategory {
25
+ @PrimaryGeneratedColumn('uuid')
26
+ @Field(type => ID)
27
+ readonly id: string
28
+
29
+ @ManyToOne(type => Domain)
30
+ @Field({ nullable: true })
31
+ domain?: Domain
32
+
33
+ @RelationId((accountingCategory: AccountingCategory) => accountingCategory.domain)
34
+ domainId?: string
35
+
36
+ @Column()
37
+ @Field({ nullable: true })
38
+ name?: string
39
+
40
+ @Column({ nullable: true })
41
+ @Field({ nullable: true })
42
+ description?: string
43
+
44
+ @Column({ nullable: true })
45
+ @Field({ nullable: true })
46
+ active?: boolean
47
+
48
+ @ManyToOne(type => AccountingCategory, accountingCategory => accountingCategory.children, { nullable: true })
49
+ @Field({ nullable: true })
50
+ parent?: AccountingCategory
51
+
52
+ @RelationId((accountingCategory: AccountingCategory) => accountingCategory.parent)
53
+ parentId?: string
54
+
55
+ @OneToMany(type => AccountingCategory, accountingCategory => accountingCategory.parent)
56
+ @Field(type => [AccountingCategory])
57
+ children?: AccountingCategory[]
58
+
59
+ @CreateDateColumn()
60
+ @Field({ nullable: true })
61
+ createdAt?: Date
62
+
63
+ @UpdateDateColumn()
64
+ @Field({ nullable: true })
65
+ updatedAt?: Date
66
+
67
+ @ManyToOne(type => User, { nullable: true })
68
+ @Field(type => User, { nullable: true })
69
+ creator?: User
70
+
71
+ @RelationId((accountingCategory: AccountingCategory) => accountingCategory.creator)
72
+ creatorId?: string
73
+
74
+ @ManyToOne(type => User, { nullable: true })
75
+ @Field(type => User, { nullable: true })
76
+ updater?: User
77
+
78
+ @RelationId((accountingCategory: AccountingCategory) => accountingCategory.updater)
79
+ updaterId?: string
80
+ }
@@ -0,0 +1,7 @@
1
+ import { AccountingCategory } from './accounting-category'
2
+ import { AccountingCategoryQuery } from './accounting-category-query'
3
+ import { AccountingCategoryMutation } from './accounting-category-mutation'
4
+
5
+ export const entities = [AccountingCategory]
6
+ export const resolvers = [AccountingCategoryQuery, AccountingCategoryMutation]
7
+ export const subscribers = []
@@ -0,0 +1,17 @@
1
+ import { EventSubscriber } from 'typeorm'
2
+
3
+ import { HistoryEntitySubscriber } from '@operato/typeorm-history'
4
+
5
+ import { FinancialStatement } from './financial-statement'
6
+ import { FinancialStatementHistory } from './financial-statement-history'
7
+
8
+ @EventSubscriber()
9
+ export class FinancialStatementHistoryEntitySubscriber extends HistoryEntitySubscriber<FinancialStatement, FinancialStatementHistory> {
10
+ public get entity() {
11
+ return FinancialStatement
12
+ }
13
+
14
+ public get historyEntity() {
15
+ return FinancialStatementHistory
16
+ }
17
+ }