intanode/receiptprinter

v1.5.0 2021-12-12 12:04 UTC

This package is not auto-updated.

Last update: 2024-09-19 02:46:58 UTC


README

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

安装

通过 Composer

$ composer require intanode/receiptprinter

用法

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

$ 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 Intanode\ReceiptPrinter\ReceiptPrinter as ReceiptPrinter;

然后使用以下两个函数之一发送“打印”命令到打印机。

printReceipt()
printRequest()

示例(打印收据)

use Intanode\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';

// 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 qr code
$printer->setQRcode([
    'tid' => $transaction_id,
]);

// Print receipt
$printer->printReceipt();

示例(打印请求)

use Intanode\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';

// 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 qr code
$printer->setQRcode([
    'tid' => $transaction_id,
    'amount' => $request_amount,
]);

// Print payment request
$printer->printRequest();

变更日志

请参阅变更日志以获取有关最近更改的更多信息。

致谢

许可证

MIT。请参阅许可证文件以获取更多信息。