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
|
|
|
|