ConsoleTVs/Invoices
Über uns
PDF-Rechnungen für Ihre Kunden in Laravel erstellen.
Web- und App-EntwicklungWhat you can do
- Invoices, quotes, receipts, credit notes and proforma invoices, with the right headings and date labels.
- Tax rates (percentage or fixed), discounts and extra charges such as delivery, with a documented calculation order.
- Exact money math with half-up rounding, also beyond float precision.
- Returns a download or inline response, attaches to Mailables and notifications, saves to any filesystem disk and previews as HTML.
Gemessener Sternzuwachs
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- -1
- in 1 month
- Verlauf wird gesammelt
Nettoänderungen in überlappenden Zeiträumen, keine Tagessummen. Fehlende Messwerte bleiben leer. Sterne zeigen Interesse, nicht Qualität.
README.md
OriginalInvoices
PDF invoices, quotes, receipts and credit notes for Laravel. Fluent API, exact money math, eight languages.
Invoices builds a PDF document from a chain of method calls: customer, items, taxes, discounts, delivery fees. Blade renders the template and dompdf turns it into a PDF that you can return from a controller, attach to an email or save to a disk. Every amount is a decimal string, never a float, so the numbers on the paper always add up.
Features
- Invoices, quotes, receipts, credit notes and proforma invoices, with the right headings and date labels.
- Tax rates (percentage or fixed), discounts and extra charges such as delivery, with a documented calculation order.
- Exact money math with half-up rounding, also beyond float precision.
- Returns a download or inline response, attaches to Mailables and notifications, saves to any filesystem disk and previews as HTML.
- Translated into English, Spanish, Catalan, French, German, Italian, Portuguese and Dutch; locale aware dates and currency formatting.
- Right to left layout, status stamps (
PAID,VOID, or your own text), logos, item images, repeated headers and page numbers. - Small PDFs by default (the Helvetica core font), any font installed in dompdf on request.
- Secure dompdf configuration: no PHP in templates, files restricted to a chroot, remote hosts allow list.
- Natively typed (PHP 8.4), PHPStan level 9.
Requirements
- PHP 8.4 or newer and the
bcmathextension - Laravel 12 or 13
- Recommended:
ext-intl, for locale aware currency formatting - To attach invoices to emails:
illuminate/mail(already there in any Laravel application)
Installation
composer require consoletvs/invoices:^2.0
The service provider is discovered automatically. Everything has a default, so you can start right away. Publish what you want to change:
php artisan vendor:publish --tag=invoices-config # config/invoices.php
php artisan vendor:publish --tag=invoices-views # resources/views/vendor/invoices
php artisan vendor:publish --tag=invoices-translations # lang/vendor/invoices
php artisan vendor:publish --tag=invoices # all three
Coming from 1.x? Read UPGRADE.md.
Quick start
use Carbon\Carbon;
use ConsoleTVs\Invoices\Invoice;
$invoice = Invoice::make()
->number(4021)
->customer([
'name' => 'Jane Doe',
'id' => '12345678A',
'phone' => '+34 123 456 789',
'address' => 'C / Unknown Street 1st',
'zip' => '08241',
'city' => 'Manresa',
'country' => 'Spain',
])
->addItem('Test Item', 10.25, 2, 1412)
->addItem('Test Item 2', 5, 2, 923, description: 'With a description')
->addItem('Test Item 3', 5, 2, 924, 'https://dummyimage.com/64x64/000/fff')
->taxRate('VAT', 21)
->dueDate(Carbon::now()->addMonth())
->notes('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
$invoice->total(); // "49.01", amounts are decimal strings
Return it from a controller, and the browser shows the PDF:
Route::get('/invoices/{id}', fn () => $invoice); // inline PDF response
Invoice::make() is also available through the ConsoleTVs\Invoices\Facades\Invoice facade (use ConsoleTVs\Invoices\Facades\Invoice;; no global alias is registered, so it cannot clash with your own Invoice model)
and the InvoiceFactory container binding. The usual Laravel helpers work: ->when($condition, fn ($invoice) => ...),
->tap() and Invoice::macro().
Output
| Call | Result |
|---|---|
return $invoice; |
Inline PDF response (the invoice is Responsable). |
$invoice->show() or ->stream() |
The same, explicitly. |
$invoice->download() |
A response that makes the browser download the file. |
$invoice->output() |
The raw PDF bytes (a string). |
$invoice->save('invoices/2026-001.pdf', 's3') |
Writes to a filesystem disk, returns the bool of Storage::put(). |
$invoice->toHtml() |
The rendered Blade template, see Preview in the browser. |
download() and show() return an Illuminate\Http\Response, not a stream: middleware, ->header() and
->withCookie() all keep working. The response carries Content-Type: application/pdf, Content-Length and a
Content-Disposition that is safe for non-ASCII names.
File name
$invoice->filename('invoice-2026-001'); // .pdf is appended when missing
return $invoice->download(); // invoice-2026-001.pdf
return $invoice->download('Q3 report'); // an argument wins: Q3 report.pdf
Without a name, the default is a slug of the heading and the number: invoice-4021.pdf, factura-4021.pdf for a Spanish
invoice. $invoice->pdfFilename() returns the final name.
Email attachments
The invoice is Illuminate\Contracts\Mail\Attachable, so it can be attached anywhere Laravel takes an attachment. The
PDF is rendered when the message is built, with the file name above.
use Illuminate\Mail\Mailable;
class InvoiceMail extends Mailable
{
public function __construct(private Invoice $invoice) {}
public function attachments(): array
{
return [$this->invoice];
}
}
// or on the fly, in a Mailable or in a notification's MailMessage:
return (new MailMessage)->subject('Your invoice')->attach($invoice);
In tests, send the mail through the array mailer and read the attachment from the message. Do not compare PDF bytes:
every render contains a creation timestamp, so assertHasAttachment() cannot match.
Preview in the browser
toHtml() returns the template as HTML in the invoice locale, without building the PDF. It is much faster, handy for
styling a published template and for tests (expect($invoice->toHtml())->toContain('Widget')).
Route::get('/invoices/{id}/preview', fn () => Invoice::make()->addItem('Widget', 10)->toHtml());
What you see in the browser is close to the PDF but not identical: dompdf supports a subset of CSS 2.1. Check the PDF before shipping a template change.
Items, parties and numbers
$invoice->addItem('Widget', 10.25, 2, 'SKU-1', 'img/widget.png', 'Blue one'); // name, price, quantity, id, image, description
$invoice->addItem(new Item('Gadget', 3));
$invoice->addItem(['name' => 'Gizmo', 'price' => '4.10', 'quantity' => 3]);
$invoice->addItems($rows);
$invoice->popItem();
$invoice->business(['name' => 'Acme Inc', 'id' => 'B12345678', 'extra' => ['IBAN ES00 0000 0000 0000 0000 0000']]);
$invoice->customer(Party::fromArray([...]));
business() defaults to invoices.business_details. A party has name, id, phone, email, address, zip,
city, country and extra (a list of free form lines); blank fields are not printed. The label in front of the id
is translated (ID: 12345678A, see Translations).
Prices and quantities can be ints, floats or plain decimal strings ('8333.325'). Strings with thousands separators
('8,333.325') throw InvalidNumber (an InvalidArgumentException) on purpose: guessing between a decimal comma and
a thousands comma silently misprices an invoice. The columns for images and ids only appear when at least one item has
one.
How the total is calculated
Everything is derived from the items on every call, so the order of the setters never matters. The steps, in order:
- Subtotal: the sum of the line totals (
price * quantity, each rounded half-up todecimals). - Minus the discounts. Every discount is calculated on the subtotal (they do not compound) and rounded.
- Plus the taxable fees. The result is the tax base.
- Plus the taxes. A percentage tax is a percentage of the tax base, a fixed tax is added as is; each is rounded.
- Plus the fees that are not taxable. The result is the total.
Every number is rounded when it is created and the totals are sums of rounded numbers, so the lines printed on the PDF add up to the total exactly. Nothing goes through a float: values beyond float precision keep every digit.
$invoice = Invoice::make()
->addItem('Item', '33.33')
->discount('Early payment', 10) // 3.333 rounds to 3.33
->fee('Delivery', '1.005') // 1.01, taxable
->fee('Deposit', 2.5, taxable: false)
->taxRate('VAT', 21); // 21% of 31.01 = 6.5121, rounds to 6.51
$invoice->subtotal(); // "33.33"
$invoice->discountTotal(); // "3.33"
$invoice->feeTotal(); // "3.51"
$invoice->taxBase(); // "31.01" 33.33 - 3.33 + 1.01
$invoice->taxTotal(); // "6.51"
$invoice->total(); // "40.02" 31.01 + 6.51 + 2.50
Discounts are not capped: a discount larger than the subtotal gives a negative base. Discounts and fees take positive
amounts (InvalidAdjustment otherwise); a fee cannot be negative, use a discount instead.
Tax rates
$invoice->taxRates([
TaxRate::percentage('VAT', 21),
['name' => 'Shipping', 'tax' => 5, 'tax_type' => 'fixed'],
]);
$invoice->taxRate('Handling', 2.5, TaxType::Fixed); // add to the existing ones
$invoice->taxRates([]); // no taxes
taxRate() appends to the rates already present, including the ones from invoices.tax_rates. An invoice without
tax rates prints no tax row.
Discounts
$invoice->discount('Early payment', 10); // 10% of the subtotal
$invoice->discount('Voucher', 5, TaxType::Fixed); // 5.00
$invoice->discount(Discount::percentage('Loyalty', 2.5));
Discounts print as negative lines under the subtotal. When there are discounts or taxable fees, a "Tax base" line shows what the taxes are calculated on.
Fees
$invoice->fee('Delivery', 4.90); // taxable: part of the tax base
$invoice->fee('Deposit', 20, taxable: false); // added after the taxes
Decimals and currency
$invoice->currency('USD'); // ISO 4217 code, see resources/currencies.json
$invoice->decimals(3); // 0 to 20, every rounding step and the printed amounts
Document types
Invoice::make(); // "Invoice" (the default)
Invoice::quote(); // "Quote", and "Valid until" instead of "Due date"
Invoice::receipt(); // "Receipt", "Payment date" and no due date
Invoice::creditNote(); // "Credit note"
Invoice::proforma(); // "Proforma invoice"
Invoice::make()->type(DocumentType::Quote);
Invoice::quote('Offer 12'); // an explicit heading wins over the type
The type changes the default heading and the date labels (quotes say "Valid until", receipts print "Payment date" and no due date), all translated. The calculations are the same for every type: a credit note is an invoice you build with the refunded lines.
Status stamp
$invoice->paid(); // a rotated, semi-transparent "PAID" on every page, translated (PAGADA, PAYÉE, ...)
$invoice->void();
$invoice->stamp('OVERDUE'); // free text, printed as given
$invoice->stamp(null); // remove
Translations
Every label of the default template is translated; English, Spanish, Catalan, French, German, Italian, Portuguese and
Dutch ship with the package (lang/<locale>/invoice.php, namespace invoices::invoice).
$invoice->locale('es'); // labels, dates and numbers of this invoice
Without locale(), the application locale at the moment of rendering is used. The locale is applied only while the
document renders and the application locale is restored afterwards, also when rendering fails. A locale without
translations falls back to your app.fallback_locale.
To change a text or add a language, publish the translations and edit or add files:
php artisan vendor:publish --tag=invoices-translations
# lang/vendor/invoices/pt_BR/invoice.php
Dates
Dates are printed with Carbon's isoFormat using the date_format config key (default dddd D MMMM YYYY) in the
invoice locale: miércoles 4 marzo 2026. Use L or LL for each language's own short and long forms. date() and
dueDate() accept any DateTimeInterface; the default due date is +3 months and dueDate(null) removes it.
Currency formatting
With ext-intl installed (composer suggest), amounts are formatted with Illuminate\Support\Number::currency() in the
invoice locale: $12,345.50 in English, 12.345,50 € in Spanish, always with the invoice decimals. Without it, the
exact formatter prints 12,345.50 € whatever the locale.
Number::currency() only accepts floats. The package rounds the decimal string first and uses Number only when the
amount has at most 15 significant digits, which a float holds exactly. Bigger amounts are printed by the exact
formatter (English style, every digit) so that no digit is ever lost. $invoice->money($amount) is the method the
template calls; $invoice->format($amount) is the plain exact number without a currency.
Fonts and right to left
$invoice->font('DejaVu Sans'); // or 'font' => 'DejaVu Sans' in config/invoices.php
The default font is Helvetica, one of the PDF core fonts: nothing is embedded, so a typical invoice is under 10 KB
instead of 30 KB or more. It covers Latin alphabets (Western European languages, including the euro sign), and not
Cyrillic, Greek, Arabic, Hebrew, Chinese, Japanese or Korean text. For those, set DejaVu Sans, which dompdf bundles
and which supports Cyrillic, Greek and many other scripts (Chinese, Japanese and Korean need a font that you install in
dompdf's font directory and name here).
Right to left
$invoice->locale('ar'); // right to left automatically for ar, fa, he and ur
$invoice->direction('rtl'); // or force it, 'ltr' goes the other way
A right to left invoice sets dir="rtl" and mirrors the layout: the columns of the tables, the position of the blocks
and the alignment of the text.
Arabic and Persian are not shaped by dompdf. dompdf has no text shaping engine: Arabic letters are printed in their isolated form (unjoined) and the text may come out in the wrong order. Hebrew has no joining letters and is much less affected, but check the result. For Arabic or Persian invoices, shape the text yourself before passing it in (for example with a library that converts to presentation forms) or render the HTML (
toHtml()) with a browser based renderer such as Browsershot or a service that prints Chromium PDFs. The labels shipped with the package are not translated into these languages yet; publish the translations and add your own.
Layout and paper
$invoice->paper(Paper::A4);
$invoice->paper('a4', Orientation::Landscape);
$invoice->paper([0, 0, 595, 842]); // points
$invoice->logo('img/logo.png', 80); // path relative to public_path(), absolute path, URL or data URI
$invoice->notes('Thanks!')->footnote('Registered in ...');
$invoice->withPagination(false); // "1 of 3" on multi page documents (on by default)
$invoice->duplicateHeader(); // repeat the header on every page
$invoice->template('mytemplate'); // another view in the invoices:: namespace
Empty sections are not printed: no notes box without notes, no logo, due date or number when unset, no tax or fee rows when there are none.
Custom templates
Publish the views (--tag=invoices-views) and edit resources/views/vendor/invoices/default.blade.php, or add
a template of your own next to it and select it with ->template('name'). The template receives $invoice; read its
state ($invoice->items, ->discounts, ->fees, ->taxRates, ->customer->lines()), the helpers (heading(),
money(), formatDate(), stampText(), resolvedDirection()) and the totals (subtotal(), taxBase(), total()...).
Use __('invoices::invoice.key') for texts. dompdf supports a subset of CSS 2.1: no flexbox or grid, and direction: rtl
does not mirror tables, so build mirrored layouts by hand, as the default template does.
Security
Invoices configures dompdf for untrusted input. PHP execution in templates is never enabled and TLS verification is never disabled; neither is configurable. Things to keep in mind:
- Remote fetching. By default dompdf may download remote images (logo, item images). If you only use local files or
data URIs, set
pdf.remote_enabledtofalse; otherwise restrict it withpdf.allowed_remote_hosts(['cdn.example.com']). Never put untrusted URLs in the logo or item images: a URL is requested by your server. - Local files. dompdf only reads files below
pdf.chroot, which defaults topublic_path()andstorage_path('app'). Relative item images (img/a.png) are resolved to a file inpublic_path()and never outside it. - Templates.
<script type="text/php">blocks are not executed. Page numbers are drawn by the package. - Fonts. The font name is written into the template's CSS, so only letters, digits, spaces,
-and_are accepted. - Escaping. Names, notes and addresses are escaped by Blade, so user input cannot inject HTML into the document.
- dompdf. Keep
dompdf/dompdfat ^3.1.6 or later: older versions have known vulnerabilities.
Report vulnerabilities as described in SECURITY.md.
Configuration reference
php artisan vendor:publish --tag=invoices-config creates config/invoices.php. Every key can be overridden per invoice.
| Key | Default | Per invoice | Meaning |
|---|---|---|---|
currency |
EUR |
currency() |
ISO 4217 code. |
decimals |
2 |
decimals() |
Decimals of every rounding step and of the printed amounts, 0 to 20. |
logo |
null |
logo() |
URL, absolute path or path relative to public_path(). |
logo_height |
60 |
logo($url, $height) |
Height in CSS pixels. |
business_details |
sample | business() |
The issuer: name, id, phone, email, address, zip, city, country, extra. |
footnote |
'' |
footnote() |
Text at the end of the document. |
tax_rates |
[] |
taxRates(), taxRate() |
Taxes on every invoice: name, tax, tax_type (percentage or fixed). |
due_date |
'+3 months' |
dueDate() |
Anything Carbon parses, or null. Relative strings are resolved per invoice. |
with_pagination |
true |
withPagination() |
"1 of 3" on multi page documents. |
duplicate_header |
false |
duplicateHeader() |
Repeat the header on every page. |
date_format |
'dddd D MMMM YYYY' |
n/a | Carbon isoFormat string for the dates. |
font |
'Helvetica' |
font() |
CSS font family; 'DejaVu Sans' for non-Latin scripts. |
paper, orientation |
'letter', 'portrait' |
paper() |
Paper name or [0, 0, width, height] in points, and portrait or landscape. |
pdf.remote_enabled |
true |
n/a | Let dompdf download remote images. |
pdf.allowed_remote_hosts |
null |
n/a | Restrict remote downloads to these hosts; null allows any. |
pdf.chroot |
null |
n/a | Directories dompdf may read; null is public_path() and storage_path('app'). |
The locale, direction, document type, stamp and file name have no config key: set them per invoice.
Testing your own code
Build the invoice, then assert on total(), on toHtml() or on the response headers. Avoid comparing PDF bytes, they
contain a timestamp.
$response = $invoice->download();
expect($response->headers->get('Content-Disposition'))->toBe('attachment; filename=invoice-4021.pdf')
->and($response->getContent())->toStartWith('%PDF');
Upgrading
Coming from 1.x? Read UPGRADE.md: the API is camelCase, the namespace moved and templates were rewritten. Every release is listed in CHANGELOG.md.
Contributing
Issues and pull requests are welcome. Read CONTRIBUTING.md first. composer test, composer analyse
and composer lint must pass.
License
The MIT License (MIT). See LICENSE.
Special thanks
Ähnliche Projekte entdecken
Wird geladen…