Skip to content

Commit 9f81f6c

Browse files
committed
feat: mejora el impuesto de sociedades en tesorería
1 parent 82003e9 commit 9f81f6c

8 files changed

Lines changed: 186 additions & 32 deletions

File tree

Controller/ReportTreasury.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected function cuadroImpuestos(): void
177177
if ($this->da_impuestos["resultado"] < 0) {
178178
$this->da_impuestos["sociedades"] = 0;
179179
} else {
180-
$sociedades = isset($this->ejercicio_ant->impsociedades) ? floatval($this->ejercicio_ant->impsociedades) : 0;
180+
$sociedades = isset($this->ejercicio->impsociedades) ? floatval($this->ejercicio->impsociedades) : 0;
181181
$this->da_impuestos["sociedades"] = -1 * $this->da_impuestos["resultado"] * $sociedades / 100;
182182
}
183183

Extension/Model/Ejercicio.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* This file is part of Informes plugin for FacturaScripts
4+
* Copyright (C) 2026 Carlos García Gómez <carlos@facturascripts.com>
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
namespace FacturaScripts\Plugins\Informes\Extension\Model;
21+
22+
use Closure;
23+
use FacturaScripts\Core\Tools;
24+
25+
final class Ejercicio
26+
{
27+
public function test(): Closure
28+
{
29+
return function (): bool {
30+
if (
31+
!is_numeric($this->impsociedades)
32+
|| $this->impsociedades < 0
33+
|| $this->impsociedades > 100
34+
) {
35+
Tools::log()->warning('invalid-number', ['%number%' => $this->impsociedades]);
36+
return false;
37+
}
38+
39+
$this->impsociedades = (float)$this->impsociedades;
40+
return true;
41+
};
42+
}
43+
}

Extension/Table/ejercicios.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
<column>
88
<name>impsociedades</name>
99
<type>float</type>
10+
<default>0</default>
1011
</column>
11-
</table>
12+
</table>

Extension/XMLView/EditEjercicio.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<columns>
88
<group name="data">
99
<column name="company-tax" numcolumns="3" order="170">
10-
<widget type="number" fieldname="impsociedades" min="0" icon="fa-solid fa-percentage"/>
10+
<widget type="number" fieldname="impsociedades" min="0" max="100" icon="fa-solid fa-percentage"/>
1111
</column>
1212
</group>
1313
</columns>
14-
</view>
14+
</view>

Init.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
use FacturaScripts\Core\Model\RoleAccess;
2828
use FacturaScripts\Dinamic\Model\BalanceAccount;
2929
use FacturaScripts\Dinamic\Model\BalanceCode;
30-
use FacturaScripts\Dinamic\Model\Empresa;
30+
use FacturaScripts\Dinamic\Model\Ejercicio;
3131
use ParseCsv\Csv;
3232

3333
final class Init extends InitClass
@@ -40,6 +40,7 @@ public function init(): void
4040
$this->loadExtension(new Extension\Controller\EditProveedor());
4141
$this->loadExtension(new Extension\Controller\EditUser());
4242
$this->loadExtension(new Extension\Controller\Dashboard());
43+
$this->loadExtension(new Extension\Model\Ejercicio());
4344
}
4445

4546
public function uninstall(): void
@@ -50,8 +51,8 @@ public function uninstall(): void
5051

5152
public function update(): void
5253
{
53-
// inicializamos empresa para que aplique los cambios en la tabla
54-
new Empresa();
54+
// inicializamos el modelo para que aplique los cambios en la tabla
55+
new Ejercicio();
5556

5657
// migramos los datos antiguos
5758
$this->migrateOldBalances();

Test/main/EjercicioTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* This file is part of Informes plugin for FacturaScripts
4+
* Copyright (C) 2026 Carlos García Gómez <carlos@facturascripts.com>
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
namespace FacturaScripts\Test\Plugins;
21+
22+
use FacturaScripts\Dinamic\Model\Ejercicio;
23+
use PHPUnit\Framework\TestCase;
24+
25+
final class EjercicioTest extends TestCase
26+
{
27+
public function testCorporateTaxDefault(): void
28+
{
29+
$exercise = new Ejercicio();
30+
$this->assertSame(0.0, $exercise->impsociedades);
31+
}
32+
33+
public function testCorporateTaxPercentage(): void
34+
{
35+
$exercise = new Ejercicio();
36+
$exercise->codejercicio = 'test';
37+
$exercise->nombre = 'test';
38+
39+
foreach ([0, 25, 100, '25.5'] as $value) {
40+
$exercise->impsociedades = $value;
41+
$this->assertTrue($exercise->test());
42+
$this->assertIsFloat($exercise->impsociedades);
43+
}
44+
45+
foreach ([-0.01, 100.01, 'invalid'] as $value) {
46+
$exercise->impsociedades = $value;
47+
$this->assertFalse($exercise->test());
48+
}
49+
}
50+
}

Test/main/ReportTreasuryTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* This file is part of Informes plugin for FacturaScripts
4+
* Copyright (C) 2026 Carlos García Gómez <carlos@facturascripts.com>
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
namespace FacturaScripts\Test\Plugins;
21+
22+
use FacturaScripts\Dinamic\Model\Ejercicio;
23+
use FacturaScripts\Plugins\Informes\Controller\ReportTreasury;
24+
use PHPUnit\Framework\TestCase;
25+
26+
final class ReportTreasuryTest extends TestCase
27+
{
28+
public function testCurrentCorporateTaxUsesCurrentExercisePercentage(): void
29+
{
30+
$report = new class ('ReportTreasury') extends ReportTreasury {
31+
public function calculateTaxes(float $currentPercentage, float $previousPercentage): array
32+
{
33+
$this->ejercicio = new Ejercicio();
34+
$this->ejercicio->impsociedades = $currentPercentage;
35+
$this->ejercicio_ant = new Ejercicio();
36+
$this->ejercicio_ant->impsociedades = $previousPercentage;
37+
$this->desde = '2026-01-01';
38+
$this->hasta = '2026-12-31';
39+
40+
$this->cuadroImpuestos();
41+
return $this->da_impuestos;
42+
}
43+
44+
protected function getVentasTotales(): float
45+
{
46+
return 1000.0;
47+
}
48+
49+
protected function saldoCuenta(string $cuenta, string $desde, string $hasta): float
50+
{
51+
return 0.0;
52+
}
53+
};
54+
55+
$taxes = $report->calculateTaxes(25.0, 10.0);
56+
$this->assertSame(-250.0, $taxes['sociedades']);
57+
$this->assertSame(-250.0, $taxes['pagofraccionado-mod202']);
58+
}
59+
}

View/ReportTreasury.html.twig

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,29 @@
77
<div class="container-fluid mb-1 d-print-none">
88
<div class="row">
99
<div class="col-md-7">
10-
<div class="btn-group">
11-
<a class="btn btn-sm btn-secondary" href="{{ fsc.url() }}" title="{{ trans('refresh') }}">
12-
<i class="fa-solid fa-redo" aria-hidden="true"></i>
13-
</a>
14-
<a class="btn btn-sm btn-secondary" href="{{ fsc.url() }}?defaultPage=TRUE"
15-
title="{{ trans('mark-as-homepage') }}">
16-
<i class="fa-regular fa-bookmark" aria-hidden="true"></i>
17-
</a>
10+
<div class="d-flex align-items-center">
11+
<div class="btn-group">
12+
<a class="btn btn-sm btn-secondary" href="{{ fsc.url() }}" title="{{ trans('refresh') }}">
13+
<i class="fa-solid fa-redo" aria-hidden="true"></i>
14+
</a>
15+
<a class="btn btn-sm btn-secondary" href="{{ fsc.url() }}?defaultPage=TRUE"
16+
title="{{ trans('mark-as-homepage') }}">
17+
<i class="fa-regular fa-bookmark" aria-hidden="true"></i>
18+
</a>
19+
</div>
20+
21+
<select class="form-select form-select-sm ms-2" id="selectExercise"
22+
title="{{ trans('exercise') }}" aria-label="{{ trans('exercise') }}">
23+
{% for company in fsc.getCompanies() %}
24+
<optgroup label="{{ company.nombrecorto }}">
25+
{% for exercise in company.getExercises() %}
26+
<option value="{{ exercise.codejercicio }}" {{ fsc.code == exercise.codejercicio ? 'selected' : '' }}>
27+
{{ exercise.nombre }}
28+
</option>
29+
{% endfor %}
30+
</optgroup>
31+
{% endfor %}
32+
</select>
1833
</div>
1934
</div>
2035

@@ -26,26 +41,11 @@
2641
</div>
2742
</div>
2843
</div>
29-
<div class="pb-5">
30-
<div class="h5 text-success text-center">{{ trans('exercise') }}</div>
31-
<select class="form-select mx-auto" id="selectExercise">
32-
{% for company in fsc.getCompanies() %}
33-
<optgroup label="{{ company.nombrecorto }}">
34-
{% for exercise in company.getExercises() %}
35-
<option value="{{ exercise.codejercicio }}" {{ fsc.code == exercise.codejercicio ? 'selected' : '' }}>
36-
{{ exercise.nombre }}
37-
</option>
38-
{% endfor %}
39-
</optgroup>
40-
{% endfor %}
41-
</select>
42-
<br/>
43-
</div>
4444
{% endblock %}
4545

4646
{% block body %}
4747
{{ parent() }}
48-
<div class="container-fluid" style="margin-top: -50px;">
48+
<div class="container-fluid mt-3">
4949
<div class="row">
5050
<div class="col-sm-6">
5151
<div class="card border-info shadow mb-3">
@@ -256,4 +256,4 @@
256256
{% else %}
257257
{{ money(price) }}
258258
{% endif %}
259-
{% endmacro %}
259+
{% endmacro %}

0 commit comments

Comments
 (0)