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
|
|
|
if ($action === 'export' and $option === 'dgii') { |
77
|
|
|
$actualTab = $this->request->get('activetab'); |
78
|
|
|
switch ($actualTab) { |
79
|
|
|
case "FiscalReport606": |
80
|
|
|
$this->setTemplate(false); |
81
|
|
|
$fileName = 'DGII_606_'.$this->empresa->cifnif.'_'.$year.'_'.$month.'.txt'; |
82
|
|
|
$whereReport = [ |
83
|
|
|
new DataBaseWhere('facturasprov.fecha', $startDate, '>='), |
84
|
|
|
new DataBaseWhere('facturasprov.fecha', $endDate, '<='), |
85
|
|
|
]; |
86
|
|
|
$commonFunctions->exportTXT('606', $fileName, $this->empresa->cifnif, $year, $month, $whereReport); |
87
|
|
|
$this->response->headers->set('Content-type', 'text/plain'); |
88
|
|
|
$this->response->headers->set('Content-Disposition', 'attachment;filename=' . $fileName); |
89
|
|
|
$this->response->setContent(file_get_contents(\FS_FOLDER . DIRECTORY_SEPARATOR . $fileName)); |
|
|
|
|
90
|
|
|
break; |
91
|
|
|
case "FiscalReport607": |
92
|
|
|
$this->setTemplate(false); |
93
|
|
|
$whereReport = [ |
94
|
|
|
new DataBaseWhere('facturascli.fecha', $startDate, '>='), |
95
|
|
|
new DataBaseWhere('facturascli.fecha', $endDate, '<='), |
96
|
|
|
]; |
97
|
|
|
$fileName = 'DGII_607_'.$this->empresa->cifnif.'_'.$year.'_'.$month.'.txt'; |
98
|
|
|
$commonFunctions->exportTXT('607', $fileName, $this->empresa->cifnif, $year, $month, $whereReport); |
99
|
|
|
$this->response->headers->set('Content-type', 'text/plain'); |
100
|
|
|
$this->response->headers->set('Content-Disposition', 'attachment;filename=' . $fileName); |
101
|
|
|
$this->response->setContent(file_get_contents(\FS_FOLDER . DIRECTORY_SEPARATOR . $fileName)); |
102
|
|
|
break; |
103
|
|
|
case "FiscalReport608": |
104
|
|
|
$this->setTemplate(false); |
105
|
|
|
$whereReport = [ |
106
|
|
|
new DataBaseWhere('facturasprov.fecha', $startDate, '>='), |
107
|
|
|
new DataBaseWhere('facturasprov.fecha', $endDate, '<='), |
108
|
|
|
]; |
109
|
|
|
$fileName = 'DGII_608_'.$this->empresa->cifnif.'_'.$year.'_'.$month.'.txt'; |
110
|
|
|
$commonFunctions->exportTXT('608', $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
|
|
|
break; |
115
|
|
|
default: |
116
|
|
|
break; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param string $viewName |
123
|
|
|
*/ |
124
|
|
|
protected function createViewsFiscalReportsConsolidated(string $viewName = 'FiscalReports-consolidated') |
125
|
|
|
{ |
126
|
|
|
$this->addView( |
127
|
|
|
$viewName, |
128
|
|
|
'Join\FiscalReports', |
129
|
|
|
'rd-fiscal-reports-consolidated', |
130
|
|
|
'fas fa-shipping-fast' |
131
|
|
|
); |
132
|
|
|
$this->addOrderBy($viewName, ['ncf'], 'ncf'); |
133
|
|
|
$this->addFilterPeriod($viewName, 'fecha', 'date', 'facturascli.fecha'); |
134
|
|
|
$this->addCommonSearchFields($viewName); |
135
|
|
|
$this->disableButtons($viewName); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param string $viewName |
140
|
|
|
*/ |
141
|
|
|
protected function createViewsFiscalReports608(string $viewName = 'FiscalReport608') |
142
|
|
|
{ |
143
|
|
|
$this->addView($viewName, |
144
|
|
|
'Join\FiscalReport608', |
145
|
|
|
'rd-fiscal-reports-608', |
146
|
|
|
'fas fa-shopping-cart'); |
147
|
|
|
$this->addFilterPeriod($viewName, 'fecha', 'date', 'facturascli.fecha'); |
148
|
|
|
$this->addCommonSearchFields($viewName); |
149
|
|
|
$this->disableButtons($viewName); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param string $viewName |
154
|
|
|
*/ |
155
|
|
|
protected function createViewsFiscalReports607(string $viewName = 'FiscalReport607') |
156
|
|
|
{ |
157
|
|
|
$this->addView($viewName, 'Join\FiscalReport607', 'rd-fiscal-reports-607', 'fas fa-copy'); |
158
|
|
|
$this->addFilterPeriod($viewName, 'fecha', 'date', 'facturascli.fecha'); |
159
|
|
|
$this->addCommonSearchFields($viewName); |
160
|
|
|
$this->disableButtons($viewName); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param string $viewName |
165
|
|
|
*/ |
166
|
|
|
protected function createViewsFiscalReports606(string $viewName = 'FiscalReport606') |
167
|
|
|
{ |
168
|
|
|
$this->addView($viewName, 'Join\FiscalReport606', 'rd-fiscal-reports-606', 'fas fa-copy'); |
169
|
|
|
$this->addFilterPeriod($viewName, 'fecha', 'date', 'facturasprov.fecha'); |
170
|
|
|
$this->addSearchFields($viewName, ['numero2', 'cifnif', 'fecha', 'estado'], 'fecha'); |
171
|
|
|
$this->addOrderBy($viewName, ['facturasprov.fecha'], 'fecha'); |
172
|
|
|
$this->addOrderBy($viewName, ['facturasprov.numproveedor'], 'ncf'); |
173
|
|
|
$this->addOrderBy($viewName, ['cifnif'], 'cifnif'); |
174
|
|
|
$this->disableButtons($viewName); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param string $viewName |
179
|
|
|
*/ |
180
|
|
|
private function addCommonSearchFields(string $viewName) |
181
|
|
|
{ |
182
|
|
|
$this->addSearchFields($viewName, ['numero2', 'cifnif', 'fecha', 'estado'], 'fecha'); |
183
|
|
|
$this->addOrderBy($viewName, ['facturascli.fecha'], 'fecha'); |
184
|
|
|
$this->addOrderBy($viewName, ['facturascli.numero2'], 'ncf'); |
185
|
|
|
$this->addOrderBy($viewName, ['cifnif'], 'cifnif'); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param string $viewName |
190
|
|
|
*/ |
191
|
|
|
private function disableButtons(string $viewName) |
192
|
|
|
{ |
193
|
|
|
$this->setSettings($viewName, 'btnDelete', false); |
194
|
|
|
$this->setSettings($viewName, 'btnNew', false); |
195
|
|
|
$this->setSettings($viewName, 'checkBoxes', false); |
196
|
|
|
$this->setSettings($viewName, 'clickable', false); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* |
201
|
|
|
* @param string $viewName |
202
|
|
|
* @param BaseView $view |
203
|
|
|
*/ |
204
|
|
|
protected function loadData($viewName, $view) |
205
|
|
|
{ |
206
|
|
|
$periodStartDate = \date('Y-m-01'); |
207
|
|
|
$periodEndDate = \date('Y-m-d'); |
208
|
|
|
PeriodTools::applyPeriod('last-month', $periodStartDate, $periodEndDate); |
209
|
|
|
switch ($viewName) { |
210
|
|
|
case 'FiscalReport606': |
211
|
|
|
$where = [ |
212
|
|
|
new DataBaseWhere('facturasprov.fecha', $periodStartDate, '>='), |
213
|
|
|
new DataBaseWhere('facturasprov.fecha', $periodEndDate, '<='), |
214
|
|
|
]; |
215
|
|
|
$view->loadData('', $where); |
216
|
|
|
break; |
217
|
|
|
case 'FiscalReport607': |
218
|
|
|
case 'FiscalReport608': |
219
|
|
|
case 'FiscalReports-consolidated': |
220
|
|
|
$where = [ |
221
|
|
|
new DataBaseWhere('facturascli.fecha', $periodStartDate, '>='), |
222
|
|
|
new DataBaseWhere('facturascli.fecha', $periodEndDate, '<='), |
223
|
|
|
]; |
224
|
|
|
$view->loadData('', $where); |
225
|
|
|
break; |
226
|
|
|
default: |
227
|
|
|
parent::loadData($viewName, $view); |
228
|
|
|
break; |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|
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