@@ -66,4 +66,4 @@ |
||
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
| 69 | - echo $error,"\n"; |
|
| 69 | + echo $error, "\n"; |
|
@@ -98,5 +98,6 @@ |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // si hubo errores mostrar |
| 101 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 101 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 102 | 102 | echo $error,"\n"; |
| 103 | +} |
|
@@ -66,4 +66,4 @@ |
||
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
| 69 | - echo $error,"\n"; |
|
| 69 | + echo $error, "\n"; |
|
@@ -65,5 +65,6 @@ |
||
| 65 | 65 | var_dump($track_id); |
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 68 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 69 | 69 | echo $error,"\n"; |
| 70 | +} |
|
@@ -66,4 +66,4 @@ |
||
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
| 69 | - echo $error,"\n"; |
|
| 69 | + echo $error, "\n"; |
|
@@ -98,5 +98,6 @@ |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // si hubo errores mostrar |
| 101 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 101 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 102 | 102 | echo $error,"\n"; |
| 103 | +} |
|
@@ -66,4 +66,4 @@ |
||
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | 68 | foreach (\sasco\LibreDTE\Log::readAll() as $error) |
| 69 | - echo $error,"\n"; |
|
| 69 | + echo $error, "\n"; |
|
@@ -65,5 +65,6 @@ |
||
| 65 | 65 | var_dump($track_id); |
| 66 | 66 | |
| 67 | 67 | // si hubo errores mostrar |
| 68 | -foreach (\sasco\LibreDTE\Log::readAll() as $error) |
|
| 68 | +foreach (\sasco\LibreDTE\Log::readAll() as $error) { |
|
| 69 | 69 | echo $error,"\n"; |
| 70 | +} |
|
@@ -102,10 +102,12 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function agregar(array $detalle, $normalizar = true) |
| 104 | 104 | { |
| 105 | - if ($normalizar) |
|
| 106 | - $this->normalizarDetalle($detalle); |
|
| 107 | - if (!$detalle['TpoDoc']) |
|
| 108 | - return false; |
|
| 105 | + if ($normalizar) { |
|
| 106 | + $this->normalizarDetalle($detalle); |
|
| 107 | + } |
|
| 108 | + if (!$detalle['TpoDoc']) { |
|
| 109 | + return false; |
|
| 110 | + } |
|
| 109 | 111 | $this->detalles[] = $detalle; |
| 110 | 112 | return true; |
| 111 | 113 | } |
@@ -183,8 +185,9 @@ discard block |
||
| 183 | 185 | } |
| 184 | 186 | // calcular valores que no se hayan entregado |
| 185 | 187 | if (isset($detalle['FctProp'])) { |
| 186 | - if ($detalle['IVAUsoComun']===false) |
|
| 187 | - $detalle['IVAUsoComun'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
|
| 188 | + if ($detalle['IVAUsoComun']===false) { |
|
| 189 | + $detalle['IVAUsoComun'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
|
| 190 | + } |
|
| 188 | 191 | } else if (!$detalle['MntIVA'] and !is_array($detalle['IVANoRec']) and $detalle['TasaImp'] and $detalle['MntNeto']) { |
| 189 | 192 | $detalle['MntIVA'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
| 190 | 193 | } |
@@ -194,8 +197,9 @@ discard block |
||
| 194 | 197 | } |
| 195 | 198 | // normalizar IVA no recuperable |
| 196 | 199 | if (!empty($detalle['IVANoRec'])) { |
| 197 | - if (!isset($detalle['IVANoRec'][0])) |
|
| 198 | - $detalle['IVANoRec'] = [$detalle['IVANoRec']]; |
|
| 200 | + if (!isset($detalle['IVANoRec'][0])) { |
|
| 201 | + $detalle['IVANoRec'] = [$detalle['IVANoRec']]; |
|
| 202 | + } |
|
| 199 | 203 | // si son múltiples iva no recuperable se arma arreglo real |
| 200 | 204 | if (strpos($detalle['IVANoRec'][0]['CodIVANoRec'], ',')) { |
| 201 | 205 | $CodIVANoRec = explode(',', $detalle['IVANoRec'][0]['CodIVANoRec']); |
@@ -212,8 +216,9 @@ discard block |
||
| 212 | 216 | } |
| 213 | 217 | // normalizar otros impuestos |
| 214 | 218 | if (!empty($detalle['OtrosImp'])) { |
| 215 | - if (!isset($detalle['OtrosImp'][0])) |
|
| 216 | - $detalle['OtrosImp'] = [$detalle['OtrosImp']]; |
|
| 219 | + if (!isset($detalle['OtrosImp'][0])) { |
|
| 220 | + $detalle['OtrosImp'] = [$detalle['OtrosImp']]; |
|
| 221 | + } |
|
| 217 | 222 | // si son múltiples impuestos se arma arreglo real |
| 218 | 223 | if (strpos($detalle['OtrosImp'][0]['CodImp'], ',')) { |
| 219 | 224 | $CodImp = explode(',', $detalle['OtrosImp'][0]['CodImp']); |
@@ -531,8 +536,9 @@ discard block |
||
| 531 | 536 | 'TipoEnvio' => 'TOTAL', |
| 532 | 537 | 'FolioNotificacion' => false, |
| 533 | 538 | ], $caratula); |
| 534 | - if ($this->caratula['TipoEnvio']=='ESPECIAL') |
|
| 535 | - $this->caratula['FolioNotificacion'] = null; |
|
| 539 | + if ($this->caratula['TipoEnvio']=='ESPECIAL') { |
|
| 540 | + $this->caratula['FolioNotificacion'] = null; |
|
| 541 | + } |
|
| 536 | 542 | $this->id = 'LibreDTE_LIBRO_'.$this->caratula['TipoOperacion'].'_'.str_replace('-', '', $this->caratula['RutEmisorLibro']).'_'.str_replace('-', '', $this->caratula['PeriodoTributario']).'_'.date('U'); |
| 537 | 543 | } |
| 538 | 544 | |
@@ -546,8 +552,9 @@ discard block |
||
| 546 | 552 | public function generar($incluirDetalle = true) |
| 547 | 553 | { |
| 548 | 554 | // si ya se había generado se entrega directamente |
| 549 | - if ($this->xml_data) |
|
| 550 | - return $this->xml_data; |
|
| 555 | + if ($this->xml_data) { |
|
| 556 | + return $this->xml_data; |
|
| 557 | + } |
|
| 551 | 558 | // generar totales de DTE y sus montos |
| 552 | 559 | $TotalesPeriodo = $this->getResumen(); |
| 553 | 560 | $ResumenPeriodo = $TotalesPeriodo ? ['TotalesPeriodo'=>$TotalesPeriodo] : false; |
@@ -712,8 +719,9 @@ discard block |
||
| 712 | 719 | $manual = []; |
| 713 | 720 | if (isset($this->toArray()['LibroCompraVenta']['EnvioLibro']['ResumenPeriodo']['TotalesPeriodo'])) { |
| 714 | 721 | $totales = $this->toArray()['LibroCompraVenta']['EnvioLibro']['ResumenPeriodo']['TotalesPeriodo']; |
| 715 | - if (!isset($totales[0])) |
|
| 716 | - $totales = [$totales]; |
|
| 722 | + if (!isset($totales[0])) { |
|
| 723 | + $totales = [$totales]; |
|
| 724 | + } |
|
| 717 | 725 | foreach ($totales as $total) { |
| 718 | 726 | if (isset($total['TpoDoc']) and in_array($total['TpoDoc'], [35, 38, 48])) { |
| 719 | 727 | $manual[$total['TpoDoc']] = array_merge($this->total_default, $total); |
@@ -733,8 +741,9 @@ discard block |
||
| 733 | 741 | $manual = []; |
| 734 | 742 | if (isset($this->toArray()['LibroCompraVenta']['EnvioLibro']['ResumenPeriodo']['TotalesPeriodo'])) { |
| 735 | 743 | $totales = $this->toArray()['LibroCompraVenta']['EnvioLibro']['ResumenPeriodo']['TotalesPeriodo']; |
| 736 | - if (!isset($totales[0])) |
|
| 737 | - $totales = [$totales]; |
|
| 744 | + if (!isset($totales[0])) { |
|
| 745 | + $totales = [$totales]; |
|
| 746 | + } |
|
| 738 | 747 | foreach ($totales as $total) { |
| 739 | 748 | if (in_array($total['TpoDoc'], [39, 41])) { |
| 740 | 749 | $manual[$total['TpoDoc']] = array_merge($this->total_default, $total); |
@@ -184,9 +184,9 @@ discard block |
||
| 184 | 184 | // calcular valores que no se hayan entregado |
| 185 | 185 | if (isset($detalle['FctProp'])) { |
| 186 | 186 | if ($detalle['IVAUsoComun']===false) |
| 187 | - $detalle['IVAUsoComun'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
|
| 187 | + $detalle['IVAUsoComun'] = round($detalle['MntNeto'] * ($detalle['TasaImp'] / 100)); |
|
| 188 | 188 | } else if (!$detalle['MntIVA'] and !is_array($detalle['IVANoRec']) and $detalle['TasaImp'] and $detalle['MntNeto']) { |
| 189 | - $detalle['MntIVA'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
|
| 189 | + $detalle['MntIVA'] = round($detalle['MntNeto'] * ($detalle['TasaImp'] / 100)); |
|
| 190 | 190 | } |
| 191 | 191 | // si el monto total es 0 pero no se asigno neto ni exento se coloca |
| 192 | 192 | if ($detalle['MntExe']===false and $detalle['MntNeto']===false and $detalle['MntTotal']===0) { |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | $MntIVANoRec = explode(',', $detalle['IVANoRec'][0]['MntIVANoRec']); |
| 209 | 209 | $detalle['IVANoRec'] = []; |
| 210 | 210 | $n_inr = count($CodIVANoRec); |
| 211 | - for ($i=0; $i<$n_inr; $i++) { |
|
| 211 | + for ($i = 0; $i<$n_inr; $i++) { |
|
| 212 | 212 | $detalle['IVANoRec'][] = [ |
| 213 | 213 | 'CodIVANoRec' => $CodIVANoRec[$i], |
| 214 | 214 | 'MntIVANoRec' => $MntIVANoRec[$i], |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | $MntImp = explode(',', $detalle['OtrosImp'][0]['MntImp']); |
| 228 | 228 | $detalle['OtrosImp'] = []; |
| 229 | 229 | $n_impuestos = count($CodImp); |
| 230 | - for ($i=0; $i<$n_impuestos; $i++) { |
|
| 230 | + for ($i = 0; $i<$n_impuestos; $i++) { |
|
| 231 | 231 | $detalle['OtrosImp'][] = [ |
| 232 | 232 | 'CodImp' => $CodImp[$i], |
| 233 | 233 | 'TasaImp' => !empty($TasaImp[$i]) ? $TasaImp[$i] : false, |
@@ -239,20 +239,20 @@ discard block |
||
| 239 | 239 | $retenido = ImpuestosAdicionales::getRetenido($detalle['OtrosImp']); |
| 240 | 240 | if ($retenido) { |
| 241 | 241 | // si el iva retenido es total |
| 242 | - if ($retenido == $detalle['MntIVA']) { |
|
| 242 | + if ($retenido==$detalle['MntIVA']) { |
|
| 243 | 243 | $detalle['IVARetTotal'] = $retenido; |
| 244 | 244 | } |
| 245 | 245 | // si el iva retenido es parcial |
| 246 | 246 | else { |
| 247 | 247 | $detalle['IVARetParcial'] = $retenido; |
| 248 | - $detalle['IVANoRetenido'] = $detalle['MntIVA'] - $retenido; |
|
| 248 | + $detalle['IVANoRetenido'] = $detalle['MntIVA']-$retenido; |
|
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | // calcular monto total si no se especificó |
| 253 | 253 | if ($detalle['MntTotal']===false) { |
| 254 | 254 | // calcular monto total inicial |
| 255 | - $detalle['MntTotal'] = (int)$detalle['MntExe'] + (int)$detalle['MntNeto'] + (int)$detalle['MntIVA']; |
|
| 255 | + $detalle['MntTotal'] = (int)$detalle['MntExe']+(int)$detalle['MntNeto']+(int)$detalle['MntIVA']; |
|
| 256 | 256 | // agregar iva no recuperable al monto total |
| 257 | 257 | if (!empty($detalle['IVANoRec'])) { |
| 258 | 258 | foreach ($detalle['IVANoRec'] as $IVANoRec) { |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | } |
| 274 | 274 | // agregar otro montos e impuestos al total |
| 275 | - $detalle['MntTotal'] += (int)$detalle['MntSinCred'] + (int)$detalle['TabPuros'] + (int)$detalle['TabCigarrillos'] + (int)$detalle['TabElaborado'] + (int)$detalle['ImpVehiculo']; |
|
| 275 | + $detalle['MntTotal'] += (int)$detalle['MntSinCred']+(int)$detalle['TabPuros']+(int)$detalle['TabCigarrillos']+(int)$detalle['TabElaborado']+(int)$detalle['ImpVehiculo']; |
|
| 276 | 276 | } |
| 277 | 277 | // si no hay no hay monto neto, no se crean campos para IVA |
| 278 | 278 | if ($detalle['MntNeto']===false) { |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | $data = \sasco\LibreDTE\CSV::read($archivo); |
| 334 | 334 | $n_data = count($data); |
| 335 | 335 | $detalles = []; |
| 336 | - for ($i=1; $i<$n_data; $i++) { |
|
| 336 | + for ($i = 1; $i<$n_data; $i++) { |
|
| 337 | 337 | // detalle genérico |
| 338 | 338 | $detalle = [ |
| 339 | 339 | 'TpoDoc' => $data[$i][0], |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | if (!empty($data[$i][11])) { |
| 369 | 369 | $detalle['IVANoRec'] = [ |
| 370 | 370 | 'CodIVANoRec' => $data[$i][11], |
| 371 | - 'MntIVANoRec' => !empty($data[$i][12]) ? $data[$i][12] : round((int)$detalle['MntNeto'] * ((float)$detalle['TasaImp']/100)), |
|
| 371 | + 'MntIVANoRec' => !empty($data[$i][12]) ? $data[$i][12] : round((int)$detalle['MntNeto'] * ((float)$detalle['TasaImp'] / 100)), |
|
| 372 | 372 | ]; |
| 373 | 373 | } |
| 374 | 374 | // agregar código y monto de otros impuestos |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | $detalle['OtrosImp'] = [ |
| 377 | 377 | 'CodImp' => $data[$i][14], |
| 378 | 378 | 'TasaImp' => !empty($data[$i][15]) ? $data[$i][15] : 0, |
| 379 | - 'MntImp' => !empty($data[$i][16]) ? $data[$i][16] : round($detalle['MntNeto'] * ($data[$i][15]/100)), |
|
| 379 | + 'MntImp' => !empty($data[$i][16]) ? $data[$i][16] : round($detalle['MntNeto'] * ($data[$i][15] / 100)), |
|
| 380 | 380 | ]; |
| 381 | 381 | } |
| 382 | 382 | // si hay monto total se agrega |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | $data = \sasco\LibreDTE\CSV::read($archivo); |
| 452 | 452 | $n_data = count($data); |
| 453 | 453 | $detalles = []; |
| 454 | - for ($i=1; $i<$n_data; $i++) { |
|
| 454 | + for ($i = 1; $i<$n_data; $i++) { |
|
| 455 | 455 | // detalle genérico |
| 456 | 456 | $detalle = [ |
| 457 | 457 | 'TpoDoc' => $data[$i][0], |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | $detalle['OtrosImp'] = [ |
| 491 | 491 | 'CodImp' => $data[$i][11], |
| 492 | 492 | 'TasaImp' => !empty($data[$i][12]) ? $data[$i][12] : false, |
| 493 | - 'MntImp' => !empty($data[$i][13]) ? $data[$i][13] : round($detalle['MntNeto'] * ($data[$i][12]/100)), |
|
| 493 | + 'MntImp' => !empty($data[$i][13]) ? $data[$i][13] : round($detalle['MntNeto'] * ($data[$i][12] / 100)), |
|
| 494 | 494 | ]; |
| 495 | 495 | } |
| 496 | 496 | // agregar datos extranjeros |
@@ -655,8 +655,8 @@ discard block |
||
| 655 | 655 | // si hay IVA de uso común se contabiliza |
| 656 | 656 | if (!empty($d['FctProp'])) { |
| 657 | 657 | $totales[$d['TpoDoc']]['TotIVAUsoComun'] += $d['IVAUsoComun']; |
| 658 | - $totales[$d['TpoDoc']]['FctProp'] = $d['FctProp']/100; |
|
| 659 | - $totales[$d['TpoDoc']]['TotCredIVAUsoComun'] += round($d['IVAUsoComun'] * ($d['FctProp']/100)); |
|
| 658 | + $totales[$d['TpoDoc']]['FctProp'] = $d['FctProp'] / 100; |
|
| 659 | + $totales[$d['TpoDoc']]['TotCredIVAUsoComun'] += round($d['IVAUsoComun'] * ($d['FctProp'] / 100)); |
|
| 660 | 660 | unset($d['FctProp']); // se quita el factor de proporcionalidad del detalle ya que no es parte del XML |
| 661 | 661 | } |
| 662 | 662 | // contabilizar IVA fuera de plazo |
@@ -138,7 +138,7 @@ |
||
| 138 | 138 | ]; |
| 139 | 139 | // agregar otros impuestos adicionales |
| 140 | 140 | if ($n_OtrosImp>1) { |
| 141 | - for ($i=1; $i<$n_OtrosImp; $i++) { |
|
| 141 | + for ($i = 1; $i<$n_OtrosImp; $i++) { |
|
| 142 | 142 | $detalle[] = [ |
| 143 | 143 | '', |
| 144 | 144 | '', |
@@ -57,8 +57,9 @@ discard block |
||
| 57 | 57 | { |
| 58 | 58 | $this->startPageGroup(); |
| 59 | 59 | $this->AddPage(); |
| 60 | - if (isset($libro['LibroCompraVenta'])) |
|
| 61 | - $libro = $libro['LibroCompraVenta']; |
|
| 60 | + if (isset($libro['LibroCompraVenta'])) { |
|
| 61 | + $libro = $libro['LibroCompraVenta']; |
|
| 62 | + } |
|
| 62 | 63 | // título del libro |
| 63 | 64 | $this->SetFont('helvetica', 'B', 16); |
| 64 | 65 | $this->Texto('Libro de '.ucfirst(strtolower($libro['EnvioLibro']['Caratula']['TipoOperacion'])), null, null, 'C'); |
@@ -109,8 +110,7 @@ discard block |
||
| 109 | 110 | $total_resumen['TotIVARetTotal'] += !empty($total['TotIVARetTotal']) ? $total['TotIVARetTotal'] : 0; |
| 110 | 111 | $total_resumen['TotIVANoRetenido'] += !empty($total['TotIVANoRetenido']) ? $total['TotIVANoRetenido'] : 0; |
| 111 | 112 | $total_resumen['TotMntTotal'] += $total['TotMntTotal']; |
| 112 | - } |
|
| 113 | - else if (in_array($total['TpoDoc'], $this->dte_tipo_operacion['resta'])) { |
|
| 113 | + } else if (in_array($total['TpoDoc'], $this->dte_tipo_operacion['resta'])) { |
|
| 114 | 114 | $total_resumen['TotMntExe'] -= !empty($total['TotMntExe']) ? $total['TotMntExe'] : 0; |
| 115 | 115 | $total_resumen['TotMntNeto'] -= !empty($total['TotMntNeto']) ? $total['TotMntNeto'] : 0; |
| 116 | 116 | $total_resumen['TotMntIVA'] -= !empty($total['TotMntIVA']) ? $total['TotMntIVA'] : 0; |
@@ -171,10 +171,13 @@ discard block |
||
| 171 | 171 | foreach ($libro['EnvioLibro']['Detalle'] as $d) { |
| 172 | 172 | // impuesto adicional |
| 173 | 173 | if (!empty($d['OtrosImp'])) { |
| 174 | - if (!isset($d['OtrosImp'][0])) |
|
| 175 | - $d['OtrosImp'] = [$d['OtrosImp']]; |
|
| 174 | + if (!isset($d['OtrosImp'][0])) { |
|
| 175 | + $d['OtrosImp'] = [$d['OtrosImp']]; |
|
| 176 | + } |
|
| 176 | 177 | $n_OtrosImp = count($d['OtrosImp']); |
| 177 | - } else $n_OtrosImp = 0; |
|
| 178 | + } else { |
|
| 179 | + $n_OtrosImp = 0; |
|
| 180 | + } |
|
| 178 | 181 | // se agrega detalle |
| 179 | 182 | $detalle[] = [ |
| 180 | 183 | $d['TpoDoc'], |
@@ -52,15 +52,18 @@ |
||
| 52 | 52 | |
| 53 | 53 | // directorio temporal para guardar los PDF |
| 54 | 54 | $dir = sys_get_temp_dir().'/dte_'.$Caratula['RutEmisor'].'_'.$Caratula['RutReceptor'].'_'.str_replace(['-', ':', 'T'], '', $Caratula['TmstFirmaEnv']); |
| 55 | -if (is_dir($dir)) |
|
| 55 | +if (is_dir($dir)) { |
|
| 56 | 56 | \sasco\LibreDTE\File::rmdir($dir); |
| 57 | -if (!mkdir($dir)) |
|
| 57 | +} |
|
| 58 | +if (!mkdir($dir)) { |
|
| 58 | 59 | die('No fue posible crear directorio temporal para DTEs'); |
| 60 | +} |
|
| 59 | 61 | |
| 60 | 62 | // procesar cada DTEs e ir agregándolo al PDF |
| 61 | 63 | foreach ($Documentos as $DTE) { |
| 62 | - if (!$DTE->getDatos()) |
|
| 63 | - die('No se pudieron obtener los datos del DTE'); |
|
| 64 | + if (!$DTE->getDatos()) { |
|
| 65 | + die('No se pudieron obtener los datos del DTE'); |
|
| 66 | + } |
|
| 64 | 67 | $pdf = new \sasco\LibreDTE\Sii\Dte\PDF\Dte(false); // =false hoja carta, =true papel contínuo (false por defecto si no se pasa) |
| 65 | 68 | $pdf->setFooterText(); |
| 66 | 69 | $pdf->setLogo('/home/delaf/www/localhost/dev/pages/sasco/website/webroot/img/logo_mini.png'); // debe ser PNG! |
@@ -168,8 +168,9 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | public function getName() |
| 170 | 170 | { |
| 171 | - if (isset($this->data['subject']['CN'])) |
|
| 172 | - return $this->data['subject']['CN']; |
|
| 171 | + if (isset($this->data['subject']['CN'])) { |
|
| 172 | + return $this->data['subject']['CN']; |
|
| 173 | + } |
|
| 173 | 174 | return $this->error('No fue posible obtener el Name (subject.CN) de la firma'); |
| 174 | 175 | } |
| 175 | 176 | |
@@ -353,8 +354,9 @@ discard block |
||
| 353 | 354 | */ |
| 354 | 355 | public function verify($data, $signature, $pub_key = null, $signature_alg = OPENSSL_ALGO_SHA1) |
| 355 | 356 | { |
| 356 | - if ($pub_key === null) |
|
| 357 | - $pub_key = $this->certs['cert']; |
|
| 357 | + if ($pub_key === null) { |
|
| 358 | + $pub_key = $this->certs['cert']; |
|
| 359 | + } |
|
| 358 | 360 | $pub_key = $this->normalizeCert($pub_key); |
| 359 | 361 | return openssl_verify($data, base64_decode($signature), $pub_key, $signature_alg) == 1 ? true : false; |
| 360 | 362 | } |
@@ -453,8 +455,9 @@ discard block |
||
| 453 | 455 | // calcular SignatureValue |
| 454 | 456 | $SignedInfo = $doc->saveHTML($Signature->getElementsByTagName('SignedInfo')->item(0)); |
| 455 | 457 | $firma = $this->sign($SignedInfo); |
| 456 | - if (!$firma) |
|
| 457 | - return false; |
|
| 458 | + if (!$firma) { |
|
| 459 | + return false; |
|
| 460 | + } |
|
| 458 | 461 | $signature = wordwrap($firma, $this->config['wordwrap'], "\n", true); |
| 459 | 462 | // reemplazar valores en la firma de |
| 460 | 463 | $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue = $signature; |
@@ -486,8 +489,9 @@ discard block |
||
| 486 | 489 | $signature = $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue; |
| 487 | 490 | $pub_key = $Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue; |
| 488 | 491 | // verificar firma |
| 489 | - if (!$this->verify($signed_info, $signature, $pub_key)) |
|
| 490 | - return false; |
|
| 492 | + if (!$this->verify($signed_info, $signature, $pub_key)) { |
|
| 493 | + return false; |
|
| 494 | + } |
|
| 491 | 495 | // verificar digest |
| 492 | 496 | $digest_original = $Signature->getElementsByTagName('DigestValue')->item(0)->nodeValue; |
| 493 | 497 | if ($tag) { |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | $logs = \sasco\LibreDTE\Log::readAll(); |
| 121 | 121 | if (!empty($logs)) { |
| 122 | 122 | foreach ($logs as $Log) { |
| 123 | - if ($Log->code == \sasco\LibreDTE\Estado::FIRMA_ERROR) { |
|
| 123 | + if ($Log->code==\sasco\LibreDTE\Estado::FIRMA_ERROR) { |
|
| 124 | 124 | throw new \Exception($Log); |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | if (empty($run)) { |
| 131 | 131 | throw new \Exception('No fue posible obtener el RUN de la firma electrónica (verificar contraseña).'); |
| 132 | 132 | } |
| 133 | - if (explode('-', $run)[1] == 'k') { |
|
| 133 | + if (explode('-', $run)[1]=='k') { |
|
| 134 | 134 | throw new \Exception('El RUN '.$run.' asociado a la firma no es válido, termina en "k" (minúscula). Debe adquirir una nueva firma y al comprarla corroborar que la "K" sea mayúscula. Se recomienda no comprar con el mismo proveedor: '.$this->getIssuer().'.'); |
| 135 | 135 | } |
| 136 | 136 | // validar que la firma está vigente |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | if (!$when) { |
| 296 | 296 | $when = date('Y-m-d').' 00:00:00'; |
| 297 | 297 | } |
| 298 | - return $this->getTo() > $when; |
|
| 298 | + return $this->getTo()>$when; |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -411,10 +411,10 @@ discard block |
||
| 411 | 411 | */ |
| 412 | 412 | public function verify($data, $signature, $pub_key = null, $signature_alg = OPENSSL_ALGO_SHA1) |
| 413 | 413 | { |
| 414 | - if ($pub_key === null) |
|
| 414 | + if ($pub_key===null) |
|
| 415 | 415 | $pub_key = $this->certs['cert']; |
| 416 | 416 | $pub_key = $this->normalizeCert($pub_key); |
| 417 | - return openssl_verify($data, base64_decode($signature), $pub_key, $signature_alg) == 1 ? true : false; |
|
| 417 | + return openssl_verify($data, base64_decode($signature), $pub_key, $signature_alg)==1 ? true : false; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | } else { |
| 554 | 554 | $digest_calculado = base64_encode(sha1($doc->C14N(), true)); |
| 555 | 555 | } |
| 556 | - return $digest_original == $digest_calculado; |
|
| 556 | + return $digest_original==$digest_calculado; |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | /** |
@@ -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[(int)$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($retry = null, $gzip = false) |
| 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 |