@@ -57,10 +57,11 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function __construct($datos, $normalizar = true) |
59 | 59 | { |
60 | - if (is_array($datos)) |
|
61 | - $this->setDatos($datos, $normalizar); |
|
62 | - else if (is_string($datos)) |
|
63 | - $this->loadXML($datos); |
|
60 | + if (is_array($datos)) { |
|
61 | + $this->setDatos($datos, $normalizar); |
|
62 | + } else if (is_string($datos)) { |
|
63 | + $this->loadXML($datos); |
|
64 | + } |
|
64 | 65 | $this->timestamp = date('Y-m-d\TH:i:s'); |
65 | 66 | } |
66 | 67 | |
@@ -121,8 +122,9 @@ discard block |
||
121 | 122 | if ($normalizar) { |
122 | 123 | $this->normalizar($datos); |
123 | 124 | $method = 'normalizar_'.$this->tipo; |
124 | - if (method_exists($this, $method)) |
|
125 | - $this->$method($datos); |
|
125 | + if (method_exists($this, $method)) { |
|
126 | + $this->$method($datos); |
|
127 | + } |
|
126 | 128 | $this->normalizar_final($datos); |
127 | 129 | } |
128 | 130 | $this->tipo_general = $this->getTipoGeneral($this->tipo); |
@@ -199,8 +201,9 @@ discard block |
||
199 | 201 | */ |
200 | 202 | public function getJSON() |
201 | 203 | { |
202 | - if (!$this->getDatos()) |
|
203 | - return false; |
|
204 | + if (!$this->getDatos()) { |
|
205 | + return false; |
|
206 | + } |
|
204 | 207 | return json_encode($this->datos, JSON_PRETTY_PRINT); |
205 | 208 | } |
206 | 209 | |
@@ -225,9 +228,10 @@ discard block |
||
225 | 228 | */ |
226 | 229 | private function getTipoGeneral($dte) |
227 | 230 | { |
228 | - foreach ($this->tipos as $tipo => $codigos) |
|
229 | - if (in_array($dte, $codigos)) |
|
231 | + foreach ($this->tipos as $tipo => $codigos) { |
|
232 | + if (in_array($dte, $codigos)) |
|
230 | 233 | return $tipo; |
234 | + } |
|
231 | 235 | \sasco\LibreDTE\Log::write( |
232 | 236 | \sasco\LibreDTE\Estado::DTE_ERROR_TIPO, |
233 | 237 | \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::DTE_ERROR_TIPO, $dte) |
@@ -266,10 +270,12 @@ discard block |
||
266 | 270 | public function getEmisor() |
267 | 271 | { |
268 | 272 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Emisor/RUTEmisor')->item(0); |
269 | - if ($nodo) |
|
270 | - return $nodo->nodeValue; |
|
271 | - if (!$this->getDatos()) |
|
272 | - return false; |
|
273 | + if ($nodo) { |
|
274 | + return $nodo->nodeValue; |
|
275 | + } |
|
276 | + if (!$this->getDatos()) { |
|
277 | + return false; |
|
278 | + } |
|
273 | 279 | return $this->datos['Encabezado']['Emisor']['RUTEmisor']; |
274 | 280 | } |
275 | 281 | |
@@ -282,10 +288,12 @@ discard block |
||
282 | 288 | public function getReceptor() |
283 | 289 | { |
284 | 290 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Receptor/RUTRecep')->item(0); |
285 | - if ($nodo) |
|
286 | - return $nodo->nodeValue; |
|
287 | - if (!$this->getDatos()) |
|
288 | - return false; |
|
291 | + if ($nodo) { |
|
292 | + return $nodo->nodeValue; |
|
293 | + } |
|
294 | + if (!$this->getDatos()) { |
|
295 | + return false; |
|
296 | + } |
|
289 | 297 | return $this->datos['Encabezado']['Receptor']['RUTRecep']; |
290 | 298 | } |
291 | 299 | |
@@ -298,10 +306,12 @@ discard block |
||
298 | 306 | public function getFechaEmision() |
299 | 307 | { |
300 | 308 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/IdDoc/FchEmis')->item(0); |
301 | - if ($nodo) |
|
302 | - return $nodo->nodeValue; |
|
303 | - if (!$this->getDatos()) |
|
304 | - return false; |
|
309 | + if ($nodo) { |
|
310 | + return $nodo->nodeValue; |
|
311 | + } |
|
312 | + if (!$this->getDatos()) { |
|
313 | + return false; |
|
314 | + } |
|
305 | 315 | return $this->datos['Encabezado']['IdDoc']['FchEmis']; |
306 | 316 | } |
307 | 317 | |
@@ -314,10 +324,12 @@ discard block |
||
314 | 324 | public function getMontoTotal() |
315 | 325 | { |
316 | 326 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Totales/MntTotal')->item(0); |
317 | - if ($nodo) |
|
318 | - return $nodo->nodeValue; |
|
319 | - if (!$this->getDatos()) |
|
320 | - return false; |
|
327 | + if ($nodo) { |
|
328 | + return $nodo->nodeValue; |
|
329 | + } |
|
330 | + if (!$this->getDatos()) { |
|
331 | + return false; |
|
332 | + } |
|
321 | 333 | return $this->datos['Encabezado']['Totales']['MntTotal']; |
322 | 334 | } |
323 | 335 | |
@@ -330,10 +342,12 @@ discard block |
||
330 | 342 | public function getMoneda() |
331 | 343 | { |
332 | 344 | $nodo = $this->xml->xpath('/DTE/'.$this->tipo_general.'/Encabezado/Totales/TpoMoneda')->item(0); |
333 | - if ($nodo) |
|
334 | - return $nodo->nodeValue; |
|
335 | - if (!$this->getDatos()) |
|
336 | - return false; |
|
345 | + if ($nodo) { |
|
346 | + return $nodo->nodeValue; |
|
347 | + } |
|
348 | + if (!$this->getDatos()) { |
|
349 | + return false; |
|
350 | + } |
|
337 | 351 | return $this->datos['Encabezado']['Totales']['TpoMoneda']; |
338 | 352 | } |
339 | 353 | |
@@ -355,8 +369,9 @@ discard block |
||
355 | 369 | return false;*/ |
356 | 370 | $xml = new \sasco\LibreDTE\XML(); |
357 | 371 | $TED = $this->xml->getElementsByTagName('TED')->item(0); |
358 | - if (!$TED) |
|
359 | - return '<TED/>'; |
|
372 | + if (!$TED) { |
|
373 | + return '<TED/>'; |
|
374 | + } |
|
360 | 375 | $xml->loadXML($TED->C14N()); |
361 | 376 | $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); |
362 | 377 | $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', ''); |
@@ -553,10 +568,12 @@ discard block |
||
553 | 568 | */ |
554 | 569 | private function calcularNetoIVA($total, $tasa = null) |
555 | 570 | { |
556 | - if ($tasa === 0 or $tasa === false) |
|
557 | - return [0, 0]; |
|
558 | - if ($tasa === null) |
|
559 | - $tasa = \sasco\LibreDTE\Sii::getIVA(); |
|
571 | + if ($tasa === 0 or $tasa === false) { |
|
572 | + return [0, 0]; |
|
573 | + } |
|
574 | + if ($tasa === null) { |
|
575 | + $tasa = \sasco\LibreDTE\Sii::getIVA(); |
|
576 | + } |
|
560 | 577 | // WARNING: el IVA obtenido puede no ser el NETO*(TASA/100) |
561 | 578 | // se calcula el monto neto y luego se obtiene el IVA haciendo la resta |
562 | 579 | // entre el total y el neto, ya que hay casos de borde como: |
@@ -665,8 +682,9 @@ discard block |
||
665 | 682 | } |
666 | 683 | // si existe descuento o recargo global se normalizan |
667 | 684 | if (!empty($datos['DscRcgGlobal'])) { |
668 | - if (!isset($datos['DscRcgGlobal'][0])) |
|
669 | - $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
685 | + if (!isset($datos['DscRcgGlobal'][0])) { |
|
686 | + $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
687 | + } |
|
670 | 688 | $NroLinDR = 1; |
671 | 689 | foreach ($datos['DscRcgGlobal'] as &$dr) { |
672 | 690 | $dr = array_merge([ |
@@ -1310,8 +1328,9 @@ discard block |
||
1310 | 1328 | */ |
1311 | 1329 | private function normalizar_detalle(array &$datos) |
1312 | 1330 | { |
1313 | - if (!isset($datos['Detalle'][0])) |
|
1314 | - $datos['Detalle'] = [$datos['Detalle']]; |
|
1331 | + if (!isset($datos['Detalle'][0])) { |
|
1332 | + $datos['Detalle'] = [$datos['Detalle']]; |
|
1333 | + } |
|
1315 | 1334 | $item = 1; |
1316 | 1335 | foreach ($datos['Detalle'] as &$d) { |
1317 | 1336 | $d = array_merge([ |
@@ -1373,8 +1392,9 @@ discard block |
||
1373 | 1392 | ]; |
1374 | 1393 | } |
1375 | 1394 | if ($d['PrcItem']) { |
1376 | - if (!$d['QtyItem']) |
|
1377 | - $d['QtyItem'] = 1; |
|
1395 | + if (!$d['QtyItem']) { |
|
1396 | + $d['QtyItem'] = 1; |
|
1397 | + } |
|
1378 | 1398 | if (empty($d['MontoItem'])) { |
1379 | 1399 | $d['MontoItem'] = $this->round( |
1380 | 1400 | $d['QtyItem'] * $d['PrcItem'], |
@@ -1440,8 +1460,9 @@ discard block |
||
1440 | 1460 | private function normalizar_aplicar_descuentos_recargos(array &$datos) |
1441 | 1461 | { |
1442 | 1462 | if (!empty($datos['DscRcgGlobal'])) { |
1443 | - if (!isset($datos['DscRcgGlobal'][0])) |
|
1444 | - $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
1463 | + if (!isset($datos['DscRcgGlobal'][0])) { |
|
1464 | + $datos['DscRcgGlobal'] = [$datos['DscRcgGlobal']]; |
|
1465 | + } |
|
1445 | 1466 | foreach ($datos['DscRcgGlobal'] as &$dr) { |
1446 | 1467 | $dr = array_merge([ |
1447 | 1468 | 'NroLinDR' => false, |
@@ -1508,8 +1529,9 @@ discard block |
||
1508 | 1529 | $montos = []; |
1509 | 1530 | foreach ($datos['Detalle'] as &$d) { |
1510 | 1531 | if (!empty($d['CodImpAdic'])) { |
1511 | - if (!isset($montos[$d['CodImpAdic']])) |
|
1512 | - $montos[$d['CodImpAdic']] = 0; |
|
1532 | + if (!isset($montos[$d['CodImpAdic']])) { |
|
1533 | + $montos[$d['CodImpAdic']] = 0; |
|
1534 | + } |
|
1513 | 1535 | $montos[$d['CodImpAdic']] += $d['MontoItem']; |
1514 | 1536 | } |
1515 | 1537 | } |
@@ -1588,10 +1610,12 @@ discard block |
||
1588 | 1610 | } |
1589 | 1611 | if (empty($datos['Encabezado']['Totales']['MntTotal'])) { |
1590 | 1612 | $datos['Encabezado']['Totales']['MntTotal'] = $datos['Encabezado']['Totales']['MntNeto']; |
1591 | - if (!empty($datos['Encabezado']['Totales']['IVA'])) |
|
1592 | - $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['IVA']; |
|
1593 | - if (!empty($datos['Encabezado']['Totales']['MntExe'])) |
|
1594 | - $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['MntExe']; |
|
1613 | + if (!empty($datos['Encabezado']['Totales']['IVA'])) { |
|
1614 | + $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['IVA']; |
|
1615 | + } |
|
1616 | + if (!empty($datos['Encabezado']['Totales']['MntExe'])) { |
|
1617 | + $datos['Encabezado']['Totales']['MntTotal'] += $datos['Encabezado']['Totales']['MntExe']; |
|
1618 | + } |
|
1595 | 1619 | } |
1596 | 1620 | } else { |
1597 | 1621 | if (!$datos['Encabezado']['Totales']['MntTotal'] and !empty($datos['Encabezado']['Totales']['MntExe'])) { |
@@ -1617,8 +1641,10 @@ discard block |
||
1617 | 1641 | } |
1618 | 1642 | // si hay impuesto de crédito a constructoras del 65% se descuenta del total |
1619 | 1643 | if (!empty($datos['Encabezado']['Totales']['CredEC'])) { |
1620 | - if ($datos['Encabezado']['Totales']['CredEC']===true) |
|
1621 | - $datos['Encabezado']['Totales']['CredEC'] = round($datos['Encabezado']['Totales']['IVA'] * 0.65); // TODO: mover a constante o método |
|
1644 | + if ($datos['Encabezado']['Totales']['CredEC']===true) { |
|
1645 | + $datos['Encabezado']['Totales']['CredEC'] = round($datos['Encabezado']['Totales']['IVA'] * 0.65); |
|
1646 | + } |
|
1647 | + // TODO: mover a constante o método |
|
1622 | 1648 | $datos['Encabezado']['Totales']['MntTotal'] -= $datos['Encabezado']['Totales']['CredEC']; |
1623 | 1649 | } |
1624 | 1650 | } |
@@ -1724,10 +1750,12 @@ discard block |
||
1724 | 1750 | /*if (!$this->checkFirma()) |
1725 | 1751 | return 1;*/ |
1726 | 1752 | if (is_array($datos)) { |
1727 | - if (isset($datos['RUTEmisor']) and $this->getEmisor()!=$datos['RUTEmisor']) |
|
1728 | - return 2; |
|
1729 | - if (isset($datos['RUTRecep']) and $this->getReceptor()!=$datos['RUTRecep']) |
|
1730 | - return 3; |
|
1753 | + if (isset($datos['RUTEmisor']) and $this->getEmisor()!=$datos['RUTEmisor']) { |
|
1754 | + return 2; |
|
1755 | + } |
|
1756 | + if (isset($datos['RUTRecep']) and $this->getReceptor()!=$datos['RUTRecep']) { |
|
1757 | + return 3; |
|
1758 | + } |
|
1731 | 1759 | } |
1732 | 1760 | return 0; |
1733 | 1761 | } |
@@ -1741,8 +1769,9 @@ discard block |
||
1741 | 1769 | */ |
1742 | 1770 | public function checkFirma() |
1743 | 1771 | { |
1744 | - if (!$this->xml) |
|
1745 | - return null; |
|
1772 | + if (!$this->xml) { |
|
1773 | + return null; |
|
1774 | + } |
|
1746 | 1775 | // obtener firma |
1747 | 1776 | $Signature = $this->xml->documentElement->getElementsByTagName('Signature')->item(0); |
1748 | 1777 | // preparar documento a validar |
@@ -1834,12 +1863,14 @@ discard block |
||
1834 | 1863 | { |
1835 | 1864 | // solicitar token |
1836 | 1865 | $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($Firma); |
1837 | - if (!$token) |
|
1838 | - return false; |
|
1866 | + if (!$token) { |
|
1867 | + return false; |
|
1868 | + } |
|
1839 | 1869 | // consultar estado dte |
1840 | 1870 | $run = $Firma->getID(); |
1841 | - if ($run===false) |
|
1842 | - return false; |
|
1871 | + if ($run===false) { |
|
1872 | + return false; |
|
1873 | + } |
|
1843 | 1874 | list($RutConsultante, $DvConsultante) = explode('-', $run); |
1844 | 1875 | list($RutCompania, $DvCompania) = explode('-', $this->getEmisor()); |
1845 | 1876 | list($RutReceptor, $DvReceptor) = explode('-', $this->getReceptor()); |
@@ -1858,8 +1889,9 @@ discard block |
||
1858 | 1889 | 'token' => $token, |
1859 | 1890 | ]); |
1860 | 1891 | // si el estado se pudo recuperar se muestra |
1861 | - if ($xml===false) |
|
1862 | - return false; |
|
1892 | + if ($xml===false) { |
|
1893 | + return false; |
|
1894 | + } |
|
1863 | 1895 | // entregar estado |
1864 | 1896 | return (array)$xml->xpath('/SII:RESPUESTA/SII:RESP_HDR')[0]; |
1865 | 1897 | } |
@@ -1876,8 +1908,9 @@ discard block |
||
1876 | 1908 | { |
1877 | 1909 | // solicitar token |
1878 | 1910 | $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($Firma); |
1879 | - if (!$token) |
|
1880 | - return false; |
|
1911 | + if (!$token) { |
|
1912 | + return false; |
|
1913 | + } |
|
1881 | 1914 | // consultar estado dte |
1882 | 1915 | list($RutEmpresa, $DvEmpresa) = explode('-', $this->getEmisor()); |
1883 | 1916 | list($RutReceptor, $DvReceptor) = explode('-', $this->getReceptor()); |
@@ -1895,8 +1928,9 @@ discard block |
||
1895 | 1928 | 'token' => $token, |
1896 | 1929 | ]); |
1897 | 1930 | // si el estado se pudo recuperar se muestra |
1898 | - if ($xml===false) |
|
1899 | - return false; |
|
1931 | + if ($xml===false) { |
|
1932 | + return false; |
|
1933 | + } |
|
1900 | 1934 | // entregar estado |
1901 | 1935 | return (array)$xml->xpath('/SII:RESPUESTA/SII:RESP_BODY')[0]; |
1902 | 1936 | } |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | |
238 | 238 | /** |
239 | 239 | * Método que entrega el tipo de DTE |
240 | - * @return Tipo de dte, ej: 33 (factura electrónica) |
|
240 | + * @return string de dte, ej: 33 (factura electrónica) |
|
241 | 241 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
242 | 242 | * @version 2015-09-02 |
243 | 243 | */ |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | |
249 | 249 | /** |
250 | 250 | * Método que entrega el folio del DTE |
251 | - * @return Folio del DTE |
|
251 | + * @return string del DTE |
|
252 | 252 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
253 | 253 | * @version 2015-09-02 |
254 | 254 | */ |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | |
260 | 260 | /** |
261 | 261 | * Método que entrega rut del emisor del DTE |
262 | - * @return RUT del emiro |
|
262 | + * @return string del emiro |
|
263 | 263 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
264 | 264 | * @version 2015-09-07 |
265 | 265 | */ |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | |
276 | 276 | /** |
277 | 277 | * Método que entrega rut del receptor del DTE |
278 | - * @return RUT del emiro |
|
278 | + * @return string del emiro |
|
279 | 279 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
280 | 280 | * @version 2015-09-07 |
281 | 281 | */ |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | |
292 | 292 | /** |
293 | 293 | * Método que entrega fecha de emisión del DTE |
294 | - * @return Fecha de emisión en formato AAAA-MM-DD |
|
294 | + * @return string de emisión en formato AAAA-MM-DD |
|
295 | 295 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
296 | 296 | * @version 2015-09-07 |
297 | 297 | */ |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | |
401 | 401 | /** |
402 | 402 | * Método que realiza el timbrado del DTE |
403 | - * @param Folios Objeto de los Folios con los que se desea timbrar |
|
403 | + * @param Folios Folios de los Folios con los que se desea timbrar |
|
404 | 404 | * @return =true si se pudo timbrar o =false en caso de error |
405 | 405 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
406 | 406 | * @version 2016-09-01 |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | |
487 | 487 | /** |
488 | 488 | * Método que realiza la firma del DTE |
489 | - * @param Firma objeto que representa la Firma Electrónca |
|
489 | + * @param Firma \sasco\LibreDTE\FirmaElectronica que representa la Firma Electrónca |
|
490 | 490 | * @return =true si el DTE pudo ser fimado o =false si no se pudo firmar |
491 | 491 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
492 | 492 | * @version 2017-10-22 |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | |
510 | 510 | /** |
511 | 511 | * Método que entrega el DTE en XML |
512 | - * @return XML con el DTE (podría: con o sin timbre y con o sin firma) |
|
512 | + * @return string con el DTE (podría: con o sin timbre y con o sin firma) |
|
513 | 513 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
514 | 514 | * @version 2015-08-20 |
515 | 515 | */ |
@@ -1750,7 +1750,7 @@ discard block |
||
1750 | 1750 | * - Firma del DTE |
1751 | 1751 | * - RUT del emisor (si se pasó uno para comparar) |
1752 | 1752 | * - RUT del receptor (si se pasó uno para comparar) |
1753 | - * @return Código del estado de la validación |
|
1753 | + * @return integer del estado de la validación |
|
1754 | 1754 | * @warning No se está validando la firma |
1755 | 1755 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
1756 | 1756 | * @version 2015-09-08 |
@@ -1861,7 +1861,7 @@ discard block |
||
1861 | 1861 | |
1862 | 1862 | /** |
1863 | 1863 | * Método que obtiene el estado del DTE |
1864 | - * @param Firma objeto que representa la Firma Electrónca |
|
1864 | + * @param Firma \sasco\LibreDTE\FirmaElectronica que representa la Firma Electrónca |
|
1865 | 1865 | * @return Arreglo con el estado del DTE |
1866 | 1866 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
1867 | 1867 | * @version 2015-10-24 |
@@ -1902,7 +1902,7 @@ discard block |
||
1902 | 1902 | |
1903 | 1903 | /** |
1904 | 1904 | * Método que obtiene el estado avanzado del DTE |
1905 | - * @param Firma objeto que representa la Firma Electrónca |
|
1905 | + * @param Firma \sasco\LibreDTE\FirmaElectronica que representa la Firma Electrónca |
|
1906 | 1906 | * @return Arreglo con el estado del DTE |
1907 | 1907 | * @todo Corregir warning y también definir que se retornará (sobre todo en caso de error) |
1908 | 1908 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | ] |
140 | 140 | ]); |
141 | 141 | $parent = $this->xml->getElementsByTagName($this->tipo_general)->item(0); |
142 | - $this->xml->generate($datos + ['TED' => null], null, $parent); |
|
142 | + $this->xml->generate($datos+['TED' => null], null, $parent); |
|
143 | 143 | $this->datos = $datos; |
144 | 144 | if ($normalizar and !$this->verificarDatos()) { |
145 | 145 | return false; |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | $xml->documentElement->removeAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi'); |
383 | 383 | $xml->documentElement->removeAttributeNS('http://www.sii.cl/SiiDte', ''); |
384 | 384 | $TED = $xml->getFlattened('/'); |
385 | - return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1']) != 'ISO-8859-1' ? utf8_decode($TED) : $TED; |
|
385 | + return mb_detect_encoding($TED, ['UTF-8', 'ISO-8859-1'])!='ISO-8859-1' ? utf8_decode($TED) : $TED; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | { |
396 | 396 | $datos = $this->getDatos(); |
397 | 397 | $idk = !empty($datos['TED']['DD']['CAF']['DA']['IDK']) ? (int)$datos['TED']['DD']['CAF']['DA']['IDK'] : null; |
398 | - return $idk ? $idk === 100 : null; |
|
398 | + return $idk ? $idk===100 : null; |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | /** |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | { |
530 | 530 | $this->getDatos(); |
531 | 531 | // generar resumen |
532 | - $resumen = [ |
|
532 | + $resumen = [ |
|
533 | 533 | 'TpoDoc' => (int)$this->datos['Encabezado']['IdDoc']['TipoDTE'], |
534 | 534 | 'NroDoc' => (int)$this->datos['Encabezado']['IdDoc']['Folio'], |
535 | 535 | 'TasaImp' => 0, |
@@ -574,17 +574,17 @@ discard block |
||
574 | 574 | */ |
575 | 575 | private function calcularNetoIVA($total, $tasa = null) |
576 | 576 | { |
577 | - if ($tasa === 0 or $tasa === false) |
|
577 | + if ($tasa===0 or $tasa===false) |
|
578 | 578 | return [0, 0]; |
579 | - if ($tasa === null) |
|
579 | + if ($tasa===null) |
|
580 | 580 | $tasa = \sasco\LibreDTE\Sii::getIVA(); |
581 | 581 | // WARNING: el IVA obtenido puede no ser el NETO*(TASA/100) |
582 | 582 | // se calcula el monto neto y luego se obtiene el IVA haciendo la resta |
583 | 583 | // entre el total y el neto, ya que hay casos de borde como: |
584 | 584 | // - BRUTO: 680 => NETO: 571 e IVA: 108 => TOTAL: 679 |
585 | 585 | // - BRUTO: 86710 => NETO: 72866 e IVA: 13845 => TOTAL: 86711 |
586 | - $neto = round($total / (1+($tasa/100))); |
|
587 | - $iva = $total - $neto; |
|
586 | + $neto = round($total / (1+($tasa / 100))); |
|
587 | + $iva = $total-$neto; |
|
588 | 588 | return [$neto, $iva]; |
589 | 589 | } |
590 | 590 | |
@@ -1418,12 +1418,12 @@ discard block |
||
1418 | 1418 | ); |
1419 | 1419 | // aplicar descuento |
1420 | 1420 | if ($d['DescuentoPct']) { |
1421 | - $d['DescuentoMonto'] = round($d['MontoItem'] * (int)$d['DescuentoPct']/100); |
|
1421 | + $d['DescuentoMonto'] = round($d['MontoItem'] * (int)$d['DescuentoPct'] / 100); |
|
1422 | 1422 | } |
1423 | 1423 | $d['MontoItem'] -= $d['DescuentoMonto']; |
1424 | 1424 | // aplicar recargo |
1425 | 1425 | if ($d['RecargoPct']) { |
1426 | - $d['RecargoMonto'] = round($d['MontoItem'] * (int)$d['RecargoPct']/100); |
|
1426 | + $d['RecargoMonto'] = round($d['MontoItem'] * (int)$d['RecargoPct'] / 100); |
|
1427 | 1427 | } |
1428 | 1428 | $d['MontoItem'] += $d['RecargoMonto']; |
1429 | 1429 | // aproximar monto del item |
@@ -1509,7 +1509,7 @@ discard block |
||
1509 | 1509 | } |
1510 | 1510 | $valor = |
1511 | 1511 | $dr['TpoValor']=='%' |
1512 | - ? $this->round(($dr['ValorDR']/100)*$datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
1512 | + ? $this->round(($dr['ValorDR'] / 100) * $datos['Encabezado']['Totales'][$monto], $datos['Encabezado']['Totales']['TpoMoneda']) |
|
1513 | 1513 | : $dr['ValorDR'] |
1514 | 1514 | ; |
1515 | 1515 | // aplicar descuento |
@@ -1582,7 +1582,7 @@ discard block |
||
1582 | 1582 | // si el monto no existe se asigna |
1583 | 1583 | if ($datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp']===null) { |
1584 | 1584 | $datos['Encabezado']['Totales']['ImptoReten'][$i]['MontoImp'] = round( |
1585 | - $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp']/100 |
|
1585 | + $neto * $datos['Encabezado']['Totales']['ImptoReten'][$i]['TasaImp'] / 100 |
|
1586 | 1586 | ); |
1587 | 1587 | } |
1588 | 1588 | } |
@@ -1590,7 +1590,7 @@ discard block |
||
1590 | 1590 | if (isset($datos['Encabezado']['Totales']['ImptoReten']) and is_array($datos['Encabezado']['Totales']['ImptoReten'])) { |
1591 | 1591 | $codigos = array_keys($montos); |
1592 | 1592 | $n_impuestos = count($datos['Encabezado']['Totales']['ImptoReten']); |
1593 | - for ($i=0; $i<$n_impuestos; $i++) { |
|
1593 | + for ($i = 0; $i<$n_impuestos; $i++) { |
|
1594 | 1594 | if (!in_array($datos['Encabezado']['Totales']['ImptoReten'][$i]['TipoImp'], $codigos)) { |
1595 | 1595 | unset($datos['Encabezado']['Totales']['ImptoReten'][$i]); |
1596 | 1596 | } |
@@ -1618,7 +1618,7 @@ discard block |
||
1618 | 1618 | } else { |
1619 | 1619 | if (empty($datos['Encabezado']['Totales']['IVA']) and !empty($datos['Encabezado']['Totales']['TasaIVA'])) { |
1620 | 1620 | $datos['Encabezado']['Totales']['IVA'] = round( |
1621 | - $datos['Encabezado']['Totales']['MntNeto']*($datos['Encabezado']['Totales']['TasaIVA']/100) |
|
1621 | + $datos['Encabezado']['Totales']['MntNeto'] * ($datos['Encabezado']['Totales']['TasaIVA'] / 100) |
|
1622 | 1622 | ); |
1623 | 1623 | } |
1624 | 1624 | } |
@@ -1642,7 +1642,7 @@ discard block |
||
1642 | 1642 | if (ImpuestosAdicionales::getTipo($ImptoReten['TipoImp'])=='R') { |
1643 | 1643 | $datos['Encabezado']['Totales']['MntTotal'] -= $ImptoReten['MontoImp']; |
1644 | 1644 | if ($ImptoReten['MontoImp']!=$datos['Encabezado']['Totales']['IVA']) { |
1645 | - $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA'] - $ImptoReten['MontoImp']; |
|
1645 | + $datos['Encabezado']['Totales']['IVANoRet'] = $datos['Encabezado']['Totales']['IVA']-$ImptoReten['MontoImp']; |
|
1646 | 1646 | } |
1647 | 1647 | } |
1648 | 1648 | // si es adicional se suma al total |
@@ -1794,7 +1794,7 @@ discard block |
||
1794 | 1794 | $SignatureValue = $Signature->getElementsByTagName('SignatureValue')->item(0)->nodeValue; |
1795 | 1795 | $X509Certificate = $Signature->getElementsByTagName('X509Certificate')->item(0)->nodeValue; |
1796 | 1796 | $X509Certificate = '-----BEGIN CERTIFICATE-----'."\n".wordwrap(trim($X509Certificate), 64, "\n", true)."\n".'-----END CERTIFICATE----- '; |
1797 | - $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate) === 1 ? true : false; |
|
1797 | + $valid = openssl_verify($SignedInfo->C14N(), base64_decode($SignatureValue), $X509Certificate)===1 ? true : false; |
|
1798 | 1798 | return $valid; |
1799 | 1799 | //return $valid and $DigestValue===base64_encode(sha1($Documento->C14N(), true)); |
1800 | 1800 | } |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | |
155 | 155 | /** |
156 | 156 | * Método para realizar una solicitud al servicio web del SII |
157 | - * @param wsdl Nombre del WSDL que se usará |
|
158 | - * @param request Nombre de la función que se ejecutará en el servicio web |
|
157 | + * @param wsdl string del WSDL que se usará |
|
158 | + * @param request string de la función que se ejecutará en el servicio web |
|
159 | 159 | * @param args Argumentos que se pasarán al servicio web |
160 | 160 | * @param retry Intentos que se realizarán como máximo para obtener respuesta |
161 | 161 | * @return Objeto SimpleXMLElement con la espuesta del servicio web consultado |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * @param usuario RUN del usuario que envía el DTE |
250 | 250 | * @param empresa RUT de la empresa emisora del DTE |
251 | 251 | * @param dte Documento XML con el DTE que se desea enviar a SII |
252 | - * @param token Token de autenticación automática ante el SII |
|
252 | + * @param token string de autenticación automática ante el SII |
|
253 | 253 | * @param gzip Permite enviar el archivo XML comprimido al servidor |
254 | 254 | * @param retry Intentos que se realizarán como máximo para obtener respuesta |
255 | 255 | * @return Respuesta XML desde SII o bien null si no se pudo obtener respuesta |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | * \endcode |
358 | 358 | * |
359 | 359 | * @param idk IDK de la clave pública del SII. Si no se indica se tratará de determinar con el ambiente que se esté usando |
360 | - * @return Contenido del certificado |
|
360 | + * @return string|false del certificado |
|
361 | 361 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
362 | 362 | * @version 2015-09-16 |
363 | 363 | */ |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | /** |
383 | 383 | * Método que asigna el ambiente que se usará por defecto (si no está |
384 | 384 | * asignado con la constante _LibreDTE_CERTIFICACION_) |
385 | - * @param ambiente Ambiente a usar: Sii::PRODUCCION o Sii::CERTIFICACION |
|
385 | + * @param ambiente integer a usar: Sii::PRODUCCION o Sii::CERTIFICACION |
|
386 | 386 | * @warning No se está verificando SSL en ambiente de certificación |
387 | 387 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
388 | 388 | * @version 2016-08-28 |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | |
418 | 418 | /** |
419 | 419 | * Método que entrega la tasa de IVA vigente |
420 | - * @return Tasa de IVA vigente |
|
420 | + * @return integer de IVA vigente |
|
421 | 421 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
422 | 422 | * @version 2015-09-03 |
423 | 423 | */ |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | /** |
494 | 494 | * Método que entrega la dirección regional según la comuna que se esté |
495 | 495 | * consultando |
496 | - * @param comuna de la sucursal del emior o bien código de la sucursal del SII |
|
496 | + * @param comuna Sii\PDF\Código|null la sucursal del emior o bien código de la sucursal del SII |
|
497 | 497 | * @return Dirección regional del SII |
498 | 498 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
499 | 499 | * @version 2017-11-07 |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | \sasco\LibreDTE\Log::write(Estado::REQUEST_ERROR_SOAP, Estado::get(Estado::REQUEST_ERROR_SOAP, $msg)); |
198 | 198 | return false; |
199 | 199 | } |
200 | - for ($i=0; $i<$retry; $i++) { |
|
200 | + for ($i = 0; $i<$retry; $i++) { |
|
201 | 201 | try { |
202 | 202 | if ($args) { |
203 | 203 | $body = call_user_func_array([$soap, $request], $args); |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | $dte = '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n".$dte; |
266 | 266 | } |
267 | 267 | do { |
268 | - $file = sys_get_temp_dir().'/dte_'.md5(microtime().$token.$dte).'.'.($gzip?'gz':'xml'); |
|
268 | + $file = sys_get_temp_dir().'/dte_'.md5(microtime().$token.$dte).'.'.($gzip ? 'gz' : 'xml'); |
|
269 | 269 | } while (file_exists($file)); |
270 | 270 | if ($gzip) { |
271 | 271 | $dte = gzencode($dte); |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
315 | 315 | } |
316 | 316 | // enviar XML al SII |
317 | - for ($i=0; $i<$retry; $i++) { |
|
317 | + for ($i = 0; $i<$retry; $i++) { |
|
318 | 318 | $response = curl_exec($curl); |
319 | 319 | if ($response and $response!='Error 500') { |
320 | 320 | break; |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | if ($xml->STATUS!=0) { |
344 | 344 | \sasco\LibreDTE\Log::write( |
345 | 345 | $xml->STATUS, |
346 | - Estado::get($xml->STATUS).(isset($xml->DETAIL)?'. '.implode("\n", (array)$xml->DETAIL->ERROR):'') |
|
346 | + Estado::get($xml->STATUS).(isset($xml->DETAIL) ? '. '.implode("\n", (array)$xml->DETAIL->ERROR) : '') |
|
347 | 347 | ); |
348 | 348 | } |
349 | 349 | return $xml; |
@@ -475,12 +475,12 @@ discard block |
||
475 | 475 | $lines = explode("\n", $response); |
476 | 476 | $n_lines = count($lines); |
477 | 477 | $data = []; |
478 | - for ($i=1; $i<$n_lines; $i++) { |
|
478 | + for ($i = 1; $i<$n_lines; $i++) { |
|
479 | 479 | $row = str_getcsv($lines[$i], ';', ''); |
480 | 480 | unset($lines[$i]); |
481 | 481 | if (!isset($row[5])) |
482 | 482 | continue; |
483 | - for ($j=0; $j<6; $j++) |
|
483 | + for ($j = 0; $j<6; $j++) |
|
484 | 484 | $row[$j] = trim($row[$j]); |
485 | 485 | $row[1] = utf8_decode($row[1]); |
486 | 486 | $row[4] = strtolower($row[4]); |
@@ -466,8 +466,9 @@ discard block |
||
466 | 466 | // entregar WSDL local (modificados para ambiente de certificación) |
467 | 467 | if ($ambiente==self::CERTIFICACION) { |
468 | 468 | $wsdl = dirname(dirname(__FILE__)).'/wsdl/'.self::$config['servidor'][$ambiente].'/'.$servicio.'.jws'; |
469 | - if (is_readable($wsdl)) |
|
470 | - return $wsdl; |
|
469 | + if (is_readable($wsdl)) { |
|
470 | + return $wsdl; |
|
471 | + } |
|
471 | 472 | } |
472 | 473 | // entregar WSDL oficial desde SII |
473 | 474 | $location = isset(self::$config['wsdl'][$servicio]) ? self::$config['wsdl'][$servicio] : self::$config['wsdl']['*']; |
@@ -496,10 +497,12 @@ discard block |
||
496 | 497 | $retry = (int)$args; |
497 | 498 | $args = null; |
498 | 499 | } |
499 | - if (!$retry) |
|
500 | - $retry = self::$retry; |
|
501 | - if ($args and !is_array($args)) |
|
502 | - $args = [$args]; |
|
500 | + if (!$retry) { |
|
501 | + $retry = self::$retry; |
|
502 | + } |
|
503 | + if ($args and !is_array($args)) { |
|
504 | + $args = [$args]; |
|
505 | + } |
|
503 | 506 | if (!self::$verificar_ssl) { |
504 | 507 | if (self::getAmbiente()==self::PRODUCCION) { |
505 | 508 | $msg = Estado::get(Estado::ENVIO_SSL_SIN_VERIFICAR); |
@@ -736,10 +739,11 @@ discard block |
||
736 | 739 | public static function getAmbiente($ambiente = null) |
737 | 740 | { |
738 | 741 | if ($ambiente===null) { |
739 | - if (defined('_LibreDTE_CERTIFICACION_')) |
|
740 | - $ambiente = (int)_LibreDTE_CERTIFICACION_; |
|
741 | - else |
|
742 | - $ambiente = self::$ambiente; |
|
742 | + if (defined('_LibreDTE_CERTIFICACION_')) { |
|
743 | + $ambiente = (int)_LibreDTE_CERTIFICACION_; |
|
744 | + } else { |
|
745 | + $ambiente = self::$ambiente; |
|
746 | + } |
|
743 | 747 | } |
744 | 748 | return $ambiente; |
745 | 749 | } |
@@ -765,8 +769,9 @@ discard block |
||
765 | 769 | { |
766 | 770 | // solicitar token |
767 | 771 | $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($Firma); |
768 | - if (!$token) |
|
769 | - return false; |
|
772 | + if (!$token) { |
|
773 | + return false; |
|
774 | + } |
|
770 | 775 | // definir ambiente y servidor |
771 | 776 | $ambiente = self::getAmbiente($ambiente); |
772 | 777 | $servidor = self::$config['servidor'][$ambiente]; |
@@ -795,8 +800,9 @@ discard block |
||
795 | 800 | } |
796 | 801 | // realizar consulta curl |
797 | 802 | $response = curl_exec($curl); |
798 | - if (!$response) |
|
799 | - return false; |
|
803 | + if (!$response) { |
|
804 | + return false; |
|
805 | + } |
|
800 | 806 | // cerrar sesión curl |
801 | 807 | curl_close($curl); |
802 | 808 | // entregar datos del archivo CSV |
@@ -807,10 +813,12 @@ discard block |
||
807 | 813 | for ($i=1; $i<$n_lines; $i++) { |
808 | 814 | $row = str_getcsv($lines[$i], ';', ''); |
809 | 815 | unset($lines[$i]); |
810 | - if (!isset($row[5])) |
|
811 | - continue; |
|
812 | - for ($j=0; $j<6; $j++) |
|
813 | - $row[$j] = trim($row[$j]); |
|
816 | + if (!isset($row[5])) { |
|
817 | + continue; |
|
818 | + } |
|
819 | + for ($j=0; $j<6; $j++) { |
|
820 | + $row[$j] = trim($row[$j]); |
|
821 | + } |
|
814 | 822 | $row[1] = utf8_decode($row[1]); |
815 | 823 | $row[4] = strtolower($row[4]); |
816 | 824 | $row[5] = strtolower($row[5]); |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | * Método que genera nodos XML a partir de un arreglo |
53 | 53 | * @param data Arreglo con los datos que se usarán para generar XML |
54 | 54 | * @param namespace Arreglo con el espacio de nombres para el XML que se generará (URI y prefijo) |
55 | - * @param parent DOMElement padre para los elementos, o =null para que sea la raíz |
|
56 | - * @return Objeto \sasco\LibreDTE\XML |
|
55 | + * @param parent \DOMElement padre para los elementos, o =null para que sea la raíz |
|
56 | + * @return XML \sasco\LibreDTE\XML |
|
57 | 57 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
58 | 58 | * @version 2017-10-22 |
59 | 59 | */ |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | /** |
154 | 154 | * Método para realizar consultas XPATH al documento XML |
155 | 155 | * @param expression Expresión XPath a ejecutar |
156 | - * @return DOMNodeList |
|
156 | + * @return \DOMNodeList |
|
157 | 157 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
158 | 158 | * @version 2015-08-05 |
159 | 159 | */ |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * Método que cuenta los nodos con el mismo nombre hijos deun DOMElement |
275 | 275 | * No sirve usar: $dom->getElementsByTagName($tagName)->length ya que esto |
276 | 276 | * entrega todos los nodos con el nombre, sean hijos, nietos, etc. |
277 | - * @return Cantidad de nodos hijos con el mismo nombre en el DOMElement |
|
277 | + * @return integer de nodos hijos con el mismo nombre en el DOMElement |
|
278 | 278 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
279 | 279 | * @version 2015-09-07 |
280 | 280 | */ |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | |
315 | 315 | /** |
316 | 316 | * Método que entrega el nombre del archivo del schema del XML |
317 | - * @return Nombre del schema o bien =false si no se encontró |
|
317 | + * @return string del schema o bien =false si no se encontró |
|
318 | 318 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
319 | 319 | * @version 2015-12-14 |
320 | 320 | */ |
@@ -356,6 +356,7 @@ discard block |
||
356 | 356 | * respeta el estándar y las requiere convertidas |
357 | 357 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
358 | 358 | * @version 2017-01-20 |
359 | + * @param string $xml |
|
359 | 360 | */ |
360 | 361 | private function fixEntities($xml) |
361 | 362 | { |
@@ -120,8 +120,9 @@ discard block |
||
120 | 120 | private function sanitize($txt) |
121 | 121 | { |
122 | 122 | // si no se paso un texto o bien es un número no se hace nada |
123 | - if (!$txt or is_numeric($txt)) |
|
124 | - return $txt; |
|
123 | + if (!$txt or is_numeric($txt)) { |
|
124 | + return $txt; |
|
125 | + } |
|
125 | 126 | // convertir "predefined entities" de XML |
126 | 127 | $txt = str_replace( |
127 | 128 | ['&', '&', '<', '<', '>', '>', '"', '"', ''', '''], |
@@ -174,8 +175,9 @@ discard block |
||
174 | 175 | { |
175 | 176 | if ($xpath) { |
176 | 177 | $node = $this->xpath($xpath)->item(0); |
177 | - if (!$node) |
|
178 | - return false; |
|
178 | + if (!$node) { |
|
179 | + return false; |
|
180 | + } |
|
179 | 181 | $xml = $this->utf2iso($node->C14N()); |
180 | 182 | $xml = $this->fixEntities($xml); |
181 | 183 | } else { |
@@ -222,12 +224,15 @@ discard block |
||
222 | 224 | public function toArray(\DOMElement $dom = null, array &$array = null, $arregloNodos = false) |
223 | 225 | { |
224 | 226 | // determinar valores de parámetros |
225 | - if (!$dom) |
|
226 | - $dom = $this->documentElement; |
|
227 | - if (!$dom) |
|
228 | - return false; |
|
229 | - if ($array===null) |
|
230 | - $array = [$dom->tagName => null]; |
|
227 | + if (!$dom) { |
|
228 | + $dom = $this->documentElement; |
|
229 | + } |
|
230 | + if (!$dom) { |
|
231 | + return false; |
|
232 | + } |
|
233 | + if ($array===null) { |
|
234 | + $array = [$dom->tagName => null]; |
|
235 | + } |
|
231 | 236 | // agregar atributos del nodo |
232 | 237 | if ($dom->hasAttributes()) { |
233 | 238 | $array[$dom->tagName]['@attributes'] = []; |
@@ -243,22 +248,24 @@ discard block |
||
243 | 248 | if ($textContent!="") { |
244 | 249 | if ($dom->childNodes->length==1 and empty($array[$dom->tagName])) { |
245 | 250 | $array[$dom->tagName] = $textContent; |
246 | - } else |
|
247 | - $array[$dom->tagName]['@value'] = $textContent; |
|
251 | + } else { |
|
252 | + $array[$dom->tagName]['@value'] = $textContent; |
|
253 | + } |
|
248 | 254 | } |
249 | - } |
|
250 | - else if ($child instanceof \DOMElement) { |
|
255 | + } else if ($child instanceof \DOMElement) { |
|
251 | 256 | $nodos_gemelos = $this->countTwins($dom, $child->tagName); |
252 | 257 | if ($nodos_gemelos==1) { |
253 | - if ($arregloNodos) |
|
254 | - $this->toArray($child, $array); |
|
255 | - else |
|
256 | - $this->toArray($child, $array[$dom->tagName]); |
|
258 | + if ($arregloNodos) { |
|
259 | + $this->toArray($child, $array); |
|
260 | + } else { |
|
261 | + $this->toArray($child, $array[$dom->tagName]); |
|
262 | + } |
|
257 | 263 | } |
258 | 264 | // crear arreglo con nodos hijos que tienen el mismo nombre de tag |
259 | 265 | else { |
260 | - if (!isset($array[$dom->tagName][$child->tagName])) |
|
261 | - $array[$dom->tagName][$child->tagName] = []; |
|
266 | + if (!isset($array[$dom->tagName][$child->tagName])) { |
|
267 | + $array[$dom->tagName][$child->tagName] = []; |
|
268 | + } |
|
262 | 269 | $siguiente = count($array[$dom->tagName][$child->tagName]); |
263 | 270 | $array[$dom->tagName][$child->tagName][$siguiente] = []; |
264 | 271 | $this->toArray($child, $array[$dom->tagName][$child->tagName][$siguiente], true); |
@@ -282,8 +289,9 @@ discard block |
||
282 | 289 | { |
283 | 290 | $twins = 0; |
284 | 291 | foreach ($dom->childNodes as $child) { |
285 | - if ($child instanceof \DOMElement and $child->tagName==$tagName) |
|
286 | - $twins++; |
|
292 | + if ($child instanceof \DOMElement and $child->tagName==$tagName) { |
|
293 | + $twins++; |
|
294 | + } |
|
287 | 295 | } |
288 | 296 | return $twins; |
289 | 297 | } |
@@ -297,8 +305,9 @@ discard block |
||
297 | 305 | public function getErrors() |
298 | 306 | { |
299 | 307 | $errors = []; |
300 | - foreach (libxml_get_errors() as $e) |
|
301 | - $errors[] = $e->message; |
|
308 | + foreach (libxml_get_errors() as $e) { |
|
309 | + $errors[] = $e->message; |
|
310 | + } |
|
302 | 311 | return $errors; |
303 | 312 | } |
304 | 313 | |
@@ -321,8 +330,9 @@ discard block |
||
321 | 330 | public function getSchema() |
322 | 331 | { |
323 | 332 | $schemaLocation = $this->documentElement->getAttribute('xsi:schemaLocation'); |
324 | - if (!$schemaLocation or strpos($schemaLocation, ' ')===false) |
|
325 | - return false; |
|
333 | + if (!$schemaLocation or strpos($schemaLocation, ' ')===false) { |
|
334 | + return false; |
|
335 | + } |
|
326 | 336 | list($uri, $xsd) = explode(' ', $schemaLocation); |
327 | 337 | return $xsd; |
328 | 338 | } |
@@ -363,10 +373,12 @@ discard block |
||
363 | 373 | $n_letras = strlen($xml); |
364 | 374 | $convertir = false; |
365 | 375 | for ($i=0; $i<$n_letras; ++$i) { |
366 | - if ($xml[$i]=='>') |
|
367 | - $convertir = true; |
|
368 | - if ($xml[$i]=='<') |
|
369 | - $convertir = false; |
|
376 | + if ($xml[$i]=='>') { |
|
377 | + $convertir = true; |
|
378 | + } |
|
379 | + if ($xml[$i]=='<') { |
|
380 | + $convertir = false; |
|
381 | + } |
|
370 | 382 | if ($convertir) { |
371 | 383 | $l = $xml[$i]=='\'' ? ''' : ($xml[$i]=='"' ? '"' : $xml[$i]); |
372 | 384 | } else { |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | */ |
198 | 198 | private function utf2iso($string) |
199 | 199 | { |
200 | - return mb_detect_encoding($string, ['UTF-8', 'ISO-8859-1']) != 'ISO-8859-1' ? utf8_decode($string) : $string; |
|
200 | + return mb_detect_encoding($string, ['UTF-8', 'ISO-8859-1'])!='ISO-8859-1' ? utf8_decode($string) : $string; |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | } |
238 | 238 | // agregar nodos hijos |
239 | 239 | if ($dom->hasChildNodes()) { |
240 | - foreach($dom->childNodes as $child) { |
|
240 | + foreach ($dom->childNodes as $child) { |
|
241 | 241 | if ($child instanceof \DOMText) { |
242 | 242 | $textContent = trim($child->textContent); |
243 | 243 | if ($textContent!="") { |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | $newXML = ''; |
363 | 363 | $n_letras = strlen($xml); |
364 | 364 | $convertir = false; |
365 | - for ($i=0; $i<$n_letras; ++$i) { |
|
365 | + for ($i = 0; $i<$n_letras; ++$i) { |
|
366 | 366 | if ($xml[$i]=='>') |
367 | 367 | $convertir = true; |
368 | 368 | if ($xml[$i]=='<') |
@@ -254,7 +254,7 @@ |
||
254 | 254 | |
255 | 255 | /** |
256 | 256 | * Método que indica si el CAF es de certificación o no |
257 | - * @return bool =true si los folios son del ambiente de certificación, =null si no se pudo determinar |
|
257 | + * @return boolean|null =true si los folios son del ambiente de certificación, =null si no se pudo determinar |
|
258 | 258 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
259 | 259 | * @version 2015-10-30 |
260 | 260 | */ |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | // validar firma del SII sobre los folios |
64 | 64 | $firma = $this->getFirma(); |
65 | 65 | $idk = $this->getIDK(); |
66 | - if ($firma === false || $idk === false) { |
|
66 | + if ($firma===false || $idk===false) { |
|
67 | 67 | return false; |
68 | 68 | } |
69 | 69 | $pub_key = \sasco\LibreDTE\Sii::cert($idk); |
70 | - if ($pub_key === false || openssl_verify($this->xml->getFlattened('/AUTORIZACION/CAF/DA'), base64_decode($firma), $pub_key)!==1) { |
|
70 | + if ($pub_key===false || openssl_verify($this->xml->getFlattened('/AUTORIZACION/CAF/DA'), base64_decode($firma), $pub_key)!==1) { |
|
71 | 71 | \sasco\LibreDTE\Log::write( |
72 | 72 | \sasco\LibreDTE\Estado::FOLIOS_ERROR_FIRMA, |
73 | 73 | \sasco\LibreDTE\Estado::get(\sasco\LibreDTE\Estado::FOLIOS_ERROR_FIRMA) |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | ); |
99 | 99 | return false; |
100 | 100 | } |
101 | - return $plain === $plain_firmado; |
|
101 | + return $plain===$plain_firmado; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | public function getCertificacion() |
262 | 262 | { |
263 | 263 | $idk = $this->getIDK(); |
264 | - return $idk ? $idk === 100 : null; |
|
264 | + return $idk ? $idk===100 : null; |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | } |
278 | 278 | $d1 = new \DateTime($this->getFechaAutorizacion()); |
279 | 279 | $d2 = new \DateTime(date('Y-m-d')); |
280 | - $meses = $d1->diff($d2)->m + ($d1->diff($d2)->y*12); |
|
281 | - return $meses <= 18; |
|
280 | + $meses = $d1->diff($d2)->m+($d1->diff($d2)->y * 12); |
|
281 | + return $meses<=18; |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -101,13 +101,16 @@ discard block |
||
101 | 101 | $this->Line(0, $this->getY()-1, 290, $this->getY()-2, $style); |
102 | 102 | $this->SetFont('', 'B', 6); |
103 | 103 | if (empty($this->papelContinuo)) { |
104 | - if (!empty($this->footer['left'])) |
|
105 | - $this->Texto($this->footer['left']); |
|
106 | - if (!empty($this->footer['right'])) |
|
107 | - $this->Texto($this->footer['right'], null, null, 'R'); |
|
104 | + if (!empty($this->footer['left'])) { |
|
105 | + $this->Texto($this->footer['left']); |
|
106 | + } |
|
107 | + if (!empty($this->footer['right'])) { |
|
108 | + $this->Texto($this->footer['right'], null, null, 'R'); |
|
109 | + } |
|
108 | 110 | } else { |
109 | - if (!empty($this->footer['left'])) |
|
110 | - $this->Texto($this->footer['left'], null, null, 'C'); |
|
111 | + if (!empty($this->footer['left'])) { |
|
112 | + $this->Texto($this->footer['left'], null, null, 'C'); |
|
113 | + } |
|
111 | 114 | if (!empty($this->footer['right'])) { |
112 | 115 | $this->Ln(); |
113 | 116 | $this->Texto($this->footer['right'], null, null, 'C'); |
@@ -133,8 +136,9 @@ discard block |
||
133 | 136 | ]; |
134 | 137 | } |
135 | 138 | // si no es arreglo se convierte en uno |
136 | - if (!is_array($footer)) |
|
137 | - $footer = ['left'=>$footer]; |
|
139 | + if (!is_array($footer)) { |
|
140 | + $footer = ['left'=>$footer]; |
|
141 | + } |
|
138 | 142 | // asignar footer |
139 | 143 | $this->footer = array_merge(['left'=>'', 'right'=>''], $footer); |
140 | 144 | } else { |
@@ -155,8 +159,7 @@ discard block |
||
155 | 159 | for ($i=0; $i<$cells; ++$i) { |
156 | 160 | $widths[] = $width; |
157 | 161 | } |
158 | - } |
|
159 | - else if (is_array($cells)){ |
|
162 | + } else if (is_array($cells)){ |
|
160 | 163 | $width = floor($total/count($cells)); |
161 | 164 | foreach ($cells as $i) { |
162 | 165 | $widths[$i] = $width; |
@@ -177,8 +180,9 @@ discard block |
||
177 | 180 | foreach ($data as $row) { |
178 | 181 | foreach ($row as $col => $value) { |
179 | 182 | if (empty($value)) { |
180 | - if (!array_key_exists($col, $cols_empty)) |
|
181 | - $cols_empty[$col] = 0; |
|
183 | + if (!array_key_exists($col, $cols_empty)) { |
|
184 | + $cols_empty[$col] = 0; |
|
185 | + } |
|
182 | 186 | $cols_empty[$col]++; |
183 | 187 | } |
184 | 188 | } |
@@ -191,10 +195,12 @@ discard block |
||
191 | 195 | foreach ($data as &$row) { |
192 | 196 | unset($row[$col]); |
193 | 197 | } |
194 | - if (isset($options['width'])) |
|
195 | - unset($options['width'][$titles_keys[$col]]); |
|
196 | - if (isset($options['align'])) |
|
197 | - unset($options['align'][$titles_keys[$col]]); |
|
198 | + if (isset($options['width'])) { |
|
199 | + unset($options['width'][$titles_keys[$col]]); |
|
200 | + } |
|
201 | + if (isset($options['align'])) { |
|
202 | + unset($options['align'][$titles_keys[$col]]); |
|
203 | + } |
|
198 | 204 | } |
199 | 205 | } |
200 | 206 | if (isset($options['width'])) { |
@@ -202,16 +208,18 @@ discard block |
||
202 | 208 | $key_0 = null; |
203 | 209 | $suma = 0; |
204 | 210 | foreach ($options['width'] as $key => $val) { |
205 | - if ($val===0) |
|
206 | - $key_0 = $key; |
|
211 | + if ($val===0) { |
|
212 | + $key_0 = $key; |
|
213 | + } |
|
207 | 214 | $suma += $val; |
208 | 215 | } |
209 | 216 | if ($key_0!==null) { |
210 | 217 | $options['width'][$key_0] = 190 - $suma; |
211 | 218 | } |
212 | 219 | } |
213 | - if (isset($options['align'])) |
|
214 | - $options['align'] = array_slice($options['align'], 0); |
|
220 | + if (isset($options['align'])) { |
|
221 | + $options['align'] = array_slice($options['align'], 0); |
|
222 | + } |
|
215 | 223 | $this->addTable($titles, $data, $options, $html); |
216 | 224 | } |
217 | 225 | |
@@ -243,8 +251,9 @@ discard block |
||
243 | 251 | $buffer = '<table style="border:1px solid #333">'; |
244 | 252 | // Definir títulos de columnas |
245 | 253 | $thead = isset($options['width']) and is_array($options['width']) and count($options['width']) == count($headers); |
246 | - if ($thead) |
|
247 | - $buffer .= '<thead>'; |
|
254 | + if ($thead) { |
|
255 | + $buffer .= '<thead>'; |
|
256 | + } |
|
248 | 257 | $buffer .= '<tr>'; |
249 | 258 | $i = 0; |
250 | 259 | foreach ($headers as &$col) { |
@@ -254,11 +263,13 @@ discard block |
||
254 | 263 | $i++; |
255 | 264 | } |
256 | 265 | $buffer .= '</tr>'; |
257 | - if ($thead) |
|
258 | - $buffer .= '</thead>'; |
|
266 | + if ($thead) { |
|
267 | + $buffer .= '</thead>'; |
|
268 | + } |
|
259 | 269 | // Definir datos de la tabla |
260 | - if ($thead) |
|
261 | - $buffer .= '<tbody>'; |
|
270 | + if ($thead) { |
|
271 | + $buffer .= '<tbody>'; |
|
272 | + } |
|
262 | 273 | foreach ($data as &$row) { |
263 | 274 | $buffer .= '<tr>'; |
264 | 275 | $i = 0; |
@@ -270,8 +281,9 @@ discard block |
||
270 | 281 | } |
271 | 282 | $buffer .= '</tr>'; |
272 | 283 | } |
273 | - if ($thead) |
|
274 | - $buffer .= '</tbody>'; |
|
284 | + if ($thead) { |
|
285 | + $buffer .= '</tbody>'; |
|
286 | + } |
|
275 | 287 | // Finalizar tabla |
276 | 288 | $buffer .= '</table>'; |
277 | 289 | // generar tabla en HTML |
@@ -397,8 +409,12 @@ discard block |
||
397 | 409 | */ |
398 | 410 | public function Texto($txt, $x=null, $y=null, $align='', $w=0, $link='', $border=0, $fill=false) |
399 | 411 | { |
400 | - if ($x==null) $x = $this->GetX(); |
|
401 | - if ($y==null) $y = $this->GetY(); |
|
412 | + if ($x==null) { |
|
413 | + $x = $this->GetX(); |
|
414 | + } |
|
415 | + if ($y==null) { |
|
416 | + $y = $this->GetY(); |
|
417 | + } |
|
402 | 418 | $textrendermode = $this->textrendermode; |
403 | 419 | $textstrokewidth = $this->textstrokewidth; |
404 | 420 | $this->setTextRenderingMode(0, true, false); |
@@ -418,8 +434,12 @@ discard block |
||
418 | 434 | */ |
419 | 435 | public function MultiTexto($txt, $x=null, $y=null, $align='', $w=0, $border=0, $fill=false) |
420 | 436 | { |
421 | - if ($x==null) $x = $this->GetX(); |
|
422 | - if ($y==null) $y = $this->GetY(); |
|
437 | + if ($x==null) { |
|
438 | + $x = $this->GetX(); |
|
439 | + } |
|
440 | + if ($y==null) { |
|
441 | + $y = $this->GetY(); |
|
442 | + } |
|
423 | 443 | $textrendermode = $this->textrendermode; |
424 | 444 | $textstrokewidth = $this->textstrokewidth; |
425 | 445 | $this->setTextRenderingMode(0, true, false); |
@@ -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 |
@@ -152,13 +152,13 @@ discard block |
||
152 | 152 | { |
153 | 153 | $widths = []; |
154 | 154 | if (is_int($cells)) { |
155 | - $width = floor($total/$cells); |
|
156 | - for ($i=0; $i<$cells; ++$i) { |
|
155 | + $width = floor($total / $cells); |
|
156 | + for ($i = 0; $i<$cells; ++$i) { |
|
157 | 157 | $widths[] = $width; |
158 | 158 | } |
159 | 159 | } |
160 | - else if (is_array($cells)){ |
|
161 | - $width = floor($total/count($cells)); |
|
160 | + else if (is_array($cells)) { |
|
161 | + $width = floor($total / count($cells)); |
|
162 | 162 | foreach ($cells as $i) { |
163 | 163 | $widths[$i] = $width; |
164 | 164 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | $suma += $val; |
209 | 209 | } |
210 | 210 | if ($key_0!==null) { |
211 | - $options['width'][$key_0] = 190 - $suma; |
|
211 | + $options['width'][$key_0] = 190-$suma; |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | if (isset($options['align'])) |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $a = (isset($options['align']) and is_array($options['align'])) ? $options['align'] : []; |
244 | 244 | $buffer = '<table style="border:1px solid #333">'; |
245 | 245 | // Definir títulos de columnas |
246 | - $thead = isset($options['width']) and is_array($options['width']) and count($options['width']) == count($headers); |
|
246 | + $thead = isset($options['width']) and is_array($options['width']) and count($options['width'])==count($headers); |
|
247 | 247 | if ($thead) |
248 | 248 | $buffer .= '<thead>'; |
249 | 249 | $buffer .= '<tr>'; |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | $options['bordercolor'][2] |
304 | 304 | ); |
305 | 305 | $this->SetLineWidth($options['borderwidth']); |
306 | - $this->SetFont($this->defaultOptions['font']['family'], 'B', $options['fontsize']); |
|
306 | + $this->SetFont($this->defaultOptions['font']['family'], 'B', $options['fontsize']); |
|
307 | 307 | // corregir indices |
308 | 308 | $headers_keys = array_keys($headers); |
309 | 309 | if (is_array($options['width'])) { |
@@ -325,13 +325,13 @@ discard block |
||
325 | 325 | } |
326 | 326 | // Header |
327 | 327 | $x = $this->GetX(); |
328 | - foreach($headers as $i => $header) { |
|
328 | + foreach ($headers as $i => $header) { |
|
329 | 329 | $this->Cell($options['width'][$i], $options['height'], $headers[$i], 1, 0, $options['align'][$i], 1); |
330 | 330 | } |
331 | 331 | $this->Ln(); |
332 | 332 | $y = $this->GetY(); |
333 | 333 | // Color and font restoration |
334 | - $this->SetFillColor ( |
|
334 | + $this->SetFillColor( |
|
335 | 335 | $options['bodybackground'][0], |
336 | 336 | $options['bodybackground'][1], |
337 | 337 | $options['bodybackground'][2] |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | $this->SetX($x); |
357 | 357 | $y_0 = $this->GetY(); |
358 | 358 | $y_s = []; |
359 | - foreach($headers as $i => $header) { |
|
359 | + foreach ($headers as $i => $header) { |
|
360 | 360 | $x_0 = $this->GetX(); |
361 | 361 | $this->SetXY($x_0, $y_0); |
362 | 362 | $aux = explode("\n", $row[$i]); |
@@ -366,28 +366,28 @@ discard block |
||
366 | 366 | if ($value2) { |
367 | 367 | $this->Ln(); |
368 | 368 | $this->SetX($x_0); |
369 | - $this->SetFont($this->defaultOptions['font']['family'], '', $options['fontsize']-2); |
|
369 | + $this->SetFont($this->defaultOptions['font']['family'], '', $options['fontsize']-2); |
|
370 | 370 | $y_2 = $this->MultiCell($options['width'][$i], $options['height'], $value2, $options['tdborder'], $options['align'][$i], false, 0); |
371 | - $this->SetFont($this->defaultOptions['font']['family'], '', $options['fontsize']); |
|
372 | - $y_s[] = $y_1 + $y_2*0.9; |
|
371 | + $this->SetFont($this->defaultOptions['font']['family'], '', $options['fontsize']); |
|
372 | + $y_s[] = $y_1+$y_2 * 0.9; |
|
373 | 373 | } else { |
374 | 374 | $y_s[] = $y_1; |
375 | 375 | } |
376 | 376 | } |
377 | - $this->Ln(max($y_s)*5); |
|
377 | + $this->Ln(max($y_s) * 5); |
|
378 | 378 | // si se pasó a página siguiente se hace rollback y se crea nueva página con cabecera nuevamente en la tabla |
379 | - if($num_pages < $this->getNumPages()) { |
|
379 | + if ($num_pages<$this->getNumPages()) { |
|
380 | 380 | $this->rollbackTransaction(true); |
381 | 381 | $this->AddPage(); |
382 | 382 | $this->SetX($x); |
383 | - foreach($headers as $i => $header) { |
|
383 | + foreach ($headers as $i => $header) { |
|
384 | 384 | $this->Cell($options['width'][$i], $options['height'], $headers[$i], 1, 0, $options['align'][$i], 1); |
385 | 385 | } |
386 | 386 | $this->Ln(); |
387 | 387 | $this->SetX($x); |
388 | 388 | $y_0 = $this->GetY(); |
389 | 389 | $y_s = []; |
390 | - foreach($headers as $i => $header) { |
|
390 | + foreach ($headers as $i => $header) { |
|
391 | 391 | $x_0 = $this->GetX(); |
392 | 392 | $this->SetXY($x_0, $y_0); |
393 | 393 | $aux = explode("\n", $row[$i]); |
@@ -397,15 +397,15 @@ discard block |
||
397 | 397 | if ($value2) { |
398 | 398 | $this->Ln(); |
399 | 399 | $this->SetX($x_0); |
400 | - $this->SetFont($this->defaultOptions['font']['family'], '', $options['fontsize']-2); |
|
400 | + $this->SetFont($this->defaultOptions['font']['family'], '', $options['fontsize']-2); |
|
401 | 401 | $y_2 = $this->MultiCell($options['width'][$i], $options['height'], $value2, $options['tdborder'], $options['align'][$i], false, 0); |
402 | - $this->SetFont($this->defaultOptions['font']['family'], '', $options['fontsize']); |
|
403 | - $y_s[] = $y_1 + $y_2*0.9; |
|
402 | + $this->SetFont($this->defaultOptions['font']['family'], '', $options['fontsize']); |
|
403 | + $y_s[] = $y_1+$y_2 * 0.9; |
|
404 | 404 | } else { |
405 | 405 | $y_s[] = $y_1; |
406 | 406 | } |
407 | 407 | } |
408 | - $this->Ln(max($y_s)*5); |
|
408 | + $this->Ln(max($y_s) * 5); |
|
409 | 409 | } else { |
410 | 410 | $this->commitTransaction(); |
411 | 411 | } |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl) |
435 | 435 | * @version 2014-09-20 |
436 | 436 | */ |
437 | - public function Texto($txt, $x=null, $y=null, $align='', $w=0, $link='', $border=0, $fill=false) |
|
437 | + public function Texto($txt, $x = null, $y = null, $align = '', $w = 0, $link = '', $border = 0, $fill = false) |
|
438 | 438 | { |
439 | 439 | if ($x==null) $x = $this->GetX(); |
440 | 440 | if ($y==null) $y = $this->GetY(); |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl) |
456 | 456 | * @version 2014-09-20 |
457 | 457 | */ |
458 | - public function MultiTexto($txt, $x=null, $y=null, $align='', $w=0, $border=0, $fill=false) |
|
458 | + public function MultiTexto($txt, $x = null, $y = null, $align = '', $w = 0, $border = 0, $fill = false) |
|
459 | 459 | { |
460 | 460 | if ($x==null) $x = $this->GetX(); |
461 | 461 | if ($y==null) $y = $this->GetY(); |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | /** |
188 | 188 | * Método que asigna la ubicación del logo de la empresa |
189 | 189 | * @param logo URI del logo (puede ser local o en una URL) |
190 | - * @param posicion Posición respecto a datos del emisor (=0 izq, =1 arriba) |
|
190 | + * @param posicion integer respecto a datos del emisor (=0 izq, =1 arriba) |
|
191 | 191 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
192 | 192 | * @version 2016-08-04 |
193 | 193 | */ |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | * contínuo |
367 | 367 | * @param dte Arreglo con los datos del XML (tag Documento) |
368 | 368 | * @param timbre String XML con el tag TED del DTE |
369 | - * @param width Ancho del papel contínuo en mm |
|
369 | + * @param width boolean del papel contínuo en mm |
|
370 | 370 | * @author Pablo Reyes (https://github.com/pabloxp) |
371 | 371 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
372 | 372 | * @version 2017-10-24 |
@@ -522,10 +522,11 @@ discard block |
||
522 | 522 | * - Dirección casa central del emisor |
523 | 523 | * - Dirección sucursales |
524 | 524 | * @param emisor Arreglo con los datos del emisor (tag Emisor del XML) |
525 | - * @param x Posición horizontal de inicio en el PDF |
|
526 | - * @param y Posición vertical de inicio en el PDF |
|
527 | - * @param w Ancho de la información del emisor |
|
528 | - * @param w_img Ancho máximo de la imagen |
|
525 | + * @param x integer horizontal de inicio en el PDF |
|
526 | + * @param y integer vertical de inicio en el PDF |
|
527 | + * @param w integer de la información del emisor |
|
528 | + * @param w_img integer máximo de la imagen |
|
529 | + * @param integer $font_size |
|
529 | 530 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
530 | 531 | * @version 2018-04-13 |
531 | 532 | */ |
@@ -596,11 +597,13 @@ discard block |
||
596 | 597 | * @param rut RUT del emisor |
597 | 598 | * @param tipo Código o glosa del tipo de documento |
598 | 599 | * @param sucursal_sii Código o glosa de la sucursal del SII del Emisor |
599 | - * @param x Posición horizontal de inicio en el PDF |
|
600 | - * @param y Posición vertical de inicio en el PDF |
|
601 | - * @param w Ancho de la información del emisor |
|
600 | + * @param x integer horizontal de inicio en el PDF |
|
601 | + * @param y integer vertical de inicio en el PDF |
|
602 | + * @param w integer de la información del emisor |
|
603 | + * @param integer $font_size |
|
602 | 604 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
603 | 605 | * @version 2016-12-02 |
606 | + * @return integer |
|
604 | 607 | */ |
605 | 608 | protected function agregarFolio($rut, $tipo, $folio, $sucursal_sii = null, $x = 130, $y = 15, $w = 70, $font_size = null, array $color = null) |
606 | 609 | { |
@@ -647,7 +650,7 @@ discard block |
||
647 | 650 | * Método que agrega los datos de la emisión del DTE que no son los dato del |
648 | 651 | * receptor |
649 | 652 | * @param IdDoc Información general del documento |
650 | - * @param x Posición horizontal de inicio en el PDF |
|
653 | + * @param x integer horizontal de inicio en el PDF |
|
651 | 654 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
652 | 655 | * @version 2017-06-15 |
653 | 656 | */ |
@@ -735,7 +738,7 @@ discard block |
||
735 | 738 | /** |
736 | 739 | * Método que agrega los datos del receptor |
737 | 740 | * @param receptor Arreglo con los datos del receptor (tag Receptor del XML) |
738 | - * @param x Posición horizontal de inicio en el PDF |
|
741 | + * @param x integer horizontal de inicio en el PDF |
|
739 | 742 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
740 | 743 | * @version 2017-06-15 |
741 | 744 | */ |
@@ -822,7 +825,7 @@ discard block |
||
822 | 825 | * Método que agrega los datos del traslado |
823 | 826 | * @param IndTraslado |
824 | 827 | * @param Transporte |
825 | - * @param x Posición horizontal de inicio en el PDF |
|
828 | + * @param x integer horizontal de inicio en el PDF |
|
826 | 829 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
827 | 830 | * @version 2016-08-03 |
828 | 831 | */ |
@@ -893,7 +896,7 @@ discard block |
||
893 | 896 | /** |
894 | 897 | * Método que agrega las referencias del documento |
895 | 898 | * @param referencias Arreglo con las referencias del documento (tag Referencia del XML) |
896 | - * @param x Posición horizontal de inicio en el PDF |
|
899 | + * @param x integer horizontal de inicio en el PDF |
|
897 | 900 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
898 | 901 | * @version 2017-09-25 |
899 | 902 | */ |
@@ -930,7 +933,7 @@ discard block |
||
930 | 933 | /** |
931 | 934 | * Método que agrega el detalle del documento |
932 | 935 | * @param detalle Arreglo con el detalle del documento (tag Detalle del XML) |
933 | - * @param x Posición horizontal de inicio en el PDF |
|
936 | + * @param x integer horizontal de inicio en el PDF |
|
934 | 937 | * @param y Posición vertical de inicio en el PDF |
935 | 938 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
936 | 939 | * @version 2018-04-15 |
@@ -1001,7 +1004,7 @@ discard block |
||
1001 | 1004 | /** |
1002 | 1005 | * Método que agrega el detalle del documento |
1003 | 1006 | * @param detalle Arreglo con el detalle del documento (tag Detalle del XML) |
1004 | - * @param x Posición horizontal de inicio en el PDF |
|
1007 | + * @param x integer horizontal de inicio en el PDF |
|
1005 | 1008 | * @param y Posición vertical de inicio en el PDF |
1006 | 1009 | * @author Pablo Reyes (https://github.com/pabloxp) |
1007 | 1010 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
@@ -1037,7 +1040,7 @@ discard block |
||
1037 | 1040 | * Método que agrega el subtotal del DTE |
1038 | 1041 | * @param detalle Arreglo con los detalles del documentos para poder |
1039 | 1042 | * calcular subtotal |
1040 | - * @param x Posición horizontal de inicio en el PDF |
|
1043 | + * @param x integer horizontal de inicio en el PDF |
|
1041 | 1044 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
1042 | 1045 | * @version 2016-08-17 |
1043 | 1046 | */ |
@@ -1063,7 +1066,7 @@ discard block |
||
1063 | 1066 | /** |
1064 | 1067 | * Método que agrega los descuentos y/o recargos globales del documento |
1065 | 1068 | * @param descuentosRecargos Arreglo con los descuentos y/o recargos del documento (tag DscRcgGlobal del XML) |
1066 | - * @param x Posición horizontal de inicio en el PDF |
|
1069 | + * @param x integer horizontal de inicio en el PDF |
|
1067 | 1070 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
1068 | 1071 | * @version 2018-04-15 |
1069 | 1072 | */ |
@@ -1090,7 +1093,7 @@ discard block |
||
1090 | 1093 | /** |
1091 | 1094 | * Método que agrega los pagos del documento |
1092 | 1095 | * @param pagos Arreglo con los pagos del documento |
1093 | - * @param x Posición horizontal de inicio en el PDF |
|
1096 | + * @param x integer horizontal de inicio en el PDF |
|
1094 | 1097 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
1095 | 1098 | * @version 2016-07-24 |
1096 | 1099 | */ |
@@ -1239,9 +1242,9 @@ discard block |
||
1239 | 1242 | * - Se imprime en el tamaño mínimo: 2x5 cms |
1240 | 1243 | * - En el lado de abajo con margen izquierdo mínimo de 2 cms |
1241 | 1244 | * @param timbre String con los datos del timbre |
1242 | - * @param x Posición horizontal de inicio en el PDF |
|
1243 | - * @param y Posición vertical de inicio en el PDF |
|
1244 | - * @param w Ancho del timbre |
|
1245 | + * @param x integer horizontal de inicio en el PDF |
|
1246 | + * @param y integer vertical de inicio en el PDF |
|
1247 | + * @param w integer del timbre |
|
1245 | 1248 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
1246 | 1249 | * @version 2018-04-12 |
1247 | 1250 | */ |
@@ -1279,10 +1282,10 @@ discard block |
||
1279 | 1282 | |
1280 | 1283 | /** |
1281 | 1284 | * Método que agrega el acuse de rebido |
1282 | - * @param x Posición horizontal de inicio en el PDF |
|
1283 | - * @param y Posición vertical de inicio en el PDF |
|
1284 | - * @param w Ancho del acuse de recibo |
|
1285 | - * @param h Alto del acuse de recibo |
|
1285 | + * @param x integer horizontal de inicio en el PDF |
|
1286 | + * @param y integer vertical de inicio en el PDF |
|
1287 | + * @param w integer del acuse de recibo |
|
1288 | + * @param h integer del acuse de recibo |
|
1286 | 1289 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
1287 | 1290 | * @version 2018-04-13 |
1288 | 1291 | */ |
@@ -1310,10 +1313,10 @@ discard block |
||
1310 | 1313 | |
1311 | 1314 | /** |
1312 | 1315 | * Método que agrega el acuse de rebido |
1313 | - * @param x Posición horizontal de inicio en el PDF |
|
1316 | + * @param x integer horizontal de inicio en el PDF |
|
1314 | 1317 | * @param y Posición vertical de inicio en el PDF |
1315 | - * @param w Ancho del acuse de recibo |
|
1316 | - * @param h Alto del acuse de recibo |
|
1318 | + * @param w integer del acuse de recibo |
|
1319 | + * @param h integer del acuse de recibo |
|
1317 | 1320 | * @author Pablo Reyes (https://github.com/pabloxp) |
1318 | 1321 | * @version 2015-11-17 |
1319 | 1322 | */ |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | { |
182 | 182 | parent::__construct(); |
183 | 183 | $this->SetTitle('Documento Tributario Electrónico (DTE) de Chile by LibreDTE'); |
184 | - $this->papelContinuo = $papelContinuo === true ? 80 : $papelContinuo; |
|
184 | + $this->papelContinuo = $papelContinuo===true ? 80 : $papelContinuo; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | $this->setY(max($y)); |
327 | 327 | $this->Ln(); |
328 | 328 | $y = []; |
329 | - $y[] = $this->agregarDatosEmision($dte['Encabezado']['IdDoc'], !empty($dte['Encabezado']['Emisor']['CdgVendedor'])?$dte['Encabezado']['Emisor']['CdgVendedor']:null); |
|
329 | + $y[] = $this->agregarDatosEmision($dte['Encabezado']['IdDoc'], !empty($dte['Encabezado']['Emisor']['CdgVendedor']) ? $dte['Encabezado']['Emisor']['CdgVendedor'] : null); |
|
330 | 330 | $y[] = $this->agregarReceptor($dte['Encabezado']); |
331 | 331 | $this->setY(max($y)); |
332 | 332 | $this->agregarTraslado( |
@@ -386,15 +386,15 @@ discard block |
||
386 | 386 | $dte['Encabezado']['IdDoc']['TipoDTE'], |
387 | 387 | $dte['Encabezado']['IdDoc']['Folio'], |
388 | 388 | $dte['Encabezado']['Emisor']['CmnaOrigen'], |
389 | - $x_start, $y_start, $width-($x_start*4), 10, |
|
390 | - [0,0,0] |
|
389 | + $x_start, $y_start, $width-($x_start * 4), 10, |
|
390 | + [0, 0, 0] |
|
391 | 391 | ); |
392 | - $y = $this->agregarEmisor($dte['Encabezado']['Emisor'], $x_start, $y+2, $width-($x_start*4), 8, 9, [0,0,0]); |
|
392 | + $y = $this->agregarEmisor($dte['Encabezado']['Emisor'], $x_start, $y+2, $width-($x_start * 4), 8, 9, [0, 0, 0]); |
|
393 | 393 | // datos del documento |
394 | 394 | $this->SetY($y); |
395 | 395 | $this->Ln(); |
396 | 396 | $this->setFont('', '', 8); |
397 | - $this->agregarDatosEmision($dte['Encabezado']['IdDoc'], !empty($dte['Encabezado']['Emisor']['CdgVendedor'])?$dte['Encabezado']['Emisor']['CdgVendedor']:null, $x_start, $offset, false); |
|
397 | + $this->agregarDatosEmision($dte['Encabezado']['IdDoc'], !empty($dte['Encabezado']['Emisor']['CdgVendedor']) ? $dte['Encabezado']['Emisor']['CdgVendedor'] : null, $x_start, $offset, false); |
|
398 | 398 | $this->agregarReceptor($dte['Encabezado'], $x_start, $offset); |
399 | 399 | $this->agregarTraslado( |
400 | 400 | !empty($dte['Encabezado']['IdDoc']['IndTraslado']) ? $dte['Encabezado']['IdDoc']['IndTraslado'] : null, |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | $this->AddPage('P', [$height ? $height : $this->papel_continuo_alto, $width]); |
448 | 448 | $x = 1; |
449 | 449 | $y = 5; |
450 | - $this->SetXY($x,$y); |
|
450 | + $this->SetXY($x, $y); |
|
451 | 451 | // agregar datos del documento |
452 | 452 | $this->setFont('', '', 8); |
453 | 453 | $this->MultiTexto(!empty($dte['Encabezado']['Emisor']['RznSoc']) ? $dte['Encabezado']['Emisor']['RznSoc'] : $dte['Encabezado']['Emisor']['RznSocEmisor'], $x, null, '', $width-2); |
@@ -537,13 +537,13 @@ discard block |
||
537 | 537 | $this->logo['uri'], |
538 | 538 | $x, |
539 | 539 | $y, |
540 | - !$this->logo['posicion']?$w_img:null, $this->logo['posicion']?($w_img/2):null, |
|
540 | + !$this->logo['posicion'] ? $w_img : null, $this->logo['posicion'] ? ($w_img / 2) : null, |
|
541 | 541 | 'PNG', |
542 | - (isset($emisor['url'])?$emisor['url']:''), |
|
542 | + (isset($emisor['url']) ? $emisor['url'] : ''), |
|
543 | 543 | 'T' |
544 | 544 | ); |
545 | 545 | if ($this->logo['posicion']) { |
546 | - $this->SetY($this->y + ($w_img/2)); |
|
546 | + $this->SetY($this->y+($w_img / 2)); |
|
547 | 547 | $w += 40; |
548 | 548 | } else { |
549 | 549 | $x = $this->x+3; |
@@ -554,14 +554,14 @@ discard block |
||
554 | 554 | } |
555 | 555 | // agregar datos del emisor |
556 | 556 | $this->setFont('', 'B', $font_size ? $font_size : 14); |
557 | - $this->SetTextColorArray($color===null?[32, 92, 144]:$color); |
|
557 | + $this->SetTextColorArray($color===null ? [32, 92, 144] : $color); |
|
558 | 558 | $this->MultiTexto(!empty($emisor['RznSoc']) ? $emisor['RznSoc'] : $emisor['RznSocEmisor'], $x, $this->y+2, 'L', $w); |
559 | 559 | $this->setFont('', 'B', $font_size ? $font_size : 9); |
560 | - $this->SetTextColorArray([0,0,0]); |
|
560 | + $this->SetTextColorArray([0, 0, 0]); |
|
561 | 561 | $this->MultiTexto(!empty($emisor['GiroEmis']) ? $emisor['GiroEmis'] : $emisor['GiroEmisor'], $x, $this->y, 'L', $w); |
562 | 562 | $comuna = !empty($emisor['CmnaOrigen']) ? $emisor['CmnaOrigen'] : null; |
563 | 563 | $ciudad = !empty($emisor['CiudadOrigen']) ? $emisor['CiudadOrigen'] : \sasco\LibreDTE\Chile::getCiudad($comuna); |
564 | - $this->MultiTexto($emisor['DirOrigen'].($comuna?(', '.$comuna):'').($ciudad?(', '.$ciudad):''), $x, $this->y, 'L', $w); |
|
564 | + $this->MultiTexto($emisor['DirOrigen'].($comuna ? (', '.$comuna) : '').($ciudad ? (', '.$ciudad) : ''), $x, $this->y, 'L', $w); |
|
565 | 565 | if (!empty($emisor['Sucursal'])) { |
566 | 566 | $this->MultiTexto('Sucursal: '.$emisor['Sucursal'], $x, $this->y, 'L', $w); |
567 | 567 | } |
@@ -605,12 +605,12 @@ discard block |
||
605 | 605 | protected function agregarFolio($rut, $tipo, $folio, $sucursal_sii = null, $x = 130, $y = 15, $w = 70, $font_size = null, array $color = null) |
606 | 606 | { |
607 | 607 | if ($color===null) { |
608 | - $color = $tipo ? ($tipo==52 ? [0,172,140] : [255,0,0]) : [0,0,0]; |
|
608 | + $color = $tipo ? ($tipo==52 ? [0, 172, 140] : [255, 0, 0]) : [0, 0, 0]; |
|
609 | 609 | } |
610 | 610 | $this->SetTextColorArray($color); |
611 | 611 | // colocar rut emisor, glosa documento y folio |
612 | 612 | list($rut, $dv) = explode('-', $rut); |
613 | - $this->setFont ('', 'B', $font_size ? $font_size : 15); |
|
613 | + $this->setFont('', 'B', $font_size ? $font_size : 15); |
|
614 | 614 | $this->MultiTexto('R.U.T.: '.$this->num($rut).'-'.$dv, $x, $y+4, 'C', $w); |
615 | 615 | $this->setFont('', 'B', $font_size ? $font_size : 12); |
616 | 616 | $this->MultiTexto($this->getTipo($tipo), $x, null, 'C', $w); |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | if ($tipo) { |
624 | 624 | $this->Texto('S.I.I. - '.\sasco\LibreDTE\Sii::getDireccionRegional($sucursal_sii), $x, $this->getY()+4, 'C', $w); |
625 | 625 | } |
626 | - $this->SetTextColorArray([0,0,0]); |
|
626 | + $this->SetTextColorArray([0, 0, 0]); |
|
627 | 627 | $this->Ln(); |
628 | 628 | return $this->y; |
629 | 629 | } |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | $this->Texto('Señor(es)', $x); |
756 | 756 | $this->Texto(':', $x+$offset); |
757 | 757 | $this->setFont('', '', null); |
758 | - $this->MultiTexto($receptor['RznSocRecep'], $x+$offset+2, null, '', $x==10?105:0); |
|
758 | + $this->MultiTexto($receptor['RznSocRecep'], $x+$offset+2, null, '', $x==10 ? 105 : 0); |
|
759 | 759 | } |
760 | 760 | if (!empty($receptor['GiroRecep'])) { |
761 | 761 | $this->setFont('', 'B', null); |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | $ciudad = !empty($receptor['CiudadRecep']) ? $receptor['CiudadRecep'] : ( |
773 | 773 | !empty($receptor['CmnaRecep']) ? \sasco\LibreDTE\Chile::getCiudad($receptor['CmnaRecep']) : '' |
774 | 774 | ); |
775 | - $this->MultiTexto($receptor['DirRecep'].(!empty($receptor['CmnaRecep'])?(', '.$receptor['CmnaRecep']):'').($ciudad?(', '.$ciudad):''), $x+$offset+2); |
|
775 | + $this->MultiTexto($receptor['DirRecep'].(!empty($receptor['CmnaRecep']) ? (', '.$receptor['CmnaRecep']) : '').($ciudad ? (', '.$ciudad) : ''), $x+$offset+2); |
|
776 | 776 | } |
777 | 777 | if (!empty($receptor['Extranjero']['Nacionalidad'])) { |
778 | 778 | $this->setFont('', 'B', null); |
@@ -813,7 +813,7 @@ discard block |
||
813 | 813 | $this->Texto('Cód. recep.', $x); |
814 | 814 | $this->Texto(':', $x+$offset); |
815 | 815 | $this->setFont('', '', null); |
816 | - $this->MultiTexto($receptor['CdgIntRecep'], $x+$offset+2, null, '', $x==10?105:0); |
|
816 | + $this->MultiTexto($receptor['CdgIntRecep'], $x+$offset+2, null, '', $x==10 ? 105 : 0); |
|
817 | 817 | } |
818 | 818 | return $this->GetY(); |
819 | 819 | } |
@@ -901,7 +901,7 @@ discard block |
||
901 | 901 | { |
902 | 902 | if (!isset($referencias[0])) |
903 | 903 | $referencias = [$referencias]; |
904 | - foreach($referencias as $r) { |
|
904 | + foreach ($referencias as $r) { |
|
905 | 905 | $texto = $r['NroLinRef'].' - '; |
906 | 906 | if (!empty($r['TpoDocRef'])) { |
907 | 907 | $texto .= $this->getTipo($r['TpoDocRef']).' '; |
@@ -952,7 +952,7 @@ discard block |
||
952 | 952 | // quitar columnas |
953 | 953 | foreach ($item as $col => $valor) { |
954 | 954 | if ($col=='DscItem' and !empty($item['DscItem'])) { |
955 | - $item['NmbItem'] .= !$this->item_detalle_posicion ? ($html?'<br/>':"\n") : ': '; |
|
955 | + $item['NmbItem'] .= !$this->item_detalle_posicion ? ($html ? '<br/>' : "\n") : ': '; |
|
956 | 956 | if ($html) { |
957 | 957 | $item['NmbItem'] .= '<span style="font-size:0.7em">'.$item['DscItem'].'</span>'; |
958 | 958 | } else { |
@@ -1012,9 +1012,9 @@ discard block |
||
1012 | 1012 | $this->SetY($this->getY()+1); |
1013 | 1013 | $p1x = $x; |
1014 | 1014 | $p1y = $this->y; |
1015 | - $p2x = $this->getPageWidth() - 2; |
|
1016 | - $p2y = $p1y; // Use same y for a straight line |
|
1017 | - $style = array('width' => 0.2,'color' => array(0, 0, 0)); |
|
1015 | + $p2x = $this->getPageWidth()-2; |
|
1016 | + $p2y = $p1y; // Use same y for a straight line |
|
1017 | + $style = array('width' => 0.2, 'color' => array(0, 0, 0)); |
|
1018 | 1018 | $this->Line($p1x, $p1y, $p2x, $p2y, $style); |
1019 | 1019 | $this->Texto($this->detalle_cols['NmbItem']['title'], $x+1, $this->y, ucfirst($this->detalle_cols['NmbItem']['align'][0]), $this->detalle_cols['NmbItem']['width']); |
1020 | 1020 | $this->Texto($this->detalle_cols['PrcItem']['title'], $x+15, $this->y, ucfirst($this->detalle_cols['PrcItem']['align'][0]), $this->detalle_cols['PrcItem']['width']); |
@@ -1024,9 +1024,9 @@ discard block |
||
1024 | 1024 | if (!isset($detalle[0])) |
1025 | 1025 | $detalle = [$detalle]; |
1026 | 1026 | $this->SetY($this->getY()+2); |
1027 | - foreach($detalle as &$d) { |
|
1027 | + foreach ($detalle as &$d) { |
|
1028 | 1028 | $this->MultiTexto($d['NmbItem'], $x+1, $this->y+4, ucfirst($this->detalle_cols['NmbItem']['align'][0]), $this->detalle_cols['NmbItem']['width']); |
1029 | - $this->Texto(number_format($d['PrcItem'],0,',','.'), $x+15, $this->y, ucfirst($this->detalle_cols['PrcItem']['align'][0]), $this->detalle_cols['PrcItem']['width']); |
|
1029 | + $this->Texto(number_format($d['PrcItem'], 0, ',', '.'), $x+15, $this->y, ucfirst($this->detalle_cols['PrcItem']['align'][0]), $this->detalle_cols['PrcItem']['width']); |
|
1030 | 1030 | $this->Texto($this->num($d['QtyItem']), $x+35, $this->y, ucfirst($this->detalle_cols['QtyItem']['align'][0]), $this->detalle_cols['QtyItem']['width']); |
1031 | 1031 | $this->Texto($this->num($d['MontoItem']), $x+45, $this->y, ucfirst($this->detalle_cols['MontoItem']['align'][0]), $this->detalle_cols['MontoItem']['width']); |
1032 | 1032 | } |
@@ -1046,7 +1046,7 @@ discard block |
||
1046 | 1046 | if (!isset($detalle[0])) { |
1047 | 1047 | $detalle = [$detalle]; |
1048 | 1048 | } |
1049 | - foreach($detalle as &$d) { |
|
1049 | + foreach ($detalle as &$d) { |
|
1050 | 1050 | if (!empty($d['MontoItem'])) { |
1051 | 1051 | $subtotal += $d['MontoItem']; |
1052 | 1052 | } |
@@ -1071,16 +1071,16 @@ discard block |
||
1071 | 1071 | { |
1072 | 1072 | if (!isset($descuentosRecargos[0])) |
1073 | 1073 | $descuentosRecargos = [$descuentosRecargos]; |
1074 | - foreach($descuentosRecargos as $dr) { |
|
1074 | + foreach ($descuentosRecargos as $dr) { |
|
1075 | 1075 | $tipo = $dr['TpoMov']=='D' ? 'Descuento' : 'Recargo'; |
1076 | 1076 | if ($dr['IndExeDR']) { |
1077 | 1077 | $tipo .= ' EX'; |
1078 | 1078 | } |
1079 | 1079 | $valor = $dr['TpoValor']=='%' ? $dr['ValorDR'].'%' : $this->num($dr['ValorDR']); |
1080 | 1080 | if ($this->papelContinuo) { |
1081 | - $this->Texto($tipo.' global: '.$valor.(!empty($dr['GlosaDR'])?(' ('.$dr['GlosaDR'].')'):''), $x); |
|
1081 | + $this->Texto($tipo.' global: '.$valor.(!empty($dr['GlosaDR']) ? (' ('.$dr['GlosaDR'].')') : ''), $x); |
|
1082 | 1082 | } else { |
1083 | - $this->Texto($tipo.(!empty($dr['GlosaDR'])?(' ('.$dr['GlosaDR'].')'):'').':', 77, null, 'R', 100); |
|
1083 | + $this->Texto($tipo.(!empty($dr['GlosaDR']) ? (' ('.$dr['GlosaDR'].')') : '').':', 77, null, 'R', 100); |
|
1084 | 1084 | $this->Texto($valor, 177, null, 'R', 22); |
1085 | 1085 | } |
1086 | 1086 | $this->Ln(); |
@@ -1100,8 +1100,8 @@ discard block |
||
1100 | 1100 | $pagos = [$pagos]; |
1101 | 1101 | $this->Texto('Pago(s) programado(s):', $x); |
1102 | 1102 | $this->Ln(); |
1103 | - foreach($pagos as $p) { |
|
1104 | - $this->Texto(' - '.$this->date($p['FchPago'], false).': $'.$this->num($p['MntPago']).'.-'.(!empty($p['GlosaPagos'])?(' ('.$p['GlosaPagos'].')'):''), $x); |
|
1103 | + foreach ($pagos as $p) { |
|
1104 | + $this->Texto(' - '.$this->date($p['FchPago'], false).': $'.$this->num($p['MntPago']).'.-'.(!empty($p['GlosaPagos']) ? (' ('.$p['GlosaPagos'].')') : ''), $x); |
|
1105 | 1105 | $this->Ln(); |
1106 | 1106 | } |
1107 | 1107 | } |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | if (!isset($ImptoReten[0])) { |
1153 | 1153 | $ImptoReten = [$ImptoReten]; |
1154 | 1154 | } |
1155 | - foreach($ImptoReten as $i) { |
|
1155 | + foreach ($ImptoReten as $i) { |
|
1156 | 1156 | $totales['ImptoReten_'.$i['TipoImp']] = $i['MontoImp']; |
1157 | 1157 | if (!empty($i['TasaImp'])) { |
1158 | 1158 | $glosas['ImptoReten_'.$i['TipoImp']] = \sasco\LibreDTE\Sii\ImpuestosAdicionales::getGlosa($i['TipoImp']).' ('.$i['TasaImp'].'%) $'; |
@@ -1256,7 +1256,7 @@ discard block |
||
1256 | 1256 | 'vpadding' => 0, |
1257 | 1257 | 'module_width' => 1, // width of a single module in points |
1258 | 1258 | 'module_height' => 1, // height of a single module in points |
1259 | - 'fgcolor' => [0,0,0], |
|
1259 | + 'fgcolor' => [0, 0, 0], |
|
1260 | 1260 | 'bgcolor' => false, // [255,255,255] |
1261 | 1261 | 'position' => $this->papelContinuo ? 'C' : 'S', |
1262 | 1262 | ]; |
@@ -1289,7 +1289,7 @@ discard block |
||
1289 | 1289 | protected function agregarAcuseRecibo($x = 83, $y = 190, $w = 60, $h = 40) |
1290 | 1290 | { |
1291 | 1291 | $y = (!$this->papelContinuo and !$this->timbre_pie) ? $this->x_fin_datos : $y; |
1292 | - $this->SetTextColorArray([0,0,0]); |
|
1292 | + $this->SetTextColorArray([0, 0, 0]); |
|
1293 | 1293 | $this->Rect($x, $y, $w, $h, 'D', ['all' => ['width' => 0.1, 'color' => [0, 0, 0]]]); |
1294 | 1294 | $this->setFont('', 'B', 10); |
1295 | 1295 | $this->Texto('Acuse de recibo', $x, $y+1, 'C', $w); |
@@ -1319,9 +1319,9 @@ discard block |
||
1319 | 1319 | */ |
1320 | 1320 | protected function agregarAcuseReciboContinuo($x = 3, $y = null, $w = 68, $h = 40) |
1321 | 1321 | { |
1322 | - $this->SetTextColorArray([0,0,0]); |
|
1322 | + $this->SetTextColorArray([0, 0, 0]); |
|
1323 | 1323 | $this->Rect($x, $y, $w, $h, 'D', ['all' => ['width' => 0.1, 'color' => [0, 0, 0]]]); |
1324 | - $style = array('width' => 0.2,'color' => array(0, 0, 0)); |
|
1324 | + $style = array('width' => 0.2, 'color' => array(0, 0, 0)); |
|
1325 | 1325 | $this->Line($x, $y+22, $w+3, $y+22, $style); |
1326 | 1326 | //$this->setFont('', 'B', 10); |
1327 | 1327 | //$this->Texto('Acuse de recibo', $x, $y+1, 'C', $w); |
@@ -1351,7 +1351,7 @@ discard block |
||
1351 | 1351 | $y = (!$this->papelContinuo and !$this->timbre_pie) ? $this->x_fin_datos : $y; |
1352 | 1352 | $y += 64; |
1353 | 1353 | $this->setFont('', 'B', $font_size); |
1354 | - $this->Texto('CEDIBLE'.($tipo==52?' CON SU FACTURA':''), null, $y, 'R'); |
|
1354 | + $this->Texto('CEDIBLE'.($tipo==52 ? ' CON SU FACTURA' : ''), null, $y, 'R'); |
|
1355 | 1355 | } |
1356 | 1356 | |
1357 | 1357 | /** |
@@ -1362,7 +1362,7 @@ discard block |
||
1362 | 1362 | protected function agregarLeyendaDestinoContinuo($tipo) |
1363 | 1363 | { |
1364 | 1364 | $this->setFont('', 'B', 8); |
1365 | - $this->Texto('CEDIBLE'.($tipo==52?' CON SU FACTURA':''), null, $this->y+6, 'R'); |
|
1365 | + $this->Texto('CEDIBLE'.($tipo==52 ? ' CON SU FACTURA' : ''), null, $this->y+6, 'R'); |
|
1366 | 1366 | } |
1367 | 1367 | |
1368 | 1368 | /** |
@@ -1393,7 +1393,7 @@ discard block |
||
1393 | 1393 | $dias = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado']; |
1394 | 1394 | $meses = ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre']; |
1395 | 1395 | $unixtime = strtotime($date); |
1396 | - $fecha = date(($mostrar_dia?'\D\I\A ':'').'j \d\e \M\E\S \d\e\l Y', $unixtime); |
|
1396 | + $fecha = date(($mostrar_dia ? '\D\I\A ' : '').'j \d\e \M\E\S \d\e\l Y', $unixtime); |
|
1397 | 1397 | $dia = $dias[date('w', $unixtime)]; |
1398 | 1398 | $mes = $meses[date('n', $unixtime)-1]; |
1399 | 1399 | return str_replace(array('DIA', 'MES'), array($dia, $mes), $fecha); |
@@ -567,10 +567,12 @@ discard block |
||
567 | 567 | } |
568 | 568 | $contacto = []; |
569 | 569 | if (!empty($emisor['Telefono'])) { |
570 | - if (!is_array($emisor['Telefono'])) |
|
571 | - $emisor['Telefono'] = [$emisor['Telefono']]; |
|
572 | - foreach ($emisor['Telefono'] as $t) |
|
573 | - $contacto[] = $t; |
|
570 | + if (!is_array($emisor['Telefono'])) { |
|
571 | + $emisor['Telefono'] = [$emisor['Telefono']]; |
|
572 | + } |
|
573 | + foreach ($emisor['Telefono'] as $t) { |
|
574 | + $contacto[] = $t; |
|
575 | + } |
|
574 | 576 | } |
575 | 577 | if (!empty($emisor['CorreoEmisor'])) { |
576 | 578 | $contacto[] = $emisor['CorreoEmisor']; |
@@ -789,10 +791,12 @@ discard block |
||
789 | 791 | $this->MultiTexto($receptor['Extranjero']['NumId'], $x+$offset+2); |
790 | 792 | } |
791 | 793 | $contacto = []; |
792 | - if (!empty($receptor['Contacto'])) |
|
793 | - $contacto[] = $receptor['Contacto']; |
|
794 | - if (!empty($receptor['CorreoRecep'])) |
|
795 | - $contacto[] = $receptor['CorreoRecep']; |
|
794 | + if (!empty($receptor['Contacto'])) { |
|
795 | + $contacto[] = $receptor['Contacto']; |
|
796 | + } |
|
797 | + if (!empty($receptor['CorreoRecep'])) { |
|
798 | + $contacto[] = $receptor['CorreoRecep']; |
|
799 | + } |
|
796 | 800 | if (!empty($contacto)) { |
797 | 801 | $this->setFont('', 'B', null); |
798 | 802 | $this->Texto('Contacto', $x); |
@@ -842,15 +846,19 @@ discard block |
||
842 | 846 | if (!empty($Transporte['DirDest']) and !empty($Transporte['CmnaDest'])) { |
843 | 847 | $transporte .= 'a '.$Transporte['DirDest'].', '.$Transporte['CmnaDest']; |
844 | 848 | } |
845 | - if (!empty($Transporte['RUTTrans'])) |
|
846 | - $transporte .= ' por '.$Transporte['RUTTrans']; |
|
847 | - if (!empty($Transporte['Patente'])) |
|
848 | - $transporte .= ' en vehículo '.$Transporte['Patente']; |
|
849 | + if (!empty($Transporte['RUTTrans'])) { |
|
850 | + $transporte .= ' por '.$Transporte['RUTTrans']; |
|
851 | + } |
|
852 | + if (!empty($Transporte['Patente'])) { |
|
853 | + $transporte .= ' en vehículo '.$Transporte['Patente']; |
|
854 | + } |
|
849 | 855 | if (isset($Transporte['Chofer']) and is_array($Transporte['Chofer'])) { |
850 | - if (!empty($Transporte['Chofer']['NombreChofer'])) |
|
851 | - $transporte .= ' con chofer '.$Transporte['Chofer']['NombreChofer']; |
|
852 | - if (!empty($Transporte['Chofer']['RUTChofer'])) |
|
853 | - $transporte .= ' ('.$Transporte['Chofer']['RUTChofer'].')'; |
|
856 | + if (!empty($Transporte['Chofer']['NombreChofer'])) { |
|
857 | + $transporte .= ' con chofer '.$Transporte['Chofer']['NombreChofer']; |
|
858 | + } |
|
859 | + if (!empty($Transporte['Chofer']['RUTChofer'])) { |
|
860 | + $transporte .= ' ('.$Transporte['Chofer']['RUTChofer'].')'; |
|
861 | + } |
|
854 | 862 | } |
855 | 863 | if ($transporte) { |
856 | 864 | $this->setFont('', 'B', null); |
@@ -864,8 +872,9 @@ discard block |
||
864 | 872 | if (!empty($Transporte['Aduana']) and is_array($Transporte['Aduana'])) { |
865 | 873 | $col = 0; |
866 | 874 | foreach ($Transporte['Aduana'] as $tag => $codigo) { |
867 | - if ($codigo===false) |
|
868 | - continue; |
|
875 | + if ($codigo===false) { |
|
876 | + continue; |
|
877 | + } |
|
869 | 878 | $glosa = \sasco\LibreDTE\Sii\Aduana::getGlosa($tag); |
870 | 879 | $valor = \sasco\LibreDTE\Sii\Aduana::getValor($tag, $codigo); |
871 | 880 | if ($glosa!==false and $valor!==false) { |
@@ -878,15 +887,18 @@ discard block |
||
878 | 887 | $this->Texto(':', $x+$offset+$col); |
879 | 888 | $this->setFont('', '', null); |
880 | 889 | $this->Texto($valor, $x+$offset+2+$col); |
881 | - if ($tag=='TipoBultos') |
|
882 | - $col = abs($col-110); |
|
883 | - if ($col) |
|
884 | - $this->Ln(); |
|
890 | + if ($tag=='TipoBultos') { |
|
891 | + $col = abs($col-110); |
|
892 | + } |
|
893 | + if ($col) { |
|
894 | + $this->Ln(); |
|
895 | + } |
|
885 | 896 | $col = abs($col-110); |
886 | 897 | } |
887 | 898 | } |
888 | - if ($col) |
|
889 | - $this->Ln(); |
|
899 | + if ($col) { |
|
900 | + $this->Ln(); |
|
901 | + } |
|
890 | 902 | } |
891 | 903 | } |
892 | 904 | |
@@ -899,8 +911,9 @@ discard block |
||
899 | 911 | */ |
900 | 912 | protected function agregarReferencia($referencias, $x = 10, $offset = 22) |
901 | 913 | { |
902 | - if (!isset($referencias[0])) |
|
903 | - $referencias = [$referencias]; |
|
914 | + if (!isset($referencias[0])) { |
|
915 | + $referencias = [$referencias]; |
|
916 | + } |
|
904 | 917 | foreach($referencias as $r) { |
905 | 918 | $texto = $r['NroLinRef'].' - '; |
906 | 919 | if (!empty($r['TpoDocRef'])) { |
@@ -937,8 +950,9 @@ discard block |
||
937 | 950 | */ |
938 | 951 | protected function agregarDetalle($detalle, $x = 10, $html = true) |
939 | 952 | { |
940 | - if (!isset($detalle[0])) |
|
941 | - $detalle = [$detalle]; |
|
953 | + if (!isset($detalle[0])) { |
|
954 | + $detalle = [$detalle]; |
|
955 | + } |
|
942 | 956 | $this->setFont('', '', $this->detalle_fuente); |
943 | 957 | // titulos |
944 | 958 | $titulos = []; |
@@ -959,36 +973,42 @@ discard block |
||
959 | 973 | $item['NmbItem'] .= $item['DscItem']; |
960 | 974 | } |
961 | 975 | } |
962 | - if (!in_array($col, $titulos_keys) or ($dte_exento and $col=='IndExe')) |
|
963 | - unset($item[$col]); |
|
976 | + if (!in_array($col, $titulos_keys) or ($dte_exento and $col=='IndExe')) { |
|
977 | + unset($item[$col]); |
|
978 | + } |
|
964 | 979 | } |
965 | 980 | // ajustes a IndExe |
966 | 981 | if (isset($item['IndExe'])) { |
967 | - if ($item['IndExe']==1) |
|
968 | - $item['IndExe'] = 'EX'; |
|
969 | - else if ($item['IndExe']==2) |
|
970 | - $item['IndExe'] = 'NF'; |
|
982 | + if ($item['IndExe']==1) { |
|
983 | + $item['IndExe'] = 'EX'; |
|
984 | + } else if ($item['IndExe']==2) { |
|
985 | + $item['IndExe'] = 'NF'; |
|
986 | + } |
|
971 | 987 | } |
972 | 988 | // agregar todas las columnas que se podrían imprimir en la tabla |
973 | 989 | $item_default = []; |
974 | - foreach ($this->detalle_cols as $key => $info) |
|
975 | - $item_default[$key] = false; |
|
990 | + foreach ($this->detalle_cols as $key => $info) { |
|
991 | + $item_default[$key] = false; |
|
992 | + } |
|
976 | 993 | $item = array_merge($item_default, $item); |
977 | 994 | // si hay código de item se extrae su valor |
978 | - if ($item['CdgItem']) |
|
979 | - $item['CdgItem'] = $item['CdgItem']['VlrCodigo']; |
|
995 | + if ($item['CdgItem']) { |
|
996 | + $item['CdgItem'] = $item['CdgItem']['VlrCodigo']; |
|
997 | + } |
|
980 | 998 | // dar formato a números |
981 | 999 | foreach (['QtyItem', 'PrcItem', 'DescuentoMonto', 'RecargoMonto', 'MontoItem'] as $col) { |
982 | - if ($item[$col]) |
|
983 | - $item[$col] = $this->num($item[$col]); |
|
1000 | + if ($item[$col]) { |
|
1001 | + $item[$col] = $this->num($item[$col]); |
|
1002 | + } |
|
984 | 1003 | } |
985 | 1004 | } |
986 | 1005 | // opciones |
987 | 1006 | $options = ['align'=>[]]; |
988 | 1007 | $i = 0; |
989 | 1008 | foreach ($this->detalle_cols as $info) { |
990 | - if (isset($info['width'])) |
|
991 | - $options['width'][$i] = $info['width']; |
|
1009 | + if (isset($info['width'])) { |
|
1010 | + $options['width'][$i] = $info['width']; |
|
1011 | + } |
|
992 | 1012 | $options['align'][$i] = $info['align']; |
993 | 1013 | $i++; |
994 | 1014 | } |
@@ -1021,8 +1041,9 @@ discard block |
||
1021 | 1041 | $this->Texto($this->detalle_cols['QtyItem']['title'], $x+35, $this->y, ucfirst($this->detalle_cols['QtyItem']['align'][0]), $this->detalle_cols['QtyItem']['width']); |
1022 | 1042 | $this->Texto($this->detalle_cols['MontoItem']['title'], $x+45, $this->y, ucfirst($this->detalle_cols['MontoItem']['align'][0]), $this->detalle_cols['MontoItem']['width']); |
1023 | 1043 | $this->Line($p1x, $p1y+4, $p2x, $p2y+4, $style); |
1024 | - if (!isset($detalle[0])) |
|
1025 | - $detalle = [$detalle]; |
|
1044 | + if (!isset($detalle[0])) { |
|
1045 | + $detalle = [$detalle]; |
|
1046 | + } |
|
1026 | 1047 | $this->SetY($this->getY()+2); |
1027 | 1048 | foreach($detalle as &$d) { |
1028 | 1049 | $this->MultiTexto($d['NmbItem'], $x+1, $this->y+4, ucfirst($this->detalle_cols['NmbItem']['align'][0]), $this->detalle_cols['NmbItem']['width']); |
@@ -1069,8 +1090,9 @@ discard block |
||
1069 | 1090 | */ |
1070 | 1091 | protected function agregarDescuentosRecargos(array $descuentosRecargos, $x = 10) |
1071 | 1092 | { |
1072 | - if (!isset($descuentosRecargos[0])) |
|
1073 | - $descuentosRecargos = [$descuentosRecargos]; |
|
1093 | + if (!isset($descuentosRecargos[0])) { |
|
1094 | + $descuentosRecargos = [$descuentosRecargos]; |
|
1095 | + } |
|
1074 | 1096 | foreach($descuentosRecargos as $dr) { |
1075 | 1097 | $tipo = $dr['TpoMov']=='D' ? 'Descuento' : 'Recargo'; |
1076 | 1098 | if ($dr['IndExeDR']) { |
@@ -1096,8 +1118,9 @@ discard block |
||
1096 | 1118 | */ |
1097 | 1119 | protected function agregarPagos(array $pagos, $x = 10) |
1098 | 1120 | { |
1099 | - if (!isset($pagos[0])) |
|
1100 | - $pagos = [$pagos]; |
|
1121 | + if (!isset($pagos[0])) { |
|
1122 | + $pagos = [$pagos]; |
|
1123 | + } |
|
1101 | 1124 | $this->Texto('Pago(s) programado(s):', $x); |
1102 | 1125 | $this->Ln(); |
1103 | 1126 | foreach($pagos as $p) { |
@@ -1375,11 +1398,13 @@ discard block |
||
1375 | 1398 | */ |
1376 | 1399 | protected function num($n) |
1377 | 1400 | { |
1378 | - if (!is_numeric($n)) |
|
1379 | - return $n; |
|
1401 | + if (!is_numeric($n)) { |
|
1402 | + return $n; |
|
1403 | + } |
|
1380 | 1404 | $broken_number = explode('.', (string)$n); |
1381 | - if (isset($broken_number[1])) |
|
1382 | - return number_format($broken_number[0], 0, ',', '.').','.$broken_number[1]; |
|
1405 | + if (isset($broken_number[1])) { |
|
1406 | + return number_format($broken_number[0], 0, ',', '.').','.$broken_number[1]; |
|
1407 | + } |
|
1383 | 1408 | return number_format($broken_number[0], 0, ',', '.'); |
1384 | 1409 | } |
1385 | 1410 |