This commit is contained in:
alzalia1 2025-08-15 11:46:09 +02:00
parent 11c66e7bf1
commit 3a013c829f

View file

@ -52,6 +52,47 @@ class SellViewModel extends ChangeNotifier {
notifyListeners();
}
Future<void> scanBook(BarcodeCapture barcode) async {
int ean = int.parse(barcode.barcodes.first.rawValue!);
Bal? bal = await _balRepository.ongoingBal();
_scannedBooks.clear();
final result = await _bookInstanceRepository.getByEan(bal!.id, ean);
switch (result) {
case Ok():
for (BookInstance instance in result.value) {
Book book;
final result2 = await _bookRepository.getBookById(instance.bookId);
switch (result2) {
case Ok():
book = result2.value;
break;
case Error():
continue;
}
Owner owner;
final result3 = await _ownerRepository.getOwnerById(instance.ownerId);
switch (result3) {
case Ok():
owner = result3.value;
break;
case Error():
continue;
}
_scannedBooks.add(
BookStack(instance: instance, book: book, owner: owner),
);
}
break;
case Error():
break;
}
isScanLoaded = true;
notifyListeners();
return;
}
/*
* =================
* =====[ BAL ]=====