@@ -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 | /** |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | return true; |
277 | 277 | } |
278 | 278 | $fecha_autorizacion = $this->getFechaAutorizacion(); |
279 | - $vigencia = $fecha_autorizacion >= '2018-07-01' ? 6 : 18; |
|
279 | + $vigencia = $fecha_autorizacion>='2018-07-01' ? 6 : 18; |
|
280 | 280 | $d1 = new \DateTime($fecha_autorizacion); |
281 | 281 | $d2 = new \DateTime(date('Y-m-d')); |
282 | - $meses = $d1->diff($d2)->m + ($d1->diff($d2)->y*12); |
|
283 | - return $meses <= $vigencia; |
|
282 | + $meses = $d1->diff($d2)->m+($d1->diff($d2)->y * 12); |
|
283 | + return $meses<=$vigencia; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
@@ -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(); |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | /** |
189 | 189 | * Método que asigna la ubicación del logo de la empresa |
190 | 190 | * @param logo URI del logo (puede ser local o en una URL) |
191 | - * @param posicion Posición respecto a datos del emisor (=0 izq, =1 arriba) |
|
191 | + * @param posicion integer respecto a datos del emisor (=0 izq, =1 arriba) |
|
192 | 192 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
193 | 193 | * @version 2016-08-04 |
194 | 194 | */ |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | * contínuo |
379 | 379 | * @param dte Arreglo con los datos del XML (tag Documento) |
380 | 380 | * @param timbre String XML con el tag TED del DTE |
381 | - * @param width Ancho del papel contínuo en mm |
|
381 | + * @param width boolean del papel contínuo en mm |
|
382 | 382 | * @author Pablo Reyes (https://github.com/pabloxp) |
383 | 383 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
384 | 384 | * @version 2017-10-24 |
@@ -537,10 +537,11 @@ discard block |
||
537 | 537 | * - Dirección casa central del emisor |
538 | 538 | * - Dirección sucursales |
539 | 539 | * @param emisor Arreglo con los datos del emisor (tag Emisor del XML) |
540 | - * @param x Posición horizontal de inicio en el PDF |
|
541 | - * @param y Posición vertical de inicio en el PDF |
|
542 | - * @param w Ancho de la información del emisor |
|
543 | - * @param w_img Ancho máximo de la imagen |
|
540 | + * @param x integer horizontal de inicio en el PDF |
|
541 | + * @param y integer vertical de inicio en el PDF |
|
542 | + * @param w integer de la información del emisor |
|
543 | + * @param w_img integer máximo de la imagen |
|
544 | + * @param integer $font_size |
|
544 | 545 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
545 | 546 | * @version 2018-06-15 |
546 | 547 | */ |
@@ -614,11 +615,13 @@ discard block |
||
614 | 615 | * @param rut RUT del emisor |
615 | 616 | * @param tipo Código o glosa del tipo de documento |
616 | 617 | * @param sucursal_sii Código o glosa de la sucursal del SII del Emisor |
617 | - * @param x Posición horizontal de inicio en el PDF |
|
618 | - * @param y Posición vertical de inicio en el PDF |
|
619 | - * @param w Ancho de la información del emisor |
|
618 | + * @param x integer horizontal de inicio en el PDF |
|
619 | + * @param y integer vertical de inicio en el PDF |
|
620 | + * @param w integer de la información del emisor |
|
621 | + * @param integer $font_size |
|
620 | 622 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
621 | 623 | * @version 2016-12-02 |
624 | + * @return integer |
|
622 | 625 | */ |
623 | 626 | protected function agregarFolio($rut, $tipo, $folio, $sucursal_sii = null, $x = 130, $y = 15, $w = 70, $font_size = null, array $color = null) |
624 | 627 | { |
@@ -665,7 +668,7 @@ discard block |
||
665 | 668 | * Método que agrega los datos de la emisión del DTE que no son los dato del |
666 | 669 | * receptor |
667 | 670 | * @param IdDoc Información general del documento |
668 | - * @param x Posición horizontal de inicio en el PDF |
|
671 | + * @param x integer horizontal de inicio en el PDF |
|
669 | 672 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
670 | 673 | * @version 2017-06-15 |
671 | 674 | */ |
@@ -753,7 +756,7 @@ discard block |
||
753 | 756 | /** |
754 | 757 | * Método que agrega los datos del receptor |
755 | 758 | * @param receptor Arreglo con los datos del receptor (tag Receptor del XML) |
756 | - * @param x Posición horizontal de inicio en el PDF |
|
759 | + * @param x integer horizontal de inicio en el PDF |
|
757 | 760 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
758 | 761 | * @version 2017-06-15 |
759 | 762 | */ |
@@ -840,7 +843,7 @@ discard block |
||
840 | 843 | * Método que agrega los datos del traslado |
841 | 844 | * @param IndTraslado |
842 | 845 | * @param Transporte |
843 | - * @param x Posición horizontal de inicio en el PDF |
|
846 | + * @param x integer horizontal de inicio en el PDF |
|
844 | 847 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
845 | 848 | * @version 2016-08-03 |
846 | 849 | */ |
@@ -911,7 +914,7 @@ discard block |
||
911 | 914 | /** |
912 | 915 | * Método que agrega las referencias del documento |
913 | 916 | * @param referencias Arreglo con las referencias del documento (tag Referencia del XML) |
914 | - * @param x Posición horizontal de inicio en el PDF |
|
917 | + * @param x integer horizontal de inicio en el PDF |
|
915 | 918 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
916 | 919 | * @version 2017-09-25 |
917 | 920 | */ |
@@ -948,7 +951,7 @@ discard block |
||
948 | 951 | /** |
949 | 952 | * Método que agrega el detalle del documento |
950 | 953 | * @param detalle Arreglo con el detalle del documento (tag Detalle del XML) |
951 | - * @param x Posición horizontal de inicio en el PDF |
|
954 | + * @param x integer horizontal de inicio en el PDF |
|
952 | 955 | * @param y Posición vertical de inicio en el PDF |
953 | 956 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
954 | 957 | * @version 2018-04-15 |
@@ -1019,7 +1022,7 @@ discard block |
||
1019 | 1022 | /** |
1020 | 1023 | * Método que agrega el detalle del documento |
1021 | 1024 | * @param detalle Arreglo con el detalle del documento (tag Detalle del XML) |
1022 | - * @param x Posición horizontal de inicio en el PDF |
|
1025 | + * @param x integer horizontal de inicio en el PDF |
|
1023 | 1026 | * @param y Posición vertical de inicio en el PDF |
1024 | 1027 | * @author Pablo Reyes (https://github.com/pabloxp) |
1025 | 1028 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
@@ -1055,7 +1058,7 @@ discard block |
||
1055 | 1058 | * Método que agrega el subtotal del DTE |
1056 | 1059 | * @param detalle Arreglo con los detalles del documentos para poder |
1057 | 1060 | * calcular subtotal |
1058 | - * @param x Posición horizontal de inicio en el PDF |
|
1061 | + * @param x integer horizontal de inicio en el PDF |
|
1059 | 1062 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
1060 | 1063 | * @version 2016-08-17 |
1061 | 1064 | */ |
@@ -1081,7 +1084,7 @@ discard block |
||
1081 | 1084 | /** |
1082 | 1085 | * Método que agrega los descuentos y/o recargos globales del documento |
1083 | 1086 | * @param descuentosRecargos Arreglo con los descuentos y/o recargos del documento (tag DscRcgGlobal del XML) |
1084 | - * @param x Posición horizontal de inicio en el PDF |
|
1087 | + * @param x integer horizontal de inicio en el PDF |
|
1085 | 1088 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
1086 | 1089 | * @version 2018-05-29 |
1087 | 1090 | */ |
@@ -1109,7 +1112,7 @@ discard block |
||
1109 | 1112 | /** |
1110 | 1113 | * Método que agrega los pagos del documento |
1111 | 1114 | * @param pagos Arreglo con los pagos del documento |
1112 | - * @param x Posición horizontal de inicio en el PDF |
|
1115 | + * @param x integer horizontal de inicio en el PDF |
|
1113 | 1116 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
1114 | 1117 | * @version 2016-07-24 |
1115 | 1118 | */ |
@@ -1267,9 +1270,9 @@ discard block |
||
1267 | 1270 | * - Se imprime en el tamaño mínimo: 2x5 cms |
1268 | 1271 | * - En el lado de abajo con margen izquierdo mínimo de 2 cms |
1269 | 1272 | * @param timbre String con los datos del timbre |
1270 | - * @param x Posición horizontal de inicio en el PDF |
|
1271 | - * @param y Posición vertical de inicio en el PDF |
|
1272 | - * @param w Ancho del timbre |
|
1273 | + * @param x integer horizontal de inicio en el PDF |
|
1274 | + * @param y integer vertical de inicio en el PDF |
|
1275 | + * @param w integer del timbre |
|
1273 | 1276 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
1274 | 1277 | * @version 2018-04-12 |
1275 | 1278 | */ |
@@ -1307,10 +1310,10 @@ discard block |
||
1307 | 1310 | |
1308 | 1311 | /** |
1309 | 1312 | * Método que agrega el acuse de rebido |
1310 | - * @param x Posición horizontal de inicio en el PDF |
|
1311 | - * @param y Posición vertical de inicio en el PDF |
|
1312 | - * @param w Ancho del acuse de recibo |
|
1313 | - * @param h Alto del acuse de recibo |
|
1313 | + * @param x integer horizontal de inicio en el PDF |
|
1314 | + * @param y integer vertical de inicio en el PDF |
|
1315 | + * @param w integer del acuse de recibo |
|
1316 | + * @param h integer del acuse de recibo |
|
1314 | 1317 | * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl) |
1315 | 1318 | * @version 2018-04-13 |
1316 | 1319 | */ |
@@ -1338,10 +1341,10 @@ discard block |
||
1338 | 1341 | |
1339 | 1342 | /** |
1340 | 1343 | * Método que agrega el acuse de rebido |
1341 | - * @param x Posición horizontal de inicio en el PDF |
|
1344 | + * @param x integer horizontal de inicio en el PDF |
|
1342 | 1345 | * @param y Posición vertical de inicio en el PDF |
1343 | - * @param w Ancho del acuse de recibo |
|
1344 | - * @param h Alto del acuse de recibo |
|
1346 | + * @param w integer del acuse de recibo |
|
1347 | + * @param h integer del acuse de recibo |
|
1345 | 1348 | * @author Pablo Reyes (https://github.com/pabloxp) |
1346 | 1349 | * @version 2015-11-17 |
1347 | 1350 | */ |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | { |
183 | 183 | parent::__construct(); |
184 | 184 | $this->SetTitle('Documento Tributario Electrónico (DTE) de Chile by LibreDTE'); |
185 | - $this->papelContinuo = $papelContinuo === true ? 80 : $papelContinuo; |
|
185 | + $this->papelContinuo = $papelContinuo===true ? 80 : $papelContinuo; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | $this->setY(max($y)); |
339 | 339 | $this->Ln(); |
340 | 340 | $y = []; |
341 | - $y[] = $this->agregarDatosEmision($dte['Encabezado']['IdDoc'], !empty($dte['Encabezado']['Emisor']['CdgVendedor'])?$dte['Encabezado']['Emisor']['CdgVendedor']:null); |
|
341 | + $y[] = $this->agregarDatosEmision($dte['Encabezado']['IdDoc'], !empty($dte['Encabezado']['Emisor']['CdgVendedor']) ? $dte['Encabezado']['Emisor']['CdgVendedor'] : null); |
|
342 | 342 | $y[] = $this->agregarReceptor($dte['Encabezado']); |
343 | 343 | $this->setY(max($y)); |
344 | 344 | $this->agregarTraslado( |
@@ -398,15 +398,15 @@ discard block |
||
398 | 398 | $dte['Encabezado']['IdDoc']['TipoDTE'], |
399 | 399 | $dte['Encabezado']['IdDoc']['Folio'], |
400 | 400 | $dte['Encabezado']['Emisor']['CmnaOrigen'], |
401 | - $x_start, $y_start, $width-($x_start*4), 10, |
|
402 | - [0,0,0] |
|
401 | + $x_start, $y_start, $width-($x_start * 4), 10, |
|
402 | + [0, 0, 0] |
|
403 | 403 | ); |
404 | - $y = $this->agregarEmisor($dte['Encabezado']['Emisor'], $x_start, $y+2, $width-($x_start*45), 8, 9, [0,0,0]); |
|
404 | + $y = $this->agregarEmisor($dte['Encabezado']['Emisor'], $x_start, $y+2, $width-($x_start * 45), 8, 9, [0, 0, 0]); |
|
405 | 405 | // datos del documento |
406 | 406 | $this->SetY($y); |
407 | 407 | $this->Ln(); |
408 | 408 | $this->setFont('', '', 8); |
409 | - $this->agregarDatosEmision($dte['Encabezado']['IdDoc'], !empty($dte['Encabezado']['Emisor']['CdgVendedor'])?$dte['Encabezado']['Emisor']['CdgVendedor']:null, $x_start, $offset, false); |
|
409 | + $this->agregarDatosEmision($dte['Encabezado']['IdDoc'], !empty($dte['Encabezado']['Emisor']['CdgVendedor']) ? $dte['Encabezado']['Emisor']['CdgVendedor'] : null, $x_start, $offset, false); |
|
410 | 410 | $this->agregarReceptor($dte['Encabezado'], $x_start, $offset); |
411 | 411 | $this->agregarTraslado( |
412 | 412 | !empty($dte['Encabezado']['IdDoc']['IndTraslado']) ? $dte['Encabezado']['IdDoc']['IndTraslado'] : null, |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | $this->AddPage('P', [$height ? $height : $this->papel_continuo_alto, $width]); |
460 | 460 | $x = 1; |
461 | 461 | $y = 5; |
462 | - $this->SetXY($x,$y); |
|
462 | + $this->SetXY($x, $y); |
|
463 | 463 | // agregar datos del documento |
464 | 464 | $this->setFont('', '', 8); |
465 | 465 | $this->MultiTexto(!empty($dte['Encabezado']['Emisor']['RznSoc']) ? $dte['Encabezado']['Emisor']['RznSoc'] : $dte['Encabezado']['Emisor']['RznSocEmisor'], $x, null, '', $width-2); |
@@ -552,13 +552,13 @@ discard block |
||
552 | 552 | $this->logo['uri'], |
553 | 553 | $x, |
554 | 554 | $y, |
555 | - !$this->logo['posicion']?$w_img:null, $this->logo['posicion']?($w_img/2):null, |
|
555 | + !$this->logo['posicion'] ? $w_img : null, $this->logo['posicion'] ? ($w_img / 2) : null, |
|
556 | 556 | 'PNG', |
557 | - (isset($emisor['url'])?$emisor['url']:''), |
|
557 | + (isset($emisor['url']) ? $emisor['url'] : ''), |
|
558 | 558 | 'T' |
559 | 559 | ); |
560 | 560 | if ($this->logo['posicion']) { |
561 | - $this->SetY($this->y + ($w_img/2)); |
|
561 | + $this->SetY($this->y+($w_img / 2)); |
|
562 | 562 | $w += 40; |
563 | 563 | } else { |
564 | 564 | $x = $this->x+3; |
@@ -569,14 +569,14 @@ discard block |
||
569 | 569 | } |
570 | 570 | // agregar datos del emisor |
571 | 571 | $this->setFont('', 'B', $font_size ? $font_size : 14); |
572 | - $this->SetTextColorArray($color===null?[32, 92, 144]:$color); |
|
572 | + $this->SetTextColorArray($color===null ? [32, 92, 144] : $color); |
|
573 | 573 | $this->MultiTexto(!empty($emisor['RznSoc']) ? $emisor['RznSoc'] : $emisor['RznSocEmisor'], $x, $this->y+2, 'L', $w); |
574 | 574 | $this->setFont('', 'B', $font_size ? $font_size : 9); |
575 | - $this->SetTextColorArray([0,0,0]); |
|
575 | + $this->SetTextColorArray([0, 0, 0]); |
|
576 | 576 | $this->MultiTexto(!empty($emisor['GiroEmis']) ? $emisor['GiroEmis'] : $emisor['GiroEmisor'], $x, $this->y, 'L', $w); |
577 | 577 | $comuna = !empty($emisor['CmnaOrigen']) ? $emisor['CmnaOrigen'] : null; |
578 | 578 | $ciudad = !empty($emisor['CiudadOrigen']) ? $emisor['CiudadOrigen'] : \sasco\LibreDTE\Chile::getCiudad($comuna); |
579 | - $this->MultiTexto($emisor['DirOrigen'].($comuna?(', '.$comuna):'').($ciudad?(', '.$ciudad):''), $x, $this->y, 'L', $w); |
|
579 | + $this->MultiTexto($emisor['DirOrigen'].($comuna ? (', '.$comuna) : '').($ciudad ? (', '.$ciudad) : ''), $x, $this->y, 'L', $w); |
|
580 | 580 | if (!empty($emisor['Sucursal'])) { |
581 | 581 | $this->MultiTexto('Sucursal: '.$emisor['Sucursal'], $x, $this->y, 'L', $w); |
582 | 582 | } |
@@ -623,12 +623,12 @@ discard block |
||
623 | 623 | protected function agregarFolio($rut, $tipo, $folio, $sucursal_sii = null, $x = 130, $y = 15, $w = 70, $font_size = null, array $color = null) |
624 | 624 | { |
625 | 625 | if ($color===null) { |
626 | - $color = $tipo ? ($tipo==52 ? [0,172,140] : [255,0,0]) : [0,0,0]; |
|
626 | + $color = $tipo ? ($tipo==52 ? [0, 172, 140] : [255, 0, 0]) : [0, 0, 0]; |
|
627 | 627 | } |
628 | 628 | $this->SetTextColorArray($color); |
629 | 629 | // colocar rut emisor, glosa documento y folio |
630 | 630 | list($rut, $dv) = explode('-', $rut); |
631 | - $this->setFont ('', 'B', $font_size ? $font_size : 15); |
|
631 | + $this->setFont('', 'B', $font_size ? $font_size : 15); |
|
632 | 632 | $this->MultiTexto('R.U.T.: '.$this->num($rut).'-'.$dv, $x, $y+4, 'C', $w); |
633 | 633 | $this->setFont('', 'B', $font_size ? $font_size : 12); |
634 | 634 | $this->MultiTexto($this->getTipo($tipo), $x, null, 'C', $w); |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | if ($tipo) { |
642 | 642 | $this->Texto('S.I.I. - '.\sasco\LibreDTE\Sii::getDireccionRegional($sucursal_sii), $x, $this->getY()+4, 'C', $w); |
643 | 643 | } |
644 | - $this->SetTextColorArray([0,0,0]); |
|
644 | + $this->SetTextColorArray([0, 0, 0]); |
|
645 | 645 | $this->Ln(); |
646 | 646 | return $this->y; |
647 | 647 | } |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | $this->Texto('Señor(es)', $x); |
774 | 774 | $this->Texto(':', $x+$offset); |
775 | 775 | $this->setFont('', '', null); |
776 | - $this->MultiTexto($receptor['RznSocRecep'], $x+$offset+2, null, '', $x==10?105:0); |
|
776 | + $this->MultiTexto($receptor['RznSocRecep'], $x+$offset+2, null, '', $x==10 ? 105 : 0); |
|
777 | 777 | } |
778 | 778 | if (!empty($receptor['GiroRecep'])) { |
779 | 779 | $this->setFont('', 'B', null); |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | $ciudad = !empty($receptor['CiudadRecep']) ? $receptor['CiudadRecep'] : ( |
791 | 791 | !empty($receptor['CmnaRecep']) ? \sasco\LibreDTE\Chile::getCiudad($receptor['CmnaRecep']) : '' |
792 | 792 | ); |
793 | - $this->MultiTexto($receptor['DirRecep'].(!empty($receptor['CmnaRecep'])?(', '.$receptor['CmnaRecep']):'').($ciudad?(', '.$ciudad):''), $x+$offset+2); |
|
793 | + $this->MultiTexto($receptor['DirRecep'].(!empty($receptor['CmnaRecep']) ? (', '.$receptor['CmnaRecep']) : '').($ciudad ? (', '.$ciudad) : ''), $x+$offset+2); |
|
794 | 794 | } |
795 | 795 | if (!empty($receptor['Extranjero']['Nacionalidad'])) { |
796 | 796 | $this->setFont('', 'B', null); |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | $this->Texto('Cód. recep.', $x); |
832 | 832 | $this->Texto(':', $x+$offset); |
833 | 833 | $this->setFont('', '', null); |
834 | - $this->MultiTexto($receptor['CdgIntRecep'], $x+$offset+2, null, '', $x==10?105:0); |
|
834 | + $this->MultiTexto($receptor['CdgIntRecep'], $x+$offset+2, null, '', $x==10 ? 105 : 0); |
|
835 | 835 | } |
836 | 836 | return $this->GetY(); |
837 | 837 | } |
@@ -919,7 +919,7 @@ discard block |
||
919 | 919 | { |
920 | 920 | if (!isset($referencias[0])) |
921 | 921 | $referencias = [$referencias]; |
922 | - foreach($referencias as $r) { |
|
922 | + foreach ($referencias as $r) { |
|
923 | 923 | $texto = $r['NroLinRef'].' - '; |
924 | 924 | if (!empty($r['TpoDocRef'])) { |
925 | 925 | $texto .= $this->getTipo($r['TpoDocRef']).' '; |
@@ -970,7 +970,7 @@ discard block |
||
970 | 970 | // quitar columnas |
971 | 971 | foreach ($item as $col => $valor) { |
972 | 972 | if ($col=='DscItem' and !empty($item['DscItem'])) { |
973 | - $item['NmbItem'] .= !$this->item_detalle_posicion ? ($html?'<br/>':"\n") : ': '; |
|
973 | + $item['NmbItem'] .= !$this->item_detalle_posicion ? ($html ? '<br/>' : "\n") : ': '; |
|
974 | 974 | if ($html) { |
975 | 975 | $item['NmbItem'] .= '<span style="font-size:0.7em">'.$item['DscItem'].'</span>'; |
976 | 976 | } else { |
@@ -1030,9 +1030,9 @@ discard block |
||
1030 | 1030 | $this->SetY($this->getY()+1); |
1031 | 1031 | $p1x = $x; |
1032 | 1032 | $p1y = $this->y; |
1033 | - $p2x = $this->getPageWidth() - 2; |
|
1034 | - $p2y = $p1y; // Use same y for a straight line |
|
1035 | - $style = array('width' => 0.2,'color' => array(0, 0, 0)); |
|
1033 | + $p2x = $this->getPageWidth()-2; |
|
1034 | + $p2y = $p1y; // Use same y for a straight line |
|
1035 | + $style = array('width' => 0.2, 'color' => array(0, 0, 0)); |
|
1036 | 1036 | $this->Line($p1x, $p1y, $p2x, $p2y, $style); |
1037 | 1037 | $this->Texto($this->detalle_cols['NmbItem']['title'], $x+1, $this->y, ucfirst($this->detalle_cols['NmbItem']['align'][0]), $this->detalle_cols['NmbItem']['width']); |
1038 | 1038 | $this->Texto($this->detalle_cols['PrcItem']['title'], $x+15, $this->y, ucfirst($this->detalle_cols['PrcItem']['align'][0]), $this->detalle_cols['PrcItem']['width']); |
@@ -1042,9 +1042,9 @@ discard block |
||
1042 | 1042 | if (!isset($detalle[0])) |
1043 | 1043 | $detalle = [$detalle]; |
1044 | 1044 | $this->SetY($this->getY()+2); |
1045 | - foreach($detalle as &$d) { |
|
1045 | + foreach ($detalle as &$d) { |
|
1046 | 1046 | $this->MultiTexto($d['NmbItem'], $x+1, $this->y+4, ucfirst($this->detalle_cols['NmbItem']['align'][0]), $this->detalle_cols['NmbItem']['width']); |
1047 | - $this->Texto(number_format($d['PrcItem'],0,',','.'), $x+15, $this->y, ucfirst($this->detalle_cols['PrcItem']['align'][0]), $this->detalle_cols['PrcItem']['width']); |
|
1047 | + $this->Texto(number_format($d['PrcItem'], 0, ',', '.'), $x+15, $this->y, ucfirst($this->detalle_cols['PrcItem']['align'][0]), $this->detalle_cols['PrcItem']['width']); |
|
1048 | 1048 | $this->Texto($this->num($d['QtyItem']), $x+35, $this->y, ucfirst($this->detalle_cols['QtyItem']['align'][0]), $this->detalle_cols['QtyItem']['width']); |
1049 | 1049 | $this->Texto($this->num($d['MontoItem']), $x+45, $this->y, ucfirst($this->detalle_cols['MontoItem']['align'][0]), $this->detalle_cols['MontoItem']['width']); |
1050 | 1050 | } |
@@ -1064,7 +1064,7 @@ discard block |
||
1064 | 1064 | if (!isset($detalle[0])) { |
1065 | 1065 | $detalle = [$detalle]; |
1066 | 1066 | } |
1067 | - foreach($detalle as &$d) { |
|
1067 | + foreach ($detalle as &$d) { |
|
1068 | 1068 | if (!empty($d['MontoItem'])) { |
1069 | 1069 | $subtotal += $d['MontoItem']; |
1070 | 1070 | } |
@@ -1090,16 +1090,16 @@ discard block |
||
1090 | 1090 | if (!isset($descuentosRecargos[0])) { |
1091 | 1091 | $descuentosRecargos = [$descuentosRecargos]; |
1092 | 1092 | } |
1093 | - foreach($descuentosRecargos as $dr) { |
|
1093 | + foreach ($descuentosRecargos as $dr) { |
|
1094 | 1094 | $tipo = $dr['TpoMov']=='D' ? 'Descuento' : 'Recargo'; |
1095 | 1095 | if (!empty($dr['IndExeDR'])) { |
1096 | 1096 | $tipo .= ' EX'; |
1097 | 1097 | } |
1098 | 1098 | $valor = $dr['TpoValor']=='%' ? $dr['ValorDR'].'%' : $this->num($dr['ValorDR']); |
1099 | 1099 | if ($this->papelContinuo) { |
1100 | - $this->Texto($tipo.' global: '.$valor.(!empty($dr['GlosaDR'])?(' ('.$dr['GlosaDR'].')'):''), $x); |
|
1100 | + $this->Texto($tipo.' global: '.$valor.(!empty($dr['GlosaDR']) ? (' ('.$dr['GlosaDR'].')') : ''), $x); |
|
1101 | 1101 | } else { |
1102 | - $this->Texto($tipo.(!empty($dr['GlosaDR'])?(' ('.$dr['GlosaDR'].')'):'').':', 77, null, 'R', 100); |
|
1102 | + $this->Texto($tipo.(!empty($dr['GlosaDR']) ? (' ('.$dr['GlosaDR'].')') : '').':', 77, null, 'R', 100); |
|
1103 | 1103 | $this->Texto($valor, 177, null, 'R', 22); |
1104 | 1104 | } |
1105 | 1105 | $this->Ln(); |
@@ -1119,8 +1119,8 @@ discard block |
||
1119 | 1119 | $pagos = [$pagos]; |
1120 | 1120 | $this->Texto('Pago(s) programado(s):', $x); |
1121 | 1121 | $this->Ln(); |
1122 | - foreach($pagos as $p) { |
|
1123 | - $this->Texto(' - '.$this->date($p['FchPago'], false).': $'.$this->num($p['MntPago']).'.-'.(!empty($p['GlosaPagos'])?(' ('.$p['GlosaPagos'].')'):''), $x); |
|
1122 | + foreach ($pagos as $p) { |
|
1123 | + $this->Texto(' - '.$this->date($p['FchPago'], false).': $'.$this->num($p['MntPago']).'.-'.(!empty($p['GlosaPagos']) ? (' ('.$p['GlosaPagos'].')') : ''), $x); |
|
1124 | 1124 | $this->Ln(); |
1125 | 1125 | } |
1126 | 1126 | } |
@@ -1171,7 +1171,7 @@ discard block |
||
1171 | 1171 | if (!isset($ImptoReten[0])) { |
1172 | 1172 | $ImptoReten = [$ImptoReten]; |
1173 | 1173 | } |
1174 | - foreach($ImptoReten as $i) { |
|
1174 | + foreach ($ImptoReten as $i) { |
|
1175 | 1175 | $totales['ImptoReten_'.$i['TipoImp']] = $i['MontoImp']; |
1176 | 1176 | if (!empty($i['TasaImp'])) { |
1177 | 1177 | $glosas['ImptoReten_'.$i['TipoImp']] = \sasco\LibreDTE\Sii\ImpuestosAdicionales::getGlosa($i['TipoImp']).' ('.$i['TasaImp'].'%) $'; |
@@ -1284,7 +1284,7 @@ discard block |
||
1284 | 1284 | 'vpadding' => 0, |
1285 | 1285 | 'module_width' => 1, // width of a single module in points |
1286 | 1286 | 'module_height' => 1, // height of a single module in points |
1287 | - 'fgcolor' => [0,0,0], |
|
1287 | + 'fgcolor' => [0, 0, 0], |
|
1288 | 1288 | 'bgcolor' => false, // [255,255,255] |
1289 | 1289 | 'position' => $this->papelContinuo ? 'C' : 'S', |
1290 | 1290 | ]; |
@@ -1317,7 +1317,7 @@ discard block |
||
1317 | 1317 | protected function agregarAcuseRecibo($x = 83, $y = 190, $w = 60, $h = 40) |
1318 | 1318 | { |
1319 | 1319 | $y = (!$this->papelContinuo and !$this->timbre_pie) ? $this->x_fin_datos : $y; |
1320 | - $this->SetTextColorArray([0,0,0]); |
|
1320 | + $this->SetTextColorArray([0, 0, 0]); |
|
1321 | 1321 | $this->Rect($x, $y, $w, $h, 'D', ['all' => ['width' => 0.1, 'color' => [0, 0, 0]]]); |
1322 | 1322 | $this->setFont('', 'B', 10); |
1323 | 1323 | $this->Texto('Acuse de recibo', $x, $y+1, 'C', $w); |
@@ -1347,9 +1347,9 @@ discard block |
||
1347 | 1347 | */ |
1348 | 1348 | protected function agregarAcuseReciboContinuo($x = 3, $y = null, $w = 68, $h = 40) |
1349 | 1349 | { |
1350 | - $this->SetTextColorArray([0,0,0]); |
|
1350 | + $this->SetTextColorArray([0, 0, 0]); |
|
1351 | 1351 | $this->Rect($x, $y, $w, $h, 'D', ['all' => ['width' => 0.1, 'color' => [0, 0, 0]]]); |
1352 | - $style = array('width' => 0.2,'color' => array(0, 0, 0)); |
|
1352 | + $style = array('width' => 0.2, 'color' => array(0, 0, 0)); |
|
1353 | 1353 | $this->Line($x, $y+22, $w+3, $y+22, $style); |
1354 | 1354 | //$this->setFont('', 'B', 10); |
1355 | 1355 | //$this->Texto('Acuse de recibo', $x, $y+1, 'C', $w); |
@@ -1379,7 +1379,7 @@ discard block |
||
1379 | 1379 | $y = (!$this->papelContinuo and !$this->timbre_pie and $this->x_fin_datos<=$y) ? $this->x_fin_datos : $y; |
1380 | 1380 | $y += 48; |
1381 | 1381 | $this->setFont('', 'B', $font_size); |
1382 | - $this->Texto('CEDIBLE'.($tipo==52?' CON SU FACTURA':''), null, $y, 'R'); |
|
1382 | + $this->Texto('CEDIBLE'.($tipo==52 ? ' CON SU FACTURA' : ''), null, $y, 'R'); |
|
1383 | 1383 | } |
1384 | 1384 | |
1385 | 1385 | /** |
@@ -1390,7 +1390,7 @@ discard block |
||
1390 | 1390 | protected function agregarLeyendaDestinoContinuo($tipo) |
1391 | 1391 | { |
1392 | 1392 | $this->setFont('', 'B', 8); |
1393 | - $this->Texto('CEDIBLE'.($tipo==52?' CON SU FACTURA':''), null, $this->y+6, 'R'); |
|
1393 | + $this->Texto('CEDIBLE'.($tipo==52 ? ' CON SU FACTURA' : ''), null, $this->y+6, 'R'); |
|
1394 | 1394 | } |
1395 | 1395 | |
1396 | 1396 | /** |
@@ -1421,7 +1421,7 @@ discard block |
||
1421 | 1421 | $dias = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado']; |
1422 | 1422 | $meses = ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre']; |
1423 | 1423 | $unixtime = strtotime($date); |
1424 | - $fecha = date(($mostrar_dia?'\D\I\A ':'').'j \d\e \M\E\S \d\e\l Y', $unixtime); |
|
1424 | + $fecha = date(($mostrar_dia ? '\D\I\A ' : '').'j \d\e \M\E\S \d\e\l Y', $unixtime); |
|
1425 | 1425 | $dia = $dias[date('w', $unixtime)]; |
1426 | 1426 | $mes = $meses[date('n', $unixtime)-1]; |
1427 | 1427 | return str_replace(array('DIA', 'MES'), array($dia, $mes), $fecha); |
@@ -585,10 +585,12 @@ discard block |
||
585 | 585 | } |
586 | 586 | $contacto = []; |
587 | 587 | if (!empty($emisor['Telefono'])) { |
588 | - if (!is_array($emisor['Telefono'])) |
|
589 | - $emisor['Telefono'] = [$emisor['Telefono']]; |
|
590 | - foreach ($emisor['Telefono'] as $t) |
|
591 | - $contacto[] = $t; |
|
588 | + if (!is_array($emisor['Telefono'])) { |
|
589 | + $emisor['Telefono'] = [$emisor['Telefono']]; |
|
590 | + } |
|
591 | + foreach ($emisor['Telefono'] as $t) { |
|
592 | + $contacto[] = $t; |
|
593 | + } |
|
592 | 594 | } |
593 | 595 | if (!empty($emisor['CorreoEmisor'])) { |
594 | 596 | $contacto[] = $emisor['CorreoEmisor']; |
@@ -807,10 +809,12 @@ discard block |
||
807 | 809 | $this->MultiTexto($receptor['Extranjero']['NumId'], $x+$offset+2); |
808 | 810 | } |
809 | 811 | $contacto = []; |
810 | - if (!empty($receptor['Contacto'])) |
|
811 | - $contacto[] = $receptor['Contacto']; |
|
812 | - if (!empty($receptor['CorreoRecep'])) |
|
813 | - $contacto[] = $receptor['CorreoRecep']; |
|
812 | + if (!empty($receptor['Contacto'])) { |
|
813 | + $contacto[] = $receptor['Contacto']; |
|
814 | + } |
|
815 | + if (!empty($receptor['CorreoRecep'])) { |
|
816 | + $contacto[] = $receptor['CorreoRecep']; |
|
817 | + } |
|
814 | 818 | if (!empty($contacto)) { |
815 | 819 | $this->setFont('', 'B', null); |
816 | 820 | $this->Texto('Contacto', $x); |
@@ -860,15 +864,19 @@ discard block |
||
860 | 864 | if (!empty($Transporte['DirDest']) and !empty($Transporte['CmnaDest'])) { |
861 | 865 | $transporte .= 'a '.$Transporte['DirDest'].', '.$Transporte['CmnaDest']; |
862 | 866 | } |
863 | - if (!empty($Transporte['RUTTrans'])) |
|
864 | - $transporte .= ' por '.$Transporte['RUTTrans']; |
|
865 | - if (!empty($Transporte['Patente'])) |
|
866 | - $transporte .= ' en vehículo '.$Transporte['Patente']; |
|
867 | + if (!empty($Transporte['RUTTrans'])) { |
|
868 | + $transporte .= ' por '.$Transporte['RUTTrans']; |
|
869 | + } |
|
870 | + if (!empty($Transporte['Patente'])) { |
|
871 | + $transporte .= ' en vehículo '.$Transporte['Patente']; |
|
872 | + } |
|
867 | 873 | if (isset($Transporte['Chofer']) and is_array($Transporte['Chofer'])) { |
868 | - if (!empty($Transporte['Chofer']['NombreChofer'])) |
|
869 | - $transporte .= ' con chofer '.$Transporte['Chofer']['NombreChofer']; |
|
870 | - if (!empty($Transporte['Chofer']['RUTChofer'])) |
|
871 | - $transporte .= ' ('.$Transporte['Chofer']['RUTChofer'].')'; |
|
874 | + if (!empty($Transporte['Chofer']['NombreChofer'])) { |
|
875 | + $transporte .= ' con chofer '.$Transporte['Chofer']['NombreChofer']; |
|
876 | + } |
|
877 | + if (!empty($Transporte['Chofer']['RUTChofer'])) { |
|
878 | + $transporte .= ' ('.$Transporte['Chofer']['RUTChofer'].')'; |
|
879 | + } |
|
872 | 880 | } |
873 | 881 | if ($transporte) { |
874 | 882 | $this->setFont('', 'B', null); |
@@ -882,8 +890,9 @@ discard block |
||
882 | 890 | if (!empty($Transporte['Aduana']) and is_array($Transporte['Aduana'])) { |
883 | 891 | $col = 0; |
884 | 892 | foreach ($Transporte['Aduana'] as $tag => $codigo) { |
885 | - if ($codigo===false) |
|
886 | - continue; |
|
893 | + if ($codigo===false) { |
|
894 | + continue; |
|
895 | + } |
|
887 | 896 | $glosa = \sasco\LibreDTE\Sii\Aduana::getGlosa($tag); |
888 | 897 | $valor = \sasco\LibreDTE\Sii\Aduana::getValor($tag, $codigo); |
889 | 898 | if ($glosa!==false and $valor!==false) { |
@@ -896,15 +905,18 @@ discard block |
||
896 | 905 | $this->Texto(':', $x+$offset+$col); |
897 | 906 | $this->setFont('', '', null); |
898 | 907 | $this->Texto($valor, $x+$offset+2+$col); |
899 | - if ($tag=='TipoBultos') |
|
900 | - $col = abs($col-110); |
|
901 | - if ($col) |
|
902 | - $this->Ln(); |
|
908 | + if ($tag=='TipoBultos') { |
|
909 | + $col = abs($col-110); |
|
910 | + } |
|
911 | + if ($col) { |
|
912 | + $this->Ln(); |
|
913 | + } |
|
903 | 914 | $col = abs($col-110); |
904 | 915 | } |
905 | 916 | } |
906 | - if ($col) |
|
907 | - $this->Ln(); |
|
917 | + if ($col) { |
|
918 | + $this->Ln(); |
|
919 | + } |
|
908 | 920 | } |
909 | 921 | } |
910 | 922 | |
@@ -917,8 +929,9 @@ discard block |
||
917 | 929 | */ |
918 | 930 | protected function agregarReferencia($referencias, $x = 10, $offset = 22) |
919 | 931 | { |
920 | - if (!isset($referencias[0])) |
|
921 | - $referencias = [$referencias]; |
|
932 | + if (!isset($referencias[0])) { |
|
933 | + $referencias = [$referencias]; |
|
934 | + } |
|
922 | 935 | foreach($referencias as $r) { |
923 | 936 | $texto = $r['NroLinRef'].' - '; |
924 | 937 | if (!empty($r['TpoDocRef'])) { |
@@ -955,8 +968,9 @@ discard block |
||
955 | 968 | */ |
956 | 969 | protected function agregarDetalle($detalle, $x = 10, $html = true) |
957 | 970 | { |
958 | - if (!isset($detalle[0])) |
|
959 | - $detalle = [$detalle]; |
|
971 | + if (!isset($detalle[0])) { |
|
972 | + $detalle = [$detalle]; |
|
973 | + } |
|
960 | 974 | $this->setFont('', '', $this->detalle_fuente); |
961 | 975 | // titulos |
962 | 976 | $titulos = []; |
@@ -977,36 +991,42 @@ discard block |
||
977 | 991 | $item['NmbItem'] .= $item['DscItem']; |
978 | 992 | } |
979 | 993 | } |
980 | - if (!in_array($col, $titulos_keys) or ($dte_exento and $col=='IndExe')) |
|
981 | - unset($item[$col]); |
|
994 | + if (!in_array($col, $titulos_keys) or ($dte_exento and $col=='IndExe')) { |
|
995 | + unset($item[$col]); |
|
996 | + } |
|
982 | 997 | } |
983 | 998 | // ajustes a IndExe |
984 | 999 | if (isset($item['IndExe'])) { |
985 | - if ($item['IndExe']==1) |
|
986 | - $item['IndExe'] = 'EX'; |
|
987 | - else if ($item['IndExe']==2) |
|
988 | - $item['IndExe'] = 'NF'; |
|
1000 | + if ($item['IndExe']==1) { |
|
1001 | + $item['IndExe'] = 'EX'; |
|
1002 | + } else if ($item['IndExe']==2) { |
|
1003 | + $item['IndExe'] = 'NF'; |
|
1004 | + } |
|
989 | 1005 | } |
990 | 1006 | // agregar todas las columnas que se podrían imprimir en la tabla |
991 | 1007 | $item_default = []; |
992 | - foreach ($this->detalle_cols as $key => $info) |
|
993 | - $item_default[$key] = false; |
|
1008 | + foreach ($this->detalle_cols as $key => $info) { |
|
1009 | + $item_default[$key] = false; |
|
1010 | + } |
|
994 | 1011 | $item = array_merge($item_default, $item); |
995 | 1012 | // si hay código de item se extrae su valor |
996 | - if ($item['CdgItem']) |
|
997 | - $item['CdgItem'] = $item['CdgItem']['VlrCodigo']; |
|
1013 | + if ($item['CdgItem']) { |
|
1014 | + $item['CdgItem'] = $item['CdgItem']['VlrCodigo']; |
|
1015 | + } |
|
998 | 1016 | // dar formato a números |
999 | 1017 | foreach (['QtyItem', 'PrcItem', 'DescuentoMonto', 'RecargoMonto', 'MontoItem'] as $col) { |
1000 | - if ($item[$col]) |
|
1001 | - $item[$col] = $this->num($item[$col]); |
|
1018 | + if ($item[$col]) { |
|
1019 | + $item[$col] = $this->num($item[$col]); |
|
1020 | + } |
|
1002 | 1021 | } |
1003 | 1022 | } |
1004 | 1023 | // opciones |
1005 | 1024 | $options = ['align'=>[]]; |
1006 | 1025 | $i = 0; |
1007 | 1026 | foreach ($this->detalle_cols as $info) { |
1008 | - if (isset($info['width'])) |
|
1009 | - $options['width'][$i] = $info['width']; |
|
1027 | + if (isset($info['width'])) { |
|
1028 | + $options['width'][$i] = $info['width']; |
|
1029 | + } |
|
1010 | 1030 | $options['align'][$i] = $info['align']; |
1011 | 1031 | $i++; |
1012 | 1032 | } |
@@ -1039,8 +1059,9 @@ discard block |
||
1039 | 1059 | $this->Texto($this->detalle_cols['QtyItem']['title'], $x+35, $this->y, ucfirst($this->detalle_cols['QtyItem']['align'][0]), $this->detalle_cols['QtyItem']['width']); |
1040 | 1060 | $this->Texto($this->detalle_cols['MontoItem']['title'], $x+45, $this->y, ucfirst($this->detalle_cols['MontoItem']['align'][0]), $this->detalle_cols['MontoItem']['width']); |
1041 | 1061 | $this->Line($p1x, $p1y+4, $p2x, $p2y+4, $style); |
1042 | - if (!isset($detalle[0])) |
|
1043 | - $detalle = [$detalle]; |
|
1062 | + if (!isset($detalle[0])) { |
|
1063 | + $detalle = [$detalle]; |
|
1064 | + } |
|
1044 | 1065 | $this->SetY($this->getY()+2); |
1045 | 1066 | foreach($detalle as &$d) { |
1046 | 1067 | $this->MultiTexto($d['NmbItem'], $x+1, $this->y+4, ucfirst($this->detalle_cols['NmbItem']['align'][0]), $this->detalle_cols['NmbItem']['width']); |
@@ -1115,8 +1136,9 @@ discard block |
||
1115 | 1136 | */ |
1116 | 1137 | protected function agregarPagos(array $pagos, $x = 10) |
1117 | 1138 | { |
1118 | - if (!isset($pagos[0])) |
|
1119 | - $pagos = [$pagos]; |
|
1139 | + if (!isset($pagos[0])) { |
|
1140 | + $pagos = [$pagos]; |
|
1141 | + } |
|
1120 | 1142 | $this->Texto('Pago(s) programado(s):', $x); |
1121 | 1143 | $this->Ln(); |
1122 | 1144 | foreach($pagos as $p) { |
@@ -1403,11 +1425,13 @@ discard block |
||
1403 | 1425 | */ |
1404 | 1426 | protected function num($n) |
1405 | 1427 | { |
1406 | - if (!is_numeric($n)) |
|
1407 | - return $n; |
|
1428 | + if (!is_numeric($n)) { |
|
1429 | + return $n; |
|
1430 | + } |
|
1408 | 1431 | $broken_number = explode('.', (string)$n); |
1409 | - if (isset($broken_number[1])) |
|
1410 | - return number_format($broken_number[0], 0, ',', '.').','.$broken_number[1]; |
|
1432 | + if (isset($broken_number[1])) { |
|
1433 | + return number_format($broken_number[0], 0, ',', '.').','.$broken_number[1]; |
|
1434 | + } |
|
1411 | 1435 | return number_format($broken_number[0], 0, ',', '.'); |
1412 | 1436 | } |
1413 | 1437 |