@@ -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 |
@@ -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 |
@@ -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 |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | public function caso2() |
67 | 67 | { |
68 | - for ($i=0; $i<5; $i++) |
|
68 | + for ($i = 0; $i<5; $i++) |
|
69 | 69 | \sasco\LibreDTE\Log::write('Soy el error '.($i+1)); |
70 | 70 | } |
71 | 71 | public function caso3() |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | $GeneradorErrores->caso1(); |
83 | 83 | |
84 | 84 | // obtener el error más reciente y usar como string |
85 | -echo \sasco\LibreDTE\Log::read(),"\n\n"; |
|
85 | +echo \sasco\LibreDTE\Log::read(), "\n\n"; |
|
86 | 86 | |
87 | 87 | // mostrar el resto de errores y usar como string |
88 | 88 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
89 | - echo $error,"\n"; |
|
89 | + echo $error, "\n"; |
|
90 | 90 | echo "\n\n\n"; |
91 | 91 | |
92 | 92 | // ejecutar caso 2 |
@@ -94,27 +94,27 @@ discard block |
||
94 | 94 | |
95 | 95 | // obtener el error más reciente y usar como objeto |
96 | 96 | $error = \sasco\LibreDTE\Log::read(); |
97 | -echo 'error código: ',$error->code,' y mensaje ',$error->msg,"\n\n"; |
|
97 | +echo 'error código: ', $error->code, ' y mensaje ', $error->msg, "\n\n"; |
|
98 | 98 | |
99 | 99 | // mostrar el resto de errores y usar como objeto |
100 | 100 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
101 | - echo 'error código: ',$error->code,' y mensaje ',$error->msg,"\n"; |
|
101 | + echo 'error código: ', $error->code, ' y mensaje ', $error->msg, "\n"; |
|
102 | 102 | echo "\n\n\n"; |
103 | 103 | |
104 | 104 | // ejecutar caso 3 y mostrar en español todos los mensajes |
105 | 105 | $GeneradorErrores->caso3(); |
106 | 106 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
107 | - echo $error,"\n"; |
|
107 | + echo $error, "\n"; |
|
108 | 108 | echo "\n\n\n"; |
109 | 109 | |
110 | 110 | // ejecutar caso 3 y mostrar en español todos los mensajes pero como objetos |
111 | 111 | $GeneradorErrores->caso3(); |
112 | 112 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
113 | - echo 'error código: ',$error->code,' y mensaje ',$error->msg,"\n"; |
|
113 | + echo 'error código: ', $error->code, ' y mensaje ', $error->msg, "\n"; |
|
114 | 114 | echo "\n\n\n"; |
115 | 115 | |
116 | 116 | // ejecutar caso 3 y mostrar en inglés todos los mensajes |
117 | 117 | \sasco\LibreDTE\I18n::setIdioma('en'); // idioma se debe asignar antes que se registre cualquier mensaje en el Log |
118 | 118 | $GeneradorErrores->caso3(); |
119 | 119 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
120 | - echo $error,"\n"; |
|
120 | + echo $error, "\n"; |
@@ -65,8 +65,9 @@ discard block |
||
65 | 65 | } |
66 | 66 | public function caso2() |
67 | 67 | { |
68 | - for ($i=0; $i<5; $i++) |
|
69 | - \sasco\LibreDTE\Log::write('Soy el error '.($i+1)); |
|
68 | + for ($i=0; $i<5; $i++) { |
|
69 | + \sasco\LibreDTE\Log::write('Soy el error '.($i+1)); |
|
70 | + } |
|
70 | 71 | } |
71 | 72 | public function caso3() |
72 | 73 | { |
@@ -85,8 +86,9 @@ discard block |
||
85 | 86 | echo \sasco\LibreDTE\Log::read(),"\n\n"; |
86 | 87 | |
87 | 88 | // mostrar el resto de errores y usar como string |
88 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
89 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
89 | 90 | echo $error,"\n"; |
91 | +} |
|
90 | 92 | echo "\n\n\n"; |
91 | 93 | |
92 | 94 | // ejecutar caso 2 |
@@ -97,24 +99,28 @@ discard block |
||
97 | 99 | echo 'error código: ',$error->code,' y mensaje ',$error->msg,"\n\n"; |
98 | 100 | |
99 | 101 | // mostrar el resto de errores y usar como objeto |
100 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
102 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
101 | 103 | echo 'error código: ',$error->code,' y mensaje ',$error->msg,"\n"; |
104 | +} |
|
102 | 105 | echo "\n\n\n"; |
103 | 106 | |
104 | 107 | // ejecutar caso 3 y mostrar en español todos los mensajes |
105 | 108 | $GeneradorErrores->caso3(); |
106 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
109 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
107 | 110 | echo $error,"\n"; |
111 | +} |
|
108 | 112 | echo "\n\n\n"; |
109 | 113 | |
110 | 114 | // ejecutar caso 3 y mostrar en español todos los mensajes pero como objetos |
111 | 115 | $GeneradorErrores->caso3(); |
112 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
116 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
113 | 117 | echo 'error código: ',$error->code,' y mensaje ',$error->msg,"\n"; |
118 | +} |
|
114 | 119 | echo "\n\n\n"; |
115 | 120 | |
116 | 121 | // ejecutar caso 3 y mostrar en inglés todos los mensajes |
117 | 122 | \sasco\LibreDTE\I18n::setIdioma('en'); // idioma se debe asignar antes que se registre cualquier mensaje en el Log |
118 | 123 | $GeneradorErrores->caso3(); |
119 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
124 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
120 | 125 | echo $error,"\n"; |
126 | +} |
@@ -38,18 +38,20 @@ |
||
38 | 38 | date_default_timezone_set('America/Santiago'); |
39 | 39 | |
40 | 40 | // incluir autocarga de composer |
41 | -if (is_readable(dirname(dirname(__FILE__)).'/vendor/autoload.php')) |
|
41 | +if (is_readable(dirname(dirname(__FILE__)).'/vendor/autoload.php')) { |
|
42 | 42 | include dirname(dirname(__FILE__)).'/vendor/autoload.php'; |
43 | -else |
|
43 | +} else { |
|
44 | 44 | die('Para probar los ejemplos debes ejecutar primero "composer install" en el directorio '.dirname(dirname(__FILE__))."\n"); |
45 | +} |
|
45 | 46 | |
46 | 47 | // todos los ejemplos se ejecutan con backtrace activado, esto para ayudar al |
47 | 48 | // debug de los mismos |
48 | 49 | \sasco\LibreDTE\Log::setBacktrace(true); |
49 | 50 | |
50 | 51 | // incluir configuración específica de los ejemplos |
51 | -if (is_readable('config.php')) |
|
52 | +if (is_readable('config.php')) { |
|
52 | 53 | include 'config.php'; |
53 | -else |
|
54 | +} else { |
|
54 | 55 | die('Debes crear config.php a partir de config-dist.php'."\n"); |
56 | +} |
|
55 | 57 |