Skip to content

Instantly share code, notes, and snippets.

@abr4xas
Created February 28, 2018 20:56
Show Gist options
  • Save abr4xas/d5afe9ec9ad05d275d636a6e914e56b6 to your computer and use it in GitHub Desktop.
Save abr4xas/d5afe9ec9ad05d275d636a6e914e56b6 to your computer and use it in GitHub Desktop.
<php
class NameClass {
/**
* Genera numero secuencial de solicitud
*/
public function getNextOrderNumber()
{
// Get the last created order
$lastOrder = TuModelo::orderBy('created_at', 'desc')->first();
if (!$lastOrder)
// We get here if there is no order at all
// If there is no number set it to 0, which will be 1 at the end.
$number = 0;
else
$number = substr($lastOrder->nunfactura, 3);
// If we have SOL0000001 in the database then we only want the number
// So the substr returns this 0000001
// Add the string in front and higher up the number.
// the %07d part makes sure that there are always 7 numbers in the string.
// so it adds the missing zero's when needed.
return 'SOL' . sprintf('%07d', intval($number) + 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment