Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ahmadshobirin/ac3d16c43fe071660f75b267f0217452 to your computer and use it in GitHub Desktop.
Save ahmadshobirin/ac3d16c43fe071660f75b267f0217452 to your computer and use it in GitHub Desktop.
GENERATE CODE TRANSACTION STRING PHP MYSQL
`DEFINE FUNCTION`
protected function getCode()
{
/*PATTERN
'LINK' + year date + month date + '0000'
'0000' is generate number 4 digit
*/
$query = DB::table('mar_tra_sales_order')
->select(DB::raw("(coalesce(MAX(CAST(RIGHT(ordersn, 5)AS INT )),0))+1 as sequensialnumber"))
->where('type_so', 'Link')
->whereNotNull('ordersn')
->where('ordersn','<>', '')
->pluck('sequensialnumber')
->first();
return "LINK".date('ym').sprintf("%'.04d", $query); //'04d' used for replace/add 0 in var $query
}
`call function`
$code = $this->getCode();
//results LINK20070001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment