Completed
Push — master ( 427926...362d6c )
by Esteban De La Fuente
01:42
created
lib/Sii/Dte.php 1 patch
Braces   +62 added lines, -42 removed lines patch added patch discarded remove patch
@@ -57,10 +57,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.