dashed/receiptprinter

v1.0.9 2024-09-26 10:25 UTC

This package is auto-updated.

Last update: 2024-09-26 10:26:09 UTC


README

Latest Version on Packagist Total Downloads Build Status StyleCI

一个简单的Laravel包,用于集成PHP的ESC/POS打印驱动程序。

安装

通过Composer

$ composer require Dashed/receiptprinter

示例应用

我已创建了一个基于Laravel 7的简单应用,您可以在此处查看,作为演示使用。

使用方法

执行以下命令以发布此包使用的配置

$ php artisan vendor:publish --tag=receiptprinter.config

按照以下方式编辑位于config/receiptprinter.php的配置文件

  1. connector_type设置为
    • 如果您使用Windows作为您的Web服务器,则设置为windows
    • 如果您使用Linux或Mac作为您的Web服务器,则设置为cups
    • 如果您使用网络打印机,则设置为network
  2. connector_descriptor设置为
    • 如果您connector_typewindowscups,则设置为打印机名称
    • 如果您connector_typenetwork,则设置为IP地址或Samba URI,例如:smb://192.168.0.5/PrinterName
  3. 如果您connector_typenetwork,则将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以获取详细信息以及待办事项列表。

问题

如果您发现任何问题,请在问题跟踪器上发布详细信息。

鸣谢

许可证

MIT。请查看许可证文件以获取更多信息。