ikidnapmyself / laravel-invoicable
该软件包已被废弃,不再维护。作者建议使用ikidnapmyself/laravel-invoicable软件包。
使用 Laravel Eloquent 简单创建发票,最初由 sander-van-hooft/laravel-invoicable 创建
v2.0.2
2019-06-09 22:29 UTC
Requires
- php: ~5.6|~7.0
- ext-intl: *
- dompdf/dompdf: ^0.8.0
- illuminate/support: ~5.1|~5.2|~5.3|~5.4|~5.5|~5.6
- nesbot/carbon: ^1.22
- webpatser/laravel-uuid: ^3.0
Requires (Dev)
- graham-campbell/testbench: ^3.3
- mockery/mockery: ^0.9.9
- orchestra/database: ^3.4
- phpunit/phpunit: ~4.0||~5.0||~6.0||~7.0
- squizlabs/php_codesniffer: ^2.3
README
重要!此存储库是 sandervanhooft/laravel-invoicable
的分支,将用于个人使用。任何贡献都十分欢迎。
为 Laravel 5.4 及更高版本提供简单的发票创建功能。与 Laravel Cashier 不同,此软件包与支付网关无关。
如果您需要 Mollie 支付处理,请务必查看 laravel-payable-redirect-mollie。
结构
database/
resources
src/
tests/
vendor/
安装
通过 Composer
$ composer require ikidnapmyself/laravel-invoicable
您可以使用以下命令发布迁移:
$ php artisan vendor:publish --provider="IKidnapMyself\Invoicable\InvoicableServiceProvider" --tag="migrations"
迁移发布后,您可以通过运行迁移来创建 invoices 和 invoice_lines 表
$ php artisan migrate
可选地,您还可以使用以下命令发布 invoicable.php
配置文件:
$ php artisan vendor:publish --provider="IKidnapMyself\Invoicable\InvoicableServiceProvider" --tag="config"
这是默认配置文件的外观:
return [ 'default_currency' => 'EUR', 'default_status' => 'concept', 'locale' => 'nl_NL', ];
如果您想覆盖发票 blade 视图和 pdf 的设计,请发布视图:
$ php artisan vendor:publish --provider="IKidnapMyself\Invoicable\InvoicableServiceProvider" --tag="views"
现在您可以在 <project_root>/resources/views/invoicable/receipt.blade.php
中编辑 receipt.blade.php
以匹配您的风格。
使用
货币金额以分计算!
将 invoicable 特性添加到需要开具发票的 Eloquent 模型中(通常是 Order 模型)
use Illuminate\Database\Eloquent\Model; use IKidnapMyself\Invoicable\IsInvoicable\IsInvoicableTrait; class Order extends Model { use IsInvoicableTrait; // enables the ->invoices() Eloquent relationship }
现在您可以创建订单的发票了
$order = new Order(); $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->addLinetInclTax(121, 'Some description', 0.21); $invoice = $invoice->addLinetExclTax(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->addLinetInclTax(-121, 'A nice discount', 0.21); // Or by applying the discount and discribing the discount manually $invoice = $invoice->addLinetInclTax(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)。有关更多信息,请参阅 许可文件。