soap / laravel-invoices
使用 Laravel Eloquent 轻松生成发票
v3.0.1
2021-10-14 07:37 UTC
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-09-14 21:31:11 UTC
README
此软件包已被更改、更新和重新分发。要使用原始分发,请参阅 NeptuneSoftware/laravel-invoice 仓库。
重要
此分支将由 Prasit Gebsaap 维护,并且与原始仓库不兼容。
为 Laravel 创建发票非常简单。与 Laravel Cashier 不同,此软件包不依赖于特定的支付网关。
有什么不同?
为了跟踪变更,请参阅 变更日志 文件。
结构
.
├── 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
安装
通过 Composer
$ composer require soap/laravel-invoices
您可以使用以下命令发布迁移
$ php artisan vendor:publish --provider="Soap\Invoices\Providers\InvoicesServiceProvider" --tag="migrations"
迁移发布后,您可以通过运行迁移来创建发票和发票行表
$ php artisan migrate
可选地,您还可以使用以下命令发布 invoices.php
配置文件
$ php artisan vendor:publish --provider="Soap\Invoices\Providers\InvoicesServiceProvider" --tag="config"
这是默认配置文件的样子
return [ 'default_currency' => 'THB', 'default_status' => 'draft', 'locale' => 'th_TH', 'table_names' => [ 'invoices' => 'invoices', 'invoice_lines' => 'invoice_lines', ] ];
如果您想覆盖发票 blade 视图和 pdf 的设计,请发布视图
$ php artisan vendor:publish --provider="Soap\Invoices\Providers\InvoiceServiceProvider" --tag="views"
现在您可以在 <project_root>/resources/views/invoice/receipt.blade.php
中的 receipt.blade.php
进行编辑以匹配您的风格。
使用方法
货币金额以分表示!
将 HasInvoice 特性添加到需要发送或接收发票的 Eloquent 模型(通常是客户或公司模型)中
use Illuminate\Database\Eloquent\Model; use Soap\Invoices\Traits\HasInvoice; class Order extends Model { use HasInvoices; // enables the ->invoices() Eloquent relationship }
现在您可以为客户创建发票
$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
变更日志
有关最近更改的详细信息,请参阅 CHANGELOG。
测试
$ composer test
贡献
请参阅 CONTRIBUTING 和 CONDUCT 以获取详细信息。
鸣谢
- Burak
- Fatih
- Uğur
- Sander van Hooft
- 所有贡献者
- 受 Laravel Cashier 的发票启发。
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。