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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/client/activities/activity-book-edit.ts +88 -0
  2. package/client/activities/activity-book-view.ts +88 -0
  3. package/client/activities/activity-expense-edit.ts +88 -0
  4. package/client/activities/activity-expense-view.ts +88 -0
  5. package/client/bootstrap.ts +10 -0
  6. package/client/components/accounting-category-selector.ts +136 -0
  7. package/client/components/accounting-category-view.ts +75 -0
  8. package/client/grist-editors/grist-editor-accounting-category-object.ts +83 -0
  9. package/client/grist-editors/grist-renderer-accounting-category-object.ts +13 -0
  10. package/client/index.ts +0 -0
  11. package/client/pages/account/account-importer.ts +97 -0
  12. package/client/pages/account/account-list-page.ts +364 -0
  13. package/client/pages/accounting-category/accounting-category-importer.ts +97 -0
  14. package/client/pages/accounting-category/accounting-category-list-page.ts +368 -0
  15. package/client/pages/accounting-category/accounting-category-tree-page.ts +338 -0
  16. package/client/pages/accounting-document/accounting-document-importer.ts +90 -0
  17. package/client/pages/accounting-document/accounting-document-list-page.ts +398 -0
  18. package/client/pages/financial-statement/financial-statement-importer.ts +97 -0
  19. package/client/pages/financial-statement/financial-statement-list-page.ts +338 -0
  20. package/client/pages/fiscal-month/fiscal-month-importer.ts +90 -0
  21. package/client/pages/fiscal-month/fiscal-month-list-page.ts +398 -0
  22. package/client/pages/fiscal-quarter/fiscal-quarter-importer.ts +90 -0
  23. package/client/pages/fiscal-quarter/fiscal-quarter-list-page.ts +398 -0
  24. package/client/pages/fiscal-year/fiscal-year-importer.ts +90 -0
  25. package/client/pages/fiscal-year/fiscal-year-list-page.ts +398 -0
  26. package/client/pages/income-statement/income-statement-importer.ts +97 -0
  27. package/client/pages/income-statement/income-statement-list-page.ts +338 -0
  28. package/client/pages/payment/payment-importer.ts +90 -0
  29. package/client/pages/payment/payment-list-page.ts +398 -0
  30. package/client/pages/transaction/transaction-importer.ts +97 -0
  31. package/client/pages/transaction/transaction-list-page.ts +338 -0
  32. package/client/route.ts +35 -0
  33. package/client/tsconfig.json +13 -0
  34. package/client/types/accounting-category.ts +23 -0
  35. package/client/types/index.ts +1 -0
  36. package/dist-client/pages/accounting-category/accounting-category-tree-page.js +1 -1
  37. package/dist-client/pages/accounting-category/accounting-category-tree-page.js.map +1 -1
  38. package/dist-client/tsconfig.tsbuildinfo +1 -1
  39. package/dist-server/service/index.d.ts +2 -3
  40. package/dist-server/service/index.js +0 -5
  41. package/dist-server/service/index.js.map +1 -1
  42. package/dist-server/service/payment/index.d.ts +2 -1
  43. package/dist-server/service/payment/payment-history.d.ts +1 -8
  44. package/dist-server/service/payment/payment-history.js +10 -41
  45. package/dist-server/service/payment/payment-history.js.map +1 -1
  46. package/dist-server/service/payment/payment-type.d.ts +1 -7
  47. package/dist-server/service/payment/payment-type.js +0 -24
  48. package/dist-server/service/payment/payment-type.js.map +1 -1
  49. package/dist-server/service/payment/payment.d.ts +0 -12
  50. package/dist-server/service/payment/payment.js +1 -36
  51. package/dist-server/service/payment/payment.js.map +1 -1
  52. package/dist-server/tsconfig.tsbuildinfo +1 -1
  53. package/package.json +7 -7
  54. package/server/activities/activity-book.ts +172 -0
  55. package/server/activities/activity-expense.ts +149 -0
  56. package/server/activities/index.ts +18 -0
  57. package/server/controllers/index.ts +1 -0
  58. package/server/controllers/summary-statements.ts +166 -0
  59. package/server/index.ts +6 -0
  60. package/server/middlewares/index.ts +3 -0
  61. package/server/migrations/1725200507196-seed-fiscal-entities.ts +106 -0
  62. package/server/migrations/1725201467183-seed-accounts.ts +339 -0
  63. package/server/migrations/index.ts +9 -0
  64. package/server/routes.ts +26 -0
  65. package/server/service/account/account-history.ts +117 -0
  66. package/server/service/account/account-mutation.ts +140 -0
  67. package/server/service/account/account-query.ts +51 -0
  68. package/server/service/account/account-type.ts +44 -0
  69. package/server/service/account/account.ts +97 -0
  70. package/server/service/account/event-subscriber.ts +17 -0
  71. package/server/service/account/index.ts +9 -0
  72. package/server/service/accounting-category/accounting-category-history.ts +129 -0
  73. package/server/service/accounting-category/accounting-category-mutation.ts +148 -0
  74. package/server/service/accounting-category/accounting-category-query.ts +74 -0
  75. package/server/service/accounting-category/accounting-category-type.ts +48 -0
  76. package/server/service/accounting-category/accounting-category.ts +100 -0
  77. package/server/service/accounting-category/event-subscriber.ts +20 -0
  78. package/server/service/accounting-category/index.ts +9 -0
  79. package/server/service/accounting-document/accounting-document-history.ts +123 -0
  80. package/server/service/accounting-document/accounting-document-mutation.ts +137 -0
  81. package/server/service/accounting-document/accounting-document-query.ts +48 -0
  82. package/server/service/accounting-document/accounting-document-type.ts +52 -0
  83. package/server/service/accounting-document/accounting-document.ts +93 -0
  84. package/server/service/accounting-document/event-subscriber.ts +17 -0
  85. package/server/service/accounting-document/index.ts +9 -0
  86. package/server/service/common-type.ts +12 -0
  87. package/server/service/financial-statement/event-subscriber.ts +17 -0
  88. package/server/service/financial-statement/financial-statement-history.ts +129 -0
  89. package/server/service/financial-statement/financial-statement-line-item.ts +82 -0
  90. package/server/service/financial-statement/financial-statement-mutation.ts +148 -0
  91. package/server/service/financial-statement/financial-statement-query.ts +53 -0
  92. package/server/service/financial-statement/financial-statement-type.ts +51 -0
  93. package/server/service/financial-statement/financial-statement.ts +116 -0
  94. package/server/service/financial-statement/index.ts +10 -0
  95. package/server/service/fiscal-month/fiscal-month-mutation.ts +145 -0
  96. package/server/service/fiscal-month/fiscal-month-query.ts +58 -0
  97. package/server/service/fiscal-month/fiscal-month-type.ts +66 -0
  98. package/server/service/fiscal-month/fiscal-month.ts +84 -0
  99. package/server/service/fiscal-month/index.ts +7 -0
  100. package/server/service/fiscal-quarter/fiscal-quarter-mutation.ts +148 -0
  101. package/server/service/fiscal-quarter/fiscal-quarter-query.ts +60 -0
  102. package/server/service/fiscal-quarter/fiscal-quarter-type.ts +60 -0
  103. package/server/service/fiscal-quarter/fiscal-quarter.ts +80 -0
  104. package/server/service/fiscal-quarter/index.ts +7 -0
  105. package/server/service/fiscal-year/fiscal-year-mutation.ts +145 -0
  106. package/server/service/fiscal-year/fiscal-year-query.ts +53 -0
  107. package/server/service/fiscal-year/fiscal-year-type.ts +54 -0
  108. package/server/service/fiscal-year/fiscal-year.ts +76 -0
  109. package/server/service/fiscal-year/index.ts +7 -0
  110. package/server/service/income-statement/event-subscriber.ts +17 -0
  111. package/server/service/income-statement/income-statement-history.ts +133 -0
  112. package/server/service/income-statement/income-statement-line-item.ts +84 -0
  113. package/server/service/income-statement/income-statement-mutation.ts +147 -0
  114. package/server/service/income-statement/income-statement-query.ts +50 -0
  115. package/server/service/income-statement/income-statement-type.ts +51 -0
  116. package/server/service/income-statement/income-statement.ts +120 -0
  117. package/server/service/income-statement/index.ts +10 -0
  118. package/server/service/index.ts +108 -0
  119. package/server/service/payment/event-subscriber.ts +17 -0
  120. package/server/service/payment/index.ts +9 -0
  121. package/server/service/payment/payment-history.ts +132 -0
  122. package/server/service/payment/payment-mutation.ts +139 -0
  123. package/server/service/payment/payment-query.ts +50 -0
  124. package/server/service/payment/payment-type.ts +64 -0
  125. package/server/service/payment/payment.ts +123 -0
  126. package/server/service/transaction/event-subscriber.ts +17 -0
  127. package/server/service/transaction/index.ts +9 -0
  128. package/server/service/transaction/transaction-history.ts +161 -0
  129. package/server/service/transaction/transaction-mutation.ts +146 -0
  130. package/server/service/transaction/transaction-query.ts +50 -0
  131. package/server/service/transaction/transaction-type.ts +48 -0
  132. package/server/service/transaction/transaction.ts +230 -0
  133. package/server/tsconfig.json +10 -0
  134. package/dist-client/pages/bank/bank-importer.d.ts +0 -23
  135. package/dist-client/pages/bank/bank-importer.js +0 -93
  136. package/dist-client/pages/bank/bank-importer.js.map +0 -1
  137. package/dist-client/pages/bank/bank-list-page.d.ts +0 -66
  138. package/dist-client/pages/bank/bank-list-page.js +0 -370
  139. package/dist-client/pages/bank/bank-list-page.js.map +0 -1
  140. package/dist-client/pages/bank-account/bank-account-importer.d.ts +0 -23
  141. package/dist-client/pages/bank-account/bank-account-importer.js +0 -93
  142. package/dist-client/pages/bank-account/bank-account-importer.js.map +0 -1
  143. package/dist-client/pages/bank-account/bank-account-list-page.d.ts +0 -66
  144. package/dist-client/pages/bank-account/bank-account-list-page.js +0 -370
  145. package/dist-client/pages/bank-account/bank-account-list-page.js.map +0 -1
  146. package/dist-client/pages/financial-institution/financial-institution-importer.d.ts +0 -23
  147. package/dist-client/pages/financial-institution/financial-institution-importer.js +0 -93
  148. package/dist-client/pages/financial-institution/financial-institution-importer.js.map +0 -1
  149. package/dist-client/pages/financial-institution/financial-institution-list-page.d.ts +0 -66
  150. package/dist-client/pages/financial-institution/financial-institution-list-page.js +0 -370
  151. package/dist-client/pages/financial-institution/financial-institution-list-page.js.map +0 -1
  152. package/dist-server/migrations/1725201567284-seed-country-codes.d.ts +0 -5
  153. package/dist-server/migrations/1725201567284-seed-country-codes.js +0 -248
  154. package/dist-server/migrations/1725201567284-seed-country-codes.js.map +0 -1
  155. package/dist-server/migrations/1725201667385-seed-financial-institutions.d.ts +0 -5
  156. package/dist-server/migrations/1725201667385-seed-financial-institutions.js +0 -348
  157. package/dist-server/migrations/1725201667385-seed-financial-institutions.js.map +0 -1
  158. package/dist-server/service/bank-account/bank-account-history.d.ts +0 -34
  159. package/dist-server/service/bank-account/bank-account-history.js +0 -172
  160. package/dist-server/service/bank-account/bank-account-history.js.map +0 -1
  161. package/dist-server/service/bank-account/bank-account-mutation.d.ts +0 -10
  162. package/dist-server/service/bank-account/bank-account-mutation.js +0 -128
  163. package/dist-server/service/bank-account/bank-account-mutation.js.map +0 -1
  164. package/dist-server/service/bank-account/bank-account-query.d.ts +0 -11
  165. package/dist-server/service/bank-account/bank-account-query.js +0 -79
  166. package/dist-server/service/bank-account/bank-account-query.js.map +0 -1
  167. package/dist-server/service/bank-account/bank-account-type.d.ts +0 -39
  168. package/dist-server/service/bank-account/bank-account-type.js +0 -153
  169. package/dist-server/service/bank-account/bank-account-type.js.map +0 -1
  170. package/dist-server/service/bank-account/bank-account.d.ts +0 -38
  171. package/dist-server/service/bank-account/bank-account.js +0 -164
  172. package/dist-server/service/bank-account/bank-account.js.map +0 -1
  173. package/dist-server/service/bank-account/event-subscriber.d.ts +0 -7
  174. package/dist-server/service/bank-account/event-subscriber.js +0 -21
  175. package/dist-server/service/bank-account/event-subscriber.js.map +0 -1
  176. package/dist-server/service/bank-account/index.d.ts +0 -7
  177. package/dist-server/service/bank-account/index.js +0 -12
  178. package/dist-server/service/bank-account/index.js.map +0 -1
  179. package/dist-server/service/financial-institution/financial-institution-mutation.d.ts +0 -10
  180. package/dist-server/service/financial-institution/financial-institution-mutation.js +0 -169
  181. package/dist-server/service/financial-institution/financial-institution-mutation.js.map +0 -1
  182. package/dist-server/service/financial-institution/financial-institution-query.d.ts +0 -12
  183. package/dist-server/service/financial-institution/financial-institution-query.js +0 -97
  184. package/dist-server/service/financial-institution/financial-institution-query.js.map +0 -1
  185. package/dist-server/service/financial-institution/financial-institution-type.d.ts +0 -32
  186. package/dist-server/service/financial-institution/financial-institution-type.js +0 -126
  187. package/dist-server/service/financial-institution/financial-institution-type.js.map +0 -1
  188. package/dist-server/service/financial-institution/financial-institution.d.ts +0 -34
  189. package/dist-server/service/financial-institution/financial-institution.js +0 -137
  190. package/dist-server/service/financial-institution/financial-institution.js.map +0 -1
  191. package/dist-server/service/financial-institution/index.d.ts +0 -6
  192. package/dist-server/service/financial-institution/index.js +0 -10
  193. package/dist-server/service/financial-institution/index.js.map +0 -1
  194. package/helps/accounting/bank-account.md +0 -160
  195. package/helps/accounting/bank.md +0 -160
  196. package/helps/accounting/financial-institution.md +0 -160
@@ -0,0 +1,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,97 @@
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], {
21
+ unique: true,
22
+ where: '"deleted_at" IS NULL'
23
+ })
24
+ @Index('ix_account_1', (account: Account) => [account.domain, account.code], {
25
+ unique: true,
26
+ where: '"deleted_at" IS NULL'
27
+ })
28
+ @Index('ix_account_2', (account: Account) => [account.domain, account.category], {
29
+ unique: false,
30
+ where: '"deleted_at" IS NULL'
31
+ })
32
+ @ObjectType({ description: 'Entity for Account' })
33
+ export class Account {
34
+ @PrimaryGeneratedColumn('uuid')
35
+ @Field(type => ID)
36
+ readonly id: string
37
+
38
+ @VersionColumn()
39
+ @Field({ nullable: true })
40
+ version?: number = 1
41
+
42
+ @ManyToOne(type => Domain)
43
+ @Field({ nullable: true })
44
+ domain?: Domain
45
+
46
+ @RelationId((account: Account) => account.domain)
47
+ domainId?: string
48
+
49
+ @Column()
50
+ @Field({ nullable: true, description: 'Account code number' })
51
+ code?: string
52
+
53
+ @Column()
54
+ @Field({ nullable: true, description: 'Account name' })
55
+ name?: string
56
+
57
+ @Column({ nullable: true })
58
+ @Field({ nullable: true })
59
+ description?: string
60
+
61
+ @Column({ nullable: true })
62
+ @Field({ nullable: true })
63
+ active?: boolean
64
+
65
+ @ManyToOne(type => AccountingCategory)
66
+ @Field(type => AccountingCategory, { nullable: true })
67
+ category?: AccountingCategory
68
+
69
+ @RelationId((account: Account) => account.category)
70
+ categoryId?: string
71
+
72
+ @CreateDateColumn()
73
+ @Field({ nullable: true })
74
+ createdAt?: Date
75
+
76
+ @UpdateDateColumn()
77
+ @Field({ nullable: true })
78
+ updatedAt?: Date
79
+
80
+ @DeleteDateColumn()
81
+ @Field({ nullable: true })
82
+ deletedAt?: Date
83
+
84
+ @ManyToOne(type => User, { nullable: true })
85
+ @Field(type => User, { nullable: true })
86
+ creator?: User
87
+
88
+ @RelationId((account: Account) => account.creator)
89
+ creatorId?: string
90
+
91
+ @ManyToOne(type => User, { nullable: true })
92
+ @Field(type => User, { nullable: true })
93
+ updater?: User
94
+
95
+ @RelationId((account: Account) => account.updater)
96
+ updaterId?: string
97
+ }
@@ -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,129 @@
1
+ import { Field, ID, ObjectType } from 'type-graphql'
2
+ import { Entity, Index, Column, ManyToOne, RelationId, PrimaryGeneratedColumn, OneToMany } 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 { AccountingCategory } from './accounting-category'
15
+
16
+ const ORMCONFIG = config.get('ormconfig', {})
17
+ const DATABASE_TYPE = ORMCONFIG.type
18
+
19
+ @Entity()
20
+ @Index(
21
+ 'ix_accounting_category_history_0',
22
+ (accountingCategoryHistory: AccountingCategoryHistory) => [
23
+ accountingCategoryHistory.originalId,
24
+ accountingCategoryHistory.version
25
+ ],
26
+ { unique: true }
27
+ )
28
+ @Index(
29
+ 'ix_accounting_category_history_1',
30
+ (accountingCategoryHistory: AccountingCategoryHistory) => [
31
+ accountingCategoryHistory.domain,
32
+ accountingCategoryHistory.originalId,
33
+ accountingCategoryHistory.version
34
+ ],
35
+ { unique: true }
36
+ )
37
+ @ObjectType({ description: 'History Entity of Accounting Category' })
38
+ export class AccountingCategoryHistory implements HistoryEntityInterface<AccountingCategory> {
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((accountingCategoryHistory: AccountingCategoryHistory) => accountingCategoryHistory.domain)
52
+ domainId?: string
53
+
54
+ @Column()
55
+ @Field({ nullable: true, description: 'Account category code' })
56
+ code?: string
57
+
58
+ @Column()
59
+ @Field({ nullable: true })
60
+ name?: string
61
+
62
+ @Column({ nullable: true })
63
+ @Field({ nullable: true })
64
+ description?: string
65
+
66
+ @Column({ nullable: true })
67
+ @Field({ nullable: true })
68
+ active?: boolean
69
+
70
+ @ManyToOne(type => AccountingCategoryHistory, accountingCategoryHistory => accountingCategoryHistory.children, {
71
+ nullable: true
72
+ })
73
+ @Field({ nullable: true })
74
+ parent?: AccountingCategoryHistory
75
+
76
+ @RelationId((accountingCategoryHistory: AccountingCategoryHistory) => accountingCategoryHistory.parent)
77
+ parentId?: string
78
+
79
+ @OneToMany(type => AccountingCategoryHistory, accountingCategoryHistory => accountingCategoryHistory.parent)
80
+ @Field(type => [AccountingCategoryHistory])
81
+ children?: AccountingCategoryHistory[]
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((accountingCategory: AccountingCategoryHistory) => accountingCategory.creator)
100
+ creatorId?: string
101
+
102
+ @ManyToOne(type => User, { nullable: true })
103
+ @Field(type => User, { nullable: true })
104
+ updater?: User
105
+
106
+ @RelationId((accountingCategory: AccountingCategoryHistory) => accountingCategory.updater)
107
+ updaterId?: string
108
+
109
+ @HistoryOriginalIdColumn()
110
+ public originalId!: string
111
+
112
+ @HistoryActionColumn({
113
+ nullable: false,
114
+ type:
115
+ DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
116
+ ? 'enum'
117
+ : DATABASE_TYPE == 'oracle'
118
+ ? 'varchar2'
119
+ : DATABASE_TYPE == 'mssql'
120
+ ? 'nvarchar'
121
+ : 'varchar',
122
+ enum:
123
+ DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
124
+ ? HistoryActionType
125
+ : undefined,
126
+ length: DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb' ? undefined : 10
127
+ })
128
+ public action!: HistoryActionType
129
+ }
@@ -0,0 +1,148 @@
1
+ import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
2
+ import { In } from 'typeorm'
3
+
4
+ import { getRepository } from '@things-factory/shell'
5
+
6
+ import { AccountingCategory } from './accounting-category'
7
+ import { NewAccountingCategory, AccountingCategoryPatch } from './accounting-category-type'
8
+
9
+ @Resolver(AccountingCategory)
10
+ export class AccountingCategoryMutation {
11
+ @Directive('@transaction')
12
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
13
+ @Mutation(returns => AccountingCategory, { description: 'To create new AccountingCategory' })
14
+ async createAccountingCategory(
15
+ @Arg('accountingCategory') accountingCategory: NewAccountingCategory,
16
+ @Ctx() context: ResolverContext
17
+ ): Promise<AccountingCategory> {
18
+ const { domain, user, tx } = context.state
19
+
20
+ const result = await getRepository(AccountingCategory, tx).save({
21
+ ...accountingCategory,
22
+ domain,
23
+ creator: user,
24
+ updater: user
25
+ })
26
+
27
+ return result
28
+ }
29
+
30
+ @Directive('@transaction')
31
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
32
+ @Mutation(returns => AccountingCategory, { description: 'To modify AccountingCategory information' })
33
+ async updateAccountingCategory(
34
+ @Arg('id') id: string,
35
+ @Arg('patch') patch: AccountingCategoryPatch,
36
+ @Ctx() context: ResolverContext
37
+ ): Promise<AccountingCategory> {
38
+ const { domain, user, tx } = context.state
39
+
40
+ const repository = getRepository(AccountingCategory, tx)
41
+ const accountingCategory = await repository.findOne({
42
+ where: { domain: { id: domain.id }, id }
43
+ })
44
+
45
+ const result = await repository.save({
46
+ ...accountingCategory,
47
+ ...patch,
48
+ updater: user
49
+ })
50
+
51
+ return result
52
+ }
53
+
54
+ @Directive('@transaction')
55
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
56
+ @Mutation(returns => [AccountingCategory], { description: "To modify multiple AccountingCategories' information" })
57
+ async updateMultipleAccountingCategory(
58
+ @Arg('patches', type => [AccountingCategoryPatch]) patches: AccountingCategoryPatch[],
59
+ @Ctx() context: ResolverContext
60
+ ): Promise<AccountingCategory[]> {
61
+ const { domain, user, tx } = context.state
62
+
63
+ let results = []
64
+ const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
65
+ const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
66
+ const accountingCategoryRepo = getRepository(AccountingCategory, tx)
67
+
68
+ if (_createRecords.length > 0) {
69
+ for (let i = 0; i < _createRecords.length; i++) {
70
+ const newRecord = _createRecords[i]
71
+
72
+ const result = await accountingCategoryRepo.save({
73
+ ...newRecord,
74
+ domain,
75
+ creator: user,
76
+ updater: user
77
+ })
78
+
79
+ results.push({ ...result, cuFlag: '+' })
80
+ }
81
+ }
82
+
83
+ if (_updateRecords.length > 0) {
84
+ for (let i = 0; i < _updateRecords.length; i++) {
85
+ const updateRecord = _updateRecords[i]
86
+ const accountingCategory = await accountingCategoryRepo.findOneBy({ id: updateRecord.id })
87
+
88
+ const result = await accountingCategoryRepo.save({
89
+ ...accountingCategory,
90
+ ...updateRecord,
91
+ updater: user
92
+ })
93
+
94
+ results.push({ ...result, cuFlag: 'M' })
95
+ }
96
+ }
97
+
98
+ return results
99
+ }
100
+
101
+ @Directive('@transaction')
102
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
103
+ @Mutation(returns => Boolean, { description: 'To delete AccountingCategory' })
104
+ async deleteAccountingCategory(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
105
+ const { domain, tx } = context.state
106
+
107
+ await getRepository(AccountingCategory, tx).delete({ domain: { id: domain.id }, id })
108
+
109
+ return true
110
+ }
111
+
112
+ @Directive('@transaction')
113
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
114
+ @Mutation(returns => Boolean, { description: 'To delete multiple AccountingCategories' })
115
+ async deleteAccountingCategories(
116
+ @Arg('ids', type => [String]) ids: string[],
117
+ @Ctx() context: ResolverContext
118
+ ): Promise<boolean> {
119
+ const { domain, tx } = context.state
120
+
121
+ await getRepository(AccountingCategory, tx).delete({
122
+ domain: { id: domain.id },
123
+ id: In(ids)
124
+ })
125
+
126
+ return true
127
+ }
128
+
129
+ @Directive('@transaction')
130
+ @Directive('@privilege(category: "accounting", privilege: "mutation")')
131
+ @Mutation(returns => Boolean, { description: 'To import multiple AccountingCategories' })
132
+ async importAccountingCategories(
133
+ @Arg('accountingCategories', type => [AccountingCategoryPatch]) accountingCategories: AccountingCategoryPatch[],
134
+ @Ctx() context: ResolverContext
135
+ ): Promise<boolean> {
136
+ const { domain, tx } = context.state
137
+
138
+ await Promise.all(
139
+ accountingCategories.map(async (accountingCategory: AccountingCategoryPatch) => {
140
+ const createdAccountingCategory: AccountingCategory = await tx
141
+ .getRepository(AccountingCategory)
142
+ .save({ domain, ...accountingCategory })
143
+ })
144
+ )
145
+
146
+ return true
147
+ }
148
+ }
@@ -0,0 +1,74 @@
1
+ import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
2
+ import { IsNull } from 'typeorm'
3
+ import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
4
+ import { User } from '@things-factory/auth-base'
5
+ import { AccountingCategory } from './accounting-category'
6
+ import { AccountingCategoryList } from './accounting-category-type'
7
+
8
+ @Resolver(AccountingCategory)
9
+ export class AccountingCategoryQuery {
10
+ @Directive('@privilege(category: "accounting", privilege: "query", domainOwnerGranted: true)')
11
+ @Query(returns => AccountingCategoryList, { nullable: true, description: 'To fetch a Root AccountingCategorys' })
12
+ async accountingCategoryRoots(
13
+ @Args(type => ListParam) params: ListParam,
14
+ @Ctx() context: ResolverContext
15
+ ): Promise<AccountingCategoryList> {
16
+ const { domain } = context.state
17
+
18
+ const queryBuilder = getQueryBuilderFromListParams({
19
+ domain,
20
+ params,
21
+ repository: await getRepository(AccountingCategory),
22
+ searchables: ['name', 'description', 'code']
23
+ }).andWhere({ domain: { id: domain.id }, parent: { id: IsNull() } })
24
+
25
+ const [items, total] = await queryBuilder.getManyAndCount()
26
+
27
+ return { items, total }
28
+ }
29
+
30
+ @Directive('@privilege(category: "accounting", privilege: "query")')
31
+ @Query(returns => AccountingCategory!, { nullable: true, description: 'To fetch a AccountingCategory' })
32
+ async accountingCategory(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<AccountingCategory> {
33
+ const { domain } = context.state
34
+
35
+ return await getRepository(AccountingCategory).findOne({
36
+ where: { domain: { id: domain.id }, id }
37
+ })
38
+ }
39
+
40
+ @Directive('@privilege(category: "accounting", privilege: "query")')
41
+ @Query(returns => AccountingCategoryList, { description: 'To fetch multiple AccountingCategories' })
42
+ async accountingCategories(
43
+ @Args() params: ListParam,
44
+ @Ctx() context: ResolverContext
45
+ ): Promise<AccountingCategoryList> {
46
+ const { domain } = context.state
47
+
48
+ const queryBuilder = getQueryBuilderFromListParams({
49
+ domain,
50
+ params,
51
+ repository: await getRepository(AccountingCategory),
52
+ searchables: ['name', 'description']
53
+ })
54
+
55
+ const [items, total] = await queryBuilder.getManyAndCount()
56
+
57
+ return { items, total }
58
+ }
59
+
60
+ @FieldResolver(type => Domain)
61
+ async domain(@Root() accountingCategory: AccountingCategory): Promise<Domain> {
62
+ return await getRepository(Domain).findOneBy({ id: accountingCategory.domainId })
63
+ }
64
+
65
+ @FieldResolver(type => User)
66
+ async updater(@Root() accountingCategory: AccountingCategory): Promise<User> {
67
+ return await getRepository(User).findOneBy({ id: accountingCategory.updaterId })
68
+ }
69
+
70
+ @FieldResolver(type => User)
71
+ async creator(@Root() accountingCategory: AccountingCategory): Promise<User> {
72
+ return await getRepository(User).findOneBy({ id: accountingCategory.creatorId })
73
+ }
74
+ }
@@ -0,0 +1,48 @@
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({ nullable: true, description: 'Account category code' })
8
+ code: string
9
+
10
+ @Field()
11
+ name: string
12
+
13
+ @Field({ nullable: true })
14
+ description?: string
15
+
16
+ @Field({ nullable: true })
17
+ active?: boolean
18
+ }
19
+
20
+ @InputType()
21
+ export class AccountingCategoryPatch {
22
+ @Field(type => ID, { nullable: true })
23
+ id?: string
24
+
25
+ @Field({ nullable: true, description: 'Account category code' })
26
+ code?: string
27
+
28
+ @Field({ nullable: true })
29
+ name?: string
30
+
31
+ @Field({ nullable: true })
32
+ description?: string
33
+
34
+ @Field({ nullable: true })
35
+ active?: boolean
36
+
37
+ @Field({ nullable: true })
38
+ cuFlag?: string
39
+ }
40
+
41
+ @ObjectType()
42
+ export class AccountingCategoryList {
43
+ @Field(type => [AccountingCategory])
44
+ items: AccountingCategory[]
45
+
46
+ @Field(type => Int)
47
+ total: number
48
+ }
@@ -0,0 +1,100 @@
1
+ import {
2
+ CreateDateColumn,
3
+ UpdateDateColumn,
4
+ DeleteDateColumn,
5
+ Entity,
6
+ Index,
7
+ Column,
8
+ RelationId,
9
+ ManyToOne,
10
+ OneToMany,
11
+ PrimaryGeneratedColumn
12
+ } from 'typeorm'
13
+ import { ObjectType, Field, Int, ID } from 'type-graphql'
14
+
15
+ import { Domain } from '@things-factory/shell'
16
+ import { User } from '@things-factory/auth-base'
17
+
18
+ @Entity()
19
+ @Index(
20
+ 'ix_accounting_category_0',
21
+ (accountingCategory: AccountingCategory) => [accountingCategory.domain, accountingCategory.name],
22
+ {
23
+ unique: true,
24
+ where: '"deleted_at" IS NULL'
25
+ }
26
+ )
27
+ @Index(
28
+ 'ix_accounting_category_1',
29
+ (accountingCategory: AccountingCategory) => [accountingCategory.domain, accountingCategory.code],
30
+ {
31
+ unique: true,
32
+ where: '"deleted_at" IS NULL'
33
+ }
34
+ )
35
+ @ObjectType({ description: 'Entity for AccountingCategory' })
36
+ export class AccountingCategory {
37
+ @PrimaryGeneratedColumn('uuid')
38
+ @Field(type => ID)
39
+ readonly id: string
40
+
41
+ @ManyToOne(type => Domain)
42
+ @Field({ nullable: true })
43
+ domain?: Domain
44
+
45
+ @RelationId((accountingCategory: AccountingCategory) => accountingCategory.domain)
46
+ domainId?: string
47
+
48
+ @Column()
49
+ @Field({ nullable: true, description: 'Account category code' })
50
+ code?: string
51
+
52
+ @Column()
53
+ @Field({ nullable: true })
54
+ name?: string
55
+
56
+ @Column({ nullable: true })
57
+ @Field({ nullable: true })
58
+ description?: string
59
+
60
+ @Column({ nullable: true })
61
+ @Field({ nullable: true })
62
+ active?: boolean
63
+
64
+ @ManyToOne(type => AccountingCategory, accountingCategory => accountingCategory.children, { nullable: true })
65
+ @Field({ nullable: true })
66
+ parent?: AccountingCategory
67
+
68
+ @RelationId((accountingCategory: AccountingCategory) => accountingCategory.parent)
69
+ parentId?: string
70
+
71
+ @OneToMany(type => AccountingCategory, accountingCategory => accountingCategory.parent)
72
+ @Field(type => [AccountingCategory], { nullable: true })
73
+ children?: AccountingCategory[]
74
+
75
+ @CreateDateColumn()
76
+ @Field({ nullable: true })
77
+ createdAt?: Date
78
+
79
+ @UpdateDateColumn()
80
+ @Field({ nullable: true })
81
+ updatedAt?: Date
82
+
83
+ @ManyToOne(type => User, { nullable: true })
84
+ @Field(type => User, { nullable: true })
85
+ creator?: User
86
+
87
+ @RelationId((accountingCategory: AccountingCategory) => accountingCategory.creator)
88
+ creatorId?: string
89
+
90
+ @ManyToOne(type => User, { nullable: true })
91
+ @Field(type => User, { nullable: true })
92
+ updater?: User
93
+
94
+ @RelationId((accountingCategory: AccountingCategory) => accountingCategory.updater)
95
+ updaterId?: string
96
+
97
+ @DeleteDateColumn()
98
+ @Field({ nullable: true })
99
+ deletedAt?: Date
100
+ }
@@ -0,0 +1,20 @@
1
+ import { EventSubscriber } from 'typeorm'
2
+
3
+ import { HistoryEntitySubscriber } from '@operato/typeorm-history'
4
+
5
+ import { AccountingCategory } from './accounting-category'
6
+ import { AccountingCategoryHistory } from './accounting-category-history'
7
+
8
+ @EventSubscriber()
9
+ export class AccountingCategoryHistoryEntitySubscriber extends HistoryEntitySubscriber<
10
+ AccountingCategory,
11
+ AccountingCategoryHistory
12
+ > {
13
+ public get entity() {
14
+ return AccountingCategory
15
+ }
16
+
17
+ public get historyEntity() {
18
+ return AccountingCategoryHistory
19
+ }
20
+ }