Completed
Push — master ( 62d2ea...1993b9 )
by Andrii
11:09
created

SaleController::actions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 24
rs 8.9713
c 1
b 0
f 0
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
3
namespace hipanel\modules\finance\controllers;
4
5
use hipanel\actions\IndexAction;
6
use hipanel\actions\ViewAction;
7
use hipanel\modules\client\models\stub\ClientRelationFreeStub;
8
use hipanel\modules\finance\logic\TariffManagerFactory;
9
use hipanel\modules\finance\models\Tariff;
10
use yii\base\Event;
11
12
class SaleController extends \hipanel\base\CrudController
13
{
14
    public function actions()
15
    {
16
        return [
17
            'index' => [
18
                'class' => IndexAction::class,
19
            ],
20
            'view' => [
21
                'class' => ViewAction::class,
22
                'data' => function ($action) {
23
                    $sale = $action->model;
24
                    $attributes = [
25
                        'id' => $sale->buyer_id,
26
                        'login' => $sale->buyer,
27
                        'seller' => $sale->seller,
28
                        'seller_id' => $sale->seller_id,
29
                    ];
30
                    $client = new ClientRelationFreeStub($attributes);
31
                    $tariff = Tariff::find()->where(['id' => $sale->tariff_id])->one();
32
33
                    return compact('client', 'tariff');
34
                },
35
            ],
36
        ];
37
    }
38
}
39