@@ -73,7 +73,7 @@ |
||
73 | 73 | |
74 | 74 | /** |
75 | 75 | * Método que entrega el mimetype de un archivo |
76 | - * @param file Ruta hacia el fichero |
|
76 | + * @param file string hacia el fichero |
|
77 | 77 | * @return Mimetype del fichero o =false si no se pudo determinar |
78 | 78 | * @author http://stackoverflow.com/a/23287361 |
79 | 79 | * @version 2015-11-03 |
@@ -49,18 +49,18 @@ discard block |
||
49 | 49 | public static function rmdir($dir) |
50 | 50 | { |
51 | 51 | // List the contents of the directory table |
52 | - $dir_content = scandir ($dir); |
|
52 | + $dir_content = scandir($dir); |
|
53 | 53 | // Is it a directory? |
54 | 54 | if ($dir_content!==false) { |
55 | 55 | // For each directory entry |
56 | 56 | foreach ($dir_content as &$entry) { |
57 | 57 | // Unix symbolic shortcuts, we go |
58 | - if (!in_array ($entry, array ('.','..'))) { |
|
58 | + if (!in_array($entry, array('.', '..'))) { |
|
59 | 59 | // We find the path from the beginning |
60 | - $entry = $dir.DIRECTORY_SEPARATOR. $entry; |
|
60 | + $entry = $dir.DIRECTORY_SEPARATOR.$entry; |
|
61 | 61 | // This entry is not an issue: it clears |
62 | 62 | if (!is_dir($entry)) { |
63 | - unlink ($entry); |
|
63 | + unlink($entry); |
|
64 | 64 | } else { // This entry is a folder, it again on this issue |
65 | 65 | self::rmdir($entry); |
66 | 66 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | } |
69 | 69 | } |
70 | 70 | // It has erased all entries in the folder, we can now erase |
71 | - rmdir ($dir); |
|
71 | + rmdir($dir); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | // enviar archivo |
161 | 161 | if ($options['download']) { |
162 | 162 | ob_clean(); |
163 | - header ('Content-Disposition: attachment; filename='.$file_compressed); |
|
163 | + header('Content-Disposition: attachment; filename='.$file_compressed); |
|
164 | 164 | $mimetype = self::mimetype($dir.DIRECTORY_SEPARATOR.$file_compressed); |
165 | 165 | if ($mimetype) |
166 | - header ('Content-Type: '.$mimetype); |
|
167 | - header ('Content-Length: '.filesize($dir.DIRECTORY_SEPARATOR.$file_compressed)); |
|
166 | + header('Content-Type: '.$mimetype); |
|
167 | + header('Content-Length: '.filesize($dir.DIRECTORY_SEPARATOR.$file_compressed)); |
|
168 | 168 | readfile($dir.DIRECTORY_SEPARATOR.$file_compressed); |
169 | 169 | unlink($dir.DIRECTORY_SEPARATOR.$file_compressed); |
170 | 170 | } |
@@ -80,8 +80,9 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public static function mimetype($file) |
82 | 82 | { |
83 | - if (!function_exists('finfo_open')) |
|
84 | - return false; |
|
83 | + if (!function_exists('finfo_open')) { |
|
84 | + return false; |
|
85 | + } |
|
85 | 86 | $finfo = finfo_open(FILEINFO_MIME_TYPE); |
86 | 87 | $mimetype = finfo_file($finfo, $file); |
87 | 88 | finfo_close($finfo); |
@@ -121,8 +122,11 @@ discard block |
||
121 | 122 | } |
122 | 123 | // si es formato gz y es directorio se cambia a tgz |
123 | 124 | if (is_dir($file)) { |
124 | - if ($options['format']=='gz') $options['format'] = 'tar.gz'; |
|
125 | - else if ($options['format']=='bz2') $options['format'] = 'tar.bz2'; |
|
125 | + if ($options['format']=='gz') { |
|
126 | + $options['format'] = 'tar.gz'; |
|
127 | + } else if ($options['format']=='bz2') { |
|
128 | + $options['format'] = 'tar.bz2'; |
|
129 | + } |
|
126 | 130 | } |
127 | 131 | // obtener directorio que contiene al archivo/directorio y el nombre de este |
128 | 132 | $filepath = $file; |
@@ -162,8 +166,9 @@ discard block |
||
162 | 166 | ob_clean(); |
163 | 167 | header ('Content-Disposition: attachment; filename='.$file_compressed); |
164 | 168 | $mimetype = self::mimetype($dir.DIRECTORY_SEPARATOR.$file_compressed); |
165 | - if ($mimetype) |
|
166 | - header ('Content-Type: '.$mimetype); |
|
169 | + if ($mimetype) { |
|
170 | + header ('Content-Type: '.$mimetype); |
|
171 | + } |
|
167 | 172 | header ('Content-Length: '.filesize($dir.DIRECTORY_SEPARATOR.$file_compressed)); |
168 | 173 | readfile($dir.DIRECTORY_SEPARATOR.$file_compressed); |
169 | 174 | unlink($dir.DIRECTORY_SEPARATOR.$file_compressed); |
@@ -171,8 +176,11 @@ discard block |
||
171 | 176 | // borrar directorio o archivo que se está comprimiendo si así se ha |
172 | 177 | // solicitado |
173 | 178 | if ($options['delete']) { |
174 | - if (is_dir($filepath)) self::rmdir($filepath); |
|
175 | - else unlink($filepath); |
|
179 | + if (is_dir($filepath)) { |
|
180 | + self::rmdir($filepath); |
|
181 | + } else { |
|
182 | + unlink($filepath); |
|
183 | + } |
|
176 | 184 | } |
177 | 185 | } |
178 | 186 |
@@ -58,7 +58,7 @@ |
||
58 | 58 | * Método que escribe un mensaje en la bitácora |
59 | 59 | * @param code Código del mensaje que se desea escribir |
60 | 60 | * @param msg Mensaje que se desea escribir |
61 | - * @param severity Gravedad del mensaje, por defecto LOG_ERR (puede ser cualquiera de las constantes PHP de syslog) |
|
61 | + * @param severity integer del mensaje, por defecto LOG_ERR (puede ser cualquiera de las constantes PHP de syslog) |
|
62 | 62 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
63 | 63 | * @version 2015-09-16 |
64 | 64 | */ |
@@ -65,8 +65,9 @@ discard block |
||
65 | 65 | public static function write($code, $msg = null, $severity = LOG_ERR) |
66 | 66 | { |
67 | 67 | // si no existe la bitácora para la gravedad se crea |
68 | - if (!isset(self::$bitacora[$severity])) |
|
69 | - self::$bitacora[$severity] = []; |
|
68 | + if (!isset(self::$bitacora[$severity])) { |
|
69 | + self::$bitacora[$severity] = []; |
|
70 | + } |
|
70 | 71 | // si el código es un string se copia a msg |
71 | 72 | if (is_string($code)) { |
72 | 73 | $msg = $code; |
@@ -97,8 +98,9 @@ discard block |
||
97 | 98 | */ |
98 | 99 | public static function read($severity = LOG_ERR) |
99 | 100 | { |
100 | - if (!isset(self::$bitacora[$severity])) |
|
101 | - return false; |
|
101 | + if (!isset(self::$bitacora[$severity])) { |
|
102 | + return false; |
|
103 | + } |
|
102 | 104 | return array_pop(self::$bitacora[$severity]); |
103 | 105 | } |
104 | 106 | |
@@ -112,11 +114,13 @@ discard block |
||
112 | 114 | */ |
113 | 115 | public static function readAll($severity = LOG_ERR, $new_first = true) |
114 | 116 | { |
115 | - if (!isset(self::$bitacora[$severity])) |
|
116 | - return []; |
|
117 | + if (!isset(self::$bitacora[$severity])) { |
|
118 | + return []; |
|
119 | + } |
|
117 | 120 | $bitacora = self::$bitacora[$severity]; |
118 | - if ($new_first) |
|
119 | - krsort($bitacora); |
|
121 | + if ($new_first) { |
|
122 | + krsort($bitacora); |
|
123 | + } |
|
120 | 124 | self::$bitacora[$severity] = []; |
121 | 125 | return $bitacora; |
122 | 126 | } |
@@ -163,8 +167,9 @@ discard block |
||
163 | 167 | public function __toString() |
164 | 168 | { |
165 | 169 | $msg = $this->msg ? $this->msg : 'Error código '.$this->code; |
166 | - if (!$this->file) |
|
167 | - return $msg; |
|
170 | + if (!$this->file) { |
|
171 | + return $msg; |
|
172 | + } |
|
168 | 173 | return $msg.' (by '.$this->class.$this->type.$this->function.'() in '.$this->file.' on line '.$this->line.')'; |
169 | 174 | } |
170 | 175 |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | |
141 | 141 | /** |
142 | 142 | * Método para realizar una solicitud al servicio web del SII |
143 | - * @param wsdl Nombre del WSDL que se usará |
|
144 | - * @param request Nombre de la función que se ejecutará en el servicio web |
|
143 | + * @param wsdl string del WSDL que se usará |
|
144 | + * @param request string de la función que se ejecutará en el servicio web |
|
145 | 145 | * @param args Argumentos que se pasarán al servicio web |
146 | 146 | * @param retry Intentos que se realizarán como máximo para obtener respuesta |
147 | 147 | * @return Objeto SimpleXMLElement con la espuesta del servicio web consultado |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @param usuario RUN del usuario que envía el DTE |
226 | 226 | * @param empresa RUT de la empresa emisora del DTE |
227 | 227 | * @param dte Documento XML con el DTE que se desea enviar a SII |
228 | - * @param token Token de autenticación automática ante el SII |
|
228 | + * @param token string de autenticación automática ante el SII |
|
229 | 229 | * @param retry Intentos que se realizarán como máximo para obtener respuesta |
230 | 230 | * @return Respuesta XML desde SII o bien null si no se pudo obtener respuesta |
231 | 231 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | * \endcode |
322 | 322 | * |
323 | 323 | * @param idk IDK de la clave pública del SII. Si no se indica se tratará de determinar con el ambiente que se esté usando |
324 | - * @return Contenido del certificado |
|
324 | + * @return string|false del certificado |
|
325 | 325 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
326 | 326 | * @version 2015-09-16 |
327 | 327 | */ |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | /** |
347 | 347 | * Método que asigna el ambiente que se usará por defecto (si no está |
348 | 348 | * asignado con la constante _LibreDTE_CERTIFICACION_) |
349 | - * @param ambiente Ambiente a usar: Sii::PRODUCCION o Sii::CERTIFICACION |
|
349 | + * @param ambiente integer a usar: Sii::PRODUCCION o Sii::CERTIFICACION |
|
350 | 350 | * @warning No se está verificando SSL en ambiente de certificación |
351 | 351 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
352 | 352 | * @version 2016-08-28 |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | |
382 | 382 | /** |
383 | 383 | * Método que entrega la tasa de IVA vigente |
384 | - * @return Tasa de IVA vigente |
|
384 | + * @return integer de IVA vigente |
|
385 | 385 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
386 | 386 | * @version 2015-09-03 |
387 | 387 | */ |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | /** |
458 | 458 | * Método que entrega la dirección regional según la comuna que se esté |
459 | 459 | * consultando |
460 | - * @param comuna de la sucursal del emior o bien código de la sucursal del SII |
|
460 | + * @param comuna Sii\PDF\Código|null la sucursal del emior o bien código de la sucursal del SII |
|
461 | 461 | * @return Dirección regional del SII |
462 | 462 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
463 | 463 | * @version 2016-06-03 |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | \sasco\LibreDTE\Log::write(Estado::REQUEST_ERROR_SOAP, Estado::get(Estado::REQUEST_ERROR_SOAP, $msg)); |
184 | 184 | return false; |
185 | 185 | } |
186 | - for ($i=0; $i<$retry; $i++) { |
|
186 | + for ($i = 0; $i<$retry; $i++) { |
|
187 | 187 | try { |
188 | 188 | if ($args) { |
189 | 189 | $body = call_user_func_array([$soap, $request], $args); |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
282 | 282 | } |
283 | 283 | // enviar XML al SII |
284 | - for ($i=0; $i<$retry; $i++) { |
|
284 | + for ($i = 0; $i<$retry; $i++) { |
|
285 | 285 | $response = curl_exec($curl); |
286 | 286 | if ($response and $response!='Error 500') |
287 | 287 | break; |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | if ($xml->STATUS!=0) { |
308 | 308 | \sasco\LibreDTE\Log::write( |
309 | 309 | $xml->STATUS, |
310 | - Estado::get($xml->STATUS).(isset($xml->DETAIL)?'. '.implode("\n", (array)$xml->DETAIL->ERROR):'') |
|
310 | + Estado::get($xml->STATUS).(isset($xml->DETAIL) ? '. '.implode("\n", (array)$xml->DETAIL->ERROR) : '') |
|
311 | 311 | ); |
312 | 312 | } |
313 | 313 | return $xml; |
@@ -439,12 +439,12 @@ discard block |
||
439 | 439 | $lines = explode("\n", $response); |
440 | 440 | $n_lines = count($lines); |
441 | 441 | $data = []; |
442 | - for ($i=1; $i<$n_lines; $i++) { |
|
442 | + for ($i = 1; $i<$n_lines; $i++) { |
|
443 | 443 | $row = str_getcsv($lines[$i], ';', ''); |
444 | 444 | unset($lines[$i]); |
445 | 445 | if (!isset($row[5])) |
446 | 446 | continue; |
447 | - for ($j=0; $j<6; $j++) |
|
447 | + for ($j = 0; $j<6; $j++) |
|
448 | 448 | $row[$j] = trim($row[$j]); |
449 | 449 | $row[1] = utf8_decode($row[1]); |
450 | 450 | $row[4] = strtolower($row[4]); |
@@ -124,8 +124,9 @@ discard block |
||
124 | 124 | // entregar WSDL local (modificados para ambiente de certificación) |
125 | 125 | if ($ambiente==self::CERTIFICACION) { |
126 | 126 | $wsdl = dirname(dirname(__FILE__)).'/wsdl/'.self::$config['servidor'][$ambiente].'/'.$servicio.'.jws'; |
127 | - if (is_readable($wsdl)) |
|
128 | - return $wsdl; |
|
127 | + if (is_readable($wsdl)) { |
|
128 | + return $wsdl; |
|
129 | + } |
|
129 | 130 | } |
130 | 131 | // entregar WSDL oficial desde SII |
131 | 132 | $location = isset(self::$config['wsdl'][$servicio]) ? self::$config['wsdl'][$servicio] : self::$config['wsdl']['*']; |
@@ -154,10 +155,12 @@ discard block |
||
154 | 155 | $retry = (int)$args; |
155 | 156 | $args = null; |
156 | 157 | } |
157 | - if (!$retry) |
|
158 | - $retry = self::$retry; |
|
159 | - if ($args and !is_array($args)) |
|
160 | - $args = [$args]; |
|
158 | + if (!$retry) { |
|
159 | + $retry = self::$retry; |
|
160 | + } |
|
161 | + if ($args and !is_array($args)) { |
|
162 | + $args = [$args]; |
|
163 | + } |
|
161 | 164 | if (!self::$verificar_ssl) { |
162 | 165 | if (self::getAmbiente()==self::PRODUCCION) { |
163 | 166 | $msg = Estado::get(Estado::ENVIO_SSL_SIN_VERIFICAR); |
@@ -255,8 +258,9 @@ discard block |
||
255 | 258 | ), |
256 | 259 | ]; |
257 | 260 | // definir reintentos si no se pasaron |
258 | - if (!$retry) |
|
259 | - $retry = self::$retry; |
|
261 | + if (!$retry) { |
|
262 | + $retry = self::$retry; |
|
263 | + } |
|
260 | 264 | // crear sesión curl con sus opciones |
261 | 265 | $curl = curl_init(); |
262 | 266 | $header = [ |
@@ -283,16 +287,19 @@ discard block |
||
283 | 287 | // enviar XML al SII |
284 | 288 | for ($i=0; $i<$retry; $i++) { |
285 | 289 | $response = curl_exec($curl); |
286 | - if ($response and $response!='Error 500') |
|
287 | - break; |
|
290 | + if ($response and $response!='Error 500') { |
|
291 | + break; |
|
292 | + } |
|
288 | 293 | } |
289 | 294 | unlink($file); |
290 | 295 | // verificar respuesta del envío y entregar error en caso que haya uno |
291 | 296 | if (!$response or $response=='Error 500') { |
292 | - if (!$response) |
|
293 | - \sasco\LibreDTE\Log::write(Estado::ENVIO_ERROR_CURL, Estado::get(Estado::ENVIO_ERROR_CURL, curl_error($curl))); |
|
294 | - if ($response=='Error 500') |
|
295 | - \sasco\LibreDTE\Log::write(Estado::ENVIO_ERROR_500, Estado::get(Estado::ENVIO_ERROR_500)); |
|
297 | + if (!$response) { |
|
298 | + \sasco\LibreDTE\Log::write(Estado::ENVIO_ERROR_CURL, Estado::get(Estado::ENVIO_ERROR_CURL, curl_error($curl))); |
|
299 | + } |
|
300 | + if ($response=='Error 500') { |
|
301 | + \sasco\LibreDTE\Log::write(Estado::ENVIO_ERROR_500, Estado::get(Estado::ENVIO_ERROR_500)); |
|
302 | + } |
|
296 | 303 | return false; |
297 | 304 | } |
298 | 305 | // cerrar sesión curl |
@@ -330,8 +337,9 @@ discard block |
||
330 | 337 | // si se pasó un idk y existe el archivo asociado se entrega |
331 | 338 | if ($idk) { |
332 | 339 | $cert = dirname(dirname(__FILE__)).'/certs/'.$idk.'.cer'; |
333 | - if (is_readable($cert)) |
|
334 | - return file_get_contents($cert); |
|
340 | + if (is_readable($cert)) { |
|
341 | + return file_get_contents($cert); |
|
342 | + } |
|
335 | 343 | } |
336 | 344 | // buscar certificado y entregar si existe o =false si no |
337 | 345 | $ambiente = self::getAmbiente(); |
@@ -371,10 +379,11 @@ discard block |
||
371 | 379 | public static function getAmbiente($ambiente = null) |
372 | 380 | { |
373 | 381 | if ($ambiente===null) { |
374 | - if (defined('_LibreDTE_CERTIFICACION_')) |
|
375 | - $ambiente = (int)_LibreDTE_CERTIFICACION_; |
|
376 | - else |
|
377 | - $ambiente = self::$ambiente; |
|
382 | + if (defined('_LibreDTE_CERTIFICACION_')) { |
|
383 | + $ambiente = (int)_LibreDTE_CERTIFICACION_; |
|
384 | + } else { |
|
385 | + $ambiente = self::$ambiente; |
|
386 | + } |
|
378 | 387 | } |
379 | 388 | return $ambiente; |
380 | 389 | } |
@@ -400,8 +409,9 @@ discard block |
||
400 | 409 | { |
401 | 410 | // solicitar token |
402 | 411 | $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($Firma); |
403 | - if (!$token) |
|
404 | - return false; |
|
412 | + if (!$token) { |
|
413 | + return false; |
|
414 | + } |
|
405 | 415 | // definir ambiente y servidor |
406 | 416 | $ambiente = self::getAmbiente($ambiente); |
407 | 417 | $servidor = self::$config['servidor'][$ambiente]; |
@@ -430,8 +440,9 @@ discard block |
||
430 | 440 | } |
431 | 441 | // realizar consulta curl |
432 | 442 | $response = curl_exec($curl); |
433 | - if (!$response) |
|
434 | - return false; |
|
443 | + if (!$response) { |
|
444 | + return false; |
|
445 | + } |
|
435 | 446 | // cerrar sesión curl |
436 | 447 | curl_close($curl); |
437 | 448 | // entregar datos del archivo CSV |
@@ -442,10 +453,12 @@ discard block |
||
442 | 453 | for ($i=1; $i<$n_lines; $i++) { |
443 | 454 | $row = str_getcsv($lines[$i], ';', ''); |
444 | 455 | unset($lines[$i]); |
445 | - if (!isset($row[5])) |
|
446 | - continue; |
|
447 | - for ($j=0; $j<6; $j++) |
|
448 | - $row[$j] = trim($row[$j]); |
|
456 | + if (!isset($row[5])) { |
|
457 | + continue; |
|
458 | + } |
|
459 | + for ($j=0; $j<6; $j++) { |
|
460 | + $row[$j] = trim($row[$j]); |
|
461 | + } |
|
449 | 462 | $row[1] = utf8_decode($row[1]); |
450 | 463 | $row[4] = strtolower($row[4]); |
451 | 464 | $row[5] = strtolower($row[5]); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * WSDL producción: https://palena.sii.cl/DTEWS/CrSeed.jws?WSDL |
58 | 58 | * WSDL certificación: https://maullin.sii.cl/DTEWS/CrSeed.jws?WSDL |
59 | 59 | * |
60 | - * @return Semilla obtenida desde SII |
|
60 | + * @return false|string obtenida desde SII |
|
61 | 61 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
62 | 62 | * @version 2015-09-17 |
63 | 63 | */ |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | |
77 | 77 | /** |
78 | 78 | * Método que firma una semilla previamente obtenida |
79 | - * @param seed Semilla obtenida desde SII |
|
79 | + * @param seed string obtenida desde SII |
|
80 | 80 | * @param Firma objeto de la Firma electrónica o arreglo con configuración de la misma |
81 | - * @return Solicitud de token con la semilla incorporada y firmada |
|
81 | + * @return \sasco\LibreDTE\Argumentos|null de token con la semilla incorporada y firmada |
|
82 | 82 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
83 | 83 | * @version 2015-09-17 |
84 | 84 | */ |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * WSDL certificación: https://maullin.sii.cl/DTEWS/GetTokenFromSeed.jws?WSDL |
114 | 114 | * |
115 | 115 | * @param Firma objeto de la Firma electrónica o arreglo con configuración de la misma |
116 | - * @return Token para autenticación en SII o =false si no se pudo obtener |
|
116 | + * @return false|string para autenticación en SII o =false si no se pudo obtener |
|
117 | 117 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
118 | 118 | * @version 2015-11-03 |
119 | 119 | */ |
@@ -84,8 +84,9 @@ discard block |
||
84 | 84 | */ |
85 | 85 | private static function getTokenRequest($seed, $Firma = []) |
86 | 86 | { |
87 | - if (is_array($Firma)) |
|
88 | - $Firma = new \sasco\LibreDTE\FirmaElectronica($Firma); |
|
87 | + if (is_array($Firma)) { |
|
88 | + $Firma = new \sasco\LibreDTE\FirmaElectronica($Firma); |
|
89 | + } |
|
89 | 90 | $seedSigned = $Firma->signXML( |
90 | 91 | (new \sasco\LibreDTE\XML())->generate([ |
91 | 92 | 'getToken' => [ |
@@ -119,11 +120,17 @@ discard block |
||
119 | 120 | */ |
120 | 121 | public static function getToken($Firma = []) |
121 | 122 | { |
122 | - if (!$Firma) return false; |
|
123 | + if (!$Firma) { |
|
124 | + return false; |
|
125 | + } |
|
123 | 126 | $semilla = self::getSeed(); |
124 | - if (!$semilla) return false; |
|
127 | + if (!$semilla) { |
|
128 | + return false; |
|
129 | + } |
|
125 | 130 | $requestFirmado = self::getTokenRequest($semilla, $Firma); |
126 | - if (!$requestFirmado) return false; |
|
131 | + if (!$requestFirmado) { |
|
132 | + return false; |
|
133 | + } |
|
127 | 134 | $xml = \sasco\LibreDTE\Sii::request('GetTokenFromSeed', 'getToken', $requestFirmado); |
128 | 135 | if ($xml===false or (string)$xml->xpath('/SII:RESPUESTA/SII:RESP_HDR/ESTADO')[0]!=='00') { |
129 | 136 | \sasco\LibreDTE\Log::write( |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Método que entrega el ID del documento |
62 | - * @return ID del libro |
|
62 | + * @return string del libro |
|
63 | 63 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
64 | 64 | * @version 2015-12-14 |
65 | 65 | */ |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Método para asignar la caratula |
73 | - * @param Firma Objeto con la firma electrónica |
|
73 | + * @param Firma \sasco\LibreDTE\FirmaElectronica con la firma electrónica |
|
74 | 74 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
75 | 75 | * @version 2015-12-14 |
76 | 76 | */ |
@@ -169,10 +169,12 @@ |
||
169 | 169 | */ |
170 | 170 | public function toArray() |
171 | 171 | { |
172 | - if (!$this->xml) |
|
173 | - return false; |
|
174 | - if (!$this->arreglo) |
|
175 | - $this->arreglo = $this->xml->toArray(); |
|
172 | + if (!$this->xml) { |
|
173 | + return false; |
|
174 | + } |
|
175 | + if (!$this->arreglo) { |
|
176 | + $this->arreglo = $this->xml->toArray(); |
|
177 | + } |
|
176 | 178 | return $this->arreglo; |
177 | 179 | } |
178 | 180 |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | |
237 | 237 | /** |
238 | 238 | * Método que entrega el tipo de DTE |
239 | - * @return Tipo de dte, ej: 33 (factura electrónica) |
|
239 | + * @return string de dte, ej: 33 (factura electrónica) |
|
240 | 240 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
241 | 241 | * @version 2015-09-02 |
242 | 242 | */ |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | |
248 | 248 | /** |
249 | 249 | * Método que entrega el folio del DTE |
250 | - * @return Folio del DTE |
|
250 | + * @return string del DTE |
|
251 | 251 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
252 | 252 | * @version 2015-09-02 |
253 | 253 | */ |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | |
259 | 259 | /** |
260 | 260 | * Método que entrega rut del emisor del DTE |
261 | - * @return RUT del emiro |
|
261 | + * @return string del emiro |
|
262 | 262 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
263 | 263 | * @version 2015-09-07 |
264 | 264 | */ |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | |
275 | 275 | /** |
276 | 276 | * Método que entrega rut del receptor del DTE |
277 | - * @return RUT del emiro |
|
277 | + * @return string del emiro |
|
278 | 278 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
279 | 279 | * @version 2015-09-07 |
280 | 280 | */ |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | |
291 | 291 | /** |
292 | 292 | * Método que entrega fecha de emisión del DTE |
293 | - * @return Fecha de emisión en formato AAAA-MM-DD |
|
293 | + * @return string de emisión en formato AAAA-MM-DD |
|
294 | 294 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
295 | 295 | * @version 2015-09-07 |
296 | 296 | */ |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | |
379 | 379 | /** |
380 | 380 | * Método que realiza el timbrado del DTE |
381 | - * @param Folios Objeto de los Folios con los que se desea timbrar |
|
381 | + * @param Folios Folios de los Folios con los que se desea timbrar |
|
382 | 382 | * @return =true si se pudo timbrar o =false en caso de error |
383 | 383 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
384 | 384 | * @version 2016-09-01 |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | |
465 | 465 | /** |
466 | 466 | * Método que realiza la firma del DTE |
467 | - * @param Firma objeto que representa la Firma Electrónca |
|
467 | + * @param Firma \sasco\LibreDTE\FirmaElectronica que representa la Firma Electrónca |
|
468 | 468 | * @return =true si el DTE pudo ser fimado o =false si no se pudo firmar |
469 | 469 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
470 | 470 | * @version 2015-09-17 |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | |
488 | 488 | /** |
489 | 489 | * Método que entrega el DTE en XML |
490 | - * @return XML con el DTE (podría: con o sin timbre y con o sin firma) |
|
490 | + * @return string con el DTE (podría: con o sin timbre y con o sin firma) |
|
491 | 491 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
492 | 492 | * @version 2015-08-20 |
493 | 493 | */ |
@@ -1595,7 +1595,7 @@ discard block |
||
1595 | 1595 | * - Firma del DTE |
1596 | 1596 | * - RUT del emisor (si se pasó uno para comparar) |
1597 | 1597 | * - RUT del receptor (si se pasó uno para comparar) |
1598 | - * @return Código del estado de la validación |
|
1598 | + * @return integer del estado de la validación |
|
1599 | 1599 | * @warning No se está validando la firma |
1600 | 1600 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
1601 | 1601 | * @version 2015-09-08 |
@@ -1706,7 +1706,7 @@ discard block |
||
1706 | 1706 | |
1707 | 1707 | /** |
1708 | 1708 | * Método que obtiene el estado del DTE |
1709 | - * @param Firma objeto que representa la Firma Electrónca |
|
1709 | + * @param Firma \sasco\LibreDTE\FirmaElectronica que representa la Firma Electrónca |
|
1710 | 1710 | * @return Arreglo con el estado del DTE |
1711 | 1711 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
1712 | 1712 | * @version 2015-10-24 |
@@ -1747,7 +1747,7 @@ discard block |
||
1747 | 1747 | |
1748 | 1748 | /** |
1749 | 1749 | * Método que obtiene el estado avanzado del DTE |
1750 | - * @param Firma objeto que representa la Firma Electrónca |
|
1750 | + * @param Firma \sasco\LibreDTE\FirmaElectronica que representa la Firma Electrónca |
|
1751 | 1751 | * @return Arreglo con el estado del DTE |
1752 | 1752 | * @todo Corregir warning y también definir que se retornará (sobre todo en caso de error) |
1753 | 1753 | * @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], $parent); |
|
142 | + $this->xml->generate($datos+['TED' => null], $parent); |
|
143 | 143 | $this->datos = $datos; |
144 | 144 | if ($normalizar and !$this->verificarDatos()) { |
145 | 145 | return false; |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); |
362 | 362 | $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', ''); |
363 | 363 | $TED = $xml->getFlattened('/'); |
364 | - return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1']) != 'ISO-8859-1' ? utf8_decode($TED) : $TED; |
|
364 | + return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1'])!='ISO-8859-1' ? utf8_decode($TED) : $TED; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | /** |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | { |
375 | 375 | $datos = $this->getDatos(); |
376 | 376 | $idk = !empty($datos['TED']['DD']['CAF']['DA']['IDK']) ? (int)$datos['TED']['DD']['CAF']['DA']['IDK'] : null; |
377 | - return $idk ? $idk === 100 : null; |
|
377 | + return $idk ? $idk===100 : null; |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | /** |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | { |
509 | 509 | $this->getDatos(); |
510 | 510 | // generar resumen |
511 | - $resumen = [ |
|
511 | + $resumen = [ |
|
512 | 512 | 'TpoDoc' => (int)$this->datos['Encabezado']['IdDoc']['TipoDTE'], |
513 | 513 | 'NroDoc' => (int)$this->datos['Encabezado']['IdDoc']['Folio'], |
514 | 514 | 'TasaImp' => 0, |
@@ -553,17 +553,17 @@ discard block |
||
553 | 553 | */ |
554 | 554 | private function calcularNetoIVA($total, $tasa = null) |
555 | 555 | { |
556 | - if ($tasa === 0 or $tasa === false) |
|
556 | + if ($tasa===0 or $tasa===false) |
|
557 | 557 | return [0, 0]; |
558 | - if ($tasa === null) |
|
558 | + if ($tasa===null) |
|
559 | 559 | $tasa = \sasco\LibreDTE\Sii::getIVA(); |
560 | 560 | // WARNING: el IVA obtenido puede no ser el NETO*(TASA/100) |
561 | 561 | // se calcula el monto neto y luego se obtiene el IVA haciendo la resta |
562 | 562 | // entre el total y el neto, ya que hay casos de borde como: |
563 | 563 | // - BRUTO: 680 => NETO: 571 e IVA: 108 => TOTAL: 679 |
564 | 564 | // - BRUTO: 86710 => NETO: 72866 e IVA: 13845 => TOTAL: 86711 |
565 | - $neto = round($total / (1+($tasa/100))); |
|
566 | - $iva = $total - $neto; |
|
565 | + $neto = round($total / (1+($tasa / 100))); |
|
566 | + $iva = $total-$neto; |
|
567 | 567 | return [$neto, $iva]; |
568 | 568 | } |
569 | 569 | |
@@ -1309,12 +1309,12 @@ discard block |
||
1309 | 1309 | ); |
1310 | 1310 | // aplicar descuento |
1311 | 1311 | if ($d['DescuentoPct']) { |
1312 | - $d['DescuentoMonto'] = round($d['MontoItem'] * (int)$d['DescuentoPct']/100); |
|
1312 | + $d['DescuentoMonto'] = round($d['MontoItem'] * (int)$d['DescuentoPct'] / 100); |
|
1313 | 1313 | } |
1314 | 1314 | $d['MontoItem'] -= $d['DescuentoMonto']; |
1315 | 1315 | // aplicar recargo |
1316 | 1316 | if ($d['RecargoPct']) { |
1317 | - $d['RecargoMonto'] = round($d['MontoItem'] * (int)$d['RecargoPct']/100); |
|
1317 | + $d['RecargoMonto'] = round($d['MontoItem'] * (int)$d['RecargoPct'] / 100); |
|
1318 | 1318 | } |
1319 | 1319 | $d['MontoItem'] += $d['RecargoMonto']; |
1320 | 1320 | // aproximar monto del item |
@@ -1400,7 +1400,7 @@ discard block |
||
1400 | 1400 | } |
1401 | 1401 | $valor = |
1402 | 1402 | $dr['TpoValor']=='%' |
1403 | - ? $this->round(($dr['ValorDR']/100)*$datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
1403 | + ? $this->round(($dr['ValorDR'] / 100) * $datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
1404 | 1404 | : $dr['ValorDR'] |
1405 | 1405 | ; |
1406 | 1406 | // aplicar descuento |
@@ -1473,7 +1473,7 @@ discard block |
||
1473 | 1473 | // si el monto no existe se asigna |
1474 | 1474 | if ($datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp']===null) { |
1475 | 1475 | $datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp'] = round( |
1476 | - $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp']/100 |
|
1476 | + $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp'] / 100 |
|
1477 | 1477 | ); |
1478 | 1478 | } |
1479 | 1479 | } |
@@ -1481,7 +1481,7 @@ discard block |
||
1481 | 1481 | if (isset($datos['Encabezado']['Totales']['ImptoReten']) and is_array($datos['Encabezado']['Totales']['ImptoReten'])) { |
1482 | 1482 | $codigos = array_keys($montos); |
1483 | 1483 | $n_impuestos = count($datos['Encabezado']['Totales']['ImptoReten']); |
1484 | - for ($i=0; $i<$n_impuestos; $i++) { |
|
1484 | + for ($i = 0; $i<$n_impuestos; $i++) { |
|
1485 | 1485 | if (!in_array($datos['Encabezado']['Totales']['ImptoReten'][$i]['TipoImp'], $codigos)) { |
1486 | 1486 | unset($datos['Encabezado']['Totales']['ImptoReten'][$i]); |
1487 | 1487 | } |
@@ -1509,7 +1509,7 @@ discard block |
||
1509 | 1509 | } else { |
1510 | 1510 | if (empty($datos['Encabezado']['Totales']['IVA']) and !empty($datos['Encabezado']['Totales']['TasaIVA'])) { |
1511 | 1511 | $datos['Encabezado']['Totales']['IVA'] = round( |
1512 | - $datos['Encabezado']['Totales']['MntNeto']*($datos['Encabezado']['Totales']['TasaIVA']/100) |
|
1512 | + $datos['Encabezado']['Totales']['MntNeto'] * ($datos['Encabezado']['Totales']['TasaIVA'] / 100) |
|
1513 | 1513 | ); |
1514 | 1514 | } |
1515 | 1515 | } |
@@ -1533,7 +1533,7 @@ discard block |
||
1533 | 1533 | if (ImpuestosAdicionales::getTipo($ImptoReten['TipoImp'])=='R') { |
1534 | 1534 | $datos['Encabezado']['Totales']['MntTotal'] -= $ImptoReten['MontoImp']; |
1535 | 1535 | if ($ImptoReten['MontoImp']!=$datos['Encabezado']['Totales']['IVA']) { |
1536 | - $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA'] - $ImptoReten['MontoImp']; |
|
1536 | + $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA']-$ImptoReten['MontoImp']; |
|
1537 | 1537 | } |
1538 | 1538 | } |
1539 | 1539 | // si es adicional se suma al total |
@@ -1679,7 +1679,7 @@ discard block |
||
1679 | 1679 | $SignatureValue = $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue; |
1680 | 1680 | $X509Certificate = $Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue; |
1681 | 1681 | $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap(trim($X509Certificate), 64, "\n", true)."\n".'-----END CERTIFICATE----- '; |
1682 | - $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false; |
|
1682 | + $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false; |
|
1683 | 1683 | return $valid; |
1684 | 1684 | //return $valid and $DigestValue===base64_encode(sha1($Documento->C14N(), true)); |
1685 | 1685 | } |
@@ -57,10 +57,11 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct($datos, $normalizar = true) |
59 | 59 | { |
60 | - if (is_array($datos)) |
|
61 | - $this->setDatos($datos, $normalizar); |
|
62 | - else if (is_string($datos)) |
|
63 | - $this->loadXML($datos); |
|
60 | + if (is_array($datos)) { |
|
61 | + $this->setDatos($datos, $normalizar); |
|
62 | + } else if (is_string($datos)) { |
|
63 | + $this->loadXML($datos); |
|
64 | + } |
|
64 | 65 | $this->timestamp = date('Y-m-d\TH:i:s'); |
65 | 66 | } |
66 | 67 | |
@@ -121,8 +122,9 @@ discard block |
||
121 | 122 | if ($normalizar) { |
122 | 123 | $this->normalizar($datos); |
123 | 124 | $method = 'normalizar_'.$this->tipo; |
124 | - if (method_exists($this, $method)) |
|
125 | - $this->$method($datos); |
|
125 | + if (method_exists($this, $method)) { |
|
126 | + $this->$method($datos); |
|
127 | + } |
|
126 | 128 | $this->normalizar_final($datos); |
127 | 129 | } |
128 | 130 | $this->tipo_general = $this->getTipoGeneral($this->tipo); |
@@ -199,8 +201,9 @@ discard block |
||
199 | 201 | */ |
200 | 202 | public function getJSON() |
201 | 203 | { |
202 | - if (!$this->getDatos()) |
|
203 | - return false; |
|
204 | + if (!$this->getDatos()) { |
|
205 | + return false; |
|
206 | + } |
|
204 | 207 | return json_encode($this->datos, JSON_PRETTY_PRINT); |
205 | 208 | } |
206 | 209 | |
@@ -225,9 +228,10 @@ discard block |
||
225 | 228 | */ |
226 | 229 | private function getTipoGeneral($dte) |
227 | 230 | { |
228 | - foreach ($this->tipos as $tipo => $codigos) |
|
229 | - if (in_array($dte, $codigos)) |
|
231 | + foreach ($this->tipos as $tipo => $codigos) { |
|
232 | + if (in_array($dte, $codigos)) |
|
230 | 233 | return $tipo; |
234 | + } |
|
231 | 235 | \sasco\LibreDTE\Log::write( |
232 | 236 | \sasco\LibreDTE\Estado::DTE_ERROR_TIPO, |
233 | 237 | \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::DTE_ERROR_TIPO, $dte) |
@@ -266,10 +270,12 @@ discard block |
||
266 | 270 | public function getEmisor() |
267 | 271 | { |
268 | 272 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Emisor/RUTEmisor')->item(0); |
269 | - if ($nodo) |
|
270 | - return $nodo->nodeValue; |
|
271 | - if (!$this->getDatos()) |
|
272 | - return false; |
|
273 | + if ($nodo) { |
|
274 | + return $nodo->nodeValue; |
|
275 | + } |
|
276 | + if (!$this->getDatos()) { |
|
277 | + return false; |
|
278 | + } |
|
273 | 279 | return $this->datos['Encabezado']['Emisor']['RUTEmisor']; |
274 | 280 | } |
275 | 281 | |
@@ -282,10 +288,12 @@ discard block |
||
282 | 288 | public function getReceptor() |
283 | 289 | { |
284 | 290 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Receptor/RUTRecep')->item(0); |
285 | - if ($nodo) |
|
286 | - return $nodo->nodeValue; |
|
287 | - if (!$this->getDatos()) |
|
288 | - return false; |
|
291 | + if ($nodo) { |
|
292 | + return $nodo->nodeValue; |
|
293 | + } |
|
294 | + if (!$this->getDatos()) { |
|
295 | + return false; |
|
296 | + } |
|
289 | 297 | return $this->datos['Encabezado']['Receptor']['RUTRecep']; |
290 | 298 | } |
291 | 299 | |
@@ -298,10 +306,12 @@ discard block |
||
298 | 306 | public function getFechaEmision() |
299 | 307 | { |
300 | 308 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/IdDoc/FchEmis')->item(0); |
301 | - if ($nodo) |
|
302 | - return $nodo->nodeValue; |
|
303 | - if (!$this->getDatos()) |
|
304 | - return false; |
|
309 | + if ($nodo) { |
|
310 | + return $nodo->nodeValue; |
|
311 | + } |
|
312 | + if (!$this->getDatos()) { |
|
313 | + return false; |
|
314 | + } |
|
305 | 315 | return $this->datos['Encabezado']['IdDoc']['FchEmis']; |
306 | 316 | } |
307 | 317 | |
@@ -314,10 +324,12 @@ discard block |
||
314 | 324 | public function getMontoTotal() |
315 | 325 | { |
316 | 326 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Totales/MntTotal')->item(0); |
317 | - if ($nodo) |
|
318 | - return $nodo->nodeValue; |
|
319 | - if (!$this->getDatos()) |
|
320 | - return false; |
|
327 | + if ($nodo) { |
|
328 | + return $nodo->nodeValue; |
|
329 | + } |
|
330 | + if (!$this->getDatos()) { |
|
331 | + return false; |
|
332 | + } |
|
321 | 333 | return $this->datos['Encabezado']['Totales']['MntTotal']; |
322 | 334 | } |
323 | 335 | |
@@ -330,10 +342,12 @@ discard block |
||
330 | 342 | public function getMoneda() |
331 | 343 | { |
332 | 344 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Totales/TpoMoneda')->item(0); |
333 | - if ($nodo) |
|
334 | - return $nodo->nodeValue; |
|
335 | - if (!$this->getDatos()) |
|
336 | - return false; |
|
345 | + if ($nodo) { |
|
346 | + return $nodo->nodeValue; |
|
347 | + } |
|
348 | + if (!$this->getDatos()) { |
|
349 | + return false; |
|
350 | + } |
|
337 | 351 | return $this->datos['Encabezado']['Totales']['TpoMoneda']; |
338 | 352 | } |
339 | 353 | |
@@ -355,8 +369,9 @@ discard block |
||
355 | 369 | return false;*/ |
356 | 370 | $xml = new \sasco\LibreDTE\XML(); |
357 | 371 | $TED = $this->xml->getElementsByTagName('TED')->item(0); |
358 | - if (!$TED) |
|
359 | - return '<TED/>'; |
|
372 | + if (!$TED) { |
|
373 | + return '<TED/>'; |
|
374 | + } |
|
360 | 375 | $xml->loadXML($TED->C14N()); |
361 | 376 | $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); |
362 | 377 | $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', ''); |
@@ -553,10 +568,12 @@ discard block |
||
553 | 568 | */ |
554 | 569 | private function calcularNetoIVA($total, $tasa = null) |
555 | 570 | { |
556 | - if ($tasa === 0 or $tasa === false) |
|
557 | - return [0, 0]; |
|
558 | - if ($tasa === null) |
|
559 | - $tasa = \sasco\LibreDTE\Sii::getIVA(); |
|
571 | + if ($tasa === 0 or $tasa === false) { |
|
572 | + return [0, 0]; |
|
573 | + } |
|
574 | + if ($tasa === null) { |
|
575 | + $tasa = \sasco\LibreDTE\Sii::getIVA(); |
|
576 | + } |
|
560 | 577 | // WARNING: el IVA obtenido puede no ser el NETO*(TASA/100) |
561 | 578 | // se calcula el monto neto y luego se obtiene el IVA haciendo la resta |
562 | 579 | // entre el total y el neto, ya que hay casos de borde como: |
@@ -665,8 +682,9 @@ discard block |
||
665 | 682 | } |
666 | 683 | // si existe descuento o recargo global se normalizan |
667 | 684 | if (!empty($datos['DscRcgGlobal'])) { |
668 | - if (!isset($datos['DscRcgGlobal'][0])) |
|
669 | - $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
685 | + if (!isset($datos['DscRcgGlobal'][0])) { |
|
686 | + $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
687 | + } |
|
670 | 688 | $NroLinDR = 1; |
671 | 689 | foreach ($datos['DscRcgGlobal'] as &$dr) { |
672 | 690 | $dr = array_merge([ |
@@ -676,8 +694,9 @@ discard block |
||
676 | 694 | } |
677 | 695 | // si existe una o más referencias se normalizan |
678 | 696 | if (!empty($datos['Referencia'])) { |
679 | - if (!isset($datos['Referencia'][0])) |
|
680 | - $datos['Referencia'] = [$datos['Referencia']]; |
|
697 | + if (!isset($datos['Referencia'][0])) { |
|
698 | + $datos['Referencia'] = [$datos['Referencia']]; |
|
699 | + } |
|
681 | 700 | $NroLinRef = 1; |
682 | 701 | foreach ($datos['Referencia'] as &$r) { |
683 | 702 | $r = array_merge([ |
@@ -707,8 +726,9 @@ discard block |
||
707 | 726 | // normalizar montos de pagos programados |
708 | 727 | if (is_array($datos['Encabezado']['IdDoc']['MntPagos'])) { |
709 | 728 | $montos = 0; |
710 | - if (!isset($datos['Encabezado']['IdDoc']['MntPagos'][0])) |
|
711 | - $datos['Encabezado']['IdDoc']['MntPagos'] = [$datos['Encabezado']['IdDoc']['MntPagos']]; |
|
729 | + if (!isset($datos['Encabezado']['IdDoc']['MntPagos'][0])) { |
|
730 | + $datos['Encabezado']['IdDoc']['MntPagos'] = [$datos['Encabezado']['IdDoc']['MntPagos']]; |
|
731 | + } |
|
712 | 732 | foreach ($datos['Encabezado']['IdDoc']['MntPagos'] as &$MntPagos) { |
713 | 733 | $MntPagos = array_merge([ |
714 | 734 | 'FchPago' => null, |
@@ -1240,8 +1260,9 @@ discard block |
||
1240 | 1260 | */ |
1241 | 1261 | private function normalizar_detalle(array &$datos) |
1242 | 1262 | { |
1243 | - if (!isset($datos['Detalle'][0])) |
|
1244 | - $datos['Detalle'] = [$datos['Detalle']]; |
|
1263 | + if (!isset($datos['Detalle'][0])) { |
|
1264 | + $datos['Detalle'] = [$datos['Detalle']]; |
|
1265 | + } |
|
1245 | 1266 | $item = 1; |
1246 | 1267 | foreach ($datos['Detalle'] as &$d) { |
1247 | 1268 | $d = array_merge([ |
@@ -1300,8 +1321,9 @@ discard block |
||
1300 | 1321 | ]; |
1301 | 1322 | } |
1302 | 1323 | if ($d['PrcItem']) { |
1303 | - if (!$d['QtyItem']) |
|
1304 | - $d['QtyItem'] = 1; |
|
1324 | + if (!$d['QtyItem']) { |
|
1325 | + $d['QtyItem'] = 1; |
|
1326 | + } |
|
1305 | 1327 | if (empty($d['MontoItem'])) { |
1306 | 1328 | $d['MontoItem'] = $this->round( |
1307 | 1329 | $d['QtyItem'] * $d['PrcItem'], |
@@ -1367,8 +1389,9 @@ discard block |
||
1367 | 1389 | private function normalizar_aplicar_descuentos_recargos(array &$datos) |
1368 | 1390 | { |
1369 | 1391 | if (!empty($datos['DscRcgGlobal'])) { |
1370 | - if (!isset($datos['DscRcgGlobal'][0])) |
|
1371 | - $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
1392 | + if (!isset($datos['DscRcgGlobal'][0])) { |
|
1393 | + $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
1394 | + } |
|
1372 | 1395 | foreach ($datos['DscRcgGlobal'] as &$dr) { |
1373 | 1396 | $dr = array_merge([ |
1374 | 1397 | 'NroLinDR' => false, |
@@ -1435,8 +1458,9 @@ discard block |
||
1435 | 1458 | $montos = []; |
1436 | 1459 | foreach ($datos['Detalle'] as &$d) { |
1437 | 1460 | if (!empty($d['CodImpAdic'])) { |
1438 | - if (!isset($montos[$d['CodImpAdic']])) |
|
1439 | - $montos[$d['CodImpAdic']] = 0; |
|
1461 | + if (!isset($montos[$d['CodImpAdic']])) { |
|
1462 | + $montos[$d['CodImpAdic']] = 0; |
|
1463 | + } |
|
1440 | 1464 | $montos[$d['CodImpAdic']] += $d['MontoItem']; |
1441 | 1465 | } |
1442 | 1466 | } |
@@ -1515,10 +1539,12 @@ discard block |
||
1515 | 1539 | } |
1516 | 1540 | if (empty($datos['Encabezado']['Totales']['MntTotal'])) { |
1517 | 1541 | $datos['Encabezado']['Totales']['MntTotal'] = $datos['Encabezado']['Totales']['MntNeto']; |
1518 | - if (!empty($datos['Encabezado']['Totales']['IVA'])) |
|
1519 | - $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['IVA']; |
|
1520 | - if (!empty($datos['Encabezado']['Totales']['MntExe'])) |
|
1521 | - $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['MntExe']; |
|
1542 | + if (!empty($datos['Encabezado']['Totales']['IVA'])) { |
|
1543 | + $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['IVA']; |
|
1544 | + } |
|
1545 | + if (!empty($datos['Encabezado']['Totales']['MntExe'])) { |
|
1546 | + $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['MntExe']; |
|
1547 | + } |
|
1522 | 1548 | } |
1523 | 1549 | } else { |
1524 | 1550 | if (!$datos['Encabezado']['Totales']['MntTotal'] and !empty($datos['Encabezado']['Totales']['MntExe'])) { |
@@ -1544,8 +1570,10 @@ discard block |
||
1544 | 1570 | } |
1545 | 1571 | // si hay impuesto de crédito a constructoras del 65% se descuenta del total |
1546 | 1572 | if (!empty($datos['Encabezado']['Totales']['CredEC'])) { |
1547 | - if ($datos['Encabezado']['Totales']['CredEC']===true) |
|
1548 | - $datos['Encabezado']['Totales']['CredEC'] = round($datos['Encabezado']['Totales']['IVA'] * 0.65); // TODO: mover a constante o método |
|
1573 | + if ($datos['Encabezado']['Totales']['CredEC']===true) { |
|
1574 | + $datos['Encabezado']['Totales']['CredEC'] = round($datos['Encabezado']['Totales']['IVA'] * 0.65); |
|
1575 | + } |
|
1576 | + // TODO: mover a constante o método |
|
1549 | 1577 | $datos['Encabezado']['Totales']['MntTotal'] -= $datos['Encabezado']['Totales']['CredEC']; |
1550 | 1578 | } |
1551 | 1579 | } |
@@ -1645,10 +1673,12 @@ discard block |
||
1645 | 1673 | /*if (!$this->checkFirma()) |
1646 | 1674 | return 1;*/ |
1647 | 1675 | if (is_array($datos)) { |
1648 | - if (isset($datos['RUTEmisor']) and $this->getEmisor()!=$datos['RUTEmisor']) |
|
1649 | - return 2; |
|
1650 | - if (isset($datos['RUTRecep']) and $this->getReceptor()!=$datos['RUTRecep']) |
|
1651 | - return 3; |
|
1676 | + if (isset($datos['RUTEmisor']) and $this->getEmisor()!=$datos['RUTEmisor']) { |
|
1677 | + return 2; |
|
1678 | + } |
|
1679 | + if (isset($datos['RUTRecep']) and $this->getReceptor()!=$datos['RUTRecep']) { |
|
1680 | + return 3; |
|
1681 | + } |
|
1652 | 1682 | } |
1653 | 1683 | return 0; |
1654 | 1684 | } |
@@ -1662,8 +1692,9 @@ discard block |
||
1662 | 1692 | */ |
1663 | 1693 | public function checkFirma() |
1664 | 1694 | { |
1665 | - if (!$this->xml) |
|
1666 | - return null; |
|
1695 | + if (!$this->xml) { |
|
1696 | + return null; |
|
1697 | + } |
|
1667 | 1698 | // obtener firma |
1668 | 1699 | $Signature = $this->xml->documentElement->getElementsByTagName('Signature')->item(0); |
1669 | 1700 | // preparar documento a validar |
@@ -1755,12 +1786,14 @@ discard block |
||
1755 | 1786 | { |
1756 | 1787 | // solicitar token |
1757 | 1788 | $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($Firma); |
1758 | - if (!$token) |
|
1759 | - return false; |
|
1789 | + if (!$token) { |
|
1790 | + return false; |
|
1791 | + } |
|
1760 | 1792 | // consultar estado dte |
1761 | 1793 | $run = $Firma->getID(); |
1762 | - if ($run===false) |
|
1763 | - return false; |
|
1794 | + if ($run===false) { |
|
1795 | + return false; |
|
1796 | + } |
|
1764 | 1797 | list($RutConsultante, $DvConsultante) = explode('-', $run); |
1765 | 1798 | list($RutCompania, $DvCompania) = explode('-', $this->getEmisor()); |
1766 | 1799 | list($RutReceptor, $DvReceptor) = explode('-', $this->getReceptor()); |
@@ -1779,8 +1812,9 @@ discard block |
||
1779 | 1812 | 'token' => $token, |
1780 | 1813 | ]); |
1781 | 1814 | // si el estado se pudo recuperar se muestra |
1782 | - if ($xml===false) |
|
1783 | - return false; |
|
1815 | + if ($xml===false) { |
|
1816 | + return false; |
|
1817 | + } |
|
1784 | 1818 | // entregar estado |
1785 | 1819 | return (array)$xml->xpath('/SII:RESPUESTA/SII:RESP_HDR')[0]; |
1786 | 1820 | } |
@@ -1797,8 +1831,9 @@ discard block |
||
1797 | 1831 | { |
1798 | 1832 | // solicitar token |
1799 | 1833 | $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($Firma); |
1800 | - if (!$token) |
|
1801 | - return false; |
|
1834 | + if (!$token) { |
|
1835 | + return false; |
|
1836 | + } |
|
1802 | 1837 | // consultar estado dte |
1803 | 1838 | list($RutEmpresa, $DvEmpresa) = explode('-', $this->getEmisor()); |
1804 | 1839 | list($RutReceptor, $DvReceptor) = explode('-', $this->getReceptor()); |
@@ -1816,8 +1851,9 @@ discard block |
||
1816 | 1851 | 'token' => $token, |
1817 | 1852 | ]); |
1818 | 1853 | // si el estado se pudo recuperar se muestra |
1819 | - if ($xml===false) |
|
1820 | - return false; |
|
1854 | + if ($xml===false) { |
|
1855 | + return false; |
|
1856 | + } |
|
1821 | 1857 | // entregar estado |
1822 | 1858 | return (array)$xml->xpath('/SII:RESPUESTA/SII:RESP_BODY')[0]; |
1823 | 1859 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Método que agrega un DTE al listado que se enviará |
45 | - * @param DTE Objeto del DTE |
|
45 | + * @param DTE Dte del DTE |
|
46 | 46 | * @return =true si se pudo agregar el DTE o =false si no se agregó por exceder el límite de un envío |
47 | 47 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
48 | 48 | * @version 2015-12-11 |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | /** |
396 | 396 | * Método que determina el estado de validación sobre el envío |
397 | 397 | * @param datos Arreglo con datos para hacer las validaciones |
398 | - * @return Código del estado de la validación |
|
398 | + * @return integer del estado de la validación |
|
399 | 399 | * @warning No se está validando la firma del EnvioDTE |
400 | 400 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
401 | 401 | * @version 2015-09-07 |
@@ -135,8 +135,9 @@ discard block |
||
135 | 135 | public function generar() |
136 | 136 | { |
137 | 137 | // si ya se había generado se entrega directamente |
138 | - if ($this->xml_data) |
|
139 | - return $this->xml_data; |
|
138 | + if ($this->xml_data) { |
|
139 | + return $this->xml_data; |
|
140 | + } |
|
140 | 141 | // si no hay DTEs para generar entregar falso |
141 | 142 | if (!isset($this->dtes[0])) { |
142 | 143 | \sasco\LibreDTE\Log::write( |
@@ -185,8 +186,9 @@ discard block |
||
185 | 186 | $SubTotDTE = []; |
186 | 187 | $subtotales = []; |
187 | 188 | foreach ($this->dtes as &$DTE) { |
188 | - if (!isset($subtotales[$DTE->getTipo()])) |
|
189 | - $subtotales[$DTE->getTipo()] = 0; |
|
189 | + if (!isset($subtotales[$DTE->getTipo()])) { |
|
190 | + $subtotales[$DTE->getTipo()] = 0; |
|
191 | + } |
|
190 | 192 | $subtotales[$DTE->getTipo()]++; |
191 | 193 | } |
192 | 194 | foreach ($subtotales as $tipo => $subtotal) { |
@@ -301,8 +303,9 @@ discard block |
||
301 | 303 | { |
302 | 304 | $fecha = '9999-12-31'; |
303 | 305 | foreach ($this->getDocumentos() as $Dte) { |
304 | - if ($Dte->getFechaEmision() < $fecha) |
|
305 | - $fecha = $Dte->getFechaEmision(); |
|
306 | + if ($Dte->getFechaEmision() < $fecha) { |
|
307 | + $fecha = $Dte->getFechaEmision(); |
|
308 | + } |
|
306 | 309 | } |
307 | 310 | return $fecha; |
308 | 311 | } |
@@ -316,8 +319,9 @@ discard block |
||
316 | 319 | { |
317 | 320 | $fecha = '0000-01-01'; |
318 | 321 | foreach ($this->getDocumentos() as $Dte) { |
319 | - if ($Dte->getFechaEmision() > $fecha) |
|
320 | - $fecha = $Dte->getFechaEmision(); |
|
322 | + if ($Dte->getFechaEmision() > $fecha) { |
|
323 | + $fecha = $Dte->getFechaEmision(); |
|
324 | + } |
|
321 | 325 | } |
322 | 326 | return $fecha; |
323 | 327 | } |
@@ -371,8 +375,9 @@ discard block |
||
371 | 375 | $DTEs = $this->xml->getElementsByTagName('DTE'); |
372 | 376 | foreach ($DTEs as $nodo_dte) { |
373 | 377 | $e = $nodo_dte->getElementsByTagName('RUTEmisor')->item(0)->nodeValue; |
374 | - if (is_numeric($emisor)) |
|
375 | - $e = substr($e, 0, -2); |
|
378 | + if (is_numeric($emisor)) { |
|
379 | + $e = substr($e, 0, -2); |
|
380 | + } |
|
376 | 381 | $d = (int)$nodo_dte->getElementsByTagName('TipoDTE')->item(0)->nodeValue; |
377 | 382 | $f = (int)$nodo_dte->getElementsByTagName('Folio')->item(0)->nodeValue; |
378 | 383 | if ($folio == $f and $dte == $d and $emisor == $e) { |
@@ -402,12 +407,14 @@ discard block |
||
402 | 407 | */ |
403 | 408 | public function getEstadoValidacion(array $datos = null) |
404 | 409 | { |
405 | - if (!$this->schemaValidate()) |
|
406 | - return 1; |
|
410 | + if (!$this->schemaValidate()) { |
|
411 | + return 1; |
|
412 | + } |
|
407 | 413 | /*if (!$this->checkFirma()) |
408 | 414 | return 2;*/ |
409 | - if ($datos and $this->getReceptor()!=$datos['RutReceptor']) |
|
410 | - return 3; |
|
415 | + if ($datos and $this->getReceptor()!=$datos['RutReceptor']) { |
|
416 | + return 3; |
|
417 | + } |
|
411 | 418 | return 0; |
412 | 419 | } |
413 | 420 | |
@@ -419,8 +426,9 @@ discard block |
||
419 | 426 | */ |
420 | 427 | public function checkFirma() |
421 | 428 | { |
422 | - if (!$this->xml) |
|
423 | - return null; |
|
429 | + if (!$this->xml) { |
|
430 | + return null; |
|
431 | + } |
|
424 | 432 | // listado de firmas del XML |
425 | 433 | $Signatures = $this->xml->documentElement->getElementsByTagName('Signature'); |
426 | 434 | // verificar firma de SetDTE |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | { |
33 | 33 | |
34 | 34 | private $dtes = []; ///< Objetos con los DTE que se enviarán |
35 | - private $config = [ // 0: DTE, 1: boleta |
|
35 | + private $config = [// 0: DTE, 1: boleta |
|
36 | 36 | 'SubTotDTE_max' => [20, 2], ///< máxima cantidad de tipos de documentos en el envío |
37 | 37 | 'DTE_max' => [2000, 1000], ///< máxima cantidad de DTE en un envío |
38 | 38 | 'tipos' => ['EnvioDTE', 'EnvioBOLETA'], ///< Tag para el envío, según si son Boletas o no |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | public function agregar(Dte $DTE) |
51 | 51 | { |
52 | 52 | // determinar el tipo del envío (DTE o boleta) |
53 | - if ($this->tipo === null) { |
|
53 | + if ($this->tipo===null) { |
|
54 | 54 | $this->tipo = (int)$DTE->esBoleta(); |
55 | 55 | } |
56 | 56 | // validar que el tipo de documento sea del tipo que se espera |
57 | - else if ((int)$DTE->esBoleta() != $this->tipo) { |
|
57 | + else if ((int)$DTE->esBoleta()!=$this->tipo) { |
|
58 | 58 | return false; |
59 | 59 | } |
60 | 60 | // |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | 'RutEnvia' => $Dte->getEmisor(), |
222 | 222 | 'RutReceptor' => $Dte->getReceptor(), |
223 | 223 | 'FchResol' => date('Y-m-d'), |
224 | - 'NroResol' => ($Dte->getCertificacion()?'0':'').'9999', |
|
224 | + 'NroResol' => ($Dte->getCertificacion() ? '0' : '').'9999', |
|
225 | 225 | ]); |
226 | 226 | if (!parent::loadXML($this->generar())) { |
227 | 227 | return false; |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | { |
302 | 302 | $fecha = '9999-12-31'; |
303 | 303 | foreach ($this->getDocumentos() as $Dte) { |
304 | - if ($Dte->getFechaEmision() < $fecha) |
|
304 | + if ($Dte->getFechaEmision()<$fecha) |
|
305 | 305 | $fecha = $Dte->getFechaEmision(); |
306 | 306 | } |
307 | 307 | return $fecha; |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | { |
317 | 317 | $fecha = '0000-01-01'; |
318 | 318 | foreach ($this->getDocumentos() as $Dte) { |
319 | - if ($Dte->getFechaEmision() > $fecha) |
|
319 | + if ($Dte->getFechaEmision()>$fecha) |
|
320 | 320 | $fecha = $Dte->getFechaEmision(); |
321 | 321 | } |
322 | 322 | return $fecha; |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | $e = substr($e, 0, -2); |
376 | 376 | $d = (int)$nodo_dte->getElementsByTagName('TipoDTE')->item(0)->nodeValue; |
377 | 377 | $f = (int)$nodo_dte->getElementsByTagName('Folio')->item(0)->nodeValue; |
378 | - if ($folio == $f and $dte == $d and $emisor == $e) { |
|
378 | + if ($folio==$f and $dte==$d and $emisor==$e) { |
|
379 | 379 | return new Dte($nodo_dte->C14N(), false); // cargar DTE sin normalizar |
380 | 380 | } |
381 | 381 | } |
@@ -432,12 +432,12 @@ discard block |
||
432 | 432 | if ($X509Certificate[1]==' ' or $X509Certificate[1]=="\t") { |
433 | 433 | $lineas = explode("\n", $X509Certificate); |
434 | 434 | $X509Certificate = ''; |
435 | - foreach($lineas as $l) { |
|
435 | + foreach ($lineas as $l) { |
|
436 | 436 | $X509Certificate .= trim($l); |
437 | 437 | } |
438 | 438 | } |
439 | 439 | $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap(trim($X509Certificate), 64, "\n", true)."\n".'-----END CERTIFICATE-----'; |
440 | - $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false; |
|
440 | + $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false; |
|
441 | 441 | return $valid and $DigestValue===base64_encode(sha1($SetDTE, true)); |
442 | 442 | } |
443 | 443 |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | /** |
50 | 50 | * Método que agrega el objeto Cesion |
51 | - * @param Cesion Objeto de \sasco\LibreDTE\Sii\Factoring\Cesion |
|
51 | + * @param Cesion Cesion de \sasco\LibreDTE\Sii\Factoring\Cesion |
|
52 | 52 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
53 | 53 | * @version 2016-12-10 |
54 | 54 | */ |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Método que genera el XML del AEC |
83 | - * @return XML AEC con DTE y Cesion |
|
83 | + * @return boolean|string AEC con DTE y Cesion |
|
84 | 84 | * @author Adonias Vasquez (adonias.vasquez[at]epys.cl) |
85 | 85 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
86 | 86 | * @version 2016-12-10 |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @param email del usuario que envía el AEC |
174 | 174 | * @param empresa RUT de la empresa emisora del AEC |
175 | 175 | * @param dte Documento XML con el DTE que se desea enviar a SII |
176 | - * @param token Token de autenticación automática ante el SII |
|
176 | + * @param token string de autenticación automática ante el SII |
|
177 | 177 | * @param retry Intentos que se realizarán como máximo para obtener respuesta |
178 | 178 | * @return Respuesta XML desde SII o bien null si no se pudo obtener respuesta |
179 | 179 | * @author Adonias Vasquez (adonias.vasquez[at]epys.cl) |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | { |
185 | 185 | // definir datos que se usarán en el envío |
186 | 186 | list($rutCompany, $dvCompany) = explode('-', str_replace('.', '', $empresa)); |
187 | - if (strpos($dte, '<?xml') === false) { |
|
188 | - $dte = '<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n" . $dte; |
|
187 | + if (strpos($dte, '<?xml')===false) { |
|
188 | + $dte = '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n".$dte; |
|
189 | 189 | } |
190 | 190 | do { |
191 | - $file = sys_get_temp_dir() . '/aec_' . md5(microtime() . $token . $dte) . '.xml'; |
|
191 | + $file = sys_get_temp_dir().'/aec_'.md5(microtime().$token.$dte).'.xml'; |
|
192 | 192 | } while (file_exists($file)); |
193 | 193 | file_put_contents($file, $dte); |
194 | 194 | $data = [ |
@@ -228,17 +228,17 @@ discard block |
||
228 | 228 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
229 | 229 | } |
230 | 230 | // enviar XML al SII |
231 | - for ($i = 0; $i < $retry; $i++) { |
|
231 | + for ($i = 0; $i<$retry; $i++) { |
|
232 | 232 | $response = curl_exec($curl); |
233 | - if ($response and $response != 'Error 500') |
|
233 | + if ($response and $response!='Error 500') |
|
234 | 234 | break; |
235 | 235 | } |
236 | 236 | unlink($file); |
237 | 237 | // verificar respuesta del envío y entregar error en caso que haya uno |
238 | - if (!$response or $response == 'Error 500') { |
|
238 | + if (!$response or $response=='Error 500') { |
|
239 | 239 | if (!$response) |
240 | 240 | \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::ENVIO_ERROR_CURL, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::ENVIO_ERROR_CURL, curl_error($curl))); |
241 | - if ($response == 'Error 500') |
|
241 | + if ($response=='Error 500') |
|
242 | 242 | \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::ENVIO_ERROR_500, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::ENVIO_ERROR_500)); |
243 | 243 | return false; |
244 | 244 | } |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | 9 => 'Error Interno', |
271 | 271 | 10 => 'Error Interno' |
272 | 272 | ]; |
273 | - if ($xml->STATUS != 0) { |
|
273 | + if ($xml->STATUS!=0) { |
|
274 | 274 | \sasco\LibreDTE\Log::write( |
275 | 275 | $xml->STATUS, |
276 | 276 | $error[$xml->STATUS] |
@@ -87,10 +87,12 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function generar() |
89 | 89 | { |
90 | - if (!isset($this->cedido) or !isset($this->cesiones[0])) |
|
91 | - return false; |
|
92 | - if (!isset($this->caratula)) |
|
93 | - $this->setCaratula(); |
|
90 | + if (!isset($this->cedido) or !isset($this->cesiones[0])) { |
|
91 | + return false; |
|
92 | + } |
|
93 | + if (!isset($this->caratula)) { |
|
94 | + $this->setCaratula(); |
|
95 | + } |
|
94 | 96 | // genear XML del envío |
95 | 97 | $xmlEnvio = (new \sasco\LibreDTE\XML())->generate([ |
96 | 98 | 'AEC' => [ |
@@ -137,8 +139,9 @@ discard block |
||
137 | 139 | public function enviar() |
138 | 140 | { |
139 | 141 | // generar XML que se enviará |
140 | - if (!$this->xml_data) |
|
141 | - $this->xml_data = $this->generar(); |
|
142 | + if (!$this->xml_data) { |
|
143 | + $this->xml_data = $this->generar(); |
|
144 | + } |
|
142 | 145 | if (!$this->xml_data) { |
143 | 146 | \sasco\LibreDTE\Log::write( |
144 | 147 | \sasco\LibreDTE\Estado::DOCUMENTO_ERROR_GENERAR_XML, |
@@ -150,20 +153,24 @@ discard block |
||
150 | 153 | return false; |
151 | 154 | } |
152 | 155 | // validar schema del documento antes de enviar |
153 | - if (!$this->schemaValidate()) |
|
154 | - return false; |
|
156 | + if (!$this->schemaValidate()) { |
|
157 | + return false; |
|
158 | + } |
|
155 | 159 | // solicitar token |
156 | 160 | $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($this->Firma); |
157 | - if (!$token) |
|
158 | - return false; |
|
161 | + if (!$token) { |
|
162 | + return false; |
|
163 | + } |
|
159 | 164 | // enviar AEC |
160 | 165 | $email = $this->caratula['MailContacto']; |
161 | 166 | $emisor = $this->caratula['RutCedente']; |
162 | 167 | $result = $this->enviarRTC($email, $emisor, $this->xml_data, $token, 10); |
163 | - if ($result===false) |
|
164 | - return false; |
|
165 | - if (!is_numeric((string)$result->TRACKID)) |
|
166 | - return false; |
|
168 | + if ($result===false) { |
|
169 | + return false; |
|
170 | + } |
|
171 | + if (!is_numeric((string)$result->TRACKID)) { |
|
172 | + return false; |
|
173 | + } |
|
167 | 174 | return (int)(string)$result->TRACKID; |
168 | 175 | } |
169 | 176 | |
@@ -230,16 +237,19 @@ discard block |
||
230 | 237 | // enviar XML al SII |
231 | 238 | for ($i = 0; $i < $retry; $i++) { |
232 | 239 | $response = curl_exec($curl); |
233 | - if ($response and $response != 'Error 500') |
|
234 | - break; |
|
240 | + if ($response and $response != 'Error 500') { |
|
241 | + break; |
|
242 | + } |
|
235 | 243 | } |
236 | 244 | unlink($file); |
237 | 245 | // verificar respuesta del envío y entregar error en caso que haya uno |
238 | 246 | if (!$response or $response == 'Error 500') { |
239 | - if (!$response) |
|
240 | - \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::ENVIO_ERROR_CURL, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::ENVIO_ERROR_CURL, curl_error($curl))); |
|
241 | - if ($response == 'Error 500') |
|
242 | - \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::ENVIO_ERROR_500, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::ENVIO_ERROR_500)); |
|
247 | + if (!$response) { |
|
248 | + \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::ENVIO_ERROR_CURL, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::ENVIO_ERROR_CURL, curl_error($curl))); |
|
249 | + } |
|
250 | + if ($response == 'Error 500') { |
|
251 | + \sasco\LibreDTE\Log::write(\sasco\LibreDTE\Estado::ENVIO_ERROR_500, \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::ENVIO_ERROR_500)); |
|
252 | + } |
|
243 | 253 | return false; |
244 | 254 | } |
245 | 255 | // cerrar sesión curl |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Constructor de la clase Cesion |
41 | - * @param DTECedido Objeto DteCedido |
|
42 | - * @param Seq secuencia de la cesión |
|
41 | + * @param DTECedido DteCedido DteCedido |
|
42 | + * @param Seq integer de la cesión |
|
43 | 43 | * @author Adonias Vasquez (adonias.vasquez[at]epys.cl) |
44 | 44 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
45 | 45 | * @version 2016-12-10 |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | |
178 | 178 | /** |
179 | 179 | * Método que realiza la firma de cesión |
180 | - * @param Firma objeto que representa la Firma Electrónca |
|
180 | + * @param Firma \sasco\LibreDTE\FirmaElectronica que representa la Firma Electrónca |
|
181 | 181 | * @return =true si el DTE pudo ser fimado o =false si no se pudo firmar |
182 | 182 | * @author Adonias Vasquez (adonias.vasquez[at]epys.cl) |
183 | 183 | * @version 2016-08-10 |
@@ -194,8 +194,9 @@ |
||
194 | 194 | return false; |
195 | 195 | } |
196 | 196 | $this->xml = new \sasco\LibreDTE\XML(); |
197 | - if (!$this->xml->loadXML($xml) or !$this->schemaValidate()) |
|
198 | - return false; |
|
197 | + if (!$this->xml->loadXML($xml) or !$this->schemaValidate()) { |
|
198 | + return false; |
|
199 | + } |
|
199 | 200 | return true; |
200 | 201 | } |
201 | 202 |