capacitor-hugin-gmp3 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +8 -0
- package/android/src/main/AndroidManifest.xml +7 -0
- package/android/src/main/aidl/com/kerzz/hugin/gmp3/IPrinterService.aidl +19 -0
- package/android/src/main/java/com/kerzz/hugin/gmp3/CapacitorHuginGMP3Plugin.java +90 -49
- package/android/src/main/java/com/kerzz/hugin/gmp3/PrinterCoverService.java +207 -0
- package/package.json +1 -1
- package/android/src/main/java/com/kerzz/hugin/gmp3/CapacitorHuginGMP3.java +0 -122
package/android/build.gradle
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
<application>
|
|
3
|
+
<service
|
|
4
|
+
android:name=".PrinterCoverService"
|
|
5
|
+
android:process=":printer_process"
|
|
6
|
+
android:exported="false"
|
|
7
|
+
android:permission="android.permission.BIND_JOB_SERVICE"/>
|
|
8
|
+
</application>
|
|
2
9
|
</manifest>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// IPrinterService.aidl
|
|
2
|
+
package com.kerzz.hugin.gmp3;
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
// Declare any non-default types here with import statements
|
|
6
|
+
|
|
7
|
+
interface IPrinterService {
|
|
8
|
+
boolean printXReport(int type);
|
|
9
|
+
boolean printZReport();
|
|
10
|
+
boolean connect(String ip, int port, String terminalNo);
|
|
11
|
+
boolean tcpConnect(String ip, int port);
|
|
12
|
+
String Sale(String saleItem);
|
|
13
|
+
String GetDepartment(int depId);
|
|
14
|
+
String GetVatRate(int index);
|
|
15
|
+
String libraryVersion();
|
|
16
|
+
String SetDepartment(int id, String name, int vatId, double price, int weighable);
|
|
17
|
+
String SetVATRate(int index, double vatRate);
|
|
18
|
+
String VoidReceipt();
|
|
19
|
+
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
package com.kerzz.hugin.gmp3;
|
|
2
2
|
|
|
3
|
-
import static com.kerzz.hugin.gmp3.CapacitorHuginGMP3.printResponse;
|
|
4
3
|
|
|
4
|
+
import android.content.ComponentName;
|
|
5
|
+
import android.content.Context;
|
|
6
|
+
import android.content.Intent;
|
|
7
|
+
import android.content.ServiceConnection;
|
|
5
8
|
import android.os.Build;
|
|
9
|
+
import android.os.DeadObjectException;
|
|
10
|
+
import android.os.IBinder;
|
|
11
|
+
import android.os.RemoteException;
|
|
6
12
|
import android.util.Log;
|
|
7
13
|
|
|
8
14
|
import com.getcapacitor.JSArray;
|
|
@@ -11,6 +17,8 @@ import com.getcapacitor.Plugin;
|
|
|
11
17
|
import com.getcapacitor.PluginCall;
|
|
12
18
|
import com.getcapacitor.PluginMethod;
|
|
13
19
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
20
|
+
import com.kerzz.hugin.gmp3.IPrinterService;
|
|
21
|
+
|
|
14
22
|
|
|
15
23
|
import java.time.LocalDateTime;
|
|
16
24
|
|
|
@@ -19,30 +27,42 @@ import gmp3.droid.printer.Utility;
|
|
|
19
27
|
|
|
20
28
|
@CapacitorPlugin(name = "CapacitorHuginGMP3")
|
|
21
29
|
public class CapacitorHuginGMP3Plugin extends Plugin {
|
|
22
|
-
private final CapacitorHuginGMP3 implementation = new CapacitorHuginGMP3();
|
|
23
30
|
private final String TAG = "CapacitorHuginGMP3";
|
|
31
|
+
private IPrinterService printerService;
|
|
32
|
+
private boolean bound = false;
|
|
33
|
+
|
|
34
|
+
private final ServiceConnection serviceConnection = new ServiceConnection() {
|
|
35
|
+
@Override
|
|
36
|
+
public void onServiceConnected(ComponentName name, IBinder service) {
|
|
37
|
+
printerService = IPrinterService.Stub.asInterface(service);
|
|
38
|
+
bound = true;
|
|
39
|
+
Log.d(TAG, "Printer servise bağlandı.");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Override
|
|
43
|
+
public void onServiceDisconnected(ComponentName name) {
|
|
44
|
+
printerService = null;
|
|
45
|
+
bound = false;
|
|
46
|
+
Log.d(TAG, "Printer servis bağlantısı koptu.");
|
|
47
|
+
Intent intent = new Intent(getContext(), PrinterCoverService.class);
|
|
48
|
+
getContext().bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
24
51
|
@Override
|
|
25
52
|
public void load() {
|
|
26
53
|
super.load();
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
public CapacitorHuginGMP3Plugin() {
|
|
30
|
-
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
|
31
|
-
@Override
|
|
32
|
-
public void uncaughtException(Thread t, Throwable e) {
|
|
33
|
-
Log.e(TAG, "Yakalanmayan hata: " + e.getMessage());
|
|
34
|
-
// Burada kullanıcıya hata gösterebilirsin veya loglayabilirsin
|
|
35
|
-
// Uygulama çökmeye devam eder ama en azından bilgi alırsın
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
Log.d(TAG, "HuginPrinter constructor çalıştı ve exception handler kuruldu.");
|
|
39
|
-
|
|
54
|
+
Intent intent = new Intent(getContext(), PrinterCoverService.class);
|
|
55
|
+
getContext().bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
|
40
56
|
}
|
|
41
57
|
|
|
42
58
|
@PluginMethod
|
|
43
59
|
public void GetLibraryVersion(PluginCall call) {
|
|
44
|
-
|
|
45
|
-
|
|
60
|
+
try {
|
|
61
|
+
String version = printerService.libraryVersion();
|
|
62
|
+
call.resolve(new JSObject().put("version", version));
|
|
63
|
+
} catch (Exception e) {
|
|
64
|
+
call.resolve(new JSObject().put("version", -1));
|
|
65
|
+
}
|
|
46
66
|
}
|
|
47
67
|
|
|
48
68
|
@PluginMethod
|
|
@@ -61,12 +81,15 @@ public class CapacitorHuginGMP3Plugin extends Plugin {
|
|
|
61
81
|
return;
|
|
62
82
|
}
|
|
63
83
|
|
|
64
|
-
boolean connected =
|
|
84
|
+
boolean connected = printerService.connect(ip, port, terminalNo);
|
|
65
85
|
JSObject result = new JSObject();
|
|
66
86
|
result.put("connected", connected);
|
|
67
87
|
call.resolve(result);
|
|
68
|
-
} catch (
|
|
69
|
-
|
|
88
|
+
} catch (RemoteException e) {
|
|
89
|
+
JSObject result = new JSObject();
|
|
90
|
+
result.put("connected", false);
|
|
91
|
+
call.resolve(result);
|
|
92
|
+
Log.i(TAG,"Hata Bizde" + e.toString());
|
|
70
93
|
}
|
|
71
94
|
}
|
|
72
95
|
|
|
@@ -83,7 +106,7 @@ public class CapacitorHuginGMP3Plugin extends Plugin {
|
|
|
83
106
|
|
|
84
107
|
Log.i(TAG, "Sale Request: " + saleItem);
|
|
85
108
|
|
|
86
|
-
String response =
|
|
109
|
+
String response = printerService.Sale(saleItem.toString());
|
|
87
110
|
Log.i(TAG, "Sale Response: " + response);
|
|
88
111
|
JSObject res = new JSObject();
|
|
89
112
|
if(!response.equals("-1")) {
|
|
@@ -97,38 +120,52 @@ public class CapacitorHuginGMP3Plugin extends Plugin {
|
|
|
97
120
|
call.resolve(res);
|
|
98
121
|
}
|
|
99
122
|
|
|
100
|
-
} catch (
|
|
123
|
+
} catch (RemoteException e) {
|
|
101
124
|
Log.e(TAG, "Sale Error", e);
|
|
125
|
+
call.reject("Must Reconnect", e);
|
|
126
|
+
} catch (Exception e) {
|
|
102
127
|
call.reject("Sale failed", e);
|
|
103
128
|
}
|
|
104
129
|
}
|
|
105
130
|
|
|
106
131
|
@PluginMethod
|
|
107
132
|
public void PrintZReport(PluginCall call) {
|
|
108
|
-
|
|
133
|
+
if (printerService != null) {
|
|
134
|
+
try {
|
|
135
|
+
call.resolve(JSObjectHelper.result(printerService.printZReport()));
|
|
136
|
+
} catch (RemoteException e) {
|
|
137
|
+
Log.e(TAG, e.toString());
|
|
138
|
+
call.resolve(JSObjectHelper.result(false));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
109
141
|
}
|
|
110
142
|
|
|
111
143
|
@PluginMethod
|
|
112
|
-
public void PrintXReport(PluginCall call) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
144
|
+
public void PrintXReport(PluginCall call) throws DeadObjectException {
|
|
145
|
+
if (printerService != null) {
|
|
146
|
+
int type = 1;
|
|
147
|
+
try {
|
|
148
|
+
Integer typeValue = call.getInt("type");
|
|
149
|
+
if (typeValue != null) {
|
|
150
|
+
type = typeValue;
|
|
151
|
+
}
|
|
152
|
+
call.resolve(JSObjectHelper.result(printerService.printXReport(type)));
|
|
153
|
+
} catch (RemoteException e) {
|
|
154
|
+
Log.e(TAG, e.toString());
|
|
155
|
+
call.resolve(JSObjectHelper.result(false));
|
|
118
156
|
}
|
|
119
|
-
} catch (Exception e) {
|
|
120
|
-
Log.e(TAG, e.toString());
|
|
121
157
|
}
|
|
122
|
-
|
|
158
|
+
|
|
123
159
|
}
|
|
124
160
|
|
|
125
161
|
@PluginMethod
|
|
126
162
|
public void GetDepartments(PluginCall call) {
|
|
127
163
|
JSArray depts = new JSArray();
|
|
128
164
|
try {
|
|
165
|
+
printerService.VoidReceipt();
|
|
129
166
|
for (int i = 1; i < 9; i++) { // 1-8
|
|
130
|
-
String deptResponse =
|
|
131
|
-
String[] parts = printResponse(deptResponse);
|
|
167
|
+
String deptResponse = printerService.GetDepartment(i);
|
|
168
|
+
String[] parts = PrinterCoverService.printResponse(deptResponse);
|
|
132
169
|
|
|
133
170
|
if (parts.length >= 6) {
|
|
134
171
|
JSObject dept = new JSObject();
|
|
@@ -152,11 +189,12 @@ public class CapacitorHuginGMP3Plugin extends Plugin {
|
|
|
152
189
|
|
|
153
190
|
@PluginMethod
|
|
154
191
|
public void GetVatRates(PluginCall call) {
|
|
155
|
-
JSArray vatRates = new JSArray();
|
|
156
192
|
try {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
193
|
+
printerService.VoidReceipt();
|
|
194
|
+
JSArray vatRates = new JSArray();
|
|
195
|
+
for (int i = 0; i < 8; i++) { // 0'dan 7'e
|
|
196
|
+
String vatResponse = printerService.GetVatRate(i);
|
|
197
|
+
String[] responseParts = PrinterCoverService.printResponse(vatResponse);
|
|
160
198
|
if (responseParts.length >= 3) {
|
|
161
199
|
vatRates.put(responseParts[2]); // 3. parça: KDV oranı
|
|
162
200
|
}
|
|
@@ -216,17 +254,19 @@ public class CapacitorHuginGMP3Plugin extends Plugin {
|
|
|
216
254
|
return;
|
|
217
255
|
}
|
|
218
256
|
|
|
219
|
-
String vatResponse = implementation.huginPrinter.GetVATRate(vatId - 1);
|
|
220
|
-
String[] vatParts = printResponse(vatResponse);
|
|
221
257
|
|
|
222
|
-
if (vatParts.length < 3 || vatParts[2] == null || vatParts[2].trim().isEmpty()) {
|
|
223
|
-
call.reject("Belirtilen vatId (" + vatId + ") için geçerli bir KDV oranı bulunamadı. Lütfen önce geçerli bir KDV oranı tanımlayın.");
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
258
|
|
|
227
259
|
try {
|
|
228
|
-
|
|
229
|
-
String
|
|
260
|
+
printerService.VoidReceipt();
|
|
261
|
+
String vatResponse = printerService.GetVatRate(vatId - 1);
|
|
262
|
+
String[] vatParts = PrinterCoverService.printResponse(vatResponse);
|
|
263
|
+
|
|
264
|
+
if (vatParts.length < 3 || vatParts[2] == null || vatParts[2].trim().isEmpty()) {
|
|
265
|
+
call.reject("Belirtilen vatId (" + vatId + ") için geçerli bir KDV oranı bulunamadı. Lütfen önce geçerli bir KDV oranı tanımlayın.");
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
String response = printerService.SetDepartment(id, name, vatId, price, weighable);
|
|
269
|
+
String[] parts = PrinterCoverService.printResponse(response);
|
|
230
270
|
int errorCode = Integer.parseInt(parts[0]);
|
|
231
271
|
|
|
232
272
|
if (errorCode != 0) {
|
|
@@ -270,15 +310,16 @@ public class CapacitorHuginGMP3Plugin extends Plugin {
|
|
|
270
310
|
return;
|
|
271
311
|
}
|
|
272
312
|
|
|
273
|
-
if (vatRate <
|
|
313
|
+
if (vatRate < -1 || vatRate > 100) {
|
|
274
314
|
call.reject("KDV oranı (vatRate) 0 ile 100 arasında olmalıdır.");
|
|
275
315
|
return;
|
|
276
316
|
}
|
|
277
317
|
|
|
278
318
|
// --- KDV Ayarlama ---
|
|
279
319
|
try {
|
|
280
|
-
|
|
281
|
-
String
|
|
320
|
+
printerService.VoidReceipt();
|
|
321
|
+
String response = printerService.SetVATRate(index, vatRate);
|
|
322
|
+
String[] parts = PrinterCoverService.printResponse(response);
|
|
282
323
|
int errorCode = Integer.parseInt(parts[0]);
|
|
283
324
|
|
|
284
325
|
if (errorCode != 0) {
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
package com.kerzz.hugin.gmp3;
|
|
2
|
+
|
|
3
|
+
import android.app.Service;
|
|
4
|
+
import android.content.Intent;
|
|
5
|
+
import android.os.DeadObjectException;
|
|
6
|
+
import android.os.IBinder;
|
|
7
|
+
import android.os.RemoteException;
|
|
8
|
+
import android.util.Log;
|
|
9
|
+
|
|
10
|
+
import gmp3.droid.printer.DeviceInfo;
|
|
11
|
+
import gmp3.droid.printer.HuginPrinter;
|
|
12
|
+
import gmp3.droid.printer.Utility;
|
|
13
|
+
|
|
14
|
+
public class PrinterCoverService extends Service {
|
|
15
|
+
private final String TAG = "PrinterCoverService";
|
|
16
|
+
protected HuginPrinter printer = new HuginPrinter();
|
|
17
|
+
protected boolean tcpConnected = false;
|
|
18
|
+
|
|
19
|
+
private final IPrinterService.Stub binder = new IPrinterService.Stub() {
|
|
20
|
+
@Override
|
|
21
|
+
public boolean printXReport(int type) throws DeadObjectException {
|
|
22
|
+
try {
|
|
23
|
+
if (type < 0 || type > 10) {
|
|
24
|
+
Log.e("PrinterCoverService", "Geçersiz parametre.");
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return _printXReport(printer,type);
|
|
28
|
+
} catch (DeadObjectException e) {
|
|
29
|
+
Log.e("PrinterCoverService", "Java hatası: " + e.getMessage(), e);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Override
|
|
35
|
+
public boolean printZReport() throws DeadObjectException {
|
|
36
|
+
try {
|
|
37
|
+
return _printZReport(printer);
|
|
38
|
+
} catch (DeadObjectException e) {
|
|
39
|
+
Log.e("PrinterCoverService", "Java hatası: " + e.getMessage(), e);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Override
|
|
45
|
+
public boolean connect(String ip, int port, String terminalNo) throws RemoteException {
|
|
46
|
+
try {
|
|
47
|
+
tcpConnected = tcpConnect(ip,port);
|
|
48
|
+
if(!tcpConnected) {
|
|
49
|
+
Log.w(TAG,"TCP Bağlantısı sağlanamadı.");
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
DeviceInfo serverInfo = new DeviceInfo();
|
|
53
|
+
serverInfo.Brand = "HUGIN";
|
|
54
|
+
serverInfo.IP = ip;
|
|
55
|
+
serverInfo.Model = "HUGIN COMPACT";
|
|
56
|
+
serverInfo.Port = port;
|
|
57
|
+
serverInfo.TerminalNo = terminalNo;// "FP11004397";
|
|
58
|
+
serverInfo.Version = "";
|
|
59
|
+
serverInfo.SerialNum = "";
|
|
60
|
+
Log.i(TAG, serverInfo.IP);
|
|
61
|
+
return printer.Connect(serverInfo, serverInfo.TerminalNo, "");
|
|
62
|
+
} catch (Exception e) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Override
|
|
68
|
+
public boolean tcpConnect(String ip, int port) throws RemoteException {
|
|
69
|
+
try {
|
|
70
|
+
Log.i(TAG, "Binder TCP Connect");
|
|
71
|
+
if (ip == null || ip.isEmpty() || port <= 0) {
|
|
72
|
+
Log.e(TAG, "Geçersiz IP veya port.");
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return printer.TCPConnect(ip, port);
|
|
76
|
+
} catch (Exception e) {
|
|
77
|
+
Log.e(TAG, "tcpConnect hata: " + e.getMessage(), e);
|
|
78
|
+
return false;
|
|
79
|
+
} finally {
|
|
80
|
+
Log.i(TAG, "Finally ");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@Override
|
|
86
|
+
public String Sale(String saleItem) throws RemoteException {
|
|
87
|
+
try {
|
|
88
|
+
printer.VoidReceipt();
|
|
89
|
+
String res = printer.CheckPrinterStatus();
|
|
90
|
+
Log.i(TAG, res);
|
|
91
|
+
String result = printer.PrintDocumentHeader();
|
|
92
|
+
Log.i(TAG, result);
|
|
93
|
+
String str = printer.PrintJSONDocumentDeptOnly(saleItem);
|
|
94
|
+
Log.i(TAG, str);
|
|
95
|
+
String[] response = printResponse(str);
|
|
96
|
+
if(response.length > 2) {
|
|
97
|
+
return printResponse(str)[2];
|
|
98
|
+
}
|
|
99
|
+
return "-1";
|
|
100
|
+
} catch (Exception e) {
|
|
101
|
+
return "-1";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@Override
|
|
107
|
+
public String GetDepartment(int index) throws RemoteException {
|
|
108
|
+
try {
|
|
109
|
+
return printer.GetDepartment(index);
|
|
110
|
+
} catch (Exception e) {
|
|
111
|
+
return "";
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@Override
|
|
116
|
+
public String GetVatRate(int index) throws RemoteException {
|
|
117
|
+
try {
|
|
118
|
+
return printer.GetVATRate(index);
|
|
119
|
+
} catch (Exception e) {
|
|
120
|
+
return "";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@Override
|
|
125
|
+
public String libraryVersion() throws RemoteException {
|
|
126
|
+
return printer.LibraryVersion();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@Override
|
|
130
|
+
public String SetDepartment(int var1, String var2, int var3, double var4, int var6) throws RemoteException {
|
|
131
|
+
return printer.SetDepartment(var1,var2,var3,var4,var6);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@Override
|
|
135
|
+
public String SetVATRate(int index, double vatRate) throws RemoteException {
|
|
136
|
+
return printer.SetVATRate(index, vatRate);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@Override
|
|
140
|
+
public String VoidReceipt() throws RemoteException {
|
|
141
|
+
printer.VoidReceipt();
|
|
142
|
+
return "";
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
@Override
|
|
147
|
+
public IBinder onBind(Intent intent) {
|
|
148
|
+
return binder;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@Override
|
|
152
|
+
public void onCreate() {
|
|
153
|
+
super.onCreate();
|
|
154
|
+
printer = new HuginPrinter();
|
|
155
|
+
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
|
|
156
|
+
Log.e("GlobalCrash", "Yakalanamayan hata: " + e.getMessage(), e);
|
|
157
|
+
android.os.Process.killProcess(android.os.Process.myPid());
|
|
158
|
+
System.exit(1); // ❗ Android alert göstermez
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
private boolean _printXReport(HuginPrinter printer,int type) throws DeadObjectException {
|
|
164
|
+
try {
|
|
165
|
+
printer.VoidReceipt();
|
|
166
|
+
String[] response = printResponse(printer.PrintXReport(type));
|
|
167
|
+
int errorCode = Integer.parseInt(response[0]);
|
|
168
|
+
if(errorCode != 0) {
|
|
169
|
+
System.out.println("Error Code : " + Utility.GetErrorMessage(errorCode));
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
return true;
|
|
173
|
+
} catch (Exception e) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private boolean _printZReport(HuginPrinter printer) throws DeadObjectException {
|
|
179
|
+
try {
|
|
180
|
+
printer.VoidReceipt();
|
|
181
|
+
String[] response = printResponse(printer.PrintZReport());
|
|
182
|
+
int errorCode = Integer.parseInt(response[0]);
|
|
183
|
+
if(errorCode != 0) {
|
|
184
|
+
System.out.println("Error Code : " + Utility.GetErrorMessage(errorCode));
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return true;
|
|
189
|
+
} catch (Exception e) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
public static String[] printResponse(String response) {
|
|
195
|
+
int res = 6;
|
|
196
|
+
String[] splitted = response.split("\\|", 0);
|
|
197
|
+
if (splitted.length >= 2) {
|
|
198
|
+
res = Integer.parseInt(splitted[0]);
|
|
199
|
+
System.out.println("Error Code : " + Utility.GetErrorMessage(res));
|
|
200
|
+
System.out.println("State : " + Utility.GetStateMessage(Integer.parseInt(splitted[1])));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
System.out.println("Full Response : " + response);
|
|
204
|
+
return splitted;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
}
|
package/package.json
CHANGED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
package com.kerzz.hugin.gmp3;
|
|
2
|
-
|
|
3
|
-
import android.util.Log;
|
|
4
|
-
|
|
5
|
-
import com.getcapacitor.JSObject;
|
|
6
|
-
|
|
7
|
-
import gmp3.droid.printer.DeviceInfo;
|
|
8
|
-
import gmp3.droid.printer.HuginPrinter;
|
|
9
|
-
import gmp3.droid.printer.Utility;
|
|
10
|
-
|
|
11
|
-
public class CapacitorHuginGMP3 {
|
|
12
|
-
protected final HuginPrinter huginPrinter = new HuginPrinter();
|
|
13
|
-
private final String TAG = "CapacitorHuginGMP3Plugin";
|
|
14
|
-
protected boolean tcpConnected = false;
|
|
15
|
-
private int tcpRetry = 0;
|
|
16
|
-
private boolean tcpConnect(String ip, Integer port) {
|
|
17
|
-
try {
|
|
18
|
-
if(tcpConnected) return true;
|
|
19
|
-
if (port == null) {
|
|
20
|
-
Log.w(TAG,"Port parametresi eksik.");
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return huginPrinter.TCPConnect(ip, port);
|
|
25
|
-
} catch (RuntimeException e) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
protected boolean connect(String ip, int port, String terminalNo) {
|
|
31
|
-
try {
|
|
32
|
-
tcpConnected = tcpConnect(ip,port);
|
|
33
|
-
if(!tcpConnected) {
|
|
34
|
-
tcpRetry += 1;
|
|
35
|
-
Log.w(TAG,"TCP Bağlantısı sağlanamadı. Tekrar deneniyor: " + tcpRetry);
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
DeviceInfo serverInfo = new DeviceInfo();
|
|
39
|
-
serverInfo.Brand = "HUGIN";
|
|
40
|
-
serverInfo.IP = ip;
|
|
41
|
-
serverInfo.Model = "HUGIN COMPACT";
|
|
42
|
-
serverInfo.Port = port;
|
|
43
|
-
serverInfo.TerminalNo = terminalNo;// "FP11004397";
|
|
44
|
-
serverInfo.Version = "";
|
|
45
|
-
serverInfo.SerialNum = "";
|
|
46
|
-
Log.i(TAG, serverInfo.IP);
|
|
47
|
-
return huginPrinter.Connect(serverInfo, serverInfo.TerminalNo, "");
|
|
48
|
-
} catch (Exception e) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
protected String libraryVersion() {
|
|
54
|
-
return huginPrinter.LibraryVersion();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
protected boolean printZReport() {
|
|
58
|
-
try {
|
|
59
|
-
String[] response = printResponse(huginPrinter.PrintZReport());
|
|
60
|
-
int errorCode = Integer.parseInt(response[0]);
|
|
61
|
-
if(errorCode != 0) {
|
|
62
|
-
System.out.println("Error Code : " + Utility.GetErrorMessage(errorCode));
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return true;
|
|
67
|
-
} catch (Exception e) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
protected boolean printXReport(int type) {
|
|
73
|
-
try {
|
|
74
|
-
String[] response = printResponse(huginPrinter.PrintXReport(type));
|
|
75
|
-
int errorCode = Integer.parseInt(response[0]);
|
|
76
|
-
if(errorCode != 0) {
|
|
77
|
-
System.out.println("Error Code : " + Utility.GetErrorMessage(errorCode));
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
return true;
|
|
81
|
-
} catch (Exception e) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
protected static String[] printResponse(String response) {
|
|
88
|
-
int res = 6;
|
|
89
|
-
String[] splitted = response.split("\\|", 0);
|
|
90
|
-
if (splitted.length >= 2) {
|
|
91
|
-
res = Integer.parseInt(splitted[0]);
|
|
92
|
-
System.out.println("Error Code : " + Utility.GetErrorMessage(res));
|
|
93
|
-
System.out.println("State : " + Utility.GetStateMessage(Integer.parseInt(splitted[1])));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
System.out.println("Full Response : " + response);
|
|
97
|
-
return splitted;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
protected String sale(JSObject saleItem) {
|
|
101
|
-
String res = huginPrinter.CheckPrinterStatus();
|
|
102
|
-
Log.i(TAG, res);
|
|
103
|
-
String result = huginPrinter.PrintDocumentHeader();
|
|
104
|
-
Log.i(TAG, result);
|
|
105
|
-
String str = huginPrinter.PrintJSONDocumentDeptOnly(saleItem.toString());
|
|
106
|
-
Log.i(TAG, str);
|
|
107
|
-
String[] response = printResponse(str);
|
|
108
|
-
if(response.length > 2) {
|
|
109
|
-
return printResponse(str)[2];
|
|
110
|
-
}
|
|
111
|
-
return "-1";
|
|
112
|
-
// String result = huginPrinter.PrintDocumentHeader();
|
|
113
|
-
// String item1 = huginPrinter.PrintItem(1, 15, 3.00, "Capacitor Ürün", "", 1, 1);
|
|
114
|
-
// String item2 = huginPrinter.PrintItem(1, 30, 3.00, "Capacitor Ürün 2", "", 1, 1);
|
|
115
|
-
// String payment = huginPrinter.PrintPayment(0 , -1 , 300);
|
|
116
|
-
//
|
|
117
|
-
// huginPrinter.CloseReceipt(false);
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|