1 | <?php |
||
30 | class BillController extends \hipanel\base\CrudController |
||
31 | { |
||
32 | public function behaviors() |
||
33 | { |
||
34 | return array_merge(parent::behaviors(), [ |
||
35 | 'access-bill' => [ |
||
36 | 'class' => AccessControl::class, |
||
37 | 'only' => ['index', 'view', 'create', 'update', 'delete'], |
||
38 | 'rules' => [ |
||
39 | [ |
||
40 | 'allow' => true, |
||
41 | 'roles' => ['manage', 'deposit'], |
||
42 | 'actions' => ['index', 'view'], |
||
43 | ], |
||
44 | [ |
||
45 | 'allow' => true, |
||
46 | 'roles' => ['bill.create'], |
||
47 | 'actions' => ['create', 'import', 'copy'], |
||
48 | ], |
||
49 | [ |
||
50 | 'allow' => true, |
||
51 | 'roles' => ['bill.update'], |
||
52 | 'actions' => ['update'], |
||
53 | ], |
||
54 | [ |
||
55 | 'allow' => true, |
||
56 | 'roles' => ['bill.delete'], |
||
57 | 'actions' => ['delete'], |
||
58 | ], |
||
59 | ], |
||
60 | 1 | ], |
|
61 | ]); |
||
62 | } |
||
63 | |||
64 | public function actions() |
||
65 | { |
||
66 | return [ |
||
67 | 'set-orientation' => [ |
||
68 | 1 | 'class' => OrientationAction::class, |
|
69 | 'allowedRoutes' => [ |
||
70 | '@bill/index', |
||
71 | ], |
||
72 | ], |
||
73 | 'index' => [ |
||
74 | 'class' => IndexAction::class, |
||
75 | 1 | 'data' => function ($action) { |
|
|
|||
76 | list($billTypes, $billGroupLabels) = $this->getTypesAndGroups(); |
||
77 | |||
78 | return compact('billTypes', 'billGroupLabels'); |
||
79 | }, |
||
80 | ], |
||
81 | 'view' => [ |
||
82 | 'class' => ViewAction::class, |
||
83 | ], |
||
84 | 'validate-form' => [ |
||
85 | 'class' => ValidateFormAction::class, |
||
86 | ], |
||
87 | 'create' => [ |
||
88 | 'class' => SmartCreateAction::class, |
||
89 | 1 | 'data' => function ($action) { |
|
90 | 1 | list($billTypes, $billGroupLabels) = $this->getTypesAndGroups(); |
|
91 | |||
92 | return compact('billTypes', 'billGroupLabels'); |
||
93 | }, |
||
94 | 1 | 'success' => Yii::t('hipanel:finance', 'Payment was created successfully'), |
|
95 | ], |
||
96 | 'update' => [ |
||
97 | 'class' => SmartUpdateAction::class, |
||
98 | 'success' => Yii::t('hipanel:finance', 'Payment was updated successfully'), |
||
99 | 1 | 'data' => function ($action) { |
|
100 | list($billTypes, $billGroupLabels) = $this->getTypesAndGroups(); |
||
101 | |||
102 | return compact('billTypes', 'billGroupLabels'); |
||
103 | 1 | }, |
|
104 | ], |
||
105 | 'copy' => [ |
||
106 | 'class' => SmartUpdateAction::class, |
||
107 | 'scenario' => 'create', |
||
108 | 'data' => function ($action, $data) { |
||
109 | foreach ($data['models'] as $model) { |
||
110 | /** @var Bill $model */ |
||
111 | $model->prepareToCopy(); |
||
112 | } |
||
113 | 1 | ||
114 | list($billTypes, $billGroupLabels) = $this->getTypesAndGroups(); |
||
115 | |||
116 | return compact('billTypes', 'billGroupLabels'); |
||
117 | 1 | } |
|
118 | ], |
||
119 | 'delete' => [ |
||
120 | 'class' => SmartPerformAction::class, |
||
121 | 'success' => Yii::t('hipanel:finance', 'Payment was deleted successfully'), |
||
122 | ], |
||
123 | ]; |
||
124 | } |
||
125 | |||
126 | public function actionImport() |
||
127 | { |
||
128 | $model = new BillImportForm([ |
||
129 | 'billTypes' => array_filter($this->getPaymentTypes(), function ($key) { |
||
130 | // Kick out items that are categories names, but not real types |
||
131 | return (strpos($key, ',') !== false); |
||
132 | }, ARRAY_FILTER_USE_KEY) |
||
133 | ]); |
||
134 | |||
135 | if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) { |
||
136 | $models = $model->parse(); |
||
137 | |||
138 | if ($models !== false) { |
||
139 | list($billTypes, $billGroupLabels) = $this->getTypesAndGroups(); |
||
140 | |||
141 | return $this->render('create', [ |
||
142 | 'models' => $models, |
||
143 | 'model' => reset($models), |
||
144 | 'billTypes' => $billTypes, |
||
145 | 'billGroupLabels' => $billGroupLabels, |
||
146 | ]); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | return $this->render('import', ['model' => $model]); |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * @return array |
||
155 | */ |
||
156 | public function getPaymentTypes() |
||
163 | |||
164 | /** |
||
165 | * @return array |
||
166 | */ |
||
167 | private function getTypesAndGroups() |
||
174 | } |
||
175 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.