1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Finance module for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-finance |
6
|
|
|
* @package hipanel-module-finance |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\finance\controllers; |
12
|
|
|
|
13
|
|
|
use hipanel\actions\IndexAction; |
14
|
|
|
use hipanel\actions\SmartDeleteAction; |
15
|
|
|
use hipanel\actions\SmartUpdateAction; |
16
|
|
|
use hipanel\actions\ValidateFormAction; |
17
|
|
|
use hipanel\actions\ViewAction; |
18
|
|
|
use hipanel\filters\EasyAccessControl; |
19
|
|
|
use hipanel\modules\client\models\stub\ClientRelationFreeStub; |
20
|
|
|
use hipanel\modules\finance\models\Plan; |
21
|
|
|
use Yii; |
22
|
|
|
|
23
|
|
|
class SaleController extends \hipanel\base\CrudController |
24
|
|
|
{ |
25
|
|
View Code Duplication |
public function behaviors() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
return array_merge(parent::behaviors(), [ |
28
|
|
|
[ |
29
|
|
|
'class' => EasyAccessControl::class, |
30
|
|
|
'actions' => [ |
31
|
|
|
'delete' => 'sale.delete', |
32
|
|
|
'update' => 'sale.update', |
33
|
|
|
'*' => 'sale.read', |
34
|
|
|
], |
35
|
|
|
], |
36
|
|
|
]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function actions() |
40
|
|
|
{ |
41
|
|
|
return array_merge(parent::actions(), [ |
42
|
|
|
'index' => [ |
43
|
|
|
'class' => IndexAction::class, |
44
|
|
|
], |
45
|
|
|
'view' => [ |
46
|
|
|
'class' => ViewAction::class, |
47
|
|
|
'data' => function ($action) { |
48
|
|
|
$sale = $action->model; |
49
|
|
|
$attributes = [ |
50
|
|
|
'id' => $sale->buyer_id, |
51
|
|
|
'login' => $sale->buyer, |
52
|
|
|
'seller' => $sale->seller, |
53
|
|
|
'seller_id' => $sale->seller_id, |
54
|
|
|
]; |
55
|
|
|
$client = new ClientRelationFreeStub($attributes); |
56
|
|
|
$tariff = Plan::find()->where(['id' => $sale->tariff_id])->one(); |
57
|
|
|
|
58
|
|
|
return compact('client', 'tariff'); |
59
|
|
|
}, |
60
|
|
|
], |
61
|
|
|
'update' => [ |
62
|
|
|
'class' => SmartUpdateAction::class, |
63
|
|
|
'success' => Yii::t('hipanel.finance.plan', 'Sale has been successfully changed'), |
64
|
|
|
], |
65
|
|
|
'delete' => [ |
66
|
|
|
'class' => SmartDeleteAction::class, |
67
|
|
|
'success' => Yii::t('hipanel:finance:sale', 'Sale was successfully deleted.'), |
68
|
|
|
], |
69
|
|
|
'validate-form' => [ |
70
|
|
|
'class' => ValidateFormAction::class, |
71
|
|
|
], |
72
|
|
|
]); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.