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

This commit is contained in:
swdee 2026-01-17 19:51:40 +13:00
parent 052780c865
commit 3b1ea8275f
3 changed files with 90 additions and 52 deletions

View file

@ -321,36 +321,44 @@ class ScanController extends AbstractController
$decoded = $scan->getDecodedForInfoMode(); $decoded = $scan->getDecodedForInfoMode();
// Resolve part (or null) // Determine if this barcode resolves to *anything* (part, lot->part, storelocation)
$part = $this->barcodeParser->resolvePartOrNull($scan);
$redirectUrl = null; $redirectUrl = null;
if ($part !== null) { $targetFound = false;
// Redirector knows how to route parts, lots, and storelocations.
try {
$redirectUrl = $this->barcodeParser->getRedirectURL($scan); $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; $partName = null;
$partUrl = null; $partUrl = null;
$locations = []; $locations = [];
$createUrl = null;
if ($part !== null) { if ($targetFound) {
$part = $this->barcodeParser->resolvePartOrNull($scan);
if ($part instanceof Part) {
$partName = $part->getName(); $partName = $part->getName();
$partUrl = $this->generateUrl('app_part_show', ['id' => $part->getID()]); $partUrl = $this->generateUrl('app_part_show', ['id' => $part->getID()]);
$locations = $this->buildLocationsForPart($part); $locations = $this->buildLocationsForPart($part);
} else { }
}
// Create link only when NOT found (vendor codes)
$createUrl = null;
if (!$targetFound) {
$createUrl = $this->buildCreateUrlForScanResult($scan, $locale); $createUrl = $this->buildCreateUrlForScanResult($scan, $locale);
} }
// Render one fragment that shows: // Render fragment (use openUrl for universal "Open" link)
// - decoded info (optional if you kept it)
// - part info + locations when found
// - create link when not found
$html = $this->renderView('label_system/scanner/augmented_result.html.twig', [ $html = $this->renderView('label_system/scanner/augmented_result.html.twig', [
'decoded' => $decoded, 'decoded' => $decoded,
'found' => ($part !== null), 'found' => $targetFound,
'openUrl' => $redirectUrl,
'partName' => $partName, 'partName' => $partName,
'partUrl' => $partUrl, 'partUrl' => $partUrl,
'locations' => $locations, 'locations' => $locations,
@ -359,7 +367,7 @@ class ScanController extends AbstractController
return new JsonResponse([ return new JsonResponse([
'ok' => true, 'ok' => true,
'found' => ($part !== null), 'found' => $targetFound,
'redirectUrl' => $redirectUrl, // client redirects only when infoMode=false 'redirectUrl' => $redirectUrl, // client redirects only when infoMode=false
'html' => $html, 'html' => $html,
'infoMode' => $infoMode, 'infoMode' => $infoMode,

View file

@ -2,7 +2,14 @@
<hr> <hr>
<div class="d-flex align-items-center mb-2"> <div class="d-flex align-items-center mb-2">
<h4 class="mb-0 me-2">{% trans %}label_scanner.part_info.title{% endtrans %}</h4> <h4 class="mb-0 me-2">
{% if found and partName %}
{% trans %}label_scanner.part_info.title{% endtrans %}
{% else %}
{% trans %}label_scanner.scan_result.title{% endtrans %}
{% endif %}
</h4>
{% if createUrl %} {% if createUrl %}
<a class="btn btn-primary ms-2 mb-2" <a class="btn btn-primary ms-2 mb-2"
@ -15,13 +22,23 @@
</div> </div>
{% if found %} {% if found %}
<div class="alert alert-success mb-2"> <div class="alert alert-success mb-2 d-flex align-items-center justify-content-between">
<div>
{% if partName %}
{{ partName }} {{ partName }}
{% if partUrl %} {% else %}
— <a href="{{ partUrl }}" target="_blank">{% trans %}open{% endtrans %}</a> {% trans %}label_scanner.target_found{% endtrans %}
{% endif %} {% endif %}
</div> </div>
{% if openUrl %}
<a href="{{ openUrl }}" target="_blank" class="btn btn-sm btn-outline-success">
{% trans %}open{% endtrans %}
</a>
{% endif %}
</div>
{% if partName %}
{% if locations is not empty %} {% if locations is not empty %}
<table class="table table-sm mb-2 w-auto"> <table class="table table-sm mb-2 w-auto">
<thead> <thead>
@ -52,6 +69,7 @@
{% else %} {% else %}
<div class="text-muted mb-2">{% trans %}label_scanner.no_locations{% endtrans %}</div> <div class="text-muted mb-2">{% trans %}label_scanner.no_locations{% endtrans %}</div>
{% endif %} {% endif %}
{% endif %}
{% else %} {% else %}
<div class="alert alert-warning mb-2"> <div class="alert alert-warning mb-2">
{% trans %}label_scanner.qr_part_no_found{% endtrans %} {% trans %}label_scanner.qr_part_no_found{% endtrans %}

View file

@ -12051,6 +12051,18 @@ Please note, that you can not impersonate a disabled user. If you try you will g
<target>Part information</target> <target>Part information</target>
</segment> </segment>
</unit> </unit>
<unit id="k9lvxgf" name="label_scanner.target_found">
<segment state="translated">
<source>label_scanner.target_found</source>
<target>Item Found</target>
</segment>
</unit>
<unit id="kd6G2gf" name="label_scanner.scan_result.title">
<segment state="translated">
<source>label_scanner.scan_result.title</source>
<target>Scan result</target>
</segment>
</unit>
<unit id="kG2vk5p" name="label_scanner.no_locations"> <unit id="kG2vk5p" name="label_scanner.no_locations">
<segment state="translated"> <segment state="translated">
<source>label_scanner.no_locations</source> <source>label_scanner.no_locations</source>