1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Finance module for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-finance |
6
|
|
|
* @package hipanel-module-finance |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\finance\models; |
12
|
|
|
|
13
|
|
|
use Yii; |
14
|
|
|
use yii\base\Model; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class PriceSuggestionRequestForm. |
18
|
|
|
* |
19
|
|
|
* @author Dmytro Naumenko <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class PriceSuggestionRequestForm extends Model |
22
|
|
|
{ |
23
|
|
|
public const SCENARIO_PREDEFINED_OBJECT = 'predefinedObject'; |
24
|
|
|
|
25
|
|
|
public $plan_id; |
26
|
|
|
|
27
|
|
|
public $plan_type; |
28
|
|
|
|
29
|
|
|
public $template_plan_id; |
30
|
|
|
|
31
|
|
|
public $type; |
32
|
|
|
|
33
|
|
|
public $object_id; |
34
|
|
|
|
35
|
|
|
public function formName() |
36
|
|
|
{ |
37
|
|
|
return ''; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function rules() |
41
|
|
|
{ |
42
|
|
|
$result = [ |
43
|
|
|
[['plan_id', 'type'], 'required', 'on' => [self::SCENARIO_DEFAULT, self::SCENARIO_PREDEFINED_OBJECT]], |
44
|
|
|
[['object_id', 'type'], 'required', 'on' => [self::SCENARIO_DEFAULT]], |
45
|
|
|
[['plan_id', 'object_id', 'template_plan_id'], 'integer', 'on' => [self::SCENARIO_DEFAULT, self::SCENARIO_PREDEFINED_OBJECT]], |
46
|
|
|
[['type'], 'safe', 'on' => [self::SCENARIO_DEFAULT, self::SCENARIO_PREDEFINED_OBJECT]], |
47
|
|
|
]; |
48
|
|
|
if ($this->plan_type !== Plan::TYPE_TEMPLATE) { |
49
|
|
|
$result[] = [['template_plan_id'], 'required']; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $result; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function isObjectPredefined(): bool |
56
|
|
|
{ |
57
|
|
|
return $this->scenario === self::SCENARIO_PREDEFINED_OBJECT; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function attributeLabels() |
61
|
|
|
{ |
62
|
|
|
return [ |
63
|
|
|
'plan_id' => Yii::t('hipanel.finance.price', 'Tariff plan'), |
64
|
|
|
'template_plan_id' => Yii::t('hipanel.finance.price', 'Template tariff plan'), |
65
|
|
|
'type' => Yii::t('hipanel', 'Type'), |
66
|
|
|
'object_id' => Yii::t('hipanel', 'Object'), |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|