1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hipanel\modules\finance\controllers; |
4
|
|
|
|
5
|
|
|
use hipanel\actions\IndexAction; |
6
|
|
|
use hipanel\actions\SmartCreateAction; |
7
|
|
|
use hipanel\actions\SmartUpdateAction; |
8
|
|
|
use hipanel\actions\ValidateFormAction; |
9
|
|
|
use hipanel\actions\ViewAction; |
10
|
|
|
use hipanel\base\CrudController; |
11
|
|
|
use hipanel\modules\finance\models\Plan; |
12
|
|
|
use hipanel\modules\finance\models\Price; |
13
|
|
|
use Yii; |
14
|
|
|
|
15
|
|
|
class PriceController extends CrudController |
16
|
|
|
{ |
17
|
|
|
public function actions() |
18
|
|
|
{ |
19
|
|
|
return array_merge(parent::actions(), [ |
20
|
|
|
'create' => [ |
21
|
|
|
'class' => SmartCreateAction::class, |
22
|
|
|
'data' => function ($action, $data) { |
|
|
|
|
23
|
|
|
$plan = null; |
24
|
|
|
if ($plan_id = Yii::$app->request->get('plan_id')) { |
25
|
|
|
$plan = Plan::findOne(['id' => $plan_id]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
return compact('plan'); |
29
|
|
|
}, |
30
|
|
|
], |
31
|
|
|
'update' => [ |
32
|
|
|
'class' => SmartUpdateAction::class, |
33
|
|
|
], |
34
|
|
|
'index' => [ |
35
|
|
|
'class' => IndexAction::class, |
36
|
|
|
], |
37
|
|
|
'view' => [ |
38
|
|
|
'class' => ViewAction::class, |
39
|
|
|
], |
40
|
|
|
'set-note' => [ |
41
|
|
|
'class' => SmartUpdateAction::class, |
42
|
|
|
'success' => Yii::t('hipanel', 'Note changed'), |
43
|
|
|
], |
44
|
|
|
'validate-form' => [ |
45
|
|
|
'class' => ValidateFormAction::class, |
46
|
|
|
], |
47
|
|
|
]); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function actionSuggest($object_id, $plan_id, $type = 'default') |
51
|
|
|
{ |
52
|
|
|
$plan = Plan::findOne(['id' => $plan_id]); |
53
|
|
|
|
54
|
|
|
$suggestions = (new Price)->batchQuery('suggest', [ |
55
|
|
|
'object_id' => $object_id, |
56
|
|
|
'plan_id' => $plan_id, |
57
|
|
|
'type' => $type |
58
|
|
|
]); |
59
|
|
|
|
60
|
|
|
$models = []; |
61
|
|
|
foreach ($suggestions as $suggestion) { |
62
|
|
|
$models[] = new Price([ |
63
|
|
|
'type' => $suggestion['type']['name'], |
64
|
|
|
'type_id' => $suggestion['type']['id'], |
65
|
|
|
'object_id' => $suggestion['target']['id'], |
66
|
|
|
'object' => $suggestion['target']['name'], |
67
|
|
|
'unit' => $suggestion['prepaid']['unit'], |
68
|
|
|
'quantity' => $suggestion['prepaid']['quantity'], |
69
|
|
|
'unit_id' => 0, // todo |
70
|
|
|
'price' => $suggestion['price']['amount'] / 100, |
71
|
|
|
'currency' => $suggestion['price']['currency'] |
72
|
|
|
]); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $this->render('create', [ |
76
|
|
|
'model' => reset($models), |
77
|
|
|
'models' => $models, |
78
|
|
|
'plan' => $plan |
79
|
|
|
]); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.