2017 © Pedro Peláez
 

yii2-extension yii2-autonumber

Auto number extension for the Yii framework

image

mdmsoft/yii2-autonumber

Auto number extension for the Yii framework

  • Saturday, February 6, 2016
  • by mdmunir
  • Repository
  • 5 Watchers
  • 12 Stars
  • 12,749 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 12 Forks
  • 0 Open issues
  • 6 Versions
  • 9 % Grown

The README.md

Auto Number Extension for Yii 2

Yii2 extension to genarete formated autonumber. It can be used for generate document number., (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist mdmsoft/yii2-autonumber "~1.0"

or add, (*4)

"mdmsoft/yii2-autonumber": "~1.0"

to the require section of your composer.json file., (*5)

Usage

Prepare required table by execute yii migrate., (*6)

yii migrate --migrationPath=@mdm/autonumber/migrations

if wantn't use db migration. you can create required table manually., (*7)

CREATE TABLE auto_number (
    "group" varchar(32) NOT NULL,
    "number" int,
    optimistic_lock int,
    update_time int,
    PRIMARY KEY ("group")
);

Once the extension is installed, simply modify your ActiveRecord class:, (*8)

public function behaviors()
{
    return [
        [
            'class' => 'mdm\autonumber\Behavior',
            'attribute' => 'sales_num', // required
            'group' => $this->id_branch, // optional
            'value' => 'SA.'.date('Y-m-d').'.?' , // format auto number. '?' will be replaced with generated number
            'digit' => 4 // optional, default to null. 
        ],
    ];
}

// it will set value $model->sales_num as 'SA.2014-06-25.0001'

Instead of behavior, you can use this extension as validator, (*9)

public function rules()
{
    return [
        [['sales_num'], 'autonumber', 'format'=>'SA.'.date('Y-m-d').'.?'],
        ...
    ];
}

New Format

Since version 1.5 we introduce new format of number. Now we use {} to evaluate as date and number of digit represented as number of ?., (*10)

public function rules()
{
    return [
        [['sales_num'], 'autonumber', 'format' => 'SA/{Y/m}/?.???'],
        ...
    ];
}

// it will set value $model->sales_num as 'SA/2019/10/0.001'


public function behaviors()
{
    return [
        [
            'class' => 'class' => 'mdm\autonumber\Behavior',
            'attribute' => 'sales_num', // required
            'value' => 'SA/{Y/m}/?.???'
        ]
    ];
}

// another usage

public function actionCreate()
{
    $model = new Sales()
    $model->load(Yii::$app->request->post());
    $model->sales_num = mdm\autonumber\AutoNumber::generate('SA/{Y/m}/?.???');
    ...
}

The Versions

06/02 2016

dev-master

9999999-dev

Auto number extension for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

by Misbahul D Munir

yii2 extension behavior autonumber

06/02 2016

1.4

1.4.0.0

Auto number extension for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

by Misbahul D Munir

yii2 extension behavior autonumber

02/02 2016

1.3

1.3.0.0

Auto number extension for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

by Misbahul D Munir

yii2 extension behavior autonumber

26/07 2015

1.2

1.2.0.0

Auto number extension for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

by Misbahul D Munir

yii2 extension behavior autonumber

23/07 2015

1.1

1.1.0.0

Auto number extension for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

by Misbahul D Munir

yii2 extension behavior autonumber

02/11 2014

1.0.0

1.0.0.0

Auto number extension for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

by Misbahul D Munir

yii2 extension behavior autonumber