From 2932796068f653eaa0751119fc38357d89f4c1d5 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Wed, 17 Jan 2024 11:00:40 +0300 Subject: [PATCH] asset transfer room model & comment added --- lib/models/device/asset.dart | 13 ++++--- lib/models/device/asset_transfer.dart | 10 +++++- lib/models/new_models/department.dart | 28 +++++++++++---- lib/models/new_models/room_model.dart | 26 ++++++++++++++ .../device_transfer_details.dart | 17 +++++---- .../request_device_transfer.dart | 35 ++++++++++--------- 6 files changed, 95 insertions(+), 34 deletions(-) create mode 100644 lib/models/new_models/room_model.dart diff --git a/lib/models/device/asset.dart b/lib/models/device/asset.dart index 9b3775ec..56c4ce90 100644 --- a/lib/models/device/asset.dart +++ b/lib/models/device/asset.dart @@ -1,6 +1,7 @@ import 'package:test_sa/models/device/supplier.dart'; import 'package:test_sa/models/device/technical_guidance_book.dart'; import 'package:test_sa/models/lookup.dart'; +import 'package:test_sa/models/new_models/room_model.dart'; import '../new_models/building.dart'; import '../new_models/department.dart'; @@ -80,7 +81,7 @@ class Asset { building = json['building'] != null ? Building.fromJson(json['building']) : null; floor = json['floor'] != null ? Floor.fromJson(json['floor']) : null; department = json['department'] != null ? Department.fromJson(json['department']) : null; - room = json['room']; + room = json['room'] != null ? Rooms.fromJson(json['room']) : null; testsDay = json['testsDay']; purchasingPrice = json['purchasingPrice']; nbv = json['nbv']; @@ -136,7 +137,8 @@ class Asset { Building building; Floor floor; Department department; - String room; + Rooms room; + // String room; num testsDay; num purchasingPrice; String nbv; @@ -187,7 +189,7 @@ class Asset { Building building, Floor floor, Department department, - String room, + Rooms room, num testsDay, num purchasingPrice, String nbv, @@ -313,7 +315,10 @@ class Asset { if (department != null) { map['department'] = department.toJson(); } - map['room'] = room; + // map['room'] = room; + if (room != null) { + map['room'] = room.toJson(); + } map['testsDay'] = testsDay; map['purchasingPrice'] = purchasingPrice; map['nbv'] = nbv; diff --git a/lib/models/device/asset_transfer.dart b/lib/models/device/asset_transfer.dart index a50592eb..518e51d0 100644 --- a/lib/models/device/asset_transfer.dart +++ b/lib/models/device/asset_transfer.dart @@ -25,6 +25,7 @@ class AssetTransfer { this.senderAssignedEmployeeId, this.senderMachineStatusId, this.senderComment, + this.comment, this.senderStartDate, this.senderEndDate, this.senderWorkingHours, @@ -88,6 +89,7 @@ class AssetTransfer { senderAssignedEmployeeId = json['senderAssignedEmployeeId']; senderMachineStatusId = json['senderMachineStatusId']; senderComment = json['senderComment']; + comment = json['comment']; senderStartDate = json['senderStartDate']; senderEndDate = json['senderEndDate']; senderWorkingHours = json['senderWorkingHours']; @@ -170,7 +172,7 @@ class AssetTransfer { num destBuildingId; num destFloorId; num destDepartmentId; - String destRoom; + num destRoom; num senderSiteId; num senderBuildingId; num senderFloorId; @@ -179,6 +181,7 @@ class AssetTransfer { String senderAssignedEmployeeId; num senderMachineStatusId; String senderComment; + String comment; String senderStartDate; String senderEndDate; String senderWorkingHours; @@ -234,6 +237,7 @@ class AssetTransfer { String senderAssignedEmployeeId, num senderMachineStatusId, String senderComment, + String comment, String senderStartDate, String senderEndDate, String senderWorkingHours, @@ -297,6 +301,7 @@ class AssetTransfer { senderAssignedEmployeeId: senderAssignedEmployeeId ?? this.senderAssignedEmployeeId, senderMachineStatusId: senderMachineStatusId ?? this.senderMachineStatusId, senderComment: senderComment ?? this.senderComment, + comment: comment ?? this.comment, senderStartDate: senderStartDate ?? this.senderStartDate, senderEndDate: senderEndDate ?? this.senderEndDate, senderWorkingHours: senderWorkingHours ?? this.senderWorkingHours, @@ -360,6 +365,7 @@ class AssetTransfer { map['senderAssignedEmployeeId'] = senderAssignedEmployeeId; map['senderMachineStatusId'] = senderMachineStatusId; map['senderComment'] = senderComment; + map['comment'] = comment; map['senderStartDate'] = senderStartDate; map['senderEndDate'] = senderEndDate; map['senderWorkingHours'] = senderWorkingHours; @@ -427,6 +433,7 @@ class AssetTransfer { map['senderAssignedEmployeeId'] = senderAssignedEmployeeId; map['senderMachineStatusId'] = senderMachineStatusId; map['senderComment'] = senderComment; + map['comment'] = comment; map['senderStartDate'] = senderStartDate; map['senderEndDate'] = senderEndDate; map['senderWorkingHours'] = senderWorkingHours; @@ -468,6 +475,7 @@ class AssetTransfer { senderAssignedEmployeeId = assetTransfer.senderAssignedEmployeeId; senderMachineStatusId = assetTransfer.senderMachineStatusId; senderComment = assetTransfer.senderComment; + comment = assetTransfer.comment; senderStartDate = assetTransfer.senderStartDate; senderEndDate = assetTransfer.senderEndDate; senderWorkingHours = assetTransfer.senderWorkingHours; diff --git a/lib/models/new_models/department.dart b/lib/models/new_models/department.dart index b8f50c99..295527bd 100644 --- a/lib/models/new_models/department.dart +++ b/lib/models/new_models/department.dart @@ -1,3 +1,5 @@ +import 'package:test_sa/models/new_models/room_model.dart'; + import '../base.dart'; class Department extends Base { @@ -5,7 +7,9 @@ class Department extends Base { this.id, this.departmentName, this.departmentCode, + this.departmentId, this.ntCode, + this.rooms, }) : super(identifier: id.toString(), name: departmentName); Department.fromJson(dynamic json) { @@ -14,25 +18,31 @@ class Department extends Base { departmentName = json['departmentName'] ?? json['name']; name = departmentName; departmentCode = json['departmentCode']; + departmentId = json['departmentId']; ntCode = json['ntCode']; + rooms = []; + if (json['rooms'] != null) { + json['rooms'].forEach((v) { + rooms.add(Rooms.fromJson(v)); + }); + } } num id; String departmentName; String departmentCode; + String departmentId; String ntCode; - Department copyWith({ - num id, - String departmentName, - String departmentCode, - String ntCode, - }) => - Department( + List rooms; + + Department copyWith({num id, String departmentName, String departmentCode, String ntCode, List rooms}) => Department( id: id ?? this.id, departmentName: departmentName ?? this.departmentName, departmentCode: departmentCode ?? this.departmentCode, + departmentId: departmentId ?? this.departmentId, ntCode: ntCode ?? this.ntCode, + rooms: rooms ?? this.rooms, ); Map toJson() { @@ -40,7 +50,11 @@ class Department extends Base { map['id'] = id; map['departmentName'] = departmentName; map['departmentCode'] = departmentCode; + map['departmentId'] = departmentId; map['ntCode'] = ntCode; + if (rooms != null) { + map['rooms'] = rooms.map((v) => v.toJson()).toList(); + } return map; } } diff --git a/lib/models/new_models/room_model.dart b/lib/models/new_models/room_model.dart new file mode 100644 index 00000000..8ee19de8 --- /dev/null +++ b/lib/models/new_models/room_model.dart @@ -0,0 +1,26 @@ +import 'package:test_sa/models/base.dart'; + +class Rooms extends Base { + int id; + int departmentId; + int clientRoomId; + String roomName; + + Rooms({this.id, this.departmentId, this.clientRoomId, this.roomName}); + + Rooms.fromJson(Map json) { + id = json['id']; + departmentId = json['departmentId']; + clientRoomId = json['clientRoomId']; + roomName = json['roomName']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['departmentId'] = this.departmentId; + data['clientRoomId'] = this.clientRoomId; + data['roomName'] = this.roomName; + return data; + } +} diff --git a/lib/views/pages/device_transfer/device_transfer_details.dart b/lib/views/pages/device_transfer/device_transfer_details.dart index f1eff387..c9d83de4 100644 --- a/lib/views/pages/device_transfer/device_transfer_details.dart +++ b/lib/views/pages/device_transfer/device_transfer_details.dart @@ -78,6 +78,12 @@ class _DeviceTransferDetailsState extends State { _buildTextWidget('${context.translation.assetNumber} : ${_model?.assetNumber ?? ""}'), _buildTextWidget('${context.translation.model} : ${_model?.modelName ?? ""}'), _buildTextWidget('${context.translation.sn} : ${_model?.assetSerialNo ?? ""}'), + if ((_model?.comment ?? "").isNotEmpty) ...[ + 8.height, + const Divider().defaultStyle(context), + 8.height, + _buildTextWidget(_model?.comment), + ] ], ), 8.height, @@ -193,13 +199,12 @@ class _DeviceTransferDetailsState extends State { ], ), if ((_userProvider.user?.type == UsersTypes.engineer)) - if(isCurrentEngineerEligibleForEdit && !isCurrentRequestCompletedOrClosed) + if (isCurrentEngineerEligibleForEdit && !isCurrentRequestCompletedOrClosed) - - // if (isSender - // ? (!(_model?.senderMachineStatusName?.toLowerCase()?.contains("close") ?? false) && !(_model?.senderMachineStatusName?.toLowerCase()?.contains("complete") ?? false)) - // : (!(_model?.receiverMachineStatusName?.toLowerCase()?.contains("close") ?? false) && !(_model?.receiverMachineStatusName?.toLowerCase()?.contains("complete") ?? false))) - // + // if (isSender + // ? (!(_model?.senderMachineStatusName?.toLowerCase()?.contains("close") ?? false) && !(_model?.senderMachineStatusName?.toLowerCase()?.contains("complete") ?? false)) + // : (!(_model?.receiverMachineStatusName?.toLowerCase()?.contains("close") ?? false) && !(_model?.receiverMachineStatusName?.toLowerCase()?.contains("complete") ?? false))) + // "edit".toSvgAsset(height: 48, width: 48).onPress(() { Navigator.of(context).push(MaterialPageRoute(builder: (_) => UpdateDeviceTransfer(model: _model, isSender: isSender))); diff --git a/lib/views/pages/device_transfer/request_device_transfer.dart b/lib/views/pages/device_transfer/request_device_transfer.dart index 4f6cfdde..86ee1e53 100644 --- a/lib/views/pages/device_transfer/request_device_transfer.dart +++ b/lib/views/pages/device_transfer/request_device_transfer.dart @@ -12,6 +12,7 @@ import 'package:test_sa/models/device/asset.dart'; import 'package:test_sa/models/device/asset_transfer.dart'; import 'package:test_sa/models/new_models/department.dart'; import 'package:test_sa/models/new_models/floor.dart'; +import 'package:test_sa/models/new_models/room_model.dart'; import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart'; import '../../../models/new_models/building.dart'; @@ -55,6 +56,7 @@ class _RequestDeviceTransferState extends State { _transferModel.destBuildingId = _assetDestination.building?.id; _transferModel.destFloorId = _assetDestination.floor?.id; _transferModel.destDepartmentId = _assetDestination.department?.id; + _transferModel.destRoom = _assetDestination.room?.clientRoomId; if (!_formKey.currentState.validate() || !(await _transferModel.validate(context))) { return; } @@ -159,23 +161,24 @@ class _RequestDeviceTransferState extends State { }, ), 8.height, - // SingleItemDropDownMenu( - // context: context, - // title: context.translation.room, - // initialValue: _assetDestination?.department, - // enabled: _assetDestination?.floor?.departments?.isNotEmpty ?? false, - // staticData: _assetDestination?.floor?.departments ?? [], - // onSelect: (value) { - // _assetDestination?.department = value; - // }, - // ), - 8.height, - AppTextFormField( - labelText: context.translation.room, - onSaved: (text) { - _transferModel.destRoom = text; + SingleItemDropDownMenu( + context: context, + title: context.translation.room, + initialValue: _assetDestination?.room, + enabled: _assetDestination?.department?.rooms?.isNotEmpty ?? false, + staticData: _assetDestination?.department?.rooms ?? [], + onSelect: (value) { + _assetDestination?.room = value; + _transferModel.destRoom = value.clientRoomId; }, ), + 8.height, + // AppTextFormField( + // labelText: context.translation.room, + // onSaved: (text) { + // _transferModel.destRoom = text; + // }, + // ), 16.height, context.translation.comments.heading5(context), 8.height, @@ -183,7 +186,7 @@ class _RequestDeviceTransferState extends State { controller: _commentsController, labelText: context.translation.comments, onSaved: (text) { - _transferModel.senderComment = text; + _transferModel.comment = text; }, ), 100.height,