diff --git a/lib/bloc/app_bloc.dart b/lib/bloc/app_bloc.dart index 8f199a4..588a0a0 100644 --- a/lib/bloc/app_bloc.dart +++ b/lib/bloc/app_bloc.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hl_lieferservice/bloc/app_events.dart'; @@ -27,10 +28,11 @@ class AppBloc extends Bloc { var config = await repository.getDocuFrameConfiguration(); locator.registerSingleton(config); - emit( - AppConfigLoaded(config: config), - ); - } catch (e) { + emit(AppConfigLoaded(config: config)); + } catch (e, st) { + debugPrint(e.toString()); + debugPrint(st.toString()); + emit( AppConfigLoadingFailed( message: "Fehler beim Laden der Konfigurationsdatei.", diff --git a/lib/feature/cars/service/cars_service.dart b/lib/feature/cars/service/cars_service.dart index 337acc6..4c1b4fc 100644 --- a/lib/feature/cars/service/cars_service.dart +++ b/lib/feature/cars/service/cars_service.dart @@ -3,18 +3,16 @@ import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:hl_lieferservice/feature/authentication/exceptions.dart'; -import 'package:hl_lieferservice/services/erpframe.dart'; import 'package:hl_lieferservice/util.dart'; import 'package:http/http.dart'; import '../../../dto/basic_response.dart'; -import '../../../dto/car_add.dart'; import '../../../dto/car_add_response.dart'; import '../../../dto/car_get_response.dart'; import '../../../model/car.dart'; -class CarService extends ErpFrameService { - CarService({required super.config}); +class CarService { + CarService(); Future addCar(String plate, int teamId) async { try { @@ -122,7 +120,7 @@ class CarService extends ErpFrameService { var response = await post( urlBuilder("_web_getCars"), headers: getSessionOrThrow(), - body:{"team_id": teamId.toString()}, + body: {"team_id": teamId.toString()}, ); if (response.statusCode == HttpStatus.unauthorized) { diff --git a/lib/feature/delivery/detail/bloc/note_bloc.dart b/lib/feature/delivery/detail/bloc/note_bloc.dart index cf8e8ea..967ccf3 100644 --- a/lib/feature/delivery/detail/bloc/note_bloc.dart +++ b/lib/feature/delivery/detail/bloc/note_bloc.dart @@ -22,6 +22,11 @@ class NoteBloc extends Bloc { on(_remove); on(_upload); on(_removeImage); + on(_reset); + } + + Future _reset(ResetNotes event, Emitter emit) async { + emit.call(NoteInitial()); } Future _removeImage( diff --git a/lib/feature/delivery/detail/bloc/note_event.dart b/lib/feature/delivery/detail/bloc/note_event.dart index 044b956..eedf60b 100644 --- a/lib/feature/delivery/detail/bloc/note_event.dart +++ b/lib/feature/delivery/detail/bloc/note_event.dart @@ -9,6 +9,8 @@ class LoadNote extends NoteEvent { final Delivery delivery; } +class ResetNotes extends NoteEvent {} + class AddNote extends NoteEvent { AddNote({required this.note, required this.deliveryId}); diff --git a/lib/feature/delivery/detail/presentation/delivery_detail_page.dart b/lib/feature/delivery/detail/presentation/delivery_detail_page.dart index bdd9d41..c925ee9 100644 --- a/lib/feature/delivery/detail/presentation/delivery_detail_page.dart +++ b/lib/feature/delivery/detail/presentation/delivery_detail_page.dart @@ -6,6 +6,9 @@ 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'; @@ -35,6 +38,11 @@ class _DeliveryDetailState extends State { LoadDeliveryEvent(delivery: widget.delivery), ); + // Reset Note BLOC + // otherwise the notes of the previously + // opened delivery would be loaded + context.read().add(ResetNotes()); + // Initialize steps _step = 0; _steps = [ @@ -120,10 +128,8 @@ class _DeliveryDetailState extends State { Navigator.of(context).push( MaterialPageRoute( builder: - (context) => SignatureView( - onSigned: _onSign, - customer: widget.delivery.customer, - ), + (context) => + SignatureView(onSigned: _onSign, delivery: widget.delivery), ), ); } @@ -176,13 +182,16 @@ class _DeliveryDetailState extends State { listener: (context, state) { if (state is DeliveryFinished) { final tourState = context.read().state as TourLoaded; - final newTour = tourState.tour.copyWith(deliveries: tourState.tour.deliveries.map((delivery) { - if (delivery.id == state.delivery.id) { - return state.delivery; - } + final newTour = tourState.tour.copyWith( + deliveries: + tourState.tour.deliveries.map((delivery) { + if (delivery.id == state.delivery.id) { + return state.delivery; + } - return delivery; - }).toList()); + return delivery; + }).toList(), + ); context.read().add(UpdateTour(tour: newTour)); diff --git a/lib/feature/delivery/detail/presentation/delivery_sign.dart b/lib/feature/delivery/detail/presentation/delivery_sign.dart index f51520b..84d071f 100644 --- a/lib/feature/delivery/detail/presentation/delivery_sign.dart +++ b/lib/feature/delivery/detail/presentation/delivery_sign.dart @@ -1,7 +1,12 @@ import 'dart:typed_data'; +import 'package:flutter_bloc/flutter_bloc.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/model/customer.dart'; import 'package:flutter/material.dart'; +import 'package:hl_lieferservice/model/delivery.dart'; import 'package:intl/intl.dart'; import 'package:signature/signature.dart'; @@ -9,14 +14,18 @@ class SignatureView extends StatefulWidget { const SignatureView({ super.key, required this.onSigned, - required this.customer, + required this.delivery, }); - final Customer customer; + final Delivery delivery; /// Callback that is called when the user has signed. /// The parameter stores the path to the image file of the signature. - final void Function(Uint8List customerSignaturePng, Uint8List driverSignaturePng) onSigned; + final void Function( + Uint8List customerSignaturePng, + Uint8List driverSignaturePng, + ) + onSigned; @override State createState() => _SignatureViewState(); @@ -37,10 +46,18 @@ class _SignatureViewState extends State { bool _isDriverSigning = false; bool _customerAccepted = false; + bool _noteAccepted = false; + bool _notesEmpty = true; @override void initState() { super.initState(); + + // only load notes if they are not already loaded + final noteState = context.read().state; + if (noteState is NoteInitial) { + context.read().add(LoadNote(delivery: widget.delivery)); + } } @override @@ -56,6 +73,124 @@ class _SignatureViewState extends State { ); } + Widget _notes() { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only(bottom: 15), + child: Text( + "Notizen", + style: Theme.of(context).textTheme.headlineSmall, + ), + ), + BlocConsumer( + listener: (context, state) { + final current = state; + if (current is NoteLoaded) { + setState(() { + _notesEmpty = current.notes.isEmpty; + }); + } + }, + + builder: (context, state) { + final current = state; + + if (current is NoteLoaded) { + if (current.notes.isEmpty) { + return const SizedBox( + width: double.infinity, + child: Center(child: Text("Keine Notizen vorhanden")), + ); + } + + return ListView.separated( + shrinkWrap: true, + physics: NeverScrollableScrollPhysics(), + itemBuilder: (context, index) { + return ListTile( + leading: const Icon(Icons.event_note_outlined), + title: Text(current.notes[index].content), + contentPadding: EdgeInsets.all(20), + tileColor: Theme.of(context).colorScheme.onSecondary, + ); + }, + separatorBuilder: (context, index) => const Divider(height: 0), + itemCount: current.notes.length, + ); + } + + return SizedBox( + width: double.infinity, + child: Center(child: CircularProgressIndicator()), + ); + }, + ), + + const Padding(padding: EdgeInsets.only(top: 25), child: Divider()), + ], + ); + } + + Widget _customerCheckboxes() { + return !_isDriverSigning + ? Column( + children: [ + Padding( + padding: const EdgeInsets.only(top: 25, bottom: 0), + child: _notes(), + ), + Padding( + padding: const EdgeInsets.only(top: 25.0, bottom: 0), + child: Row( + children: [ + Checkbox( + value: _noteAccepted, + onChanged: + _notesEmpty + ? null + : (value) { + setState(() { + _noteAccepted = value!; + }); + }, + ), + const Flexible( + child: Text( + "Ich nehme die oben genannten Anmerkungen zur Lieferung zur Kenntnis.", + overflow: TextOverflow.fade, + ), + ), + ], + ), + ), + Padding( + padding: const EdgeInsets.only(top: 25.0, bottom: 10.0), + child: Row( + children: [ + Checkbox( + value: _customerAccepted, + onChanged: (value) { + setState(() { + _customerAccepted = value!; + }); + }, + ), + const Flexible( + child: Text( + "Ich bestätige, dass ich die Ware im ordnungsgemäßen Zustand erhalten habe und, dass die Aufstell- und Einbauarbeiten korrekt durchgeführt wurden.", + overflow: TextOverflow.fade, + ), + ), + ], + ), + ), + ], + ) + : Container(); + } + @override Widget build(BuildContext context) { String formattedDate = DateFormat("dd.MM.yyyy").format(DateTime.now()); @@ -69,73 +204,50 @@ class _SignatureViewState extends State { ), body: Padding( padding: const EdgeInsets.all(20.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, + child: ListView( children: [ - Expanded( - child: SizedBox( - width: double.infinity, - child: DecoratedBox( - decoration: const BoxDecoration(color: Colors.white), - child: Padding( - padding: const EdgeInsets.all(20.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - "Lieferung an: ${widget.customer.name}", - style: const TextStyle( - fontWeight: FontWeight.bold, - ), + SizedBox( + width: double.infinity, + height: + MediaQuery.of(context).size.height * + (_isDriverSigning ? 0.75 : 0.5), + child: DecoratedBox( + decoration: const BoxDecoration(color: Colors.white), + child: Padding( + padding: const EdgeInsets.all(20.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + "Lieferung an: ${widget.delivery.customer.name}", + style: const TextStyle( + fontWeight: FontWeight.bold, ), - Expanded(child: _signatureField()), - ], - ), + ), + Expanded(child: _signatureField()), + ], ), - const Divider(), - Text( - "${widget.customer.address.city}, den $formattedDate", - ), - ], - ), + ), + const Divider(), + Text( + "${widget.delivery.customer.address.city}, den $formattedDate", + ), + ], ), ), ), ), - !_isDriverSigning - ? Padding( - padding: const EdgeInsets.only(top: 25.0, bottom: 25.0), - child: Row( - children: [ - Checkbox( - value: _customerAccepted, - onChanged: (value) { - setState(() { - _customerAccepted = value!; - }); - }, - ), - const Flexible( - child: Text( - "Ich bestätige, dass ich die Ware im ordnungsgemäßen Zustand erhalten habe und, dass die Aufstell- und Einbauarbeiten korrekt durchgeführt wurden.", - overflow: TextOverflow.fade, - ), - ), - ], - ), - ) - : Container(), + _customerCheckboxes(), Padding( padding: const EdgeInsets.only(top: 25.0, bottom: 25.0), child: Center( child: FilledButton( onPressed: - !_customerAccepted + !(_customerAccepted && (_noteAccepted || _notesEmpty)) ? null : () async { if (!_isDriverSigning) { diff --git a/lib/feature/delivery/detail/service/notes_service.dart b/lib/feature/delivery/detail/service/notes_service.dart index a02e7fe..5e05902 100644 --- a/lib/feature/delivery/detail/service/notes_service.dart +++ b/lib/feature/delivery/detail/service/notes_service.dart @@ -19,7 +19,7 @@ import '../../../../util.dart'; import '../../../authentication/exceptions.dart'; class NoteService extends ErpFrameService { - NoteService({required super.config}); + NoteService({required super.backendUrl}); Future deleteNote(int noteId) async { try { @@ -210,20 +210,31 @@ class NoteService extends ErpFrameService { } String uploadId = data["uploadId"]; - http.MultipartRequest request = - http.MultipartRequest("POST", Uri.parse("$basePath/$uploadId")); + http.MultipartRequest request = http.MultipartRequest( + "POST", + Uri.parse("$basePath/$uploadId"), + ); HashMap header = HashMap(); header["Content-Type"] = "multipart/form-data"; header.addAll(getSessionOrThrow()); request.headers.addAll(header); - request.files.add(http.MultipartFile.fromBytes("file", bytes, + request.files.add( + http.MultipartFile.fromBytes( + "file", + bytes, filename: filename, - contentType: MediaType.parse(mimeType ?? "application/octet-stream"))); + contentType: MediaType.parse(mimeType ?? "application/octet-stream"), + ), + ); - http.Response fileUploadResponse = await http.Response.fromStream(await request.send()); - Map fileUploadResponseJson = jsonDecode(fileUploadResponse.body); + http.Response fileUploadResponse = await http.Response.fromStream( + await request.send(), + ); + Map fileUploadResponseJson = jsonDecode( + fileUploadResponse.body, + ); debugPrint("UPLOAD IMAGE RESPONSE: ${fileUploadResponse.body}"); @@ -233,7 +244,10 @@ class NoteService extends ErpFrameService { throw NoteImageAddException(); } - var fileCommitResponse = await http.patch(Uri.parse("$basePath/$uploadId"), headers: getSessionOrThrow()); + var fileCommitResponse = await http.patch( + Uri.parse("$basePath/$uploadId"), + headers: getSessionOrThrow(), + ); debugPrint("FILE COMMIT BODY: ${fileCommitResponse.body}"); var fileCommitResponseJson = jsonDecode(fileCommitResponse.body); @@ -251,7 +265,7 @@ class NoteService extends ErpFrameService { try { return urls.map((url) async { return (await http.get( - Uri.parse("${config.backendUrl}$url"), + Uri.parse("$backendUrl$url"), headers: getSessionOrThrow(), )).bodyBytes; }).toList(); diff --git a/lib/feature/delivery/overview/service/delivery_info_service.dart b/lib/feature/delivery/overview/service/delivery_info_service.dart index 7f63afd..2c43e8a 100644 --- a/lib/feature/delivery/overview/service/delivery_info_service.dart +++ b/lib/feature/delivery/overview/service/delivery_info_service.dart @@ -13,7 +13,6 @@ 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:hl_lieferservice/services/erpframe.dart'; import 'package:http/http.dart'; import '../../../../dto/basic_response.dart'; @@ -23,20 +22,17 @@ import '../../../../dto/discount_update_response.dart'; import '../../../../dto/scan_response.dart'; import '../../../authentication/exceptions.dart'; -class DeliveryInfoService extends ErpFrameService { - DeliveryInfoService({required super.config}); +class DeliveryInfoService { + DeliveryInfoService(); Future updateDelivery(Delivery delivery) async { try { - var headers = { - "Content-Type": "application/json" - }; + var headers = {"Content-Type": "application/json"}; headers.addAll(getSessionOrThrow()); debugPrint(getSessionOrThrow().toString()); debugPrint(jsonEncode(DeliveryUpdateDTO.fromEntity(delivery).toJson())); - var response = await post( urlBuilder("_web_updateDelivery"), headers: headers, @@ -70,9 +66,7 @@ class DeliveryInfoService extends ErpFrameService { Future assignCar(String deliveryId, String carId) async { try { - var headers = { - "Content-Type": "application/json" - }; + var headers = {"Content-Type": "application/json"}; headers.addAll(getSessionOrThrow()); var response = await post( @@ -87,7 +81,7 @@ class DeliveryInfoService extends ErpFrameService { Map responseJson = jsonDecode(response.body); DeliveryUpdateResponseDTO responseDto = - DeliveryUpdateResponseDTO.fromJson(responseJson); + DeliveryUpdateResponseDTO.fromJson(responseJson); if (responseDto.code == "200") { return; @@ -118,23 +112,29 @@ class DeliveryInfoService extends ErpFrameService { if (response.statusCode == HttpStatus.unauthorized) { throw UserUnauthorized(); } - - DeliveryResponseDTO responseDto = - DeliveryResponseDTO.fromJson(jsonDecode(response.body)); + + 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)) + 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)); + teamNumber: int.parse(responseDto.driver.id), + name: responseDto.driver.name, + salutation: responseDto.driver.salutation, + ), + ); } catch (e, stacktrace) { debugPrint(e.toString()); debugPrint(stacktrace.toString()); @@ -157,8 +157,9 @@ class DeliveryInfoService extends ErpFrameService { } Map responseJson = jsonDecode(response.body); - PaymentMethodListDTO responseDto = - PaymentMethodListDTO.fromJson(responseJson); + PaymentMethodListDTO responseDto = PaymentMethodListDTO.fromJson( + responseJson, + ); return responseDto.paymentMethods; } catch (e, st) { @@ -171,7 +172,10 @@ class DeliveryInfoService extends ErpFrameService { } Future unscanArticle( - String internalId, int amount, String reason) async { + String internalId, + int amount, + String reason, + ) async { try { var response = await post( urlBuilder("_web_unscanArticle"), @@ -179,7 +183,7 @@ class DeliveryInfoService extends ErpFrameService { body: { "article_id": internalId, "amount": amount.toString(), - "reason": reason + "reason": reason, }, ); @@ -234,7 +238,10 @@ class DeliveryInfoService extends ErpFrameService { } Future addDiscount( - String deliveryId, int discount, String note) async { + String deliveryId, + int discount, + String note, + ) async { try { var response = await post( urlBuilder("_web_addDiscount"), @@ -242,7 +249,7 @@ class DeliveryInfoService extends ErpFrameService { body: { "delivery_id": deliveryId, "discount": discount.toString(), - "note": note + "note": note, }, ); @@ -268,9 +275,7 @@ class DeliveryInfoService extends ErpFrameService { var response = await post( urlBuilder("_web_removeDiscount"), headers: getSessionOrThrow(), - body: { - "delivery_id": deliveryId, - }, + body: {"delivery_id": deliveryId}, ); if (response.statusCode == HttpStatus.unauthorized) { @@ -291,16 +296,15 @@ class DeliveryInfoService extends ErpFrameService { } Future updateDiscount( - String deliveryId, String? note, int? discount) async { + 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 - }, + body: {"delivery_id": deliveryId, "discount": discount, "note": note}, ); if (response.statusCode == HttpStatus.unauthorized) { @@ -336,9 +340,7 @@ class DeliveryInfoService extends ErpFrameService { Map responseJson = jsonDecode(response.body); debugPrint(responseJson.toString()); - ScanResponseDTO responseDto = ScanResponseDTO.fromJson( - responseJson, - ); + ScanResponseDTO responseDto = ScanResponseDTO.fromJson(responseJson); if (responseDto.succeeded == true) { return; diff --git a/lib/services/erpframe.dart b/lib/services/erpframe.dart index 8e7a807..36a7ddf 100644 --- a/lib/services/erpframe.dart +++ b/lib/services/erpframe.dart @@ -1,79 +1,23 @@ -import 'dart:async'; -import 'package:docuframe/docuframe.dart' as df; import 'package:hl_lieferservice/util.dart'; -import 'package:flutter/cupertino.dart'; class LocalDocuFrameConfiguration { - String host; String backendUrl; - final String user; - final String pass; - final List appNames; - final String appKey; - LocalDocuFrameConfiguration( - {required this.host, - required this.appKey, - required this.appNames, - required this.pass, - required this.backendUrl, - required this.user}); + LocalDocuFrameConfiguration({required this.backendUrl}); Map toJson() { - return { - "host": host, - "user": user, - "pass": pass, - "backendUrl": backendUrl, - "appNames": appNames, - "appKey": appKey - }; + return {"backendUrl": backendUrl}; } factory LocalDocuFrameConfiguration.fromJson(Map json) { return LocalDocuFrameConfiguration( - host: getValueOrThrowIfNotPresent("host", json), - appKey: getValueOrThrowIfNotPresent("appKey", json), - appNames: (getValueOrThrowIfNotPresent("appNames", json) as List) - .cast(), - pass: getValueOrThrowIfNotPresent("pass", json), - backendUrl: getValueOrThrowIfNotPresent("backendUrl", json), - user: getValueOrThrowIfNotPresent("user", json)); + backendUrl: getValueOrThrowIfNotPresent("backendUrl", json), + ); } } class ErpFrameService { - ErpFrameService({required this.config}); + ErpFrameService({required this.backendUrl}); - final LocalDocuFrameConfiguration config; - - df.DocuFrameConfiguration get dfConfig { - df.DocuFrameConfiguration dfConfig = - df.DocuFrameConfiguration(url: config.host, appkey: config.appKey); - - return dfConfig; - } - - Future getSession() async { - df.LoginV1 request = df.LoginV1(config: dfConfig); - df.LoginSession session = - await request.authorize(config.user, config.pass, config.appNames); - - debugPrint("LOGIN WITH SESSION ID ${session.sessionId}"); - - return session; - } - - Future logout(df.LoginSession? session) async { - if (session != null) { - try { - await df.Logout(config: dfConfig, session: session).logout(); - } catch (e, st) { - debugPrint("Logout failed"); - debugPrint(e.toString()); - debugPrint(st.toString()); - } - debugPrint("Logged out with session ID: ${session.sessionId}"); - } - } -} \ No newline at end of file + final String backendUrl; +} diff --git a/lib/services/scan_service.dart b/lib/services/scan_service.dart deleted file mode 100644 index 1d4927c..0000000 --- a/lib/services/scan_service.dart +++ /dev/null @@ -1,109 +0,0 @@ -import 'dart:convert'; - -import 'package:hl_lieferservice/services/erpframe.dart'; -import 'package:docuframe/docuframe.dart' as df; -import 'package:flutter/cupertino.dart'; - -import '../dto/basic_response.dart'; -import '../dto/scan.dart'; -import '../dto/scan_response.dart'; - -class ScanService extends ErpFrameService { - ScanService({required super.config}); - - Future scanArticle(String internalId) async { - df.LoginSession? session; - - try { - session = await getSession(); - df.DocuFrameMacroResponse response = - await df.Macro(config: dfConfig, session: session).execute( - "_web_scanArticle", - parameter: ScanDTO(internalId: internalId).toJson() - as Map); - - Map responseJson = jsonDecode(response.body!); - ScanResponseDTO responseDto = ScanResponseDTO.fromJson(responseJson); - - if (responseDto.succeeded == true) { - return; - } else { - throw responseDto.message; - } - } on df.DocuFrameException catch (e, st) { - debugPrint("ERROR WHILE SCANNING ARTICLE $internalId"); - debugPrint(e.toString()); - debugPrint(st.toString()); - - rethrow; - } finally { - await logout(session); - } - } - - Future 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 - }); - - Map responseJson = jsonDecode(response.body!); - debugPrint(responseJson.toString()); - 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; - } finally { - await logout(session); - } - } - - Future 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}); - - Map 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; - } finally { - await logout(session); - } - } -} diff --git a/lib/widget/app.dart b/lib/widget/app.dart index 7ba886e..676a75d 100644 --- a/lib/widget/app.dart +++ b/lib/widget/app.dart @@ -53,9 +53,7 @@ class _DeliveryAppState extends State { (context) => TourBloc( opBloc: context.read(), tourRepository: TourRepository( - service: DeliveryInfoService( - config: currentAppState.config, - ), + service: DeliveryInfoService(), ), ), ), @@ -64,7 +62,9 @@ class _DeliveryAppState extends State { (context) => NoteBloc( opBloc: context.read(), repository: NoteRepository( - service: NoteService(config: currentAppState.config), + service: NoteService( + backendUrl: currentAppState.config.backendUrl, + ), ), ), ), @@ -73,12 +73,12 @@ class _DeliveryAppState extends State { (context) => DeliveryBloc( opBloc: context.read(), noteRepository: NoteRepository( - service: NoteService(config: currentAppState.config), + service: NoteService( + backendUrl: currentAppState.config.backendUrl, + ), ), repository: DeliveryRepository( - service: DeliveryInfoService( - config: currentAppState.config, - ), + service: DeliveryInfoService(), ), ), ), diff --git a/lib/widget/home/presentation/home.dart b/lib/widget/home/presentation/home.dart index d8925aa..4cf2eda 100644 --- a/lib/widget/home/presentation/home.dart +++ b/lib/widget/home/presentation/home.dart @@ -12,8 +12,6 @@ import 'package:hl_lieferservice/widget/home/bloc/navigation_bloc.dart'; import 'package:hl_lieferservice/widget/home/bloc/navigation_state.dart'; import 'package:hl_lieferservice/widget/navigation_bar/presentation/navigation_bar.dart'; -import '../../../bloc/app_bloc.dart'; -import '../../../bloc/app_states.dart'; import '../../../feature/cars/bloc/cars_bloc.dart'; import '../../../feature/cars/repository/cars_repository.dart'; import '../../../feature/cars/service/cars_service.dart'; @@ -46,13 +44,10 @@ class _HomeState extends State { } if (index == 2) { - final currentAppState = context.read().state as AppConfigLoaded; return BlocProvider( create: (context) => CarsBloc( - repository: CarsRepository( - service: CarService(config: currentAppState.config), - ), + repository: CarsRepository(service: CarService()), opBloc: context.read(), ), child: CarManagementPage(),