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