1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hipanel\modules\finance\controllers; |
4
|
|
|
|
5
|
|
|
use hipanel\actions\Action; |
6
|
|
|
use hipanel\actions\IndexAction; |
7
|
|
|
use hipanel\actions\SmartCreateAction; |
8
|
|
|
use hipanel\actions\SmartUpdateAction; |
9
|
|
|
use hipanel\actions\ValidateFormAction; |
10
|
|
|
use hipanel\actions\ViewAction; |
11
|
|
|
use hipanel\base\CrudController; |
12
|
|
|
use hipanel\modules\finance\helpers\PlanInternalsGrouper; |
13
|
|
|
use hipanel\modules\finance\models\Plan; |
14
|
|
|
use hipanel\filters\EasyAccessControl; |
15
|
|
|
use hiqdev\hiart\Query; |
16
|
|
|
use Yii; |
17
|
|
|
use yii\base\Event; |
18
|
|
|
use yii\web\NotFoundHttpException; |
19
|
|
|
|
20
|
|
|
class PlanController extends CrudController |
21
|
|
|
{ |
22
|
|
|
public function behaviors() |
23
|
|
|
{ |
24
|
|
|
return array_merge(parent::behaviors(), [ |
25
|
|
|
[ |
26
|
|
|
'class' => EasyAccessControl::class, |
27
|
|
|
'actions' => [ |
28
|
|
|
'create' => 'plan.create', |
29
|
|
|
'update' => 'plan.update', |
30
|
|
|
'*' => 'plan.read', |
31
|
|
|
], |
32
|
|
|
], |
33
|
|
|
]); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function actions() |
37
|
|
|
{ |
38
|
|
|
return array_merge(parent::actions(), [ |
39
|
|
|
'create' => [ |
40
|
|
|
'class' => SmartCreateAction::class, |
41
|
|
|
], |
42
|
|
|
'update' => [ |
43
|
|
|
'class' => SmartUpdateAction::class, |
44
|
|
|
], |
45
|
|
|
'index' => [ |
46
|
|
|
'class' => IndexAction::class, |
47
|
|
|
], |
48
|
|
|
'view' => [ |
49
|
|
|
'class' => ViewAction::class, |
50
|
|
|
'on beforePerform' => function (Event $event) { |
51
|
|
|
$action = $event->sender; |
52
|
|
|
$action->getDataProvider()->query |
53
|
|
|
->joinWith('sales') |
54
|
|
|
->with([ |
55
|
|
|
'prices' => function (Query $query) { |
56
|
|
|
$query |
57
|
|
|
->addSelect('main_object_id') |
58
|
|
|
->joinWith('object') |
59
|
|
|
->limit('ALL'); |
60
|
|
|
}, |
61
|
|
|
]); |
62
|
|
|
}, |
63
|
|
|
'data' => function (Action $action, array $data) { |
64
|
|
|
return array_merge($data, [ |
65
|
|
|
'grouper' => new PlanInternalsGrouper($data['model']), |
66
|
|
|
]); |
67
|
|
|
}, |
68
|
|
|
], |
69
|
|
|
'set-note' => [ |
70
|
|
|
'class' => SmartUpdateAction::class, |
71
|
|
|
'success' => Yii::t('hipanel', 'Note changed'), |
72
|
|
|
], |
73
|
|
|
'validate-form' => [ |
74
|
|
|
'class' => ValidateFormAction::class, |
75
|
|
|
], |
76
|
|
|
]); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function actionCreatePrices($id) |
80
|
|
|
{ |
81
|
|
|
$plan = Plan::findOne(['id' => $id]); |
82
|
|
|
if ($plan === null) { |
83
|
|
|
throw new NotFoundHttpException('Not found'); |
84
|
|
|
} |
85
|
|
|
$this->layout = false; |
86
|
|
|
|
87
|
|
|
return $this->renderAjax('_createPrices', ['plan' => $plan]); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|