Autosave: 20260522-040104

This commit is contained in:
Flatlogic Bot 2026-05-22 04:01:05 +00:00
parent 8073e5e1b3
commit 8dc1fb0062
4 changed files with 185 additions and 44 deletions

97
debug_barcode_issue.php Normal file
View File

@ -0,0 +1,97 @@
<?php
require_once 'db/config.php';
require_once 'includes/barcode_generator.php';
header('Content-Type: text/html; charset=utf-8');
function get_hex($str) {
$hex = '';
for ($i = 0; $i < strlen($str); $i++) {
$hex .= sprintf("%02X ", ord($str[$i]));
}
return trim($hex);
}
function analyze_sku($sku, $label) {
echo "<h3>Análisis de $label: '$sku'</h3>";
echo "<ul>";
echo "<li><b>Longitud:</b> " . strlen($sku) . "</li>";
echo "<li><b>HEX:</b> " . get_hex($sku) . "</li>";
echo "<li><b>Caracteres invisibles/especiales:</b> ";
$has_special = false;
for ($i = 0; $i < strlen($sku); $i++) {
$ord = ord($sku[$i]);
if ($ord < 32 || $ord > 126) {
echo "<span style='color:red'>[ORD $ord en pos $i]</span> ";
$has_special = true;
}
}
if (!$has_special) echo "Ninguno detectado (ASCII estándar)";
echo "</li>";
echo "</ul>";
}
$skus_to_test = ['AFS-0465', 'AFS-0466', 'AFS-0467'];
echo "<h2>Diagnóstico de SKU AFS-0466 (NUEVA LÓGICA AUTO)</h2>";
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 "<h2>Simulación de Generación CODE128 AUTO</h2>";
foreach ($skus_to_test as $s) {
echo "<h4>Generando para: $s</h4>";
// 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) . "<br>";
echo "Checksum: $checksum<br>";
echo "<hr>";
}
?>

View File

@ -50,8 +50,8 @@ if (empty($codes)) {
grid-template-rows: repeat(3, 21mm); grid-template-rows: repeat(3, 21mm);
column-gap: 4mm; column-gap: 4mm;
row-gap: 3mm; row-gap: 3mm;
padding-left: 2.5mm; padding-left: 3.5mm; /* Ajustado a 3.5mm */
padding-top: 6.5mm; /* Aumentado de 5mm a 6.5mm */ padding-top: 5mm; /* Ajustado a 5mm */
background: white; background: white;
box-sizing: border-box; box-sizing: border-box;
page-break-after: always; page-break-after: always;
@ -73,22 +73,21 @@ if (empty($codes)) {
} }
.barcode-container { .barcode-container {
height: 11.5mm; height: 8.5mm; /* Ajustado para que el total con texto sea 12mm */
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
margin-top: 1.5mm; /* Añadido margen superior para bajarlo un poco */ margin-top: 2mm;
padding: 0; padding: 0;
box-sizing: border-box; box-sizing: border-box;
width: 100%; width: 100%;
} }
.barcode-container svg { .barcode-container svg {
height: 11.5mm; height: 8.5mm;
width: auto; width: auto;
display: block; display: block;
margin: 0 auto; margin: 0 auto;
/* Desactivar suavizado para máxima nitidez */
shape-rendering: crispEdges; shape-rendering: crispEdges;
} }
@ -96,10 +95,11 @@ if (empty($codes)) {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
font-size: 3.5mm; font-size: 3.5mm;
font-weight: normal; font-weight: normal;
margin-top: 0.5mm; margin-top: 0mm;
width: 100%; width: 100%;
line-height: 1; line-height: 3.5mm;
color: black; color: black;
text-transform: uppercase;
} }
@media print { @media print {
@ -142,8 +142,9 @@ if (empty($codes)) {
<div class="etiqueta"> <div class="etiqueta">
<div class="barcode-container"> <div class="barcode-container">
<?php <?php
// Narrow bar: 0.25mm (2 dots), Height: 11.5mm, Quiet Zone: 4mm // CONFIGURACIÓN SOLICITADA (V3):
echo $generator->getBarcode($code, 0.25, 11.5, 'black', 4); // 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);
?> ?>
</div> </div>
<div class="sku-text"><?php echo htmlspecialchars($code); ?></div> <div class="sku-text"><?php echo htmlspecialchars($code); ?></div>

View File

@ -41,21 +41,56 @@ class BarcodeGenerator
private function getBarcodeData($code) private function getBarcodeData($code)
{ {
$code = str_replace(' ', '', strtoupper(trim($code))); $code = strtoupper(trim($code));
$len = strlen($code); $len = strlen($code);
$indices = [104]; // Start B if ($len == 0) return null;
for ($i = 0; $i < $len; $i++) { $indices = [];
$char = $code[$i]; $currentSet = '';
$val = $this->getCharValue('B', $char);
if ($val !== null) { // Determine initial set
$indices[] = $val; 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]; $sum = $indices[0];
for ($i = 1; $i < count($indices); $i++) { for ($k = 1; $k < count($indices); $k++) {
$sum += ($indices[$i] * $i); $sum += ($indices[$k] * $k);
} }
$checksum = $sum % 103; $checksum = $sum % 103;
$indices[] = $checksum; $indices[] = $checksum;
@ -138,4 +173,4 @@ class BarcodeGenerator
] ]
]; ];
} }
} }

View File

@ -2,8 +2,8 @@
require_once 'includes/barcode_generator.php'; require_once 'includes/barcode_generator.php';
$generator = new BarcodeGenerator(); $generator = new BarcodeGenerator();
// Simulación de datos para prueba // SKUs de prueba incluyendo el que fallaba y sus vecinos
$codes = ['AFS123456', 'PROD789012', 'TEST345678', 'ITEM901234', 'SKU567890', 'CODE112233', 'BAR445566', 'LBL778899', 'FIN001122']; $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'); $product_names = array_fill(0, 9, 'Producto de Prueba');
?> ?>
@ -11,7 +11,7 @@ $product_names = array_fill(0, 9, 'Producto de Prueba');
<html lang="es"> <html lang="es">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Prueba de Etiquetas - REDPOS 4B-2054K</title> <title>Prueba de Etiquetas V4 - REDPOS 4B-2054K</title>
<style> <style>
body { body {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
@ -26,7 +26,7 @@ $product_names = array_fill(0, 9, 'Producto de Prueba');
.no-print { .no-print {
margin: 20px; margin: 20px;
padding: 12px 25px; padding: 12px 25px;
background: #28a745; background: #1976d2;
color: white; color: white;
border: none; border: none;
border-radius: 6px; border-radius: 6px;
@ -40,9 +40,10 @@ $product_names = array_fill(0, 9, 'Producto de Prueba');
padding: 15px; padding: 15px;
margin: 10px; margin: 10px;
border-radius: 8px; border-radius: 8px;
border-left: 5px solid #28a745; border-left: 5px solid #1976d2;
max-width: 600px; max-width: 800px;
font-size: 14px; font-size: 14px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
} }
/* Hoja: 96mm x 75mm */ /* Hoja: 96mm x 75mm */
@ -54,13 +55,12 @@ $product_names = array_fill(0, 9, 'Producto de Prueba');
grid-template-rows: repeat(3, 21mm); grid-template-rows: repeat(3, 21mm);
column-gap: 4mm; column-gap: 4mm;
row-gap: 3mm; row-gap: 3mm;
padding-left: 2.5mm; padding-left: 3.5mm;
padding-top: 6.5mm; /* Aumentado de 5mm a 6.5mm */ padding-top: 5mm;
background: white; background: white;
box-sizing: border-box; box-sizing: border-box;
page-break-after: always; page-break-after: always;
overflow: hidden; overflow: hidden;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
} }
.etiqueta { .etiqueta {
@ -78,18 +78,18 @@ $product_names = array_fill(0, 9, 'Producto de Prueba');
} }
.barcode-container { .barcode-container {
height: 11.5mm; height: 8.5mm;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
margin-top: 1.5mm; /* Añadido margen superior para bajarlo un poco */ margin-top: 2mm;
padding: 0; padding: 0;
box-sizing: border-box; box-sizing: border-box;
width: 100%; width: 100%;
} }
.barcode-container svg { .barcode-container svg {
height: 11.5mm; height: 8.5mm;
width: auto; width: auto;
display: block; display: block;
margin: 0 auto; margin: 0 auto;
@ -100,10 +100,11 @@ $product_names = array_fill(0, 9, 'Producto de Prueba');
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
font-size: 3.5mm; font-size: 3.5mm;
font-weight: normal; font-weight: normal;
margin-top: 0.5mm; margin-top: 0mm;
width: 100%; width: 100%;
line-height: 1; line-height: 3.5mm;
color: black; color: black;
text-transform: uppercase;
} }
@media print { @media print {
@ -129,25 +130,32 @@ $product_names = array_fill(0, 9, 'Producto de Prueba');
} }
} }
</style> </style>
<script>
console.log("Versión de etiquetas: 2.0.2 (Auto Mode) - " + new Date().getTime());
</script>
</head> </head>
<body> <body>
<div class="info-box"> <div class="info-box">
<strong>Configuración Aplicada:</strong><br> <h3 style="margin-top:0; color: #1976d2;">Configuración Aplicada (V4 - Modo Auto)</h3>
- Hoja: 96x75mm | Margen: L:2.5mm, T:6.5mm | Gaps: C:4mm, R:3mm<br> <p><b>Cambios técnicos para solucionar AFS-0466:</b></p>
- Etiqueta: 28x21mm | Texto: Arial 3.5mm<br> <ul style="margin-top:0;">
- Barcode: CODE128, Altura 11.5mm, Narrow Bar 0.25mm (2 dots), Quiet Zone 4mm<br> <li><b>Lógica CODE128:</b> Activado modo <b>AUTO</b> (Subconjunto B + C). Ahora los números se generan como en Excel.</li>
- Ajuste: Margen superior de 1.5mm en barcode para centrado visual<br> <li><b>Narrow Bar Width:</b> 0.125mm (1 dot nativo).</li>
- Render: SVG crispEdges (Sin anti-alias) <li><b>Ancho resultante:</b> ~14mm (Cumple rango 14-16mm).</li>
<li><b>Quiet Zone:</b> 4mm (Izquierda/Derecha).</li>
<li><b>Render:</b> SVG Vectorial con <code>shape-rendering: crispEdges</code>.</li>
</ul>
<p style="color: #d32f2f; font-weight: bold;">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.</p>
</div> </div>
<button class="no-print" onclick="window.print()">IMPRIMIR PRUEBA</button> <button class="no-print" onclick="window.print()">IMPRIMIR PRUEBA V4</button>
<div class="etiquetas-container"> <div class="etiquetas-container">
<?php foreach ($codes as $code): ?> <?php foreach ($codes as $code): ?>
<div class="etiqueta"> <div class="etiqueta">
<div class="barcode-container"> <div class="barcode-container">
<?php echo $generator->getBarcode($code, 0.25, 11.5, 'black', 4); ?> <?php echo $generator->getBarcode($code, 0.125, 8.5, 'black', 4); ?>
</div> </div>
<div class="sku-text"><?php echo htmlspecialchars($code); ?></div> <div class="sku-text"><?php echo htmlspecialchars($code); ?></div>
</div> </div>
@ -155,4 +163,4 @@ $product_names = array_fill(0, 9, 'Producto de Prueba');
</div> </div>
</body> </body>
</html> </html>