soap / laravel-invoices
Easy invoices generation using Laravel Eloquent
Requires
- php: ^7.3
- ext-intl: *
- dompdf/dompdf: ^0.8.0
- illuminate/support: ^6.0|^7.0|^8.0
- nesbot/carbon: ^1.22|^2.0
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0
- phpunit/phpunit: ^7.5|^8.3|^9.0
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-12-14 22:01:39 UTC
README
This package has been changed, updated and redistributed. To utilize original distribution, see NeptuneSoftware/laravel-invoice repository.
IMPORTANT
This fork is going to be maintained by Prasit Gebsaap and it's not compatible with original repository.
Easy invoices creation for Laravel. Unlike Laravel Cashier, this package is payment gateway agnostic.
What is different?
In order to follow changes, see changelog file.
Structure
.
├── config # Configuration file
├── database # Database files
│ └── migrations
├── resources # Resource files
│ └── views
├── src # Soruce files
│ ├── Interfaces
│ ├── Models
│ ├── Providers
│ ├── Scopes
│ ├── Services
│ └── Traits
└── tests # Test files
├── Feature
└── Unit
Install
Via Composer
$ composer require soap/laravel-invoices
You can publish the migration with:
$ php artisan vendor:publish --provider="Soap\Invoices\Providers\InvoicesServiceProvider" --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 invoices.php
config file with:
$ php artisan vendor:publish --provider="Soap\Invoices\Providers\InvoicesServiceProvider" --tag="config"
This is what the default config file looks like:
return [ 'default_currency' => 'THB', 'default_status' => 'draft', 'locale' => 'th_TH', 'table_names' => [ 'invoices' => 'invoices', 'invoice_lines' => 'invoice_lines', ] ];
If you'd like to override the design of the invoice blade view and pdf, publish the view:
$ php artisan vendor:publish --provider="Soap\Invoices\Providers\InvoiceServiceProvider" --tag="views"
You can now edit receipt.blade.php
in <project_root>/resources/views/invoice/receipt.blade.php
to match your style.
Usage
Money figures are in cents!
Add the HasInvoice trait to the Eloquent model which needs to send or receive invoices (typically a Customer or Company model):
use Illuminate\Database\Eloquent\Model; use Soap\Invoices\Traits\HasInvoice; class Order extends Model { use HasInvoices; // enables the ->invoices() Eloquent relationship }
Now you can create invoices for a customer:
$customer = Customer::first(); $product = Product::first(); // Any model to be referenced in an invoice line $service = $service->create($customer); // Injected dependency // To add a line to the invoice, use these example parameters: // Amount: // 118 (₺1,18) incl tax // 100 (₺1,00) excl tax // Description: 'Some description' // Tax percentage: 0.18 (18%) # Scenerio 1: $service->addTaxPercentage('VAT', 0.18)->addAmountInclTax($product, 118, 'Some description'); $service->addTaxPercentage('VAT', 0.18)->addAmountExclTax($product, 100, 'Some description'); # Scenerio 2: $service->addTaxFixed('VAT', 18)->addAmountInclTax($product, 118, 'Some description'); $service->addTaxFixed('VAT', 18)->addAmountExclTax($product, 100, 'Some description'); # Scenerio 3 for taxes: $service->addTaxPercentage('VAT', 0.18)->addAmountInclTax($product, 118, 'Some description'); $service->addTaxFixed('VAT', 18)->addAmountExclTax($product, 100, 'Some description'); // Invoice totals are now updated $invoice = $service->getInvoice(); echo $invoice->total; // 236 echo $invoice->tax; // 36 // Set additional information (optional) $invoice->currency; // defaults to 'TRY' (see config file) $invoice->status; // defaults to 'concept' (see config file) $invoice->receiver_info; // defaul ts 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 $service->lines; $service->lines(); // Access as pdf $service->download(); // download as pdf (returns http response) $service->pdf(); // or just grab the pdf (raw bytes) // Handling discounts // By adding a line with a negative amount. $invoice = $invoice->setReference($product)->addAmountInclTax(-118, 'A nice discount', 0.18); // Or by applying the discount and discribing the discount manually $invoice = $invoice->setReference($product)->addAmountInclTax(118 * (1 - 0.30), 'Product XYZ incl 30% discount', 0.18); // Convenience methods $service->findByReference($reference); $service->findByReferenceOrFail($reference); $service->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.
Credits
- Burak
- Fatih
- Uğur
- Sander van Hooft
- All Contributors
- Inspired by Laravel Cashier's invoices.
License
The MIT License (MIT). Please see License File for more information.