|
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-2017, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hipanel\modules\finance\logic; |
|
12
|
|
|
|
|
13
|
|
|
use hipanel\models\Ref; |
|
14
|
|
|
use hipanel\modules\finance\forms\CertificateTariffForm; |
|
15
|
|
|
use hipanel\modules\finance\models\Tariff; |
|
16
|
|
|
use hiqdev\hiart\ConnectionInterface; |
|
17
|
|
|
use hiqdev\hiart\ResponseErrorException; |
|
18
|
|
|
use Yii; |
|
19
|
|
|
use yii\base\InvalidConfigException; |
|
20
|
|
|
use yii\web\NotFoundHttpException; |
|
21
|
|
|
use yii\web\UnprocessableEntityHttpException; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class CertificateTariffManager |
|
25
|
|
|
* |
|
26
|
|
|
* @author Dmytro Naumenko <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
class CertificateTariffManager extends AbstractTariffManager |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var CertificateTariffForm |
|
32
|
|
|
*/ |
|
33
|
|
|
public $form; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $type = Tariff::TYPE_CERT; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var ConnectionInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
private $connection; |
|
44
|
|
|
|
|
45
|
|
|
public function __construct(ConnectionInterface $connection, $config = []) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->connection = $connection; |
|
48
|
|
|
|
|
49
|
|
|
parent::__construct($config); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function init() |
|
53
|
|
|
{ |
|
54
|
|
|
if (!Yii::getAlias('@certificate', true)) { |
|
55
|
|
|
throw new InvalidConfigException('Certificate module is missing'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
parent::init(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function determineParentTariff() |
|
62
|
|
|
{ |
|
63
|
|
|
$id = parent::determineParentTariff(); |
|
64
|
|
|
|
|
65
|
|
|
if ($id === null) { |
|
66
|
|
|
$tariff = reset(Tariff::find() |
|
|
|
|
|
|
67
|
|
|
->action('get-available-info') |
|
68
|
|
|
->andFilterWhere(['type' => $this->type]) |
|
69
|
|
|
->all()); |
|
70
|
|
|
|
|
71
|
|
|
if ($tariff instanceof Tariff) { |
|
72
|
|
|
$id = $tariff->id; |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $id; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
protected function getFormOptions() |
|
80
|
|
|
{ |
|
81
|
|
|
return array_merge([ |
|
82
|
|
|
'class' => CertificateTariffForm::class, |
|
83
|
|
|
'certificateTypes' => Ref::getList('type,certificate', 'hipanel:certificate', [ |
|
84
|
|
|
'select' => 'id_label', |
|
85
|
|
|
'mapOptions' => ['from' => 'id'], |
|
86
|
|
|
]), |
|
87
|
|
|
], parent::getFormOptions()); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|