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_report.dart

186 lines
6.8 KiB
Dart

3 years ago
import 'dart:typed_data';
3 years ago
3 years ago
import 'package:test_sa/controllers/api_routes/urls.dart';
3 years ago
import 'package:test_sa/models/device/device.dart';
3 years ago
import 'package:test_sa/models/engineer.dart';
import 'package:test_sa/models/lookup.dart';
3 years ago
import 'package:test_sa/models/part.dart';
import 'package:test_sa/models/service_request/service_request.dart';
3 years ago
import 'package:test_sa/models/timer_model.dart';
class ServiceReport {
3 years ago
int id;
3 years ago
String operatingHours;
DateTime visitDate;
DateTime endDate;
3 years ago
Lookup assetType;
Lookup callLastSituation;
3 years ago
Engineer engineer;
Lookup status;
Lookup type;
Lookup reason;
3 years ago
int faultDescriptionId;
3 years ago
String workPreformed;
//String workHours;
String travelingHours;
String invoiceNumber;
String invoiceCode;
List<Part> parts;
String image;
Device device;
String quantity;
String jobSheetNumber;
TimerModel timer;
3 years ago
String signatureNurse;
String signatureEngineer;
Uint8List localNurseSignature;
Uint8List localEngineerSignature;
3 years ago
ServiceReport({
this.id,
this.visitDate,
this.endDate,
3 years ago
this.assetType,
3 years ago
this.status,
this.type,
3 years ago
this.faultDescriptionId,
3 years ago
//this.workHours,
this.travelingHours,
this.parts,
3 years ago
this.engineer,
3 years ago
this.workPreformed,
this.reason,
this.operatingHours,
this.callLastSituation,
this.jobSheetNumber,
this.image,
this.device,
this.invoiceCode,
this.invoiceNumber,
this.quantity = "1",
this.timer,
3 years ago
this.signatureNurse,
this.signatureEngineer,
this.localNurseSignature,
this.localEngineerSignature
3 years ago
});
3 years ago
Map<String,dynamic> toMap(ServiceRequest request){
Map<String,dynamic> _map = {};
3 years ago
if(id != null) _map["id"] = id;
3 years ago
if(visitDate != null) _map["visitDate"] = visitDate.toIso8601String();
//if(serviceType != null) _map["service_type"] = serviceType.id.toString();
if(status != null) _map["status"] = status?.toMap();
if(type != null) _map["typeOfWO"] = type?.toMap();
if(assetType != null) _map["TypeOfWO"] = assetType?.toMap();
//if(faultDescriptionId != null && faultDescriptionId.isNotEmpty) _map["fault_description"] = faultDescriptionId;
3 years ago
//if(workHours != null && workHours.isNotEmpty) _map["working_hours"] = workHours;
if(timer != null){
3 years ago
_map["startofWorkTime"] = timer.startAt.toIso8601String();
_map["endofWorkTime"] = (timer.endAt ?? DateTime.now()).toIso8601String();
_map["workingHours"] = (timer.durationInSecond / 60 / 60).toStringAsFixed(5);
3 years ago
}
if(travelingHours != null && travelingHours.isNotEmpty) _map["traveling_hours"] = travelingHours;
3 years ago
// if(workPreformed != null && workPreformed.isNotEmpty){
// _map["faultDescription"] = {
// //"id":faultDescriptionId ?? 0,
// "workPerformed":workPreformed
// };
// }
3 years ago
if(jobSheetNumber != null && jobSheetNumber.isNotEmpty) _map["job_sheet_no"] = jobSheetNumber;
if(parts != null && parts.isNotEmpty){
3 years ago
_map["sparePartsWorkOrders"] = parts.map((e) => e.toJson()).toList();
}
if(device != null && device.id != null){
_map["callRequest"] = {
"id":request.id,
"asset":device?.toMap(assetType),
};
_map["callRequest"]["asset"]["invoiceNumber"] = invoiceNumber;
3 years ago
}
3 years ago
_map["AssignedEmployee"] = engineer?.toMap();
//if(quantity != null && quantity.isNotEmpty) _map["qty"] = quantity;
//if(endDate != null) _map["end_date"] = (endDate.millisecondsSinceEpoch ~/ 1000).toString();
if(reason != null) _map["reason"] = reason.toMap();
//if(operatingHours != null && operatingHours.isNotEmpty) _map["operation_hours"] = operatingHours;
if(callLastSituation != null) _map["calllastSituation"] = callLastSituation.toMap();
//if(image != null) _map["image"] = image;
//if(invoiceCode != null) _map["invoice_no"] = invoiceCode;
//if(invoiceNumber != null) _map["invoice_code"] = invoiceNumber;
if(image != null){
_map["attachmentsWorkOrder"]=[{
"name":image
}];
}
_map["nurseSignature"] = signatureNurse;
_map["engSignature"] = signatureEngineer;
3 years ago
return _map;
}
bool validate(){
if(visitDate == null) return false;
3 years ago
//if(serviceType == null) return false;
3 years ago
if(status == null) return false;
if(type == null && assetType==null) return false;
3 years ago
if(engineer == null) return false;
3 years ago
if(callLastSituation == null) return false;
3 years ago
if(callLastSituation?.value == 12){
// if(invoiceCode != null || invoiceCode?.isEmpty == true) return false;
3 years ago
if(invoiceNumber != null || invoiceNumber?.isEmpty== true ) return false;
}
if(parts == null) return false;
//if(endDate == null) return false;
//if(reason == null) return false;
3 years ago
//todo uncoment this line
//if((device?.id == null || device.id.isEmpty) && type?.id != 1) return false;
3 years ago
//if(quantity == null || quantity.isEmpty) return false;
//if(image == null) return false;
return true;
}
3 years ago
factory ServiceReport.fromJson(Map<String,dynamic> parsedJson,int id){
3 years ago
List<Part> _parts = [];
3 years ago
if(parsedJson["sparePartsWorkOrders"] != null){
if(parsedJson["sparePartsWorkOrders"][0]["id"] != null){
List partsList = parsedJson["sparePartsWorkOrders"];
_parts = partsList.map((e) => Part.fromJson(
e["sparePart"],reportJson: e)).toList();
3 years ago
}
}
return ServiceReport(
id: id,
3 years ago
assetType: Lookup.fromJson(parsedJson["assetType"]),
callLastSituation: Lookup.fromJson(parsedJson["calllastSituation"]),
reason: Lookup.fromJson(parsedJson["reason"]),
status: Lookup.fromJson(parsedJson["status"]),
type: Lookup.fromJson(parsedJson["typeOfWO"]),
//faultDescriptionId: parsedJson["fault_description"],
endDate:DateTime.tryParse(parsedJson["endofWorkTime"]),
//invoiceCode: parsedJson["invoice_code"],
//invoiceNumber: parsedJson["invoice_no"],
//jobSheetNumber: parsedJson["job_sheet_no"],
//operatingHours: parsedJson["workingHours"],
engineer: Engineer.fromJson(parsedJson["assignedEmployee"]),
3 years ago
parts: _parts,
3 years ago
//quantity: parsedJson["nid"],
//travelingHours: parsedJson["traveling_hours"],
visitDate: DateTime.tryParse(parsedJson["visitDate"]),
3 years ago
//workHours: parsedJson["working_hours"],
timer: TimerModel(
3 years ago
startAt: DateTime.tryParse(parsedJson["startofWorkTime"]),
endAt: DateTime.tryParse(parsedJson["endofWorkTime"]),
durationInSecond: ((parsedJson["workingHours"] ?? 0) * 60 *60).toInt()
),
//workPreformed: parsedJson["work_performed"],
device: Device.fromJson(parsedJson["callRequest"]["asset"]),
signatureNurse: URLs.getFileUrl(parsedJson["nurseSignature"]) ,
signatureEngineer:URLs.getFileUrl(parsedJson["engSignature"]),
3 years ago
);
}
3 years ago
// static getDate(String date){
// return date == null || date.isEmpty
// ? null : DateTime.fromMillisecondsSinceEpoch(int.tryParse(date) * 1000);
// }
3 years ago
}