@things-factory/operato-hub 4.3.19 → 4.4.0-alpha.3

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 (65) hide show
  1. package/client/pages/constants/setting.js +0 -1
  2. package/dist-server/controllers/bizplace-initializer/dataset/codes.js +0 -9
  3. package/dist-server/controllers/bizplace-initializer/dataset/codes.js.map +1 -1
  4. package/dist-server/controllers/bizplace-initializer/dataset/index.js +5 -1
  5. package/dist-server/controllers/bizplace-initializer/dataset/index.js.map +1 -1
  6. package/dist-server/controllers/bizplace-initializer/dataset/settings.js +0 -10
  7. package/dist-server/controllers/bizplace-initializer/dataset/settings.js.map +1 -1
  8. package/dist-server/controllers/bizplace-initializer/index.js +5 -1
  9. package/dist-server/controllers/bizplace-initializer/index.js.map +1 -1
  10. package/dist-server/controllers/company-initializer/index.js +5 -1
  11. package/dist-server/controllers/company-initializer/index.js.map +1 -1
  12. package/dist-server/graphql/index.js +5 -1
  13. package/dist-server/graphql/index.js.map +1 -1
  14. package/dist-server/graphql/resolvers/index.js +5 -1
  15. package/dist-server/graphql/resolvers/index.js.map +1 -1
  16. package/dist-server/graphql/resolvers/synchronization/sync-products-to-sellercraft.js +50 -82
  17. package/dist-server/graphql/resolvers/synchronization/sync-products-to-sellercraft.js.map +1 -1
  18. package/dist-server/graphql/types/index.js +5 -1
  19. package/dist-server/graphql/types/index.js.map +1 -1
  20. package/dist-server/index.js +5 -1
  21. package/dist-server/index.js.map +1 -1
  22. package/dist-server/routers/api/restful-apis/unstable/add-marketplace-order.js +75 -85
  23. package/dist-server/routers/api/restful-apis/unstable/add-marketplace-order.js.map +1 -1
  24. package/dist-server/routers/api/restful-apis/unstable/add-release-order.js +424 -576
  25. package/dist-server/routers/api/restful-apis/unstable/add-release-order.js.map +1 -1
  26. package/dist-server/routers/api/restful-apis/unstable/index.js +0 -1
  27. package/dist-server/routers/api/restful-apis/unstable/index.js.map +1 -1
  28. package/dist-server/routers/api/restful-apis/v1/add-marketplace-order.js +75 -85
  29. package/dist-server/routers/api/restful-apis/v1/add-marketplace-order.js.map +1 -1
  30. package/dist-server/routers/api/restful-apis/v1/add-release-order.js +428 -577
  31. package/dist-server/routers/api/restful-apis/v1/add-release-order.js.map +1 -1
  32. package/dist-server/routers/api/restful-apis/v1/index.js +0 -1
  33. package/dist-server/routers/api/restful-apis/v1/index.js.map +1 -1
  34. package/dist-server/routers/api/restful-apis/v2/add-marketplace-order.js +75 -85
  35. package/dist-server/routers/api/restful-apis/v2/add-marketplace-order.js.map +1 -1
  36. package/dist-server/routers/api/restful-apis/v2/add-release-order.js +428 -577
  37. package/dist-server/routers/api/restful-apis/v2/add-release-order.js.map +1 -1
  38. package/dist-server/routers/api/restful-apis/v2/index.js +0 -1
  39. package/dist-server/routers/api/restful-apis/v2/index.js.map +1 -1
  40. package/dist-server/routers/business/index.js +5 -1
  41. package/dist-server/routers/business/index.js.map +1 -1
  42. package/dist-server/utils/index.js +5 -1
  43. package/dist-server/utils/index.js.map +1 -1
  44. package/package.json +55 -55
  45. package/server/controllers/bizplace-initializer/dataset/codes.ts +0 -9
  46. package/server/controllers/bizplace-initializer/dataset/settings.ts +0 -10
  47. package/server/graphql/resolvers/synchronization/sync-products-to-sellercraft.ts +57 -89
  48. package/server/routers/api/restful-apis/unstable/add-marketplace-order.ts +85 -97
  49. package/server/routers/api/restful-apis/unstable/add-release-order.ts +499 -734
  50. package/server/routers/api/restful-apis/unstable/index.ts +0 -1
  51. package/server/routers/api/restful-apis/v1/add-marketplace-order.ts +85 -97
  52. package/server/routers/api/restful-apis/v1/add-release-order.ts +504 -735
  53. package/server/routers/api/restful-apis/v1/index.ts +0 -1
  54. package/server/routers/api/restful-apis/v2/add-marketplace-order.ts +85 -97
  55. package/server/routers/api/restful-apis/v2/add-release-order.ts +503 -735
  56. package/server/routers/api/restful-apis/v2/index.ts +0 -1
  57. package/dist-server/routers/api/restful-apis/unstable/add-draft-release-order.js +0 -171
  58. package/dist-server/routers/api/restful-apis/unstable/add-draft-release-order.js.map +0 -1
  59. package/dist-server/routers/api/restful-apis/v1/add-draft-release-order.js +0 -171
  60. package/dist-server/routers/api/restful-apis/v1/add-draft-release-order.js.map +0 -1
  61. package/dist-server/routers/api/restful-apis/v2/add-draft-release-order.js +0 -171
  62. package/dist-server/routers/api/restful-apis/v2/add-draft-release-order.js.map +0 -1
  63. package/server/routers/api/restful-apis/unstable/add-draft-release-order.ts +0 -196
  64. package/server/routers/api/restful-apis/v1/add-draft-release-order.ts +0 -196
  65. package/server/routers/api/restful-apis/v2/add-draft-release-order.ts +0 -196
@@ -3,7 +3,6 @@ import { EntityManager, getConnection, SelectQueryBuilder } from 'typeorm'
3
3
 
4
4
  import { restfulApiRouter as router } from '@things-factory/api'
5
5
  import { Bizplace, getCompanyBizplace } from '@things-factory/biz-base'
6
- import { createPayloadLog, PayloadType } from '@things-factory/integration-base'
7
6
  import { Product, ProductBundle, ProductDetail } from '@things-factory/product-base'
8
7
  import { ORDER_TYPES, OrderInventory } from '@things-factory/sales-base'
9
8
  import { Setting } from '@things-factory/setting-base'
@@ -13,11 +12,10 @@ import { WorksheetDetail } from '@things-factory/worksheet-base'
13
12
  import { businessMiddleware } from '../../../../middlewares/business-middleware'
14
13
  import { warehouseMiddleware } from '../../../../middlewares/warehouse-middleware'
15
14
 
16
- const debug = require('debug')('things-factory:operato-hub:restful-api:unstable:add-release-order')
17
- const apiVersion = 'v2'
15
+ const debug = require('debug')('things-factory:operato-hub:restful-api:v2:add-release-order')
18
16
 
19
17
  router.post(
20
- `/${apiVersion}/warehouse/:warehouseId/add-release-order`,
18
+ '/v2/warehouse/:warehouseId/add-release-order',
21
19
  businessMiddleware,
22
20
  warehouseMiddleware,
23
21
  async (context, next) => {
@@ -25,720 +23,580 @@ router.post(
25
23
  const { client, domain } = context.state
26
24
  const { warehouseId: customerBizplaceId } = context.params
27
25
  const { t } = context
28
- const bodyReq = context.request.body
29
- try {
30
- if (!customerBizplaceId) context.throw(404, t('error.warehouse id not found'))
31
26
 
32
- if (typeof bodyReq === undefined || !Object.keys(bodyReq)?.length) {
33
- context.throw(400, t('error.invalid body request format'))
34
- }
35
- debug('post:/add-release-order request.body', bodyReq)
36
- await checkMandatoryKey(context, bodyReq)
27
+ if (!customerBizplaceId) context.throw(404, t('error.warehouse id not found'))
37
28
 
38
- const isAutoAssign: Boolean = bodyReq.hasOwnProperty('isAutoAssign') ? bodyReq.isAutoAssign : true
39
- const requiredDraft: Boolean = bodyReq.hasOwnProperty('requiredDraft') ? bodyReq.requiredDraft : true
29
+ let bodyReq = context.request.body
30
+ if (typeof bodyReq === undefined || !Object.keys(bodyReq)?.length) {
31
+ context.throw(400, t('error.invalid body request format'))
32
+ }
33
+ debug('post:/add-release-order request.body', bodyReq)
34
+ await checkMandatoryKey(context, bodyReq)
40
35
 
41
- // get customer company's bizplace
42
- const custCompanyBizplace: Bizplace = await getCompanyBizplace(null, null, customerBizplaceId, tx)
43
- const customerBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({
44
- where: { id: customerBizplaceId }
45
- })
36
+ const isAutoAssign: Boolean = bodyReq.hasOwnProperty('isAutoAssign') ? bodyReq.isAutoAssign : true
46
37
 
47
- let locationSortingRules = []
48
- const inventoryAssignmentSetting: Setting = await tx.getRepository(Setting).findOne({
49
- where: { domain, name: 'rule-for-inventory-assignment' }
50
- })
38
+ // get customer company's bizplace
39
+ const custCompanyBizplace: Bizplace = await getCompanyBizplace(null, null, customerBizplaceId, tx)
40
+ const customerBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({
41
+ where: { id: customerBizplaceId }
42
+ })
43
+
44
+ let locationSortingRules = []
45
+ const inventoryAssignmentSetting: Setting = await tx.getRepository(Setting).findOne({
46
+ where: { domain, name: 'rule-for-inventory-assignment' }
47
+ })
51
48
 
52
- if (inventoryAssignmentSetting) {
53
- let locationSetting = JSON.parse(inventoryAssignmentSetting.value)
49
+ if (inventoryAssignmentSetting) {
50
+ let locationSetting = JSON.parse(inventoryAssignmentSetting.value)
51
+ for (const key in locationSetting) {
52
+ locationSortingRules.push({ name: key, desc: locationSetting[key] == 'ASC' ? false : true })
53
+ }
54
+ } else {
55
+ const pickingProductSetting: Setting = await tx.getRepository(Setting).findOne({
56
+ where: { domain, name: 'rule-for-picking-product' }
57
+ })
58
+ if (pickingProductSetting) {
59
+ let locationSetting = JSON.parse(pickingProductSetting.value)
54
60
  for (const key in locationSetting) {
55
61
  locationSortingRules.push({ name: key, desc: locationSetting[key] == 'ASC' ? false : true })
56
62
  }
57
- } else {
58
- const pickingProductSetting: Setting = await tx.getRepository(Setting).findOne({
59
- where: { domain, name: 'rule-for-picking-product' }
60
- })
61
- if (pickingProductSetting) {
62
- let locationSetting = JSON.parse(pickingProductSetting.value)
63
- for (const key in locationSetting) {
64
- locationSortingRules.push({ name: key, desc: locationSetting[key] == 'ASC' ? false : true })
65
- }
66
- }
67
63
  }
64
+ }
65
+
66
+ const orderInventories: OrderInventory[] = bodyReq.orderInventories
67
+ let newOrderInventories: OrderInventory[] = []
68
+ let bundleInfo: any[] = []
69
+
70
+ await Promise.all(
71
+ orderInventories.map(async orderInventory => {
72
+ const sku: string = orderInventory.product?.sku
73
+ const refCode: string = orderInventory.product?.refCode
74
+ const { packingType, packingSize }: { packingType: string; packingSize: number } = orderInventory
68
75
 
69
- const orderInventories: OrderInventory[] = bodyReq.orderInventories
70
- let newOrderInventories: OrderInventory[] = []
71
- let bundleInfo: any[] = []
76
+ const qb: SelectQueryBuilder<ProductDetail> = tx
77
+ .getRepository(ProductDetail)
78
+ .createQueryBuilder('PD')
79
+ .innerJoinAndSelect('PD.product', 'PROD')
80
+ .where('PROD.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id })
72
81
 
73
- await Promise.all(
74
- orderInventories.map(async orderInventory => {
75
- const sku: string = orderInventory.product?.sku
76
- const refCode: string = orderInventory.product?.refCode
77
- const packingType: string = orderInventory.packingType
82
+ if (!sku && !refCode) {
83
+ context.throw(404, t('error.sku or refCode not found'))
84
+ }
85
+
86
+ if (refCode) {
87
+ qb.andWhere('PD.ref_code = :refCode', { refCode })
88
+ }
78
89
 
90
+ if (sku) {
91
+ qb.andWhere('PROD.sku = :sku', { sku })
92
+ }
93
+
94
+ if (packingType) {
95
+ qb.andWhere('PD.packing_type = :packingType', { packingType })
96
+ }
97
+
98
+ if (!packingType && !refCode) {
99
+ qb.andWhere('PD.is_default = :isDefault', { isDefault: true })
100
+ }
101
+ if (packingSize) {
102
+ qb.andWhere('PD.packing_size = :packingSize', { packingSize })
103
+ }
104
+
105
+ const productDetail: ProductDetail = await qb.getOne()
106
+
107
+ if (productDetail) {
108
+ let newOrderInventory: OrderInventory = Object.assign({}, orderInventory)
109
+
110
+ newOrderInventory.product.sku = productDetail.product.sku
111
+ newOrderInventory.product = productDetail.product
112
+ newOrderInventory.packingType = productDetail.packingType
113
+ newOrderInventory.uomValue = productDetail.uomValue
114
+ newOrderInventories.push(newOrderInventory)
115
+ }
116
+
117
+ if (!productDetail) {
79
118
  const qb: SelectQueryBuilder<ProductDetail> = tx
80
- .getRepository(ProductDetail)
81
- .createQueryBuilder('PD')
82
- .innerJoinAndSelect('PD.product', 'PROD')
83
- .where('PROD.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id })
119
+ .getRepository(ProductBundle)
120
+ .createQueryBuilder('PB')
121
+ .innerJoinAndSelect('PB.productBundleSettings', 'PBS')
122
+ .innerJoinAndSelect('PBS.productDetail', 'PBD')
123
+ .innerJoinAndSelect('PBD.product', 'PROD')
124
+ .where('PB.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id })
84
125
 
85
126
  if (!sku && !refCode) {
86
127
  context.throw(404, t('error.sku or refCode not found'))
87
128
  }
88
129
 
89
130
  if (refCode) {
90
- qb.andWhere('PD.ref_code = :refCode', { refCode })
131
+ qb.andWhere('PB.ref_code = :refCode', { refCode })
91
132
  }
92
133
 
93
134
  if (sku) {
94
- qb.andWhere('PROD.sku = :sku', { sku })
135
+ qb.andWhere('PB.sku = :sku', { sku })
95
136
  }
96
137
 
97
138
  if (packingType) {
98
- qb.andWhere('PD.packing_type = :packingType', { packingType })
99
- }
100
-
101
- if (!packingType && !refCode) {
102
- qb.andWhere('PD.is_default = :isDefault', { isDefault: true })
103
- }
104
-
105
- const productDetail: ProductDetail = await qb.getOne()
106
-
107
- if (productDetail) {
108
- let newOrderInventory: OrderInventory = Object.assign({}, orderInventory)
109
-
110
- newOrderInventory.product.sku = productDetail.product.sku
111
- newOrderInventory.product = productDetail.product
112
- newOrderInventory.packingType = productDetail.packingType
113
- newOrderInventory.uomValue = productDetail.uomValue
114
- newOrderInventories.push(newOrderInventory)
139
+ qb.andWhere('PB.packing_type = :packingType', { packingType })
115
140
  }
116
141
 
117
- if (!productDetail) {
118
- const qb: SelectQueryBuilder<ProductDetail> = tx
119
- .getRepository(ProductBundle)
120
- .createQueryBuilder('PB')
121
- .innerJoinAndSelect('PB.productBundleSettings', 'PBS')
122
- .innerJoinAndSelect('PBS.productDetail', 'PBD')
123
- .innerJoinAndSelect('PBD.product', 'PROD')
124
- .where('PB.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id })
125
-
126
- if (!sku && !refCode) {
127
- context.throw(404, t('error.sku or refCode not found'))
128
- }
142
+ const foundProductBundle: ProductBundle = await qb.getOne()
129
143
 
130
- if (refCode) {
131
- qb.andWhere('PB.ref_code = :refCode', { refCode })
144
+ if (foundProductBundle) {
145
+ bundleInfo.push({
146
+ productBundleId: foundProductBundle.id,
147
+ sku: foundProductBundle.sku,
148
+ releaseQty: orderInventory.releaseQty
149
+ })
150
+ const bundleProductSettings: any[] = foundProductBundle.productBundleSettings
151
+ bundleProductSettings.map(bundleProductSetting => {
152
+ const productDetailBundle: ProductDetail = bundleProductSetting.productDetail
153
+
154
+ let newOrderInventory: OrderInventory = Object.assign({}, orderInventory)
155
+ newOrderInventory.product.sku = productDetailBundle.product.sku
156
+ newOrderInventory.packingType = productDetailBundle.packingType
157
+ newOrderInventory.uomValue = productDetailBundle.uomValue
158
+ newOrderInventory.releaseQty = orderInventory.releaseQty * bundleProductSetting.bundleQty
159
+ newOrderInventory.product = productDetailBundle.product
160
+ newOrderInventories.push(newOrderInventory)
161
+ })
162
+ } else {
163
+ if (sku && refCode) {
164
+ context.throw(404, t(`error.sku ${sku} and refCode ${refCode} not exist in product / bundle master`))
132
165
  }
133
166
 
134
167
  if (sku) {
135
- qb.andWhere('PB.sku = :sku', { sku })
168
+ context.throw(404, t(`error.sku ${sku} not exist in product / bundle master`))
136
169
  }
137
170
 
138
- if (packingType) {
139
- qb.andWhere('PB.packing_type = :packingType', { packingType })
140
- }
141
-
142
- const foundProductBundle: ProductBundle = await qb.getOne()
143
-
144
- if (foundProductBundle) {
145
- bundleInfo.push({
146
- productBundleId: foundProductBundle.id,
147
- sku: foundProductBundle.sku,
148
- releaseQty: orderInventory.releaseQty
149
- })
150
- const bundleProductSettings: any[] = foundProductBundle.productBundleSettings
151
- bundleProductSettings.map(bundleProductSetting => {
152
- const productDetailBundle: ProductDetail = bundleProductSetting.productDetail
153
-
154
- let newOrderInventory: OrderInventory = Object.assign({}, orderInventory)
155
- newOrderInventory.product.sku = productDetailBundle.product.sku
156
- newOrderInventory.packingType = productDetailBundle.packingType
157
- newOrderInventory.uomValue = productDetailBundle.uomValue
158
- newOrderInventory.releaseQty = orderInventory.releaseQty * bundleProductSetting.bundleQty
159
- newOrderInventory.product = productDetailBundle.product
160
- newOrderInventories.push(newOrderInventory)
161
- })
162
- } else {
163
- if (sku && refCode) {
164
- context.throw(404, t(`error.sku ${sku} and refCode ${refCode} not exist in product / bundle master`))
165
- }
166
-
167
- if (sku) {
168
- context.throw(404, t(`error.sku ${sku} not exist in product / bundle master`))
169
- }
170
-
171
- if (refCode) {
172
- context.throw(404, t(`error.refCode ${refCode} not exist in product / bundle master`))
173
- }
171
+ if (refCode) {
172
+ context.throw(404, t(`error.refCode ${refCode} not exist in product / bundle master`))
174
173
  }
175
174
  }
176
- })
177
- )
178
-
179
- let finalOrderInventories: OrderInventory[] = []
180
-
181
- // Case 1. Every order inventories has specified batch id
182
- if (newOrderInventories.every((orderInventory: OrderInventory) => orderInventory.batchId)) {
183
- finalOrderInventories = await Promise.all(
184
- newOrderInventories.map(async (orderInventory: OrderInventory) => {
185
- let filters: any = [
186
- {
187
- name: 'batchId',
188
- operator: 'eq',
189
- value: orderInventory.batchId
190
- },
191
- {
192
- name: 'productName',
193
- operator: 'eq',
194
- value: orderInventory.product.sku
195
- },
196
- {
197
- name: 'bizplace',
198
- operator: 'in',
199
- value: [customerBizplaceId]
200
- }
201
- ]
175
+ }
176
+ })
177
+ )
178
+
179
+ let finalOrderInventories: OrderInventory[] = []
180
+
181
+ // Case 1. Every order inventories has specified batch id
182
+ if (newOrderInventories.every((orderInventory: OrderInventory) => orderInventory.batchId)) {
183
+ finalOrderInventories = await Promise.all(
184
+ newOrderInventories.map(async (orderInventory: OrderInventory) => {
185
+ let filters: any = [
186
+ {
187
+ name: 'batchId',
188
+ operator: 'eq',
189
+ value: orderInventory.batchId
190
+ },
191
+ {
192
+ name: 'productName',
193
+ operator: 'eq',
194
+ value: orderInventory.product.sku
195
+ },
196
+ {
197
+ name: 'bizplace',
198
+ operator: 'in',
199
+ value: [customerBizplaceId]
200
+ }
201
+ ]
202
202
 
203
- let sortings: any = []
203
+ let sortings: any = []
204
204
 
205
- switch (orderInventory.product.pickingStrategy) {
206
- case 'FIFO':
207
- sortings.push({ name: 'created_at', desc: false })
208
- break
205
+ switch (orderInventory.product.pickingStrategy) {
206
+ case 'FIFO':
207
+ sortings.push({ name: 'created_at', desc: false })
208
+ break
209
209
 
210
- case 'LIFO':
211
- sortings.push({ name: 'created_at', desc: true })
212
- break
210
+ case 'LIFO':
211
+ sortings.push({ name: 'created_at', desc: true })
212
+ break
213
213
 
214
- case 'FEFO':
215
- sortings.push({ name: 'expiration_date', desc: false })
216
- break
214
+ case 'FEFO':
215
+ sortings.push({ name: 'expiration_date', desc: false })
216
+ break
217
217
 
218
- case 'FMFO':
219
- sortings.push({ name: 'manufacture_date', desc: false })
220
- break
221
- }
218
+ case 'FMFO':
219
+ sortings.push({ name: 'manufacture_date', desc: false })
220
+ break
221
+ }
222
222
 
223
- // 2. get all inventory data according to SKU and batchId
224
- const response = await client.query({
225
- query: gql`
226
- query inventoriesByPallet(
227
- $filters: [Filter]
228
- $sortings: [Sorting]
229
- $locationSortingRules: [Sorting]
223
+ // 2. get all inventory data according to SKU and batchId
224
+ const response = await client.query({
225
+ query: gql`
226
+ query inventoriesByPallet($filters: [Filter], $sortings: [Sorting], $locationSortingRules: [Sorting]) {
227
+ inventoriesByPallet(
228
+ filters: $filters
229
+ sortings: $sortings
230
+ locationSortingRules: $locationSortingRules
230
231
  ) {
231
- inventoriesByPallet(
232
- filters: $filters
233
- sortings: $sortings
234
- locationSortingRules: $locationSortingRules
235
- ) {
236
- items {
237
- product {
238
- id
239
- name
240
- description
241
- }
242
- batchId
243
- packingType
244
- remainQty
245
- remainUomValue
232
+ items {
233
+ product {
234
+ id
235
+ name
236
+ description
246
237
  }
247
- total
238
+ batchId
239
+ packingType
240
+ remainQty
241
+ remainUomValue
248
242
  }
249
- }
250
- `,
251
- variables: { filters, sortings, locationSortingRules },
252
- context: {
253
- ...context,
254
- state: {
255
- ...context.state,
256
- bizplace: customerBizplace,
257
- domain
243
+ total
258
244
  }
259
245
  }
260
- } as any)
261
-
262
- if (!response.errors) {
263
- const items = response.data.inventoriesByPallet.items || []
264
- if (requiredDraft) {
265
- if (!items?.length) {
266
- context.body = {
267
- result: await createDraftOrder(
268
- client,
269
- customerBizplace,
270
- bodyReq,
271
- bundleInfo,
272
- domain,
273
- context,
274
- orderInventories,
275
- tx
276
- )
277
- }
278
- return
279
- }
246
+ `,
247
+ variables: { filters, sortings, locationSortingRules },
248
+ context: {
249
+ ...context,
250
+ state: {
251
+ ...context.state,
252
+ bizplace: customerBizplace,
253
+ domain
280
254
  }
255
+ }
256
+ } as any)
281
257
 
282
- items.forEach(async item => {
283
- if (requiredDraft) {
284
- if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
285
- context.body = {
286
- result: await createDraftOrder(
287
- client,
288
- customerBizplace,
289
- bodyReq,
290
- bundleInfo,
291
- domain,
292
- context,
293
- orderInventories,
294
- tx
295
- )
296
- }
297
- return
298
- }
299
- }
300
-
301
- // 3. add more information to orderInventory
302
- orderInventory.product.id = item.product.id
303
- orderInventory.packingType = item.packingType
304
- orderInventory.batchId = item.batchId
305
- orderInventory.type = ORDER_TYPES.RELEASE_OF_GOODS
306
- orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue
307
- orderInventory.uom = item.uom
308
- })
309
-
310
- return orderInventory
311
- } else {
312
- if (requiredDraft) {
313
- context.body = {
314
- result: await createDraftOrder(
315
- client,
316
- customerBizplace,
317
- bodyReq,
318
- bundleInfo,
319
- domain,
320
- context,
321
- orderInventories,
322
- tx
323
- )
324
- }
325
- return
258
+ if (!response.errors) {
259
+ const items = response.data.inventoriesByPallet.items || []
260
+ if (!items?.length)
261
+ context.throw(
262
+ 404,
263
+ t(
264
+ `error.no inventories found for ${orderInventory.product?.sku} with batch ID ${orderInventory?.batchId}`
265
+ )
266
+ )
267
+
268
+ items.forEach(item => {
269
+ if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
270
+ context.throw(404, t(`error.invalid release qty for ${orderInventory.product?.sku}`))
326
271
  }
327
- }
328
- })
329
- )
330
- } else {
331
- // Case 2. Some of order inventories doesn't have specified batch id
332
- // MMS order doesn't have batch ID field.
333
- // To cover this case first result of found inventory will be a target of RO
334
-
335
- // To combine items from different bundles
336
- newOrderInventories = combineItems(newOrderInventories)
337
-
338
- for (let i: number = 0; i < newOrderInventories.length; i++) {
339
- const orderInventory: OrderInventory = newOrderInventories[i]
340
- const { product, packingType }: { product: Product; packingType: string } = orderInventory
341
- const pickingStrategy: string = product.pickingStrategy
342
-
343
- if (isAutoAssign) {
344
- let qb: SelectQueryBuilder<Inventory> = tx.getRepository(Inventory).createQueryBuilder('iv')
345
- qb.leftJoinAndSelect('iv.location', 'loc')
346
- .andWhere('"iv"."domain_id" = :domainId')
347
- .andWhere('"iv"."bizplace_id" = :bizplaceId')
348
- .andWhere('"iv"."packing_type" = :packingType')
349
- .andWhere('"iv"."product_id" = :productId')
350
- .andWhere('"iv"."status" = :status')
351
- .andWhere('"loc"."type" NOT IN (:...locationTypes)')
352
- .setParameters({
353
- domainId: domain.id,
354
- bizplaceId: customerBizplace.id,
355
- packingType: packingType,
356
- productId: product.id,
357
- status: INVENTORY_STATUS.STORED,
358
- locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]
359
- })
360
-
361
- switch (pickingStrategy) {
362
- case 'FIFO':
363
- qb.orderBy('"iv"."created_at"', 'ASC')
364
- if (locationSortingRules?.length > 0) {
365
- locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
366
- qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
367
- })
368
- }
369
- break
370
-
371
- case 'LIFO':
372
- qb.orderBy('"iv"."created_at"', 'DESC')
373
- if (locationSortingRules?.length > 0) {
374
- locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
375
- qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
376
- })
377
- }
378
- break
379
-
380
- case 'FEFO':
381
- qb.orderBy('"iv"."expiration_date"', 'ASC')
382
- if (locationSortingRules?.length > 0) {
383
- locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
384
- qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
385
- })
386
- }
387
- break
388
-
389
- case 'FMFO':
390
- qb.orderBy('"iv"."manufacture_date"', 'ASC')
391
- if (locationSortingRules?.length > 0) {
392
- locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
393
- qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
394
- })
395
- }
396
- break
397
-
398
- case 'LOCATION':
399
- if (locationSortingRules?.length > 0) {
400
- locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
401
- idx === 0
402
- ? qb.orderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
403
- : qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
404
- })
405
- } else {
406
- qb.orderBy('"loc"."name"', 'DESC')
407
- }
408
- break
409
- }
410
272
 
411
- let inventories: Inventory[] = await qb.getMany()
412
- if (requiredDraft) {
413
- if (!inventories?.length) {
414
- context.body = {
415
- result: await createDraftOrder(
416
- client,
417
- customerBizplace,
418
- bodyReq,
419
- bundleInfo,
420
- domain,
421
- context,
422
- orderInventories,
423
- tx
424
- )
425
- }
426
- return
273
+ // 3. add more information to orderInventory
274
+ orderInventory.product.id = item.product.id
275
+ orderInventory.packingType = item.packingType
276
+ orderInventory.batchId = item.batchId
277
+ orderInventory.type = ORDER_TYPES.RELEASE_OF_GOODS
278
+ orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue
279
+ orderInventory.uom = item.uom
280
+ })
281
+
282
+ return orderInventory
283
+ } else context.throw(404, t('error.failed to fetch inventory'))
284
+ })
285
+ )
286
+ } else {
287
+ // Case 2. Some of order inventories doesn't have specified batch id
288
+ // MMS order doesn't have batch ID field.
289
+ // To cover this case first result of found inventory will be a target of RO
290
+
291
+ // To combine items from different bundles
292
+ newOrderInventories = combineItems(newOrderInventories)
293
+
294
+ for (let i: number = 0; i < newOrderInventories.length; i++) {
295
+ const orderInventory: OrderInventory = newOrderInventories[i]
296
+ const { product, packingType }: { product: Product; packingType: string } = orderInventory
297
+ const pickingStrategy: string = product.pickingStrategy
298
+
299
+ if (isAutoAssign) {
300
+ let qb: SelectQueryBuilder<Inventory> = tx.getRepository(Inventory).createQueryBuilder('iv')
301
+ qb.leftJoinAndSelect('iv.location', 'loc')
302
+ .andWhere('"iv"."domain_id" = :domainId')
303
+ .andWhere('"iv"."bizplace_id" = :bizplaceId')
304
+ .andWhere('"iv"."packing_type" = :packingType')
305
+ .andWhere('"iv"."product_id" = :productId')
306
+ .andWhere('"iv"."status" = :status')
307
+ .andWhere('"loc"."type" NOT IN (:...locationTypes)')
308
+ .setParameters({
309
+ domainId: domain.id,
310
+ bizplaceId: customerBizplace.id,
311
+ packingType: packingType,
312
+ productId: product.id,
313
+ status: INVENTORY_STATUS.STORED,
314
+ locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]
315
+ })
316
+
317
+ switch (pickingStrategy) {
318
+ case 'FIFO':
319
+ qb.orderBy('"iv"."created_at"', 'ASC')
320
+ if (locationSortingRules?.length > 0) {
321
+ locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
322
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
323
+ })
427
324
  }
428
- }
429
- inventories = inventories
430
- .map(inventory => {
431
- return {
432
- ...inventory,
433
- remainQty: inventory.qty - inventory.lockedQty,
434
- remainUomValue: inventory.uomValue - inventory.lockedUomValue
435
- }
436
- })
437
- .filter(inventory => inventory.remainQty > 0)
438
-
439
- let targetInventories: WorksheetDetail[]
440
- try {
441
- targetInventories = _composeTargetInventories(context, product, orderInventory, inventories)
442
- } catch (e) {
443
- if (requiredDraft) {
444
- context.body = {
445
- result: await createDraftOrder(
446
- client,
447
- customerBizplace,
448
- bodyReq,
449
- bundleInfo,
450
- domain,
451
- context,
452
- orderInventories,
453
- tx
454
- )
455
- }
456
- return
457
- } else {
458
- targetInventories = _composeTargetInventories(context, product, orderInventory, inventories)
325
+ break
326
+
327
+ case 'LIFO':
328
+ qb.orderBy('"iv"."created_at"', 'DESC')
329
+ if (locationSortingRules?.length > 0) {
330
+ locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
331
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
332
+ })
459
333
  }
460
- }
461
- if (!targetInventories?.length) {
462
- context.throw(404, t(`error.no inventories found`))
463
- }
464
- targetInventories.map(item => {
465
- finalOrderInventories.push(item.targetInventory)
466
- })
467
- } else {
468
- let filters: any = [
469
- {
470
- name: 'productName',
471
- operator: 'eq',
472
- value: orderInventory.product.sku
473
- },
474
- {
475
- name: 'bizplace_id',
476
- operator: 'eq',
477
- value: customerBizplaceId
334
+ break
335
+
336
+ case 'FEFO':
337
+ qb.orderBy('"iv"."expiration_date"', 'ASC')
338
+ if (locationSortingRules?.length > 0) {
339
+ locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
340
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
341
+ })
478
342
  }
479
- ]
480
-
481
- // 2. get all inventory data according to SKU and batchId
482
- const response = await client.query({
483
- query: gql`
484
- query inventoryProductGroup($filters: [Filter]) {
485
- inventoryProductGroup(filters: $filters) {
486
- items {
487
- productId
488
- productSKU
489
- productName
490
- batchId
491
- packingType
492
- remainQty
493
- remainUomValue
494
- }
495
- total
496
- }
497
- }
498
- `,
499
- variables: { filters },
500
- context: {
501
- ...context,
502
- state: {
503
- ...context.state,
504
- bizplace: customerBizplace,
505
- domain
506
- }
343
+ break
344
+
345
+ case 'FMFO':
346
+ qb.orderBy('"iv"."manufacture_date"', 'ASC')
347
+ if (locationSortingRules?.length > 0) {
348
+ locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
349
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
350
+ })
507
351
  }
508
- } as any)
509
-
510
- if (!response.errors) {
511
- const items = response.data.inventoryProductGroup.items || []
512
- if (requiredDraft) {
513
- if (!items?.length) {
514
- context.body = {
515
- result: await createDraftOrder(
516
- client,
517
- customerBizplace,
518
- bodyReq,
519
- bundleInfo,
520
- domain,
521
- context,
522
- orderInventories,
523
- tx
524
- )
525
- }
526
- return
527
- }
352
+ break
353
+
354
+ case 'LOCATION':
355
+ if (locationSortingRules?.length > 0) {
356
+ locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
357
+ idx === 0
358
+ ? qb.orderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
359
+ : qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
360
+ })
361
+ } else {
362
+ qb.orderBy('"loc"."name"', 'DESC')
528
363
  }
364
+ break
365
+ }
529
366
 
530
- items.forEach(async item => {
531
- if (requiredDraft) {
532
- if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
533
- context.body = {
534
- result: await createDraftOrder(
535
- client,
536
- customerBizplace,
537
- bodyReq,
538
- bundleInfo,
539
- domain,
540
- context,
541
- orderInventories,
542
- tx
543
- )
544
- }
545
- return
546
- }
547
- }
367
+ let inventories: Inventory[] = await qb.getMany()
368
+ if (!inventories?.length) context.throw(404, t(`error.no inventories found for ${product.sku}`))
548
369
 
549
- // 3. add more information to orderInventory
550
- orderInventory.product = { id: item.productId }
551
- orderInventory.packingType = item.packingType
552
- orderInventory.batchId = item.batchId
553
- orderInventory.type = ORDER_TYPES.RELEASE_OF_GOODS
554
- orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue
555
- orderInventory.uom = item.uom
556
- })
557
-
558
- delete orderInventory.uomValue
559
- finalOrderInventories.push(orderInventory)
560
- } else {
561
- if (requiredDraft) {
562
- context.body = {
563
- result: await createDraftOrder(
564
- client,
565
- customerBizplace,
566
- bodyReq,
567
- bundleInfo,
568
- domain,
569
- context,
570
- orderInventories,
571
- tx
572
- )
573
- }
574
- return
370
+ inventories = inventories
371
+ .map(inventory => {
372
+ return {
373
+ ...inventory,
374
+ remainQty: inventory.qty - inventory.lockedQty,
375
+ remainUomValue: inventory.uomValue - inventory.lockedUomValue
575
376
  }
377
+ })
378
+ .filter(inventory => inventory.remainQty > 0)
379
+
380
+ const targetInventories: WorksheetDetail[] = _composeTargetInventories(
381
+ context,
382
+ product,
383
+ orderInventory,
384
+ inventories
385
+ )
386
+ targetInventories.map(item => {
387
+ finalOrderInventories.push(item.targetInventory)
388
+ })
389
+ } else {
390
+ let filters: any = [
391
+ {
392
+ name: 'productName',
393
+ operator: 'eq',
394
+ value: orderInventory.product.sku
395
+ },
396
+ {
397
+ name: 'bizplace_id',
398
+ operator: 'eq',
399
+ value: customerBizplaceId
576
400
  }
577
- }
578
- }
579
- }
580
-
581
- context.body = {
582
- result: (
583
- await client.mutate({
584
- mutation: gql`
585
- mutation addReleaseGood(
586
- $releaseGood: NewReleaseGood
587
- $shippingOrder: ShippingOrderPatch
588
- $file: Upload
589
- ) {
590
- addReleaseGood(releaseGood: $releaseGood, shippingOrder: $shippingOrder, file: $file) {
591
- id
592
- name
593
- refNo
594
- status
595
- truckNo
596
- ownTransport
597
- crossDocking
598
- marketplaceOrderStatus
599
- billingAddress
600
- deliveryAddress1
601
- deliveryAddress2
602
- deliveryAddress3
603
- deliveryAddress4
604
- deliveryAddress5
605
- attentionTo
606
- attentionCompany
607
- city
608
- state
609
- postalCode
610
- country
611
- phone1
612
- phone2
613
- email
614
- transporter
615
- trackingNo
616
- airwayBill
617
- invoice
618
- type
619
- storeName
620
- storeId
621
- routeId
622
- stopId
623
- arrivalNotice {
624
- name
625
- }
626
- exportOption
627
- releaseDate
628
- collectionOrderNo
629
- bizplace {
630
- name
631
- }
632
- orderInventories {
633
- product {
634
- sku
635
- name
636
- description
637
- }
401
+ ]
402
+
403
+ // 2. get all inventory data according to SKU and batchId
404
+ const response = await client.query({
405
+ query: gql`
406
+ query inventoryProductGroup($filters: [Filter]) {
407
+ inventoryProductGroup(filters: $filters) {
408
+ items {
409
+ productId
410
+ productSKU
411
+ productName
638
412
  batchId
639
413
  packingType
640
- packingSize
641
- releaseQty
642
- releaseUomValue
643
- }
644
- orderVass {
645
- vas {
646
- name
647
- operationGuide
648
- operationGuideType
649
- }
650
- set
651
- targetType
652
- targetBatchId
653
- targetProduct {
654
- name
655
- description
656
- }
657
- packingType
658
- qty
659
- uomValue
660
- otherTarget
661
- description
662
- remark
663
- status
664
- operationGuide
414
+ remainQty
415
+ remainUomValue
665
416
  }
417
+ total
666
418
  }
667
419
  }
668
420
  `,
669
- variables: {
670
- releaseGood: {
671
- customerBizplaceId: customerBizplace.id,
672
- courierOption: bodyReq.courierOption,
673
- collectionOrderNo: bodyReq.collectionOrderNo,
674
- exportOption: bodyReq.exportOption,
675
- orderInventories: finalOrderInventories,
676
- ownTransport: bodyReq.ownTransport,
677
- packingOption: bodyReq.packingOption,
678
- refNo: bodyReq.refNo,
679
- refNo2: bodyReq?.refNo2,
680
- releaseDate: bodyReq.releaseDate,
681
- type: bodyReq.type,
682
- marketplaceOrderStatus: bodyReq?.marketplaceOrderStatus,
683
- remark: bodyReq?.remark || null,
684
- billingAddress: bodyReq?.billTo?.billingAddress || null,
685
- deliveryAddress1: bodyReq?.deliverTo?.deliveryAddress1 || null,
686
- deliveryAddress2: bodyReq?.deliverTo?.deliveryAddress2 || null,
687
- deliveryAddress3: bodyReq?.deliverTo?.deliveryAddress3 || null,
688
- deliveryAddress4: bodyReq?.deliverTo?.deliveryAddress4 || null,
689
- deliveryAddress5: bodyReq?.deliverTo?.deliveryAddress5 || null,
690
- attentionTo: bodyReq?.deliverTo?.attentionTo || null,
691
- attentionCompany: bodyReq?.deliverTo?.attentionCompany || null,
692
- city: bodyReq?.deliverTo?.city || null,
693
- state: bodyReq?.deliverTo?.state || null,
694
- postalCode: bodyReq?.deliverTo?.postalCode || null,
695
- country: bodyReq?.deliverTo?.country || null,
696
- phone1: bodyReq?.deliverTo?.phone1 || null,
697
- phone2: bodyReq?.deliverTo?.phone2 || null,
698
- email: bodyReq?.deliverTo?.email || null,
699
- transporter: bodyReq?.transporter,
700
- trackingNo: bodyReq?.trackingNo,
701
- airwayBill: bodyReq?.airwayBill,
702
- invoice: bodyReq?.invoice,
703
- bundleInfo: JSON.stringify(bundleInfo),
704
- storeName: bodyReq?.storeName,
705
- storeId: bodyReq?.storeId,
706
- routeId: bodyReq?.routeId,
707
- stopId: bodyReq?.stopId
708
- }
709
- },
421
+ variables: { filters },
710
422
  context: {
711
423
  ...context,
712
- hasUpload: true,
713
424
  state: {
714
425
  ...context.state,
715
- customerBizplace,
716
- domain,
717
- type: 'api'
426
+ bizplace: customerBizplace,
427
+ domain
718
428
  }
719
429
  }
720
430
  } as any)
721
- ).data
431
+
432
+ if (!response.errors) {
433
+ const items = response.data.inventoryProductGroup.items || []
434
+ if (!items?.length)
435
+ context.throw(
436
+ 404,
437
+ t(
438
+ `error.no inventories found for ${orderInventory.product?.sku} with batch ID ${orderInventory?.batchId}`
439
+ )
440
+ )
441
+
442
+ items.forEach(item => {
443
+ if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
444
+ context.throw(404, t(`error.invalid release qty for ${orderInventory.product?.sku}`))
445
+ }
446
+
447
+ // 3. add more information to orderInventory
448
+ orderInventory.product = { id: item.productId }
449
+ orderInventory.packingType = item.packingType
450
+ orderInventory.batchId = item.batchId
451
+ orderInventory.type = ORDER_TYPES.RELEASE_OF_GOODS
452
+ orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue
453
+ orderInventory.uom = item.uom
454
+ })
455
+
456
+ delete orderInventory.uomValue
457
+ finalOrderInventories.push(orderInventory)
458
+ } else context.throw(404, t('error.failed to fetch inventory'))
459
+ }
722
460
  }
461
+ }
723
462
 
724
- createPayloadLog(
725
- customerBizplaceId,
726
- `/${apiVersion}/warehouse/:warehouseId/add-release-order`,
727
- bodyReq,
728
- context.body,
729
- context,
730
- PayloadType.INGESTION
731
- )
732
- } catch (error) {
733
- createPayloadLog(
734
- customerBizplaceId,
735
- `/${apiVersion}/warehouse/:warehouseId/add-release-order`,
736
- bodyReq,
737
- error,
738
- context,
739
- PayloadType.INGESTION
740
- )
741
- throw error
463
+ context.body = {
464
+ result: (
465
+ await client.mutate({
466
+ mutation: gql`
467
+ mutation addReleaseGood($releaseGood: NewReleaseGood, $shippingOrder: ShippingOrderPatch, $file: Upload) {
468
+ addReleaseGood(releaseGood: $releaseGood, shippingOrder: $shippingOrder, file: $file) {
469
+ id
470
+ name
471
+ refNo
472
+ status
473
+ truckNo
474
+ ownTransport
475
+ crossDocking
476
+ marketplaceOrderStatus
477
+ billingAddress
478
+ deliveryAddress1
479
+ deliveryAddress2
480
+ deliveryAddress3
481
+ deliveryAddress4
482
+ deliveryAddress5
483
+ attentionTo
484
+ attentionCompany
485
+ city
486
+ state
487
+ postalCode
488
+ country
489
+ phone1
490
+ phone2
491
+ email
492
+ transporter
493
+ trackingNo
494
+ airwayBill
495
+ invoice
496
+ type
497
+ storeName
498
+ storeId
499
+ routeId
500
+ stopId
501
+ arrivalNotice {
502
+ name
503
+ }
504
+ exportOption
505
+ releaseDate
506
+ collectionOrderNo
507
+ bizplace {
508
+ name
509
+ }
510
+ orderInventories {
511
+ product {
512
+ sku
513
+ name
514
+ description
515
+ }
516
+ batchId
517
+ packingType
518
+ packingSize
519
+ releaseQty
520
+ releaseUomValue
521
+ }
522
+ orderVass {
523
+ vas {
524
+ name
525
+ operationGuide
526
+ operationGuideType
527
+ }
528
+ set
529
+ targetType
530
+ targetBatchId
531
+ targetProduct {
532
+ name
533
+ description
534
+ }
535
+ packingType
536
+ qty
537
+ uomValue
538
+ otherTarget
539
+ description
540
+ remark
541
+ status
542
+ operationGuide
543
+ }
544
+ }
545
+ }
546
+ `,
547
+ variables: {
548
+ releaseGood: {
549
+ customerBizplaceId: customerBizplace.id,
550
+ courierOption: bodyReq.courierOption,
551
+ collectionOrderNo: bodyReq.collectionOrderNo,
552
+ exportOption: bodyReq.exportOption,
553
+ orderInventories: finalOrderInventories,
554
+ ownTransport: bodyReq.ownTransport,
555
+ packingOption: bodyReq.packingOption,
556
+ refNo: bodyReq.refNo,
557
+ refNo2: bodyReq?.refNo2,
558
+ releaseDate: bodyReq.releaseDate,
559
+ type: bodyReq.type,
560
+ marketplaceOrderStatus: bodyReq?.marketplaceOrderStatus,
561
+ remark: bodyReq?.remark || null,
562
+ billingAddress: bodyReq?.billTo?.billingAddress || null,
563
+ deliveryAddress1: bodyReq?.deliverTo?.deliveryAddress1 || null,
564
+ deliveryAddress2: bodyReq?.deliverTo?.deliveryAddress2 || null,
565
+ deliveryAddress3: bodyReq?.deliverTo?.deliveryAddress3 || null,
566
+ deliveryAddress4: bodyReq?.deliverTo?.deliveryAddress4 || null,
567
+ deliveryAddress5: bodyReq?.deliverTo?.deliveryAddress5 || null,
568
+ attentionTo: bodyReq?.deliverTo?.attentionTo || null,
569
+ attentionCompany: bodyReq?.deliverTo?.attentionCompany || null,
570
+ city: bodyReq?.deliverTo?.city || null,
571
+ state: bodyReq?.deliverTo?.state || null,
572
+ postalCode: bodyReq?.deliverTo?.postalCode || null,
573
+ country: bodyReq?.deliverTo?.country || null,
574
+ phone1: bodyReq?.deliverTo?.phone1 || null,
575
+ phone2: bodyReq?.deliverTo?.phone2 || null,
576
+ email: bodyReq?.deliverTo?.email || null,
577
+ transporter: bodyReq?.transporter,
578
+ trackingNo: bodyReq?.trackingNo,
579
+ airwayBill: bodyReq?.airwayBill,
580
+ invoice: bodyReq?.invoice,
581
+ bundleInfo: JSON.stringify(bundleInfo),
582
+ storeName: bodyReq?.storeName,
583
+ storeId: bodyReq?.storeId,
584
+ routeId: bodyReq?.routeId,
585
+ stopId: bodyReq?.stopId
586
+ }
587
+ },
588
+ context: {
589
+ ...context,
590
+ hasUpload: true,
591
+ state: {
592
+ ...context.state,
593
+ customerBizplace,
594
+ domain,
595
+ type: 'api'
596
+ }
597
+ }
598
+ } as any)
599
+ ).data
742
600
  }
743
601
  })
744
602
  }
@@ -805,7 +663,7 @@ export function _composeTargetInventories(context, product, record, inventories)
805
663
  })
806
664
 
807
665
  if (totalInventoryQty < record.releaseQty) {
808
- context.throw(404, t(`error.invalid release qty for ${product?.sku}`)) //
666
+ context.throw(404, t(`error.invalid release qty for ${product?.sku}`))
809
667
  }
810
668
 
811
669
  let targetInventories = []
@@ -871,93 +729,3 @@ function combineItems(inventoryList) {
871
729
 
872
730
  return mappedList
873
731
  }
874
-
875
- async function createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx) {
876
- return (
877
- await client.mutate({
878
- mutation: gql`
879
- mutation upsertDraftReleaseGood(
880
- $draftReleaseGood: DraftReleaseGoodPatch!
881
- $orderProducts: [OrderProductPatch!]!
882
- ) {
883
- upsertDraftReleaseGood(draftReleaseGood: $draftReleaseGood, orderProducts: $orderProducts) {
884
- id
885
- name
886
- refNo
887
- refNo2
888
- status
889
- truckNo
890
- ownTransport
891
- marketplaceOrderStatus
892
- billingAddress
893
- deliveryAddress1
894
- deliveryAddress2
895
- deliveryAddress3
896
- deliveryAddress4
897
- deliveryAddress5
898
- attentionTo
899
- attentionCompany
900
- city
901
- state
902
- postalCode
903
- country
904
- phone1
905
- phone2
906
- email
907
- type
908
- exportOption
909
- releaseDate
910
- collectionOrderNo
911
- bizplace {
912
- name
913
- }
914
- }
915
- }
916
- `,
917
- variables: {
918
- draftReleaseGood: {
919
- bizplace: {
920
- id: customerBizplace.id
921
- },
922
- courierOption: bodyReq.courierOption,
923
- collectionOrderNo: bodyReq.collectionOrderNo,
924
- exportOption: bodyReq.exportOption,
925
- ownTransport: bodyReq.ownTransport,
926
- packingOption: bodyReq.packingOption,
927
- refNo: bodyReq.refNo,
928
- refNo2: bodyReq?.refNo2,
929
- releaseDate: bodyReq.releaseDate,
930
- type: bodyReq.type,
931
- marketplaceOrderStatus: bodyReq?.marketplaceOrderStatus,
932
- remark: bodyReq?.remark || null,
933
- billingAddress: bodyReq?.billTo?.billingAddress || null,
934
- deliveryAddress1: bodyReq?.deliverTo?.deliveryAddress1 || null,
935
- deliveryAddress2: bodyReq?.deliverTo?.deliveryAddress2 || null,
936
- deliveryAddress3: bodyReq?.deliverTo?.deliveryAddress3 || null,
937
- deliveryAddress4: bodyReq?.deliverTo?.deliveryAddress4 || null,
938
- deliveryAddress5: bodyReq?.deliverTo?.deliveryAddress5 || null,
939
- attentionTo: bodyReq?.deliverTo?.attentionTo || null,
940
- attentionCompany: bodyReq?.deliverTo?.attentionCompany || null,
941
- city: bodyReq?.deliverTo?.city || null,
942
- state: bodyReq?.deliverTo?.state || null,
943
- postalCode: bodyReq?.deliverTo?.postalCode || null,
944
- country: bodyReq?.deliverTo?.country || null,
945
- phone1: bodyReq?.deliverTo?.phone1 || null,
946
- phone2: bodyReq?.deliverTo?.phone2 || null,
947
- email: bodyReq?.deliverTo?.email || null
948
- },
949
- orderProducts: orderInventories
950
- },
951
- context: {
952
- ...context,
953
- hasUpload: true,
954
- state: {
955
- ...context.state,
956
- customerBizplace,
957
- domain,
958
- type: 'api'
959
- }
960
- }
961
- } as any)
962
- ).data
963
- }