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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-invoices

Everything You Need to Manage Invoices in Laravel

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provides a robust, easy-to-use system for managing invoices within a Laravel application, with options for database storage, serial numbering, and PDF generation.

laravel-invoices

Interactive Demo

Try out the interactive demo to explore package capabilities.

Table of Contents

Requirements

Installation

You can install the package via composer:

If you intent to store your invoices using the Eloquent Model, you must publish and run the migrations with:

You can publish the config file with:

This is the contents of the published config file:

The PdfInvoice Class

This package provides a powerful, standalone PdfInvoice class. Its main functionalities include the ability to:

The PdfInvoice class is also integrated with the Invoice Eloquent Model, allowing you to easily convert an Invoice model instance into its PDF representation.

You can even use this package exclusively for the PdfInvoice class if you don't require database storage for your invoices.

Full Example

Rendering the Invoice as a PDF

Storing the PDF in a file

Downloading the Invoice as a PDF

From a controller

To download the PDF, simply return the download method.

From a Livewire component

To download the PDF from a Livewire component, use the streamDownload method as shown below:

Rendering the Invoice as a view

Rendering the Invoice within a View

You can embed the invoice within a larger Blade view to create interfaces like an "invoice builder," similar to the interactive demo.

To do this, include the main invoice partial in your view as shown below:

This approach allows for seamless integration of the invoice into a dynamic and customizable user interface.

[!NOTE]
The default template uses Tailwind CSS for styling. This ensures seamless integration with websites already using Tailwind. If your project doesn't use Tailwind, the invoice styling may not appear as intended.

Adding Taxes

Taxes are applied to individual PdfInvoiceItem item. You can define them either as a percentage or a fixed amount.

Tax by Percentage

To add a tax as a percentage, set the tax_percentage property on the PdfInvoiceItem. This value should be a float between 0 and 100.

Tax as a Fixed Amount

To apply a tax as a specific monetary amount, set the unit_tax property on the PdfInvoiceItem.

Adding Discounts

Discounts are represented by the InvoiceDiscount class and are applied to the entire PdfInvoice. They cannot be attached to individual PdfInvoiceItems at this time.

Discount by Percentage

To apply a discount as a percentage, set the percent_off property.

Discount as a Fixed Amount

To apply a discount as a fixed amount, set the amount_off property.

Adding Payment Instructions

You can include detailed payment instructions directly within the generated PDF invoice. This can be helpful for providing bank transfer details, QR codes for quick payments, and custom payment links.

Here’s an example of how to add a payment instruction:

Note: You can include HTML tags (e.g., links) within the fields array for interactive content.

QR Code Generation

To dynamically generate QR codes, I recommend using the chillerlan/php-qrcode package. It provides a simple and flexible API for generating QR codes in various formats.

Customization

Customizing Fonts

See the Dompdf font guide.

Customizing the Invoice Template

To customize the invoice template, first publish the package's views:

After publishing, you can modify the Blade files in resources/views/vendor/invoices/ to suit your needs.

[!NOTE] If you introduce new CSS classes in your custom template, ensure you define their styles in the style.blade.php file.

Alternatively, to use a completely different custom template, you can specify its path in the configuration file:

[!WARNING] Your custom template file must be in resources/views/vendor/invoices

Ensure that your custom template follows the same structure and conventions as the default one to maintain compatibility with various use cases.

The Invoice Eloquent Model

The design of the Invoice Eloquent Model closely mirrors that of the PdfInvoice class.

This model provides powerful features for:

[!NOTE] Remember to publish and run the database migrations

Complete Example

The following example demonstrates how to create and store an invoice.

For this illustration, let's assume the following application structure:

Generating Unique Serial Numbers

This package provides a simple and reliable way to generate serial numbers automatically, such as "INV240001".

You can configure the format of your serial numbers in the configuration file. The default format is PPYYCCCC, where each letter has a specific meaning (see the config file for details).

When invoices.serial_number.auto_generate is set to true, a unique serial number is assigned to each new invoice automatically.

Serial numbers are generated sequentially, with each new serial number based on the latest available one. To define what qualifies as the previous serial number, you can extend the Elegantly\Invoices\Models\Invoice class and override the getPreviousInvoice method.

By default, the previous invoice is determined based on criteria such as prefix, series, year, and month for accurate, scoped numbering.

Using Multiple Prefixes and Series for Serial Numbers

In more complex applications, you may need to use different prefixes and/or series for your invoices.

For instance, you might want to define a unique series for each user, creating serial numbers that look like: INV0001-2400X, where 0001 represents the user’s ID, 24 the year and X the index of the invoice.

[!NOTE] When using IDs for series, it's recommended to plan for future growth to avoid overflow. Even if you have a limited number of users now, ensure that the ID can accommodate the maximum number of digits allowed by the serial number format.

When creating an invoice, you can dynamically specify the prefix and series with configureSerialNumber method:

Customizing the Serial Number Format

In most cases, the format of your serial numbers should remain consistent, so it's recommended to set it in the configuration file.

The format you choose will determine the types of information you need to provide to configureSerialNumber.

Below is an example of the most complex serial number format you can create with this package:

Converting an Invoice Model to a PdfInvoice

You can obtained a PdfInvoice class from your Invoice model by calling the toPdfInvoice method:

Display, Download, and Store Invoices

You can then stream the PdfInvoice instance directly or initiate a download:

Attaching Invoices to Mailables

You can easily attach an invoice to your Mailable as follows:

Attaching Invoices to Notifications

You can easily attach an invoice to your Notification as follows:

Customizing PDF Output from the Model

To customize how your Invoice model is converted into a PdfInvoice object, follow these steps:

  1. Create a Custom Invoice Model:

Define your own App\Models\Invoice class and ensure it extends the base Elegantly\Invoices\Models\Invoice.

  1. Override the toPdfInvoice Method:

In your custom Invoice model, override the toPdfInvoice method. This is where you'll implement your specific logic to construct and return the PdfInvoice object with your desired customizations.

  1. Update the Package Configuration:

First, if you haven't already, publish the package's configuration file:

Then, modify the config/invoices.php file to tell the package to use your custom model by updating the model_invoice key:

Using a Custom PdfInvoice Class

You can extend the default PdfInvoice class provided by the package to customize its behavior, such as changing the generated filename or adding additional logic.

  1. Create Your Custom PdfInvoice Class

In this example, we're overriding the getFilename method.

  1. Return Your Custom PdfInvoice from the Invoice Model

Update your Invoice model to return an instance of your custom PdfInvoice class.

By overriding the toPdfInvoice method, you can inject your custom logic while preserving compatibility with the rest of the package.

Casting state and type to Enums

By default, the type and state properties on the Invoice model are stored as strings. This approach offers flexibility, as it doesn't restrict you to predefined values and they are not automatically cast to Enum objects.

However, you might prefer to cast these properties to Enum objects for better type safety and code clarity. You can use your own custom Enums or the ones provided by this package (e.g., Elegantly\Invoices\Enums\InvoiceState, Elegantly\Invoices\Enums\InvoiceType).

To enable Enum casting for these properties, follow these steps:

  1. Create a Custom Invoice Model:

Define your own App\Models\Invoice class that extends \Elegantly\Invoices\Models\Invoice. In this custom model, override the casts() method to specify the Enum classes for the type and state attributes.

  1. Publish Package Configuration:

If you haven't already, publish the package's configuration file:

  1. Update Configuration to Use Your Custom Model:

Modify the config/invoices.php file and update the model_invoice key to point to your newly created custom Invoice model:

Using a Dynamic Logo

In scenarios where the invoice logo needs to be set dynamically (for instance, allowing users to upload their own company logo), you can achieve this by overriding the getLogo method in your Invoice model.

Follow these steps:

  1. Create a Custom Invoice Model:

Define your own App\Models\Invoice that extends \Elegantly\Invoices\Models\Invoice class. Inside this custom model, implement the getLogo method to return the path or data for your dynamic logo.

[!NOTE] The getLogo method must return either a base64-encoded data URL (e.g., data:image/png;base64,...) or a local filesystem path to the logo image.

Here's an example of how you might implement this:

  1. Publish Package Configuration:

If you haven't done so already, publish the package's configuration file:

  1. Update Configuration to Use Your Custom Model:

Modify the config/invoices.php file and update the model_invoice key to point to your custom Invoice model:

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

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-invoices with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
dompdf/dompdf Version ^3.1
elegantly/laravel-money Version ^2.1.0
illuminate/contracts Version ^11.0||^12.0
spatie/laravel-package-tools Version ^1.14
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package finller/laravel-invoices contains the following files

Loading the files please wait ....