@@ -83,5 +83,6 @@ |
||
| 83 | 83 | echo $XML2->getFlattened('/nodo1/nodo2')."\n\n"; |
| 84 | 84 | |
| 85 | 85 | // si hubo errores mostrar |
| 86 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 86 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 87 | 87 | echo $error, "\n"; |
| 88 | +} |
|
@@ -66,4 +66,4 @@ |
||
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
| 69 | - echo $error,"\n"; |
|
| 69 | + echo $error, "\n"; |
|
@@ -411,17 +411,20 @@ discard block |
||
| 411 | 411 | // Objetos de Firma, Folios y EnvioDTE |
| 412 | 412 | $Firma = new \sasco\LibreDTE\FirmaElectronica($config['firma']); |
| 413 | 413 | $Folios = []; |
| 414 | -foreach ($folios as $tipo => $cantidad) |
|
| 414 | +foreach ($folios as $tipo => $cantidad) { |
|
| 415 | 415 | $Folios[$tipo] = new \sasco\LibreDTE\Sii\Folios(file_get_contents('xml/folios/'.$tipo.'.xml')); |
| 416 | +} |
|
| 416 | 417 | $EnvioDTE = new \sasco\LibreDTE\Sii\EnvioDte(); |
| 417 | 418 | |
| 418 | 419 | // generar cada DTE, timbrar, firmar y agregar al sobre de EnvioDTE |
| 419 | 420 | foreach ($set_pruebas as $documento) { |
| 420 | 421 | $DTE = new \sasco\LibreDTE\Sii\Dte($documento); |
| 421 | - if (!$DTE->timbrar($Folios[$DTE->getTipo()])) |
|
| 422 | - break; |
|
| 423 | - if (!$DTE->firmar($Firma)) |
|
| 424 | - break; |
|
| 422 | + if (!$DTE->timbrar($Folios[$DTE->getTipo()])) { |
|
| 423 | + break; |
|
| 424 | + } |
|
| 425 | + if (!$DTE->firmar($Firma)) { |
|
| 426 | + break; |
|
| 427 | + } |
|
| 425 | 428 | $EnvioDTE->agregar($DTE); |
| 426 | 429 | } |
| 427 | 430 | |
@@ -433,5 +436,6 @@ discard block |
||
| 433 | 436 | var_dump($track_id); |
| 434 | 437 | |
| 435 | 438 | // si hubo errores mostrar |
| 436 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 439 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 437 | 440 | echo $error,"\n"; |
| 441 | +} |
|
@@ -66,4 +66,4 @@ |
||
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
| 69 | - echo $error,"\n"; |
|
| 69 | + echo $error, "\n"; |
|
@@ -98,5 +98,6 @@ |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // si hubo errores mostrar |
| 101 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 101 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 102 | 102 | echo $error,"\n"; |
| 103 | +} |
|
@@ -66,4 +66,4 @@ |
||
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
| 69 | - echo $error,"\n"; |
|
| 69 | + echo $error, "\n"; |
|
@@ -98,5 +98,6 @@ |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // si hubo errores mostrar |
| 101 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 101 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 102 | 102 | echo $error,"\n"; |
| 103 | +} |
|
@@ -66,4 +66,4 @@ |
||
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
| 69 | - echo $error,"\n"; |
|
| 69 | + echo $error, "\n"; |
|
@@ -65,5 +65,6 @@ |
||
| 65 | 65 | var_dump($track_id); |
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 68 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 69 | 69 | echo $error,"\n"; |
| 70 | +} |
|
@@ -66,4 +66,4 @@ |
||
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
| 69 | - echo $error,"\n"; |
|
| 69 | + echo $error, "\n"; |
|
@@ -98,5 +98,6 @@ |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // si hubo errores mostrar |
| 101 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 101 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 102 | 102 | echo $error,"\n"; |
| 103 | +} |
|
@@ -66,4 +66,4 @@ |
||
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
| 69 | - echo $error,"\n"; |
|
| 69 | + echo $error, "\n"; |
|
@@ -65,5 +65,6 @@ |
||
| 65 | 65 | var_dump($track_id); |
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 68 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 69 | 69 | echo $error,"\n"; |
| 70 | +} |
|
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * Constructor, obtiene el token de la sesión y lo guarda |
| 58 | - * @param Firma Objeto con la firma electrónica |
|
| 58 | + * @param Firma \sasco\LibreDTE\FirmaElectronica con la firma electrónica |
|
| 59 | 59 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 60 | 60 | * @version 2017-08-28 |
| 61 | 61 | */ |
@@ -97,6 +97,8 @@ discard block |
||
| 97 | 97 | * Método que entrega los eventos asociados a un DTE |
| 98 | 98 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 99 | 99 | * @version 2017-08-28 |
| 100 | + * @param string $dte |
|
| 101 | + * @param string $folio |
|
| 100 | 102 | */ |
| 101 | 103 | public function listarEventosHistDoc($rut, $dv, $dte, $folio) |
| 102 | 104 | { |
@@ -184,10 +186,10 @@ discard block |
||
| 184 | 186 | |
| 185 | 187 | /** |
| 186 | 188 | * Método para realizar una solicitud al servicio web del SII |
| 187 | - * @param request Nombre de la función que se ejecutará en el servicio web |
|
| 189 | + * @param request string de la función que se ejecutará en el servicio web |
|
| 188 | 190 | * @param args Argumentos que se pasarán al servicio web |
| 189 | - * @param retry Intentos que se realizarán como máximo para obtener respuesta |
|
| 190 | - * @return Objeto o String con la respuesta (depende servicio web) |
|
| 191 | + * @param retry integer que se realizarán como máximo para obtener respuesta |
|
| 192 | + * @return string o String con la respuesta (depende servicio web) |
|
| 191 | 193 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 192 | 194 | * @version 2017-08-28 |
| 193 | 195 | */ |
@@ -220,7 +220,7 @@ |
||
| 220 | 220 | \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::REQUEST_ERROR_SOAP, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::REQUEST_ERROR_SOAP, $msg)); |
| 221 | 221 | return false; |
| 222 | 222 | } |
| 223 | - for ($i=0; $i<$retry; $i++) { |
|
| 223 | + for ($i = 0; $i<$retry; $i++) { |
|
| 224 | 224 | try { |
| 225 | 225 | $body = call_user_func_array([$soap, $request], $args); |
| 226 | 226 | break; |
@@ -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([ |
@@ -1310,8 +1328,9 @@ discard block |
||
| 1310 | 1328 | */ |
| 1311 | 1329 | private function normalizar_detalle(array &$datos) |
| 1312 | 1330 | { |
| 1313 | - if (!isset($datos['Detalle'][0])) |
|
| 1314 | - $datos['Detalle'] = [$datos['Detalle']]; |
|
| 1331 | + if (!isset($datos['Detalle'][0])) { |
|
| 1332 | + $datos['Detalle'] = [$datos['Detalle']]; |
|
| 1333 | + } |
|
| 1315 | 1334 | $item = 1; |
| 1316 | 1335 | foreach ($datos['Detalle'] as &$d) { |
| 1317 | 1336 | $d = array_merge([ |
@@ -1373,8 +1392,9 @@ discard block |
||
| 1373 | 1392 | ]; |
| 1374 | 1393 | } |
| 1375 | 1394 | if ($d['PrcItem']) { |
| 1376 | - if (!$d['QtyItem']) |
|
| 1377 | - $d['QtyItem'] = 1; |
|
| 1395 | + if (!$d['QtyItem']) { |
|
| 1396 | + $d['QtyItem'] = 1; |
|
| 1397 | + } |
|
| 1378 | 1398 | if (empty($d['MontoItem'])) { |
| 1379 | 1399 | $d['MontoItem'] = $this->round( |
| 1380 | 1400 | $d['QtyItem'] * $d['PrcItem'], |
@@ -1440,8 +1460,9 @@ discard block |
||
| 1440 | 1460 | private function normalizar_aplicar_descuentos_recargos(array &$datos) |
| 1441 | 1461 | { |
| 1442 | 1462 | if (!empty($datos['DscRcgGlobal'])) { |
| 1443 | - if (!isset($datos['DscRcgGlobal'][0])) |
|
| 1444 | - $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
| 1463 | + if (!isset($datos['DscRcgGlobal'][0])) { |
|
| 1464 | + $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
| 1465 | + } |
|
| 1445 | 1466 | foreach ($datos['DscRcgGlobal'] as &$dr) { |
| 1446 | 1467 | $dr = array_merge([ |
| 1447 | 1468 | 'NroLinDR' => false, |
@@ -1508,8 +1529,9 @@ discard block |
||
| 1508 | 1529 | $montos = []; |
| 1509 | 1530 | foreach ($datos['Detalle'] as &$d) { |
| 1510 | 1531 | if (!empty($d['CodImpAdic'])) { |
| 1511 | - if (!isset($montos[$d['CodImpAdic']])) |
|
| 1512 | - $montos[$d['CodImpAdic']] = 0; |
|
| 1532 | + if (!isset($montos[$d['CodImpAdic']])) { |
|
| 1533 | + $montos[$d['CodImpAdic']] = 0; |
|
| 1534 | + } |
|
| 1513 | 1535 | $montos[$d['CodImpAdic']] += $d['MontoItem']; |
| 1514 | 1536 | } |
| 1515 | 1537 | } |
@@ -1588,10 +1610,12 @@ discard block |
||
| 1588 | 1610 | } |
| 1589 | 1611 | if (empty($datos['Encabezado']['Totales']['MntTotal'])) { |
| 1590 | 1612 | $datos['Encabezado']['Totales']['MntTotal'] = $datos['Encabezado']['Totales']['MntNeto']; |
| 1591 | - if (!empty($datos['Encabezado']['Totales']['IVA'])) |
|
| 1592 | - $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['IVA']; |
|
| 1593 | - if (!empty($datos['Encabezado']['Totales']['MntExe'])) |
|
| 1594 | - $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['MntExe']; |
|
| 1613 | + if (!empty($datos['Encabezado']['Totales']['IVA'])) { |
|
| 1614 | + $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['IVA']; |
|
| 1615 | + } |
|
| 1616 | + if (!empty($datos['Encabezado']['Totales']['MntExe'])) { |
|
| 1617 | + $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['MntExe']; |
|
| 1618 | + } |
|
| 1595 | 1619 | } |
| 1596 | 1620 | } else { |
| 1597 | 1621 | if (!$datos['Encabezado']['Totales']['MntTotal'] and !empty($datos['Encabezado']['Totales']['MntExe'])) { |
@@ -1617,8 +1641,10 @@ discard block |
||
| 1617 | 1641 | } |
| 1618 | 1642 | // si hay impuesto de crédito a constructoras del 65% se descuenta del total |
| 1619 | 1643 | if (!empty($datos['Encabezado']['Totales']['CredEC'])) { |
| 1620 | - if ($datos['Encabezado']['Totales']['CredEC']===true) |
|
| 1621 | - $datos['Encabezado']['Totales']['CredEC'] = round($datos['Encabezado']['Totales']['IVA'] * 0.65); // TODO: mover a constante o método |
|
| 1644 | + if ($datos['Encabezado']['Totales']['CredEC']===true) { |
|
| 1645 | + $datos['Encabezado']['Totales']['CredEC'] = round($datos['Encabezado']['Totales']['IVA'] * 0.65); |
|
| 1646 | + } |
|
| 1647 | + // TODO: mover a constante o método |
|
| 1622 | 1648 | $datos['Encabezado']['Totales']['MntTotal'] -= $datos['Encabezado']['Totales']['CredEC']; |
| 1623 | 1649 | } |
| 1624 | 1650 | } |
@@ -1724,10 +1750,12 @@ discard block |
||
| 1724 | 1750 | /*if (!$this->checkFirma()) |
| 1725 | 1751 | return 1;*/ |
| 1726 | 1752 | if (is_array($datos)) { |
| 1727 | - if (isset($datos['RUTEmisor']) and $this->getEmisor()!=$datos['RUTEmisor']) |
|
| 1728 | - return 2; |
|
| 1729 | - if (isset($datos['RUTRecep']) and $this->getReceptor()!=$datos['RUTRecep']) |
|
| 1730 | - return 3; |
|
| 1753 | + if (isset($datos['RUTEmisor']) and $this->getEmisor()!=$datos['RUTEmisor']) { |
|
| 1754 | + return 2; |
|
| 1755 | + } |
|
| 1756 | + if (isset($datos['RUTRecep']) and $this->getReceptor()!=$datos['RUTRecep']) { |
|
| 1757 | + return 3; |
|
| 1758 | + } |
|
| 1731 | 1759 | } |
| 1732 | 1760 | return 0; |
| 1733 | 1761 | } |
@@ -1741,8 +1769,9 @@ discard block |
||
| 1741 | 1769 | */ |
| 1742 | 1770 | public function checkFirma() |
| 1743 | 1771 | { |
| 1744 | - if (!$this->xml) |
|
| 1745 | - return null; |
|
| 1772 | + if (!$this->xml) { |
|
| 1773 | + return null; |
|
| 1774 | + } |
|
| 1746 | 1775 | // obtener firma |
| 1747 | 1776 | $Signature = $this->xml->documentElement->getElementsByTagName('Signature')->item(0); |
| 1748 | 1777 | // preparar documento a validar |
@@ -1834,12 +1863,14 @@ discard block |
||
| 1834 | 1863 | { |
| 1835 | 1864 | // solicitar token |
| 1836 | 1865 | $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($Firma); |
| 1837 | - if (!$token) |
|
| 1838 | - return false; |
|
| 1866 | + if (!$token) { |
|
| 1867 | + return false; |
|
| 1868 | + } |
|
| 1839 | 1869 | // consultar estado dte |
| 1840 | 1870 | $run = $Firma->getID(); |
| 1841 | - if ($run===false) |
|
| 1842 | - return false; |
|
| 1871 | + if ($run===false) { |
|
| 1872 | + return false; |
|
| 1873 | + } |
|
| 1843 | 1874 | list($RutConsultante, $DvConsultante) = explode('-', $run); |
| 1844 | 1875 | list($RutCompania, $DvCompania) = explode('-', $this->getEmisor()); |
| 1845 | 1876 | list($RutReceptor, $DvReceptor) = explode('-', $this->getReceptor()); |
@@ -1858,8 +1889,9 @@ discard block |
||
| 1858 | 1889 | 'token' => $token, |
| 1859 | 1890 | ]); |
| 1860 | 1891 | // si el estado se pudo recuperar se muestra |
| 1861 | - if ($xml===false) |
|
| 1862 | - return false; |
|
| 1892 | + if ($xml===false) { |
|
| 1893 | + return false; |
|
| 1894 | + } |
|
| 1863 | 1895 | // entregar estado |
| 1864 | 1896 | return (array)$xml->xpath('/SII:RESPUESTA/SII:RESP_HDR')[0]; |
| 1865 | 1897 | } |
@@ -1876,8 +1908,9 @@ discard block |
||
| 1876 | 1908 | { |
| 1877 | 1909 | // solicitar token |
| 1878 | 1910 | $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($Firma); |
| 1879 | - if (!$token) |
|
| 1880 | - return false; |
|
| 1911 | + if (!$token) { |
|
| 1912 | + return false; |
|
| 1913 | + } |
|
| 1881 | 1914 | // consultar estado dte |
| 1882 | 1915 | list($RutEmpresa, $DvEmpresa) = explode('-', $this->getEmisor()); |
| 1883 | 1916 | list($RutReceptor, $DvReceptor) = explode('-', $this->getReceptor()); |
@@ -1895,8 +1928,9 @@ discard block |
||
| 1895 | 1928 | 'token' => $token, |
| 1896 | 1929 | ]); |
| 1897 | 1930 | // si el estado se pudo recuperar se muestra |
| 1898 | - if ($xml===false) |
|
| 1899 | - return false; |
|
| 1931 | + if ($xml===false) { |
|
| 1932 | + return false; |
|
| 1933 | + } |
|
| 1900 | 1934 | // entregar estado |
| 1901 | 1935 | return (array)$xml->xpath('/SII:RESPUESTA/SII:RESP_BODY')[0]; |
| 1902 | 1936 | } |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | /** |
| 239 | 239 | * Método que entrega el tipo de DTE |
| 240 | - * @return Tipo de dte, ej: 33 (factura electrónica) |
|
| 240 | + * @return string de dte, ej: 33 (factura electrónica) |
|
| 241 | 241 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 242 | 242 | * @version 2015-09-02 |
| 243 | 243 | */ |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | /** |
| 250 | 250 | * Método que entrega el folio del DTE |
| 251 | - * @return Folio del DTE |
|
| 251 | + * @return string del DTE |
|
| 252 | 252 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 253 | 253 | * @version 2015-09-02 |
| 254 | 254 | */ |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | |
| 260 | 260 | /** |
| 261 | 261 | * Método que entrega rut del emisor del DTE |
| 262 | - * @return RUT del emiro |
|
| 262 | + * @return string del emiro |
|
| 263 | 263 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 264 | 264 | * @version 2015-09-07 |
| 265 | 265 | */ |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | |
| 276 | 276 | /** |
| 277 | 277 | * Método que entrega rut del receptor del DTE |
| 278 | - * @return RUT del emiro |
|
| 278 | + * @return string del emiro |
|
| 279 | 279 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 280 | 280 | * @version 2015-09-07 |
| 281 | 281 | */ |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | |
| 292 | 292 | /** |
| 293 | 293 | * Método que entrega fecha de emisión del DTE |
| 294 | - * @return Fecha de emisión en formato AAAA-MM-DD |
|
| 294 | + * @return string de emisión en formato AAAA-MM-DD |
|
| 295 | 295 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 296 | 296 | * @version 2015-09-07 |
| 297 | 297 | */ |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | |
| 401 | 401 | /** |
| 402 | 402 | * Método que realiza el timbrado del DTE |
| 403 | - * @param Folios Objeto de los Folios con los que se desea timbrar |
|
| 403 | + * @param Folios Folios de los Folios con los que se desea timbrar |
|
| 404 | 404 | * @return =true si se pudo timbrar o =false en caso de error |
| 405 | 405 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 406 | 406 | * @version 2016-09-01 |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | |
| 487 | 487 | /** |
| 488 | 488 | * Método que realiza la firma del DTE |
| 489 | - * @param Firma objeto que representa la Firma Electrónca |
|
| 489 | + * @param Firma \sasco\LibreDTE\FirmaElectronica que representa la Firma Electrónca |
|
| 490 | 490 | * @return =true si el DTE pudo ser fimado o =false si no se pudo firmar |
| 491 | 491 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 492 | 492 | * @version 2017-10-22 |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | |
| 510 | 510 | /** |
| 511 | 511 | * Método que entrega el DTE en XML |
| 512 | - * @return XML con el DTE (podría: con o sin timbre y con o sin firma) |
|
| 512 | + * @return string con el DTE (podría: con o sin timbre y con o sin firma) |
|
| 513 | 513 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 514 | 514 | * @version 2015-08-20 |
| 515 | 515 | */ |
@@ -1750,7 +1750,7 @@ discard block |
||
| 1750 | 1750 | * - Firma del DTE |
| 1751 | 1751 | * - RUT del emisor (si se pasó uno para comparar) |
| 1752 | 1752 | * - RUT del receptor (si se pasó uno para comparar) |
| 1753 | - * @return Código del estado de la validación |
|
| 1753 | + * @return integer del estado de la validación |
|
| 1754 | 1754 | * @warning No se está validando la firma |
| 1755 | 1755 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 1756 | 1756 | * @version 2015-09-08 |
@@ -1861,7 +1861,7 @@ discard block |
||
| 1861 | 1861 | |
| 1862 | 1862 | /** |
| 1863 | 1863 | * Método que obtiene el estado del DTE |
| 1864 | - * @param Firma objeto que representa la Firma Electrónca |
|
| 1864 | + * @param Firma \sasco\LibreDTE\FirmaElectronica que representa la Firma Electrónca |
|
| 1865 | 1865 | * @return Arreglo con el estado del DTE |
| 1866 | 1866 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 1867 | 1867 | * @version 2015-10-24 |
@@ -1902,7 +1902,7 @@ discard block |
||
| 1902 | 1902 | |
| 1903 | 1903 | /** |
| 1904 | 1904 | * Método que obtiene el estado avanzado del DTE |
| 1905 | - * @param Firma objeto que representa la Firma Electrónca |
|
| 1905 | + * @param Firma \sasco\LibreDTE\FirmaElectronica que representa la Firma Electrónca |
|
| 1906 | 1906 | * @return Arreglo con el estado del DTE |
| 1907 | 1907 | * @todo Corregir warning y también definir que se retornará (sobre todo en caso de error) |
| 1908 | 1908 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
@@ -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], null, $parent); |
|
| 142 | + $this->xml->generate($datos+['TED' => null], null, $parent); |
|
| 143 | 143 | $this->datos = $datos; |
| 144 | 144 | if ($normalizar and !$this->verificarDatos()) { |
| 145 | 145 | return false; |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); |
| 383 | 383 | $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', ''); |
| 384 | 384 | $TED = $xml->getFlattened('/'); |
| 385 | - return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1']) != 'ISO-8859-1' ? utf8_decode($TED) : $TED; |
|
| 385 | + return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1'])!='ISO-8859-1' ? utf8_decode($TED) : $TED; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | { |
| 396 | 396 | $datos = $this->getDatos(); |
| 397 | 397 | $idk = !empty($datos['TED']['DD']['CAF']['DA']['IDK']) ? (int)$datos['TED']['DD']['CAF']['DA']['IDK'] : null; |
| 398 | - return $idk ? $idk === 100 : null; |
|
| 398 | + return $idk ? $idk===100 : null; |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | /** |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | { |
| 530 | 530 | $this->getDatos(); |
| 531 | 531 | // generar resumen |
| 532 | - $resumen = [ |
|
| 532 | + $resumen = [ |
|
| 533 | 533 | 'TpoDoc' => (int)$this->datos['Encabezado']['IdDoc']['TipoDTE'], |
| 534 | 534 | 'NroDoc' => (int)$this->datos['Encabezado']['IdDoc']['Folio'], |
| 535 | 535 | 'TasaImp' => 0, |
@@ -574,17 +574,17 @@ discard block |
||
| 574 | 574 | */ |
| 575 | 575 | private function calcularNetoIVA($total, $tasa = null) |
| 576 | 576 | { |
| 577 | - if ($tasa === 0 or $tasa === false) |
|
| 577 | + if ($tasa===0 or $tasa===false) |
|
| 578 | 578 | return [0, 0]; |
| 579 | - if ($tasa === null) |
|
| 579 | + if ($tasa===null) |
|
| 580 | 580 | $tasa = \sasco\LibreDTE\Sii::getIVA(); |
| 581 | 581 | // WARNING: el IVA obtenido puede no ser el NETO*(TASA/100) |
| 582 | 582 | // se calcula el monto neto y luego se obtiene el IVA haciendo la resta |
| 583 | 583 | // entre el total y el neto, ya que hay casos de borde como: |
| 584 | 584 | // - BRUTO: 680 => NETO: 571 e IVA: 108 => TOTAL: 679 |
| 585 | 585 | // - BRUTO: 86710 => NETO: 72866 e IVA: 13845 => TOTAL: 86711 |
| 586 | - $neto = round($total / (1+($tasa/100))); |
|
| 587 | - $iva = $total - $neto; |
|
| 586 | + $neto = round($total / (1+($tasa / 100))); |
|
| 587 | + $iva = $total-$neto; |
|
| 588 | 588 | return [$neto, $iva]; |
| 589 | 589 | } |
| 590 | 590 | |
@@ -1429,12 +1429,12 @@ discard block |
||
| 1429 | 1429 | ); |
| 1430 | 1430 | // aplicar descuento |
| 1431 | 1431 | if ($d['DescuentoPct']) { |
| 1432 | - $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct']/100); |
|
| 1432 | + $d['DescuentoMonto'] = round($d['MontoItem'] * (float)$d['DescuentoPct'] / 100); |
|
| 1433 | 1433 | } |
| 1434 | 1434 | $d['MontoItem'] -= $d['DescuentoMonto']; |
| 1435 | 1435 | // aplicar recargo |
| 1436 | 1436 | if ($d['RecargoPct']) { |
| 1437 | - $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct']/100); |
|
| 1437 | + $d['RecargoMonto'] = round($d['MontoItem'] * (float)$d['RecargoPct'] / 100); |
|
| 1438 | 1438 | } |
| 1439 | 1439 | $d['MontoItem'] += $d['RecargoMonto']; |
| 1440 | 1440 | // aproximar monto del item |
@@ -1520,7 +1520,7 @@ discard block |
||
| 1520 | 1520 | } |
| 1521 | 1521 | $valor = |
| 1522 | 1522 | $dr['TpoValor']=='%' |
| 1523 | - ? $this->round(($dr['ValorDR']/100)*$datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
| 1523 | + ? $this->round(($dr['ValorDR'] / 100) * $datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
| 1524 | 1524 | : $dr['ValorDR'] |
| 1525 | 1525 | ; |
| 1526 | 1526 | // aplicar descuento |
@@ -1593,7 +1593,7 @@ discard block |
||
| 1593 | 1593 | // si el monto no existe se asigna |
| 1594 | 1594 | if ($datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp']===null) { |
| 1595 | 1595 | $datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp'] = round( |
| 1596 | - $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp']/100 |
|
| 1596 | + $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp'] / 100 |
|
| 1597 | 1597 | ); |
| 1598 | 1598 | } |
| 1599 | 1599 | } |
@@ -1601,7 +1601,7 @@ discard block |
||
| 1601 | 1601 | if (isset($datos['Encabezado']['Totales']['ImptoReten']) and is_array($datos['Encabezado']['Totales']['ImptoReten'])) { |
| 1602 | 1602 | $codigos = array_keys($montos); |
| 1603 | 1603 | $n_impuestos = count($datos['Encabezado']['Totales']['ImptoReten']); |
| 1604 | - for ($i=0; $i<$n_impuestos; $i++) { |
|
| 1604 | + for ($i = 0; $i<$n_impuestos; $i++) { |
|
| 1605 | 1605 | if (!in_array($datos['Encabezado']['Totales']['ImptoReten'][$i]['TipoImp'], $codigos)) { |
| 1606 | 1606 | unset($datos['Encabezado']['Totales']['ImptoReten'][$i]); |
| 1607 | 1607 | } |
@@ -1629,7 +1629,7 @@ discard block |
||
| 1629 | 1629 | } else { |
| 1630 | 1630 | if (empty($datos['Encabezado']['Totales']['IVA']) and !empty($datos['Encabezado']['Totales']['TasaIVA'])) { |
| 1631 | 1631 | $datos['Encabezado']['Totales']['IVA'] = round( |
| 1632 | - $datos['Encabezado']['Totales']['MntNeto']*($datos['Encabezado']['Totales']['TasaIVA']/100) |
|
| 1632 | + $datos['Encabezado']['Totales']['MntNeto'] * ($datos['Encabezado']['Totales']['TasaIVA'] / 100) |
|
| 1633 | 1633 | ); |
| 1634 | 1634 | } |
| 1635 | 1635 | } |
@@ -1653,7 +1653,7 @@ discard block |
||
| 1653 | 1653 | if (ImpuestosAdicionales::getTipo($ImptoReten['TipoImp'])=='R') { |
| 1654 | 1654 | $datos['Encabezado']['Totales']['MntTotal'] -= $ImptoReten['MontoImp']; |
| 1655 | 1655 | if ($ImptoReten['MontoImp']!=$datos['Encabezado']['Totales']['IVA']) { |
| 1656 | - $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA'] - $ImptoReten['MontoImp']; |
|
| 1656 | + $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA']-$ImptoReten['MontoImp']; |
|
| 1657 | 1657 | } |
| 1658 | 1658 | } |
| 1659 | 1659 | // si es adicional se suma al total |
@@ -1811,7 +1811,7 @@ discard block |
||
| 1811 | 1811 | $SignatureValue = $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue; |
| 1812 | 1812 | $X509Certificate = $Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue; |
| 1813 | 1813 | $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap(trim($X509Certificate), 64, "\n", true)."\n".'-----END CERTIFICATE----- '; |
| 1814 | - $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false; |
|
| 1814 | + $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false; |
|
| 1815 | 1815 | return $valid; |
| 1816 | 1816 | //return $valid and $DigestValue===base64_encode(sha1($Documento->C14N(), true)); |
| 1817 | 1817 | } |