|
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-2016, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hipanel\modules\finance\controllers; |
|
13
|
|
|
|
|
14
|
|
|
use hipanel\actions\OrientationAction; |
|
15
|
|
|
use Yii; |
|
16
|
|
|
use yii\base\Event; |
|
17
|
|
|
use yii\filters\AccessControl; |
|
18
|
|
|
use hipanel\actions\IndexAction; |
|
19
|
|
|
use hipanel\actions\PrepareBulkAction; |
|
20
|
|
|
use hipanel\actions\RedirectAction; |
|
21
|
|
|
use hipanel\actions\SmartUpdateAction; |
|
22
|
|
|
use hipanel\base\CrudController; |
|
23
|
|
|
use hipanel\modules\server\models\Change; |
|
24
|
|
|
|
|
25
|
|
|
class HeldPaymentsController extends CrudController |
|
26
|
|
|
{ |
|
27
|
|
|
public static function modelClassName() |
|
28
|
|
|
{ |
|
29
|
|
|
return Change::class; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function behaviors() |
|
33
|
|
|
{ |
|
34
|
|
|
return array_merge(parent::behaviors(), [ |
|
35
|
|
|
'access' => [ |
|
36
|
|
|
'class' => AccessControl::class, |
|
37
|
|
|
'rules' => [ |
|
38
|
|
|
[ |
|
39
|
|
|
'allow' => true, |
|
40
|
|
|
'roles' => ['resell'], |
|
41
|
|
|
], |
|
42
|
|
|
], |
|
43
|
|
|
], |
|
44
|
|
|
]); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function actions() |
|
48
|
|
|
{ |
|
49
|
|
|
return [ |
|
50
|
|
|
'index' => [ |
|
51
|
|
|
'class' => IndexAction::class, |
|
52
|
|
|
'findOptions' => ['state' => 'new', 'class' => 'merchant'], |
|
53
|
|
|
'data' => function ($action) { |
|
|
|
|
|
|
54
|
|
|
return [ |
|
55
|
|
|
'states' => Change::getStates(), |
|
56
|
|
|
]; |
|
57
|
|
|
}, |
|
58
|
|
|
], |
|
59
|
|
|
'set-orientation' => [ |
|
60
|
|
|
'class' => OrientationAction::class, |
|
61
|
|
|
'allowedRoutes' => [ |
|
62
|
|
|
'@finance/held-payments/index', |
|
63
|
|
|
], |
|
64
|
|
|
], |
|
65
|
|
|
'bulk-approve' => [ |
|
66
|
|
|
'class' => SmartUpdateAction::class, |
|
67
|
|
|
'scenario' => 'approve', |
|
68
|
|
|
'success' => Yii::t('hipanel:finance:change', 'Held payments were approved successfully'), |
|
69
|
|
|
'error' => Yii::t('hipanel:finance:change', 'Error occurred during held payments approving'), |
|
70
|
|
|
'POST html' => [ |
|
71
|
|
|
'save' => true, |
|
72
|
|
|
'success' => [ |
|
73
|
|
|
'class' => RedirectAction::class, |
|
74
|
|
|
], |
|
75
|
|
|
], |
|
76
|
|
View Code Duplication |
'on beforeSave' => function (Event $event) { |
|
|
|
|
|
|
77
|
|
|
/** @var \hipanel\actions\Action $action */ |
|
78
|
|
|
$action = $event->sender; |
|
79
|
|
|
$comment = Yii::$app->request->post('comment'); |
|
80
|
|
|
foreach ($action->collection->models as $model) { |
|
81
|
|
|
$model->setAttribute('comment', $comment); |
|
82
|
|
|
} |
|
83
|
|
|
}, |
|
84
|
|
|
], |
|
85
|
|
|
'bulk-approve-modal' => [ |
|
86
|
|
|
'class' => PrepareBulkAction::class, |
|
87
|
|
|
'scenario' => 'approve', |
|
88
|
|
|
'view' => '_bulkApprove', |
|
89
|
|
|
'findOptions' => [ |
|
90
|
|
|
'state' => Change::STATE_NEW |
|
91
|
|
|
] |
|
92
|
|
|
], |
|
93
|
|
|
'bulk-reject' => [ |
|
94
|
|
|
'class' => SmartUpdateAction::class, |
|
95
|
|
|
'scenario' => 'reject', |
|
96
|
|
|
'success' => Yii::t('hipanel:finance:change', 'Held payments were rejected successfully'), |
|
97
|
|
|
'error' => Yii::t('hipanel:finance:change', 'Error occurred during held payments rejecting'), |
|
98
|
|
|
'POST html' => [ |
|
99
|
|
|
'save' => true, |
|
100
|
|
|
'success' => [ |
|
101
|
|
|
'class' => RedirectAction::class, |
|
102
|
|
|
], |
|
103
|
|
|
], |
|
104
|
|
View Code Duplication |
'on beforeSave' => function (Event $event) { |
|
|
|
|
|
|
105
|
|
|
/** @var \hipanel\actions\Action $action */ |
|
106
|
|
|
$action = $event->sender; |
|
107
|
|
|
$comment = Yii::$app->request->post('comment'); |
|
108
|
|
|
foreach ($action->collection->models as $model) { |
|
109
|
|
|
$model->setAttribute('comment', $comment); |
|
110
|
|
|
} |
|
111
|
|
|
}, |
|
112
|
|
|
], |
|
113
|
|
|
'bulk-reject-modal' => [ |
|
114
|
|
|
'class' => PrepareBulkAction::class, |
|
115
|
|
|
'scenario' => 'reject', |
|
116
|
|
|
'view' => '_bulkReject', |
|
117
|
|
|
'findOptions' => [ |
|
118
|
|
|
'state' => Change::STATE_NEW |
|
119
|
|
|
] |
|
120
|
|
|
], |
|
121
|
|
|
]; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.