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 hiqdev\hiart\Query; |
15
|
|
|
use Yii; |
16
|
|
|
use yii\base\Event; |
17
|
|
|
use yii\web\NotFoundHttpException; |
18
|
|
|
|
19
|
|
|
class PlanController extends CrudController |
20
|
|
|
{ |
21
|
|
|
public function actions() |
22
|
|
|
{ |
23
|
|
|
return array_merge(parent::actions(), [ |
24
|
|
|
'create' => [ |
25
|
|
|
'class' => SmartCreateAction::class, |
26
|
|
|
], |
27
|
|
|
'update' => [ |
28
|
|
|
'class' => SmartUpdateAction::class, |
29
|
|
|
], |
30
|
|
|
'index' => [ |
31
|
|
|
'class' => IndexAction::class, |
32
|
|
|
], |
33
|
|
|
'view' => [ |
34
|
|
|
'class' => ViewAction::class, |
35
|
|
|
'on beforePerform' => function (Event $event) { |
36
|
|
|
$action = $event->sender; |
37
|
|
|
$action->getDataProvider()->query |
38
|
|
|
->joinWith('sales') |
39
|
|
|
->with([ |
40
|
|
|
'prices' => function (Query $query) { |
41
|
|
|
$query |
42
|
|
|
->addSelect('main_object_id') |
43
|
|
|
->joinWith('object') |
44
|
|
|
->limit('ALL'); |
45
|
|
|
}, |
46
|
|
|
]); |
47
|
|
|
}, |
48
|
|
|
'data' => function (Action $action, array $data) { |
49
|
|
|
return array_merge($data, [ |
50
|
|
|
'grouper' => new PlanInternalsGrouper($data['model']), |
51
|
|
|
]); |
52
|
|
|
}, |
53
|
|
|
], |
54
|
|
|
'set-note' => [ |
55
|
|
|
'class' => SmartUpdateAction::class, |
56
|
|
|
'success' => Yii::t('hipanel', 'Note changed'), |
57
|
|
|
], |
58
|
|
|
'validate-form' => [ |
59
|
|
|
'class' => ValidateFormAction::class, |
60
|
|
|
], |
61
|
|
|
]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function actionCreatePrices($id) |
65
|
|
|
{ |
66
|
|
|
$plan = Plan::findOne(['id' => $id]); |
67
|
|
|
if ($plan === null) { |
68
|
|
|
throw new NotFoundHttpException('Not found'); |
69
|
|
|
} |
70
|
|
|
$this->layout = false; |
71
|
|
|
|
72
|
|
|
return $this->renderAjax('_createPrices', ['plan' => $plan]); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|