Passed
Push — master ( 540769...d71d6d )
by Joe Nilson
01:52
created

FiscalReports::createViews()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
/*
3
 * Copyright (C) 2019 joenilson.
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 3 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA 02110-1301  USA
19
 */
20
21
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Controller;
22
23
use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Base\DataBase\DataBaseWhere was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use FacturaScripts\Core\Lib\ExtendedController\ListController;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Lib\...ntroller\ListController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use FacturaScripts\Dinamic\Model\Ejercicio;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\Ejercicio was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use FacturaScripts\Dinamic\Model\ReportBalance;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\ReportBalance was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
28
/**
29
 * Description of FiscalReports
30
 *
31
 * @author joenilson
32
 */
33
class FiscalReports extends ListController
34
{
35
    /**
36
     *
37
     * @var array
38
     */
39
    private $companyList;
40
41
    public function getPageData(): array
42
    {
43
        $pageData = parent::getPageData();
44
        $pageData['title'] = 'fiscal-reports';
45
        $pageData['menu'] = 'reports';
46
        $pageData['submenu'] = 'dominican-republic';
47
        $pageData['icon'] = 'fas fa-hand-holding-usd';
48
        return $pageData;
49
    }
50
51
    /**
52
     * Add to indicated view a filter select with company list
53
     *
54
     * @param string $viewName
55
     */
56
    private function addCommonFilter(string $viewName)
57
    {
58
        if (empty($this->companyList)) {
59
            $this->companyList = $this->codeModel->all('empresas', 'idempresa', 'nombrecorto');
60
        }
61
        $this->addFilterSelect($viewName, 'idcompany', 'company', 'idcompany', $this->companyList);
62
        $this->addFilterNumber($viewName, 'channel', 'channel', 'channel', '=');
63
        $this->addFilterPeriod($viewName, 'fecha', 'date', 'fecha');
64
    }
65
66
    /**
67
     *
68
     * @param string $viewName
69
     */
70
    protected function addGenerateButton(string $viewName)
71
    {
72
//        $this->addButton($viewName, [
73
//            'action' => 'generate-balances',
74
//            'color' => 'warning',
75
//            'confirm' => true,
76
//            'icon' => 'fas fa-magic',
77
//            'label' => 'generate'
78
//        ]);
79
    }
80
81
    /**
82
     * Inserts the views or tabs to display.
83
     */
84
    protected function createViews()
85
    {
86
//        $this->createViewsLedger();
87
        $this->createViewsAmount();
88
//        $this->createViewsBalance();
89
//        $this->createViewsPreferences();
90
    }
91
92
    /**
93
     * Inserts the view for amount balances.
94
     *
95
     * @param string $viewName
96
     */
97
    protected function createViewsAmount(string $viewName = 'FiscalReports')
98
    {
99
        $this->addView($viewName, 'FiscalReports', 'fiscal-reports', 'fas fa-hand-holding-usd');
100
        $this->addOrderBy($viewName, ['fecha'], 'fecha');
101
        $this->addOrderBy($viewName, ['idcompany', 'fecha'], 'company');
102
        $this->addSearchFields($viewName, ['ncf']);
103
        $this->addCommonFilter($viewName);
104
        $this->addGenerateButton($viewName);
105
    }
106
107
    /**
108
     *
109
     * @param string $action
110
     *
111
     * @return bool
112
     */
113
    protected function execPreviousAction($action)
114
    {
115
        switch ($action) {
116
            case 'generate-balances':
117
                return $this->generateBalancesAction();
118
            default:
119
                return parent::execPreviousAction($action);
120
        }
121
    }
122
123
    /**
124
     *
125
     * @return bool
126
     */
127
    protected function generateBalancesAction(): bool
128
    {
129
        $total = 0;
130
        $ejercicioModel = new Ejercicio();
131
        foreach ($ejercicioModel->all() as $eje) {
132
            $this->generateBalances($total, $eje);
133
        }
134
135
        $this->toolBox()->i18nLog()->notice('items-added-correctly', ['%num%' => $total]);
136
        return true;
137
    }
138
139
    /**
140
     * Load values into special widget columns
141
     *
142
     * @param string $viewName
143
     */
144
    protected function loadWidgetValues($viewName)
145
    {
146
        $typeColumn = $this->views[$viewName]->columnForField('type');
147
        if ($typeColumn) {
148
            $typeColumn->widget->setValuesFromArray(ReportBalance::typeList());
149
        }
150
151
        $formatColumn = $this->views[$viewName]->columnForField('subtype');
152
        if ($formatColumn) {
153
            $formatColumn->widget->setValuesFromArray(ReportBalance::subtypeList());
154
        }
155
    }
156
}
157