@things-factory/operato-wms 4.3.642 → 4.3.644
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/client/pages/outbound/loading-v2/loading-execution-base.js +625 -153
- package/client/pages/outbound/loading-v2/loading-execution.js +239 -139
- package/client/pages/outbound/loading-v2/loading.js +297 -179
- package/client/pages/outbound/loading-v2/release-good-info.js +8 -8
- package/client/pages/outbound/picking-v2/picking.js +4 -0
- package/client/pages/outbound/show-ro-list-popup.js +17 -3
- package/client/pages/report/billing-module-report.js +421 -0
- package/client/route.js +4 -0
- package/dist-server/graphql/resolvers/outbound/complete-load.js +6 -1
- package/dist-server/graphql/resolvers/outbound/complete-load.js.map +1 -1
- package/dist-server/graphql/resolvers/outbound/find-loadable-release-good-by-bin.js +148 -0
- package/dist-server/graphql/resolvers/outbound/find-loadable-release-good-by-bin.js.map +1 -0
- package/dist-server/graphql/resolvers/outbound/find-loadable-release-good.js +67 -13
- package/dist-server/graphql/resolvers/outbound/find-loadable-release-good.js.map +1 -1
- package/dist-server/graphql/resolvers/outbound/get-delivery-orders.js +20 -3
- package/dist-server/graphql/resolvers/outbound/get-delivery-orders.js.map +1 -1
- package/dist-server/graphql/resolvers/outbound/index.js +2 -1
- package/dist-server/graphql/resolvers/outbound/index.js.map +1 -1
- package/dist-server/graphql/resolvers/outbound/load-by-qty.js +15 -3
- package/dist-server/graphql/resolvers/outbound/load-by-qty.js.map +1 -1
- package/dist-server/graphql/resolvers/outbound/loading-worksheet-v2.js +36 -15
- package/dist-server/graphql/resolvers/outbound/loading-worksheet-v2.js.map +1 -1
- package/dist-server/graphql/resolvers/outbound/sort-item.js +53 -52
- package/dist-server/graphql/resolvers/outbound/sort-item.js.map +1 -1
- package/dist-server/graphql/resolvers/reports/billing-module-report.js +355 -0
- package/dist-server/graphql/resolvers/reports/billing-module-report.js.map +1 -0
- package/dist-server/graphql/resolvers/reports/index.js +2 -1
- package/dist-server/graphql/resolvers/reports/index.js.map +1 -1
- package/dist-server/graphql/resolvers/reports/outbound-order-details-report.js +3 -0
- package/dist-server/graphql/resolvers/reports/outbound-order-details-report.js.map +1 -1
- package/dist-server/graphql/resolvers/reports/pg-udf-query.js +5 -3
- package/dist-server/graphql/resolvers/reports/pg-udf-query.js.map +1 -1
- package/dist-server/graphql/resolvers/zone-worksheet/zone-picking.js +3 -3
- package/dist-server/graphql/types/outbound/index.js +2 -1
- package/dist-server/graphql/types/outbound/index.js.map +1 -1
- package/dist-server/graphql/types/reports/billing-module-report-list.js +14 -0
- package/dist-server/graphql/types/reports/billing-module-report-list.js.map +1 -0
- package/dist-server/graphql/types/reports/billing-module-report.js +15 -0
- package/dist-server/graphql/types/reports/billing-module-report.js.map +1 -0
- package/dist-server/graphql/types/reports/index.js +5 -0
- package/dist-server/graphql/types/reports/index.js.map +1 -1
- package/package.json +4 -4
- package/server/graphql/resolvers/outbound/complete-load.ts +6 -1
- package/server/graphql/resolvers/outbound/find-loadable-release-good-by-bin.ts +154 -0
- package/server/graphql/resolvers/outbound/find-loadable-release-good.ts +82 -16
- package/server/graphql/resolvers/outbound/get-delivery-orders.ts +27 -3
- package/server/graphql/resolvers/outbound/index.ts +2 -0
- package/server/graphql/resolvers/outbound/load-by-qty.ts +19 -7
- package/server/graphql/resolvers/outbound/loading-worksheet-v2.ts +116 -22
- package/server/graphql/resolvers/outbound/sort-item.ts +56 -58
- package/server/graphql/resolvers/reports/billing-module-report.ts +372 -0
- package/server/graphql/resolvers/reports/index.ts +2 -0
- package/server/graphql/resolvers/reports/outbound-order-details-report.ts +5 -8
- package/server/graphql/resolvers/reports/pg-udf-query.ts +15 -13
- package/server/graphql/resolvers/zone-worksheet/zone-picking.ts +3 -3
- package/server/graphql/types/outbound/index.ts +2 -1
- package/server/graphql/types/reports/billing-module-report-list.ts +8 -0
- package/server/graphql/types/reports/billing-module-report.ts +9 -0
- package/server/graphql/types/reports/index.ts +6 -0
- package/things-factory.config.js +4 -0
- package/translations/en.json +7 -0
- package/translations/ko.json +2 -0
- package/translations/ms.json +2 -0
- package/translations/zh.json +2 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { EntityManager } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
import { Location } from '@things-factory/warehouse-base'
|
|
4
|
+
import { Domain } from '@things-factory/shell'
|
|
5
|
+
import { OrderInventory, ORDER_INVENTORY_STATUS, ORDER_STATUS, ReleaseGood } from '@things-factory/sales-base'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Custom error class for outbound order related errors
|
|
9
|
+
* Covers both ReleaseGood and OrderInventory related errors
|
|
10
|
+
*/
|
|
11
|
+
class OutboundOrderError extends Error {
|
|
12
|
+
constructor(message: string, public code: string) {
|
|
13
|
+
super(message)
|
|
14
|
+
this.name = 'OutboundOrderError'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Builds a query to find a release good by order number
|
|
20
|
+
*/
|
|
21
|
+
const buildfindReleaseGoodByNameQuery = (tx: EntityManager, domainId: string, orderNo: string) => {
|
|
22
|
+
return tx
|
|
23
|
+
.getRepository(ReleaseGood)
|
|
24
|
+
.createQueryBuilder('releaseGood')
|
|
25
|
+
.leftJoinAndSelect('releaseGood.bizplace', 'bizplace')
|
|
26
|
+
.where('releaseGood.domain_id = :domainId', { domainId })
|
|
27
|
+
.andWhere('releaseGood.name = :orderNo', { orderNo })
|
|
28
|
+
.andWhere('releaseGood.status IN (:...status)', {
|
|
29
|
+
status: [ORDER_STATUS.LOADING, ORDER_STATUS.PROCESSING, ORDER_STATUS.PARTIAL_PROCESSING, ORDER_STATUS.DONE]
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Builds a query to find order inventories by bin location
|
|
35
|
+
*/
|
|
36
|
+
const buildOrderInventoryQuery = (tx: EntityManager, domainId: string, locationId: string) => {
|
|
37
|
+
return tx
|
|
38
|
+
.getRepository(OrderInventory)
|
|
39
|
+
.createQueryBuilder('orderInventory')
|
|
40
|
+
.leftJoinAndSelect('orderInventory.inventory', 'inventory')
|
|
41
|
+
.leftJoinAndSelect('inventory.product', 'product')
|
|
42
|
+
.leftJoinAndSelect('inventory.productDetail', 'productDetail')
|
|
43
|
+
.leftJoinAndSelect('orderInventory.binLocation', 'binLocation')
|
|
44
|
+
.where('orderInventory.domain_id = :domainId', { domainId })
|
|
45
|
+
.andWhere('orderInventory.status IN (:...orderInventoryStatus)', {
|
|
46
|
+
orderInventoryStatus: [
|
|
47
|
+
ORDER_INVENTORY_STATUS.SORTING,
|
|
48
|
+
ORDER_INVENTORY_STATUS.LOADING,
|
|
49
|
+
ORDER_INVENTORY_STATUS.LOADED
|
|
50
|
+
]
|
|
51
|
+
})
|
|
52
|
+
.andWhere('orderInventory.bin_location_id = :locationId', { locationId })
|
|
53
|
+
.orderBy('orderInventory.createdAt', 'ASC')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Transforms order inventory data into the required worksheet format
|
|
58
|
+
*/
|
|
59
|
+
const transformToWorksheetFormat = (orderInventories: OrderInventory[]) => {
|
|
60
|
+
if (!orderInventories.length) return null
|
|
61
|
+
|
|
62
|
+
// Extract unique bin location names
|
|
63
|
+
const uniqueBinLocations = [...new Set(orderInventories.map(oi => oi.binLocation?.name).filter(Boolean))]
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
worksheetInfo: {
|
|
67
|
+
worksheet: {
|
|
68
|
+
id: null,
|
|
69
|
+
name: null,
|
|
70
|
+
type: null,
|
|
71
|
+
status: null
|
|
72
|
+
},
|
|
73
|
+
bizplaceName: null,
|
|
74
|
+
startedAt: null,
|
|
75
|
+
releaseGood: null,
|
|
76
|
+
binLocationName: uniqueBinLocations.join(', ') // Join multiple bin locations with comma
|
|
77
|
+
},
|
|
78
|
+
worksheetDetailInfos: orderInventories.map(oi => ({
|
|
79
|
+
id: null,
|
|
80
|
+
name: null,
|
|
81
|
+
batchId: oi.batchId,
|
|
82
|
+
releaseQty: oi.releaseQty,
|
|
83
|
+
pickedQty: oi.pickedQty,
|
|
84
|
+
sortedQty: oi.sortedQty,
|
|
85
|
+
status: oi.status,
|
|
86
|
+
packingType: oi.packingType,
|
|
87
|
+
packingSize: oi.packingSize,
|
|
88
|
+
expirationDate: oi.inventory?.expirationDate,
|
|
89
|
+
binLocation: {
|
|
90
|
+
name: oi.binLocation?.name
|
|
91
|
+
},
|
|
92
|
+
productName: oi.inventory?.product?.name,
|
|
93
|
+
productSku: oi.inventory?.product?.sku,
|
|
94
|
+
relatedOrderInv: {
|
|
95
|
+
id: oi.id,
|
|
96
|
+
batchId: oi.batchId,
|
|
97
|
+
packingType: oi.packingType,
|
|
98
|
+
product: oi.inventory?.product
|
|
99
|
+
? {
|
|
100
|
+
id: oi.inventory.product.id,
|
|
101
|
+
sku: oi.inventory.product.sku,
|
|
102
|
+
name: oi.inventory.product.name
|
|
103
|
+
}
|
|
104
|
+
: null,
|
|
105
|
+
productDetail: oi.inventory?.productDetail
|
|
106
|
+
? {
|
|
107
|
+
id: oi.inventory.productDetail.id
|
|
108
|
+
}
|
|
109
|
+
: null
|
|
110
|
+
}
|
|
111
|
+
}))
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Finds loadable release goods by bin location
|
|
117
|
+
* @param _ - GraphQL resolver parent object
|
|
118
|
+
* @param orderNo - The order number or bin location name to search for
|
|
119
|
+
* @param context - GraphQL context containing domain and transaction manager
|
|
120
|
+
* @returns Promise<Object> - Transformed worksheet data structure
|
|
121
|
+
* @throws OutboundOrderError if order is DONE or if no items found in bin
|
|
122
|
+
*/
|
|
123
|
+
export const findLoadableReleaseGoodByBin = {
|
|
124
|
+
async findLoadableReleaseGoodByBin(_: any, { orderNo }: { orderNo: string }, context: any): Promise<any> {
|
|
125
|
+
const { domain, tx }: { domain: Domain; tx: EntityManager } = context.state
|
|
126
|
+
|
|
127
|
+
let orderInventoryByBin: OrderInventory[] = []
|
|
128
|
+
|
|
129
|
+
let foundReleaseGood: ReleaseGood = await buildfindReleaseGoodByNameQuery(tx, domain.id, orderNo).getOne()
|
|
130
|
+
|
|
131
|
+
if (foundReleaseGood && foundReleaseGood.status == ORDER_STATUS.DONE) {
|
|
132
|
+
throw new OutboundOrderError('This order is DONE', 'ORDER_DONE')
|
|
133
|
+
} else if (foundReleaseGood) {
|
|
134
|
+
throw new OutboundOrderError(
|
|
135
|
+
'You are scanning using order number. Your setting for QC by BIN is enabled. Please contact your administrator.',
|
|
136
|
+
'QC_BY_BIN_ENABLED'
|
|
137
|
+
)
|
|
138
|
+
} else {
|
|
139
|
+
const binLocation: Location = await tx.getRepository(Location).findOne({
|
|
140
|
+
where: { domain, name: orderNo }
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
if (binLocation) {
|
|
144
|
+
orderInventoryByBin = await buildOrderInventoryQuery(tx, domain.id, binLocation.id).getMany()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (orderInventoryByBin.length > 0) {
|
|
148
|
+
return transformToWorksheetFormat(orderInventoryByBin)
|
|
149
|
+
} else {
|
|
150
|
+
throw new OutboundOrderError('There is no item in this bin', 'NO_ITEMS_IN_BIN')
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -1,35 +1,60 @@
|
|
|
1
|
-
import { EntityManager
|
|
1
|
+
import { EntityManager } from 'typeorm'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { Inventory, Location } from '@things-factory/warehouse-base'
|
|
3
|
+
import { Location } from '@things-factory/warehouse-base'
|
|
5
4
|
import { Domain } from '@things-factory/shell'
|
|
6
5
|
import { OrderInventory, ORDER_INVENTORY_STATUS, ORDER_STATUS, ReleaseGood } from '@things-factory/sales-base'
|
|
7
6
|
|
|
8
7
|
export const findLoadableReleaseGood = {
|
|
9
|
-
async findLoadableReleaseGood(_: any, { orderNo }, context: any): Promise<ReleaseGood[]> {
|
|
8
|
+
async findLoadableReleaseGood(_: any, { orderNo, tabName }, context: any): Promise<ReleaseGood[]> {
|
|
10
9
|
const { domain, tx }: { domain: Domain; tx: EntityManager } = context.state
|
|
11
10
|
|
|
12
|
-
let
|
|
11
|
+
let releaseGoods = []
|
|
13
12
|
|
|
14
13
|
let foundReleaseGood: ReleaseGood = await tx
|
|
15
14
|
.getRepository(ReleaseGood)
|
|
16
15
|
.createQueryBuilder('releaseGood')
|
|
17
16
|
.where('releaseGood.domain_id = :domainId', { domainId: domain.id })
|
|
18
17
|
.andWhere('releaseGood.name = :orderNo', { orderNo })
|
|
19
|
-
.andWhere('releaseGood.status IN (:...status)', {
|
|
18
|
+
.andWhere('releaseGood.status IN (:...status)', {
|
|
19
|
+
status: [ORDER_STATUS.LOADING, ORDER_STATUS.PROCESSING, ORDER_STATUS.PARTIAL_PROCESSING, ORDER_STATUS.DONE]
|
|
20
|
+
})
|
|
20
21
|
.getOne()
|
|
21
22
|
|
|
22
23
|
if (foundReleaseGood && foundReleaseGood.status == ORDER_STATUS.DONE) {
|
|
23
|
-
throw new Error
|
|
24
|
+
throw new Error('This order is DONE')
|
|
24
25
|
} else if (foundReleaseGood) {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
// Get counts for single release good
|
|
27
|
+
const counts = await tx
|
|
28
|
+
.getRepository(OrderInventory)
|
|
29
|
+
.createQueryBuilder('orderInventory')
|
|
30
|
+
.select('COUNT(*)', 'total')
|
|
31
|
+
.addSelect(`SUM(CASE WHEN orderInventory.status IN (:...completedStatuses) THEN 1 ELSE 0 END)`, 'completed')
|
|
32
|
+
.where('orderInventory.release_good_id = :releaseGoodId', { releaseGoodId: foundReleaseGood.id })
|
|
33
|
+
.andWhere('orderInventory.domain_id = :domainId', { domainId: domain.id })
|
|
34
|
+
.setParameter(
|
|
35
|
+
'completedStatuses',
|
|
36
|
+
tabName === 'QC'
|
|
37
|
+
? [ORDER_INVENTORY_STATUS.LOADING, ORDER_INVENTORY_STATUS.LOADED]
|
|
38
|
+
: tabName === 'LOADING'
|
|
39
|
+
? [ORDER_INVENTORY_STATUS.LOADED]
|
|
40
|
+
: [ORDER_INVENTORY_STATUS.LOADED]
|
|
41
|
+
)
|
|
42
|
+
.getRawOne()
|
|
43
|
+
|
|
44
|
+
foundReleaseGood['itemCounts'] = {
|
|
45
|
+
total: parseInt(counts.total) || 0,
|
|
46
|
+
pending: parseInt(counts.completed) || 0
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
releaseGoods.push(foundReleaseGood)
|
|
50
|
+
return releaseGoods
|
|
27
51
|
} else {
|
|
28
52
|
const binLocation: Location = await tx.getRepository(Location).findOne({
|
|
29
53
|
where: { domain, name: orderNo }
|
|
30
54
|
})
|
|
31
55
|
|
|
32
56
|
if (binLocation) {
|
|
57
|
+
// First get all matching release goods
|
|
33
58
|
const orderInventoryByBin: OrderInventory[] = await tx
|
|
34
59
|
.getRepository(OrderInventory)
|
|
35
60
|
.createQueryBuilder('orderInventory')
|
|
@@ -38,24 +63,65 @@ export const findLoadableReleaseGood = {
|
|
|
38
63
|
.innerJoinAndSelect('bizplace.domain', 'domain')
|
|
39
64
|
.leftJoinAndSelect('releaseGood.sortedBy', 'sortedBy')
|
|
40
65
|
.where('orderInventory.domain_id = :domainId', { domainId: domain.id })
|
|
41
|
-
.andWhere('orderInventory.status
|
|
42
|
-
orderInventoryStatus:
|
|
66
|
+
.andWhere('orderInventory.status = :orderInventoryStatus', {
|
|
67
|
+
orderInventoryStatus:
|
|
68
|
+
tabName === 'QC'
|
|
69
|
+
? ORDER_INVENTORY_STATUS.SORTING
|
|
70
|
+
: tabName === 'LOADING'
|
|
71
|
+
? ORDER_INVENTORY_STATUS.LOADING
|
|
72
|
+
: ORDER_INVENTORY_STATUS.LOADED
|
|
43
73
|
})
|
|
44
74
|
.andWhere('orderInventory.bin_location_id = :locationId', { locationId: binLocation.id })
|
|
45
|
-
.andWhere('releaseGood.status IN (:...status)', {
|
|
75
|
+
.andWhere('releaseGood.status IN (:...status)', {
|
|
76
|
+
status: [ORDER_STATUS.LOADING, ORDER_STATUS.PROCESSING, ORDER_STATUS.PARTIAL_PROCESSING]
|
|
77
|
+
})
|
|
46
78
|
.orderBy('releaseGood.createdAt', 'ASC')
|
|
47
79
|
.getMany()
|
|
48
80
|
|
|
49
|
-
|
|
81
|
+
// Get unique release goods
|
|
82
|
+
releaseGoods = orderInventoryByBin.reduce((acc, oi) => {
|
|
50
83
|
if (!acc.some(rg => rg.id === oi.releaseGood.id)) {
|
|
51
84
|
acc.push(oi.releaseGood)
|
|
52
85
|
}
|
|
53
86
|
return acc
|
|
54
87
|
}, [])
|
|
88
|
+
|
|
89
|
+
// Get counts for each release good
|
|
90
|
+
for (const releaseGood of releaseGoods) {
|
|
91
|
+
const counts = await tx
|
|
92
|
+
.getRepository(OrderInventory)
|
|
93
|
+
.createQueryBuilder('orderInventory')
|
|
94
|
+
.select('COUNT(*)', 'total')
|
|
95
|
+
.addSelect(`SUM(CASE WHEN orderInventory.status IN (:...completedStatuses) THEN 1 ELSE 0 END)`, 'completed')
|
|
96
|
+
.where('orderInventory.release_good_id = :releaseGoodId', { releaseGoodId: releaseGood.id })
|
|
97
|
+
.andWhere('orderInventory.domain_id = :domainId', { domainId: domain.id })
|
|
98
|
+
.setParameter(
|
|
99
|
+
'completedStatuses',
|
|
100
|
+
tabName === 'LOADING'
|
|
101
|
+
? [ORDER_INVENTORY_STATUS.LOADING]
|
|
102
|
+
: tabName === 'LOADED'
|
|
103
|
+
? [ORDER_INVENTORY_STATUS.LOADED]
|
|
104
|
+
: [ORDER_INVENTORY_STATUS.LOADED]
|
|
105
|
+
)
|
|
106
|
+
.getRawOne()
|
|
107
|
+
|
|
108
|
+
releaseGood['itemCounts'] = {
|
|
109
|
+
total: parseInt(counts.total) || 0,
|
|
110
|
+
pending: parseInt(counts.completed) || 0
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (releaseGoods.length > 0) return releaseGoods
|
|
116
|
+
else {
|
|
117
|
+
const errorMessage =
|
|
118
|
+
tabName === 'QC'
|
|
119
|
+
? 'No items pending QC verification'
|
|
120
|
+
: tabName === 'LOADING'
|
|
121
|
+
? 'No items pending loading'
|
|
122
|
+
: 'No items pending dispatch'
|
|
123
|
+
throw new Error(errorMessage)
|
|
55
124
|
}
|
|
56
|
-
|
|
57
|
-
if (releaseGood.length > 0) return releaseGood
|
|
58
|
-
else throw new Error('Unable to find release good')
|
|
59
125
|
}
|
|
60
126
|
}
|
|
61
127
|
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import { getRepository } from 'typeorm'
|
|
1
|
+
import { EntityManager, Repository, getRepository } from 'typeorm'
|
|
2
2
|
import { Domain } from '@things-factory/shell'
|
|
3
3
|
import { User } from '@things-factory/auth-base'
|
|
4
4
|
import { ReleaseGood, DeliveryOrder, ORDER_INVENTORY_STATUS } from '@things-factory/sales-base'
|
|
5
|
+
import { Setting } from '@things-factory/setting-base'
|
|
6
|
+
|
|
7
|
+
const SETTINGS = {
|
|
8
|
+
QC_SKU: 'qc-sku'
|
|
9
|
+
}
|
|
5
10
|
|
|
6
11
|
export const getDeliveryOrders = {
|
|
7
12
|
async getDeliveryOrders(_: any, { releaseGoodNo }, context: any) {
|
|
8
|
-
const { domain }: { domain: Domain } = context.state
|
|
13
|
+
const { domain, tx }: { domain: Domain, tx: EntityManager } = context.state
|
|
9
14
|
|
|
10
15
|
const releaseGood: ReleaseGood = await getRepository(ReleaseGood).findOne({
|
|
11
16
|
where: { domain, name: releaseGoodNo },
|
|
@@ -18,12 +23,31 @@ export const getDeliveryOrders = {
|
|
|
18
23
|
|
|
19
24
|
const complete_status = [ORDER_INVENTORY_STATUS.LOADED, ORDER_INVENTORY_STATUS.TERMINATED, ORDER_INVENTORY_STATUS.RETURNING, ORDER_INVENTORY_STATUS.MISSING]
|
|
20
25
|
const completable = releaseGood.orderInventories?.every(oi => complete_status.includes(oi.status))
|
|
26
|
+
|
|
27
|
+
const settingRepo: Repository<Setting> = tx?.getRepository(Setting) || getRepository(Setting)
|
|
28
|
+
const qcSetting = await settingRepo.findOne({
|
|
29
|
+
where: { domain, name: SETTINGS.QC_SKU }
|
|
30
|
+
})
|
|
21
31
|
|
|
22
|
-
const
|
|
32
|
+
const useQcSku =
|
|
33
|
+
qcSetting?.value?.toString().toLowerCase().trim() === 'true'
|
|
34
|
+
|
|
35
|
+
let deliveryOrders: DeliveryOrder[] = await getRepository(DeliveryOrder).find({
|
|
23
36
|
where: { releaseGood },
|
|
24
37
|
relations: ['orderInventories', 'orderInventories.inventory', 'orderInventories.product']
|
|
25
38
|
})
|
|
26
39
|
|
|
40
|
+
if (useQcSku) {
|
|
41
|
+
deliveryOrders = deliveryOrders
|
|
42
|
+
.map((do_) => {
|
|
43
|
+
const liveOIs = do_.orderInventories.filter(
|
|
44
|
+
(oi) => oi.status !== ORDER_INVENTORY_STATUS.TERMINATED
|
|
45
|
+
)
|
|
46
|
+
return { ...do_, orderInventories: liveOIs }
|
|
47
|
+
})
|
|
48
|
+
.filter((do_) => do_.orderInventories.length > 0)
|
|
49
|
+
}
|
|
50
|
+
|
|
27
51
|
return {
|
|
28
52
|
completable: completable,
|
|
29
53
|
deliveryOrders: deliveryOrders
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getLoadingTask } from './get-loading-task'
|
|
2
2
|
import { sortItem } from './sort-item'
|
|
3
3
|
import { findLoadableReleaseGood } from './find-loadable-release-good'
|
|
4
|
+
import { findLoadableReleaseGoodByBin } from './find-loadable-release-good-by-bin'
|
|
4
5
|
import { loadingWorksheetv2 } from './loading-worksheet-v2'
|
|
5
6
|
import { loadByQty } from './load-by-qty'
|
|
6
7
|
import { myLoadingAssignmentStatus } from './my-loading-assignment-status'
|
|
@@ -11,6 +12,7 @@ import { completeLoad } from './complete-load'
|
|
|
11
12
|
|
|
12
13
|
export const Query = {
|
|
13
14
|
...findLoadableReleaseGood,
|
|
15
|
+
...findLoadableReleaseGoodByBin,
|
|
14
16
|
...loadingWorksheetv2,
|
|
15
17
|
...myLoadingAssignmentStatus,
|
|
16
18
|
...getDeliveryOrders
|
|
@@ -36,7 +36,10 @@ export const loadByQty = {
|
|
|
36
36
|
domain,
|
|
37
37
|
releaseGood,
|
|
38
38
|
type: WORKSHEET_TYPE.LOADING,
|
|
39
|
-
status:
|
|
39
|
+
status: In([
|
|
40
|
+
WORKSHEET_STATUS.EXECUTING,
|
|
41
|
+
WORKSHEET_STATUS.PARTIAL_EXECUTING
|
|
42
|
+
])
|
|
40
43
|
},
|
|
41
44
|
relations: ['worksheetDetails', 'worksheetDetails.targetInventory', 'worksheetDetails.domain']
|
|
42
45
|
})
|
|
@@ -47,8 +50,17 @@ export const loadByQty = {
|
|
|
47
50
|
|
|
48
51
|
const oiIds = worksheet.worksheetDetails.map((wsd: WorksheetDetail) => wsd.targetInventory.id)
|
|
49
52
|
const orderInventories: OrderInventory[] = await tx.getRepository(OrderInventory).find({
|
|
50
|
-
where: { id: In(oiIds) },
|
|
51
|
-
relations: [
|
|
53
|
+
where: { id: In(oiIds) },
|
|
54
|
+
relations: [
|
|
55
|
+
'inventory',
|
|
56
|
+
'domain',
|
|
57
|
+
'bizplace',
|
|
58
|
+
'releaseGood',
|
|
59
|
+
'product',
|
|
60
|
+
'productDetail',
|
|
61
|
+
'binLocation',
|
|
62
|
+
'orderProduct'
|
|
63
|
+
]
|
|
52
64
|
})
|
|
53
65
|
|
|
54
66
|
const updatedOrderInventories: OrderInventory[] = []
|
|
@@ -58,7 +70,7 @@ export const loadByQty = {
|
|
|
58
70
|
foundWsd => foundWsd.name === wsd.name
|
|
59
71
|
)
|
|
60
72
|
let orderInventory = orderInventories.find(oi => oi.id === foundWorksheetDetail.targetInventory.id)
|
|
61
|
-
|
|
73
|
+
|
|
62
74
|
//validate oi status and do is not yet generated
|
|
63
75
|
if (orderInventory.status === ORDER_INVENTORY_STATUS.LOADED || orderInventory.deliveryOrderId !== null) {
|
|
64
76
|
continue
|
|
@@ -88,7 +100,7 @@ export const loadByQty = {
|
|
|
88
100
|
//split oi
|
|
89
101
|
//create new order inventory with remaining quantity
|
|
90
102
|
const remainingQty = orderInventory.releaseQty - wsd.loadedQty
|
|
91
|
-
|
|
103
|
+
const newOrderInventory = tx.getRepository(OrderInventory).create({
|
|
92
104
|
...orderInventory,
|
|
93
105
|
id: undefined,
|
|
94
106
|
name: OrderNoGenerator.orderInventory(),
|
|
@@ -96,10 +108,10 @@ export const loadByQty = {
|
|
|
96
108
|
releaseUomValue: (orderInventory.releaseUomValue / orderInventory.releaseQty) * remainingQty,
|
|
97
109
|
pickedQty: orderInventory.pickedQty - wsd.loadedQty,
|
|
98
110
|
sortedQty: orderInventory.sortedQty === 0 ? 0 : orderInventory.sortedQty - wsd.loadedQty,
|
|
99
|
-
status:
|
|
111
|
+
status: orderInventory.status,
|
|
100
112
|
updater: user,
|
|
101
113
|
updatedAt: new Date()
|
|
102
|
-
|
|
114
|
+
})
|
|
103
115
|
|
|
104
116
|
await tx.getRepository(OrderInventory).save(newOrderInventory)
|
|
105
117
|
|
|
@@ -1,35 +1,118 @@
|
|
|
1
1
|
import { EntityManager } from 'typeorm'
|
|
2
|
+
import { In } from 'typeorm'
|
|
2
3
|
|
|
3
4
|
import { Domain } from '@things-factory/shell'
|
|
4
5
|
import { ReleaseGood, ORDER_INVENTORY_STATUS, ORDER_STATUS } from '@things-factory/sales-base'
|
|
5
6
|
import { Worksheet, WorksheetDetail, WORKSHEET_TYPE, WORKSHEET_STATUS } from '@things-factory/worksheet-base'
|
|
6
7
|
import { Setting } from '@things-factory/setting-base'
|
|
7
8
|
|
|
9
|
+
const FILTER_TYPES = {
|
|
10
|
+
QC: 'qc',
|
|
11
|
+
LOADING: 'loading'
|
|
12
|
+
} as const
|
|
13
|
+
|
|
14
|
+
// Types
|
|
15
|
+
interface WorksheetInfo {
|
|
16
|
+
worksheet: {
|
|
17
|
+
id: string
|
|
18
|
+
name: string
|
|
19
|
+
type: string
|
|
20
|
+
status: string
|
|
21
|
+
}
|
|
22
|
+
bizplaceName: string
|
|
23
|
+
startedAt: string | null
|
|
24
|
+
releaseGood: {
|
|
25
|
+
id: string
|
|
26
|
+
name: string
|
|
27
|
+
status: string
|
|
28
|
+
attentionCompany?: string
|
|
29
|
+
refNo?: string
|
|
30
|
+
refNo2?: string
|
|
31
|
+
refNo3?: string
|
|
32
|
+
remark?: string
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface WorksheetDetailInfo {
|
|
37
|
+
id: string
|
|
38
|
+
name: string
|
|
39
|
+
batchId: string
|
|
40
|
+
releaseQty: number
|
|
41
|
+
pickedQty: number
|
|
42
|
+
sortedQty: number
|
|
43
|
+
loadedQty: number
|
|
44
|
+
status: string
|
|
45
|
+
packingType: string
|
|
46
|
+
packingSize: string
|
|
47
|
+
expirationDate?: string
|
|
48
|
+
binLocation: {
|
|
49
|
+
name?: string
|
|
50
|
+
}
|
|
51
|
+
productName?: string
|
|
52
|
+
productSku?: string
|
|
53
|
+
relatedOrderInv: {
|
|
54
|
+
id?: string
|
|
55
|
+
batchId?: string
|
|
56
|
+
packingType?: string
|
|
57
|
+
product?: {
|
|
58
|
+
id?: string
|
|
59
|
+
sku?: string
|
|
60
|
+
name?: string
|
|
61
|
+
}
|
|
62
|
+
productDetail?: {
|
|
63
|
+
id?: string
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface LoadingWorksheetResponse {
|
|
69
|
+
worksheetInfo: WorksheetInfo
|
|
70
|
+
worksheetDetailInfos: WorksheetDetailInfo[]
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Helper functions
|
|
74
|
+
function formatDate(date: Date | null): string | null {
|
|
75
|
+
if (!date) return null
|
|
76
|
+
return new Date(date).toISOString().slice(0, 19).replace('T', ' ')
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function shouldFilterBySortedQty(releaseGoodStatus: string, disableQC: boolean): boolean {
|
|
80
|
+
return releaseGoodStatus !== ORDER_STATUS.LOADING || (releaseGoodStatus === ORDER_STATUS.LOADING && !disableQC)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function getSortedQty(releaseGoodStatus: string, disableQC: boolean, pickedQty: number, sortedQty: number): number {
|
|
84
|
+
return releaseGoodStatus === ORDER_STATUS.LOADING && disableQC ? pickedQty : sortedQty
|
|
85
|
+
}
|
|
86
|
+
|
|
8
87
|
export const loadingWorksheetv2 = {
|
|
9
|
-
async loadingWorksheetv2(_: any, { orderNo, filter = null }, context: any) {
|
|
88
|
+
async loadingWorksheetv2(_: any, { orderNo, filter = null }, context: any): Promise<LoadingWorksheetResponse> {
|
|
10
89
|
const { domain, tx }: { domain: Domain; tx: EntityManager } = context.state
|
|
11
90
|
|
|
12
|
-
if (process.env.NODE_ENV
|
|
91
|
+
if (process.env.NODE_ENV === 'development') {
|
|
13
92
|
console.time('loadingWorksheetv2')
|
|
14
93
|
}
|
|
94
|
+
|
|
95
|
+
// Find release good
|
|
15
96
|
const releaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
|
|
16
97
|
where: { domain, name: orderNo }
|
|
17
98
|
})
|
|
18
99
|
|
|
19
100
|
if (!releaseGood) throw new Error('Release good not found')
|
|
20
101
|
|
|
102
|
+
// Find worksheet
|
|
21
103
|
const worksheet: Worksheet = await tx.getRepository(Worksheet).findOne({
|
|
22
104
|
where: {
|
|
23
105
|
domain,
|
|
24
106
|
releaseGood,
|
|
25
107
|
type: WORKSHEET_TYPE.LOADING,
|
|
26
|
-
status:
|
|
108
|
+
status: In([WORKSHEET_STATUS.EXECUTING, WORKSHEET_STATUS.PARTIAL_EXECUTING])
|
|
27
109
|
},
|
|
28
110
|
relations: ['bizplace']
|
|
29
111
|
})
|
|
30
112
|
|
|
31
113
|
if (!worksheet) throw new Error('No loading worksheet found for order ' + orderNo)
|
|
32
114
|
|
|
115
|
+
// Get QC setting
|
|
33
116
|
const disableQcSetting: Setting = await tx.getRepository(Setting).findOne({
|
|
34
117
|
where: {
|
|
35
118
|
domain,
|
|
@@ -37,8 +120,9 @@ export const loadingWorksheetv2 = {
|
|
|
37
120
|
}
|
|
38
121
|
})
|
|
39
122
|
|
|
40
|
-
const disableQc = disableQcSetting?.value === 'true'
|
|
123
|
+
const disableQc = disableQcSetting?.value === 'true'
|
|
41
124
|
|
|
125
|
+
// Build worksheet details query
|
|
42
126
|
const qb = tx
|
|
43
127
|
.getRepository(WorksheetDetail)
|
|
44
128
|
.createQueryBuilder('worksheetDetail')
|
|
@@ -51,11 +135,13 @@ export const loadingWorksheetv2 = {
|
|
|
51
135
|
.where('worksheetDetail.domain_id = :domainId', { domainId: domain.id })
|
|
52
136
|
.andWhere('worksheetDetail.worksheet_id = :worksheetId', { worksheetId: worksheet.id })
|
|
53
137
|
|
|
138
|
+
// Check if all items are deactivated
|
|
54
139
|
const allWorksheetDetails: WorksheetDetail[] = await qb.getMany()
|
|
55
|
-
if (allWorksheetDetails.every(wsd => wsd.status
|
|
140
|
+
if (allWorksheetDetails.every(wsd => wsd.status === WORKSHEET_STATUS.DEACTIVATED)) {
|
|
56
141
|
throw new Error('Item in this RO is not ready to be loaded')
|
|
57
142
|
}
|
|
58
143
|
|
|
144
|
+
// Apply filters
|
|
59
145
|
qb.andWhere('targetInventory.status NOT IN (:...excludeStatuses)', {
|
|
60
146
|
excludeStatuses: [ORDER_INVENTORY_STATUS.TERMINATED, ORDER_INVENTORY_STATUS.RETURNING]
|
|
61
147
|
})
|
|
@@ -64,17 +150,13 @@ export const loadingWorksheetv2 = {
|
|
|
64
150
|
wsdStatus: [WORKSHEET_STATUS.EXECUTING]
|
|
65
151
|
})
|
|
66
152
|
|
|
67
|
-
if (filter ===
|
|
68
|
-
qb.andWhere('targetInventory.status = :loadingStatus', { loadingStatus: ORDER_INVENTORY_STATUS.
|
|
153
|
+
if (filter === FILTER_TYPES.QC) {
|
|
154
|
+
qb.andWhere('targetInventory.status = :loadingStatus', { loadingStatus: ORDER_INVENTORY_STATUS.SORTING })
|
|
69
155
|
qb.andWhere('targetInventory.sortedQty <> targetInventory.pickedQty')
|
|
70
156
|
}
|
|
71
157
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const shouldFilterBySortedQty =
|
|
75
|
-
releaseGood.status !== ORDER_STATUS.LOADING || (releaseGood.status === ORDER_STATUS.LOADING && !disableQc)
|
|
76
|
-
|
|
77
|
-
if (shouldFilterBySortedQty) {
|
|
158
|
+
if (filter === FILTER_TYPES.LOADING) {
|
|
159
|
+
if (shouldFilterBySortedQty(releaseGood.status, disableQc)) {
|
|
78
160
|
qb.andWhere('targetInventory.sortedQty > 0')
|
|
79
161
|
}
|
|
80
162
|
}
|
|
@@ -82,13 +164,22 @@ export const loadingWorksheetv2 = {
|
|
|
82
164
|
qb.orderBy('product.name', 'ASC')
|
|
83
165
|
|
|
84
166
|
const worksheetDetails = await qb.getMany()
|
|
85
|
-
|
|
167
|
+
|
|
168
|
+
if (process.env.NODE_ENV === 'development') {
|
|
169
|
+
console.timeEnd('loadingWorksheetv2')
|
|
170
|
+
}
|
|
171
|
+
|
|
86
172
|
return await mapdata(worksheet, worksheetDetails, releaseGood, disableQc)
|
|
87
173
|
}
|
|
88
174
|
}
|
|
89
175
|
|
|
90
|
-
async function mapdata(
|
|
91
|
-
|
|
176
|
+
async function mapdata(
|
|
177
|
+
worksheet: Worksheet,
|
|
178
|
+
worksheetDetails: WorksheetDetail[],
|
|
179
|
+
releaseGood: ReleaseGood,
|
|
180
|
+
disableQC: boolean
|
|
181
|
+
): Promise<LoadingWorksheetResponse> {
|
|
182
|
+
const worksheetInfo: WorksheetInfo = {
|
|
92
183
|
worksheet: {
|
|
93
184
|
id: worksheet.id,
|
|
94
185
|
name: worksheet.name,
|
|
@@ -96,7 +187,7 @@ async function mapdata(worksheet, worksheetDetails, releaseGood, disableQC) {
|
|
|
96
187
|
status: worksheet.status
|
|
97
188
|
},
|
|
98
189
|
bizplaceName: worksheet.bizplace?.name,
|
|
99
|
-
startedAt:
|
|
190
|
+
startedAt: formatDate(worksheet.startedAt),
|
|
100
191
|
releaseGood: {
|
|
101
192
|
id: releaseGood.id,
|
|
102
193
|
name: releaseGood.name,
|
|
@@ -108,16 +199,19 @@ async function mapdata(worksheet, worksheetDetails, releaseGood, disableQC) {
|
|
|
108
199
|
remark: releaseGood?.remark
|
|
109
200
|
}
|
|
110
201
|
}
|
|
111
|
-
|
|
202
|
+
|
|
203
|
+
const worksheetDetailInfos: WorksheetDetailInfo[] = worksheetDetails.map(wsd => ({
|
|
112
204
|
id: wsd.id,
|
|
113
205
|
name: wsd.name,
|
|
114
206
|
batchId: wsd.targetInventory.batchId || '-',
|
|
115
207
|
releaseQty: wsd.targetInventory.releaseQty,
|
|
116
208
|
pickedQty: wsd.targetInventory.pickedQty,
|
|
117
|
-
sortedQty:
|
|
118
|
-
releaseGood.status
|
|
119
|
-
|
|
120
|
-
|
|
209
|
+
sortedQty: getSortedQty(
|
|
210
|
+
releaseGood.status,
|
|
211
|
+
disableQC,
|
|
212
|
+
wsd.targetInventory.pickedQty,
|
|
213
|
+
wsd.targetInventory.sortedQty
|
|
214
|
+
),
|
|
121
215
|
loadedQty: wsd.targetInventory.loadedQty,
|
|
122
216
|
status: wsd.status,
|
|
123
217
|
packingType: wsd.targetInventory.packingType,
|