Skip to content

Commit

Permalink
Fix por tipo de retorno en montos al ser flotante y comparar con ente…
Browse files Browse the repository at this point in the history
…ro en tests. Fix en config de scrutinizer y se crea CNAME de docs en el workflow.
  • Loading branch information
estebandelaf committed Sep 24, 2024
1 parent 725a32b commit 875bcf3
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
- name: Generate Documentation
run: php tools/phpdocumentor run --config=phpdoc.xml

- name: Create CNAME file
run: echo "lib-core.docs.libredte.cl" > build/docs/CNAME

- name: Deploy to GitHub Pages
if: success()
uses: peaceiris/actions-gh-pages@v4
Expand Down
3 changes: 0 additions & 3 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ build:
dependencies:
before:
- composer install --no-progress --no-suggest --prefer-dist
cache:
directories:
- vendor

tools:
php_code_sniffer:
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/ImpuestosAdicionalesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public function getRetenido(array $OtrosImp): float
{
$retenido = 0.0;
foreach ($OtrosImp as $Imp) {
if ($this->getTipo((int)$Imp['CodImp']) === 'R') {
$retenido += (float)$Imp['MntImp'];
if ($this->getTipo((int) $Imp['CodImp']) === 'R') {
$retenido += (float) $Imp['MntImp'];
}
}
return $retenido;
Expand Down
9 changes: 8 additions & 1 deletion src/Sii/Dte/Documento/AbstractDocumento.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,15 @@ public function getTotales(): array
public function getMontoTotal(): int|float
{
$data = $this->getData();
$monto = $data['Encabezado']['Totales']['MntTotal'];

return $data['Encabezado']['Totales']['MntTotal'];
// Verificar si el monto es equivalente a un entero.
if (is_float($monto) && floor($monto) == $monto) {
return (int) $monto;
}

// Entregar como flotante.
return $monto;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ protected function applyIvaMntTotalNormalization(array $data): array
}
}

// Si hay IVA definido se cambia a valor entero. El IVA no es decimal.
if (is_numeric($data['Encabezado']['Totales']['IVA'] ?? null)) {
$data['Encabezado']['Totales']['IVA'] =
(int) $data['Encabezado']['Totales']['IVA']
;
}

// Si hay impuesto retenido o adicional se contabiliza en el total.
if (!empty($data['Encabezado']['Totales']['ImptoReten'])) {
foreach ($data['Encabezado']['Totales']['ImptoReten'] as &$ImptoReten) {
Expand Down Expand Up @@ -181,6 +188,17 @@ protected function applyIvaMntTotalNormalization(array $data): array
}
}

// Si hay monto total definido, y el documento no es de exportación, se
// cambia a valor entero. El monto total no es decimal en documentos
// nacionales.
if (is_numeric($data['Encabezado']['Totales']['MntTotal'] ?? null)) {
if (!$this->getTipoDocumento()->esExportacion()) {
$data['Encabezado']['Totales']['MntTotal'] =
(int) $data['Encabezado']['Totales']['MntTotal']
;
}
}

// Entregar los datos normalizados.
return $data;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/resources/use_cases/xml_converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
// Caso con nodos vacíos.
'empty_node' => [
'data' => ['root' => ['element' => '']],
'expected' => ['root' => ['element' => '']],
'expected' => ['root' => ['element' => null]],
'expectedException' => null,
],
// Caso con múltiples valores repetidos.
Expand Down Expand Up @@ -306,7 +306,7 @@
// Caso con nodos vacíos.
'empty_node' => [
'xmlContent' => '<?xml version="1.0" encoding="ISO-8859-1"?><root><element></element></root>',
'expected' => ['root' => ['element' => '']],
'expected' => ['root' => ['element' => null]],
'expectedException' => null,
],
// Caso con múltiples valores repetidos.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testGetGlosa(): void

public function testGetTasa(): void
{
$this->assertSame(19, $this->repository->getTasa(15));
$this->assertSame(19.0, $this->repository->getTasa(15));
$this->assertSame(31.5, $this->repository->getTasa(24));
$this->assertFalse($this->repository->getTasa(999));
}
Expand All @@ -71,6 +71,6 @@ public function testGetRetenido(): void
['CodImp' => 30, 'MntImp' => 700],
];

$this->assertSame(1700, $this->repository->getRetenido($OtrosImp));
$this->assertSame(1700, (int) $this->repository->getRetenido($OtrosImp));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ private function validateExpectedValues(

// Si el valor esperado no es un arreglo, se compara directamente.
else {
// Si el valor actual es un flotante, se revisa si se debe
// convertir a un entero para usar assertSame() con el tipo de
// datos correcto y que no falle porque se compara entero con
// float.
if (
is_float($actualValues[$key])
&& floor($actualValues[$key]) == $actualValues[$key]
) {
$actualValues[$key] = (int) $actualValues[$key];
}

// Realizar validación del valor.
$this->assertSame(
$expectedValue,
$actualValues[$key],
Expand Down

0 comments on commit 875bcf3

Please sign in to comment.