From 3b1ea8275f16f8cc49bc6955bbc8d3e48bfce3e4 Mon Sep 17 00:00:00 2001 From: swdee Date: Sat, 17 Jan 2026 19:51:40 +1300 Subject: [PATCH] fix scanning of part-db barcodes to redirect to storage location or part lots. made scan result messages conditional for parts or other non-part barcodes --- src/Controller/ScanController.php | 44 ++++++---- .../scanner/augmented_result.html.twig | 86 +++++++++++-------- translations/messages.en.xlf | 12 +++ 3 files changed, 90 insertions(+), 52 deletions(-) diff --git a/src/Controller/ScanController.php b/src/Controller/ScanController.php index 8676095f..4e9dc8b2 100644 --- a/src/Controller/ScanController.php +++ b/src/Controller/ScanController.php @@ -321,36 +321,44 @@ class ScanController extends AbstractController $decoded = $scan->getDecodedForInfoMode(); - // Resolve part (or null) - $part = $this->barcodeParser->resolvePartOrNull($scan); - + // Determine if this barcode resolves to *anything* (part, lot->part, storelocation) $redirectUrl = null; - if ($part !== null) { - // Redirector knows how to route parts, lots, and storelocations. + $targetFound = false; + + try { $redirectUrl = $this->barcodeParser->getRedirectURL($scan); + $targetFound = true; + } catch (EntityNotFoundException) { + $targetFound = false; } - // Build template vars + // Only resolve Part for part-like targets. Storelocation scans should remain null here. + $part = null; $partName = null; $partUrl = null; $locations = []; - $createUrl = null; - if ($part !== null) { - $partName = $part->getName(); - $partUrl = $this->generateUrl('app_part_show', ['id' => $part->getID()]); - $locations = $this->buildLocationsForPart($part); - } else { + if ($targetFound) { + $part = $this->barcodeParser->resolvePartOrNull($scan); + + if ($part instanceof Part) { + $partName = $part->getName(); + $partUrl = $this->generateUrl('app_part_show', ['id' => $part->getID()]); + $locations = $this->buildLocationsForPart($part); + } + } + + // Create link only when NOT found (vendor codes) + $createUrl = null; + if (!$targetFound) { $createUrl = $this->buildCreateUrlForScanResult($scan, $locale); } - // Render one fragment that shows: - // - decoded info (optional if you kept it) - // - part info + locations when found - // - create link when not found + // Render fragment (use openUrl for universal "Open" link) $html = $this->renderView('label_system/scanner/augmented_result.html.twig', [ 'decoded' => $decoded, - 'found' => ($part !== null), + 'found' => $targetFound, + 'openUrl' => $redirectUrl, 'partName' => $partName, 'partUrl' => $partUrl, 'locations' => $locations, @@ -359,7 +367,7 @@ class ScanController extends AbstractController return new JsonResponse([ 'ok' => true, - 'found' => ($part !== null), + 'found' => $targetFound, 'redirectUrl' => $redirectUrl, // client redirects only when infoMode=false 'html' => $html, 'infoMode' => $infoMode, diff --git a/templates/label_system/scanner/augmented_result.html.twig b/templates/label_system/scanner/augmented_result.html.twig index 044d4ac6..c31e336a 100644 --- a/templates/label_system/scanner/augmented_result.html.twig +++ b/templates/label_system/scanner/augmented_result.html.twig @@ -2,7 +2,14 @@
-

{% trans %}label_scanner.part_info.title{% endtrans %}

+

+ {% if found and partName %} + {% trans %}label_scanner.part_info.title{% endtrans %} + {% else %} + {% trans %}label_scanner.scan_result.title{% endtrans %} + {% endif %} +

+ {% if createUrl %} {% if found %} - +
+
+ {% if partName %} + {{ partName }} + {% else %} + {% trans %}label_scanner.target_found{% endtrans %} + {% endif %} +
- {% if locations is not empty %} - - - - - - - - - {% for loc in locations %} + {% if openUrl %} + + {% trans %}open{% endtrans %} + + {% endif %} + + + {% if partName %} + {% if locations is not empty %} +
{% trans %}part_lots.storage_location{% endtrans %} - {% trans %}part_lots.amount{% endtrans %} -
+ - - + + - {% endfor %} - -
- - - {% if loc.qty is not null %}{{ loc.qty }}{% else %}{% endif %} - {% trans %}part_lots.storage_location{% endtrans %} + {% trans %}part_lots.amount{% endtrans %} +
- {% else %} -
{% trans %}label_scanner.no_locations{% endtrans %}
+ + + {% for loc in locations %} + + + + + + {% if loc.qty is not null %}{{ loc.qty }}{% else %}{% endif %} + + + {% endfor %} + + + {% else %} +
{% trans %}label_scanner.no_locations{% endtrans %}
+ {% endif %} {% endif %} {% else %}
diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index 37b39085..8ae6b777 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -12051,6 +12051,18 @@ Please note, that you can not impersonate a disabled user. If you try you will g Part information + + + label_scanner.target_found + Item Found + + + + + label_scanner.scan_result.title + Scan result + + label_scanner.no_locations