nextgen-tech / laravel-sequence
v1.1.0
2021-06-23 13:13 UTC
Requires
- php: ^7.3|^8.0
- bensampo/laravel-enum: ^3.3
- laravel/framework: ^8.0
Requires (Dev)
- nunomaduro/larastan: ^0.7.6
- orchestra/testbench: ^6.18
- phpstan/phpstan: ^0.12.87
- phpunit/phpunit: ^9.5
- psy/psysh: ^0.10.8
README
Generate sequential numbers with pattern (e.g. for invoice numbers)
Features
- Easy integration
- Multiple pattern placeholders
- Support for three most common reset frequencies
- Automatically creating new ordinal number based on reset frequency
Installation
composer require nextgen-tech/laravel-sequence
Usage
use Carbon\Carbon; use NGT\Laravel\Sequence\Enums\ResetFrequency; use NGT\Laravel\Sequence\Models\SequenceRule; use NGT\Laravel\Sequence\SequenceFactory; /** * Create new sequence rule. It needs to be done only once. */ SequenceRule::create([ 'type' => 'invoice', 'pattern' => '{number}/COMPANY/{year}', 'reset_frequency' => ResetFrequency::YEARLY, ]); /** * Make sequence factory via container or DI. */ $factory = app(SequenceFactory::class); /** * Create sequence by passing sequence type and date (e.g. issue date of invoice). */ $sequence = $factory->create( 'invoice', Carbon::createFromFormat('Y-m-d', '2021-06-01') ); /** * Public methods of sequence. */ $ordinal = $sequence->getOrdinalNumber(); // e.g. 21 $number = $sequence->getNumber(); // e.g. 21/COMPANY/2021 $pattern = $sequence->getPattern(); // e.g. {number}/COMPANY/{year} /** * After use of generated number, manual increment of ordinal number is required. */ $sequence->increment();
Reset Frequencies
Sequences supports three most commonly used reset frequencies. \NGT\Laravel\Sequence\Enums\ResetFrequency
class should be used when creating new sequence rule.
ResetFrequency::YEARLY
- resets ordinal number at the beginning of new yearResetFrequency::MONTHLY
- resets ordinal number at the beginning of new monthResetFrequency::DAILY
- resets ordinal number at the beginning of new day