capacitor-hugin-gmp3 0.2.1 → 0.2.3
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/README.md +5 -72
- 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 +91 -49
- package/android/src/main/java/com/kerzz/hugin/gmp3/PrinterCoverService.java +257 -0
- package/dist/docs.json +2 -246
- package/dist/esm/definitions.d.ts +22 -6
- package/dist/esm/definitions.js +34 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +4 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +37 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +37 -0
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
- package/android/src/main/java/com/kerzz/hugin/gmp3/CapacitorHuginGMP3.java +0 -122
package/README.md
CHANGED
|
@@ -77,9 +77,9 @@ Sale(options: { saleItem: SaleItem; }) => Promise<{ orderNo?: number; result: bo
|
|
|
77
77
|
|
|
78
78
|
Satış işlemi başlatır.
|
|
79
79
|
|
|
80
|
-
| Param | Type
|
|
81
|
-
| ------------- |
|
|
82
|
-
| **`options`** | <code>{ saleItem:
|
|
80
|
+
| Param | Type | Description |
|
|
81
|
+
| ------------- | ------------------------------------ | ----------------------------------- |
|
|
82
|
+
| **`options`** | <code>{ saleItem: SaleItem; }</code> | Satış nesnesi (JSON string olarak). |
|
|
83
83
|
|
|
84
84
|
**Returns:** <code>Promise<{ orderNo?: number; result: boolean; message?: string; }></code>
|
|
85
85
|
|
|
@@ -119,12 +119,12 @@ Z raporu yazdırır.
|
|
|
119
119
|
### GetVatRates()
|
|
120
120
|
|
|
121
121
|
```typescript
|
|
122
|
-
GetVatRates() => Promise<string[]>
|
|
122
|
+
GetVatRates() => Promise<{ result: boolean; vatRates: string[]; }>
|
|
123
123
|
```
|
|
124
124
|
|
|
125
125
|
Kayıtlı KDV oranlarını getirir.
|
|
126
126
|
|
|
127
|
-
**Returns:** <code>Promise<string[]></code>
|
|
127
|
+
**Returns:** <code>Promise<{ result: boolean; vatRates: string[]; }></code>
|
|
128
128
|
|
|
129
129
|
--------------------
|
|
130
130
|
|
|
@@ -190,73 +190,6 @@ Bağlantı ayarları.
|
|
|
190
190
|
| **`port`** | <code>number</code> | Cihaz port numarası. |
|
|
191
191
|
|
|
192
192
|
|
|
193
|
-
#### SaleItem
|
|
194
|
-
|
|
195
|
-
Satış bilgisi.
|
|
196
|
-
|
|
197
|
-
| Prop | Type | Description |
|
|
198
|
-
| ---------------------- | ------------------------------------------------------------- | ---------------------------- |
|
|
199
|
-
| **`FiscalItems`** | <code>FiscalItem[]</code> | Satışta yer alan ürünler. |
|
|
200
|
-
| **`Adjustments`** | <code>Adj[]</code> | Satışa uygulanan indirimler. |
|
|
201
|
-
| **`Payments`** | <code>Payment[]</code> | Ödeme bilgileri. |
|
|
202
|
-
| **`FooterNotes`** | <code>string[]</code> | Fiş altı notları. |
|
|
203
|
-
| **`EndOfReceiptInfo`** | <code><a href="#endofreceiptinfo">EndOfReceiptInfo</a></code> | Fiş kapanış bilgisi. |
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
#### FiscalItem
|
|
207
|
-
|
|
208
|
-
Satışta yer alan ürün bilgisi.
|
|
209
|
-
|
|
210
|
-
| Prop | Type | Description |
|
|
211
|
-
| --------------- | ------------------------------------------- | ------------------- |
|
|
212
|
-
| **`Id`** | <code>number</code> | Ürün ID. |
|
|
213
|
-
| **`Quantity`** | <code>number</code> | Miktar. |
|
|
214
|
-
| **`Price`** | <code>number</code> | Fiyat. |
|
|
215
|
-
| **`Name`** | <code>string</code> | Ürün adı. |
|
|
216
|
-
| **`DeptId`** | <code>number</code> | Departman ID. |
|
|
217
|
-
| **`Status`** | <code>number</code> | Ürün durumu. |
|
|
218
|
-
| **`Adj`** | <code><a href="#adj">Adj</a> \| null</code> | Ürüne özel indirim. |
|
|
219
|
-
| **`NoteLine1`** | <code>string \| null</code> | Not satırı 1. |
|
|
220
|
-
| **`NoteLine2`** | <code>string \| null</code> | Not satırı 2. |
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
#### Adj
|
|
224
|
-
|
|
225
|
-
İndirim bilgisi.
|
|
226
|
-
|
|
227
|
-
| Prop | Type | Description |
|
|
228
|
-
| ---------------- | --------------------------- | ---------------- |
|
|
229
|
-
| **`Type`** | <code>number</code> | İndirim tipi. |
|
|
230
|
-
| **`Amount`** | <code>number</code> | İndirim tutarı. |
|
|
231
|
-
| **`percentage`** | <code>number</code> | İndirim yüzdesi. |
|
|
232
|
-
| **`NoteLine1`** | <code>string \| null</code> | Not satırı 1. |
|
|
233
|
-
| **`NoteLine2`** | <code>string \| null</code> | Not satırı 2. |
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
#### Payment
|
|
237
|
-
|
|
238
|
-
Ödeme bilgileri.
|
|
239
|
-
|
|
240
|
-
| Prop | Type | Description |
|
|
241
|
-
| ---------------- | -------------------- | ------------------------------- |
|
|
242
|
-
| **`Type`** | <code>number</code> | Ödeme tipi (örn: nakit, kredi). |
|
|
243
|
-
| **`Index`** | <code>number</code> | Ödeme indexi. |
|
|
244
|
-
| **`PaidTotal`** | <code>number</code> | Ödenen toplam tutar. |
|
|
245
|
-
| **`viaByEFT`** | <code>boolean</code> | EFT ile mi yapıldı? |
|
|
246
|
-
| **`SequenceNo`** | <code>number</code> | Sıra numarası. |
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
#### EndOfReceiptInfo
|
|
250
|
-
|
|
251
|
-
Fiş kapanış bilgileri.
|
|
252
|
-
|
|
253
|
-
| Prop | Type | Description |
|
|
254
|
-
| ---------------------- | --------------------------- | ------------------- |
|
|
255
|
-
| **`CloseReceiptFlag`** | <code>boolean</code> | Fişi kapat. |
|
|
256
|
-
| **`BarcodeFlag`** | <code>boolean</code> | Barkod basılsın mı? |
|
|
257
|
-
| **`Barcode`** | <code>string \| null</code> | Barkod numarası. |
|
|
258
|
-
|
|
259
|
-
|
|
260
193
|
#### Department
|
|
261
194
|
|
|
262
195
|
Departman bilgisi.
|
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,9 +106,10 @@ 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();
|
|
112
|
+
|
|
89
113
|
if(!response.equals("-1")) {
|
|
90
114
|
|
|
91
115
|
res.put("orderNo", response);
|
|
@@ -97,38 +121,52 @@ public class CapacitorHuginGMP3Plugin extends Plugin {
|
|
|
97
121
|
call.resolve(res);
|
|
98
122
|
}
|
|
99
123
|
|
|
100
|
-
} catch (
|
|
124
|
+
} catch (RemoteException e) {
|
|
101
125
|
Log.e(TAG, "Sale Error", e);
|
|
126
|
+
call.reject("Must Reconnect", e);
|
|
127
|
+
} catch (Exception e) {
|
|
102
128
|
call.reject("Sale failed", e);
|
|
103
129
|
}
|
|
104
130
|
}
|
|
105
131
|
|
|
106
132
|
@PluginMethod
|
|
107
133
|
public void PrintZReport(PluginCall call) {
|
|
108
|
-
|
|
134
|
+
if (printerService != null) {
|
|
135
|
+
try {
|
|
136
|
+
call.resolve(JSObjectHelper.result(printerService.printZReport()));
|
|
137
|
+
} catch (RemoteException e) {
|
|
138
|
+
Log.e(TAG, e.toString());
|
|
139
|
+
call.resolve(JSObjectHelper.result(false));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
109
142
|
}
|
|
110
143
|
|
|
111
144
|
@PluginMethod
|
|
112
|
-
public void PrintXReport(PluginCall call) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
145
|
+
public void PrintXReport(PluginCall call) throws DeadObjectException {
|
|
146
|
+
if (printerService != null) {
|
|
147
|
+
int type = 1;
|
|
148
|
+
try {
|
|
149
|
+
Integer typeValue = call.getInt("type");
|
|
150
|
+
if (typeValue != null) {
|
|
151
|
+
type = typeValue;
|
|
152
|
+
}
|
|
153
|
+
call.resolve(JSObjectHelper.result(printerService.printXReport(type)));
|
|
154
|
+
} catch (RemoteException e) {
|
|
155
|
+
Log.e(TAG, e.toString());
|
|
156
|
+
call.resolve(JSObjectHelper.result(false));
|
|
118
157
|
}
|
|
119
|
-
} catch (Exception e) {
|
|
120
|
-
Log.e(TAG, e.toString());
|
|
121
158
|
}
|
|
122
|
-
|
|
159
|
+
|
|
123
160
|
}
|
|
124
161
|
|
|
125
162
|
@PluginMethod
|
|
126
163
|
public void GetDepartments(PluginCall call) {
|
|
127
164
|
JSArray depts = new JSArray();
|
|
128
165
|
try {
|
|
166
|
+
printerService.VoidReceipt();
|
|
129
167
|
for (int i = 1; i < 9; i++) { // 1-8
|
|
130
|
-
String deptResponse =
|
|
131
|
-
String[] parts = printResponse(deptResponse);
|
|
168
|
+
String deptResponse = printerService.GetDepartment(i);
|
|
169
|
+
String[] parts = PrinterCoverService.printResponse(deptResponse);
|
|
132
170
|
|
|
133
171
|
if (parts.length >= 6) {
|
|
134
172
|
JSObject dept = new JSObject();
|
|
@@ -152,11 +190,12 @@ public class CapacitorHuginGMP3Plugin extends Plugin {
|
|
|
152
190
|
|
|
153
191
|
@PluginMethod
|
|
154
192
|
public void GetVatRates(PluginCall call) {
|
|
155
|
-
JSArray vatRates = new JSArray();
|
|
156
193
|
try {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
194
|
+
printerService.VoidReceipt();
|
|
195
|
+
JSArray vatRates = new JSArray();
|
|
196
|
+
for (int i = 0; i < 8; i++) { // 0'dan 7'e
|
|
197
|
+
String vatResponse = printerService.GetVatRate(i);
|
|
198
|
+
String[] responseParts = PrinterCoverService.printResponse(vatResponse);
|
|
160
199
|
if (responseParts.length >= 3) {
|
|
161
200
|
vatRates.put(responseParts[2]); // 3. parça: KDV oranı
|
|
162
201
|
}
|
|
@@ -216,17 +255,19 @@ public class CapacitorHuginGMP3Plugin extends Plugin {
|
|
|
216
255
|
return;
|
|
217
256
|
}
|
|
218
257
|
|
|
219
|
-
String vatResponse = implementation.huginPrinter.GetVATRate(vatId - 1);
|
|
220
|
-
String[] vatParts = printResponse(vatResponse);
|
|
221
258
|
|
|
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
259
|
|
|
227
260
|
try {
|
|
228
|
-
|
|
229
|
-
String
|
|
261
|
+
printerService.VoidReceipt();
|
|
262
|
+
String vatResponse = printerService.GetVatRate(vatId - 1);
|
|
263
|
+
String[] vatParts = PrinterCoverService.printResponse(vatResponse);
|
|
264
|
+
|
|
265
|
+
if (vatParts.length < 3 || vatParts[2] == null || vatParts[2].trim().isEmpty()) {
|
|
266
|
+
call.reject("Belirtilen vatId (" + vatId + ") için geçerli bir KDV oranı bulunamadı. Lütfen önce geçerli bir KDV oranı tanımlayın.");
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
String response = printerService.SetDepartment(id, name, vatId, price, weighable);
|
|
270
|
+
String[] parts = PrinterCoverService.printResponse(response);
|
|
230
271
|
int errorCode = Integer.parseInt(parts[0]);
|
|
231
272
|
|
|
232
273
|
if (errorCode != 0) {
|
|
@@ -270,15 +311,16 @@ public class CapacitorHuginGMP3Plugin extends Plugin {
|
|
|
270
311
|
return;
|
|
271
312
|
}
|
|
272
313
|
|
|
273
|
-
if (vatRate <
|
|
314
|
+
if (vatRate < -1 || vatRate > 100) {
|
|
274
315
|
call.reject("KDV oranı (vatRate) 0 ile 100 arasında olmalıdır.");
|
|
275
316
|
return;
|
|
276
317
|
}
|
|
277
318
|
|
|
278
319
|
// --- KDV Ayarlama ---
|
|
279
320
|
try {
|
|
280
|
-
|
|
281
|
-
String
|
|
321
|
+
printerService.VoidReceipt();
|
|
322
|
+
String response = printerService.SetVATRate(index, vatRate);
|
|
323
|
+
String[] parts = PrinterCoverService.printResponse(response);
|
|
282
324
|
int errorCode = Integer.parseInt(parts[0]);
|
|
283
325
|
|
|
284
326
|
if (errorCode != 0) {
|
|
@@ -0,0 +1,257 @@
|
|
|
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 com.getcapacitor.JSArray;
|
|
11
|
+
import com.getcapacitor.JSObject;
|
|
12
|
+
|
|
13
|
+
import org.json.JSONArray;
|
|
14
|
+
import org.json.JSONObject;
|
|
15
|
+
|
|
16
|
+
import gmp3.droid.printer.DeviceInfo;
|
|
17
|
+
import gmp3.droid.printer.HuginPrinter;
|
|
18
|
+
import gmp3.droid.printer.Utility;
|
|
19
|
+
|
|
20
|
+
public class PrinterCoverService extends Service {
|
|
21
|
+
private final String TAG = "PrinterCoverService";
|
|
22
|
+
protected HuginPrinter printer = new HuginPrinter();
|
|
23
|
+
protected boolean tcpConnected = false;
|
|
24
|
+
|
|
25
|
+
private final IPrinterService.Stub binder = new IPrinterService.Stub() {
|
|
26
|
+
@Override
|
|
27
|
+
public boolean printXReport(int type) throws DeadObjectException {
|
|
28
|
+
try {
|
|
29
|
+
if (type < 0 || type > 10) {
|
|
30
|
+
Log.e("PrinterCoverService", "Geçersiz parametre.");
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return _printXReport(printer,type);
|
|
34
|
+
} catch (DeadObjectException e) {
|
|
35
|
+
Log.e("PrinterCoverService", "Java hatası: " + e.getMessage(), e);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Override
|
|
41
|
+
public boolean printZReport() throws DeadObjectException {
|
|
42
|
+
try {
|
|
43
|
+
return _printZReport(printer);
|
|
44
|
+
} catch (DeadObjectException e) {
|
|
45
|
+
Log.e("PrinterCoverService", "Java hatası: " + e.getMessage(), e);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Override
|
|
51
|
+
public boolean connect(String ip, int port, String terminalNo) throws RemoteException {
|
|
52
|
+
try {
|
|
53
|
+
tcpConnected = tcpConnect(ip,port);
|
|
54
|
+
if(!tcpConnected) {
|
|
55
|
+
Log.w(TAG,"TCP Bağlantısı sağlanamadı.");
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
DeviceInfo serverInfo = new DeviceInfo();
|
|
59
|
+
serverInfo.Brand = "HUGIN";
|
|
60
|
+
serverInfo.IP = ip;
|
|
61
|
+
serverInfo.Model = "HUGIN COMPACT";
|
|
62
|
+
serverInfo.Port = port;
|
|
63
|
+
serverInfo.TerminalNo = terminalNo;// "FP11004397";
|
|
64
|
+
serverInfo.Version = "";
|
|
65
|
+
serverInfo.SerialNum = "";
|
|
66
|
+
Log.i(TAG, serverInfo.IP);
|
|
67
|
+
return printer.Connect(serverInfo, serverInfo.TerminalNo, "");
|
|
68
|
+
} catch (Exception e) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Override
|
|
74
|
+
public boolean tcpConnect(String ip, int port) throws RemoteException {
|
|
75
|
+
try {
|
|
76
|
+
Log.i(TAG, "Binder TCP Connect");
|
|
77
|
+
if (ip == null || ip.isEmpty() || port <= 0) {
|
|
78
|
+
Log.e(TAG, "Geçersiz IP veya port.");
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return printer.TCPConnect(ip, port);
|
|
82
|
+
} catch (Exception e) {
|
|
83
|
+
Log.e(TAG, "tcpConnect hata: " + e.getMessage(), e);
|
|
84
|
+
return false;
|
|
85
|
+
} finally {
|
|
86
|
+
Log.i(TAG, "Finally ");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@Override
|
|
92
|
+
public String Sale(String saleItem) throws RemoteException {
|
|
93
|
+
try {
|
|
94
|
+
printer.VoidReceipt();
|
|
95
|
+
JSONObject jsObjectSale = new JSONObject(saleItem);
|
|
96
|
+
JSObject saleItems = new JSObject();
|
|
97
|
+
saleItems.put("FiscalItems", (jsObjectSale.getJSONArray("FiscalItems")));
|
|
98
|
+
saleItems.put("Adjustments", (jsObjectSale.getJSONArray("Adjustments")));
|
|
99
|
+
saleItems.put("Payments", new JSArray());
|
|
100
|
+
saleItems.put("EndOfReceiptInfo", jsObjectSale.getJSONObject("EndOfReceiptInfo"));
|
|
101
|
+
saleItems.put("FooterNotes", (jsObjectSale.getJSONArray("FooterNotes")));
|
|
102
|
+
JSONArray payments = jsObjectSale.getJSONArray("Payments");
|
|
103
|
+
|
|
104
|
+
String res = printer.CheckPrinterStatus();
|
|
105
|
+
Log.i(TAG, res);
|
|
106
|
+
String result = printer.PrintDocumentHeader();
|
|
107
|
+
Log.i(TAG, saleItems.toString());
|
|
108
|
+
|
|
109
|
+
String str = printer.PrintJSONDocumentDeptOnly(saleItems.toString());
|
|
110
|
+
|
|
111
|
+
JSONArray otherPayments = new JSONArray();
|
|
112
|
+
Double totalCreditPayment = 0.0;
|
|
113
|
+
for (var i = 0; i < payments.length(); i++) {
|
|
114
|
+
JSONObject payment = new JSONObject(payments.getJSONObject(i).toString());
|
|
115
|
+
if(payment.getInt("Type") == 99) {
|
|
116
|
+
totalCreditPayment = payment.getDouble("PaidTotal");
|
|
117
|
+
} else {
|
|
118
|
+
otherPayments.put(payment);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
String creditPayment = "0";
|
|
122
|
+
if(totalCreditPayment > 0.0) {
|
|
123
|
+
creditPayment = printer.GetEFTAuthorisation(totalCreditPayment, 0, "");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if(creditPayment.startsWith("0")) {
|
|
127
|
+
for (var i = 0; i < otherPayments.length(); i++) {
|
|
128
|
+
JSONObject payment = new JSONObject(payments.getJSONObject(i).toString());
|
|
129
|
+
printer.PrintPayment(payment.getInt("Type"), i, payment.getDouble("PaidTotal"));
|
|
130
|
+
}
|
|
131
|
+
Log.i(TAG, creditPayment);
|
|
132
|
+
|
|
133
|
+
String closeReceipt = printer.CloseReceipt(true);
|
|
134
|
+
|
|
135
|
+
Log.i(TAG, str);
|
|
136
|
+
String[] response = printResponse(closeReceipt);
|
|
137
|
+
if(response[0].equals("0")) {
|
|
138
|
+
return response[2];
|
|
139
|
+
}
|
|
140
|
+
return "-1";
|
|
141
|
+
} else {
|
|
142
|
+
printer.VoidReceipt();
|
|
143
|
+
return "-1";
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
} catch (Exception e) {
|
|
148
|
+
Log.i(TAG, e.toString());
|
|
149
|
+
printer.VoidPayment(0);
|
|
150
|
+
printer.VoidReceipt();
|
|
151
|
+
return "-1";
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
@Override
|
|
157
|
+
public String GetDepartment(int index) throws RemoteException {
|
|
158
|
+
try {
|
|
159
|
+
return printer.GetDepartment(index);
|
|
160
|
+
} catch (Exception e) {
|
|
161
|
+
return "";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@Override
|
|
166
|
+
public String GetVatRate(int index) throws RemoteException {
|
|
167
|
+
try {
|
|
168
|
+
return printer.GetVATRate(index);
|
|
169
|
+
} catch (Exception e) {
|
|
170
|
+
return "";
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@Override
|
|
175
|
+
public String libraryVersion() throws RemoteException {
|
|
176
|
+
return printer.LibraryVersion();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@Override
|
|
180
|
+
public String SetDepartment(int var1, String var2, int var3, double var4, int var6) throws RemoteException {
|
|
181
|
+
return printer.SetDepartment(var1,var2,var3,var4,var6);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@Override
|
|
185
|
+
public String SetVATRate(int index, double vatRate) throws RemoteException {
|
|
186
|
+
return printer.SetVATRate(index, vatRate);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
@Override
|
|
190
|
+
public String VoidReceipt() throws RemoteException {
|
|
191
|
+
printer.VoidReceipt();
|
|
192
|
+
return "";
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
@Override
|
|
197
|
+
public IBinder onBind(Intent intent) {
|
|
198
|
+
return binder;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@Override
|
|
202
|
+
public void onCreate() {
|
|
203
|
+
super.onCreate();
|
|
204
|
+
printer = new HuginPrinter();
|
|
205
|
+
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
|
|
206
|
+
Log.e("GlobalCrash", "Yakalanamayan hata: " + e.getMessage(), e);
|
|
207
|
+
android.os.Process.killProcess(android.os.Process.myPid());
|
|
208
|
+
System.exit(1); // ❗ Android alert göstermez
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
private boolean _printXReport(HuginPrinter printer,int type) throws DeadObjectException {
|
|
214
|
+
try {
|
|
215
|
+
printer.VoidReceipt();
|
|
216
|
+
String[] response = printResponse(printer.PrintXReport(type));
|
|
217
|
+
int errorCode = Integer.parseInt(response[0]);
|
|
218
|
+
if(errorCode != 0) {
|
|
219
|
+
System.out.println("Error Code : " + Utility.GetErrorMessage(errorCode));
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
return true;
|
|
223
|
+
} catch (Exception e) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
private boolean _printZReport(HuginPrinter printer) throws DeadObjectException {
|
|
229
|
+
try {
|
|
230
|
+
printer.VoidReceipt();
|
|
231
|
+
String[] response = printResponse(printer.PrintZReport());
|
|
232
|
+
int errorCode = Integer.parseInt(response[0]);
|
|
233
|
+
if(errorCode != 0) {
|
|
234
|
+
System.out.println("Error Code : " + Utility.GetErrorMessage(errorCode));
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return true;
|
|
239
|
+
} catch (Exception e) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
public static String[] printResponse(String response) {
|
|
245
|
+
int res = 6;
|
|
246
|
+
String[] splitted = response.split("\\|", 0);
|
|
247
|
+
if (splitted.length >= 2) {
|
|
248
|
+
res = Integer.parseInt(splitted[0]);
|
|
249
|
+
System.out.println("Error Code : " + Utility.GetErrorMessage(res));
|
|
250
|
+
System.out.println("State : " + Utility.GetStateMessage(Integer.parseInt(splitted[1])));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
System.out.println("Full Response : " + response);
|
|
254
|
+
return splitted;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
}
|