|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (C) 2022 Joe Nilson <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU Lesser General Public License as |
|
7
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
8
|
|
|
* License, or (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* This program 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 |
|
13
|
|
|
* GNU Lesser General Public License for more details. |
|
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
15
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Lib; |
|
19
|
|
|
|
|
20
|
|
|
use FacturaScripts\Dinamic\Model\NCFTipo; |
|
|
|
|
|
|
21
|
|
|
use FacturaScripts\Dinamic\Model\Join\FiscalReport606; |
|
|
|
|
|
|
22
|
|
|
use FacturaScripts\Dinamic\Model\Join\FiscalReport607; |
|
|
|
|
|
|
23
|
|
|
use FacturaScripts\Dinamic\Model\Join\FiscalReport608; |
|
|
|
|
|
|
24
|
|
|
use FacturaScripts\Plugins\fsRepublicaDominicana\Interfaces\CommonFunctionsInterface; |
|
25
|
|
|
use FacturaScripts\Core\Base\DataBase\DataBaseWhere; |
|
|
|
|
|
|
26
|
|
|
use FacturaScripts\Dinamic\Model\NCFRango; |
|
|
|
|
|
|
27
|
|
|
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipoAnulacion; |
|
28
|
|
|
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFTipoMovimiento; |
|
29
|
|
|
|
|
30
|
|
|
class CommonFunctionsDominicanRepublic implements CommonFunctionsInterface |
|
31
|
|
|
{ |
|
32
|
|
|
public static function ncfRango() |
|
33
|
|
|
{ |
|
34
|
|
|
// TODO: Implement ncfRango() method. |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public static function ncfCorrelativo($tipoComprobante, $idempresa) |
|
38
|
|
|
{ |
|
39
|
|
|
$tipocomprobante = new NCFRango(); |
|
40
|
|
|
$where = [ |
|
41
|
|
|
new DatabaseWhere('tipocomprobante', $tipoComprobante), |
|
42
|
|
|
new DatabaseWhere('idempresa', $idempresa), |
|
43
|
|
|
new DatabaseWhere('estado', 1) |
|
44
|
|
|
]; |
|
45
|
|
|
$comprobante = $tipocomprobante->all($where); |
|
46
|
|
|
if ($comprobante) { |
|
47
|
|
|
echo json_encode(['existe' => $comprobante], JSON_THROW_ON_ERROR); |
|
48
|
|
|
} else { |
|
49
|
|
|
echo json_encode(['existe' => false], JSON_THROW_ON_ERROR); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @throws \JsonException |
|
55
|
|
|
*/ |
|
56
|
|
|
public static function ncfTipoPago(string $tipoPago) |
|
57
|
|
|
{ |
|
58
|
|
|
$where = [new DatabaseWhere('tipopago', $tipoPago)]; |
|
59
|
|
|
$tipoPagos = new NCFTipoPago(); |
|
|
|
|
|
|
60
|
|
|
$pagos = $tipoPagos->all($where); |
|
61
|
|
|
if ($pagos) { |
|
62
|
|
|
echo \json_encode(['pagos' => $pagos], JSON_THROW_ON_ERROR); |
|
63
|
|
|
} else { |
|
64
|
|
|
echo ''; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @throws \JsonException |
|
70
|
|
|
*/ |
|
71
|
|
|
public static function ncfTipoMovimiento(string $tipoMovimiento) |
|
72
|
|
|
{ |
|
73
|
|
|
$tipomovimiento = new NCFTipoMovimiento(); |
|
74
|
|
|
$where = [new DatabaseWhere('tipomovimiento', $tipoMovimiento)]; |
|
75
|
|
|
$movimientos = $tipomovimiento->all($where); |
|
76
|
|
|
if ($movimientos) { |
|
77
|
|
|
echo json_encode(['movimientos' => $movimientos], JSON_THROW_ON_ERROR); |
|
78
|
|
|
} else { |
|
79
|
|
|
echo ''; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public static function ncfTipoAnulacion(string $tipoAnulacion) |
|
84
|
|
|
{ |
|
85
|
|
|
$where = [new DatabaseWhere('codigo', $tipoAnulacion)]; |
|
86
|
|
|
$tipoAnulaciones = new NCFTipoAnulacion(); |
|
87
|
|
|
$anulaciones = $tipoAnulaciones->all($where); |
|
88
|
|
|
if ($anulaciones) { |
|
89
|
|
|
echo \json_encode(['anulaciones' => $anulaciones], JSON_THROW_ON_ERROR); |
|
90
|
|
|
} else { |
|
91
|
|
|
echo ''; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @throws \JsonException |
|
97
|
|
|
*/ |
|
98
|
|
|
public static function ncfTipoComprobante($tipoComprobante) |
|
99
|
|
|
{ |
|
100
|
|
|
$where = [new DatabaseWhere($tipoComprobante, 'Y')]; |
|
101
|
|
|
$tipoComprobantes = new NCFTipo(); |
|
102
|
|
|
$lista = $tipoComprobantes->all($where); |
|
103
|
|
|
if ($lista) { |
|
104
|
|
|
echo json_encode(['tipocomprobantes' => $lista], JSON_THROW_ON_ERROR); |
|
105
|
|
|
} else { |
|
106
|
|
|
echo ''; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public static function ncfFechaVencimiento() |
|
111
|
|
|
{ |
|
112
|
|
|
// TODO: Implement ncfFechaVencimiento() method. |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @throws \JsonException |
|
117
|
|
|
*/ |
|
118
|
|
|
public static function ncfTipoCliente(string $cliente) |
|
119
|
|
|
{ |
|
120
|
|
|
$NCFTipo = new NCFTipo(); |
|
121
|
|
|
$tipoCliente = $NCFTipo->tipoCliente($cliente); |
|
122
|
|
|
if ($tipoCliente) { |
|
123
|
|
|
echo json_encode(['infocliente' => $tipoCliente], JSON_THROW_ON_ERROR); |
|
124
|
|
|
} else { |
|
125
|
|
|
echo ''; |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function exportTXT( |
|
130
|
|
|
string $report, |
|
131
|
|
|
string $fileName, |
|
132
|
|
|
string $rncCompany, |
|
133
|
|
|
string $yearReport, |
|
134
|
|
|
string $monthReport, |
|
135
|
|
|
array $whereReport |
|
136
|
|
|
) { |
|
137
|
|
|
if (file_exists($fileName)) { |
|
138
|
|
|
unlink($fileName); |
|
139
|
|
|
} |
|
140
|
|
|
$dataCounter = 0; |
|
|
|
|
|
|
141
|
|
|
$fp = fopen($fileName, "w"); |
|
142
|
|
|
switch ($report) { |
|
143
|
|
|
case "607": |
|
144
|
|
|
default: |
|
145
|
|
|
$this->exportTXT607( |
|
146
|
|
|
$fp, |
|
147
|
|
|
$rncCompany, |
|
148
|
|
|
$yearReport, |
|
149
|
|
|
$monthReport, |
|
150
|
|
|
$whereReport |
|
151
|
|
|
); |
|
152
|
|
|
break; |
|
153
|
|
|
case "608": |
|
154
|
|
|
$this->exportTXT608( |
|
155
|
|
|
$fp, |
|
156
|
|
|
$rncCompany, |
|
157
|
|
|
$yearReport, |
|
158
|
|
|
$monthReport, |
|
159
|
|
|
$whereReport |
|
160
|
|
|
); |
|
161
|
|
|
break; |
|
162
|
|
|
} |
|
163
|
|
|
fclose($fp); |
|
164
|
|
|
return true; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @param mixed $fp |
|
169
|
|
|
* @param string $rncCompany |
|
170
|
|
|
* @param string $yearReport |
|
171
|
|
|
* @param string $monthReport |
|
172
|
|
|
* @param array $whereReport |
|
173
|
|
|
* @return void |
|
174
|
|
|
*/ |
|
175
|
|
|
protected function exportTXT607( |
|
176
|
|
|
&$fp, |
|
177
|
|
|
string $rncCompany, |
|
178
|
|
|
string $yearReport, |
|
179
|
|
|
string $monthReport, |
|
180
|
|
|
array $whereReport |
|
181
|
|
|
): void |
|
182
|
|
|
{ |
|
183
|
|
|
$reportData = new FiscalReport607(); |
|
184
|
|
|
$data = $reportData->all($whereReport); |
|
185
|
|
|
$dataCounter = count($data); |
|
186
|
|
|
fwrite( |
|
187
|
|
|
$fp, |
|
188
|
|
|
sprintf( |
|
189
|
|
|
"%s|%s|%4s%2s|%s\r\n", |
|
190
|
|
|
'607', |
|
191
|
|
|
$rncCompany, |
|
192
|
|
|
$yearReport, |
|
193
|
|
|
$monthReport, |
|
194
|
|
|
$dataCounter |
|
195
|
|
|
) |
|
196
|
|
|
); |
|
197
|
|
|
foreach ($data as $line) { |
|
198
|
|
|
fwrite( |
|
199
|
|
|
$fp, |
|
200
|
|
|
sprintf( |
|
201
|
|
|
"%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s\r\n", |
|
202
|
|
|
$line->cifnif, |
|
203
|
|
|
$line->tipoid, |
|
204
|
|
|
substr($line->ncf, -11, 11), |
|
205
|
|
|
substr($line->ncfmodifica, -11, 11), |
|
206
|
|
|
1, |
|
207
|
|
|
$line->fecha, |
|
208
|
|
|
"", |
|
209
|
|
|
number_format($line->base, 2, ".", ""), |
|
210
|
|
|
number_format($line->itbis, 2, ".", ""), |
|
211
|
|
|
"", "", "", "", "", "", "", |
|
212
|
|
|
number_format($line->totalefectivo, 2, ".", ""), |
|
213
|
|
|
number_format($line->totalcheque, 2, ".", ""), |
|
214
|
|
|
number_format($line->totaltarjeta, 2, ".", ""), |
|
215
|
|
|
number_format($line->totalcredito, 2, ".", ""), |
|
216
|
|
|
number_format($line->totalbonos, 2, ".", ""), |
|
217
|
|
|
number_format($line->totalpermuta, 2, ".", ""), |
|
218
|
|
|
number_format($line->totalotrasformas, 2, ".", "") |
|
219
|
|
|
)); |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* @param mixed $fp |
|
225
|
|
|
* @param string $rncCompany |
|
226
|
|
|
* @param string $yearReport |
|
227
|
|
|
* @param string $monthReport |
|
228
|
|
|
* @param array $whereReport |
|
229
|
|
|
* @return void |
|
230
|
|
|
*/ |
|
231
|
|
|
protected function exportTXT608( |
|
232
|
|
|
&$fp, |
|
233
|
|
|
string $rncCompany, |
|
234
|
|
|
string $yearReport, |
|
235
|
|
|
string $monthReport, |
|
236
|
|
|
array $whereReport |
|
237
|
|
|
): void { |
|
238
|
|
|
$reportData = new FiscalReport608(); |
|
239
|
|
|
$data = $reportData->all($whereReport); |
|
240
|
|
|
$dataCounter = count($data); |
|
241
|
|
|
fwrite( |
|
242
|
|
|
$fp, |
|
243
|
|
|
sprintf( |
|
244
|
|
|
"%s|%s|%4s%2s|%s\r\n", |
|
245
|
|
|
'608', |
|
246
|
|
|
$rncCompany, |
|
247
|
|
|
$yearReport, |
|
248
|
|
|
$monthReport, |
|
249
|
|
|
$dataCounter |
|
250
|
|
|
) |
|
251
|
|
|
); |
|
252
|
|
|
foreach ($data as $line) { |
|
253
|
|
|
fwrite( |
|
254
|
|
|
$fp, |
|
255
|
|
|
sprintf( |
|
256
|
|
|
"%s|%s|%s\r\n", |
|
257
|
|
|
substr($line->ncf, -11, 11), |
|
258
|
|
|
$line->fecha, |
|
259
|
|
|
$line->tipoanulacion |
|
260
|
|
|
) |
|
261
|
|
|
); |
|
262
|
|
|
} |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
public function checkDateFormat($dateValue) |
|
266
|
|
|
{ |
|
267
|
|
|
$year = (substr($dateValue, 4, 1) === '-') |
|
268
|
|
|
? substr($dateValue, 0, 4) |
|
269
|
|
|
: substr($dateValue, 6, 4); |
|
270
|
|
|
$month = (substr($dateValue, 4, 1) === '-') |
|
271
|
|
|
? substr($dateValue, 5, 2) |
|
272
|
|
|
: substr($dateValue, 3, 2); |
|
273
|
|
|
|
|
274
|
|
|
return [$year, $month]; |
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
|
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