Completed
Push — master ( 62d2ea...1993b9 )
by Andrii
11:09
created

Charge::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace hipanel\modules\finance\models;
4
5
use Yii;
6
7
class Charge extends \hiqdev\hiart\ActiveRecord
8
{
9
    const SCENARIO_CREATE = 'create';
10
    const SCENARIO_UPDATE = 'update';
11
12
    private $isNewRecord;
13
14
    public function rules()
15
    {
16
        return [
17
            [['id', 'type_id', 'object_id', 'bill_id'], 'integer'],
18
            [['type', 'label', 'ftype'], 'safe'],
19
            [['sum', 'quantity'], 'number'],
20
21
            [['sum', 'type', 'label', 'quantity'], 'required', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]],
22
            [['id'], 'safe', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]]
23
        ];
24
    }
25
26
    public function attributeLabels()
27
    {
28
        return array_merge(parent::attributeLabels(), [
29
            'sum' => Yii::t('hipanel', 'Sum'),
30
            'type' => Yii::t('hipanel', 'Type'),
31
            'quantity' => Yii::t('hipanel', 'Quantity'),
32
            'label' => Yii::t('hipanel', 'Description'),
33
        ]);
34
    }
35
36
    public function markAsNotNew()
37
    {
38
        $this->isNewRecord = false;
39
    }
40
41
    public function getIsNewRecord()
42
    {
43
        return $this->isNewRecord !== false && parent::getIsNewRecord();
44
    }
45
}
46