@things-factory/operato-wms 4.1.31 → 4.1.34

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 (39) hide show
  1. package/client/pages/inbound/serial-number-list-popup.js +342 -0
  2. package/client/pages/inbound/unload-product.js +218 -39
  3. package/client/pages/inbound/unloaded-inventories-popup.js +7 -0
  4. package/client/pages/outbound/packing-product.js +7 -2
  5. package/client/pages/outbound/picking-product.js +61 -36
  6. package/client/pages/outbound/serial-number-popup.js +150 -64
  7. package/client/pages/report/inbound-serial-number-report.js +452 -0
  8. package/client/pages/report/outbound-serial-number-report.js +460 -0
  9. package/client/route.js +7 -0
  10. package/dist-server/graphql/resolvers/reports/inbound-serial-number-report.js +111 -0
  11. package/dist-server/graphql/resolvers/reports/inbound-serial-number-report.js.map +1 -0
  12. package/dist-server/graphql/resolvers/reports/index.js +3 -1
  13. package/dist-server/graphql/resolvers/reports/index.js.map +1 -1
  14. package/dist-server/graphql/resolvers/reports/outbound-serial-number-report.js +116 -0
  15. package/dist-server/graphql/resolvers/reports/outbound-serial-number-report.js.map +1 -0
  16. package/dist-server/graphql/types/reports/inbound-serial-number-report-list.js +14 -0
  17. package/dist-server/graphql/types/reports/inbound-serial-number-report-list.js.map +1 -0
  18. package/dist-server/graphql/types/reports/inbound-serial-number-report.js +23 -0
  19. package/dist-server/graphql/types/reports/inbound-serial-number-report.js.map +1 -0
  20. package/dist-server/graphql/types/reports/index.js +10 -0
  21. package/dist-server/graphql/types/reports/index.js.map +1 -1
  22. package/dist-server/graphql/types/reports/outbound-serial-number-report-list.js +14 -0
  23. package/dist-server/graphql/types/reports/outbound-serial-number-report-list.js.map +1 -0
  24. package/dist-server/graphql/types/reports/outbound-serial-number-report.js +24 -0
  25. package/dist-server/graphql/types/reports/outbound-serial-number-report.js.map +1 -0
  26. package/package.json +6 -6
  27. package/server/graphql/resolvers/reports/inbound-serial-number-report.ts +128 -0
  28. package/server/graphql/resolvers/reports/index.ts +5 -0
  29. package/server/graphql/resolvers/reports/outbound-serial-number-report.ts +133 -0
  30. package/server/graphql/types/reports/inbound-serial-number-report-list.ts +8 -0
  31. package/server/graphql/types/reports/inbound-serial-number-report.ts +17 -0
  32. package/server/graphql/types/reports/index.ts +11 -0
  33. package/server/graphql/types/reports/outbound-serial-number-report-list.ts +8 -0
  34. package/server/graphql/types/reports/outbound-serial-number-report.ts +18 -0
  35. package/things-factory.config.js +8 -0
  36. package/translations/en.json +14 -2
  37. package/translations/ko.json +14 -3
  38. package/translations/ms.json +14 -3
  39. package/translations/zh.json +18 -7
@@ -25,15 +25,6 @@ const PICKING_TYPES = { PICKING, BATCH_PICKING }
25
25
  class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
26
26
  static get properties() {
27
27
  return {
28
- config: Object,
29
- data: Object,
30
- isWholePicking: Boolean,
31
- locations: Array,
32
- locationNameSplit: Array,
33
- refPickingType: String,
34
- releaseGoodNo: String,
35
- orderNo: String,
36
- worksheetNo: String,
37
28
  _bizplaceName: String,
38
29
  _crossDocking: Boolean,
39
30
  _currentBinLocation: String,
@@ -43,10 +34,20 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
43
34
  _isCartonLabel: Boolean,
44
35
  _isExecuting: Boolean,
45
36
  _isReplacement: Boolean,
46
- _isRequireSerialNumberScanning: Boolean,
37
+ _isRequireSerialNumberScanningOutbound: Boolean,
38
+ _locationName: String,
47
39
  _reusablePalletList: Object,
48
40
  _worksheetInfo: Object,
49
- _locationName: String
41
+ config: Object,
42
+ data: Object,
43
+ isWholePicking: Boolean,
44
+ locationNameSplit: Array,
45
+ locations: Array,
46
+ orderNo: String,
47
+ refPickingType: String,
48
+ releaseGoodNo: String,
49
+ releaseGoodId: String,
50
+ worksheetNo: String
50
51
  }
51
52
  }
52
53
 
@@ -108,11 +109,11 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
108
109
  ...CommonButtonStyles.inspect
109
110
  })
110
111
 
111
- if (this._selectedOrderInventory && this._isRequireSerialNumberScanning) {
112
+ if (this._selectedOrderInventory && this._isRequireSerialNumberScanningOutbound) {
112
113
  actions.push({
113
114
  title: i18next.t('button.serial_number'),
114
115
  action: this.openSerialNumberPopup.bind(this),
115
- ...CommonButtonStyles.description
116
+ ...CommonButtonStyles.activate
116
117
  })
117
118
  }
118
119
 
@@ -251,6 +252,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
251
252
  this.locationNameSplit = []
252
253
  this.refPickingType = PICKING_TYPES.PICKING.value
253
254
  this.releaseGoodNo = ''
255
+ this.releaseGoodId = ''
254
256
  this.taskNo = ''
255
257
 
256
258
  this._incompleteLocationName = false
@@ -258,7 +260,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
258
260
  /* A flag to indicate either PICKING process is executing */
259
261
  this._isExecuting = false
260
262
  this._isReplacement = false
261
- this._isRequireSerialNumberScanning = false
263
+ this._isRequireSerialNumberScanningOutbound = false
262
264
  this._crossDocking = false
263
265
  this._enableProductScanning = false
264
266
  this._hasBinPicking = false
@@ -351,7 +353,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
351
353
  <barcode-scanable-input name="productBarcode" custom-input></barcode-scanable-input>
352
354
  `
353
355
  : html`
354
- ${this._isRequireSerialNumberScanning
356
+ ${this._isRequireSerialNumberScanningOutbound
355
357
  ? ''
356
358
  : html`
357
359
  <label>${i18next.t('label.picked_qty')}</label>
@@ -362,7 +364,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
362
364
  this._crossDocking ||
363
365
  this._isCartonLabel ||
364
366
  this._enableProductScanning ||
365
- this._isRequireSerialNumberScanning
367
+ this._isRequireSerialNumberScanningOutbound
366
368
  ? ''
367
369
  : html`
368
370
  ${this._incompleteLocationName
@@ -388,7 +390,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
388
390
  )}
389
391
  </select>
390
392
  `}
391
- ${this._isRequireSerialNumberScanning
393
+ ${this._isRequireSerialNumberScanningOutbound
392
394
  ? html`
393
395
  <label>${i18next.t('label.serial_number')}</label>
394
396
  <barcode-scanable-input name="serialNumber" custom-input></barcode-scanable-input>
@@ -444,6 +446,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
444
446
  try {
445
447
  this.grist.showSpinner()
446
448
  if (data.records.length && record) {
449
+ this._isRequireSerialNumberScanningOutbound = record.product.isRequireSerialNumberScanningOutbound
447
450
  this.inputForm.reset()
448
451
  this._isReplacement = false
449
452
 
@@ -591,6 +594,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
591
594
  pickingWorksheet(releaseGoodNo: $releaseGoodNo, locationSortingRules: $locationSortingRules) {
592
595
  worksheetInfo {
593
596
  releaseGood {
597
+ id
594
598
  name
595
599
  crossDocking
596
600
  }
@@ -612,10 +616,11 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
612
616
  batchId
613
617
  batchIdRef
614
618
  product {
619
+ id
615
620
  sku
616
621
  name
617
622
  description
618
- isRequireSerialNumberScanning
623
+ isRequireSerialNumberScanningOutbound
619
624
  }
620
625
  qty
621
626
  releaseQty
@@ -644,10 +649,11 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
644
649
  name
645
650
  }
646
651
  product {
652
+ id
647
653
  sku
648
654
  name
649
655
  description
650
- isRequireSerialNumberScanning
656
+ isRequireSerialNumberScanningOutbound
651
657
  }
652
658
  }
653
659
  }
@@ -660,6 +666,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
660
666
  if (!response.errors) {
661
667
  if (!this._selectedOrderInventory) this.clearView()
662
668
  this.releaseGoodNo = response.data.pickingWorksheet.worksheetInfo.releaseGood.name
669
+ this.releaseGoodId = response.data.pickingWorksheet.worksheetInfo.releaseGood.id
663
670
  if (!response.data?.pickingWorksheet) return
664
671
 
665
672
  const { worksheetInfo, worksheetDetailInfos } = response.data.pickingWorksheet
@@ -860,8 +867,9 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
860
867
  this.data = { records: [] }
861
868
  this.infoForm.reset()
862
869
  this.inputForm.reset()
863
- this._isRequireSerialNumberScanning = false
870
+ this._isRequireSerialNumberScanningOutbound = false
864
871
  this.releaseGoodNo = null
872
+ this.releaseGoodId = null
865
873
  this.taskNo = null
866
874
  this._crossDocking = false
867
875
  this._selectedOrderInventory = null
@@ -909,7 +917,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
909
917
  } else if (this._enableProductScanning || this._isCartonLabel) {
910
918
  response = await this.productBarcodePicking()
911
919
  } else {
912
- if (this._isReplacement) {
920
+ if (this._isReplacement && !this._isCartonLabel) {
913
921
  this.openPalletReplacementPopup()
914
922
  return
915
923
  } else {
@@ -918,12 +926,12 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
918
926
  }
919
927
 
920
928
  if (!response.errors) {
921
- if (this._isRequireSerialNumberScanning) this.serialInput.value = ''
922
- else if (this._enableProductScanning && !this._isRequireSerialNumberScanning)
929
+ if (this._isRequireSerialNumberScanningOutbound) this.serialInput.value = ''
930
+ else if (this._enableProductScanning && !this._isRequireSerialNumberScanningOutbound)
923
931
  this.productBarcodeInput.value = ''
924
932
  else this.releaseQtyInput.value = ''
925
933
 
926
- if (!this._isCartonLabel && !this._isRequireSerialNumberScanning) {
934
+ if (!this._isCartonLabel && !this._isRequireSerialNumberScanningOutbound) {
927
935
  this.palletInput.value = ''
928
936
  // this._selectedTaskStatus = null
929
937
  this._selectedOrderInventory = null
@@ -977,10 +985,20 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
977
985
  openSerialNumberPopup() {
978
986
  openPopup(
979
987
  html`
980
- <serial-number-popup .orderInventory="${this?._selectedOrderInventory?.relatedOrderInv}"></serial-number-popup>
988
+ <serial-number-popup
989
+ .orderInventory="${this?._selectedOrderInventory?.relatedOrderInv}"
990
+ .orderType="${i18next.t('text.outbound')}"
991
+ .orderId="${this.releaseGoodId}"
992
+ .data="${this?._selectedOrderInventory}"
993
+ @close-serial-number-popup="${async e => {
994
+ await this.fetchAll(this.releaseGoodNo)
995
+ }}"
996
+ ></serial-number-popup>
981
997
  `,
982
998
  {
983
- backdrop: true,
999
+ closable: false,
1000
+ backdrop: false,
1001
+ escapable: false,
984
1002
  size: 'large',
985
1003
  title: i18next.t('title.serial_number_list')
986
1004
  }
@@ -1060,9 +1078,9 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
1060
1078
  worksheetType: this.refPickingType,
1061
1079
  palletId: this.palletInput.value.trim(),
1062
1080
  locationName: this._locationName ? this._locationName : this._selectedOrderInventory?.location.name,
1063
- releaseQty: this._isRequireSerialNumberScanning ? 1 : parseInt(this.releaseQtyInput.value),
1081
+ releaseQty: this._isRequireSerialNumberScanningOutbound ? 1 : parseInt(this.releaseQtyInput.value),
1064
1082
  binLocation: this._hasBinPicking ? this.binLocationInput.value : null,
1065
- serialNumber: this._isRequireSerialNumberScanning ? this.serialInput.value : null
1083
+ serialNumber: this._isRequireSerialNumberScanningOutbound ? this.serialInput.value : null
1066
1084
  }
1067
1085
  })
1068
1086
 
@@ -1136,7 +1154,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
1136
1154
  worksheetType: this.refPickingType,
1137
1155
  productBarcode: this.productBarcodeInput.value.trim(),
1138
1156
  cartonId: this.cartonInput.value.trim(),
1139
- serialNumber: this._isRequireSerialNumberScanning ? this.serialInput.value : null,
1157
+ serialNumber: this._isRequireSerialNumberScanningOutbound ? this.serialInput.value : null,
1140
1158
  binLocation: this._hasBinPicking ? this.binLocationInput.value : null
1141
1159
  }
1142
1160
  })
@@ -1194,7 +1212,10 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
1194
1212
  this._focusOnLotNoInput()
1195
1213
  throw new Error(i18next.t('text.lot_id_is_empty'))
1196
1214
  } else {
1197
- if (this._selectedOrderInventory.palletId !== this.palletInput.value) {
1215
+ if (
1216
+ this._selectedOrderInventory.palletId !== this.palletInput.value &&
1217
+ !this._isRequireSerialNumberScanningOutbound
1218
+ ) {
1198
1219
  const isInProgressing = await this.checkProgressingPallet(this.palletInput.value)
1199
1220
  if (isInProgressing) throw new Error(i18next.t('text.pallet_is_in_progressing'))
1200
1221
 
@@ -1212,7 +1233,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
1212
1233
 
1213
1234
  // Release qty existing
1214
1235
  if (!this._isReplacement) {
1215
- if (!this._isRequireSerialNumberScanning) {
1236
+ if (!this._isRequireSerialNumberScanningOutbound) {
1216
1237
  if (!parseInt(this.releaseQtyInput?.value)) {
1217
1238
  this._focusOnReleaseQtyInput()
1218
1239
  throw new Error(i18next.t('text.release_qty_is_empty'))
@@ -1287,6 +1308,8 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
1287
1308
 
1288
1309
  if (this._selectedOrderInventory.cartonId) {
1289
1310
  if (this._selectedOrderInventory.cartonId !== this.cartonInput.value) {
1311
+ //carton replacement?
1312
+ throw new Error(i18next.t('text.invalid_carton_id'))
1290
1313
  this._isReplacement = await this.checkCartonIdenticality(
1291
1314
  this._selectedOrderInventory.cartonId,
1292
1315
  this._selectedOrderInventory.palletId,
@@ -1309,7 +1332,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
1309
1332
  }
1310
1333
  }
1311
1334
 
1312
- if (this._isRequireSerialNumberScanning) {
1335
+ if (this._isRequireSerialNumberScanningOutbound) {
1313
1336
  if (!this.serialInput?.value) {
1314
1337
  this._focusOnSerialInput()
1315
1338
  throw new Error(i18next.t('text.empty_serial_number'))
@@ -1515,6 +1538,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
1515
1538
  refNo3
1516
1539
  startedAt
1517
1540
  releaseGood {
1541
+ id
1518
1542
  name
1519
1543
  crossDocking
1520
1544
  }
@@ -1569,6 +1593,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
1569
1593
  this._bizplaceName = worksheetInfo.bizplaceName
1570
1594
  this._crossDocking = worksheetInfo.releaseGood?._crossDocking
1571
1595
  this.releaseGoodNo = worksheetInfo.releaseGood?.name
1596
+ this.releaseGoodId = worksheetInfo.releaseGood?.id
1572
1597
  this._orderNo = this.releaseGoodNo
1573
1598
  this._worksheetInfo = worksheetInfo
1574
1599
  this.data = { records: this.formatWorksheetDetailInfos(worksheetDetailInfos) }
@@ -1629,7 +1654,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
1629
1654
  return true
1630
1655
  }
1631
1656
  } else {
1632
- if (!this._enableProductScanning && !this._isRequireSerialNumberScanning) this.palletInput.value = ''
1657
+ if (!this._enableProductScanning && !this._isRequireSerialNumberScanningOutbound) this.palletInput.value = ''
1633
1658
 
1634
1659
  if (this.palletInput.value == '') {
1635
1660
  this._focusOnLotNoInput()
@@ -1638,13 +1663,13 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
1638
1663
  }
1639
1664
  }
1640
1665
 
1641
- if (this._enableProductScanning && !this._isRequireSerialNumberScanning) {
1666
+ if (this._enableProductScanning && !this._isRequireSerialNumberScanningOutbound) {
1642
1667
  this.productBarcodeInput.value = ''
1643
1668
  this._focusOnProductBarcodeInput()
1644
1669
  return true
1645
1670
  }
1646
1671
 
1647
- if (this._isRequireSerialNumberScanning) {
1672
+ if (this._isRequireSerialNumberScanningOutbound) {
1648
1673
  this.serialInput.value = ''
1649
1674
  this._focusOnSerialInput()
1650
1675
  return true
@@ -1664,7 +1689,7 @@ class PickingProduct extends connect(store)(localize(i18next)(PageView)) {
1664
1689
  }
1665
1690
 
1666
1691
  this._isCartonLabel = selectedRecords.hasCartonLabel
1667
- this._isRequireSerialNumberScanning = selectedRecords?.product?.isRequireSerialNumberScanning
1692
+ this._isRequireSerialNumberScanningOutbound = selectedRecords?.product?.isRequireSerialNumberScanningOutbound
1668
1693
  }
1669
1694
 
1670
1695
  _showToast({ type, message }) {
@@ -57,22 +57,33 @@ class SerialNumberPopup extends localize(i18next)(LitElement) {
57
57
  orderInventory: Object,
58
58
  config: Object,
59
59
  data: Object,
60
- _currentSerialNumber: String
60
+ orderId: String,
61
+ orderType: String,
62
+ _inventoryItems: Object,
63
+ _selectedSerialNumber: Object
61
64
  }
62
65
  }
63
66
 
64
- get selectedSerialInput() {
65
- return this.shadowRoot.querySelector('input[name=selectedSerialNumber]')
66
- }
67
-
68
67
  get serialInput() {
69
- return this.shadowRoot.querySelector('barcode-scanable-input[name=serialNumber]').shadowRoot.querySelector('input')
68
+ return this.shadowRoot
69
+ ?.querySelector('barcode-scanable-input[name=serialNumber]')
70
+ ?.shadowRoot.querySelector('input')
70
71
  }
71
72
 
72
73
  get dataGrist() {
73
74
  return this.shadowRoot.querySelector('data-grist')
74
75
  }
75
76
 
77
+ get infoForm() {
78
+ return this.shadowRoot.querySelector('form#info-form')
79
+ }
80
+
81
+ _focusOnSerialInput() {
82
+ if (this.serialInput) {
83
+ setTimeout(() => this.serialInput.focus(), 50)
84
+ }
85
+ }
86
+
76
87
  constructor() {
77
88
  super()
78
89
  this.clearView()
@@ -80,9 +91,18 @@ class SerialNumberPopup extends localize(i18next)(LitElement) {
80
91
 
81
92
  render() {
82
93
  return html`
83
- <form class="multi-column-form">
94
+ <form id="info-form" class="multi-column-form">
84
95
  <fieldset>
85
- <legend>${i18next.t('title.serial_number_list')}</legend>
96
+ <legend>${i18next.t('title.product_sku_x', { x: this?.data?.product.sku })}</legend>
97
+
98
+ <label>${i18next.t('label.carton_id')}</label>
99
+ <input name="cartonId" ${this?.data.cartonId} disabled />
100
+
101
+ <label>${i18next.t('label.lot_id')}</label>
102
+ <input name="palletId" ${this?.data.palletId} disabled />
103
+
104
+ <label>${i18next.t('label.location')}</label>
105
+ <input name="locationName" ${this?.data.locationName} disabled />
86
106
  </fieldset>
87
107
  </form>
88
108
 
@@ -90,19 +110,20 @@ class SerialNumberPopup extends localize(i18next)(LitElement) {
90
110
  <data-grist
91
111
  .mode=${isMobileDevice() ? 'LIST' : 'GRID'}
92
112
  .config=${this.config}
93
- .data="${this.data}"
113
+ .data=${this._inventoryItems}
94
114
  ></data-grist>
95
115
  </div>
96
116
 
97
- <form id="input-form" class="single-column-form">
117
+ <form id="input-form" class="single-column-form" @keypress="${this.updateSerialNumber.bind(this)}">
98
118
  <input
99
119
  name="selectedSerialNumber"
100
120
  placeholder="-- Selected Serial Number --"
101
121
  disabled
102
122
  readonly
103
123
  class="mobile-full-width"
104
- value="${this._currentSerialNumber}"
124
+ value="${this._selectedSerialNumber.serialNumber}"
105
125
  />
126
+
106
127
  <barcode-scanable-input name="serialNumber" class="mobile-full-width" custom-input></barcode-scanable-input>
107
128
 
108
129
  <mwc-button
@@ -118,6 +139,7 @@ class SerialNumberPopup extends localize(i18next)(LitElement) {
118
139
  <mwc-button
119
140
  danger
120
141
  @click=${() => {
142
+ this.dispatchEvent(new CustomEvent('close-serial-number-popup', {}))
121
143
  history.back()
122
144
  }}
123
145
  raised
@@ -142,8 +164,11 @@ class SerialNumberPopup extends localize(i18next)(LitElement) {
142
164
  click: async (columns, data, column, record, rowIndex) => {
143
165
  try {
144
166
  this.dataGrist.showSpinner()
145
- this._currentSerialNumber = record.serialNumber
146
- // this.selectedSerialInput.value = record.serialNumber
167
+ if (data.records.length && record) {
168
+ this._selectedSerialNumber = record
169
+ delete this._selectedSerialNumber.__seq__
170
+ delete this._selectedSerialNumber.__origin__
171
+ }
147
172
  } catch (ex) {
148
173
  console.log(ex)
149
174
  } finally {
@@ -158,18 +183,31 @@ class SerialNumberPopup extends localize(i18next)(LitElement) {
158
183
  },
159
184
  columns: [
160
185
  { type: 'gutter', gutterName: 'sequence' },
186
+ {
187
+ type: 'gutter',
188
+ gutterName: 'button',
189
+ icon: 'close',
190
+ handlers: {
191
+ click: (columns, data, column, record, rowIndex) => {
192
+ try {
193
+ const newData = data.records.filter((_, idx) => idx !== rowIndex)
194
+ this._inventoryItems = { ...this._inventoryItems, records: newData }
195
+ this.undoSerialNumberPicking(record.id)
196
+ } catch (e) {}
197
+ }
198
+ }
199
+ },
161
200
  {
162
201
  type: 'string',
163
202
  name: 'serialNumber',
164
203
  header: i18next.t('field.serial_number'),
165
- width: 140
204
+ width: 150
166
205
  }
167
206
  ]
168
207
  }
169
- await this.fetchOrderInventory()
170
- console.log()
171
-
172
- // await this.getPalletInfo(this.replacePalletId)
208
+ if (this.data) this._fillUpForm(this.infoForm, this.data)
209
+ await this.fetchInventoryItems()
210
+ this._focusOnSerialInput()
173
211
  }
174
212
 
175
213
  // async pageUpdated(changes, lifecycle) {
@@ -180,61 +218,67 @@ class SerialNumberPopup extends localize(i18next)(LitElement) {
180
218
  // }
181
219
 
182
220
  clearView() {
183
- this.targetInventory = null
184
- this.data = { records: [] }
185
- this._currentSerialNumber = ''
186
- if (this.serialNumber) this.serialInput.value = ''
221
+ this._selectedSerialNumber = {}
222
+ if (this.serialInput) this.serialInput.value = ''
187
223
  }
188
224
 
189
- async fetchOrderInventory() {
190
- try {
191
- this.dataGrist.showSpinner()
192
- if (this?.orderInventory?.id) {
193
- const response = await client.query({
194
- query: gql`
195
- query orderInventory($id: String!) {
196
- orderInventory(id: $id) {
225
+ async fetchInventoryItems() {
226
+ let filters = [
227
+ { name: 'orderType', operator: 'eq', value: this.orderType },
228
+ { name: 'orderId', operator: 'eq', value: this.orderId },
229
+ { name: 'productId', operator: 'eq', value: this.data.product.id },
230
+ { name: 'inventory_info', operator: 'i_like', value: `%${this.data.palletId}%` }
231
+ ]
232
+
233
+ const pagination = { page: 1, limit: 9999999 }
234
+ const sortings = []
235
+
236
+ const response = await client.query({
237
+ query: gql`
238
+ query inventoryItemsByInventory($filters: [Filter!]!, $pagination: Pagination, $sortings: [Sorting!]!) {
239
+ inventoryItemsByInventory(filters: $filters, pagination: $pagination, sortings: $sortings) {
240
+ items {
241
+ id
242
+ name
243
+ status
244
+ serialNumber
245
+ outboundOrderId
246
+ inventory {
247
+ id
248
+ name
249
+ }
250
+ product {
197
251
  id
198
252
  name
199
- serialNumber
200
253
  }
201
254
  }
202
- `,
203
- variables: { id: this.orderInventory.id }
204
- })
205
-
206
- if (!response.errors) {
207
- this.orderInventory = response.data.orderInventory
208
- this.data = {
209
- records: (JSON.parse(response.data.orderInventory.serialNumber) || []).map(x => {
210
- return { serialNumber: x }
211
- })
255
+ total
212
256
  }
213
257
  }
214
- }
215
- } catch (error) {
216
- throw error
217
- } finally {
218
- this.dataGrist.hideSpinner()
258
+ `,
259
+ variables: { filters, pagination, sortings }
260
+ })
261
+
262
+ if (!response.errors) {
263
+ return (this._inventoryItems = {
264
+ records: response.data.inventoryItemsByInventory.items || []
265
+ })
219
266
  }
220
267
  }
221
268
 
222
- async updateSerialNumber() {
223
- try {
224
- this.validate()
225
-
226
- let orderInventory = this.orderInventory
227
- let serialNumber = JSON.parse(orderInventory.serialNumber)
228
- let index = serialNumber.indexOf(this.selectedSerialInput.value)
229
-
230
- if (index >= 0) {
231
- serialNumber.splice(index, 1, this.serialInput.value)
232
- orderInventory.serialNumber = JSON.stringify(serialNumber)
269
+ async updateSerialNumber(e) {
270
+ if (e.keyCode === 13 || e.type == 'click') {
271
+ e.preventDefault()
272
+ try {
273
+ this.validate()
233
274
 
234
275
  const response = await client.mutate({
235
276
  mutation: gql`
236
- mutation updateOrderInventorySerialNumber($orderInventory: OrderInventoryPatch!) {
237
- updateOrderInventorySerialNumber(orderInventory: $orderInventory) {
277
+ mutation replacePickedInventoryItem($selectedSerialNumber: InventoryItemPatch!, $newSerialNumber: String!) {
278
+ replacePickedInventoryItem(
279
+ selectedSerialNumber: $selectedSerialNumber
280
+ newSerialNumber: $newSerialNumber
281
+ ) {
238
282
  id
239
283
  name
240
284
  serialNumber
@@ -242,16 +286,38 @@ class SerialNumberPopup extends localize(i18next)(LitElement) {
242
286
  }
243
287
  `,
244
288
  variables: {
245
- orderInventory
289
+ selectedSerialNumber: this._selectedSerialNumber,
290
+ newSerialNumber: this.serialInput.value.trim()
246
291
  }
247
292
  })
248
293
 
249
294
  if (!response.errors) {
250
- this._currentSerialNumber = ''
251
- this.serialInput.value = ''
295
+ this.clearView()
296
+ await this.fetchInventoryItems()
297
+ this._focusOnSerialInput()
298
+ }
299
+ } catch (e) {
300
+ this._showToast(e)
301
+ }
302
+ }
303
+ }
252
304
 
253
- this.fetchOrderInventory()
305
+ async undoSerialNumberPicking(id) {
306
+ try {
307
+ const response = await client.mutate({
308
+ mutation: gql`
309
+ mutation undoSerialNumberPicking($worksheetDetailName: String!, $inventoryItemId: String!) {
310
+ undoSerialNumberPicking(worksheetDetailName: $worksheetDetailName, inventoryItemId: $inventoryItemId)
311
+ }
312
+ `,
313
+ variables: {
314
+ worksheetDetailName: this.data.name,
315
+ inventoryItemId: id
254
316
  }
317
+ })
318
+
319
+ if (!response.errors) {
320
+ this.dataGrist.fetch()
255
321
  }
256
322
  } catch (e) {
257
323
  this._showToast(e)
@@ -260,11 +326,31 @@ class SerialNumberPopup extends localize(i18next)(LitElement) {
260
326
 
261
327
  validate() {
262
328
  // validate for previous picking execution (multiple picking scanning)
263
- if (this.selectedSerialInput.value == '') throw new Error(i18next.t('text.no_serial_number_selected'))
329
+ let foundSerialNumber = this.dataGrist.data.records.filter(itm => itm.serialNumber == this.serialInput.value.trim())
330
+ if (foundSerialNumber.length > 0) {
331
+ throw new Error(i18next.t('text.serial_number_has_been_scanned'))
332
+ }
333
+
334
+ if (!this._selectedSerialNumber.id) throw new Error(i18next.t('text.no_serial_number_selected'))
264
335
 
265
336
  if (this.serialInput.value == '') throw new Error(i18next.t('text.please_key_in_new_serial_number'))
266
337
  }
267
338
 
339
+ _fillUpForm(form, data) {
340
+ for (let key in data) {
341
+ Array.from(form.querySelectorAll('input')).forEach(field => {
342
+ if (field.name === key) {
343
+ if (data[key] instanceof Object) {
344
+ const objectData = data[key]
345
+ field.value = `${objectData.name} ${objectData.description ? `(${objectData.description})` : ''}`
346
+ } else {
347
+ field.value = data[key]
348
+ }
349
+ }
350
+ })
351
+ }
352
+ }
353
+
268
354
  _showToast({ type, message }) {
269
355
  document.dispatchEvent(
270
356
  new CustomEvent('notify', {