Skip to content

Commit 53a5b5a

Browse files
committed
Add new invoice fields and refactor AEAT client
Introduces new optional fields to the VeriFactuInvoice contract and Invoice model: operation_date, tax_period, correction_type, and external_reference. Refactors AeatClient to modularize SOAP request building, support the new fields, and improve testability. Adds a unit test to verify correct structure and field mapping in AEAT client requests.
1 parent 7fcf59b commit 53a5b5a

File tree

5 files changed

+372
-124
lines changed

5 files changed

+372
-124
lines changed

composer.json

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,58 @@
11
{
2-
"name": "squareetlabs/laravel-verifactu",
3-
"description": "Paquete Laravel para gestión y registro de facturación electrónica VeriFactu. Compatible con Laravel 10 a 12.x",
4-
"type": "library",
5-
"license": "MIT",
6-
"keywords": ["laravel", "verifactu", "facturacion electrónica"],
7-
"authors": [
8-
{
9-
"name": "Alberto Rial Barreiro",
10-
"email": "[email protected]",
11-
"homepage": "https://www.squareet.com",
12-
"role": "Developer"
13-
},
14-
{
15-
"name": "Jacobo Cantorna Cigarrán",
16-
"email": "[email protected]",
17-
"homepage": "https://www.squareet.com",
18-
"role": "Developer"
19-
}
20-
],
21-
"require": {
22-
"php": ">=8.1",
23-
"illuminate/support": "^10.0|^11.0|^12.0"
2+
"name": "squareetlabs/laravel-verifactu",
3+
"description": "Paquete Laravel para gestión y registro de facturación electrónica VeriFactu. Compatible con Laravel 10 a 12.x",
4+
"type": "library",
5+
"license": "MIT",
6+
"keywords": [
7+
"laravel",
8+
"verifactu",
9+
"facturacion electrónica"
10+
],
11+
"authors": [
12+
{
13+
"name": "Alberto Rial Barreiro",
14+
"email": "[email protected]",
15+
"homepage": "https://www.squareet.com",
16+
"role": "Developer"
2417
},
25-
"autoload": {
26-
"psr-4": {
27-
"Squareetlabs\\VeriFactu\\": "src/"
28-
}
29-
},
30-
"autoload-dev": {
31-
"psr-4": {
32-
"Tests\\": "tests/",
33-
"Database\\Factories\\": "database/factories/",
34-
"Database\\Factories\\Squareetlabs\\VeriFactu\\Models\\": "database/factories/Squareetlabs/VeriFactu/Models/"
35-
}
36-
},
37-
"extra": {
38-
"laravel": {
39-
"providers": [
40-
"Squareetlabs\\VeriFactu\\Providers\\VeriFactuServiceProvider"
41-
],
42-
"aliases": {
43-
"VeriFactu": "Squareetlabs\\VeriFactu\\Facades\\VeriFactu"
44-
}
45-
}
46-
},
47-
"minimum-stability": "dev",
48-
"prefer-stable": true,
49-
"require-dev": {
50-
"phpunit/phpunit": "^10.0|^11.5",
51-
"orchestra/testbench": "^8.0|^9.0|^10.4"
18+
{
19+
"name": "Jacobo Cantorna Cigarrán",
20+
"email": "[email protected]",
21+
"homepage": "https://www.squareet.com",
22+
"role": "Developer"
23+
}
24+
],
25+
"require": {
26+
"php": ">=8.1",
27+
"illuminate/support": "^10.0|^11.0|^12.0",
28+
"ext-soap": "*"
29+
},
30+
"autoload": {
31+
"psr-4": {
32+
"Squareetlabs\\VeriFactu\\": "src/"
33+
}
34+
},
35+
"autoload-dev": {
36+
"psr-4": {
37+
"Tests\\": "tests/",
38+
"Database\\Factories\\": "database/factories/",
39+
"Database\\Factories\\Squareetlabs\\VeriFactu\\Models\\": "database/factories/Squareetlabs/VeriFactu/Models/"
40+
}
41+
},
42+
"extra": {
43+
"laravel": {
44+
"providers": [
45+
"Squareetlabs\\VeriFactu\\Providers\\VeriFactuServiceProvider"
46+
],
47+
"aliases": {
48+
"VeriFactu": "Squareetlabs\\VeriFactu\\Facades\\VeriFactu"
49+
}
5250
}
51+
},
52+
"minimum-stability": "dev",
53+
"prefer-stable": true,
54+
"require-dev": {
55+
"phpunit/phpunit": "^10.0|^11.5",
56+
"orchestra/testbench": "^8.0|^9.0|^10.4"
57+
}
5358
}

src/Contracts/VeriFactuInvoice.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,33 @@ public function getPreviousHash(): ?string;
9393
* @return string
9494
*/
9595
public function getOperationDescription(): string;
96+
97+
/**
98+
* Get the operation date (if different from issue date)
99+
*
100+
* @return Carbon|null
101+
*/
102+
public function getOperationDate(): ?Carbon;
103+
104+
/**
105+
* Get the tax period (e.g., "01", "02", "0A")
106+
*
107+
* @return string|null
108+
*/
109+
public function getTaxPeriod(): ?string;
110+
111+
/**
112+
* Get the correction type (e.g., "S", "I")
113+
* Required for corrective invoices (R1-R5)
114+
*
115+
* @return string|null
116+
*/
117+
public function getCorrectionType(): ?string;
118+
119+
/**
120+
* Get the external reference (optional)
121+
*
122+
* @return string|null
123+
*/
124+
public function getExternalReference(): ?string;
96125
}

src/Models/Invoice.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ protected static function booted()
6363
'issued_at',
6464
'cancelled_at',
6565
'hash',
66+
'operation_date',
67+
'tax_period',
68+
'correction_type',
6669
];
6770

6871
protected $casts = [
6972
'date' => 'date',
73+
'operation_date' => 'date',
7074
'type' => InvoiceType::class,
7175
'amount' => 'decimal:2',
7276
'tax' => 'decimal:2',
@@ -139,4 +143,24 @@ public function getOperationDescription(): string
139143
{
140144
return $this->description ?? 'Invoice issued';
141145
}
146+
147+
public function getOperationDate(): ?Carbon
148+
{
149+
return $this->operation_date;
150+
}
151+
152+
public function getTaxPeriod(): ?string
153+
{
154+
return $this->tax_period;
155+
}
156+
157+
public function getCorrectionType(): ?string
158+
{
159+
return $this->correction_type;
160+
}
161+
162+
public function getExternalReference(): ?string
163+
{
164+
return $this->external_reference;
165+
}
142166
}

0 commit comments

Comments
 (0)