@@ -259,7 +259,7 @@ discard block |
||
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 |
||
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); |
@@ -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([ |
@@ -1502,8 +1516,9 @@ discard block |
||
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 |
||
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 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | ] |
154 | 154 | ]); |
155 | 155 | $parent = $this->xml->getElementsByTagName($this->tipo_general)->item(0); |
156 | - $this->xml->generate($datos + ['TED' => null], null, $parent); |
|
156 | + $this->xml->generate($datos+['TED' => null], null, $parent); |
|
157 | 157 | $this->datos = $datos; |
158 | 158 | // validar datos |
159 | 159 | $this->verificar_datos(); |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); |
396 | 396 | $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', ''); |
397 | 397 | $TED = $xml->getFlattened('/'); |
398 | - return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1']) != 'ISO-8859-1' ? utf8_decode($TED) : $TED; |
|
398 | + return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1'])!='ISO-8859-1' ? utf8_decode($TED) : $TED; |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | /** |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | { |
409 | 409 | $datos = $this->getDatos(); |
410 | 410 | $idk = !empty($datos['TED']['DD']['CAF']['DA']['IDK']) ? (int)$datos['TED']['DD']['CAF']['DA']['IDK'] : null; |
411 | - return $idk ? $idk === 100 : null; |
|
411 | + return $idk ? $idk===100 : null; |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | /** |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | { |
546 | 546 | $this->getDatos(); |
547 | 547 | // generar resumen |
548 | - $resumen = [ |
|
548 | + $resumen = [ |
|
549 | 549 | 'TpoDoc' => (int)$this->datos['Encabezado']['IdDoc']['TipoDTE'], |
550 | 550 | 'NroDoc' => (int)$this->datos['Encabezado']['IdDoc']['Folio'], |
551 | 551 | 'TasaImp' => 0, |
@@ -590,10 +590,10 @@ discard block |
||
590 | 590 | */ |
591 | 591 | private function calcularNetoIVA($total, $tasa = null) |
592 | 592 | { |
593 | - if ($tasa === 0 or $tasa === false) { |
|
593 | + if ($tasa===0 or $tasa===false) { |
|
594 | 594 | return [0, 0]; |
595 | 595 | } |
596 | - if ($tasa === null) { |
|
596 | + if ($tasa===null) { |
|
597 | 597 | $tasa = \sasco\LibreDTE\Sii::getIVA(); |
598 | 598 | } |
599 | 599 | // WARNING: el IVA obtenido puede no ser el NETO*(TASA/100) |
@@ -601,8 +601,8 @@ discard block |
||
601 | 601 | // entre el total y el neto, ya que hay casos de borde como: |
602 | 602 | // - BRUTO: 680 => NETO: 571 e IVA: 108 => TOTAL: 679 |
603 | 603 | // - BRUTO: 86710 => NETO: 72866 e IVA: 13845 => TOTAL: 86711 |
604 | - $neto = round($total / (1+($tasa/100))); |
|
605 | - $iva = $total - $neto; |
|
604 | + $neto = round($total / (1+($tasa / 100))); |
|
605 | + $iva = $total-$neto; |
|
606 | 606 | return [$neto, $iva]; |
607 | 607 | } |
608 | 608 | |
@@ -1363,7 +1363,7 @@ discard block |
||
1363 | 1363 | $item = 1; |
1364 | 1364 | $sumarMontoNF = ( |
1365 | 1365 | !isset($datos['Encabezado']['Totales']['MontoNF']) |
1366 | - or $datos['Encabezado']['Totales']['MontoNF'] === false |
|
1366 | + or $datos['Encabezado']['Totales']['MontoNF']===false |
|
1367 | 1367 | ); |
1368 | 1368 | foreach ($datos['Detalle'] as &$d) { |
1369 | 1369 | $d = array_merge([ |
@@ -1435,12 +1435,12 @@ discard block |
||
1435 | 1435 | ); |
1436 | 1436 | // aplicar descuento |
1437 | 1437 | if ($d['DescuentoPct']) { |
1438 | - $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct']/100); |
|
1438 | + $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct'] / 100); |
|
1439 | 1439 | } |
1440 | 1440 | $d['MontoItem'] -= $d['DescuentoMonto']; |
1441 | 1441 | // aplicar recargo |
1442 | 1442 | if ($d['RecargoPct']) { |
1443 | - $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct']/100); |
|
1443 | + $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct'] / 100); |
|
1444 | 1444 | } |
1445 | 1445 | $d['MontoItem'] += $d['RecargoMonto']; |
1446 | 1446 | // aproximar monto del item |
@@ -1542,7 +1542,7 @@ discard block |
||
1542 | 1542 | } |
1543 | 1543 | $valor = |
1544 | 1544 | $dr['TpoValor']=='%' |
1545 | - ? $this->round(($dr['ValorDR']/100)*$datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
1545 | + ? $this->round(($dr['ValorDR'] / 100) * $datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
1546 | 1546 | : $dr['ValorDR'] |
1547 | 1547 | ; |
1548 | 1548 | // aplicar descuento |
@@ -1615,7 +1615,7 @@ discard block |
||
1615 | 1615 | // si el monto no existe se asigna |
1616 | 1616 | if ($datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp']===null) { |
1617 | 1617 | $datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp'] = round( |
1618 | - $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp']/100 |
|
1618 | + $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp'] / 100 |
|
1619 | 1619 | ); |
1620 | 1620 | } |
1621 | 1621 | } |
@@ -1623,7 +1623,7 @@ discard block |
||
1623 | 1623 | if (isset($datos['Encabezado']['Totales']['ImptoReten']) and is_array($datos['Encabezado']['Totales']['ImptoReten'])) { |
1624 | 1624 | $codigos = array_keys($montos); |
1625 | 1625 | $n_impuestos = count($datos['Encabezado']['Totales']['ImptoReten']); |
1626 | - for ($i=0; $i<$n_impuestos; $i++) { |
|
1626 | + for ($i = 0; $i<$n_impuestos; $i++) { |
|
1627 | 1627 | if (!in_array($datos['Encabezado']['Totales']['ImptoReten'][$i]['TipoImp'], $codigos)) { |
1628 | 1628 | unset($datos['Encabezado']['Totales']['ImptoReten'][$i]); |
1629 | 1629 | } |
@@ -1648,7 +1648,7 @@ discard block |
||
1648 | 1648 | // valor IndMntNeto = 2 indica que los montosde las líneas on netos en cuyo caso no aplica el cálculo |
1649 | 1649 | // de neto e iva a partir del total y deberá venir informado de otra forma (aun no definido) |
1650 | 1650 | if ($this->esBoleta() and (empty($datos['Encabezado']['IdDoc']['IndMntNeto']) or $datos['Encabezado']['IdDoc']['IndMntNeto']!=2)) { |
1651 | - $total = (int)$datos['Encabezado']['Totales']['MntTotal'] - (int)$datos['Encabezado']['Totales']['MntExe']; |
|
1651 | + $total = (int)$datos['Encabezado']['Totales']['MntTotal']-(int)$datos['Encabezado']['Totales']['MntExe']; |
|
1652 | 1652 | if ($total and (empty($datos['Encabezado']['Totales']['MntNeto']) or empty($datos['Encabezado']['Totales']['IVA']))) { |
1653 | 1653 | list($datos['Encabezado']['Totales']['MntNeto'], $datos['Encabezado']['Totales']['IVA']) = $this->calcularNetoIVA($total); |
1654 | 1654 | } |
@@ -1663,7 +1663,7 @@ discard block |
||
1663 | 1663 | } else { |
1664 | 1664 | if (empty($datos['Encabezado']['Totales']['IVA']) and !empty($datos['Encabezado']['Totales']['TasaIVA'])) { |
1665 | 1665 | $datos['Encabezado']['Totales']['IVA'] = round( |
1666 | - $datos['Encabezado']['Totales']['MntNeto']*($datos['Encabezado']['Totales']['TasaIVA']/100) |
|
1666 | + $datos['Encabezado']['Totales']['MntNeto'] * ($datos['Encabezado']['Totales']['TasaIVA'] / 100) |
|
1667 | 1667 | ); |
1668 | 1668 | } |
1669 | 1669 | } |
@@ -1689,7 +1689,7 @@ discard block |
||
1689 | 1689 | if (ImpuestosAdicionales::getTipo($ImptoReten['TipoImp'])=='R') { |
1690 | 1690 | $datos['Encabezado']['Totales']['MntTotal'] -= $ImptoReten['MontoImp']; |
1691 | 1691 | if ($ImptoReten['MontoImp']!=$datos['Encabezado']['Totales']['IVA']) { |
1692 | - $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA'] - $ImptoReten['MontoImp']; |
|
1692 | + $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA']-$ImptoReten['MontoImp']; |
|
1693 | 1693 | } |
1694 | 1694 | } |
1695 | 1695 | // si es adicional se suma al total |
@@ -1708,7 +1708,7 @@ discard block |
||
1708 | 1708 | // si hay monto total y monto no facturable se agrega monto del periodo |
1709 | 1709 | if (!in_array($datos['Encabezado']['IdDoc']['TipoDTE'], [39, 41])) { |
1710 | 1710 | if (!empty($datos['Encabezado']['Totales']['MntTotal']) and !empty($datos['Encabezado']['Totales']['MontoNF'])) { |
1711 | - $datos['Encabezado']['Totales']['MontoPeriodo'] = $datos['Encabezado']['Totales']['MntTotal'] + $datos['Encabezado']['Totales']['MontoNF']; |
|
1711 | + $datos['Encabezado']['Totales']['MontoPeriodo'] = $datos['Encabezado']['Totales']['MntTotal']+$datos['Encabezado']['Totales']['MontoNF']; |
|
1712 | 1712 | } |
1713 | 1713 | } |
1714 | 1714 | } |
@@ -1921,7 +1921,7 @@ discard block |
||
1921 | 1921 | $SignatureValue = trim(str_replace(["\n", ' ', "\t"], '', $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue)); |
1922 | 1922 | $X509Certificate = trim(str_replace(["\n", ' ', "\t"], '', $Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue)); |
1923 | 1923 | $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap($X509Certificate, 64, "\n", true)."\n".'-----END CERTIFICATE----- '; |
1924 | - $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false; |
|
1924 | + $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false; |
|
1925 | 1925 | return $valid; |
1926 | 1926 | //return $valid and $DigestValue===base64_encode(sha1($Documento->C14N(), true)); |
1927 | 1927 | } |
@@ -65,11 +65,11 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | /** |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | // buscar el caso y copiar sus columnas que no estén |
274 | 274 | $detalle_r = $documentos[$caso['referencia']['caso']]['Detalle']; |
275 | 275 | $n_detalle_r = count($detalle_r); |
276 | - for ($i=0; $i<$n_detalle_r; $i++) { |
|
276 | + for ($i = 0; $i<$n_detalle_r; $i++) { |
|
277 | 277 | if ($detalle_r[$i]['NmbItem']==$detalle['NmbItem']) { |
278 | 278 | foreach ($detalle_r[$i] as $attr => $val) { |
279 | 279 | if (!isset($detalle[$attr])) { |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | $documento['DscRcgGlobal'][] = [ |
338 | 338 | 'TpoMov' => 'R', |
339 | 339 | 'TpoValor' => '$', |
340 | - 'ValorDR' => round((substr($caso['recargo-total-clausula'], 0, -1)/100) * $documento['Encabezado']['Transporte']['Aduana']['TotClauVenta'], 2), |
|
340 | + 'ValorDR' => round((substr($caso['recargo-total-clausula'], 0, -1) / 100) * $documento['Encabezado']['Transporte']['Aduana']['TotClauVenta'], 2), |
|
341 | 341 | ]; |
342 | 342 | } |
343 | 343 | // agregar recargo por flete y/o seguro, se agrega sólo en factura |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | $casos = explode($separador, $archivo); |
479 | 479 | $separador_len = strlen($separador); |
480 | 480 | $n_casos = count($casos); |
481 | - for ($i=1; $i<$n_casos; $i++) { |
|
481 | + for ($i = 1; $i<$n_casos; $i++) { |
|
482 | 482 | $caso = trim($casos[$i]); |
483 | 483 | $caso_anterior = trim($casos[$i-1]); |
484 | 484 | $caso_titulo = substr($caso_anterior, -$separador_len); |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | $titulos = array_slice(array_filter(explode("\t", $lineas[$linea_titulos_detalles])), 0); |
536 | 536 | // extraer detalles |
537 | 537 | $datos['detalle'] = []; |
538 | - $i = $linea_titulos_detalles + 1; |
|
538 | + $i = $linea_titulos_detalles+1; |
|
539 | 539 | while (!empty($lineas[$i])) { |
540 | 540 | $item = array_slice(array_filter(explode("\t", $lineas[$i])), 0); |
541 | 541 | $n_item = count($item); |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | // sólo continuar si hay más líneas, será, por ej, el descuento global |
550 | 550 | if (isset($lineas[$i])) { |
551 | 551 | $n_lineas = count($lineas); |
552 | - for ($i=$i; $i<$n_lineas; $i++) { |
|
552 | + for ($i = $i; $i<$n_lineas; $i++) { |
|
553 | 553 | // si la línea está vacía se omite |
554 | 554 | if (!$lineas[$i]) |
555 | 555 | continue; |
@@ -154,8 +154,9 @@ discard block |
||
154 | 154 | foreach ($casos as $caso) { |
155 | 155 | // determinar tipo documento y folio |
156 | 156 | $TipoDTE = self::$tipos[$caso['documento']]; |
157 | - if (!isset($folios[$TipoDTE])) |
|
158 | - $folios[$TipoDTE] = 1; |
|
157 | + if (!isset($folios[$TipoDTE])) { |
|
158 | + $folios[$TipoDTE] = 1; |
|
159 | + } |
|
159 | 160 | $Folio = $folios[$TipoDTE]; |
160 | 161 | // crear encabezado del documento |
161 | 162 | $documento = [ |
@@ -362,8 +363,9 @@ discard block |
||
362 | 363 | 'ValorDR' => substr($caso['recargo'], 0, -1), |
363 | 364 | ]; |
364 | 365 | } |
365 | - if (empty($documento['DscRcgGlobal'])) |
|
366 | - unset($documento['DscRcgGlobal']); |
|
366 | + if (empty($documento['DscRcgGlobal'])) { |
|
367 | + unset($documento['DscRcgGlobal']); |
|
368 | + } |
|
367 | 369 | // agregar descuento del documento de la referencia |
368 | 370 | else if (!empty($caso['referencia'])) { |
369 | 371 | $referencia = self::getReferencia($caso['referencia']['razon']); |
@@ -395,14 +397,16 @@ discard block |
||
395 | 397 | // agregar totales |
396 | 398 | $documento['Encabezado']['Totales'] = $referencia['Totales']; |
397 | 399 | // agregar tasa de IVA si corresponde |
398 | - if (isset($documento['Encabezado']['Totales']['TasaIVA'])) |
|
399 | - $documento['Encabezado']['Totales']['TasaIVA'] = \sasco\LibreDTE\Sii::getIVA(); |
|
400 | + if (isset($documento['Encabezado']['Totales']['TasaIVA'])) { |
|
401 | + $documento['Encabezado']['Totales']['TasaIVA'] = \sasco\LibreDTE\Sii::getIVA(); |
|
402 | + } |
|
400 | 403 | // si el documento referenciado es factura exenta y hay MntExe |
401 | 404 | if (isset($documento['Encabezado']['Totales']['MntExe'])) { |
402 | - if ($documentos[$caso['referencia']['caso']]['Encabezado']['IdDoc']['TipoDTE']==34) |
|
403 | - $documento['Encabezado']['Totales']['MntExe'] = 0; |
|
404 | - else |
|
405 | - unset($documento['Encabezado']['Totales']['MntExe']); |
|
405 | + if ($documentos[$caso['referencia']['caso']]['Encabezado']['IdDoc']['TipoDTE']==34) { |
|
406 | + $documento['Encabezado']['Totales']['MntExe'] = 0; |
|
407 | + } else { |
|
408 | + unset($documento['Encabezado']['Totales']['MntExe']); |
|
409 | + } |
|
406 | 410 | } |
407 | 411 | // si es documento de exportación se resetean los totales y se copia el tipo de moneda si no existe |
408 | 412 | if (in_array($documento['Encabezado']['IdDoc']['TipoDTE'], [111, 112])) { |
@@ -415,8 +419,9 @@ discard block |
||
415 | 419 | } |
416 | 420 | // agregar referencia de exportación si existe |
417 | 421 | if (!empty($caso['exportacion']['REFERENCIA'])) { |
418 | - if (!is_array($caso['exportacion']['REFERENCIA'])) |
|
419 | - $caso['exportacion']['REFERENCIA'] = [$caso['exportacion']['REFERENCIA']]; |
|
422 | + if (!is_array($caso['exportacion']['REFERENCIA'])) { |
|
423 | + $caso['exportacion']['REFERENCIA'] = [$caso['exportacion']['REFERENCIA']]; |
|
424 | + } |
|
420 | 425 | foreach ($caso['exportacion']['REFERENCIA'] as $ref) { |
421 | 426 | $documento['Referencia'][] = [ |
422 | 427 | 'TpoDocRef' => self::$referencias_exportacion[$ref], |
@@ -436,14 +441,16 @@ discard block |
||
436 | 441 | if (isset($documento['Encabezado']['Totales'])) { |
437 | 442 | $hayValor = false; |
438 | 443 | foreach ($documento['Detalle'] as $d) { |
439 | - if (!empty($d['PrcItem'])) |
|
440 | - $hayValor = true; |
|
444 | + if (!empty($d['PrcItem'])) { |
|
445 | + $hayValor = true; |
|
446 | + } |
|
441 | 447 | } |
442 | 448 | if (!$hayValor) { |
443 | - if (isset($documento['Encabezado']['Totales']['MntExe'])) |
|
444 | - $documento['Encabezado']['Totales'] = ['MntExe'=>0]; |
|
445 | - else |
|
446 | - $documento['Encabezado']['Totales'] = []; |
|
449 | + if (isset($documento['Encabezado']['Totales']['MntExe'])) { |
|
450 | + $documento['Encabezado']['Totales'] = ['MntExe'=>0]; |
|
451 | + } else { |
|
452 | + $documento['Encabezado']['Totales'] = []; |
|
453 | + } |
|
447 | 454 | $documento['Encabezado']['Totales']['MntTotal'] = 0; |
448 | 455 | } |
449 | 456 | } |
@@ -551,8 +558,9 @@ discard block |
||
551 | 558 | $n_lineas = count($lineas); |
552 | 559 | for ($i=$i; $i<$n_lineas; $i++) { |
553 | 560 | // si la línea está vacía se omite |
554 | - if (!$lineas[$i]) |
|
555 | - continue; |
|
561 | + if (!$lineas[$i]) { |
|
562 | + continue; |
|
563 | + } |
|
556 | 564 | // si hay descuento global se guarda |
557 | 565 | if (strpos($lineas[$i], 'DESCUENTO GLOBAL ITEMES AFECTOS')===0) { |
558 | 566 | $aux = explode("\t", $lineas[$i]); |
@@ -588,13 +596,15 @@ discard block |
||
588 | 596 | } |
589 | 597 | // agregar a los datos de aduanas |
590 | 598 | else { |
591 | - if (!isset($datos['exportacion'])) |
|
592 | - $datos['exportacion'] = []; |
|
599 | + if (!isset($datos['exportacion'])) { |
|
600 | + $datos['exportacion'] = []; |
|
601 | + } |
|
593 | 602 | if (!isset($datos['exportacion'][$var])) { |
594 | 603 | $datos['exportacion'][$var] = $val; |
595 | 604 | } else { |
596 | - if (!is_array($datos['exportacion'][$var])) |
|
597 | - $datos['exportacion'][$var] = [$datos['exportacion'][$var]]; |
|
605 | + if (!is_array($datos['exportacion'][$var])) { |
|
606 | + $datos['exportacion'][$var] = [$datos['exportacion'][$var]]; |
|
607 | + } |
|
598 | 608 | $datos['exportacion'][$var][] = $val; |
599 | 609 | } |
600 | 610 | } |