@@ -46,10 +46,10 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public static function read($archivo, $separador = ';', $delimitadortexto = '"') |
| 48 | 48 | { |
| 49 | - if (($handle = fopen($archivo, 'r')) !== FALSE) { |
|
| 49 | + if (($handle = fopen($archivo, 'r'))!==FALSE) { |
|
| 50 | 50 | $data = array(); |
| 51 | 51 | $i = 0; |
| 52 | - while (($row = fgetcsv($handle, 0, $separador, $delimitadortexto)) !== FALSE) { |
|
| 52 | + while (($row = fgetcsv($handle, 0, $separador, $delimitadortexto))!==FALSE) { |
|
| 53 | 53 | $j = 0; |
| 54 | 54 | foreach ($row as &$col) { |
| 55 | 55 | $data[$i][$j++] = $col; |
@@ -77,11 +77,11 @@ discard block |
||
| 77 | 77 | header('Content-Disposition: attachment; filename='.$archivo.'.csv'); |
| 78 | 78 | header('Pragma: no-cache'); |
| 79 | 79 | header('Expires: 0'); |
| 80 | - foreach($data as &$row) { |
|
| 81 | - foreach($row as &$col) { |
|
| 80 | + foreach ($data as &$row) { |
|
| 81 | + foreach ($row as &$col) { |
|
| 82 | 82 | $col = $delimitadortexto.rtrim(str_replace('<br />', ', ', strip_tags($col, '<br>')), " \t\n\r\0\x0B,").$delimitadortexto; |
| 83 | 83 | } |
| 84 | - echo implode($separador, $row),"\r\n"; |
|
| 84 | + echo implode($separador, $row), "\r\n"; |
|
| 85 | 85 | unset($row); |
| 86 | 86 | } |
| 87 | 87 | unset($data); |
@@ -100,8 +100,8 @@ discard block |
||
| 100 | 100 | public static function save(array $data, $archivo, $separador = ';', $delimitadortexto = '"') |
| 101 | 101 | { |
| 102 | 102 | $fd = fopen($archivo, 'w'); |
| 103 | - foreach($data as &$row) { |
|
| 104 | - foreach($row as &$col) { |
|
| 103 | + foreach ($data as &$row) { |
|
| 104 | + foreach ($row as &$col) { |
|
| 105 | 105 | $col = $delimitadortexto.rtrim(str_replace('<br />', ', ', strip_tags($col, '<br>')), " \t\n\r\0\x0B,").$delimitadortexto; |
| 106 | 106 | } |
| 107 | 107 | fwrite($fd, implode($separador, $row)."\r\n"); |
@@ -174,12 +174,14 @@ |
||
| 174 | 174 | public static function get($codigo, $args = null) |
| 175 | 175 | { |
| 176 | 176 | // si no hay glosa asociada al código se entrega el mismo código |
| 177 | - if (!isset(self::$glosas[(int)$codigo])) |
|
| 178 | - return (int)$codigo; |
|
| 177 | + if (!isset(self::$glosas[(int)$codigo])) { |
|
| 178 | + return (int)$codigo; |
|
| 179 | + } |
|
| 179 | 180 | // si los argumentos no son un arreglo se obtiene arreglo a partir |
| 180 | 181 | // de los argumentos pasados a la función |
| 181 | - if (!is_array($args)) |
|
| 182 | - $args = array_slice(func_get_args(), 1); |
|
| 182 | + if (!is_array($args)) { |
|
| 183 | + $args = array_slice(func_get_args(), 1); |
|
| 184 | + } |
|
| 183 | 185 | // entregar glosa |
| 184 | 186 | return vsprintf(I18n::translate(self::$glosas[(int)$codigo], 'estados'), $args); |
| 185 | 187 | } |
@@ -68,7 +68,7 @@ |
||
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * Método que realiza la firma del DTE cedido |
| 71 | - * @param Firma objeto que representa la Firma Electrónca |
|
| 71 | + * @param Firma \sasco\LibreDTE\FirmaElectronica que representa la Firma Electrónca |
|
| 72 | 72 | * @return =true si el DTE pudo ser fimado o =false si no se pudo firmar |
| 73 | 73 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 74 | 74 | * @version 2016-12-10 |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | /** |
| 52 | 52 | * Método que genera nodos XML a partir de un arreglo |
| 53 | 53 | * @param array Arreglo con los datos que se usarán para generar XML |
| 54 | - * @param parent DOMElement padre para los elementos, o =null para que sea la raíz |
|
| 55 | - * @return Objeto \sasco\LibreDTE\XML |
|
| 54 | + * @param parent \DOMElement padre para los elementos, o =null para que sea la raíz |
|
| 55 | + * @return XML \sasco\LibreDTE\XML |
|
| 56 | 56 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 57 | 57 | * @version 2016-04-03 |
| 58 | 58 | */ |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | /** |
| 141 | 141 | * Método para realizar consultas XPATH al documento XML |
| 142 | 142 | * @param expression Expresión XPath a ejecutar |
| 143 | - * @return DOMNodeList |
|
| 143 | + * @return \DOMNodeList |
|
| 144 | 144 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 145 | 145 | * @version 2015-08-05 |
| 146 | 146 | */ |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | * Método que cuenta los nodos con el mismo nombre hijos deun DOMElement |
| 262 | 262 | * No sirve usar: $dom->getElementsByTagName($tagName)->length ya que esto |
| 263 | 263 | * entrega todos los nodos con el nombre, sean hijos, nietos, etc. |
| 264 | - * @return Cantidad de nodos hijos con el mismo nombre en el DOMElement |
|
| 264 | + * @return integer de nodos hijos con el mismo nombre en el DOMElement |
|
| 265 | 265 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 266 | 266 | * @version 2015-09-07 |
| 267 | 267 | */ |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | |
| 302 | 302 | /** |
| 303 | 303 | * Método que entrega el nombre del archivo del schema del XML |
| 304 | - * @return Nombre del schema o bien =false si no se encontró |
|
| 304 | + * @return string del schema o bien =false si no se encontró |
|
| 305 | 305 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 306 | 306 | * @version 2015-12-14 |
| 307 | 307 | */ |
@@ -343,6 +343,7 @@ discard block |
||
| 343 | 343 | * respeta el estándar y las requiere convertidas |
| 344 | 344 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 345 | 345 | * @version 2017-01-20 |
| 346 | + * @param string $xml |
|
| 346 | 347 | */ |
| 347 | 348 | private function fixEntities($xml) |
| 348 | 349 | { |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
| 57 | 57 | * @version 2016-04-03 |
| 58 | 58 | */ |
| 59 | - public function generate(array $array, \DOMElement &$parent = null) |
|
| 59 | + public function generate(array $array, \DOMElement & $parent = null) |
|
| 60 | 60 | { |
| 61 | 61 | if ($parent===null) |
| 62 | 62 | $parent = &$this; |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | private function utf2iso($string) |
| 186 | 186 | { |
| 187 | - return mb_detect_encoding($string, ['UTF-8', 'ISO-8859-1']) != 'ISO-8859-1' ? utf8_decode($string) : $string; |
|
| 187 | + return mb_detect_encoding($string, ['UTF-8', 'ISO-8859-1'])!='ISO-8859-1' ? utf8_decode($string) : $string; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | // agregar nodos hijos |
| 226 | 226 | if ($dom->hasChildNodes()) { |
| 227 | - foreach($dom->childNodes as $child) { |
|
| 227 | + foreach ($dom->childNodes as $child) { |
|
| 228 | 228 | if ($child instanceof \DOMText) { |
| 229 | 229 | $textContent = trim($child->textContent); |
| 230 | 230 | if ($textContent!="") { |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | $newXML = ''; |
| 350 | 350 | $n_letras = strlen($xml); |
| 351 | 351 | $convertir = false; |
| 352 | - for ($i=0; $i<$n_letras; ++$i) { |
|
| 352 | + for ($i = 0; $i<$n_letras; ++$i) { |
|
| 353 | 353 | if ($xml[$i]=='>') |
| 354 | 354 | $convertir = true; |
| 355 | 355 | if ($xml[$i]=='<') |
@@ -58,13 +58,15 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | public function generate(array $array, \DOMElement &$parent = null) |
| 60 | 60 | { |
| 61 | - if ($parent===null) |
|
| 62 | - $parent = &$this; |
|
| 61 | + if ($parent===null) { |
|
| 62 | + $parent = &$this; |
|
| 63 | + } |
|
| 63 | 64 | foreach ($array as $key => $value) { |
| 64 | 65 | if ($key=='@attributes') { |
| 65 | 66 | foreach ($value as $attr => $val) { |
| 66 | - if ($val!==false) |
|
| 67 | - $parent->setAttribute($attr, $val); |
|
| 67 | + if ($val!==false) { |
|
| 68 | + $parent->setAttribute($attr, $val); |
|
| 69 | + } |
|
| 68 | 70 | } |
| 69 | 71 | } else if ($key=='@value') { |
| 70 | 72 | $parent->nodeValue = $this->sanitize($value); |
@@ -107,8 +109,9 @@ discard block |
||
| 107 | 109 | private function sanitize($txt) |
| 108 | 110 | { |
| 109 | 111 | // si no se paso un texto o bien es un número no se hace nada |
| 110 | - if (!$txt or is_numeric($txt)) |
|
| 111 | - return $txt; |
|
| 112 | + if (!$txt or is_numeric($txt)) { |
|
| 113 | + return $txt; |
|
| 114 | + } |
|
| 112 | 115 | // convertir "predefined entities" de XML |
| 113 | 116 | $txt = str_replace( |
| 114 | 117 | ['&', '&', '<', '<', '>', '>', '"', '"', ''', '''], |
@@ -161,8 +164,9 @@ discard block |
||
| 161 | 164 | { |
| 162 | 165 | if ($xpath) { |
| 163 | 166 | $node = $this->xpath($xpath)->item(0); |
| 164 | - if (!$node) |
|
| 165 | - return false; |
|
| 167 | + if (!$node) { |
|
| 168 | + return false; |
|
| 169 | + } |
|
| 166 | 170 | $xml = $this->utf2iso($node->C14N()); |
| 167 | 171 | $xml = $this->fixEntities($xml); |
| 168 | 172 | } else { |
@@ -209,12 +213,15 @@ discard block |
||
| 209 | 213 | public function toArray(\DOMElement $dom = null, array &$array = null, $arregloNodos = false) |
| 210 | 214 | { |
| 211 | 215 | // determinar valores de parámetros |
| 212 | - if (!$dom) |
|
| 213 | - $dom = $this->documentElement; |
|
| 214 | - if (!$dom) |
|
| 215 | - return false; |
|
| 216 | - if ($array===null) |
|
| 217 | - $array = [$dom->tagName => null]; |
|
| 216 | + if (!$dom) { |
|
| 217 | + $dom = $this->documentElement; |
|
| 218 | + } |
|
| 219 | + if (!$dom) { |
|
| 220 | + return false; |
|
| 221 | + } |
|
| 222 | + if ($array===null) { |
|
| 223 | + $array = [$dom->tagName => null]; |
|
| 224 | + } |
|
| 218 | 225 | // agregar atributos del nodo |
| 219 | 226 | if ($dom->hasAttributes()) { |
| 220 | 227 | $array[$dom->tagName]['@attributes'] = []; |
@@ -230,22 +237,24 @@ discard block |
||
| 230 | 237 | if ($textContent!="") { |
| 231 | 238 | if ($dom->childNodes->length==1 and empty($array[$dom->tagName])) { |
| 232 | 239 | $array[$dom->tagName] = $textContent; |
| 233 | - } else |
|
| 234 | - $array[$dom->tagName]['@value'] = $textContent; |
|
| 240 | + } else { |
|
| 241 | + $array[$dom->tagName]['@value'] = $textContent; |
|
| 242 | + } |
|
| 235 | 243 | } |
| 236 | - } |
|
| 237 | - else if ($child instanceof \DOMElement) { |
|
| 244 | + } else if ($child instanceof \DOMElement) { |
|
| 238 | 245 | $nodos_gemelos = $this->countTwins($dom, $child->tagName); |
| 239 | 246 | if ($nodos_gemelos==1) { |
| 240 | - if ($arregloNodos) |
|
| 241 | - $this->toArray($child, $array); |
|
| 242 | - else |
|
| 243 | - $this->toArray($child, $array[$dom->tagName]); |
|
| 247 | + if ($arregloNodos) { |
|
| 248 | + $this->toArray($child, $array); |
|
| 249 | + } else { |
|
| 250 | + $this->toArray($child, $array[$dom->tagName]); |
|
| 251 | + } |
|
| 244 | 252 | } |
| 245 | 253 | // crear arreglo con nodos hijos que tienen el mismo nombre de tag |
| 246 | 254 | else { |
| 247 | - if (!isset($array[$dom->tagName][$child->tagName])) |
|
| 248 | - $array[$dom->tagName][$child->tagName] = []; |
|
| 255 | + if (!isset($array[$dom->tagName][$child->tagName])) { |
|
| 256 | + $array[$dom->tagName][$child->tagName] = []; |
|
| 257 | + } |
|
| 249 | 258 | $siguiente = count($array[$dom->tagName][$child->tagName]); |
| 250 | 259 | $array[$dom->tagName][$child->tagName][$siguiente] = []; |
| 251 | 260 | $this->toArray($child, $array[$dom->tagName][$child->tagName][$siguiente], true); |
@@ -269,8 +278,9 @@ discard block |
||
| 269 | 278 | { |
| 270 | 279 | $twins = 0; |
| 271 | 280 | foreach ($dom->childNodes as $child) { |
| 272 | - if ($child instanceof \DOMElement and $child->tagName==$tagName) |
|
| 273 | - $twins++; |
|
| 281 | + if ($child instanceof \DOMElement and $child->tagName==$tagName) { |
|
| 282 | + $twins++; |
|
| 283 | + } |
|
| 274 | 284 | } |
| 275 | 285 | return $twins; |
| 276 | 286 | } |
@@ -284,8 +294,9 @@ discard block |
||
| 284 | 294 | public function getErrors() |
| 285 | 295 | { |
| 286 | 296 | $errors = []; |
| 287 | - foreach (libxml_get_errors() as $e) |
|
| 288 | - $errors[] = $e->message; |
|
| 297 | + foreach (libxml_get_errors() as $e) { |
|
| 298 | + $errors[] = $e->message; |
|
| 299 | + } |
|
| 289 | 300 | return $errors; |
| 290 | 301 | } |
| 291 | 302 | |
@@ -308,8 +319,9 @@ discard block |
||
| 308 | 319 | public function getSchema() |
| 309 | 320 | { |
| 310 | 321 | $schemaLocation = $this->documentElement->getAttribute('xsi:schemaLocation'); |
| 311 | - if (!$schemaLocation or strpos($schemaLocation, ' ')===false) |
|
| 312 | - return false; |
|
| 322 | + if (!$schemaLocation or strpos($schemaLocation, ' ')===false) { |
|
| 323 | + return false; |
|
| 324 | + } |
|
| 313 | 325 | list($uri, $xsd) = explode(' ', $schemaLocation); |
| 314 | 326 | return $xsd; |
| 315 | 327 | } |
@@ -350,10 +362,12 @@ discard block |
||
| 350 | 362 | $n_letras = strlen($xml); |
| 351 | 363 | $convertir = false; |
| 352 | 364 | for ($i=0; $i<$n_letras; ++$i) { |
| 353 | - if ($xml[$i]=='>') |
|
| 354 | - $convertir = true; |
|
| 355 | - if ($xml[$i]=='<') |
|
| 356 | - $convertir = false; |
|
| 365 | + if ($xml[$i]=='>') { |
|
| 366 | + $convertir = true; |
|
| 367 | + } |
|
| 368 | + if ($xml[$i]=='<') { |
|
| 369 | + $convertir = false; |
|
| 370 | + } |
|
| 357 | 371 | if ($convertir) { |
| 358 | 372 | $l = $xml[$i]=='\'' ? ''' : ($xml[$i]=='"' ? '"' : $xml[$i]); |
| 359 | 373 | } else { |
@@ -66,4 +66,4 @@ |
||
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
| 69 | - echo $error,"\n"; |
|
| 69 | + echo $error, "\n"; |
|
@@ -98,5 +98,6 @@ |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // si hubo errores mostrar |
| 101 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 101 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 102 | 102 | echo $error,"\n"; |
| 103 | +} |
|
@@ -66,4 +66,4 @@ |
||
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
| 69 | - echo $error,"\n"; |
|
| 69 | + echo $error, "\n"; |
|
@@ -65,5 +65,6 @@ |
||
| 65 | 65 | var_dump($track_id); |
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 68 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 69 | 69 | echo $error,"\n"; |
| 70 | +} |
|
@@ -66,4 +66,4 @@ |
||
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
| 69 | - echo $error,"\n"; |
|
| 69 | + echo $error, "\n"; |
|
@@ -98,5 +98,6 @@ |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // si hubo errores mostrar |
| 101 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 101 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 102 | 102 | echo $error,"\n"; |
| 103 | +} |
|
@@ -83,5 +83,6 @@ |
||
| 83 | 83 | echo $XML2->getFlattened('/nodo1/nodo2')."\n\n"; |
| 84 | 84 | |
| 85 | 85 | // si hubo errores mostrar |
| 86 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 86 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 87 | 87 | echo $error, "\n"; |
| 88 | +} |
|
@@ -66,4 +66,4 @@ |
||
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
| 69 | - echo $error,"\n"; |
|
| 69 | + echo $error, "\n"; |
|
@@ -411,17 +411,20 @@ discard block |
||
| 411 | 411 | // Objetos de Firma, Folios y EnvioDTE |
| 412 | 412 | $Firma = new \sasco\LibreDTE\FirmaElectronica($config['firma']); |
| 413 | 413 | $Folios = []; |
| 414 | -foreach ($folios as $tipo => $cantidad) |
|
| 414 | +foreach ($folios as $tipo => $cantidad) { |
|
| 415 | 415 | $Folios[$tipo] = new \sasco\LibreDTE\Sii\Folios(file_get_contents('xml/folios/'.$tipo.'.xml')); |
| 416 | +} |
|
| 416 | 417 | $EnvioDTE = new \sasco\LibreDTE\Sii\EnvioDte(); |
| 417 | 418 | |
| 418 | 419 | // generar cada DTE, timbrar, firmar y agregar al sobre de EnvioDTE |
| 419 | 420 | foreach ($set_pruebas as $documento) { |
| 420 | 421 | $DTE = new \sasco\LibreDTE\Sii\Dte($documento); |
| 421 | - if (!$DTE->timbrar($Folios[$DTE->getTipo()])) |
|
| 422 | - break; |
|
| 423 | - if (!$DTE->firmar($Firma)) |
|
| 424 | - break; |
|
| 422 | + if (!$DTE->timbrar($Folios[$DTE->getTipo()])) { |
|
| 423 | + break; |
|
| 424 | + } |
|
| 425 | + if (!$DTE->firmar($Firma)) { |
|
| 426 | + break; |
|
| 427 | + } |
|
| 425 | 428 | $EnvioDTE->agregar($DTE); |
| 426 | 429 | } |
| 427 | 430 | |
@@ -433,5 +436,6 @@ discard block |
||
| 433 | 436 | var_dump($track_id); |
| 434 | 437 | |
| 435 | 438 | // si hubo errores mostrar |
| 436 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 439 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 437 | 440 | echo $error,"\n"; |
| 441 | +} |
|