Implemented new set article mechanism for unscannable articles
This commit is contained in:
@ -60,7 +60,7 @@ class _DeliveryListState extends State<DeliveryList> {
|
||||
.where(
|
||||
(delivery) =>
|
||||
delivery.carId == widget.selectedCarId &&
|
||||
delivery.allArticlesScanned(),
|
||||
delivery.allArticlesScanned() || delivery.state == DeliveryState.finished,
|
||||
)
|
||||
.toList();
|
||||
|
||||
|
||||
@ -1,351 +0,0 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/service/delivery_info_service.dart';
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
import 'package:hl_lieferservice/model/tour.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
import '../../../../dto/discount_add_response.dart';
|
||||
import '../../../../dto/discount_remove_response.dart';
|
||||
import '../../../../dto/discount_update_response.dart';
|
||||
import '../../../../model/article.dart';
|
||||
import '../../detail/repository/note_repository.dart';
|
||||
import '../../detail/service/notes_service.dart';
|
||||
|
||||
enum ScanResult { scanned, alreadyScanned, notFound }
|
||||
|
||||
class TourNotFoundException implements Exception {}
|
||||
|
||||
class TourRepository {
|
||||
TourService service;
|
||||
|
||||
final _tourStream = BehaviorSubject<Tour?>();
|
||||
final _paymentOptionsStream = BehaviorSubject<List<Payment>>.seeded([]);
|
||||
|
||||
Stream<Tour?> get tour => _tourStream.stream;
|
||||
|
||||
Stream<List<Payment>> get paymentOptions => _paymentOptionsStream.stream;
|
||||
|
||||
TourRepository({required this.service});
|
||||
|
||||
Future<void> loadTourOfToday(String userId) async {
|
||||
_tourStream.add(await service.getTourOfToday(userId));
|
||||
}
|
||||
|
||||
Future<void> loadPaymentOptions() async {
|
||||
_paymentOptionsStream.add(
|
||||
(await service.getPaymentMethods())
|
||||
.map((option) => Payment.fromDTO(option))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> assignCar(String deliveryId, String carId) async {
|
||||
await service.assignCar(deliveryId, carId);
|
||||
|
||||
final tour = _tourStream.value!;
|
||||
final index = tour.deliveries.indexWhere(
|
||||
(delivery) => delivery.id == deliveryId,
|
||||
);
|
||||
tour.deliveries[index].carId = int.parse(carId);
|
||||
|
||||
_tourStream.add(tour);
|
||||
}
|
||||
|
||||
Future<ScanResult> scanArticle(
|
||||
String deliveryId,
|
||||
String carId,
|
||||
String articleNumber,
|
||||
) async {
|
||||
if (!_tourStream.hasValue) {
|
||||
throw TourNotFoundException();
|
||||
}
|
||||
|
||||
final tour = _tourStream.value!;
|
||||
|
||||
if (tour.deliveries.any(
|
||||
(delivery) => delivery.articles.any(
|
||||
(article) => article.articleNumber == articleNumber,
|
||||
),
|
||||
)) {
|
||||
var delivery = tour.deliveries.firstWhere(
|
||||
(delivery) => delivery.id == deliveryId,
|
||||
);
|
||||
var article = delivery.articles.firstWhere(
|
||||
(article) => article.articleNumber == articleNumber,
|
||||
);
|
||||
|
||||
await service.scanArticle(article.internalId.toString());
|
||||
|
||||
if (article.scannedAmount < article.amount) {
|
||||
article.scannedAmount += 1;
|
||||
_tourStream.add(tour);
|
||||
return ScanResult.scanned;
|
||||
} else {
|
||||
return ScanResult.alreadyScanned;
|
||||
}
|
||||
} else {
|
||||
return ScanResult.notFound;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> unscan(
|
||||
String deliveryId,
|
||||
String articleId,
|
||||
int newAmount,
|
||||
String reason,
|
||||
) async {
|
||||
if (!_tourStream.hasValue) {
|
||||
throw TourNotFoundException();
|
||||
}
|
||||
|
||||
Tour tour = _tourStream.value!;
|
||||
String? noteId = await service.unscanArticle(articleId, newAmount, reason);
|
||||
Article article = tour.deliveries
|
||||
.firstWhere((delivery) => delivery.id == deliveryId)
|
||||
.articles
|
||||
.firstWhere((article) => article.internalId == int.parse(articleId));
|
||||
|
||||
article.removeNoteId = noteId;
|
||||
article.scannedRemovedAmount += newAmount;
|
||||
article.scannedAmount -= newAmount;
|
||||
|
||||
_tourStream.add(tour);
|
||||
}
|
||||
|
||||
Future<void> resetScan(String articleId, String deliveryId) async {
|
||||
if (!_tourStream.hasValue) {
|
||||
throw TourNotFoundException();
|
||||
}
|
||||
|
||||
Tour tour = _tourStream.value!;
|
||||
await service.resetScannedArticleAmount(articleId);
|
||||
|
||||
Article article = tour.deliveries
|
||||
.firstWhere((delivery) => delivery.id == deliveryId)
|
||||
.articles
|
||||
.firstWhere((article) => article.internalId == int.parse(articleId));
|
||||
|
||||
article.removeNoteId = null;
|
||||
article.scannedRemovedAmount = 0;
|
||||
article.scannedAmount = article.amount;
|
||||
|
||||
_tourStream.add(tour);
|
||||
}
|
||||
|
||||
Future<void> uploadDriverSignature(
|
||||
String deliveryId,
|
||||
Uint8List signature,
|
||||
) async {
|
||||
NoteRepository noteRepository = NoteRepository(service: NoteService());
|
||||
await noteRepository.addNamedImage(
|
||||
deliveryId,
|
||||
signature,
|
||||
"delivery_${deliveryId}_signature_driver.jpg",
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> uploadCustomerSignature(
|
||||
String deliveryId,
|
||||
Uint8List signature,
|
||||
) async {
|
||||
NoteRepository noteRepository = NoteRepository(service: NoteService());
|
||||
await noteRepository.addNamedImage(
|
||||
deliveryId,
|
||||
signature,
|
||||
"delivery_${deliveryId}_signature_customer.jpg",
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> addDiscount(String deliveryId, String reason, int value) async {
|
||||
if (!_tourStream.hasValue) {
|
||||
throw TourNotFoundException();
|
||||
}
|
||||
|
||||
Tour tour = _tourStream.value!;
|
||||
DiscountAddResponseDTO response = await service.addDiscount(
|
||||
deliveryId,
|
||||
value,
|
||||
reason,
|
||||
);
|
||||
|
||||
Delivery delivery = tour.deliveries.firstWhere(
|
||||
(delivery) => delivery.id == deliveryId,
|
||||
);
|
||||
delivery.totalNetValue = response.values.receipt.net;
|
||||
delivery.totalGrossValue = response.values.receipt.gross;
|
||||
delivery.discount = Discount(
|
||||
article: Article.fromDTO(response.values.article),
|
||||
note: response.values.note.noteDescription,
|
||||
noteId: response.values.note.rowId,
|
||||
);
|
||||
|
||||
_tourStream.add(tour);
|
||||
}
|
||||
|
||||
Future<void> removeDiscount(String deliveryId) async {
|
||||
if (!_tourStream.hasValue) {
|
||||
throw TourNotFoundException();
|
||||
}
|
||||
|
||||
Tour tour = _tourStream.value!;
|
||||
DiscountRemoveResponseDTO response = await service.removeDiscount(
|
||||
deliveryId,
|
||||
);
|
||||
|
||||
Delivery delivery = tour.deliveries.firstWhere(
|
||||
(delivery) => delivery.id == deliveryId,
|
||||
);
|
||||
delivery.articles =
|
||||
delivery.articles
|
||||
.where(
|
||||
(article) =>
|
||||
article.internalId != delivery.discount?.article.internalId,
|
||||
)
|
||||
.toList();
|
||||
|
||||
delivery.discount = null;
|
||||
delivery.totalGrossValue = response.receipt.gross;
|
||||
delivery.totalNetValue = response.receipt.net;
|
||||
|
||||
_tourStream.add(tour);
|
||||
}
|
||||
|
||||
Future<void> updateDiscount(
|
||||
String deliveryId,
|
||||
String? reason,
|
||||
int? value,
|
||||
) async {
|
||||
if (!_tourStream.hasValue) {
|
||||
throw TourNotFoundException();
|
||||
}
|
||||
|
||||
Tour tour = _tourStream.value!;
|
||||
DiscountUpdateResponseDTO response = await service.updateDiscount(
|
||||
deliveryId,
|
||||
reason,
|
||||
value,
|
||||
);
|
||||
|
||||
Delivery delivery = tour.deliveries.firstWhere(
|
||||
(delivery) => delivery.id == deliveryId,
|
||||
);
|
||||
if (response.values?.receipt != null) {
|
||||
delivery.totalNetValue = response.values!.receipt.net;
|
||||
delivery.totalGrossValue = response.values!.receipt.gross;
|
||||
}
|
||||
|
||||
String discountArticleNumber = delivery.discount!.article.articleNumber;
|
||||
delivery.discount = Discount(
|
||||
article:
|
||||
response.values?.article != null
|
||||
? Article.fromDTO(response.values!.article)
|
||||
: delivery.discount!.article,
|
||||
note:
|
||||
response.values?.note != null
|
||||
? response.values!.note.noteDescription
|
||||
: delivery.discount!.note,
|
||||
noteId:
|
||||
response.values?.note != null
|
||||
? response.values!.note.rowId
|
||||
: delivery.discount!.noteId,
|
||||
);
|
||||
|
||||
delivery.articles = [
|
||||
...delivery.articles.where(
|
||||
(article) => article.articleNumber != discountArticleNumber,
|
||||
),
|
||||
delivery.discount!.article,
|
||||
];
|
||||
|
||||
_tourStream.add(tour);
|
||||
}
|
||||
|
||||
Future<void> reactivateDelivery(String deliveryId) async {
|
||||
await _changeState(deliveryId, DeliveryState.ongoing);
|
||||
}
|
||||
|
||||
Future<void> holdDelivery(String deliveryId) async {
|
||||
await _changeState(deliveryId, DeliveryState.onhold);
|
||||
}
|
||||
|
||||
Future<void> cancelDelivery(String deliveryId) async {
|
||||
await _changeState(deliveryId, DeliveryState.canceled);
|
||||
}
|
||||
|
||||
Future<void> finishDelivery(String deliveryId) async {
|
||||
await _changeState(deliveryId, DeliveryState.finished);
|
||||
}
|
||||
|
||||
Future<void> _changeState(String deliveryId, DeliveryState state) async {
|
||||
if (!_tourStream.hasValue) {
|
||||
throw TourNotFoundException();
|
||||
}
|
||||
|
||||
Tour tour = _tourStream.value!;
|
||||
Delivery delivery = tour.deliveries.firstWhere(
|
||||
(delivery) => delivery.id == deliveryId,
|
||||
);
|
||||
|
||||
delivery.state = state;
|
||||
await _updateDelivery(delivery);
|
||||
|
||||
_tourStream.add(tour);
|
||||
}
|
||||
|
||||
Future<void> _updateDelivery(Delivery newDelivery) async {
|
||||
if (!_tourStream.hasValue) {
|
||||
throw TourNotFoundException();
|
||||
}
|
||||
|
||||
await service.updateDelivery(newDelivery);
|
||||
}
|
||||
|
||||
Future<void> updatePayment(String deliveryId, Payment payment) async {
|
||||
if (!_tourStream.hasValue) {
|
||||
throw TourNotFoundException();
|
||||
}
|
||||
|
||||
Tour tour = _tourStream.value!;
|
||||
Delivery delivery = tour.deliveries.firstWhere(
|
||||
(delivery) => delivery.id == deliveryId,
|
||||
);
|
||||
|
||||
delivery.payment = payment;
|
||||
await _updateDelivery(delivery);
|
||||
|
||||
_tourStream.add(tour);
|
||||
}
|
||||
|
||||
Future<void> updateOption(
|
||||
String deliveryId,
|
||||
String key,
|
||||
dynamic value,
|
||||
) async {
|
||||
if (!_tourStream.hasValue) {
|
||||
throw TourNotFoundException();
|
||||
}
|
||||
|
||||
Tour tour = _tourStream.value!;
|
||||
Delivery delivery = tour.deliveries.firstWhere(
|
||||
(delivery) => delivery.id == deliveryId,
|
||||
);
|
||||
|
||||
delivery.options =
|
||||
delivery.options.map((option) {
|
||||
if (option.key == key) {
|
||||
if (option.numerical) {
|
||||
return option.copyWith(value: value);
|
||||
} else {
|
||||
return option.copyWith(value: value == true ? "1" : "0");
|
||||
}
|
||||
}
|
||||
|
||||
return option;
|
||||
}).toList();
|
||||
|
||||
await _updateDelivery(delivery);
|
||||
|
||||
_tourStream.add(tour);
|
||||
}
|
||||
}
|
||||
@ -1,352 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hl_lieferservice/dto/delivery_response.dart';
|
||||
import 'package:hl_lieferservice/dto/delivery_update.dart';
|
||||
import 'package:hl_lieferservice/dto/delivery_update_response.dart';
|
||||
import 'package:hl_lieferservice/dto/payment.dart';
|
||||
import 'package:hl_lieferservice/dto/payments.dart';
|
||||
import 'package:hl_lieferservice/model/car.dart';
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
import 'package:hl_lieferservice/model/tour.dart';
|
||||
import 'package:hl_lieferservice/util.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 TourService {
|
||||
TourService();
|
||||
|
||||
Future<void> updateDelivery(Delivery delivery) async {
|
||||
try {
|
||||
var headers = {"Content-Type": "application/json"};
|
||||
headers.addAll(getSessionOrThrow());
|
||||
|
||||
debugPrint(getSessionOrThrow().toString());
|
||||
debugPrint(delivery.state.toString());
|
||||
debugPrint(jsonEncode(DeliveryUpdateDTO.fromEntity(delivery).toJson()));
|
||||
|
||||
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);
|
||||
|
||||
if (responseDto.code == "200") {
|
||||
return;
|
||||
}
|
||||
|
||||
debugPrint("ERROR UPDATING:");
|
||||
debugPrint(responseDto.message);
|
||||
} catch (e, st) {
|
||||
debugPrint("ERROR WHILE UPDATING DELIVERY");
|
||||
debugPrint("$e");
|
||||
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);
|
||||
} catch (e, st) {
|
||||
debugPrint("ERROR WHILE UPDATING DELIVERY");
|
||||
debugPrint("$e");
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
/// List all available deliveries for today.
|
||||
|
||||
Future<Tour> getTourOfToday(String userId) async {
|
||||
try {
|
||||
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(
|
||||
jsonDecode(response.body),
|
||||
);
|
||||
|
||||
return Tour(
|
||||
discountArticleNumber: responseDto.discountArticleNumber,
|
||||
date: DateTime.now(),
|
||||
deliveries: responseDto.deliveries.map(Delivery.fromDTO).toList(),
|
||||
paymentMethods: [],
|
||||
driver: Driver(
|
||||
cars:
|
||||
responseDto.driver.cars
|
||||
.map(
|
||||
(carDto) =>
|
||||
Car(id: int.parse(carDto.id), plate: carDto.plate),
|
||||
)
|
||||
.toList(),
|
||||
teamNumber: int.parse(responseDto.driver.id),
|
||||
name: responseDto.driver.name,
|
||||
salutation: responseDto.driver.salutation,
|
||||
),
|
||||
);
|
||||
} catch (e, stacktrace) {
|
||||
debugPrint(e.toString());
|
||||
debugPrint(stacktrace.toString());
|
||||
debugPrint("RANDOM EXCEPTION!");
|
||||
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<PaymentMethodDTO>> getPaymentMethods() async {
|
||||
try {
|
||||
var response = await post(
|
||||
urlBuilder("_web_getPaymentMethods"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {},
|
||||
);
|
||||
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
PaymentMethodListDTO responseDto = PaymentMethodListDTO.fromJson(
|
||||
responseJson,
|
||||
);
|
||||
|
||||
return responseDto.paymentMethods;
|
||||
} catch (e, st) {
|
||||
debugPrint("ERROR while retrieving allowed payment methods");
|
||||
debugPrint(e.toString());
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> unscanArticle(
|
||||
String internalId,
|
||||
int amount,
|
||||
String reason,
|
||||
) async {
|
||||
try {
|
||||
var response = await post(
|
||||
urlBuilder("_web_unscanArticle"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {
|
||||
"article_id": internalId,
|
||||
"amount": amount.toString(),
|
||||
"reason": reason,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> resetScannedArticleAmount(String receiptRowId) async {
|
||||
try {
|
||||
var response = await post(
|
||||
urlBuilder("_web_unscanArticleReset"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {"receipt_row_id": receiptRowId},
|
||||
);
|
||||
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Future<DiscountAddResponseDTO> addDiscount(
|
||||
String deliveryId,
|
||||
int discount,
|
||||
String note,
|
||||
) async {
|
||||
try {
|
||||
var response = await post(
|
||||
urlBuilder("_web_addDiscount"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {
|
||||
"delivery_id": deliveryId,
|
||||
"discount": discount.toString(),
|
||||
"note": note,
|
||||
},
|
||||
);
|
||||
|
||||
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);
|
||||
} catch (e, st) {
|
||||
debugPrint("ERROR while adding discount");
|
||||
debugPrint(e.toString());
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<DiscountRemoveResponseDTO> removeDiscount(String deliveryId) async {
|
||||
try {
|
||||
var response = await post(
|
||||
urlBuilder("_web_removeDiscount"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {"delivery_id": deliveryId},
|
||||
);
|
||||
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
|
||||
// let it throw, if the values are invalid
|
||||
return DiscountRemoveResponseDTO.fromJson(responseJson);
|
||||
} catch (e, st) {
|
||||
debugPrint("ERROR while removing discount");
|
||||
debugPrint(e.toString());
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<DiscountUpdateResponseDTO> updateDiscount(
|
||||
String deliveryId,
|
||||
String? note,
|
||||
int? discount,
|
||||
) async {
|
||||
try {
|
||||
var response = await post(
|
||||
urlBuilder("_web_updateDiscount"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {"delivery_id": deliveryId, "discount": discount, "note": note},
|
||||
);
|
||||
|
||||
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);
|
||||
} catch (e, st) {
|
||||
debugPrint("ERROR while retrieving allowed payment methods");
|
||||
debugPrint(e.toString());
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
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