# 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

MethodParametersDescription
create()string $numberStatic constructor
series()string $seriesSet series
date()string|DateTimeImmutable $dateIssue date
operationDate()string|DateTimeImmutable $dateOperation date
billingPeriod()$from, $toBilling period
schema()Schema $schemaFacturaE version
type()InvoiceType $typeInvoice type
currency()string $currencyCurrency (ISO 4217)
description()string $descriptionDescription
seller()Party $sellerSeller
buyer()Party $buyerBuyer
line()See Lines and taxesAdd line
exemptLine()See Lines and taxesExempt line
customLine()See Lines and taxesLine with custom taxes
transferPayment()string $iban, ?string $dueDate, ?float $amountWire transfer payment
cashPayment()?string $dueDate, ?float $amountCash payment
cardPayment()?string $dueDate, ?float $amountCard payment
directDebitPayment()string $iban, ?string $dueDate, ?float $amountDirect debit
splitPayments()See PaymentsSplit payments
sign()InvoiceSigner $signerSign invoice
toXml()Generate XML
export()string $pathExport to file