bkfdev / invoicable
使用Laravel Eloquent轻松生成发票
v1.1.8
2024-02-13 06:16 UTC
README
Laravel的简单发票创建。与Laravel Cashier不同,此包与支付网关无关。
结构
database/
resources
src/
tests/
vendor/
安装
通过Composer
composer require bkfdev/invoicable
接下来,如果您使用Laravel 5.4,您必须安装服务提供程序
// config/app.php 'providers' => [ ... Bkfdev\Invoicable\InvoicableServiceProvider::class, ];
您可以使用以下命令发布迁移:
php artisan vendor:publish --provider="Bkfdev\Invoicable\InvoicableServiceProvider" --tag="migrations"
迁移发布后,您可以通过运行迁移来创建发票和发票行表
php artisan migrate
可选地,您也可以使用以下命令发布invoicable.php
配置文件:
php artisan vendor:publish --provider="Bkfdev\Invoicable\InvoicableServiceProvider" --tag="config"
这是默认配置文件的外观:
return [ 'invoice_number' => 'INV#' . date('M-y') . '-', 'payment_number' => 'PAY#' . date('M-y') . '-', ];
如果您想覆盖发票blade视图和pdf的设计,请发布视图
php artisan vendor:publish --provider="Bkfdev\Invoicable\InvoicableServiceProvider" --tag="views"
现在您可以在<project_root>/resources/views/invoicable/receipt.blade.php
中编辑receipt.blade.php
以匹配您的风格。
使用方法
货币金额以分计!
将invoicable特性添加到需要开票的Eloquent模型中(通常是订单模型)
use Illuminate\Database\Eloquent\Model; use Bkfdev\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@Bkfdev.com联系,而不是使用问题跟踪器。
致谢
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。