Completed
Push — master ( 0a64ef...c3bb5e )
by Dmitry
13:05
created

PurseController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 61
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A actionGenerateMonthlyDocument() 0 7 1
A actionGenerateDocument() 0 7 1
A asPdf() 0 6 1
B actions() 0 35 1
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-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\controllers;
12
13
use hipanel\actions\IndexAction;
14
use hipanel\actions\RedirectAction;
15
use hipanel\actions\SmartPerformAction;
16
use hipanel\actions\SmartUpdateAction;
17
use hipanel\actions\ValidateFormAction;
18
use hipanel\actions\ViewAction;
19
use hipanel\modules\finance\models\Purse;
20
use Yii;
21
22
class PurseController extends \hipanel\base\CrudController
23
{
24 1
    public function actions()
25
    {
26
        return [
27
            'index' => [
28
                'class' => IndexAction::class,
29 1
            ],
30
            'view' => [
31
                'class' => ViewAction::class,
32 1
            ],
33
            'update' => [
34
                'class' => SmartUpdateAction::class,
35 1
            ],
36
            'update-contact' => [
37
                'class' => SmartUpdateAction::class,
38 1
            ],
39
            'update-requisite' => [
40
                'class' => SmartUpdateAction::class,
41 1
            ],
42
            'validate-form' => [
43
                'class' => ValidateFormAction::class,
44 1
            ],
45
            'invoice-archive' => [
46 1
                'class' => RedirectAction::class,
47 1
                'error' => Yii::t('hipanel', 'Under construction'),
48 1
            ],
49
            'generate-and-save-monthly-document' => [
50 1
                'class'   => SmartPerformAction::class,
51 1
                'success' => Yii::t('hipanel:finance', 'Document updated'),
52 1
            ],
53
            'generate-and-save-document' => [
54 1
                'class'   => SmartPerformAction::class,
55 1
                'success' => Yii::t('hipanel:finance', 'Document updated'),
56 1
            ],
57 1
        ];
58
    }
59
60
    public function actionGenerateMonthlyDocument($id, $type, $month = null)
61
    {
62
        $data = Purse::perform('generate-monthly-document', compact('id', 'type', 'month'));
63
        $this->asPdf();
64
65
        return $data;
66
    }
67
68
    public function actionGenerateDocument($id, $type)
69
    {
70
        $data = Purse::perform('generate-monthly-document', compact('id', 'type'));
71
        $this->asPdf();
72
73
        return $data;
74
    }
75
76
    protected function asPdf()
77
    {
78
        $response = Yii::$app->getResponse();
79
        $response->format = $response::FORMAT_RAW;
80
        $response->getHeaders()->add('content-type', 'application/pdf');
81
    }
82
}
83