Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nick2474/c8944750f7946b5e6d1b75e22a0d3156 to your computer and use it in GitHub Desktop.
Save nick2474/c8944750f7946b5e6d1b75e22a0d3156 to your computer and use it in GitHub Desktop.
Código alfanúmerico para FE en PHP
<?php
$letras = ""; // Obtengo la LETRA guardada en la base de datos
$consecutivo = 1; // Obtengo el ID guardado en en la base de datos
$top = "9999999999"; // Obtengo el TOP guardado en en la base de datos
if ($consecutivo > (int)$top){
$consecutivo = 1;
if ($letras == ""){
$letras = "A";
} else {
$len_letras = strlen($letras);
if (substr($letras,($len_letras - 1),1) == "Z"){
$letras = "";
for($i=0;$i<=$len_letras;$i++){
$letras .= "A";
}
} else {
$letras++;
}
}
}
$len_letras = strlen($letras);
$len_top = strlen($top);
$top = substr($top,$len_letras,($len_top - $len_letras));
$consecutivo_xml = $letras.str_pad($consecutivo,(10-$len_letras),'0',STR_PAD_LEFT);
echo $consecutivo_xml;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment