@things-factory/sales-base 8.0.0-beta.9 → 8.0.0

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 (178) hide show
  1. package/dist-server/tsconfig.tsbuildinfo +1 -1
  2. package/package.json +13 -13
  3. package/server/constants/attachment-type.ts +9 -0
  4. package/server/constants/index.ts +7 -0
  5. package/server/constants/load-type.ts +4 -0
  6. package/server/constants/order.ts +203 -0
  7. package/server/constants/product-group-type.ts +4 -0
  8. package/server/constants/release-good.ts +9 -0
  9. package/server/constants/transfer-order-type.ts +6 -0
  10. package/server/constants/validation-error-code.ts +3 -0
  11. package/server/constants/vas-target-type.ts +25 -0
  12. package/server/controllers/ecommerce/ecommerce-controller.ts +122 -0
  13. package/server/controllers/ecommerce/index.ts +2 -0
  14. package/server/controllers/ecommerce/sellercraft-controller.ts +182 -0
  15. package/server/controllers/index.ts +2 -0
  16. package/server/controllers/order-controller.ts +296 -0
  17. package/server/errors/index.ts +1 -0
  18. package/server/errors/validation-error.ts +25 -0
  19. package/server/index.ts +5 -0
  20. package/server/migrations/index.ts +9 -0
  21. package/server/service/arrival-notice/arrival-notice-mutation.ts +1152 -0
  22. package/server/service/arrival-notice/arrival-notice-query.ts +549 -0
  23. package/server/service/arrival-notice/arrival-notice-types.ts +310 -0
  24. package/server/service/arrival-notice/arrival-notice.ts +202 -0
  25. package/server/service/arrival-notice/index.ts +9 -0
  26. package/server/service/claim/claim-mutation.ts +308 -0
  27. package/server/service/claim/claim-query.ts +122 -0
  28. package/server/service/claim/claim-types.ts +130 -0
  29. package/server/service/claim/claim.ts +140 -0
  30. package/server/service/claim/index.ts +9 -0
  31. package/server/service/claim-detail/claim-detail-mutation.ts +102 -0
  32. package/server/service/claim-detail/claim-detail-query.ts +55 -0
  33. package/server/service/claim-detail/claim-detail-types.ts +47 -0
  34. package/server/service/claim-detail/claim-detail.ts +69 -0
  35. package/server/service/claim-detail/index.ts +9 -0
  36. package/server/service/claim-order/claim-order-mutation.ts +101 -0
  37. package/server/service/claim-order/claim-order-query.ts +47 -0
  38. package/server/service/claim-order/claim-order-types.ts +35 -0
  39. package/server/service/claim-order/claim-order.ts +81 -0
  40. package/server/service/claim-order/index.ts +9 -0
  41. package/server/service/collection-order/collection-order-mutation.ts +245 -0
  42. package/server/service/collection-order/collection-order-query.ts +97 -0
  43. package/server/service/collection-order/collection-order-types.ts +165 -0
  44. package/server/service/collection-order/collection-order.ts +135 -0
  45. package/server/service/collection-order/index.ts +9 -0
  46. package/server/service/delivery-order/delivery-order-mutation.ts +967 -0
  47. package/server/service/delivery-order/delivery-order-query.ts +631 -0
  48. package/server/service/delivery-order/delivery-order-types.ts +268 -0
  49. package/server/service/delivery-order/delivery-order.ts +258 -0
  50. package/server/service/delivery-order/index.ts +9 -0
  51. package/server/service/draft-release-good/draft-release-good-mutation.ts +765 -0
  52. package/server/service/draft-release-good/draft-release-good-query.ts +354 -0
  53. package/server/service/draft-release-good/draft-release-good-type.ts +261 -0
  54. package/server/service/draft-release-good/draft-release-good.ts +284 -0
  55. package/server/service/draft-release-good/index.ts +9 -0
  56. package/server/service/goods-receival-note/goods-receival-note-mutation.ts +129 -0
  57. package/server/service/goods-receival-note/goods-receival-note-query.ts +280 -0
  58. package/server/service/goods-receival-note/goods-receival-note-types.ts +105 -0
  59. package/server/service/goods-receival-note/goods-receival-note.ts +127 -0
  60. package/server/service/goods-receival-note/index.ts +9 -0
  61. package/server/service/index.ts +238 -0
  62. package/server/service/inventory-check/index.ts +9 -0
  63. package/server/service/inventory-check/inventory-check-mutation.ts +149 -0
  64. package/server/service/inventory-check/inventory-check-query.ts +48 -0
  65. package/server/service/inventory-check/inventory-check-types.ts +48 -0
  66. package/server/service/inventory-check/inventory-check.ts +90 -0
  67. package/server/service/invoice/index.ts +9 -0
  68. package/server/service/invoice/invoice-mutation.ts +95 -0
  69. package/server/service/invoice/invoice-query.ts +53 -0
  70. package/server/service/invoice/invoice-types.ts +279 -0
  71. package/server/service/invoice/invoice.ts +230 -0
  72. package/server/service/invoice-product/index.ts +9 -0
  73. package/server/service/invoice-product/invoice-product-mutation.ts +54 -0
  74. package/server/service/invoice-product/invoice-product-query.ts +54 -0
  75. package/server/service/invoice-product/invoice-product-types.ts +84 -0
  76. package/server/service/invoice-product/invoice-product.ts +92 -0
  77. package/server/service/job-sheet/index.ts +9 -0
  78. package/server/service/job-sheet/job-sheet-mutation.ts +92 -0
  79. package/server/service/job-sheet/job-sheet-query.ts +112 -0
  80. package/server/service/job-sheet/job-sheet-types.ts +78 -0
  81. package/server/service/job-sheet/job-sheet.ts +102 -0
  82. package/server/service/manifest/index.ts +6 -0
  83. package/server/service/manifest/manifest-mutation.ts +190 -0
  84. package/server/service/manifest/manifest-query.ts +149 -0
  85. package/server/service/manifest/manifest-type.ts +84 -0
  86. package/server/service/manifest/manifest.ts +114 -0
  87. package/server/service/order-inventory/index.ts +9 -0
  88. package/server/service/order-inventory/order-inventory-mutation.ts +54 -0
  89. package/server/service/order-inventory/order-inventory-query.ts +722 -0
  90. package/server/service/order-inventory/order-inventory-types.ts +238 -0
  91. package/server/service/order-inventory/order-inventory.ts +401 -0
  92. package/server/service/order-product/index.ts +9 -0
  93. package/server/service/order-product/order-product-mutation.ts +48 -0
  94. package/server/service/order-product/order-product-query.ts +89 -0
  95. package/server/service/order-product/order-product-types.ts +335 -0
  96. package/server/service/order-product/order-product.ts +362 -0
  97. package/server/service/order-tote/index.ts +9 -0
  98. package/server/service/order-tote/order-tote-mutation.ts +31 -0
  99. package/server/service/order-tote/order-tote-query.ts +112 -0
  100. package/server/service/order-tote/order-tote-types.ts +47 -0
  101. package/server/service/order-tote/order-tote.ts +73 -0
  102. package/server/service/order-tote-item/index.ts +9 -0
  103. package/server/service/order-tote-item/order-tote-item-mutation.ts +31 -0
  104. package/server/service/order-tote-item/order-tote-item-query.ts +82 -0
  105. package/server/service/order-tote-item/order-tote-item-types.ts +56 -0
  106. package/server/service/order-tote-item/order-tote-item.ts +72 -0
  107. package/server/service/order-tote-seal/index.ts +9 -0
  108. package/server/service/order-tote-seal/order-tote-seal-mutation.ts +31 -0
  109. package/server/service/order-tote-seal/order-tote-seal-query.ts +59 -0
  110. package/server/service/order-tote-seal/order-tote-seal-types.ts +41 -0
  111. package/server/service/order-tote-seal/order-tote-seal.ts +46 -0
  112. package/server/service/order-vas/index.ts +9 -0
  113. package/server/service/order-vas/order-vas-mutation.ts +20 -0
  114. package/server/service/order-vas/order-vas-query.ts +72 -0
  115. package/server/service/order-vas/order-vas-types.ts +159 -0
  116. package/server/service/order-vas/order-vas.ts +207 -0
  117. package/server/service/others/index.ts +5 -0
  118. package/server/service/others/other-query.ts +563 -0
  119. package/server/service/others/other-types.ts +115 -0
  120. package/server/service/purchase-order/index.ts +9 -0
  121. package/server/service/purchase-order/purchase-order-mutation.ts +458 -0
  122. package/server/service/purchase-order/purchase-order-query.ts +90 -0
  123. package/server/service/purchase-order/purchase-order-types.ts +154 -0
  124. package/server/service/purchase-order/purchase-order.ts +172 -0
  125. package/server/service/purchase-order-other-charge/index.ts +9 -0
  126. package/server/service/purchase-order-other-charge/purchase-order-other-charge-mutation.ts +31 -0
  127. package/server/service/purchase-order-other-charge/purchase-order-other-charge-query.ts +52 -0
  128. package/server/service/purchase-order-other-charge/purchase-order-other-charge-types.ts +44 -0
  129. package/server/service/purchase-order-other-charge/purchase-order-other-charge.ts +68 -0
  130. package/server/service/release-good/index.ts +9 -0
  131. package/server/service/release-good/release-good-mutation.ts +1686 -0
  132. package/server/service/release-good/release-good-query.ts +980 -0
  133. package/server/service/release-good/release-good-types.ts +662 -0
  134. package/server/service/release-good/release-good.ts +490 -0
  135. package/server/service/retail-replenishment-order/index.ts +9 -0
  136. package/server/service/retail-replenishment-order/retail-replenishment-order-mutation.ts +382 -0
  137. package/server/service/retail-replenishment-order/retail-replenishment-order-query.ts +54 -0
  138. package/server/service/retail-replenishment-order/retail-replenishment-order-types.ts +101 -0
  139. package/server/service/retail-replenishment-order/retail-replenishment-order.ts +115 -0
  140. package/server/service/return-order/index.ts +9 -0
  141. package/server/service/return-order/return-order-mutation.ts +516 -0
  142. package/server/service/return-order/return-order-query.ts +226 -0
  143. package/server/service/return-order/return-order-types.ts +196 -0
  144. package/server/service/return-order/return-order.ts +127 -0
  145. package/server/service/reverse-kitting-order/index.ts +9 -0
  146. package/server/service/reverse-kitting-order/reverse-kitting-order-mutation.ts +500 -0
  147. package/server/service/reverse-kitting-order/reverse-kitting-order-query.ts +197 -0
  148. package/server/service/reverse-kitting-order/reverse-kitting-order-type.ts +173 -0
  149. package/server/service/reverse-kitting-order/reverse-kitting-order.ts +121 -0
  150. package/server/service/reverse-kitting-order-inventory/index.ts +9 -0
  151. package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-mutation.ts +129 -0
  152. package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-query.ts +52 -0
  153. package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory-type.ts +95 -0
  154. package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.ts +143 -0
  155. package/server/service/shipping-order/index.ts +9 -0
  156. package/server/service/shipping-order/shipping-order-mutation.ts +61 -0
  157. package/server/service/shipping-order/shipping-order-query.ts +61 -0
  158. package/server/service/shipping-order/shipping-order-types.ts +89 -0
  159. package/server/service/shipping-order/shipping-order.ts +129 -0
  160. package/server/service/transfer-order/index.ts +9 -0
  161. package/server/service/transfer-order/transfer-order-mutation.ts +309 -0
  162. package/server/service/transfer-order/transfer-order-query.ts +66 -0
  163. package/server/service/transfer-order/transfer-order-types.ts +97 -0
  164. package/server/service/transfer-order/transfer-order.ts +117 -0
  165. package/server/service/vas/index.ts +9 -0
  166. package/server/service/vas/vas-mutation.ts +106 -0
  167. package/server/service/vas/vas-query.ts +60 -0
  168. package/server/service/vas/vas-types.ts +71 -0
  169. package/server/service/vas/vas.ts +77 -0
  170. package/server/service/vas-order/index.ts +9 -0
  171. package/server/service/vas-order/vas-order-mutation.ts +259 -0
  172. package/server/service/vas-order/vas-order-query.ts +119 -0
  173. package/server/service/vas-order/vas-order-types.ts +49 -0
  174. package/server/service/vas-order/vas-order.ts +81 -0
  175. package/server/utils/datetime-util.ts +54 -0
  176. package/server/utils/index.ts +3 -0
  177. package/server/utils/inventory-util.ts +1155 -0
  178. package/server/utils/order-no-generator.ts +146 -0
@@ -0,0 +1,230 @@
1
+ import { Field, ID, ObjectType } from 'type-graphql'
2
+ import {
3
+ Column,
4
+ CreateDateColumn,
5
+ Entity,
6
+ Index,
7
+ JoinColumn,
8
+ ManyToOne,
9
+ OneToMany,
10
+ OneToOne,
11
+ PrimaryGeneratedColumn,
12
+ RelationId,
13
+ UpdateDateColumn
14
+ } from 'typeorm'
15
+
16
+ import { User } from '@things-factory/auth-base'
17
+ import { Domain } from '@things-factory/shell'
18
+
19
+ import { InvoiceProduct } from '../invoice-product/invoice-product'
20
+ import { ReleaseGood } from '../release-good/release-good'
21
+
22
+ @Entity()
23
+ @Index('ix_invoice_0', (invoice: Invoice) => [invoice.id], { unique: true })
24
+ @ObjectType()
25
+ export class Invoice {
26
+ @PrimaryGeneratedColumn('uuid')
27
+ @Field(type => ID)
28
+ readonly id: string
29
+
30
+ @ManyToOne(type => Domain)
31
+ @Field(type => Domain, { nullable: true })
32
+ domain: Domain
33
+
34
+ @RelationId((invoice: Invoice) => invoice.domain)
35
+ domainId: string
36
+
37
+ @Column()
38
+ @Field()
39
+ name: string
40
+
41
+ @Column({ nullable: true })
42
+ @Field({ nullable: true })
43
+ description: string
44
+
45
+ @OneToMany(type => InvoiceProduct, invoiceProduct => invoiceProduct.invoice)
46
+ @Field(type => [InvoiceProduct], { nullable: true })
47
+ invoiceProducts: InvoiceProduct[]
48
+
49
+ @OneToOne(type => ReleaseGood, { nullable: true })
50
+ @Field(type => ReleaseGood, { nullable: true })
51
+ @JoinColumn()
52
+ releaseGood: ReleaseGood
53
+
54
+ @Column({ default: '' })
55
+ @Field({ nullable: true })
56
+ refNo1: string
57
+
58
+ @Column({ default: '' })
59
+ @Field({ nullable: true })
60
+ refNo2: string
61
+
62
+ @Column({ default: '' })
63
+ @Field({ nullable: true })
64
+ refNo3: string
65
+
66
+ @Column({ nullable: true })
67
+ @Field({ nullable: true })
68
+ issuedOn: Date
69
+
70
+ @Column({ type: 'uuid', nullable: true })
71
+ @Field({ nullable: true })
72
+ contactPointRefId: string
73
+
74
+ @Column()
75
+ @Field()
76
+ from: string
77
+
78
+ @Column()
79
+ @Field()
80
+ fromContactPhone: string
81
+
82
+ @Column({ nullable: true })
83
+ @Field({ nullable: true })
84
+ fromAddress1: string
85
+
86
+ @Column({ nullable: true })
87
+ @Field({ nullable: true })
88
+ fromAddress2: string
89
+
90
+ @Column({ nullable: true })
91
+ @Field({ nullable: true })
92
+ fromAddress3: string
93
+
94
+ @Column({ nullable: true })
95
+ @Field({ nullable: true })
96
+ fromAddress4: string
97
+
98
+ @Column({ nullable: true })
99
+ @Field({ nullable: true })
100
+ fromAddress5: string
101
+
102
+ @Column({ nullable: true })
103
+ @Field({ nullable: true })
104
+ fromPostcode: string
105
+
106
+ @Column({ nullable: true })
107
+ @Field({ nullable: true })
108
+ fromCity: string
109
+
110
+ @Column({ nullable: true })
111
+ @Field({ nullable: true })
112
+ fromState: string
113
+
114
+ @Column({ nullable: true })
115
+ @Field({ nullable: true })
116
+ fromCountry: string
117
+
118
+ @Column()
119
+ @Field()
120
+ deliverTo: string
121
+
122
+ @Column()
123
+ @Field()
124
+ deliverToPhone: string
125
+
126
+ @Column()
127
+ @Field()
128
+ deliveryAddress1: string
129
+
130
+ @Column({ nullable: true })
131
+ @Field({ nullable: true })
132
+ deliveryAddress2: string
133
+
134
+ @Column({ nullable: true })
135
+ @Field({ nullable: true })
136
+ deliveryAddress3: string
137
+
138
+ @Column({ nullable: true })
139
+ @Field({ nullable: true })
140
+ deliveryAddress4: string
141
+
142
+ @Column({ nullable: true })
143
+ @Field({ nullable: true })
144
+ deliveryAddress5: string
145
+
146
+ @Column()
147
+ @Field()
148
+ deliveryPostcode: string
149
+
150
+ @Column()
151
+ @Field()
152
+ deliveryCity: string
153
+
154
+ @Column()
155
+ @Field()
156
+ deliveryState: string
157
+
158
+ @Column()
159
+ @Field()
160
+ deliveryCountry: string
161
+
162
+ @Column()
163
+ @Field()
164
+ billTo: string
165
+
166
+ @Column()
167
+ @Field()
168
+ billToPhone: string
169
+
170
+ @Column()
171
+ @Field()
172
+ billingAddress1: string
173
+
174
+ @Column({ nullable: true })
175
+ @Field({ nullable: true })
176
+ billingAddress2: string
177
+
178
+ @Column({ nullable: true })
179
+ @Field({ nullable: true })
180
+ billingAddress3: string
181
+
182
+ @Column({ nullable: true })
183
+ @Field({ nullable: true })
184
+ billingAddress4: string
185
+
186
+ @Column({ nullable: true })
187
+ @Field({ nullable: true })
188
+ billingAddress5: string
189
+
190
+ @Column()
191
+ @Field()
192
+ billingPostcode: string
193
+
194
+ @Column()
195
+ @Field()
196
+ billingCity: string
197
+
198
+ @Column()
199
+ @Field()
200
+ billingState: string
201
+
202
+ @Column()
203
+ @Field()
204
+ billingCountry: string
205
+
206
+ @Field({ nullable: true })
207
+ paymentDue: string
208
+
209
+ @CreateDateColumn()
210
+ @Field()
211
+ createdAt: Date
212
+
213
+ @UpdateDateColumn()
214
+ @Field()
215
+ updatedAt: Date
216
+
217
+ @ManyToOne(type => User)
218
+ @Field(type => User, { nullable: true })
219
+ creator: User
220
+
221
+ @RelationId((invoice: Invoice) => invoice.creator)
222
+ creatorId: string
223
+
224
+ @ManyToOne(type => User)
225
+ @Field(type => User, { nullable: true })
226
+ updater: User
227
+
228
+ @RelationId((invoice: Invoice) => invoice.updater)
229
+ updaterId: string
230
+ }
@@ -0,0 +1,9 @@
1
+ import { InvoiceProduct } from './invoice-product'
2
+ import { InvoiceProductMutation } from './invoice-product-mutation'
3
+ import { InvoiceProductQuery } from './invoice-product-query'
4
+
5
+ export const entities = [InvoiceProduct]
6
+ export const resolvers = [InvoiceProductQuery, InvoiceProductMutation]
7
+
8
+ export * from './invoice-product-mutation'
9
+ export * from './invoice-product-query'
@@ -0,0 +1,54 @@
1
+ import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
+
3
+ import { InvoiceProduct } from '../invoice-product/invoice-product'
4
+ import { InvoiceProductPatch, NewInvoiceProduct } from './invoice-product-types'
5
+
6
+ @Resolver(InvoiceProduct)
7
+ export class InvoiceProductMutation {
8
+ @Mutation(returns => InvoiceProduct)
9
+ @Directive('@transaction')
10
+ async createInvoiceProduct(
11
+ @Arg('invoiceProduct', type => NewInvoiceProduct) invoiceProduct: NewInvoiceProduct,
12
+ @Ctx() context: ResolverContext
13
+ ): Promise<InvoiceProduct> {
14
+ const { domain, user, tx } = context.state
15
+
16
+ return await tx.getRepository(InvoiceProduct).save({
17
+ ...invoiceProduct,
18
+ domain,
19
+ creator: user,
20
+ updater: user
21
+ })
22
+ }
23
+
24
+ @Mutation(returns => InvoiceProduct)
25
+ @Directive('@transaction')
26
+ async updateInvoiceProduct(
27
+ @Arg('name') name: string,
28
+ @Arg('patch', type => InvoiceProductPatch) patch: InvoiceProductPatch,
29
+ @Ctx() context: ResolverContext
30
+ ): Promise<InvoiceProduct> {
31
+ const { domain, user, tx } = context.state
32
+
33
+ const repository = tx.getRepository(InvoiceProduct)
34
+ const invoiceProduct = await repository.findOne({
35
+ where: { domain: { id: domain.id }, name }
36
+ })
37
+
38
+ return await repository.save({
39
+ ...invoiceProduct,
40
+ ...patch,
41
+ updater: user
42
+ })
43
+ }
44
+
45
+ @Mutation(returns => Boolean)
46
+ @Directive('@transaction')
47
+ async deleteInvoiceProduct(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<boolean> {
48
+ const { domain, tx } = context.state
49
+
50
+ await tx.getRepository(InvoiceProduct).delete({ domain: { id: domain.id }, name })
51
+
52
+ return true
53
+ }
54
+ }
@@ -0,0 +1,54 @@
1
+ import { Arg, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'
2
+
3
+ import { User } from '@things-factory/auth-base'
4
+ import { buildQuery, Domain, Filter, getRepository, Pagination, Sorting } from '@things-factory/shell'
5
+
6
+ import { InvoiceProduct } from './invoice-product'
7
+ import { InvoiceProductList } from './invoice-product-types'
8
+
9
+ @Resolver(InvoiceProduct)
10
+ export class InvoiceProductQuery {
11
+ @Query(returns => InvoiceProductList)
12
+ async invoiceProducts(
13
+ @Ctx() context: ResolverContext,
14
+ @Arg('filters', type => [Filter], { nullable: true }) filters?: Filter[],
15
+ @Arg('pagination', type => Pagination, { nullable: true }) pagination?: Pagination,
16
+ @Arg('sortings', type => [Sorting], { nullable: true }) sortings?: Sorting[]
17
+ ): Promise<InvoiceProductList> {
18
+ const queryBuilder = getRepository(InvoiceProduct).createQueryBuilder()
19
+ buildQuery(queryBuilder, { filters, pagination, sortings }, context)
20
+ const [items, total] = await queryBuilder
21
+ .leftJoinAndSelect('InvoiceProduct.domain', 'Domain')
22
+ .leftJoinAndSelect('InvoiceProduct.invoice', 'Invoice')
23
+ .leftJoinAndSelect('InvoiceProduct.creator', 'Creator')
24
+ .leftJoinAndSelect('InvoiceProduct.updater', 'Updater')
25
+ .getManyAndCount()
26
+
27
+ return { items, total }
28
+ }
29
+
30
+ @Query(returns => InvoiceProduct)
31
+ async invoiceProduct(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<InvoiceProduct> {
32
+ const { domain } = context.state
33
+
34
+ return await getRepository(InvoiceProduct).findOne({
35
+ where: { domain: { id: domain.id }, name },
36
+ relations: ['domain', 'invoice', 'creator', 'updater']
37
+ })
38
+ }
39
+
40
+ @FieldResolver(type => Domain)
41
+ async domain(@Root() invoiceProduct: InvoiceProduct): Promise<Domain> {
42
+ return await getRepository(Domain).findOneBy({ id: invoiceProduct.domainId })
43
+ }
44
+
45
+ @FieldResolver(type => User)
46
+ async creator(@Root() invoiceProduct: InvoiceProduct): Promise<User> {
47
+ return await getRepository(User).findOneBy({ id: invoiceProduct.creatorId })
48
+ }
49
+
50
+ @FieldResolver(type => User)
51
+ async updater(@Root() invoiceProduct: InvoiceProduct): Promise<User> {
52
+ return await getRepository(User).findOneBy({ id: invoiceProduct.updaterId })
53
+ }
54
+ }
@@ -0,0 +1,84 @@
1
+ import { Field, Float, InputType, Int, ObjectType } from 'type-graphql'
2
+
3
+ import { InvoiceProduct } from './invoice-product'
4
+
5
+ @ObjectType()
6
+ export class InvoiceProductList {
7
+ @Field(type => [InvoiceProduct], { nullable: true })
8
+ items: InvoiceProduct[]
9
+
10
+ @Field(type => Int, { nullable: true })
11
+ total: number
12
+ }
13
+
14
+ @InputType()
15
+ export class ProductInput {
16
+ @Field()
17
+ sku: string
18
+ }
19
+
20
+ @InputType()
21
+ export class NewInvoiceProduct {
22
+ @Field({ nullable: true })
23
+ name: string
24
+
25
+ @Field({ nullable: true })
26
+ sku: string
27
+
28
+ @Field({ nullable: true })
29
+ description: string
30
+
31
+ @Field(type => ProductInput, { nullable: true })
32
+ product: ProductInput
33
+
34
+ @Field(type => Int)
35
+ qty: number
36
+
37
+ @Field(type => Float, { nullable: true })
38
+ otherCharges: number
39
+
40
+ @Field(type => Float)
41
+ unitPrice: number
42
+
43
+ @Field(type => Float)
44
+ paidPrice: number
45
+
46
+ @Field(type => Float, { nullable: true })
47
+ discount: number
48
+
49
+ @Field(type => Float, { nullable: true })
50
+ shippingFeePaidByCustomer: number
51
+ }
52
+
53
+ @InputType()
54
+ export class InvoiceProductPatch {
55
+ @Field({ nullable: true })
56
+ name: string
57
+
58
+ @Field({ nullable: true })
59
+ sku: string
60
+
61
+ @Field({ nullable: true })
62
+ description: string
63
+
64
+ @Field(type => ProductInput)
65
+ product: ProductInput
66
+
67
+ @Field(type => Int)
68
+ qty: number
69
+
70
+ @Field(type => Float, { nullable: true })
71
+ otherCharges: number
72
+
73
+ @Field(type => Float)
74
+ unitPrice: number
75
+
76
+ @Field(type => Float)
77
+ paidPrice: number
78
+
79
+ @Field(type => Float, { nullable: true })
80
+ discount: number
81
+
82
+ @Field(type => Float, { nullable: true })
83
+ shippingFeePaidByCustomer: number
84
+ }
@@ -0,0 +1,92 @@
1
+ import { Field, ID, ObjectType } from 'type-graphql'
2
+ import { Column, CreateDateColumn, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId, UpdateDateColumn } from 'typeorm'
3
+
4
+ import { User } from '@things-factory/auth-base'
5
+ import { Product } from '@things-factory/product-base'
6
+ import { Domain, roundTransformer } from '@things-factory/shell'
7
+
8
+ import { Invoice } from '../invoice/invoice'
9
+
10
+ @Entity()
11
+ @Index('ix_invoice_product_0', (invoiceProduct: InvoiceProduct) => [invoiceProduct.id], {
12
+ unique: true
13
+ })
14
+ @ObjectType()
15
+ export class InvoiceProduct {
16
+ @PrimaryGeneratedColumn('uuid')
17
+ @Field(type => ID)
18
+ readonly id: string
19
+
20
+ @ManyToOne(type => Domain)
21
+ @Field(type => Domain, { nullable: true })
22
+ domain: Domain
23
+
24
+ @RelationId((invoiceProduct: InvoiceProduct) => invoiceProduct.domain)
25
+ domainId: string
26
+
27
+ @Column({ nullable: true })
28
+ @Field({ nullable: true })
29
+ sku: string
30
+
31
+ @Column()
32
+ @Field()
33
+ name: string
34
+
35
+ @Column({ nullable: true })
36
+ @Field()
37
+ description: string
38
+
39
+ @ManyToOne(type => Invoice)
40
+ @Field(type => Invoice)
41
+ invoice: Invoice
42
+
43
+ @ManyToOne(type => Product, { nullable: true })
44
+ @Field(type => Product, { nullable: true })
45
+ product: Product
46
+
47
+ @Column('int', { default: 0 })
48
+ @Field()
49
+ qty: number
50
+
51
+ @Column('float', { default: 0, transformer: roundTransformer })
52
+ @Field({ nullable: true })
53
+ otherCharges: number
54
+
55
+ @Column('float', { default: 0, transformer: roundTransformer })
56
+ @Field()
57
+ unitPrice: number
58
+
59
+ @Column('float', { default: 0, transformer: roundTransformer })
60
+ @Field()
61
+ paidPrice: number
62
+
63
+ @Column('float', { default: 0, transformer: roundTransformer })
64
+ @Field({ nullable: true })
65
+ discount: number
66
+
67
+ @Column('float', { default: 0, transformer: roundTransformer })
68
+ @Field({ nullable: true })
69
+ shippingFeePaidByCustomer: number
70
+
71
+ @CreateDateColumn()
72
+ @Field()
73
+ createdAt: Date
74
+
75
+ @UpdateDateColumn()
76
+ @Field({ nullable: true })
77
+ updatedAt: Date
78
+
79
+ @ManyToOne(type => User, { nullable: true })
80
+ @Field(type => User, { nullable: true })
81
+ creator: User
82
+
83
+ @RelationId((invoiceProduct: InvoiceProduct) => invoiceProduct.creator)
84
+ creatorId: string
85
+
86
+ @ManyToOne(type => User, { nullable: true })
87
+ @Field(type => User, { nullable: true })
88
+ updater: User
89
+
90
+ @RelationId((invoiceProduct: InvoiceProduct) => invoiceProduct.updater)
91
+ updaterId: string
92
+ }
@@ -0,0 +1,9 @@
1
+ import { JobSheet } from './job-sheet'
2
+ import { JobSheetMutation } from './job-sheet-mutation'
3
+ import { JobSheetQuery } from './job-sheet-query'
4
+
5
+ export const entities = [JobSheet]
6
+ export const resolvers = [JobSheetQuery, JobSheetMutation]
7
+
8
+ export * from './job-sheet-mutation'
9
+ export * from './job-sheet-query'
@@ -0,0 +1,92 @@
1
+ import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
2
+ import { EntityManager, Repository } from 'typeorm'
3
+
4
+ import { User } from '@things-factory/auth-base'
5
+ import { Domain, getRepository } from '@things-factory/shell'
6
+
7
+ import { ArrivalNotice, ArrivalNoticePatch, JobSheetPatch } from '../'
8
+ import { OrderNoGenerator } from '../../utils/order-no-generator'
9
+ import { JobSheet } from './job-sheet'
10
+
11
+ @Resolver(JobSheet)
12
+ export class JobSheetMutation {
13
+ @Directive('@transaction')
14
+ @Mutation(returns => JobSheet)
15
+ async generateJobSheet(
16
+ @Ctx() context: ResolverContext,
17
+ @Arg('arrivalNotice', type => ArrivalNoticePatch, { nullable: true }) arrivalNotice?: ArrivalNoticePatch
18
+ ): Promise<JobSheet> {
19
+ const { domain, user, tx } = context.state
20
+ return await generateJobSheet(domain, user, arrivalNotice, tx)
21
+ }
22
+
23
+ @Directive('@transaction')
24
+ @Mutation(returns => JobSheet)
25
+ async updateJobSheet(
26
+ @Arg('name') name: string,
27
+ @Arg('patch', type => JobSheetPatch) patch: JobSheetPatch,
28
+ @Ctx() context: ResolverContext
29
+ ): Promise<JobSheet> {
30
+ const { tx, domain, user } = context.state
31
+
32
+ const jobSheet = await tx.getRepository(JobSheet).findOne({ where: { domain: { id: domain.id }, name } })
33
+ if (!jobSheet) throw new Error('No job sheet is found')
34
+
35
+ const foundGAN: ArrivalNotice = await tx.getRepository(ArrivalNotice).findOne({
36
+ where: {
37
+ domain: { id: domain.id },
38
+ name: jobSheet.arrivalNoticeRefNo
39
+ }
40
+ })
41
+
42
+ await tx.getRepository(ArrivalNotice).save({
43
+ ...foundGAN,
44
+ ata: patch.ata,
45
+ updater: user
46
+ })
47
+
48
+ return await tx.getRepository(JobSheet).save({
49
+ ...jobSheet,
50
+ containerMtDate: patch?.containerMtDate ? patch.containerMtDate : null,
51
+ adviseMtDate: patch?.adviseMtDate ? patch.adviseMtDate : null,
52
+ sumPalletQty: patch?.sumPalletQty ? patch.sumPalletQty : null
53
+ })
54
+ }
55
+ }
56
+
57
+ export async function generateJobSheet(
58
+ domain: Domain,
59
+ user: User,
60
+ arrivalNotice: ArrivalNotice | ArrivalNoticePatch,
61
+ tx?: EntityManager
62
+ ): Promise<JobSheet> {
63
+ const jobSheetRepo: Repository<JobSheet> = tx?.getRepository(JobSheet) || getRepository(JobSheet)
64
+
65
+ let foundJS: JobSheet = null
66
+ if (arrivalNotice?.refNo) {
67
+ foundJS = await jobSheetRepo.findOne({
68
+ where: { domain: { id: domain.id }, name: arrivalNotice.refNo, bizplace: { id: arrivalNotice.bizplace.id } }
69
+ })
70
+ }
71
+
72
+ let jobName: any = null
73
+ if (foundJS) {
74
+ jobName = OrderNoGenerator.jobSheet(domain.name)
75
+ } else {
76
+ jobName = arrivalNotice?.refNo
77
+ }
78
+
79
+ // 1. Create job sheet
80
+ const createdJobSheet: JobSheet = await jobSheetRepo.save({
81
+ name: jobName ? jobName : OrderNoGenerator.jobSheet(domain.name),
82
+ domain,
83
+ bizplace: arrivalNotice.bizplace,
84
+ containerSize: arrivalNotice?.containerSize ? arrivalNotice.containerSize : null,
85
+ containerNo: arrivalNotice?.containerNo ? arrivalNotice.containerNo : null,
86
+ arrivalNoticeRefNo: arrivalNotice.name,
87
+ creator: user,
88
+ updater: user
89
+ })
90
+
91
+ return createdJobSheet
92
+ }