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/plan_preventive_visit/plan_preventive_visit_model...

589 lines
19 KiB
Dart

import 'dart:developer';
import 'dart:io';
import 'package:flutter/widgets.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/models/device/asset.dart';
import 'package:test_sa/models/helper_data_models/spare_part/activity_spare_part_model.dart';
import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/models/service_request/supplier_details.dart';
import 'package:test_sa/models/timer_model.dart';
class PlanPreventiveVisit {
String? id;
String? visitNo;
Asset? asset;
String? planNo;
String? planName;
String? nextPMDate;
String? assetName;
String? model;
String? manufacturer;
String? supplierName;
String? siteName;
String? buildingName;
String? floorName;
String? departmentName;
String? roomName;
String? fromDate;
String? creationDate;
String? createdDate;
String? closedDate;
String? toDate;
AssignedEmployee? assignedEmployee;
DateTime? acutalDateOfVisit;
Lookup? typeOfService;
Lookup? visitStatus;
num? travelingHours;
String? comments;
int? executionTimeFrame;
Lookup? taskStatus;
Lookup? deviceStatus;
Lookup? assetAvailability = Lookup();
Lookup? safety;
String? engSignature;
String? nurseSignature;
List<PreventiveVisitAttachments>? preventiveVisitAttachments;
List<File>? attachments = [];
List<PreventiveVisitCalibrations>? preventiveVisitCalibrations;
List<PreventiveVisitChecklists>? preventiveVisitChecklists;
List<PreventiveVisitKits>? preventiveVisitKits;
List<PreventiveVisitTimers>? preventiveVisitTimers;
List<PreventiveVisitSuppliers>? preventiveVisitSuppliers;
List<PMSparePartActivityModel>? activities;
num? sparePartCost;
num? labourCost;
num? travelCost;
num? qAmount;
String? prNo;
String? poNo;
String? mrNo;
num? exchangeCost;
TimerModel? tbsTimer = TimerModel();
List<TimerModel>? timerModelList = [];
TimerModel? ppMTimePicker;
PlanPreventiveVisit(
{this.id,
this.visitNo,
this.asset,
this.planNo,
this.planName,
this.nextPMDate,
this.assetName,
this.model,
this.manufacturer,
this.supplierName,
this.siteName,
this.buildingName,
this.floorName,
this.departmentName,
this.roomName,
this.fromDate,
this.creationDate,
this.createdDate,
this.closedDate,
this.toDate,
this.assignedEmployee,
this.acutalDateOfVisit,
this.typeOfService,
this.visitStatus,
this.travelingHours,
this.comments,
this.executionTimeFrame,
this.taskStatus,
this.deviceStatus,
this.assetAvailability,
this.safety,
this.engSignature,
this.nurseSignature,
this.preventiveVisitAttachments,
this.attachments,
this.preventiveVisitCalibrations,
this.preventiveVisitChecklists,
this.preventiveVisitKits,
this.preventiveVisitTimers,
this.timerModelList,
this.ppMTimePicker,
this.activities,
this.labourCost,
this.sparePartCost,
this.travelCost,
this.qAmount,
this.prNo,
this.poNo,
this.mrNo,
this.exchangeCost,
this.preventiveVisitSuppliers});
PlanPreventiveVisit.fromJson(Map<String, dynamic> json) {
id = json['id'];
visitNo = json['visitNo'];
asset = json['asset'] != null ? Asset.fromJson(json['asset']) : null;
planNo = json['planNo'];
planName = json['planName'];
nextPMDate = json['nextPMDate'];
assetName = json['assetName'];
model = json['model'];
manufacturer = json['manufacturer'];
supplierName = json['supplierName'];
siteName = json['siteName'];
buildingName = json['buildingName'];
floorName = json['floorName'];
departmentName = json['departmentName'];
roomName = json['roomName'];
fromDate = json['fromDate'];
creationDate = json['creationDate'];
createdDate = json['createdDate'];
closedDate = json['closedDate'];
toDate = json['toDate'];
assignedEmployee = json['assignedEmployee'] != null ? AssignedEmployee.fromJson(json['assignedEmployee']) : null;
acutalDateOfVisit = json['acutalDateOfVisit'] != null ? DateTime.parse(json['acutalDateOfVisit']) : null;
typeOfService = json['typeOfService'] != null ? Lookup.fromJson(json['typeOfService']) : null;
visitStatus = json['visitStatus'] != null ? Lookup.fromJson(json['visitStatus']) : null;
travelingHours = json['travelingHours'];
comments = json['comments'];
executionTimeFrame = json['executionTimeFrame'];
taskStatus = json['taskStatus'] != null ? Lookup.fromJson(json['taskStatus']) : null;
deviceStatus = json['deviceStatus'] != null ? Lookup.fromJson(json['deviceStatus']) : null;
assetAvailability = json['assetAvailability'] != null ? Lookup.fromJson(json['assetAvailability']) : null;
safety = json['safety'] != null ? Lookup.fromJson(json['safety']) : null;
engSignature = json['engSignature'];
nurseSignature = json['nurseSignature'];
travelCost= json['travelCost'];
sparePartCost= json['sparePartCost'];
labourCost =json['laborCost'];
qAmount= json['qAmount'];
prNo= json['prNo'];
poNo= json['poNo'];
mrNo= json['mrNo'];
exchangeCost= json['exchangeCost'];
if (json['preventiveVisitAttachments'] != null) {
preventiveVisitAttachments = <PreventiveVisitAttachments>[];
json['preventiveVisitAttachments'].forEach((v) {
preventiveVisitAttachments!.add(PreventiveVisitAttachments.fromJson(v));
});
}
if (json['preventiveVisitCalibrations'] != null) {
preventiveVisitCalibrations = <PreventiveVisitCalibrations>[];
json['preventiveVisitCalibrations'].forEach((v) {
preventiveVisitCalibrations!.add(PreventiveVisitCalibrations.fromJson(v));
});
}
if (json['preventiveVisitChecklists'] != null) {
preventiveVisitChecklists = <PreventiveVisitChecklists>[];
json['preventiveVisitChecklists'].forEach((v) {
preventiveVisitChecklists!.add(PreventiveVisitChecklists.fromJson(v));
});
}
if (json['preventiveVisitKits'] != null) {
preventiveVisitKits = <PreventiveVisitKits>[];
json['preventiveVisitKits'].forEach((v) {
preventiveVisitKits!.add(PreventiveVisitKits.fromJson(v));
});
}
if (json['preventiveVisitTimers'] != null) {
preventiveVisitTimers = <PreventiveVisitTimers>[];
json['preventiveVisitTimers'].forEach((v) {
preventiveVisitTimers!.add(PreventiveVisitTimers.fromJson(v));
});
}
if (json['preventiveVisitSuppliers'] != null) {
preventiveVisitSuppliers = <PreventiveVisitSuppliers>[];
json['preventiveVisitSuppliers'].forEach((v) {
preventiveVisitSuppliers!.add(PreventiveVisitSuppliers.fromJson(v));
});
}
if (json['activitySparePartsPPM'] != null) {
activities = <PMSparePartActivityModel>[];
json['activitySparePartsPPM'].forEach((v) {
activities!.add(PMSparePartActivityModel.fromJson(v));
});
}
}
Map<String, dynamic> toJson({required int status}) {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['acutalDateOfVisit'] = acutalDateOfVisit?.toIso8601String();
data['typeOfServiceId'] = typeOfService?.id;
data['visitStatusValue'] = status;
data['travelingHours'] = travelingHours;
data['comments'] = comments;
data['taskStatusId'] = taskStatus?.id;
data['deviceStatusId'] = deviceStatus?.id;
data['assetAvailabilityId'] = assetAvailability?.id;
data['safetyId'] = safety?.id;
data['engSignature'] = engSignature;
data['nurseSignature'] = nurseSignature;
if (preventiveVisitAttachments != null) {
data['preventiveVisitAttachments'] = preventiveVisitAttachments!.map((v) => v.toJson()).toList();
}
if (preventiveVisitCalibrations != null) {
data['preventiveVisitCalibrations'] = preventiveVisitCalibrations!.map((v) => v.toJson()).toList();
}
if (preventiveVisitChecklists != null) {
data['preventiveVisitChecklists'] = preventiveVisitChecklists!.map((v) => v.toJson()).toList();
}
if (preventiveVisitKits != null) {
data['preventiveVisitKits'] = preventiveVisitKits!.map((v) => v.toJson()).toList();
}
if (preventiveVisitTimers != null) {
data['preventiveVisitTimers'] = preventiveVisitTimers!.map((v) => v.toJson()).toList();
}
if (preventiveVisitSuppliers != null) {
data['preventiveVisitSuppliers'] = preventiveVisitSuppliers!.map((v) => v.toJson()).toList();
}
if (activities != null) {
data['activitySparePartsPPM'] = activities!.map((v) => v.toJson()).toList();
}
return data;
}
Future<bool> validate(BuildContext context) async {
if (visitStatus?.id == null) {
await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.status}");
return false;
}
if (acutalDateOfVisit == null) {
await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.actualDate}");
return false;
}
// if (expectedDate == null) {
// await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.visitDate}");
// return false;
// }
if (tbsTimer?.startAt == null) {
await Fluttertoast.showToast(msg: "Working Hours Required");
return false;
}
if (tbsTimer?.endAt == null) {
await Fluttertoast.showToast(msg: "Please Stop The Timer");
return false;
}
// if (externalEngineerTimer?.startAt != null && externalEngineerTimer?.endAt == null) {
// await Fluttertoast.showToast(msg: "Please Stop External Engineer Timer");
// return false;
// }
return true;
}
void removeEmptyObjects() {
// if (vCalibrationTools?.isNotEmpty ?? false) vCalibrationTools!.removeWhere((element) => element.assetId == null && element.calibrationDateOfTesters == null);
// if (vKits?.isNotEmpty ?? false) vKits!.removeWhere((element) => element.partName == null && element.partNumber == null);
}
}
class AssignedEmployee {
String? userId;
String? userName;
String? email;
String? employeeId;
int? languageId;
AssignedEmployee({this.userId, this.userName, this.email, this.employeeId, this.languageId});
AssignedEmployee.fromJson(Map<String, dynamic> json) {
userId = json['userId'];
userName = json['userName'];
email = json['email'];
employeeId = json['employeeId'];
languageId = json['languageId'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>();
data['userId'] = this.userId;
data['userName'] = this.userName;
data['email'] = this.email;
data['employeeId'] = this.employeeId;
data['languageId'] = this.languageId;
return data;
}
}
class PreventiveVisitChecklists {
int? id;
Lookup? taskStatus;
String? taskComment;
String? measuredValue;
InstructionText? instructionText;
PreventiveVisitChecklists({this.id, this.taskStatus, this.taskComment, this.measuredValue, this.instructionText});
PreventiveVisitChecklists.fromJson(Map<String, dynamic> json) {
id = json['id'];
taskStatus = json['taskStatus'] != null ? Lookup.fromJson(json['taskStatus']) : null;
taskComment = json['taskComment'];
measuredValue = json['measuredValue'];
instructionText = json['instructionText'] != null ? InstructionText.fromJson(json['instructionText']) : null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['taskStatusId'] = taskStatus?.id;
data['taskComment'] = taskComment;
data['measuredValue'] = measuredValue;
// if (instructionText != null) {
// data['instructionText'] = instructionText!.toJson();
// }
return data;
}
}
class InstructionText {
int? id;
String? text;
InstructionText({this.id, this.text});
InstructionText.fromJson(Map<String, dynamic> json) {
id = json['id'];
text = json['text'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['text'] = text;
return data;
}
}
class PreventiveVisitTimers {
int? id;
String? startDateTime;
String? endDateTime;
double? workingHours;
PreventiveVisitTimers({this.id, this.startDateTime, this.endDateTime, this.workingHours});
PreventiveVisitTimers.fromJson(Map<String, dynamic> json) {
id = json['id'];
startDateTime = json['startDateTime'];
endDateTime = json['endDateTime'];
workingHours = json['workingHours'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['startDateTime'] = startDateTime;
data['endDateTime'] = endDateTime;
data['workingHours'] = workingHours;
return data;
}
}
class PreventiveVisitAttachments {
int? id;
String? attachmentName;
PreventiveVisitAttachments({this.id, this.attachmentName});
PreventiveVisitAttachments.fromJson(Map<String, dynamic> json) {
id = json['id'];
attachmentName = json['attachmentName'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['attachmentName'] = attachmentName;
return data;
}
}
class PreventiveVisitCalibrations {
num? id;
Asset? asset;
String? calibrationDateOfTesters;
PreventiveVisitCalibrations({this.id, this.asset, this.calibrationDateOfTesters});
PreventiveVisitCalibrations.fromJson(Map<String, dynamic> json) {
id = json['id'];
asset = json['asset'] != null ? Asset.fromJson(json['asset']) : null;
calibrationDateOfTesters = json['calibrationDateOfTesters'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
if (asset != null) {
// data['asset'] = asset!.toJson();
data['assetId'] = asset?.id;
}
data['calibrationDateOfTesters'] = calibrationDateOfTesters;
return data;
}
}
class PreventiveVisitSuppliers {
int? id;
SupplierDetails? supplier;
SuppPersons? suppPerson;
DateTime? startDateTime;
DateTime? endDateTime;
TextEditingController? workingHoursController;
num? workingHours;
PreventiveVisitSuppliers({this.id, this.supplier, this.suppPerson, this.startDateTime, this.endDateTime, this.workingHours, this.workingHoursController});
PreventiveVisitSuppliers.fromJson(Map<String, dynamic> json) {
id = json['id'];
supplier = json['supplier'] != null ? SupplierDetails.fromJson(json['supplier']) : null;
suppPerson = json['suppPerson'] != null ? SuppPersons.fromJson(json['suppPerson']) : null;
startDateTime = json['startDateTime'] != null ? DateTime.parse(json['startDateTime']) : null;
endDateTime = json['endDateTime'] != null ? DateTime.parse(json['endDateTime']) : null;
workingHours = json['workingHours'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
if (supplier != null) {
// data['supplier'] = supplier!.toJson();
data['supplierId'] = supplier?.id;
}
if (suppPerson != null) {
// data['suppPerson'] = suppPerson!.toJson();
data['suppPersonId'] = suppPerson?.id;
}
data['startDateTime'] = startDateTime?.toIso8601String();
data['endDateTime'] = endDateTime?.toIso8601String();
data['workingHours'] = workingHours;
return data;
}
}
class PreventiveVisitKits {
int? id;
PartCatalogItem? partCatalogItem;
PreventiveVisitKits({this.id, partCatalogItem});
PreventiveVisitKits.fromJson(Map<String, dynamic> json) {
id = json['id'];
partCatalogItem = json['partCatalogItem'] != null ? PartCatalogItem.fromJson(json['partCatalogItem']) : null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
if (partCatalogItem != null) {
data['partCatalogItemId'] = partCatalogItem?.id;
}
return data;
}
}
class PartCatalogItem {
num? id;
String? partName;
String? partNumber;
String? oracleCode;
PartCatalogItem({this.id, this.partName, this.partNumber, this.oracleCode});
PartCatalogItem.fromJson(Map<String, dynamic> json) {
id = json['id'];
partName = json['partName'];
partNumber = json['partNumber'];
oracleCode = json['oracleCode'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['partName'] = partName;
data['partNumber'] = partNumber;
data['oracleCode'] = oracleCode;
return data;
}
}
class PMSparePartActivityModel {
int? id;
PartCatalogItem? partCatalogItem;
Lookup? activityStatus;
double? quantity;
double? installQty;
double? returnQty;
String? comment;
dynamic price;
List<SparePartAttachments> activitySparePartPPMAttachments;
PMSparePartActivityModel({
this.id,
this.partCatalogItem,
this.activityStatus,
this.quantity,
this.installQty,
this.returnQty,
this.comment,
this.price,
List<SparePartAttachments>? activitySparePartPPMAttachments,
}) : activitySparePartPPMAttachments = activitySparePartPPMAttachments ?? [];
PMSparePartActivityModel.fromJson(Map<String, dynamic> json) : activitySparePartPPMAttachments = [] {
id = json['id'];
partCatalogItem = json['partCatalogItem'] != null ? PartCatalogItem.fromJson(json['partCatalogItem']) : null;
activityStatus = json['activityStatus'] != null ? Lookup.fromJson(json['activityStatus']) : null;
quantity = json['quantity']?.toDouble();
installQty = json['installQty']?.toDouble();
returnQty = json['returnQty']?.toDouble();
comment = json['comment'];
price = json['price'];
// Handle typo in API response: "acitiySparePartPPMAttachments" instead of "activitySparePartPPMAttachments"
final attachmentsKey = json.containsKey('acitiySparePartPPMAttachments')
? 'acitiySparePartPPMAttachments'
: 'activitySparePartPPMAttachments';
activitySparePartPPMAttachments = json[attachmentsKey] == null
? []
: List.from(json[attachmentsKey]).map((e) => SparePartAttachments.fromJson(e)).toList();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = {};
data['id'] = id;
if (partCatalogItem != null) {
data['partCatalogItem'] = partCatalogItem!.toJson();
}
if (activityStatus != null) {
data['activityStatus'] = activityStatus!.toJson();
}
data['quantity'] = quantity;
data['installQty'] = installQty;
data['returnQty'] = returnQty;
data['comment'] = comment;
data['price'] = price;
data['activitySparePartPPMAttachments'] = activitySparePartPPMAttachments
.map(
(v) => v.toJson(),
)
.toList();
return data;
}
}