|
|
@@ -11,6 +11,8 @@ use App\Models\Transaction;
|
|
11
|
11
|
use App\Models\TransactionStatus;
|
|
12
|
12
|
use Illuminate\Database\QueryException;
|
|
13
|
13
|
use Illuminate\Support\Facades\DB;
|
|
|
14
|
+use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
|
|
15
|
+use Mike42\Escpos\Printer;
|
|
14
|
16
|
|
|
15
|
17
|
class TransactionController extends Controller
|
|
16
|
18
|
{
|
|
|
@@ -114,6 +116,108 @@ class TransactionController extends Controller
|
|
114
|
116
|
|
|
115
|
117
|
DB::commit();
|
|
116
|
118
|
|
|
|
119
|
+ // /* Information for the receipt */
|
|
|
120
|
+ // $items = array(
|
|
|
121
|
+ // new item("Example item #1", "4.00"),
|
|
|
122
|
+ // new item("Another thing", "3.50"),
|
|
|
123
|
+ // new item("Something else", "1.00"),
|
|
|
124
|
+ // new item("A final item", "4.45"),
|
|
|
125
|
+ // );
|
|
|
126
|
+ // $subtotal = new item('Subtotal', '12.95');
|
|
|
127
|
+ // $tax = new item('A local tax', '1.30');
|
|
|
128
|
+ // $total = new item('Total', '14.25', true);
|
|
|
129
|
+ // /* Date is kept the same for testing */
|
|
|
130
|
+ // // $date = date('l jS \of F Y h:i:s A');
|
|
|
131
|
+ // $date = "Monday 6th of April 2015 02:56:25 PM";
|
|
|
132
|
+
|
|
|
133
|
+ // /* Start the printer */
|
|
|
134
|
+ // // $logo = EscposImage::load(public_path('images/escpos-php.png'), false);
|
|
|
135
|
+ // $connector = new FilePrintConnector("/dev/usb/lp1");
|
|
|
136
|
+ // $printer = new Printer($connector);
|
|
|
137
|
+
|
|
|
138
|
+ // /* Print top logo */
|
|
|
139
|
+ // $printer->setJustification(Printer::JUSTIFY_CENTER);
|
|
|
140
|
+ // // $printer->graphics($logo);
|
|
|
141
|
+
|
|
|
142
|
+ // /* Name of shop */
|
|
|
143
|
+ // $printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
|
|
|
144
|
+ // $printer->text("ExampleMart Ltd.\n");
|
|
|
145
|
+ // $printer->selectPrintMode();
|
|
|
146
|
+ // $printer->text("Shop No. 42.\n");
|
|
|
147
|
+ // $printer->feed();
|
|
|
148
|
+
|
|
|
149
|
+ // /* Title of receipt */
|
|
|
150
|
+ // $printer->setEmphasis(true);
|
|
|
151
|
+ // $printer->text("SALES INVOICE\n");
|
|
|
152
|
+ // $printer->setEmphasis(false);
|
|
|
153
|
+
|
|
|
154
|
+ // /* Items */
|
|
|
155
|
+ // $printer->setJustification(Printer::JUSTIFY_LEFT);
|
|
|
156
|
+ // $printer->setEmphasis(true);
|
|
|
157
|
+ // $printer->text(new item('', '$'));
|
|
|
158
|
+ // $printer->setEmphasis(false);
|
|
|
159
|
+ // foreach ($items as $item) {
|
|
|
160
|
+ // $printer->text($item);
|
|
|
161
|
+ // }
|
|
|
162
|
+ // $printer->setEmphasis(true);
|
|
|
163
|
+ // $printer->text($subtotal);
|
|
|
164
|
+ // $printer->setEmphasis(false);
|
|
|
165
|
+ // $printer->feed();
|
|
|
166
|
+
|
|
|
167
|
+ // /* Tax and total */
|
|
|
168
|
+ // $printer->text($tax);
|
|
|
169
|
+ // $printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
|
|
|
170
|
+ // $printer->text($total);
|
|
|
171
|
+ // $printer->selectPrintMode();
|
|
|
172
|
+
|
|
|
173
|
+ // /* Footer */
|
|
|
174
|
+ // $printer->feed(2);
|
|
|
175
|
+ // $printer->setJustification(Printer::JUSTIFY_CENTER);
|
|
|
176
|
+ // $printer->text("Thank you for shopping at ExampleMart\n");
|
|
|
177
|
+ // $printer->text("For trading hours, please visit example.com\n");
|
|
|
178
|
+ // $printer->feed(2);
|
|
|
179
|
+ // $printer->text($date . "\n");
|
|
|
180
|
+
|
|
|
181
|
+ // /* Cut the receipt and open the cash drawer */
|
|
|
182
|
+ // $printer->cut();
|
|
|
183
|
+ // $printer->pulse();
|
|
|
184
|
+
|
|
|
185
|
+ // $printer->close();
|
|
|
186
|
+
|
|
|
187
|
+ $transaction = Transaction::latest()->first();
|
|
|
188
|
+
|
|
|
189
|
+ $connector = new FilePrintConnector("/dev/usb/lp1");
|
|
|
190
|
+ $printer = new Printer($connector);
|
|
|
191
|
+
|
|
|
192
|
+ /* Brand */
|
|
|
193
|
+ $printer->setJustification(Printer::JUSTIFY_CENTER);
|
|
|
194
|
+ $printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
|
|
|
195
|
+ $printer->text("BAMB'S LAUNDRY \n");
|
|
|
196
|
+ $printer->selectPrintMode();
|
|
|
197
|
+ $printer->feed();
|
|
|
198
|
+
|
|
|
199
|
+ /* Unique Id */
|
|
|
200
|
+ $printer->barcode($transaction->transaction_number, Printer::BARCODE_CODE39);
|
|
|
201
|
+ $printer->text("Id Transaksi: {$transaction->transaction_number} \n");
|
|
|
202
|
+ $printer->feed(2);
|
|
|
203
|
+
|
|
|
204
|
+ /* Title of receipt */
|
|
|
205
|
+ $printer->setEmphasis(true);
|
|
|
206
|
+ $printer->text("DETAIL TRANSAKSI\n");
|
|
|
207
|
+ $printer->setEmphasis(false);
|
|
|
208
|
+
|
|
|
209
|
+ /* Footer */
|
|
|
210
|
+ $printer->setJustification(Printer::JUSTIFY_CENTER);
|
|
|
211
|
+ $printer->text("** Terima Kasih ** \n");
|
|
|
212
|
+ $printer->feed();
|
|
|
213
|
+ $printer->text($transaction->created_at . "\n");
|
|
|
214
|
+
|
|
|
215
|
+ /* Cut the receipt */
|
|
|
216
|
+ $printer->cut();
|
|
|
217
|
+ $printer->pulse();
|
|
|
218
|
+
|
|
|
219
|
+ $printer->close();
|
|
|
220
|
+
|
|
117
|
221
|
return to_route('transactions.index')->with('success', __('messages.success.store.transaction'));
|
|
118
|
222
|
} catch (QueryException $e) {
|
|
119
|
223
|
return back()->with('error', __('messages.error.store.transaction'));
|
|
|
@@ -196,3 +300,31 @@ class TransactionController extends Controller
|
|
196
|
300
|
//
|
|
197
|
301
|
}
|
|
198
|
302
|
}
|
|
|
303
|
+
|
|
|
304
|
+class item
|
|
|
305
|
+{
|
|
|
306
|
+ private $name;
|
|
|
307
|
+ private $price;
|
|
|
308
|
+ private $dollarSign;
|
|
|
309
|
+
|
|
|
310
|
+ public function __construct($name = '', $price = '', $dollarSign = false)
|
|
|
311
|
+ {
|
|
|
312
|
+ $this->name = $name;
|
|
|
313
|
+ $this->price = $price;
|
|
|
314
|
+ $this->dollarSign = $dollarSign;
|
|
|
315
|
+ }
|
|
|
316
|
+
|
|
|
317
|
+ public function __toString()
|
|
|
318
|
+ {
|
|
|
319
|
+ $rightCols = 10;
|
|
|
320
|
+ $leftCols = 38;
|
|
|
321
|
+ if ($this->dollarSign) {
|
|
|
322
|
+ $leftCols = $leftCols / 2 - $rightCols / 2;
|
|
|
323
|
+ }
|
|
|
324
|
+ $left = str_pad($this->name, $leftCols);
|
|
|
325
|
+
|
|
|
326
|
+ $sign = ($this->dollarSign ? '$ ' : '');
|
|
|
327
|
+ $right = str_pad($sign . $this->price, $rightCols, ' ', STR_PAD_LEFT);
|
|
|
328
|
+ return "$left$right\n";
|
|
|
329
|
+ }
|
|
|
330
|
+}
|