nasrulhazim
11/18/2017 - 3:54 AM

Generate Document Reference Number

Generate Document Reference Number

<?php

/**
 * I use abbrv() function in https://gist.github.com/nasrulhazim/df8f4046cceb37ab61fa5d5c0c65dba6
 * And for str_random() from Laravel Framework 
 **/
if (!function_exists('generate_reference_number')) {
    function generate_reference_number($module_label, $module_component = null)
    {
        if (empty($module_label)) {
            return '';
        }

        $reference_number[] = strtoupper(abbrv($module_label));
        $reference_number[] = strtoupper(abbrv($module_component));
        $reference_number[] = date('Y/m/d');
        // i'm using Laravel Helper, you may add your own functino to generate random string OR
        // you may have other option to generate reference number like
        // using hashing, based on module, based on sequence number, etc.
        $reference_number[] = strtoupper(str_random(12));

        return implode('/', $reference_number);
    }
}

// Usage
echo generate_reference_number('claim', 'application') . PHP_EOL; // CLM/PLCTN/2017/11/18/MUGYTSNWH9U7