1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Finance module for HiPanel |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/hipanel-module-finance |
7
|
|
|
* @package hipanel-module-finance |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hipanel\modules\finance\models; |
13
|
|
|
|
14
|
|
|
use hipanel\modules\finance\models\decorators\AbstractResourceDecorator; |
15
|
|
|
use hipanel\modules\stock\models\Part; |
16
|
|
|
use Yii; |
17
|
|
|
use yii\base\InvalidConfigException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @property Tariff $tariff |
21
|
|
|
*/ |
22
|
|
|
class Resource extends \hipanel\base\Model |
23
|
|
|
{ |
24
|
|
|
use \hipanel\base\ModelTrait; |
25
|
|
|
|
26
|
|
|
/** @var AbstractResourceDecorator */ |
27
|
|
|
protected $decorator; |
28
|
|
|
|
29
|
|
|
/** @inheritdoc */ |
30
|
|
|
public static $i18nDictionary = 'hipanel/finance/tariff'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function rules() |
36
|
|
|
{ |
37
|
|
|
return [ |
38
|
|
|
[['id', 'tariff_id', 'object_id', 'type_id', 'unit_id', 'currency_id', 'hardlim'], 'integer'], |
39
|
|
|
[['type', 'ftype', 'unit', 'unit_factor', 'currency'], 'safe'], |
40
|
|
|
[['price', 'fee', 'quantity', 'discount'], 'number'], |
41
|
|
|
|
42
|
|
|
[['object_id', 'type_id'], 'integer', 'on' => ['create', 'update']], |
43
|
|
|
[['type'], 'safe', 'on' => ['create', 'update']], |
44
|
|
|
[['price'], 'number', 'on' => ['create', 'update']], |
45
|
|
|
'create-required' => [['object_id', 'price'], 'required', 'on' => ['create', 'update']], |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getTariff() |
50
|
|
|
{ |
51
|
|
|
return $this->hasOne(Tariff::class, ['id' => 'tariff_id'])->inverseOf('resources'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getPart() |
55
|
|
|
{ |
56
|
|
|
if (!Yii::getAlias('@part', false)) { |
57
|
|
|
throw new InvalidConfigException('Stock module is a must to retrieve resource parts'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $this->hasOne(Part::class, ['object_id' => 'id']); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
public function attributeLabels() |
67
|
|
|
{ |
68
|
|
|
return $this->mergeAttributeLabels([ |
69
|
|
|
'price' => Yii::t('hipanel/finance/tariff', 'Price per period') |
70
|
|
|
]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function isTypeCorrect() |
74
|
|
|
{ |
75
|
|
|
return isset($this->getTypes()[$this->type]); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getTypes() |
79
|
|
|
{ |
80
|
|
|
return []; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function isPeriodic() |
84
|
|
|
{ |
85
|
|
|
return $this->type === 'periodic'; |
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function decorator() |
89
|
|
|
{ |
90
|
|
|
throw new InvalidConfigException('Method "decorator" is not available for class Resource'); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.