Skip to main content
The Invoice class is the core component of PHP FacturaE. It provides a fluent interface for building electronic invoices compliant with the Spanish FacturaE format.

Creating an Invoice

create()

Create a new invoice instance.
number
string
required
The invoice number
return
Invoice
Returns a new Invoice instance
$invoice = Invoice::create('INV-2024-001');

Core Properties

series()

Set the invoice series.
series
string
required
The invoice series identifier
return
Invoice
Returns self for method chaining
$invoice->series('A');

date()

Set the invoice issue date.
date
string|DateTimeImmutable
required
The issue date. Can be a date string (parsed by DateTimeImmutable) or a DateTimeImmutable object
return
Invoice
Returns self for method chaining
$invoice->date('2024-01-15');
$invoice->date(new DateTimeImmutable('2024-01-15'));

operationDate()

Set the operation date (when the transaction occurred).
date
string|DateTimeImmutable
required
The operation date
return
Invoice
Returns self for method chaining
$invoice->operationDate('2024-01-15');

billingPeriod()

Set the billing period for the invoice.
from
string|DateTimeImmutable
required
Start date of the billing period
to
string|DateTimeImmutable
required
End date of the billing period
return
Invoice
Returns self for method chaining
$invoice->billingPeriod('2024-01-01', '2024-01-31');

schema()

Set the FacturaE schema version.
schema
Schema
required
The schema version enum value
return
Invoice
Returns self for method chaining
use PhpFacturae\Enums\Schema;

$invoice->schema(Schema::V3_2_2);

type()

Set the invoice type.
type
InvoiceType
required
The invoice type enum value
return
Invoice
Returns self for method chaining
use PhpFacturae\Enums\InvoiceType;

$invoice->type(InvoiceType::Full);

currency()

Set the invoice currency.
currency
string
required
ISO 4217 currency code (default: ‘EUR’)
return
Invoice
Returns self for method chaining
$invoice->currency('EUR');

description()

Set the invoice description.
description
string
required
Invoice description
return
Invoice
Returns self for method chaining
$invoice->description('Servicios de consultoría enero 2024');

Parties

seller()

Set the seller (supplier) party.
seller
Party
required
The seller Party instance
return
Invoice
Returns self for method chaining
$seller = Party::company('B12345678', 'Mi Empresa SL')
    ->address('Calle Mayor 1', '28001', 'Madrid', 'Madrid');

$invoice->seller($seller);

buyer()

Set the buyer (customer) party.
buyer
Party
required
The buyer Party instance
return
Invoice
Returns self for method chaining
$buyer = Party::company('B87654321', 'Cliente SA')
    ->address('Gran Vía 10', '28013', 'Madrid', 'Madrid');

$invoice->buyer($buyer);

Invoice Lines

line()

Add a standard invoice line with Spanish tax shortcuts.
description
string
required
Line item description
price
float
required
Unit price (without taxes)
quantity
float
default:"1"
Quantity
vat
float|null
VAT (IVA) rate percentage
irpf
float|null
Income tax withholding (IRPF) rate percentage
igic
float|null
Canary Islands tax (IGIC) rate percentage
surcharge
float|null
Equivalence surcharge rate percentage
ie
float|null
Special tax (IE) rate percentage
ieWithheld
bool
default:"false"
Whether special tax is withheld
discount
float|null
Line discount amount
articleCode
string|null
Product/article code
detailedDescription
string|null
Additional detailed description
unit
UnitOfMeasure|null
Unit of measure enum value
return
Invoice
Returns self for method chaining
// Standard line with VAT
$invoice->line('Lámpara LED', quantity: 3, price: 20.14, vat: 21);

// Service with VAT and IRPF withholding
$invoice->line('Consultoría', price: 500, vat: 21, irpf: 15);

// Canary Islands product with IGIC
$invoice->line('Producto Canarias', price: 100, igic: 7);

// Jewelry with equivalence surcharge
$invoice->line('Joyería', price: 200, vat: 21, surcharge: 5.2);

// Electricity with custom unit
$invoice->line('Electricidad', price: 80, vat: 21, unit: UnitOfMeasure::KWh);

exemptLine()

Add a tax-exempt line with exemption reason.
description
string
required
Line item description
price
float
required
Unit price
quantity
float
default:"1"
Quantity
reason
string|null
Tax exemption reason (e.g., legal article reference)
discount
float|null
Line discount amount
articleCode
string|null
Product/article code
unit
UnitOfMeasure|null
Unit of measure enum value
return
Invoice
Returns self for method chaining
$invoice->exemptLine(
    'Formación FUNDAE',
    price: 2000,
    reason: 'Exenta art. 20 LIVA'
);

customLine()

Add a line with custom tax configuration.
description
string
required
Line item description
price
float
required
Unit price
taxes
TaxBreakdown[]
required
Array of TaxBreakdown objects
quantity
float
default:"1"
Quantity
discount
float|null
Line discount amount
articleCode
string|null
Product/article code
unit
UnitOfMeasure|null
Unit of measure enum value
specialTaxableEvent
SpecialTaxableEvent|null
Special taxable event enum value
specialTaxableEventReason
string|null
Reason for special taxable event
return
Invoice
Returns self for method chaining
use PhpFacturae\Entities\TaxBreakdown;
use PhpFacturae\Enums\Tax;

$taxes = [
    new TaxBreakdown(Tax::IVA, 21),
    new TaxBreakdown(Tax::IRPF, 15),
];

$invoice->customLine('Servicio profesional', price: 1000, taxes: $taxes);

Payments

payment()

Add a custom payment object.
payment
Payment
required
Payment entity instance
return
Invoice
Returns self for method chaining
use PhpFacturae\Entities\Payment;
use PhpFacturae\Enums\PaymentMethod;

$payment = new Payment(
    method: PaymentMethod::Transfer,
    dueDate: new DateTimeImmutable('2024-02-15'),
    iban: 'ES7921000813610123456789'
);

$invoice->payment($payment);

transferPayment()

Add a bank transfer payment.
iban
string
required
Bank account IBAN
dueDate
string|null
Payment due date
amount
float|null
Payment amount (null for full invoice amount)
return
Invoice
Returns self for method chaining
$invoice->transferPayment(
    iban: 'ES7921000813610123456789',
    dueDate: '2024-02-15'
);

cashPayment()

Add a cash payment.
dueDate
string|null
Payment due date
amount
float|null
Payment amount (null for full invoice amount)
return
Invoice
Returns self for method chaining
$invoice->cashPayment();

cardPayment()

Add a card payment.
dueDate
string|null
Payment due date
amount
float|null
Payment amount (null for full invoice amount)
return
Invoice
Returns self for method chaining
$invoice->cardPayment();

directDebitPayment()

Add a direct debit payment.
iban
string
required
Bank account IBAN for direct debit
dueDate
string|null
Payment due date
amount
float|null
Payment amount (null for full invoice amount)
return
Invoice
Returns self for method chaining
$invoice->directDebitPayment(
    iban: 'ES7921000813610123456789',
    dueDate: '2024-02-15'
);

splitPayments()

Split payment into multiple installments.
method
PaymentMethod
required
Payment method enum value
installments
int
required
Number of installments
firstDueDate
string
required
Due date for the first installment
intervalDays
int
default:"30"
Days between each installment
iban
string|null
Bank account IBAN (required for Transfer and DirectDebit)
return
Invoice
Returns self for method chaining
use PhpFacturae\Enums\PaymentMethod;

$invoice->splitPayments(
    method: PaymentMethod::Transfer,
    installments: 3,
    firstDueDate: '2024-02-15',
    intervalDays: 30,
    iban: 'ES7921000813610123456789'
);

Corrective Invoices

corrects()

Mark this invoice as a correction of another invoice.
invoiceNumber
string
required
Number of the invoice being corrected
reason
CorrectionReason
default:"CorrectionReason::TransactionDetail"
Reason for the correction
method
CorrectionMethod
default:"CorrectionMethod::FullReplacement"
Correction method
series
string|null
Series of the invoice being corrected
periodStart
string|DateTimeImmutable|null
Start of correction period
periodEnd
string|DateTimeImmutable|null
End of correction period
return
Invoice
Returns self for method chaining
use PhpFacturae\Enums\CorrectionReason;
use PhpFacturae\Enums\CorrectionMethod;

$invoice->corrects(
    invoiceNumber: 'INV-2024-001',
    reason: CorrectionReason::TransactionDetail,
    method: CorrectionMethod::FullReplacement
);

legalLiteral()

Add a legal literal text to the invoice.
literal
string
required
Legal text to include
return
Invoice
Returns self for method chaining
$invoice->legalLiteral('Factura acogida al régimen especial de criterio de caja');

Discounts & Charges

generalDiscount()

Add a general discount at invoice level.
reason
string
required
Reason for the discount
rate
float|null
Discount rate percentage
amount
float|null
Fixed discount amount
return
Invoice
Returns self for method chaining
// Fixed amount discount
$invoice->generalDiscount('Descuento cliente VIP', amount: 50.00);

// Percentage discount
$invoice->generalDiscount('10% pronto pago', rate: 10);

generalCharge()

Add a general charge at invoice level.
reason
string
required
Reason for the charge
rate
float|null
Charge rate percentage
amount
float|null
Fixed charge amount
return
Invoice
Returns self for method chaining
$invoice->generalCharge('Portes', amount: 15.00);

Attachments

attach()

Attach a file to the invoice.
attachment
Attachment
required
Attachment entity instance
return
Invoice
Returns self for method chaining
use PhpFacturae\Entities\Attachment;

$attachment = Attachment::fromFile('/path/to/contract.pdf', 'Contrato firmado');
$invoice->attach($attachment);

attachFile()

Attach a file directly from a file path.
path
string
required
Path to the file
description
string
required
Description of the attachment
mimeType
string|null
MIME type (auto-detected if null)
return
Invoice
Returns self for method chaining
$invoice->attachFile('/path/to/contract.pdf', 'Contrato firmado');

Signing

sign()

Set the signer for the invoice.
signer
InvoiceSigner
required
Signer implementation (e.g., Pkcs12Signer)
return
Invoice
Returns self for method chaining
$invoice->sign(Signer::pfx('cert.pfx', 'password'));

Output

toXml()

Generate the FacturaE XML string.
return
string
XML string of the invoice
throws
InvoiceValidationException
If the invoice fails validation
try {
    $xml = $invoice->toXml();
    echo $xml;
} catch (InvoiceValidationException $e) {
    print_r($e->getErrors());
}

export()

Export the invoice to an XML file.
path
string
required
File path where the XML will be saved
return
Invoice
Returns self for method chaining
throws
InvoiceValidationException
If the invoice fails validation
$invoice->export('/path/to/invoice.xml');

Build docs developers (and LLMs) love