Completed
Push — master ( 156270...ac2069 )
by Andrii
04:03
created

PurseController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 66.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 0
cbo 3
dl 0
loc 36
ccs 14
cts 21
cp 0.6667
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A actionGenerateInvoice() 0 10 1
A actions() 0 22 1
1
<?php
2
3
/*
4
 * Finance module for HiPanel
5
 *
6
 * @link      https://github.com/hiqdev/hipanel-module-finance
7
 * @package   hipanel-module-finance
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\modules\finance\controllers;
13
14
use hipanel\actions\IndexAction;
15
use hipanel\actions\RedirectAction;
16
use hipanel\actions\SmartPerformAction;
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 1
                'class' => IndexAction::class,
29 1
            ],
30
            'view' => [
31 1
                'class' => ViewAction::class,
32 1
            ],
33
            'validate-form' => [
34 1
                'class' => ValidateFormAction::class,
35 1
            ],
36
            'invoice-archive' => [
37 1
                'class' => RedirectAction::class,
38 1
                'error' => Yii::t('app', 'Under construction'),
39 1
            ],
40
            'update-monthly-invoice' => [
41 1
                'class'   => SmartPerformAction::class,
42 1
                'success' => Yii::t('app', 'Invoice updated'),
43 1
            ],
44 1
        ];
45
    }
46
47
    public function actionGenerateInvoice($id, $month = null)
48
    {
49
        $content_type = 'application/pdf';
50
        $data = Purse::perform('GenerateMonthlyInvoice', compact('id', 'month'));
51
        $response = Yii::$app->getResponse();
52
        $response->format = $response::FORMAT_RAW;
53
        $response->getHeaders()->add('content-type', $content_type);
54
55
        return $data;
56
    }
57
}
58