Completed
Push — master ( d5bd73...69c076 )
by Esteban De La Fuente
41s
created
lib/Sii/RegistroCompraVenta.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
lib/Sii/Dte/Base/DteImpreso.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
lib/Sii/Dte.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
                 ]
146 146
             ]);
147 147
             $parent = $this->xml->getElementsByTagName($this->tipo_general)->item(0);
148
-            $this->xml->generate($datos + ['TED' => null], null, $parent);
148
+            $this->xml->generate($datos+['TED' => null], null, $parent);
149 149
             $this->datos = $datos;
150 150
             $this->verificar_datos();
151 151
             return $this->schemaValidate();
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
         $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi');
387 387
         $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', '');
388 388
         $TED = $xml->getFlattened('/');
389
-        return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1']) != 'ISO-8859-1' ? utf8_decode($TED) : $TED;
389
+        return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1'])!='ISO-8859-1' ? utf8_decode($TED) : $TED;
390 390
     }
391 391
 
392 392
     /**
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
     {
400 400
         $datos = $this->getDatos();
401 401
         $idk = !empty($datos['TED']['DD']['CAF']['DA']['IDK']) ? (int)$datos['TED']['DD']['CAF']['DA']['IDK'] : null;
402
-        return $idk ? $idk === 100 : null;
402
+        return $idk ? $idk===100 : null;
403 403
     }
404 404
 
405 405
     /**
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
     {
537 537
         $this->getDatos();
538 538
         // generar resumen
539
-        $resumen =  [
539
+        $resumen = [
540 540
             'TpoDoc' => (int)$this->datos['Encabezado']['IdDoc']['TipoDTE'],
541 541
             'NroDoc' => (int)$this->datos['Encabezado']['IdDoc']['Folio'],
542 542
             'TasaImp' => 0,
@@ -581,10 +581,10 @@  discard block
 block discarded – undo
581 581
      */
582 582
     private function calcularNetoIVA($total, $tasa = null)
583 583
     {
584
-        if ($tasa === 0 or $tasa === false) {
584
+        if ($tasa===0 or $tasa===false) {
585 585
             return [0, 0];
586 586
         }
587
-        if ($tasa === null) {
587
+        if ($tasa===null) {
588 588
             $tasa = \sasco\LibreDTE\Sii::getIVA();
589 589
         }
590 590
         // WARNING: el IVA obtenido puede no ser el NETO*(TASA/100)
@@ -592,8 +592,8 @@  discard block
 block discarded – undo
592 592
         // entre el total y el neto, ya que hay casos de borde como:
593 593
         //  - BRUTO:   680 => NETO:   571 e IVA:   108 => TOTAL:   679
594 594
         //  - BRUTO: 86710 => NETO: 72866 e IVA: 13845 => TOTAL: 86711
595
-        $neto = round($total / (1+($tasa/100)));
596
-        $iva = $total - $neto;
595
+        $neto = round($total / (1+($tasa / 100)));
596
+        $iva = $total-$neto;
597 597
         return [$neto, $iva];
598 598
     }
599 599
 
@@ -1354,7 +1354,7 @@  discard block
 block discarded – undo
1354 1354
         $item = 1;
1355 1355
         $sumarMontoNF = (
1356 1356
             !isset($datos['Encabezado']['Totales']['MontoNF'])
1357
-            or $datos['Encabezado']['Totales']['MontoNF'] === false
1357
+            or $datos['Encabezado']['Totales']['MontoNF']===false
1358 1358
         );
1359 1359
         foreach ($datos['Detalle'] as &$d) {
1360 1360
             $d = array_merge([
@@ -1426,12 +1426,12 @@  discard block
 block discarded – undo
1426 1426
                     );
1427 1427
                     // aplicar descuento
1428 1428
                     if ($d['DescuentoPct']) {
1429
-                        $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct']/100);
1429
+                        $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct'] / 100);
1430 1430
                     }
1431 1431
                     $d['MontoItem'] -= $d['DescuentoMonto'];
1432 1432
                     // aplicar recargo
1433 1433
                     if ($d['RecargoPct']) {
1434
-                        $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct']/100);
1434
+                        $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct'] / 100);
1435 1435
                     }
1436 1436
                     $d['MontoItem'] += $d['RecargoMonto'];
1437 1437
                     // aproximar monto del item
@@ -1535,7 +1535,7 @@  discard block
 block discarded – undo
1535 1535
                 }
1536 1536
                 $valor =
1537 1537
                     $dr['TpoValor']=='%'
1538
-                    ? $this->round(($dr['ValorDR']/100)*$datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda'])
1538
+                    ? $this->round(($dr['ValorDR'] / 100) * $datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda'])
1539 1539
                     : $dr['ValorDR']
1540 1540
                 ;
1541 1541
                 // aplicar descuento
@@ -1608,7 +1608,7 @@  discard block
 block discarded – undo
1608 1608
             // si el monto no existe se asigna
1609 1609
             if ($datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp']===null) {
1610 1610
                 $datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp'] = round(
1611
-                    $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp']/100
1611
+                    $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp'] / 100
1612 1612
                 );
1613 1613
             }
1614 1614
         }
@@ -1616,7 +1616,7 @@  discard block
 block discarded – undo
1616 1616
         if (isset($datos['Encabezado']['Totales']['ImptoReten']) and is_array($datos['Encabezado']['Totales']['ImptoReten'])) {
1617 1617
             $codigos = array_keys($montos);
1618 1618
             $n_impuestos = count($datos['Encabezado']['Totales']['ImptoReten']);
1619
-            for ($i=0; $i<$n_impuestos; $i++) {
1619
+            for ($i = 0; $i<$n_impuestos; $i++) {
1620 1620
                 if (!in_array($datos['Encabezado']['Totales']['ImptoReten'][$i]['TipoImp'], $codigos)) {
1621 1621
                     unset($datos['Encabezado']['Totales']['ImptoReten'][$i]);
1622 1622
                 }
@@ -1641,7 +1641,7 @@  discard block
 block discarded – undo
1641 1641
         // valor IndMntNeto = 2 indica que los montosde las líneas on netos en cuyo caso no aplica el cálculo
1642 1642
         // de neto e iva a partir del total y deberá venir informado de otra forma (aun no definido)
1643 1643
         if ($this->esBoleta() and (empty($datos['Encabezado']['IdDoc']['IndMntNeto']) or $datos['Encabezado']['IdDoc']['IndMntNeto']!=2)) {
1644
-            $total = (int)$datos['Encabezado']['Totales']['MntTotal'] - (int)$datos['Encabezado']['Totales']['MntExe'];
1644
+            $total = (int)$datos['Encabezado']['Totales']['MntTotal']-(int)$datos['Encabezado']['Totales']['MntExe'];
1645 1645
             if ($total and (empty($datos['Encabezado']['Totales']['MntNeto']) or empty($datos['Encabezado']['Totales']['IVA']))) {
1646 1646
                 list($datos['Encabezado']['Totales']['MntNeto'], $datos['Encabezado']['Totales']['IVA']) = $this->calcularNetoIVA($total);
1647 1647
             }
@@ -1656,7 +1656,7 @@  discard block
 block discarded – undo
1656 1656
             } else {
1657 1657
                 if (empty($datos['Encabezado']['Totales']['IVA']) and !empty($datos['Encabezado']['Totales']['TasaIVA'])) {
1658 1658
                     $datos['Encabezado']['Totales']['IVA'] = round(
1659
-                        $datos['Encabezado']['Totales']['MntNeto']*($datos['Encabezado']['Totales']['TasaIVA']/100)
1659
+                        $datos['Encabezado']['Totales']['MntNeto'] * ($datos['Encabezado']['Totales']['TasaIVA'] / 100)
1660 1660
                     );
1661 1661
                 }
1662 1662
             }
@@ -1682,7 +1682,7 @@  discard block
 block discarded – undo
1682 1682
                 if (ImpuestosAdicionales::getTipo($ImptoReten['TipoImp'])=='R') {
1683 1683
                     $datos['Encabezado']['Totales']['MntTotal'] -= $ImptoReten['MontoImp'];
1684 1684
                     if ($ImptoReten['MontoImp']!=$datos['Encabezado']['Totales']['IVA']) {
1685
-                        $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA'] - $ImptoReten['MontoImp'];
1685
+                        $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA']-$ImptoReten['MontoImp'];
1686 1686
                     }
1687 1687
                 }
1688 1688
                 // si es adicional se suma al total
@@ -1908,7 +1908,7 @@  discard block
 block discarded – undo
1908 1908
         $SignatureValue = trim(str_replace(["\n", ' ', "\t"], '', $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue));
1909 1909
         $X509Certificate = trim(str_replace(["\n", ' ', "\t"], '', $Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue));
1910 1910
         $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap($X509Certificate, 64, "\n", true)."\n".'-----END CERTIFICATE----- ';
1911
-        $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false;
1911
+        $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false;
1912 1912
         return $valid;
1913 1913
         //return $valid and $DigestValue===base64_encode(sha1($Documento->C14N(), true));
1914 1914
     }
Please login to merge, or discard this patch.
Braces   +48 added lines, -32 removed lines patch added patch discarded remove patch
@@ -203,8 +203,9 @@  discard block
 block discarded – undo
203 203
      */
204 204
     public function getJSON()
205 205
     {
206
-        if (!$this->getDatos())
207
-            return false;
206
+        if (!$this->getDatos()) {
207
+                    return false;
208
+        }
208 209
         return json_encode($this->datos, JSON_PRETTY_PRINT);
209 210
     }
210 211
 
@@ -229,9 +230,10 @@  discard block
 block discarded – undo
229 230
      */
230 231
     private function getTipoGeneral($dte)
231 232
     {
232
-        foreach ($this->tipos as $tipo => $codigos)
233
-            if (in_array($dte, $codigos))
233
+        foreach ($this->tipos as $tipo => $codigos) {
234
+                    if (in_array($dte, $codigos))
234 235
                 return $tipo;
236
+        }
235 237
         \sasco\LibreDTE\Log::write(
236 238
             \sasco\LibreDTE\Estado::DTE_ERROR_TIPO,
237 239
             \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::DTE_ERROR_TIPO, $dte)
@@ -270,10 +272,12 @@  discard block
 block discarded – undo
270 272
     public function getEmisor()
271 273
     {
272 274
         $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Emisor/RUTEmisor')->item(0);
273
-        if ($nodo)
274
-            return $nodo->nodeValue;
275
-        if (!$this->getDatos())
276
-            return false;
275
+        if ($nodo) {
276
+                    return $nodo->nodeValue;
277
+        }
278
+        if (!$this->getDatos()) {
279
+                    return false;
280
+        }
277 281
         return $this->datos['Encabezado']['Emisor']['RUTEmisor'];
278 282
     }
279 283
 
@@ -286,10 +290,12 @@  discard block
 block discarded – undo
286 290
     public function getReceptor()
287 291
     {
288 292
         $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Receptor/RUTRecep')->item(0);
289
-        if ($nodo)
290
-            return $nodo->nodeValue;
291
-        if (!$this->getDatos())
292
-            return false;
293
+        if ($nodo) {
294
+                    return $nodo->nodeValue;
295
+        }
296
+        if (!$this->getDatos()) {
297
+                    return false;
298
+        }
293 299
         return $this->datos['Encabezado']['Receptor']['RUTRecep'];
294 300
     }
295 301
 
@@ -302,10 +308,12 @@  discard block
 block discarded – undo
302 308
     public function getFechaEmision()
303 309
     {
304 310
         $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/IdDoc/FchEmis')->item(0);
305
-        if ($nodo)
306
-            return $nodo->nodeValue;
307
-        if (!$this->getDatos())
308
-            return false;
311
+        if ($nodo) {
312
+                    return $nodo->nodeValue;
313
+        }
314
+        if (!$this->getDatos()) {
315
+                    return false;
316
+        }
309 317
         return $this->datos['Encabezado']['IdDoc']['FchEmis'];
310 318
     }
311 319
 
@@ -318,10 +326,12 @@  discard block
 block discarded – undo
318 326
     public function getMontoTotal()
319 327
     {
320 328
         $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Totales/MntTotal')->item(0);
321
-        if ($nodo)
322
-            return $nodo->nodeValue;
323
-        if (!$this->getDatos())
324
-            return false;
329
+        if ($nodo) {
330
+                    return $nodo->nodeValue;
331
+        }
332
+        if (!$this->getDatos()) {
333
+                    return false;
334
+        }
325 335
         return $this->datos['Encabezado']['Totales']['MntTotal'];
326 336
     }
327 337
 
@@ -334,10 +344,12 @@  discard block
 block discarded – undo
334 344
     public function getMoneda()
335 345
     {
336 346
         $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Totales/TpoMoneda')->item(0);
337
-        if ($nodo)
338
-            return $nodo->nodeValue;
339
-        if (!$this->getDatos())
340
-            return false;
347
+        if ($nodo) {
348
+                    return $nodo->nodeValue;
349
+        }
350
+        if (!$this->getDatos()) {
351
+                    return false;
352
+        }
341 353
         return $this->datos['Encabezado']['Totales']['TpoMoneda'];
342 354
     }
343 355
 
@@ -380,8 +392,9 @@  discard block
 block discarded – undo
380 392
             return false;*/
381 393
         $xml = new \sasco\LibreDTE\XML();
382 394
         $TED = $this->xml->getElementsByTagName('TED')->item(0);
383
-        if (!$TED)
384
-            return '<TED/>';
395
+        if (!$TED) {
396
+                    return '<TED/>';
397
+        }
385 398
         $xml->loadXML($TED->C14N());
386 399
         $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi');
387 400
         $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', '');
@@ -680,8 +693,9 @@  discard block
 block discarded – undo
680 693
         ], $datos);
681 694
         // si existe descuento o recargo global se normalizan
682 695
         if (!empty($datos['DscRcgGlobal'])) {
683
-            if (!isset($datos['DscRcgGlobal'][0]))
684
-                $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']];
696
+            if (!isset($datos['DscRcgGlobal'][0])) {
697
+                            $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']];
698
+            }
685 699
             $NroLinDR = 1;
686 700
             foreach ($datos['DscRcgGlobal'] as &$dr) {
687 701
                 $dr = array_merge([
@@ -1502,8 +1516,9 @@  discard block
 block discarded – undo
1502 1516
     private function normalizar_aplicar_descuentos_recargos(array &$datos)
1503 1517
     {
1504 1518
         if (!empty($datos['DscRcgGlobal'])) {
1505
-            if (!isset($datos['DscRcgGlobal'][0]))
1506
-                $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']];
1519
+            if (!isset($datos['DscRcgGlobal'][0])) {
1520
+                            $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']];
1521
+            }
1507 1522
             foreach ($datos['DscRcgGlobal'] as &$dr) {
1508 1523
                 $dr = array_merge([
1509 1524
                     'NroLinDR' => false,
@@ -1570,8 +1585,9 @@  discard block
 block discarded – undo
1570 1585
         $montos = [];
1571 1586
         foreach ($datos['Detalle'] as &$d) {
1572 1587
             if (!empty($d['CodImpAdic'])) {
1573
-                if (!isset($montos[$d['CodImpAdic']]))
1574
-                    $montos[$d['CodImpAdic']] = 0;
1588
+                if (!isset($montos[$d['CodImpAdic']])) {
1589
+                                    $montos[$d['CodImpAdic']] = 0;
1590
+                }
1575 1591
                 $montos[$d['CodImpAdic']] += $d['MontoItem'];
1576 1592
             }
1577 1593
         }
Please login to merge, or discard this patch.
lib/Sii/Folios.php 1 patch
Spacing   +7 added lines, -7 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
     /**
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
         if (!$fecha_autorizacion) {
270 270
             return false;
271 271
         }
272
-        return date('Y-m-d', strtotime($fecha_autorizacion. ' + 180 days')); // 6 meses = 6 * 30 días
272
+        return date('Y-m-d', strtotime($fecha_autorizacion.' + 180 days')); // 6 meses = 6 * 30 días
273 273
     }
274 274
 
275 275
     /**
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
         $d1 = new \DateTime($this->getFechaAutorizacion());
283 283
         $d2 = new \DateTime(date('Y-m-d'));
284 284
         $diff = $d1->diff($d2);
285
-        $meses = $diff->m + ($diff->y*12);
285
+        $meses = $diff->m+($diff->y * 12);
286 286
         if ($diff->d) {
287 287
             $meses += round($diff->d / 30, 2);
288 288
         }
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
         if (!$this->vence()) {
301 301
             return true;
302 302
         }
303
-        return date('Y-m-d') < $this->getFechaVencimiento();
303
+        return date('Y-m-d')<$this->getFechaVencimiento();
304 304
     }
305 305
 
306 306
     /**
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
     public function getCertificacion()
324 324
     {
325 325
         $idk = $this->getIDK();
326
-        return $idk ?  $idk === 100 : null;
326
+        return $idk ? $idk===100 : null;
327 327
     }
328 328
 
329 329
     /**
Please login to merge, or discard this patch.