|
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\widgets; |
|
12
|
|
|
|
|
13
|
|
|
use hipanel\inputs\OptionsInput; |
|
14
|
|
|
use hipanel\modules\finance\models\ServerResource; |
|
15
|
|
|
use yii\base\Widget; |
|
16
|
|
|
use yii\helpers\Html; |
|
17
|
|
|
use yii\widgets\ActiveField; |
|
18
|
|
|
|
|
19
|
|
|
final class PrepaidAmountWidget extends Widget |
|
20
|
|
|
{ |
|
21
|
|
|
public $model; |
|
22
|
|
|
public $attribute; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var ActiveField |
|
26
|
|
|
*/ |
|
27
|
|
|
public $activeField; |
|
28
|
|
|
|
|
29
|
|
|
/** @var ServerResource */ |
|
30
|
|
|
public $resource; |
|
31
|
|
|
|
|
32
|
|
|
public function init() |
|
33
|
|
|
{ |
|
34
|
|
|
Html::addCssClass($this->activeField->options, 'form-group-sm'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function run() |
|
38
|
|
|
{ |
|
39
|
|
|
$type = $this->resource->decorator()->prepaidAmountType(); |
|
40
|
|
|
|
|
41
|
|
|
if ($type instanceof OptionsInput) { |
|
42
|
|
|
echo $this->renderDropdownInput($type); |
|
43
|
|
|
} else { |
|
44
|
|
|
echo $this->renderTextInput($type); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
private function renderTextInput($type) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
$this->activeField->template = "{label}\n<div class=\"input-group\">{input}</div>\n{hint}\n{error}"; |
|
51
|
|
|
|
|
52
|
|
|
return $this->activeField->input('number', [ |
|
53
|
|
|
'class' => 'form-control price-input', |
|
54
|
|
|
'autocomplete' => false, |
|
55
|
|
|
'step' => 'any', |
|
56
|
|
|
'data' => [ |
|
57
|
|
|
'min-price' => $this->resource->getMinimumQuantity(), |
|
58
|
|
|
], |
|
59
|
|
|
'value' => $this->resource->decorator()->getPrepaidQuantity(), |
|
60
|
|
|
]); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
private function renderDropdownInput(OptionsInput $boolean) |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->activeField->dropDownList($boolean->getOptions(), [ |
|
66
|
|
|
'class' => 'form-control', |
|
67
|
|
|
'value' => $this->resource->decorator()->getPrepaidQuantity(), |
|
68
|
|
|
]); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.