@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 = 'v1'
15
+ const debug = require('debug')('things-factory:operato-hub:restful-api:v1:add-release-order')
18
16
 
19
17
  router.post(
20
- `/${apiVersion}/warehouse/:warehouseId/add-release-order`,
18
+ '/v1/warehouse/:warehouseId/add-release-order',
21
19
  businessMiddleware,
22
20
  warehouseMiddleware,
23
21
  async (context, next) => {
@@ -25,720 +23,581 @@ 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 (packingSize) {
99
+ qb.andWhere('PD.packing_size = :packingSize', { packingSize })
100
+ }
101
+
102
+ if (!packingType && !refCode) {
103
+ qb.andWhere('PD.is_default = :isDefault', { isDefault: true })
104
+ }
105
+
106
+ const productDetail: ProductDetail = await qb.getOne()
107
+
108
+ if (productDetail) {
109
+ let newOrderInventory: OrderInventory = Object.assign({}, orderInventory)
110
+
111
+ newOrderInventory.product.sku = productDetail.product.sku
112
+ newOrderInventory.product = productDetail.product
113
+ newOrderInventory.packingType = productDetail.packingType
114
+ newOrderInventory.uomValue = productDetail.uomValue
115
+ newOrderInventories.push(newOrderInventory)
116
+ }
117
+
118
+ if (!productDetail) {
79
119
  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 })
120
+ .getRepository(ProductBundle)
121
+ .createQueryBuilder('PB')
122
+ .innerJoinAndSelect('PB.productBundleSettings', 'PBS')
123
+ .innerJoinAndSelect('PBS.productDetail', 'PBD')
124
+ .innerJoinAndSelect('PBD.product', 'PROD')
125
+ .where('PB.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id })
84
126
 
85
127
  if (!sku && !refCode) {
86
128
  context.throw(404, t('error.sku or refCode not found'))
87
129
  }
88
130
 
89
131
  if (refCode) {
90
- qb.andWhere('PD.ref_code = :refCode', { refCode })
132
+ qb.andWhere('PB.ref_code = :refCode', { refCode })
91
133
  }
92
134
 
93
135
  if (sku) {
94
- qb.andWhere('PROD.sku = :sku', { sku })
136
+ qb.andWhere('PB.sku = :sku', { sku })
95
137
  }
96
138
 
97
139
  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)
140
+ qb.andWhere('PB.packing_type = :packingType', { packingType })
115
141
  }
116
142
 
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
- }
143
+ const foundProductBundle: ProductBundle = await qb.getOne()
129
144
 
130
- if (refCode) {
131
- qb.andWhere('PB.ref_code = :refCode', { refCode })
145
+ if (foundProductBundle) {
146
+ bundleInfo.push({
147
+ productBundleId: foundProductBundle.id,
148
+ sku: foundProductBundle.sku,
149
+ releaseQty: orderInventory.releaseQty
150
+ })
151
+ const bundleProductSettings: any[] = foundProductBundle.productBundleSettings
152
+ bundleProductSettings.map(bundleProductSetting => {
153
+ const productDetailBundle: ProductDetail = bundleProductSetting.productDetail
154
+
155
+ let newOrderInventory: OrderInventory = Object.assign({}, orderInventory)
156
+ newOrderInventory.product.sku = productDetailBundle.product.sku
157
+ newOrderInventory.packingType = productDetailBundle.packingType
158
+ newOrderInventory.uomValue = productDetailBundle.uomValue
159
+ newOrderInventory.releaseQty = orderInventory.releaseQty * bundleProductSetting.bundleQty
160
+ newOrderInventory.product = productDetailBundle.product
161
+ newOrderInventories.push(newOrderInventory)
162
+ })
163
+ } else {
164
+ if (sku && refCode) {
165
+ context.throw(404, t(`error.sku ${sku} and refCode ${refCode} not exist in product / bundle master`))
132
166
  }
133
167
 
134
168
  if (sku) {
135
- qb.andWhere('PB.sku = :sku', { sku })
136
- }
137
-
138
- if (packingType) {
139
- qb.andWhere('PB.packing_type = :packingType', { packingType })
169
+ context.throw(404, t(`error.sku ${sku} not exist in product / bundle master`))
140
170
  }
141
171
 
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
- }
172
+ if (refCode) {
173
+ context.throw(404, t(`error.refCode ${refCode} not exist in product / bundle master`))
174
174
  }
175
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
- ]
176
+ }
177
+ })
178
+ )
179
+
180
+ let finalOrderInventories: OrderInventory[] = []
181
+
182
+ // Case 1. Every order inventories has specified batch id
183
+ if (newOrderInventories.every((orderInventory: OrderInventory) => orderInventory.batchId)) {
184
+ finalOrderInventories = await Promise.all(
185
+ newOrderInventories.map(async (orderInventory: OrderInventory) => {
186
+ let filters: any = [
187
+ {
188
+ name: 'batchId',
189
+ operator: 'eq',
190
+ value: orderInventory.batchId
191
+ },
192
+ {
193
+ name: 'productName',
194
+ operator: 'eq',
195
+ value: orderInventory.product.sku
196
+ },
197
+ {
198
+ name: 'bizplace',
199
+ operator: 'in',
200
+ value: [customerBizplaceId]
201
+ }
202
+ ]
202
203
 
203
- let sortings: any = []
204
+ let sortings: any = []
204
205
 
205
- switch (orderInventory.product.pickingStrategy) {
206
- case 'FIFO':
207
- sortings.push({ name: 'created_at', desc: false })
208
- break
206
+ switch (orderInventory.product.pickingStrategy) {
207
+ case 'FIFO':
208
+ sortings.push({ name: 'created_at', desc: false })
209
+ break
209
210
 
210
- case 'LIFO':
211
- sortings.push({ name: 'created_at', desc: true })
212
- break
211
+ case 'LIFO':
212
+ sortings.push({ name: 'created_at', desc: true })
213
+ break
213
214
 
214
- case 'FEFO':
215
- sortings.push({ name: 'expiration_date', desc: false })
216
- break
215
+ case 'FEFO':
216
+ sortings.push({ name: 'expiration_date', desc: false })
217
+ break
217
218
 
218
- case 'FMFO':
219
- sortings.push({ name: 'manufacture_date', desc: false })
220
- break
221
- }
219
+ case 'FMFO':
220
+ sortings.push({ name: 'manufacture_date', desc: false })
221
+ break
222
+ }
222
223
 
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]
224
+ // 2. get all inventory data according to SKU and batchId
225
+ const response = await client.query({
226
+ query: gql`
227
+ query inventoriesByPallet($filters: [Filter], $sortings: [Sorting], $locationSortingRules: [Sorting]) {
228
+ inventoriesByPallet(
229
+ filters: $filters
230
+ sortings: $sortings
231
+ locationSortingRules: $locationSortingRules
230
232
  ) {
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
233
+ items {
234
+ product {
235
+ id
236
+ name
237
+ description
246
238
  }
247
- total
239
+ batchId
240
+ packingType
241
+ remainQty
242
+ remainUomValue
248
243
  }
249
- }
250
- `,
251
- variables: { filters, sortings, locationSortingRules },
252
- context: {
253
- ...context,
254
- state: {
255
- ...context.state,
256
- bizplace: customerBizplace,
257
- domain
244
+ total
258
245
  }
259
246
  }
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
- }
247
+ `,
248
+ variables: { filters, sortings, locationSortingRules },
249
+ context: {
250
+ ...context,
251
+ state: {
252
+ ...context.state,
253
+ bizplace: customerBizplace,
254
+ domain
280
255
  }
256
+ }
257
+ } as any)
281
258
 
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
259
+ if (!response.errors) {
260
+ const items = response.data.inventoriesByPallet.items || []
261
+ if (!items?.length)
262
+ context.throw(
263
+ 404,
264
+ t(
265
+ `error.no inventories found for ${orderInventory.product?.sku} with batch ID ${orderInventory?.batchId}`
266
+ )
267
+ )
268
+
269
+ items.forEach(item => {
270
+ if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
271
+ context.throw(404, t(`error.invalid release qty for ${orderInventory.product?.sku}`))
326
272
  }
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
273
 
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
274
+ // 3. add more information to orderInventory
275
+ orderInventory.product.id = item.product.id
276
+ orderInventory.packingType = item.packingType
277
+ orderInventory.batchId = item.batchId
278
+ orderInventory.type = ORDER_TYPES.RELEASE_OF_GOODS
279
+ orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue
280
+ orderInventory.uom = item.uom
281
+ })
282
+
283
+ return orderInventory
284
+ } else context.throw(404, t('error.failed to fetch inventory'))
285
+ })
286
+ )
287
+ } else {
288
+ // Case 2. Some of order inventories doesn't have specified batch id
289
+ // MMS order doesn't have batch ID field.
290
+ // To cover this case first result of found inventory will be a target of RO
291
+
292
+ // To combine items from different bundles
293
+ newOrderInventories = combineItems(newOrderInventories)
294
+
295
+ for (let i: number = 0; i < newOrderInventories.length; i++) {
296
+ const orderInventory: OrderInventory = newOrderInventories[i]
297
+ const { product, packingType }: { product: Product; packingType: string } = orderInventory
298
+ const pickingStrategy: string = product.pickingStrategy
299
+
300
+ if (isAutoAssign) {
301
+ let qb: SelectQueryBuilder<Inventory> = tx.getRepository(Inventory).createQueryBuilder('iv')
302
+ qb.leftJoinAndSelect('iv.location', 'loc')
303
+ .andWhere('"iv"."domain_id" = :domainId')
304
+ .andWhere('"iv"."bizplace_id" = :bizplaceId')
305
+ .andWhere('"iv"."packing_type" = :packingType')
306
+ .andWhere('"iv"."product_id" = :productId')
307
+ .andWhere('"iv"."status" = :status')
308
+ .andWhere('"loc"."type" NOT IN (:...locationTypes)')
309
+ .setParameters({
310
+ domainId: domain.id,
311
+ bizplaceId: customerBizplace.id,
312
+ packingType: packingType,
313
+ productId: product.id,
314
+ status: INVENTORY_STATUS.STORED,
315
+ locationTypes: [LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]
316
+ })
317
+
318
+ switch (pickingStrategy) {
319
+ case 'FIFO':
320
+ qb.orderBy('"iv"."created_at"', 'ASC')
321
+ if (locationSortingRules?.length > 0) {
322
+ locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
323
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
324
+ })
427
325
  }
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)
326
+ break
327
+
328
+ case 'LIFO':
329
+ qb.orderBy('"iv"."created_at"', 'DESC')
330
+ if (locationSortingRules?.length > 0) {
331
+ locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
332
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
333
+ })
459
334
  }
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
335
+ break
336
+
337
+ case 'FEFO':
338
+ qb.orderBy('"iv"."expiration_date"', 'ASC')
339
+ if (locationSortingRules?.length > 0) {
340
+ locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
341
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
342
+ })
478
343
  }
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
- }
344
+ break
345
+
346
+ case 'FMFO':
347
+ qb.orderBy('"iv"."manufacture_date"', 'ASC')
348
+ if (locationSortingRules?.length > 0) {
349
+ locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
350
+ qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
351
+ })
507
352
  }
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
- }
353
+ break
354
+
355
+ case 'LOCATION':
356
+ if (locationSortingRules?.length > 0) {
357
+ locationSortingRules.forEach((rule: { name: string; desc: boolean }, idx: number) => {
358
+ idx === 0
359
+ ? qb.orderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
360
+ : qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
361
+ })
362
+ } else {
363
+ qb.orderBy('"loc"."name"', 'DESC')
528
364
  }
365
+ break
366
+ }
529
367
 
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
- }
368
+ let inventories: Inventory[] = await qb.getMany()
369
+ if (!inventories?.length) context.throw(404, t(`error.no inventories found for ${product.sku}`))
548
370
 
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
371
+ inventories = inventories
372
+ .map(inventory => {
373
+ return {
374
+ ...inventory,
375
+ remainQty: inventory.qty - inventory.lockedQty,
376
+ remainUomValue: inventory.uomValue - inventory.lockedUomValue
575
377
  }
378
+ })
379
+ .filter(inventory => inventory.remainQty > 0)
380
+
381
+ const targetInventories: WorksheetDetail[] = _composeTargetInventories(
382
+ context,
383
+ product,
384
+ orderInventory,
385
+ inventories
386
+ )
387
+ targetInventories.map(item => {
388
+ finalOrderInventories.push(item.targetInventory)
389
+ })
390
+ } else {
391
+ let filters: any = [
392
+ {
393
+ name: 'productName',
394
+ operator: 'eq',
395
+ value: orderInventory.product.sku
396
+ },
397
+ {
398
+ name: 'bizplace_id',
399
+ operator: 'eq',
400
+ value: customerBizplaceId
576
401
  }
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
- }
402
+ ]
403
+
404
+ // 2. get all inventory data according to SKU and batchId
405
+ const response = await client.query({
406
+ query: gql`
407
+ query inventoryProductGroup($filters: [Filter]) {
408
+ inventoryProductGroup(filters: $filters) {
409
+ items {
410
+ productId
411
+ productSKU
412
+ productName
638
413
  batchId
639
414
  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
415
+ remainQty
416
+ remainUomValue
665
417
  }
418
+ total
666
419
  }
667
420
  }
668
421
  `,
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
- },
422
+ variables: { filters },
710
423
  context: {
711
424
  ...context,
712
- hasUpload: true,
713
425
  state: {
714
426
  ...context.state,
715
- customerBizplace,
716
- domain,
717
- type: 'api'
427
+ bizplace: customerBizplace,
428
+ domain
718
429
  }
719
430
  }
720
431
  } as any)
721
- ).data
432
+
433
+ if (!response.errors) {
434
+ const items = response.data.inventoryProductGroup.items || []
435
+ if (!items?.length)
436
+ context.throw(
437
+ 404,
438
+ t(
439
+ `error.no inventories found for ${orderInventory.product?.sku} with batch ID ${orderInventory?.batchId}`
440
+ )
441
+ )
442
+
443
+ items.forEach(item => {
444
+ if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
445
+ context.throw(404, t(`error.invalid release qty for ${orderInventory.product?.sku}`))
446
+ }
447
+
448
+ // 3. add more information to orderInventory
449
+ orderInventory.product = { id: item.productId }
450
+ orderInventory.packingType = item.packingType
451
+ orderInventory.batchId = item.batchId
452
+ orderInventory.type = ORDER_TYPES.RELEASE_OF_GOODS
453
+ orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue
454
+ orderInventory.uom = item.uom
455
+ })
456
+
457
+ delete orderInventory.uomValue
458
+ finalOrderInventories.push(orderInventory)
459
+ } else context.throw(404, t('error.failed to fetch inventory'))
460
+ }
722
461
  }
462
+ }
723
463
 
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
464
+ context.body = {
465
+ result: (
466
+ await client.mutate({
467
+ mutation: gql`
468
+ mutation addReleaseGood($releaseGood: NewReleaseGood, $shippingOrder: ShippingOrderPatch, $file: Upload) {
469
+ addReleaseGood(releaseGood: $releaseGood, shippingOrder: $shippingOrder, file: $file) {
470
+ id
471
+ name
472
+ refNo
473
+ status
474
+ truckNo
475
+ ownTransport
476
+ crossDocking
477
+ marketplaceOrderStatus
478
+ billingAddress
479
+ deliveryAddress1
480
+ deliveryAddress2
481
+ deliveryAddress3
482
+ deliveryAddress4
483
+ deliveryAddress5
484
+ attentionTo
485
+ attentionCompany
486
+ city
487
+ state
488
+ postalCode
489
+ country
490
+ phone1
491
+ phone2
492
+ email
493
+ transporter
494
+ trackingNo
495
+ airwayBill
496
+ invoice
497
+ type
498
+ storeName
499
+ storeId
500
+ routeId
501
+ stopId
502
+ arrivalNotice {
503
+ name
504
+ }
505
+ exportOption
506
+ releaseDate
507
+ collectionOrderNo
508
+ bizplace {
509
+ name
510
+ }
511
+ orderInventories {
512
+ product {
513
+ sku
514
+ name
515
+ description
516
+ }
517
+ batchId
518
+ packingType
519
+ packingSize
520
+ releaseQty
521
+ releaseUomValue
522
+ }
523
+ orderVass {
524
+ vas {
525
+ name
526
+ operationGuide
527
+ operationGuideType
528
+ }
529
+ set
530
+ targetType
531
+ targetBatchId
532
+ targetProduct {
533
+ name
534
+ description
535
+ }
536
+ packingType
537
+ qty
538
+ uomValue
539
+ otherTarget
540
+ description
541
+ remark
542
+ status
543
+ operationGuide
544
+ }
545
+ }
546
+ }
547
+ `,
548
+ variables: {
549
+ releaseGood: {
550
+ customerBizplaceId: customerBizplace.id,
551
+ courierOption: bodyReq.courierOption,
552
+ collectionOrderNo: bodyReq.collectionOrderNo,
553
+ exportOption: bodyReq.exportOption,
554
+ orderInventories: finalOrderInventories,
555
+ ownTransport: bodyReq.ownTransport,
556
+ packingOption: bodyReq.packingOption,
557
+ refNo: bodyReq.refNo,
558
+ refNo2: bodyReq?.refNo2,
559
+ releaseDate: bodyReq.releaseDate,
560
+ type: bodyReq.type,
561
+ marketplaceOrderStatus: bodyReq?.marketplaceOrderStatus,
562
+ remark: bodyReq?.remark || null,
563
+ billingAddress: bodyReq?.billTo?.billingAddress || null,
564
+ deliveryAddress1: bodyReq?.deliverTo?.deliveryAddress1 || null,
565
+ deliveryAddress2: bodyReq?.deliverTo?.deliveryAddress2 || null,
566
+ deliveryAddress3: bodyReq?.deliverTo?.deliveryAddress3 || null,
567
+ deliveryAddress4: bodyReq?.deliverTo?.deliveryAddress4 || null,
568
+ deliveryAddress5: bodyReq?.deliverTo?.deliveryAddress5 || null,
569
+ attentionTo: bodyReq?.deliverTo?.attentionTo || null,
570
+ attentionCompany: bodyReq?.deliverTo?.attentionCompany || null,
571
+ city: bodyReq?.deliverTo?.city || null,
572
+ state: bodyReq?.deliverTo?.state || null,
573
+ postalCode: bodyReq?.deliverTo?.postalCode || null,
574
+ country: bodyReq?.deliverTo?.country || null,
575
+ phone1: bodyReq?.deliverTo?.phone1 || null,
576
+ phone2: bodyReq?.deliverTo?.phone2 || null,
577
+ email: bodyReq?.deliverTo?.email || null,
578
+ transporter: bodyReq?.transporter,
579
+ trackingNo: bodyReq?.trackingNo,
580
+ airwayBill: bodyReq?.airwayBill,
581
+ invoice: bodyReq?.invoice,
582
+ bundleInfo: JSON.stringify(bundleInfo),
583
+ storeName: bodyReq?.storeName,
584
+ storeId: bodyReq?.storeId,
585
+ routeId: bodyReq?.routeId,
586
+ stopId: bodyReq?.stopId
587
+ }
588
+ },
589
+ context: {
590
+ ...context,
591
+ hasUpload: true,
592
+ state: {
593
+ ...context.state,
594
+ customerBizplace,
595
+ domain,
596
+ type: 'api'
597
+ }
598
+ }
599
+ } as any)
600
+ ).data
742
601
  }
743
602
  })
744
603
  }
@@ -805,7 +664,7 @@ export function _composeTargetInventories(context, product, record, inventories)
805
664
  })
806
665
 
807
666
  if (totalInventoryQty < record.releaseQty) {
808
- context.throw(404, t(`error.invalid release qty for ${product?.sku}`)) //
667
+ context.throw(404, t(`error.invalid release qty for ${product?.sku}`))
809
668
  }
810
669
 
811
670
  let targetInventories = []
@@ -871,93 +730,3 @@ function combineItems(inventoryList) {
871
730
 
872
731
  return mappedList
873
732
  }
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
- }