@things-factory/worksheet-base 4.3.105-alpha.0 → 4.3.105

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 (79) hide show
  1. package/dist-server/controllers/inbound/unloading-worksheet-controller.js +72 -56
  2. package/dist-server/controllers/inbound/unloading-worksheet-controller.js.map +1 -1
  3. package/dist-server/controllers/inspect/cycle-count-worksheet-controller.js +4 -2
  4. package/dist-server/controllers/inspect/cycle-count-worksheet-controller.js.map +1 -1
  5. package/dist-server/controllers/outbound/loading-worksheet-controller.js +4 -10
  6. package/dist-server/controllers/outbound/loading-worksheet-controller.js.map +1 -1
  7. package/dist-server/controllers/outbound/packing-worksheet-controller.js +24 -33
  8. package/dist-server/controllers/outbound/packing-worksheet-controller.js.map +1 -1
  9. package/dist-server/controllers/outbound/picking-worksheet-controller.js +48 -78
  10. package/dist-server/controllers/outbound/picking-worksheet-controller.js.map +1 -1
  11. package/dist-server/controllers/outbound/sorting-worksheet-controller.js +14 -12
  12. package/dist-server/controllers/outbound/sorting-worksheet-controller.js.map +1 -1
  13. package/dist-server/controllers/vas/vas-worksheet-controller.js +2 -1
  14. package/dist-server/controllers/vas/vas-worksheet-controller.js.map +1 -1
  15. package/dist-server/controllers/worksheet-controller.js +8 -3
  16. package/dist-server/controllers/worksheet-controller.js.map +1 -1
  17. package/dist-server/entities/index.js +2 -3
  18. package/dist-server/entities/index.js.map +1 -1
  19. package/dist-server/entities/warehouse-bizplace-onhand-inventory.js +62 -29
  20. package/dist-server/entities/warehouse-bizplace-onhand-inventory.js.map +1 -1
  21. package/dist-server/graphql/resolvers/worksheet/batch-picking-worksheet.js +0 -6
  22. package/dist-server/graphql/resolvers/worksheet/batch-picking-worksheet.js.map +1 -1
  23. package/dist-server/graphql/resolvers/worksheet/confirm-cancellation-release-order.js +2 -1
  24. package/dist-server/graphql/resolvers/worksheet/confirm-cancellation-release-order.js.map +1 -1
  25. package/dist-server/graphql/resolvers/worksheet/cycle-count-adjustment.js +6 -6
  26. package/dist-server/graphql/resolvers/worksheet/cycle-count-adjustment.js.map +1 -1
  27. package/dist-server/graphql/resolvers/worksheet/inventories-by-pallet.js +1 -2
  28. package/dist-server/graphql/resolvers/worksheet/inventories-by-pallet.js.map +1 -1
  29. package/dist-server/graphql/resolvers/worksheet/packing/complete-packing.js +0 -61
  30. package/dist-server/graphql/resolvers/worksheet/packing/complete-packing.js.map +1 -1
  31. package/dist-server/graphql/resolvers/worksheet/packing-worksheet.js +1 -4
  32. package/dist-server/graphql/resolvers/worksheet/packing-worksheet.js.map +1 -1
  33. package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js +21 -1
  34. package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js.map +1 -1
  35. package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js +3 -1
  36. package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js.map +1 -1
  37. package/dist-server/graphql/resolvers/worksheet/picking-worksheet.js +2 -3
  38. package/dist-server/graphql/resolvers/worksheet/picking-worksheet.js.map +1 -1
  39. package/dist-server/graphql/resolvers/worksheet/transfer.js +9 -9
  40. package/dist-server/graphql/resolvers/worksheet/transfer.js.map +1 -1
  41. package/dist-server/graphql/resolvers/worksheet/unloaded-inventories.js +1 -1
  42. package/dist-server/graphql/resolvers/worksheet/unloaded-inventories.js.map +1 -1
  43. package/dist-server/graphql/resolvers/worksheet/vas-transactions/common-utils.js +17 -17
  44. package/dist-server/graphql/resolvers/worksheet/vas-transactions/common-utils.js.map +1 -1
  45. package/dist-server/graphql/resolvers/worksheet/worksheets.js +1 -1
  46. package/dist-server/graphql/resolvers/worksheet/worksheets.js.map +1 -1
  47. package/dist-server/graphql/resolvers/worksheet-detail/regenerate-release-good-worksheet-details.js +4 -4
  48. package/dist-server/graphql/resolvers/worksheet-detail/regenerate-release-good-worksheet-details.js.map +1 -1
  49. package/dist-server/graphql/types/worksheet-detail/index.js +0 -1
  50. package/dist-server/graphql/types/worksheet-detail/index.js.map +1 -1
  51. package/dist-server/utils/inventory-util.js +98 -1
  52. package/dist-server/utils/inventory-util.js.map +1 -1
  53. package/package.json +17 -17
  54. package/server/controllers/inbound/unloading-worksheet-controller.ts +85 -70
  55. package/server/controllers/inspect/cycle-count-worksheet-controller.ts +4 -2
  56. package/server/controllers/outbound/loading-worksheet-controller.ts +3 -9
  57. package/server/controllers/outbound/packing-worksheet-controller.ts +36 -41
  58. package/server/controllers/outbound/picking-worksheet-controller.ts +66 -98
  59. package/server/controllers/outbound/sorting-worksheet-controller.ts +12 -12
  60. package/server/controllers/vas/vas-worksheet-controller.ts +2 -2
  61. package/server/controllers/worksheet-controller.ts +23 -18
  62. package/server/entities/index.ts +2 -2
  63. package/server/entities/warehouse-bizplace-onhand-inventory.ts +63 -29
  64. package/server/graphql/resolvers/worksheet/batch-picking-worksheet.ts +0 -6
  65. package/server/graphql/resolvers/worksheet/confirm-cancellation-release-order.ts +2 -1
  66. package/server/graphql/resolvers/worksheet/cycle-count-adjustment.ts +2 -2
  67. package/server/graphql/resolvers/worksheet/inventories-by-pallet.ts +1 -3
  68. package/server/graphql/resolvers/worksheet/packing/complete-packing.ts +1 -69
  69. package/server/graphql/resolvers/worksheet/packing-worksheet.ts +2 -4
  70. package/server/graphql/resolvers/worksheet/picking/complete-batch-picking.ts +24 -1
  71. package/server/graphql/resolvers/worksheet/picking/complete-picking.ts +4 -1
  72. package/server/graphql/resolvers/worksheet/picking-worksheet.ts +2 -3
  73. package/server/graphql/resolvers/worksheet/transfer.ts +16 -18
  74. package/server/graphql/resolvers/worksheet/unloaded-inventories.ts +1 -1
  75. package/server/graphql/resolvers/worksheet/vas-transactions/common-utils.ts +2 -3
  76. package/server/graphql/resolvers/worksheet/worksheets.ts +1 -1
  77. package/server/graphql/resolvers/worksheet-detail/regenerate-release-good-worksheet-details.ts +1 -4
  78. package/server/graphql/types/worksheet-detail/index.ts +0 -1
  79. package/server/utils/inventory-util.ts +126 -1
@@ -32,7 +32,6 @@ export const batchPickingWorksheetResolver = {
32
32
  .addSelect('"PROD".name', 'productName')
33
33
  .addSelect('"PROD".sku', 'productSku')
34
34
  .addSelect('"PROD".description', 'productDescription')
35
- .addSelect('"PROD_DET".id', 'productDetailId')
36
35
  .addSelect('"INV".qty', 'qty')
37
36
  .addSelect('"INV".packing_type', 'packingType')
38
37
  .addSelect('"INV".packing_size', 'packingSize')
@@ -48,7 +47,6 @@ export const batchPickingWorksheetResolver = {
48
47
  .leftJoin('WSD.targetInventory', 'T_INV')
49
48
  .leftJoin('T_INV.inventory', 'INV')
50
49
  .leftJoin('T_INV.product', 'PROD')
51
- .leftJoin('T_INV.productDetail', 'PROD_DET')
52
50
  .leftJoin('T_INV.binLocation', 'BIN_LOC')
53
51
  .leftJoin('INV.location', 'LOC')
54
52
  .where('"WSD"."worksheet_id" = :worksheetId', { worksheetId: worksheet.id })
@@ -66,7 +64,6 @@ export const batchPickingWorksheetResolver = {
66
64
  .addGroupBy('"PROD".name')
67
65
  .addGroupBy('"PROD".sku')
68
66
  .addGroupBy('"PROD".description')
69
- .addGroupBy('"PROD_DET".id')
70
67
  .addGroupBy('"T_INV".batch_id')
71
68
  .addGroupBy('"T_INV".packing_type')
72
69
  .addGroupBy('BIN_LOC.name')
@@ -129,9 +126,6 @@ export const batchPickingWorksheetResolver = {
129
126
  name: item?.productName,
130
127
  description: item?.productDescription,
131
128
  sku: item?.productSku
132
- },
133
- productDetail: {
134
- id: item?.productDetailId
135
129
  }
136
130
  }
137
131
  }
@@ -11,9 +11,10 @@ import {
11
11
  ReleaseGood
12
12
  } from '@things-factory/sales-base'
13
13
  import { Domain } from '@things-factory/shell'
14
- import { Inventory, INVENTORY_STATUS, INVENTORY_TRANSACTION_TYPE, Location, generateInventoryHistory } from '@things-factory/warehouse-base'
14
+ import { Inventory, INVENTORY_STATUS, INVENTORY_TRANSACTION_TYPE, Location } from '@things-factory/warehouse-base'
15
15
 
16
16
  import { Worksheet, WorksheetDetail } from '../../../entities'
17
+ import { generateInventoryHistory } from '../../../utils'
17
18
 
18
19
  export const confirmCancellationReleaseOrder = {
19
20
  async confirmCancellationReleaseOrder(_: any, { name }, context: any) {
@@ -4,12 +4,12 @@ import { User } from '@things-factory/auth-base'
4
4
  import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
5
5
  import { InventoryCheck, ORDER_INVENTORY_STATUS, ORDER_STATUS, OrderInventory } from '@things-factory/sales-base'
6
6
  import { Domain } from '@things-factory/shell'
7
- import { Inventory, INVENTORY_STATUS, INVENTORY_TRANSACTION_TYPE, Location, generateInventoryHistory } from '@things-factory/warehouse-base'
7
+ import { Inventory, INVENTORY_STATUS, INVENTORY_TRANSACTION_TYPE, Location } from '@things-factory/warehouse-base'
8
8
 
9
9
  import { WORKSHEET_STATUS, WORKSHEET_TYPE } from '../../../constants'
10
10
  import { SellercraftController } from '../../../controllers'
11
11
  import { Worksheet, WorksheetDetail } from '../../../entities'
12
- import { switchLocationStatus } from '../../../utils'
12
+ import { generateInventoryHistory, switchLocationStatus } from '../../../utils'
13
13
 
14
14
  export const cycleCountAdjustmentResolver = {
15
15
  async cycleCountAdjustment(_: any, { cycleCountNo }, context: any) {
@@ -40,7 +40,6 @@ export const inventoriesByPalletResolver = {
40
40
  qb.leftJoinAndSelect('iv.domain', 'domain')
41
41
  .leftJoinAndSelect('iv.bizplace', 'bizplace')
42
42
  .leftJoinAndSelect('iv.product', 'product')
43
- .leftJoinAndSelect('iv.productDetail', 'productDetail')
44
43
  .leftJoinAndSelect('iv.warehouse', 'warehouse')
45
44
  .leftJoinAndSelect('iv.location', 'location')
46
45
  .leftJoinAndSelect('iv.creator', 'creator')
@@ -135,8 +134,7 @@ export const inventoriesByPalletResolver = {
135
134
  productName: item.product.name,
136
135
  productSKU: item.product.sku,
137
136
  productBrand: item.product.brand,
138
- productId: item.product.id,
139
- productDetailId: item.productDetail.id
137
+ productId: item.product.id
140
138
  }
141
139
  })
142
140
  )
@@ -1,14 +1,10 @@
1
1
  import { EntityManager } from 'typeorm'
2
2
 
3
- import { ApplicationType, User } from '@things-factory/auth-base'
3
+ import { User } from '@things-factory/auth-base'
4
4
  import { Bizplace, getMyBizplace } from '@things-factory/biz-base'
5
- import { MarketplaceStore } from '@things-factory/integration-marketplace'
6
- import { MarketplaceOrder } from '@things-factory/marketplace-base'
7
- import { ReleaseGood } from '@things-factory/sales-base'
8
5
  import { Domain } from '@things-factory/shell'
9
6
 
10
7
  import { PackingWorksheetController } from '../../../../controllers/'
11
- import { EcommerceController } from '../../../../controllers/ecommerce'
12
8
  import { WorksheetController } from '../../../../controllers/worksheet-controller'
13
9
 
14
10
  export const completePackingResolver = {
@@ -16,70 +12,6 @@ export const completePackingResolver = {
16
12
  const { tx, domain, user }: { tx: EntityManager; domain: Domain; user: User } = context.state
17
13
  await completePacking(tx, domain, user, releaseGoodNo)
18
14
 
19
- const releaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
20
- where: { domain, name: releaseGoodNo },
21
- relations: [
22
- 'bizplace',
23
- 'bizplace.domain',
24
- 'bizplace.company',
25
- 'bizplace.company.domain',
26
- 'orderInventories',
27
- 'orderInventories.product'
28
- ]
29
- })
30
-
31
- const orderSource: string = releaseGood.source
32
- switch (orderSource) {
33
- case ApplicationType.MMS:
34
- const companyDomain: Domain = releaseGood.bizplace.company.domain
35
- const marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
36
- where: { orderNo: releaseGood.refNo, domain: companyDomain },
37
- relations: [
38
- 'marketplaceOrderItems',
39
- 'marketplaceOrderItems.marketplaceOrderShippingItems',
40
- 'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping',
41
- 'marketplaceStore',
42
- 'marketplaceStore.marketplaceDistributors'
43
- ]
44
- })
45
- const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
46
-
47
- if (marketplaceStore.isAutoUpdateShipment) {
48
- const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
49
- await ecommerceCtrl.createOrderShip(releaseGood, marketplaceStore, marketplaceOrder, companyDomain)
50
- }
51
- break
52
-
53
- default:
54
- break
55
- }
56
-
57
- // if (releaseGood.type === 'b2c') {
58
- // const sellercraft: Sellercraft = await tx
59
- // .getRepository(Sellercraft)
60
- // .findOne({ domain: releaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE })
61
-
62
- // if (!sellercraft) {
63
- // const companyDomain: Domain = releaseGood.bizplace.company.domain
64
- // const marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
65
- // where: { orderNo: releaseGood.refNo, domain: companyDomain },
66
- // relations: [
67
- // 'marketplaceOrderItems',
68
- // 'marketplaceOrderItems.marketplaceOrderShippingItems',
69
- // 'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping',
70
- // 'marketplaceStore',
71
- // 'marketplaceStore.marketplaceDistributors'
72
- // ]
73
- // })
74
- // const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
75
-
76
- // if (marketplaceStore.isAutoUpdateShipment) {
77
- // const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
78
- // await ecommerceCtrl.createOrderShip(releaseGood, marketplaceStore, marketplaceOrder, companyDomain)
79
- // }
80
- // }
81
- // }
82
-
83
15
  const bizplace: Bizplace = await getMyBizplace(domain, user)
84
16
  const worksheetController: WorksheetController = new WorksheetController(tx, domain, user)
85
17
  await worksheetController.notifyToCustomer(bizplace, {
@@ -14,7 +14,7 @@ import { PartnerSetting, Setting } from '@things-factory/setting-base'
14
14
  import { Domain } from '@things-factory/shell'
15
15
  import { Inventory, Location } from '@things-factory/warehouse-base'
16
16
 
17
- import { WORKSHEET_TYPE, WORKSHEET_STATUS } from '../../../constants'
17
+ import { WORKSHEET_TYPE } from '../../../constants'
18
18
  import { PackingWorksheetController, SellercraftController } from '../../../controllers'
19
19
  import { Worksheet, WorksheetDetail } from '../../../entities'
20
20
 
@@ -104,9 +104,7 @@ export const packingWorksheetResolver = {
104
104
 
105
105
  if (!worksheet) throw new Error('Worksheet does not exist')
106
106
 
107
- if (worksheet.status === WORKSHEET_STATUS.DONE) {
108
- throw new Error(`Worksheet is completed already`)
109
- } else if (worksheet.status === WORKSHEET_STATUS.DEACTIVATED) {
107
+ if (worksheet.status === 'DEACTIVATED') {
110
108
  const packingWSCtrl: PackingWorksheetController = new PackingWorksheetController(tx, domain, user)
111
109
 
112
110
  const directActivatePackingWorksheet: Setting = await tx.getRepository(Setting).findOne({
@@ -2,7 +2,9 @@ import { EntityManager } from 'typeorm'
2
2
 
3
3
  import { ApplicationType, User } from '@things-factory/auth-base'
4
4
  import { Bizplace, getMyBizplace } from '@things-factory/biz-base'
5
+ import { MarketplaceStore } from '@things-factory/integration-marketplace'
5
6
  import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
7
+ import { MarketplaceOrder } from '@things-factory/marketplace-base'
6
8
  import { OrderInventory, ReleaseGood } from '@things-factory/sales-base'
7
9
  import { Domain } from '@things-factory/shell'
8
10
 
@@ -12,6 +14,7 @@ import {
12
14
  SellercraftController,
13
15
  SortingWorksheetController
14
16
  } from '../../../../controllers/'
17
+ import { EcommerceController } from '../../../../controllers/ecommerce'
15
18
  import { WorksheetController } from '../../../../controllers/worksheet-controller'
16
19
  import { Worksheet, WorksheetDetail } from '../../../../entities'
17
20
 
@@ -62,7 +65,7 @@ export async function completeBatchPicking(
62
65
  uniqueReleaseGoods.map(async releaseGood => {
63
66
  let foundReleaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
64
67
  where: { id: releaseGood.id },
65
- relations: ['orderProducts', 'orderProducts.product']
68
+ relations: ['orderProducts', 'orderProducts.product', 'bizplace', 'bizplace.company', 'bizplace.company.domain']
66
69
  })
67
70
  const orderSource: string = foundReleaseGood.source
68
71
  switch (orderSource) {
@@ -89,6 +92,26 @@ export async function completeBatchPicking(
89
92
  }
90
93
  break
91
94
 
95
+ case ApplicationType.MMS:
96
+ const companyDomain: Domain = releaseGood.bizplace.company.domain
97
+ const marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
98
+ where: { orderNo: releaseGood.refNo, domain: companyDomain },
99
+ relations: [
100
+ 'marketplaceOrderItems',
101
+ 'marketplaceOrderItems.marketplaceOrderShippingItems',
102
+ 'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping',
103
+ 'marketplaceStore',
104
+ 'marketplaceStore.marketplaceDistributors'
105
+ ]
106
+ })
107
+ const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
108
+
109
+ if (marketplaceStore?.isAutoUpdateShipment) {
110
+ const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
111
+ await ecommerceCtrl.createOrderShip(releaseGood, marketplaceStore, marketplaceOrder, companyDomain)
112
+ }
113
+ break
114
+
92
115
  default:
93
116
  break
94
117
  }
@@ -120,6 +120,7 @@ export async function completePicking(
120
120
  where: { orderNo: releaseGood.refNo, domain: companyDomain },
121
121
  relations: [
122
122
  'marketplaceStore',
123
+ 'marketplaceStore.marketplaceDistributors',
123
124
  'marketplaceOrderItems',
124
125
  'marketplaceOrderItems.marketplaceOrderShippingItems',
125
126
  'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping'
@@ -130,9 +131,11 @@ export async function completePicking(
130
131
  const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
131
132
  let eTraxOption: boolean
132
133
 
133
- if (marketplaceStore.isAutoUpdateShipment) {
134
+ if (marketplaceStore?.isAutoUpdateShipment) {
134
135
  const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
135
136
  await ecommerceCtrl.createOrderComment(marketplaceStore, marketplaceOrder, ORDER_STATUS.PACKING)
137
+
138
+ await ecommerceCtrl.createOrderShip(releaseGood, marketplaceStore, marketplaceOrder, companyDomain)
136
139
  }
137
140
 
138
141
  if (!marketplaceOrder)
@@ -76,7 +76,6 @@ export async function pickingWorksheet(
76
76
  .leftJoinAndSelect('T_INV.binLocation', 'BIN_LOC')
77
77
  .leftJoinAndSelect('T_INV.inventory', 'INV')
78
78
  .leftJoinAndSelect('T_INV.product', 'PROD')
79
- .leftJoinAndSelect('T_INV.productDetail', 'PROD_DET')
80
79
  .leftJoinAndSelect('INV.location', 'LOC')
81
80
 
82
81
  if (locationSortingRules?.length > 0) {
@@ -115,8 +114,8 @@ export async function pickingWorksheet(
115
114
  const inventoryChangesCount: number = await tx.getRepository(InventoryChange).count({
116
115
  where: {
117
116
  inventory: inventory.id,
118
- status: 'PENDING',
119
- transactionType: 'MISSING'
117
+ status: "PENDING",
118
+ transactionType: "MISSING"
120
119
  },
121
120
  relations: ['inventory', 'product']
122
121
  })
@@ -1,36 +1,38 @@
1
- import { EntityManager } from 'typeorm'
2
-
3
1
  import { User } from '@things-factory/auth-base'
4
2
  import { Bizplace } from '@things-factory/biz-base'
5
- import { ORDER_PRODUCT_STATUS, OrderInventory } from '@things-factory/sales-base'
6
3
  import { Domain } from '@things-factory/shell'
4
+ import { OrderInventory, ORDER_PRODUCT_STATUS } from '@things-factory/sales-base'
7
5
  import {
8
6
  Inventory,
9
- INVENTORY_STATUS,
10
- INVENTORY_TRANSACTION_TYPE,
11
7
  InventoryHistory,
12
- InventoryNoGenerator
8
+ InventoryNoGenerator,
9
+ INVENTORY_STATUS,
10
+ INVENTORY_TRANSACTION_TYPE
13
11
  } from '@things-factory/warehouse-base'
14
-
12
+ import { EntityManager } from 'typeorm'
15
13
  import { WORKSHEET_STATUS, WORKSHEET_TYPE } from '../../../constants'
16
14
  import { Worksheet, WorksheetDetail } from '../../../entities'
17
15
 
18
16
  export const transfer = {
19
17
  async transfer(_: any, { palletId, toPalletId, qty }, context: any) {
20
- const { tx, domain, bizplace, user }: { tx: EntityManager; domain: Domain; bizplace: Bizplace; user: User } =
21
- context.state
18
+ const {
19
+ tx,
20
+ domain,
21
+ bizplace,
22
+ user
23
+ }: { tx: EntityManager; domain: Domain; bizplace: Bizplace; user: User } = context.state
22
24
 
23
25
  // 1. get to inventory
24
26
  let toInventory: Inventory = await tx.getRepository(Inventory).findOne({
25
27
  where: { domain: domain, palletId: toPalletId },
26
- relations: ['bizplace', 'product', 'productDetail', 'warehouse', 'location']
28
+ relations: ['bizplace', 'product', 'warehouse', 'location']
27
29
  })
28
30
  if (!toInventory) throw new Error(`to pallet doesn't exists`)
29
31
 
30
32
  // 2. get from inventory
31
33
  let fromInventory: Inventory = await tx.getRepository(Inventory).findOne({
32
34
  where: { domain: domain, palletId },
33
- relations: ['bizplace', 'product', 'productDetail', 'warehouse', 'location']
35
+ relations: ['bizplace', 'product', 'warehouse', 'location']
34
36
  })
35
37
  if (!fromInventory) throw new Error(`from pallet doesn't exists`)
36
38
  if (toInventory.batchId !== fromInventory.batchId) throw new Error(`Can't transfer to different batch`)
@@ -72,7 +74,6 @@ export const transfer = {
72
74
  domain: domain,
73
75
  name: InventoryNoGenerator.inventoryHistoryName(),
74
76
  product: toInventory.product,
75
- productDetail: toInventory.productDetail,
76
77
  warehouse: toInventory.warehouse,
77
78
  location: toInventory.location,
78
79
  seq: toInventory.lastSeq,
@@ -96,7 +97,7 @@ export const transfer = {
96
97
 
97
98
  fromInventory = await tx.getRepository(Inventory).findOne({
98
99
  where: { id: fromInventory.id },
99
- relations: ['bizplace', 'product', 'productDetail', 'warehouse', 'location']
100
+ relations: ['bizplace', 'product', 'warehouse', 'location']
100
101
  })
101
102
 
102
103
  // - add inventory history
@@ -104,7 +105,6 @@ export const transfer = {
104
105
  ...fromInventory,
105
106
  name: InventoryNoGenerator.inventoryHistoryName(),
106
107
  product: fromInventory.product,
107
- productDetail: fromInventory.productDetail,
108
108
  warehouse: fromInventory.warehouse,
109
109
  location: fromInventory.location,
110
110
  seq: fromInventory.lastSeq,
@@ -131,7 +131,7 @@ export const transfer = {
131
131
 
132
132
  toInventory = await tx.getRepository(Inventory).findOne({
133
133
  where: { id: toInventory.id },
134
- relations: ['bizplace', 'product', 'productDetail', 'warehouse', 'location']
134
+ relations: ['bizplace', 'product', 'warehouse', 'location']
135
135
  })
136
136
  // - add inventory history
137
137
  delete toInventory.id
@@ -140,7 +140,6 @@ export const transfer = {
140
140
  domain,
141
141
  name: InventoryNoGenerator.inventoryHistoryName(),
142
142
  product: toInventory.product,
143
- productDetail: toInventory.productDetail,
144
143
  warehouse: toInventory.warehouse,
145
144
  location: toInventory.location,
146
145
  seq: toInventory.lastSeq,
@@ -158,7 +157,7 @@ export const transfer = {
158
157
 
159
158
  fromInventory = await tx.getRepository(Inventory).findOne({
160
159
  where: { id: fromInventory.id },
161
- relations: ['bizplace', 'product', 'productDetail', 'warehouse', 'location']
160
+ relations: ['bizplace', 'product', 'warehouse', 'location']
162
161
  })
163
162
 
164
163
  // - add inventory history
@@ -166,7 +165,6 @@ export const transfer = {
166
165
  ...fromInventory,
167
166
  name: InventoryNoGenerator.inventoryHistoryName(),
168
167
  product: fromInventory.product,
169
- productDetail: fromInventory.productDetail,
170
168
  warehouse: fromInventory.warehouse,
171
169
  location: fromInventory.location,
172
170
  seq: fromInventory.lastSeq,
@@ -44,7 +44,7 @@ export const unloadedInventories = {
44
44
  orderProductId: In(foundWorksheetDetails.map(wsd => wsd.targetProduct.id)),
45
45
  status: In([INVENTORY_STATUS.UNLOADED, INVENTORY_STATUS.CHECKED])
46
46
  },
47
- relations: ['reusablePallet', 'product', 'bizplace', 'inventoryItems']
47
+ relations: ['reusablePallet', 'product', 'bizplace']
48
48
  })
49
49
  const items = foundInv.map((inv: Inventory) => {
50
50
  const expirationDate: Date = inv.expirationDate ? new Date(inv.expirationDate) : null
@@ -19,13 +19,12 @@ import {
19
19
  InventoryNoGenerator,
20
20
  Location,
21
21
  Pallet,
22
- Warehouse,
23
- generateInventoryHistory
22
+ Warehouse
24
23
  } from '@things-factory/warehouse-base'
25
24
 
26
25
  import { WORKSHEET_STATUS, WORKSHEET_TYPE } from '../../../../constants'
27
26
  import { Worksheet, WorksheetDetail } from '../../../../entities'
28
- import { WorksheetNoGenerator } from '../../../../utils'
27
+ import { generateInventoryHistory, WorksheetNoGenerator } from '../../../../utils'
29
28
  import {
30
29
  OperationGuideInterface,
31
30
  PackingUnits,
@@ -242,7 +242,7 @@ export const worksheetsResolver = {
242
242
  params.filters.findIndex(item => item.name == 'executionDate'),
243
243
  1
244
244
  )
245
- arrFilters.push({ ...executionDateParam, name: 'executionDate' })
245
+ arrFilters.push({ ...releaseGoodRefNoParam, name: 'refNo' })
246
246
  }
247
247
  const foundInventoryCheck: InventoryCheck[] = await getRepository(InventoryCheck).find({
248
248
  ...convertListParams({ filters: arrFilters })
@@ -19,7 +19,7 @@ import { WorksheetNoGenerator } from '../../../utils'
19
19
  export const regenerateReleaseGoodWorksheetDetailsResolver = {
20
20
  async regenerateReleaseGoodWorksheetDetails(
21
21
  _: any,
22
- { worksheetNo, batchId, productId, productDetailId, packingType, packingSize, orderProductId, worksheetDetails },
22
+ { worksheetNo, batchId, productId, packingType, packingSize, orderProductId, worksheetDetails },
23
23
  context: any
24
24
  ): Promise<void> {
25
25
  const { tx, domain, user }: { tx: EntityManager; domain: Domain; user: User } = context.state
@@ -30,7 +30,6 @@ export const regenerateReleaseGoodWorksheetDetailsResolver = {
30
30
  worksheetNo,
31
31
  batchId,
32
32
  productId,
33
- productDetailId,
34
33
  packingType,
35
34
  packingSize,
36
35
  orderProductId,
@@ -46,7 +45,6 @@ export async function regenerateReleaseGoodWorksheetDetails(
46
45
  worksheetNo: string,
47
46
  batchId: string,
48
47
  productId: string,
49
- productDetailId: string,
50
48
  packingType: string,
51
49
  packingSize: number,
52
50
  orderProductId: string,
@@ -117,7 +115,6 @@ export async function regenerateReleaseGoodWorksheetDetails(
117
115
  batchIdRef: inventory.batchIdRef,
118
116
  status: ORDER_INVENTORY_STATUS.READY_TO_PICK,
119
117
  product: await tx.getRepository(Product).findOne(productId),
120
- productDetail: productDetailId,
121
118
  packingType,
122
119
  packingSize,
123
120
  orderProduct: targetProduct,
@@ -32,7 +32,6 @@ export const Mutation = /* GraphQL */ `
32
32
  worksheetNo: String!
33
33
  batchId: String!
34
34
  productId: String!
35
- productDetailId: String!
36
35
  packingType: String!
37
36
  packingSize: Float!
38
37
  orderProductId: String!
@@ -4,9 +4,134 @@ import { User } from '@things-factory/auth-base'
4
4
  import { Bizplace } from '@things-factory/biz-base'
5
5
  import { Product } from '@things-factory/product-base'
6
6
  import { Domain } from '@things-factory/shell'
7
- import { Inventory, INVENTORY_STATUS, Location, LOCATION_STATUS, LOCATION_TYPE } from '@things-factory/warehouse-base'
7
+ import {
8
+ Inventory,
9
+ INVENTORY_STATUS,
10
+ InventoryHistory,
11
+ InventoryNoGenerator,
12
+ Location,
13
+ LOCATION_STATUS,
14
+ LOCATION_TYPE
15
+ } from '@things-factory/warehouse-base'
8
16
 
9
17
  /**
18
+ * @description It will insert new record into inventory histories table.
19
+ * seq will be calculated based on number of records for one specific pallet id (provided by inventory object)
20
+ */
21
+ export async function generateInventoryHistory(
22
+ inventory: Inventory,
23
+ refOrder: any,
24
+ transactionType: string,
25
+ qty: number = 0,
26
+ uomValue: number = 0,
27
+ user: User,
28
+ trxMgr?: EntityManager,
29
+ targetInventory: Inventory = {}
30
+ ): Promise<InventoryHistory> {
31
+ const invHistoryRepo: Repository<InventoryHistory> =
32
+ trxMgr?.getRepository(InventoryHistory) || getRepository(InventoryHistory)
33
+ const invRepo: Repository<Inventory> = trxMgr?.getRepository(Inventory) || getRepository(Inventory)
34
+
35
+ if (!inventory?.id) throw new Error(`Can't find out ID of inventory.`)
36
+ if (!refOrder?.id || !refOrder.name) throw new Error(`Can't find out ID or Name of Reference Order`)
37
+ if (
38
+ !inventory?.domain ||
39
+ !inventory?.bizplace ||
40
+ !inventory?.product?.id ||
41
+ !inventory?.warehouse?.id ||
42
+ !inventory?.location?.id
43
+ ) {
44
+ inventory = await invRepo.findOne({
45
+ where: { id: inventory.id },
46
+ relations: ['domain', 'bizplace', 'product', 'warehouse', 'location']
47
+ })
48
+ }
49
+
50
+ const domain: Domain = inventory.domain
51
+ const location: Location = inventory.location
52
+
53
+ const seq: number = await invHistoryRepo.count({ domain: inventory.domain, palletId: inventory.palletId })
54
+ let openingQty: number = 0
55
+ let openingUomValue: number = 0
56
+
57
+ if (seq) {
58
+ const lastInvHistory: InventoryHistory = await invHistoryRepo.findOne({
59
+ domain: inventory.domain,
60
+ palletId: inventory.palletId,
61
+ seq: seq - 1
62
+ })
63
+
64
+ openingQty = lastInvHistory.openingQty + lastInvHistory.qty
65
+ openingUomValue = lastInvHistory.openingUomValue + lastInvHistory.uomValue
66
+ }
67
+
68
+ if (transactionType == 'PICKING' || transactionType == 'UNLOADING') {
69
+ const [findSameOrderHistory, total]: InventoryHistory = await invHistoryRepo.findAndCount({
70
+ domain: inventory.domain,
71
+ palletId: inventory.palletId,
72
+ refOrderId: refOrder.id
73
+ })
74
+
75
+ if (findSameOrderHistory) {
76
+ let prevTotalQty = 0
77
+ let prevTotalUomValue = 0
78
+ for (let oh of findSameOrderHistory) {
79
+ prevTotalQty += oh.qty
80
+ prevTotalUomValue += oh.uomValue
81
+ }
82
+ qty -= prevTotalQty
83
+ uomValue -= prevTotalUomValue
84
+ }
85
+ }
86
+
87
+ let inventoryHistory: InventoryHistory = new InventoryHistory()
88
+ inventoryHistory.name = InventoryNoGenerator.inventoryHistoryName()
89
+ inventoryHistory.description = inventory.description
90
+ inventoryHistory.seq = seq
91
+ inventoryHistory.palletId = inventory.palletId
92
+ inventoryHistory.cartonId = inventory.cartonId
93
+ inventoryHistory.batchId = inventory.batchId
94
+ inventoryHistory.batchIdRef = inventory.batchIdRef
95
+ inventoryHistory.status = inventory.status
96
+ inventoryHistory.transactionType = transactionType
97
+ inventoryHistory.refOrderId = refOrder?.id || null
98
+ inventoryHistory.orderNo = refOrder?.name || null
99
+ inventoryHistory.orderRefNo = refOrder?.refNo || null
100
+ inventoryHistory.inventory = inventory
101
+ inventoryHistory.targetInventory = targetInventory
102
+ inventoryHistory.product = inventory.product
103
+ inventoryHistory.reusablePallet = inventory.reusablePallet
104
+ inventoryHistory.zone = inventory.zone
105
+ inventoryHistory.warehouse = inventory.warehouse
106
+ inventoryHistory.location = inventory.location
107
+ inventoryHistory.expirationDate = inventory.expirationDate
108
+ inventoryHistory.packingType = inventory.packingType
109
+ inventoryHistory.packingSize = inventory.packingSize
110
+ inventoryHistory.uom = inventory.uom
111
+ inventoryHistory.qty = qty
112
+ inventoryHistory.openingQty = openingQty
113
+ inventoryHistory.uomValue = uomValue
114
+ inventoryHistory.openingUomValue = openingUomValue
115
+ inventoryHistory.unitCost = inventory.unitCost
116
+ inventoryHistory.domain = inventory.domain
117
+ inventoryHistory.bizplace = inventory.bizplace
118
+ inventoryHistory.creator = user
119
+ inventoryHistory.updater = user
120
+
121
+ inventoryHistory = await invHistoryRepo.save(inventoryHistory)
122
+
123
+ if (inventory.lastSeq !== seq) {
124
+ await invRepo.save({
125
+ id: inventory.id,
126
+ lastSeq: inventoryHistory.seq,
127
+ updater: user
128
+ })
129
+ }
130
+
131
+ await switchLocationStatus(domain, location, user, trxMgr)
132
+ return inventoryHistory
133
+ }
134
+
10
135
  /**
11
136
  * @description: Check location emptiness and update status of location
12
137
  * @param domain