@things-factory/sales-base 8.0.0-beta.8 → 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,354 @@
1
+ import { Arg, Args, Ctx, Directive, Query, Resolver } from 'type-graphql'
2
+ import { EntityManager, In, OrderByCondition, SelectQueryBuilder } from 'typeorm'
3
+
4
+ import { Attachment } from '@things-factory/attachment-base'
5
+ import { User } from '@things-factory/auth-base'
6
+ import { Bizplace, getPermittedBizplaceIds, getPermittedBizplaces } from '@things-factory/biz-base'
7
+ import { buildQuery, Domain, getRepository, ListParam } from '@things-factory/shell'
8
+
9
+ import { ATTACHMENT_TYPE, DRAFT_RELEASE_ORDER_STATUS } from '../../constants'
10
+ import { InventoryUtil } from '../../utils'
11
+ import { DraftReleaseGood } from './draft-release-good'
12
+ import { DraftReleaseGoodList } from './draft-release-good-type'
13
+
14
+ @Resolver(DraftReleaseGood)
15
+ export class DraftReleaseGoodQuery {
16
+ @Query(returns => DraftReleaseGood, { description: 'To fetch a DraftReleaseGood' })
17
+ async draftReleaseGood(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<DraftReleaseGood> {
18
+ const { domain } = context.state
19
+
20
+ return await getRepository(DraftReleaseGood).findOne({
21
+ where: { domain: { id: domain.id }, id }
22
+ })
23
+ }
24
+
25
+ @Directive('@transaction')
26
+ @Query(returns => DraftReleaseGood, { description: 'To fetch a DraftReleaseGood' })
27
+ async draftReleaseGoodByName(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<DraftReleaseGood> {
28
+ const { domain, tx } = context.state
29
+
30
+ return getDraftReleaseGoodFunction(null, name, context, tx)
31
+ }
32
+
33
+ @Directive('@transaction')
34
+ @Query(returns => DraftReleaseGoodList, { description: 'To fetch multiple DraftReleaseGoods' })
35
+ async draftReleaseGoods(
36
+ @Args(type => ListParam) params: ListParam,
37
+ @Ctx() context: ResolverContext
38
+ ): Promise<DraftReleaseGoodList> {
39
+ try {
40
+ const { domain, user, tx } = context.state
41
+
42
+ const statusFilter = params.filters.find(e => e.name === 'status')
43
+ const bizplaceFilter = params.filters.find(param => param.name === 'bizplaceId')
44
+ const noOfItemsFilter = params.filters.find(param => param.name === 'noOfItems')
45
+ const skuFilter = params.filters.find(param => param.name === 'sku')
46
+ const orderRemarkFilter = params.filters.find(param => param.name === 'orderRemark')
47
+
48
+ if (!bizplaceFilter) {
49
+ params.filters.push({
50
+ name: 'bizplaceId',
51
+ operator: 'in',
52
+ value: await getPermittedBizplaceIds(domain, user),
53
+ relation: false
54
+ })
55
+ }
56
+
57
+ params.filters = params.filters.filter(
58
+ itm => itm.name !== 'noOfItems' && itm.name !== 'sku' && itm.name !== 'status'
59
+ )
60
+
61
+ if (orderRemarkFilter) {
62
+ const orderRemarkIdx = params.filters.findIndex(param => param.name === 'orderRemark')
63
+ if (orderRemarkFilter.value == true) {
64
+ params.filters.splice(orderRemarkIdx, 1)
65
+ params.filters.push({
66
+ name: 'remark',
67
+ operator: 'is_not_null',
68
+ value: null,
69
+ relation: false
70
+ })
71
+ } else {
72
+ params.filters.splice(orderRemarkIdx, 1)
73
+ params.filters.push({
74
+ name: 'remark',
75
+ operator: 'is_null',
76
+ value: null,
77
+ relation: false
78
+ })
79
+ }
80
+ }
81
+
82
+ const fromDateParamIdx = params.filters.findIndex(param => param.name === 'fromDate')
83
+ if (fromDateParamIdx >= 0) {
84
+ let fromDateVal = new Date(params.filters[fromDateParamIdx].value)
85
+ params.filters.splice(fromDateParamIdx, 1)
86
+
87
+ params.filters.push({
88
+ name: 'createdAt',
89
+ operator: 'gte',
90
+ value: fromDateVal.toISOString(),
91
+ relation: false
92
+ })
93
+ }
94
+
95
+ const toDateParamIdx = params.filters.findIndex(param => param.name === 'toDate')
96
+ if (toDateParamIdx >= 0) {
97
+ let toDateVal = new Date(params.filters[toDateParamIdx].value)
98
+ params.filters.splice(toDateParamIdx, 1)
99
+
100
+ params.filters.push({
101
+ name: 'createdAt',
102
+ operator: 'lt',
103
+ value: new Date(toDateVal.setDate(toDateVal.getDate() + 1)).toISOString(),
104
+ relation: false
105
+ })
106
+ }
107
+
108
+ tx.query(
109
+ `
110
+ create temp table temp_op_calculation on commit drop as (
111
+ SELECT drg1.id from draft_release_goods drg1
112
+ left join order_products op on drg1.id = op.draft_release_good_id
113
+ where drg1.status ='DRAFT' AND drg1.domain_id = $1
114
+ AND NOT EXISTS (
115
+ SELECT * FROM warehouse_bizplace_onhand_inventories wboi
116
+ where (wboi."productId" = op.product_id or wboi."productBundleId" = op.product_id)
117
+ and wboi."domainId" = op.domain_id
118
+ and wboi."bizplaceId" = op.bizplace_id
119
+ AND wboi."remainQty" >= op.release_qty
120
+ ) GROUP BY drg1.id
121
+ )
122
+ `,
123
+ [domain.id]
124
+ )
125
+
126
+ const qb: SelectQueryBuilder<DraftReleaseGood> = tx.getRepository(DraftReleaseGood).createQueryBuilder('drg')
127
+ buildQuery(qb, params, context)
128
+ qb.addSelect('COALESCE("cc".rank, 99999)', 'rank')
129
+ qb.addSelect(
130
+ `CASE WHEN "drg".status = 'DRAFT' and tmp_calc.id IS NOT null then 'INSUFFICIENT' else "drg".status END`,
131
+ 'computed_status'
132
+ )
133
+ qb.leftJoin(`temp_op_calculation`, 'tmp_calc', 'tmp_calc.id = drg.id')
134
+ qb.leftJoinAndSelect('drg.domain', 'domain')
135
+ qb.leftJoinAndSelect('drg.bizplace', 'bizplace')
136
+ qb.leftJoinAndSelect('drg.creator', 'creator')
137
+ qb.leftJoinAndSelect('drg.updater', 'updater')
138
+ qb.leftJoinAndSelect('drg.deliverTo', 'deliverTo')
139
+ qb.leftJoin(
140
+ subQuery => {
141
+ return subQuery
142
+ .select(`ccd.rank`, 'rank')
143
+ .addSelect(`ccd.name`, 'status')
144
+ .from(`common_code_details`, 'ccd')
145
+ .innerJoin(`ccd.commonCode`, 'cc')
146
+ .where(`ccd.domain_id = :domainId`, { domainId: domain.id })
147
+ .andWhere(`cc.name = 'ODO_REQUESTS_STATUS'`)
148
+ },
149
+ 'cc',
150
+ 'cc.status = drg.status'
151
+ )
152
+
153
+ if (skuFilter) {
154
+ qb.andWhere(
155
+ `
156
+ exists (
157
+ select * from order_products op
158
+ inner join products p on op.product_id = p.id
159
+ where op.draft_release_good_id = drg.id
160
+ and lower(p.sku) ilike :sku
161
+ )
162
+ `,
163
+ { sku: skuFilter.value.toLowerCase() }
164
+ )
165
+ }
166
+
167
+ if (noOfItemsFilter) {
168
+ qb.andWhere(
169
+ `
170
+ exists (
171
+ select numberFilterOp.product_id from order_products numberFilterOp
172
+ where numberFilterOp.draft_release_good_id = drg.id
173
+ group by numberFilterOp.product_id having count(*) ${noOfItemsFilter.value == 1 ? ' = 1' : '> 1'}
174
+ )
175
+ `
176
+ )
177
+ }
178
+
179
+ if (statusFilter) {
180
+ if (statusFilter.value == DRAFT_RELEASE_ORDER_STATUS.DRAFT) {
181
+ qb.andWhere(
182
+ `
183
+ drg.status = 'DRAFT' and tmp_calc.id IS null
184
+ `
185
+ )
186
+ } else if (statusFilter.value == DRAFT_RELEASE_ORDER_STATUS.INSUFFICIENT) {
187
+ qb.andWhere(
188
+ `
189
+ drg.status = 'DRAFT' and tmp_calc.id IS NOT null
190
+ `
191
+ )
192
+ } else {
193
+ qb.andWhere(
194
+ `
195
+ drg.status = '${statusFilter.value}'
196
+ `
197
+ )
198
+ }
199
+ }
200
+
201
+ const arrChildSortData = ['bizplace', 'creator']
202
+ const sort: OrderByCondition = (params.sortings || []).reduce(
203
+ (acc, sort) => ({
204
+ ...acc,
205
+ [arrChildSortData.indexOf(sort.name) >= 0 ? sort.name + '.name' : 'drg.' + sort.name]: sort.desc
206
+ ? 'DESC'
207
+ : 'ASC'
208
+ }),
209
+ params.sortings.length < 1 ? { rank: 'ASC', 'drg.createdAt': 'DESC' } : {}
210
+ )
211
+
212
+ qb.orderBy(sort)
213
+ qb.offset((params.pagination.page - 1) * params.pagination.limit)
214
+ qb.limit(params.pagination.limit)
215
+
216
+ let [items, total] = await Promise.all([qb.getRawMany(), qb.getCount()])
217
+
218
+ items = items.map(itm => {
219
+ return {
220
+ id: itm.drg_id,
221
+ name: itm.drg_name,
222
+ description: itm.drg_description,
223
+ type: itm.drg_type,
224
+ releaseDate: itm.drg_release_date,
225
+ exportOption: itm.drg_export_option,
226
+ ownTransport: itm.drg_own_transport,
227
+ bizplace: { id: itm.bizplace_id, name: itm.bizplace_name, description: itm.bizplace_description },
228
+ refNo: itm.drg_ref_no,
229
+ refNo2: itm.drg_ref_no_2,
230
+ refNo3: itm.drg_ref_no_3,
231
+ status: itm.computed_status,
232
+ createdAt: itm.drg_created_at,
233
+ creator: { id: itm.creator_id, name: itm.creator_name, description: itm.creator_description },
234
+ updatedAt: itm.drg_updated_at,
235
+ updater: { id: itm.updater_id, name: itm.updater_name, description: itm.updater_description }
236
+ }
237
+ })
238
+
239
+ return { items, total }
240
+ } catch (error) {
241
+ throw error
242
+ }
243
+ }
244
+ }
245
+
246
+ export async function getDraftReleaseGoodFunction(_: any, name: any, context: any, tx?: EntityManager) {
247
+ try {
248
+ const { domain, user, bizplace }: { domain: Domain; user: User; bizplace: Bizplace } = context.state
249
+
250
+ let permittedBizplaces = await getPermittedBizplaces(domain, user)
251
+ let result: any = await tx.getRepository(DraftReleaseGood).findOne({
252
+ where: { domain: { id: domain.id }, name, bizplace: { id: In(permittedBizplaces.map(biz => biz.id)) } },
253
+ relations: [
254
+ 'releaseGood',
255
+ 'orderProducts',
256
+ 'orderProducts.product',
257
+ 'orderProducts.productBundle',
258
+ 'shippingOrder',
259
+ 'bizplace',
260
+ 'domain',
261
+ 'creator',
262
+ 'updater'
263
+ ]
264
+ })
265
+
266
+ if (!result?.id) throw new Error(`Failed to find draft release good ${name}`)
267
+
268
+ let foundPermittedBizplace: Bizplace
269
+ let companyBizplace: Bizplace
270
+
271
+ if (result.bizplace.id) {
272
+ foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == result.bizplace.id)
273
+
274
+ if (foundPermittedBizplace) {
275
+ if (!foundPermittedBizplace.company?.id) {
276
+ foundPermittedBizplace = await tx.getRepository(Bizplace).findOne({
277
+ where: { id: foundPermittedBizplace.id },
278
+ relations: ['company', 'company.domain']
279
+ })
280
+ }
281
+ const companyDomain: Domain = foundPermittedBizplace.company.domain
282
+ companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: { id: companyDomain.id } } })
283
+ }
284
+ }
285
+
286
+ const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
287
+
288
+ let productInventory
289
+ if (result.orderProducts.length > 0)
290
+ productInventory = await InventoryUtil.bizplaceProductInventory(
291
+ bizplaces,
292
+ {
293
+ filters: [
294
+ { name: 'bizplaceId', operator: 'eq', value: result.bizplace.id },
295
+ {
296
+ name: 'productId',
297
+ operator: 'in',
298
+ value: [
299
+ ...result.orderProducts
300
+ .filter(itm => itm?.product)
301
+ .map(itm => {
302
+ return itm.product.id
303
+ }),
304
+ ...result.orderProducts
305
+ .filter(itm => itm?.productBundle)
306
+ .map(itm => {
307
+ return itm.productBundle.id
308
+ })
309
+ ]
310
+ }
311
+ ]
312
+ },
313
+ context,
314
+ tx
315
+ )
316
+
317
+ result.orderProducts = result.orderProducts.map(itm => {
318
+ let foundProductInv = productInventory?.items.find(
319
+ i =>
320
+ (i.productId == itm?.product?.id || i.productId == itm?.productBundle?.id) &&
321
+ i.packingType == itm.packingType &&
322
+ i.packingSize == itm.packingSize &&
323
+ i.uom == itm.uom
324
+ )
325
+ return {
326
+ ...itm,
327
+ product: itm.product || {
328
+ id: foundProductInv.productId,
329
+ name: foundProductInv.productName,
330
+ brand: foundProductInv.productBrand,
331
+ sku: foundProductInv.productSKU
332
+ },
333
+ groupType: foundProductInv ? foundProductInv.groupType : 'SINGLE',
334
+ remainQty: foundProductInv ? foundProductInv.remainQty : 0,
335
+ remainUomValue: foundProductInv ? foundProductInv.remainUomValue : 0,
336
+ remainUomValueWithUom: foundProductInv ? foundProductInv.remainUomValueWithUom : 0
337
+ }
338
+ })
339
+ const foundAttachments: Attachment[] = await tx.getRepository(Attachment).find({
340
+ where: {
341
+ domain: { id: domain.id },
342
+ refBy: result.id,
343
+ category: ATTACHMENT_TYPE.DGRN
344
+ }
345
+ })
346
+
347
+ return {
348
+ ...result,
349
+ attachment: foundAttachments
350
+ }
351
+ } catch (error) {
352
+ console.error(error)
353
+ }
354
+ }
@@ -0,0 +1,261 @@
1
+ import { Field, InputType, Int, ObjectType } from 'type-graphql'
2
+
3
+ import { ObjectRef } from '@things-factory/shell'
4
+
5
+ import { OrderProductPatch } from '../order-product/order-product-types'
6
+ import { DraftReleaseGood } from './draft-release-good'
7
+
8
+ @InputType()
9
+ export class NewDraftReleaseGood {
10
+ @Field({ nullable: true })
11
+ name: string
12
+
13
+ @Field({ nullable: true })
14
+ releaseDate: string
15
+
16
+ @Field({ nullable: true })
17
+ type: string
18
+
19
+ @Field({ nullable: true })
20
+ collectionOrderNo: string
21
+
22
+ @Field({ nullable: true })
23
+ ownTransport: Boolean
24
+
25
+ @Field({ nullable: true })
26
+ courierOption: Boolean
27
+
28
+ @Field({ nullable: true })
29
+ packingOption: Boolean
30
+
31
+ @Field({ nullable: true })
32
+ packageId: string
33
+
34
+ @Field({ nullable: true })
35
+ truckNo: string
36
+
37
+ @Field({ nullable: true })
38
+ refNo: string
39
+
40
+ @Field({ nullable: true })
41
+ refNo2: string
42
+
43
+ @Field({ nullable: true })
44
+ refNo3: string
45
+
46
+ @Field({ nullable: true })
47
+ pickupAddress: string
48
+
49
+ @Field({ nullable: true })
50
+ pickupTime: string
51
+
52
+ @Field({ nullable: true })
53
+ handoverType: string
54
+
55
+ @Field({ nullable: true })
56
+ dropoffAddress: string
57
+
58
+ @Field({ nullable: true })
59
+ marketplaceOrderStatus: string
60
+
61
+ @Field({ nullable: true })
62
+ billingAddress: string
63
+
64
+ @Field({ nullable: true })
65
+ deliveryAddress1: string
66
+
67
+ @Field({ nullable: true })
68
+ deliveryAddress2: string
69
+
70
+ @Field({ nullable: true })
71
+ deliveryAddress3: string
72
+
73
+ @Field({ nullable: true })
74
+ deliveryAddress4: string
75
+
76
+ @Field({ nullable: true })
77
+ deliveryAddress5: string
78
+
79
+ @Field({ nullable: true })
80
+ attentionTo: string
81
+
82
+ @Field({ nullable: true })
83
+ attentionCompany: string
84
+
85
+ @Field({ nullable: true })
86
+ city: string
87
+
88
+ @Field({ nullable: true })
89
+ state: string
90
+
91
+ @Field({ nullable: true })
92
+ postalCode: string
93
+
94
+ @Field({ nullable: true })
95
+ country: string
96
+
97
+ @Field({ nullable: true })
98
+ phone1: string
99
+
100
+ @Field({ nullable: true })
101
+ phone2: string
102
+
103
+ @Field({ nullable: true })
104
+ email: string
105
+
106
+ @Field()
107
+ exportOption: Boolean
108
+
109
+ @Field({ nullable: true })
110
+ status: string
111
+
112
+ @Field({ nullable: true })
113
+ description: string
114
+
115
+ @Field({ nullable: true })
116
+ deliverTo: string
117
+
118
+ @Field(type => ObjectRef, { nullable: true })
119
+ bizplace: ObjectRef
120
+
121
+ @Field({ nullable: true })
122
+ remark: string
123
+
124
+ @Field(type => [ObjectRef], { nullable: true })
125
+ orderProducts: ObjectRef[]
126
+ }
127
+
128
+ @InputType()
129
+ export class DraftReleaseGoodPatch {
130
+ @Field({ nullable: true })
131
+ id: string
132
+
133
+ @Field({ nullable: true })
134
+ name: string
135
+
136
+ @Field(type => ObjectRef, { nullable: true })
137
+ bizplace: ObjectRef
138
+
139
+ @Field({ nullable: true })
140
+ releaseDate: string
141
+
142
+ @Field({ nullable: true })
143
+ collectionOrderNo: string
144
+
145
+ @Field({ nullable: true })
146
+ ownTransport: Boolean
147
+
148
+ @Field({ nullable: true })
149
+ type: string
150
+
151
+ @Field({ nullable: true })
152
+ truckNo: string
153
+
154
+ @Field({ nullable: true })
155
+ packageId: string
156
+
157
+ @Field({ nullable: true })
158
+ refNo: string
159
+
160
+ @Field({ nullable: true })
161
+ refNo2: string
162
+
163
+ @Field({ nullable: true })
164
+ refNo3: string
165
+
166
+ @Field({ nullable: true })
167
+ exportOption: Boolean
168
+
169
+ @Field({ nullable: true })
170
+ packingOption: Boolean
171
+
172
+ @Field(type => ObjectRef, { nullable: true })
173
+ shippingOrder: ObjectRef
174
+
175
+ @Field({ nullable: true })
176
+ status: string
177
+
178
+ @Field({ nullable: true })
179
+ remark: string
180
+
181
+ @Field({ nullable: true })
182
+ billingAddress: string
183
+
184
+ @Field({ nullable: true })
185
+ deliveryAddress1: string
186
+
187
+ @Field({ nullable: true })
188
+ deliveryAddress2: string
189
+
190
+ @Field({ nullable: true })
191
+ deliveryAddress3: string
192
+
193
+ @Field({ nullable: true })
194
+ deliveryAddress4: string
195
+
196
+ @Field({ nullable: true })
197
+ deliveryAddress5: string
198
+
199
+ @Field({ nullable: true })
200
+ attentionTo: string
201
+
202
+ @Field({ nullable: true })
203
+ attentionCompany: string
204
+
205
+ @Field({ nullable: true })
206
+ city: string
207
+
208
+ @Field({ nullable: true })
209
+ state: string
210
+
211
+ @Field({ nullable: true })
212
+ postalCode: string
213
+
214
+ @Field({ nullable: true })
215
+ country: string
216
+
217
+ @Field({ nullable: true })
218
+ phone1: string
219
+
220
+ @Field({ nullable: true })
221
+ phone2: string
222
+
223
+ @Field({ nullable: true })
224
+ email: string
225
+
226
+ @Field({ nullable: true })
227
+ description: string
228
+
229
+ @Field({ nullable: true })
230
+ courierOption: Boolean
231
+
232
+ @Field({ nullable: true })
233
+ pickupAddress: string
234
+
235
+ @Field({ nullable: true })
236
+ pickupTime: string
237
+
238
+ @Field({ nullable: true })
239
+ handoverType: string
240
+
241
+ @Field({ nullable: true })
242
+ dropoffAddress: string
243
+
244
+ @Field({ nullable: true })
245
+ marketplaceOrderStatus: string
246
+
247
+ @Field({ nullable: true })
248
+ deliverTo: string
249
+
250
+ @Field(type => [OrderProductPatch], { nullable: true })
251
+ orderProducts: OrderProductPatch[]
252
+ }
253
+
254
+ @ObjectType()
255
+ export class DraftReleaseGoodList {
256
+ @Field(type => [DraftReleaseGood])
257
+ items: DraftReleaseGood[]
258
+
259
+ @Field(type => Int)
260
+ total: number
261
+ }