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-2019, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hipanel\modules\finance\controllers; |
13
|
|
|
|
14
|
|
|
use hipanel\actions\IndexAction; |
15
|
|
|
use hipanel\actions\RenderAction; |
16
|
|
|
use hipanel\base\CrudController; |
17
|
|
|
use hipanel\filters\EasyAccessControl; |
18
|
|
|
use hipanel\modules\finance\models\query\ChargeQuery; |
19
|
|
|
use hipanel\modules\finance\providers\BillTypesProvider; |
20
|
|
|
use yii\base\Event; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class ChargeController |
24
|
|
|
* @package hipanel\modules\finance\controllers |
25
|
|
|
*/ |
26
|
|
|
class ChargeController extends CrudController |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var BillTypesProvider |
30
|
|
|
*/ |
31
|
|
|
private $billTypesProvider; |
32
|
|
|
|
33
|
|
|
public function __construct($id, $module, BillTypesProvider $billTypesProvider, $config = []) |
34
|
|
|
{ |
35
|
|
|
parent::__construct($id, $module, $config); |
36
|
|
|
|
37
|
|
|
$this->billTypesProvider = $billTypesProvider; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @inheritDoc |
42
|
|
|
*/ |
43
|
|
|
public function behaviors() |
44
|
|
|
{ |
45
|
|
|
return array_merge(parent::behaviors(), [ |
46
|
|
|
'access-bill' => [ |
47
|
|
|
'class' => EasyAccessControl::class, |
48
|
|
|
'actions' => [ |
49
|
|
|
'*' => 'bill.charges.read', |
50
|
|
|
], |
51
|
|
|
], |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @inheritDoc |
57
|
|
|
*/ |
58
|
|
|
public function actions() |
59
|
|
|
{ |
60
|
|
|
return array_merge(parent::actions(), [ |
61
|
|
|
'index' => [ |
62
|
|
|
'class' => IndexAction::class, |
63
|
|
|
'on beforePerform' => function (Event $event) { |
64
|
|
|
/** @var ChargeQuery $query */ |
65
|
|
|
$query = $event->sender->getDataProvider()->query; |
66
|
|
|
$query->withCommonObject()->withLatestCommonObject(); |
67
|
|
|
}, |
68
|
|
|
'data' => function (RenderAction $action, array $data): array { |
|
|
|
|
69
|
|
|
[$billTypes, $billGroupLabels] = $this->getTypesAndGroups(); |
70
|
|
|
|
71
|
|
|
return compact('billTypes', 'billGroupLabels'); |
72
|
|
|
}, |
73
|
|
|
], |
74
|
|
|
]); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
private function getTypesAndGroups() |
81
|
|
|
{ |
82
|
|
|
return $this->billTypesProvider->getGroupedList(); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.