@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | { |
33 | 33 | |
34 | 34 | private $dtes = []; ///< Objetos con los DTE que se enviarán |
35 | - private $config = [ // 0: DTE, 1: boleta |
|
35 | + private $config = [// 0: DTE, 1: boleta |
|
36 | 36 | 'SubTotDTE_max' => [20, 2], ///< máxima cantidad de tipos de documentos en el envío |
37 | 37 | 'DTE_max' => [2000, 1000], ///< máxima cantidad de DTE en un envío |
38 | 38 | 'tipos' => ['EnvioDTE', 'EnvioBOLETA'], ///< Tag para el envío, según si son Boletas o no |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | public function agregar(Dte $DTE) |
51 | 51 | { |
52 | 52 | // determinar el tipo del envío (DTE o boleta) |
53 | - if ($this->tipo === null) { |
|
53 | + if ($this->tipo===null) { |
|
54 | 54 | $this->tipo = (int)$DTE->esBoleta(); |
55 | 55 | } |
56 | 56 | // validar que el tipo de documento sea del tipo que se espera |
57 | - else if ((int)$DTE->esBoleta() != $this->tipo) { |
|
57 | + else if ((int)$DTE->esBoleta()!=$this->tipo) { |
|
58 | 58 | return false; |
59 | 59 | } |
60 | 60 | // |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | 'RutEnvia' => $Dte->getEmisor(), |
222 | 222 | 'RutReceptor' => $Dte->getReceptor(), |
223 | 223 | 'FchResol' => date('Y-m-d'), |
224 | - 'NroResol' => ($Dte->getCertificacion()?'0':'').'9999', |
|
224 | + 'NroResol' => ($Dte->getCertificacion() ? '0' : '').'9999', |
|
225 | 225 | ]); |
226 | 226 | if (!parent::loadXML($this->generar())) { |
227 | 227 | return false; |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | { |
302 | 302 | $fecha = '9999-12-31'; |
303 | 303 | foreach ($this->getDocumentos() as $Dte) { |
304 | - if ($Dte->getFechaEmision() < $fecha) |
|
304 | + if ($Dte->getFechaEmision()<$fecha) |
|
305 | 305 | $fecha = $Dte->getFechaEmision(); |
306 | 306 | } |
307 | 307 | return $fecha; |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | { |
317 | 317 | $fecha = '0000-01-01'; |
318 | 318 | foreach ($this->getDocumentos() as $Dte) { |
319 | - if ($Dte->getFechaEmision() > $fecha) |
|
319 | + if ($Dte->getFechaEmision()>$fecha) |
|
320 | 320 | $fecha = $Dte->getFechaEmision(); |
321 | 321 | } |
322 | 322 | return $fecha; |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | $e = substr($e, 0, -2); |
376 | 376 | $d = (int)$nodo_dte->getElementsByTagName('TipoDTE')->item(0)->nodeValue; |
377 | 377 | $f = (int)$nodo_dte->getElementsByTagName('Folio')->item(0)->nodeValue; |
378 | - if ($folio == $f and $dte == $d and $emisor == $e) { |
|
378 | + if ($folio==$f and $dte==$d and $emisor==$e) { |
|
379 | 379 | return new Dte($nodo_dte->C14N(), false); // cargar DTE sin normalizar |
380 | 380 | } |
381 | 381 | } |
@@ -435,12 +435,12 @@ discard block |
||
435 | 435 | if ($X509Certificate[1]==' ' or $X509Certificate[1]=="\t") { |
436 | 436 | $lineas = explode("\n", $X509Certificate); |
437 | 437 | $X509Certificate = ''; |
438 | - foreach($lineas as $l) { |
|
438 | + foreach ($lineas as $l) { |
|
439 | 439 | $X509Certificate .= trim($l); |
440 | 440 | } |
441 | 441 | } |
442 | - $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap(trim(str_replace(' ','',$X509Certificate)), 64, "\n", true)."\n".'-----END CERTIFICATE-----'; |
|
443 | - $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false; |
|
442 | + $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap(trim(str_replace(' ', '', $X509Certificate)), 64, "\n", true)."\n".'-----END CERTIFICATE-----'; |
|
443 | + $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false; |
|
444 | 444 | return $valid and $DigestValue===base64_encode(sha1($SetDTE, true)); |
445 | 445 | } |
446 | 446 |
@@ -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 | /** |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | { |
530 | 530 | $this->getDatos(); |
531 | 531 | // generar resumen |
532 | - $resumen = [ |
|
532 | + $resumen = [ |
|
533 | 533 | 'TpoDoc' => (int)$this->datos['Encabezado']['IdDoc']['TipoDTE'], |
534 | 534 | 'NroDoc' => (int)$this->datos['Encabezado']['IdDoc']['Folio'], |
535 | 535 | 'TasaImp' => 0, |
@@ -574,17 +574,17 @@ discard block |
||
574 | 574 | */ |
575 | 575 | private function calcularNetoIVA($total, $tasa = null) |
576 | 576 | { |
577 | - if ($tasa === 0 or $tasa === false) |
|
577 | + if ($tasa===0 or $tasa===false) |
|
578 | 578 | return [0, 0]; |
579 | - if ($tasa === null) |
|
579 | + if ($tasa===null) |
|
580 | 580 | $tasa = \sasco\LibreDTE\Sii::getIVA(); |
581 | 581 | // WARNING: el IVA obtenido puede no ser el NETO*(TASA/100) |
582 | 582 | // se calcula el monto neto y luego se obtiene el IVA haciendo la resta |
583 | 583 | // entre el total y el neto, ya que hay casos de borde como: |
584 | 584 | // - BRUTO: 680 => NETO: 571 e IVA: 108 => TOTAL: 679 |
585 | 585 | // - BRUTO: 86710 => NETO: 72866 e IVA: 13845 => TOTAL: 86711 |
586 | - $neto = round($total / (1+($tasa/100))); |
|
587 | - $iva = $total - $neto; |
|
586 | + $neto = round($total / (1+($tasa / 100))); |
|
587 | + $iva = $total-$neto; |
|
588 | 588 | return [$neto, $iva]; |
589 | 589 | } |
590 | 590 | |
@@ -1429,12 +1429,12 @@ discard block |
||
1429 | 1429 | ); |
1430 | 1430 | // aplicar descuento |
1431 | 1431 | if ($d['DescuentoPct']) { |
1432 | - $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct']/100); |
|
1432 | + $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct'] / 100); |
|
1433 | 1433 | } |
1434 | 1434 | $d['MontoItem'] -= $d['DescuentoMonto']; |
1435 | 1435 | // aplicar recargo |
1436 | 1436 | if ($d['RecargoPct']) { |
1437 | - $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct']/100); |
|
1437 | + $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct'] / 100); |
|
1438 | 1438 | } |
1439 | 1439 | $d['MontoItem'] += $d['RecargoMonto']; |
1440 | 1440 | // aproximar monto del item |
@@ -1520,7 +1520,7 @@ discard block |
||
1520 | 1520 | } |
1521 | 1521 | $valor = |
1522 | 1522 | $dr['TpoValor']=='%' |
1523 | - ? $this->round(($dr['ValorDR']/100)*$datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
1523 | + ? $this->round(($dr['ValorDR'] / 100) * $datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
1524 | 1524 | : $dr['ValorDR'] |
1525 | 1525 | ; |
1526 | 1526 | // aplicar descuento |
@@ -1593,7 +1593,7 @@ discard block |
||
1593 | 1593 | // si el monto no existe se asigna |
1594 | 1594 | if ($datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp']===null) { |
1595 | 1595 | $datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp'] = round( |
1596 | - $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp']/100 |
|
1596 | + $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp'] / 100 |
|
1597 | 1597 | ); |
1598 | 1598 | } |
1599 | 1599 | } |
@@ -1601,7 +1601,7 @@ discard block |
||
1601 | 1601 | if (isset($datos['Encabezado']['Totales']['ImptoReten']) and is_array($datos['Encabezado']['Totales']['ImptoReten'])) { |
1602 | 1602 | $codigos = array_keys($montos); |
1603 | 1603 | $n_impuestos = count($datos['Encabezado']['Totales']['ImptoReten']); |
1604 | - for ($i=0; $i<$n_impuestos; $i++) { |
|
1604 | + for ($i = 0; $i<$n_impuestos; $i++) { |
|
1605 | 1605 | if (!in_array($datos['Encabezado']['Totales']['ImptoReten'][$i]['TipoImp'], $codigos)) { |
1606 | 1606 | unset($datos['Encabezado']['Totales']['ImptoReten'][$i]); |
1607 | 1607 | } |
@@ -1629,7 +1629,7 @@ discard block |
||
1629 | 1629 | } else { |
1630 | 1630 | if (empty($datos['Encabezado']['Totales']['IVA']) and !empty($datos['Encabezado']['Totales']['TasaIVA'])) { |
1631 | 1631 | $datos['Encabezado']['Totales']['IVA'] = round( |
1632 | - $datos['Encabezado']['Totales']['MntNeto']*($datos['Encabezado']['Totales']['TasaIVA']/100) |
|
1632 | + $datos['Encabezado']['Totales']['MntNeto'] * ($datos['Encabezado']['Totales']['TasaIVA'] / 100) |
|
1633 | 1633 | ); |
1634 | 1634 | } |
1635 | 1635 | } |
@@ -1653,7 +1653,7 @@ discard block |
||
1653 | 1653 | if (ImpuestosAdicionales::getTipo($ImptoReten['TipoImp'])=='R') { |
1654 | 1654 | $datos['Encabezado']['Totales']['MntTotal'] -= $ImptoReten['MontoImp']; |
1655 | 1655 | if ($ImptoReten['MontoImp']!=$datos['Encabezado']['Totales']['IVA']) { |
1656 | - $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA'] - $ImptoReten['MontoImp']; |
|
1656 | + $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA']-$ImptoReten['MontoImp']; |
|
1657 | 1657 | } |
1658 | 1658 | } |
1659 | 1659 | // si es adicional se suma al total |
@@ -1812,8 +1812,8 @@ discard block |
||
1812 | 1812 | $DigestValue = $Signature->getElementsByTagName('DigestValue')->item(0)->nodeValue; |
1813 | 1813 | $SignatureValue = $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue; |
1814 | 1814 | $X509Certificate = $Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue; |
1815 | - $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap(trim(str_replace(' ','',$X509Certificate)), 64, "\n", true)."\n".'-----END CERTIFICATE----- '; |
|
1816 | - $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false; |
|
1815 | + $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap(trim(str_replace(' ', '', $X509Certificate)), 64, "\n", true)."\n".'-----END CERTIFICATE----- '; |
|
1816 | + $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false; |
|
1817 | 1817 | return $valid; |
1818 | 1818 | //return $valid and $DigestValue===base64_encode(sha1($Documento->C14N(), true)); |
1819 | 1819 | } |