|
|
|
|
@ -309,82 +309,40 @@ class ServiceRequestsProvider extends ChangeNotifier {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<int> createServiceReport({@required ServiceReport report, @required ServiceRequest request}) async {
|
|
|
|
|
Future<int> createServiceReport(BuildContext context, {@required ServiceReport report, @required User user, @required ServiceRequest request}) async {
|
|
|
|
|
Response response;
|
|
|
|
|
try {
|
|
|
|
|
// Map<String, dynamic> body = {
|
|
|
|
|
// "id": 0,
|
|
|
|
|
// "parentWOId": null,
|
|
|
|
|
// "workOrderNo": "",
|
|
|
|
|
// "workOrderYear": null,
|
|
|
|
|
// "workOrderSequennce": null,
|
|
|
|
|
// "callRequest": {
|
|
|
|
|
// "id": request.id,
|
|
|
|
|
// },
|
|
|
|
|
// "assetType": report.assetType?.toJson(),
|
|
|
|
|
// "assignedEmployee": {"id": report.engineer?.id, "name": report.engineer?.name ?? ""},
|
|
|
|
|
// "visitDate": report.returnToService?.toIso8601String() ?? "",
|
|
|
|
|
// // "assistantEmployees": [
|
|
|
|
|
// // {"id": report.engineer.id, "name": report.engineer.name},
|
|
|
|
|
// // ],
|
|
|
|
|
// "supplier": null,
|
|
|
|
|
// "vendorTicketNumber": null,
|
|
|
|
|
// "contactPersonWorkOrders": [
|
|
|
|
|
// {
|
|
|
|
|
// "id": 0,
|
|
|
|
|
// // "employeeCode": "",
|
|
|
|
|
// "name": user.userName,
|
|
|
|
|
// "telephone": user.phoneNumber,
|
|
|
|
|
// // "job": "",
|
|
|
|
|
// "email": user.email,
|
|
|
|
|
// // "land": "",
|
|
|
|
|
// "contactUserId": user.userID,
|
|
|
|
|
// }
|
|
|
|
|
// ],
|
|
|
|
|
// "calllastSituation": report.callLastSituation?.toJson(),
|
|
|
|
|
// "currentSituation": null,
|
|
|
|
|
// "repairLocation": report.repairLocation?.toJson(),
|
|
|
|
|
// "reason": report.reason?.toJson(),
|
|
|
|
|
// "startofWorkTime": report.timer?.startAt?.toIso8601String() ?? "",
|
|
|
|
|
// "endofWorkTime": report.timer?.endAt?.toIso8601String() ?? "",
|
|
|
|
|
// "workingHours": report?.workingHours,
|
|
|
|
|
// "travelingHours": report.travelingHours,
|
|
|
|
|
// "travelingExpenses": report.travelingExpense ?? 0,
|
|
|
|
|
// if (report.faultDescription != null) "faultDescription": report.faultDescription.toJson(),
|
|
|
|
|
// "sparePartsWorkOrders": report.parts
|
|
|
|
|
// ?.map(
|
|
|
|
|
// (p) => {
|
|
|
|
|
// "id": p.reportPartID ?? 0,
|
|
|
|
|
// "sparePart": {"id": p.id, "partNo": p.partNo, "partName": p.partName},
|
|
|
|
|
// "qty": p.quantity
|
|
|
|
|
// },
|
|
|
|
|
// )
|
|
|
|
|
// ?.toList(),
|
|
|
|
|
// "reviewComment": "",
|
|
|
|
|
// "comment": report.comment,
|
|
|
|
|
// "attachmentsWorkOrder": request.devicePhotos?.map((e) => {"name": e})?.toList(),
|
|
|
|
|
// "equipmentStatus": report.equipmentStatus?.toJson(),
|
|
|
|
|
// "suppEngineerWorkOrders": null,
|
|
|
|
|
// "engSignature": report.signatureEngineer,
|
|
|
|
|
// "nurseSignature": report.signatureNurse,
|
|
|
|
|
// "woParentDto": null,
|
|
|
|
|
// };
|
|
|
|
|
// body["uid"] = user.id;
|
|
|
|
|
// body["token"] = user.token;
|
|
|
|
|
response = await ApiManager.instance.post(URLs.createServiceReport, body: {});
|
|
|
|
|
// response = await post(
|
|
|
|
|
// Uri.parse(
|
|
|
|
|
// host+URLs.createServiceReport),
|
|
|
|
|
// body: body,
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
|
|
|
|
final body = report.toJson();
|
|
|
|
|
final callRequest = CallRequest(id: num.tryParse(request?.id ?? "")).toJson();
|
|
|
|
|
final contactPerson = [
|
|
|
|
|
{
|
|
|
|
|
"id": 0,
|
|
|
|
|
// "employeeCode": "",
|
|
|
|
|
"name": user.userName,
|
|
|
|
|
"telephone": user.phoneNumber,
|
|
|
|
|
// "job": "",
|
|
|
|
|
"email": user.email,
|
|
|
|
|
// "land": "",
|
|
|
|
|
"contactUserId": user.userID,
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
body.update("contactPersonWorkOrders", (value) => contactPerson, ifAbsent: () => contactPerson);
|
|
|
|
|
body.update("callRequest", (value) => callRequest, ifAbsent: () => callRequest);
|
|
|
|
|
response = await ApiManager.instance.post(URLs.createServiceReport, body: body);
|
|
|
|
|
stateCode = response.statusCode;
|
|
|
|
|
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}: ${json.decode(response.body)['message']}");
|
|
|
|
|
}
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
return response.statusCode;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
print(error);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|