charlieuki / receiptprinter
:描述
1.2.5a
2021-11-20 15:15 UTC
Requires
- illuminate/support: >=7
- mike42/escpos-php: ^2.1
Requires (Dev)
- mockery/mockery: ^1.1
- orchestra/testbench: ~5.3
- phpunit/phpunit: ~8.5
- sempro/phpunit-pretty-print: ^1.0
README
这是一个简单的Laravel包,用于集成PHP的ESC/POS打印驱动程序。
安装
通过Composer
$ composer require charlieuki/receiptprinter
示例应用
我已经基于Laravel 7搭建了一个简单的应用,可以作为演示使用。
用法
执行以下命令以发布此包使用的配置
$ php artisan vendor:publish --tag=receiptprinter.config
按照以下方式编辑位于 config/receiptprinter.php
的配置文件
- 将
connector_type
设置为windows
如果您使用Windows作为您的Web服务器。cups
如果您使用Linux或Mac作为您的Web服务器。network
如果您使用网络打印机。
- 将
connector_descriptor
设置为- 如果您的
connector_type
是windows
或cups
,则为打印机名称 - 如果您的
connector_type
是network
,则为IP地址或Samba URI,例如:smb://192.168.0.5/PrinterName
- 如果您的
- 如果您的
connector_type
是network
,则将connector_port
设置为打印机的开放端口
包含库
use charlieuki\ReceiptPrinter\ReceiptPrinter as ReceiptPrinter;
然后使用以下两个函数之一将“打印”命令发送到打印机。
printReceipt()
printRequest()
示例(打印收据)
use charlieuki\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 charlieuki\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 Print Driver 库
许可
MIT。请参阅 许可文件 了解更多信息。