@@ -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 | } |
@@ -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 | |
@@ -1354,7 +1354,7 @@ discard block |
||
| 1354 | 1354 | $item = 1; |
| 1355 | 1355 | $sumarMontoNF = ( |
| 1356 | 1356 | !isset($datos['Encabezado']['Totales']['MontoNF']) |
| 1357 | - or $datos['Encabezado']['Totales']['MontoNF'] === false |
|
| 1357 | + or $datos['Encabezado']['Totales']['MontoNF']===false |
|
| 1358 | 1358 | ); |
| 1359 | 1359 | foreach ($datos['Detalle'] as &$d) { |
| 1360 | 1360 | $d = array_merge([ |
@@ -1426,12 +1426,12 @@ discard block |
||
| 1426 | 1426 | ); |
| 1427 | 1427 | // aplicar descuento |
| 1428 | 1428 | if ($d['DescuentoPct']) { |
| 1429 | - $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct']/100); |
|
| 1429 | + $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct'] / 100); |
|
| 1430 | 1430 | } |
| 1431 | 1431 | $d['MontoItem'] -= $d['DescuentoMonto']; |
| 1432 | 1432 | // aplicar recargo |
| 1433 | 1433 | if ($d['RecargoPct']) { |
| 1434 | - $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct']/100); |
|
| 1434 | + $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct'] / 100); |
|
| 1435 | 1435 | } |
| 1436 | 1436 | $d['MontoItem'] += $d['RecargoMonto']; |
| 1437 | 1437 | // aproximar monto del item |
@@ -1533,7 +1533,7 @@ discard block |
||
| 1533 | 1533 | } |
| 1534 | 1534 | $valor = |
| 1535 | 1535 | $dr['TpoValor']=='%' |
| 1536 | - ? $this->round(($dr['ValorDR']/100)*$datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
| 1536 | + ? $this->round(($dr['ValorDR'] / 100) * $datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
| 1537 | 1537 | : $dr['ValorDR'] |
| 1538 | 1538 | ; |
| 1539 | 1539 | // aplicar descuento |
@@ -1606,7 +1606,7 @@ discard block |
||
| 1606 | 1606 | // si el monto no existe se asigna |
| 1607 | 1607 | if ($datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp']===null) { |
| 1608 | 1608 | $datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp'] = round( |
| 1609 | - $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp']/100 |
|
| 1609 | + $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp'] / 100 |
|
| 1610 | 1610 | ); |
| 1611 | 1611 | } |
| 1612 | 1612 | } |
@@ -1614,7 +1614,7 @@ discard block |
||
| 1614 | 1614 | if (isset($datos['Encabezado']['Totales']['ImptoReten']) and is_array($datos['Encabezado']['Totales']['ImptoReten'])) { |
| 1615 | 1615 | $codigos = array_keys($montos); |
| 1616 | 1616 | $n_impuestos = count($datos['Encabezado']['Totales']['ImptoReten']); |
| 1617 | - for ($i=0; $i<$n_impuestos; $i++) { |
|
| 1617 | + for ($i = 0; $i<$n_impuestos; $i++) { |
|
| 1618 | 1618 | if (!in_array($datos['Encabezado']['Totales']['ImptoReten'][$i]['TipoImp'], $codigos)) { |
| 1619 | 1619 | unset($datos['Encabezado']['Totales']['ImptoReten'][$i]); |
| 1620 | 1620 | } |
@@ -1639,7 +1639,7 @@ discard block |
||
| 1639 | 1639 | // valor IndMntNeto = 2 indica que los montosde las líneas on netos en cuyo caso no aplica el cálculo |
| 1640 | 1640 | // de neto e iva a partir del total y deberá venir informado de otra forma (aun no definido) |
| 1641 | 1641 | if ($this->esBoleta() and (empty($datos['Encabezado']['IdDoc']['IndMntNeto']) or $datos['Encabezado']['IdDoc']['IndMntNeto']!=2)) { |
| 1642 | - $total = (int)$datos['Encabezado']['Totales']['MntTotal'] - (int)$datos['Encabezado']['Totales']['MntExe']; |
|
| 1642 | + $total = (int)$datos['Encabezado']['Totales']['MntTotal']-(int)$datos['Encabezado']['Totales']['MntExe']; |
|
| 1643 | 1643 | if ($total and (empty($datos['Encabezado']['Totales']['MntNeto']) or empty($datos['Encabezado']['Totales']['IVA']))) { |
| 1644 | 1644 | list($datos['Encabezado']['Totales']['MntNeto'], $datos['Encabezado']['Totales']['IVA']) = $this->calcularNetoIVA($total); |
| 1645 | 1645 | } |
@@ -1654,7 +1654,7 @@ discard block |
||
| 1654 | 1654 | } else { |
| 1655 | 1655 | if (empty($datos['Encabezado']['Totales']['IVA']) and !empty($datos['Encabezado']['Totales']['TasaIVA'])) { |
| 1656 | 1656 | $datos['Encabezado']['Totales']['IVA'] = round( |
| 1657 | - $datos['Encabezado']['Totales']['MntNeto']*($datos['Encabezado']['Totales']['TasaIVA']/100) |
|
| 1657 | + $datos['Encabezado']['Totales']['MntNeto'] * ($datos['Encabezado']['Totales']['TasaIVA'] / 100) |
|
| 1658 | 1658 | ); |
| 1659 | 1659 | } |
| 1660 | 1660 | } |
@@ -1680,7 +1680,7 @@ discard block |
||
| 1680 | 1680 | if (ImpuestosAdicionales::getTipo($ImptoReten['TipoImp'])=='R') { |
| 1681 | 1681 | $datos['Encabezado']['Totales']['MntTotal'] -= $ImptoReten['MontoImp']; |
| 1682 | 1682 | if ($ImptoReten['MontoImp']!=$datos['Encabezado']['Totales']['IVA']) { |
| 1683 | - $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA'] - $ImptoReten['MontoImp']; |
|
| 1683 | + $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA']-$ImptoReten['MontoImp']; |
|
| 1684 | 1684 | } |
| 1685 | 1685 | } |
| 1686 | 1686 | // si es adicional se suma al total |
@@ -1699,7 +1699,7 @@ discard block |
||
| 1699 | 1699 | // si hay monto total y monto no facturable se agrega monto del periodo |
| 1700 | 1700 | if (!in_array($datos['Encabezado']['IdDoc']['TipoDTE'], [39, 41])) { |
| 1701 | 1701 | if (!empty($datos['Encabezado']['Totales']['MntTotal']) and !empty($datos['Encabezado']['Totales']['MontoNF'])) { |
| 1702 | - $datos['Encabezado']['Totales']['MontoPeriodo'] = $datos['Encabezado']['Totales']['MntTotal'] + $datos['Encabezado']['Totales']['MontoNF']; |
|
| 1702 | + $datos['Encabezado']['Totales']['MontoPeriodo'] = $datos['Encabezado']['Totales']['MntTotal']+$datos['Encabezado']['Totales']['MontoNF']; |
|
| 1703 | 1703 | } |
| 1704 | 1704 | } |
| 1705 | 1705 | } |
@@ -1912,7 +1912,7 @@ discard block |
||
| 1912 | 1912 | $SignatureValue = trim(str_replace(["\n", ' ', "\t"], '', $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue)); |
| 1913 | 1913 | $X509Certificate = trim(str_replace(["\n", ' ', "\t"], '', $Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue)); |
| 1914 | 1914 | $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap($X509Certificate, 64, "\n", true)."\n".'-----END CERTIFICATE----- '; |
| 1915 | - $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false; |
|
| 1915 | + $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false; |
|
| 1916 | 1916 | return $valid; |
| 1917 | 1917 | //return $valid and $DigestValue===base64_encode(sha1($Documento->C14N(), true)); |
| 1918 | 1918 | } |
@@ -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 | } |