import 'package:flutter/src/widgets/framework.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/models/device/device.dart'; import 'asset_transfer_attachment.dart'; class AssetTransfer { AssetTransfer({ this.id, this.transferNo, this.transferCode, this.assetId, this.destSiteId, this.destBuildingId, this.destFloorId, this.destDepartmentId, this.destRoom, this.senderSiteId, this.senderBuildingId, this.senderFloorId, this.senderDepartmentId, this.senderRoom, this.senderAssignedEmployeeId, this.senderMachineStatusId, this.senderComment, this.senderStartDate, this.senderEndDate, this.senderWorkingHours, this.senderTravelingHours, this.senderEngSignature, this.senderAttachments, this.receiverAssignedEmployeeId, this.receiverMachineStatusId, this.receiverComment, this.receiverStartDate, this.receiverEndDate, this.receiverWorkingHours, this.receiverTravelingHours, this.receiverEngSignature, this.receiverAttachments, }); AssetTransfer.fromJson(dynamic json) { id = json['id']; transferNo = json['transferNo']; transferCode = json['transferCode']; assetId = json['assetId']; destSiteId = json['destSiteId']; destBuildingId = json['destBuildingId']; destFloorId = json['destFloorId']; destDepartmentId = json['destDepartmentId']; destRoom = json['destRoom']; senderSiteId = json['senderSiteId']; senderBuildingId = json['senderBuildingId']; senderFloorId = json['senderFloorId']; senderDepartmentId = json['senderDepartmentId']; senderRoom = json['senderRoom']; senderAssignedEmployeeId = json['senderAssignedEmployeeId']; senderMachineStatusId = json['senderMachineStatusId']; senderComment = json['senderComment']; senderStartDate = json['senderStartDate']; senderEndDate = json['senderEndDate']; senderWorkingHours = json['senderWorkingHours']; senderTravelingHours = json['senderTravelingHours']; senderEngSignature = json['senderEngSignature']; if (json['senderAttachments'] != null) { senderAttachments = []; json['senderAttachments'].forEach((v) { senderAttachments.add(AssetTransferAttachment.fromJson(v)); }); } receiverAssignedEmployeeId = json['receiverAssignedEmployeeId']; receiverMachineStatusId = json['receiverMachineStatusId']; receiverComment = json['receiverComment']; receiverStartDate = json['receiverStartDate']; receiverEndDate = json['receiverEndDate']; receiverWorkingHours = json['receiverWorkingHours']; receiverTravelingHours = json['receiverTravelingHours']; receiverEngSignature = json['receiverEngSignature']; if (json['receiverAttachments'] != null) { receiverAttachments = []; json['receiverAttachments'].forEach((v) { receiverAttachments.add(AssetTransferAttachment.fromJson(v)); }); } } num id; num transferNo; String transferCode; num assetId; num destSiteId; num destBuildingId; num destFloorId; num destDepartmentId; String destRoom; num senderSiteId; num senderBuildingId; num senderFloorId; num senderDepartmentId; String senderRoom; String senderAssignedEmployeeId; num senderMachineStatusId; String senderComment; String senderStartDate; String senderEndDate; String senderWorkingHours; String senderTravelingHours; String senderEngSignature; List senderAttachments; String receiverAssignedEmployeeId; num receiverMachineStatusId; String receiverComment; String receiverStartDate; String receiverEndDate; String receiverWorkingHours; String receiverTravelingHours; String receiverEngSignature; List receiverAttachments; AssetTransfer copyWith({ num id, num transferNo, String transferCode, num assetId, num destSiteId, num destBuildingId, num destFloorId, num destDepartmentId, String destRoom, num senderSiteId, num senderBuildingId, num senderFloorId, num senderDepartmentId, String senderRoom, String senderAssignedEmployeeId, num senderMachineStatusId, String senderComment, String senderStartDate, String senderEndDate, String senderWorkingHours, String senderTravelingHours, String senderEngSignature, List senderAttachments, String receiverAssignedEmployeeId, num receiverMachineStatusId, String receiverComment, String receiverStartDate, String receiverEndDate, String receiverWorkingHours, String receiverTravelingHours, String receiverEngSignature, List receiverAttachments, }) => AssetTransfer( id: id ?? this.id, transferNo: transferNo ?? this.transferNo, transferCode: transferCode ?? this.transferCode, assetId: assetId ?? this.assetId, destSiteId: destSiteId ?? this.destSiteId, destBuildingId: destBuildingId ?? this.destBuildingId, destFloorId: destFloorId ?? this.destFloorId, destDepartmentId: destDepartmentId ?? this.destDepartmentId, destRoom: destRoom ?? this.destRoom, senderSiteId: senderSiteId ?? this.senderSiteId, senderBuildingId: senderBuildingId ?? this.senderBuildingId, senderFloorId: senderFloorId ?? this.senderFloorId, senderDepartmentId: senderDepartmentId ?? this.senderDepartmentId, senderRoom: senderRoom ?? this.senderRoom, senderAssignedEmployeeId: senderAssignedEmployeeId ?? this.senderAssignedEmployeeId, senderMachineStatusId: senderMachineStatusId ?? this.senderMachineStatusId, senderComment: senderComment ?? this.senderComment, senderStartDate: senderStartDate ?? this.senderStartDate, senderEndDate: senderEndDate ?? this.senderEndDate, senderWorkingHours: senderWorkingHours ?? this.senderWorkingHours, senderTravelingHours: senderTravelingHours ?? this.senderTravelingHours, senderEngSignature: senderEngSignature ?? this.senderEngSignature, senderAttachments: senderAttachments ?? this.senderAttachments, receiverAssignedEmployeeId: receiverAssignedEmployeeId ?? this.receiverAssignedEmployeeId, receiverMachineStatusId: receiverMachineStatusId ?? this.receiverMachineStatusId, receiverComment: receiverComment ?? this.receiverComment, receiverStartDate: receiverStartDate ?? this.receiverStartDate, receiverEndDate: receiverEndDate ?? this.receiverEndDate, receiverWorkingHours: receiverWorkingHours ?? this.receiverWorkingHours, receiverTravelingHours: receiverTravelingHours ?? this.receiverTravelingHours, receiverEngSignature: receiverEngSignature ?? this.receiverEngSignature, receiverAttachments: receiverAttachments ?? this.receiverAttachments, ); Map toJson() { final map = {}; map['id'] = id; map['transferNo'] = transferNo; map['transferCode'] = transferCode; map['assetId'] = assetId; map['destSiteId'] = destSiteId; map['destBuildingId'] = destBuildingId; map['destFloorId'] = destFloorId; map['destDepartmentId'] = destDepartmentId; map['destRoom'] = destRoom; map['senderSiteId'] = senderSiteId; map['senderBuildingId'] = senderBuildingId; map['senderFloorId'] = senderFloorId; map['senderDepartmentId'] = senderDepartmentId; map['senderRoom'] = senderRoom; map['senderAssignedEmployeeId'] = senderAssignedEmployeeId; map['senderMachineStatusId'] = senderMachineStatusId; map['senderComment'] = senderComment; map['senderStartDate'] = senderStartDate; map['senderEndDate'] = senderEndDate; map['senderWorkingHours'] = senderWorkingHours; map['senderTravelingHours'] = senderTravelingHours; map['senderEngSignature'] = senderEngSignature; if (senderAttachments != null) { map['senderAttachments'] = senderAttachments.map((v) => v.toJson()).toList(); } map['receiverAssignedEmployeeId'] = receiverAssignedEmployeeId; map['receiverMachineStatusId'] = receiverMachineStatusId; map['receiverComment'] = receiverComment; map['receiverStartDate'] = receiverStartDate; map['receiverEndDate'] = receiverEndDate; map['receiverWorkingHours'] = receiverWorkingHours; map['receiverTravelingHours'] = receiverTravelingHours; map['receiverEngSignature'] = receiverEngSignature; if (receiverAttachments != null) { map['receiverAttachments'] = receiverAttachments.map((v) => v.toJson()).toList(); } return map; } Map transferBody({Device asset}) { final map = {}; map['id'] = 0; map['transferNo'] = transferNo; map['transferCode'] = transferCode; map['assetId'] = asset?.id; map['destSiteId'] = destSiteId; map['destBuildingId'] = destBuildingId; map['destFloorId'] = destFloorId; map['destDepartmentId'] = destDepartmentId; map['destRoom'] = destRoom; map['senderSiteId'] = asset?.site?.id; map['senderBuildingId'] = asset?.building?.id; map['senderFloorId'] = asset?.floor?.id; map['senderDepartmentId'] = asset?.department?.id; map['senderRoom'] = asset?.room; map['senderAssignedEmployeeId'] = senderAssignedEmployeeId; map['senderMachineStatusId'] = senderMachineStatusId; map['senderComment'] = senderComment; map['senderStartDate'] = senderStartDate; map['senderEndDate'] = senderEndDate; map['senderWorkingHours'] = senderWorkingHours; map['senderTravelingHours'] = senderTravelingHours; map['senderEngSignature'] = senderEngSignature; if (senderAttachments != null) { map['senderAttachments'] = senderAttachments.map((v) => v.toJson()).toList(); } map['receiverAssignedEmployeeId'] = receiverAssignedEmployeeId; map['receiverMachineStatusId'] = receiverMachineStatusId; map['receiverComment'] = receiverComment; map['receiverStartDate'] = receiverStartDate; map['receiverEndDate'] = receiverEndDate; map['receiverWorkingHours'] = receiverWorkingHours; map['receiverTravelingHours'] = receiverTravelingHours; map['receiverEngSignature'] = receiverEngSignature; if (receiverAttachments != null) { map['receiverAttachments'] = receiverAttachments.map((v) => v.toJson()).toList(); } return map; } Future validate(BuildContext context) async { if (assetId == null) { await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.device}"); return false; } else if (destSiteId == null) { await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.destinationSite}"); return false; } else if (destBuildingId == null) { await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.building}"); return false; } else if (destFloorId == null) { await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.floor}"); return false; } else if (destDepartmentId == null) { await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.department}"); return false; } return true; } }