-
Notifications
You must be signed in to change notification settings - Fork 862
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #801 from mike42/development
Changes for release v2.2
- Loading branch information
Showing
6 changed files
with
314 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<!DOCTYPE html> | ||
<html lang="ru"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>RawBT Integration Demo</title> | ||
<meta content="width=device-width, initial-scale=1" name="viewport"> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | ||
<style> | ||
html { | ||
background-color: grey; | ||
padding: 32px; | ||
} | ||
|
||
body { | ||
max-width: 640px; | ||
margin: 0 auto; | ||
padding: 32px; | ||
background-color: white; | ||
} | ||
|
||
button { | ||
background-color: #6e89ff; | ||
color: white; | ||
padding: 16px; | ||
border: none; | ||
} | ||
|
||
pre { | ||
background-color: #f0f0f0; | ||
border-left: #6e89ff solid 3px | ||
} | ||
|
||
p { | ||
text-align: right; | ||
} | ||
|
||
a { | ||
color: #6e89ff; | ||
text-decoration: none; | ||
} | ||
a:before{ | ||
content: '\1F855'; | ||
margin-right:4px; | ||
} | ||
</style> | ||
<script> | ||
// for php demo call | ||
function ajax_print(url, btn) { | ||
b = $(btn); | ||
b.attr('data-old', b.text()); | ||
b.text('wait'); | ||
$.get(url, function (data) { | ||
window.location.href = data; // main action | ||
}).fail(function () { | ||
alert("ajax error"); | ||
}).always(function () { | ||
b.text(b.attr('data-old')); | ||
}) | ||
} | ||
</script> | ||
|
||
</head> | ||
<body> | ||
<img src="resources/rawbtlogo.png" alt="black & white picture"> | ||
<h1>RawBT Integration Demo</h1> | ||
<pre> | ||
|
||
window.location.href = ajax_backend_data; | ||
|
||
</pre> | ||
<br/> | ||
<button onclick="ajax_print('rawbt-receipt.php',this)">RECEIPT</button> | ||
|
||
<p><a href="https://rawbt.ru/">Visit RawBT site</a></p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?php | ||
require __DIR__ . '/../autoload.php'; | ||
|
||
use Mike42\Escpos\Printer; | ||
use Mike42\Escpos\EscposImage; | ||
use Mike42\Escpos\PrintConnectors\RawbtPrintConnector; | ||
use Mike42\Escpos\CapabilityProfile; | ||
|
||
try { | ||
$profile = CapabilityProfile::load("POS-5890"); | ||
|
||
/* Fill in your own connector here */ | ||
$connector = new RawbtPrintConnector(); | ||
|
||
/* Information for the receipt */ | ||
$items = array( | ||
new item("Example item #1", "4.00"), | ||
new item("Another thing", "3.50"), | ||
new item("Something else", "1.00"), | ||
new item("A final item", "4.45"), | ||
); | ||
$subtotal = new item('Subtotal', '12.95'); | ||
$tax = new item('A local tax', '1.30'); | ||
$total = new item('Total', '14.25', true); | ||
/* Date is kept the same for testing */ | ||
// $date = date('l jS \of F Y h:i:s A'); | ||
$date = "Monday 6th of April 2015 02:56:25 PM"; | ||
|
||
/* Start the printer */ | ||
$logo = EscposImage::load("resources/rawbtlogo.png", false); | ||
$printer = new Printer($connector, $profile); | ||
|
||
|
||
/* Print top logo */ | ||
if ($profile->getSupportsGraphics()) { | ||
$printer->graphics($logo); | ||
} | ||
if ($profile->getSupportsBitImageRaster() && !$profile->getSupportsGraphics()) { | ||
$printer->bitImage($logo); | ||
} | ||
|
||
/* Name of shop */ | ||
$printer->setJustification(Printer::JUSTIFY_CENTER); | ||
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH); | ||
$printer->text("ExampleMart Ltd.\n"); | ||
$printer->selectPrintMode(); | ||
$printer->text("Shop No. 42.\n"); | ||
$printer->feed(); | ||
|
||
|
||
/* Title of receipt */ | ||
$printer->setEmphasis(true); | ||
$printer->text("SALES INVOICE\n"); | ||
$printer->setEmphasis(false); | ||
|
||
/* Items */ | ||
$printer->setJustification(Printer::JUSTIFY_LEFT); | ||
$printer->setEmphasis(true); | ||
$printer->text(new item('', '$')); | ||
$printer->setEmphasis(false); | ||
foreach ($items as $item) { | ||
$printer->text($item->getAsString(32)); // for 58mm Font A | ||
} | ||
$printer->setEmphasis(true); | ||
$printer->text($subtotal->getAsString(32)); | ||
$printer->setEmphasis(false); | ||
$printer->feed(); | ||
|
||
/* Tax and total */ | ||
$printer->text($tax->getAsString(32)); | ||
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH); | ||
$printer->text($total->getAsString(32)); | ||
$printer->selectPrintMode(); | ||
|
||
/* Footer */ | ||
$printer->feed(2); | ||
$printer->setJustification(Printer::JUSTIFY_CENTER); | ||
$printer->text("Thank you for shopping\n"); | ||
$printer->text("at ExampleMart\n"); | ||
$printer->text("For trading hours,\n"); | ||
$printer->text("please visit example.com\n"); | ||
$printer->feed(2); | ||
$printer->text($date . "\n"); | ||
|
||
/* Barcode Default look */ | ||
|
||
$printer->barcode("ABC", Printer::BARCODE_CODE39); | ||
$printer->feed(); | ||
$printer->feed(); | ||
|
||
|
||
// Demo that alignment QRcode is the same as text | ||
$printer2 = new Printer($connector); // dirty printer profile hack !! | ||
$printer2->setJustification(Printer::JUSTIFY_CENTER); | ||
$printer2->qrCode("https://rawbt.ru/mike42", Printer::QR_ECLEVEL_M, 8); | ||
$printer2->text("rawbt.ru/mike42\n"); | ||
$printer2->setJustification(); | ||
$printer2->feed(); | ||
|
||
|
||
/* Cut the receipt and open the cash drawer */ | ||
$printer->cut(); | ||
$printer->pulse(); | ||
|
||
} catch (Exception $e) { | ||
echo $e->getMessage(); | ||
} finally { | ||
$printer->close(); | ||
} | ||
|
||
/* A wrapper to do organise item names & prices into columns */ | ||
|
||
class item | ||
{ | ||
private $name; | ||
private $price; | ||
private $dollarSign; | ||
|
||
public function __construct($name = '', $price = '', $dollarSign = false) | ||
{ | ||
$this->name = $name; | ||
$this->price = $price; | ||
$this->dollarSign = $dollarSign; | ||
} | ||
|
||
public function getAsString($width = 48) | ||
{ | ||
$rightCols = 10; | ||
$leftCols = $width - $rightCols; | ||
if ($this->dollarSign) { | ||
$leftCols = $leftCols / 2 - $rightCols / 2; | ||
} | ||
$left = str_pad($this->name, $leftCols); | ||
|
||
$sign = ($this->dollarSign ? '$ ' : ''); | ||
$right = str_pad($sign . $this->price, $rightCols, ' ', STR_PAD_LEFT); | ||
return "$left$right\n"; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->getAsString(); | ||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
/** | ||
* This file is part of escpos-php: PHP receipt printer library for use with | ||
* ESC/POS-compatible thermal and impact printers. | ||
* | ||
* Copyright (c) 2014-18 Michael Billington < [email protected] >, | ||
* incorporating modifications by others. See CONTRIBUTORS.md for a full list. | ||
* | ||
* This software is distributed under the terms of the MIT license. See LICENSE.md | ||
* for details. | ||
*/ | ||
|
||
namespace Mike42\Escpos\PrintConnectors; | ||
|
||
/** | ||
* Print connector for android RawBT application | ||
* https://play.google.com/store/apps/details?id=ru.a402d.rawbtprinter | ||
*/ | ||
final class RawbtPrintConnector implements PrintConnector | ||
{ | ||
/** | ||
* @var array $buffer | ||
* Buffer of accumilated data. | ||
*/ | ||
private $buffer; | ||
|
||
/** | ||
* @var string data which the printer will provide on next read | ||
*/ | ||
private $readData; | ||
|
||
/** | ||
* Create new print connector | ||
*/ | ||
public function __construct() | ||
{ | ||
ob_start(); | ||
$this->buffer = []; | ||
} | ||
|
||
public function clear() | ||
{ | ||
$this->buffer = []; | ||
} | ||
|
||
public function __destruct() | ||
{ | ||
if ($this->buffer !== null) { | ||
trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE); | ||
} | ||
} | ||
|
||
public function finalize() | ||
{ | ||
ob_end_clean(); | ||
echo "intent:base64," . base64_encode($this->getData()) . "#Intent;scheme=rawbt;package=ru.a402d.rawbtprinter;end;"; | ||
$this->buffer = null; | ||
} | ||
|
||
/** | ||
* @return string Get the accumulated data that has been sent to this buffer. | ||
*/ | ||
public function getData() | ||
{ | ||
return implode($this->buffer); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* @see PrintConnector::read() | ||
*/ | ||
public function read($len) | ||
{ | ||
return $len >= strlen($this->readData) ? $this->readData : substr($this->readData, 0, $len); | ||
} | ||
|
||
public function write($data) | ||
{ | ||
$this->buffer[] = $data; | ||
} | ||
} |