dashed / receiptprinter
:描述
v1.0.9
2024-09-26 10:25 UTC
Requires
- illuminate/support: ^11.0
- mike42/escpos-php: ^4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- mockery/mockery: ^1.1
- orchestra/testbench: ^9.5
- phpunit/phpunit: ^11.3
- sempro/phpunit-pretty-print: ^1.0
README
一个简单的Laravel包,用于集成PHP的ESC/POS打印驱动程序。
安装
通过Composer
$ composer require Dashed/receiptprinter
示例应用
我已创建了一个基于Laravel 7的简单应用,您可以在此处查看,作为演示使用。
使用方法
执行以下命令以发布此包使用的配置
$ php artisan vendor:publish --tag=receiptprinter.config
按照以下方式编辑位于config/receiptprinter.php
的配置文件
- 将
connector_type
设置为- 如果您使用Windows作为您的Web服务器,则设置为
windows
- 如果您使用Linux或Mac作为您的Web服务器,则设置为
cups
- 如果您使用网络打印机,则设置为
network
- 如果您使用Windows作为您的Web服务器,则设置为
- 将
connector_descriptor
设置为- 如果您
connector_type
为windows
或cups
,则设置为打印机名称 - 如果您
connector_type
为network
,则设置为IP地址或Samba URI,例如:smb://192.168.0.5/PrinterName
- 如果您
- 如果您
connector_type
为network
,则将connector_port
设置为打印机的开放端口
包含库
use Dashed\ReceiptPrinter\ReceiptPrinter as ReceiptPrinter;
然后使用以下两个函数之一将“打印”命令发送到打印机。
printReceipt()
printRequest()
示例(打印收据)
use Dashed\ReceiptPrinter\ReceiptPrinter as ReceiptPrinter;
...
// Set params
$mid = '123123456';
$store_name = 'YOURMART';
$store_address = 'Mart Address';
$store_phone = '1234567890';
$store_email = 'yourmart@email.com';
$store_website = 'yourmart.com';
$tax_percentage = 10;
$transaction_id = 'TX123ABC456';
$currency = 'Rp';
$image_path = 'logo.png';
// Set items
$items = [
[
'name' => 'French Fries (tera)',
'qty' => 2,
'price' => 65000,
],
[
'name' => 'Roasted Milk Tea (large)',
'qty' => 1,
'price' => 24000,
],
[
'name' => 'Honey Lime (large)',
'qty' => 3,
'price' => 10000,
],
[
'name' => 'Jasmine Tea (grande)',
'qty' => 3,
'price' => 8000,
],
];
// Init printer
$printer = new ReceiptPrinter;
$printer->init(
config('receiptprinter.connector_type'),
config('receiptprinter.connector_descriptor')
);
// Set store info
$printer->setStore($mid, $store_name, $store_address, $store_phone, $store_email, $store_website);
// Set currency
$printer->setCurrency($currency);
// Add items
foreach ($items as $item) {
$printer->addItem(
$item['name'],
$item['qty'],
$item['price']
);
}
// Set tax
$printer->setTax($tax_percentage);
// Calculate total
$printer->calculateSubTotal();
$printer->calculateGrandTotal();
// Set transaction ID
$printer->setTransactionID($transaction_id);
// Set logo
// Uncomment the line below if $image_path is defined
//$printer->setLogo($image_path);
// Set QR code
$printer->setQRcode([
'tid' => $transaction_id,
]);
// Print receipt
$printer->printReceipt();
示例(打印请求)
use Dashed\ReceiptPrinter\ReceiptPrinter as ReceiptPrinter;
...
// Set params
$mid = '123123456';
$store_name = 'YOURMART';
$store_address = 'Mart Address';
$store_phone = '1234567890';
$store_email = 'yourmart@email.com';
$store_website = 'yourmart.com';
$tax_percentage = 10;
$transaction_id = 'TX123ABC456';
$currency = 'Rp';
$image_path = 'logo.png';
// Init printer
$printer = new ReceiptPrinter;
$printer->init(
config('receiptprinter.connector_type'),
config('receiptprinter.connector_descriptor')
);
// Set store info
$printer->setStore($mid, $store_name, $store_address, $store_phone, $store_email, $store_website);
// Set currency
$printer->setCurrency($currency);
// Set request amount
$printer->setRequestAmount($request_amount);
// Set transaction ID
$printer->setTransactionID($transaction_id);
// Set logo
// Uncomment the line below if $image_path is defined
//$printer->setLogo($image_path);
// Set QR code
$printer->setQRcode([
'tid' => $transaction_id,
'amount' => $request_amount,
]);
// Print payment request
$printer->printRequest();
变更日志
请查看变更日志以获取有关最近更改的更多信息。
贡献
请查看contributing.md以获取详细信息以及待办事项列表。
问题
如果您发现任何问题,请在问题跟踪器上发布详细信息。
鸣谢
- Mike42,感谢他提供的优秀的PHP ESC/POS打印驱动程序库
许可证
MIT。请查看许可证文件以获取更多信息。