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(string $report, string $fileName, string $rncCompany, string $yearReport, |
130
|
|
|
string $monthReport, array $whereReport) |
131
|
|
|
{ |
132
|
|
|
if (file_exists($fileName)) { |
133
|
|
|
unlink($fileName); |
134
|
|
|
} |
135
|
|
|
$dataCounter = 0; |
|
|
|
|
136
|
|
|
$fp = fopen($fileName, "w"); |
137
|
|
|
switch ($report) { |
138
|
|
|
case "607": |
139
|
|
|
default: |
140
|
|
|
$this->exportTXT607( |
141
|
|
|
$fp, |
142
|
|
|
$rncCompany, |
143
|
|
|
$yearReport, |
144
|
|
|
$monthReport, |
145
|
|
|
$whereReport |
146
|
|
|
); |
147
|
|
|
break; |
148
|
|
|
case "608": |
149
|
|
|
$this->exportTXT608( |
150
|
|
|
$fp, |
151
|
|
|
$rncCompany, |
152
|
|
|
$yearReport, |
153
|
|
|
$monthReport, |
154
|
|
|
$whereReport |
155
|
|
|
); |
156
|
|
|
break; |
157
|
|
|
} |
158
|
|
|
fclose($fp); |
159
|
|
|
return true; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param mixed $fp |
164
|
|
|
* @param string $rncCompany |
165
|
|
|
* @param string $yearReport |
166
|
|
|
* @param string $monthReport |
167
|
|
|
* @param array $whereReport |
168
|
|
|
* @return void |
169
|
|
|
*/ |
170
|
|
|
protected function exportTXT607( |
171
|
|
|
&$fp, |
172
|
|
|
string $rncCompany, |
173
|
|
|
string $yearReport, |
174
|
|
|
string $monthReport, |
175
|
|
|
array $whereReport |
176
|
|
|
): void |
177
|
|
|
{ |
178
|
|
|
$reportData = new FiscalReport607(); |
179
|
|
|
$data = $reportData->all($whereReport); |
180
|
|
|
$dataCounter = count($data); |
181
|
|
|
fwrite( |
182
|
|
|
$fp, |
183
|
|
|
sprintf( |
184
|
|
|
"%s|%s|%4s%2s|%s\r\n", |
185
|
|
|
'607', |
186
|
|
|
$rncCompany, |
187
|
|
|
$yearReport, |
188
|
|
|
$monthReport, |
189
|
|
|
$dataCounter |
190
|
|
|
) |
191
|
|
|
); |
192
|
|
|
foreach ($data as $line) { |
193
|
|
|
fwrite( |
194
|
|
|
$fp, |
195
|
|
|
sprintf( |
196
|
|
|
"%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", |
197
|
|
|
$line->cifnif, |
198
|
|
|
$line->tipoid, |
199
|
|
|
substr($line->ncf, -11, 11), |
200
|
|
|
substr($line->ncfmodifica, -11, 11), |
201
|
|
|
1, |
202
|
|
|
$line->fecha, |
203
|
|
|
"", |
204
|
|
|
number_format($line->base, 2, ".", ""), |
205
|
|
|
number_format($line->itbis, 2, ".", ""), |
206
|
|
|
"", "", "", "", "", "", "", |
207
|
|
|
number_format($line->totalefectivo, 2, ".", ""), |
208
|
|
|
number_format($line->totalcheque, 2, ".", ""), |
209
|
|
|
number_format($line->totaltarjeta, 2, ".", ""), |
210
|
|
|
number_format($line->totalcredito, 2, ".", ""), |
211
|
|
|
number_format($line->totalbonos, 2, ".", ""), |
212
|
|
|
number_format($line->totalpermuta, 2, ".", ""), |
213
|
|
|
number_format($line->totalotrasformas, 2, ".", "") |
214
|
|
|
)); |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @param mixed $fp |
220
|
|
|
* @param string $rncCompany |
221
|
|
|
* @param string $yearReport |
222
|
|
|
* @param string $monthReport |
223
|
|
|
* @param array $whereReport |
224
|
|
|
* @return void |
225
|
|
|
*/ |
226
|
|
|
protected function exportTXT608( |
227
|
|
|
&$fp, |
228
|
|
|
string $rncCompany, |
229
|
|
|
string $yearReport, |
230
|
|
|
string $monthReport, |
231
|
|
|
array $whereReport |
232
|
|
|
): void |
233
|
|
|
{ |
234
|
|
|
$reportData = new FiscalReport608(); |
235
|
|
|
$data = $reportData->all($whereReport); |
236
|
|
|
$dataCounter = count($data); |
237
|
|
|
fwrite( |
238
|
|
|
$fp, |
239
|
|
|
sprintf( |
240
|
|
|
"%s|%s|%4s%2s|%s\r\n", |
241
|
|
|
'608', |
242
|
|
|
$rncCompany, |
243
|
|
|
$yearReport, |
244
|
|
|
$monthReport, |
245
|
|
|
$dataCounter |
246
|
|
|
) |
247
|
|
|
); |
248
|
|
|
foreach ($data as $line) { |
249
|
|
|
fwrite( |
250
|
|
|
$fp, |
251
|
|
|
sprintf( |
252
|
|
|
"%s|%s|%s\r\n", |
253
|
|
|
substr($line->ncf, -11, 11), |
254
|
|
|
$line->fecha, |
255
|
|
|
$line->tipoanulacion |
256
|
|
|
) |
257
|
|
|
); |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
} |
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