ListNCFTipoPago   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 52
c 1
b 0
f 1
dl 0
loc 77
rs 10
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A execPreviousAction() 0 19 4
A loadData() 0 12 3
A getPageData() 0 9 1
A addRestoreButton() 0 13 1
A createViews() 0 13 1
1
<?php
2
3
/**
4
 * Copyright (C) 2019 Joe Zegarra.
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 3 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA 02110-1301  USA
20
 */
21
22
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Controller;
23
24
use FacturaScripts\Core\Tools;
25
use FacturaScripts\Dinamic\Lib\AssetManager;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Lib\AssetManager 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\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...
27
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...
28
29
/**
30
 * Description of ListNCFTipoPago
31
 *
32
 * @author Joe Zegarra
33
 */
34
class ListNCFTipoPago extends ListController
35
{
36
    public function getPageData(): array
37
    {
38
        $pageData = parent::getPageData();
39
        $pageData['menu'] = 'accounting';
40
        $pageData['submenu'] = 'Republica Dominicana';
41
        $pageData['title'] = 'ncf-payment-types';
42
        $pageData['icon'] = 'fa-solid fa-list';
43
        
44
        return $pageData;
45
    }
46
    
47
    public function addRestoreButton($viewName)
48
    {
49
        $restoreButton = [
50
            'color' => 'danger',
51
            'icon' => 'fa-solid fa-undo',
52
            'label' => 'restore-original-data',
53
            'title' => 'restore-original-data',
54
            'type' => 'action',
55
            'action' => 'restore-data',
56
            'hint' => 'restore-original-data',
57
            'confirm' => true
58
        ];
59
        $this->addButton($viewName, $restoreButton);
60
    }
61
    
62
    protected function createViews()
63
    {
64
        $this->addView('ListNCFTipoPago-1', 'NCFTipoPago', 'sales', 'fa-solid fa-store');
65
        $this->addSearchFields('ListNCFTipoPago-1', ['tipopago','codigo','descripcion']);
66
        $this->addOrderBy('ListNCFTipoPago-1', ['codigo'], 'code');
67
        $this->addOrderBy('ListNCFTipoPago-1', ['descripcion'], 'description');
68
        $this->addRestoreButton('ListNCFTipoPago-1');
69
        
70
        $this->addView('ListNCFTipoPago-2', 'NCFTipoPago', 'purchases', 'fa-solid fa-credit-card');
71
        $this->addSearchFields('ListNCFTipoPago-2', ['tipopago','codigo','descripcion']);
72
        $this->addOrderBy('ListNCFTipoPago-2', ['codigo'], 'code');
73
        $this->addOrderBy('ListNCFTipoPago-2', ['descripcion'], 'description');
74
        $this->addRestoreButton('ListNCFTipoPago-2');
75
    }
76
    
77
    protected function execPreviousAction($action)
78
    {
79
        switch ($action) {
80
            case 'restore-data':
81
                $this->views['ListNCFTipoPago-1']->model->restoreData();
82
                Tools::log()->notice('restored-original-data');
83
                break;
84
            case 'busca_pago':
85
                $this->setTemplate(false);
86
                $where = [new DatabaseWhere('tipopago', $_REQUEST['tipopago'])];
87
                $pagos = $this->views['ListNCFTipoPago-1']->model->all($where);
88
                if ($pagos) {
89
                    echo json_encode(['pagos' => $pagos], JSON_THROW_ON_ERROR);
90
                } else {
91
                    echo '';
92
                }
93
                break;
94
            default:
95
                parent::execPreviousAction($action);
96
        }
97
    }
98
    
99
    protected function loadData($viewName, $view)
100
    {
101
        switch ($viewName) {
102
            case 'ListNCFTipoPago-1':
103
                $where = [new DataBaseWhere('tipopago', '01')];
104
                $view->loadData('', $where);
105
                break;
106
107
            case 'ListNCFTipoPago-2':
108
                $where = [new DataBaseWhere('tipopago', '02')];
109
                $view->loadData('', $where);
110
                break;
111
        }
112
    }
113
}
114