Skip to main content
The Line entity represents a single line item on an invoice. Each line includes a description, quantity, unit price, applicable taxes, and optional details like discounts and article codes.

Constructor

new Line(
    string $description,
    float $quantity,
    float $unitPrice,
    array $taxes = [],
    ?string $articleCode = null,
    ?float $discount = null,
    ?string $detailedDescription = null,
    ?UnitOfMeasure $unitOfMeasure = null,
    ?SpecialTaxableEvent $specialTaxableEvent = null,
    ?string $specialTaxableEventReason = null
)

Parameters

description
string
required
Short description of the product or service
quantity
float
required
Quantity of items
unitPrice
float
required
Unit price without taxes (precio unitario sin impuestos)
taxes
TaxBreakdown[]
default:"[]"
Array of tax breakdowns to apply to this line. See TaxBreakdown
articleCode
string|null
default:"null"
Product or article code for identification
discount
float|null
default:"null"
Discount percentage (0-100). For example, 10 represents a 10% discount
detailedDescription
string|null
default:"null"
Extended description with additional details
unitOfMeasure
UnitOfMeasure|null
default:"null"
Unit of measure for the quantity. See UnitOfMeasure
specialTaxableEvent
SpecialTaxableEvent|null
default:"null"
Special tax treatment code. See SpecialTaxableEvent
specialTaxableEventReason
string|null
default:"null"
Reason for the special tax treatment (motivo de la fiscalidad especial)

Properties

All constructor parameters are exposed as public readonly properties:
description
string
Short description of the product or service
quantity
float
Quantity of items
unitPrice
float
Unit price without taxes
taxes
TaxBreakdown[]
Array of tax breakdowns
articleCode
string|null
Product or article code
discount
float|null
Discount percentage
detailedDescription
string|null
Extended description
unitOfMeasure
UnitOfMeasure|null
Unit of measure
specialTaxableEvent
SpecialTaxableEvent|null
Special tax treatment code
specialTaxableEventReason
string|null
Reason for special tax treatment

Methods

grossAmount()

Calculates the gross amount for this line (quantity × price - discount).
public function grossAmount(): float
Returns: The gross amount rounded to 2 decimal places

Example Usage

Basic Line Item

use PhpFacturae\Entities\Line;
use PhpFacturae\Entities\TaxBreakdown;
use PhpFacturae\Enums\Tax;

$line = new Line(
    description: 'Web Development Services',
    quantity: 10,
    unitPrice: 50.00,
    taxes: [
        new TaxBreakdown(Tax::IVA, 21),
    ]
);

echo $line->grossAmount(); // 500.00

Line with Discount

$line = new Line(
    description: 'Premium Support Package',
    quantity: 1,
    unitPrice: 1000.00,
    taxes: [
        new TaxBreakdown(Tax::IVA, 21),
    ],
    discount: 10 // 10% discount
);

echo $line->grossAmount(); // 900.00

Detailed Line Item

use PhpFacturae\Enums\UnitOfMeasure;

$line = new Line(
    description: 'Organic Olive Oil',
    quantity: 24,
    unitPrice: 8.50,
    taxes: [
        new TaxBreakdown(Tax::IVA, 10),
    ],
    articleCode: 'OLV-001',
    detailedDescription: 'Extra virgin olive oil from Andalusia, 1L bottles',
    unitOfMeasure: UnitOfMeasure::Bottles,
    discount: 5
);

Line with Special Tax Treatment

use PhpFacturae\Enums\SpecialTaxableEvent;

$line = new Line(
    description: 'Educational Services',
    quantity: 1,
    unitPrice: 500.00,
    taxes: [],
    specialTaxableEvent: SpecialTaxableEvent::Exempt,
    specialTaxableEventReason: 'Article 20.1.9 - Educational services'
);

Build docs developers (and LLMs) love