Sign page: added user check for accepting notes of a delivery
This commit is contained in:
@ -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<AppEvents, AppState> {
|
||||
var config = await repository.getDocuFrameConfiguration();
|
||||
locator.registerSingleton<LocalDocuFrameConfiguration>(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.",
|
||||
|
||||
@ -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<Car> addCar(String plate, int teamId) async {
|
||||
try {
|
||||
|
||||
@ -22,6 +22,11 @@ class NoteBloc extends Bloc<NoteEvent, NoteState> {
|
||||
on<RemoveNote>(_remove);
|
||||
on<AddImageNote>(_upload);
|
||||
on<RemoveImageNote>(_removeImage);
|
||||
on<ResetNotes>(_reset);
|
||||
}
|
||||
|
||||
Future<void> _reset(ResetNotes event, Emitter<NoteState> emit) async {
|
||||
emit.call(NoteInitial());
|
||||
}
|
||||
|
||||
Future<void> _removeImage(
|
||||
|
||||
@ -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});
|
||||
|
||||
|
||||
@ -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<DeliveryDetail> {
|
||||
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
|
||||
_step = 0;
|
||||
_steps = [
|
||||
@ -120,10 +128,8 @@ class _DeliveryDetailState extends State<DeliveryDetail> {
|
||||
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<DeliveryDetail> {
|
||||
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) {
|
||||
final newTour = tourState.tour.copyWith(
|
||||
deliveries:
|
||||
tourState.tour.deliveries.map((delivery) {
|
||||
if (delivery.id == state.delivery.id) {
|
||||
return state.delivery;
|
||||
}
|
||||
|
||||
return delivery;
|
||||
}).toList());
|
||||
}).toList(),
|
||||
);
|
||||
|
||||
context.read<TourBloc>().add(UpdateTour(tour: newTour));
|
||||
|
||||
|
||||
@ -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<StatefulWidget> createState() => _SignatureViewState();
|
||||
@ -37,10 +46,18 @@ class _SignatureViewState extends State<SignatureView> {
|
||||
|
||||
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<NoteBloc>().state;
|
||||
if (noteState is NoteInitial) {
|
||||
context.read<NoteBloc>().add(LoadNote(delivery: widget.delivery));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@ -56,60 +73,100 @@ class _SignatureViewState extends State<SignatureView> {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String formattedDate = DateFormat("dd.MM.yyyy").format(DateTime.now());
|
||||
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;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title:
|
||||
!_isDriverSigning
|
||||
? const Text("Unterschrift des Kunden")
|
||||
: const Text("Unterschrift des Fahrers"),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
builder: (context, state) {
|
||||
final current = state;
|
||||
|
||||
if (current is NoteLoaded) {
|
||||
if (current.notes.isEmpty) {
|
||||
return const 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,
|
||||
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()),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Expanded(child: _signatureField()),
|
||||
|
||||
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,
|
||||
),
|
||||
const Divider(),
|
||||
Text(
|
||||
"${widget.customer.address.city}, den $formattedDate",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
!_isDriverSigning
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(top: 25.0, bottom: 25.0),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 25.0, bottom: 10.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Checkbox(
|
||||
@ -128,14 +185,69 @@ class _SignatureViewState extends State<SignatureView> {
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Container(),
|
||||
: Container();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String formattedDate = DateFormat("dd.MM.yyyy").format(DateTime.now());
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title:
|
||||
!_isDriverSigning
|
||||
? const Text("Unterschrift des Kunden")
|
||||
: const Text("Unterschrift des Fahrers"),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: ListView(
|
||||
children: [
|
||||
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()),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
Text(
|
||||
"${widget.delivery.customer.address.city}, den $formattedDate",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_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) {
|
||||
|
||||
@ -19,7 +19,7 @@ import '../../../../util.dart';
|
||||
import '../../../authentication/exceptions.dart';
|
||||
|
||||
class NoteService extends ErpFrameService {
|
||||
NoteService({required super.config});
|
||||
NoteService({required super.backendUrl});
|
||||
|
||||
Future<void> 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<String, String> 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<String, dynamic> fileUploadResponseJson = jsonDecode(fileUploadResponse.body);
|
||||
http.Response fileUploadResponse = await http.Response.fromStream(
|
||||
await request.send(),
|
||||
);
|
||||
Map<String, dynamic> 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();
|
||||
|
||||
@ -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<void> 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<void> 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(
|
||||
@ -119,8 +113,9 @@ class DeliveryInfoService extends ErpFrameService {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
DeliveryResponseDTO responseDto =
|
||||
DeliveryResponseDTO.fromJson(jsonDecode(response.body));
|
||||
DeliveryResponseDTO responseDto = DeliveryResponseDTO.fromJson(
|
||||
jsonDecode(response.body),
|
||||
);
|
||||
|
||||
return Tour(
|
||||
discountArticleNumber: responseDto.discountArticleNumber,
|
||||
@ -128,13 +123,18 @@ class DeliveryInfoService extends ErpFrameService {
|
||||
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))
|
||||
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));
|
||||
salutation: responseDto.driver.salutation,
|
||||
),
|
||||
);
|
||||
} catch (e, stacktrace) {
|
||||
debugPrint(e.toString());
|
||||
debugPrint(stacktrace.toString());
|
||||
@ -157,8 +157,9 @@ class DeliveryInfoService extends ErpFrameService {
|
||||
}
|
||||
|
||||
Map<String, dynamic> 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<String?> 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<DiscountAddResponseDTO> 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<DiscountUpdateResponseDTO> 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<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
debugPrint(responseJson.toString());
|
||||
ScanResponseDTO responseDto = ScanResponseDTO.fromJson(
|
||||
responseJson,
|
||||
);
|
||||
ScanResponseDTO responseDto = ScanResponseDTO.fromJson(responseJson);
|
||||
|
||||
if (responseDto.succeeded == true) {
|
||||
return;
|
||||
|
||||
@ -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<String> 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<String, dynamic> toJson() {
|
||||
return {
|
||||
"host": host,
|
||||
"user": user,
|
||||
"pass": pass,
|
||||
"backendUrl": backendUrl,
|
||||
"appNames": appNames,
|
||||
"appKey": appKey
|
||||
};
|
||||
return {"backendUrl": backendUrl};
|
||||
}
|
||||
|
||||
factory LocalDocuFrameConfiguration.fromJson(Map<String, dynamic> json) {
|
||||
return LocalDocuFrameConfiguration(
|
||||
host: getValueOrThrowIfNotPresent("host", 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 {
|
||||
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<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}");
|
||||
}
|
||||
}
|
||||
final String backendUrl;
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -53,9 +53,7 @@ class _DeliveryAppState extends State<DeliveryApp> {
|
||||
(context) => TourBloc(
|
||||
opBloc: context.read<OperationBloc>(),
|
||||
tourRepository: TourRepository(
|
||||
service: DeliveryInfoService(
|
||||
config: currentAppState.config,
|
||||
),
|
||||
service: DeliveryInfoService(),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -64,7 +62,9 @@ class _DeliveryAppState extends State<DeliveryApp> {
|
||||
(context) => NoteBloc(
|
||||
opBloc: context.read<OperationBloc>(),
|
||||
repository: NoteRepository(
|
||||
service: NoteService(config: currentAppState.config),
|
||||
service: NoteService(
|
||||
backendUrl: currentAppState.config.backendUrl,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -73,12 +73,12 @@ class _DeliveryAppState extends State<DeliveryApp> {
|
||||
(context) => DeliveryBloc(
|
||||
opBloc: context.read<OperationBloc>(),
|
||||
noteRepository: NoteRepository(
|
||||
service: NoteService(config: currentAppState.config),
|
||||
service: NoteService(
|
||||
backendUrl: currentAppState.config.backendUrl,
|
||||
),
|
||||
),
|
||||
repository: DeliveryRepository(
|
||||
service: DeliveryInfoService(
|
||||
config: currentAppState.config,
|
||||
),
|
||||
service: DeliveryInfoService(),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@ -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<Home> {
|
||||
}
|
||||
|
||||
if (index == 2) {
|
||||
final currentAppState = context.read<AppBloc>().state as AppConfigLoaded;
|
||||
return BlocProvider(
|
||||
create:
|
||||
(context) => CarsBloc(
|
||||
repository: CarsRepository(
|
||||
service: CarService(config: currentAppState.config),
|
||||
),
|
||||
repository: CarsRepository(service: CarService()),
|
||||
opBloc: context.read<OperationBloc>(),
|
||||
),
|
||||
child: CarManagementPage(),
|
||||
|
||||
Reference in New Issue
Block a user