GithubHelp home page GithubHelp logo

sandervanhooft / laravel-invoicable Goto Github PK

View Code? Open in Web Editor NEW
144.0 5.0 42.0 57 KB

Easy invoice creation for Laravel

Home Page: https://www.sandervanhooft.com/blog/laravel/stop-creating-your-laravel-invoices-manually/

License: MIT License

PHP 84.54% Blade 15.46%
laravel invoice invoice-pdf eloquent

laravel-invoicable's Introduction

laravel-invoicable

Latest Version on Packagist Software License Github Actions Total Downloads

Easy invoice creation for Laravel. Unlike Laravel Cashier, this package is payment gateway agnostic.

If you're looking for Mollie payment processing, be sure to check out laravel-payable-redirect-mollie.

Structure

database/
resources
src/
tests/
vendor/

Install

Via Composer

$ composer require sander-van-hooft/laravel-invoicable

You can publish the migration with:

$ php artisan vendor:publish --provider="SanderVanHooft\Invoicable\InvoicableServiceProvider" --tag="migrations"

After the migration has been published you can create the invoices and invoice_lines tables by running the migrations:

$ php artisan migrate

Optionally, you can also publish the invoicable.php config file with:

$ php artisan vendor:publish --provider="SanderVanHooft\Invoicable\InvoicableServiceProvider" --tag="config"

This is what the default config file looks like:

return [
    'default_currency' => 'EUR',
    'default_status' => 'concept',
    'locale' => 'nl_NL',
];

If you'd like to override the design of the invoice blade view and pdf, publish the view:

$ php artisan vendor:publish --provider="SanderVanHooft\Invoicable\InvoicableServiceProvider" --tag="views"

You can now edit receipt.blade.php in <project_root>/resources/views/invoicable/receipt.blade.php to match your style.

Usage

Money figures are in cents!

Add the invoicable trait to the Eloquent model which needs to be invoiced (typically an Order model):

use Illuminate\Database\Eloquent\Model;
use SanderVanHooft\Invoicable\IsInvoicable\IsInvoicableTrait;

class Order extends Model
{
    use IsInvoicableTrait; // enables the ->invoices() Eloquent relationship
}

Now you can create invoices for an Order:

$order = Order::first();
$invoice = $order->invoices()->create([]);

// To add a line to the invoice, use these example parameters:
//  Amount:
//      121 (€1,21) incl tax
//      100 (€1,00) excl tax
//  Description: 'Some description'
//  Tax percentage: 0.21 (21%)
$invoice = $invoice->addAmountInclTax(121, 'Some description', 0.21);
$invoice = $invoice->addAmountExclTax(100, 'Some description', 0.21);

// Invoice totals are now updated
echo $invoice->total; // 242
echo $invoice->tax; // 42

// Set additional information (optional)
$invoice->currency; // defaults to 'EUR' (see config file)
$invoice->status; // defaults to 'concept' (see config file)
$invoice->receiver_info; // defaults to null
$invoice->sender_info; // defaults to null
$invoice->payment_info; // defaults to null
$invoice->note; // defaults to null

// access individual invoice lines using Eloquent relationship
$invoice->lines;
$invoice->lines();

// Access as pdf
$invoice->download(); // download as pdf (returns http response)
$invoice->pdf(); // or just grab the pdf (raw bytes)

// Handling discounts
// By adding a line with a negative amount.
$invoice = $invoice->addAmountInclTax(-121, 'A nice discount', 0.21);

// Or by applying the discount and discribing the discount manually
$invoice = $invoice->addAmountInclTax(121 * (1 - 0.30), 'Product XYZ incl 30% discount', 0.21);

// Convenience methods
Invoice::findByReference($reference);
Invoice::findByReferenceOrFail($reference);
$invoice->invoicable() // Access the related model

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

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

laravel-invoicable's People

Contributors

ciungulete avatar povilaskorop avatar sandervanhooft avatar timwassenburg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

laravel-invoicable's Issues

Bad tax calculation in addAmountInclTax Method

Detailed description

In class Invoice.php, method addAmountIncTax, you're making the tax calculation like this:
'tax' => $amount - $amount / (1 + $taxPercentage)

while it should be like this:
'tax' => $amount * $taxPercentage,

Context

It's important because this is a bad calculation !

Possible implementation

change this line: 'tax' => $amount - $amount / (1 + $taxPercentage)
with this: 'tax' => $amount * $taxPercentage

Your environment

Laravel 5.7

Invoice template could be prettier...

I don't like the current invoice template very much...

It was adapted form Laravel Cashier's old invoice template.

I think something like the Sparksuite template would be a huge improvement (link).

Installation doesn't work - on publishing migrations

This command

$ php artisan vendor:publish --provider="SanderVanHooft\Invoicable\InvoicableServiceProvider" --tag="migrations"
doesn't work.

Filename is incorrect:

        // Publish migrations
         $this->publishes([
             __DIR__.'/../database/migrations/2017_06_17_163005_create_invoices_table.php'
             => database_path('migrations/2017_06_17_163005_create_invoices_table.php'),
         ], 'migrations');

Versus folder contents:

screen shot 2017-07-03 at 8 46 39 am

What is invoicable_id?

What is this supposed to be?
I see the db table BIGINT(20) but I can never fill it with anything.

$data = [
      'invoicable_id' => $profile->id,
      'tax' => 0.00,
      'total' => 100.00,
      'receiver_info' => 'its to you',
      'sender_info' => 'its from me',
      'payment_info' => 'who knows',
      'note' => 'Some note',
    ];
$order = new Order();
$invoice = $order->invoices()->create($data);

Results in:
Integrity constraint violation: 1048 Column 'invoicable_id' cannot be null.

Fails when trying to insert the record into invoices table.

Any ideas?

Thanks,

Dave

How do we add discounts to an invoice?

Great package, but I was unable to find a method to add a discount. This is more of an enhancement I think, but a feature that may be necessary.

Also, just like Tax, would be great to know how to add a discount before tax and after tax.

Invoice Model

How do i customize the invoices model since its in the vendors folder?

V2: next major release

There are some upcoming changes warranting a next major release, including:

  • dropping support for php < 7.2
  • dropping support for Laravel < 5.5
  • Carbon v2 support (Laravel 5.8) (#16)
  • custom InvoiceReferenceGenerator (#13)

To do's:

  • prettier default template (#6)
  • update Readme.
  • update Github description (below page title)
  • use MoneyPHP for populating the invoice, i.e. addMoneyInclTax(Money $money, float $tax)
  • update/new blog post. (Update Github link)
  • use MoneyPHP for invoice/formatting
  • new travis config
  • provide blade view name parameter to view(), download(), pdf().
  • move away from graham-campbell/testbench to orchestra/testbench.

This issue is dedicated to keeping a list of to do's and any related discussion. Development will occur in the v2 branch.

Invoice number / reference does not comply with some countries

Hi

Package seems to work as described, but the reference or invoice number does not comply with may countries as the number should be a continuous number sequence

It would be nice if one was able to provide a 'InvoiceReferenceGenerator' instead of modifying the code directly.

Invoicable_id should not be null

Detailed description

I got a bug when I wanted to create a new Order:
Integrity constraint violation: 1048 Column 'invoicable_id' cannot be null (SQL: insert into invoices (invoicable_id, invoicable_type, currency, status, reference, updated_at, created_at)

It happens when I am using this:
$invoice = $order->invoices()->create([]);

Your environment

Using laravel 5.8 with php 7.3

  • Version used (e.g. PHP 5.6, HHVM 3):
  • Operating system and version (e.g. Ubuntu 16.04, Windows 7):
  • Link to your project:
  • ...
  • ...

Installation error

I have a problem installing on Laravel version 9

Problem 1
- Root composer.json requires sander-van-hooft/laravel-invoicable ^1.4 -> satisfiable by sander-van-hooft/laravel-invoicable[1.4.0].
- sander-van-hooft/laravel-invoicable 1.4.0 requires illuminate/support ^7.0 || ^8.0 -> found illuminate/support[v7.0.0, ..., 7.x-dev, v8.0
.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require.

View invoice throws an error

Hi

when trying to render a invoice like this:

$so = SalesOder::find(1);
$invoice = $so->invoices()->first();
return view('vendor.invoicable.receipt')->withInvoice($invoice);

I get the following error:

Undefined variable: moneyFormatter (View: /home/vagrant/code/xxxx/resources/views/vendor/invoicable/receipt.blade.php)

[DOC] Error on creating invoice pdf using the Readme example

Hi,
I followed all the steps that you described and I ran the example that you have posted at Readme and I got the following error.

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'invoicable_id' cannot be null 
(SQL: insert into `invoices` 
(`invoicable_id`, `invoicable_type`, `currency`, `status`, `reference`, `updated_at`, `created_at`)
 values (, App\Invoices, EUR, concept, 2018-06-24-3P2L4M, 2018-06-24 15:27:15, 2018-06-24 15:27:15))

Following is the code

       try {
                $order   = new Orders();
                $invoice = $order->invoices()->create([]);
            }
            catch (\Exception $exception){

                echo $exception->getMessage();
            }

Contexts

php 7.2
latest version of this library
laravel - 5.6

So I was wondering what is the correct procedure to create the invoice?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.