rifthyahmed / laravel-invoices
Laravel 缺失发票
dev-master
2021-03-19 05:54 UTC
Requires
- php: >=7.2.5
- barryvdh/laravel-dompdf: ^0.8.5
- illuminate/http: ^5.5|^6|^7
- illuminate/support: ^5.5|^6|^7
Requires (Dev)
- phpunit/phpunit: ^8.4
- symfony/var-dumper: ^5.0
This package is not auto-updated.
Last update: 2024-09-28 22:51:38 UTC
README
此 Laravel 包提供了一个易于使用的界面,用于生成包含您提供数据的 发票 PDF 文件。
发票文件可以存储、下载、在任何您配置的文件系统中流式传输。支持不同的模板和区域设置。
原始包是在 PHP 7.3.11 和 Laravel 6.2 上开发的,但应该也能在较低版本上工作。
功能
- 税费 - 固定或按比率 - 对项目或发票
- 折扣 - 固定或按百分比 - 对项目或发票
- 运费 - 将运费添加到您的发票中
- 自动计算 - 提供最小信息集,或自行计算并提供要打印的内容
- 到期日
- 易于自定义货币格式
- 按您的喜好设置序列号
- 模板
- 翻译
- 全局设置和即时覆盖
变更日志
请参阅 变更日志 了解最近有哪些更改。
安装
通过 Composer
$ composer require laraveldaily/laravel-invoices
安装 Laravel Invoices 后,使用 invoices:install
Artisan 命令发布其资产、视图、翻译和配置
$ php artisan invoices:install
更新
由于它发展迅速,您可能希望使用 Artisan 命令更新模板以获取最新版本
$ php artisan invoices:update
如果确实要覆盖默认资源,它将给出警告
或者,也可以分别执行。
$ php artisan vendor:publish --tag=invoices.views --force
$ php artisan vendor:publish --tag=invoices.translations --force
对于 Laravel 版本 < 5.5
如果您不使用自动发现,请将 ServiceProvider 添加到 config/app.php
中的 providers 数组
LaravelDaily\Invoices\InvoiceServiceProvider::class,
如果您想使用外观来生成发票,请将其添加到您的 facades 中的 config/app.php
'Invoice' => LaravelDaily\Invoices\Facades\Invoice::class
基本用法
RandomController.php
use LaravelDaily\Invoices\Invoice; use LaravelDaily\Invoices\Classes\Buyer; use LaravelDaily\Invoices\Classes\InvoiceItem; <...> $customer = new Buyer([ 'name' => 'John Doe', 'custom_fields' => [ 'email' => 'test@example.com', ], ]); $item = (new InvoiceItem())->title('Service 1')->pricePerUnit(2); $invoice = Invoice::make() ->buyer($customer) ->discountByPercent(10) ->taxRate(15) ->shipping(1.99) ->addItem($item); return $invoice->stream();
查看结果 Invoice_AA_00001.pdf。
高级用法
use LaravelDaily\Invoices\Invoice; use LaravelDaily\Invoices\Classes\Party; use LaravelDaily\Invoices\Classes\InvoiceItem; <...> $client = new Party([ 'name' => 'Roosevelt Lloyd', 'phone' => '(520) 318-9486', 'custom_fields' => [ 'note' => 'IDDQD', 'business id' => '365#GG', ], ]); $customer = new Party([ 'name' => 'Ashley Medina', 'address' => 'The Green Street 12', 'code' => '#22663214', 'custom_fields' => [ 'order number' => '> 654321 <', ], ]); $items = [ (new InvoiceItem())->title('Service 1')->pricePerUnit(47.79)->quantity(2)->discount(10), (new InvoiceItem())->title('Service 2')->pricePerUnit(71.96)->quantity(2), (new InvoiceItem())->title('Service 3')->pricePerUnit(4.56), (new InvoiceItem())->title('Service 4')->pricePerUnit(87.51)->quantity(7)->discount(4)->units('kg'), (new InvoiceItem())->title('Service 5')->pricePerUnit(71.09)->quantity(7)->discountByPercent(9), (new InvoiceItem())->title('Service 6')->pricePerUnit(76.32)->quantity(9), (new InvoiceItem())->title('Service 7')->pricePerUnit(58.18)->quantity(3)->discount(3), (new InvoiceItem())->title('Service 8')->pricePerUnit(42.99)->quantity(4)->discountByPercent(3), (new InvoiceItem())->title('Service 9')->pricePerUnit(33.24)->quantity(6)->units('m2'), (new InvoiceItem())->title('Service 11')->pricePerUnit(97.45)->quantity(2), (new InvoiceItem())->title('Service 12')->pricePerUnit(92.82), (new InvoiceItem())->title('Service 13')->pricePerUnit(12.98), (new InvoiceItem())->title('Service 14')->pricePerUnit(160)->units('hours'), (new InvoiceItem())->title('Service 15')->pricePerUnit(62.21)->discountByPercent(5), (new InvoiceItem())->title('Service 16')->pricePerUnit(2.80), (new InvoiceItem())->title('Service 17')->pricePerUnit(56.21), (new InvoiceItem())->title('Service 18')->pricePerUnit(66.81)->discountByPercent(8), (new InvoiceItem())->title('Service 19')->pricePerUnit(76.37), (new InvoiceItem())->title('Service 20')->pricePerUnit(55.80), ]; $notes = [ 'your multiline', 'additional notes', 'in regards of delivery or something else', ]; $notes = implode("<br>", $notes); $invoice = Invoice::make('receipt') ->series('BIG') ->sequence(667) ->serialNumberFormat('{SEQUENCE}/{SERIES}') ->seller($client) ->buyer($customer) ->date(now()->subWeeks(3)) ->dateFormat('m/d/Y') ->payUntilDays(14) ->currencySymbol('$') ->currencyCode('USD') ->currencyFormat('{SYMBOL}{VALUE}') ->currencyThousandsSeparator('.') ->currencyDecimalPoint(',') ->filename($client->name . ' ' . $customer->name) ->addItems($items) ->notes($notes) ->logo(public_path('vendor/invoices/sample-logo.png')) // You can additionally save generated invoice to configured disk ->save('public'); $link = $invoice->url(); // Then send email to party with link // And return invoice itself to browser or have a different view return $invoice->stream();
查看结果 Roosevelt Lloyd Ashley Medina.pdf。
使用外观的替代方案
您可以选择使用外观来创建新当事人或项目
use Invoice; $customer = Invoice::makeParty([ 'name' => 'John Doe', ]); $item = Invoice::makeItem('Your service or product title')->pricePerUnit(9.99); return Invoice::make()->buyer($customer)->addItem($item)->stream();
配置
return [ 'date' => [ /** * Carbon date format */ 'format' => 'Y-m-d', /** * Due date for payment since invoice's date. */ 'pay_until_days' => 7, ], 'serial_number' => [ 'series' => 'AA', 'sequence' => 1, /** * Sequence will be padded accordingly, for ex. 00001 */ 'sequence_padding' => 5, 'delimiter' => '.', /** * Supported tags {SERIES}, {DELIMITER}, {SEQUENCE} * Example: AA.00001 */ 'format' => '{SERIES}{DELIMITER}{SEQUENCE}', ], 'currency' => [ 'code' => 'eur', /** * Usually cents * Used when spelling out the amount and if your currency has decimals. * * Example: Amount in words: Eight hundred fifty thousand sixty-eight EUR and fifteen ct. */ 'fraction' => 'ct.', 'symbol' => '€', /** * Example: 19.00 */ 'decimals' => 2, /** * Example: 1.99 */ 'decimal_point' => '.', /** * By default empty. * Example: 1,999.00 */ 'thousands_separator' => '', /** * Supported tags {VALUE}, {SYMBOL}, {CODE} * Example: 1.99 € */ 'format' => '{VALUE} {SYMBOL}', ], 'paper' => [ // A4 = 210 mm x 297 mm = 595 pt x 842 pt 'size' => 'a4', 'orientation' => 'portrait', ], 'disk' => 'local', 'seller' => [ /** * Class used in templates via $invoice->seller * * Must implement LaravelDaily\Invoices\Contracts\PartyContract * or extend LaravelDaily\Invoices\Classes\Party */ 'class' => \LaravelDaily\Invoices\Classes\Seller::class, /** * Default attributes for Seller::class */ 'attributes' => [ 'name' => 'Towne, Smith and Ebert', 'address' => '89982 Pfeffer Falls Damianstad, CO 66972-8160', 'code' => '41-1985581', 'vat' => '123456789', 'phone' => '760-355-3930', 'custom_fields' => [ /** * Custom attributes for Seller::class * * Used to display additional info on Seller section in invoice * attribute => value */ 'SWIFT' => 'BANK101', ], ], ], ];
可用方法
几乎每个配置值都可以通过方法动态覆盖。
发票
通用
- addItem(InvoiceItem $item)
- addItems(Iterable)
- name(string)
- seller(PartyContract)
- buyer(PartyContract)
- template(string)
- logo(string) - logo 的路径
- getLogo() - 返回 base64 编码的图像,在模板中使用以避免路径问题
- filename(string) - 覆盖自动文件名
- taxRate(float)
- shipping(float) - 运费金额
- totalDiscount(float) - 如果未提供,则自行计算
- totalTaxes(float) - 如果未提供,则自行计算
- totalAmount(float) - 如果未提供,则自行计算
- taxableAmount(float) - 如果未提供,则自行计算
序列号
- series(string)
- sequence(int)
- delimiter(string)
- sequencePadding(int)
- serialNumberFormat(string)
- getSerialNumber() - 返回格式化的序列号
日期
- date(Carbon)
- dateFormat(string) - 日期的 Carbon 格式
- payUntilDays(int) - 自发票发出以来的付款天数
- getDate() - 返回格式化的日期
- getPayUntilDate() - 返回格式化的到期日期
货币
- currencyCode(string) - EUR, USD 等。
- currencyFraction(string) - 分、分币、便士等。
- currencySymbol(string)
- currencyDecimals(int)
- currencyDecimalPoint(string)
- currencyThousandsSeparator(string)
- currencyFormat(string)
- getAmountInWords(float) - 将浮点数转换为文字(仅限英语)
- getTotalAmountInWords() - 将 total_amount 转换为文字
- formatCurrency(float) - 返回格式化的货币值,格式为 '$ 1,99'
文件
- stream() - 在浏览器中打开发票
- download() - 提供下载发票
- save($disk) - 将发票保存到存储,使用 ->filename() 设置文件名
- url() - 返回保存的发票的 URL
InvoiceItem
- title(string) - 产品或服务名称
- units(string) - 项目的计量单位(如果设置,将添加单位列)
- quantity(float) - 项目的单位数量
- pricePerUnit(float)
- discount(float) - 货币形式的折扣
- discountByPercent(float) - 百分比折扣,discountByPercent(15) 表示 15%
- tax(float)
- taxByPercent(float)
- subTotalPrice(float) - 如果未提供,则自动计算
测试
$ composer test
安全
如果您发现任何与安全相关的问题,请通过电子邮件 mysticcode@gmail.com 联系我们,而不是使用问题跟踪器。
作者
许可证
GPL-3.0-only。有关更多信息,请参阅许可证文件。