Sign page: added user check for accepting notes of a delivery

This commit is contained in:
Dennis Nemec
2025-11-28 20:46:03 +01:00
parent 7ea9108f62
commit 0150614ef5
12 changed files with 289 additions and 315 deletions

View File

@ -1,5 +1,6 @@
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hl_lieferservice/bloc/app_events.dart'; import 'package:hl_lieferservice/bloc/app_events.dart';
@ -27,10 +28,11 @@ class AppBloc extends Bloc<AppEvents, AppState> {
var config = await repository.getDocuFrameConfiguration(); var config = await repository.getDocuFrameConfiguration();
locator.registerSingleton<LocalDocuFrameConfiguration>(config); locator.registerSingleton<LocalDocuFrameConfiguration>(config);
emit( emit(AppConfigLoaded(config: config));
AppConfigLoaded(config: config), } catch (e, st) {
); debugPrint(e.toString());
} catch (e) { debugPrint(st.toString());
emit( emit(
AppConfigLoadingFailed( AppConfigLoadingFailed(
message: "Fehler beim Laden der Konfigurationsdatei.", message: "Fehler beim Laden der Konfigurationsdatei.",

View File

@ -3,18 +3,16 @@ import 'dart:io';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:hl_lieferservice/feature/authentication/exceptions.dart'; import 'package:hl_lieferservice/feature/authentication/exceptions.dart';
import 'package:hl_lieferservice/services/erpframe.dart';
import 'package:hl_lieferservice/util.dart'; import 'package:hl_lieferservice/util.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import '../../../dto/basic_response.dart'; import '../../../dto/basic_response.dart';
import '../../../dto/car_add.dart';
import '../../../dto/car_add_response.dart'; import '../../../dto/car_add_response.dart';
import '../../../dto/car_get_response.dart'; import '../../../dto/car_get_response.dart';
import '../../../model/car.dart'; import '../../../model/car.dart';
class CarService extends ErpFrameService { class CarService {
CarService({required super.config}); CarService();
Future<Car> addCar(String plate, int teamId) async { Future<Car> addCar(String plate, int teamId) async {
try { try {
@ -122,7 +120,7 @@ class CarService extends ErpFrameService {
var response = await post( var response = await post(
urlBuilder("_web_getCars"), urlBuilder("_web_getCars"),
headers: getSessionOrThrow(), headers: getSessionOrThrow(),
body:{"team_id": teamId.toString()}, body: {"team_id": teamId.toString()},
); );
if (response.statusCode == HttpStatus.unauthorized) { if (response.statusCode == HttpStatus.unauthorized) {

View File

@ -22,6 +22,11 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
on<RemoveNote>(_remove); on<RemoveNote>(_remove);
on<AddImageNote>(_upload); on<AddImageNote>(_upload);
on<RemoveImageNote>(_removeImage); on<RemoveImageNote>(_removeImage);
on<ResetNotes>(_reset);
}
Future<void> _reset(ResetNotes event, Emitter<NoteState> emit) async {
emit.call(NoteInitial());
} }
Future<void> _removeImage( Future<void> _removeImage(

View File

@ -9,6 +9,8 @@ class LoadNote extends NoteEvent {
final Delivery delivery; final Delivery delivery;
} }
class ResetNotes extends NoteEvent {}
class AddNote extends NoteEvent { class AddNote extends NoteEvent {
AddNote({required this.note, required this.deliveryId}); AddNote({required this.note, required this.deliveryId});

View File

@ -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_bloc.dart';
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_event.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/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/delivery_sign.dart';
import 'package:hl_lieferservice/feature/delivery/detail/presentation/steps/step.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_bloc.dart';
@ -35,6 +38,11 @@ class _DeliveryDetailState extends State<DeliveryDetail> {
LoadDeliveryEvent(delivery: widget.delivery), LoadDeliveryEvent(delivery: widget.delivery),
); );
// Reset Note BLOC
// otherwise the notes of the previously
// opened delivery would be loaded
context.read<NoteBloc>().add(ResetNotes());
// Initialize steps // Initialize steps
_step = 0; _step = 0;
_steps = [ _steps = [
@ -120,10 +128,8 @@ class _DeliveryDetailState extends State<DeliveryDetail> {
Navigator.of(context).push( Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: builder:
(context) => SignatureView( (context) =>
onSigned: _onSign, SignatureView(onSigned: _onSign, delivery: widget.delivery),
customer: widget.delivery.customer,
),
), ),
); );
} }
@ -176,13 +182,16 @@ class _DeliveryDetailState extends State<DeliveryDetail> {
listener: (context, state) { listener: (context, state) {
if (state is DeliveryFinished) { if (state is DeliveryFinished) {
final tourState = context.read<TourBloc>().state as TourLoaded; final tourState = context.read<TourBloc>().state as TourLoaded;
final newTour = tourState.tour.copyWith(deliveries: tourState.tour.deliveries.map((delivery) { final newTour = tourState.tour.copyWith(
if (delivery.id == state.delivery.id) { deliveries:
return state.delivery; tourState.tour.deliveries.map((delivery) {
} if (delivery.id == state.delivery.id) {
return state.delivery;
}
return delivery; return delivery;
}).toList()); }).toList(),
);
context.read<TourBloc>().add(UpdateTour(tour: newTour)); context.read<TourBloc>().add(UpdateTour(tour: newTour));

View File

@ -1,7 +1,12 @@
import 'dart:typed_data'; 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:hl_lieferservice/model/customer.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hl_lieferservice/model/delivery.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:signature/signature.dart'; import 'package:signature/signature.dart';
@ -9,14 +14,18 @@ class SignatureView extends StatefulWidget {
const SignatureView({ const SignatureView({
super.key, super.key,
required this.onSigned, required this.onSigned,
required this.customer, required this.delivery,
}); });
final Customer customer; final Delivery delivery;
/// Callback that is called when the user has signed. /// Callback that is called when the user has signed.
/// The parameter stores the path to the image file of the signature. /// 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 @override
State<StatefulWidget> createState() => _SignatureViewState(); State<StatefulWidget> createState() => _SignatureViewState();
@ -37,10 +46,18 @@ class _SignatureViewState extends State<SignatureView> {
bool _isDriverSigning = false; bool _isDriverSigning = false;
bool _customerAccepted = false; bool _customerAccepted = false;
bool _noteAccepted = false;
bool _notesEmpty = true;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
// only load notes if they are not already loaded
final noteState = context.read<NoteBloc>().state;
if (noteState is NoteInitial) {
context.read<NoteBloc>().add(LoadNote(delivery: widget.delivery));
}
} }
@override @override
@ -56,6 +73,124 @@ class _SignatureViewState extends State<SignatureView> {
); );
} }
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<NoteBloc, NoteState>(
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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String formattedDate = DateFormat("dd.MM.yyyy").format(DateTime.now()); String formattedDate = DateFormat("dd.MM.yyyy").format(DateTime.now());
@ -69,73 +204,50 @@ class _SignatureViewState extends State<SignatureView> {
), ),
body: Padding( body: Padding(
padding: const EdgeInsets.all(20.0), padding: const EdgeInsets.all(20.0),
child: Column( child: ListView(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Expanded( SizedBox(
child: SizedBox( width: double.infinity,
width: double.infinity, height:
child: DecoratedBox( MediaQuery.of(context).size.height *
decoration: const BoxDecoration(color: Colors.white), (_isDriverSigning ? 0.75 : 0.5),
child: Padding( child: DecoratedBox(
padding: const EdgeInsets.all(20.0), decoration: const BoxDecoration(color: Colors.white),
child: Column( child: Padding(
crossAxisAlignment: CrossAxisAlignment.start, padding: const EdgeInsets.all(20.0),
children: [ child: Column(
Expanded( crossAxisAlignment: CrossAxisAlignment.start,
child: Column( children: [
crossAxisAlignment: CrossAxisAlignment.center, Expanded(
children: [ child: Column(
Text( crossAxisAlignment: CrossAxisAlignment.center,
"Lieferung an: ${widget.customer.name}", children: [
style: const TextStyle( Text(
fontWeight: FontWeight.bold, "Lieferung an: ${widget.delivery.customer.name}",
), style: const TextStyle(
fontWeight: FontWeight.bold,
), ),
Expanded(child: _signatureField()), ),
], Expanded(child: _signatureField()),
), ],
), ),
const Divider(), ),
Text( const Divider(),
"${widget.customer.address.city}, den $formattedDate", Text(
), "${widget.delivery.customer.address.city}, den $formattedDate",
], ),
), ],
), ),
), ),
), ),
), ),
!_isDriverSigning _customerCheckboxes(),
? 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(),
Padding( Padding(
padding: const EdgeInsets.only(top: 25.0, bottom: 25.0), padding: const EdgeInsets.only(top: 25.0, bottom: 25.0),
child: Center( child: Center(
child: FilledButton( child: FilledButton(
onPressed: onPressed:
!_customerAccepted !(_customerAccepted && (_noteAccepted || _notesEmpty))
? null ? null
: () async { : () async {
if (!_isDriverSigning) { if (!_isDriverSigning) {

View File

@ -19,7 +19,7 @@ import '../../../../util.dart';
import '../../../authentication/exceptions.dart'; import '../../../authentication/exceptions.dart';
class NoteService extends ErpFrameService { class NoteService extends ErpFrameService {
NoteService({required super.config}); NoteService({required super.backendUrl});
Future<void> deleteNote(int noteId) async { Future<void> deleteNote(int noteId) async {
try { try {
@ -210,20 +210,31 @@ class NoteService extends ErpFrameService {
} }
String uploadId = data["uploadId"]; String uploadId = data["uploadId"];
http.MultipartRequest request = http.MultipartRequest request = http.MultipartRequest(
http.MultipartRequest("POST", Uri.parse("$basePath/$uploadId")); "POST",
Uri.parse("$basePath/$uploadId"),
);
HashMap<String, String> header = HashMap(); HashMap<String, String> header = HashMap();
header["Content-Type"] = "multipart/form-data"; header["Content-Type"] = "multipart/form-data";
header.addAll(getSessionOrThrow()); header.addAll(getSessionOrThrow());
request.headers.addAll(header); request.headers.addAll(header);
request.files.add(http.MultipartFile.fromBytes("file", bytes, request.files.add(
http.MultipartFile.fromBytes(
"file",
bytes,
filename: filename, 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()); http.Response fileUploadResponse = await http.Response.fromStream(
Map<String, dynamic> fileUploadResponseJson = jsonDecode(fileUploadResponse.body); await request.send(),
);
Map<String, dynamic> fileUploadResponseJson = jsonDecode(
fileUploadResponse.body,
);
debugPrint("UPLOAD IMAGE RESPONSE: ${fileUploadResponse.body}"); debugPrint("UPLOAD IMAGE RESPONSE: ${fileUploadResponse.body}");
@ -233,7 +244,10 @@ class NoteService extends ErpFrameService {
throw NoteImageAddException(); 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}"); debugPrint("FILE COMMIT BODY: ${fileCommitResponse.body}");
var fileCommitResponseJson = jsonDecode(fileCommitResponse.body); var fileCommitResponseJson = jsonDecode(fileCommitResponse.body);
@ -251,7 +265,7 @@ class NoteService extends ErpFrameService {
try { try {
return urls.map((url) async { return urls.map((url) async {
return (await http.get( return (await http.get(
Uri.parse("${config.backendUrl}$url"), Uri.parse("$backendUrl$url"),
headers: getSessionOrThrow(), headers: getSessionOrThrow(),
)).bodyBytes; )).bodyBytes;
}).toList(); }).toList();

View File

@ -13,7 +13,6 @@ import 'package:hl_lieferservice/model/car.dart';
import 'package:hl_lieferservice/model/delivery.dart'; import 'package:hl_lieferservice/model/delivery.dart';
import 'package:hl_lieferservice/model/tour.dart'; import 'package:hl_lieferservice/model/tour.dart';
import 'package:hl_lieferservice/util.dart'; import 'package:hl_lieferservice/util.dart';
import 'package:hl_lieferservice/services/erpframe.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import '../../../../dto/basic_response.dart'; import '../../../../dto/basic_response.dart';
@ -23,20 +22,17 @@ import '../../../../dto/discount_update_response.dart';
import '../../../../dto/scan_response.dart'; import '../../../../dto/scan_response.dart';
import '../../../authentication/exceptions.dart'; import '../../../authentication/exceptions.dart';
class DeliveryInfoService extends ErpFrameService { class DeliveryInfoService {
DeliveryInfoService({required super.config}); DeliveryInfoService();
Future<void> updateDelivery(Delivery delivery) async { Future<void> updateDelivery(Delivery delivery) async {
try { try {
var headers = { var headers = {"Content-Type": "application/json"};
"Content-Type": "application/json"
};
headers.addAll(getSessionOrThrow()); headers.addAll(getSessionOrThrow());
debugPrint(getSessionOrThrow().toString()); debugPrint(getSessionOrThrow().toString());
debugPrint(jsonEncode(DeliveryUpdateDTO.fromEntity(delivery).toJson())); debugPrint(jsonEncode(DeliveryUpdateDTO.fromEntity(delivery).toJson()));
var response = await post( var response = await post(
urlBuilder("_web_updateDelivery"), urlBuilder("_web_updateDelivery"),
headers: headers, headers: headers,
@ -70,9 +66,7 @@ class DeliveryInfoService extends ErpFrameService {
Future<void> assignCar(String deliveryId, String carId) async { Future<void> assignCar(String deliveryId, String carId) async {
try { try {
var headers = { var headers = {"Content-Type": "application/json"};
"Content-Type": "application/json"
};
headers.addAll(getSessionOrThrow()); headers.addAll(getSessionOrThrow());
var response = await post( var response = await post(
@ -87,7 +81,7 @@ class DeliveryInfoService extends ErpFrameService {
Map<String, dynamic> responseJson = jsonDecode(response.body); Map<String, dynamic> responseJson = jsonDecode(response.body);
DeliveryUpdateResponseDTO responseDto = DeliveryUpdateResponseDTO responseDto =
DeliveryUpdateResponseDTO.fromJson(responseJson); DeliveryUpdateResponseDTO.fromJson(responseJson);
if (responseDto.code == "200") { if (responseDto.code == "200") {
return; return;
@ -118,23 +112,29 @@ class DeliveryInfoService extends ErpFrameService {
if (response.statusCode == HttpStatus.unauthorized) { if (response.statusCode == HttpStatus.unauthorized) {
throw UserUnauthorized(); throw UserUnauthorized();
} }
DeliveryResponseDTO responseDto = DeliveryResponseDTO responseDto = DeliveryResponseDTO.fromJson(
DeliveryResponseDTO.fromJson(jsonDecode(response.body)); jsonDecode(response.body),
);
return Tour( return Tour(
discountArticleNumber: responseDto.discountArticleNumber, discountArticleNumber: responseDto.discountArticleNumber,
date: DateTime.now(), date: DateTime.now(),
deliveries: responseDto.deliveries.map(Delivery.fromDTO).toList(), deliveries: responseDto.deliveries.map(Delivery.fromDTO).toList(),
paymentMethods: [], paymentMethods: [],
driver: Driver( driver: Driver(
cars: responseDto.driver.cars cars:
.map((carDto) => responseDto.driver.cars
Car(id: int.parse(carDto.id), plate: carDto.plate)) .map(
(carDto) =>
Car(id: int.parse(carDto.id), plate: carDto.plate),
)
.toList(), .toList(),
teamNumber: int.parse(responseDto.driver.id), teamNumber: int.parse(responseDto.driver.id),
name: responseDto.driver.name, name: responseDto.driver.name,
salutation: responseDto.driver.salutation)); salutation: responseDto.driver.salutation,
),
);
} catch (e, stacktrace) { } catch (e, stacktrace) {
debugPrint(e.toString()); debugPrint(e.toString());
debugPrint(stacktrace.toString()); debugPrint(stacktrace.toString());
@ -157,8 +157,9 @@ class DeliveryInfoService extends ErpFrameService {
} }
Map<String, dynamic> responseJson = jsonDecode(response.body); Map<String, dynamic> responseJson = jsonDecode(response.body);
PaymentMethodListDTO responseDto = PaymentMethodListDTO responseDto = PaymentMethodListDTO.fromJson(
PaymentMethodListDTO.fromJson(responseJson); responseJson,
);
return responseDto.paymentMethods; return responseDto.paymentMethods;
} catch (e, st) { } catch (e, st) {
@ -171,7 +172,10 @@ class DeliveryInfoService extends ErpFrameService {
} }
Future<String?> unscanArticle( Future<String?> unscanArticle(
String internalId, int amount, String reason) async { String internalId,
int amount,
String reason,
) async {
try { try {
var response = await post( var response = await post(
urlBuilder("_web_unscanArticle"), urlBuilder("_web_unscanArticle"),
@ -179,7 +183,7 @@ class DeliveryInfoService extends ErpFrameService {
body: { body: {
"article_id": internalId, "article_id": internalId,
"amount": amount.toString(), "amount": amount.toString(),
"reason": reason "reason": reason,
}, },
); );
@ -234,7 +238,10 @@ class DeliveryInfoService extends ErpFrameService {
} }
Future<DiscountAddResponseDTO> addDiscount( Future<DiscountAddResponseDTO> addDiscount(
String deliveryId, int discount, String note) async { String deliveryId,
int discount,
String note,
) async {
try { try {
var response = await post( var response = await post(
urlBuilder("_web_addDiscount"), urlBuilder("_web_addDiscount"),
@ -242,7 +249,7 @@ class DeliveryInfoService extends ErpFrameService {
body: { body: {
"delivery_id": deliveryId, "delivery_id": deliveryId,
"discount": discount.toString(), "discount": discount.toString(),
"note": note "note": note,
}, },
); );
@ -268,9 +275,7 @@ class DeliveryInfoService extends ErpFrameService {
var response = await post( var response = await post(
urlBuilder("_web_removeDiscount"), urlBuilder("_web_removeDiscount"),
headers: getSessionOrThrow(), headers: getSessionOrThrow(),
body: { body: {"delivery_id": deliveryId},
"delivery_id": deliveryId,
},
); );
if (response.statusCode == HttpStatus.unauthorized) { if (response.statusCode == HttpStatus.unauthorized) {
@ -291,16 +296,15 @@ class DeliveryInfoService extends ErpFrameService {
} }
Future<DiscountUpdateResponseDTO> updateDiscount( Future<DiscountUpdateResponseDTO> updateDiscount(
String deliveryId, String? note, int? discount) async { String deliveryId,
String? note,
int? discount,
) async {
try { try {
var response = await post( var response = await post(
urlBuilder("_web_updateDiscount"), urlBuilder("_web_updateDiscount"),
headers: getSessionOrThrow(), headers: getSessionOrThrow(),
body: { body: {"delivery_id": deliveryId, "discount": discount, "note": note},
"delivery_id": deliveryId,
"discount": discount,
"note": note
},
); );
if (response.statusCode == HttpStatus.unauthorized) { if (response.statusCode == HttpStatus.unauthorized) {
@ -336,9 +340,7 @@ class DeliveryInfoService extends ErpFrameService {
Map<String, dynamic> responseJson = jsonDecode(response.body); Map<String, dynamic> responseJson = jsonDecode(response.body);
debugPrint(responseJson.toString()); debugPrint(responseJson.toString());
ScanResponseDTO responseDto = ScanResponseDTO.fromJson( ScanResponseDTO responseDto = ScanResponseDTO.fromJson(responseJson);
responseJson,
);
if (responseDto.succeeded == true) { if (responseDto.succeeded == true) {
return; return;

View File

@ -1,79 +1,23 @@
import 'dart:async';
import 'package:docuframe/docuframe.dart' as df;
import 'package:hl_lieferservice/util.dart'; import 'package:hl_lieferservice/util.dart';
import 'package:flutter/cupertino.dart';
class LocalDocuFrameConfiguration { class LocalDocuFrameConfiguration {
String host;
String backendUrl; String backendUrl;
final String user;
final String pass;
final List<String> appNames;
final String appKey;
LocalDocuFrameConfiguration( LocalDocuFrameConfiguration({required this.backendUrl});
{required this.host,
required this.appKey,
required this.appNames,
required this.pass,
required this.backendUrl,
required this.user});
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return { return {"backendUrl": backendUrl};
"host": host,
"user": user,
"pass": pass,
"backendUrl": backendUrl,
"appNames": appNames,
"appKey": appKey
};
} }
factory LocalDocuFrameConfiguration.fromJson(Map<String, dynamic> json) { factory LocalDocuFrameConfiguration.fromJson(Map<String, dynamic> json) {
return LocalDocuFrameConfiguration( return LocalDocuFrameConfiguration(
host: getValueOrThrowIfNotPresent("host", json), backendUrl: getValueOrThrowIfNotPresent("backendUrl", json),
appKey: getValueOrThrowIfNotPresent("appKey", json), );
appNames: (getValueOrThrowIfNotPresent("appNames", json) as List)
.cast<String>(),
pass: getValueOrThrowIfNotPresent("pass", json),
backendUrl: getValueOrThrowIfNotPresent("backendUrl", json),
user: getValueOrThrowIfNotPresent("user", json));
} }
} }
class ErpFrameService { class ErpFrameService {
ErpFrameService({required this.config}); ErpFrameService({required this.backendUrl});
final LocalDocuFrameConfiguration config; final String backendUrl;
}
df.DocuFrameConfiguration get dfConfig {
df.DocuFrameConfiguration dfConfig =
df.DocuFrameConfiguration(url: config.host, appkey: config.appKey);
return dfConfig;
}
Future<df.LoginSession> 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<void> 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}");
}
}
}

View File

@ -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<void> 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<String, dynamic>);
Map<String, dynamic> 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<String?> 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<String, dynamic> 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<void> 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<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;
} finally {
await logout(session);
}
}
}

View File

@ -53,9 +53,7 @@ class _DeliveryAppState extends State<DeliveryApp> {
(context) => TourBloc( (context) => TourBloc(
opBloc: context.read<OperationBloc>(), opBloc: context.read<OperationBloc>(),
tourRepository: TourRepository( tourRepository: TourRepository(
service: DeliveryInfoService( service: DeliveryInfoService(),
config: currentAppState.config,
),
), ),
), ),
), ),
@ -64,7 +62,9 @@ class _DeliveryAppState extends State<DeliveryApp> {
(context) => NoteBloc( (context) => NoteBloc(
opBloc: context.read<OperationBloc>(), opBloc: context.read<OperationBloc>(),
repository: NoteRepository( repository: NoteRepository(
service: NoteService(config: currentAppState.config), service: NoteService(
backendUrl: currentAppState.config.backendUrl,
),
), ),
), ),
), ),
@ -73,12 +73,12 @@ class _DeliveryAppState extends State<DeliveryApp> {
(context) => DeliveryBloc( (context) => DeliveryBloc(
opBloc: context.read<OperationBloc>(), opBloc: context.read<OperationBloc>(),
noteRepository: NoteRepository( noteRepository: NoteRepository(
service: NoteService(config: currentAppState.config), service: NoteService(
backendUrl: currentAppState.config.backendUrl,
),
), ),
repository: DeliveryRepository( repository: DeliveryRepository(
service: DeliveryInfoService( service: DeliveryInfoService(),
config: currentAppState.config,
),
), ),
), ),
), ),

View File

@ -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/home/bloc/navigation_state.dart';
import 'package:hl_lieferservice/widget/navigation_bar/presentation/navigation_bar.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/bloc/cars_bloc.dart';
import '../../../feature/cars/repository/cars_repository.dart'; import '../../../feature/cars/repository/cars_repository.dart';
import '../../../feature/cars/service/cars_service.dart'; import '../../../feature/cars/service/cars_service.dart';
@ -46,13 +44,10 @@ class _HomeState extends State<Home> {
} }
if (index == 2) { if (index == 2) {
final currentAppState = context.read<AppBloc>().state as AppConfigLoaded;
return BlocProvider( return BlocProvider(
create: create:
(context) => CarsBloc( (context) => CarsBloc(
repository: CarsRepository( repository: CarsRepository(service: CarService()),
service: CarService(config: currentAppState.config),
),
opBloc: context.read<OperationBloc>(), opBloc: context.read<OperationBloc>(),
), ),
child: CarManagementPage(), child: CarManagementPage(),