Initial draft

This commit is contained in:
Dennis Nemec
2025-09-20 16:14:06 +02:00
commit b19a6e1cd4
219 changed files with 10317 additions and 0 deletions

View File

View File

@ -0,0 +1,75 @@
import 'dart:async';
import 'package:docuframe/docuframe.dart' as df;
import 'package:hl_lieferservice/util.dart';
import 'package:flutter/cupertino.dart';
class LocalDocuFrameConfiguration {
String host;
final String user;
final String pass;
final List<String> appNames;
final String appKey;
LocalDocuFrameConfiguration(
{required this.host,
required this.appKey,
required this.appNames,
required this.pass,
required this.user});
Map<String, dynamic> toJson() {
return {
"host": host,
"user": user,
"pass": pass,
"appNames": appNames,
"appKey": appKey
};
}
factory LocalDocuFrameConfiguration.fromJson(Map<String, dynamic> json) {
return LocalDocuFrameConfiguration(
host: getValueOrThrowIfNotPresent("host", json),
appKey: getValueOrThrowIfNotPresent("appKey", json),
appNames: (getValueOrThrowIfNotPresent("appNames", json) as List)
.cast<String>(),
pass: getValueOrThrowIfNotPresent("pass", json),
user: getValueOrThrowIfNotPresent("user", json));
}
}
class ErpFrameService {
ErpFrameService({required this.config});
final LocalDocuFrameConfiguration config;
df.DocuFrameConfiguration get dfConfig {
df.DocuFrameConfiguration dfConfig =
df.DocuFrameConfiguration(url: config.host, appkey: config.appKey);
return dfConfig;
}
Future<df.LoginSession> getSession() async {
df.LoginV1 request = df.LoginV1(config: dfConfig);
df.LoginSession session =
await request.authorize(config.user, config.pass, config.appNames);
debugPrint("LOGIN WITH SESSION ID ${session.sessionId}");
return session;
}
Future<void> logout(df.LoginSession? session) async {
if (session != null) {
try {
await df.Logout(config: dfConfig, session: session).logout();
} catch (e, st) {
debugPrint("Logout failed");
debugPrint(e.toString());
debugPrint(st.toString());
}
debugPrint("Logged out with session ID: ${session.sessionId}");
}
}
}

View File

@ -0,0 +1,109 @@
import 'dart:convert';
import 'package:hl_lieferservice/services/erpframe.dart';
import 'package:docuframe/docuframe.dart' as df;
import 'package:flutter/cupertino.dart';
import '../dto/basic_response.dart';
import '../dto/scan.dart';
import '../dto/scan_response.dart';
class ScanService extends ErpFrameService {
ScanService({required super.config});
Future<void> scanArticle(String internalId) async {
df.LoginSession? session;
try {
session = await getSession();
df.DocuFrameMacroResponse response =
await df.Macro(config: dfConfig, session: session).execute(
"_web_scanArticle",
parameter: ScanDTO(internalId: internalId).toJson()
as Map<String, dynamic>);
Map<String, dynamic> responseJson = jsonDecode(response.body!);
ScanResponseDTO responseDto = ScanResponseDTO.fromJson(responseJson);
if (responseDto.succeeded == true) {
return;
} else {
throw responseDto.message;
}
} on df.DocuFrameException catch (e, st) {
debugPrint("ERROR WHILE SCANNING ARTICLE $internalId");
debugPrint(e.toString());
debugPrint(st.toString());
rethrow;
} finally {
await logout(session);
}
}
Future<String?> unscanArticle(
String internalId, int amount, String reason) async {
df.LoginSession? session;
debugPrint("AMOUNT: $amount");
debugPrint("ID: $internalId");
try {
session = await getSession();
df.DocuFrameMacroResponse response =
await df.Macro(config: dfConfig, session: session)
.execute("_web_unscanArticle", parameter: {
"article_id": internalId,
"amount": amount.toString(),
"reason": reason
});
Map<String, dynamic> responseJson = jsonDecode(response.body!);
debugPrint(responseJson.toString());
ScanResponseDTO responseDto = ScanResponseDTO.fromJson(responseJson);
if (responseDto.succeeded == true) {
return responseDto.noteId;
} else {
throw responseDto.message;
}
} catch (e, st) {
debugPrint("ERROR WHILE REVERTING THE SCAN OF ARTICLE $internalId");
debugPrint(e.toString());
debugPrint(st.toString());
rethrow;
} finally {
await logout(session);
}
}
Future<void> resetScannedArticleAmount(String receiptRowId) async {
df.LoginSession? session;
try {
session = await getSession();
df.DocuFrameMacroResponse response =
await df.Macro(config: dfConfig, session: session).execute(
"_web_unscanArticleReset",
parameter: {"receipt_row_id": receiptRowId});
Map<String, dynamic> responseJson = jsonDecode(response.body!);
BasicResponseDTO responseDto = BasicResponseDTO.fromJson(responseJson);
if (responseDto.succeeded == true) {
return;
} else {
throw responseDto.message;
}
} catch (e, st) {
debugPrint("ERROR WHILE REVERTING THE UNSCAN OF ARTICLE $receiptRowId");
debugPrint(e.toString());
debugPrint(st.toString());
rethrow;
} finally {
await logout(session);
}
}
}