97 lines
2.8 KiB
PHP
97 lines
2.8 KiB
PHP
<?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>";
|
|
}
|
|
?>
|