@things-factory/operato-wms 4.3.607 → 4.3.609

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.
@@ -6,20 +6,40 @@ import './order-remark-popup'
6
6
  import './packing-serial-number-popup'
7
7
 
8
8
  import gql from 'graphql-tag'
9
- import { css, html } from 'lit-element'
9
+ import {
10
+ css,
11
+ html
12
+ } from 'lit-element'
10
13
  import { connect } from 'pwa-helpers/connect-mixin.js'
11
14
 
12
15
  import { GhostPrint } from '@operato/ghost-print'
13
16
  import { sleep } from '@operato/utils'
14
17
  import { MultiColumnFormStyles } from '@things-factory/form-ui'
15
- import { i18next, localize } from '@things-factory/i18n-base'
18
+ import {
19
+ i18next,
20
+ localize
21
+ } from '@things-factory/i18n-base'
16
22
  import { openPopup } from '@things-factory/layout-base'
17
- import { client, CustomAlert, PageView, store } from '@things-factory/shell'
23
+ import {
24
+ client,
25
+ CustomAlert,
26
+ PageView,
27
+ store
28
+ } from '@things-factory/shell'
18
29
  import { CommonButtonStyles } from '@things-factory/styles'
19
30
  import { isMobileDevice } from '@things-factory/utils'
20
31
 
21
32
  import { fetchSettingRule } from '../../fetch-setting-value'
22
- import { ORDER_SOURCES, PLATFORM, WORKSHEET_STATUS } from '../constants'
33
+ import {
34
+ decodeQR,
35
+ fetchPageSettings,
36
+ isValidHttpUrl
37
+ } from '../../util/index'
38
+ import {
39
+ ORDER_SOURCES,
40
+ PLATFORM,
41
+ WORKSHEET_STATUS
42
+ } from '../constants'
23
43
 
24
44
  class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
25
45
  static get properties() {
@@ -43,6 +63,7 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
43
63
  lmdOption: Boolean,
44
64
  _bizplaceName: String,
45
65
  _enableProductScanning: Boolean,
66
+ _qrProcessing: Number,
46
67
  _productName: String,
47
68
  _logisticsInitiated: Boolean,
48
69
  _selectedTaskStatus: String,
@@ -196,7 +217,8 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
196
217
  if (
197
218
  this.releaseGoodNo &&
198
219
  (this.source == 'OTHERS' || this.source == null) &&
199
- this.platform == 'operato' && this.completed
220
+ this.platform == 'operato' &&
221
+ this.completed
200
222
  ) {
201
223
  actions.push({
202
224
  title: i18next.t('button.print_airway_bill'),
@@ -297,23 +319,23 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
297
319
  }
298
320
 
299
321
  addGrossWeightListener() {
300
- const grossWeightInput = this.shadowRoot.querySelector('#grossWeightInput');
322
+ const grossWeightInput = this.shadowRoot.querySelector('#grossWeightInput')
301
323
  if (grossWeightInput) {
302
- grossWeightInput.addEventListener('input', (event) => {
303
- let value = event.target.value;
304
-
305
- // Check if the input is valid and contains more than 3 decimal places
306
- if (value.includes('.')) {
307
- let [integer, decimals] = value.split('.');
308
- if (decimals.length > 3) {
309
- event.target.value = `${integer}.${decimals.slice(0, 3)}`;
310
- }
311
- }
312
- });
324
+ grossWeightInput.addEventListener('input', event => {
325
+ let value = event.target.value
326
+
327
+ // Check if the input is valid and contains more than 3 decimal places
328
+ if (value.includes('.')) {
329
+ let [integer, decimals] = value.split('.')
330
+ if (decimals.length > 3) {
331
+ event.target.value = `${integer}.${decimals.slice(0, 3)}`
332
+ }
333
+ }
334
+ })
313
335
  } else {
314
- console.error("Gross weight input not found.");
336
+ console.error('Gross weight input not found.')
315
337
  }
316
- }
338
+ }
317
339
 
318
340
  render() {
319
341
  return html`
@@ -339,15 +361,24 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
339
361
  <form id="input-form" class="multi-column-form" @keypress="${this.packing.bind(this)}">
340
362
  <fieldset>
341
363
  ${this._enableProductScanning
342
- ? html` <label>${i18next.t('label.product_barcode')}</label>
343
- <barcode-scanable-input name="productBarcode" custom-input></barcode-scanable-input>
344
-
345
- ${this._enablePackingGrossWeight
346
- ? html`
347
- <label>${i18next.t('label.gross_weight')}</label>
348
- <input name="grossWeight" id="grossWeightInput" type="number" min="0" step="0.001"/>`
349
- : ''}
350
- `
364
+ ? html`
365
+ <label>${i18next.t('label.product_barcode')}</label>
366
+ <barcode-scanable-input
367
+ name="productBarcode"
368
+ custom-input
369
+ @keypress="${async e => {
370
+ if (e.keyCode === 13) {
371
+ e.preventDefault()
372
+ await this._processQRAndFillForm(e)
373
+ }
374
+ }}"
375
+ ></barcode-scanable-input>
376
+
377
+ ${this._enablePackingGrossWeight
378
+ ? html` <label>${i18next.t('label.gross_weight')}</label>
379
+ <input name="grossWeight" id="grossWeightInput" type="number" min="0" step="0.001" />`
380
+ : ''}
381
+ `
351
382
  : this._isRequireSerialNumberScanningOutbound && this._isBatchPicking
352
383
  ? ``
353
384
  : html`
@@ -357,7 +388,16 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
357
388
  ${this._isRequireSerialNumberScanningOutbound && this._isBatchPicking
358
389
  ? html`
359
390
  <label>${i18next.t('label.serial_number')}</label>
360
- <barcode-scanable-input name="serialNumber" custom-input></barcode-scanable-input>
391
+ <barcode-scanable-input
392
+ name="serialNumber"
393
+ custom-input
394
+ @keypress="${async e => {
395
+ if (this._qrProcessing > 0 && e.keyCode === 13) {
396
+ e.preventDefault()
397
+ await this._processQRAndFillForm(e)
398
+ }
399
+ }}"
400
+ ></barcode-scanable-input>
361
401
  `
362
402
  : ``}
363
403
  </fieldset>
@@ -391,6 +431,7 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
391
431
  this.totalBinRO = 0
392
432
  this.checkedRemarkAt = ''
393
433
  this._enableProductScanning = false
434
+ this._qrProcessing = 0
394
435
  this._productName = ''
395
436
  this._selectedOrderInventory = null
396
437
  this._selectedTaskStatus = null
@@ -403,9 +444,10 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
403
444
  this._enablePackingGrossWeight = false
404
445
  }
405
446
 
406
-
407
447
  updated(changedProps) {
408
- this.addGrossWeightListener()
448
+ if (this._enablePackingGrossWeight) {
449
+ this.addGrossWeightListener()
450
+ }
409
451
  if (changedProps.has('_selectedTaskStatus') && this._selectedTaskStatus) {
410
452
  this.updateContext()
411
453
  }
@@ -677,8 +719,21 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
677
719
  this.printBill()
678
720
  }
679
721
 
680
- this._enableProductScanning = await fetchSettingRule('enable-product-scanning', worksheetInfo.partnerDomainId)
681
- this._enablePackingGrossWeight = await fetchSettingRule('enable-packing-gross-weight', worksheetInfo.partnerDomainId)
722
+ //fetch all page settings
723
+ let pageSettings = await fetchPageSettings({
724
+ settings: {
725
+ name: 'name',
726
+ operator: 'in',
727
+ value: ['enable-product-scanning', 'enable-packing-gross-weight', 'qr-code-scanning']
728
+ },
729
+ settingsDomain: this._worksheetInfo.partnerDomainId
730
+ })
731
+
732
+ const settingsMaps = new Map(pageSettings.settings.map(setting => [setting.name, setting.value]))
733
+
734
+ this._enableProductScanning = settingsMaps.get('enable-product-scanning') === 'true'
735
+ this._enablePackingGrossWeight = settingsMaps.get('enable-packing-gross-weight') === 'true'
736
+ this._qrProcessing = settingsMaps.get('qr-code-scanning')
682
737
 
683
738
  if (this._enableProductScanning) {
684
739
  this.focusOnProductBarcodeInput()
@@ -1167,6 +1222,36 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
1167
1222
  }
1168
1223
  }
1169
1224
 
1225
+ async _processQRAndFillForm(e) {
1226
+ // QR scanning
1227
+ if (
1228
+ this._enableProductScanning &&
1229
+ this._qrProcessing > 0 &&
1230
+ (isValidHttpUrl(this.productBarcodeInput?.value) || isValidHttpUrl(this.serialInput?.value))
1231
+ ) {
1232
+ let input = isValidHttpUrl(this.productBarcodeInput?.value)
1233
+ ? this.productBarcodeInput?.value
1234
+ : this.serialInput?.value
1235
+ let config = JSON.parse(
1236
+ await fetchSettingRule('qr-data-parsing-configuration', this._worksheetInfo.partnerDomainId)
1237
+ )
1238
+ // Get GTIN and serial number from QR code
1239
+ let data = await decodeQR(input, config)
1240
+
1241
+ // Fill up form
1242
+ if (this.productBarcodeInput && data.productBarcode) {
1243
+ this.productBarcodeInput.value = data.productBarcode
1244
+ }
1245
+ if (this.serialInput && data.serialNumber) {
1246
+ this.serialInput.value = data.serialNumber
1247
+ }
1248
+
1249
+ await sleep(1010)
1250
+
1251
+ this.packing(e)
1252
+ }
1253
+ }
1254
+
1170
1255
  async packing(e) {
1171
1256
  if (e.keyCode === 13) {
1172
1257
  e.preventDefault()
@@ -1182,9 +1267,9 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
1182
1267
  if (!response.errors) {
1183
1268
  if (this._enableProductScanning) {
1184
1269
  this.productBarcodeInput.value = ''
1185
- if (this._enablePackingGrossWeight){
1186
- this.grossWeightInput.value = ''
1187
- }
1270
+ if (this._enablePackingGrossWeight) {
1271
+ this.grossWeightInput.value = ''
1272
+ }
1188
1273
  } else {
1189
1274
  this.releaseQtyInput.value = ''
1190
1275
  this._selectedTaskStatus = null
@@ -1212,8 +1297,8 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
1212
1297
  } finally {
1213
1298
  if (!this._isRequireSerialNumberScanningOutbound) {
1214
1299
  this._enableProductScanning ? (this.productBarcodeInput.value = '') : (this.releaseQtyInput.value = '')
1215
- if(this._enablePackingGrossWeight){
1216
- this.grossWeightInput.value = ''
1300
+ if (this._enablePackingGrossWeight) {
1301
+ this.grossWeightInput.value = ''
1217
1302
  }
1218
1303
  } else {
1219
1304
  if (this._isBatchPicking) this.serialInput.value = ''
@@ -1398,14 +1483,20 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
1398
1483
  validatePacking() {
1399
1484
  // validate for order selection
1400
1485
  if (this._enableProductScanning) {
1401
-
1402
1486
  //if entered weight without fully scanning product barcode and settings enabled
1403
- if (this._enablePackingGrossWeight && this.grossWeightInput.value && (this._selectedOrderInventory?.packedQty !== this._selectedOrderInventory?.releaseQty)) {
1404
- this._selectedOrderInventory = null
1405
- throw new Error(i18next.t('text.please_scan_all_items_first_before_entering_the_gross_weight'))
1487
+ if (
1488
+ this._enablePackingGrossWeight &&
1489
+ this.grossWeightInput.value &&
1490
+ this._selectedOrderInventory?.packedQty !== this._selectedOrderInventory?.releaseQty
1491
+ ) {
1492
+ this._selectedOrderInventory = null
1493
+ throw new Error(i18next.t('text.please_scan_all_items_first_before_entering_the_gross_weight'))
1406
1494
  }
1407
-
1408
- if (!this.productBarcodeInput.value && (this._selectedOrderInventory?.packedQty !== this._selectedOrderInventory?.releaseQty)) {
1495
+
1496
+ if (
1497
+ !this.productBarcodeInput.value &&
1498
+ this._selectedOrderInventory?.packedQty !== this._selectedOrderInventory?.releaseQty
1499
+ ) {
1409
1500
  this.focusOnProductBarcodeInput()
1410
1501
  throw new Error(i18next.t('text.no_product_barcode_detected'))
1411
1502
  }
@@ -1456,23 +1547,25 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
1456
1547
  }
1457
1548
 
1458
1549
  async complete() {
1550
+ if (this._enablePackingGrossWeight) {
1551
+ const grossWeightValue = this.grossWeightInput.value
1459
1552
 
1460
- if (this._enablePackingGrossWeight) {
1461
- const grossWeightValue = this.grossWeightInput.value;
1462
-
1463
- if (!grossWeightValue) {
1464
- throw new Error(this.showToast({
1465
- message: i18next.t('text.please_input_the_gross_weight_to_proceed_with_complete_packing')
1466
- }));
1467
- }
1553
+ if (!grossWeightValue) {
1554
+ throw new Error(
1555
+ this.showToast({
1556
+ message: i18next.t('text.please_input_the_gross_weight_to_proceed_with_complete_packing')
1557
+ })
1558
+ )
1559
+ }
1468
1560
 
1469
- if (!/^\d*\.?\d*$/.test(grossWeightValue)) {
1470
- throw new Error(this.showToast({
1471
- message: i18next.t('text.please_input_a_positive_gross_weight_to_proceed_with_complete_packing')
1472
- }));
1561
+ if (!/^\d*\.?\d*$/.test(grossWeightValue)) {
1562
+ throw new Error(
1563
+ this.showToast({
1564
+ message: i18next.t('text.please_input_a_positive_gross_weight_to_proceed_with_complete_packing')
1565
+ })
1566
+ )
1567
+ }
1473
1568
  }
1474
- }
1475
-
1476
1569
 
1477
1570
  const response = await client.mutate({
1478
1571
  mutation: gql`
@@ -1480,10 +1573,12 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
1480
1573
  completePacking(releaseGoodNo: $releaseGoodNo, orderPackageId: $orderPackageId, grossWeight: $grossWeight)
1481
1574
  }
1482
1575
  `,
1483
- variables: {
1484
- releaseGoodNo: this.releaseGoodNo,
1576
+ variables: {
1577
+ releaseGoodNo: this.releaseGoodNo,
1485
1578
  orderPackageId: this._orderPackageInformation?.orderPackage?.id,
1486
- grossWeight: this._enablePackingGrossWeight && this.grossWeightInput.value ? parseFloat(this.grossWeightInput.value) : null }
1579
+ grossWeight:
1580
+ this._enablePackingGrossWeight && this.grossWeightInput.value ? parseFloat(this.grossWeightInput.value) : null
1581
+ }
1487
1582
  })
1488
1583
 
1489
1584
  if (!response.errors) {
@@ -1601,6 +1696,12 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
1601
1696
 
1602
1697
  async openSerialNumberPopup() {
1603
1698
  await sleep(1010)
1699
+ let qrConfig = null
1700
+ if (this._qrProcessing > 0) {
1701
+ qrConfig = JSON.parse(
1702
+ await fetchSettingRule('qr-data-parsing-configuration', this._worksheetInfo.partnerDomainId)
1703
+ )
1704
+ }
1604
1705
  openPopup(
1605
1706
  html`
1606
1707
  <packing-serial-number-popup
@@ -1608,6 +1709,8 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
1608
1709
  .orderSource="${ORDER_SOURCES.PACKING.value}"
1609
1710
  .orderId="${this.releaseGoodId}"
1610
1711
  .orderPackageId="${this._orderPackageInformation?.orderPackage?.id}"
1712
+ .qrProcessing="${this._qrProcessing}"
1713
+ .qrConfig="${qrConfig}"
1611
1714
  @close-serial-number-popup="${async e => {
1612
1715
  await this.fetchInventories(this.releaseGoodNo)
1613
1716
  }}"
@@ -1701,18 +1804,6 @@ class PackingProduct extends connect(store)(localize(i18next)(PageView)) {
1701
1804
  })
1702
1805
  )
1703
1806
  }
1704
-
1705
- isValidHttpUrl(string) {
1706
- let url
1707
-
1708
- try {
1709
- url = new URL(string)
1710
- } catch (_) {
1711
- return false
1712
- }
1713
-
1714
- return url.protocol === 'http:' || url.protocol === 'https:'
1715
- }
1716
1807
  }
1717
1808
 
1718
1809
  window.customElements.define('packing-product', PackingProduct)
@@ -10,6 +10,7 @@ import { client } from '@things-factory/shell'
10
10
  import { isMobileDevice } from '@things-factory/utils'
11
11
 
12
12
  import { ORDER_SOURCES } from '../constants'
13
+ import { decodeQR, isValidHttpUrl } from '../../util'
13
14
 
14
15
  class PackingSerialNumberPopup extends localize(i18next)(LitElement) {
15
16
  static get styles() {
@@ -64,7 +65,9 @@ class PackingSerialNumberPopup extends localize(i18next)(LitElement) {
64
65
  orderSource: String,
65
66
  orderPackageId: String,
66
67
  _inventoryItems: Object,
67
- _selectedSerialNumber: Object
68
+ _selectedSerialNumber: Object,
69
+ qrProcessing: Number,
70
+ qrConfig: Object
68
71
  // enableRemove: Boolean,
69
72
  // enableUpdateBtn: Boolean
70
73
  }
@@ -112,7 +115,17 @@ class PackingSerialNumberPopup extends localize(i18next)(LitElement) {
112
115
  class="mobile-full-width"
113
116
  value="${this._selectedSerialNumber.serialNumber}"
114
117
  />
115
- <barcode-scanable-input name="serialNumber" class="mobile-full-width" custom-input></barcode-scanable-input>
118
+ <barcode-scanable-input
119
+ name="serialNumber"
120
+ class="mobile-full-width"
121
+ custom-input
122
+ @keypress="${async e => {
123
+ if (e.keyCode === 13) {
124
+ e.preventDefault()
125
+ await this._extractSerialNumber(e)
126
+ }
127
+ }}"
128
+ ></barcode-scanable-input>
116
129
  <mwc-button
117
130
  name="setSerialNumber"
118
131
  class="mobile-full-width"
@@ -268,6 +281,21 @@ class PackingSerialNumberPopup extends localize(i18next)(LitElement) {
268
281
  }
269
282
  }
270
283
 
284
+ async _extractSerialNumber() {
285
+ // QR scanning
286
+ if (this.qrProcessing > 0 && isValidHttpUrl(this.serialInput.value)) {
287
+ let input = this.serialInput.value.trim()
288
+
289
+ // Get GTIN and serial number from QR code
290
+ let data = await decodeQR(input, this.qrConfig)
291
+
292
+ // Fill up form
293
+ if (this.serialInput && data.serialNumber) {
294
+ this.serialInput.value = data.serialNumber
295
+ }
296
+ }
297
+ }
298
+
271
299
  async updateSerialNumber(e) {
272
300
  if (e.keyCode === 13 || e.type == 'click') {
273
301
  e.preventDefault()