Created
March 8, 2018 21:31
-
-
Save enzojimenez/d34578b2803ac4c59b03b1201e54b79c to your computer and use it in GitHub Desktop.
Código alfanúmerico para FE en PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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