-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintestimate.php
More file actions
133 lines (114 loc) · 5.73 KB
/
printestimate.php
File metadata and controls
133 lines (114 loc) · 5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
require_once('dbconnect.php');
/* Change to the correct path if you copy this example! */
require '/vendor/mike42/escpos-php/autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
/**
* Assuming your printer is available at LPT1,
* simpy instantiate a WindowsPrintConnector to it.
*
* When troubleshooting, make sure you can send it
* data from the command-line first:
* echo "Hello World" > LPT1
*/
if ($_GET['command'])
{
if($_GET['command'] == 'print')
{
$conn = dbConn();
$Query = "SELECT e.CODE CODE,p.NAME NAME,e.PRICESELL PRICESELL,e.QUANTITY QUANTITY
FROM estimate e
INNER JOIN products p on p.CODE = e.CODE";
if($records = $conn->prepare($Query))
{
$grandTotal = 0;
$records->execute();
$records->bind_result($CODE,$NAME,$PRICESELL,$QUANTITY);
$connector = new WindowsPrintConnector("LPT1");
// A FilePrintConnector will also work, but on non-Windows systems, writes
// to an actual file called 'LPT1' rather than giving a useful error.
// $connector = new FilePrintConnector("LPT1");
/* Print a "Hello world" receipt" */
$printer = new Printer($connector);
$printer -> setJustification(Printer::JUSTIFY_CENTER);
$printer -> text("Estimate\n");
$printer -> setJustification(Printer::JUSTIFY_LEFT);
$printer -> text(str_repeat("=",42) . "\n");
$printer -> text(str_pad("Qty",3) . " " . str_pad("Item Details",22) . " " . str_pad("Price",7," ",STR_PAD_RIGHT) . " ");
$printer -> text(str_pad("Total",7," ",STR_PAD_LEFT) . "\n");
$printer -> text(str_repeat("=",42) . "\n");
while($records->fetch())
{
try
{
$barcode=$CODE;
$desc=$NAME;
$price=number_format(floatval($PRICESELL),2,".","");
$qty=$QUANTITY;
$total=number_format(floatval($PRICESELL * $qty),2,".","");
$printer -> text(str_pad($qty,3) . " " . str_pad(trim(substr($desc,0,20)),22) . " " . str_pad($price,7," ",STR_PAD_RIGHT) . " ");
$printer -> setJustification(Printer::JUSTIFY_RIGHT); //to print total
$printer -> text(str_pad(number_format($total,2,".",""),7," ",STR_PAD_LEFT) . "\n");
$printer -> setJustification(Printer::JUSTIFY_LEFT);
$printer -> text(str_pad($barcode,17," ",STR_PAD_LEFT) . "\n");
$grandTotal = $grandTotal + ($total);
}
catch (Exception $e)
{
echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
}
}
$printer -> text(str_repeat("=",42) . "\n");
//$printer -> setJustification(Printer::JUSTIFY_RIGHT); //to print grand total
$printer -> text(str_pad(number_format($grandTotal,2,".",""),42," ",STR_PAD_LEFT) . "\n");
$printer -> setJustification(Printer::JUSTIFY_LEFT); //to print grand total
//$printer -> text($grandTotal . "\n");
$printer -> text(str_repeat("=",42) . "\n");
$printer -> cut();
/* Close printer */
$printer -> close();
$grandTotal = 0;
$records->close();
mysqli_close($conn);
$conn=null;
$Query ="";
}
}//validate command parameter
} //check for command parameter
if ($_GET['redirect'])
{
if($_GET['redirect'] == "estimate")
{
header("Location: ./estimate.php");
}
}
function test() {
try {
$connector = new WindowsPrintConnector("LPT1");
// A FilePrintConnector will also work, but on non-Windows systems, writes
// to an actual file called 'LPT1' rather than giving a useful error.
// $connector = new FilePrintConnector("LPT1");
/* Print a "Hello world" receipt" */
$printer = new Printer($connector);
$barcode="8901180228128";
$desc="Faber Castell Plastic Crayons 12+2";
$price="1156.82";
$qty="111";
$total="1111.00";
$printer -> setJustification(Printer::JUSTIFY_CENTER);
$printer -> text("Estimate\n");
$printer -> setJustification(Printer::JUSTIFY_LEFT);
$printer -> text(str_repeat("=",42) . "\n");
$printer -> text(str_pad("Qty",3) . " " . str_pad("Item Details",22) . " " . str_pad("Price",7," ",STR_PAD_RIGHT) . " " . str_pad("Total",7," ",STR_PAD_RIGHT) . "\n");
$printer -> text(str_repeat("=",42) . "\n");
$printer -> text(str_pad($qty,3) . " " . str_pad(trim(substr($desc,0,20)),22) . " " . str_pad($price,7," ",STR_PAD_RIGHT) . " " . str_pad($total,7," ",STR_PAD_RIGHT) . "\n");
$printer -> text(str_pad($barcode,17," ",STR_PAD_LEFT) . "\n");
$printer -> cut();
/* Close printer */
$printer -> close();
} catch (Exception $e) {
echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
}
}
// $connector = new WindowsPrintConnector("EPSON TM-T88IV Receipt");