@@ -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 { |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | { |
| 168 | 168 | parent::__construct(); |
| 169 | 169 | $this->SetTitle('Documento Tributario Electrónico (DTE) de Chile by LibreDTE'); |
| 170 | - $this->papelContinuo = $papelContinuo === true ? 80 : $papelContinuo; |
|
| 170 | + $this->papelContinuo = $papelContinuo===true ? 80 : $papelContinuo; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | // determinar alto de la página y agregarla |
| 343 | 343 | $height = 145; |
| 344 | 344 | $n_detalle = count($dte['Detalle']); |
| 345 | - if ($n_detalle>1) $height += $n_detalle*20; |
|
| 345 | + if ($n_detalle>1) $height += $n_detalle * 20; |
|
| 346 | 346 | if ($this->cedible) $height += 50; |
| 347 | 347 | $this->AddPage('P', [$height, $width]); |
| 348 | 348 | // agregar cabecera del documento |
@@ -351,10 +351,10 @@ discard block |
||
| 351 | 351 | $dte['Encabezado']['IdDoc']['TipoDTE'], |
| 352 | 352 | $dte['Encabezado']['IdDoc']['Folio'], |
| 353 | 353 | $dte['Encabezado']['Emisor']['CmnaOrigen'], |
| 354 | - $x_start, $y_start, $width-($x_start*4), 10, |
|
| 355 | - [0,0,0] |
|
| 354 | + $x_start, $y_start, $width-($x_start * 4), 10, |
|
| 355 | + [0, 0, 0] |
|
| 356 | 356 | ); |
| 357 | - $y = $this->agregarEmisor($dte['Encabezado']['Emisor'], $x_start, $y+2, 40, 8, 9, [0,0,0]); |
|
| 357 | + $y = $this->agregarEmisor($dte['Encabezado']['Emisor'], $x_start, $y+2, 40, 8, 9, [0, 0, 0]); |
|
| 358 | 358 | // datos del documento |
| 359 | 359 | $this->SetY($y); |
| 360 | 360 | $this->Ln(); |
@@ -416,13 +416,13 @@ discard block |
||
| 416 | 416 | $this->logo['uri'], |
| 417 | 417 | $x, |
| 418 | 418 | $y, |
| 419 | - !$this->logo['posicion']?$w_img:null, $this->logo['posicion']?($w_img/2):null, |
|
| 419 | + !$this->logo['posicion'] ? $w_img : null, $this->logo['posicion'] ? ($w_img / 2) : null, |
|
| 420 | 420 | 'PNG', |
| 421 | - (isset($emisor['url'])?$emisor['url']:''), |
|
| 421 | + (isset($emisor['url']) ? $emisor['url'] : ''), |
|
| 422 | 422 | 'T' |
| 423 | 423 | ); |
| 424 | 424 | if ($this->logo['posicion']) { |
| 425 | - $this->SetY($this->y + ($w_img/2)); |
|
| 425 | + $this->SetY($this->y+($w_img / 2)); |
|
| 426 | 426 | $w += 40; |
| 427 | 427 | } else { |
| 428 | 428 | $x = $this->x+3; |
@@ -433,13 +433,13 @@ discard block |
||
| 433 | 433 | } |
| 434 | 434 | // agregar datos del emisor |
| 435 | 435 | $this->setFont('', 'B', $font_size ? $font_size : 14); |
| 436 | - $this->SetTextColorArray($color===null?[32, 92, 144]:$color); |
|
| 436 | + $this->SetTextColorArray($color===null ? [32, 92, 144] : $color); |
|
| 437 | 437 | $this->MultiTexto(!empty($emisor['RznSoc']) ? $emisor['RznSoc'] : $emisor['RznSocEmisor'], $x, $this->y+2, 'L', $w); |
| 438 | 438 | $this->setFont('', 'B', $font_size ? $font_size : 9); |
| 439 | - $this->SetTextColorArray([0,0,0]); |
|
| 439 | + $this->SetTextColorArray([0, 0, 0]); |
|
| 440 | 440 | $this->MultiTexto(!empty($emisor['GiroEmis']) ? $emisor['GiroEmis'] : $emisor['GiroEmisor'], $x, $this->y, 'L', $w); |
| 441 | 441 | $ciudad = !empty($emisor['CiudadOrigen']) ? $emisor['CiudadOrigen'] : \sasco\LibreDTE\Chile::getCiudad($emisor['CmnaOrigen']); |
| 442 | - $this->MultiTexto($emisor['DirOrigen'].', '.$emisor['CmnaOrigen'].($ciudad?(', '.$ciudad):''), $x, $this->y, 'L', $w); |
|
| 442 | + $this->MultiTexto($emisor['DirOrigen'].', '.$emisor['CmnaOrigen'].($ciudad ? (', '.$ciudad) : ''), $x, $this->y, 'L', $w); |
|
| 443 | 443 | if (!empty($emisor['Sucursal'])) { |
| 444 | 444 | $this->MultiTexto('Sucursal: '.$emisor['Sucursal'], $x, $this->y, 'L', $w); |
| 445 | 445 | } |
@@ -483,12 +483,12 @@ discard block |
||
| 483 | 483 | private function agregarFolio($rut, $tipo, $folio, $sucursal_sii = null, $x = 130, $y = 15, $w = 70, $font_size = null, array $color = null) |
| 484 | 484 | { |
| 485 | 485 | if ($color===null) { |
| 486 | - $color = $tipo ? ($tipo==52 ? [0,172,140] : [255,0,0]) : [0,0,0]; |
|
| 486 | + $color = $tipo ? ($tipo==52 ? [0, 172, 140] : [255, 0, 0]) : [0, 0, 0]; |
|
| 487 | 487 | } |
| 488 | 488 | $this->SetTextColorArray($color); |
| 489 | 489 | // colocar rut emisor, glosa documento y folio |
| 490 | 490 | list($rut, $dv) = explode('-', $rut); |
| 491 | - $this->setFont ('', 'B', $font_size ? $font_size : 15); |
|
| 491 | + $this->setFont('', 'B', $font_size ? $font_size : 15); |
|
| 492 | 492 | $this->MultiTexto('R.U.T.: '.$this->num($rut).'-'.$dv, $x, $y+4, 'C', $w); |
| 493 | 493 | $this->setFont('', 'B', $font_size ? $font_size : 12); |
| 494 | 494 | $this->MultiTexto($this->getTipo($tipo), $x, null, 'C', $w); |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | if ($tipo) { |
| 502 | 502 | $this->Texto('S.I.I. - '.\sasco\LibreDTE\Sii::getDireccionRegional($sucursal_sii), $x, $this->getY()+4, 'C', $w); |
| 503 | 503 | } |
| 504 | - $this->SetTextColorArray([0,0,0]); |
|
| 504 | + $this->SetTextColorArray([0, 0, 0]); |
|
| 505 | 505 | $this->Ln(); |
| 506 | 506 | return $this->y; |
| 507 | 507 | } |
@@ -628,7 +628,7 @@ discard block |
||
| 628 | 628 | $this->Texto('Señor(es)', $x); |
| 629 | 629 | $this->Texto(':', $x+$offset); |
| 630 | 630 | $this->setFont('', '', null); |
| 631 | - $this->MultiTexto($receptor['RznSocRecep'], $x+$offset+2, null, '', $x==10?105:0); |
|
| 631 | + $this->MultiTexto($receptor['RznSocRecep'], $x+$offset+2, null, '', $x==10 ? 105 : 0); |
|
| 632 | 632 | } |
| 633 | 633 | if (!empty($receptor['GiroRecep'])) { |
| 634 | 634 | $this->setFont('', 'B', null); |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | $ciudad = !empty($receptor['CiudadRecep']) ? $receptor['CiudadRecep'] : ( |
| 646 | 646 | !empty($receptor['CmnaRecep']) ? \sasco\LibreDTE\Chile::getCiudad($receptor['CmnaRecep']) : '' |
| 647 | 647 | ); |
| 648 | - $this->MultiTexto($receptor['DirRecep'].(!empty($receptor['CmnaRecep'])?(', '.$receptor['CmnaRecep']):'').($ciudad?(', '.$ciudad):''), $x+$offset+2); |
|
| 648 | + $this->MultiTexto($receptor['DirRecep'].(!empty($receptor['CmnaRecep']) ? (', '.$receptor['CmnaRecep']) : '').($ciudad ? (', '.$ciudad) : ''), $x+$offset+2); |
|
| 649 | 649 | } |
| 650 | 650 | if (!empty($receptor['Extranjero']['Nacionalidad'])) { |
| 651 | 651 | $this->setFont('', 'B', null); |
@@ -760,7 +760,7 @@ discard block |
||
| 760 | 760 | { |
| 761 | 761 | if (!isset($referencias[0])) |
| 762 | 762 | $referencias = [$referencias]; |
| 763 | - foreach($referencias as $r) { |
|
| 763 | + foreach ($referencias as $r) { |
|
| 764 | 764 | $texto = $r['NroLinRef'].' - '.$this->getTipo($r['TpoDocRef']).' N° '.$r['FolioRef'].' del '.$r['FchRef']; |
| 765 | 765 | if (isset($r['RazonRef']) and $r['RazonRef']!==false) |
| 766 | 766 | $texto = $texto.': '.$r['RazonRef']; |
@@ -853,9 +853,9 @@ discard block |
||
| 853 | 853 | $this->SetY($this->getY()+1); |
| 854 | 854 | $p1x = $x; |
| 855 | 855 | $p1y = $this->y; |
| 856 | - $p2x = $this->getPageWidth() - 2; |
|
| 857 | - $p2y = $p1y; // Use same y for a straight line |
|
| 858 | - $style = array('width' => 0.2,'color' => array(0, 0, 0)); |
|
| 856 | + $p2x = $this->getPageWidth()-2; |
|
| 857 | + $p2y = $p1y; // Use same y for a straight line |
|
| 858 | + $style = array('width' => 0.2, 'color' => array(0, 0, 0)); |
|
| 859 | 859 | $this->Line($p1x, $p1y, $p2x, $p2y, $style); |
| 860 | 860 | $this->Texto($this->detalle_cols['NmbItem']['title'], $x+1, $this->y, ucfirst($this->detalle_cols['NmbItem']['align'][0]), $this->detalle_cols['NmbItem']['width']); |
| 861 | 861 | $this->Texto($this->detalle_cols['PrcItem']['title'], $x+15, $this->y, ucfirst($this->detalle_cols['PrcItem']['align'][0]), $this->detalle_cols['PrcItem']['width']); |
@@ -865,9 +865,9 @@ discard block |
||
| 865 | 865 | if (!isset($detalle[0])) |
| 866 | 866 | $detalle = [$detalle]; |
| 867 | 867 | $this->SetY($this->getY()+2); |
| 868 | - foreach($detalle as &$d) { |
|
| 868 | + foreach ($detalle as &$d) { |
|
| 869 | 869 | $this->MultiTexto($d['NmbItem'], $x+1, $this->y+4, ucfirst($this->detalle_cols['NmbItem']['align'][0]), $this->detalle_cols['NmbItem']['width']); |
| 870 | - $this->Texto(number_format($d['PrcItem'],0,',','.'), $x+15, $this->y, ucfirst($this->detalle_cols['PrcItem']['align'][0]), $this->detalle_cols['PrcItem']['width']); |
|
| 870 | + $this->Texto(number_format($d['PrcItem'], 0, ',', '.'), $x+15, $this->y, ucfirst($this->detalle_cols['PrcItem']['align'][0]), $this->detalle_cols['PrcItem']['width']); |
|
| 871 | 871 | $this->Texto($this->num($d['QtyItem']), $x+35, $this->y, ucfirst($this->detalle_cols['QtyItem']['align'][0]), $this->detalle_cols['QtyItem']['width']); |
| 872 | 872 | $this->Texto($this->num($d['MontoItem']), $x+45, $this->y, ucfirst($this->detalle_cols['MontoItem']['align'][0]), $this->detalle_cols['MontoItem']['width']); |
| 873 | 873 | } |
@@ -887,7 +887,7 @@ discard block |
||
| 887 | 887 | if (!isset($detalle[0])) { |
| 888 | 888 | $detalle = [$detalle]; |
| 889 | 889 | } |
| 890 | - foreach($detalle as &$d) { |
|
| 890 | + foreach ($detalle as &$d) { |
|
| 891 | 891 | if (!empty($d['MontoItem'])) { |
| 892 | 892 | $subtotal += $d['MontoItem']; |
| 893 | 893 | } |
@@ -907,10 +907,10 @@ discard block |
||
| 907 | 907 | { |
| 908 | 908 | if (!isset($descuentosRecargos[0])) |
| 909 | 909 | $descuentosRecargos = [$descuentosRecargos]; |
| 910 | - foreach($descuentosRecargos as $dr) { |
|
| 910 | + foreach ($descuentosRecargos as $dr) { |
|
| 911 | 911 | $tipo = $dr['TpoMov']=='D' ? 'Descuento' : 'Recargo'; |
| 912 | 912 | $valor = $dr['TpoValor']=='%' ? $dr['ValorDR'].'%' : '$'.$this->num($dr['ValorDR']).'.-'; |
| 913 | - $this->Texto($tipo.' global: '.$valor.(!empty($dr['GlosaDR'])?(' ('.$dr['GlosaDR'].')'):''), $x); |
|
| 913 | + $this->Texto($tipo.' global: '.$valor.(!empty($dr['GlosaDR']) ? (' ('.$dr['GlosaDR'].')') : ''), $x); |
|
| 914 | 914 | $this->Ln(); |
| 915 | 915 | } |
| 916 | 916 | } |
@@ -928,8 +928,8 @@ discard block |
||
| 928 | 928 | $pagos = [$pagos]; |
| 929 | 929 | $this->Texto('Pago(s) programado(s):', $x); |
| 930 | 930 | $this->Ln(); |
| 931 | - foreach($pagos as $p) { |
|
| 932 | - $this->Texto(' - '.$this->date($p['FchPago'], false).': $'.$this->num($p['MntPago']).'.-'.(!empty($p['GlosaPagos'])?(' ('.$p['GlosaPagos'].')'):''), $x); |
|
| 931 | + foreach ($pagos as $p) { |
|
| 932 | + $this->Texto(' - '.$this->date($p['FchPago'], false).': $'.$this->num($p['MntPago']).'.-'.(!empty($p['GlosaPagos']) ? (' ('.$p['GlosaPagos'].')') : ''), $x); |
|
| 933 | 933 | $this->Ln(); |
| 934 | 934 | } |
| 935 | 935 | } |
@@ -979,7 +979,7 @@ discard block |
||
| 979 | 979 | if (!isset($ImptoReten[0])) { |
| 980 | 980 | $ImptoReten = [$ImptoReten]; |
| 981 | 981 | } |
| 982 | - foreach($ImptoReten as $i) { |
|
| 982 | + foreach ($ImptoReten as $i) { |
|
| 983 | 983 | $totales['ImptoReten_'.$i['TipoImp']] = $i['MontoImp']; |
| 984 | 984 | if (!empty($i['TasaImp'])) { |
| 985 | 985 | $glosas['ImptoReten_'.$i['TipoImp']] = \sasco\LibreDTE\Sii\ImpuestosAdicionales::getGlosa($i['TipoImp']).' ('.$i['TasaImp'].'%) $'; |
@@ -1044,7 +1044,7 @@ discard block |
||
| 1044 | 1044 | 'vpadding' => 0, |
| 1045 | 1045 | 'module_width' => 1, // width of a single module in points |
| 1046 | 1046 | 'module_height' => 1, // height of a single module in points |
| 1047 | - 'fgcolor' => [0,0,0], |
|
| 1047 | + 'fgcolor' => [0, 0, 0], |
|
| 1048 | 1048 | 'bgcolor' => false, // [255,255,255] |
| 1049 | 1049 | 'position' => $this->papelContinuo ? 'C' : 'S', |
| 1050 | 1050 | ]; |
@@ -1070,7 +1070,7 @@ discard block |
||
| 1070 | 1070 | */ |
| 1071 | 1071 | private function agregarAcuseRecibo($x = 93, $y = 190, $w = 50, $h = 40) |
| 1072 | 1072 | { |
| 1073 | - $this->SetTextColorArray([0,0,0]); |
|
| 1073 | + $this->SetTextColorArray([0, 0, 0]); |
|
| 1074 | 1074 | $this->Rect($x, $y, $w, $h, 'D', ['all' => ['width' => 0.1, 'color' => [0, 0, 0]]]); |
| 1075 | 1075 | $this->setFont('', 'B', 10); |
| 1076 | 1076 | $this->Texto('Acuse de recibo', $x, $y+1, 'C', $w); |
@@ -1100,9 +1100,9 @@ discard block |
||
| 1100 | 1100 | */ |
| 1101 | 1101 | private function agregarAcuseReciboContinuo($x = 3, $y = null, $w = 68, $h = 40) |
| 1102 | 1102 | { |
| 1103 | - $this->SetTextColorArray([0,0,0]); |
|
| 1103 | + $this->SetTextColorArray([0, 0, 0]); |
|
| 1104 | 1104 | $this->Rect($x, $y, $w, $h, 'D', ['all' => ['width' => 0.1, 'color' => [0, 0, 0]]]); |
| 1105 | - $style = array('width' => 0.2,'color' => array(0, 0, 0)); |
|
| 1105 | + $style = array('width' => 0.2, 'color' => array(0, 0, 0)); |
|
| 1106 | 1106 | $this->Line($x, $y+22, $w+3, $y+22, $style); |
| 1107 | 1107 | //$this->setFont('', 'B', 10); |
| 1108 | 1108 | //$this->Texto('Acuse de recibo', $x, $y+1, 'C', $w); |
@@ -1130,7 +1130,7 @@ discard block |
||
| 1130 | 1130 | private function agregarLeyendaDestino($tipo, $y = 254, $font_size = 10) |
| 1131 | 1131 | { |
| 1132 | 1132 | $this->setFont('', 'B', $font_size); |
| 1133 | - $this->Texto('CEDIBLE'.($tipo==52?' CON SU FACTURA':''), null, $y, 'R'); |
|
| 1133 | + $this->Texto('CEDIBLE'.($tipo==52 ? ' CON SU FACTURA' : ''), null, $y, 'R'); |
|
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | /** |
@@ -1161,7 +1161,7 @@ discard block |
||
| 1161 | 1161 | $dias = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado']; |
| 1162 | 1162 | $meses = ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre']; |
| 1163 | 1163 | $unixtime = strtotime($date); |
| 1164 | - $fecha = date(($mostrar_dia?'\D\I\A ':'').'j \d\e \M\E\S \d\e\l Y', $unixtime); |
|
| 1164 | + $fecha = date(($mostrar_dia ? '\D\I\A ' : '').'j \d\e \M\E\S \d\e\l Y', $unixtime); |
|
| 1165 | 1165 | $dia = $dias[date('w', $unixtime)]; |
| 1166 | 1166 | $mes = $meses[date('n', $unixtime)-1]; |
| 1167 | 1167 | return str_replace(array('DIA', 'MES'), array($dia, $mes), $fecha); |
@@ -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 |
@@ -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 | |
@@ -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 | +} |
|