Download the PHP package finller/laravel-invoices without Composer
On this page you can find all versions of the php package finller/laravel-invoices. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download finller/laravel-invoices
More information about finller/laravel-invoices
Files in finller/laravel-invoices
Package laravel-invoices
Short Description Store invoices safely in your Laravel application
License MIT
Homepage https://github.com/ElegantEngineeringTech/laravel-invoices
Informations about the package laravel-invoices
Everything You Need to Manage Invoices in Laravel
Create, store, calculate, and render invoices, quotes, proformas, and credit notes in Laravel. The package supports multiple item-level discounts and taxes, serial numbers, PDF generation, mail attachments, polymorphic relations, Stripe Checkout imports, and GOBL export.
Amounts are denormalized: items and invoices hold their calculated amounts. Supply precomputed values from your application or payment provider, or call denormalize() to calculate missing amounts. Existing values are preserved unless you request recalculation.
There are two independent ways to use the package:
PdfInvoice: build and render invoices without a database.Invoice: store invoices and their items with Eloquent, then optionally generate PDFs or export them.
Interactive Demo
Try the interactive demo to explore the package.
Table of Contents
- Interactive Demo
- Requirements
- Installation
- Configuration
- Upgrading from v5
- The
PdfInvoiceClass- Full Example
- Creating PDFs from Arrays
- PDF Amounts and Denormalization
- PDF Discounts and Taxes
- Parties, Addresses, and Custom Fields
- Types, States, and Dates
- Payment Instructions and QR Codes
- Rendering, Downloading, and Storing PDFs
- Livewire Downloads
- Accessing Dompdf
- Rendering Blade Views
- PDF Mail Attachments
- Attaching PDFs to Mailables
- Attaching PDFs to Notifications
- PDF Customization and Localization
- Logos, Templates, and Template Data
- Fonts and PDF Options
- Localization and Money Formatting
- Extending PdfInvoice
- The
InvoiceEloquent Model- Complete Example
- Stored Amounts and Denormalization
- Managing Invoice Items
- Stored Discounts and Taxes
- Stored Parties, Fields, and Payment Instructions
- Relations, Quotes, and Credits
- Types, States, and Query Scopes
- Generating Serial Numbers
- Multiple Prefixes and Series
- Manual Serial Numbers and Parsing
- Storing Logos
- Converting Models to PDFs
- Livewire Downloads from a Model
- Customizing PDF Output from the Model
- Model Mail Attachments
- Mailables
- Notifications
- Replicating, Scaling, and Allocating Amounts
- Replicating and Scaling
- Allocating Amounts
- Collections and Money Totals
- Importing Stripe Checkout Line Items
- GOBL Export
- Custom Models and Value Objects
- Casting Types and States to Enums
- Testing
- Changelog
- Contributing
- Security Vulnerabilities
- Credits
- License
Requirements
- PHP 8.4+
- Laravel 13.x
dompdf/dompdf3.1+elegantly/laravel-money4.2+
The Stripe integration additionally requires stripe/stripe-php.
Installation
For Eloquent storage, publish and run the migrations:
Standalone PdfInvoice usage does not require migrations.
Configuration
Use config/invoices.php to configure your default seller, currency, rounding, serial numbers, and PDF appearance. See the configuration file for all settings and defaults.
Upgrading from v5
See the migration guide for breaking changes, database conversions, and examples for upgrading from v5 to v6.
The PdfInvoice Class
Build PDFs, Blade previews, and mail attachments from your own data, without database storage.
Full Example
Creating PDFs from Arrays
Use PdfInvoice::make() to build an invoice from nested arrays. Numeric amounts are in major units, using currency or invoices.default_currency (USD by default).
PDF Amounts and Denormalization
Each item holds its amounts, and the invoice holds their totals:
| Item property | Meaning | Invoice total |
|---|---|---|
unit_price |
Price of one unit before discounts and taxes. | — |
price_subtotal |
Line subtotal, normally unit_price × quantity. |
subtotal_amount |
price_discount |
Sum of the line's discount amounts. | discount_amount |
price_tax |
Sum of the line's tax amounts. | tax_amount |
price |
Final line amount: price_subtotal − price_discount + price_tax. |
total_amount |
Letting the Package Calculate Amounts
Call denormalize() to calculate line amounts and invoice totals before rendering:
- Only missing (
null) amounts are calculated; existing amounts, including zero, are preserved. - If you supply only
price_subtotal, the unit price is derived from the quantity. - Calculations use
invoices.rounding_mode, defaulting toRoundingMode::HalfUp.
Rendering does not calculate amounts automatically.
Using Precomputed Amounts
Supply line amounts and invoice totals directly when they have already been calculated:
You can mix precomputed and calculated amounts: denormalize() fills the gaps. To display discount and tax breakdowns, also supply the corresponding entries with their amounts.
Recalculating after Changes
After changing a quantity, unit price, discount, or tax percentage, request recalculation explicitly:
force: true recalculates line amounts and invoice totals. Percentage discounts and taxes are recalculated; fixed amounts remain inputs.
PDF Discounts and Taxes
Add percentage or fixed-amount discounts and taxes to each item:
- Fixed amounts apply to the whole line, not each unit.
- Percentage discounts are applied sequentially, in the order provided.
- Each percentage tax is calculated on the subtotal after all discounts; taxes are not compounded.
- For an invoice-wide promotion, distribute its discount across the items.
The default template groups discount and tax breakdowns automatically. Use getDiscounts() and getTaxes() for these summaries in custom templates. Taxes can include country, state, and taxability for jurisdiction and exemption information.
Use Money::of('19.80', 'EUR') for major units or Money::ofMinor(1980, 'EUR') for minor units. If you use direct discount/tax array constructors instead of Money, their numeric amounts are in minor units; PdfInvoice::make() uses major units throughout.
Parties, Addresses, and Custom Fields
Use Party for the seller and buyer. Add billing and shipping addresses, contact details, tax IDs, registration identities, and custom fields as shown in the full example.
Custom fields can appear in the invoice header, party details, or addresses:
Types, States, and Dates
Built-in document types and states have translated labels:
InvoiceType:Invoice,Quote,Credit,Proforma.InvoiceState:Draft,Pending,Paid,Refunded.
For custom labels, use your own enum implementing Elegantly\Invoices\Contracts\HasLabel.
Set created_at, due_at, and paid_at to display dates. Change their format with invoices.date_format.
Payment Instructions and QR Codes
Add bank details, payment links, and QR codes with paymentInstructions:
Payment fields and invoice descriptions support HTML. Generate QR codes with a package such as chillerlan/php-qrcode.
Rendering, Downloading, and Storing PDFs
stream() displays the PDF inline; download() downloads it. The default filename is the serial number followed by .pdf.
Livewire Downloads
In resources/views/livewire/invoice-preview.blade.php:
Accessing Dompdf
pdf() returns an unrendered Dompdf instance. Override configured options, paper settings, or view data for a particular render:
Rendering Blade Views
To embed the invoice in another Blade view:
The partial uses Tailwind CSS classes. Include the package's invoices::default.style partial or provide equivalent styles in your application. The complete default layout already includes the package's CSS.
PDF Mail Attachments
Attaching PDFs to Mailables
Send the PDF built in the full example:
Attaching PDFs to Notifications
PDF Customization and Localization
Logos, Templates, and Template Data
Set logo to an image path or data URI, or configure a default with invoices.pdf.logo.
Publish views to customize the layout, invoice content, header, footer, and payment instructions:
Edit files in resources/views/vendor/invoices/. For a layout at resources/views/vendor/invoices/my-custom/layout.blade.php, use template: 'my-custom.layout' or set invoices.pdf.template.
Pass custom template settings through templateData, and extra Blade variables through view($data) or pdf(data: ...). Add styles for custom classes in style.blade.php.
Fonts and PDF Options
The default layout reads font and fonts from templateData:
You can set these defaults in invoices.pdf.template_data. Configure Dompdf's font directories, cache, remote resources, and other options through invoices.pdf.options. See the Dompdf font guide.
Localization and Money Formatting
Built-in type/state labels and template text use Laravel translations. Set your application locale and publish translations to customize them:
Use format_money() in custom templates to format amounts with the application locale, or specify a locale:
Extending PdfInvoice
Extend PdfInvoice to customize behavior such as filenames:
The Invoice Eloquent Model
Store invoice snapshots and totals with Invoice, and their line amounts, discounts, and taxes with InvoiceItem.
Publish and run the migrations before using the models. Assign amounts using Money; the package handles database storage and currency.
Complete Example
The transaction saves the invoice and its items together.
Stored Amounts and Denormalization
Line amounts and invoice totals are stored separately:
| Item attribute | Meaning | Invoice attribute |
|---|---|---|
unit_price |
Price of one unit before discounts and taxes. | — |
price_subtotal |
Normally unit_price × quantity. |
subtotal_amount |
price_discount |
Sum of line discounts. | discount_amount |
price_tax |
Sum of line taxes. | tax_amount |
price |
price_subtotal − price_discount + price_tax. |
total_amount |
Use the same currency for an invoice and its items. Numeric amounts assigned to the models are in major units.
Calculating and Saving Amounts
denormalize() calculates missing line amounts and sums them into invoice totals.
- Items fill missing line amounts when saved. Call
denormalize()on the invoice to update its totals. - Existing amounts, including zero, are preserved.
- If you supply only
price_subtotal, the unit price is derived from the quantity. - Calculations use
invoices.rounding_mode, defaulting toRoundingMode::HalfUp.
Storing Precomputed Amounts
Supply amounts directly to preserve your own calculations or those of a payment provider:
You can mix precomputed and calculated amounts: denormalize() fills the gaps. Include discount and tax entries with their amounts for PDF breakdowns and exports.
Recalculating Existing Invoices
Existing derived amounts remain populated after you edit source data. Recalculate them explicitly:
force: true recalculates line amounts, percentage discounts and taxes, and invoice totals. Fixed amounts remain inputs.
Denormalizing with Artisan
Use the command to fill missing amounts or recalculate existing invoices in bulk:
Managing Invoice Items
Use saveWithItems() to persist the invoice and its items, or saveItems() for an already saved invoice. setItems() replaces the loaded collection; delete unwanted database rows explicitly through items().
You can also manage items through the items() Eloquent relation. Reload items and use denormalize(force: true) to refresh calculated totals after changes.
For fractional quantities, change the published integer quantity column to a decimal column in your application's migrations.
Deleting an invoice deletes its items by default. Set invoices.cascade_invoice_delete_to_invoice_items to false to disable the model's cascading delete behavior.
Stored Discounts and Taxes
Add percentage or fixed-amount discounts and taxes with the item helpers:
- Discounts are applied sequentially, in the order provided.
- Each percentage tax uses the subtotal after all discounts.
- Fixed amounts apply to the whole line, not each unit.
- Taxes can include
country,state, andtaxabilityfor jurisdiction and exemption information.
Use Money for amounts. Direct discount/tax array constructors interpret numeric amounts with a currency key in minor units.
Stored Parties, Fields, and Payment Instructions
Store seller and buyer details in seller_information and buyer_information so invoices retain their original details when customer records change. Include addresses, contact details, tax IDs, and registration identities as needed.
fields appear in the PDF header; mergeFields() adds to existing fields. Use metadata for application data that should not appear on the invoice.
Payment instructions appear in the PDF and can include bank details, HTML payment links, and QR codes through qrcode.
Relations, Quotes, and Credits
Associate an invoice with any Eloquent model through its polymorphic relations:
Define the inverse relation on your customer model:
Invoices can also relate to other invoices through parent_id:
parent()belongs to the parent invoice.children()returns all child documents.quote()returns a child with typequote.credits()returns children with typecredit.
Types, States, and Query Scopes
New invoices default to type invoice and state draft. Available values are:
- Types:
invoice,quote,credit,proforma. - States:
draft,pending,paid,refunded.
Set the state and state_set_at when your application records a payment or refund. Use query scopes to filter documents:
Type scopes are invoice(), quote(), and credit(). State scopes are draft(), pending(), paid(), and refunded().
To display a paid date in the PDF, set paid_at on the converted PdfInvoice.
Generating Serial Numbers
Serial numbers are generated automatically when an invoice is saved without one. The default format, PPYYCCCC, produces values such as IN260001.
| Token | Meaning |
|---|---|
P |
Prefix |
S |
Series |
Y |
Year |
M |
Month |
C |
Sequential count |
Repeat a token to set its width, and add separators as needed.
Multiple Prefixes and Series
Numbering is sequential within each prefix, series, year, and month. Override getPreviousInvoice() in a custom model to change that scope.
Set default numbering rules in configuration:
Manual Serial Numbers and Parsing
Manual numbers are preserved. Set invoices.serial_number.auto_generate to false if your application always supplies them.
Use SerialNumberGenerator independently to generate or parse numbers without a model:
Storing Logos
Without a stored logo, PDFs fall back to invoices.pdf.logo. To capture a logo in the database, store its binary contents:
Converting Models to PDFs
Use toPdfInvoice() to render the stored invoice without recalculating its amounts:
In routes/web.php:
For a Blade preview, include invoices::default.invoice with the converted PDF as invoice and include the package's CSS.
Livewire Downloads from a Model
In resources/views/livewire/invoice-download.blade.php:
Mount it in a Blade view with your stored invoice:
Customizing PDF Output from the Model
Extend the model and override toPdfInvoice() to adjust the returned PDF:
Register the model through invoices.model_invoice. You can also return your own PdfInvoice subclass, or configure global PDF settings under invoices.pdf.
Model Mail Attachments
Attach a stored invoice directly to mailables and notifications.
Mailables
Customize the filename with $invoice->toPdfInvoice()->toMailAttachment(filename: 'invoice.pdf').
Notifications
Replicating, Scaling, and Allocating Amounts
Replicating and Scaling
Replicate an invoice and its items to create a new document. For example, create a credit with negative amounts:
The copy receives a new serial number. multiplyBy() scales invoice, item, discount, and tax amounts without changing quantities or percentages. Use a string such as '0.5' for decimal factors.
Allocating Amounts
Allocate target amounts proportionally across existing items, for example to create a partial credit or match a payment provider's totals:
Allocation uses existing item and breakdown amounts as proportions, and updates unit prices, discounts, and taxes. Start with calculated amounts and nonzero quantities. Save without forced denormalization to preserve the allocated result.
Collections and Money Totals
Use sumMoney() to total amounts in the same currency, or convert collections to PDFs:
Importing Stripe Checkout Line Items
Install the optional Stripe SDK:
Import Stripe Checkout line items while preserving Stripe's precomputed amounts and breakdowns:
Use the expansions shown above and fetch all pages for larger sessions. toInvoiceItem($lineItem) imports a single line. Your application supplies invoice parties, dates, and associations; denormalize() sums the imported amounts without overwriting them.
GOBL Export
Export an invoice using the GOBL invoice schema:
The export includes document details, parties, lines, discounts, taxes, payment terms, and a reference to the parent invoice where applicable.
Pass additional values to extend or override the mapping:
Items, parties, discounts, and taxes can also be exported individually with toGOBL().
Custom Models and Value Objects
Extend the package classes and register your subclasses in config/invoices.php:
Use seller_class and buyer_class to configure separate party classes if needed.
Factories are available through Invoice::factory() and InvoiceItem::factory(). Invoice factories include invoice(), quote(), credit(), and proforma() states.
Casting Types and States to Enums
If you prefer enum attributes, merge enum casts with the parent's casts. Also override getType() and getState() to return the cast values for PDF conversion:
Set invoices.model_invoice to this subclass. For custom enums, implement Elegantly\Invoices\Contracts\HasLabel to provide PDF labels, and configure serial numbers for your custom document types.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Quentin Gabriele
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-invoices with dependencies
dompdf/dompdf Version ^3.1
elegantly/laravel-money Version ^4.2.0
illuminate/contracts Version ^13.0
spatie/laravel-package-tools Version ^1.14