# Invoice
The Invoice class is the heart of PHP FacturaE. It provides a fluent API to build compliant FacturaE XML documents with automatic validation, tax calculation and digital signature.
Create an invoice
use PhpFacturae\Invoice;
$invoice = Invoice::create('2024-001') ->date('2024-03-09') ->seller($seller) ->buyer($buyer) ->line('Service', price: 100, vat: 21) ->transferPayment('ES12 3456 7890 1234 5678 9012');Basic configuration
Series and dates:
$invoice->series('A') ->date('2024-03-09') ->operationDate('2024-03-01') ->billingPeriod(from: '2024-03-01', to: '2024-03-31');Schema and type:
use PhpFacturae\Enums\Schema;use PhpFacturae\Enums\InvoiceType;
$invoice->schema(Schema::V3_2_2) ->type(InvoiceType::Full);Schema versions: V3_2, V3_2_1, V3_2_2 (default).
Invoice types: Full (FC), Simplified (FA), SimplifiedRectified (AF).
Currency and description:
$invoice->currency('EUR') ->description('Monthly consulting services');General discounts and charges
$invoice->generalDiscount('VIP customer discount', rate: 10);$invoice->generalDiscount('Early payment', amount: 50.00);$invoice->generalCharge('Shipping costs', amount: 15.00);Corrective invoices
use PhpFacturae\Enums\CorrectionReason;use PhpFacturae\Enums\CorrectionMethod;
$invoice->corrects( invoiceNumber: '2024-001', reason: CorrectionReason::TransactionDetail, method: CorrectionMethod::FullReplacement, series: 'A');Attachments
$invoice->attachFile('/path/to/contract.pdf', 'Signed contract');Export to XML
$xml = $invoice->toXml();$invoice->export('/path/to/invoice.xml');Digital signature
use PhpFacturae\Signer;
$invoice->sign(Signer::pfx('certificate.pfx', 'password')) ->export('signed-invoice.xml');Method reference
| Method | Parameters | Description |
|---|---|---|
create() | string $number | Static constructor |
series() | string $series | Set series |
date() | string|DateTimeImmutable $date | Issue date |
operationDate() | string|DateTimeImmutable $date | Operation date |
billingPeriod() | $from, $to | Billing period |
schema() | Schema $schema | FacturaE version |
type() | InvoiceType $type | Invoice type |
currency() | string $currency | Currency (ISO 4217) |
description() | string $description | Description |
seller() | Party $seller | Seller |
buyer() | Party $buyer | Buyer |
line() | See Lines and taxes | Add line |
exemptLine() | See Lines and taxes | Exempt line |
customLine() | See Lines and taxes | Line with custom taxes |
transferPayment() | string $iban, ?string $dueDate, ?float $amount | Wire transfer payment |
cashPayment() | ?string $dueDate, ?float $amount | Cash payment |
cardPayment() | ?string $dueDate, ?float $amount | Card payment |
directDebitPayment() | string $iban, ?string $dueDate, ?float $amount | Direct debit |
splitPayments() | See Payments | Split payments |
sign() | InvoiceSigner $signer | Sign invoice |
toXml() | — | Generate XML |
export() | string $path | Export to file |