You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/models/service_request/service_request.dart

159 lines
5.8 KiB
Dart

import 'package:flutter/src/widgets/framework.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:test_sa/controllers/api_routes/urls.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/models/device/device.dart';
import 'package:test_sa/models/fault_description.dart';
import 'package:test_sa/models/lookup.dart';
class ServiceRequest {
String id;
String requestCode;
String deviceSerialNumber;
int deviceId;
String deviceArName;
String deviceEnName;
List<String> devicePhotos;
String callComments;
String hospitalName;
int hospitalId;
String departmentName;
String engineerName;
String engineerId;
String date;
String audio;
int statusValue;
int statusId;
String statusLabel;
String reviewComment;
String comments;
bool viewReport;
String engineerMobile;
String deviceModel;
FaultDescription faultDescription;
//String workPerformed;
String visitDate;
DateTime nextVisitDate;
String jobSheetNumber;
int reportID;
String deviceNumber;
Lookup priority;
Lookup defectType;
Lookup type;
Lookup requestedThrough;
Lookup firstAction;
Lookup loanAvailability;
Device device;
ServiceRequest({
this.id,
this.date,
this.requestCode,
this.hospitalName,
this.deviceArName,
this.deviceEnName,
this.devicePhotos,
this.hospitalId,
this.deviceSerialNumber,
this.callComments,
this.statusLabel,
this.statusValue,
this.statusId,
this.departmentName,
this.deviceId,
this.audio,
this.engineerName,
this.engineerId,
this.viewReport = false,
this.deviceModel,
this.engineerMobile,
this.faultDescription,
this.jobSheetNumber,
this.visitDate,
this.nextVisitDate,
//this.workPerformed,
this.reportID,
this.defectType,
this.priority,
this.deviceNumber,
this.type,
this.requestedThrough,
this.device,
this.reviewComment,
this.comments,
this.loanAvailability,
this.firstAction,
});
factory ServiceRequest.fromJson(Map<String, dynamic> parsedJson) {
List<String> images = [];
if (parsedJson["attachmentsCallRequest"] != null) if (parsedJson["attachmentsCallRequest"] is List) {
List list = parsedJson["attachmentsCallRequest"];
images = list.map((e) => URLs.getFileUrl(e["name"])).toList();
}
// print(parsedJson["requestedDate"]??"");
return ServiceRequest(
id: parsedJson["id"].toString(),
requestCode: parsedJson["callNo"].toString(),
hospitalName: parsedJson["asset"]["site"]["custName"],
deviceNumber: parsedJson["asset"]["assetNumber"].toString(),
deviceId: parsedJson["asset"]["id"],
audio: URLs.getFileUrl(parsedJson["voiceNote"] ?? ""),
deviceArName: parsedJson["asset"]["modelDefinition"]["assetName"] ?? "",
deviceEnName: parsedJson["asset"]["modelDefinition"]["assetName"] ?? "",
devicePhotos: images,
deviceSerialNumber: parsedJson["asset"]["assetSerialNo"],
date: DateTime.tryParse(parsedJson["requestedDate"] ?? "").toString(),
// todo. add requeste time param for time
callComments: parsedJson["callComments"],
comments: parsedJson["comments"],
statusLabel: parsedJson["status"] == null ? null : parsedJson["status"]["name"],
statusValue: parsedJson["status"] == null ? null : parsedJson["status"]["value"],
statusId: parsedJson["status"] == null ? null : parsedJson["status"]["id"],
departmentName: parsedJson["asset"]["department"] != null ? parsedJson["asset"]["department"]["name"] : "",
engineerName: parsedJson["assignedEmployee"] == null ? null : parsedJson["assignedEmployee"]["name"],
engineerId: parsedJson["assignedEmployee"] == null ? null : parsedJson["assignedEmployee"]["id"],
hospitalId: parsedJson["asset"]["site"]["id"],
reportID: parsedJson["workOrder"] != null ? parsedJson["workOrder"]["workOrderId"] : null,
viewReport: parsedJson["workOrder"] != null,
deviceModel: parsedJson["asset"]["modelDefinition"]["modelName"],
engineerMobile: parsedJson["assignedEmployee"] == null ? null : parsedJson["assignedEmployee"]["phone"],
faultDescription: parsedJson["workOrder"] != null
? parsedJson["workOrder"]["faultDescription"] != null
? FaultDescription.fromJson(parsedJson["workOrder"]["faultDescription"])
: null
: null,
jobSheetNumber: parsedJson["workOrder"] != null ? parsedJson["workOrder"]["jobSheetNumber"] : null,
visitDate: DateTime.tryParse(parsedJson["visitDate"] ?? "").toString().split(" ").first,
nextVisitDate: DateTime.tryParse(parsedJson["nextVisitDate"] ?? ""),
//workPerformed: parsedJson["workOrder"] != null ? parsedJson["workOrder"]["workPerformed"] : null,
device: Device.fromJson(parsedJson["asset"]),
reviewComment: parsedJson["reviewComment"],
type: Lookup.fromJson(parsedJson['typeofRequest']),
defectType: Lookup.fromJson(parsedJson['defectType']),
loanAvailability: Lookup.fromJson(parsedJson['loanAvailablity']),
firstAction: Lookup.fromJson(parsedJson['firstAction']),
requestedThrough: Lookup.fromJson(parsedJson['requestedThrough']),
priority: Lookup.fromJson(parsedJson['priority']),
);
}
Future<bool> validateNewRequest(BuildContext context) async {
if (device == null) {
await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.device}");
return false;
} else if (priority == null) {
await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.priority}");
return false;
} else if (defectType == null) {
await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.equipmentStatus}");
return false;
}
return true;
}
}