@@ -58,7 +58,7 @@ |
||
58 | 58 | return false; |
59 | 59 | } |
60 | 60 | // si no se debe enviar no continuar |
61 | - if ($retry === 0) { |
|
61 | + if ($retry===0) { |
|
62 | 62 | return false; |
63 | 63 | } |
64 | 64 | // solicitar token |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | ] |
140 | 140 | ]); |
141 | 141 | $parent = $this->xml->getElementsByTagName($this->tipo_general)->item(0); |
142 | - $this->xml->generate($datos + ['TED' => null], null, $parent); |
|
142 | + $this->xml->generate($datos+['TED' => null], null, $parent); |
|
143 | 143 | $this->datos = $datos; |
144 | 144 | if ($normalizar and !$this->verificarDatos()) { |
145 | 145 | return false; |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); |
383 | 383 | $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', ''); |
384 | 384 | $TED = $xml->getFlattened('/'); |
385 | - return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1']) != 'ISO-8859-1' ? utf8_decode($TED) : $TED; |
|
385 | + return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1'])!='ISO-8859-1' ? utf8_decode($TED) : $TED; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | { |
396 | 396 | $datos = $this->getDatos(); |
397 | 397 | $idk = !empty($datos['TED']['DD']['CAF']['DA']['IDK']) ? (int)$datos['TED']['DD']['CAF']['DA']['IDK'] : null; |
398 | - return $idk ? $idk === 100 : null; |
|
398 | + return $idk ? $idk===100 : null; |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | /** |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | { |
533 | 533 | $this->getDatos(); |
534 | 534 | // generar resumen |
535 | - $resumen = [ |
|
535 | + $resumen = [ |
|
536 | 536 | 'TpoDoc' => (int)$this->datos['Encabezado']['IdDoc']['TipoDTE'], |
537 | 537 | 'NroDoc' => (int)$this->datos['Encabezado']['IdDoc']['Folio'], |
538 | 538 | 'TasaImp' => 0, |
@@ -577,10 +577,10 @@ discard block |
||
577 | 577 | */ |
578 | 578 | private function calcularNetoIVA($total, $tasa = null) |
579 | 579 | { |
580 | - if ($tasa === 0 or $tasa === false) { |
|
580 | + if ($tasa===0 or $tasa===false) { |
|
581 | 581 | return [0, 0]; |
582 | 582 | } |
583 | - if ($tasa === null) { |
|
583 | + if ($tasa===null) { |
|
584 | 584 | $tasa = \sasco\LibreDTE\Sii::getIVA(); |
585 | 585 | } |
586 | 586 | // WARNING: el IVA obtenido puede no ser el NETO*(TASA/100) |
@@ -588,8 +588,8 @@ discard block |
||
588 | 588 | // entre el total y el neto, ya que hay casos de borde como: |
589 | 589 | // - BRUTO: 680 => NETO: 571 e IVA: 108 => TOTAL: 679 |
590 | 590 | // - BRUTO: 86710 => NETO: 72866 e IVA: 13845 => TOTAL: 86711 |
591 | - $neto = round($total / (1+($tasa/100))); |
|
592 | - $iva = $total - $neto; |
|
591 | + $neto = round($total / (1+($tasa / 100))); |
|
592 | + $iva = $total-$neto; |
|
593 | 593 | return [$neto, $iva]; |
594 | 594 | } |
595 | 595 | |
@@ -1436,12 +1436,12 @@ discard block |
||
1436 | 1436 | ); |
1437 | 1437 | // aplicar descuento |
1438 | 1438 | if ($d['DescuentoPct']) { |
1439 | - $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct']/100); |
|
1439 | + $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct'] / 100); |
|
1440 | 1440 | } |
1441 | 1441 | $d['MontoItem'] -= $d['DescuentoMonto']; |
1442 | 1442 | // aplicar recargo |
1443 | 1443 | if ($d['RecargoPct']) { |
1444 | - $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct']/100); |
|
1444 | + $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct'] / 100); |
|
1445 | 1445 | } |
1446 | 1446 | $d['MontoItem'] += $d['RecargoMonto']; |
1447 | 1447 | // aproximar monto del item |
@@ -1527,7 +1527,7 @@ discard block |
||
1527 | 1527 | } |
1528 | 1528 | $valor = |
1529 | 1529 | $dr['TpoValor']=='%' |
1530 | - ? $this->round(($dr['ValorDR']/100)*$datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
1530 | + ? $this->round(($dr['ValorDR'] / 100) * $datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
1531 | 1531 | : $dr['ValorDR'] |
1532 | 1532 | ; |
1533 | 1533 | // aplicar descuento |
@@ -1600,7 +1600,7 @@ discard block |
||
1600 | 1600 | // si el monto no existe se asigna |
1601 | 1601 | if ($datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp']===null) { |
1602 | 1602 | $datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp'] = round( |
1603 | - $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp']/100 |
|
1603 | + $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp'] / 100 |
|
1604 | 1604 | ); |
1605 | 1605 | } |
1606 | 1606 | } |
@@ -1608,7 +1608,7 @@ discard block |
||
1608 | 1608 | if (isset($datos['Encabezado']['Totales']['ImptoReten']) and is_array($datos['Encabezado']['Totales']['ImptoReten'])) { |
1609 | 1609 | $codigos = array_keys($montos); |
1610 | 1610 | $n_impuestos = count($datos['Encabezado']['Totales']['ImptoReten']); |
1611 | - for ($i=0; $i<$n_impuestos; $i++) { |
|
1611 | + for ($i = 0; $i<$n_impuestos; $i++) { |
|
1612 | 1612 | if (!in_array($datos['Encabezado']['Totales']['ImptoReten'][$i]['TipoImp'], $codigos)) { |
1613 | 1613 | unset($datos['Encabezado']['Totales']['ImptoReten'][$i]); |
1614 | 1614 | } |
@@ -1633,7 +1633,7 @@ discard block |
||
1633 | 1633 | // valor IndMntNeto = 2 indica que los montosde las líneas on netos en cuyo caso no aplica el cálculo |
1634 | 1634 | // de neto e iva a partir del total y deberá venir informado de otra forma (aun no definido) |
1635 | 1635 | if ($this->esBoleta() and (empty($datos['Encabezado']['IdDoc']['IndMntNeto']) or $datos['Encabezado']['IdDoc']['IndMntNeto']!=2)) { |
1636 | - $total = (int)$datos['Encabezado']['Totales']['MntTotal'] - (int)$datos['Encabezado']['Totales']['MntExe']; |
|
1636 | + $total = (int)$datos['Encabezado']['Totales']['MntTotal']-(int)$datos['Encabezado']['Totales']['MntExe']; |
|
1637 | 1637 | if ($total and (empty($datos['Encabezado']['Totales']['MntNeto']) or empty($datos['Encabezado']['Totales']['IVA']))) { |
1638 | 1638 | list($datos['Encabezado']['Totales']['MntNeto'], $datos['Encabezado']['Totales']['IVA']) = $this->calcularNetoIVA($total); |
1639 | 1639 | } |
@@ -1648,7 +1648,7 @@ discard block |
||
1648 | 1648 | } else { |
1649 | 1649 | if (empty($datos['Encabezado']['Totales']['IVA']) and !empty($datos['Encabezado']['Totales']['TasaIVA'])) { |
1650 | 1650 | $datos['Encabezado']['Totales']['IVA'] = round( |
1651 | - $datos['Encabezado']['Totales']['MntNeto']*($datos['Encabezado']['Totales']['TasaIVA']/100) |
|
1651 | + $datos['Encabezado']['Totales']['MntNeto'] * ($datos['Encabezado']['Totales']['TasaIVA'] / 100) |
|
1652 | 1652 | ); |
1653 | 1653 | } |
1654 | 1654 | } |
@@ -1674,7 +1674,7 @@ discard block |
||
1674 | 1674 | if (ImpuestosAdicionales::getTipo($ImptoReten['TipoImp'])=='R') { |
1675 | 1675 | $datos['Encabezado']['Totales']['MntTotal'] -= $ImptoReten['MontoImp']; |
1676 | 1676 | if ($ImptoReten['MontoImp']!=$datos['Encabezado']['Totales']['IVA']) { |
1677 | - $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA'] - $ImptoReten['MontoImp']; |
|
1677 | + $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA']-$ImptoReten['MontoImp']; |
|
1678 | 1678 | } |
1679 | 1679 | } |
1680 | 1680 | // si es adicional se suma al total |
@@ -1832,7 +1832,7 @@ discard block |
||
1832 | 1832 | $SignatureValue = trim(str_replace(["\n", ' ', "\t"], '', $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue)); |
1833 | 1833 | $X509Certificate = trim(str_replace(["\n", ' ', "\t"], '', $Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue)); |
1834 | 1834 | $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap($X509Certificate, 64, "\n", true)."\n".'-----END CERTIFICATE----- '; |
1835 | - $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false; |
|
1835 | + $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false; |
|
1836 | 1836 | return $valid; |
1837 | 1837 | //return $valid and $DigestValue===base64_encode(sha1($Documento->C14N(), true)); |
1838 | 1838 | } |
@@ -57,10 +57,11 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct($datos, $normalizar = true) |
59 | 59 | { |
60 | - if (is_array($datos)) |
|
61 | - $this->setDatos($datos, $normalizar); |
|
62 | - else if (is_string($datos)) |
|
63 | - $this->loadXML($datos); |
|
60 | + if (is_array($datos)) { |
|
61 | + $this->setDatos($datos, $normalizar); |
|
62 | + } else if (is_string($datos)) { |
|
63 | + $this->loadXML($datos); |
|
64 | + } |
|
64 | 65 | $this->timestamp = date('Y-m-d\TH:i:s'); |
65 | 66 | } |
66 | 67 | |
@@ -121,8 +122,9 @@ discard block |
||
121 | 122 | if ($normalizar) { |
122 | 123 | $this->normalizar($datos); |
123 | 124 | $method = 'normalizar_'.$this->tipo; |
124 | - if (method_exists($this, $method)) |
|
125 | - $this->$method($datos); |
|
125 | + if (method_exists($this, $method)) { |
|
126 | + $this->$method($datos); |
|
127 | + } |
|
126 | 128 | $this->normalizar_final($datos); |
127 | 129 | } |
128 | 130 | $this->tipo_general = $this->getTipoGeneral($this->tipo); |
@@ -199,8 +201,9 @@ discard block |
||
199 | 201 | */ |
200 | 202 | public function getJSON() |
201 | 203 | { |
202 | - if (!$this->getDatos()) |
|
203 | - return false; |
|
204 | + if (!$this->getDatos()) { |
|
205 | + return false; |
|
206 | + } |
|
204 | 207 | return json_encode($this->datos, JSON_PRETTY_PRINT); |
205 | 208 | } |
206 | 209 | |
@@ -225,9 +228,10 @@ discard block |
||
225 | 228 | */ |
226 | 229 | private function getTipoGeneral($dte) |
227 | 230 | { |
228 | - foreach ($this->tipos as $tipo => $codigos) |
|
229 | - if (in_array($dte, $codigos)) |
|
231 | + foreach ($this->tipos as $tipo => $codigos) { |
|
232 | + if (in_array($dte, $codigos)) |
|
230 | 233 | return $tipo; |
234 | + } |
|
231 | 235 | \sasco\LibreDTE\Log::write( |
232 | 236 | \sasco\LibreDTE\Estado::DTE_ERROR_TIPO, |
233 | 237 | \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::DTE_ERROR_TIPO, $dte) |
@@ -266,10 +270,12 @@ discard block |
||
266 | 270 | public function getEmisor() |
267 | 271 | { |
268 | 272 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Emisor/RUTEmisor')->item(0); |
269 | - if ($nodo) |
|
270 | - return $nodo->nodeValue; |
|
271 | - if (!$this->getDatos()) |
|
272 | - return false; |
|
273 | + if ($nodo) { |
|
274 | + return $nodo->nodeValue; |
|
275 | + } |
|
276 | + if (!$this->getDatos()) { |
|
277 | + return false; |
|
278 | + } |
|
273 | 279 | return $this->datos['Encabezado']['Emisor']['RUTEmisor']; |
274 | 280 | } |
275 | 281 | |
@@ -282,10 +288,12 @@ discard block |
||
282 | 288 | public function getReceptor() |
283 | 289 | { |
284 | 290 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Receptor/RUTRecep')->item(0); |
285 | - if ($nodo) |
|
286 | - return $nodo->nodeValue; |
|
287 | - if (!$this->getDatos()) |
|
288 | - return false; |
|
291 | + if ($nodo) { |
|
292 | + return $nodo->nodeValue; |
|
293 | + } |
|
294 | + if (!$this->getDatos()) { |
|
295 | + return false; |
|
296 | + } |
|
289 | 297 | return $this->datos['Encabezado']['Receptor']['RUTRecep']; |
290 | 298 | } |
291 | 299 | |
@@ -298,10 +306,12 @@ discard block |
||
298 | 306 | public function getFechaEmision() |
299 | 307 | { |
300 | 308 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/IdDoc/FchEmis')->item(0); |
301 | - if ($nodo) |
|
302 | - return $nodo->nodeValue; |
|
303 | - if (!$this->getDatos()) |
|
304 | - return false; |
|
309 | + if ($nodo) { |
|
310 | + return $nodo->nodeValue; |
|
311 | + } |
|
312 | + if (!$this->getDatos()) { |
|
313 | + return false; |
|
314 | + } |
|
305 | 315 | return $this->datos['Encabezado']['IdDoc']['FchEmis']; |
306 | 316 | } |
307 | 317 | |
@@ -314,10 +324,12 @@ discard block |
||
314 | 324 | public function getMontoTotal() |
315 | 325 | { |
316 | 326 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Totales/MntTotal')->item(0); |
317 | - if ($nodo) |
|
318 | - return $nodo->nodeValue; |
|
319 | - if (!$this->getDatos()) |
|
320 | - return false; |
|
327 | + if ($nodo) { |
|
328 | + return $nodo->nodeValue; |
|
329 | + } |
|
330 | + if (!$this->getDatos()) { |
|
331 | + return false; |
|
332 | + } |
|
321 | 333 | return $this->datos['Encabezado']['Totales']['MntTotal']; |
322 | 334 | } |
323 | 335 | |
@@ -330,10 +342,12 @@ discard block |
||
330 | 342 | public function getMoneda() |
331 | 343 | { |
332 | 344 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Totales/TpoMoneda')->item(0); |
333 | - if ($nodo) |
|
334 | - return $nodo->nodeValue; |
|
335 | - if (!$this->getDatos()) |
|
336 | - return false; |
|
345 | + if ($nodo) { |
|
346 | + return $nodo->nodeValue; |
|
347 | + } |
|
348 | + if (!$this->getDatos()) { |
|
349 | + return false; |
|
350 | + } |
|
337 | 351 | return $this->datos['Encabezado']['Totales']['TpoMoneda']; |
338 | 352 | } |
339 | 353 | |
@@ -376,8 +390,9 @@ discard block |
||
376 | 390 | return false;*/ |
377 | 391 | $xml = new \sasco\LibreDTE\XML(); |
378 | 392 | $TED = $this->xml->getElementsByTagName('TED')->item(0); |
379 | - if (!$TED) |
|
380 | - return '<TED/>'; |
|
393 | + if (!$TED) { |
|
394 | + return '<TED/>'; |
|
395 | + } |
|
381 | 396 | $xml->loadXML($TED->C14N()); |
382 | 397 | $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); |
383 | 398 | $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', ''); |
@@ -676,8 +691,9 @@ discard block |
||
676 | 691 | ], $datos); |
677 | 692 | // si existe descuento o recargo global se normalizan |
678 | 693 | if (!empty($datos['DscRcgGlobal'])) { |
679 | - if (!isset($datos['DscRcgGlobal'][0])) |
|
680 | - $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
694 | + if (!isset($datos['DscRcgGlobal'][0])) { |
|
695 | + $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
696 | + } |
|
681 | 697 | $NroLinDR = 1; |
682 | 698 | foreach ($datos['DscRcgGlobal'] as &$dr) { |
683 | 699 | $dr = array_merge([ |
@@ -1344,8 +1360,9 @@ discard block |
||
1344 | 1360 | */ |
1345 | 1361 | private function normalizar_detalle(array &$datos) |
1346 | 1362 | { |
1347 | - if (!isset($datos['Detalle'][0])) |
|
1348 | - $datos['Detalle'] = [$datos['Detalle']]; |
|
1363 | + if (!isset($datos['Detalle'][0])) { |
|
1364 | + $datos['Detalle'] = [$datos['Detalle']]; |
|
1365 | + } |
|
1349 | 1366 | $item = 1; |
1350 | 1367 | foreach ($datos['Detalle'] as &$d) { |
1351 | 1368 | $d = array_merge([ |
@@ -1407,8 +1424,9 @@ discard block |
||
1407 | 1424 | ]; |
1408 | 1425 | } |
1409 | 1426 | if ($d['PrcItem']) { |
1410 | - if (!$d['QtyItem']) |
|
1411 | - $d['QtyItem'] = 1; |
|
1427 | + if (!$d['QtyItem']) { |
|
1428 | + $d['QtyItem'] = 1; |
|
1429 | + } |
|
1412 | 1430 | if (empty($d['MontoItem'])) { |
1413 | 1431 | $d['MontoItem'] = $this->round( |
1414 | 1432 | (float)$d['QtyItem'] * (float)$d['PrcItem'], |
@@ -1474,8 +1492,9 @@ discard block |
||
1474 | 1492 | private function normalizar_aplicar_descuentos_recargos(array &$datos) |
1475 | 1493 | { |
1476 | 1494 | if (!empty($datos['DscRcgGlobal'])) { |
1477 | - if (!isset($datos['DscRcgGlobal'][0])) |
|
1478 | - $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
1495 | + if (!isset($datos['DscRcgGlobal'][0])) { |
|
1496 | + $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
1497 | + } |
|
1479 | 1498 | foreach ($datos['DscRcgGlobal'] as &$dr) { |
1480 | 1499 | $dr = array_merge([ |
1481 | 1500 | 'NroLinDR' => false, |
@@ -1542,8 +1561,9 @@ discard block |
||
1542 | 1561 | $montos = []; |
1543 | 1562 | foreach ($datos['Detalle'] as &$d) { |
1544 | 1563 | if (!empty($d['CodImpAdic'])) { |
1545 | - if (!isset($montos[$d['CodImpAdic']])) |
|
1546 | - $montos[$d['CodImpAdic']] = 0; |
|
1564 | + if (!isset($montos[$d['CodImpAdic']])) { |
|
1565 | + $montos[$d['CodImpAdic']] = 0; |
|
1566 | + } |
|
1547 | 1567 | $montos[$d['CodImpAdic']] += $d['MontoItem']; |
1548 | 1568 | } |
1549 | 1569 | } |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | ]; ///< Tipos de transacciones o caracterizaciones/clasificaciones de las compras |
72 | 72 | |
73 | 73 | public static $estados_ok = [ |
74 | - 7, // Evento registrado previamente |
|
75 | - 8, // Pasados 8 días después de la recepción no es posible registrar reclamos o eventos |
|
74 | + 7, // Evento registrado previamente |
|
75 | + 8, // Pasados 8 días después de la recepción no es posible registrar reclamos o eventos |
|
76 | 76 | 27, // No se puede registrar un evento (acuse de recibo, reclamo o aceptación de contenido) de un DTE pagado al contado o gratuito |
77 | 77 | ]; ///< Código de estado de respuesta de la asignación de estado que son considerados como OK |
78 | 78 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | return false; |
252 | 252 | } |
253 | 253 | // hacer consultas al SII |
254 | - for ($i=0; $i<$retry; $i++) { |
|
254 | + for ($i = 0; $i<$retry; $i++) { |
|
255 | 255 | try { |
256 | 256 | $body = call_user_func_array([$soap, $request], $args); |
257 | 257 | break; |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | if (!is_numeric($n)) { |
260 | 260 | return $n; |
261 | 261 | } |
262 | - if ($decimales === null) { |
|
262 | + if ($decimales===null) { |
|
263 | 263 | $broken_number = explode('.', (string)$n); |
264 | 264 | if (isset($broken_number[1])) { |
265 | 265 | return number_format($broken_number[0], 0, ',', '.').','.$broken_number[1]; |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | $dias = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado']; |
281 | 281 | $meses = ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre']; |
282 | 282 | $unixtime = strtotime($date); |
283 | - $fecha = date(($mostrar_dia?'\D\I\A ':'').'j \d\e \M\E\S \d\e\l Y', $unixtime); |
|
283 | + $fecha = date(($mostrar_dia ? '\D\I\A ' : '').'j \d\e \M\E\S \d\e\l Y', $unixtime); |
|
284 | 284 | $dia = $dias[date('w', $unixtime)]; |
285 | 285 | $mes = $meses[date('n', $unixtime)-1]; |
286 | 286 | return str_replace(array('DIA', 'MES'), array($dia, $mes), $fecha); |