Completed
Push — master ( 3bfee6...c87263 )
by Dmitry
29:30
created

Plan::getPrices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace hipanel\modules\finance\models;
4
5
use hipanel\models\Ref;
6
use Yii;
7
8
/**
9
 * Class Plan
10
 *
11
 * @property string $id
12
 * @property string $name
13
 *
14
 * @property Sale[] $sales
15
 * @property Price[] $prices
16
 *
17
 * @author Dmytro Naumenko <[email protected]>
18
 */
19
class Plan extends \hipanel\base\Model
20
{
21
    use \hipanel\base\ModelTrait;
22
23
    public function rules()
24
    {
25
        return array_merge(parent::rules(), [
26
            [['id', 'type_id', 'state_id', 'client_id'], 'integer'],
27
            [['type', 'state', 'client', 'name', 'note'], 'string'],
28
29
            [['type', 'name'], 'required', 'on' => 'create'],
30
            [['id'], 'required', 'on' => ['update', 'delete', 'set-note']],
31
        ]);
32
    }
33
34
    public function attributeLabels()
35
    {
36
        return array_merge(parent::attributeLabels(), [
37
            'name' => Yii::t('hipanel:finance', 'Name'),
38
        ]);
39
    }
40
41
    public function getPrices()
42
    {
43
        return $this->hasMany(Price::class, ['plan_id' => 'id']);
44
    }
45
46
    public function getSales()
47
    {
48
        return $this->hasMany(Sale::class, ['tariff_id' => 'id']);
49
    }
50
51
    public function getTypeOptions()
52
    {
53
        return Ref::getList('type,tariff');
54
    }
55
56
    public function getStateOptions()
57
    {
58
        return Ref::getList('state,tariff');
59
    }
60
}
61