Implemented new set article mechanism for unscannable articles
This commit is contained in:
@ -5,7 +5,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/bloc/tour_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/bloc/tour_state.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/model/sorting_information.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/repository/tour_repository.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/repository/tour_repository.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/service/distance_service.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/service/reorder_service.dart';
|
||||
import 'package:hl_lieferservice/model/tour.dart';
|
||||
@ -55,6 +55,7 @@ class TourBloc extends Bloc<TourEvent, TourState> {
|
||||
on<RequestSortingInformationEvent>(_requestSortingInformation);
|
||||
on<ReorderDeliveryEvent>(_reorderDelivery);
|
||||
on<CarsLoadedEvent>(_carsLoaded);
|
||||
on<SetArticleAmountEvent>(_setArticleAmount);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -64,6 +65,33 @@ class TourBloc extends Bloc<TourEvent, TourState> {
|
||||
return super.close();
|
||||
}
|
||||
|
||||
void _setArticleAmount(
|
||||
SetArticleAmountEvent event,
|
||||
Emitter<TourState> emit,
|
||||
) async {
|
||||
final currentState = state;
|
||||
if (currentState is TourLoaded) {
|
||||
opBloc.add(LoadOperation());
|
||||
try {
|
||||
await tourRepository.setArticleAmount(
|
||||
event.deliveryId,
|
||||
event.articleId,
|
||||
event.amount,
|
||||
event.reason
|
||||
);
|
||||
|
||||
opBloc.add(FinishOperation());
|
||||
} catch (e, st) {
|
||||
opBloc.add(
|
||||
FailOperation(message: "Fehler beim Ändern der Menge des Artikels"),
|
||||
);
|
||||
|
||||
debugPrint("$e");
|
||||
debugPrint("$st");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _carsLoaded(CarsLoadedEvent event, Emitter<TourState> emit) {
|
||||
final currentState = state;
|
||||
if (currentState is TourLoaded) {
|
||||
@ -78,13 +106,16 @@ class TourBloc extends Bloc<TourEvent, TourState> {
|
||||
) async {
|
||||
final currentState = state;
|
||||
if (currentState is TourLoaded) {
|
||||
int newPosition = event.newPosition == currentState.sortingInformation.sorting.length ? event.newPosition - 1 : event.newPosition;
|
||||
SortingInformation informationOld = currentState.sortingInformation.sorting
|
||||
.firstWhere((info) => info.position == event.oldPosition);
|
||||
|
||||
SortingInformation information = currentState
|
||||
int newPosition =
|
||||
event.newPosition == currentState.sortingInformation.sorting.length
|
||||
? event.newPosition - 1
|
||||
: event.newPosition;
|
||||
SortingInformation informationOld = currentState
|
||||
.sortingInformation
|
||||
.sorting
|
||||
.firstWhere((info) => info.position == event.oldPosition);
|
||||
|
||||
SortingInformation information = currentState.sortingInformation.sorting
|
||||
.firstWhere((info) => info.position == newPosition);
|
||||
|
||||
information.position = event.oldPosition;
|
||||
|
||||
@ -203,3 +203,17 @@ class FinishDeliveryEvent extends TourEvent {
|
||||
Uint8List customerSignature;
|
||||
Uint8List driverSignature;
|
||||
}
|
||||
|
||||
class SetArticleAmountEvent extends TourEvent {
|
||||
final String deliveryId;
|
||||
final String articleId;
|
||||
final String? reason;
|
||||
final int amount;
|
||||
|
||||
SetArticleAmountEvent({
|
||||
required this.deliveryId,
|
||||
required this.articleId,
|
||||
required this.amount,
|
||||
this.reason,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user