@@ -813,8 +813,9 @@ discard block |
||
813 | 813 | */ |
814 | 814 | public static function getGlosa($tag) |
815 | 815 | { |
816 | - if (!isset(self::$tablas[$tag])) |
|
817 | - return false; |
|
816 | + if (!isset(self::$tablas[$tag])) { |
|
817 | + return false; |
|
818 | + } |
|
818 | 819 | return is_array(self::$tablas[$tag]) ? self::$tablas[$tag]['glosa'] : self::$tablas[$tag]; |
819 | 820 | } |
820 | 821 | |
@@ -825,10 +826,12 @@ discard block |
||
825 | 826 | */ |
826 | 827 | public static function getValor($tag, $codigo) |
827 | 828 | { |
828 | - if (!isset(self::$tablas[$tag])) |
|
829 | - return false; |
|
830 | - if (!is_array(self::$tablas[$tag])) |
|
831 | - return $codigo; |
|
829 | + if (!isset(self::$tablas[$tag])) { |
|
830 | + return false; |
|
831 | + } |
|
832 | + if (!is_array(self::$tablas[$tag])) { |
|
833 | + return $codigo; |
|
834 | + } |
|
832 | 835 | $tabla = isset(self::$tablas[$tag]['valor']) ? self::$tablas[$tag]['valor'] : self::$tablas[self::$tablas[$tag]['tabla']]; |
833 | 836 | if ($tag=='TipoBultos') { |
834 | 837 | $valor = isset($tabla[$codigo['CodTpoBultos']]) ? $tabla[$codigo['CodTpoBultos']] : $codigo['CodTpoBultos']; |
@@ -868,8 +871,9 @@ discard block |
||
868 | 871 | { |
869 | 872 | self::$tablasInvertidas = []; |
870 | 873 | foreach (self::$tablas as $tag => $info) { |
871 | - if (is_string($info) or (!isset($info['valor']) and !isset($info['tabla']))) |
|
872 | - continue; |
|
874 | + if (is_string($info) or (!isset($info['valor']) and !isset($info['tabla']))) { |
|
875 | + continue; |
|
876 | + } |
|
873 | 877 | $tabla = isset($info['valor']) ? $info['valor'] : self::$tablas[$info['tabla']]; |
874 | 878 | foreach ($tabla as &$val) { |
875 | 879 | $val = str_replace( |
@@ -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 |
@@ -96,10 +96,12 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function agregar(array $detalle, $normalizar = true) |
98 | 98 | { |
99 | - if ($normalizar) |
|
100 | - $this->normalizarDetalle($detalle); |
|
101 | - if (!$detalle['TpoDoc']) |
|
102 | - return false; |
|
99 | + if ($normalizar) { |
|
100 | + $this->normalizarDetalle($detalle); |
|
101 | + } |
|
102 | + if (!$detalle['TpoDoc']) { |
|
103 | + return false; |
|
104 | + } |
|
103 | 105 | $this->detalles[] = $detalle; |
104 | 106 | return true; |
105 | 107 | } |
@@ -166,8 +168,9 @@ discard block |
||
166 | 168 | $detalle['RznSoc'] = substr($detalle['RznSoc'], 0, 50); |
167 | 169 | // calcular valores que no se hayan entregado |
168 | 170 | if (isset($detalle['FctProp'])) { |
169 | - if ($detalle['IVAUsoComun']===false) |
|
170 | - $detalle['IVAUsoComun'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
|
171 | + if ($detalle['IVAUsoComun']===false) { |
|
172 | + $detalle['IVAUsoComun'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
|
173 | + } |
|
171 | 174 | } else if (!$detalle['MntIVA'] and !is_array($detalle['IVANoRec']) and $detalle['TasaImp'] and $detalle['MntNeto']) { |
172 | 175 | $detalle['MntIVA'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
173 | 176 | } |
@@ -177,8 +180,9 @@ discard block |
||
177 | 180 | } |
178 | 181 | // normalizar IVA no recuperable |
179 | 182 | if (!empty($detalle['IVANoRec'])) { |
180 | - if (!isset($detalle['IVANoRec'][0])) |
|
181 | - $detalle['IVANoRec'] = [$detalle['IVANoRec']]; |
|
183 | + if (!isset($detalle['IVANoRec'][0])) { |
|
184 | + $detalle['IVANoRec'] = [$detalle['IVANoRec']]; |
|
185 | + } |
|
182 | 186 | // si son múltiples iva no recuperable se arma arreglo real |
183 | 187 | if (strpos($detalle['IVANoRec'][0]['CodIVANoRec'], ',')) { |
184 | 188 | $CodIVANoRec = explode(',', $detalle['IVANoRec'][0]['CodIVANoRec']); |
@@ -195,8 +199,9 @@ discard block |
||
195 | 199 | } |
196 | 200 | // normalizar otros impuestos |
197 | 201 | if (!empty($detalle['OtrosImp'])) { |
198 | - if (!isset($detalle['OtrosImp'][0])) |
|
199 | - $detalle['OtrosImp'] = [$detalle['OtrosImp']]; |
|
202 | + if (!isset($detalle['OtrosImp'][0])) { |
|
203 | + $detalle['OtrosImp'] = [$detalle['OtrosImp']]; |
|
204 | + } |
|
200 | 205 | // si son múltiples impuestos se arma arreglo real |
201 | 206 | if (strpos($detalle['OtrosImp'][0]['CodImp'], ',')) { |
202 | 207 | $CodImp = explode(',', $detalle['OtrosImp'][0]['CodImp']); |
@@ -257,8 +262,9 @@ discard block |
||
257 | 262 | } |
258 | 263 | // si el código de sucursal no existe se pone a falso, esto básicamente |
259 | 264 | // porque algunos sistemas podrían usar 0 cuando no hay CdgSIISucur |
260 | - if (!$detalle['CdgSIISucur']) |
|
261 | - $detalle['CdgSIISucur'] = false; |
|
265 | + if (!$detalle['CdgSIISucur']) { |
|
266 | + $detalle['CdgSIISucur'] = false; |
|
267 | + } |
|
262 | 268 | } |
263 | 269 | |
264 | 270 | /** |
@@ -513,8 +519,9 @@ discard block |
||
513 | 519 | 'TipoEnvio' => 'TOTAL', |
514 | 520 | 'FolioNotificacion' => false, |
515 | 521 | ], $caratula); |
516 | - if ($this->caratula['TipoEnvio']=='ESPECIAL') |
|
517 | - $this->caratula['FolioNotificacion'] = null; |
|
522 | + if ($this->caratula['TipoEnvio']=='ESPECIAL') { |
|
523 | + $this->caratula['FolioNotificacion'] = null; |
|
524 | + } |
|
518 | 525 | $this->id = 'LibreDTE_LIBRO_'.$this->caratula['TipoOperacion'].'_'.str_replace('-', '', $this->caratula['RutEmisorLibro']).'_'.str_replace('-', '', $this->caratula['PeriodoTributario']).'_'.date('U'); |
519 | 526 | } |
520 | 527 | |
@@ -528,8 +535,9 @@ discard block |
||
528 | 535 | public function generar($incluirDetalle = true) |
529 | 536 | { |
530 | 537 | // si ya se había generado se entrega directamente |
531 | - if ($this->xml_data) |
|
532 | - return $this->xml_data; |
|
538 | + if ($this->xml_data) { |
|
539 | + return $this->xml_data; |
|
540 | + } |
|
533 | 541 | // generar totales de DTE y sus montos |
534 | 542 | $TotalesPeriodo = $this->getResumen(); |
535 | 543 | $ResumenPeriodo = $TotalesPeriodo ? ['TotalesPeriodo'=>$TotalesPeriodo] : false; |
@@ -604,13 +612,16 @@ discard block |
||
604 | 612 | } |
605 | 613 | $totales[$d['TpoDoc']]['TotMntTotal'] += $d['MntTotal']; |
606 | 614 | // contabilizar documentos anulados |
607 | - if (!empty($d['Anulado']) and $d['Anulado']=='A') |
|
608 | - $totales[$d['TpoDoc']]['TotAnulado']++; |
|
615 | + if (!empty($d['Anulado']) and $d['Anulado']=='A') { |
|
616 | + $totales[$d['TpoDoc']]['TotAnulado']++; |
|
617 | + } |
|
609 | 618 | // si hay activo fijo se contabiliza |
610 | - if (!empty($d['MntActivoFijo'])) |
|
611 | - $totales[$d['TpoDoc']]['TotMntActivoFijo'] += $d['MntActivoFijo']; |
|
612 | - if (!empty($d['MntIVAActivoFijo'])) |
|
613 | - $totales[$d['TpoDoc']]['TotMntIVAActivoFijo'] += $d['MntIVAActivoFijo']; |
|
619 | + if (!empty($d['MntActivoFijo'])) { |
|
620 | + $totales[$d['TpoDoc']]['TotMntActivoFijo'] += $d['MntActivoFijo']; |
|
621 | + } |
|
622 | + if (!empty($d['MntIVAActivoFijo'])) { |
|
623 | + $totales[$d['TpoDoc']]['TotMntIVAActivoFijo'] += $d['MntIVAActivoFijo']; |
|
624 | + } |
|
614 | 625 | // si hay iva no recuperable se contabiliza |
615 | 626 | if (!empty($d['IVANoRec'])) { |
616 | 627 | foreach ($d['IVANoRec'] as $IVANoRec) { |
@@ -633,8 +644,9 @@ discard block |
||
633 | 644 | unset($d['FctProp']); // se quita el factor de proporcionalidad del detalle ya que no es parte del XML |
634 | 645 | } |
635 | 646 | // contabilizar IVA fuera de plazo |
636 | - if (!empty($d['IVAFueraPlazo'])) |
|
637 | - $totales[$d['TpoDoc']]['TotIVAFueraPlazo'] += $d['IVAFueraPlazo']; |
|
647 | + if (!empty($d['IVAFueraPlazo'])) { |
|
648 | + $totales[$d['TpoDoc']]['TotIVAFueraPlazo'] += $d['IVAFueraPlazo']; |
|
649 | + } |
|
638 | 650 | // si hay otro tipo de impuesto se contabiliza |
639 | 651 | if (!empty($d['OtrosImp'])) { |
640 | 652 | foreach ($d['OtrosImp'] as $OtrosImp) { |
@@ -648,17 +660,21 @@ discard block |
||
648 | 660 | } |
649 | 661 | } |
650 | 662 | // contabilizar impuesto sin derecho a crédito |
651 | - if (!empty($d['MntSinCred'])) |
|
652 | - $totales[$d['TpoDoc']]['TotImpSinCredito'] += $d['MntSinCred']; |
|
663 | + if (!empty($d['MntSinCred'])) { |
|
664 | + $totales[$d['TpoDoc']]['TotImpSinCredito'] += $d['MntSinCred']; |
|
665 | + } |
|
653 | 666 | // contabilidad IVA retenido total |
654 | - if (!empty($d['IVARetTotal'])) |
|
655 | - $totales[$d['TpoDoc']]['TotIVARetTotal'] += $d['IVARetTotal']; |
|
667 | + if (!empty($d['IVARetTotal'])) { |
|
668 | + $totales[$d['TpoDoc']]['TotIVARetTotal'] += $d['IVARetTotal']; |
|
669 | + } |
|
656 | 670 | // contabilizar IVA retenido parcial |
657 | - if (!empty($d['IVARetParcial'])) |
|
658 | - $totales[$d['TpoDoc']]['TotIVARetParcial'] += $d['IVARetParcial']; |
|
671 | + if (!empty($d['IVARetParcial'])) { |
|
672 | + $totales[$d['TpoDoc']]['TotIVARetParcial'] += $d['IVARetParcial']; |
|
673 | + } |
|
659 | 674 | // contabilizar IVA no retenido |
660 | - if (!empty($d['IVANoRetenido'])) |
|
661 | - $totales[$d['TpoDoc']]['TotIVANoRetenido'] += $d['IVANoRetenido']; |
|
675 | + if (!empty($d['IVANoRetenido'])) { |
|
676 | + $totales[$d['TpoDoc']]['TotIVANoRetenido'] += $d['IVANoRetenido']; |
|
677 | + } |
|
662 | 678 | } |
663 | 679 | // agregar resumenes pasados que no se hayan generado por los detalles |
664 | 680 | foreach ($this->resumen as $tipo => $resumen) { |
@@ -682,8 +698,9 @@ discard block |
||
682 | 698 | $manual = []; |
683 | 699 | if (isset($this->toArray()['LibroCompraVenta']['EnvioLibro']['ResumenPeriodo']['TotalesPeriodo'])) { |
684 | 700 | $totales = $this->toArray()['LibroCompraVenta']['EnvioLibro']['ResumenPeriodo']['TotalesPeriodo']; |
685 | - if (!isset($totales[0])) |
|
686 | - $totales = [$totales]; |
|
701 | + if (!isset($totales[0])) { |
|
702 | + $totales = [$totales]; |
|
703 | + } |
|
687 | 704 | foreach ($totales as $total) { |
688 | 705 | if (isset($total['TpoDoc']) and in_array($total['TpoDoc'], [35, 38, 48])) { |
689 | 706 | $manual[$total['TpoDoc']] = array_merge($this->total_default, $total); |
@@ -703,8 +720,9 @@ discard block |
||
703 | 720 | $manual = []; |
704 | 721 | if (isset($this->toArray()['LibroCompraVenta']['EnvioLibro']['ResumenPeriodo']['TotalesPeriodo'])) { |
705 | 722 | $totales = $this->toArray()['LibroCompraVenta']['EnvioLibro']['ResumenPeriodo']['TotalesPeriodo']; |
706 | - if (!isset($totales[0])) |
|
707 | - $totales = [$totales]; |
|
723 | + if (!isset($totales[0])) { |
|
724 | + $totales = [$totales]; |
|
725 | + } |
|
708 | 726 | foreach ($totales as $total) { |
709 | 727 | if (in_array($total['TpoDoc'], [39, 41])) { |
710 | 728 | $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 = [ |
@@ -219,8 +220,9 @@ discard block |
||
219 | 220 | $documento['Encabezado']['Transporte']['Aduana']['TipoBultos']['EmisorSello'] = 'Sellos de Chile'; |
220 | 221 | } |
221 | 222 | } |
222 | - if (empty($documento['Encabezado']['Transporte']['Aduana'])) |
|
223 | - unset($documento['Encabezado']['Transporte']); |
|
223 | + if (empty($documento['Encabezado']['Transporte']['Aduana'])) { |
|
224 | + unset($documento['Encabezado']['Transporte']); |
|
225 | + } |
|
224 | 226 | // agregar moneda a los totales |
225 | 227 | if (!empty($caso['exportacion']['MONEDA DE LA OPERACION'])) { |
226 | 228 | $documento['Encabezado']['Totales']['TpoMoneda'] = $caso['exportacion']['MONEDA DE LA OPERACION']; |
@@ -248,14 +250,17 @@ discard block |
||
248 | 250 | foreach ($item as $col => $val) { |
249 | 251 | $col = self::$item_cols[$col]; |
250 | 252 | // procesar cada valor de acuerdo al nombre de la columna |
251 | - if (in_array($col, ['DescuentoPct', 'RecargoPct'])) |
|
252 | - $detalle[$col] = substr($val, 0, -1); |
|
253 | - else |
|
254 | - $detalle[$col] = utf8_encode($val); // se convierte de ISO-8859-1 a UTF-8 |
|
253 | + if (in_array($col, ['DescuentoPct', 'RecargoPct'])) { |
|
254 | + $detalle[$col] = substr($val, 0, -1); |
|
255 | + } else { |
|
256 | + $detalle[$col] = utf8_encode($val); |
|
257 | + } |
|
258 | + // se convierte de ISO-8859-1 a UTF-8 |
|
255 | 259 | } |
256 | 260 | // si el item es EXENTO se agrega campo que lo indica |
257 | - if (strpos($detalle['NmbItem'], 'EXENTO')) |
|
258 | - $detalle['IndExe'] = 1; |
|
261 | + if (strpos($detalle['NmbItem'], 'EXENTO')) { |
|
262 | + $detalle['IndExe'] = 1; |
|
263 | + } |
|
259 | 264 | // si hay una referencia se completa con los campos del |
260 | 265 | // detalle de la referencia que no estén en este detalle |
261 | 266 | if (!empty($caso['referencia'])) { |
@@ -265,8 +270,9 @@ discard block |
||
265 | 270 | for ($i=0; $i<$n_detalle_r; $i++) { |
266 | 271 | if ($detalle_r[$i]['NmbItem']==$detalle['NmbItem']) { |
267 | 272 | foreach ($detalle_r[$i] as $attr => $val) { |
268 | - if (!isset($detalle[$attr])) |
|
269 | - $detalle[$attr] = $val; |
|
273 | + if (!isset($detalle[$attr])) { |
|
274 | + $detalle[$attr] = $val; |
|
275 | + } |
|
270 | 276 | } |
271 | 277 | } |
272 | 278 | } |
@@ -350,8 +356,9 @@ discard block |
||
350 | 356 | 'ValorDR' => substr($caso['recargo'], 0, -1), |
351 | 357 | ]; |
352 | 358 | } |
353 | - if (empty($documento['DscRcgGlobal'])) |
|
354 | - unset($documento['DscRcgGlobal']); |
|
359 | + if (empty($documento['DscRcgGlobal'])) { |
|
360 | + unset($documento['DscRcgGlobal']); |
|
361 | + } |
|
355 | 362 | // agregar descuento del documento de la referencia |
356 | 363 | else if (!empty($caso['referencia'])) { |
357 | 364 | $referencia = self::getReferencia($caso['referencia']['razon']); |
@@ -383,14 +390,16 @@ discard block |
||
383 | 390 | // agregar totales |
384 | 391 | $documento['Encabezado']['Totales'] = $referencia['Totales']; |
385 | 392 | // agregar tasa de IVA si corresponde |
386 | - if (isset($documento['Encabezado']['Totales']['TasaIVA'])) |
|
387 | - $documento['Encabezado']['Totales']['TasaIVA'] = \sasco\LibreDTE\Sii::getIVA(); |
|
393 | + if (isset($documento['Encabezado']['Totales']['TasaIVA'])) { |
|
394 | + $documento['Encabezado']['Totales']['TasaIVA'] = \sasco\LibreDTE\Sii::getIVA(); |
|
395 | + } |
|
388 | 396 | // si el documento referenciado es factura exenta y hay MntExe |
389 | 397 | if (isset($documento['Encabezado']['Totales']['MntExe'])) { |
390 | - if ($documentos[$caso['referencia']['caso']]['Encabezado']['IdDoc']['TipoDTE']==34) |
|
391 | - $documento['Encabezado']['Totales']['MntExe'] = 0; |
|
392 | - else |
|
393 | - unset($documento['Encabezado']['Totales']['MntExe']); |
|
398 | + if ($documentos[$caso['referencia']['caso']]['Encabezado']['IdDoc']['TipoDTE']==34) { |
|
399 | + $documento['Encabezado']['Totales']['MntExe'] = 0; |
|
400 | + } else { |
|
401 | + unset($documento['Encabezado']['Totales']['MntExe']); |
|
402 | + } |
|
394 | 403 | } |
395 | 404 | // si es documento de exportación se resetean los totales y se copia el tipo de moneda si no existe |
396 | 405 | if (in_array($documento['Encabezado']['IdDoc']['TipoDTE'], [111, 112])) { |
@@ -403,8 +412,9 @@ discard block |
||
403 | 412 | } |
404 | 413 | // agregar referencia de exportación si existe |
405 | 414 | if (!empty($caso['exportacion']['REFERENCIA'])) { |
406 | - if (!is_array($caso['exportacion']['REFERENCIA'])) |
|
407 | - $caso['exportacion']['REFERENCIA'] = [$caso['exportacion']['REFERENCIA']]; |
|
415 | + if (!is_array($caso['exportacion']['REFERENCIA'])) { |
|
416 | + $caso['exportacion']['REFERENCIA'] = [$caso['exportacion']['REFERENCIA']]; |
|
417 | + } |
|
408 | 418 | foreach ($caso['exportacion']['REFERENCIA'] as $ref) { |
409 | 419 | $documento['Referencia'][] = [ |
410 | 420 | 'TpoDocRef' => self::$referencias_exportacion[$ref], |
@@ -424,14 +434,16 @@ discard block |
||
424 | 434 | if (isset($documento['Encabezado']['Totales'])) { |
425 | 435 | $hayValor = false; |
426 | 436 | foreach ($documento['Detalle'] as $d) { |
427 | - if (!empty($d['PrcItem'])) |
|
428 | - $hayValor = true; |
|
437 | + if (!empty($d['PrcItem'])) { |
|
438 | + $hayValor = true; |
|
439 | + } |
|
429 | 440 | } |
430 | 441 | if (!$hayValor) { |
431 | - if (isset($documento['Encabezado']['Totales']['MntExe'])) |
|
432 | - $documento['Encabezado']['Totales'] = ['MntExe'=>0]; |
|
433 | - else |
|
434 | - $documento['Encabezado']['Totales'] = []; |
|
442 | + if (isset($documento['Encabezado']['Totales']['MntExe'])) { |
|
443 | + $documento['Encabezado']['Totales'] = ['MntExe'=>0]; |
|
444 | + } else { |
|
445 | + $documento['Encabezado']['Totales'] = []; |
|
446 | + } |
|
435 | 447 | $documento['Encabezado']['Totales']['MntTotal'] = 0; |
436 | 448 | } |
437 | 449 | } |
@@ -539,8 +551,9 @@ discard block |
||
539 | 551 | $n_lineas = count($lineas); |
540 | 552 | for ($i=$i; $i<$n_lineas; $i++) { |
541 | 553 | // si la línea está vacía se omite |
542 | - if (!$lineas[$i]) |
|
543 | - continue; |
|
554 | + if (!$lineas[$i]) { |
|
555 | + continue; |
|
556 | + } |
|
544 | 557 | // si hay descuento global se guarda |
545 | 558 | if (strpos($lineas[$i], 'DESCUENTO GLOBAL ITEMES AFECTOS')===0) { |
546 | 559 | $aux = explode("\t", $lineas[$i]); |
@@ -576,13 +589,15 @@ discard block |
||
576 | 589 | } |
577 | 590 | // agregar a los datos de aduanas |
578 | 591 | else { |
579 | - if (!isset($datos['exportacion'])) |
|
580 | - $datos['exportacion'] = []; |
|
592 | + if (!isset($datos['exportacion'])) { |
|
593 | + $datos['exportacion'] = []; |
|
594 | + } |
|
581 | 595 | if (!isset($datos['exportacion'][$var])) { |
582 | 596 | $datos['exportacion'][$var] = $val; |
583 | 597 | } else { |
584 | - if (!is_array($datos['exportacion'][$var])) |
|
585 | - $datos['exportacion'][$var] = [$datos['exportacion'][$var]]; |
|
598 | + if (!is_array($datos['exportacion'][$var])) { |
|
599 | + $datos['exportacion'][$var] = [$datos['exportacion'][$var]]; |
|
600 | + } |
|
586 | 601 | $datos['exportacion'][$var][] = $val; |
587 | 602 | } |
588 | 603 | } |
@@ -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' => [ |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | { |
126 | 126 | $fecha = '9999-12-31'; |
127 | 127 | foreach ($this->detalles as &$d) { |
128 | - if ($d['FchDoc'] < $fecha) |
|
128 | + if ($d['FchDoc']<$fecha) |
|
129 | 129 | $fecha = $d['FchDoc']; |
130 | 130 | } |
131 | 131 | return $fecha; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | { |
142 | 142 | $fecha = '0000-01-01'; |
143 | 143 | foreach ($this->detalles as &$d) { |
144 | - if ($d['FchDoc'] > $fecha) |
|
144 | + if ($d['FchDoc']>$fecha) |
|
145 | 145 | $fecha = $d['FchDoc']; |
146 | 146 | } |
147 | 147 | return $fecha; |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | // ajustes post agregar detalles |
200 | 200 | foreach ($Resumen as &$r) { |
201 | 201 | // obtener folios utilizados = emitidos + anulados |
202 | - $r['FoliosUtilizados'] = $r['FoliosEmitidos'] + $r['FoliosAnulados']; |
|
202 | + $r['FoliosUtilizados'] = $r['FoliosEmitidos']+$r['FoliosAnulados']; |
|
203 | 203 | $r['RangoUtilizados'] = $this->getRangos($RangoUtilizados[$r['TipoDocumento']]); |
204 | 204 | } |
205 | 205 | // completar con los resumenes que no se colocaron |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | $aux = []; |
232 | 232 | $inicial = $folios[0]; |
233 | 233 | $i = $inicial; |
234 | - foreach($folios as $f) { |
|
234 | + foreach ($folios as $f) { |
|
235 | 235 | if ($i!=$f) { |
236 | 236 | $inicial = $f; |
237 | 237 | $i = $inicial; |
@@ -90,8 +90,9 @@ discard block |
||
90 | 90 | public function generar() |
91 | 91 | { |
92 | 92 | // si ya se había generado se entrega directamente |
93 | - if ($this->xml_data) |
|
94 | - return $this->xml_data; |
|
93 | + if ($this->xml_data) { |
|
94 | + return $this->xml_data; |
|
95 | + } |
|
95 | 96 | // generar XML del envío |
96 | 97 | $xmlEnvio = (new \sasco\LibreDTE\XML())->generate([ |
97 | 98 | 'ConsumoFolios' => [ |
@@ -125,8 +126,9 @@ discard block |
||
125 | 126 | { |
126 | 127 | $fecha = '9999-12-31'; |
127 | 128 | foreach ($this->detalles as &$d) { |
128 | - if ($d['FchDoc'] < $fecha) |
|
129 | - $fecha = $d['FchDoc']; |
|
129 | + if ($d['FchDoc'] < $fecha) { |
|
130 | + $fecha = $d['FchDoc']; |
|
131 | + } |
|
130 | 132 | } |
131 | 133 | return $fecha; |
132 | 134 | } |
@@ -141,8 +143,9 @@ discard block |
||
141 | 143 | { |
142 | 144 | $fecha = '0000-01-01'; |
143 | 145 | foreach ($this->detalles as &$d) { |
144 | - if ($d['FchDoc'] > $fecha) |
|
145 | - $fecha = $d['FchDoc']; |
|
146 | + if ($d['FchDoc'] > $fecha) { |
|
147 | + $fecha = $d['FchDoc']; |
|
148 | + } |
|
146 | 149 | } |
147 | 150 | return $fecha; |
148 | 151 | } |
@@ -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 | ]; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | namespace sasco\LibreDTE; |
25 | 25 | |
26 | 26 | // Directorio para imágenes (no se asume nada) |
27 | -define ('K_PATH_IMAGES', ''); |
|
27 | +define('K_PATH_IMAGES', ''); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Clase para generar PDFs |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | { |
149 | 149 | $widths = []; |
150 | 150 | if (is_int($cells)) { |
151 | - $width = floor($total/$cells); |
|
152 | - for ($i=0; $i<$cells; ++$i) { |
|
151 | + $width = floor($total / $cells); |
|
152 | + for ($i = 0; $i<$cells; ++$i) { |
|
153 | 153 | $widths[] = $width; |
154 | 154 | } |
155 | 155 | } |
156 | - else if (is_array($cells)){ |
|
157 | - $width = floor($total/count($cells)); |
|
156 | + else if (is_array($cells)) { |
|
157 | + $width = floor($total / count($cells)); |
|
158 | 158 | foreach ($cells as $i) { |
159 | 159 | $widths[$i] = $width; |
160 | 160 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | $suma += $val; |
205 | 205 | } |
206 | 206 | if ($key_0!==null) { |
207 | - $options['width'][$key_0] = 190 - $suma; |
|
207 | + $options['width'][$key_0] = 190-$suma; |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | if (isset($options['align'])) |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | $a = (isset($options['align']) and is_array($options['align'])) ? $options['align'] : []; |
240 | 240 | $buffer = '<table style="border:1px solid #333">'; |
241 | 241 | // Definir títulos de columnas |
242 | - $thead = isset($options['width']) and is_array($options['width']) and count($options['width']) == count($headers); |
|
242 | + $thead = isset($options['width']) and is_array($options['width']) and count($options['width'])==count($headers); |
|
243 | 243 | if ($thead) |
244 | 244 | $buffer .= '<thead>'; |
245 | 245 | $buffer .= '<tr>'; |
@@ -293,16 +293,15 @@ discard block |
||
293 | 293 | $options['headercolor'][1], |
294 | 294 | $options['headercolor'][2] |
295 | 295 | ); |
296 | - $this->SetFont($this->defaultOptions['font']['family'], 'B', $options['fontsize']); |
|
296 | + $this->SetFont($this->defaultOptions['font']['family'], 'B', $options['fontsize']); |
|
297 | 297 | // Header |
298 | - $w = is_array($options['width']) ? $options['width'] : |
|
299 | - $this->getTableCellWidth($options['width'], array_keys($headers)); |
|
300 | - foreach($headers as $i => $header) { |
|
301 | - $this->Cell ($w[$i], $options['height'], $headers[$i], 1, 0, $options['align'], 1); |
|
298 | + $w = is_array($options['width']) ? $options['width'] : $this->getTableCellWidth($options['width'], array_keys($headers)); |
|
299 | + foreach ($headers as $i => $header) { |
|
300 | + $this->Cell($w[$i], $options['height'], $headers[$i], 1, 0, $options['align'], 1); |
|
302 | 301 | } |
303 | 302 | $this->Ln(); |
304 | 303 | // Color and font restoration |
305 | - $this->SetFillColor ( |
|
304 | + $this->SetFillColor( |
|
306 | 305 | $options['bodybackground'][0], |
307 | 306 | $options['bodybackground'][1], |
308 | 307 | $options['bodybackground'][2] |
@@ -318,19 +317,19 @@ discard block |
||
318 | 317 | foreach ($data as &$row) { |
319 | 318 | $num_pages = $this->getNumPages(); |
320 | 319 | $this->startTransaction(); |
321 | - foreach($headers as $i => $header) { |
|
322 | - $this->Cell ($w[$i], $options['height'], $row[$i], 'LR', 0, $options['align'], $fill); |
|
320 | + foreach ($headers as $i => $header) { |
|
321 | + $this->Cell($w[$i], $options['height'], $row[$i], 'LR', 0, $options['align'], $fill); |
|
323 | 322 | } |
324 | 323 | $this->Ln(); |
325 | - if($num_pages < $this->getNumPages()) { |
|
324 | + if ($num_pages<$this->getNumPages()) { |
|
326 | 325 | $this->rollbackTransaction(true); |
327 | 326 | $this->AddPage(); |
328 | - foreach($headers as $i => $header) { |
|
329 | - $this->Cell ($w[$i], $options['height'], $headers[$i], 1, 0, $options['align'], 1); |
|
327 | + foreach ($headers as $i => $header) { |
|
328 | + $this->Cell($w[$i], $options['height'], $headers[$i], 1, 0, $options['align'], 1); |
|
330 | 329 | } |
331 | 330 | $this->Ln(); |
332 | - foreach($headers as $i => $header) { |
|
333 | - $this->Cell ($w[$i], $options['height'], $row[$i], 'LR', 0, $options['align'], $fill); |
|
331 | + foreach ($headers as $i => $header) { |
|
332 | + $this->Cell($w[$i], $options['height'], $row[$i], 'LR', 0, $options['align'], $fill); |
|
334 | 333 | } |
335 | 334 | $this->Ln(); |
336 | 335 | } else { |
@@ -350,7 +349,7 @@ discard block |
||
350 | 349 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl) |
351 | 350 | * @version 2014-09-20 |
352 | 351 | */ |
353 | - public function Texto($txt, $x=null, $y=null, $align='', $w=0, $link='', $border=0, $fill=false) |
|
352 | + public function Texto($txt, $x = null, $y = null, $align = '', $w = 0, $link = '', $border = 0, $fill = false) |
|
354 | 353 | { |
355 | 354 | if ($x==null) $x = $this->GetX(); |
356 | 355 | if ($y==null) $y = $this->GetY(); |
@@ -371,7 +370,7 @@ discard block |
||
371 | 370 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl) |
372 | 371 | * @version 2014-09-20 |
373 | 372 | */ |
374 | - public function MultiTexto($txt, $x=null, $y=null, $align='', $w=0, $border=0, $fill=false) |
|
373 | + public function MultiTexto($txt, $x = null, $y = null, $align = '', $w = 0, $border = 0, $fill = false) |
|
375 | 374 | { |
376 | 375 | if ($x==null) $x = $this->GetX(); |
377 | 376 | if ($y==null) $y = $this->GetY(); |
@@ -98,13 +98,16 @@ discard block |
||
98 | 98 | $this->Line(0, $this->getY()-1, 290, $this->getY()-2, $style); |
99 | 99 | $this->SetFont('', 'B', 6); |
100 | 100 | if (empty($this->papelContinuo)) { |
101 | - if (!empty($this->footer['left'])) |
|
102 | - $this->Texto($this->footer['left']); |
|
103 | - if (!empty($this->footer['right'])) |
|
104 | - $this->Texto($this->footer['right'], null, null, 'R'); |
|
101 | + if (!empty($this->footer['left'])) { |
|
102 | + $this->Texto($this->footer['left']); |
|
103 | + } |
|
104 | + if (!empty($this->footer['right'])) { |
|
105 | + $this->Texto($this->footer['right'], null, null, 'R'); |
|
106 | + } |
|
105 | 107 | } else { |
106 | - if (!empty($this->footer['left'])) |
|
107 | - $this->Texto($this->footer['left'], null, null, 'C'); |
|
108 | + if (!empty($this->footer['left'])) { |
|
109 | + $this->Texto($this->footer['left'], null, null, 'C'); |
|
110 | + } |
|
108 | 111 | if (!empty($this->footer['right'])) { |
109 | 112 | $this->Ln(); |
110 | 113 | $this->Texto($this->footer['right'], null, null, 'C'); |
@@ -130,8 +133,9 @@ discard block |
||
130 | 133 | ]; |
131 | 134 | } |
132 | 135 | // si no es arreglo se convierte en uno |
133 | - if (!is_array($footer)) |
|
134 | - $footer = ['left'=>$footer]; |
|
136 | + if (!is_array($footer)) { |
|
137 | + $footer = ['left'=>$footer]; |
|
138 | + } |
|
135 | 139 | // asignar footer |
136 | 140 | $this->footer = array_merge(['left'=>'', 'right'=>''], $footer); |
137 | 141 | } else { |
@@ -152,8 +156,7 @@ discard block |
||
152 | 156 | for ($i=0; $i<$cells; ++$i) { |
153 | 157 | $widths[] = $width; |
154 | 158 | } |
155 | - } |
|
156 | - else if (is_array($cells)){ |
|
159 | + } else if (is_array($cells)){ |
|
157 | 160 | $width = floor($total/count($cells)); |
158 | 161 | foreach ($cells as $i) { |
159 | 162 | $widths[$i] = $width; |
@@ -174,8 +177,9 @@ discard block |
||
174 | 177 | foreach ($data as $row) { |
175 | 178 | foreach ($row as $col => $value) { |
176 | 179 | if (empty($value)) { |
177 | - if (!array_key_exists($col, $cols_empty)) |
|
178 | - $cols_empty[$col] = 0; |
|
180 | + if (!array_key_exists($col, $cols_empty)) { |
|
181 | + $cols_empty[$col] = 0; |
|
182 | + } |
|
179 | 183 | $cols_empty[$col]++; |
180 | 184 | } |
181 | 185 | } |
@@ -188,10 +192,12 @@ discard block |
||
188 | 192 | foreach ($data as &$row) { |
189 | 193 | unset($row[$col]); |
190 | 194 | } |
191 | - if (isset($options['width'])) |
|
192 | - unset($options['width'][$titles_keys[$col]]); |
|
193 | - if (isset($options['align'])) |
|
194 | - unset($options['align'][$titles_keys[$col]]); |
|
195 | + if (isset($options['width'])) { |
|
196 | + unset($options['width'][$titles_keys[$col]]); |
|
197 | + } |
|
198 | + if (isset($options['align'])) { |
|
199 | + unset($options['align'][$titles_keys[$col]]); |
|
200 | + } |
|
195 | 201 | } |
196 | 202 | } |
197 | 203 | if (isset($options['width'])) { |
@@ -199,16 +205,18 @@ discard block |
||
199 | 205 | $key_0 = null; |
200 | 206 | $suma = 0; |
201 | 207 | foreach ($options['width'] as $key => $val) { |
202 | - if ($val===0) |
|
203 | - $key_0 = $key; |
|
208 | + if ($val===0) { |
|
209 | + $key_0 = $key; |
|
210 | + } |
|
204 | 211 | $suma += $val; |
205 | 212 | } |
206 | 213 | if ($key_0!==null) { |
207 | 214 | $options['width'][$key_0] = 190 - $suma; |
208 | 215 | } |
209 | 216 | } |
210 | - if (isset($options['align'])) |
|
211 | - $options['align'] = array_slice($options['align'], 0); |
|
217 | + if (isset($options['align'])) { |
|
218 | + $options['align'] = array_slice($options['align'], 0); |
|
219 | + } |
|
212 | 220 | $this->addTable($titles, $data, $options, $html); |
213 | 221 | } |
214 | 222 | |
@@ -240,8 +248,9 @@ discard block |
||
240 | 248 | $buffer = '<table style="border:1px solid #333">'; |
241 | 249 | // Definir títulos de columnas |
242 | 250 | $thead = isset($options['width']) and is_array($options['width']) and count($options['width']) == count($headers); |
243 | - if ($thead) |
|
244 | - $buffer .= '<thead>'; |
|
251 | + if ($thead) { |
|
252 | + $buffer .= '<thead>'; |
|
253 | + } |
|
245 | 254 | $buffer .= '<tr>'; |
246 | 255 | $i = 0; |
247 | 256 | foreach ($headers as &$col) { |
@@ -251,11 +260,13 @@ discard block |
||
251 | 260 | $i++; |
252 | 261 | } |
253 | 262 | $buffer .= '</tr>'; |
254 | - if ($thead) |
|
255 | - $buffer .= '</thead>'; |
|
263 | + if ($thead) { |
|
264 | + $buffer .= '</thead>'; |
|
265 | + } |
|
256 | 266 | // Definir datos de la tabla |
257 | - if ($thead) |
|
258 | - $buffer .= '<tbody>'; |
|
267 | + if ($thead) { |
|
268 | + $buffer .= '<tbody>'; |
|
269 | + } |
|
259 | 270 | foreach ($data as &$row) { |
260 | 271 | $buffer .= '<tr>'; |
261 | 272 | $i = 0; |
@@ -267,8 +278,9 @@ discard block |
||
267 | 278 | } |
268 | 279 | $buffer .= '</tr>'; |
269 | 280 | } |
270 | - if ($thead) |
|
271 | - $buffer .= '</tbody>'; |
|
281 | + if ($thead) { |
|
282 | + $buffer .= '</tbody>'; |
|
283 | + } |
|
272 | 284 | // Finalizar tabla |
273 | 285 | $buffer .= '</table>'; |
274 | 286 | // generar tabla en HTML |
@@ -336,8 +348,9 @@ discard block |
||
336 | 348 | } else { |
337 | 349 | $this->commitTransaction(); |
338 | 350 | } |
339 | - if ($options['colorchange']) |
|
340 | - $fill = !$fill; |
|
351 | + if ($options['colorchange']) { |
|
352 | + $fill = !$fill; |
|
353 | + } |
|
341 | 354 | } |
342 | 355 | $this->Cell(array_sum($w), 0, '', 'T'); |
343 | 356 | $this->Ln(); |
@@ -352,8 +365,12 @@ discard block |
||
352 | 365 | */ |
353 | 366 | public function Texto($txt, $x=null, $y=null, $align='', $w=0, $link='', $border=0, $fill=false) |
354 | 367 | { |
355 | - if ($x==null) $x = $this->GetX(); |
|
356 | - if ($y==null) $y = $this->GetY(); |
|
368 | + if ($x==null) { |
|
369 | + $x = $this->GetX(); |
|
370 | + } |
|
371 | + if ($y==null) { |
|
372 | + $y = $this->GetY(); |
|
373 | + } |
|
357 | 374 | $textrendermode = $this->textrendermode; |
358 | 375 | $textstrokewidth = $this->textstrokewidth; |
359 | 376 | $this->setTextRenderingMode(0, true, false); |
@@ -373,8 +390,12 @@ discard block |
||
373 | 390 | */ |
374 | 391 | public function MultiTexto($txt, $x=null, $y=null, $align='', $w=0, $border=0, $fill=false) |
375 | 392 | { |
376 | - if ($x==null) $x = $this->GetX(); |
|
377 | - if ($y==null) $y = $this->GetY(); |
|
393 | + if ($x==null) { |
|
394 | + $x = $this->GetX(); |
|
395 | + } |
|
396 | + if ($y==null) { |
|
397 | + $y = $this->GetY(); |
|
398 | + } |
|
378 | 399 | $textrendermode = $this->textrendermode; |
379 | 400 | $textstrokewidth = $this->textstrokewidth; |
380 | 401 | $this->setTextRenderingMode(0, true, false); |