cnrp / laravel-invoicer
使用spatiepdf的灵活发票包,适用于Laravel
1.0.1
2024-08-01 16:42 UTC
Requires
- php: ^7.3|^8.0
- illuminate/support: ^8.0|^9.0|^10.0
- illuminate/view: ^8.0|^9.0|^10.0
- livewire/livewire: ^3.5
- spatie/browsershot: ^4.0
- spatie/laravel-pdf: ^1.2
README
介绍
此包使用Spatie PDF生成发票。它简化了在Laravel应用程序中创建和管理发票的过程。
安装
要安装包,请使用Composer
composer require cnrp/invoice-package
安装包后,发布配置文件
php artisan vendor:publish --provider="CNRP\InvoicePackage\InvoiceServiceProvider" --tag=invoice
配置
配置文件位于config/invoice.php
。它包含以下设置
<?php return [ 'node_binary' => env('NODE_BINARY', 'node'), // Path to the Node.js executable 'default_theme'=> 'css/invoice-clean.php', // Path to the default invoice theme ];
Node二进制路径
node_binary
设置指定了机器上Node.js可执行文件的路径。这对于包正常工作是必要的。
-
Windows示例:
NODE_BINARY="C:\\Program Files\\nodejs\\node.exe"
-
Linux示例:
NODE_BINARY="/usr/local/bin/node"
确保在.env
文件中正确设置路径。
用法
安装和配置后,您可以使用此包生成发票。
基本示例
use CNRP\InvoicePackage\Invoice; // Add here whatever is nessescary, remove variables that are not required in your invoice $invoice = new Invoice( [ 'logo' => 'https://jordheyeshair.co.uk/images/graphics/logo.webp', 'title' => 'INVOICE', 'invoice_number' => 'INV-0001', 'date' => '19/06/2024', 'from' => [ 'name' => 'Jord Heyes Hair', 'phone' => '0987654321', 'email' => 'email@company.com', 'address_line_1' => '1234 Street Name', 'address_line_2' => 'Suite 567', 'address_line_3' => 'City, State, ZIP', ], 'to' => [ 'name' => 'Jane Doe', 'phone' => '0987654321', 'email' => 'customer@domain.com', 'address_line_1' => '5678 Client St', 'address_line_2' => 'Apt 910', 'address_line_3' => 'Client City, State, ZIP', ], 'description' => 'Invoice for services rendered', 'payment_terms' => 'Payment is due within 30 days.', 'payment_details' => 'Account Number/Sort Code: 12345678 / 12-34-56', 'footer' => 'See you soon!', 'is_paid' => true, ], // Items can be added as an array here. [ ['name' => 'Service 1', 'quantity' => 2, 'price' => 50], ['name' => 'Product A', 'description' => 'High quality product', 'quantity' => 1, 'price' => 30], ['name' => 'Consultation', 'price' => 100] ] ); // Alternatively to add items you can call upon the addItem method on the Invoice $invoice->addItem([ 'name' => 'Booking Deposit', 'Move Date' => '2024-07-19', 'price' => 150, ]); // Generate the PDF & Download return $invoice->generateAndDownloadPdf();
此示例演示了如何创建一个新的发票,包含客户详情、项目和总计金额,然后将生成的PDF保存到指定的路径。表中的列由您添加的项目确定,项目中唯一必需的值是'price'。
主题
默认情况下,它使用css/invoice-clean.php
主题。
如果您想更改此设置,请编辑已发布的视图resources/views/vendor/invoice/default.blade.php
并更改
@vite(['resources/css/invoice-clean.css'])
或更新文件resources/css/invoice-clean.css
。
许可证
此包是开源软件,受MIT许可证许可。