Skip to content
Draft
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ use eseperio\verifactu\models\enums\TaxType;
use eseperio\verifactu\models\enums\YesNoType;
use eseperio\verifactu\models\enums\HashType;
use eseperio\verifactu\models\enums\OperationQualificationType;
use eseperio\verifactu\models\enums\RegimeType;

// After calling Verifactu::config(...)

Expand All @@ -150,6 +151,7 @@ $invoice->invoiceWithoutRecipient = YesNoType::NO;
$breakdown = new Breakdown();
$detail = new BreakdownDetail();
$detail->taxType = TaxType::IVA;
$detail->regimeKey = RegimeType::GENERAL; // General regime operation
$detail->taxRate = 21.00;
$detail->taxableBase = 100.00;
$detail->taxAmount = 21.00;
Expand Down Expand Up @@ -609,6 +611,7 @@ The library uses enum classes for type-safe constants:
* **OperationQualificationType:** Tax operation qualifications
* **PeriodType:** Month or quarter periods
* **RectificationType:** Types of invoice rectifications
* **RegimeType:** Special regime keys for VAT (ClaveRegimen) - General regime, exports, travel agencies, cash basis, etc.
* **YesNoType:** Yes/No values for boolean fields
* **GeneratorType:** Invoice generator types
* **ThirdPartyOrRecipientType:** Types of third parties or recipients
Expand Down
11 changes: 9 additions & 2 deletions src/models/BreakdownDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use eseperio\verifactu\models\enums\ExemptOperationType;
use eseperio\verifactu\models\enums\OperationQualificationType;
use eseperio\verifactu\models\enums\RegimeType;
use eseperio\verifactu\models\enums\TaxType;

/**
Expand All @@ -24,7 +25,7 @@ class BreakdownDetail extends Model

/**
* Regime key (ClaveRegimen, optional).
* @var string|null
* @var RegimeType|null
*/
public $regimeKey;

Expand Down Expand Up @@ -83,7 +84,6 @@ public function rules(): array
{
return [
[['taxableBase'], 'required'],
[['regimeKey'], 'string'],
[['taxRate', 'taxableBase', 'costBasedTaxableBase', 'taxAmount', 'equivalenceSurchargeRate', 'equivalenceSurchargeAmount'], fn($value): bool|string => (is_null($value) || is_float($value) || is_int($value)) ? true : 'Must be a number or null.'],
[['operationQualification', 'exemptOperation'], function ($value, $model): string|bool {
// Either operationQualification or exemptOperation must be set
Expand All @@ -100,6 +100,13 @@ public function rules(): array

return ($value instanceof TaxType) ? true : 'Must be an instance of TaxType.';
}],
['regimeKey', function ($value): bool|string {
if ($value === null) {
return true;
}

return ($value instanceof RegimeType) ? true : 'Must be an instance of RegimeType.';
}],
['operationQualification', function ($value): bool|string {
if ($value === null) {
return true;
Expand Down
114 changes: 114 additions & 0 deletions src/models/enums/RegimeType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

declare(strict_types=1);

namespace eseperio\verifactu\models\enums;

/**
* Enumeration for Special Regime Keys or Additional Transcendence (ClaveRegimenType).
* Claves de Régimen Especial o Trascendencia Adicional.
*/
enum RegimeType: string
{
/**
* General regime operation.
* Operación de régimen general.
*/
case GENERAL = '01';

/**
* Export.
* Exportación.
*/
case EXPORT = '02';

/**
* Operations under the special regime for used goods, works of art, antiques and collectibles.
* Operaciones a las que se aplique el régimen especial de bienes usados, objetos de arte, antigüedades y objetos de colección.
*/
case USED_GOODS = '03';

/**
* Special regime for investment gold.
* Régimen especial del oro de inversión.
*/
case INVESTMENT_GOLD = '04';

/**
* Special regime for travel agencies.
* Régimen especial de las agencias de viajes.
*/
case TRAVEL_AGENCIES = '05';

/**
* Special regime for groups of entities in VAT (Advanced Level).
* Régimen especial grupo de entidades en IVA (Nivel Avanzado).
*/
case ENTITY_GROUPS = '06';

/**
* Special regime for cash basis accounting.
* Régimen especial del criterio de caja.
*/
case CASH_BASIS = '07';

/**
* Operations subject to IPSI / IGIC (Tax on Production, Services and Imports / Canary Islands General Indirect Tax).
* Operaciones sujetas al IPSI / IGIC (Impuesto sobre la Producción, los Servicios y la Importación / Impuesto General Indirecto Canario).
*/
case IPSI_IGIC = '08';

/**
* Invoicing of travel agency services acting as intermediaries on behalf and for the account of others (D.A 4ª RD1619/2012).
* Facturación de las prestaciones de servicios de agencias de viaje que actúan como mediadoras en nombre y por cuenta ajena (D.A 4ª RD1619/2012).
*/
case TRAVEL_AGENCY_INTERMEDIARY = '09';

/**
* Collections on behalf of third parties for professional fees or rights derived from industrial property, copyright or other rights on behalf of their members, associates or members made by companies, associations, professional associations or other entities that perform these collection functions.
* Cobros por cuenta de terceros de honorarios profesionales o de derechos derivados de la propiedad industrial, de autor u otros por cuenta de sus socios, asociados o colegiados efectuados por sociedades, asociaciones, colegios profesionales u otras entidades que realicen estas funciones de cobro.
*/
case THIRD_PARTY_COLLECTIONS = '10';

/**
* Business premises rental operations.
* Operaciones de arrendamiento de local de negocio.
*/
case BUSINESS_RENTAL = '11';

/**
* Invoice with VAT pending accrual in work certifications whose recipient is a Public Administration.
* Factura con IVA pendiente de devengo en certificaciones de obra cuyo destinatario sea una Administración Pública.
*/
case PENDING_VAT_PUBLIC_WORKS = '14';

/**
* Invoice with VAT pending accrual in successive tract operations.
* Factura con IVA pendiente de devengo en operaciones de tracto sucesivo.
*/
case PENDING_VAT_SUCCESSIVE = '15';

/**
* Operation covered by one of the regimes provided for in Chapter XI of Title IX (OSS and IOSS).
* Operación acogida a alguno de los regímenes previstos en el Capítulo XI del Título IX (OSS e IOSS).
*/
case OSS_IOSS = '17';

/**
* Equivalence surcharge.
* Recargo de equivalencia.
*/
case EQUIVALENCE_SURCHARGE = '18';

/**
* Operations of activities included in the Special Regime for Agriculture, Livestock and Fishing (REAGYP).
* Operaciones de actividades incluidas en el Régimen Especial de Agricultura, Ganadería y Pesca (REAGYP).
*/
case AGRICULTURE_LIVESTOCK_FISHING = '19';

/**
* Simplified regime.
* Régimen simplificado.
*/
case SIMPLIFIED = '20';
}
4 changes: 2 additions & 2 deletions src/services/InvoiceSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ public static function toInvoiceXml(InvoiceSubmission $invoice, bool $validate =
}

// ClaveRegimen (optional)
if (!empty($detail->regimeKey)) {
$detalleDesglose->appendChild($doc->createElementNS(self::SF_NAMESPACE, 'sf:ClaveRegimen', (string) $detail->regimeKey));
if ($detail->regimeKey) {
$detalleDesglose->appendChild($doc->createElementNS(self::SF_NAMESPACE, 'sf:ClaveRegimen', (string) $detail->regimeKey->value));
}

// Either CalificacionOperacion or OperacionExenta (one is required)
Expand Down