Completed
Push — master ( 14088c...41674b )
by Dmitry
03:58
created

PurseController::actionGenerateInvoice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 2
crap 2
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
            'update-monthly-invoice' => [
50 1
                'class'   => SmartPerformAction::class,
51 1
                'success' => Yii::t('hipanel:finance', 'Invoice updated'),
52 1
            ],
53 1
        ];
54
    }
55
56
    public function actionGenerateInvoice($id, $month = null)
57
    {
58
        $content_type = 'application/pdf';
59
        $data = Purse::perform('generate-monthly-invoice', compact('id', 'month'));
60
        $response = Yii::$app->getResponse();
61
        $response->format = $response::FORMAT_RAW;
62
        $response->getHeaders()->add('content-type', $content_type);
63
64
        return $data;
65
    }
66
}
67