aabosham / laravel-invoicable
使用 Laravel Eloquent 实现简单的发票生成
1.4.2
2023-07-31 13:00 UTC
Requires
- php: ^7.4 || ^8.0 || ^9.0
- ext-intl: *
- dompdf/dompdf: ^2.0
- nesbot/carbon: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.18
- graham-campbell/testbench: ^5.6
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.4
README
为 Laravel 实现简单的发票创建。与 Laravel Cashier 不同,此包不依赖于特定的支付网关。
如果您正在寻找 Mollie 支付处理,请务必查看 laravel-payable-redirect-mollie。
结构
database/
resources
src/
tests/
vendor/
安装
通过 Composer
$ composer require sander-van-hooft/laravel-invoicable
您可以使用以下命令发布迁移:
$ php artisan vendor:publish --provider="SanderVanHooft\Invoicable\InvoicableServiceProvider" --tag="migrations"
迁移发布后,您可以通过运行迁移来创建发票和发票行表:
$ php artisan migrate
可选地,您也可以使用以下命令发布 invoicable.php
配置文件:
$ php artisan vendor:publish --provider="SanderVanHooft\Invoicable\InvoicableServiceProvider" --tag="config"
这是默认配置文件的样子:
return [ 'default_currency' => 'EUR', 'default_status' => 'concept', 'locale' => 'nl_NL', ];
如果您想覆盖发票 blade 视图和 PDF 的设计,请发布视图:
$ php artisan vendor:publish --provider="SanderVanHooft\Invoicable\InvoicableServiceProvider" --tag="views"
现在您可以在 <project_root>/resources/views/invoicable/receipt.blade.php
中编辑 receipt.blade.php
以匹配您的风格。
用法
金额以分表示!
将 invoicable 特性添加到需要开具发票的 Eloquent 模型(通常是订单模型)中
use Illuminate\Database\Eloquent\Model; use SanderVanHooft\Invoicable\IsInvoicable\IsInvoicableTrait; class Order extends Model { use IsInvoicableTrait; // enables the ->invoices() Eloquent relationship }
现在您可以创建订单的发票了
$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
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG。
测试
$ composer test
贡献
请参阅 CONTRIBUTING 和 CONDUCT 以获取详细信息。
安全
如果您发现任何与安全相关的问题,请通过电子邮件 info@sandervanhooft.com 而不是使用问题跟踪器来报告。
鸣谢
- Sander van Hooft
- 所有贡献者
- 灵感来源于 Laravel Cashier 的发票。
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。