@things-factory/worksheet-base 4.3.88 → 4.3.94-alpha.1
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/dist-server/controllers/ecommerce/ecommerce-controller.js +1 -1
- package/dist-server/controllers/ecommerce/ecommerce-controller.js.map +1 -1
- package/dist-server/controllers/inbound/unloading-worksheet-controller.js +87 -71
- package/dist-server/controllers/inbound/unloading-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/inspect/cycle-count-worksheet-controller.js +2 -4
- package/dist-server/controllers/inspect/cycle-count-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/outbound/loading-worksheet-controller.js +10 -4
- package/dist-server/controllers/outbound/loading-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/outbound/packing-worksheet-controller.js +47 -33
- package/dist-server/controllers/outbound/packing-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/outbound/picking-worksheet-controller.js +78 -48
- package/dist-server/controllers/outbound/picking-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/outbound/sorting-worksheet-controller.js +12 -14
- package/dist-server/controllers/outbound/sorting-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/vas/vas-worksheet-controller.js +1 -2
- package/dist-server/controllers/vas/vas-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/worksheet-controller.js +3 -8
- package/dist-server/controllers/worksheet-controller.js.map +1 -1
- package/dist-server/entities/index.js +3 -2
- package/dist-server/entities/index.js.map +1 -1
- package/dist-server/entities/warehouse-bizplace-onhand-inventory.js +29 -62
- package/dist-server/entities/warehouse-bizplace-onhand-inventory.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/batch-picking-worksheet.js +6 -0
- package/dist-server/graphql/resolvers/worksheet/batch-picking-worksheet.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/confirm-cancellation-release-order.js +1 -2
- package/dist-server/graphql/resolvers/worksheet/confirm-cancellation-release-order.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/cycle-count-adjustment.js +6 -6
- package/dist-server/graphql/resolvers/worksheet/cycle-count-adjustment.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/delivery-order-by-worksheet.js +7 -4
- package/dist-server/graphql/resolvers/worksheet/delivery-order-by-worksheet.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/inventories-by-pallet.js +2 -1
- package/dist-server/graphql/resolvers/worksheet/inventories-by-pallet.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/loading/complete-loading.js +67 -28
- package/dist-server/graphql/resolvers/worksheet/loading/complete-loading.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/packing/activate-packing.js +23 -8
- package/dist-server/graphql/resolvers/worksheet/packing/activate-packing.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/packing/complete-packing.js +30 -7
- package/dist-server/graphql/resolvers/worksheet/packing/complete-packing.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/packing/packing.js +23 -8
- package/dist-server/graphql/resolvers/worksheet/packing/packing.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/packing/scan-product-packing.js +25 -8
- package/dist-server/graphql/resolvers/worksheet/packing/scan-product-packing.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/packing-worksheet.js +60 -12
- package/dist-server/graphql/resolvers/worksheet/packing-worksheet.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking/activate-picking.js +51 -25
- package/dist-server/graphql/resolvers/worksheet/picking/activate-picking.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js +37 -29
- package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js +132 -118
- package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking-worksheet.js +3 -2
- package/dist-server/graphql/resolvers/worksheet/picking-worksheet.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/proceed-extra-products.js +6 -4
- package/dist-server/graphql/resolvers/worksheet/proceed-extra-products.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/putaway/complete-putaway.js +39 -14
- package/dist-server/graphql/resolvers/worksheet/putaway/complete-putaway.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/transfer.js +9 -9
- package/dist-server/graphql/resolvers/worksheet/transfer.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/vas-transactions/common-utils.js +17 -17
- package/dist-server/graphql/resolvers/worksheet/vas-transactions/common-utils.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet-detail/regenerate-release-good-worksheet-details.js +4 -4
- package/dist-server/graphql/resolvers/worksheet-detail/regenerate-release-good-worksheet-details.js.map +1 -1
- package/dist-server/graphql/types/worksheet/delivery-order-info.js +1 -0
- package/dist-server/graphql/types/worksheet/delivery-order-info.js.map +1 -1
- package/dist-server/graphql/types/worksheet-detail/index.js +1 -0
- package/dist-server/graphql/types/worksheet-detail/index.js.map +1 -1
- package/dist-server/utils/inventory-util.js +1 -98
- package/dist-server/utils/inventory-util.js.map +1 -1
- package/package.json +17 -17
- package/server/controllers/ecommerce/ecommerce-controller.ts +1 -1
- package/server/controllers/inbound/unloading-worksheet-controller.ts +102 -84
- package/server/controllers/inspect/cycle-count-worksheet-controller.ts +2 -4
- package/server/controllers/outbound/loading-worksheet-controller.ts +9 -3
- package/server/controllers/outbound/packing-worksheet-controller.ts +56 -45
- package/server/controllers/outbound/picking-worksheet-controller.ts +98 -66
- package/server/controllers/outbound/sorting-worksheet-controller.ts +12 -12
- package/server/controllers/vas/vas-worksheet-controller.ts +2 -2
- package/server/controllers/worksheet-controller.ts +18 -23
- package/server/entities/index.ts +2 -2
- package/server/entities/warehouse-bizplace-onhand-inventory.ts +29 -63
- package/server/graphql/resolvers/worksheet/batch-picking-worksheet.ts +6 -0
- package/server/graphql/resolvers/worksheet/confirm-cancellation-release-order.ts +1 -2
- package/server/graphql/resolvers/worksheet/cycle-count-adjustment.ts +2 -2
- package/server/graphql/resolvers/worksheet/delivery-order-by-worksheet.ts +7 -6
- package/server/graphql/resolvers/worksheet/inventories-by-pallet.ts +3 -1
- package/server/graphql/resolvers/worksheet/loading/complete-loading.ts +77 -33
- package/server/graphql/resolvers/worksheet/packing/activate-packing.ts +26 -9
- package/server/graphql/resolvers/worksheet/packing/complete-packing.ts +34 -9
- package/server/graphql/resolvers/worksheet/packing/packing.ts +26 -9
- package/server/graphql/resolvers/worksheet/packing/scan-product-packing.ts +28 -9
- package/server/graphql/resolvers/worksheet/packing-worksheet.ts +69 -13
- package/server/graphql/resolvers/worksheet/picking/activate-picking.ts +60 -30
- package/server/graphql/resolvers/worksheet/picking/complete-batch-picking.ts +46 -40
- package/server/graphql/resolvers/worksheet/picking/complete-picking.ts +142 -131
- package/server/graphql/resolvers/worksheet/picking-worksheet.ts +3 -2
- package/server/graphql/resolvers/worksheet/proceed-extra-products.ts +5 -4
- package/server/graphql/resolvers/worksheet/putaway/complete-putaway.ts +45 -15
- package/server/graphql/resolvers/worksheet/transfer.ts +18 -16
- package/server/graphql/resolvers/worksheet/vas-transactions/common-utils.ts +3 -2
- package/server/graphql/resolvers/worksheet-detail/regenerate-release-good-worksheet-details.ts +4 -1
- package/server/graphql/types/worksheet/delivery-order-info.ts +1 -0
- package/server/graphql/types/worksheet-detail/index.ts +1 -0
- package/server/utils/inventory-util.ts +1 -126
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EntityManager } from 'typeorm'
|
|
2
2
|
|
|
3
|
-
import { User } from '@things-factory/auth-base'
|
|
3
|
+
import { ApplicationType, User } from '@things-factory/auth-base'
|
|
4
4
|
import { MarketplaceStore } from '@things-factory/integration-marketplace'
|
|
5
5
|
import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
|
|
6
6
|
import { ArrivalNotice } from '@things-factory/sales-base'
|
|
@@ -33,24 +33,54 @@ export const completePutawayResolver = {
|
|
|
33
33
|
// search for any active marketplace connection
|
|
34
34
|
const companyDomain: Domain = arrivalNotice.bizplace.company.domain
|
|
35
35
|
const customerDomain: Domain = arrivalNotice.bizplace.domain
|
|
36
|
-
const marketplaceStores: MarketplaceStore[] = await tx.getRepository(MarketplaceStore).find({
|
|
37
|
-
where: { domain: companyDomain, status: 'ACTIVE', isAutoUpdateStockQty: true },
|
|
38
|
-
relations: ['marketplaceDistributors']
|
|
39
|
-
})
|
|
40
36
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
.
|
|
37
|
+
const orderSource: string = arrivalNotice.source
|
|
38
|
+
switch (orderSource) {
|
|
39
|
+
case ApplicationType.SELLERCRAFT:
|
|
40
|
+
const sellercraft: Sellercraft = await tx
|
|
41
|
+
.getRepository(Sellercraft)
|
|
42
|
+
.findOne({ domain: customerDomain, status: SellercraftStatus.ACTIVE })
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
if (sellercraft) {
|
|
45
|
+
const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
|
|
46
|
+
await sellercraftCtrl.registerProductInbound(sellercraft, arrivalNotice)
|
|
47
|
+
}
|
|
48
|
+
break
|
|
49
|
+
|
|
50
|
+
case ApplicationType.MMS:
|
|
51
|
+
const marketplaceStores: MarketplaceStore[] = await tx.getRepository(MarketplaceStore).find({
|
|
52
|
+
where: { domain: companyDomain, status: 'ACTIVE', isAutoUpdateStockQty: true },
|
|
53
|
+
relations: ['marketplaceDistributors']
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
if (marketplaceStores?.length && marketplaceStores.some(store => store.isAutoUpdateStockQty)) {
|
|
57
|
+
const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
58
|
+
await ecommerceCtrl.updateProductVariationStock(marketplaceStores, arrivalNotice.orderProducts, companyDomain)
|
|
59
|
+
}
|
|
60
|
+
break
|
|
49
61
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
await ecommerceCtrl.updateProductVariationStock(marketplaceStores, arrivalNotice.orderProducts, companyDomain)
|
|
62
|
+
default:
|
|
63
|
+
break
|
|
53
64
|
}
|
|
65
|
+
|
|
66
|
+
// const marketplaceStores: MarketplaceStore[] = await tx.getRepository(MarketplaceStore).find({
|
|
67
|
+
// where: { domain: companyDomain, status: 'ACTIVE', isAutoUpdateStockQty: true },
|
|
68
|
+
// relations: ['marketplaceDistributors']
|
|
69
|
+
// })
|
|
70
|
+
|
|
71
|
+
// const sellercraft: Sellercraft = await tx
|
|
72
|
+
// .getRepository(Sellercraft)
|
|
73
|
+
// .findOne({ domain: customerDomain, status: SellercraftStatus.ACTIVE })
|
|
74
|
+
|
|
75
|
+
// if (sellercraft) {
|
|
76
|
+
// const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
|
|
77
|
+
// await sellercraftCtrl.registerProductInbound(sellercraft, arrivalNotice)
|
|
78
|
+
// }
|
|
79
|
+
|
|
80
|
+
// if (marketplaceStores?.length && marketplaceStores.some(store => store.isAutoUpdateStockQty)) {
|
|
81
|
+
// const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
82
|
+
// await ecommerceCtrl.updateProductVariationStock(marketplaceStores, arrivalNotice.orderProducts, companyDomain)
|
|
83
|
+
// }
|
|
54
84
|
}
|
|
55
85
|
}
|
|
56
86
|
|
|
@@ -1,38 +1,36 @@
|
|
|
1
|
+
import { EntityManager } from 'typeorm'
|
|
2
|
+
|
|
1
3
|
import { User } from '@things-factory/auth-base'
|
|
2
4
|
import { Bizplace } from '@things-factory/biz-base'
|
|
5
|
+
import { ORDER_PRODUCT_STATUS, OrderInventory } from '@things-factory/sales-base'
|
|
3
6
|
import { Domain } from '@things-factory/shell'
|
|
4
|
-
import { OrderInventory, ORDER_PRODUCT_STATUS } from '@things-factory/sales-base'
|
|
5
7
|
import {
|
|
6
8
|
Inventory,
|
|
7
|
-
InventoryHistory,
|
|
8
|
-
InventoryNoGenerator,
|
|
9
9
|
INVENTORY_STATUS,
|
|
10
|
-
INVENTORY_TRANSACTION_TYPE
|
|
10
|
+
INVENTORY_TRANSACTION_TYPE,
|
|
11
|
+
InventoryHistory,
|
|
12
|
+
InventoryNoGenerator
|
|
11
13
|
} from '@things-factory/warehouse-base'
|
|
12
|
-
|
|
14
|
+
|
|
13
15
|
import { WORKSHEET_STATUS, WORKSHEET_TYPE } from '../../../constants'
|
|
14
16
|
import { Worksheet, WorksheetDetail } from '../../../entities'
|
|
15
17
|
|
|
16
18
|
export const transfer = {
|
|
17
19
|
async transfer(_: any, { palletId, toPalletId, qty }, context: any) {
|
|
18
|
-
const {
|
|
19
|
-
|
|
20
|
-
domain,
|
|
21
|
-
bizplace,
|
|
22
|
-
user
|
|
23
|
-
}: { tx: EntityManager; domain: Domain; bizplace: Bizplace; user: User } = context.state
|
|
20
|
+
const { tx, domain, bizplace, user }: { tx: EntityManager; domain: Domain; bizplace: Bizplace; user: User } =
|
|
21
|
+
context.state
|
|
24
22
|
|
|
25
23
|
// 1. get to inventory
|
|
26
24
|
let toInventory: Inventory = await tx.getRepository(Inventory).findOne({
|
|
27
25
|
where: { domain: domain, palletId: toPalletId },
|
|
28
|
-
relations: ['bizplace', 'product', 'warehouse', 'location']
|
|
26
|
+
relations: ['bizplace', 'product', 'productDetail', 'warehouse', 'location']
|
|
29
27
|
})
|
|
30
28
|
if (!toInventory) throw new Error(`to pallet doesn't exists`)
|
|
31
29
|
|
|
32
30
|
// 2. get from inventory
|
|
33
31
|
let fromInventory: Inventory = await tx.getRepository(Inventory).findOne({
|
|
34
32
|
where: { domain: domain, palletId },
|
|
35
|
-
relations: ['bizplace', 'product', 'warehouse', 'location']
|
|
33
|
+
relations: ['bizplace', 'product', 'productDetail', 'warehouse', 'location']
|
|
36
34
|
})
|
|
37
35
|
if (!fromInventory) throw new Error(`from pallet doesn't exists`)
|
|
38
36
|
if (toInventory.batchId !== fromInventory.batchId) throw new Error(`Can't transfer to different batch`)
|
|
@@ -74,6 +72,7 @@ export const transfer = {
|
|
|
74
72
|
domain: domain,
|
|
75
73
|
name: InventoryNoGenerator.inventoryHistoryName(),
|
|
76
74
|
product: toInventory.product,
|
|
75
|
+
productDetail: toInventory.productDetail,
|
|
77
76
|
warehouse: toInventory.warehouse,
|
|
78
77
|
location: toInventory.location,
|
|
79
78
|
seq: toInventory.lastSeq,
|
|
@@ -97,7 +96,7 @@ export const transfer = {
|
|
|
97
96
|
|
|
98
97
|
fromInventory = await tx.getRepository(Inventory).findOne({
|
|
99
98
|
where: { id: fromInventory.id },
|
|
100
|
-
relations: ['bizplace', 'product', 'warehouse', 'location']
|
|
99
|
+
relations: ['bizplace', 'product', 'productDetail', 'warehouse', 'location']
|
|
101
100
|
})
|
|
102
101
|
|
|
103
102
|
// - add inventory history
|
|
@@ -105,6 +104,7 @@ export const transfer = {
|
|
|
105
104
|
...fromInventory,
|
|
106
105
|
name: InventoryNoGenerator.inventoryHistoryName(),
|
|
107
106
|
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', 'warehouse', 'location']
|
|
134
|
+
relations: ['bizplace', 'product', 'productDetail', 'warehouse', 'location']
|
|
135
135
|
})
|
|
136
136
|
// - add inventory history
|
|
137
137
|
delete toInventory.id
|
|
@@ -140,6 +140,7 @@ export const transfer = {
|
|
|
140
140
|
domain,
|
|
141
141
|
name: InventoryNoGenerator.inventoryHistoryName(),
|
|
142
142
|
product: toInventory.product,
|
|
143
|
+
productDetail: toInventory.productDetail,
|
|
143
144
|
warehouse: toInventory.warehouse,
|
|
144
145
|
location: toInventory.location,
|
|
145
146
|
seq: toInventory.lastSeq,
|
|
@@ -157,7 +158,7 @@ export const transfer = {
|
|
|
157
158
|
|
|
158
159
|
fromInventory = await tx.getRepository(Inventory).findOne({
|
|
159
160
|
where: { id: fromInventory.id },
|
|
160
|
-
relations: ['bizplace', 'product', 'warehouse', 'location']
|
|
161
|
+
relations: ['bizplace', 'product', 'productDetail', 'warehouse', 'location']
|
|
161
162
|
})
|
|
162
163
|
|
|
163
164
|
// - add inventory history
|
|
@@ -165,6 +166,7 @@ export const transfer = {
|
|
|
165
166
|
...fromInventory,
|
|
166
167
|
name: InventoryNoGenerator.inventoryHistoryName(),
|
|
167
168
|
product: fromInventory.product,
|
|
169
|
+
productDetail: fromInventory.productDetail,
|
|
168
170
|
warehouse: fromInventory.warehouse,
|
|
169
171
|
location: fromInventory.location,
|
|
170
172
|
seq: fromInventory.lastSeq,
|
|
@@ -19,12 +19,13 @@ import {
|
|
|
19
19
|
InventoryNoGenerator,
|
|
20
20
|
Location,
|
|
21
21
|
Pallet,
|
|
22
|
-
Warehouse
|
|
22
|
+
Warehouse,
|
|
23
|
+
generateInventoryHistory
|
|
23
24
|
} from '@things-factory/warehouse-base'
|
|
24
25
|
|
|
25
26
|
import { WORKSHEET_STATUS, WORKSHEET_TYPE } from '../../../../constants'
|
|
26
27
|
import { Worksheet, WorksheetDetail } from '../../../../entities'
|
|
27
|
-
import {
|
|
28
|
+
import { WorksheetNoGenerator } from '../../../../utils'
|
|
28
29
|
import {
|
|
29
30
|
OperationGuideInterface,
|
|
30
31
|
PackingUnits,
|
package/server/graphql/resolvers/worksheet-detail/regenerate-release-good-worksheet-details.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { WorksheetNoGenerator } from '../../../utils'
|
|
|
19
19
|
export const regenerateReleaseGoodWorksheetDetailsResolver = {
|
|
20
20
|
async regenerateReleaseGoodWorksheetDetails(
|
|
21
21
|
_: any,
|
|
22
|
-
{ worksheetNo, batchId, productId, packingType, packingSize, orderProductId, worksheetDetails },
|
|
22
|
+
{ worksheetNo, batchId, productId, productDetailId, 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,6 +30,7 @@ export const regenerateReleaseGoodWorksheetDetailsResolver = {
|
|
|
30
30
|
worksheetNo,
|
|
31
31
|
batchId,
|
|
32
32
|
productId,
|
|
33
|
+
productDetailId,
|
|
33
34
|
packingType,
|
|
34
35
|
packingSize,
|
|
35
36
|
orderProductId,
|
|
@@ -45,6 +46,7 @@ export async function regenerateReleaseGoodWorksheetDetails(
|
|
|
45
46
|
worksheetNo: string,
|
|
46
47
|
batchId: string,
|
|
47
48
|
productId: string,
|
|
49
|
+
productDetailId: string,
|
|
48
50
|
packingType: string,
|
|
49
51
|
packingSize: number,
|
|
50
52
|
orderProductId: string,
|
|
@@ -115,6 +117,7 @@ export async function regenerateReleaseGoodWorksheetDetails(
|
|
|
115
117
|
batchIdRef: inventory.batchIdRef,
|
|
116
118
|
status: ORDER_INVENTORY_STATUS.READY_TO_PICK,
|
|
117
119
|
product: await tx.getRepository(Product).findOne(productId),
|
|
120
|
+
productDetail: productDetailId,
|
|
118
121
|
packingType,
|
|
119
122
|
packingSize,
|
|
120
123
|
orderProduct: targetProduct,
|
|
@@ -4,134 +4,9 @@ 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 {
|
|
8
|
-
Inventory,
|
|
9
|
-
INVENTORY_STATUS,
|
|
10
|
-
InventoryHistory,
|
|
11
|
-
InventoryNoGenerator,
|
|
12
|
-
Location,
|
|
13
|
-
LOCATION_STATUS,
|
|
14
|
-
LOCATION_TYPE
|
|
15
|
-
} from '@things-factory/warehouse-base'
|
|
7
|
+
import { Inventory, INVENTORY_STATUS, Location, LOCATION_STATUS, LOCATION_TYPE } from '@things-factory/warehouse-base'
|
|
16
8
|
|
|
17
9
|
/**
|
|
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
|
-
|
|
135
10
|
/**
|
|
136
11
|
* @description: Check location emptiness and update status of location
|
|
137
12
|
* @param domain
|