Last active
July 24, 2020 07:55
-
-
Save ahmadshobirin/ac3d16c43fe071660f75b267f0217452 to your computer and use it in GitHub Desktop.
GENERATE CODE TRANSACTION STRING PHP MYSQL
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
`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