@@ -145,7 +145,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | |
@@ -1420,12 +1420,12 @@ discard block |
||
1420 | 1420 | ); |
1421 | 1421 | // aplicar descuento |
1422 | 1422 | if ($d['DescuentoPct']) { |
1423 | - $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct']/100); |
|
1423 | + $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct'] / 100); |
|
1424 | 1424 | } |
1425 | 1425 | $d['MontoItem'] -= $d['DescuentoMonto']; |
1426 | 1426 | // aplicar recargo |
1427 | 1427 | if ($d['RecargoPct']) { |
1428 | - $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct']/100); |
|
1428 | + $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct'] / 100); |
|
1429 | 1429 | } |
1430 | 1430 | $d['MontoItem'] += $d['RecargoMonto']; |
1431 | 1431 | // aproximar monto del item |
@@ -1511,7 +1511,7 @@ discard block |
||
1511 | 1511 | } |
1512 | 1512 | $valor = |
1513 | 1513 | $dr['TpoValor']=='%' |
1514 | - ? $this->round(($dr['ValorDR']/100)*$datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
1514 | + ? $this->round(($dr['ValorDR'] / 100) * $datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
1515 | 1515 | : $dr['ValorDR'] |
1516 | 1516 | ; |
1517 | 1517 | // aplicar descuento |
@@ -1584,7 +1584,7 @@ discard block |
||
1584 | 1584 | // si el monto no existe se asigna |
1585 | 1585 | if ($datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp']===null) { |
1586 | 1586 | $datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp'] = round( |
1587 | - $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp']/100 |
|
1587 | + $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp'] / 100 |
|
1588 | 1588 | ); |
1589 | 1589 | } |
1590 | 1590 | } |
@@ -1592,7 +1592,7 @@ discard block |
||
1592 | 1592 | if (isset($datos['Encabezado']['Totales']['ImptoReten']) and is_array($datos['Encabezado']['Totales']['ImptoReten'])) { |
1593 | 1593 | $codigos = array_keys($montos); |
1594 | 1594 | $n_impuestos = count($datos['Encabezado']['Totales']['ImptoReten']); |
1595 | - for ($i=0; $i<$n_impuestos; $i++) { |
|
1595 | + for ($i = 0; $i<$n_impuestos; $i++) { |
|
1596 | 1596 | if (!in_array($datos['Encabezado']['Totales']['ImptoReten'][$i]['TipoImp'], $codigos)) { |
1597 | 1597 | unset($datos['Encabezado']['Totales']['ImptoReten'][$i]); |
1598 | 1598 | } |
@@ -1617,7 +1617,7 @@ discard block |
||
1617 | 1617 | // valor IndMntNeto = 2 indica que los montosde las líneas on netos en cuyo caso no aplica el cálculo |
1618 | 1618 | // de neto e iva a partir del total y deberá venir informado de otra forma (aun no definido) |
1619 | 1619 | if ($this->esBoleta() and (empty($datos['Encabezado']['IdDoc']['IndMntNeto']) or $datos['Encabezado']['IdDoc']['IndMntNeto']!=2)) { |
1620 | - $total = (int)$datos['Encabezado']['Totales']['MntTotal'] - (int)$datos['Encabezado']['Totales']['MntExe']; |
|
1620 | + $total = (int)$datos['Encabezado']['Totales']['MntTotal']-(int)$datos['Encabezado']['Totales']['MntExe']; |
|
1621 | 1621 | if ($total and (empty($datos['Encabezado']['Totales']['MntNeto']) or empty($datos['Encabezado']['Totales']['IVA']))) { |
1622 | 1622 | list($datos['Encabezado']['Totales']['MntNeto'], $datos['Encabezado']['Totales']['IVA']) = $this->calcularNetoIVA($total); |
1623 | 1623 | } |
@@ -1632,7 +1632,7 @@ discard block |
||
1632 | 1632 | } else { |
1633 | 1633 | if (empty($datos['Encabezado']['Totales']['IVA']) and !empty($datos['Encabezado']['Totales']['TasaIVA'])) { |
1634 | 1634 | $datos['Encabezado']['Totales']['IVA'] = round( |
1635 | - $datos['Encabezado']['Totales']['MntNeto']*($datos['Encabezado']['Totales']['TasaIVA']/100) |
|
1635 | + $datos['Encabezado']['Totales']['MntNeto'] * ($datos['Encabezado']['Totales']['TasaIVA'] / 100) |
|
1636 | 1636 | ); |
1637 | 1637 | } |
1638 | 1638 | } |
@@ -1658,7 +1658,7 @@ discard block |
||
1658 | 1658 | if (ImpuestosAdicionales::getTipo($ImptoReten['TipoImp'])=='R') { |
1659 | 1659 | $datos['Encabezado']['Totales']['MntTotal'] -= $ImptoReten['MontoImp']; |
1660 | 1660 | if ($ImptoReten['MontoImp']!=$datos['Encabezado']['Totales']['IVA']) { |
1661 | - $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA'] - $ImptoReten['MontoImp']; |
|
1661 | + $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA']-$ImptoReten['MontoImp']; |
|
1662 | 1662 | } |
1663 | 1663 | } |
1664 | 1664 | // si es adicional se suma al total |
@@ -1884,7 +1884,7 @@ discard block |
||
1884 | 1884 | $SignatureValue = trim(str_replace(["\n", ' ', "\t"], '', $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue)); |
1885 | 1885 | $X509Certificate = trim(str_replace(["\n", ' ', "\t"], '', $Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue)); |
1886 | 1886 | $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap($X509Certificate, 64, "\n", true)."\n".'-----END CERTIFICATE----- '; |
1887 | - $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false; |
|
1887 | + $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false; |
|
1888 | 1888 | return $valid; |
1889 | 1889 | //return $valid and $DigestValue===base64_encode(sha1($Documento->C14N(), true)); |
1890 | 1890 | } |
@@ -203,8 +203,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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([ |
@@ -1348,8 +1362,9 @@ discard block |
||
1348 | 1362 | */ |
1349 | 1363 | private function normalizar_detalle(array &$datos) |
1350 | 1364 | { |
1351 | - if (!isset($datos['Detalle'][0])) |
|
1352 | - $datos['Detalle'] = [$datos['Detalle']]; |
|
1365 | + if (!isset($datos['Detalle'][0])) { |
|
1366 | + $datos['Detalle'] = [$datos['Detalle']]; |
|
1367 | + } |
|
1353 | 1368 | $item = 1; |
1354 | 1369 | foreach ($datos['Detalle'] as &$d) { |
1355 | 1370 | $d = array_merge([ |
@@ -1411,8 +1426,9 @@ discard block |
||
1411 | 1426 | ]; |
1412 | 1427 | } |
1413 | 1428 | if ($d['PrcItem']) { |
1414 | - if (!$d['QtyItem']) |
|
1415 | - $d['QtyItem'] = 1; |
|
1429 | + if (!$d['QtyItem']) { |
|
1430 | + $d['QtyItem'] = 1; |
|
1431 | + } |
|
1416 | 1432 | if (empty($d['MontoItem'])) { |
1417 | 1433 | $d['MontoItem'] = $this->round( |
1418 | 1434 | (float)$d['QtyItem'] * (float)$d['PrcItem'], |
@@ -1478,8 +1494,9 @@ discard block |
||
1478 | 1494 | private function normalizar_aplicar_descuentos_recargos(array &$datos) |
1479 | 1495 | { |
1480 | 1496 | if (!empty($datos['DscRcgGlobal'])) { |
1481 | - if (!isset($datos['DscRcgGlobal'][0])) |
|
1482 | - $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
1497 | + if (!isset($datos['DscRcgGlobal'][0])) { |
|
1498 | + $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
1499 | + } |
|
1483 | 1500 | foreach ($datos['DscRcgGlobal'] as &$dr) { |
1484 | 1501 | $dr = array_merge([ |
1485 | 1502 | 'NroLinDR' => false, |
@@ -1546,8 +1563,9 @@ discard block |
||
1546 | 1563 | $montos = []; |
1547 | 1564 | foreach ($datos['Detalle'] as &$d) { |
1548 | 1565 | if (!empty($d['CodImpAdic'])) { |
1549 | - if (!isset($montos[$d['CodImpAdic']])) |
|
1550 | - $montos[$d['CodImpAdic']] = 0; |
|
1566 | + if (!isset($montos[$d['CodImpAdic']])) { |
|
1567 | + $montos[$d['CodImpAdic']] = 0; |
|
1568 | + } |
|
1551 | 1569 | $montos[$d['CodImpAdic']] += $d['MontoItem']; |
1552 | 1570 | } |
1553 | 1571 | } |