Added Streams to TourRepository
This commit is contained in:
@ -1,353 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/dto/discount_add_response.dart';
|
||||
import 'package:hl_lieferservice/dto/discount_update_response.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_state.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/repository/delivery_repository.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/repository/note_repository.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_event.dart';
|
||||
|
||||
import '../../../../dto/discount_remove_response.dart';
|
||||
import '../../../../model/article.dart';
|
||||
import '../../../../model/delivery.dart' as model;
|
||||
|
||||
class DeliveryBloc extends Bloc<DeliveryEvent, DeliveryState> {
|
||||
OperationBloc opBloc;
|
||||
NoteBloc noteBloc;
|
||||
DeliveryRepository repository;
|
||||
NoteRepository noteRepository;
|
||||
|
||||
DeliveryBloc({
|
||||
required this.opBloc,
|
||||
required this.repository,
|
||||
required this.noteRepository,
|
||||
required this.noteBloc
|
||||
}) : super(DeliveryInitial()) {
|
||||
on<UnscanArticleEvent>(_unscan);
|
||||
on<ResetScanAmountEvent>(_resetAmount);
|
||||
on<LoadDeliveryEvent>(_load);
|
||||
on<AddDiscountEvent>(_addDiscount);
|
||||
on<RemoveDiscountEvent>(_removeDiscount);
|
||||
on<UpdateDiscountEvent>(_updateDiscount);
|
||||
on<UpdateDeliveryOptionEvent>(_updateDeliveryOptions);
|
||||
on<UpdateSelectedPaymentMethodEvent>(_updatePayment);
|
||||
on<FinishDeliveryEvent>(_finishDelivery);
|
||||
}
|
||||
|
||||
void _finishDelivery(FinishDeliveryEvent event,
|
||||
Emitter<DeliveryState> emit,) async {
|
||||
final currentState = state;
|
||||
opBloc.add(LoadOperation());
|
||||
|
||||
if (currentState is DeliveryLoaded) {
|
||||
try {
|
||||
model.Delivery newDelivery = event.delivery.copyWith();
|
||||
newDelivery.state = model.DeliveryState.finished;
|
||||
|
||||
for (final option in event.delivery.options) {
|
||||
debugPrint("VALUE=${option.value};KEY=${option.key}");
|
||||
}
|
||||
|
||||
await repository.updateDelivery(newDelivery);
|
||||
await noteRepository.addNamedImage(
|
||||
event.delivery.id,
|
||||
event.driverSignature,
|
||||
"delivery_${event.delivery.id}_signature_driver.jpg",
|
||||
);
|
||||
await noteRepository.addNamedImage(
|
||||
event.delivery.id,
|
||||
event.customerSignature,
|
||||
"delivery_${event.delivery.id}_signature_customer.jpg",
|
||||
);
|
||||
emit(DeliveryFinished(delivery: newDelivery));
|
||||
opBloc.add(FinishOperation());
|
||||
} catch (e, st) {
|
||||
opBloc.add(FailOperation(message: "Failed to update delivery"));
|
||||
debugPrint(st.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _updatePayment(UpdateSelectedPaymentMethodEvent event,
|
||||
Emitter<DeliveryState> emit,) {
|
||||
final currentState = state;
|
||||
|
||||
if (currentState is DeliveryLoaded) {
|
||||
emit(
|
||||
DeliveryLoaded(
|
||||
delivery: currentState.delivery.copyWith(payment: event.payment),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _updateDeliveryOptions(UpdateDeliveryOptionEvent event,
|
||||
Emitter<DeliveryState> emit,) {
|
||||
final currentState = state;
|
||||
|
||||
if (currentState is DeliveryLoaded) {
|
||||
List<model.DeliveryOption> options =
|
||||
currentState.delivery.options.map((option) {
|
||||
if (option.key == event.key) {
|
||||
if (option.numerical) {
|
||||
return option.copyWith(value: event.value);
|
||||
} else {
|
||||
return option.copyWith(value: event.value == true ? "1" : "0");
|
||||
}
|
||||
}
|
||||
|
||||
return option;
|
||||
}).toList();
|
||||
|
||||
emit(
|
||||
DeliveryLoaded(
|
||||
delivery: currentState.delivery.copyWith(options: options),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _updateDiscount(UpdateDiscountEvent event,
|
||||
Emitter<DeliveryState> emit,) async {
|
||||
opBloc.add(LoadOperation());
|
||||
|
||||
try {
|
||||
final currentState = state;
|
||||
|
||||
if (currentState is DeliveryLoaded) {
|
||||
DiscountUpdateResponseDTO response = await repository.updateDiscount(
|
||||
event.deliveryId,
|
||||
event.reason,
|
||||
event.value,
|
||||
);
|
||||
|
||||
model.Delivery delivery = currentState.delivery;
|
||||
|
||||
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 = model.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,
|
||||
];
|
||||
|
||||
emit(currentState.copyWith(delivery));
|
||||
|
||||
opBloc.add(FinishOperation());
|
||||
}
|
||||
} catch (e, st) {
|
||||
debugPrint(
|
||||
"Fehler beim Hinzufügen eins Discounts zur Lieferung: ${event
|
||||
.deliveryId}:",
|
||||
);
|
||||
debugPrint("$e");
|
||||
debugPrint("$st");
|
||||
|
||||
opBloc.add(
|
||||
FailOperation(message: "Fehler beim Hinzufügen des Discounts: $e"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _removeDiscount(RemoveDiscountEvent event,
|
||||
Emitter<DeliveryState> emit,) async {
|
||||
opBloc.add(LoadOperation());
|
||||
|
||||
try {
|
||||
final currentState = state;
|
||||
|
||||
if (currentState is DeliveryLoaded) {
|
||||
model.Delivery delivery = currentState.delivery;
|
||||
|
||||
DiscountRemoveResponseDTO response = await repository.removeDiscount(
|
||||
event.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;
|
||||
|
||||
emit(currentState.copyWith(delivery));
|
||||
|
||||
opBloc.add(FinishOperation());
|
||||
}
|
||||
} catch (e, st) {
|
||||
debugPrint(
|
||||
"Fehler beim Löschen des Discounts der Lieferung: ${event.deliveryId}:",
|
||||
);
|
||||
debugPrint("$e");
|
||||
debugPrint("$st");
|
||||
|
||||
opBloc.add(
|
||||
FailOperation(message: "Fehler beim Löschen des Discounts: $e"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _addDiscount(AddDiscountEvent event, Emitter<DeliveryState> emit) async {
|
||||
opBloc.add(LoadOperation());
|
||||
|
||||
try {
|
||||
final currentState = state;
|
||||
|
||||
if (currentState is DeliveryLoaded) {
|
||||
DiscountAddResponseDTO response = await repository.addDiscount(
|
||||
event.deliveryId,
|
||||
event.reason,
|
||||
event.value,
|
||||
);
|
||||
|
||||
model.Delivery delivery = currentState.delivery;
|
||||
delivery.totalNetValue = response.values.receipt.net;
|
||||
delivery.totalGrossValue = response.values.receipt.gross;
|
||||
|
||||
delivery.discount = model.Discount(
|
||||
article: Article.fromDTO(response.values.article),
|
||||
note: response.values.note.noteDescription,
|
||||
noteId: response.values.note.rowId,
|
||||
);
|
||||
|
||||
noteBloc.add(AddNoteOffline(note: response.values.note.noteDescription,
|
||||
deliveryId: delivery.id,
|
||||
noteId: response.values.note.rowId));
|
||||
|
||||
delivery.articles = [...delivery.articles, delivery.discount!.article];
|
||||
|
||||
emit(currentState.copyWith(delivery));
|
||||
|
||||
opBloc.add(FinishOperation());
|
||||
}
|
||||
} catch (e, st) {
|
||||
debugPrint(
|
||||
"Fehler beim Hinzufügen eins Discounts zur Lieferung: ${event
|
||||
.deliveryId}:",
|
||||
);
|
||||
debugPrint("$e");
|
||||
debugPrint("$st");
|
||||
|
||||
opBloc.add(
|
||||
FailOperation(message: "Fehler beim Hinzufügen des Discounts: $e"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _load(LoadDeliveryEvent event, Emitter<DeliveryState> emit) async {
|
||||
debugPrint("Discount; ${event.delivery.discount?.note}");
|
||||
emit(DeliveryLoaded(delivery: event.delivery));
|
||||
}
|
||||
|
||||
void _unscan(UnscanArticleEvent event, Emitter<DeliveryState> emit) async {
|
||||
opBloc.add(LoadOperation());
|
||||
|
||||
try {
|
||||
String? noteId = await repository.unscan(
|
||||
event.articleId,
|
||||
event.newAmount,
|
||||
event.reason,
|
||||
);
|
||||
|
||||
if (noteId != null) {
|
||||
final currentState = state;
|
||||
|
||||
if (currentState is DeliveryLoaded) {
|
||||
Article article = currentState.delivery.articles.firstWhere(
|
||||
(article) => article.internalId == int.parse(event.articleId),
|
||||
);
|
||||
|
||||
article.removeNoteId = noteId;
|
||||
article.scannedRemovedAmount += event.newAmount;
|
||||
article.scannedAmount -= event.newAmount;
|
||||
|
||||
List<Article> articles = [
|
||||
...currentState.delivery.articles.where(
|
||||
(article) => article.internalId != int.parse(event.articleId),
|
||||
),
|
||||
article,
|
||||
];
|
||||
currentState.delivery.articles = articles;
|
||||
|
||||
emit.call(currentState.copyWith(currentState.delivery));
|
||||
}
|
||||
}
|
||||
|
||||
opBloc.add(FinishOperation());
|
||||
} catch (e, st) {
|
||||
debugPrint("Fehler beim Unscan des Artikels: ${event.articleId}:");
|
||||
debugPrint("$e");
|
||||
debugPrint("$st");
|
||||
|
||||
opBloc.add(FailOperation(message: "Fehler beim Unscan des Artikels: $e"));
|
||||
}
|
||||
}
|
||||
|
||||
void _resetAmount(ResetScanAmountEvent event,
|
||||
Emitter<DeliveryState> emit,) async {
|
||||
opBloc.add(LoadOperation());
|
||||
|
||||
try {
|
||||
final currentState = state;
|
||||
await repository.resetScan(event.articleId);
|
||||
|
||||
if (currentState is DeliveryLoaded) {
|
||||
Article article = currentState.delivery.articles.firstWhere(
|
||||
(article) => article.internalId == int.parse(event.articleId),
|
||||
);
|
||||
|
||||
article.removeNoteId = null;
|
||||
article.scannedRemovedAmount = 0;
|
||||
article.scannedAmount = article.amount;
|
||||
|
||||
List<Article> articles = [
|
||||
...currentState.delivery.articles.where(
|
||||
(article) => article.internalId != int.parse(event.articleId),
|
||||
),
|
||||
article,
|
||||
];
|
||||
currentState.delivery.articles = articles;
|
||||
|
||||
emit.call(currentState.copyWith(currentState.delivery));
|
||||
}
|
||||
|
||||
opBloc.add(FinishOperation());
|
||||
} catch (e, st) {
|
||||
debugPrint("Fehler beim Unscan des Artikels: ${event.articleId}:");
|
||||
debugPrint("$e");
|
||||
debugPrint("$st");
|
||||
|
||||
opBloc.add(FailOperation(message: "Fehler beim Zurücksetzen: $e"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,85 +0,0 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
import 'package:hl_lieferservice/model/tour.dart';
|
||||
|
||||
abstract class DeliveryEvent {}
|
||||
|
||||
class LoadDeliveryEvent extends DeliveryEvent {
|
||||
LoadDeliveryEvent({required this.delivery});
|
||||
|
||||
Delivery delivery;
|
||||
}
|
||||
|
||||
class UnscanArticleEvent extends DeliveryEvent {
|
||||
UnscanArticleEvent({
|
||||
required this.articleId,
|
||||
required this.newAmount,
|
||||
required this.reason,
|
||||
});
|
||||
|
||||
String articleId;
|
||||
String reason;
|
||||
int newAmount;
|
||||
}
|
||||
|
||||
class ResetScanAmountEvent extends DeliveryEvent {
|
||||
ResetScanAmountEvent({required this.articleId});
|
||||
|
||||
String articleId;
|
||||
}
|
||||
|
||||
class AddDiscountEvent extends DeliveryEvent {
|
||||
AddDiscountEvent({
|
||||
required this.deliveryId,
|
||||
required this.value,
|
||||
required this.reason,
|
||||
});
|
||||
|
||||
String deliveryId;
|
||||
String reason;
|
||||
int value;
|
||||
}
|
||||
|
||||
class RemoveDiscountEvent extends DeliveryEvent {
|
||||
RemoveDiscountEvent({required this.deliveryId});
|
||||
|
||||
String deliveryId;
|
||||
}
|
||||
|
||||
class UpdateDiscountEvent extends DeliveryEvent {
|
||||
UpdateDiscountEvent({
|
||||
required this.deliveryId,
|
||||
required this.value,
|
||||
required this.reason,
|
||||
});
|
||||
|
||||
String deliveryId;
|
||||
String? reason;
|
||||
int? value;
|
||||
}
|
||||
|
||||
class UpdateDeliveryOptionEvent extends DeliveryEvent {
|
||||
UpdateDeliveryOptionEvent({required this.key, required this.value});
|
||||
|
||||
String key;
|
||||
dynamic value;
|
||||
}
|
||||
|
||||
class UpdateSelectedPaymentMethodEvent extends DeliveryEvent {
|
||||
UpdateSelectedPaymentMethodEvent({required this.payment});
|
||||
|
||||
Payment payment;
|
||||
}
|
||||
|
||||
class FinishDeliveryEvent extends DeliveryEvent {
|
||||
FinishDeliveryEvent({
|
||||
required this.delivery,
|
||||
required this.driverSignature,
|
||||
required this.customerSignature,
|
||||
});
|
||||
|
||||
Delivery delivery;
|
||||
Uint8List customerSignature;
|
||||
Uint8List driverSignature;
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
|
||||
abstract class DeliveryState {}
|
||||
|
||||
class DeliveryInitial extends DeliveryState {}
|
||||
|
||||
class DeliveryLoaded extends DeliveryState {
|
||||
DeliveryLoaded({required this.delivery});
|
||||
|
||||
Delivery delivery;
|
||||
|
||||
DeliveryLoaded copyWith(Delivery? delivery) {
|
||||
return DeliveryLoaded(delivery: delivery ?? this.delivery);
|
||||
}
|
||||
}
|
||||
|
||||
class DeliveryFinished extends DeliveryState {
|
||||
DeliveryFinished({required this.delivery});
|
||||
|
||||
Delivery delivery;
|
||||
|
||||
DeliveryFinished copyWith(Delivery? delivery) {
|
||||
return DeliveryFinished(delivery: delivery ?? this.delivery);
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_event.dart';
|
||||
|
||||
@ -13,9 +13,23 @@ import 'package:hl_lieferservice/feature/delivery/detail/repository/note_reposit
|
||||
class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
final NoteRepository repository;
|
||||
final OperationBloc opBloc;
|
||||
final String deliveryId;
|
||||
|
||||
NoteBloc({required this.repository, required this.opBloc})
|
||||
StreamSubscription? _noteSubscription;
|
||||
StreamSubscription? _imageSubscription;
|
||||
|
||||
NoteBloc({required this.repository, required this.opBloc, required this.deliveryId})
|
||||
: super(NoteInitial()) {
|
||||
repository.loadNotes(deliveryId);
|
||||
|
||||
_noteSubscription = repository.notes.listen((notes) {
|
||||
add(NotesUpdated(notes: notes));
|
||||
});
|
||||
|
||||
_imageSubscription = repository.images.listen((images) {
|
||||
add(ImageUpdated(images: images));
|
||||
});
|
||||
|
||||
on<LoadNote>(_load);
|
||||
on<AddNote>(_add);
|
||||
on<EditNote>(_edit);
|
||||
@ -23,61 +37,41 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
on<AddImageNote>(_upload);
|
||||
on<RemoveImageNote>(_removeImage);
|
||||
on<ResetNotes>(_reset);
|
||||
on<AddNoteOffline>(_addOffline);
|
||||
on<NotesUpdated>(_noteUpdated);
|
||||
on<ImageUpdated>(_imageUpdated);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_noteSubscription?.cancel();
|
||||
_imageSubscription?.cancel();
|
||||
|
||||
return super.close();
|
||||
}
|
||||
|
||||
Future<void> _imageUpdated(ImageUpdated event, Emitter<NoteState> emit) async {
|
||||
final currentState = state;
|
||||
|
||||
if (currentState is NoteLoaded) {
|
||||
emit.call(currentState.copyWith(images: event.images));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _noteUpdated(NotesUpdated event, Emitter<NoteState> emit) async {
|
||||
emit(NoteLoaded(notes: event.notes));
|
||||
}
|
||||
|
||||
Future<void> _reset(ResetNotes event, Emitter<NoteState> emit) async {
|
||||
emit.call(NoteInitial());
|
||||
}
|
||||
|
||||
Future<void> _addOffline(AddNoteOffline event,
|
||||
Emitter<NoteState> emit,) async {
|
||||
if (state is NoteInitial) {
|
||||
emit(
|
||||
NoteLoadedBase(
|
||||
notes: [Note(content: event.note, id: int.parse(event.noteId))],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is NoteLoadedBase) {
|
||||
emit(
|
||||
NoteLoadedBase(
|
||||
notes: [
|
||||
...(state as NoteLoadedBase).notes,
|
||||
Note(content: event.note, id: int.parse(event.noteId)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (state is NoteLoaded) {
|
||||
final current = state as NoteLoaded;
|
||||
emit(NoteLoaded(notes: [...current.notes, Note(content: event.note, id: int.parse(event.noteId))],
|
||||
templates: [...current.templates],
|
||||
images: [...current.images]));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _removeImage(RemoveImageNote event,
|
||||
Emitter<NoteState> emit,) async {
|
||||
opBloc.add(LoadOperation());
|
||||
|
||||
try {
|
||||
final currentState = state;
|
||||
await repository.deleteImage(event.deliveryId, event.objectId);
|
||||
|
||||
if (currentState is NoteLoaded) {
|
||||
emit.call(
|
||||
currentState.copyWith(
|
||||
images:
|
||||
currentState.images
|
||||
.where((image) => image.$1.objectId != event.objectId)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
opBloc.add(FinishOperation());
|
||||
} catch (e, st) {
|
||||
debugPrint("Fehler beim Löschen des Bildes: $e");
|
||||
@ -91,18 +85,8 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
opBloc.add(LoadOperation());
|
||||
|
||||
try {
|
||||
final currentState = state;
|
||||
Uint8List imageBytes = await event.file.readAsBytes();
|
||||
ImageNote note = await repository.addImage(event.deliveryId, imageBytes);
|
||||
|
||||
if (currentState is NoteLoaded) {
|
||||
emit.call(
|
||||
currentState.copyWith(
|
||||
images: [...currentState.images, (note, imageBytes)],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
await repository.addImage(event.deliveryId, imageBytes);
|
||||
opBloc.add(FinishOperation());
|
||||
} catch (e, st) {
|
||||
debugPrint("Fehler beim Hinzufügen des Bildes: $e");
|
||||
@ -118,20 +102,12 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
try {
|
||||
List<String> urls =
|
||||
event.delivery.images.map((image) => image.url).toList();
|
||||
List<Note> notes = await repository.loadNotes(event.delivery.id);
|
||||
List<NoteTemplate> templates = await repository.loadTemplates();
|
||||
List<Uint8List> images = await repository.loadImages(urls);
|
||||
|
||||
emit.call(
|
||||
NoteLoaded(
|
||||
notes: notes,
|
||||
templates: templates,
|
||||
images: List.generate(
|
||||
images.length,
|
||||
(index) => (event.delivery.images[index], images[index]),
|
||||
),
|
||||
),
|
||||
);
|
||||
debugPrint("IMAGE URLS : $urls");
|
||||
|
||||
await repository.loadNotes(event.delivery.id);
|
||||
await repository.loadTemplates();
|
||||
|
||||
opBloc.add(FinishOperation());
|
||||
} catch (e, st) {
|
||||
debugPrint("Fehler beim Herunterladen der Notizen: $e");
|
||||
@ -149,14 +125,7 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
opBloc.add(LoadOperation());
|
||||
|
||||
try {
|
||||
final currentState = state;
|
||||
Note note = await repository.addNote(event.deliveryId, event.note);
|
||||
|
||||
if (currentState is NoteLoaded) {
|
||||
List<Note> refreshedNotes = [...currentState.notes, note];
|
||||
emit.call(currentState.copyWith(notes: refreshedNotes));
|
||||
}
|
||||
|
||||
await repository.addNote(event.deliveryId, event.note);
|
||||
opBloc.add(FinishOperation());
|
||||
} catch (e, st) {
|
||||
debugPrint("Fehler beim Hinzufügen der Notiz: $e");
|
||||
@ -170,19 +139,7 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
opBloc.add(LoadOperation());
|
||||
|
||||
try {
|
||||
final currentState = state;
|
||||
await repository.editNote(event.noteId, event.content);
|
||||
|
||||
if (currentState is NoteLoaded) {
|
||||
List<Note> refreshedNotes = [
|
||||
...currentState.notes.where(
|
||||
(note) => note.id != int.parse(event.noteId),
|
||||
),
|
||||
Note(content: event.content, id: int.parse(event.noteId)),
|
||||
];
|
||||
emit.call(currentState.copyWith(notes: refreshedNotes));
|
||||
}
|
||||
|
||||
opBloc.add(FinishOperation());
|
||||
} catch (e, st) {
|
||||
debugPrint("Fehler beim Hinzufügen der Notiz: $e");
|
||||
@ -196,18 +153,7 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
opBloc.add(LoadOperation());
|
||||
|
||||
try {
|
||||
final currentState = state;
|
||||
await repository.deleteNote(event.noteId);
|
||||
|
||||
if (currentState is NoteLoaded) {
|
||||
List<Note> refreshedNotes =
|
||||
currentState.notes
|
||||
.where((note) => note.id != int.parse(event.noteId))
|
||||
.toList();
|
||||
|
||||
emit.call(currentState.copyWith(notes: refreshedNotes));
|
||||
}
|
||||
|
||||
opBloc.add(FinishOperation());
|
||||
} catch (e, st) {
|
||||
debugPrint("Fehler beim Hinzufügen der Notiz: $e");
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
@ -51,4 +53,16 @@ class RemoveImageNote extends NoteEvent {
|
||||
|
||||
final String objectId;
|
||||
final String deliveryId;
|
||||
}
|
||||
|
||||
class NotesUpdated extends NoteEvent {
|
||||
final List<Note> notes;
|
||||
|
||||
NotesUpdated({required this.notes});
|
||||
}
|
||||
|
||||
class ImageUpdated extends NoteEvent {
|
||||
final List<ImageNote> images;
|
||||
|
||||
ImageUpdated({required this.images});
|
||||
}
|
||||
@ -20,18 +20,18 @@ class NoteLoadedBase extends NoteState {
|
||||
|
||||
class NoteLoaded extends NoteLoadedBase {
|
||||
NoteLoaded({
|
||||
required this.templates,
|
||||
required this.images,
|
||||
this.templates,
|
||||
this.images,
|
||||
required super.notes,
|
||||
});
|
||||
|
||||
List<NoteTemplate> templates;
|
||||
List<(ImageNote, Uint8List)> images;
|
||||
List<NoteTemplate>? templates;
|
||||
List<ImageNote>? images;
|
||||
|
||||
NoteLoaded copyWith({
|
||||
List<Note>? notes,
|
||||
List<NoteTemplate>? templates,
|
||||
List<(ImageNote, Uint8List)>? images,
|
||||
List<ImageNote>? images,
|
||||
}) {
|
||||
return NoteLoaded(
|
||||
notes: notes ?? this.notes,
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:hl_lieferservice/model/article.dart';
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
|
||||
@ -6,4 +8,4 @@ class NoteInformation {
|
||||
|
||||
Note note;
|
||||
Article? article;
|
||||
}
|
||||
}
|
||||
@ -43,7 +43,11 @@ class _ArticleListItem extends State<ArticleListItem> {
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => ArticleUnscanDialog(article: widget.article),
|
||||
builder:
|
||||
(context) => ArticleUnscanDialog(
|
||||
article: widget.article,
|
||||
deliveryId: widget.deliveryId,
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: Icon(
|
||||
@ -61,7 +65,10 @@ class _ArticleListItem extends State<ArticleListItem> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder:
|
||||
(context) => ResetArticleAmountDialog(article: widget.article),
|
||||
(context) => ResetArticleAmountDialog(
|
||||
article: widget.article,
|
||||
deliveryId: widget.deliveryId,
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: Icon(
|
||||
|
||||
@ -1,14 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_event.dart';
|
||||
|
||||
import '../../../../../model/article.dart';
|
||||
|
||||
class ResetArticleAmountDialog extends StatefulWidget {
|
||||
const ResetArticleAmountDialog({super.key, required this.article});
|
||||
const ResetArticleAmountDialog({
|
||||
super.key,
|
||||
required this.article,
|
||||
required this.deliveryId,
|
||||
});
|
||||
|
||||
final Article article;
|
||||
final String deliveryId;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _ResetArticleAmountDialogState();
|
||||
@ -16,8 +21,11 @@ class ResetArticleAmountDialog extends StatefulWidget {
|
||||
|
||||
class _ResetArticleAmountDialogState extends State<ResetArticleAmountDialog> {
|
||||
void _reset() {
|
||||
context.read<DeliveryBloc>().add(
|
||||
ResetScanAmountEvent(articleId: widget.article.internalId.toString()),
|
||||
context.read<TourBloc>().add(
|
||||
ResetScanAmountEvent(
|
||||
articleId: widget.article.internalId.toString(),
|
||||
deliveryId: widget.deliveryId,
|
||||
),
|
||||
);
|
||||
|
||||
Navigator.pop(context);
|
||||
|
||||
@ -1,14 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_event.dart';
|
||||
|
||||
import '../../../../../model/article.dart';
|
||||
|
||||
class ArticleUnscanDialog extends StatefulWidget {
|
||||
const ArticleUnscanDialog({super.key, required this.article});
|
||||
const ArticleUnscanDialog({super.key, required this.article, required this.deliveryId});
|
||||
|
||||
final String deliveryId;
|
||||
final Article article;
|
||||
|
||||
@override
|
||||
@ -22,8 +23,9 @@ class _ArticleUnscanDialogState extends State<ArticleUnscanDialog> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
void _unscan() {
|
||||
context.read<DeliveryBloc>().add(
|
||||
context.read<TourBloc>().add(
|
||||
UnscanArticleEvent(
|
||||
deliveryId: widget.deliveryId,
|
||||
articleId: widget.article.internalId.toString(),
|
||||
newAmount: int.parse(unscanAmountController.text),
|
||||
reason: unscanNoteController.text,
|
||||
|
||||
@ -3,23 +3,19 @@ import 'dart:typed_data';
|
||||
import 'package:easy_stepper/easy_stepper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_state.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_state.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/presentation/delivery_sign.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/presentation/steps/step.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_state.dart';
|
||||
import 'package:hl_lieferservice/model/delivery.dart' as model;
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
|
||||
class DeliveryDetail extends StatefulWidget {
|
||||
final model.Delivery delivery;
|
||||
final String deliveryId;
|
||||
|
||||
const DeliveryDetail({super.key, required this.delivery});
|
||||
const DeliveryDetail({super.key, required this.deliveryId});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _DeliveryDetailState();
|
||||
@ -33,11 +29,6 @@ class _DeliveryDetailState extends State<DeliveryDetail> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// Initialize BLOC
|
||||
context.read<DeliveryBloc>().add(
|
||||
LoadDeliveryEvent(delivery: widget.delivery),
|
||||
);
|
||||
|
||||
// Reset Note BLOC
|
||||
// otherwise the notes of the previously
|
||||
// opened delivery would be loaded
|
||||
@ -124,28 +115,27 @@ class _DeliveryDetailState extends State<DeliveryDetail> {
|
||||
}
|
||||
}
|
||||
|
||||
void _openSignatureView() {
|
||||
void _openSignatureView(Delivery delivery) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder:
|
||||
(context) =>
|
||||
SignatureView(onSigned: _onSign, delivery: widget.delivery),
|
||||
SignatureView(onSigned: _onSign, delivery: delivery),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onSign(Uint8List customer, Uint8List driver) async {
|
||||
final currentState = context.read<DeliveryBloc>().state as DeliveryLoaded;
|
||||
context.read<DeliveryBloc>().add(
|
||||
context.read<TourBloc>().add(
|
||||
FinishDeliveryEvent(
|
||||
delivery: currentState.delivery,
|
||||
deliveryId: widget.deliveryId,
|
||||
customerSignature: customer,
|
||||
driverSignature: driver,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _stepsNavigation() {
|
||||
Widget _stepsNavigation(Delivery delivery) {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
height: 90,
|
||||
@ -160,9 +150,9 @@ class _DeliveryDetailState extends State<DeliveryDetail> {
|
||||
padding: const EdgeInsets.only(left: 20),
|
||||
child: FilledButton(
|
||||
onPressed:
|
||||
_step == _steps.length - 1
|
||||
? _openSignatureView
|
||||
: _clickForward,
|
||||
() => _step == _steps.length - 1
|
||||
? _openSignatureView(delivery)
|
||||
: _clickForward,
|
||||
child:
|
||||
_step == _steps.length - 1
|
||||
? const Text("Unterschreiben")
|
||||
@ -178,48 +168,27 @@ class _DeliveryDetailState extends State<DeliveryDetail> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text("Auslieferungsdetails")),
|
||||
body: BlocConsumer<DeliveryBloc, DeliveryState>(
|
||||
listener: (context, state) {
|
||||
if (state is DeliveryFinished) {
|
||||
final tourState = context.read<TourBloc>().state as TourLoaded;
|
||||
final newTour = tourState.tour.copyWith(
|
||||
deliveries:
|
||||
tourState.tour.deliveries.map((delivery) {
|
||||
if (delivery.id == state.delivery.id) {
|
||||
return state.delivery;
|
||||
}
|
||||
body: BlocBuilder<TourBloc, TourState>(builder: (context, state) {
|
||||
final currentState = state;
|
||||
|
||||
return delivery;
|
||||
}).toList(),
|
||||
);
|
||||
if (currentState is TourLoaded) {
|
||||
Delivery delivery = currentState.tour.deliveries.firstWhere((delivery) => delivery.id == widget.deliveryId);
|
||||
return Column(
|
||||
children: [
|
||||
_stepInfo(),
|
||||
const Divider(),
|
||||
Expanded(
|
||||
child:
|
||||
StepFactory().make(_step, delivery) ??
|
||||
_stepMissingWarning(),
|
||||
),
|
||||
_stepsNavigation(delivery),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
context.read<TourBloc>().add(UpdateTour(tour: newTour));
|
||||
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
final currentState = state;
|
||||
|
||||
if (currentState is DeliveryLoaded) {
|
||||
return Column(
|
||||
children: [
|
||||
_stepInfo(),
|
||||
const Divider(),
|
||||
Expanded(
|
||||
child:
|
||||
StepFactory().make(_step, currentState.delivery) ??
|
||||
_stepMissingWarning(),
|
||||
),
|
||||
_stepsNavigation(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
return const Center(child: CircularProgressIndicator(),);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_bloc.dart';
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
|
||||
import '../../overview/bloc/tour_event.dart';
|
||||
|
||||
class DeliveryDiscount extends StatefulWidget {
|
||||
const DeliveryDiscount({
|
||||
super.key,
|
||||
@ -126,14 +127,14 @@ class _DeliveryDiscountState extends State<DeliveryDiscount> {
|
||||
_isUpdated = false;
|
||||
});
|
||||
|
||||
context.read<DeliveryBloc>().add(
|
||||
context.read<TourBloc>().add(
|
||||
RemoveDiscountEvent(deliveryId: widget.deliveryId),
|
||||
);
|
||||
}
|
||||
|
||||
void _updateValues() async {
|
||||
if (_isUpdated) {
|
||||
context.read<DeliveryBloc>().add(
|
||||
context.read<TourBloc>().add(
|
||||
UpdateDiscountEvent(
|
||||
deliveryId: widget.deliveryId,
|
||||
value: _discountValue,
|
||||
@ -141,7 +142,7 @@ class _DeliveryDiscountState extends State<DeliveryDiscount> {
|
||||
),
|
||||
);
|
||||
} else {
|
||||
context.read<DeliveryBloc>().add(
|
||||
context.read<TourBloc>().add(
|
||||
AddDiscountEvent(
|
||||
deliveryId: widget.deliveryId,
|
||||
value: _discountValue,
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_bloc.dart';
|
||||
import 'package:hl_lieferservice/model/delivery.dart' as model;
|
||||
|
||||
import '../../overview/bloc/tour_event.dart';
|
||||
|
||||
class DeliveryOptionsView extends StatefulWidget {
|
||||
const DeliveryOptionsView({super.key, required this.options});
|
||||
const DeliveryOptionsView({super.key, required this.options, required this.deliveryId});
|
||||
|
||||
final List<model.DeliveryOption> options;
|
||||
final String deliveryId;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _DeliveryOptionsViewState();
|
||||
@ -28,17 +30,16 @@ class _DeliveryOptionsViewState extends State<DeliveryOptionsView> {
|
||||
debugPrint(option.key);
|
||||
|
||||
if (value is bool) {
|
||||
context.read<DeliveryBloc>().add(
|
||||
UpdateDeliveryOptionEvent(key: option.key, value: !value),
|
||||
context.read<TourBloc>().add(
|
||||
UpdateDeliveryOptionEvent(key: option.key, value: !value, deliveryId: widget.deliveryId),
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
context.read<DeliveryBloc>().add(
|
||||
UpdateDeliveryOptionEvent(key: option.key, value: value),
|
||||
context.read<TourBloc>().add(
|
||||
UpdateDeliveryOptionEvent(key: option.key, value: value, deliveryId: widget.deliveryId),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
List<Widget> _options() {
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_state.dart';
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
|
||||
@ -97,11 +96,10 @@ class _DeliverySummaryState extends State<DeliverySummary> {
|
||||
dropdownMenuEntries: entries,
|
||||
initialSelection: widget.delivery.payment.id,
|
||||
onSelected: (id) {
|
||||
context.read<DeliveryBloc>().add(
|
||||
context.read<TourBloc>().add(
|
||||
UpdateSelectedPaymentMethodEvent(
|
||||
payment: _paymentMethods.firstWhere(
|
||||
(payment) => payment.id == id,
|
||||
),
|
||||
deliveryId: widget.delivery.id,
|
||||
payment: _paymentMethods.firstWhere((payment) => payment.id == id),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@ -9,7 +9,7 @@ import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_event.dart';
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
|
||||
class NoteImageOverview extends StatefulWidget {
|
||||
final List<(ImageNote, Uint8List)> images;
|
||||
final List<ImageNote> images;
|
||||
final String deliveryId;
|
||||
|
||||
const NoteImageOverview({
|
||||
@ -26,7 +26,7 @@ class _NoteImageOverviewState extends State<NoteImageOverview> {
|
||||
int? _imageDeleting;
|
||||
|
||||
void _onRemoveImage(int index) {
|
||||
ImageNote note = widget.images[index].$1;
|
||||
ImageNote note = widget.images[index];
|
||||
|
||||
context.read<NoteBloc>().add(
|
||||
RemoveImageNote(objectId: note.objectId, deliveryId: widget.deliveryId),
|
||||
@ -42,8 +42,7 @@ class _NoteImageOverviewState extends State<NoteImageOverview> {
|
||||
),
|
||||
items:
|
||||
widget.images.mapIndexed((index, data) {
|
||||
ImageNote note = data.$1;
|
||||
Uint8List bytes = data.$2;
|
||||
Uint8List bytes = data.data!;
|
||||
|
||||
return Builder(
|
||||
builder: (BuildContext context) {
|
||||
|
||||
@ -16,7 +16,7 @@ import 'package:image_picker/image_picker.dart';
|
||||
class NoteOverview extends StatefulWidget {
|
||||
final List<NoteInformation> notes;
|
||||
final List<NoteTemplate> templates;
|
||||
final List<(ImageNote, Uint8List)> images;
|
||||
final List<ImageNote> images;
|
||||
final String deliveryId;
|
||||
|
||||
const NoteOverview({
|
||||
|
||||
@ -17,6 +17,9 @@ class _DeliveryStepInfo extends State<DeliveryStepOptions> {
|
||||
debugPrint(
|
||||
"${widget.delivery.options.map((option) => "${option.display}, ${option.value}")}",
|
||||
);
|
||||
return DeliveryOptionsView(options: widget.delivery.options);
|
||||
return DeliveryOptionsView(
|
||||
options: widget.delivery.options,
|
||||
deliveryId: widget.delivery.id,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ class _DeliveryStepInfo extends State<DeliveryStepNote> {
|
||||
BuildContext context,
|
||||
List<Note> notes,
|
||||
List<NoteTemplate> templates,
|
||||
List<(ImageNote, Uint8List)> images,
|
||||
List<ImageNote> images,
|
||||
) {
|
||||
List<NoteInformation> hydratedNotes =
|
||||
notes
|
||||
@ -75,8 +75,8 @@ class _DeliveryStepInfo extends State<DeliveryStepNote> {
|
||||
return _notesOverview(
|
||||
context,
|
||||
state.notes,
|
||||
state.templates,
|
||||
state.images,
|
||||
(state.templates ?? []),
|
||||
(state.images ?? []),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -1,13 +1,17 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:hl_lieferservice/dto/discount_add_response.dart';
|
||||
import 'package:hl_lieferservice/dto/discount_remove_response.dart';
|
||||
import 'package:hl_lieferservice/dto/discount_update_response.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/repository/note_repository.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/service/notes_service.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/service/delivery_info_service.dart';
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
|
||||
class DeliveryRepository {
|
||||
DeliveryRepository({required this.service});
|
||||
|
||||
DeliveryInfoService service;
|
||||
TourService service;
|
||||
|
||||
Future<String?> unscan(String articleId, int newAmount, String reason) async {
|
||||
return await service.unscanArticle(articleId, newAmount, reason);
|
||||
@ -17,6 +21,16 @@ class DeliveryRepository {
|
||||
return await service.resetScannedArticleAmount(articleId);
|
||||
}
|
||||
|
||||
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<DiscountAddResponseDTO> addDiscount(
|
||||
String deliveryId,
|
||||
String reason,
|
||||
|
||||
@ -2,43 +2,61 @@ import 'dart:typed_data';
|
||||
|
||||
import 'package:hl_lieferservice/model/delivery.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/service/notes_service.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
class NoteRepository {
|
||||
final NoteService service;
|
||||
|
||||
final _notesStream = BehaviorSubject<List<Note>>.seeded([]);
|
||||
final _imageNoteStream = BehaviorSubject<List<ImageNote>>.seeded([]);
|
||||
final _noteTemplateStream = BehaviorSubject<List<NoteTemplate>>.seeded([]);
|
||||
|
||||
Stream<List<Note>> get notes => _notesStream.stream;
|
||||
Stream<List<ImageNote>> get images => _imageNoteStream.stream;
|
||||
Stream<List<NoteTemplate>> get templates => _noteTemplateStream.stream;
|
||||
|
||||
NoteRepository({required this.service});
|
||||
|
||||
Future<Note> addNote(String deliveryId, String content) async {
|
||||
return service.addNote(content, int.parse(deliveryId));
|
||||
Future<void> addNote(String deliveryId, String content) async {
|
||||
final note = await service.addNote(content, int.parse(deliveryId));
|
||||
final currentNotes = _notesStream.value;
|
||||
currentNotes.add(note);
|
||||
|
||||
_notesStream.add(currentNotes);
|
||||
}
|
||||
|
||||
Future<void> editNote(String noteId, String content) async {
|
||||
return service.editNote(Note(content: content, id: int.parse(noteId)));
|
||||
final newNote = Note(content: content, id: int.parse(noteId));
|
||||
await service.editNote(newNote);
|
||||
|
||||
final currentNotes = _notesStream.value;
|
||||
final index = currentNotes.indexWhere((note) => note.id == int.parse(noteId));
|
||||
currentNotes[index] = newNote;
|
||||
|
||||
_notesStream.add(currentNotes);
|
||||
}
|
||||
|
||||
Future<void> deleteNote(String noteId) async {
|
||||
return service.deleteNote(int.parse(noteId));
|
||||
await service.deleteNote(int.parse(noteId));
|
||||
final currentNotes = _notesStream.value;
|
||||
final index = currentNotes.indexWhere((note) => note.id == int.parse(noteId));
|
||||
currentNotes.removeAt(index);
|
||||
|
||||
_notesStream.add(currentNotes);
|
||||
}
|
||||
|
||||
Future<List<Note>> loadNotes(String deliveryId) async {
|
||||
return service.getNotes(deliveryId);
|
||||
Future<void> loadNotes(String deliveryId) async {
|
||||
var (notes, images) = await service.getNotes(deliveryId);
|
||||
|
||||
_notesStream.add(notes);
|
||||
_imageNoteStream.add(images);
|
||||
}
|
||||
|
||||
Future<List<Uint8List>> loadImages(List<String> urls) async {
|
||||
List<Uint8List> images = [];
|
||||
|
||||
for (final image in await service.downloadImages(urls)) {
|
||||
images.add(await image);
|
||||
}
|
||||
|
||||
return images;
|
||||
Future<void> loadTemplates() async {
|
||||
_noteTemplateStream.add(await service.getNoteTemplates());
|
||||
}
|
||||
|
||||
Future<List<NoteTemplate>> loadTemplates() async {
|
||||
return service.getNoteTemplates();
|
||||
}
|
||||
|
||||
Future<ImageNote> addImage(String deliveryId, Uint8List bytes) async {
|
||||
Future<void> addImage(String deliveryId, Uint8List bytes) async {
|
||||
final fileName =
|
||||
"delivery_note_${deliveryId}_${DateTime.timestamp().microsecondsSinceEpoch}.jpg";
|
||||
|
||||
@ -48,11 +66,12 @@ class NoteRepository {
|
||||
bytes,
|
||||
"image/png",
|
||||
);
|
||||
|
||||
return ImageNote.make(objectId, fileName);
|
||||
final imageNotes = _imageNoteStream.value;
|
||||
imageNotes.add(ImageNote.make(objectId, fileName, bytes));
|
||||
_imageNoteStream.add(imageNotes);
|
||||
}
|
||||
|
||||
Future<ImageNote> addNamedImage(String deliveryId, Uint8List bytes, String filename) async {
|
||||
Future<void> addNamedImage(String deliveryId, Uint8List bytes, String filename) async {
|
||||
String objectId = await service.uploadImage(
|
||||
deliveryId,
|
||||
filename,
|
||||
@ -60,10 +79,18 @@ class NoteRepository {
|
||||
"image/png",
|
||||
);
|
||||
|
||||
return ImageNote.make(objectId, filename);
|
||||
final imageNotes = _imageNoteStream.value;
|
||||
imageNotes.add(ImageNote.make(objectId, filename, bytes));
|
||||
_imageNoteStream.add(imageNotes);
|
||||
}
|
||||
|
||||
Future<void> deleteImage(String deliveryId, String objectId) async {
|
||||
await service.removeImage(objectId);
|
||||
|
||||
final images = _imageNoteStream.value;
|
||||
final index = images.indexWhere((imageNote) => imageNote.objectId == objectId);
|
||||
images.removeAt(index);
|
||||
|
||||
_imageNoteStream.add(images);
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,9 +17,7 @@ import '../../../../model/delivery.dart';
|
||||
import '../../../../util.dart';
|
||||
import '../../../authentication/exceptions.dart';
|
||||
|
||||
class NoteService extends ErpFrameService {
|
||||
NoteService({required super.backendUrl});
|
||||
|
||||
class NoteService {
|
||||
Future<void> deleteNote(int noteId) async {
|
||||
try {
|
||||
var response = await http.post(
|
||||
@ -110,7 +108,7 @@ class NoteService extends ErpFrameService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Note>> getNotes(String deliveryId) async {
|
||||
Future<(List<Note>, List<ImageNote>)> getNotes(String deliveryId) async {
|
||||
try {
|
||||
var response = await http.post(
|
||||
urlBuilder("_web_getNotes"),
|
||||
@ -129,9 +127,22 @@ class NoteService extends ErpFrameService {
|
||||
);
|
||||
|
||||
if (responseDto.succeeded == true) {
|
||||
return responseDto.notes
|
||||
.map((noteDto) => Note.fromDto(noteDto))
|
||||
.toList();
|
||||
List<ImageNote> imageNotes =
|
||||
responseDto.images
|
||||
.map((imageNoteDto) => ImageNote.fromDTO(imageNoteDto))
|
||||
.toList();
|
||||
|
||||
final images = await downloadImages(imageNotes.map((note) => note.url).toList());
|
||||
for (var (index, note) in imageNotes.indexed) {
|
||||
note.data = await images[index];
|
||||
}
|
||||
|
||||
return (
|
||||
responseDto.notes
|
||||
.map((noteDto) => Note.fromDto(noteDto))
|
||||
.toList(),
|
||||
imageNotes
|
||||
);
|
||||
} else {
|
||||
throw responseDto.message;
|
||||
}
|
||||
@ -262,9 +273,11 @@ class NoteService extends ErpFrameService {
|
||||
|
||||
Future<List<Future<Uint8List>>> downloadImages(List<String> urls) async {
|
||||
try {
|
||||
LocalDocuFrameConfiguration config = getConfig();
|
||||
|
||||
return urls.map((url) async {
|
||||
return (await http.get(
|
||||
Uri.parse("$backendUrl$url"),
|
||||
Uri.parse("${config.backendUrl}$url"),
|
||||
headers: getSessionOrThrow(),
|
||||
)).bodyBytes;
|
||||
}).toList();
|
||||
|
||||
Reference in New Issue
Block a user