capacitor-hugin-gmp3 0.1.0
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/CapacitorHuginGMP3Plugin.podspec +17 -0
- package/Package.swift +28 -0
- package/README.md +275 -0
- package/android/build.gradle +64 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/kerzz/hugin/gmp3/CapacitorHuginGMP3.java +122 -0
- package/android/src/main/java/com/kerzz/hugin/gmp3/CapacitorHuginGMP3Plugin.java +296 -0
- package/android/src/main/java/com/kerzz/hugin/gmp3/JSObjectHelper.java +18 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +519 -0
- package/dist/esm/definitions.d.ts +182 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +32 -0
- package/dist/esm/web.js +36 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +50 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +53 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/HuginGMP3Plugin/HuginGMP3.swift +8 -0
- package/ios/Sources/HuginGMP3Plugin/HuginGMP3Plugin.swift +23 -0
- package/ios/Tests/HuginGMP3PluginTests/HuginGMP3PluginTests.swift +15 -0
- package/package.json +77 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
package com.kerzz.hugin.gmp3;
|
|
2
|
+
|
|
3
|
+
import static com.kerzz.hugin.gmp3.CapacitorHuginGMP3.printResponse;
|
|
4
|
+
|
|
5
|
+
import android.os.Build;
|
|
6
|
+
import android.util.Log;
|
|
7
|
+
|
|
8
|
+
import com.getcapacitor.JSArray;
|
|
9
|
+
import com.getcapacitor.JSObject;
|
|
10
|
+
import com.getcapacitor.Plugin;
|
|
11
|
+
import com.getcapacitor.PluginCall;
|
|
12
|
+
import com.getcapacitor.PluginMethod;
|
|
13
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
14
|
+
|
|
15
|
+
import java.time.LocalDateTime;
|
|
16
|
+
|
|
17
|
+
import gmp3.droid.printer.Utility;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@CapacitorPlugin(name = "CapacitorHuginGMP3")
|
|
21
|
+
public class CapacitorHuginGMP3Plugin extends Plugin {
|
|
22
|
+
private final CapacitorHuginGMP3 implementation = new CapacitorHuginGMP3();
|
|
23
|
+
private final String TAG = "CapacitorHuginGMP3";
|
|
24
|
+
@Override
|
|
25
|
+
public void load() {
|
|
26
|
+
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
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@PluginMethod
|
|
43
|
+
public void GetLibraryVersion(PluginCall call) {
|
|
44
|
+
String version = implementation.libraryVersion();
|
|
45
|
+
call.resolve(new JSObject().put("version", version));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@PluginMethod
|
|
49
|
+
public void Connect(PluginCall call) {
|
|
50
|
+
try {
|
|
51
|
+
String terminalNo = call.getString("terminalNo");
|
|
52
|
+
String ip = call.getString("ip");
|
|
53
|
+
Integer port = call.getInt("port", 4444);
|
|
54
|
+
if (port == null) {
|
|
55
|
+
call.reject("Port parametresi eksik.");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (terminalNo == null || ip == null || port == 0) {
|
|
60
|
+
call.reject("Parametre eksik: terminalNo, ip veya port");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
boolean connected = implementation.connect(ip, port, terminalNo);
|
|
65
|
+
JSObject result = new JSObject();
|
|
66
|
+
result.put("connected", connected);
|
|
67
|
+
call.resolve(result);
|
|
68
|
+
} catch (Exception e) {
|
|
69
|
+
Log.i(TAG,e.toString());
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@PluginMethod
|
|
75
|
+
public void Sale(PluginCall call) {
|
|
76
|
+
// TODO: Sale
|
|
77
|
+
try {
|
|
78
|
+
JSObject saleItem = call.getObject("saleItem");
|
|
79
|
+
if (saleItem == null) {
|
|
80
|
+
call.resolve(JSObjectHelper.result(false, "Sale Item Required"));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Log.i(TAG, "Sale Request: " + saleItem);
|
|
85
|
+
|
|
86
|
+
String response = implementation.sale(saleItem);
|
|
87
|
+
Log.i(TAG, "Sale Response: " + response);
|
|
88
|
+
JSObject res = new JSObject();
|
|
89
|
+
if(!response.equals("-1")) {
|
|
90
|
+
|
|
91
|
+
res.put("orderNo", response);
|
|
92
|
+
res.put("result", true);
|
|
93
|
+
call.resolve(res);
|
|
94
|
+
} else {
|
|
95
|
+
res.put("message", "Sale Error");
|
|
96
|
+
res.put("result", false);
|
|
97
|
+
call.resolve(res);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
} catch (Exception e) {
|
|
101
|
+
Log.e(TAG, "Sale Error", e);
|
|
102
|
+
call.reject("Sale failed", e);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@PluginMethod
|
|
107
|
+
public void PrintZReport(PluginCall call) {
|
|
108
|
+
call.resolve(JSObjectHelper.result(implementation.printZReport()));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@PluginMethod
|
|
112
|
+
public void PrintXReport(PluginCall call) {
|
|
113
|
+
int type = 1;
|
|
114
|
+
try {
|
|
115
|
+
Integer typeValue = call.getInt("type");
|
|
116
|
+
if (typeValue != null) {
|
|
117
|
+
type = typeValue;
|
|
118
|
+
}
|
|
119
|
+
} catch (Exception e) {
|
|
120
|
+
Log.e(TAG, e.toString());
|
|
121
|
+
}
|
|
122
|
+
call.resolve(JSObjectHelper.result(implementation.printXReport(type)));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@PluginMethod
|
|
126
|
+
public void GetDepartments(PluginCall call) {
|
|
127
|
+
JSArray depts = new JSArray();
|
|
128
|
+
try {
|
|
129
|
+
for (int i = 1; i < 9; i++) { // 1-8
|
|
130
|
+
String deptResponse = implementation.huginPrinter.GetDepartment(i);
|
|
131
|
+
String[] parts = printResponse(deptResponse);
|
|
132
|
+
|
|
133
|
+
if (parts.length >= 6) {
|
|
134
|
+
JSObject dept = new JSObject();
|
|
135
|
+
dept.put("name", parts[2]);
|
|
136
|
+
dept.put("vatId", Integer.parseInt(parts[3]));
|
|
137
|
+
dept.put("price", parts[4]);
|
|
138
|
+
dept.put("weighable", Integer.parseInt(parts[5]));
|
|
139
|
+
depts.put(dept);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
JSObject result = new JSObject();
|
|
144
|
+
result.put("departments", depts);
|
|
145
|
+
result.put("result", true);
|
|
146
|
+
call.resolve(result);
|
|
147
|
+
|
|
148
|
+
} catch (Exception e) {
|
|
149
|
+
call.reject("Departmanlar alınamadı", e);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@PluginMethod
|
|
154
|
+
public void GetVatRates(PluginCall call) {
|
|
155
|
+
JSArray vatRates = new JSArray();
|
|
156
|
+
try {
|
|
157
|
+
for (int i = 0; i < 9; i++) { // 0'dan 8'e
|
|
158
|
+
String vatResponse = implementation.huginPrinter.GetVATRate(i);
|
|
159
|
+
String[] responseParts = CapacitorHuginGMP3.printResponse(vatResponse);
|
|
160
|
+
if (responseParts.length >= 3) {
|
|
161
|
+
vatRates.put(responseParts[2]); // 3. parça: KDV oranı
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
JSObject result = new JSObject();
|
|
165
|
+
result.put("vatRates", vatRates);
|
|
166
|
+
result.put("result", true);
|
|
167
|
+
call.resolve(result);
|
|
168
|
+
} catch (Exception e) {
|
|
169
|
+
call.reject("KDV oranları alınamadı", e);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
@PluginMethod
|
|
175
|
+
public void SetDepartment(PluginCall call) {
|
|
176
|
+
Integer idValue = call.getInt("id");
|
|
177
|
+
String name = call.getString("name");
|
|
178
|
+
Integer vatIdValue = call.getInt("vatId");
|
|
179
|
+
Double priceValue = call.getDouble("price");
|
|
180
|
+
Integer weighableValue = call.getInt("weighable");
|
|
181
|
+
|
|
182
|
+
// Null kontrol
|
|
183
|
+
if (idValue == null || name == null || vatIdValue == null || priceValue == null || weighableValue == null) {
|
|
184
|
+
call.reject("Tüm parametreler zorunludur: id, name, vatId, price, weighable.");
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
int id = idValue;
|
|
189
|
+
int vatId = vatIdValue;
|
|
190
|
+
double price = priceValue;
|
|
191
|
+
int weighable = weighableValue;
|
|
192
|
+
|
|
193
|
+
// --- Validasyon ---
|
|
194
|
+
if (id < 1 || id > 8) {
|
|
195
|
+
call.reject("Departman ID (id) 1 ile 8 arasında olmalıdır.");
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (name.length() > 20) {
|
|
200
|
+
call.reject("Departman ismi (name) 20 karakterden uzun olamaz.");
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (vatId < 1 || vatId > 8) {
|
|
205
|
+
call.reject("KDV Grup ID (vatId) 1 ile 8 arasında olmalıdır.");
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (price < 0 || price > 999999.99) {
|
|
210
|
+
call.reject("Fiyat (price) 0 ile 999.999,99 arasında olmalıdır.");
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (weighable != 0 && weighable != 1) {
|
|
215
|
+
call.reject("Tartılabilirlik (weighable) değeri 0 veya 1 olmalıdır.");
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
String vatResponse = implementation.huginPrinter.GetVATRate(vatId - 1);
|
|
220
|
+
String[] vatParts = printResponse(vatResponse);
|
|
221
|
+
|
|
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
|
+
|
|
227
|
+
try {
|
|
228
|
+
String response = implementation.huginPrinter.SetDepartment(id, name, vatId, price, weighable);
|
|
229
|
+
String[] parts = printResponse(response);
|
|
230
|
+
int errorCode = Integer.parseInt(parts[0]);
|
|
231
|
+
|
|
232
|
+
if (errorCode != 0) {
|
|
233
|
+
String message = switch (errorCode) {
|
|
234
|
+
case 71 ->
|
|
235
|
+
"Tanımsız KDV. Departmana tanımlanan KDV grubunda tanımlı bir KDV değeri bulunmamaktadır.";
|
|
236
|
+
case 92 ->
|
|
237
|
+
"Departman üzerinde satış bulunmaktadır. Bu yüzden departman değerleri değiştirilemez. Z raporu alınmalıdır.";
|
|
238
|
+
case 113 -> "Geçersiz departman numarası.";
|
|
239
|
+
case 115 -> "Geçersiz departman adı.";
|
|
240
|
+
default ->
|
|
241
|
+
"Bilinmeyen hata. Kod: " + errorCode + ". " + Utility.GetErrorMessage(errorCode);
|
|
242
|
+
};
|
|
243
|
+
call.resolve(JSObjectHelper.result(false, message));
|
|
244
|
+
} else {
|
|
245
|
+
call.resolve(JSObjectHelper.result(true, "Departman başarıyla eklendi."));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
} catch (Exception e) {
|
|
249
|
+
call.reject("Departman ayarlanamadı", e);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
@PluginMethod
|
|
254
|
+
public void SetVatRate(PluginCall call) {
|
|
255
|
+
Integer indexValue = call.getInt("index");
|
|
256
|
+
Double vatRateValue = call.getDouble("vatRate");
|
|
257
|
+
|
|
258
|
+
// --- Null Kontrol ---
|
|
259
|
+
if (indexValue == null || vatRateValue == null) {
|
|
260
|
+
call.reject("Parametreler zorunludur: index ve vatRate.");
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
int index = indexValue;
|
|
265
|
+
double vatRate = vatRateValue;
|
|
266
|
+
|
|
267
|
+
// --- Validasyon ---
|
|
268
|
+
if (index < 0 || index > 8) {
|
|
269
|
+
call.reject("index parametresi 0 ile 8 arasında olmalıdır.");
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (vatRate < 0 || vatRate > 100) {
|
|
274
|
+
call.reject("KDV oranı (vatRate) 0 ile 100 arasında olmalıdır.");
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// --- KDV Ayarlama ---
|
|
279
|
+
try {
|
|
280
|
+
String response = implementation.huginPrinter.SetVATRate(index, vatRate);
|
|
281
|
+
String[] parts = printResponse(response);
|
|
282
|
+
int errorCode = Integer.parseInt(parts[0]);
|
|
283
|
+
|
|
284
|
+
if (errorCode != 0) {
|
|
285
|
+
String message = "KDV oranı ayarlanamadı. Kod: " + errorCode + ". " + Utility.GetErrorMessage(errorCode);
|
|
286
|
+
call.resolve(JSObjectHelper.result(false, message));
|
|
287
|
+
} else {
|
|
288
|
+
call.resolve(JSObjectHelper.result(true, "KDV oranı başarıyla ayarlandı."));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
} catch (Exception e) {
|
|
292
|
+
call.reject("SetVATRate işleminde hata oluştu.", e);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package com.kerzz.hugin.gmp3;
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.JSObject;
|
|
4
|
+
|
|
5
|
+
public class JSObjectHelper {
|
|
6
|
+
|
|
7
|
+
public static JSObject result(boolean success) {
|
|
8
|
+
return result(success, success ? "Success" : "Failure");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public static JSObject result(boolean success, String message) {
|
|
12
|
+
JSObject obj = new JSObject();
|
|
13
|
+
obj.put("result", success);
|
|
14
|
+
obj.put("message", message);
|
|
15
|
+
return obj;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
}
|
|
File without changes
|