Issues (232)

Controller/FiscalReports.php (8 issues)

Labels
Severity
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
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\Base\MyFilesToken;
0 ignored issues
show
The type FacturaScripts\Core\Base\MyFilesToken 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\Core\DataSrc\Almacenes;
0 ignored issues
show
The type FacturaScripts\Core\DataSrc\Almacenes 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\Lib\ExtendedController\BaseView;
0 ignored issues
show
The type FacturaScripts\Core\Lib\...ndedController\BaseView 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
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
use FacturaScripts\Core\Lib\ListFilter\PeriodTools;
0 ignored issues
show
The type FacturaScripts\Core\Lib\ListFilter\PeriodTools 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...
29
use FacturaScripts\Dinamic\Model\LineaFacturaCliente;
0 ignored issues
show
The type FacturaScripts\Dinamic\Model\LineaFacturaCliente 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...
30
use FacturaScripts\Plugins\fsRepublicaDominicana\Lib\CommonFunctionsDominicanRepublic;
31
32
/**
33
 * Description of FiscalReports
34
 *
35
 * @author joenilson
36
 */
37
class FiscalReports extends ListController
38
{
39
    /**
40
     * @return array
41
     */
42
    public function getPageData(): array
43
    {
44
        $data = parent::getPageData();
45
        $data['menu'] = 'reports';
46
        $data['submenu'] = 'dominican-republic';
47
        $data['icon'] = 'fas fa-hand-holding-usd';
48
        $data['title'] = 'rd-fiscal-reports';
49
        return $data;
50
    }
51
52
    protected function createViews(): void
53
    {
54
        // needed dependencies
55
        new LineaFacturaCliente();
56
        $this->createViewsFiscalReportsConsolidated();
57
        $this->createViewsFiscalReports606();
58
        $this->createViewsFiscalReports607();
59
        $this->createViewsFiscalReports608();
60
        $this->exportManager::addOption('dgii', 'txt-export', 'fas fa-file-alt');
61
    }
62
63
    public function execAfterAction($action)
64
    {
65
        parent::execAfterAction($action);
66
        $periodStartDate = \date('Y-m-01');
67
        $periodEndDate = \date('Y-m-d');
68
        if ($this->request->request->get('filterfecha') !== null) {
69
            PeriodTools::applyPeriod($this->request->request->get('filterfecha'), $periodStartDate, $periodEndDate);
70
        }
71
        $startDate = (($this->request->request->get('filterstartfecha') !== null) === true)
72
            ? $this->request->request->get('filterstartfecha')
73
            : $periodStartDate;
74
        $endDate = (($this->request->request->get('filterstartfecha') !== null) === true)
75
            ? $this->request->request->get('filterendfecha')
76
            : $periodEndDate;
77
78
        $commonFunctions = new CommonFunctionsDominicanRepublic();
79
80
        [$year, $month] = $commonFunctions->checkDateFormat($startDate);
81
82
        $option = $this->request->get('option');
83
        $actualTab = $this->request->get('activetab');
84
        switch ($actualTab) {
85
            case "FiscalReport606":
86
                $whereReport = [
87
                    new DataBaseWhere('facturasprov.fecha', $startDate, '>='),
88
                    new DataBaseWhere('facturasprov.fecha', $endDate, '<='),
89
                ];
90
                $reportCode = 606;
91
                break;
92
            case "FiscalReport607":
93
                $whereReport = [
94
                    new DataBaseWhere('facturascli.fecha', $startDate, '>='),
95
                    new DataBaseWhere('facturascli.fecha', $endDate, '<='),
96
                ];
97
                $reportCode = 607;
98
                break;
99
            case "FiscalReport608":
100
                $whereReport = [
101
                    new DataBaseWhere('facturascli.fecha', $startDate, '>='),
102
                    new DataBaseWhere('facturascli.fecha', $endDate, '<='),
103
                ];
104
                $reportCode = 608;
105
                break;
106
            default:
107
                $whereReport = [
108
                    new DataBaseWhere('facturascli.fecha', $startDate, '>='),
109
                    new DataBaseWhere('facturascli.fecha', $endDate, '<='),
110
                ];
111
                $reportCode = '';
112
                break;
113
        }
114
        if ($action === 'export' && $option === 'dgii' && $reportCode !== '') {
115
            $this->setTemplate(false);
116
            $fileName = 'MyFiles/DGII_F_'.$reportCode.'_'.$this->empresa->cifnif.'_'.$year.'_'.$month.'.TXT';
117
            $commonFunctions->exportTXT($reportCode, $fileName, $this->empresa->cifnif, $year, $month, $whereReport);
118
            $this->response->headers->set('Content-type', 'text/plain');
119
            $this->response->headers->set('Content-Disposition', 'attachment;filename=' . $fileName);
120
            $this->response->setContent(
121
                file_get_contents(
122
                \FS_FOLDER
0 ignored issues
show
The constant FS_FOLDER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
123
                    . DIRECTORY_SEPARATOR
124
                    . $fileName
125
//                    . '?myft='
126
//                    . MyFilesToken::get(
127
//                        $fileName,
128
//                        false,
129
//                        \date('Y-m-d', strtotime('+1 days'))
130
//                    )
131
                )
132
            );
133
        }
134
    }
135
136
    /**
137
     * @param string $viewName
138
     */
139
    protected function createViewsFiscalReportsConsolidated(string $viewName = 'FiscalReports-consolidated')
140
    {
141
        $this->addView(
142
            $viewName,
143
            'Join\FiscalReports',
144
            'rd-fiscal-reports-consolidated',
145
            'fas fa-shipping-fast'
146
        );
147
        $this->addOrderBy($viewName, ['ncf'], 'ncf');
148
        $this->addFilterPeriod($viewName, 'fecha', 'date', 'facturascli.fecha');
149
        $this->addCommonSearchFields($viewName);
150
        $this->disableButtons($viewName);
151
    }
152
153
    /**
154
     * @param string $viewName
155
     */
156
    protected function createViewsFiscalReports608(string $viewName = 'FiscalReport608')
157
    {
158
        $this->addView(
159
            $viewName,
160
            'Join\FiscalReport608',
161
            'rd-fiscal-reports-608',
162
            'fas fa-shopping-cart'
163
        );
164
        $this->addFilterPeriod($viewName, 'fecha', 'date', 'facturascli.fecha');
165
        $this->addCommonSearchFields($viewName);
166
        $this->disableButtons($viewName);
167
    }
168
169
    /**
170
     * @param string $viewName
171
     */
172
    protected function createViewsFiscalReports607(string $viewName = 'FiscalReport607')
173
    {
174
        $this->addView($viewName, 'Join\FiscalReport607', 'rd-fiscal-reports-607', 'fas fa-copy');
175
        $this->addFilterPeriod($viewName, 'fecha', 'date', 'facturascli.fecha');
176
        $this->addCommonSearchFields($viewName);
177
        $this->disableButtons($viewName);
178
    }
179
180
    /**
181
     * @param string $viewName
182
     */
183
    protected function createViewsFiscalReports606(string $viewName = 'FiscalReport606')
184
    {
185
        $this->addView($viewName, 'Join\FiscalReport606', 'rd-fiscal-reports-606', 'fas fa-copy');
186
        $this->addFilterPeriod($viewName, 'fecha', 'date', 'facturasprov.fecha');
187
        $this->addSearchFields($viewName, ['numero2', 'cifnif', 'fecha', 'estado'], 'fecha');
188
        $this->addOrderBy($viewName, ['facturasprov.fecha'], 'fecha');
189
        $this->addOrderBy($viewName, ['facturasprov.numproveedor'], 'ncf');
190
        $this->addOrderBy($viewName, ['cifnif'], 'cifnif');
191
        $this->disableButtons($viewName);
192
    }
193
194
    /**
195
     * @param string $viewName
196
     */
197
    private function addCommonSearchFields(string $viewName)
198
    {
199
        $this->addSearchFields($viewName, ['numero2', 'cifnif', 'fecha', 'estado'], 'fecha');
200
        $this->addOrderBy($viewName, ['facturascli.fecha'], 'fecha');
201
        $this->addOrderBy($viewName, ['facturascli.numero2'], 'ncf');
202
        $this->addOrderBy($viewName, ['cifnif'], 'cifnif');
203
    }
204
205
    /**
206
     * @param string $viewName
207
     */
208
    private function disableButtons(string $viewName)
209
    {
210
        $this->setSettings($viewName, 'btnDelete', false);
211
        $this->setSettings($viewName, 'btnNew', false);
212
        $this->setSettings($viewName, 'checkBoxes', false);
213
        $this->setSettings($viewName, 'clickable', false);
214
    }
215
216
    /**
217
     *
218
     * @param string   $viewName
219
     * @param BaseView $view
220
     */
221
    protected function loadData($viewName, $view)
222
    {
223
        $periodStartDate = \date('Y-m-01');
224
        $periodEndDate = \date('Y-m-d');
225
        PeriodTools::applyPeriod('last-month', $periodStartDate, $periodEndDate);
226
        if (in_array($this->request->request->get('filterfecha'), ['',null], true) === false) {
227
            PeriodTools::applyPeriod($this->request->request->get('filterfecha'), $periodStartDate, $periodEndDate);
228
        } else {
229
            $periodStartDate = $this->request->request->get('filterstartfecha') ?? $periodStartDate;
230
            $periodEndDate = $this->request->request->get('filterendfecha') ?? $periodEndDate;
231
        }
232
        switch ($viewName) {
233
            case 'FiscalReport606':
234
                $where = [
235
                    new DataBaseWhere('facturasprov.fecha', $periodStartDate, '>='),
236
                    new DataBaseWhere('facturasprov.fecha', $periodEndDate, '<='),
237
                ];
238
                $view->loadData('', $where);
239
                break;
240
            case 'FiscalReport607':
241
            case 'FiscalReport608':
242
            case 'FiscalReports-consolidated':
243
                $where = [
244
                    new DataBaseWhere('facturascli.fecha', $periodStartDate, '>='),
245
                    new DataBaseWhere('facturascli.fecha', $periodEndDate, '<='),
246
                ];
247
                $view->loadData('', $where);
248
                break;
249
            default:
250
                parent::loadData($viewName, $view);
251
                break;
252
        }
253
    }
254
}
255