Skip to main content

Overview

Every FacturaE invoice requires two parties: a seller (issuer) and a buyer (recipient). The Party class provides static constructors for companies and individuals, with fluent methods for addresses, contact info, and FACe administrative centers.

Creating Parties

Companies

Use Party::company() for legal entities:
use PhpFacturae\Party;

$company = Party::company(
    taxNumber: 'B12345678',
    name: 'Acme Corporation S.L.'
);
Tax numbers are automatically normalized (trimmed and uppercased). Spanish CIF/NIF validation is performed during invoice export.

Individuals

Use Party::person() for natural persons:
$person = Party::person(
    taxNumber: '12345678Z',
    name: 'John',
    firstSurname: 'Doe',
    lastSurname: 'Smith'  // Optional
);
The last surname is optional, but name and first surname are required for individuals.
In Spanish documents, individuals have separate fields for name (nombre), first surname (primer apellido), and second surname (segundo apellido). This follows Spanish naming conventions.

Address Configuration

Add a postal address to any party:
$party->address(
    street: 'Gran Via 1, 3rd Floor',
    postalCode: '28013',
    town: 'Madrid',
    province: 'Madrid',
    countryCode: 'ESP'  // Default: ESP
);
1

Street Address

Full street address including building, floor, door, etc.
'Calle Mayor 10, Piso 2, Puerta B'
2

Postal Code

Spanish postal codes are validated (5 digits). International codes are also supported.
postalCode: '28013'  // Spanish
postalCode: '75001'  // French (when countryCode: 'FRA')
3

Town and Province

Municipality and province names:
town: 'Madrid',
province: 'Madrid'
4

Country Code

ISO 3166-1 alpha-3 country code (default: ESP for Spain):
countryCode: 'ESP'  // Spain
countryCode: 'FRA'  // France
countryCode: 'DEU'  // Germany

Contact Information

Add communication details:
$party->email('[email protected]')
      ->phone('+34 91 123 4567')
      ->fax('+34 91 123 4568')
      ->website('https://example.com')
      ->contactPeople('John Doe, Accounting Department');
All contact fields are optional but recommended for better communication.

Trade Name

Set a commercial trading name different from the legal name:
$party->tradeName('Acme Tech');
Trade names are useful when the legal company name differs from the brand name used in commerce.

Administrative Centers (FACe)

For invoices submitted to Spanish public administrations via FACe, you must specify administrative centers:
$buyer = Party::company('Q2819002D', 'Ministerio de Hacienda')
    ->centre(
        role: '01',  // Fiscal
        code: 'L01281901',
        name: 'Oficina Contable'
    )
    ->centre(
        role: '02',  // Receptor
        code: 'L01281902', 
        name: 'Unidad Tramitadora'
    )
    ->centre(
        role: '03',  // Pagador
        code: 'L01281903',
        name: 'Oficina Gestora'
    );
FACe requires specific administrative center codes. Contact your buyer to obtain the correct codes for:
  • Role 01 (Fiscal): Accounting office code
  • Role 02 (Receptor): Processing unit code
  • Role 03 (Pagador): Payment office code

Multiple Centers

You can add multiple administrative centers by calling ->centre() multiple times:
$party->centre('01', 'L01281901', 'Primary Accounting Office')
      ->centre('02', 'L01281902', 'Processing Unit A')
      ->centre('02', 'L01281903', 'Processing Unit B');

Merchant Register Information

For companies, you can include commercial registry data:
$party->merchantRegister(
    register: 'Madrid',
    book: '1234',
    folio: '56',
    sheet: 'M-123456',
    section: '8',
    volume: '789'
);
All parameters are optional. Include only the fields that apply to your registration.
Merchant register information is required for certain invoice types and specific business regulations in Spain.

Economic Activity Codes

CNO/CNAE

Set the National Classification of Economic Activities code:
$party->cnoCnae('6201');  // Computer programming activities

INE Town Code

Set the National Statistics Institute town code:
$party->ineTownCode('28079');  // Madrid

Complete Example

Here’s a fully configured seller and buyer:
use PhpFacturae\Party;

// Seller (Service provider)
$seller = Party::company('B12345678', 'Tech Solutions S.L.')
    ->tradeName('TechSol')
    ->address(
        street: 'Calle Serrano 45, 2°B',
        postalCode: '28001',
        town: 'Madrid',
        province: 'Madrid',
        countryCode: 'ESP'
    )
    ->email('[email protected]')
    ->phone('+34 91 123 4567')
    ->website('https://techsol.es')
    ->cnoCnae('6201')
    ->merchantRegister(
        register: 'Madrid',
        book: '1234',
        sheet: 'M-123456',
        folio: '78',
        section: '8'
    );

// Buyer (Public administration)
$buyer = Party::company('Q2819002D', 'Ministerio de Hacienda y Administraciones Públicas')
    ->address(
        street: 'Calle Alcalá 5',
        postalCode: '28014',
        town: 'Madrid',
        province: 'Madrid'
    )
    ->centre('01', 'L01281901', 'Oficina Contable')
    ->centre('02', 'L01281902', 'Unidad Tramitadora')
    ->centre('03', 'L01281903', 'Oficina Gestora');

// Use in invoice
$invoice = Invoice::create('2024-001')
    ->seller($seller)
    ->buyer($buyer);

International Parties

For parties outside Spain:
$foreignBuyer = Party::company(
    taxNumber: 'FR12345678901',  // French SIRET
    name: 'Société Française SARL'
)
->address(
    street: '10 Avenue des Champs-Élysées',
    postalCode: '75008',
    town: 'Paris',
    province: 'Île-de-France',
    countryCode: 'FRA'  // Important: Set correct country
)
->email('[email protected]');
When dealing with international parties, always set the correct countryCode to ensure proper VAT treatment and validation.

Method Reference

Static Constructors

MethodParametersReturnsDescription
company()string $taxNumber, string $namePartyCreate legal entity
person()string $taxNumber, string $name, string $firstSurname, ?string $lastSurnamePartyCreate individual

Configuration Methods

MethodParametersReturnsDescription
address()string $street, string $postalCode, string $town, string $province, string $countryCode = 'ESP'selfSet postal address
tradeName()string $tradeNameselfSet commercial name
email()string $emailselfSet email address
phone()string $phoneselfSet phone number
fax()string $faxselfSet fax number
website()string $websiteselfSet website URL
contactPeople()string $valueselfSet contact person info
cnoCnae()string $valueselfSet economic activity code
ineTownCode()string $valueselfSet INE town code
centre()string $role, string $code, ?string $nameselfAdd administrative center
merchantRegister()?string $book, ?string $register, ?string $sheet, ?string $folio, ?string $section, ?string $volumeselfSet registry data

Source Reference

The complete Party class implementation:
  • src/Party.php:9-132 - Main Party class
  • src/Entities/Address.php - Address entity

Build docs developers (and LLMs) love