@things-factory/operato-hub 4.3.30 → 4.3.31

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/operato-hub",
3
- "version": "4.3.30",
3
+ "version": "4.3.31",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -78,19 +78,19 @@
78
78
  "@things-factory/import-ui": "^4.3.27",
79
79
  "@things-factory/import-ui-excel": "^4.3.27",
80
80
  "@things-factory/integration-accounting": "^4.3.27",
81
- "@things-factory/integration-fulfillment": "^4.3.30",
81
+ "@things-factory/integration-fulfillment": "^4.3.31",
82
82
  "@things-factory/integration-lmd": "^4.3.27",
83
83
  "@things-factory/integration-marketplace": "^4.3.29",
84
84
  "@things-factory/integration-pos": "^4.3.27",
85
85
  "@things-factory/integration-sellercraft": "^4.3.29",
86
- "@things-factory/integration-sftp": "^4.3.30",
86
+ "@things-factory/integration-sftp": "^4.3.31",
87
87
  "@things-factory/lite-menu": "^4.3.27",
88
88
  "@things-factory/more-ui": "^4.3.27",
89
89
  "@things-factory/notification": "^4.3.27",
90
90
  "@things-factory/pdf": "^4.3.27",
91
91
  "@things-factory/product-ui": "^4.3.27",
92
92
  "@things-factory/resource-ui": "^4.3.27",
93
- "@things-factory/sales-base": "^4.3.30",
93
+ "@things-factory/sales-base": "^4.3.31",
94
94
  "@things-factory/scene-data-transform": "^4.3.27",
95
95
  "@things-factory/scene-excel": "^4.3.27",
96
96
  "@things-factory/scene-firebase": "^4.3.27",
@@ -105,8 +105,8 @@
105
105
  "@things-factory/setting-ui": "^4.3.27",
106
106
  "@things-factory/shell": "^4.3.27",
107
107
  "@things-factory/system-ui": "^4.3.27",
108
- "@things-factory/warehouse-base": "^4.3.30",
109
- "@things-factory/worksheet-base": "^4.3.30",
108
+ "@things-factory/warehouse-base": "^4.3.31",
109
+ "@things-factory/worksheet-base": "^4.3.31",
110
110
  "koa2-swagger-ui": "^5.0.2",
111
111
  "swagger-jsdoc": "^5.0.0",
112
112
  "yamljs": "^0.3.0"
@@ -117,5 +117,5 @@
117
117
  "resolutions": {
118
118
  "core-js": "^3.16.0"
119
119
  },
120
- "gitHead": "087f169ad0ea9e85186350b5870d8ae25725392d"
120
+ "gitHead": "fe90b785970aafd08592c0692df9879fb48b6b84"
121
121
  }
@@ -12,6 +12,8 @@ import { MarketplaceOrder } from '@things-factory/marketplace-base'
12
12
  import { ProductBundle, ProductDetail } from '@things-factory/product-base'
13
13
  import {
14
14
  createDraftReleaseGoodFunction,
15
+ DRAFT_RELEASE_ORDER_STATUS,
16
+ DraftReleaseGood,
15
17
  ORDER_INVENTORY_STATUS,
16
18
  ORDER_NUMBER_RULE_TYPE,
17
19
  ORDER_NUMBER_SETTING_KEY,
@@ -62,7 +64,8 @@ router.post(
62
64
  // get customer company's bizplace
63
65
  const custCompanyBizplace: Bizplace = await getCompanyBizplace(null, null, customerBizplaceId, tx)
64
66
  const customerBizplace: Bizplace = await tx.getRepository(Bizplace).findOne({
65
- where: { id: customerBizplaceId }
67
+ where: { id: customerBizplaceId },
68
+ relations: ['domain']
66
69
  })
67
70
 
68
71
  releaseGood = {
@@ -174,6 +177,18 @@ router.post(
174
177
  let result = await createReleaseGood(releaseGood, assignedOrderProducts, customerBizplace, context, tx)
175
178
  console.timeEnd('save')
176
179
 
180
+ const sellercraft: Sellercraft = await tx
181
+ .getRepository(Sellercraft)
182
+ .findOne({ domain: customerBizplace.domain })
183
+
184
+ if (sellercraft) {
185
+ const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
186
+ await sellercraftCtrl.packOrder(sellercraft, {
187
+ ...result,
188
+ orderProducts: result.orderProducts
189
+ })
190
+ }
191
+
177
192
  let addReleaseGood = {
178
193
  id: result.id,
179
194
  name: result.name,
@@ -217,7 +232,8 @@ router.post(
217
232
  orderInventories: result.orderInventories
218
233
  }
219
234
  // return body
220
- context.body = { result: addReleaseGood }
235
+ context.body = { result: { addReleaseGood } }
236
+
221
237
  createPayloadLog(
222
238
  customerBizplaceId,
223
239
  `/${apiVersion}/warehouse/:warehouseId/add-release-order`,
@@ -298,14 +314,35 @@ async function checkMandatoryKey(context, params) {
298
314
 
299
315
  async function checkExistingOrder(releaseGood, bizplace, context, tx) {
300
316
  const { domain, user }: { domain: Domain; user: User } = context.state
317
+ const refNo: string = releaseGood.refNo
318
+ const refNo2: string = releaseGood.refNo2
319
+ const refNo3: string = releaseGood.refNo3
320
+
301
321
  if (releaseGood.type == 'b2c') {
322
+ const foundDraftReleaseGood: DraftReleaseGood = await tx.getRepository(DraftReleaseGood).findOne({
323
+ where: {
324
+ domain,
325
+ refNo: refNo || null,
326
+ refNo2: refNo2 || null,
327
+ refNo3: refNo3 || null,
328
+ status: Not(In([DRAFT_RELEASE_ORDER_STATUS.CANCELLED]))
329
+ }
330
+ })
331
+
332
+ if (foundDraftReleaseGood) {
333
+ throw new ValidationError({
334
+ errorCode: 'EXISTING_ORDER',
335
+ message: 'existing draft release order found',
336
+ detail: foundDraftReleaseGood.name
337
+ })
338
+ }
339
+
302
340
  const sellercraft: Sellercraft = await tx.getRepository(Sellercraft).findOne({ domain: bizplace.domain })
303
341
 
304
342
  if (sellercraft) {
305
343
  const sellercraftCtrl: SellercraftController = new SellercraftController(tx, bizplace.domain, user)
306
344
  await sellercraftCtrl.checkExistingReleaseGood(sellercraft, releaseGood)
307
345
  } else {
308
- const refNo: string = releaseGood.refNo
309
346
  const foundReleaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
310
347
  where: {
311
348
  domain: domain,
@@ -439,7 +476,7 @@ async function createReleaseGood(
439
476
 
440
477
  let resultReleaseGood = await tx.getRepository(ReleaseGood).save(newReleaseGood)
441
478
  let combinedOrderInventories: OrderInventory[] = []
442
- await Promise.all(
479
+ let savedOrderProducts = await Promise.all(
443
480
  orderProducts.map(async orderProduct => {
444
481
  let orderInventories: OrderInventory[] = orderProduct.orderInventories
445
482
  orderProduct = Object.assign(new OrderProduct(), {
@@ -451,7 +488,7 @@ async function createReleaseGood(
451
488
  type: ORDER_TYPES.RELEASE_OF_GOODS,
452
489
  status: ORDER_PRODUCT_STATUS.ASSIGNED
453
490
  })
454
- await tx.getRepository(OrderProduct).save(orderProduct)
491
+ let result = await tx.getRepository(OrderProduct).save(orderProduct)
455
492
 
456
493
  for (let oiIdx = 0; oiIdx < orderInventories.length; oiIdx++) {
457
494
  let orderInventory = Object.assign(new OrderInventory(), {
@@ -474,9 +511,12 @@ async function createReleaseGood(
474
511
  releaseUomValue: orderInventory.releaseUomValue
475
512
  })
476
513
  }
514
+
515
+ return result
477
516
  })
478
517
  )
479
518
 
519
+ newReleaseGood.orderProducts = savedOrderProducts
480
520
  newReleaseGood.orderInventories = combinedOrderInventories
481
521
 
482
522
  return newReleaseGood
@@ -508,7 +548,7 @@ async function massageOrderItems(
508
548
  refCode: refCode,
509
549
  packingType: packingType?.trim(),
510
550
  packingSize: packingSize,
511
- qty: releaseQty,
551
+ qty: releaseQty
512
552
  })
513
553
  )
514
554
  }
@@ -522,7 +562,7 @@ async function massageOrderItems(
522
562
  refCode: refCode,
523
563
  packingType: packingType?.trim(),
524
564
  packingSize: packingSize,
525
- qty: releaseQty,
565
+ qty: releaseQty
526
566
  })
527
567
  )
528
568
  }
@@ -869,7 +909,8 @@ async function assignToInventory(orderProducts: OrderProduct[], customerBizplace
869
909
  sum(qty - locked_qty - release_qty) over (order by sort_seq asc rows between unbounded preceding and current row) as lock_amount
870
910
  from (
871
911
  SELECT 0 as sort_seq, null as id, null as pallet_id, null as batch_id, null as batch_id_ref,
872
- null as unit, '${orderInventory.uom}' as uom, '${orderInventory.packingType}' as packing_type, '${orderInventory.packingSize
912
+ null as unit, '${orderInventory.uom}' as uom, '${orderInventory.packingType}' as packing_type, '${
913
+ orderInventory.packingSize
873
914
  }' as packing_size,
874
915
  null as manufacture_year, null as carton_id, 0 as uom_value, 0 as locked_uom_value, 0 as qty, 0 as locked_qty, null as created_at,
875
916
  '${orderInventory.releaseQty}' as release_qty, '${orderInventory.releaseUomValue}' as release_uom_value
@@ -3,7 +3,7 @@ import { getRepository } from 'typeorm'
3
3
 
4
4
  import { restfulApiRouter as router } from '@things-factory/api'
5
5
  import { Bizplace } from '@things-factory/biz-base'
6
- import { ReleaseGood } from '@things-factory/sales-base'
6
+ import { ReleaseGood, DraftReleaseGood } from '@things-factory/sales-base'
7
7
 
8
8
  import { businessMiddleware } from '../../../../middlewares/business-middleware'
9
9
  import { warehouseMiddleware } from '../../../../middlewares/warehouse-middleware'
@@ -32,7 +32,37 @@ router.post(
32
32
  where: [{ id: bodyReq.releaseOrderId }, { refNo: bodyReq.orderNo }]
33
33
  })
34
34
 
35
- if (!releaseOrder) context.throw(400, t('error.release order not exist'))
35
+ if (!releaseOrder) {
36
+ const draftReleaseOrder: DraftReleaseGood = await getRepository(DraftReleaseGood).findOne({
37
+ where: [{ refNo: bodyReq.orderNo }]
38
+ })
39
+ if (draftReleaseOrder) {
40
+ context.body = {
41
+ result: (
42
+ await client.mutate({
43
+ mutation: gql`
44
+ mutation cancelDraftReleaseOrder($name: String!) {
45
+ cancelDraftReleaseOrder(name: $name)
46
+ }
47
+ `,
48
+ variables: { name: draftReleaseOrder.name },
49
+ context: {
50
+ ...context,
51
+ state: {
52
+ ...context.state,
53
+ customerBizplace,
54
+ domain,
55
+ type: 'api'
56
+ }
57
+ }
58
+ } as any)
59
+ ).data
60
+ }
61
+ return
62
+ } else {
63
+ context.throw(400, t('error.release order not exist'))
64
+ }
65
+ }
36
66
 
37
67
  debug('post:/cancel-release-order body request', bodyReq)
38
68
 
@@ -3,7 +3,7 @@ import { getRepository } from 'typeorm'
3
3
 
4
4
  import { restfulApiRouter as router } from '@things-factory/api'
5
5
  import { Bizplace } from '@things-factory/biz-base'
6
- import { ReleaseGood } from '@things-factory/sales-base'
6
+ import { ReleaseGood, DraftReleaseGood } from '@things-factory/sales-base'
7
7
 
8
8
  import { businessMiddleware } from '../../../../middlewares/business-middleware'
9
9
  import { warehouseMiddleware } from '../../../../middlewares/warehouse-middleware'
@@ -32,7 +32,37 @@ router.post(
32
32
  where: [{ id: bodyReq.releaseOrderId }, { refNo: bodyReq.orderNo }]
33
33
  })
34
34
 
35
- if (!releaseOrder) context.throw(400, t('error.release order not exist'))
35
+ if (!releaseOrder) {
36
+ const draftReleaseOrder: DraftReleaseGood = await getRepository(DraftReleaseGood).findOne({
37
+ where: [{ refNo: bodyReq.orderNo }]
38
+ })
39
+ if (draftReleaseOrder) {
40
+ context.body = {
41
+ result: (
42
+ await client.mutate({
43
+ mutation: gql`
44
+ mutation cancelDraftReleaseOrder($name: String!) {
45
+ cancelDraftReleaseOrder(name: $name)
46
+ }
47
+ `,
48
+ variables: { name: draftReleaseOrder.name },
49
+ context: {
50
+ ...context,
51
+ state: {
52
+ ...context.state,
53
+ customerBizplace,
54
+ domain,
55
+ type: 'api'
56
+ }
57
+ }
58
+ } as any)
59
+ ).data
60
+ }
61
+ return
62
+ } else {
63
+ context.throw(400, t('error.release order not exist'))
64
+ }
65
+ }
36
66
 
37
67
  debug('post:/cancel-release-order body request', bodyReq)
38
68
 
@@ -3,7 +3,7 @@ import { getRepository } from 'typeorm'
3
3
 
4
4
  import { restfulApiRouter as router } from '@things-factory/api'
5
5
  import { Bizplace } from '@things-factory/biz-base'
6
- import { ReleaseGood } from '@things-factory/sales-base'
6
+ import { ReleaseGood, DraftReleaseGood } from '@things-factory/sales-base'
7
7
 
8
8
  import { businessMiddleware } from '../../../../middlewares/business-middleware'
9
9
  import { warehouseMiddleware } from '../../../../middlewares/warehouse-middleware'
@@ -32,7 +32,37 @@ router.post(
32
32
  where: [{ id: bodyReq.releaseOrderId }, { refNo: bodyReq.orderNo }]
33
33
  })
34
34
 
35
- if (!releaseOrder) context.throw(400, t('error.release order not exist'))
35
+ if (!releaseOrder) {
36
+ const draftReleaseOrder: DraftReleaseGood = await getRepository(DraftReleaseGood).findOne({
37
+ where: [{ refNo: bodyReq.orderNo }]
38
+ })
39
+ if (draftReleaseOrder) {
40
+ context.body = {
41
+ result: (
42
+ await client.mutate({
43
+ mutation: gql`
44
+ mutation cancelDraftReleaseOrder($name: String!) {
45
+ cancelDraftReleaseOrder(name: $name)
46
+ }
47
+ `,
48
+ variables: { name: draftReleaseOrder.name },
49
+ context: {
50
+ ...context,
51
+ state: {
52
+ ...context.state,
53
+ customerBizplace,
54
+ domain,
55
+ type: 'api'
56
+ }
57
+ }
58
+ } as any)
59
+ ).data
60
+ }
61
+ return
62
+ } else {
63
+ context.throw(400, t('error.release order not exist'))
64
+ }
65
+ }
36
66
 
37
67
  debug('post:/cancel-release-order body request', bodyReq)
38
68