millieofzo / php-invoicer
使用 PHP 生成 PDF 发票的库
Requires
- php: >=5.6
- setasign/fpdf: ~1.8.1
Requires (Dev)
- phpunit/phpunit: ^7
This package is not auto-updated.
Last update: 2024-09-27 09:36:46 UTC
README
PHP Invoicer
特性
- PHP 7.2 支持
- PSR-4 兼容
- 可作为 composer 包使用
- 依赖项通过 composer 提供
介绍
PHP Invoicer 是一个简单的面向对象的 PHP 类,只需几行代码即可生成美观的发票、报价或订单。使用您自己的标志和主题颜色进行品牌化,添加无限数量的商品和总行数,并实现自动分页。您可以将 PDF 输出交付给用户的浏览器,保存在服务器上或强制下载文件。PHP Invoicer 完全可定制,并可集成到任何知名 CMS。
多语言和货币
PHP Invoicer 内置以下语言的翻译:
- 英语
- 荷兰语
- 法语
- 德语
- 西班牙语
- 意大利语
- 葡萄牙语
如果需要,您可以轻松添加自己的语言,并且可以为每个文档设置所需的货币。
额外的标题、段落和徽章
可以在文档底部添加额外的内容(标题和多行段落)。您可能将其用于付款或运输信息或任何其他所需内容。
/* Set badge */ $invoice->addBadge("Payment Paid"); /* Add title */ $invoice->addTitle("Important Notice"); /* Add Paragraph */ $invoice->addParagraph("No item will be replaced or refunded if you don't have the invoice with you. You can refund within 2 days of purchase."); /* Set footer note */ $invoice->setFooternote("My Company Name Here");
安装
composer require millieofzo/php-invoicer
示例
此存储库的 examples/
文件夹中包含 3 个示例
- simple.php
- example1.php
- invoice.php
创建新发票
在这个简单的示例中,我们生成一个带有自定义标志和主题颜色的发票。它将包含 2 个产品,底部有一个包含 21% 增值税和总价格的框。然后我们在输出前添加一个“已付款”徽章。
use MillieOfzo\PHPInvoicer\PHPInvoicer; $invoice = new PHPInvoicer('','€','en'); /* Header Settings */ $invoice->setLogo("../examples/images/ti_logo_yellow.png"); $invoice->setColor("#4d4c59"); $invoice->setType("Simple Invoice"); $invoice->setOrderid("2018052100012"); $invoice->setReference("55033645"); $invoice->setDate(date('d-m-Y',time())); $invoice->setDue(date('d-m-Y',strtotime('+3 months'))); $invoice->hide_tofrom(); /* Adding Items in table */ $invoice->addItem("AMD Athlon X2DC-7450","2.4GHz/1GB/160GB/SMP-DVD/VB",2,2); $invoice->addItem("PDC-E5300","2.6GHz/1GB/320GB/SMP-DVD/FDD/VB",4,645); /* Add totals */ $invoice->addSubTotal(); $invoice->addVatTotal(21); $invoice->addTotal(true); /* Set badge */ $invoice->addBadge("Payment Paid"); /* Render */ /* I => Display on browser, D => Force Download, F => local path save, S => return document path */ $invoice->render('example2.pdf','I');
文档
创建实例
use MillieOfzo\PHPInvoicer\PHPInvoicer; // Default Param: Size: A4, Currency: $, Language: en $invoice = new PHPInvoicer($size, $currency, $language);
数字格式化
您想如何显示您的数字?
$invoice->setNumberFormat($decimalpoint, $seperator);
颜色
设置自定义颜色以个性化您的发票。
// Hexadecimal color code $invoice->setColor($color);
添加标志
$invoice->setLogo($image, $maxwidth, $maxheight);
文档标题
// A string with the document title, will be displayed // in the right top corner of the document (e.g. 'Invoice' or 'Quote') $invoice->setType($title);
订单 ID
// Set order ID of document that will be displayed in // the right top corner of the document (e.g. '2018052100012') $invoice->setOrderid($orderid);
发票号码
// Document reference number that will be displayed in // the right top corner of the document (e.g. 'INV29782') $invoice->setReference($number);
日期
//A string with the document's date $invoice->setDate($date);
到期日期
// A string with the document's due date $invoice->setDue($duedate); // Example $invoice->setDue(date('d-m-Y',strtotime('+3 months')));
发行者信息
设置您的公司详细信息。一个包含您的公司详细信息的数组。数组的第一个值将在文档上加粗显示,因此建议您使用公司的名称。您可以根据需要添加任意行。
/** Example: */ $invoice->setFrom([ 'My Company', 'Address line 1', 'Address line 2', 'City and zip', 'Country', 'VAT number', 'test' ]);
客户信息
一个包含您的客户详细信息的数组。数组的第一个值将在文档上加粗显示,因此我们建议您使用公司的名称。您可以根据需要添加任意行。
注意:请保持发行者和客户数组的计数相同。如果需要,请使用空值。
/** Example */ $invoice->setTo([ 'My Client', 'Address line 1', 'Address line 2', 'City and zip', 'Country', 'VAT number', '' //Note keep count the same as issuer ]);
翻转
切换公司和客户信息的水平位置。默认情况下,您的公司详细信息在左侧。
$invoice->flipflop();
添加项目
在公司和客户信息下方添加新的产品或服务行到您的文档中。PHP Invoicer 具有自动分页功能,因此没有任何限制。
// $vat and $discount are optional $invoice->addItem($name,$description,$quantity,$price,$vat = false,$discount = false);
添加小计
在产品下方添加一行,显示所有产品的计算合并价格总额。
$invoice->addSubTotal();
添加折扣
在产品下方添加一行,显示计算后的折扣价格。指定折扣金额为整数,例如 10。
$invoice->addDiscountTotal($percent);
添加增值税
在产品下方添加一行,显示计算后的增值税金额。增值税在折扣后计算。指定增值税金额为整数,例如 21。
$invoice->addVatTotal($percent);
添加总计
在产品和服务下方添加一行,显示总金额。包括增值税金额和任何折扣金额。
$invoice->addTotal($colored);
添加行
在产品和服务下方添加一行进行计算和总计。您可以添加无限行。
$invoice->addRow($name,$value,$colored);
- $name {string} 显示总计的字符串
- $value {decimal} 值的小数
- 设置主题颜色为行的背景颜色(可选)
添加徽章
在您的发票中产品和服务下方添加徽章。您可以使用此功能,例如显示发票已支付。
$invoice->addBadge($badge, $color);
- $badge {字符串} 徽章文本的字符串。
- $color {字符串} 可选。包含颜色十六进制代码的字符串。
添加标题
您可以在文档底部添加标题和段落以显示信息,例如付款详情或运输信息。
$invoice->addTitle($title);
- $title {字符串} 要显示在徽章中的标题的字符串。
添加段落
您可以在文档底部添加标题和段落以显示信息,例如付款详情或运输信息。
$invoice->addParagraph($paragraph);
- $Paragraph {字符串} 支持多行的段落文本的字符串。使用
或 \n 添加换行符。
页脚
您想在文档底部左角显示的简短文本。
$invoice->setFooternote($note);
- $note {字符串} 包含您想在页脚中显示的信息的字符串。
渲染发票
$invoice->render($name, $output); // Example: // $invoice->render('invoice.pdf', 'S')
- $name {字符串} 发票名称的字符串。
- $output {字符串} 选择您希望如何将发票交付给用户。
以下选项可用
- I(将文件内联发送到浏览器)
- D(发送到浏览器,并强制使用name参数中给出的名称下载文件)
- F(保存到本地文件。确保在name参数中设置路径)
- S(将文档作为字符串返回)