Implemented settings, new scan, enhanced UI/UX
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:docuframe/docuframe.dart' as df;
|
||||
import 'package:flutter/material.dart';
|
||||
@ -13,30 +14,41 @@ import 'package:hl_lieferservice/model/delivery.dart';
|
||||
import 'package:hl_lieferservice/model/tour.dart';
|
||||
import 'package:hl_lieferservice/util.dart';
|
||||
import 'package:hl_lieferservice/services/erpframe.dart';
|
||||
import 'package:http/http.dart';
|
||||
|
||||
import '../../../../dto/basic_response.dart';
|
||||
import '../../../../dto/discount_add_response.dart';
|
||||
import '../../../../dto/discount_remove_response.dart';
|
||||
import '../../../../dto/discount_update_response.dart';
|
||||
import '../../../../dto/scan_response.dart';
|
||||
import '../../../authentication/exceptions.dart';
|
||||
|
||||
class DeliveryInfoService extends ErpFrameService {
|
||||
DeliveryInfoService({required super.config});
|
||||
|
||||
Future<void> updateDelivery(Delivery delivery) async {
|
||||
df.LoginSession? session;
|
||||
|
||||
try {
|
||||
session = await getSession();
|
||||
df.DocuFrameMacroResponse response =
|
||||
await df.Macro(config: dfConfig, session: session).execute(
|
||||
"_web_updateDelivery",
|
||||
parameter: DeliveryUpdateDTO.fromEntity(delivery).toJson()
|
||||
as Map<String, dynamic>);
|
||||
var headers = {
|
||||
"Content-Type": "application/json"
|
||||
};
|
||||
headers.addAll(getSessionOrThrow());
|
||||
|
||||
df.Logout(config: dfConfig, session: session).logout();
|
||||
debugPrint(getSessionOrThrow().toString());
|
||||
debugPrint(jsonEncode(DeliveryUpdateDTO.fromEntity(delivery).toJson()));
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
|
||||
var response = await post(
|
||||
urlBuilder("_web_updateDelivery"),
|
||||
headers: headers,
|
||||
body: jsonEncode(DeliveryUpdateDTO.fromEntity(delivery).toJson()),
|
||||
);
|
||||
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
debugPrint("BODY: ${response.body}");
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
DeliveryUpdateResponseDTO responseDto =
|
||||
DeliveryUpdateResponseDTO.fromJson(responseJson);
|
||||
|
||||
@ -44,7 +56,45 @@ class DeliveryInfoService extends ErpFrameService {
|
||||
return;
|
||||
}
|
||||
|
||||
throw responseDto.message;
|
||||
debugPrint("ERROR UPDATING:");
|
||||
debugPrint(responseDto.message);
|
||||
} on df.DocuFrameException catch (e, st) {
|
||||
debugPrint("ERROR WHILE UPDATING DELIVERY");
|
||||
debugPrint(e.errorMessage);
|
||||
debugPrint(e.errorCode);
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> assignCar(String deliveryId, String carId) async {
|
||||
try {
|
||||
var headers = {
|
||||
"Content-Type": "application/json"
|
||||
};
|
||||
headers.addAll(getSessionOrThrow());
|
||||
|
||||
var response = await post(
|
||||
urlBuilder("_web_updateDelivery"),
|
||||
headers: headers,
|
||||
body: jsonEncode({"delivery_id": deliveryId, "car_id": carId}),
|
||||
);
|
||||
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
DeliveryUpdateResponseDTO responseDto =
|
||||
DeliveryUpdateResponseDTO.fromJson(responseJson);
|
||||
|
||||
if (responseDto.code == "200") {
|
||||
return;
|
||||
}
|
||||
|
||||
debugPrint("ERROR UPDATING:");
|
||||
debugPrint(responseDto.message);
|
||||
} on df.DocuFrameException catch (e, st) {
|
||||
debugPrint("ERROR WHILE UPDATING DELIVERY");
|
||||
debugPrint(e.errorMessage);
|
||||
@ -52,27 +102,25 @@ class DeliveryInfoService extends ErpFrameService {
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
} finally {
|
||||
await logout(session);
|
||||
}
|
||||
}
|
||||
|
||||
/// List all available deliveries for today.
|
||||
|
||||
Future<Tour?> getTourOfToday(String userId) async {
|
||||
df.LoginSession? session;
|
||||
|
||||
try {
|
||||
session = await getSession();
|
||||
df.DocuFrameMacroResponse response =
|
||||
await df.Macro(config: dfConfig, session: session).execute(
|
||||
"_web_getDeliveries",
|
||||
parameter: {"driver_id": userId, "date": getTodayDate()});
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
var response = await post(
|
||||
urlBuilder("_web_getDeliveries"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {"driver_id": userId, "date": getTodayDate()},
|
||||
);
|
||||
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
DeliveryResponseDTO responseDto =
|
||||
DeliveryResponseDTO.fromJson(responseJson);
|
||||
DeliveryResponseDTO.fromJson(jsonDecode(response.body));
|
||||
|
||||
return Tour(
|
||||
discountArticleNumber: responseDto.discountArticleNumber,
|
||||
@ -93,21 +141,22 @@ class DeliveryInfoService extends ErpFrameService {
|
||||
debugPrint("RANDOM EXCEPTION!");
|
||||
|
||||
rethrow;
|
||||
} finally {
|
||||
await logout(session);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<PaymentMethodDTO>> getPaymentMethods() async {
|
||||
df.LoginSession? session;
|
||||
|
||||
try {
|
||||
session = await getSession();
|
||||
df.DocuFrameMacroResponse response =
|
||||
await df.Macro(config: dfConfig, session: session)
|
||||
.execute("_web_getPaymentMethods", parameter: {});
|
||||
var response = await post(
|
||||
urlBuilder("_web_getPaymentMethods"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {},
|
||||
);
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
PaymentMethodListDTO responseDto =
|
||||
PaymentMethodListDTO.fromJson(responseJson);
|
||||
|
||||
@ -118,30 +167,27 @@ class DeliveryInfoService extends ErpFrameService {
|
||||
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
|
||||
});
|
||||
var response = await post(
|
||||
urlBuilder("_web_unscanArticle"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {
|
||||
"article_id": internalId,
|
||||
"amount": amount.toString(),
|
||||
"reason": reason
|
||||
},
|
||||
);
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
debugPrint(responseJson.toString());
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
ScanResponseDTO responseDto = ScanResponseDTO.fromJson(responseJson);
|
||||
|
||||
if (responseDto.succeeded == true) {
|
||||
@ -155,22 +201,22 @@ class DeliveryInfoService extends ErpFrameService {
|
||||
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});
|
||||
var response = await post(
|
||||
urlBuilder("_web_unscanArticleReset"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {"receipt_row_id": receiptRowId},
|
||||
);
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
BasicResponseDTO responseDto = BasicResponseDTO.fromJson(responseJson);
|
||||
|
||||
if (responseDto.succeeded == true) {
|
||||
@ -184,27 +230,27 @@ class DeliveryInfoService extends ErpFrameService {
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
} finally {
|
||||
await logout(session);
|
||||
}
|
||||
}
|
||||
|
||||
Future<DiscountAddResponseDTO> addDiscount(
|
||||
String deliveryId, int discount, String note) async {
|
||||
df.LoginSession? session;
|
||||
|
||||
try {
|
||||
session = await getSession();
|
||||
df.DocuFrameMacroResponse response =
|
||||
await df.Macro(config: dfConfig, session: session)
|
||||
.execute("_web_addDiscount", parameter: {
|
||||
"delivery_id": deliveryId,
|
||||
"discount": discount.toString(),
|
||||
"note": note
|
||||
});
|
||||
var response = await post(
|
||||
urlBuilder("_web_addDiscount"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {
|
||||
"delivery_id": deliveryId,
|
||||
"discount": discount.toString(),
|
||||
"note": note
|
||||
},
|
||||
);
|
||||
|
||||
debugPrint("BODY: ${response.body!}");
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
|
||||
// let it throw, if the values are invalid
|
||||
return DiscountAddResponseDTO.fromJson(responseJson);
|
||||
@ -214,25 +260,24 @@ class DeliveryInfoService extends ErpFrameService {
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
} finally {
|
||||
await logout(session);
|
||||
}
|
||||
}
|
||||
|
||||
Future<DiscountRemoveResponseDTO> removeDiscount(String deliveryId) async {
|
||||
df.LoginSession? session;
|
||||
|
||||
try {
|
||||
session = await getSession();
|
||||
df.DocuFrameMacroResponse response =
|
||||
await df.Macro(config: dfConfig, session: session)
|
||||
.execute("_web_removeDiscount", parameter: {
|
||||
"delivery_id": deliveryId,
|
||||
});
|
||||
var response = await post(
|
||||
urlBuilder("_web_removeDiscount"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {
|
||||
"delivery_id": deliveryId,
|
||||
},
|
||||
);
|
||||
|
||||
debugPrint("${response.body!}");
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
|
||||
// let it throw, if the values are invalid
|
||||
return DiscountRemoveResponseDTO.fromJson(responseJson);
|
||||
@ -242,26 +287,27 @@ class DeliveryInfoService extends ErpFrameService {
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
} finally {
|
||||
await logout(session);
|
||||
}
|
||||
}
|
||||
|
||||
Future<DiscountUpdateResponseDTO> updateDiscount(
|
||||
String deliveryId, String? note, int? discount) async {
|
||||
df.LoginSession? session;
|
||||
|
||||
try {
|
||||
session = await getSession();
|
||||
df.DocuFrameMacroResponse response =
|
||||
await df.Macro(config: dfConfig, session: session)
|
||||
.execute("_web_updateDiscount", parameter: {
|
||||
"delivery_id": deliveryId,
|
||||
"discount": discount,
|
||||
"note": note
|
||||
});
|
||||
var response = await post(
|
||||
urlBuilder("_web_updateDiscount"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {
|
||||
"delivery_id": deliveryId,
|
||||
"discount": discount,
|
||||
"note": note
|
||||
},
|
||||
);
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
|
||||
// let it throw, if the values are invalid
|
||||
return DiscountUpdateResponseDTO.fromJson(responseJson);
|
||||
@ -271,8 +317,37 @@ class DeliveryInfoService extends ErpFrameService {
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
} finally {
|
||||
await logout(session);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> scanArticle(String internalId) async {
|
||||
try {
|
||||
var response = await post(
|
||||
urlBuilder("_web_scanArticle"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {"internal_id": internalId},
|
||||
);
|
||||
|
||||
debugPrint(jsonEncode({"internal_id": internalId}));
|
||||
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
debugPrint(responseJson.toString());
|
||||
ScanResponseDTO responseDto = ScanResponseDTO.fromJson(
|
||||
responseJson,
|
||||
);
|
||||
|
||||
if (responseDto.succeeded == true) {
|
||||
return;
|
||||
} else {
|
||||
debugPrint("ERROR: ${responseDto.message}");
|
||||
throw responseDto.message;
|
||||
}
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user