Muhammad Iqbal Afandi пре 3 година
родитељ
комит
a2e1545dca

+ 132
- 0
app/Http/Controllers/TransactionController.php Прегледај датотеку

@@ -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
+}

+ 1
- 0
composer.json Прегледај датотеку

@@ -12,6 +12,7 @@
12 12
         "laravel/framework": "^9.0",
13 13
         "laravel/sanctum": "^2.14",
14 14
         "laravel/tinker": "^2.7",
15
+        "mike42/escpos-php": "^3.0",
15 16
         "tightenco/ziggy": "^1.4"
16 17
     },
17 18
     "require-dev": {

+ 107
- 1
composer.lock Прегледај датотеку

@@ -4,7 +4,7 @@
4 4
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 5
         "This file is @generated automatically"
6 6
     ],
7
-    "content-hash": "3ddf578d99595cdd55f044f8649c90f9",
7
+    "content-hash": "e73f43f6feafe8d220a4a1fdc4093014",
8 8
     "packages": [
9 9
         {
10 10
             "name": "asm89/stack-cors",
@@ -1799,6 +1799,112 @@
1799 1799
             ],
1800 1800
             "time": "2021-11-21T11:48:40+00:00"
1801 1801
         },
1802
+        {
1803
+            "name": "mike42/escpos-php",
1804
+            "version": "v3.0",
1805
+            "source": {
1806
+                "type": "git",
1807
+                "url": "https://github.com/mike42/escpos-php.git",
1808
+                "reference": "dcb569a123d75f9f6a4a927aae7625ca6b7fdcf3"
1809
+            },
1810
+            "dist": {
1811
+                "type": "zip",
1812
+                "url": "https://api.github.com/repos/mike42/escpos-php/zipball/dcb569a123d75f9f6a4a927aae7625ca6b7fdcf3",
1813
+                "reference": "dcb569a123d75f9f6a4a927aae7625ca6b7fdcf3",
1814
+                "shasum": ""
1815
+            },
1816
+            "require": {
1817
+                "ext-intl": "*",
1818
+                "ext-json": "*",
1819
+                "ext-zlib": "*",
1820
+                "mike42/gfx-php": "^0.6",
1821
+                "php": ">=7.0.0"
1822
+            },
1823
+            "require-dev": {
1824
+                "phpunit/phpunit": "^6.5",
1825
+                "squizlabs/php_codesniffer": "^3.3"
1826
+            },
1827
+            "suggest": {
1828
+                "ext-gd": "Used for image printing if present.",
1829
+                "ext-imagick": "Will be used for image printing if present. Required for PDF printing or use of custom fonts."
1830
+            },
1831
+            "type": "library",
1832
+            "autoload": {
1833
+                "psr-4": {
1834
+                    "Mike42\\": "src/Mike42"
1835
+                }
1836
+            },
1837
+            "notification-url": "https://packagist.org/downloads/",
1838
+            "license": [
1839
+                "MIT"
1840
+            ],
1841
+            "authors": [
1842
+                {
1843
+                    "name": "Michael Billington",
1844
+                    "email": "michael.billington@gmail.com"
1845
+                }
1846
+            ],
1847
+            "description": "PHP receipt printer library for use with ESC/POS-compatible thermal and impact printers",
1848
+            "homepage": "https://github.com/mike42/escpos-php",
1849
+            "keywords": [
1850
+                "Epson",
1851
+                "barcode",
1852
+                "escpos",
1853
+                "printer",
1854
+                "receipt-printer"
1855
+            ],
1856
+            "support": {
1857
+                "issues": "https://github.com/mike42/escpos-php/issues",
1858
+                "source": "https://github.com/mike42/escpos-php/tree/v3.0"
1859
+            },
1860
+            "time": "2019-10-13T06:27:43+00:00"
1861
+        },
1862
+        {
1863
+            "name": "mike42/gfx-php",
1864
+            "version": "v0.6",
1865
+            "source": {
1866
+                "type": "git",
1867
+                "url": "https://github.com/mike42/gfx-php.git",
1868
+                "reference": "ed9ded2a9298e4084a9c557ab74a89b71e43dbdb"
1869
+            },
1870
+            "dist": {
1871
+                "type": "zip",
1872
+                "url": "https://api.github.com/repos/mike42/gfx-php/zipball/ed9ded2a9298e4084a9c557ab74a89b71e43dbdb",
1873
+                "reference": "ed9ded2a9298e4084a9c557ab74a89b71e43dbdb",
1874
+                "shasum": ""
1875
+            },
1876
+            "require": {
1877
+                "php": ">=7.0.0"
1878
+            },
1879
+            "require-dev": {
1880
+                "phpbench/phpbench": "@dev",
1881
+                "phpunit/phpunit": "^6.5",
1882
+                "squizlabs/php_codesniffer": "^3.3.1"
1883
+            },
1884
+            "type": "library",
1885
+            "autoload": {
1886
+                "psr-4": {
1887
+                    "Mike42\\": "src/Mike42"
1888
+                }
1889
+            },
1890
+            "notification-url": "https://packagist.org/downloads/",
1891
+            "license": [
1892
+                "LGPL-2.1-or-later"
1893
+            ],
1894
+            "authors": [
1895
+                {
1896
+                    "name": "Michael Billington",
1897
+                    "email": "michael.billington@gmail.com"
1898
+                }
1899
+            ],
1900
+            "description": "The pure PHP graphics library",
1901
+            "homepage": "https://github.com/mike42/gfx-php",
1902
+            "support": {
1903
+                "issues": "https://github.com/mike42/gfx-php/issues",
1904
+                "source": "https://github.com/mike42/gfx-php/tree/v0.6"
1905
+            },
1906
+            "time": "2019-10-05T02:44:33+00:00"
1907
+        },
1802 1908
         {
1803 1909
             "name": "monolog/monolog",
1804 1910
             "version": "2.4.0",

BIN
public/images/escpos-php.png Прегледај датотеку


+ 19
- 16
public/js/resources_js_pages_transaction_Index_vue.js Прегледај датотеку

@@ -700,13 +700,15 @@ __webpack_require__.r(__webpack_exports__);
700 700
 /* harmony export */   "default": () => (__WEBPACK_DEFAULT_EXPORT__)
701 701
 /* harmony export */ });
702 702
 /* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! vue */ "./node_modules/vue/dist/vue.esm-bundler.js");
703
-/* harmony import */ var _inertiajs_inertia_vue3__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @inertiajs/inertia-vue3 */ "./node_modules/@inertiajs/inertia-vue3/dist/index.js");
704
-/* harmony import */ var _components_AppButton_vue__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @/components/AppButton.vue */ "./resources/js/components/AppButton.vue");
705
-/* harmony import */ var _components_AppPagination_vue__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @/components/AppPagination.vue */ "./resources/js/components/AppPagination.vue");
706
-/* harmony import */ var _components_AppMenu_vue__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @/components/AppMenu.vue */ "./resources/js/components/AppMenu.vue");
707
-/* harmony import */ var _components_AppDropdown_vue__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @/components/AppDropdown.vue */ "./resources/js/components/AppDropdown.vue");
708
-/* harmony import */ var _layouts_AppLayout_vue__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @/layouts/AppLayout.vue */ "./resources/js/layouts/AppLayout.vue");
709
-/* harmony import */ var _TableHeader__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./TableHeader */ "./resources/js/pages/transaction/TableHeader.js");
703
+/* harmony import */ var _inertiajs_inertia__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @inertiajs/inertia */ "./node_modules/@inertiajs/inertia/dist/index.js");
704
+/* harmony import */ var _inertiajs_inertia_vue3__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @inertiajs/inertia-vue3 */ "./node_modules/@inertiajs/inertia-vue3/dist/index.js");
705
+/* harmony import */ var _components_AppButton_vue__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @/components/AppButton.vue */ "./resources/js/components/AppButton.vue");
706
+/* harmony import */ var _components_AppPagination_vue__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @/components/AppPagination.vue */ "./resources/js/components/AppPagination.vue");
707
+/* harmony import */ var _components_AppMenu_vue__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @/components/AppMenu.vue */ "./resources/js/components/AppMenu.vue");
708
+/* harmony import */ var _components_AppDropdown_vue__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @/components/AppDropdown.vue */ "./resources/js/components/AppDropdown.vue");
709
+/* harmony import */ var _layouts_AppLayout_vue__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @/layouts/AppLayout.vue */ "./resources/js/layouts/AppLayout.vue");
710
+/* harmony import */ var _TableHeader__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./TableHeader */ "./resources/js/pages/transaction/TableHeader.js");
711
+
710 712
 
711 713
 
712 714
 
@@ -726,7 +728,7 @@ __webpack_require__.r(__webpack_exports__);
726 728
     var props = __props;
727 729
     var transactionId = (0,vue__WEBPACK_IMPORTED_MODULE_0__.ref)();
728 730
     var updateStatusDialog = (0,vue__WEBPACK_IMPORTED_MODULE_0__.ref)(false);
729
-    var updateStatusForm = (0,_inertiajs_inertia_vue3__WEBPACK_IMPORTED_MODULE_1__.useForm)({
731
+    var updateStatusForm = (0,_inertiajs_inertia_vue3__WEBPACK_IMPORTED_MODULE_2__.useForm)({
730 732
       transaction_status_id: null
731 733
     });
732 734
 
@@ -777,14 +779,15 @@ __webpack_require__.r(__webpack_exports__);
777 779
       overlayItems: overlayItems,
778 780
       overlayToggle: overlayToggle,
779 781
       ref: vue__WEBPACK_IMPORTED_MODULE_0__.ref,
780
-      Head: _inertiajs_inertia_vue3__WEBPACK_IMPORTED_MODULE_1__.Head,
781
-      useForm: _inertiajs_inertia_vue3__WEBPACK_IMPORTED_MODULE_1__.useForm,
782
-      AppButton: _components_AppButton_vue__WEBPACK_IMPORTED_MODULE_2__["default"],
783
-      AppPagination: _components_AppPagination_vue__WEBPACK_IMPORTED_MODULE_3__["default"],
784
-      AppMenu: _components_AppMenu_vue__WEBPACK_IMPORTED_MODULE_4__["default"],
785
-      AppDropdown: _components_AppDropdown_vue__WEBPACK_IMPORTED_MODULE_5__["default"],
786
-      AppLayout: _layouts_AppLayout_vue__WEBPACK_IMPORTED_MODULE_6__["default"],
787
-      IndexTable: _TableHeader__WEBPACK_IMPORTED_MODULE_7__.IndexTable
782
+      Inertia: _inertiajs_inertia__WEBPACK_IMPORTED_MODULE_1__.Inertia,
783
+      Head: _inertiajs_inertia_vue3__WEBPACK_IMPORTED_MODULE_2__.Head,
784
+      useForm: _inertiajs_inertia_vue3__WEBPACK_IMPORTED_MODULE_2__.useForm,
785
+      AppButton: _components_AppButton_vue__WEBPACK_IMPORTED_MODULE_3__["default"],
786
+      AppPagination: _components_AppPagination_vue__WEBPACK_IMPORTED_MODULE_4__["default"],
787
+      AppMenu: _components_AppMenu_vue__WEBPACK_IMPORTED_MODULE_5__["default"],
788
+      AppDropdown: _components_AppDropdown_vue__WEBPACK_IMPORTED_MODULE_6__["default"],
789
+      AppLayout: _layouts_AppLayout_vue__WEBPACK_IMPORTED_MODULE_7__["default"],
790
+      IndexTable: _TableHeader__WEBPACK_IMPORTED_MODULE_8__.IndexTable
788 791
     };
789 792
     Object.defineProperty(__returned__, '__isScriptSetup', {
790 793
       enumerable: false,

+ 43742
- 2
public/js/vue.js
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 1
- 1
public/mix-manifest.json Прегледај датотеку

@@ -1,3 +1,3 @@
1 1
 {
2
-    "/js/vue.js": "/js/vue.js?id=9dd10bcae6917fb220ff7c567ad1cec8"
2
+    "/js/vue.js": "/js/vue.js"
3 3
 }

+ 2
- 1
resources/js/pages/transaction/Index.vue Прегледај датотеку

@@ -1,5 +1,6 @@
1 1
 <script setup>
2 2
 import { ref } from 'vue'
3
+import { Inertia } from '@inertiajs/inertia'
3 4
 import { Head, useForm } from '@inertiajs/inertia-vue3'
4 5
 import AppButton from '@/components/AppButton.vue'
5 6
 import AppPagination from '@/components/AppPagination.vue'
@@ -41,7 +42,7 @@ const overlayToggle = (event, data) => {
41 42
     {
42 43
       label: 'Perbaharui status',
43 44
       icon: 'pi pi-refresh',
44
-      command: () => {
45
+      command() {
45 46
         updateStatusDialog.value = true
46 47
       },
47 48
     },

+ 0
- 0
resources/js/utils/print.js Прегледај датотеку