Skip to content

Commit 9421c52

Browse files
author
Daniel Fernández Giménez
committed
pequeñas mejoras al pr anterior y añadida función a la clase Modelo303 para obtener la tesorería para el plugin Informes
1 parent 4cf4be6 commit 9421c52

4 files changed

Lines changed: 84 additions & 20 deletions

File tree

Controller/EditRegularizacionImpuesto.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* This file is part of Modelo303 plugin for FacturaScripts
4-
* Copyright (C) 2017-2025 Carlos Garcia Gomez <carlos@facturascripts.com>
4+
* Copyright (C) 2017-2026 Carlos Garcia Gomez <carlos@facturascripts.com>
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Lesser General Public License as
@@ -16,6 +16,7 @@
1616
* You should have received a copy of the GNU Lesser General Public License
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
19+
1920
namespace FacturaScripts\Plugins\Modelo303\Controller;
2021

2122
use Exception;
@@ -28,11 +29,9 @@
2829
use FacturaScripts\Core\Tools;
2930
use FacturaScripts\Dinamic\Model\RegularizacionImpuesto;
3031
use FacturaScripts\Dinamic\Lib\Accounting\VatRegularizationToAccounting;
31-
use FacturaScripts\Plugins\Modelo303\Lib\Modelo303;
32+
use FacturaScripts\Dinamic\Lib\Modelo303;
3233

3334
/**
34-
* Controller to list the items in the RegularizacionImpuesto model
35-
*
3635
* @author Carlos García Gómez <carlos@facturascripts.com>
3736
* @author Jose Antonio Cuello Principal <yopli2000@gmail.com>
3837
*/
@@ -207,11 +206,6 @@ protected function exportAction(): void
207206
$this->request->input('langcode', '')
208207
);
209208

210-
// load data for all views before exporting
211-
foreach ($this->views as $name => $view) {
212-
$this->loadData($name, $view);
213-
}
214-
215209
foreach ($this->views as $name => $selectedView) {
216210
if (false === $selectedView->settings['active']) {
217211
continue;
@@ -233,9 +227,9 @@ protected function exportAction(): void
233227
$concept = Tools::trans('concept');
234228
$amount = Tools::trans('amount');
235229
$rows = [
236-
[$concept => Tools::trans('total-accrued-fee'), $amount => Tools::money($this->modelo303['27'])],
237-
[$concept => Tools::trans('total-to-deduct'), $amount => Tools::money($this->modelo303['45'])],
238-
[$concept => Tools::trans('total-result-of-the-general-regime'), $amount => Tools::money($this->modelo303['46'])],
230+
[$concept => Tools::trans('total-accrued-fee'), $amount => Tools::money($this->modelo303->casilla('27'))],
231+
[$concept => Tools::trans('total-to-deduct'), $amount => Tools::money($this->modelo303->casilla('45'))],
232+
[$concept => Tools::trans('total-result-of-the-general-regime'), $amount => Tools::money($this->modelo303->casilla('46'))],
239233
];
240234
$this->exportManager->addTablePage([$concept, $amount], $rows);
241235
}
@@ -277,7 +271,7 @@ protected function loadData($viewName, $view): void
277271
'partidas.codsubcuenta' => 'ASC',
278272
]);
279273

280-
$this->modelo303->loadFromResumen($view->cursor); // Load data into Modelo303 View
274+
$this->modelo303->loadFromResumen($view->cursor); // Load data into Modelo303 View
281275
break;
282276

283277
case 'ListPartida':

Lib/Modelo303.php

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* This file is part of Modelo303 plugin for FacturaScripts
4-
* Copyright (C) 2017-2025 Carlos Garcia Gomez <carlos@facturascripts.com>
4+
* Copyright (C) 2017-2026 Carlos Garcia Gomez <carlos@facturascripts.com>
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Lesser General Public License as
@@ -16,11 +16,13 @@
1616
* You should have received a copy of the GNU Lesser General Public License
1717
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
*/
19+
1920
namespace FacturaScripts\Plugins\Modelo303\Lib;
2021

21-
use FacturaScripts\Core\DataSrc\Impuestos;
22+
use FacturaScripts\Core\Base\DataBase;
2223
use FacturaScripts\Core\Tools;
23-
use FacturaScripts\Plugins\Modelo303\Model\Join\PartidaImpuestoResumen;
24+
use FacturaScripts\Dinamic\Model\Ejercicio;
25+
use FacturaScripts\Dinamic\Model\Join\PartidaImpuestoResumen;
2426

2527
/**
2628
* Class to handle Modelo 303 tax form data.
@@ -46,8 +48,8 @@ class Modelo303
4648
private array $casillaMap = [
4749
/*
4850
* IVA devengado (repercutido).
51+
* Ventas nacionales (régimen general)
4952
*/
50-
// Ventas nacionales (régimen general)
5153
'IVAREP' => [
5254
'2' => ['base' => '165', 'cuota' => '167'],
5355
'4' => ['base' => '01', 'cuota' => '03'],
@@ -76,8 +78,8 @@ class Modelo303
7678

7779
/*
7880
* IVA soportado (deducible)
81+
* Compras nacionales (régimen general)
7982
*/
80-
// Compras nacionales (régimen general)
8183
'IVASOP' => [
8284
'21' => ['base' => '28', 'cuota' => '29'],
8385
'10' => ['base' => '28', 'cuota' => '29'],
@@ -161,6 +163,25 @@ public function loadFromResumen(array $resumen): void
161163
$this->calculateTotals();
162164
}
163165

166+
public static function treasury(string $codejercicio, string $period): array
167+
{
168+
// comprobamos que el ejercicio existe
169+
$exercise = new Ejercicio();
170+
if (false === $exercise->load($codejercicio)) {
171+
return [];
172+
}
173+
174+
$dataBase = new DataBase();
175+
$period = strtoupper($period);
176+
list($dateStart, $dateEnd) = static::treasuryDates($exercise, $period);
177+
178+
return [
179+
'iva-repercutido' => static::treasurySaldoCuenta('477%', $dateStart, $dateEnd, $dataBase),
180+
'iva-soportado' => static::treasurySaldoCuenta('472%', $dateStart, $dateEnd, $dataBase),
181+
'iva-devolver' => static::treasurySaldoCuenta('4700%', $dateStart, $dateEnd, $dataBase),
182+
];
183+
}
184+
164185
/**
165186
* Add a tax movement to the model (base + quota by type and rate)
166187
* - Determine the correct square based on the type and tax rate.
@@ -239,4 +260,54 @@ private function calculateTotals(): void
239260
// Resultado régimen general
240261
$this->square['46'] = $this->square['27'] - $this->square['45'];
241262
}
263+
264+
protected static function treasurySaldoCuenta(string $cuenta, string $desde, string $hasta, DataBase $dataBase): float
265+
{
266+
$saldo = 0.0;
267+
268+
if ($dataBase->tableExists('partidas')) {
269+
// calculamos el saldo de todos aquellos asientos que afecten a caja
270+
$sql = "select sum(debe-haber) as total from partidas where codsubcuenta LIKE " . $dataBase->var2str($cuenta)
271+
. " and idasiento in (select idasiento from asientos where fecha >= " . $dataBase->var2str($desde)
272+
. " and fecha <= " . $dataBase->var2str($hasta) . ");";
273+
274+
$data = $dataBase->select($sql);
275+
if ($data && $data[0]['total'] !== null) {
276+
$saldo = floatval($data[0]['total']);
277+
}
278+
}
279+
280+
return $saldo;
281+
}
282+
283+
protected static function treasuryDates(Ejercicio $exercise, string $period): array
284+
{
285+
// si el periodo no es T1, T2, T3, T4 o Annual, se asume que es el primer trimestre
286+
if (!in_array($period, ['T1', 'T2', 'T3', 'T4', 'ANNUAL'])) {
287+
$period = 'T1';
288+
}
289+
290+
return match ($period) {
291+
'T1' => [
292+
date('01-01-Y', strtotime($exercise->fechainicio)),
293+
date('31-03-Y', strtotime($exercise->fechainicio))
294+
],
295+
'T2' => [
296+
date('01-04-Y', strtotime($exercise->fechainicio)),
297+
date('30-06-Y', strtotime($exercise->fechainicio))
298+
],
299+
'T3' => [
300+
date('01-07-Y', strtotime($exercise->fechainicio)),
301+
date('30-09-Y', strtotime($exercise->fechainicio))
302+
],
303+
'ANNUAL' => [
304+
date('01-01-Y', strtotime($exercise->fechainicio)),
305+
date('31-12-Y', strtotime($exercise->fechainicio))
306+
],
307+
default => [
308+
date('01-10-Y', strtotime($exercise->fechainicio)),
309+
date('31-12-Y', strtotime($exercise->fechainicio))
310+
],
311+
};
312+
}
242313
}

Translation/es_ES.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"model-303-390": "Modelos 303 y 390",
88
"model-390": "Modelo 390",
99
"year-model-390": "Año (modelo 390)",
10-
"---NEW---": "--------------------------",
1110
"model-303-new": "Modelos 303 (2025)",
1211
"tax-detail": "Detalle de impuestos",
1312
"vat-accrued": "IVA repercutido",

facturascripts.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name = 'Modelo303'
22
description = 'Modelo 303 y 390 de la Hacienda española para la declaración trimestral y anual de IVA.'
33
version = 2.8
4-
min_version = 2025
4+
min_version = 2025

0 commit comments

Comments
 (0)