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