@@ -76,12 +76,12 @@ |
||
76 | 76 | if (!self::$formatos) { |
77 | 77 | $dir = dirname(__FILE__).'/Formatos'; |
78 | 78 | $formatos = scandir($dir); |
79 | - foreach($formatos as &$formato) { |
|
79 | + foreach ($formatos as &$formato) { |
|
80 | 80 | if ($formato[0]=='.') |
81 | 81 | continue; |
82 | 82 | if (is_dir($dir.'/'.$formato)) { |
83 | 83 | $subformatos = scandir($dir.'/'.$formato); |
84 | - foreach($subformatos as &$subformato) { |
|
84 | + foreach ($subformatos as &$subformato) { |
|
85 | 85 | if ($subformato[0]=='.') |
86 | 86 | continue; |
87 | 87 | self::$formatos[] = $formato.'.'.substr($subformato, 0, -4); |
@@ -77,13 +77,15 @@ |
||
77 | 77 | $dir = dirname(__FILE__).'/Formatos'; |
78 | 78 | $formatos = scandir($dir); |
79 | 79 | foreach($formatos as &$formato) { |
80 | - if ($formato[0]=='.') |
|
81 | - continue; |
|
80 | + if ($formato[0]=='.') { |
|
81 | + continue; |
|
82 | + } |
|
82 | 83 | if (is_dir($dir.'/'.$formato)) { |
83 | 84 | $subformatos = scandir($dir.'/'.$formato); |
84 | 85 | foreach($subformatos as &$subformato) { |
85 | - if ($subformato[0]=='.') |
|
86 | - continue; |
|
86 | + if ($subformato[0]=='.') { |
|
87 | + continue; |
|
88 | + } |
|
87 | 89 | self::$formatos[] = $formato.'.'.substr($subformato, 0, -4); |
88 | 90 | } |
89 | 91 | } else { |
@@ -47,12 +47,13 @@ |
||
47 | 47 | if (!isset($datos['DTE'])) { |
48 | 48 | throw new \Exception('El nodo raíz del string XML debe ser el tag DTE'); |
49 | 49 | } |
50 | - if (isset($datos['DTE']['Documento'])) |
|
51 | - $dte = $datos['DTE']['Documento']; |
|
52 | - else if (isset($datos['DTE']['Exportaciones'])) |
|
53 | - $dte = $datos['DTE']['Exportaciones']; |
|
54 | - else if (isset($datos['DTE']['Liquidacion'])) |
|
55 | - $dte = $datos['DTE']['Liquidacion']; |
|
50 | + if (isset($datos['DTE']['Documento'])) { |
|
51 | + $dte = $datos['DTE']['Documento']; |
|
52 | + } else if (isset($datos['DTE']['Exportaciones'])) { |
|
53 | + $dte = $datos['DTE']['Exportaciones']; |
|
54 | + } else if (isset($datos['DTE']['Liquidacion'])) { |
|
55 | + $dte = $datos['DTE']['Liquidacion']; |
|
56 | + } |
|
56 | 57 | unset($dte['@attributes']); |
57 | 58 | return $dte; |
58 | 59 | } |
@@ -167,9 +167,9 @@ discard block |
||
167 | 167 | // calcular valores que no se hayan entregado |
168 | 168 | if (isset($detalle['FctProp'])) { |
169 | 169 | if ($detalle['IVAUsoComun']===false) |
170 | - $detalle['IVAUsoComun'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
|
170 | + $detalle['IVAUsoComun'] = round($detalle['MntNeto'] * ($detalle['TasaImp'] / 100)); |
|
171 | 171 | } else if (!$detalle['MntIVA'] and !is_array($detalle['IVANoRec']) and $detalle['TasaImp'] and $detalle['MntNeto']) { |
172 | - $detalle['MntIVA'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
|
172 | + $detalle['MntIVA'] = round($detalle['MntNeto'] * ($detalle['TasaImp'] / 100)); |
|
173 | 173 | } |
174 | 174 | // si el monto total es 0 pero no se asigno neto ni exento se coloca |
175 | 175 | if ($detalle['MntExe']===false and $detalle['MntNeto']===false and $detalle['MntTotal']===0) { |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | $MntIVANoRec = explode(',', $detalle['IVANoRec'][0]['MntIVANoRec']); |
186 | 186 | $detalle['IVANoRec'] = []; |
187 | 187 | $n_inr = count($CodIVANoRec); |
188 | - for ($i=0; $i<$n_inr; $i++) { |
|
188 | + for ($i = 0; $i<$n_inr; $i++) { |
|
189 | 189 | $detalle['IVANoRec'][] = [ |
190 | 190 | 'CodIVANoRec' => $CodIVANoRec[$i], |
191 | 191 | 'MntIVANoRec' => $MntIVANoRec[$i], |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | $MntImp = explode(',', $detalle['OtrosImp'][0]['MntImp']); |
205 | 205 | $detalle['OtrosImp'] = []; |
206 | 206 | $n_impuestos = count($CodImp); |
207 | - for ($i=0; $i<$n_impuestos; $i++) { |
|
207 | + for ($i = 0; $i<$n_impuestos; $i++) { |
|
208 | 208 | $detalle['OtrosImp'][] = [ |
209 | 209 | 'CodImp' => $CodImp[$i], |
210 | 210 | 'TasaImp' => !empty($TasaImp[$i]) ? $TasaImp[$i] : false, |
@@ -216,20 +216,20 @@ discard block |
||
216 | 216 | $retenido = ImpuestosAdicionales::getRetenido($detalle['OtrosImp']); |
217 | 217 | if ($retenido) { |
218 | 218 | // si el iva retenido es total |
219 | - if ($retenido == $detalle['MntIVA']) { |
|
219 | + if ($retenido==$detalle['MntIVA']) { |
|
220 | 220 | $detalle['IVARetTotal'] = $retenido; |
221 | 221 | } |
222 | 222 | // si el iva retenido es parcial |
223 | 223 | else { |
224 | 224 | $detalle['IVARetParcial'] = $retenido; |
225 | - $detalle['IVANoRetenido'] = $detalle['MntIVA'] - $retenido; |
|
225 | + $detalle['IVANoRetenido'] = $detalle['MntIVA']-$retenido; |
|
226 | 226 | } |
227 | 227 | } |
228 | 228 | } |
229 | 229 | // calcular monto total si no se especificó |
230 | 230 | if ($detalle['MntTotal']===false) { |
231 | 231 | // calcular monto total inicial |
232 | - $detalle['MntTotal'] = $detalle['MntExe'] + $detalle['MntNeto'] + (int)$detalle['MntIVA']; |
|
232 | + $detalle['MntTotal'] = $detalle['MntExe']+$detalle['MntNeto']+(int)$detalle['MntIVA']; |
|
233 | 233 | // agregar iva no recuperable al monto total |
234 | 234 | if (!empty($detalle['IVANoRec'])) { |
235 | 235 | foreach ($detalle['IVANoRec'] as $IVANoRec) { |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | } |
250 | 250 | } |
251 | 251 | // agregar otro montos e impuestos al total |
252 | - $detalle['MntTotal'] += (int)$detalle['MntSinCred'] + (int)$detalle['TabPuros'] + (int)$detalle['TabCigarrillos'] + (int)$detalle['TabElaborado'] + (int)$detalle['ImpVehiculo']; |
|
252 | + $detalle['MntTotal'] += (int)$detalle['MntSinCred']+(int)$detalle['TabPuros']+(int)$detalle['TabCigarrillos']+(int)$detalle['TabElaborado']+(int)$detalle['ImpVehiculo']; |
|
253 | 253 | } |
254 | 254 | // si no hay no hay monto neto, no se crean campos para IVA |
255 | 255 | if ($detalle['MntNeto']===false) { |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | $data = \sasco\LibreDTE\CSV::read($archivo); |
310 | 310 | $n_data = count($data); |
311 | 311 | $detalles = []; |
312 | - for ($i=1; $i<$n_data; $i++) { |
|
312 | + for ($i = 1; $i<$n_data; $i++) { |
|
313 | 313 | // detalle genérico |
314 | 314 | $detalle = [ |
315 | 315 | 'TpoDoc' => $data[$i][0], |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | if (!empty($data[$i][11])) { |
345 | 345 | $detalle['IVANoRec'] = [ |
346 | 346 | 'CodIVANoRec' => $data[$i][11], |
347 | - 'MntIVANoRec' => !empty($data[$i][12]) ? $data[$i][12] : round($detalle['MntNeto'] * ($detalle['TasaImp']/100)), |
|
347 | + 'MntIVANoRec' => !empty($data[$i][12]) ? $data[$i][12] : round($detalle['MntNeto'] * ($detalle['TasaImp'] / 100)), |
|
348 | 348 | ]; |
349 | 349 | } |
350 | 350 | // agregar código y monto de otros impuestos |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | $detalle['OtrosImp'] = [ |
353 | 353 | 'CodImp' => $data[$i][14], |
354 | 354 | 'TasaImp' => !empty($data[$i][15]) ? $data[$i][15] : 0, |
355 | - 'MntImp' => !empty($data[$i][16]) ? $data[$i][16] : round($detalle['MntNeto'] * ($data[$i][15]/100)), |
|
355 | + 'MntImp' => !empty($data[$i][16]) ? $data[$i][16] : round($detalle['MntNeto'] * ($data[$i][15] / 100)), |
|
356 | 356 | ]; |
357 | 357 | } |
358 | 358 | // si hay monto total se agrega |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | $data = \sasco\LibreDTE\CSV::read($archivo); |
428 | 428 | $n_data = count($data); |
429 | 429 | $detalles = []; |
430 | - for ($i=1; $i<$n_data; $i++) { |
|
430 | + for ($i = 1; $i<$n_data; $i++) { |
|
431 | 431 | // detalle genérico |
432 | 432 | $detalle = [ |
433 | 433 | 'TpoDoc' => $data[$i][0], |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | $detalle['OtrosImp'] = [ |
467 | 467 | 'CodImp' => $data[$i][11], |
468 | 468 | 'TasaImp' => !empty($data[$i][12]) ? $data[$i][12] : false, |
469 | - 'MntImp' => !empty($data[$i][13]) ? $data[$i][13] : round($detalle['MntNeto'] * ($data[$i][12]/100)), |
|
469 | + 'MntImp' => !empty($data[$i][13]) ? $data[$i][13] : round($detalle['MntNeto'] * ($data[$i][12] / 100)), |
|
470 | 470 | ]; |
471 | 471 | } |
472 | 472 | // agregar datos extranjeros |
@@ -628,8 +628,8 @@ discard block |
||
628 | 628 | // si hay IVA de uso común se contabiliza |
629 | 629 | if (!empty($d['FctProp'])) { |
630 | 630 | $totales[$d['TpoDoc']]['TotIVAUsoComun'] += $d['IVAUsoComun']; |
631 | - $totales[$d['TpoDoc']]['FctProp'] = $d['FctProp']/100; |
|
632 | - $totales[$d['TpoDoc']]['TotCredIVAUsoComun'] += round($d['IVAUsoComun'] * ($d['FctProp']/100)); |
|
631 | + $totales[$d['TpoDoc']]['FctProp'] = $d['FctProp'] / 100; |
|
632 | + $totales[$d['TpoDoc']]['TotCredIVAUsoComun'] += round($d['IVAUsoComun'] * ($d['FctProp'] / 100)); |
|
633 | 633 | unset($d['FctProp']); // se quita el factor de proporcionalidad del detalle ya que no es parte del XML |
634 | 634 | } |
635 | 635 | // contabilizar IVA fuera de plazo |
@@ -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); |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | // buscar el caso y copiar sus columnas que no estén |
263 | 263 | $detalle_r = $documentos[$caso['referencia']['caso']]['Detalle']; |
264 | 264 | $n_detalle_r = count($detalle_r); |
265 | - for ($i=0; $i<$n_detalle_r; $i++) { |
|
265 | + for ($i = 0; $i<$n_detalle_r; $i++) { |
|
266 | 266 | if ($detalle_r[$i]['NmbItem']==$detalle['NmbItem']) { |
267 | 267 | foreach ($detalle_r[$i] as $attr => $val) { |
268 | 268 | if (!isset($detalle[$attr])) |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | $documento['DscRcgGlobal'][] = [ |
326 | 326 | 'TpoMov' => 'R', |
327 | 327 | 'TpoValor' => '$', |
328 | - 'ValorDR' => round((substr($caso['recargo-total-clausula'], 0, -1)/100) * $documento['Encabezado']['Transporte']['Aduana']['TotClauVenta'], 2), |
|
328 | + 'ValorDR' => round((substr($caso['recargo-total-clausula'], 0, -1) / 100) * $documento['Encabezado']['Transporte']['Aduana']['TotClauVenta'], 2), |
|
329 | 329 | ]; |
330 | 330 | } |
331 | 331 | // agregar recargo por flete y/o seguro, se agrega sólo en factura |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | $casos = explode($separador, $archivo); |
467 | 467 | $separador_len = strlen($separador); |
468 | 468 | $n_casos = count($casos); |
469 | - for ($i=1; $i<$n_casos; $i++) { |
|
469 | + for ($i = 1; $i<$n_casos; $i++) { |
|
470 | 470 | $caso = trim($casos[$i]); |
471 | 471 | $caso_anterior = trim($casos[$i-1]); |
472 | 472 | $caso_titulo = substr($caso_anterior, -$separador_len); |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | $titulos = array_slice(array_filter(explode("\t", $lineas[$linea_titulos_detalles])), 0); |
524 | 524 | // extraer detalles |
525 | 525 | $datos['detalle'] = []; |
526 | - $i = $linea_titulos_detalles + 1; |
|
526 | + $i = $linea_titulos_detalles+1; |
|
527 | 527 | while (!empty($lineas[$i])) { |
528 | 528 | $item = array_slice(array_filter(explode("\t", $lineas[$i])), 0); |
529 | 529 | $n_item = count($item); |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | // sólo continuar si hay más líneas, será, por ej, el descuento global |
538 | 538 | if (isset($lineas[$i])) { |
539 | 539 | $n_lineas = count($lineas); |
540 | - for ($i=$i; $i<$n_lineas; $i++) { |
|
540 | + for ($i = $i; $i<$n_lineas; $i++) { |
|
541 | 541 | // si la línea está vacía se omite |
542 | 542 | if (!$lineas[$i]) |
543 | 543 | continue; |
@@ -154,8 +154,9 @@ discard block |
||
154 | 154 | foreach ($casos as $caso) { |
155 | 155 | // determinar tipo documento y folio |
156 | 156 | $TipoDTE = self::$tipos[$caso['documento']]; |
157 | - if (!isset($folios[$TipoDTE])) |
|
158 | - $folios[$TipoDTE] = 1; |
|
157 | + if (!isset($folios[$TipoDTE])) { |
|
158 | + $folios[$TipoDTE] = 1; |
|
159 | + } |
|
159 | 160 | $Folio = $folios[$TipoDTE]; |
160 | 161 | // crear encabezado del documento |
161 | 162 | $documento = [ |
@@ -257,14 +258,17 @@ discard block |
||
257 | 258 | foreach ($item as $col => $val) { |
258 | 259 | $col = self::$item_cols[$col]; |
259 | 260 | // procesar cada valor de acuerdo al nombre de la columna |
260 | - if (in_array($col, ['DescuentoPct', 'RecargoPct'])) |
|
261 | - $detalle[$col] = substr($val, 0, -1); |
|
262 | - else |
|
263 | - $detalle[$col] = utf8_encode($val); // se convierte de ISO-8859-1 a UTF-8 |
|
261 | + if (in_array($col, ['DescuentoPct', 'RecargoPct'])) { |
|
262 | + $detalle[$col] = substr($val, 0, -1); |
|
263 | + } else { |
|
264 | + $detalle[$col] = utf8_encode($val); |
|
265 | + } |
|
266 | + // se convierte de ISO-8859-1 a UTF-8 |
|
264 | 267 | } |
265 | 268 | // si el item es EXENTO se agrega campo que lo indica |
266 | - if (strpos($detalle['NmbItem'], 'EXENTO')) |
|
267 | - $detalle['IndExe'] = 1; |
|
269 | + if (strpos($detalle['NmbItem'], 'EXENTO')) { |
|
270 | + $detalle['IndExe'] = 1; |
|
271 | + } |
|
268 | 272 | // si hay una referencia se completa con los campos del |
269 | 273 | // detalle de la referencia que no estén en este detalle |
270 | 274 | if (!empty($caso['referencia'])) { |
@@ -274,8 +278,9 @@ discard block |
||
274 | 278 | for ($i=0; $i<$n_detalle_r; $i++) { |
275 | 279 | if ($detalle_r[$i]['NmbItem']==$detalle['NmbItem']) { |
276 | 280 | foreach ($detalle_r[$i] as $attr => $val) { |
277 | - if (!isset($detalle[$attr])) |
|
278 | - $detalle[$attr] = $val; |
|
281 | + if (!isset($detalle[$attr])) { |
|
282 | + $detalle[$attr] = $val; |
|
283 | + } |
|
279 | 284 | } |
280 | 285 | } |
281 | 286 | } |
@@ -359,8 +364,9 @@ discard block |
||
359 | 364 | 'ValorDR' => substr($caso['recargo'], 0, -1), |
360 | 365 | ]; |
361 | 366 | } |
362 | - if (empty($documento['DscRcgGlobal'])) |
|
363 | - unset($documento['DscRcgGlobal']); |
|
367 | + if (empty($documento['DscRcgGlobal'])) { |
|
368 | + unset($documento['DscRcgGlobal']); |
|
369 | + } |
|
364 | 370 | // agregar descuento del documento de la referencia |
365 | 371 | else if (!empty($caso['referencia'])) { |
366 | 372 | $referencia = self::getReferencia($caso['referencia']['razon']); |
@@ -392,14 +398,16 @@ discard block |
||
392 | 398 | // agregar totales |
393 | 399 | $documento['Encabezado']['Totales'] = $referencia['Totales']; |
394 | 400 | // agregar tasa de IVA si corresponde |
395 | - if (isset($documento['Encabezado']['Totales']['TasaIVA'])) |
|
396 | - $documento['Encabezado']['Totales']['TasaIVA'] = \sasco\LibreDTE\Sii::getIVA(); |
|
401 | + if (isset($documento['Encabezado']['Totales']['TasaIVA'])) { |
|
402 | + $documento['Encabezado']['Totales']['TasaIVA'] = \sasco\LibreDTE\Sii::getIVA(); |
|
403 | + } |
|
397 | 404 | // si el documento referenciado es factura exenta y hay MntExe |
398 | 405 | if (isset($documento['Encabezado']['Totales']['MntExe'])) { |
399 | - if ($documentos[$caso['referencia']['caso']]['Encabezado']['IdDoc']['TipoDTE']==34) |
|
400 | - $documento['Encabezado']['Totales']['MntExe'] = 0; |
|
401 | - else |
|
402 | - unset($documento['Encabezado']['Totales']['MntExe']); |
|
406 | + if ($documentos[$caso['referencia']['caso']]['Encabezado']['IdDoc']['TipoDTE']==34) { |
|
407 | + $documento['Encabezado']['Totales']['MntExe'] = 0; |
|
408 | + } else { |
|
409 | + unset($documento['Encabezado']['Totales']['MntExe']); |
|
410 | + } |
|
403 | 411 | } |
404 | 412 | // si es documento de exportación se resetean los totales y se copia el tipo de moneda si no existe |
405 | 413 | if (in_array($documento['Encabezado']['IdDoc']['TipoDTE'], [111, 112])) { |
@@ -412,8 +420,9 @@ discard block |
||
412 | 420 | } |
413 | 421 | // agregar referencia de exportación si existe |
414 | 422 | if (!empty($caso['exportacion']['REFERENCIA'])) { |
415 | - if (!is_array($caso['exportacion']['REFERENCIA'])) |
|
416 | - $caso['exportacion']['REFERENCIA'] = [$caso['exportacion']['REFERENCIA']]; |
|
423 | + if (!is_array($caso['exportacion']['REFERENCIA'])) { |
|
424 | + $caso['exportacion']['REFERENCIA'] = [$caso['exportacion']['REFERENCIA']]; |
|
425 | + } |
|
417 | 426 | foreach ($caso['exportacion']['REFERENCIA'] as $ref) { |
418 | 427 | $documento['Referencia'][] = [ |
419 | 428 | 'TpoDocRef' => self::$referencias_exportacion[$ref], |
@@ -433,14 +442,16 @@ discard block |
||
433 | 442 | if (isset($documento['Encabezado']['Totales'])) { |
434 | 443 | $hayValor = false; |
435 | 444 | foreach ($documento['Detalle'] as $d) { |
436 | - if (!empty($d['PrcItem'])) |
|
437 | - $hayValor = true; |
|
445 | + if (!empty($d['PrcItem'])) { |
|
446 | + $hayValor = true; |
|
447 | + } |
|
438 | 448 | } |
439 | 449 | if (!$hayValor) { |
440 | - if (isset($documento['Encabezado']['Totales']['MntExe'])) |
|
441 | - $documento['Encabezado']['Totales'] = ['MntExe'=>0]; |
|
442 | - else |
|
443 | - $documento['Encabezado']['Totales'] = []; |
|
450 | + if (isset($documento['Encabezado']['Totales']['MntExe'])) { |
|
451 | + $documento['Encabezado']['Totales'] = ['MntExe'=>0]; |
|
452 | + } else { |
|
453 | + $documento['Encabezado']['Totales'] = []; |
|
454 | + } |
|
444 | 455 | $documento['Encabezado']['Totales']['MntTotal'] = 0; |
445 | 456 | } |
446 | 457 | } |
@@ -548,8 +559,9 @@ discard block |
||
548 | 559 | $n_lineas = count($lineas); |
549 | 560 | for ($i=$i; $i<$n_lineas; $i++) { |
550 | 561 | // si la línea está vacía se omite |
551 | - if (!$lineas[$i]) |
|
552 | - continue; |
|
562 | + if (!$lineas[$i]) { |
|
563 | + continue; |
|
564 | + } |
|
553 | 565 | // si hay descuento global se guarda |
554 | 566 | if (strpos($lineas[$i], 'DESCUENTO GLOBAL ITEMES AFECTOS')===0) { |
555 | 567 | $aux = explode("\t", $lineas[$i]); |
@@ -585,13 +597,15 @@ discard block |
||
585 | 597 | } |
586 | 598 | // agregar a los datos de aduanas |
587 | 599 | else { |
588 | - if (!isset($datos['exportacion'])) |
|
589 | - $datos['exportacion'] = []; |
|
600 | + if (!isset($datos['exportacion'])) { |
|
601 | + $datos['exportacion'] = []; |
|
602 | + } |
|
590 | 603 | if (!isset($datos['exportacion'][$var])) { |
591 | 604 | $datos['exportacion'][$var] = $val; |
592 | 605 | } else { |
593 | - if (!is_array($datos['exportacion'][$var])) |
|
594 | - $datos['exportacion'][$var] = [$datos['exportacion'][$var]]; |
|
606 | + if (!is_array($datos['exportacion'][$var])) { |
|
607 | + $datos['exportacion'][$var] = [$datos['exportacion'][$var]]; |
|
608 | + } |
|
595 | 609 | $datos['exportacion'][$var][] = $val; |
596 | 610 | } |
597 | 611 | } |
@@ -170,13 +170,13 @@ |
||
170 | 170 | } |
171 | 171 | // determinar neto e iva |
172 | 172 | $tasa = \sasco\LibreDTE\Sii::getIVA(); |
173 | - $neto = round(($d['MntTotal'] - $d['MntExe']) / (1 + $tasa/100)); |
|
173 | + $neto = round(($d['MntTotal']-$d['MntExe']) / (1+$tasa / 100)); |
|
174 | 174 | if ($neto) { |
175 | 175 | $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntNeto'] += $neto; |
176 | 176 | $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TasaIVA'] = $tasa; |
177 | 177 | // WARNING: problema por aproximaciones al calcular el NETO e IVA a partir del BRUTO |
178 | 178 | //$resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntIVA'] = round($resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntNeto'] * ($tasa/100)); |
179 | - $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntIVA'] = $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntTotal'] - $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntExe'] - $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntNeto']; |
|
179 | + $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntIVA'] = $resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntTotal']-$resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntExe']-$resumen[$d['TpoDoc']]['TotalesServicio'][$d['TpoServ']]['TotMntNeto']; |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | // documento anulado |
@@ -91,8 +91,9 @@ |
||
91 | 91 | public function generar() |
92 | 92 | { |
93 | 93 | // si ya se había generado se entrega directamente |
94 | - if ($this->xml_data) |
|
95 | - return $this->xml_data; |
|
94 | + if ($this->xml_data) { |
|
95 | + return $this->xml_data; |
|
96 | + } |
|
96 | 97 | // generar XML del envío |
97 | 98 | $xmlEnvio = (new \sasco\LibreDTE\XML())->generate([ |
98 | 99 | 'LibroBoleta' => [ |
@@ -36,7 +36,7 @@ |
||
36 | 36 | { |
37 | 37 | |
38 | 38 | private static $idioma = 'es'; ///< Idioma por defecto de los mensajes |
39 | - private static $locales = [ ///< Mapeo de idioma a locales |
|
39 | + private static $locales = [///< Mapeo de idioma a locales |
|
40 | 40 | 'es' => 'es_CL.utf8', |
41 | 41 | 'en' => 'en_US.utf8', |
42 | 42 | ]; |
@@ -53,8 +53,9 @@ |
||
53 | 53 | */ |
54 | 54 | public static function getCiudad($comuna) |
55 | 55 | { |
56 | - if (!$comuna) |
|
57 | - return false; |
|
56 | + if (!$comuna) { |
|
57 | + return false; |
|
58 | + } |
|
58 | 59 | $comuna = mb_strtoupper($comuna, 'UTF-8'); |
59 | 60 | return isset(self::$ciudades[$comuna]) ? self::$ciudades[$comuna] : false; |
60 | 61 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | public static function mergeRecursiveDistinct(array $array1, array $array2) |
43 | 43 | { |
44 | 44 | $merged = $array1; |
45 | - foreach ( $array2 as $key => &$value ) { |
|
45 | + foreach ($array2 as $key => &$value) { |
|
46 | 46 | if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) { |
47 | 47 | $merged [$key] = self::mergeRecursiveDistinct( |
48 | 48 | $merged [$key], |
@@ -317,10 +317,10 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public function verify($data, $signature, $pub_key = null, $signature_alg = OPENSSL_ALGO_SHA1) |
319 | 319 | { |
320 | - if ($pub_key === null) |
|
320 | + if ($pub_key===null) |
|
321 | 321 | $pub_key = $this->certs['cert']; |
322 | 322 | $pub_key = $this->normalizeCert($pub_key); |
323 | - return openssl_verify($data, base64_decode($signature), $pub_key, $signature_alg) == 1 ? true : false; |
|
323 | + return openssl_verify($data, base64_decode($signature), $pub_key, $signature_alg)==1 ? true : false; |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | } else { |
452 | 452 | $digest_calculado = base64_encode(sha1($doc->C14N(), true)); |
453 | 453 | } |
454 | - return $digest_original == $digest_calculado; |
|
454 | + return $digest_original==$digest_calculado; |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | /** |
101 | 101 | * Método para generar un error usando una excepción de SowerPHP o terminar |
102 | 102 | * el script si no se está usando el framework |
103 | - * @param msg Mensaje del error |
|
103 | + * @param msg string del error |
|
104 | 104 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
105 | 105 | * @version 2017-08-04 |
106 | 106 | */ |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | /** |
190 | 190 | * Método que entrega desde cuando es válida la firma |
191 | - * @return validFrom_time_t |
|
191 | + * @return string |
|
192 | 192 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
193 | 193 | * @version 2015-09-22 |
194 | 194 | */ |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | |
200 | 200 | /** |
201 | 201 | * Método que entrega hasta cuando es válida la firma |
202 | - * @return validTo_time_t |
|
202 | + * @return string |
|
203 | 203 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
204 | 204 | * @version 2015-09-22 |
205 | 205 | */ |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | |
233 | 233 | /** |
234 | 234 | * Método que obtiene el módulo de la clave privada |
235 | - * @return Módulo en base64 |
|
235 | + * @return string en base64 |
|
236 | 236 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
237 | 237 | * @version 2014-12-07 |
238 | 238 | */ |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | |
245 | 245 | /** |
246 | 246 | * Método que obtiene el exponente público de la clave privada |
247 | - * @return Exponente público en base64 |
|
247 | + * @return string público en base64 |
|
248 | 248 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
249 | 249 | * @version 2014-12-06 |
250 | 250 | */ |
@@ -294,9 +294,9 @@ discard block |
||
294 | 294 | |
295 | 295 | /** |
296 | 296 | * Método para realizar la firma de datos |
297 | - * @param data Datos que se desean firmar |
|
297 | + * @param data string que se desean firmar |
|
298 | 298 | * @param signature_alg Algoritmo que se utilizará para firmar (por defect SHA1) |
299 | - * @return Firma digital de los datos en base64 o =false si no se pudo firmar |
|
299 | + * @return boolean|string digital de los datos en base64 o =false si no se pudo firmar |
|
300 | 300 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
301 | 301 | * @version 2014-12-08 |
302 | 302 | */ |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | |
312 | 312 | /** |
313 | 313 | * Método que verifica la firma digital de datos |
314 | - * @param data Datos que se desean verificar |
|
314 | + * @param data string que se desean verificar |
|
315 | 315 | * @param signature Firma digital de los datos en base64 |
316 | 316 | * @param pub_key Certificado digital, clave pública, de la firma |
317 | 317 | * @param signature_alg Algoritmo que se usó para firmar (por defect SHA1) |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | * |
335 | 335 | * @param xml Datos XML que se desean firmar |
336 | 336 | * @param reference Referencia a la que hace la firma |
337 | - * @return XML firmado o =false si no se pudo fimar |
|
337 | + * @return boolean|string firmado o =false si no se pudo fimar |
|
338 | 338 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
339 | 339 | * @version 2017-10-22 |
340 | 340 | */ |
@@ -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) { |