@@ -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 (!$this->verificarDatos()) |
145 | 145 | return false; |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); |
361 | 361 | $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', ''); |
362 | 362 | $TED = $xml->getFlattened('/'); |
363 | - return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1']) != 'ISO-8859-1' ? utf8_decode($TED) : $TED; |
|
363 | + return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1'])!='ISO-8859-1' ? utf8_decode($TED) : $TED; |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | { |
374 | 374 | $datos = $this->getDatos(); |
375 | 375 | $idk = !empty($datos['TED']['DD']['CAF']['DA']['IDK']) ? (int)$datos['TED']['DD']['CAF']['DA']['IDK'] : null; |
376 | - return $idk ? $idk === 100 : null; |
|
376 | + return $idk ? $idk===100 : null; |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | { |
508 | 508 | $this->getDatos(); |
509 | 509 | // generar resumen |
510 | - $resumen = [ |
|
510 | + $resumen = [ |
|
511 | 511 | 'TpoDoc' => (int)$this->datos['Encabezado']['IdDoc']['TipoDTE'], |
512 | 512 | 'NroDoc' => (int)$this->datos['Encabezado']['IdDoc']['Folio'], |
513 | 513 | 'TasaImp' => 0, |
@@ -552,17 +552,17 @@ discard block |
||
552 | 552 | */ |
553 | 553 | private function calcularNetoIVA($total, $tasa = null) |
554 | 554 | { |
555 | - if ($tasa === 0 or $tasa === false) |
|
555 | + if ($tasa===0 or $tasa===false) |
|
556 | 556 | return [0, 0]; |
557 | - if ($tasa === null) |
|
557 | + if ($tasa===null) |
|
558 | 558 | $tasa = \sasco\LibreDTE\Sii::getIVA(); |
559 | 559 | // WARNING: el IVA obtenido puede no ser el NETO*(TASA/100) |
560 | 560 | // se calcula el monto neto y luego se obtiene el IVA haciendo la resta |
561 | 561 | // entre el total y el neto, ya que hay casos de borde como: |
562 | 562 | // - BRUTO: 680 => NETO: 571 e IVA: 108 => TOTAL: 679 |
563 | 563 | // - BRUTO: 86710 => NETO: 72866 e IVA: 13845 => TOTAL: 86711 |
564 | - $neto = round($total / (1+($tasa/100))); |
|
565 | - $iva = $total - $neto; |
|
564 | + $neto = round($total / (1+($tasa / 100))); |
|
565 | + $iva = $total-$neto; |
|
566 | 566 | return [$neto, $iva]; |
567 | 567 | } |
568 | 568 | |
@@ -1308,12 +1308,12 @@ discard block |
||
1308 | 1308 | ); |
1309 | 1309 | // aplicar descuento |
1310 | 1310 | if ($d['DescuentoPct']) { |
1311 | - $d['DescuentoMonto'] = round($d['MontoItem'] * (int)$d['DescuentoPct']/100); |
|
1311 | + $d['DescuentoMonto'] = round($d['MontoItem'] * (int)$d['DescuentoPct'] / 100); |
|
1312 | 1312 | } |
1313 | 1313 | $d['MontoItem'] -= $d['DescuentoMonto']; |
1314 | 1314 | // aplicar recargo |
1315 | 1315 | if ($d['RecargoPct']) { |
1316 | - $d['RecargoMonto'] = round($d['MontoItem'] * (int)$d['RecargoPct']/100); |
|
1316 | + $d['RecargoMonto'] = round($d['MontoItem'] * (int)$d['RecargoPct'] / 100); |
|
1317 | 1317 | } |
1318 | 1318 | $d['MontoItem'] += $d['RecargoMonto']; |
1319 | 1319 | // aproximar monto del item |
@@ -1399,7 +1399,7 @@ discard block |
||
1399 | 1399 | } |
1400 | 1400 | $valor = |
1401 | 1401 | $dr['TpoValor']=='%' |
1402 | - ? $this->round(($dr['ValorDR']/100)*$datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
1402 | + ? $this->round(($dr['ValorDR'] / 100) * $datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
1403 | 1403 | : $dr['ValorDR'] |
1404 | 1404 | ; |
1405 | 1405 | // aplicar descuento |
@@ -1472,7 +1472,7 @@ discard block |
||
1472 | 1472 | // si el monto no existe se asigna |
1473 | 1473 | if ($datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp']===null) { |
1474 | 1474 | $datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp'] = round( |
1475 | - $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp']/100 |
|
1475 | + $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp'] / 100 |
|
1476 | 1476 | ); |
1477 | 1477 | } |
1478 | 1478 | } |
@@ -1480,7 +1480,7 @@ discard block |
||
1480 | 1480 | if (isset($datos['Encabezado']['Totales']['ImptoReten']) and is_array($datos['Encabezado']['Totales']['ImptoReten'])) { |
1481 | 1481 | $codigos = array_keys($montos); |
1482 | 1482 | $n_impuestos = count($datos['Encabezado']['Totales']['ImptoReten']); |
1483 | - for ($i=0; $i<$n_impuestos; $i++) { |
|
1483 | + for ($i = 0; $i<$n_impuestos; $i++) { |
|
1484 | 1484 | if (!in_array($datos['Encabezado']['Totales']['ImptoReten'][$i]['TipoImp'], $codigos)) { |
1485 | 1485 | unset($datos['Encabezado']['Totales']['ImptoReten'][$i]); |
1486 | 1486 | } |
@@ -1508,7 +1508,7 @@ discard block |
||
1508 | 1508 | } else { |
1509 | 1509 | if (empty($datos['Encabezado']['Totales']['IVA']) and !empty($datos['Encabezado']['Totales']['TasaIVA'])) { |
1510 | 1510 | $datos['Encabezado']['Totales']['IVA'] = round( |
1511 | - $datos['Encabezado']['Totales']['MntNeto']*($datos['Encabezado']['Totales']['TasaIVA']/100) |
|
1511 | + $datos['Encabezado']['Totales']['MntNeto'] * ($datos['Encabezado']['Totales']['TasaIVA'] / 100) |
|
1512 | 1512 | ); |
1513 | 1513 | } |
1514 | 1514 | } |
@@ -1532,7 +1532,7 @@ discard block |
||
1532 | 1532 | if (ImpuestosAdicionales::getTipo($ImptoReten['TipoImp'])=='R') { |
1533 | 1533 | $datos['Encabezado']['Totales']['MntTotal'] -= $ImptoReten['MontoImp']; |
1534 | 1534 | if ($ImptoReten['MontoImp']!=$datos['Encabezado']['Totales']['IVA']) { |
1535 | - $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA'] - $ImptoReten['MontoImp']; |
|
1535 | + $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA']-$ImptoReten['MontoImp']; |
|
1536 | 1536 | } |
1537 | 1537 | } |
1538 | 1538 | // si es adicional se suma al total |
@@ -1678,7 +1678,7 @@ discard block |
||
1678 | 1678 | $SignatureValue = $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue; |
1679 | 1679 | $X509Certificate = $Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue; |
1680 | 1680 | $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap(trim($X509Certificate), 64, "\n", true)."\n".'-----END CERTIFICATE----- '; |
1681 | - $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false; |
|
1681 | + $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false; |
|
1682 | 1682 | return $valid; |
1683 | 1683 | //return $valid and $DigestValue===base64_encode(sha1($Documento->C14N(), true)); |
1684 | 1684 | } |
@@ -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); |
@@ -141,8 +143,9 @@ discard block |
||
141 | 143 | $parent = $this->xml->getElementsByTagName($this->tipo_general)->item(0); |
142 | 144 | $this->xml->generate($datos + ['TED' => null], $parent); |
143 | 145 | $this->datos = $datos; |
144 | - if (!$this->verificarDatos()) |
|
145 | - return false; |
|
146 | + if (!$this->verificarDatos()) { |
|
147 | + return false; |
|
148 | + } |
|
146 | 149 | return $this->schemaValidate(); |
147 | 150 | } |
148 | 151 | return false; |
@@ -198,8 +201,9 @@ discard block |
||
198 | 201 | */ |
199 | 202 | public function getJSON() |
200 | 203 | { |
201 | - if (!$this->getDatos()) |
|
202 | - return false; |
|
204 | + if (!$this->getDatos()) { |
|
205 | + return false; |
|
206 | + } |
|
203 | 207 | return json_encode($this->datos, JSON_PRETTY_PRINT); |
204 | 208 | } |
205 | 209 | |
@@ -224,9 +228,10 @@ discard block |
||
224 | 228 | */ |
225 | 229 | private function getTipoGeneral($dte) |
226 | 230 | { |
227 | - foreach ($this->tipos as $tipo => $codigos) |
|
228 | - if (in_array($dte, $codigos)) |
|
231 | + foreach ($this->tipos as $tipo => $codigos) { |
|
232 | + if (in_array($dte, $codigos)) |
|
229 | 233 | return $tipo; |
234 | + } |
|
230 | 235 | \sasco\LibreDTE\Log::write( |
231 | 236 | \sasco\LibreDTE\Estado::DTE_ERROR_TIPO, |
232 | 237 | \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::DTE_ERROR_TIPO, $dte) |
@@ -265,10 +270,12 @@ discard block |
||
265 | 270 | public function getEmisor() |
266 | 271 | { |
267 | 272 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Emisor/RUTEmisor')->item(0); |
268 | - if ($nodo) |
|
269 | - return $nodo->nodeValue; |
|
270 | - if (!$this->getDatos()) |
|
271 | - return false; |
|
273 | + if ($nodo) { |
|
274 | + return $nodo->nodeValue; |
|
275 | + } |
|
276 | + if (!$this->getDatos()) { |
|
277 | + return false; |
|
278 | + } |
|
272 | 279 | return $this->datos['Encabezado']['Emisor']['RUTEmisor']; |
273 | 280 | } |
274 | 281 | |
@@ -281,10 +288,12 @@ discard block |
||
281 | 288 | public function getReceptor() |
282 | 289 | { |
283 | 290 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Receptor/RUTRecep')->item(0); |
284 | - if ($nodo) |
|
285 | - return $nodo->nodeValue; |
|
286 | - if (!$this->getDatos()) |
|
287 | - return false; |
|
291 | + if ($nodo) { |
|
292 | + return $nodo->nodeValue; |
|
293 | + } |
|
294 | + if (!$this->getDatos()) { |
|
295 | + return false; |
|
296 | + } |
|
288 | 297 | return $this->datos['Encabezado']['Receptor']['RUTRecep']; |
289 | 298 | } |
290 | 299 | |
@@ -297,10 +306,12 @@ discard block |
||
297 | 306 | public function getFechaEmision() |
298 | 307 | { |
299 | 308 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/IdDoc/FchEmis')->item(0); |
300 | - if ($nodo) |
|
301 | - return $nodo->nodeValue; |
|
302 | - if (!$this->getDatos()) |
|
303 | - return false; |
|
309 | + if ($nodo) { |
|
310 | + return $nodo->nodeValue; |
|
311 | + } |
|
312 | + if (!$this->getDatos()) { |
|
313 | + return false; |
|
314 | + } |
|
304 | 315 | return $this->datos['Encabezado']['IdDoc']['FchEmis']; |
305 | 316 | } |
306 | 317 | |
@@ -313,10 +324,12 @@ discard block |
||
313 | 324 | public function getMontoTotal() |
314 | 325 | { |
315 | 326 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Totales/MntTotal')->item(0); |
316 | - if ($nodo) |
|
317 | - return $nodo->nodeValue; |
|
318 | - if (!$this->getDatos()) |
|
319 | - return false; |
|
327 | + if ($nodo) { |
|
328 | + return $nodo->nodeValue; |
|
329 | + } |
|
330 | + if (!$this->getDatos()) { |
|
331 | + return false; |
|
332 | + } |
|
320 | 333 | return $this->datos['Encabezado']['Totales']['MntTotal']; |
321 | 334 | } |
322 | 335 | |
@@ -329,10 +342,12 @@ discard block |
||
329 | 342 | public function getMoneda() |
330 | 343 | { |
331 | 344 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Totales/TpoMoneda')->item(0); |
332 | - if ($nodo) |
|
333 | - return $nodo->nodeValue; |
|
334 | - if (!$this->getDatos()) |
|
335 | - return false; |
|
345 | + if ($nodo) { |
|
346 | + return $nodo->nodeValue; |
|
347 | + } |
|
348 | + if (!$this->getDatos()) { |
|
349 | + return false; |
|
350 | + } |
|
336 | 351 | return $this->datos['Encabezado']['Totales']['TpoMoneda']; |
337 | 352 | } |
338 | 353 | |
@@ -354,8 +369,9 @@ discard block |
||
354 | 369 | return false;*/ |
355 | 370 | $xml = new \sasco\LibreDTE\XML(); |
356 | 371 | $TED = $this->xml->getElementsByTagName('TED')->item(0); |
357 | - if (!$TED) |
|
358 | - return '<TED/>'; |
|
372 | + if (!$TED) { |
|
373 | + return '<TED/>'; |
|
374 | + } |
|
359 | 375 | $xml->loadXML($TED->C14N()); |
360 | 376 | $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); |
361 | 377 | $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', ''); |
@@ -552,10 +568,12 @@ discard block |
||
552 | 568 | */ |
553 | 569 | private function calcularNetoIVA($total, $tasa = null) |
554 | 570 | { |
555 | - if ($tasa === 0 or $tasa === false) |
|
556 | - return [0, 0]; |
|
557 | - if ($tasa === null) |
|
558 | - $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 | + } |
|
559 | 577 | // WARNING: el IVA obtenido puede no ser el NETO*(TASA/100) |
560 | 578 | // se calcula el monto neto y luego se obtiene el IVA haciendo la resta |
561 | 579 | // entre el total y el neto, ya que hay casos de borde como: |
@@ -664,8 +682,9 @@ discard block |
||
664 | 682 | } |
665 | 683 | // si existe descuento o recargo global se normalizan |
666 | 684 | if (!empty($datos['DscRcgGlobal'])) { |
667 | - if (!isset($datos['DscRcgGlobal'][0])) |
|
668 | - $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
685 | + if (!isset($datos['DscRcgGlobal'][0])) { |
|
686 | + $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
687 | + } |
|
669 | 688 | $NroLinDR = 1; |
670 | 689 | foreach ($datos['DscRcgGlobal'] as &$dr) { |
671 | 690 | $dr = array_merge([ |
@@ -675,8 +694,9 @@ discard block |
||
675 | 694 | } |
676 | 695 | // si existe una o más referencias se normalizan |
677 | 696 | if (!empty($datos['Referencia'])) { |
678 | - if (!isset($datos['Referencia'][0])) |
|
679 | - $datos['Referencia'] = [$datos['Referencia']]; |
|
697 | + if (!isset($datos['Referencia'][0])) { |
|
698 | + $datos['Referencia'] = [$datos['Referencia']]; |
|
699 | + } |
|
680 | 700 | $NroLinRef = 1; |
681 | 701 | foreach ($datos['Referencia'] as &$r) { |
682 | 702 | $r = array_merge([ |
@@ -706,8 +726,9 @@ discard block |
||
706 | 726 | // normalizar montos de pagos programados |
707 | 727 | if (is_array($datos['Encabezado']['IdDoc']['MntPagos'])) { |
708 | 728 | $montos = 0; |
709 | - if (!isset($datos['Encabezado']['IdDoc']['MntPagos'][0])) |
|
710 | - $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 | + } |
|
711 | 732 | foreach ($datos['Encabezado']['IdDoc']['MntPagos'] as &$MntPagos) { |
712 | 733 | $MntPagos = array_merge([ |
713 | 734 | 'FchPago' => null, |
@@ -1239,8 +1260,9 @@ discard block |
||
1239 | 1260 | */ |
1240 | 1261 | private function normalizar_detalle(array &$datos) |
1241 | 1262 | { |
1242 | - if (!isset($datos['Detalle'][0])) |
|
1243 | - $datos['Detalle'] = [$datos['Detalle']]; |
|
1263 | + if (!isset($datos['Detalle'][0])) { |
|
1264 | + $datos['Detalle'] = [$datos['Detalle']]; |
|
1265 | + } |
|
1244 | 1266 | $item = 1; |
1245 | 1267 | foreach ($datos['Detalle'] as &$d) { |
1246 | 1268 | $d = array_merge([ |
@@ -1299,8 +1321,9 @@ discard block |
||
1299 | 1321 | ]; |
1300 | 1322 | } |
1301 | 1323 | if ($d['PrcItem']) { |
1302 | - if (!$d['QtyItem']) |
|
1303 | - $d['QtyItem'] = 1; |
|
1324 | + if (!$d['QtyItem']) { |
|
1325 | + $d['QtyItem'] = 1; |
|
1326 | + } |
|
1304 | 1327 | if (empty($d['MontoItem'])) { |
1305 | 1328 | $d['MontoItem'] = $this->round( |
1306 | 1329 | $d['QtyItem'] * $d['PrcItem'], |
@@ -1366,8 +1389,9 @@ discard block |
||
1366 | 1389 | private function normalizar_aplicar_descuentos_recargos(array &$datos) |
1367 | 1390 | { |
1368 | 1391 | if (!empty($datos['DscRcgGlobal'])) { |
1369 | - if (!isset($datos['DscRcgGlobal'][0])) |
|
1370 | - $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
1392 | + if (!isset($datos['DscRcgGlobal'][0])) { |
|
1393 | + $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
1394 | + } |
|
1371 | 1395 | foreach ($datos['DscRcgGlobal'] as &$dr) { |
1372 | 1396 | $dr = array_merge([ |
1373 | 1397 | 'NroLinDR' => false, |
@@ -1434,8 +1458,9 @@ discard block |
||
1434 | 1458 | $montos = []; |
1435 | 1459 | foreach ($datos['Detalle'] as &$d) { |
1436 | 1460 | if (!empty($d['CodImpAdic'])) { |
1437 | - if (!isset($montos[$d['CodImpAdic']])) |
|
1438 | - $montos[$d['CodImpAdic']] = 0; |
|
1461 | + if (!isset($montos[$d['CodImpAdic']])) { |
|
1462 | + $montos[$d['CodImpAdic']] = 0; |
|
1463 | + } |
|
1439 | 1464 | $montos[$d['CodImpAdic']] += $d['MontoItem']; |
1440 | 1465 | } |
1441 | 1466 | } |
@@ -1514,10 +1539,12 @@ discard block |
||
1514 | 1539 | } |
1515 | 1540 | if (empty($datos['Encabezado']['Totales']['MntTotal'])) { |
1516 | 1541 | $datos['Encabezado']['Totales']['MntTotal'] = $datos['Encabezado']['Totales']['MntNeto']; |
1517 | - if (!empty($datos['Encabezado']['Totales']['IVA'])) |
|
1518 | - $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['IVA']; |
|
1519 | - if (!empty($datos['Encabezado']['Totales']['MntExe'])) |
|
1520 | - $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 | + } |
|
1521 | 1548 | } |
1522 | 1549 | } else { |
1523 | 1550 | if (!$datos['Encabezado']['Totales']['MntTotal'] and !empty($datos['Encabezado']['Totales']['MntExe'])) { |
@@ -1543,8 +1570,10 @@ discard block |
||
1543 | 1570 | } |
1544 | 1571 | // si hay impuesto de crédito a constructoras del 65% se descuenta del total |
1545 | 1572 | if (!empty($datos['Encabezado']['Totales']['CredEC'])) { |
1546 | - if ($datos['Encabezado']['Totales']['CredEC']===true) |
|
1547 | - $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 |
|
1548 | 1577 | $datos['Encabezado']['Totales']['MntTotal'] -= $datos['Encabezado']['Totales']['CredEC']; |
1549 | 1578 | } |
1550 | 1579 | } |
@@ -1644,10 +1673,12 @@ discard block |
||
1644 | 1673 | /*if (!$this->checkFirma()) |
1645 | 1674 | return 1;*/ |
1646 | 1675 | if (is_array($datos)) { |
1647 | - if (isset($datos['RUTEmisor']) and $this->getEmisor()!=$datos['RUTEmisor']) |
|
1648 | - return 2; |
|
1649 | - if (isset($datos['RUTRecep']) and $this->getReceptor()!=$datos['RUTRecep']) |
|
1650 | - 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 | + } |
|
1651 | 1682 | } |
1652 | 1683 | return 0; |
1653 | 1684 | } |
@@ -1661,8 +1692,9 @@ discard block |
||
1661 | 1692 | */ |
1662 | 1693 | public function checkFirma() |
1663 | 1694 | { |
1664 | - if (!$this->xml) |
|
1665 | - return null; |
|
1695 | + if (!$this->xml) { |
|
1696 | + return null; |
|
1697 | + } |
|
1666 | 1698 | // obtener firma |
1667 | 1699 | $Signature = $this->xml->documentElement->getElementsByTagName('Signature')->item(0); |
1668 | 1700 | // preparar documento a validar |
@@ -1754,12 +1786,14 @@ discard block |
||
1754 | 1786 | { |
1755 | 1787 | // solicitar token |
1756 | 1788 | $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($Firma); |
1757 | - if (!$token) |
|
1758 | - return false; |
|
1789 | + if (!$token) { |
|
1790 | + return false; |
|
1791 | + } |
|
1759 | 1792 | // consultar estado dte |
1760 | 1793 | $run = $Firma->getID(); |
1761 | - if ($run===false) |
|
1762 | - return false; |
|
1794 | + if ($run===false) { |
|
1795 | + return false; |
|
1796 | + } |
|
1763 | 1797 | list($RutConsultante, $DvConsultante) = explode('-', $run); |
1764 | 1798 | list($RutCompania, $DvCompania) = explode('-', $this->getEmisor()); |
1765 | 1799 | list($RutReceptor, $DvReceptor) = explode('-', $this->getReceptor()); |
@@ -1778,8 +1812,9 @@ discard block |
||
1778 | 1812 | 'token' => $token, |
1779 | 1813 | ]); |
1780 | 1814 | // si el estado se pudo recuperar se muestra |
1781 | - if ($xml===false) |
|
1782 | - return false; |
|
1815 | + if ($xml===false) { |
|
1816 | + return false; |
|
1817 | + } |
|
1783 | 1818 | // entregar estado |
1784 | 1819 | return (array)$xml->xpath('/SII:RESPUESTA/SII:RESP_HDR')[0]; |
1785 | 1820 | } |
@@ -1796,8 +1831,9 @@ discard block |
||
1796 | 1831 | { |
1797 | 1832 | // solicitar token |
1798 | 1833 | $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($Firma); |
1799 | - if (!$token) |
|
1800 | - return false; |
|
1834 | + if (!$token) { |
|
1835 | + return false; |
|
1836 | + } |
|
1801 | 1837 | // consultar estado dte |
1802 | 1838 | list($RutEmpresa, $DvEmpresa) = explode('-', $this->getEmisor()); |
1803 | 1839 | list($RutReceptor, $DvReceptor) = explode('-', $this->getReceptor()); |
@@ -1815,8 +1851,9 @@ discard block |
||
1815 | 1851 | 'token' => $token, |
1816 | 1852 | ]); |
1817 | 1853 | // si el estado se pudo recuperar se muestra |
1818 | - if ($xml===false) |
|
1819 | - return false; |
|
1854 | + if ($xml===false) { |
|
1855 | + return false; |
|
1856 | + } |
|
1820 | 1857 | // entregar estado |
1821 | 1858 | return (array)$xml->xpath('/SII:RESPUESTA/SII:RESP_BODY')[0]; |
1822 | 1859 | } |