@things-factory/worksheet-base 4.3.493 → 4.3.495

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 (58) hide show
  1. package/dist-server/controllers/inspect/cycle-count-worksheet-controller.js +68 -29
  2. package/dist-server/controllers/inspect/cycle-count-worksheet-controller.js.map +1 -1
  3. package/dist-server/graphql/resolvers/worksheet/cycle-count-adjustment.js +30 -6
  4. package/dist-server/graphql/resolvers/worksheet/cycle-count-adjustment.js.map +1 -1
  5. package/dist-server/graphql/resolvers/worksheet/cycle-count-worksheet-for-carton.js +17 -1
  6. package/dist-server/graphql/resolvers/worksheet/cycle-count-worksheet-for-carton.js.map +1 -1
  7. package/dist-server/graphql/resolvers/worksheet/cycle-count-worksheet-for-pallet.js +18 -2
  8. package/dist-server/graphql/resolvers/worksheet/cycle-count-worksheet-for-pallet.js.map +1 -1
  9. package/dist-server/graphql/resolvers/worksheet/generate-worksheet/generate-cycle-count-worksheet.js +4 -4
  10. package/dist-server/graphql/resolvers/worksheet/generate-worksheet/generate-cycle-count-worksheet.js.map +1 -1
  11. package/dist-server/graphql/resolvers/worksheet/generate-worksheet/generate-release-good-worksheet.js +1 -0
  12. package/dist-server/graphql/resolvers/worksheet/generate-worksheet/generate-release-good-worksheet.js.map +1 -1
  13. package/dist-server/graphql/resolvers/worksheet/inspecting/add-extra-inventory.js +4 -4
  14. package/dist-server/graphql/resolvers/worksheet/inspecting/add-extra-inventory.js.map +1 -1
  15. package/dist-server/graphql/resolvers/worksheet/inspecting/inspecting-carton.js +4 -4
  16. package/dist-server/graphql/resolvers/worksheet/inspecting/inspecting-carton.js.map +1 -1
  17. package/dist-server/graphql/resolvers/worksheet/inspecting/inspecting-pallet.js +4 -4
  18. package/dist-server/graphql/resolvers/worksheet/inspecting/inspecting-pallet.js.map +1 -1
  19. package/dist-server/graphql/resolvers/worksheet/inventories-by-pallet.js +1 -0
  20. package/dist-server/graphql/resolvers/worksheet/inventories-by-pallet.js.map +1 -1
  21. package/dist-server/graphql/resolvers/worksheet/not-tally-target-inventories.js +15 -1
  22. package/dist-server/graphql/resolvers/worksheet/not-tally-target-inventories.js.map +1 -1
  23. package/dist-server/graphql/resolvers/worksheet/picking/activate-picking.js +7 -1
  24. package/dist-server/graphql/resolvers/worksheet/picking/activate-picking.js.map +1 -1
  25. package/dist-server/graphql/resolvers/worksheet/picking/bulk-activate-picking.js +7 -1
  26. package/dist-server/graphql/resolvers/worksheet/picking/bulk-activate-picking.js.map +1 -1
  27. package/dist-server/graphql/resolvers/worksheet/worksheet-with-pagination.js +15 -1
  28. package/dist-server/graphql/resolvers/worksheet/worksheet-with-pagination.js.map +1 -1
  29. package/dist-server/graphql/resolvers/worksheet/worksheets.js +8 -0
  30. package/dist-server/graphql/resolvers/worksheet/worksheets.js.map +1 -1
  31. package/dist-server/graphql/types/worksheet/index.js +9 -3
  32. package/dist-server/graphql/types/worksheet/index.js.map +1 -1
  33. package/dist-server/graphql/types/worksheet/location-filter.js +13 -0
  34. package/dist-server/graphql/types/worksheet/location-filter.js.map +1 -0
  35. package/dist-server/graphql/types/worksheet/worksheet-detail-info.js +1 -0
  36. package/dist-server/graphql/types/worksheet/worksheet-detail-info.js.map +1 -1
  37. package/dist-server/utils/lmd-util.js +21 -26
  38. package/dist-server/utils/lmd-util.js.map +1 -1
  39. package/package.json +6 -6
  40. package/server/controllers/inspect/cycle-count-worksheet-controller.ts +98 -33
  41. package/server/graphql/resolvers/worksheet/cycle-count-adjustment.ts +39 -33
  42. package/server/graphql/resolvers/worksheet/cycle-count-worksheet-for-carton.ts +20 -5
  43. package/server/graphql/resolvers/worksheet/cycle-count-worksheet-for-pallet.ts +27 -5
  44. package/server/graphql/resolvers/worksheet/generate-worksheet/generate-cycle-count-worksheet.ts +7 -4
  45. package/server/graphql/resolvers/worksheet/generate-worksheet/generate-release-good-worksheet.ts +1 -0
  46. package/server/graphql/resolvers/worksheet/inspecting/add-extra-inventory.ts +8 -4
  47. package/server/graphql/resolvers/worksheet/inspecting/inspecting-carton.ts +7 -4
  48. package/server/graphql/resolvers/worksheet/inspecting/inspecting-pallet.ts +5 -4
  49. package/server/graphql/resolvers/worksheet/inventories-by-pallet.ts +1 -0
  50. package/server/graphql/resolvers/worksheet/not-tally-target-inventories.ts +22 -1
  51. package/server/graphql/resolvers/worksheet/picking/activate-picking.ts +7 -1
  52. package/server/graphql/resolvers/worksheet/picking/bulk-activate-picking.ts +7 -1
  53. package/server/graphql/resolvers/worksheet/worksheet-with-pagination.ts +26 -1
  54. package/server/graphql/resolvers/worksheet/worksheets.ts +12 -1
  55. package/server/graphql/types/worksheet/index.ts +9 -3
  56. package/server/graphql/types/worksheet/location-filter.ts +10 -0
  57. package/server/graphql/types/worksheet/worksheet-detail-info.ts +1 -0
  58. package/server/utils/lmd-util.ts +30 -28
@@ -27,7 +27,8 @@ export class CycleCountWorksheetController extends WorksheetController {
27
27
  executionDate: string,
28
28
  inventoryCheckItem: InventoryCheckItem[],
29
29
  selectedLocation: string[],
30
- limit: number
30
+ limit: number,
31
+ lockInventory: Boolean
31
32
  ): Promise<Worksheet> {
32
33
  const cycleCount: InventoryCheck = await generateCycleCount(
33
34
  this.trxMgr,
@@ -114,6 +115,7 @@ export class CycleCountWorksheetController extends WorksheetController {
114
115
  targetInventoryCheckItem.originQty = inventory.qty
115
116
  targetInventoryCheckItem.originWeight = 0
116
117
  targetInventoryCheckItem.originUomValue = inventory.uomValue
118
+ targetInventoryCheckItem.originExpirationDate = inventory.expirationDate
117
119
  targetInventoryCheckItem.originBatchNo = inventory.batchId
118
120
  targetInventoryCheckItem.originLocation = inventory.location
119
121
  targetInventoryCheckItem.inventory = inventory
@@ -123,15 +125,16 @@ export class CycleCountWorksheetController extends WorksheetController {
123
125
  targetInventoryCheckItem.creator = this.user
124
126
  targetInventoryCheckItem.updater = this.user
125
127
  targetInventoryCheckItems.push(targetInventoryCheckItem)
126
-
127
- inventory.updater = this.user
128
128
  }
129
129
 
130
130
  targetInventoryCheckItems = await this.trxMgr
131
131
  .getRepository(InventoryCheckItem)
132
132
  .save(targetInventoryCheckItems, { chunk: 500 })
133
133
 
134
- inventories = await this.trxMgr.getRepository(Inventory).save(inventories, { chunk: 500 })
134
+ await this.trxMgr.getRepository(Inventory).update(
135
+ inventories.map(itm => itm.id),
136
+ { updater: this.user, lockInventory: lockInventory }
137
+ )
135
138
 
136
139
  let cycleCountWorksheetDetails: WorksheetDetail[] = []
137
140
  for (let i: number = 0; i < targetInventoryCheckItems.length; i++) {
@@ -202,10 +205,12 @@ export class CycleCountWorksheetController extends WorksheetController {
202
205
  nextRoundItem.originUomValue = currentItem.inspectedUomValue || currentItem.originUomValue
203
206
  nextRoundItem.originBatchNo = currentItem.inspectedBatchNo || currentItem.originBatchNo
204
207
  nextRoundItem.originLocation = currentItem.inspectedLocationId || currentItem.originLocationId
208
+ nextRoundItem.originExpirationDate = currentItem.inspectedExpirationDate
205
209
  nextRoundItem.inspectedQty = null
206
210
  nextRoundItem.inspectedUomValue = null
207
211
  nextRoundItem.inspectedBatchNo = null
208
212
  nextRoundItem.inspectedLocationId = null
213
+ nextRoundItem.inspectedExpirationDate = null
209
214
  nextRoundItem.countNo = currentItem.countNo + 1
210
215
  nextRoundItem.inventory = currentItem.inventoryId
211
216
  nextRoundItem.product = currentItem.productId
@@ -428,7 +433,8 @@ export class CycleCountWorksheetController extends WorksheetController {
428
433
  inventoryCheckItem: InventoryCheckItem[] = [],
429
434
  limit: number = 0,
430
435
  selectedLocation: string[] = [],
431
- cycleCountNo: string
436
+ cycleCountNo: string,
437
+ lockInventory?: Boolean
432
438
  ): Promise<Worksheet> {
433
439
  const customerBizplace: Bizplace = await this.trxMgr.getRepository(Bizplace).findOne(customerId)
434
440
 
@@ -495,7 +501,8 @@ export class CycleCountWorksheetController extends WorksheetController {
495
501
  executionDate,
496
502
  inventoryCheckItem,
497
503
  selectedLocation,
498
- limit
504
+ limit,
505
+ lockInventory
499
506
  )
500
507
  }
501
508
  }
@@ -626,7 +633,8 @@ export class CycleCountWorksheetController extends WorksheetController {
626
633
  worksheetDetailName: string,
627
634
  inspectedBatchNo: string,
628
635
  inspectedQty: number,
629
- inspectedUomValue: number
636
+ inspectedUomValue: number,
637
+ inspectedExpirationDate: Date
630
638
  ): Promise<void> {
631
639
  let worksheetDetail: WorksheetDetail = await this.findExecutableWorksheetDetailByName(
632
640
  worksheetDetailName,
@@ -639,11 +647,24 @@ export class CycleCountWorksheetController extends WorksheetController {
639
647
  originBatchNo,
640
648
  originQty,
641
649
  originUomValue,
650
+ originExpirationDate,
642
651
  originLocationId
643
- }: { originBatchNo: string; originQty: number; originUomValue: number, originLocationId: string } = targetInventoryCheckItem
652
+ }: {
653
+ originBatchNo: string
654
+ originQty: number
655
+ originUomValue: number
656
+ originExpirationDate: Date
657
+ originLocationId: string
658
+ } = targetInventoryCheckItem
659
+
660
+ let checkedExpDate = inspectedExpirationDate ? formatDate(inspectedExpirationDate) : null
661
+ let checkOrgExpDate = originExpirationDate?.toString() || null
644
662
 
645
663
  const isChanged: boolean =
646
- originBatchNo !== inspectedBatchNo || originQty !== inspectedQty || originUomValue !== inspectedUomValue
664
+ originBatchNo !== inspectedBatchNo ||
665
+ originQty !== inspectedQty ||
666
+ originUomValue !== inspectedUomValue ||
667
+ checkedExpDate !== checkOrgExpDate
647
668
  const worksheetDetailStatus: string = isChanged ? WORKSHEET_STATUS.NOT_TALLY : WORKSHEET_STATUS.DONE
648
669
  const targetInventoryCheckItemStatus: string = isChanged
649
670
  ? INVENTORY_CHECK_ITEM_STATUS.NOT_TALLY
@@ -656,6 +677,7 @@ export class CycleCountWorksheetController extends WorksheetController {
656
677
  targetInventoryCheckItem.inspectedBatchNo = inspectedBatchNo
657
678
  targetInventoryCheckItem.inspectedQty = inspectedQty
658
679
  targetInventoryCheckItem.inspectedUomValue = inspectedUomValue
680
+ targetInventoryCheckItem.inspectedExpirationDate = checkedExpDate
659
681
  targetInventoryCheckItem.inspectedLocation = originLocationId
660
682
  targetInventoryCheckItem.status = targetInventoryCheckItemStatus
661
683
  targetInventoryCheckItem.updater = this.user
@@ -669,7 +691,8 @@ export class CycleCountWorksheetController extends WorksheetController {
669
691
  locationId: string,
670
692
  inspectedBatchNo: string,
671
693
  inspectedQty: number,
672
- inspectedUomValue: number
694
+ inspectedUomValue: number,
695
+ inspectedExpirationDate: Date
673
696
  ): Promise<void> {
674
697
  const productDetail: ProductDetail = await this.trxMgr.getRepository(ProductDetail).findOne({
675
698
  where: { id: productDetailId },
@@ -715,23 +738,24 @@ export class CycleCountWorksheetController extends WorksheetController {
715
738
  .andWhere('inventoryCheckItem.status = :status', { status: 'INSPECTING' })
716
739
  .getMany()
717
740
 
718
- const totalOriginQty = inventoryCheckItems.reduce((total, item) => total + (item.originQty || 0), 0)
719
- const totalOriginUomValue = inventoryCheckItems.reduce((total, item) => total + (item.originUomValue || 0), 0)
720
-
721
- const hasQtyDiscrepancy = totalOriginQty !== inspectedQty
722
- const hasUomValueDiscrepancy = totalOriginUomValue !== inspectedUomValue
723
-
724
- const hasBatchNoDiscrepancy = inventoryCheckItems.some(checkItem => checkItem.originBatchNo !== inspectedBatchNo)
741
+ const { totalOriginQty, totalOriginUomValue } = inventoryCheckItems.reduce(
742
+ (total, item) => {
743
+ total.totalOriginQty += item.originQty || 0
744
+ total.totalOriginUomValue += item.originUomValue || 0
725
745
 
726
- const hasDiscrepancies = hasQtyDiscrepancy || hasUomValueDiscrepancy || hasBatchNoDiscrepancy
727
-
728
- let inventoryCheckItemStatus
729
- let worksheetDetailStatus
746
+ return total
747
+ },
748
+ { totalOriginQty: 0, totalOriginUomValue: 0 }
749
+ )
730
750
 
731
- inventoryCheckItemStatus = hasDiscrepancies
732
- ? INVENTORY_CHECK_ITEM_STATUS.NOT_TALLY
733
- : INVENTORY_CHECK_ITEM_STATUS.INSPECTED
734
- worksheetDetailStatus = hasDiscrepancies ? WORKSHEET_STATUS.NOT_TALLY : WORKSHEET_STATUS.DONE
751
+ const hasDiscrepancies =
752
+ totalOriginQty !== inspectedQty ||
753
+ totalOriginUomValue !== inspectedUomValue ||
754
+ inventoryCheckItems.some(
755
+ checkItem =>
756
+ checkItem.originExpirationDate !== formatDate(inspectedExpirationDate) ||
757
+ checkItem.originBatchNo !== inspectedBatchNo
758
+ )
735
759
 
736
760
  let totalInspectedQty = inspectedQty
737
761
  let totalInspectedUomValue = inspectedUomValue
@@ -748,20 +772,32 @@ export class CycleCountWorksheetController extends WorksheetController {
748
772
  totalInspectedUomValue -= uomValueToInspect
749
773
 
750
774
  checkItem.inspectedBatchNo = inspectedBatchNo
775
+ checkItem.inspectedExpirationDate = inspectedExpirationDate
751
776
  checkItem.inspectedLocation = checkItem.originLocationId
752
- checkItem.status = inventoryCheckItemStatus
777
+ checkItem.status = hasDiscrepancies
778
+ ? INVENTORY_CHECK_ITEM_STATUS.NOT_TALLY
779
+ : INVENTORY_CHECK_ITEM_STATUS.INSPECTED
753
780
  checkItem.updater = this.user
754
781
 
755
- await this.trxMgr.getRepository(InventoryCheckItem).save(checkItem)
782
+ await this.trxMgr.getRepository(InventoryCheckItem).update(checkItem.id, {
783
+ inspectedQty: checkItem.inspectedQty,
784
+ inspectedUomValue: checkItem.inspectedUomValue,
785
+ inspectedBatchNo: checkItem.inspectedBatchNo,
786
+ inspectedExpirationDate: checkItem.inspectedExpirationDate,
787
+ inspectedLocation: checkItem.inspectedLocation,
788
+ status: checkItem.status,
789
+ updater: this.user
790
+ })
756
791
 
757
792
  let worksheetDetail = await this.trxMgr.getRepository(WorksheetDetail).findOne({
758
793
  where: { targetInventoryCheckItem: checkItem.id, type: WORKSHEET_TYPE.CYCLE_COUNT }
759
794
  })
760
795
 
761
796
  if (worksheetDetail) {
762
- worksheetDetail.status = worksheetDetailStatus
763
- worksheetDetail.updater = this.user
764
- await this.trxMgr.getRepository(WorksheetDetail).save(worksheetDetail)
797
+ await this.trxMgr.getRepository(WorksheetDetail).update(worksheetDetail.id, {
798
+ status: hasDiscrepancies ? WORKSHEET_STATUS.NOT_TALLY : WORKSHEET_STATUS.DONE,
799
+ updater: this.user
800
+ })
765
801
  }
766
802
  }
767
803
 
@@ -769,7 +805,12 @@ export class CycleCountWorksheetController extends WorksheetController {
769
805
  const lastItem = inventoryCheckItems[inventoryCheckItems.length - 1]
770
806
  lastItem.inspectedQty = (lastItem.inspectedQty ?? 0) + totalInspectedQty
771
807
  lastItem.inspectedUomValue = (lastItem.inspectedUomValue ?? 0) + totalInspectedUomValue
772
- await this.trxMgr.getRepository(InventoryCheckItem).save(lastItem)
808
+
809
+ await this.trxMgr.getRepository(InventoryCheckItem).update(lastItem.id, {
810
+ inspectedQty: lastItem.inspectedQty,
811
+ inspectedUomValue: lastItem.inspectedUomValue,
812
+ updater: this.user
813
+ })
773
814
  }
774
815
  }
775
816
 
@@ -785,6 +826,7 @@ export class CycleCountWorksheetController extends WorksheetController {
785
826
  targetInventoryCheckItem.inspectedWeight = null
786
827
  targetInventoryCheckItem.inspectedUomValue = null
787
828
  targetInventoryCheckItem.inspectedLocation = null
829
+ targetInventoryCheckItem.inspectedExpirationDate = null
788
830
  targetInventoryCheckItem.status = targetInventoryCheckItem.status = INVENTORY_CHECK_ITEM_STATUS.INSPECTING
789
831
  targetInventoryCheckItem.updater = this.user
790
832
  await this.updateOrderTargets([targetInventoryCheckItem])
@@ -832,6 +874,7 @@ export class CycleCountWorksheetController extends WorksheetController {
832
874
  checkItem.inspectedQty = null
833
875
  checkItem.inspectedWeight = null
834
876
  checkItem.inspectedUomValue = null
877
+ checkItem.inspectedExpirationDate = null
835
878
  checkItem.inspectedLocation = null
836
879
  checkItem.status = INVENTORY_CHECK_ITEM_STATUS.INSPECTING
837
880
  checkItem.updater = this.user
@@ -918,7 +961,8 @@ export class CycleCountWorksheetController extends WorksheetController {
918
961
  inspectedBatchNo: string,
919
962
  inspectedQty: number,
920
963
  inspectedUomValue: number,
921
- countNo: number
964
+ countNo: number,
965
+ inspectedExpirationDate: Date
922
966
  ): Promise<void> {
923
967
  let today = new Date(),
924
968
  year = today.getFullYear(),
@@ -1014,6 +1058,7 @@ export class CycleCountWorksheetController extends WorksheetController {
1014
1058
  newInventory.uom = productDetail.uom
1015
1059
  newInventory.qty = inspectedQty
1016
1060
  newInventory.uomValue = inspectedUomValue
1061
+ newInventory.expirationDate = inspectedExpirationDate
1017
1062
  newInventory.location = location
1018
1063
  newInventory.warehouse = location.warehouse
1019
1064
  newInventory.zone = location.zone
@@ -1032,6 +1077,7 @@ export class CycleCountWorksheetController extends WorksheetController {
1032
1077
  targetInventoryCheckItem.inspectedBatchNo = inspectedBatchNo
1033
1078
  targetInventoryCheckItem.inspectedQty = inspectedQty
1034
1079
  targetInventoryCheckItem.inspectedUomValue = inspectedUomValue
1080
+ targetInventoryCheckItem.inspectedExpirationDate = inspectedExpirationDate
1035
1081
  targetInventoryCheckItem.inspectedLocation = location
1036
1082
  targetInventoryCheckItem.productDetail = productDetail
1037
1083
  targetInventoryCheckItem.product = product
@@ -1301,7 +1347,17 @@ export class CycleCountWorksheetController extends WorksheetController {
1301
1347
  })
1302
1348
  await this.trxMgr.getRepository(InventoryCheckItem).save(tallyTargetInventoryCheckItems, { chunk: 500 })
1303
1349
 
1304
- await this.trxMgr.getRepository(Inventory).save(tallyInventories, { chunk: 500 })
1350
+ // await this.trxMgr.getRepository(Inventory).save(tallyInventories, { chunk: 500 })
1351
+
1352
+ if (tallyInventories.length > 0) {
1353
+ await this.trxMgr.getRepository(Inventory).update(
1354
+ tallyInventories.map(inv => inv.id),
1355
+ {
1356
+ updater: this.user,
1357
+ lockInventory: false
1358
+ }
1359
+ )
1360
+ }
1305
1361
 
1306
1362
  if (notTallyTargetInventoryCheckItems.length) {
1307
1363
  worksheet.status = WORKSHEET_STATUS.NOT_TALLY
@@ -1322,3 +1378,12 @@ export class CycleCountWorksheetController extends WorksheetController {
1322
1378
  return worksheet
1323
1379
  }
1324
1380
  }
1381
+
1382
+ function formatDate(data) {
1383
+ let date = {
1384
+ year: data.getFullYear().toString(),
1385
+ month: (data.getMonth() + 1).toString(),
1386
+ day: data.getDate().toString()
1387
+ }
1388
+ return `${date.year}-${date.month.padStart(2, '0')}-${date.day.padStart(2, '0')}`
1389
+ }
@@ -102,7 +102,7 @@ export async function cycleCountAdjustment(
102
102
  const inventory = checkItem.inventory
103
103
 
104
104
  // Exclude items that are under inspection elsewhere
105
- if (inspectingInventoryIds.has(inventory.id)) {
105
+ if (inspectingInventoryIds.has(inventory?.id)) {
106
106
  return false
107
107
  }
108
108
 
@@ -114,7 +114,8 @@ export async function cycleCountAdjustment(
114
114
  checkItem.inspectedQty !== inventory.qty ||
115
115
  checkItem.inspectedBatchNo !== inventory.batchId ||
116
116
  checkItem.inspectedLocation.id !== inventory.location.id ||
117
- checkItem.inspectedUomValue !== inventory.uomValue
117
+ checkItem.inspectedUomValue !== inventory.uomValue ||
118
+ checkItem.inspectedExpirationDate !== inventory.expirationDate
118
119
  )
119
120
  })
120
121
 
@@ -157,6 +158,7 @@ export async function cycleCountAdjustment(
157
158
  inventory.lockeduomValue = 0
158
159
  inventory.updater = user
159
160
  inventory.status = INVENTORY_STATUS.TERMINATED
161
+ inventory.lockInventory = false
160
162
  inventory = await tx.getRepository(Inventory).save(inventory)
161
163
 
162
164
  // create TERMINATED, TERMINATED history
@@ -193,6 +195,7 @@ export async function cycleCountAdjustment(
193
195
  inventory.warehouse = targetInventoryCheckItem.inspectedLocation.warehouse
194
196
  inventory.status = INVENTORY_STATUS.TERMINATED
195
197
  inventory.updater = user
198
+ inventory.lockInventory = false
196
199
  inventory = await tx.getRepository(Inventory).save(inventory)
197
200
 
198
201
  // create TERMINATED, TERMINATED history
@@ -218,47 +221,37 @@ export async function cycleCountAdjustment(
218
221
  for (let inventory of inventories) {
219
222
  inventory.qty = targetInventoryCheckItem.inspectedQty
220
223
  inventory.uomValue = targetInventoryCheckItem.inspectedUomValue
224
+ inventory.expirationDate = targetInventoryCheckItem.inspectedExpirationDate || null
221
225
  inventory.status = INVENTORY_STATUS.STORED
222
226
  inventory.creator = user
223
227
  inventory.updater = user
224
- await tx.getRepository(Inventory).save(inventory)
225
-
226
- await tx.getRepository(InventoryHistory).save({
227
- ...targetInventoryCheckItem,
228
- seq: inventory.lastSeq,
229
- refOrderId: targetInventoryCheckItem.inventoryCheckId,
230
- orderNo: targetInventoryCheckItem.inventoryCheck.name,
231
- name: InventoryNoGenerator.inventoryHistoryName(),
232
- palletId: inventory.palletId,
233
- batchId: inventory.batchId,
234
- zone: inventory.zone,
235
- packingType: inventory.packingType,
236
- qty: inventory.qty || 0,
237
- openingQty: 0,
238
- uomValue: inventory.uomValue || 0,
239
- openingUomValue: 0,
228
+
229
+
230
+ await tx.getRepository(Inventory).update(inventory.id, {
231
+ qty: inventory.qty,
232
+ uomValue: inventory.uomValue,
233
+ expirationDate: inventory.expirationDate,
240
234
  status: inventory.status,
241
- transactionType: INVENTORY_TRANSACTION_TYPE.CC_ADJUSTMENT,
242
- createdAt: inventory.createdAt,
243
- updatedAt: inventory.updatedAt,
244
- domain: domain,
245
- bizplace: targetInventoryCheckItem.inventory.bizplace,
246
- inventory: inventory.id,
247
- cartonId: inventory.cartonId,
248
- creator: user,
249
235
  updater: user,
250
- product: targetInventoryCheckItem.inventory.product,
251
- productDetail: targetInventoryCheckItem.inventory.productDetail,
252
- packingSize: inventory.packingSize,
253
- warehouse: targetInventoryCheckItem.inventory.warehouse,
254
- location: targetInventoryCheckItem.inventory.location
236
+ lockInventory: false
255
237
  })
238
+
239
+ await generateInventoryHistory(
240
+ inventory,
241
+ cycleCount,
242
+ INVENTORY_TRANSACTION_TYPE.CC_ADJUSTMENT,
243
+ inventory.qty,
244
+ inventory.uomValue,
245
+ user,
246
+ tx
247
+ )
256
248
  }
257
249
  } else if (
258
250
  targetInventoryCheckItem.inspectedQty !== inventory.qty ||
259
251
  targetInventoryCheckItem.inspectedBatchNo !== inventory.batchId ||
260
252
  targetInventoryCheckItem.inspectedLocation.id !== inventory.location.id ||
261
- targetInventoryCheckItem.inspectedUomValue !== inventory.uomValue
253
+ targetInventoryCheckItem.inspectedUomValue !== inventory.uomValue ||
254
+ targetInventoryCheckItem.inspectedExpirationDate !== inventory.expirationDate
262
255
  ) {
263
256
  const prevLocationId: string = inventory.location.id
264
257
 
@@ -290,7 +283,20 @@ export async function cycleCountAdjustment(
290
283
  inventory.warehouse = targetInventoryCheckItem.inspectedLocation.warehouse || inventory.warehouse
291
284
  inventory.status = INVENTORY_STATUS.STORED
292
285
  inventory.updater = user
293
- inventory = await tx.getRepository(Inventory).save(inventory)
286
+ inventory.lockInventory = false
287
+ inventory.expirationDate = targetInventoryCheckItem.inspectedExpirationDate
288
+
289
+ await tx.getRepository(Inventory).update(inventory.id, {
290
+ batchId: inventory.batchId,
291
+ qty: inventory.qty,
292
+ uomValue: inventory.uomValue,
293
+ location: inventory.location,
294
+ warehouse: inventory.warehouse,
295
+ status: inventory.status,
296
+ updater: user,
297
+ lockInventory: false,
298
+ expirationDate: targetInventoryCheckItem.inspectedExpirationDate
299
+ })
294
300
 
295
301
  if (prevLocationId !== targetInventoryCheckItem.inspectedLocation.id) {
296
302
  const prevLocation: Location = await tx.getRepository(Location).findOne(prevLocationId)
@@ -1,9 +1,7 @@
1
1
  import { createQueryBuilder, getRepository, In, SelectQueryBuilder } from 'typeorm'
2
-
3
2
  import { InventoryCheck, ORDER_STATUS, InventoryCheckItem } from '@things-factory/sales-base'
4
3
  import { Domain } from '@things-factory/shell'
5
- import { Inventory } from '@things-factory/warehouse-base'
6
- import { ProductDetail, Product } from '@things-factory/product-base'
4
+
7
5
 
8
6
  import { WORKSHEET_STATUS, WORKSHEET_TYPE } from '../../../constants'
9
7
  import { Worksheet, WorksheetDetail } from '../../../entities'
@@ -11,10 +9,16 @@ import { Worksheet, WorksheetDetail } from '../../../entities'
11
9
  export const cycleCountWorksheetForCartonResolver = {
12
10
  async cycleCountWorksheetForCarton(
13
11
  _: any,
14
- { inventoryCheckNo, locationSortingRules, locationName, cartonId, palletId, inventoryCheckItemStatus },
12
+ { inventoryCheckNo, locationSortingRules, locationName, cartonId, palletId, inventoryCheckItemStatus, locationFilter},
15
13
  context: any
16
14
  ) {
17
15
  const { domain }: { domain: Domain } = context.state
16
+ const filterMap = {
17
+ zone: 'zone',
18
+ column: 'column',
19
+ row: 'row',
20
+ shelf: 'shelf'
21
+ }
18
22
  const cycleCount: InventoryCheck = await getRepository(InventoryCheck).findOne({
19
23
  where: { domain, name: inventoryCheckNo, status: ORDER_STATUS.INSPECTING }
20
24
  })
@@ -58,6 +62,16 @@ export const cycleCountWorksheetForCartonResolver = {
58
62
  )
59
63
  }
60
64
 
65
+ if (Object.keys(locationFilter).length > 0) {
66
+ Object.entries(filterMap).forEach(([key, value]) => {
67
+ if (locationFilter?.[key]) {
68
+ qb.andWhere(`"LOC_INV"."${value}" = :${key}`, {
69
+ [key]: locationFilter[key]
70
+ })
71
+ }
72
+ })
73
+ }
74
+
61
75
  if (cartonId) {
62
76
  qb.andWhere('"INV"."carton_id" = :cartonId', { cartonId })
63
77
  }
@@ -99,6 +113,7 @@ export const cycleCountWorksheetForCartonResolver = {
99
113
  uom: inventory?.uom,
100
114
  originLocation: targetInventoryCheckItem?.originLocation,
101
115
  inspectedQty: targetInventoryCheckItem?.inspectedQty,
116
+ inspectedExpirationDate: targetInventoryCheckItem?.inspectedExpirationDate,
102
117
  inspectedUomValue: targetInventoryCheckItem?.inspectedUomValue,
103
118
  inspectedLocation: targetInventoryCheckItem?.inspectedLocation,
104
119
  inspectedBatchNo: targetInventoryCheckItem?.inspectedBatchNo,
@@ -112,4 +127,4 @@ export const cycleCountWorksheetForCartonResolver = {
112
127
  )
113
128
  }
114
129
  }
115
- }
130
+ }
@@ -1,9 +1,6 @@
1
1
  import { createQueryBuilder, getRepository, In, SelectQueryBuilder } from 'typeorm'
2
-
3
2
  import { InventoryCheck, ORDER_STATUS, InventoryCheckItem } from '@things-factory/sales-base'
4
3
  import { Domain } from '@things-factory/shell'
5
- import { Inventory } from '@things-factory/warehouse-base'
6
- import { ProductDetail, Product } from '@things-factory/product-base'
7
4
 
8
5
  import { WORKSHEET_STATUS, WORKSHEET_TYPE } from '../../../constants'
9
6
  import { Worksheet, WorksheetDetail } from '../../../entities'
@@ -11,13 +8,27 @@ import { Worksheet, WorksheetDetail } from '../../../entities'
11
8
  export const cycleCountWorksheetForPalletResolver = {
12
9
  async cycleCountWorksheetForPallet(
13
10
  _: any,
14
- { inventoryCheckNo, locationSortingRules, locationName, cartonId, palletId, inventoryCheckItemStatus },
11
+ {
12
+ inventoryCheckNo,
13
+ locationSortingRules,
14
+ locationName,
15
+ cartonId,
16
+ palletId,
17
+ inventoryCheckItemStatus,
18
+ locationFilter
19
+ },
15
20
  context: any
16
21
  ) {
17
22
  const { domain }: { domain: Domain } = context.state
18
23
  const cycleCount: InventoryCheck = await getRepository(InventoryCheck).findOne({
19
24
  where: { domain, name: inventoryCheckNo, status: ORDER_STATUS.INSPECTING }
20
25
  })
26
+ const filterMap = {
27
+ zone: 'zone',
28
+ column: 'column',
29
+ row: 'row',
30
+ shelf: 'shelf'
31
+ }
21
32
 
22
33
  if (!cycleCount) throw new Error('Failed to find cycle count worksheet')
23
34
 
@@ -54,11 +65,21 @@ export const cycleCountWorksheetForPalletResolver = {
54
65
 
55
66
  if (locationName) {
56
67
  qb.andWhere(
57
- '"ORG_LOC"."name" = :locationName OR "LOC_INV"."name" = :locationName OR "INS_LOC"."name" = :locationName',
68
+ '("ORG_LOC"."name" = :locationName OR "LOC_INV"."name" = :locationName OR "INS_LOC"."name" = :locationName)',
58
69
  { locationName }
59
70
  )
60
71
  }
61
72
 
73
+ if (Object.keys(locationFilter).length > 0) {
74
+ Object.entries(filterMap).forEach(([key, value]) => {
75
+ if (locationFilter?.[key]) {
76
+ qb.andWhere(`"LOC_INV"."${value}" = :${key}`, {
77
+ [key]: locationFilter[key]
78
+ })
79
+ }
80
+ })
81
+ }
82
+
62
83
  if (cartonId) {
63
84
  qb.andWhere('"INV"."carton_id" = :cartonId', { cartonId })
64
85
  }
@@ -101,6 +122,7 @@ export const cycleCountWorksheetForPalletResolver = {
101
122
  originLocation: targetInventoryCheckItem?.originLocation,
102
123
  inspectedQty: targetInventoryCheckItem?.inspectedQty,
103
124
  inspectedUomValue: targetInventoryCheckItem?.inspectedUomValue,
125
+ inspectedExpirationDate: targetInventoryCheckItem?.inspectedExpirationDate,
104
126
  inspectedLocation: targetInventoryCheckItem?.inspectedLocation,
105
127
  inspectedBatchNo: targetInventoryCheckItem?.inspectedBatchNo,
106
128
  status: cycleCountWSD.status,
@@ -10,7 +10,7 @@ import { Worksheet } from '../../../../entities'
10
10
  export const generateCycleCountWorksheetResolver = {
11
11
  async generateCycleCountWorksheet(
12
12
  _: any,
13
- { executionDate, customerId, inventoryCheckItemIds, inventoryCheckItems, limit, selectedLocation, cycleCountNo },
13
+ { executionDate, customerId, inventoryCheckItemIds, inventoryCheckItems, limit, selectedLocation, cycleCountNo,lockInventory },
14
14
  context: any
15
15
  ) {
16
16
  const { tx, domain, user }: { tx: EntityManager; domain: Domain; user: User } = context.state
@@ -25,7 +25,8 @@ export const generateCycleCountWorksheetResolver = {
25
25
  inventoryCheckItems,
26
26
  limit,
27
27
  selectedLocation,
28
- cycleCountNo
28
+ cycleCountNo,
29
+ lockInventory
29
30
  )
30
31
 
31
32
  return cycleCountWorksheet
@@ -42,7 +43,8 @@ export async function generateCycleCountWorksheet(
42
43
  inventoryCheckItems: InventoryCheckItem[],
43
44
  limit: number,
44
45
  selectedLocation: string[] = [],
45
- cycleCountNo: string
46
+ cycleCountNo: string,
47
+ lockInventory?: Boolean
46
48
  ): Promise<Worksheet> {
47
49
  const worksheetController: CycleCountWorksheetController = new CycleCountWorksheetController(tx, domain, user)
48
50
  return await worksheetController.generateCycleCountWorksheet(
@@ -52,6 +54,7 @@ export async function generateCycleCountWorksheet(
52
54
  inventoryCheckItems,
53
55
  limit,
54
56
  selectedLocation,
55
- cycleCountNo
57
+ cycleCountNo,
58
+ lockInventory
56
59
  )
57
60
  }
@@ -159,6 +159,7 @@ export async function mmsProcessOrder(
159
159
  },
160
160
  relations: [
161
161
  'marketplaceStore',
162
+ 'marketplaceStore.marketplaceDistributors',
162
163
  'marketplaceOrderPackages',
163
164
  'marketplaceOrderPackages.marketplaceOrderPackageItems',
164
165
  'marketplaceOrderPackages.marketplaceOrderPackageItems.marketplaceOrderItem',
@@ -14,7 +14,8 @@ export const addExtraInventoryResolver = {
14
14
  inspectedBatchNo,
15
15
  inspectedQty,
16
16
  inspectedUomValue,
17
- countNo
17
+ countNo,
18
+ inspectedExpirationDate
18
19
  },
19
20
  context: any
20
21
  ) {
@@ -30,7 +31,8 @@ export const addExtraInventoryResolver = {
30
31
  inspectedBatchNo,
31
32
  inspectedQty,
32
33
  inspectedUomValue,
33
- countNo
34
+ countNo,
35
+ inspectedExpirationDate
34
36
  )
35
37
  }
36
38
  }
@@ -46,7 +48,8 @@ export async function addExtraInventory(
46
48
  inspectedBatchNo: string,
47
49
  inspectedQty: number,
48
50
  inspectedUomValue: number,
49
- countNo: number
51
+ countNo: number,
52
+ inspectedExpirationDate: Date
50
53
  ) {
51
54
  const worksheetController: CycleCountWorksheetController = new CycleCountWorksheetController(tx, domain, user)
52
55
  await worksheetController.addExtraInventory(
@@ -57,6 +60,7 @@ export async function addExtraInventory(
57
60
  inspectedBatchNo,
58
61
  inspectedQty,
59
62
  inspectedUomValue,
60
- countNo
63
+ countNo,
64
+ inspectedExpirationDate
61
65
  )
62
66
  }
@@ -7,7 +7,7 @@ import { Product } from 'puppeteer'
7
7
  export const inspectingCartonResolver = {
8
8
  async inspectingCarton(
9
9
  _: any,
10
- { productDetailId, cartonId, batchId, locationId, inspectedBatchNo, inspectedQty, inspectedUomValue },
10
+ { productDetailId, cartonId, batchId, locationId, inspectedBatchNo, inspectedQty, inspectedUomValue, inspectedExpirationDate },
11
11
  context: any
12
12
  ) {
13
13
  const { tx, domain, user }: { tx: EntityManager; domain: Domain; user: User } = context.state
@@ -21,7 +21,8 @@ export const inspectingCartonResolver = {
21
21
  locationId,
22
22
  inspectedBatchNo,
23
23
  inspectedQty,
24
- inspectedUomValue
24
+ inspectedUomValue,
25
+ inspectedExpirationDate
25
26
  )
26
27
  }
27
28
  }
@@ -36,7 +37,8 @@ export async function executeInspectionCarton(
36
37
  locationId: string,
37
38
  inspectedBatchNo: string,
38
39
  inspectedQty: number,
39
- inspectedUomValue: number
40
+ inspectedUomValue: number,
41
+ inspectedExpirationDate: Date
40
42
  ) {
41
43
  const worksheetController: CycleCountWorksheetController = new CycleCountWorksheetController(tx, domain, user)
42
44
  await worksheetController.inspectingCarton(
@@ -46,6 +48,7 @@ export async function executeInspectionCarton(
46
48
  locationId,
47
49
  inspectedBatchNo,
48
50
  inspectedQty,
49
- inspectedUomValue
51
+ inspectedUomValue,
52
+ inspectedExpirationDate
50
53
  )
51
54
  }