Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Core/Controller/EditSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use FacturaScripts\Core\Lib\ExtendedController\PanelController;
use FacturaScripts\Core\Model\Settings;
use FacturaScripts\Core\Tools;
use FacturaScripts\Dinamic\Lib\RegimenIVA;
use FacturaScripts\Dinamic\Model\Impuesto;

/**
Expand Down Expand Up @@ -316,6 +317,7 @@ protected function loadData($viewName, $view)
$this->loadLogoImageValues($viewName);
$this->loadSerie($viewName);
$this->loadSerieRectifying($viewName);
$this->loadRegimeValues($viewName);
break;

default:
Expand Down Expand Up @@ -351,6 +353,14 @@ protected function loadPaymentMethodValues(string $viewName): void
}
}

protected function loadRegimeValues(string $viewName): void
{
$columnVATRegime = $this->views[$viewName]->columnForName('vat-regime');
if ($columnVATRegime && $columnVATRegime->widget->getType() === 'select') {
$columnVATRegime->widget->setValuesFromArrayKeys(RegimenIVA::all(), true, true);
}
}

protected function loadSerie(string $viewName): void
{
$columnSerie = $this->views[$viewName]->columnForName('serie');
Expand Down
23 changes: 22 additions & 1 deletion Core/Controller/ListCliente.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
use FacturaScripts\Core\DataSrc\Series;
use FacturaScripts\Core\Lib\ExtendedController\ListController;
use FacturaScripts\Core\Tools;
use FacturaScripts\Core\Where;
use FacturaScripts\Dinamic\Lib\InvoiceOperation;
use FacturaScripts\Dinamic\Lib\TaxExceptions;
use FacturaScripts\Dinamic\Model\CodeModel;

/**
Expand Down Expand Up @@ -157,9 +160,27 @@ protected function createViewCustomers(string $viewName = 'ListCliente'): void
$this->addFilterSelect($viewName, 'codretencion', 'retentions', 'codretencion', Retenciones::codeModel());
$this->addFilterSelect($viewName, 'codpago', 'payment-methods', 'codpago', FormasPago::codeModel());

$vatRegimes = $this->codeModel->all('clientes', 'regimeniva', 'regimeniva');
$vatRegimes = $this->codeModel->all('clientes', 'regimeniva', 'regimeniva', true, [Where::isNotNull('regimeniva')]);
$this->addFilterSelect($viewName, 'regimeniva', 'vat-regime', 'regimeniva', $vatRegimes);

$operations = $this->codeModel->all('clientes', 'operacion', 'operacion', true, [Where::isNotNull('operacion')]);
foreach ($operations as &$item) {
$operationKey = InvoiceOperation::get($item->code);
if (null !== $operationKey) {
$item->description = Tools::trans($operationKey);
}
}
$this->addFilterSelect($viewName, 'operation', 'operation', 'operacion', $operations);

$vatExceptions = $this->codeModel->all('clientes', 'excepcioniva', 'excepcioniva', true, [Where::isNotNull('excepcioniva')]);
foreach ($vatExceptions as &$item) {
$operationKey = InvoiceOperation::get($item->code);
if (null !== $operationKey) {
$item->description = Tools::trans($operationKey);
}
}
$this->addFilterSelect($viewName, 'vat-exception', 'vat-exception', 'excepcioniva', $vatExceptions);

$this->addFilterNumber($viewName, 'riesgoalcanzado', 'current-risk', 'riesgoalcanzado');
}

Expand Down
23 changes: 22 additions & 1 deletion Core/Controller/ListProveedor.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
use FacturaScripts\Core\DataSrc\Series;
use FacturaScripts\Core\Lib\ExtendedController\ListController;
use FacturaScripts\Core\Tools;
use FacturaScripts\Core\Where;
use FacturaScripts\Dinamic\Lib\InvoiceOperation;
use FacturaScripts\Dinamic\Lib\TaxExceptions;

/**
* Controller to list the items in the Proveedor model
Expand Down Expand Up @@ -128,7 +131,25 @@ protected function createViewSuppliers(string $viewName = 'ListProveedor'): void
$this->addFilterSelect($viewName, 'codretencion', 'retentions', 'codretencion', Retenciones::codeModel());
$this->addFilterSelect($viewName, 'codpago', 'payment-methods', 'codpago', FormasPago::codeModel());

$vatRegimes = $this->codeModel->all('proveedores', 'regimeniva', 'regimeniva');
$vatRegimes = $this->codeModel->all('proveedores', 'regimeniva', 'regimeniva', true, [Where::isNotNull('regimeniva')]);
$this->addFilterSelect($viewName, 'regimeniva', 'vat-regime', 'regimeniva', $vatRegimes);

$operations = $this->codeModel->all('proveedores', 'operacion', 'operacion', true, [Where::isNotNull('operacion')]);
foreach ($operations as &$item) {
$operationKey = InvoiceOperation::get($item->code);
if (null !== $operationKey) {
$item->description = Tools::trans($operationKey);
}
}
$this->addFilterSelect($viewName, 'operation', 'operation', 'operacion', $operations);

$vatExceptions = $this->codeModel->all('proveedores', 'excepcioniva', 'excepcioniva', true, [Where::isNotNull('excepcioniva')]);
foreach ($vatExceptions as &$item) {
$operationKey = InvoiceOperation::get($item->code);
if (null !== $operationKey) {
$item->description = Tools::trans($operationKey);
}
}
$this->addFilterSelect($viewName, 'vat-exception', 'vat-exception', 'excepcioniva', $vatExceptions);
}
}
2 changes: 1 addition & 1 deletion Core/Controller/Wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getPageData(): array

public function getRegimenIva(): array
{
$list = [];
$list = ['' => '------'];
foreach (RegimenIVA::all() as $key => $value) {
$list[$key] = Tools::trans($value);
}
Expand Down
33 changes: 17 additions & 16 deletions Core/Data/Codpais/ESP/default.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"default": {
"coddivisa": "EUR",
"codimpuesto": "IVA21",
"codpago": "CONT",
"codserie": "A",
"codserierec": "R",
"tipoidfiscal": "NIF",
"updatesupplierprices": true,
"validate_iban": true
},
"email": {
"enc": "ssl",
"host": "smtp.gmail.com",
"mailer": "smtp",
"port": "465"
}
"default": {
"coddivisa": "EUR",
"codimpuesto": "IVA21",
"codpago": "CONT",
"codserie": "A",
"codserierec": "R",
"tipoidfiscal": "NIF",
"updatesupplierprices": true,
"validate_iban": true,
"regimeniva": "General"
},
"email": {
"enc": "ssl",
"host": "smtp.gmail.com",
"mailer": "smtp",
"port": "465"
}
}
6 changes: 6 additions & 0 deletions Core/Lib/InvoiceOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public static function all(): array
return self::filter();
}

public static function get(?string $key): ?string
{
$values = self::all();
return $values[$key] ?? null;
}

public static function allForPurchases(): array
{
return self::filter(self::TYPE_PURCHASE);
Expand Down
18 changes: 9 additions & 9 deletions Core/Lib/RegimenIVA.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
class RegimenIVA
{
// Deprecated: use TaxExceptions constants.
const ES_TAX_EXCEPTION_E1 = TaxExceptions::ES_TAX_EXCEPTION_E1;
const ES_TAX_EXCEPTION_E2 = TaxExceptions::ES_TAX_EXCEPTION_E2;
const ES_TAX_EXCEPTION_E3 = TaxExceptions::ES_TAX_EXCEPTION_E3;
const ES_TAX_EXCEPTION_E4 = TaxExceptions::ES_TAX_EXCEPTION_E4;
const ES_TAX_EXCEPTION_E5 = TaxExceptions::ES_TAX_EXCEPTION_E5;
const ES_TAX_EXCEPTION_E6 = TaxExceptions::ES_TAX_EXCEPTION_E6;
const ES_TAX_EXCEPTION_N1 = TaxExceptions::ES_TAX_EXCEPTION_N1;
const ES_TAX_EXCEPTION_N2 = TaxExceptions::ES_TAX_EXCEPTION_N2;
const ES_TAX_EXCEPTION_PASSIVE_SUBJECT = TaxExceptions::ES_TAX_EXCEPTION_PASSIVE_SUBJECT;
const ES_TAX_EXCEPTION_E1 = TaxExceptions::ES_TAX_EXCEPTION_20;
const ES_TAX_EXCEPTION_E2 = TaxExceptions::ES_TAX_EXCEPTION_21;
const ES_TAX_EXCEPTION_E3 = TaxExceptions::ES_TAX_EXCEPTION_22;
const ES_TAX_EXCEPTION_E4 = TaxExceptions::ES_TAX_EXCEPTION_23_24;
const ES_TAX_EXCEPTION_E5 = TaxExceptions::ES_TAX_EXCEPTION_25;
const ES_TAX_EXCEPTION_E6 = TaxExceptions::ES_TAX_EXCEPTION_OTHER;
const ES_TAX_EXCEPTION_N1 = TaxExceptions::ES_TAX_EXCEPTION_7;
const ES_TAX_EXCEPTION_N2 = TaxExceptions::ES_TAX_EXCEPTION_68_70;
const ES_TAX_EXCEPTION_PASSIVE_SUBJECT = TaxExceptions::ES_TAX_EXCEPTION_84;
const TAX_SYSTEM_AGRARIAN = 'Agrario';
const TAX_SYSTEM_CASH_CRITERIA = 'Caja';
const TAX_SYSTEM_EXEMPT = 'Exento';
Expand Down
62 changes: 36 additions & 26 deletions Core/Lib/TaxExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@
*/
class TaxExceptions
{
const ES_TAX_EXCEPTION_E1 = 'ES_20'; // E1 Exenta art. 20 LIVA – Exenciones interiores (sanidad, enseñanza, seguros, financieros…)
const ES_TAX_EXCEPTION_E2 = 'ES_21'; // E2 Exenta art. 21 LIVA – Exportaciones a países terceros
const ES_TAX_EXCEPTION_E3 = 'ES_22'; // E3 Exenta art. 22 LIVA – Operaciones asimiladas a exportaciones
const ES_TAX_EXCEPTION_E4 = 'ES_23_24'; // E4 Exenta arts. 23–24 LIVA – Zonas francas y depósitos aduaneros
const ES_TAX_EXCEPTION_E5 = 'ES_25'; // E5 Exenta art. 25 LIVA – Entregas intracomunitarias de bienes
const ES_TAX_EXCEPTION_E6 = 'ES_OTHER'; // E6 Otras exenciones (oro de inversión, regímenes especiales, etc.)
const ES_TAX_EXCEPTION_N1 = 'ES_N1'; // N1 No sujeta – art. 7, 14 y otros (aportaciones, transmisión de UEA, muestras, operaciones vinculadas a exportaciones, OTAN, convenios…)
const ES_TAX_EXCEPTION_N2 = 'ES_N2'; // N2 No sujeta – Reglas de localización (arts. 68–70 LIVA, entregas de bienes y servicios B2B UE o fuera UE)
const ES_TAX_EXCEPTION_PASSIVE_SUBJECT = 'ES_PASSIVE_SUBJECT'; // Inversión del sujeto pasivo (art. 84 LIVA)
const ES_TAX_EXCEPTION_7 = 'ES_7'; // No sujeta – Art. 7 LIVA (aportaciones, transmisión de UEA, muestras, autoconsumo exterior, etc.)
const ES_TAX_EXCEPTION_14 = 'ES_14'; // No sujeta – Art. 14 LIVA (regímenes aduaneros, depósitos, zonas francas, operaciones en tránsito)
const ES_TAX_EXCEPTION_20 = 'ES_20'; // Exenta Art. 20 LIVA – Exenciones interiores (sanidad, enseñanza, seguros, banca…)
const ES_TAX_EXCEPTION_21 = 'ES_21'; // Exenta Art. 21 LIVA – Exportaciones a países terceros
const ES_TAX_EXCEPTION_22 = 'ES_22'; // Exenta Art. 22 LIVA – Operaciones asimiladas a exportaciones
const ES_TAX_EXCEPTION_23_24 = 'ES_23_24'; // Exenta Arts. 23–24 LIVA – Zonas francas y depósitos aduaneros
const ES_TAX_EXCEPTION_25 = 'ES_25'; // Exenta - Art. 25 LIVA – Entregas intracomunitarias
const ES_TAX_EXCEPTION_68_70 = 'ES_68_70'; // No sujeta – Arts. 68–70 LIVA (reglas de localización de bienes y servicios, B2B a UE/extranjero)
const ES_TAX_EXCEPTION_84 = 'ES_84'; // Sujeta - Inversión del sujeto pasivo Art. 84 LIVA (obras, inmuebles, residuos, oro de inversión no exento…)
const ES_TAX_EXCEPTION_OTHER = 'ES_OTHER'; // Exenta - Otras exenciones (oro de inversión, regímenes especiales, organismos internacionales, etc.)
const ES_OTHER_NOT_SUBJECT = 'ES_OTHER_NOT_SUBJECT'; // No sujeta – Otros supuestos no sujetos (OTAN, convenios internacionales, fuerzas armadas UE…)

/** @var array */
private static $values = [];
Expand All @@ -52,15 +54,17 @@ public static function add(string $key, string $value): void
public static function all(): array
{
$defaultValues = [
self::ES_TAX_EXCEPTION_E1 => 'es-tax-exception-e1',
self::ES_TAX_EXCEPTION_E2 => 'es-tax-exception-e2',
self::ES_TAX_EXCEPTION_E3 => 'es-tax-exception-e3',
self::ES_TAX_EXCEPTION_E4 => 'es-tax-exception-e4',
self::ES_TAX_EXCEPTION_E5 => 'es-tax-exception-e5',
self::ES_TAX_EXCEPTION_E6 => 'es-tax-exception-e6',
self::ES_TAX_EXCEPTION_N1 => 'es-tax-exception-n1',
self::ES_TAX_EXCEPTION_N2 => 'es-tax-exception-n2',
self::ES_TAX_EXCEPTION_PASSIVE_SUBJECT => 'es-tax-exception-passive-subject',
self::ES_TAX_EXCEPTION_7 => 'es-tax-exception-7',
self::ES_TAX_EXCEPTION_14 => 'es-tax-exception-14',
self::ES_TAX_EXCEPTION_20 => 'es-tax-exception-20',
self::ES_TAX_EXCEPTION_21 => 'es-tax-exception-21',
self::ES_TAX_EXCEPTION_22 => 'es-tax-exception-22',
self::ES_TAX_EXCEPTION_23_24 => 'es-tax-exception-23-24',
self::ES_TAX_EXCEPTION_25 => 'es-tax-exception-25',
self::ES_TAX_EXCEPTION_68_70 => 'es-tax-exception-68-70',
self::ES_TAX_EXCEPTION_84 => 'es-tax-exception-84',
self::ES_TAX_EXCEPTION_OTHER => 'es-tax-exception-other',
self::ES_OTHER_NOT_SUBJECT => 'es-tax-exception-other-not-subject',
];

$all = array_merge($defaultValues, self::$values);
Expand All @@ -71,6 +75,12 @@ public static function all(): array
return $all;
}

public static function get(?string $key): ?string
{
$values = self::all();
return $values[$key] ?? null;
}

/**
* Checks if the operation and VAT exception combination is valid.
*
Expand All @@ -82,19 +92,19 @@ public static function isValidCombination(?string $operation, ?string $exception
{
$validMap = [
InvoiceOperation::INTRA_COMMUNITY => [
'sales' => [self::ES_TAX_EXCEPTION_E3, self::ES_TAX_EXCEPTION_E4, self::ES_TAX_EXCEPTION_E5, self::ES_TAX_EXCEPTION_N2],
'purchases' => [self::ES_TAX_EXCEPTION_PASSIVE_SUBJECT, self::ES_TAX_EXCEPTION_N1, self::ES_TAX_EXCEPTION_N2],
'sales' => [self::ES_TAX_EXCEPTION_22, self::ES_TAX_EXCEPTION_23_24, self::ES_TAX_EXCEPTION_25, self::ES_TAX_EXCEPTION_68_70],
'purchases' => [self::ES_TAX_EXCEPTION_84, self::ES_TAX_EXCEPTION_7, self::ES_TAX_EXCEPTION_68_70],
],
InvoiceOperation::INTRA_COMMUNITY_SERVICES => [
'sales' => [self::ES_TAX_EXCEPTION_N2],
'purchases' => [self::ES_TAX_EXCEPTION_PASSIVE_SUBJECT],
'sales' => [self::ES_TAX_EXCEPTION_68_70],
'purchases' => [self::ES_TAX_EXCEPTION_84],
],
InvoiceOperation::REVERSE_CHARGE => [
'sales' => [self::ES_TAX_EXCEPTION_PASSIVE_SUBJECT],
'purchases' => [self::ES_TAX_EXCEPTION_PASSIVE_SUBJECT],
'sales' => [self::ES_TAX_EXCEPTION_84],
'purchases' => [self::ES_TAX_EXCEPTION_84],
],
InvoiceOperation::EXPORT => [
'sales' => [self::ES_TAX_EXCEPTION_E2],
'sales' => [self::ES_TAX_EXCEPTION_21],
'purchases' => [],
],
InvoiceOperation::IMPORT => [
Expand All @@ -105,7 +115,7 @@ public static function isValidCombination(?string $operation, ?string $exception

// without operation: generic exceptions or null are allowed
if (empty($operation)) {
$allowed = [null, self::ES_TAX_EXCEPTION_E1, self::ES_TAX_EXCEPTION_E6, self::ES_TAX_EXCEPTION_N1, self::ES_TAX_EXCEPTION_N2, self::ES_TAX_EXCEPTION_PASSIVE_SUBJECT];
$allowed = [null, self::ES_TAX_EXCEPTION_20, self::ES_TAX_EXCEPTION_OTHER, self::ES_TAX_EXCEPTION_7, self::ES_TAX_EXCEPTION_68_70, self::ES_TAX_EXCEPTION_84];
return in_array($exception, $allowed);
}

Expand Down
Loading
Loading