@@ -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], $parent); |
|
| 142 | + $this->xml->generate($datos+['TED' => null], $parent); |
|
| 143 | 143 | $this->datos = $datos; |
| 144 | 144 | if ($normalizar and !$this->verificarDatos()) { |
| 145 | 145 | return false; |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); |
| 362 | 362 | $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', ''); |
| 363 | 363 | $TED = $xml->getFlattened('/'); |
| 364 | - return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1']) != 'ISO-8859-1' ? utf8_decode($TED) : $TED; |
|
| 364 | + return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1'])!='ISO-8859-1' ? utf8_decode($TED) : $TED; |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | { |
| 375 | 375 | $datos = $this->getDatos(); |
| 376 | 376 | $idk = !empty($datos['TED']['DD']['CAF']['DA']['IDK']) ? (int)$datos['TED']['DD']['CAF']['DA']['IDK'] : null; |
| 377 | - return $idk ? $idk === 100 : null; |
|
| 377 | + return $idk ? $idk===100 : null; |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | /** |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | { |
| 509 | 509 | $this->getDatos(); |
| 510 | 510 | // generar resumen |
| 511 | - $resumen = [ |
|
| 511 | + $resumen = [ |
|
| 512 | 512 | 'TpoDoc' => (int)$this->datos['Encabezado']['IdDoc']['TipoDTE'], |
| 513 | 513 | 'NroDoc' => (int)$this->datos['Encabezado']['IdDoc']['Folio'], |
| 514 | 514 | 'TasaImp' => 0, |
@@ -553,17 +553,17 @@ discard block |
||
| 553 | 553 | */ |
| 554 | 554 | private function calcularNetoIVA($total, $tasa = null) |
| 555 | 555 | { |
| 556 | - if ($tasa === 0 or $tasa === false) |
|
| 556 | + if ($tasa===0 or $tasa===false) |
|
| 557 | 557 | return [0, 0]; |
| 558 | - if ($tasa === null) |
|
| 558 | + if ($tasa===null) |
|
| 559 | 559 | $tasa = \sasco\LibreDTE\Sii::getIVA(); |
| 560 | 560 | // WARNING: el IVA obtenido puede no ser el NETO*(TASA/100) |
| 561 | 561 | // se calcula el monto neto y luego se obtiene el IVA haciendo la resta |
| 562 | 562 | // entre el total y el neto, ya que hay casos de borde como: |
| 563 | 563 | // - BRUTO: 680 => NETO: 571 e IVA: 108 => TOTAL: 679 |
| 564 | 564 | // - BRUTO: 86710 => NETO: 72866 e IVA: 13845 => TOTAL: 86711 |
| 565 | - $neto = round($total / (1+($tasa/100))); |
|
| 566 | - $iva = $total - $neto; |
|
| 565 | + $neto = round($total / (1+($tasa / 100))); |
|
| 566 | + $iva = $total-$neto; |
|
| 567 | 567 | return [$neto, $iva]; |
| 568 | 568 | } |
| 569 | 569 | |
@@ -1309,12 +1309,12 @@ discard block |
||
| 1309 | 1309 | ); |
| 1310 | 1310 | // aplicar descuento |
| 1311 | 1311 | if ($d['DescuentoPct']) { |
| 1312 | - $d['DescuentoMonto'] = round($d['MontoItem'] * (int)$d['DescuentoPct']/100); |
|
| 1312 | + $d['DescuentoMonto'] = round($d['MontoItem'] * (int)$d['DescuentoPct'] / 100); |
|
| 1313 | 1313 | } |
| 1314 | 1314 | $d['MontoItem'] -= $d['DescuentoMonto']; |
| 1315 | 1315 | // aplicar recargo |
| 1316 | 1316 | if ($d['RecargoPct']) { |
| 1317 | - $d['RecargoMonto'] = round($d['MontoItem'] * (int)$d['RecargoPct']/100); |
|
| 1317 | + $d['RecargoMonto'] = round($d['MontoItem'] * (int)$d['RecargoPct'] / 100); |
|
| 1318 | 1318 | } |
| 1319 | 1319 | $d['MontoItem'] += $d['RecargoMonto']; |
| 1320 | 1320 | // aproximar monto del item |
@@ -1400,7 +1400,7 @@ discard block |
||
| 1400 | 1400 | } |
| 1401 | 1401 | $valor = |
| 1402 | 1402 | $dr['TpoValor']=='%' |
| 1403 | - ? $this->round(($dr['ValorDR']/100)*$datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
| 1403 | + ? $this->round(($dr['ValorDR'] / 100) * $datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
| 1404 | 1404 | : $dr['ValorDR'] |
| 1405 | 1405 | ; |
| 1406 | 1406 | // aplicar descuento |
@@ -1473,7 +1473,7 @@ discard block |
||
| 1473 | 1473 | // si el monto no existe se asigna |
| 1474 | 1474 | if ($datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp']===null) { |
| 1475 | 1475 | $datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp'] = round( |
| 1476 | - $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp']/100 |
|
| 1476 | + $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp'] / 100 |
|
| 1477 | 1477 | ); |
| 1478 | 1478 | } |
| 1479 | 1479 | } |
@@ -1481,7 +1481,7 @@ discard block |
||
| 1481 | 1481 | if (isset($datos['Encabezado']['Totales']['ImptoReten']) and is_array($datos['Encabezado']['Totales']['ImptoReten'])) { |
| 1482 | 1482 | $codigos = array_keys($montos); |
| 1483 | 1483 | $n_impuestos = count($datos['Encabezado']['Totales']['ImptoReten']); |
| 1484 | - for ($i=0; $i<$n_impuestos; $i++) { |
|
| 1484 | + for ($i = 0; $i<$n_impuestos; $i++) { |
|
| 1485 | 1485 | if (!in_array($datos['Encabezado']['Totales']['ImptoReten'][$i]['TipoImp'], $codigos)) { |
| 1486 | 1486 | unset($datos['Encabezado']['Totales']['ImptoReten'][$i]); |
| 1487 | 1487 | } |
@@ -1509,7 +1509,7 @@ discard block |
||
| 1509 | 1509 | } else { |
| 1510 | 1510 | if (empty($datos['Encabezado']['Totales']['IVA']) and !empty($datos['Encabezado']['Totales']['TasaIVA'])) { |
| 1511 | 1511 | $datos['Encabezado']['Totales']['IVA'] = round( |
| 1512 | - $datos['Encabezado']['Totales']['MntNeto']*($datos['Encabezado']['Totales']['TasaIVA']/100) |
|
| 1512 | + $datos['Encabezado']['Totales']['MntNeto'] * ($datos['Encabezado']['Totales']['TasaIVA'] / 100) |
|
| 1513 | 1513 | ); |
| 1514 | 1514 | } |
| 1515 | 1515 | } |
@@ -1533,7 +1533,7 @@ discard block |
||
| 1533 | 1533 | if (ImpuestosAdicionales::getTipo($ImptoReten['TipoImp'])=='R') { |
| 1534 | 1534 | $datos['Encabezado']['Totales']['MntTotal'] -= $ImptoReten['MontoImp']; |
| 1535 | 1535 | if ($ImptoReten['MontoImp']!=$datos['Encabezado']['Totales']['IVA']) { |
| 1536 | - $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA'] - $ImptoReten['MontoImp']; |
|
| 1536 | + $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA']-$ImptoReten['MontoImp']; |
|
| 1537 | 1537 | } |
| 1538 | 1538 | } |
| 1539 | 1539 | // si es adicional se suma al total |
@@ -1679,7 +1679,7 @@ discard block |
||
| 1679 | 1679 | $SignatureValue = $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue; |
| 1680 | 1680 | $X509Certificate = $Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue; |
| 1681 | 1681 | $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap(trim($X509Certificate), 64, "\n", true)."\n".'-----END CERTIFICATE----- '; |
| 1682 | - $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false; |
|
| 1682 | + $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false; |
|
| 1683 | 1683 | return $valid; |
| 1684 | 1684 | //return $valid and $DigestValue===base64_encode(sha1($Documento->C14N(), true)); |
| 1685 | 1685 | } |
@@ -57,10 +57,11 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -355,8 +369,9 @@ discard block |
||
| 355 | 369 | return false;*/ |
| 356 | 370 | $xml = new \sasco\LibreDTE\XML(); |
| 357 | 371 | $TED = $this->xml->getElementsByTagName('TED')->item(0); |
| 358 | - if (!$TED) |
|
| 359 | - return '<TED/>'; |
|
| 372 | + if (!$TED) { |
|
| 373 | + return '<TED/>'; |
|
| 374 | + } |
|
| 360 | 375 | $xml->loadXML($TED->C14N()); |
| 361 | 376 | $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); |
| 362 | 377 | $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', ''); |
@@ -553,10 +568,12 @@ discard block |
||
| 553 | 568 | */ |
| 554 | 569 | private function calcularNetoIVA($total, $tasa = null) |
| 555 | 570 | { |
| 556 | - if ($tasa === 0 or $tasa === false) |
|
| 557 | - return [0, 0]; |
|
| 558 | - if ($tasa === null) |
|
| 559 | - $tasa = \sasco\LibreDTE\Sii::getIVA(); |
|
| 571 | + if ($tasa === 0 or $tasa === false) { |
|
| 572 | + return [0, 0]; |
|
| 573 | + } |
|
| 574 | + if ($tasa === null) { |
|
| 575 | + $tasa = \sasco\LibreDTE\Sii::getIVA(); |
|
| 576 | + } |
|
| 560 | 577 | // WARNING: el IVA obtenido puede no ser el NETO*(TASA/100) |
| 561 | 578 | // se calcula el monto neto y luego se obtiene el IVA haciendo la resta |
| 562 | 579 | // entre el total y el neto, ya que hay casos de borde como: |
@@ -665,8 +682,9 @@ discard block |
||
| 665 | 682 | } |
| 666 | 683 | // si existe descuento o recargo global se normalizan |
| 667 | 684 | if (!empty($datos['DscRcgGlobal'])) { |
| 668 | - if (!isset($datos['DscRcgGlobal'][0])) |
|
| 669 | - $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
| 685 | + if (!isset($datos['DscRcgGlobal'][0])) { |
|
| 686 | + $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
| 687 | + } |
|
| 670 | 688 | $NroLinDR = 1; |
| 671 | 689 | foreach ($datos['DscRcgGlobal'] as &$dr) { |
| 672 | 690 | $dr = array_merge([ |
@@ -676,8 +694,9 @@ discard block |
||
| 676 | 694 | } |
| 677 | 695 | // si existe una o más referencias se normalizan |
| 678 | 696 | if (!empty($datos['Referencia'])) { |
| 679 | - if (!isset($datos['Referencia'][0])) |
|
| 680 | - $datos['Referencia'] = [$datos['Referencia']]; |
|
| 697 | + if (!isset($datos['Referencia'][0])) { |
|
| 698 | + $datos['Referencia'] = [$datos['Referencia']]; |
|
| 699 | + } |
|
| 681 | 700 | $NroLinRef = 1; |
| 682 | 701 | foreach ($datos['Referencia'] as &$r) { |
| 683 | 702 | $r = array_merge([ |
@@ -707,8 +726,9 @@ discard block |
||
| 707 | 726 | // normalizar montos de pagos programados |
| 708 | 727 | if (is_array($datos['Encabezado']['IdDoc']['MntPagos'])) { |
| 709 | 728 | $montos = 0; |
| 710 | - if (!isset($datos['Encabezado']['IdDoc']['MntPagos'][0])) |
|
| 711 | - $datos['Encabezado']['IdDoc']['MntPagos'] = [$datos['Encabezado']['IdDoc']['MntPagos']]; |
|
| 729 | + if (!isset($datos['Encabezado']['IdDoc']['MntPagos'][0])) { |
|
| 730 | + $datos['Encabezado']['IdDoc']['MntPagos'] = [$datos['Encabezado']['IdDoc']['MntPagos']]; |
|
| 731 | + } |
|
| 712 | 732 | foreach ($datos['Encabezado']['IdDoc']['MntPagos'] as &$MntPagos) { |
| 713 | 733 | $MntPagos = array_merge([ |
| 714 | 734 | 'FchPago' => null, |
@@ -1240,8 +1260,9 @@ discard block |
||
| 1240 | 1260 | */ |
| 1241 | 1261 | private function normalizar_detalle(array &$datos) |
| 1242 | 1262 | { |
| 1243 | - if (!isset($datos['Detalle'][0])) |
|
| 1244 | - $datos['Detalle'] = [$datos['Detalle']]; |
|
| 1263 | + if (!isset($datos['Detalle'][0])) { |
|
| 1264 | + $datos['Detalle'] = [$datos['Detalle']]; |
|
| 1265 | + } |
|
| 1245 | 1266 | $item = 1; |
| 1246 | 1267 | foreach ($datos['Detalle'] as &$d) { |
| 1247 | 1268 | $d = array_merge([ |
@@ -1300,8 +1321,9 @@ discard block |
||
| 1300 | 1321 | ]; |
| 1301 | 1322 | } |
| 1302 | 1323 | if ($d['PrcItem']) { |
| 1303 | - if (!$d['QtyItem']) |
|
| 1304 | - $d['QtyItem'] = 1; |
|
| 1324 | + if (!$d['QtyItem']) { |
|
| 1325 | + $d['QtyItem'] = 1; |
|
| 1326 | + } |
|
| 1305 | 1327 | if (empty($d['MontoItem'])) { |
| 1306 | 1328 | $d['MontoItem'] = $this->round( |
| 1307 | 1329 | $d['QtyItem'] * $d['PrcItem'], |
@@ -1367,8 +1389,9 @@ discard block |
||
| 1367 | 1389 | private function normalizar_aplicar_descuentos_recargos(array &$datos) |
| 1368 | 1390 | { |
| 1369 | 1391 | if (!empty($datos['DscRcgGlobal'])) { |
| 1370 | - if (!isset($datos['DscRcgGlobal'][0])) |
|
| 1371 | - $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
| 1392 | + if (!isset($datos['DscRcgGlobal'][0])) { |
|
| 1393 | + $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
| 1394 | + } |
|
| 1372 | 1395 | foreach ($datos['DscRcgGlobal'] as &$dr) { |
| 1373 | 1396 | $dr = array_merge([ |
| 1374 | 1397 | 'NroLinDR' => false, |
@@ -1435,8 +1458,9 @@ discard block |
||
| 1435 | 1458 | $montos = []; |
| 1436 | 1459 | foreach ($datos['Detalle'] as &$d) { |
| 1437 | 1460 | if (!empty($d['CodImpAdic'])) { |
| 1438 | - if (!isset($montos[$d['CodImpAdic']])) |
|
| 1439 | - $montos[$d['CodImpAdic']] = 0; |
|
| 1461 | + if (!isset($montos[$d['CodImpAdic']])) { |
|
| 1462 | + $montos[$d['CodImpAdic']] = 0; |
|
| 1463 | + } |
|
| 1440 | 1464 | $montos[$d['CodImpAdic']] += $d['MontoItem']; |
| 1441 | 1465 | } |
| 1442 | 1466 | } |
@@ -1515,10 +1539,12 @@ discard block |
||
| 1515 | 1539 | } |
| 1516 | 1540 | if (empty($datos['Encabezado']['Totales']['MntTotal'])) { |
| 1517 | 1541 | $datos['Encabezado']['Totales']['MntTotal'] = $datos['Encabezado']['Totales']['MntNeto']; |
| 1518 | - if (!empty($datos['Encabezado']['Totales']['IVA'])) |
|
| 1519 | - $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['IVA']; |
|
| 1520 | - if (!empty($datos['Encabezado']['Totales']['MntExe'])) |
|
| 1521 | - $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['MntExe']; |
|
| 1542 | + if (!empty($datos['Encabezado']['Totales']['IVA'])) { |
|
| 1543 | + $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['IVA']; |
|
| 1544 | + } |
|
| 1545 | + if (!empty($datos['Encabezado']['Totales']['MntExe'])) { |
|
| 1546 | + $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['MntExe']; |
|
| 1547 | + } |
|
| 1522 | 1548 | } |
| 1523 | 1549 | } else { |
| 1524 | 1550 | if (!$datos['Encabezado']['Totales']['MntTotal'] and !empty($datos['Encabezado']['Totales']['MntExe'])) { |
@@ -1544,8 +1570,10 @@ discard block |
||
| 1544 | 1570 | } |
| 1545 | 1571 | // si hay impuesto de crédito a constructoras del 65% se descuenta del total |
| 1546 | 1572 | if (!empty($datos['Encabezado']['Totales']['CredEC'])) { |
| 1547 | - if ($datos['Encabezado']['Totales']['CredEC']===true) |
|
| 1548 | - $datos['Encabezado']['Totales']['CredEC'] = round($datos['Encabezado']['Totales']['IVA'] * 0.65); // TODO: mover a constante o método |
|
| 1573 | + if ($datos['Encabezado']['Totales']['CredEC']===true) { |
|
| 1574 | + $datos['Encabezado']['Totales']['CredEC'] = round($datos['Encabezado']['Totales']['IVA'] * 0.65); |
|
| 1575 | + } |
|
| 1576 | + // TODO: mover a constante o método |
|
| 1549 | 1577 | $datos['Encabezado']['Totales']['MntTotal'] -= $datos['Encabezado']['Totales']['CredEC']; |
| 1550 | 1578 | } |
| 1551 | 1579 | } |
@@ -1645,10 +1673,12 @@ discard block |
||
| 1645 | 1673 | /*if (!$this->checkFirma()) |
| 1646 | 1674 | return 1;*/ |
| 1647 | 1675 | if (is_array($datos)) { |
| 1648 | - if (isset($datos['RUTEmisor']) and $this->getEmisor()!=$datos['RUTEmisor']) |
|
| 1649 | - return 2; |
|
| 1650 | - if (isset($datos['RUTRecep']) and $this->getReceptor()!=$datos['RUTRecep']) |
|
| 1651 | - return 3; |
|
| 1676 | + if (isset($datos['RUTEmisor']) and $this->getEmisor()!=$datos['RUTEmisor']) { |
|
| 1677 | + return 2; |
|
| 1678 | + } |
|
| 1679 | + if (isset($datos['RUTRecep']) and $this->getReceptor()!=$datos['RUTRecep']) { |
|
| 1680 | + return 3; |
|
| 1681 | + } |
|
| 1652 | 1682 | } |
| 1653 | 1683 | return 0; |
| 1654 | 1684 | } |
@@ -1662,8 +1692,9 @@ discard block |
||
| 1662 | 1692 | */ |
| 1663 | 1693 | public function checkFirma() |
| 1664 | 1694 | { |
| 1665 | - if (!$this->xml) |
|
| 1666 | - return null; |
|
| 1695 | + if (!$this->xml) { |
|
| 1696 | + return null; |
|
| 1697 | + } |
|
| 1667 | 1698 | // obtener firma |
| 1668 | 1699 | $Signature = $this->xml->documentElement->getElementsByTagName('Signature')->item(0); |
| 1669 | 1700 | // preparar documento a validar |
@@ -1755,12 +1786,14 @@ discard block |
||
| 1755 | 1786 | { |
| 1756 | 1787 | // solicitar token |
| 1757 | 1788 | $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($Firma); |
| 1758 | - if (!$token) |
|
| 1759 | - return false; |
|
| 1789 | + if (!$token) { |
|
| 1790 | + return false; |
|
| 1791 | + } |
|
| 1760 | 1792 | // consultar estado dte |
| 1761 | 1793 | $run = $Firma->getID(); |
| 1762 | - if ($run===false) |
|
| 1763 | - return false; |
|
| 1794 | + if ($run===false) { |
|
| 1795 | + return false; |
|
| 1796 | + } |
|
| 1764 | 1797 | list($RutConsultante, $DvConsultante) = explode('-', $run); |
| 1765 | 1798 | list($RutCompania, $DvCompania) = explode('-', $this->getEmisor()); |
| 1766 | 1799 | list($RutReceptor, $DvReceptor) = explode('-', $this->getReceptor()); |
@@ -1779,8 +1812,9 @@ discard block |
||
| 1779 | 1812 | 'token' => $token, |
| 1780 | 1813 | ]); |
| 1781 | 1814 | // si el estado se pudo recuperar se muestra |
| 1782 | - if ($xml===false) |
|
| 1783 | - return false; |
|
| 1815 | + if ($xml===false) { |
|
| 1816 | + return false; |
|
| 1817 | + } |
|
| 1784 | 1818 | // entregar estado |
| 1785 | 1819 | return (array)$xml->xpath('/SII:RESPUESTA/SII:RESP_HDR')[0]; |
| 1786 | 1820 | } |
@@ -1797,8 +1831,9 @@ discard block |
||
| 1797 | 1831 | { |
| 1798 | 1832 | // solicitar token |
| 1799 | 1833 | $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($Firma); |
| 1800 | - if (!$token) |
|
| 1801 | - return false; |
|
| 1834 | + if (!$token) { |
|
| 1835 | + return false; |
|
| 1836 | + } |
|
| 1802 | 1837 | // consultar estado dte |
| 1803 | 1838 | list($RutEmpresa, $DvEmpresa) = explode('-', $this->getEmisor()); |
| 1804 | 1839 | list($RutReceptor, $DvReceptor) = explode('-', $this->getReceptor()); |
@@ -1816,8 +1851,9 @@ discard block |
||
| 1816 | 1851 | 'token' => $token, |
| 1817 | 1852 | ]); |
| 1818 | 1853 | // si el estado se pudo recuperar se muestra |
| 1819 | - if ($xml===false) |
|
| 1820 | - return false; |
|
| 1854 | + if ($xml===false) { |
|
| 1855 | + return false; |
|
| 1856 | + } |
|
| 1821 | 1857 | // entregar estado |
| 1822 | 1858 | return (array)$xml->xpath('/SII:RESPUESTA/SII:RESP_BODY')[0]; |
| 1823 | 1859 | } |