@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.
Files changed (25) hide show
  1. package/dist-server/service/draft-release-good/draft-release-good-create.js +28 -20
  2. package/dist-server/service/draft-release-good/draft-release-good-create.js.map +1 -1
  3. package/dist-server/service/draft-release-good/draft-release-good-query.js +58 -188
  4. package/dist-server/service/draft-release-good/draft-release-good-query.js.map +1 -1
  5. package/dist-server/service/order-inventory/order-inventory-query.js +59 -18
  6. package/dist-server/service/order-inventory/order-inventory-query.js.map +1 -1
  7. package/dist-server/service/release-good/release-good-mutation.js +5 -2
  8. package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
  9. package/dist-server/service/release-good/release-good-query.js +92 -66
  10. package/dist-server/service/release-good/release-good-query.js.map +1 -1
  11. package/dist-server/service/release-good/release-good-types.js +8 -0
  12. package/dist-server/service/release-good/release-good-types.js.map +1 -1
  13. package/dist-server/service/release-good/release-good.js +4 -0
  14. package/dist-server/service/release-good/release-good.js.map +1 -1
  15. package/dist-server/utils/inventory-util.js +8 -2
  16. package/dist-server/utils/inventory-util.js.map +1 -1
  17. package/package.json +4 -4
  18. package/server/service/draft-release-good/draft-release-good-create.ts +41 -31
  19. package/server/service/draft-release-good/draft-release-good-query.ts +66 -234
  20. package/server/service/order-inventory/order-inventory-query.ts +65 -18
  21. package/server/service/release-good/release-good-mutation.ts +10 -2
  22. package/server/service/release-good/release-good-query.ts +46 -23
  23. package/server/service/release-good/release-good-types.ts +5 -0
  24. package/server/service/release-good/release-good.ts +3 -0
  25. 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
- create temp table temp_route_label ON COMMIT drop as (
385
- select distinct(ot.name) as "toteNumber", oi.id, rg3.name as "releaseGoodName",rg3.ref_no,rg3.ref_no_2,rg3.ref_no_3, (case when ot.name is null then oi.release_qty else null end) as "releaseQty",
386
- (case when ot.name is null then p.sku else null end) as "productSKU", (case when ot.name is null then p.name else null end) as "productName",
387
- (case when ot.name is null and oi.bin_location_id is not null then l.name else null end) as "binNumber", rg3.route_id as "routeId", rg3.store_id as "storeId",
388
- rg3.store_name as "storeName", rg3.stop_id as "stopId",(case when ot.name is null then l2."name" else null end )as "locationName",
389
- rg3.created_at as "createdAt", pd.packing_type as "packingType", pd.packing_size as "packingSize" from order_inventories oi
390
- inner join release_goods rg3 on rg3.id = oi.release_good_id
391
- inner join products p on p.id = oi.product_id
392
- inner join product_details pd on pd.product_id = p.id
393
- inner join inventories i on i.id = oi.inventory_id
394
- left join locations l on l.id = oi.bin_location_id
395
- left join locations l2 on l2.id = i.location_id
396
- left join order_tote_items oti on oti.order_inventory_id = oi.id
397
- left join order_totes ot on ot.id = oti.order_tote_id
398
- where oi.release_good_id in
399
- (${releaseOrderId.length > 0 ? releaseOrderId?.map(itm => `'${itm.id}'`).join(',') : null})
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(items => items.id == curr.id)
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
- WITH inv AS (
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
- ORDER BY foo.sku, remain_qty
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
- const idx = validatedData.findIndex(val => {
1010
- const comparison = ['packingType', 'packingSize', 'uom']
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((validatedData[idx]?.remainUomValue / validatedData[idx]?.remainQty) * 100) / 100) * raw.releaseQty
1056
+ (Math.round((data[idx]?.remainUomValue / data[idx]?.remainQty) * 100) / 100) * raw.releaseQty
1035
1057
 
1036
1058
  raw.assignedQty =
1037
- validatedData[idx].remainQty >= raw.releaseQty
1059
+ data[idx].remainQty >= raw.releaseQty
1038
1060
  ? raw.releaseQty > 0
1039
1061
  ? raw.releaseQty
1040
1062
  : 0
1041
- : validatedData[idx].remainQty
1063
+ : data[idx].remainQty
1042
1064
 
1043
1065
  raw.assignedUomValue =
1044
- validatedData[idx].remainUomValue >= releaseUomValue
1066
+ data[idx].remainUomValue >= releaseUomValue
1045
1067
  ? releaseUomValue > 0
1046
1068
  ? releaseUomValue
1047
1069
  : 0
1048
- : validatedData[idx].remainUomValue
1070
+ : data[idx].remainUomValue
1049
1071
 
1050
1072
  // deduct qty & uomValue from validateData
1051
- validatedData[idx].remainQty -= raw.assignedQty
1052
- validatedData[idx].remainUomValue -= raw.assignedUomValue
1053
-
1054
- raw.productId = validatedData[idx].productId
1055
- raw.productDetailId = validatedData[idx].productDetailId
1056
- raw.productInfo = validatedData[idx].productInfo
1057
- raw.packingType = validatedData[idx].packingType
1058
- raw.packingSize = validatedData[idx].packingSize
1059
- raw.uom = validatedData[idx].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
- !raw.productId || !raw.productDetailId
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'
@@ -415,6 +415,11 @@ export class NewReleaseGood {
415
415
  @Field({ nullable: true })
416
416
  paidAmount: number
417
417
 
418
+ @Field({ nullable: true })
419
+ batchId: string
420
+
421
+ @Field({ nullable: true })
422
+ cartonId: string
418
423
  }
419
424
 
420
425
  @InputType()
@@ -479,6 +479,9 @@ export class ReleaseGood {
479
479
  @Field({ nullable: true })
480
480
  batchId: string
481
481
 
482
+ @Field({ nullable: true })
483
+ cartonId: string
484
+
482
485
  @Field({ nullable: true })
483
486
  packingType: string
484
487
 
@@ -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: 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) {