From 8dc1fb0062ed9088a74f0f86d63d7c374f5db7b6 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Fri, 22 May 2026 04:01:05 +0000 Subject: [PATCH] Autosave: 20260522-040104 --- debug_barcode_issue.php | 97 ++++++++++++++++++++++++++++++++++ imprimir_etiquetas_termica.php | 21 ++++---- includes/barcode_generator.php | 57 ++++++++++++++++---- test_etiquetas.php | 54 +++++++++++-------- 4 files changed, 185 insertions(+), 44 deletions(-) create mode 100644 debug_barcode_issue.php diff --git a/debug_barcode_issue.php b/debug_barcode_issue.php new file mode 100644 index 00000000..f1f4a30a --- /dev/null +++ b/debug_barcode_issue.php @@ -0,0 +1,97 @@ +Análisis de $label: '$sku'"; + echo ""; +} + +$skus_to_test = ['AFS-0465', 'AFS-0466', 'AFS-0467']; + +echo "

Diagnóstico de SKU AFS-0466 (NUEVA LÓGICA AUTO)

"; + +foreach ($skus_to_test as $s) { + analyze_sku($s, "Literal en código"); +} + +// Simular generación de Barcode con la nueva lógica +$generator = new BarcodeGenerator(); +echo "

Simulación de Generación CODE128 AUTO

"; +foreach ($skus_to_test as $s) { + echo "

Generando para: $s

"; + + // Usar reflexión para acceder a getBarcodeData si fuera necesario, + // pero como ya actualizamos el archivo, podemos simplemente ver el resultado visual o recrear la lógica aquí para confirmar. + + $code = strtoupper(trim($s)); + $len = strlen($code); + $indices = []; + $currentSet = ''; + + if (ctype_digit(substr($code, 0, 2))) { + $indices[] = 105; // Start C + $currentSet = 'C'; + } else { + $indices[] = 104; // Start B + $currentSet = 'B'; + } + + $i = 0; + while ($i < $len) { + if ($currentSet == 'B') { + if ($i + 1 < $len && ctype_digit($code[$i]) && ctype_digit($code[$i+1])) { + $indices[] = 99; // Switch to C + $currentSet = 'C'; + continue; + } + $indices[] = ord($code[$i]) - 32; // Simplificado para B + $i++; + } else { + if (!($i + 1 < $len && ctype_digit($code[$i]) && ctype_digit($code[$i+1]))) { + $indices[] = 100; // Switch to B + $currentSet = 'B'; + continue; + } + $indices[] = (int)substr($code, $i, 2); + $i += 2; + } + } + + $sum = $indices[0]; + for ($k = 1; $k < count($indices); $k++) { + $sum += ($indices[$k] * $k); + } + $checksum = $sum % 103; + $indices[] = $checksum; + $indices[] = 106; // Stop + + echo "Índices CODE128 AUTO: " . implode(', ', $indices) . "
"; + echo "Checksum: $checksum
"; + echo "
"; +} +?> \ No newline at end of file diff --git a/imprimir_etiquetas_termica.php b/imprimir_etiquetas_termica.php index e477d550..9a39e4d2 100644 --- a/imprimir_etiquetas_termica.php +++ b/imprimir_etiquetas_termica.php @@ -50,8 +50,8 @@ if (empty($codes)) { grid-template-rows: repeat(3, 21mm); column-gap: 4mm; row-gap: 3mm; - padding-left: 2.5mm; - padding-top: 6.5mm; /* Aumentado de 5mm a 6.5mm */ + padding-left: 3.5mm; /* Ajustado a 3.5mm */ + padding-top: 5mm; /* Ajustado a 5mm */ background: white; box-sizing: border-box; page-break-after: always; @@ -73,22 +73,21 @@ if (empty($codes)) { } .barcode-container { - height: 11.5mm; + height: 8.5mm; /* Ajustado para que el total con texto sea 12mm */ display: flex; justify-content: center; align-items: center; - margin-top: 1.5mm; /* Añadido margen superior para bajarlo un poco */ + margin-top: 2mm; padding: 0; box-sizing: border-box; width: 100%; } .barcode-container svg { - height: 11.5mm; + height: 8.5mm; width: auto; display: block; margin: 0 auto; - /* Desactivar suavizado para máxima nitidez */ shape-rendering: crispEdges; } @@ -96,10 +95,11 @@ if (empty($codes)) { font-family: Arial, sans-serif; font-size: 3.5mm; font-weight: normal; - margin-top: 0.5mm; + margin-top: 0mm; width: 100%; - line-height: 1; + line-height: 3.5mm; color: black; + text-transform: uppercase; } @media print { @@ -142,8 +142,9 @@ if (empty($codes)) {
getBarcode($code, 0.25, 11.5, 'black', 4); + // CONFIGURACIÓN SOLICITADA (V3): + // CODE128, Narrow Bar: 0.125mm (1 dot para ancho 15mm), Height: 8.5mm (para total 12mm), Quiet Zone: 4mm + echo $generator->getBarcode($code, 0.125, 8.5, 'black', 4); ?>
diff --git a/includes/barcode_generator.php b/includes/barcode_generator.php index 6a90abea..c5b6a00f 100644 --- a/includes/barcode_generator.php +++ b/includes/barcode_generator.php @@ -41,21 +41,56 @@ class BarcodeGenerator private function getBarcodeData($code) { - $code = str_replace(' ', '', strtoupper(trim($code))); + $code = strtoupper(trim($code)); $len = strlen($code); - $indices = [104]; // Start B - - for ($i = 0; $i < $len; $i++) { - $char = $code[$i]; - $val = $this->getCharValue('B', $char); - if ($val !== null) { - $indices[] = $val; + if ($len == 0) return null; + + $indices = []; + $currentSet = ''; + + // Determine initial set + if (ctype_digit(substr($code, 0, 2))) { + $indices[] = 105; // Start C + $currentSet = 'C'; + } else { + $indices[] = 104; // Start B + $currentSet = 'B'; + } + + $i = 0; + while ($i < $len) { + if ($currentSet == 'B') { + // Check if we should switch to C (need at least 2 digits) + if ($i + 1 < $len && ctype_digit($code[$i]) && ctype_digit($code[$i+1])) { + $indices[] = 99; // Switch to C + $currentSet = 'C'; + continue; + } + + $char = $code[$i]; + $val = $this->getCharValue('B', $char); + if ($val !== null) { + $indices[] = $val; + } + $i++; + } else { // Set C + // Check if we should switch to B (if not 2 digits) + if (!($i + 1 < $len && ctype_digit($code[$i]) && ctype_digit($code[$i+1]))) { + $indices[] = 100; // Switch to B + $currentSet = 'B'; + continue; + } + + $pair = substr($code, $i, 2); + $indices[] = (int)$pair; + $i += 2; } } + // Calculate Checksum $sum = $indices[0]; - for ($i = 1; $i < count($indices); $i++) { - $sum += ($indices[$i] * $i); + for ($k = 1; $k < count($indices); $k++) { + $sum += ($indices[$k] * $k); } $checksum = $sum % 103; $indices[] = $checksum; @@ -138,4 +173,4 @@ class BarcodeGenerator ] ]; } -} \ No newline at end of file +} diff --git a/test_etiquetas.php b/test_etiquetas.php index 14163fc0..9427194c 100644 --- a/test_etiquetas.php +++ b/test_etiquetas.php @@ -2,8 +2,8 @@ require_once 'includes/barcode_generator.php'; $generator = new BarcodeGenerator(); -// Simulación de datos para prueba -$codes = ['AFS123456', 'PROD789012', 'TEST345678', 'ITEM901234', 'SKU567890', 'CODE112233', 'BAR445566', 'LBL778899', 'FIN001122']; +// SKUs de prueba incluyendo el que fallaba y sus vecinos +$codes = ['AFS-0465', 'AFS-0466', 'AFS-0467', 'AFS-0468', 'AFS-0469', 'AFS-0470', 'AFS-0471', 'AFS-0472', 'AFS-0473']; $product_names = array_fill(0, 9, 'Producto de Prueba'); ?> @@ -11,7 +11,7 @@ $product_names = array_fill(0, 9, 'Producto de Prueba'); - Prueba de Etiquetas - REDPOS 4B-2054K + Prueba de Etiquetas V4 - REDPOS 4B-2054K +
- Configuración Aplicada:
- - Hoja: 96x75mm | Margen: L:2.5mm, T:6.5mm | Gaps: C:4mm, R:3mm
- - Etiqueta: 28x21mm | Texto: Arial 3.5mm
- - Barcode: CODE128, Altura 11.5mm, Narrow Bar 0.25mm (2 dots), Quiet Zone 4mm
- - Ajuste: Margen superior de 1.5mm en barcode para centrado visual
- - Render: SVG crispEdges (Sin anti-alias) +

Configuración Aplicada (V4 - Modo Auto)

+

Cambios técnicos para solucionar AFS-0466:

+
    +
  • Lógica CODE128: Activado modo AUTO (Subconjunto B + C). Ahora los números se generan como en Excel.
  • +
  • Narrow Bar Width: 0.125mm (1 dot nativo).
  • +
  • Ancho resultante: ~14mm (Cumple rango 14-16mm).
  • +
  • Quiet Zone: 4mm (Izquierda/Derecha).
  • +
  • Render: SVG Vectorial con shape-rendering: crispEdges.
  • +
+

Si AFS-0466 no escanea con esto, es físicamente imposible a 1 dot; habría que subir a 2 dots (0.25mm) aunque el código sea más ancho.

- +
- getBarcode($code, 0.25, 11.5, 'black', 4); ?> + getBarcode($code, 0.125, 8.5, 'black', 4); ?>
@@ -155,4 +163,4 @@ $product_names = array_fill(0, 9, 'Producto de Prueba');
- \ No newline at end of file +