php 用于PHP的POS打印驱动程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 用于PHP的POS打印驱动程序相关的知识,希望对你有一定的参考价值。
<?php
// Plugin: ESC/POS Print Driver for PHP (https://github.com/mike42/escpos-php)
function print_receipt( $invoice_data, $invoice_items ) {
try {
// Enter the share name for your USB printer here
$connector = new WindowsPrintConnector( "CITIZEN CBM1000 Type II" );
/* Print a "Hello world" receipt" */
$printer = new Printer( $connector );
$printer->setEmphasis( true );
$printer->setPrintLeftMargin( 128 );
$printer->setTextSize( 2, 6 );
$printer->text( "Point of Sale\n" );
$printer->setPrintLeftMargin( 0 );
$printer->setEmphasis( false );
$printer->text( "------------------------------------------------". "\n" );
$printer->setPrintLeftMargin( 4 );
$printer->setJustification();
$printer->text( "\n" );
$printer->text( "Invoice Number : " . $invoice_data['invoice_number'] . "\n" );
$printer->text( "===============================================\n" );
$printer->text( "Item Name QTY Price Total\n" );
$printer->text( "===============================================\n" );
foreach ( $invoice_items as $item ) {
$product_details = Product::where( 'id', $item['product_id'] )->get();
$product_details = $product_details[0];
$printer->text( $product_details->title . " \n" );
$printer->text( $item['qty'] . " | $" . $product_details->sale_price . " | $" . ( $item['qty'] * $product_details->sale_price ) . " \n" );
$printer->setJustification();
$printer->text( "-----------------------------------------------". "\n" );
}
$printer->setJustification(1);
$printer->text( " SUB TOTAL : $ " . $invoice_data['sub_total'] . " \n" );
$printer->text( " DISC : % " . $invoice_data['discount'] . " \n" );
$printer->text( " Grand TOTAL : $ " . $invoice_data['total'] . " \n" );
$printer->text( "-----------------------------------------------". "\n" );
$printer->text( "Thank you for visiting us !\n" );
$printer->setJustification();
$printer->text( "-----------------------------------------------". "\n" );
$printer->text( "Cashier : " . $invoice_data['employee_name'] . " \n" );
$printer->text( date( "d/m/Y H:i:s" ) . "\n" );
$printer->text( "\n" );
$printer->text( "\n" );
$printer->cut();
$printer->close();
} catch ( Exception $e ) {
$message = $e->getMessage();
echo $message;die;
}
}
?>
以上是关于php 用于PHP的POS打印驱动程序的主要内容,如果未能解决你的问题,请参考以下文章