|
|
|
|
@ -461,42 +461,28 @@ class ServiceRequestsProvider extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<int> updateServiceReport({
|
|
|
|
|
@required ServiceReport report,
|
|
|
|
|
String host,
|
|
|
|
|
User user,
|
|
|
|
|
ServiceRequest request,
|
|
|
|
|
}) async {
|
|
|
|
|
Future<int> updateServiceReport(BuildContext context, {@required ServiceReport report}) async {
|
|
|
|
|
Response response;
|
|
|
|
|
//Map<String,dynamic> body = report.toMap(request);
|
|
|
|
|
// body["uid"] = user.id;
|
|
|
|
|
// body["token"] = user.token;
|
|
|
|
|
// body["job_id"] = request.id;
|
|
|
|
|
// body["report_id"] = request.reportID;
|
|
|
|
|
// try {
|
|
|
|
|
report.callRequest = CallRequest(id: report.callRequest.id);
|
|
|
|
|
Map<String, dynamic> body = report.toJson();
|
|
|
|
|
|
|
|
|
|
/// todo [zaid] : don't forget to add [request] data to [body]
|
|
|
|
|
// Map<String, dynamic> body = report.toMap(request);
|
|
|
|
|
// body["uid"] = user.id;
|
|
|
|
|
// body["token"] = user.token;
|
|
|
|
|
response = await ApiManager.instance.put(URLs.updateServiceReport, body: body);
|
|
|
|
|
// response = await post(
|
|
|
|
|
// Uri.parse(
|
|
|
|
|
// host+URLs.updateServiceReport),
|
|
|
|
|
// body: body,
|
|
|
|
|
// );
|
|
|
|
|
// stateCode = response.statusCode;
|
|
|
|
|
|
|
|
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
|
|
|
reset();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
try {
|
|
|
|
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
|
|
|
|
response = await ApiManager.instance.put(URLs.updateServiceReport, body: body);
|
|
|
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
|
|
|
reset();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
Fluttertoast.showToast(msg: context.translation.successfulRequestMessage);
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
} else {
|
|
|
|
|
Fluttertoast.showToast(msg: "${context.translation.failedToCompleteRequest}");
|
|
|
|
|
}
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
return response.statusCode;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
print(e);
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return response.statusCode;
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// print(error);
|
|
|
|
|
// return -1;
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<int> updateWorkOrderDetails({@required SearchWorkOrder workOrder}) async {
|
|
|
|
|
@ -560,28 +546,20 @@ class ServiceRequestsProvider extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<ServiceReport> getSingleServiceReport({
|
|
|
|
|
@required int reportId,
|
|
|
|
|
@required String host,
|
|
|
|
|
@required User user,
|
|
|
|
|
@required AppLocalizations subtitle,
|
|
|
|
|
}) async {
|
|
|
|
|
Future<ServiceReport> getSingleServiceReport(BuildContext context, {@required int reportId}) async {
|
|
|
|
|
Response response;
|
|
|
|
|
try {
|
|
|
|
|
response = await ApiManager.instance.get(
|
|
|
|
|
URLs.getServiceReport + "?workOrderId=$reportId",
|
|
|
|
|
);
|
|
|
|
|
response = await ApiManager.instance.get(URLs.getServiceReport + "?workOrderId=$reportId");
|
|
|
|
|
} catch (error) {
|
|
|
|
|
throw (HttpStatusManger.getStatusMessage(status: -1, subtitle: subtitle));
|
|
|
|
|
throw (context.translation.failedToCompleteRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the call to the server was successful, parse the JSON.
|
|
|
|
|
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
|
|
|
// If the call to the server was successful, parse the JSON.
|
|
|
|
|
/// todo [zaid]: check [reportId] below
|
|
|
|
|
return ServiceReport.fromJson(json.decode(response.body)["data"] /*, reportId*/);
|
|
|
|
|
return ServiceReport.fromJson(json.decode(response.body)["data"]);
|
|
|
|
|
} else {
|
|
|
|
|
throw (HttpStatusManger.getStatusMessage(status: response.statusCode, subtitle: subtitle));
|
|
|
|
|
throw (("${context.translation.failedToCompleteRequest} ${jsonDecode(response.body)["message"]}"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|