@things-factory/sales-base 4.3.508 → 4.3.510
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/service/draft-release-good/draft-release-good-create.js +28 -20
- package/dist-server/service/draft-release-good/draft-release-good-create.js.map +1 -1
- package/dist-server/service/draft-release-good/draft-release-good-query.js +58 -188
- package/dist-server/service/draft-release-good/draft-release-good-query.js.map +1 -1
- package/dist-server/service/order-inventory/order-inventory-query.js +59 -18
- package/dist-server/service/order-inventory/order-inventory-query.js.map +1 -1
- package/dist-server/service/release-good/release-good-mutation.js +5 -2
- package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
- package/dist-server/service/release-good/release-good-query.js +92 -66
- package/dist-server/service/release-good/release-good-query.js.map +1 -1
- package/dist-server/service/release-good/release-good-types.js +8 -0
- package/dist-server/service/release-good/release-good-types.js.map +1 -1
- package/dist-server/service/release-good/release-good.js +4 -0
- package/dist-server/service/release-good/release-good.js.map +1 -1
- package/dist-server/utils/inventory-util.js +8 -2
- package/dist-server/utils/inventory-util.js.map +1 -1
- package/package.json +4 -4
- package/server/service/draft-release-good/draft-release-good-create.ts +41 -31
- package/server/service/draft-release-good/draft-release-good-query.ts +66 -234
- package/server/service/order-inventory/order-inventory-query.ts +65 -18
- package/server/service/release-good/release-good-mutation.ts +10 -2
- package/server/service/release-good/release-good-query.ts +46 -23
- package/server/service/release-good/release-good-types.ts +5 -0
- package/server/service/release-good/release-good.ts +3 -0
- package/server/utils/inventory-util.ts +12 -2
|
@@ -381,23 +381,64 @@ export class OrderInventoryQuery {
|
|
|
381
381
|
|
|
382
382
|
await tx.query(
|
|
383
383
|
`
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
(
|
|
387
|
-
|
|
388
|
-
rg3.
|
|
389
|
-
rg3.
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
384
|
+
create temp table temp_route_label ON COMMIT drop as (
|
|
385
|
+
SELECT
|
|
386
|
+
DISTINCT(ot.name) AS "toteNumber",
|
|
387
|
+
rg3.id AS "releaseGoodId",
|
|
388
|
+
rg3.name AS "releaseGoodName",
|
|
389
|
+
rg3.ref_no,
|
|
390
|
+
rg3.ref_no_2,
|
|
391
|
+
rg3.ref_no_3,
|
|
392
|
+
rg3.route_id AS "routeId",
|
|
393
|
+
rg3.store_id AS "storeId",
|
|
394
|
+
rg3.store_name AS "storeName",
|
|
395
|
+
rg3.stop_id AS "stopId",
|
|
396
|
+
rg3.created_at AS "createdAt",
|
|
397
|
+
pd.packing_type AS "packingType",
|
|
398
|
+
pd.packing_size AS "packingSize",
|
|
399
|
+
oi.product_id AS "productId",
|
|
400
|
+
oi.product_detail_id AS "productDetailId",
|
|
401
|
+
SUM(CASE WHEN ot.name IS NULL THEN oi.release_qty ELSE 0 END) AS "releaseQty",
|
|
402
|
+
CASE WHEN ot.name IS NULL THEN p.sku ELSE NULL END AS "productSKU",
|
|
403
|
+
CASE WHEN ot.name IS NULL THEN p.name ELSE NULL END AS "productName",
|
|
404
|
+
CASE WHEN ot.name IS NULL AND oi.bin_location_id IS NOT NULL THEN l.name ELSE NULL END AS "binNumber",
|
|
405
|
+
CASE WHEN ot.name IS NULL THEN l2."name" ELSE NULL END AS "locationName"
|
|
406
|
+
FROM
|
|
407
|
+
order_inventories oi
|
|
408
|
+
INNER JOIN release_goods rg3 ON rg3.id = oi.release_good_id
|
|
409
|
+
INNER JOIN products p ON p.id = oi.product_id
|
|
410
|
+
INNER JOIN product_details pd ON pd.product_id = p.id
|
|
411
|
+
INNER JOIN inventories i ON i.id = oi.inventory_id
|
|
412
|
+
LEFT JOIN locations l ON l.id = oi.bin_location_id
|
|
413
|
+
LEFT JOIN locations l2 ON l2.id = i.location_id
|
|
414
|
+
LEFT JOIN order_tote_items oti ON oti.order_inventory_id = oi.id
|
|
415
|
+
LEFT JOIN order_totes ot ON ot.id = oti.order_tote_id
|
|
416
|
+
WHERE
|
|
417
|
+
oi.release_good_id IN (${
|
|
418
|
+
releaseOrderId.length > 0 ? releaseOrderId?.map(itm => `'${itm.id}'`).join(',') : null
|
|
419
|
+
})
|
|
420
|
+
GROUP BY
|
|
421
|
+
ot.name,
|
|
422
|
+
rg3.id,
|
|
423
|
+
rg3.name,
|
|
424
|
+
rg3.ref_no,
|
|
425
|
+
rg3.ref_no_2,
|
|
426
|
+
rg3.ref_no_3,
|
|
427
|
+
rg3.route_id,
|
|
428
|
+
rg3.store_id,
|
|
429
|
+
rg3.store_name,
|
|
430
|
+
rg3.stop_id,
|
|
431
|
+
rg3.created_at,
|
|
432
|
+
pd.packing_type,
|
|
433
|
+
pd.packing_size,
|
|
434
|
+
oi.product_id,
|
|
435
|
+
oi.product_detail_id,
|
|
436
|
+
oi.bin_location_id,
|
|
437
|
+
l.name,
|
|
438
|
+
l2."name",
|
|
439
|
+
p.sku,
|
|
440
|
+
p.name
|
|
441
|
+
)
|
|
401
442
|
`
|
|
402
443
|
)
|
|
403
444
|
|
|
@@ -528,7 +569,13 @@ export class OrderInventoryQuery {
|
|
|
528
569
|
)
|
|
529
570
|
|
|
530
571
|
items = items.reduce((prev, curr) => {
|
|
531
|
-
let foundItemIndex = prev.findIndex(
|
|
572
|
+
let foundItemIndex = prev.findIndex(
|
|
573
|
+
items =>
|
|
574
|
+
items.productSKU == curr.productSKU &&
|
|
575
|
+
items.releaseGoodId == curr.releaseGoodId &&
|
|
576
|
+
items.locationName == curr.locationName
|
|
577
|
+
)
|
|
578
|
+
|
|
532
579
|
if (foundItemIndex >= 0) {
|
|
533
580
|
let object = { packingType: curr.packingType, packingSize: curr.packingSize }
|
|
534
581
|
prev[foundItemIndex].productDetails.push(object)
|
|
@@ -1626,7 +1626,12 @@ export async function bulkGenerateReleaseGood(
|
|
|
1626
1626
|
locationSortingRules,
|
|
1627
1627
|
bizplace,
|
|
1628
1628
|
warehouseDomain,
|
|
1629
|
-
tx
|
|
1629
|
+
tx,
|
|
1630
|
+
oi.batchId,
|
|
1631
|
+
'',
|
|
1632
|
+
null,
|
|
1633
|
+
oi.cartonId,
|
|
1634
|
+
oi.expirationDate
|
|
1630
1635
|
)
|
|
1631
1636
|
|
|
1632
1637
|
finalOrderInventories.push(
|
|
@@ -1898,7 +1903,10 @@ function extractRawReleaseGoods(rawReleaseGoods): Partial<ReleaseGood[]> {
|
|
|
1898
1903
|
packingSize: item.packingSize,
|
|
1899
1904
|
uom: item.uom,
|
|
1900
1905
|
releaseQty: item.releaseQty,
|
|
1901
|
-
releaseUomValue: item.releaseUomValue
|
|
1906
|
+
releaseUomValue: item.releaseUomValue,
|
|
1907
|
+
batchId: item?.batchId || null,
|
|
1908
|
+
cartonId: item?.cartonId || null,
|
|
1909
|
+
expirationDate: item?.expirationDate || null
|
|
1902
1910
|
}
|
|
1903
1911
|
]
|
|
1904
1912
|
})
|
|
@@ -933,11 +933,13 @@ export async function bulkReleaseGoodsAvailableItemsFunction(
|
|
|
933
933
|
`,
|
|
934
934
|
[json_oi, companyBizplaceId.id]
|
|
935
935
|
)
|
|
936
|
+
const useDetailedQuery = rawReleaseGoods.some(raw => raw.batchId || raw.cartonId || raw.expirationDate)
|
|
936
937
|
|
|
937
938
|
let availableItems = await tx.query(
|
|
938
939
|
`
|
|
939
|
-
|
|
940
|
+
WITH inv AS (
|
|
940
941
|
SELECT i.product_id, foo.product_detail_id, foo.sku, foo.product_info, i.packing_type, i.packing_size, i.uom,
|
|
942
|
+
${useDetailedQuery ? ' i.batch_id, i.carton_id, i.expiration_date,' : ''}
|
|
941
943
|
SUM(i.qty - COALESCE(i.locked_qty, 0)) - COALESCE(
|
|
942
944
|
(
|
|
943
945
|
SELECT SUM(oi.release_qty) FROM order_inventories oi
|
|
@@ -961,8 +963,7 @@ export async function bulkReleaseGoodsAvailableItemsFunction(
|
|
|
961
963
|
AND oi.bizplace_id = $2
|
|
962
964
|
), 0) as "remain_uom_value"
|
|
963
965
|
FROM inventories i
|
|
964
|
-
LEFT JOIN locations l
|
|
965
|
-
ON i.location_id = l.id
|
|
966
|
+
LEFT JOIN locations l ON i.location_id = l.id
|
|
966
967
|
INNER JOIN (
|
|
967
968
|
SELECT rrg.product_id, rrg.product_detail_id, rrg.sku, rrg.product_info, rrg.packing_type, rrg.packing_size, rrg.uom
|
|
968
969
|
FROM raw_release_goods rrg
|
|
@@ -978,8 +979,9 @@ export async function bulkReleaseGoodsAvailableItemsFunction(
|
|
|
978
979
|
AND i.obsolete = false
|
|
979
980
|
AND i.transfer_qty <= 0
|
|
980
981
|
AND i.transfer_uom_value <= 0
|
|
981
|
-
GROUP BY i.product_id, foo.product_detail_id, foo.sku,foo.product_info, i.packing_type, i.packing_size, i.uom
|
|
982
|
-
|
|
982
|
+
GROUP BY i.product_id, foo.product_detail_id, foo.sku, foo.product_info, i.packing_type, i.packing_size, i.uom
|
|
983
|
+
${useDetailedQuery ? ', i.batch_id, i.carton_id, i.expiration_date' : ''}
|
|
984
|
+
ORDER BY foo.sku, remain_qty DESC
|
|
983
985
|
) SELECT * FROM inv WHERE remain_qty > 0
|
|
984
986
|
`,
|
|
985
987
|
[domain.id, bizplaceId, LOCATION_TYPE.QUARANTINE, LOCATION_TYPE.RESERVE]
|
|
@@ -997,7 +999,10 @@ export async function bulkReleaseGoodsAvailableItemsFunction(
|
|
|
997
999
|
packingSize: Number(item.packing_size || 0),
|
|
998
1000
|
uom: item.uom,
|
|
999
1001
|
remainQty: item.remain_qty,
|
|
1000
|
-
remainUomValue: item.remain_uom_value
|
|
1002
|
+
remainUomValue: item.remain_uom_value,
|
|
1003
|
+
batchId: item.batch_id ? item.batch_id : null,
|
|
1004
|
+
cartonId: item.carton_id ? item.carton_id : null,
|
|
1005
|
+
expirationDate: item.expiration_date ? _getStdDateStr(new Date(item.expiration_date)) : null
|
|
1001
1006
|
}
|
|
1002
1007
|
})
|
|
1003
1008
|
|
|
@@ -1006,9 +1011,26 @@ export async function bulkReleaseGoodsAvailableItemsFunction(
|
|
|
1006
1011
|
|
|
1007
1012
|
function _extractData(rawData, validatedData) {
|
|
1008
1013
|
return rawData.map(raw => {
|
|
1009
|
-
|
|
1010
|
-
|
|
1014
|
+
let errMsg
|
|
1015
|
+
let comparison = ['packingType', 'packingSize', 'uom']
|
|
1016
|
+
let data = validatedData
|
|
1017
|
+
if (raw.batchId) {
|
|
1018
|
+
data = data.filter(val => val.batchId === raw.batchId)
|
|
1019
|
+
comparison.push('batchId')
|
|
1020
|
+
if (!data.length) errMsg = errMsg ? errMsg : 'batch no not matched'
|
|
1021
|
+
}
|
|
1022
|
+
if (raw.cartonId) {
|
|
1023
|
+
data = data.filter(val => val.cartonId === raw.cartonId)
|
|
1024
|
+
comparison.push('cartonId')
|
|
1025
|
+
if (!data.length) errMsg = errMsg ? errMsg : 'carton id not matched'
|
|
1026
|
+
}
|
|
1027
|
+
if (raw.expirationDate) {
|
|
1028
|
+
data = data.filter(val => val.expirationDate === raw.expirationDate)
|
|
1029
|
+
comparison.push('expirationDate')
|
|
1030
|
+
if (!data.length) errMsg = errMsg ? errMsg : 'expiration date not matched'
|
|
1031
|
+
}
|
|
1011
1032
|
|
|
1033
|
+
const idx = data.findIndex(val => {
|
|
1012
1034
|
let a: any = {},
|
|
1013
1035
|
b: any = {}
|
|
1014
1036
|
|
|
@@ -1031,32 +1053,32 @@ function _extractData(rawData, validatedData) {
|
|
|
1031
1053
|
if (idx >= 0) {
|
|
1032
1054
|
// assign qty to rawData as much as possible
|
|
1033
1055
|
releaseUomValue =
|
|
1034
|
-
(Math.round((
|
|
1056
|
+
(Math.round((data[idx]?.remainUomValue / data[idx]?.remainQty) * 100) / 100) * raw.releaseQty
|
|
1035
1057
|
|
|
1036
1058
|
raw.assignedQty =
|
|
1037
|
-
|
|
1059
|
+
data[idx].remainQty >= raw.releaseQty
|
|
1038
1060
|
? raw.releaseQty > 0
|
|
1039
1061
|
? raw.releaseQty
|
|
1040
1062
|
: 0
|
|
1041
|
-
:
|
|
1063
|
+
: data[idx].remainQty
|
|
1042
1064
|
|
|
1043
1065
|
raw.assignedUomValue =
|
|
1044
|
-
|
|
1066
|
+
data[idx].remainUomValue >= releaseUomValue
|
|
1045
1067
|
? releaseUomValue > 0
|
|
1046
1068
|
? releaseUomValue
|
|
1047
1069
|
: 0
|
|
1048
|
-
:
|
|
1070
|
+
: data[idx].remainUomValue
|
|
1049
1071
|
|
|
1050
1072
|
// deduct qty & uomValue from validateData
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
raw.productId =
|
|
1055
|
-
raw.productDetailId =
|
|
1056
|
-
raw.productInfo =
|
|
1057
|
-
raw.packingType =
|
|
1058
|
-
raw.packingSize =
|
|
1059
|
-
raw.uom =
|
|
1073
|
+
data[idx].remainQty -= raw.assignedQty
|
|
1074
|
+
data[idx].remainUomValue -= raw.assignedUomValue
|
|
1075
|
+
|
|
1076
|
+
raw.productId = data[idx].productId
|
|
1077
|
+
raw.productDetailId = data[idx].productDetailId
|
|
1078
|
+
raw.productInfo = data[idx].productInfo
|
|
1079
|
+
raw.packingType = data[idx].packingType
|
|
1080
|
+
raw.packingSize = data[idx].packingSize
|
|
1081
|
+
raw.uom = data.uom
|
|
1060
1082
|
} else {
|
|
1061
1083
|
raw.assignedQty = 0
|
|
1062
1084
|
raw.assignedUomValue = 0
|
|
@@ -1069,7 +1091,8 @@ function _extractData(rawData, validatedData) {
|
|
|
1069
1091
|
...raw,
|
|
1070
1092
|
releaseUomValue,
|
|
1071
1093
|
errorMsg:
|
|
1072
|
-
|
|
1094
|
+
errMsg ? errMsg
|
|
1095
|
+
: !raw.productId || !raw.productDetailId
|
|
1073
1096
|
? 'inventory or product not found'
|
|
1074
1097
|
: raw.releaseQty <= 0 || raw.releaseQty % 1 !== 0
|
|
1075
1098
|
? 'invalid release qty'
|
|
@@ -626,7 +626,9 @@ export const InventoryUtil = {
|
|
|
626
626
|
trxMgr: EntityManager,
|
|
627
627
|
batchId?: string,
|
|
628
628
|
preferLocation: string = null,
|
|
629
|
-
recall: boolean = null
|
|
629
|
+
recall: boolean = null,
|
|
630
|
+
cartonId?: string,
|
|
631
|
+
expirationDate?: Date
|
|
630
632
|
): Promise<OrderInventory[]> {
|
|
631
633
|
let strictProduct = 'false'
|
|
632
634
|
|
|
@@ -681,7 +683,15 @@ export const InventoryUtil = {
|
|
|
681
683
|
})
|
|
682
684
|
|
|
683
685
|
if (batchId) {
|
|
684
|
-
qb.andWhere('"iv"."batch_id" = :batchId', { batchId
|
|
686
|
+
qb.andWhere('"iv"."batch_id" = :batchId', { batchId })
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
if (cartonId) {
|
|
690
|
+
qb.andWhere('"iv"."carton_id" = :cartonId', { cartonId })
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
if (expirationDate) {
|
|
694
|
+
qb.andWhere('"iv"."expiration_date" = :expirationDate', { expirationDate })
|
|
685
695
|
}
|
|
686
696
|
|
|
687
697
|
if (preferLocation) {
|