沙德·范·胡夫特 / laravel-invoicable
使用 Laravel Eloquent 简易生成发票
1.4.0
2021-06-08 12:40 UTC
Requires
- php: ^7.4 || ^8.0
- ext-intl: *
- dompdf/dompdf: ^1.0
- illuminate/support: ^7.0 || ^8.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 联系,而不是使用问题跟踪器。
致谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。