Completed
Push — master ( beb740...935484 )
by Esteban De La Fuente
26s
created
lib/Sii/Dte.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
                 ]
154 154
             ]);
155 155
             $parent = $this->xml->getElementsByTagName($this->tipo_general)->item(0);
156
-            $this->xml->generate($datos + ['TED' => null], null, $parent);
156
+            $this->xml->generate($datos+['TED' => null], null, $parent);
157 157
             $this->datos = $datos;
158 158
             // validar datos
159 159
             $this->verificar_datos();
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
         $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi');
396 396
         $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', '');
397 397
         $TED = $xml->getFlattened('/');
398
-        return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1']) != 'ISO-8859-1' ? utf8_decode($TED) : $TED;
398
+        return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1'])!='ISO-8859-1' ? utf8_decode($TED) : $TED;
399 399
     }
400 400
 
401 401
     /**
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
     {
409 409
         $datos = $this->getDatos();
410 410
         $idk = !empty($datos['TED']['DD']['CAF']['DA']['IDK']) ? (int)$datos['TED']['DD']['CAF']['DA']['IDK'] : null;
411
-        return $idk ? $idk === 100 : null;
411
+        return $idk ? $idk===100 : null;
412 412
     }
413 413
 
414 414
     /**
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
     {
546 546
         $this->getDatos();
547 547
         // generar resumen
548
-        $resumen =  [
548
+        $resumen = [
549 549
             'TpoDoc' => (int)$this->datos['Encabezado']['IdDoc']['TipoDTE'],
550 550
             'NroDoc' => (int)$this->datos['Encabezado']['IdDoc']['Folio'],
551 551
             'TasaImp' => 0,
@@ -590,10 +590,10 @@  discard block
 block discarded – undo
590 590
      */
591 591
     private function calcularNetoIVA($total, $tasa = null)
592 592
     {
593
-        if ($tasa === 0 or $tasa === false) {
593
+        if ($tasa===0 or $tasa===false) {
594 594
             return [0, 0];
595 595
         }
596
-        if ($tasa === null) {
596
+        if ($tasa===null) {
597 597
             $tasa = \sasco\LibreDTE\Sii::getIVA();
598 598
         }
599 599
         // WARNING: el IVA obtenido puede no ser el NETO*(TASA/100)
@@ -601,8 +601,8 @@  discard block
 block discarded – undo
601 601
         // entre el total y el neto, ya que hay casos de borde como:
602 602
         //  - BRUTO:   680 => NETO:   571 e IVA:   108 => TOTAL:   679
603 603
         //  - BRUTO: 86710 => NETO: 72866 e IVA: 13845 => TOTAL: 86711
604
-        $neto = round($total / (1+($tasa/100)));
605
-        $iva = $total - $neto;
604
+        $neto = round($total / (1+($tasa / 100)));
605
+        $iva = $total-$neto;
606 606
         return [$neto, $iva];
607 607
     }
608 608
 
@@ -1363,7 +1363,7 @@  discard block
 block discarded – undo
1363 1363
         $item = 1;
1364 1364
         $sumarMontoNF = (
1365 1365
             !isset($datos['Encabezado']['Totales']['MontoNF'])
1366
-            or $datos['Encabezado']['Totales']['MontoNF'] === false
1366
+            or $datos['Encabezado']['Totales']['MontoNF']===false
1367 1367
         );
1368 1368
         foreach ($datos['Detalle'] as &$d) {
1369 1369
             $d = array_merge([
@@ -1435,12 +1435,12 @@  discard block
 block discarded – undo
1435 1435
                     );
1436 1436
                     // aplicar descuento
1437 1437
                     if ($d['DescuentoPct']) {
1438
-                        $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct']/100);
1438
+                        $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct'] / 100);
1439 1439
                     }
1440 1440
                     $d['MontoItem'] -= $d['DescuentoMonto'];
1441 1441
                     // aplicar recargo
1442 1442
                     if ($d['RecargoPct']) {
1443
-                        $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct']/100);
1443
+                        $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct'] / 100);
1444 1444
                     }
1445 1445
                     $d['MontoItem'] += $d['RecargoMonto'];
1446 1446
                     // aproximar monto del item
@@ -1542,7 +1542,7 @@  discard block
 block discarded – undo
1542 1542
                 }
1543 1543
                 $valor =
1544 1544
                     $dr['TpoValor']=='%'
1545
-                    ? $this->round(($dr['ValorDR']/100)*$datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda'])
1545
+                    ? $this->round(($dr['ValorDR'] / 100) * $datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda'])
1546 1546
                     : $dr['ValorDR']
1547 1547
                 ;
1548 1548
                 // aplicar descuento
@@ -1615,7 +1615,7 @@  discard block
 block discarded – undo
1615 1615
             // si el monto no existe se asigna
1616 1616
             if ($datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp']===null) {
1617 1617
                 $datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp'] = round(
1618
-                    $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp']/100
1618
+                    $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp'] / 100
1619 1619
                 );
1620 1620
             }
1621 1621
         }
@@ -1623,7 +1623,7 @@  discard block
 block discarded – undo
1623 1623
         if (isset($datos['Encabezado']['Totales']['ImptoReten']) and is_array($datos['Encabezado']['Totales']['ImptoReten'])) {
1624 1624
             $codigos = array_keys($montos);
1625 1625
             $n_impuestos = count($datos['Encabezado']['Totales']['ImptoReten']);
1626
-            for ($i=0; $i<$n_impuestos; $i++) {
1626
+            for ($i = 0; $i<$n_impuestos; $i++) {
1627 1627
                 if (!in_array($datos['Encabezado']['Totales']['ImptoReten'][$i]['TipoImp'], $codigos)) {
1628 1628
                     unset($datos['Encabezado']['Totales']['ImptoReten'][$i]);
1629 1629
                 }
@@ -1648,7 +1648,7 @@  discard block
 block discarded – undo
1648 1648
         // valor IndMntNeto = 2 indica que los montosde las líneas on netos en cuyo caso no aplica el cálculo
1649 1649
         // de neto e iva a partir del total y deberá venir informado de otra forma (aun no definido)
1650 1650
         if ($this->esBoleta() and (empty($datos['Encabezado']['IdDoc']['IndMntNeto']) or $datos['Encabezado']['IdDoc']['IndMntNeto']!=2)) {
1651
-            $total = (int)$datos['Encabezado']['Totales']['MntTotal'] - (int)$datos['Encabezado']['Totales']['MntExe'];
1651
+            $total = (int)$datos['Encabezado']['Totales']['MntTotal']-(int)$datos['Encabezado']['Totales']['MntExe'];
1652 1652
             if ($total and (empty($datos['Encabezado']['Totales']['MntNeto']) or empty($datos['Encabezado']['Totales']['IVA']))) {
1653 1653
                 list($datos['Encabezado']['Totales']['MntNeto'], $datos['Encabezado']['Totales']['IVA']) = $this->calcularNetoIVA($total);
1654 1654
             }
@@ -1663,7 +1663,7 @@  discard block
 block discarded – undo
1663 1663
             } else {
1664 1664
                 if (empty($datos['Encabezado']['Totales']['IVA']) and !empty($datos['Encabezado']['Totales']['TasaIVA'])) {
1665 1665
                     $datos['Encabezado']['Totales']['IVA'] = round(
1666
-                        $datos['Encabezado']['Totales']['MntNeto']*($datos['Encabezado']['Totales']['TasaIVA']/100)
1666
+                        $datos['Encabezado']['Totales']['MntNeto'] * ($datos['Encabezado']['Totales']['TasaIVA'] / 100)
1667 1667
                     );
1668 1668
                 }
1669 1669
             }
@@ -1689,7 +1689,7 @@  discard block
 block discarded – undo
1689 1689
                 if (ImpuestosAdicionales::getTipo($ImptoReten['TipoImp'])=='R') {
1690 1690
                     $datos['Encabezado']['Totales']['MntTotal'] -= $ImptoReten['MontoImp'];
1691 1691
                     if ($ImptoReten['MontoImp']!=$datos['Encabezado']['Totales']['IVA']) {
1692
-                        $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA'] - $ImptoReten['MontoImp'];
1692
+                        $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA']-$ImptoReten['MontoImp'];
1693 1693
                     }
1694 1694
                 }
1695 1695
                 // si es adicional se suma al total
@@ -1708,7 +1708,7 @@  discard block
 block discarded – undo
1708 1708
         // si hay monto total y monto no facturable se agrega monto del periodo
1709 1709
         if (!in_array($datos['Encabezado']['IdDoc']['TipoDTE'], [39, 41])) {
1710 1710
             if (!empty($datos['Encabezado']['Totales']['MntTotal']) and !empty($datos['Encabezado']['Totales']['MontoNF'])) {
1711
-                $datos['Encabezado']['Totales']['MontoPeriodo'] = $datos['Encabezado']['Totales']['MntTotal'] + $datos['Encabezado']['Totales']['MontoNF'];
1711
+                $datos['Encabezado']['Totales']['MontoPeriodo'] = $datos['Encabezado']['Totales']['MntTotal']+$datos['Encabezado']['Totales']['MontoNF'];
1712 1712
             }
1713 1713
         }
1714 1714
     }
@@ -1921,7 +1921,7 @@  discard block
 block discarded – undo
1921 1921
         $SignatureValue = trim(str_replace(["\n", ' ', "\t"], '', $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue));
1922 1922
         $X509Certificate = trim(str_replace(["\n", ' ', "\t"], '', $Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue));
1923 1923
         $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap($X509Certificate, 64, "\n", true)."\n".'-----END CERTIFICATE----- ';
1924
-        $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false;
1924
+        $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false;
1925 1925
         return $valid;
1926 1926
         //return $valid and $DigestValue===base64_encode(sha1($Documento->C14N(), true));
1927 1927
     }
Please login to merge, or discard this patch.
Braces   +45 added lines, -30 removed lines patch added patch discarded remove patch
@@ -217,8 +217,9 @@  discard block
 block discarded – undo
217 217
      */
218 218
     public function getJSON()
219 219
     {
220
-        if (!$this->getDatos())
221
-            return false;
220
+        if (!$this->getDatos()) {
221
+                    return false;
222
+        }
222 223
         return json_encode($this->datos, JSON_PRETTY_PRINT);
223 224
     }
224 225
 
@@ -286,10 +287,12 @@  discard block
 block discarded – undo
286 287
     public function getEmisor()
287 288
     {
288 289
         $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Emisor/RUTEmisor')->item(0);
289
-        if ($nodo)
290
-            return $nodo->nodeValue;
291
-        if (!$this->getDatos())
292
-            return false;
290
+        if ($nodo) {
291
+                    return $nodo->nodeValue;
292
+        }
293
+        if (!$this->getDatos()) {
294
+                    return false;
295
+        }
293 296
         return $this->datos['Encabezado']['Emisor']['RUTEmisor'];
294 297
     }
295 298
 
@@ -302,10 +305,12 @@  discard block
 block discarded – undo
302 305
     public function getReceptor()
303 306
     {
304 307
         $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Receptor/RUTRecep')->item(0);
305
-        if ($nodo)
306
-            return $nodo->nodeValue;
307
-        if (!$this->getDatos())
308
-            return false;
308
+        if ($nodo) {
309
+                    return $nodo->nodeValue;
310
+        }
311
+        if (!$this->getDatos()) {
312
+                    return false;
313
+        }
309 314
         return $this->datos['Encabezado']['Receptor']['RUTRecep'];
310 315
     }
311 316
 
@@ -318,10 +323,12 @@  discard block
 block discarded – undo
318 323
     public function getFechaEmision()
319 324
     {
320 325
         $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/IdDoc/FchEmis')->item(0);
321
-        if ($nodo)
322
-            return $nodo->nodeValue;
323
-        if (!$this->getDatos())
324
-            return false;
326
+        if ($nodo) {
327
+                    return $nodo->nodeValue;
328
+        }
329
+        if (!$this->getDatos()) {
330
+                    return false;
331
+        }
325 332
         return $this->datos['Encabezado']['IdDoc']['FchEmis'];
326 333
     }
327 334
 
@@ -334,10 +341,12 @@  discard block
 block discarded – undo
334 341
     public function getMontoTotal()
335 342
     {
336 343
         $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Totales/MntTotal')->item(0);
337
-        if ($nodo)
338
-            return $nodo->nodeValue;
339
-        if (!$this->getDatos())
340
-            return false;
344
+        if ($nodo) {
345
+                    return $nodo->nodeValue;
346
+        }
347
+        if (!$this->getDatos()) {
348
+                    return false;
349
+        }
341 350
         return $this->datos['Encabezado']['Totales']['MntTotal'];
342 351
     }
343 352
 
@@ -350,10 +359,12 @@  discard block
 block discarded – undo
350 359
     public function getMoneda()
351 360
     {
352 361
         $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Totales/TpoMoneda')->item(0);
353
-        if ($nodo)
354
-            return $nodo->nodeValue;
355
-        if (!$this->getDatos())
356
-            return false;
362
+        if ($nodo) {
363
+                    return $nodo->nodeValue;
364
+        }
365
+        if (!$this->getDatos()) {
366
+                    return false;
367
+        }
357 368
         return $this->datos['Encabezado']['Totales']['TpoMoneda'];
358 369
     }
359 370
 
@@ -396,8 +407,9 @@  discard block
 block discarded – undo
396 407
             return false;*/
397 408
         $xml = new \sasco\LibreDTE\XML();
398 409
         $TED = $this->xml->getElementsByTagName('TED')->item(0);
399
-        if (!$TED)
400
-            return '<TED/>';
410
+        if (!$TED) {
411
+                    return '<TED/>';
412
+        }
401 413
         $xml->loadXML($TED->C14N());
402 414
         $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi');
403 415
         $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', '');
@@ -700,8 +712,9 @@  discard block
 block discarded – undo
700 712
         ], $datos);
701 713
         // si existe descuento o recargo global se normalizan
702 714
         if (!empty($datos['DscRcgGlobal'])) {
703
-            if (!isset($datos['DscRcgGlobal'][0]))
704
-                $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']];
715
+            if (!isset($datos['DscRcgGlobal'][0])) {
716
+                            $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']];
717
+            }
705 718
             $NroLinDR = 1;
706 719
             foreach ($datos['DscRcgGlobal'] as &$dr) {
707 720
                 $dr = array_merge([
@@ -1520,8 +1533,9 @@  discard block
 block discarded – undo
1520 1533
     private function normalizar_aplicar_descuentos_recargos(array &$datos)
1521 1534
     {
1522 1535
         if (!empty($datos['DscRcgGlobal'])) {
1523
-            if (!isset($datos['DscRcgGlobal'][0]))
1524
-                $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']];
1536
+            if (!isset($datos['DscRcgGlobal'][0])) {
1537
+                            $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']];
1538
+            }
1525 1539
             foreach ($datos['DscRcgGlobal'] as &$dr) {
1526 1540
                 $dr = array_merge([
1527 1541
                     'NroLinDR' => false,
@@ -1588,8 +1602,9 @@  discard block
 block discarded – undo
1588 1602
         $montos = [];
1589 1603
         foreach ($datos['Detalle'] as &$d) {
1590 1604
             if (!empty($d['CodImpAdic'])) {
1591
-                if (!isset($montos[$d['CodImpAdic']]))
1592
-                    $montos[$d['CodImpAdic']] = 0;
1605
+                if (!isset($montos[$d['CodImpAdic']])) {
1606
+                                    $montos[$d['CodImpAdic']] = 0;
1607
+                }
1593 1608
                 $montos[$d['CodImpAdic']] += $d['MontoItem'];
1594 1609
             }
1595 1610
         }
Please login to merge, or discard this patch.
lib/Sii/Folios.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -65,11 +65,11 @@  discard block
 block discarded – undo
65 65
         // validar firma del SII sobre los folios
66 66
         $firma = $this->getFirma();
67 67
         $idk = $this->getIDK();
68
-        if ($firma === false || $idk === false) {
68
+        if ($firma===false || $idk===false) {
69 69
             return false;
70 70
         }
71 71
         $pub_key = \sasco\LibreDTE\Sii::cert($idk);
72
-        if ($pub_key === false || openssl_verify($this->xml->getFlattened('/AUTORIZACION/CAF/DA'), base64_decode($firma), $pub_key)!==1) {
72
+        if ($pub_key===false || openssl_verify($this->xml->getFlattened('/AUTORIZACION/CAF/DA'), base64_decode($firma), $pub_key)!==1) {
73 73
             \sasco\LibreDTE\Log::write(
74 74
                 \sasco\LibreDTE\Estado::FOLIOS_ERROR_FIRMA,
75 75
                 \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::FOLIOS_ERROR_FIRMA)
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
             );
101 101
             return false;
102 102
         }
103
-        return $plain === $plain_firmado;
103
+        return $plain===$plain_firmado;
104 104
     }
105 105
 
106 106
     /**
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
         if (!$desde || !$hasta) {
177 177
             return false;
178 178
         }
179
-        return $hasta - $desde + 1;
179
+        return $hasta-$desde+1;
180 180
     }
181 181
 
182 182
     /**
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
         if (!$fecha_autorizacion) {
286 286
             return false;
287 287
         }
288
-        return date('Y-m-d', strtotime($fecha_autorizacion. ' + 180 days')); // 6 meses = 6 * 30 días
288
+        return date('Y-m-d', strtotime($fecha_autorizacion.' + 180 days')); // 6 meses = 6 * 30 días
289 289
     }
290 290
 
291 291
     /**
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
         $d1 = new \DateTime($this->getFechaAutorizacion());
299 299
         $d2 = new \DateTime(date('Y-m-d'));
300 300
         $diff = $d1->diff($d2);
301
-        $meses = $diff->m + ($diff->y*12);
301
+        $meses = $diff->m+($diff->y * 12);
302 302
         if ($diff->d) {
303 303
             $meses += round($diff->d / 30, 2);
304 304
         }
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
         if (!$this->vence()) {
317 317
             return true;
318 318
         }
319
-        return date('Y-m-d') < $this->getFechaVencimiento();
319
+        return date('Y-m-d')<$this->getFechaVencimiento();
320 320
     }
321 321
 
322 322
     /**
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
     public function getCertificacion()
340 340
     {
341 341
         $idk = $this->getIDK();
342
-        return $idk ?  $idk === 100 : null;
342
+        return $idk ? $idk===100 : null;
343 343
     }
344 344
 
345 345
     /**
Please login to merge, or discard this patch.