From 58c5b434e2e6bdf3e76f3b0aed649d28a053a99d Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Mon, 4 Sep 2023 09:50:41 +0300 Subject: [PATCH 1/9] Fault Desc Issue Fixed --- .../report/create_service_report.dart | 1 - .../requests/report/edit_service_report.dart | 5 +- .../status/report/fault_desc_menu.dart | 70 +++++++++---------- .../service_report_fault_description.dart | 22 ++---- 4 files changed, 43 insertions(+), 55 deletions(-) diff --git a/lib/views/pages/user/requests/report/create_service_report.dart b/lib/views/pages/user/requests/report/create_service_report.dart index 80e14e25..374c305c 100644 --- a/lib/views/pages/user/requests/report/create_service_report.dart +++ b/lib/views/pages/user/requests/report/create_service_report.dart @@ -545,7 +545,6 @@ class _CreateServiceReportState extends State with TickerPr ServiceReportFaultDescription( requestId: widget.request?.id, initialValue: _serviceReport.faultDescription, - enabled: false, onSelect: (status) { if (status != null) { _serviceReport.faultDescription = status; diff --git a/lib/views/pages/user/requests/report/edit_service_report.dart b/lib/views/pages/user/requests/report/edit_service_report.dart index 1eea6ea9..7cc3fc01 100644 --- a/lib/views/pages/user/requests/report/edit_service_report.dart +++ b/lib/views/pages/user/requests/report/edit_service_report.dart @@ -716,9 +716,10 @@ class _EditServiceReportState extends State with TickerProvid requestId: widget.request?.id, initialValue: _serviceReport.faultDescription, onSelect: (status) { - print("faluttt:${status?.toJson()}"); _serviceReport.faultDescription = status; - if (mounted) setState(() {}); + WidgetsBinding.instance.addPostFrameCallback((timeStamp) { + if (mounted) setState(() {}); + }); }, ), const SizedBox(height: 8), diff --git a/lib/views/widgets/status/report/fault_desc_menu.dart b/lib/views/widgets/status/report/fault_desc_menu.dart index 84de4304..a2b670de 100644 --- a/lib/views/widgets/status/report/fault_desc_menu.dart +++ b/lib/views/widgets/status/report/fault_desc_menu.dart @@ -7,9 +7,8 @@ class FaultDescriptionMenu extends StatefulWidget { final List statuses; final FaultDescription initialStatus; final Function(FaultDescription) onSelect; - final bool enabled; - const FaultDescriptionMenu({Key key, this.statuses, this.onSelect, this.initialStatus, this.enabled}) : super(key: key); + const FaultDescriptionMenu({Key key, this.statuses, this.onSelect, this.initialStatus}) : super(key: key); @override _SingleStatusMenuState createState() => _SingleStatusMenuState(); @@ -72,42 +71,39 @@ class _SingleStatusMenuState extends State { // AppStyle.boxShadow // ] ), - child: IgnorePointer( - ignoring: !widget.enabled, - child: DropdownButton( - value: _selectedStatus, - iconSize: 24, - icon: const Icon(Icons.keyboard_arrow_down_rounded), - elevation: 0, - isExpanded: true, - hint: Text( - "Select", - style: Theme.of(context).textTheme.subtitle1, - ), - style: TextStyle(color: Theme.of(context).primaryColor), - underline: SizedBox.shrink(), - onChanged: (FaultDescription newValue) { - setState(() { - _selectedStatus = newValue; - }); - widget.onSelect(newValue); - }, - items: widget.statuses.map>( - (FaultDescription value) { - return DropdownMenuItem( - value: value, - child: Text( - value.defectName ?? "", - style: Theme.of(context).textTheme.subtitle1.copyWith( - color: Theme.of(context).primaryColor, - fontSize: 11, - //fontWeight: FontWeight.bold - ), - ), - ); - }, - ).toList(), + child: DropdownButton( + value: _selectedStatus, + iconSize: 24, + icon: const Icon(Icons.keyboard_arrow_down_rounded), + elevation: 0, + isExpanded: true, + hint: Text( + "Select", + style: Theme.of(context).textTheme.subtitle1, ), + style: TextStyle(color: Theme.of(context).primaryColor), + underline: SizedBox.shrink(), + onChanged: (FaultDescription newValue) { + setState(() { + _selectedStatus = newValue; + }); + widget.onSelect(newValue); + }, + items: widget.statuses.map>( + (FaultDescription value) { + return DropdownMenuItem( + value: value, + child: Text( + value.defectName ?? "", + style: Theme.of(context).textTheme.subtitle1.copyWith( + color: Theme.of(context).primaryColor, + fontSize: 11, + //fontWeight: FontWeight.bold + ), + ), + ); + }, + ).toList(), ), ); } diff --git a/lib/views/widgets/status/report/service_report_fault_description.dart b/lib/views/widgets/status/report/service_report_fault_description.dart index fc90a3e7..78576877 100644 --- a/lib/views/widgets/status/report/service_report_fault_description.dart +++ b/lib/views/widgets/status/report/service_report_fault_description.dart @@ -11,9 +11,9 @@ class ServiceReportFaultDescription extends StatelessWidget { final String requestId; final Function(FaultDescription) onSelect; final FaultDescription initialValue; - final bool enabled; - const ServiceReportFaultDescription({Key key, this.requestId, this.onSelect, this.initialValue, this.enabled = true}) : super(key: key); + const ServiceReportFaultDescription({Key key, this.requestId, this.onSelect, this.initialValue}) : super(key: key); + @override Widget build(BuildContext context) { SettingProvider settingProvider = Provider.of(context); @@ -27,19 +27,11 @@ class ServiceReportFaultDescription extends StatelessWidget { menuProvider.reset(); await menuProvider.getCallRequestForWorkOrder(user: userProvider.user, host: settingProvider.host, requestId: requestId); }, - child: Builder(builder: (context) { - if (initialValue == null && !enabled && menuProvider.items.isNotEmpty) { - WidgetsBinding.instance.addPostFrameCallback((timeStamp) { - onSelect(menuProvider.items.first); - }); - } - return FaultDescriptionMenu( - initialStatus: initialValue, - statuses: menuProvider.items, - onSelect: onSelect, - enabled: enabled, - ); - }), + child: FaultDescriptionMenu( + initialStatus: initialValue, + statuses: menuProvider.items, + onSelect: onSelect, + ), ); } } From 6e0ff344999e12042f220a2ee88798b3614470d7 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Mon, 4 Sep 2023 11:50:08 +0300 Subject: [PATCH 2/9] improvements --- lib/views/widgets/status/report/fault_desc_menu.dart | 4 ++-- .../status/report/service_report_fault_description.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/views/widgets/status/report/fault_desc_menu.dart b/lib/views/widgets/status/report/fault_desc_menu.dart index a2b670de..696c18b3 100644 --- a/lib/views/widgets/status/report/fault_desc_menu.dart +++ b/lib/views/widgets/status/report/fault_desc_menu.dart @@ -79,10 +79,10 @@ class _SingleStatusMenuState extends State { isExpanded: true, hint: Text( "Select", - style: Theme.of(context).textTheme.subtitle1, + style: Theme.of(context).textTheme.subtitle1.copyWith(color: widget.statuses.isEmpty ? Colors.grey : null), ), style: TextStyle(color: Theme.of(context).primaryColor), - underline: SizedBox.shrink(), + underline: const SizedBox.shrink(), onChanged: (FaultDescription newValue) { setState(() { _selectedStatus = newValue; diff --git a/lib/views/widgets/status/report/service_report_fault_description.dart b/lib/views/widgets/status/report/service_report_fault_description.dart index 78576877..0f2990bb 100644 --- a/lib/views/widgets/status/report/service_report_fault_description.dart +++ b/lib/views/widgets/status/report/service_report_fault_description.dart @@ -29,7 +29,7 @@ class ServiceReportFaultDescription extends StatelessWidget { }, child: FaultDescriptionMenu( initialStatus: initialValue, - statuses: menuProvider.items, + statuses: menuProvider.items ?? [], onSelect: onSelect, ), ); From 0dd9400c91dab8e2d68af434c2cbc4eb2901bb22 Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Mon, 4 Sep 2023 15:16:09 +0300 Subject: [PATCH 3/9] Sorting gaz refill using mostRecent key --- lib/controllers/providers/api/regular_visits_provider.dart | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/controllers/providers/api/regular_visits_provider.dart b/lib/controllers/providers/api/regular_visits_provider.dart index 66883477..7209c08a 100644 --- a/lib/controllers/providers/api/regular_visits_provider.dart +++ b/lib/controllers/providers/api/regular_visits_provider.dart @@ -80,7 +80,6 @@ class RegularVisitsProvider extends ChangeNotifier { List visits = requestsListJson.map((request) => Visit.fromJson(request)).toList(); this.visits ??= []; this.visits.addAll(visits); - sortMostRecent(this.visits); notifyListeners(); if (visits.length == pageItemNumber) { nextPage = true; @@ -100,12 +99,6 @@ class RegularVisitsProvider extends ChangeNotifier { return response.statusCode; } - void sortMostRecent(List visits) { - visits.sort((prev, next) => (visitsSearch.mostRecent ?? false) - ? DateTime.tryParse(next.createdOn).compareTo(DateTime.tryParse(prev.createdOn)) - : DateTime.tryParse(prev.createdOn).compareTo(DateTime.tryParse(next.createdOn))); - } - /// return -2 if request in progress /// return -1 if error happen when sending request /// return state code if request complete may be 200, 404 or 403 From 05d3b7dd5dee56a9646457f3645a57fed663abaf Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Tue, 5 Sep 2023 10:22:32 +0300 Subject: [PATCH 4/9] department name shown in the gas refill details screen & the delivered quantity is reflected on the details screen --- lib/views/pages/user/gas_refill/gas_refill_details.dart | 7 ++++++- lib/views/pages/user/gas_refill/request_gas_refill.dart | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/views/pages/user/gas_refill/gas_refill_details.dart b/lib/views/pages/user/gas_refill/gas_refill_details.dart index c2ca75af..fac3a13b 100644 --- a/lib/views/pages/user/gas_refill/gas_refill_details.dart +++ b/lib/views/pages/user/gas_refill/gas_refill_details.dart @@ -135,7 +135,8 @@ class _GasRefillDetailsState extends State { ), ), ).then((value) { - _model.status = value; + _model.status = value.status; + _model.details = value.details; }); setState(() {}); }, @@ -168,6 +169,10 @@ class _GasRefillDetailsState extends State { title: "Floor", info: _model.floor?.name, ), + RequestInfoRow( + title: "Department", + info: _model.department?.departmentName, + ), RequestInfoRow( title: _subtitle.startDate, info: _model.startDate == null ? null : "${DateFormat.yMd().format(_model.startDate)} ${DateFormat.Hms().format(_model.startDate)}", diff --git a/lib/views/pages/user/gas_refill/request_gas_refill.dart b/lib/views/pages/user/gas_refill/request_gas_refill.dart index 944be588..9a4b92be 100644 --- a/lib/views/pages/user/gas_refill/request_gas_refill.dart +++ b/lib/views/pages/user/gas_refill/request_gas_refill.dart @@ -104,7 +104,7 @@ class _RequestGasRefillState extends State { Fluttertoast.showToast( msg: _subtitle.requestCompleteSuccessfully, ); - Navigator.of(context).pop(_formModel.status); + Navigator.of(context).pop(_formModel); setState(() {}); } else { String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle); From f1bb4117e261c3564d68433e70deb4eb6ebeb026 Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Tue, 5 Sep 2023 11:28:21 +0300 Subject: [PATCH 5/9] Add asset floor and room to create asset transfer screen --- .../request_device_transfer.dart | 70 +++++++++---------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/lib/views/pages/device_transfer/request_device_transfer.dart b/lib/views/pages/device_transfer/request_device_transfer.dart index 16eb104d..7e3617d1 100644 --- a/lib/views/pages/device_transfer/request_device_transfer.dart +++ b/lib/views/pages/device_transfer/request_device_transfer.dart @@ -156,43 +156,13 @@ class _RequestDeviceTransferState extends State { }, ), if (_formModel.device != null) 8.height, - if (_formModel.device != null) const ASubTitle("Asset Site"), - if (_formModel.device != null) - Container( - width: double.infinity, - alignment: Alignment.center, - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16), - decoration: BoxDecoration( - color: AColors.inputFieldBackgroundColor, - border: Border.all( - color: const Color(0xffefefef), - ), - borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), - // boxShadow: const [ - // AppStyle.boxShadow - // ] - ), - child: ASubTitle(_formModel.device?.hospital?.name), - ), + if (_formModel.device != null) AdditionalAssetInfo(title: "Asset Site", value: _formModel.device.hospital?.name), if (_formModel.device != null) 4.height, - if (_formModel.device != null && _formModel.device.destDepartmentName != null) const ASubTitle("Asset Department"), - if (_formModel.device != null && _formModel.device.destDepartmentName != null) - Container( - width: double.infinity, - alignment: Alignment.center, - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16), - decoration: BoxDecoration( - color: AColors.inputFieldBackgroundColor, - border: Border.all( - color: const Color(0xffefefef), - ), - borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), - // boxShadow: const [ - // AppStyle.boxShadow - // ] - ), - child: ASubTitle(_formModel.device.destDepartmentName.toString()), - ), + if (_formModel.device != null) AdditionalAssetInfo(title: "Asset Department", value: _formModel.device.destDepartmentName), + if (_formModel.device != null) 4.height, + if (_formModel.device != null) AdditionalAssetInfo(title: "Asset Floor", value: _formModel.device.destFloor), + if (_formModel.device != null) 4.height, + if (_formModel.device != null) AdditionalAssetInfo(title: "Asset Room", value: _formModel.device.destRoom), if (_formModel.device != null) 8.height, // const SizedBox(height: 8,), // const ASubTitle("Sender Department"), @@ -323,3 +293,31 @@ class _RequestDeviceTransferState extends State { ); } } + +class AdditionalAssetInfo extends StatelessWidget { + final String title, value; + const AdditionalAssetInfo({@required this.title, @required this.value, Key key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ASubTitle(title ?? ""), + Container( + width: double.infinity, + alignment: Alignment.center, + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16), + decoration: BoxDecoration( + color: AColors.inputFieldBackgroundColor, + border: Border.all( + color: const Color(0xffefefef), + ), + borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), + ), + child: ASubTitle(value ?? ""), + ), + ], + ); + } +} From fe1885b367fa1850d7c0cc4b405d99c5c54bb088 Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Tue, 5 Sep 2023 12:04:45 +0300 Subject: [PATCH 6/9] Fix asset destination issue --- .../api/device_transfer_provider.dart | 16 +++++++---- lib/models/device/device_transfer_info.dart | 28 +++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/lib/controllers/providers/api/device_transfer_provider.dart b/lib/controllers/providers/api/device_transfer_provider.dart index 2c6e2b37..9dbe79b4 100644 --- a/lib/controllers/providers/api/device_transfer_provider.dart +++ b/lib/controllers/providers/api/device_transfer_provider.dart @@ -202,8 +202,11 @@ class DeviceTransferProvider extends ChangeNotifier { "senderEndDate": newModel.timer?.endAt?.toIso8601String(), "senderTravelingHours": newModel.travelingHours, "senderAttachmentName": newModel?.signature ?? "", - "destSiteId": oldModel.receiver.client.id, - "destDepartmentId": oldModel.receiver.department.id, + "destSiteId": oldModel.receiver.client?.id, + "destDepartmentId": oldModel.receiver.department?.id, + "destBuildingId": oldModel.receiver.building?.id, + "destFloorId": oldModel.receiver.floor?.id, + "destRoom": oldModel.receiver?.room, "receiverAssignedEmployeeId": oldModel.receiver.userId, "receiverMachineStatusId": oldModel.receiver.status.id ?? "", "receiverComment": oldModel.receiver.comment, @@ -225,8 +228,11 @@ class DeviceTransferProvider extends ChangeNotifier { "senderEndDate": oldModel.sender.timer?.endAt?.toIso8601String(), "senderTravelingHours": oldModel.sender.travelingHours, "senderAttachmentName": oldModel.sender?.signature ?? "", - "destSiteId": newModel.client.id, - "destDepartmentId": newModel.department.id, + "destSiteId": newModel.client?.id, + "destDepartmentId": newModel.department?.id, + "destBuildingId": newModel.building?.id, + "destFloorId": newModel.floor?.id, + "destRoom": newModel.room, "receiverAssignedEmployeeId": newModel.userId, "receiverMachineStatusId": newModel.status?.id ?? "", "receiverComment": newModel.comment, @@ -237,7 +243,7 @@ class DeviceTransferProvider extends ChangeNotifier { "receiverAttachmentName": newModel?.signature ?? "", }); } - + if (true) {} //body.addAll(newModel.toJson(isSender)); print(body); Response response; diff --git a/lib/models/device/device_transfer_info.dart b/lib/models/device/device_transfer_info.dart index dd96f298..3a645508 100644 --- a/lib/models/device/device_transfer_info.dart +++ b/lib/models/device/device_transfer_info.dart @@ -9,6 +9,9 @@ class DeviceTransferInfo { String comment; Hospital client; Department department; + Buildings building; + Floors floor; + String room; String workingHours; // DateTime startDate; @@ -34,6 +37,9 @@ class DeviceTransferInfo { this.status, this.assignedEmployeeName, this.timer, + this.building, + this.room, + this.floor, }); Map toJson(bool isSender) { @@ -63,6 +69,19 @@ class DeviceTransferInfo { userName = old.userName; client = Hospital.fromHospital(old.client); department = Department.fromDepartment(old.department); + building = Buildings( + id: old.building?.id, + name: old.building?.name, + value: old.building?.value, + floors: old.building?.floors, + ); + floor = Floors( + id: old.floor?.id, + name: old.floor?.name, + value: old.floor?.value, + departments: old.floor?.departments, + ); + room = old.room; workingHours = old.workingHours; // startDate = old.startDate; // endDate = old.endDate; @@ -94,6 +113,15 @@ class DeviceTransferInfo { id: parsedJson["${key}DepartmentId"], name: parsedJson["${key}DepartmentName"], ), + building: Buildings( + id: parsedJson["${key}BuildingId"], + name: parsedJson["${key}BuildingName"], + ), + floor: Floors( + id: parsedJson["${key}FloorId"], + name: parsedJson["${key}FloorName"], + ), + room: parsedJson["${key}Room"], status: Lookup( id: parsedJson["${key}status"], name: parsedJson["${key}status"], From ea5738f7057ffadd54a9d0d03803b8585b11dd7b Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Tue, 5 Sep 2023 12:17:14 +0300 Subject: [PATCH 7/9] Gas refill update reflected on the details screen --- .../pages/user/gas_refill/gas_refill_details.dart | 11 ++++++----- .../pages/user/gas_refill/request_gas_refill.dart | 6 ++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/views/pages/user/gas_refill/gas_refill_details.dart b/lib/views/pages/user/gas_refill/gas_refill_details.dart index fac3a13b..589c9094 100644 --- a/lib/views/pages/user/gas_refill/gas_refill_details.dart +++ b/lib/views/pages/user/gas_refill/gas_refill_details.dart @@ -34,7 +34,7 @@ class GasRefillDetails extends StatefulWidget { } class _GasRefillDetailsState extends State { - final GasRefillModel _model = GasRefillModel(); + GasRefillModel _model = GasRefillModel(); bool _enableEdit = false; bool _validate = false; UserProvider _userProvider; @@ -75,7 +75,7 @@ class _GasRefillDetailsState extends State { @override void initState() { - _model.fromGasRefillModel(widget.model); + _model?.fromGasRefillModel(widget.model); super.initState(); } @@ -124,7 +124,7 @@ class _GasRefillDetailsState extends State { onPressed: () async { // _enableEdit = !_enableEdit; print(widget.model.startDate); - _model.fromGasRefillModel(widget.model); + _model?.fromGasRefillModel(widget.model); print(widget.model.startDate); // setState(() {}); Navigator.push( @@ -135,8 +135,9 @@ class _GasRefillDetailsState extends State { ), ), ).then((value) { - _model.status = value.status; - _model.details = value.details; + if (value != null) { + _model = value; + } }); setState(() {}); }, diff --git a/lib/views/pages/user/gas_refill/request_gas_refill.dart b/lib/views/pages/user/gas_refill/request_gas_refill.dart index 9a4b92be..e5242580 100644 --- a/lib/views/pages/user/gas_refill/request_gas_refill.dart +++ b/lib/views/pages/user/gas_refill/request_gas_refill.dart @@ -294,6 +294,8 @@ class _RequestGasRefillState extends State { onChange: (timer) async { _gasRefillProvider.timer = timer; _formModel.workingHours = num.tryParse((((timer?.durationInSecond ?? 0) / 60) / 60)?.toStringAsFixed(2) ?? "0"); + _formModel.startDate = timer.startAt; + _formModel.endDate = timer.endAt; return true; }, ), @@ -533,12 +535,12 @@ class _RequestGasRefillState extends State { if (widget.gasRefillModel != null) ESignature( oldSignature: _formModel.signatureEngineer, - newSignature: _formModel.localNurseSignature, + newSignature: _formModel.localEngineerSignature, onChange: (signature) { if (signature == null || signature.isEmpty) { return; } - _formModel.localNurseSignature = signature; + _formModel.localEngineerSignature = signature; _formModel.signatureEngineer = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; }, ), From 300bc0a1a620508f918747b7e7c0a0f0dde5feb8 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Tue, 5 Sep 2023 12:24:30 +0300 Subject: [PATCH 8/9] improvements --- lib/models/pantry/pentry.dart | 14 +++++-- .../device_transfer_details.dart | 8 ++-- .../user/gas_refill/gas_refill_details.dart | 42 ++++++++++--------- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/lib/models/pantry/pentry.dart b/lib/models/pantry/pentry.dart index 57f871c1..606a73f1 100644 --- a/lib/models/pantry/pentry.dart +++ b/lib/models/pantry/pentry.dart @@ -87,7 +87,7 @@ class Pentry { map["workingHours"] = (timer.durationInSecond / 60 / 60).toStringAsFixed(5); } if (files?.isNotEmpty ?? false) { - map["vAttachments"] = files.map((file) => {"attachmentName": (file.path.split("/").last + base64Encode(file.readAsBytesSync()))}).toList(); + map["vAttachments"] = files.map((file) => {"attachmentName": _isLocalUrl(file.path) ? (file.path.split("/").last + "|" + base64Encode(file.readAsBytesSync())): file.path}).toList(); } map["travelingHours"] = travelingHours; // if(contacts?.isNotEmpty == true) { @@ -104,7 +104,10 @@ class Pentry { map["engSignature"] = signatureEngineer; //"${DateTime.now().toIso8601String()}.png|$signatureEngineer"; return map; } - + bool _isLocalUrl(String url) { + if (url?.isEmpty != false) return false; + return url.startsWith("/") || url.startsWith("file://") || url.substring(1).startsWith(':\\'); + } factory Pentry.fromMap(Map map) { // List contacts = []; // if(map['contacts'] != null){ @@ -120,6 +123,7 @@ class Pentry { List files = []; if (map["vAttachments"] != null) if (map["vAttachments"] is List) { List list = map["vAttachments"]; + list.removeWhere((element) => (element["attachmentURL"]?.toString() ?? "").isEmpty); files = list.map((e) => URLs.getFileUrl(e["attachmentName"])).toList(); } List ppmCheckLists = []; @@ -146,7 +150,11 @@ class Pentry { ppmCheckLists: ppmCheckLists, calibrationTools: calibrationTools, pmKits: pmKits, - files: files.map((e) => File(e)).toList(), + files: files?.map((e) { + print("${map["id"]}:${files?.length}:e:$e"); + return File(e); + })?.toList() ?? + [], signatureNurse: URLs.getFileUrl(map["nurseSignature"]), signatureEngineer: URLs.getFileUrl(map["engSignature"]), ); diff --git a/lib/views/pages/device_transfer/device_transfer_details.dart b/lib/views/pages/device_transfer/device_transfer_details.dart index 2e807ec9..82d65dba 100644 --- a/lib/views/pages/device_transfer/device_transfer_details.dart +++ b/lib/views/pages/device_transfer/device_transfer_details.dart @@ -144,13 +144,13 @@ class _DeviceTransferDetailsState extends State { ASmallButton( text: _subtitle.edit, onPressed: (_isSender) - ? () { + ? ( _model.sender.status?.name=="Closed" ? null: () { Navigator.of(context).push(MaterialPageRoute( builder: (_) => UpdateDeviceTransfer( model: _model, isSender: true, ))); - } + }) : null, ), ], @@ -170,13 +170,13 @@ class _DeviceTransferDetailsState extends State { ASmallButton( text: _subtitle.edit, onPressed: (_isReceiver) - ? () { + ? ( _model.receiver.status?.name=="Closed" ? null: () { Navigator.of(context).push(MaterialPageRoute( builder: (_) => UpdateDeviceTransfer( model: _model, isSender: false, ))); - } + }) : null, ), ], diff --git a/lib/views/pages/user/gas_refill/gas_refill_details.dart b/lib/views/pages/user/gas_refill/gas_refill_details.dart index 589c9094..9a98b8d0 100644 --- a/lib/views/pages/user/gas_refill/gas_refill_details.dart +++ b/lib/views/pages/user/gas_refill/gas_refill_details.dart @@ -121,26 +121,28 @@ class _GasRefillDetailsState extends State { color: Theme.of(context).colorScheme.onPrimary, buttonSize: 42, backgroundColor: AColors.green, - onPressed: () async { - // _enableEdit = !_enableEdit; - print(widget.model.startDate); - _model?.fromGasRefillModel(widget.model); - print(widget.model.startDate); - // setState(() {}); - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => RequestGasRefill( - gasRefillModel: widget.model, - ), - ), - ).then((value) { - if (value != null) { - _model = value; - } - }); - setState(() {}); - }, + onPressed: (widget.model.status?.value ?? 0) == 2 + ? null + : () async { + // _enableEdit = !_enableEdit; + print(widget.model.startDate); + _model?.fromGasRefillModel(widget.model); + print(widget.model.startDate); + // setState(() {}); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => RequestGasRefill( + gasRefillModel: widget.model, + ), + ), + ).then((value) { + if (value != null) { + _model = value; + } + }); + setState(() {}); + }, ), const SizedBox( width: 16, From a26684de111be74f12bb3c7fb97286cd1c83c16a Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Tue, 5 Sep 2023 13:10:12 +0300 Subject: [PATCH 9/9] Device Status in PM Entry --- lib/models/pantry/pentry.dart | 10 ++++++---- lib/views/widgets/pentry/pentry_info_form.dart | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/models/pantry/pentry.dart b/lib/models/pantry/pentry.dart index 606a73f1..0b742040 100644 --- a/lib/models/pantry/pentry.dart +++ b/lib/models/pantry/pentry.dart @@ -75,8 +75,8 @@ class Pentry { Map toMap(int visitId) { Map map = {}; - map["visitStatusId"] = ppmVisitStatus?.id.toString(); - if (status != null) map["deviceStatusId"] = status?.id.toString(); + map["visitStatusId"] = ppmVisitStatus?.id?.toString(); + if (status != null) map["deviceStatusId"] = status?.id?.toString(); if (travelingHours != null) map["travelingHours"] = travelingHours; //if(imageFile != null) map["file_attachement"] = base64Encode(imageFile.readAsBytesSync()); map["actualDate"] = actualVisitDate.toIso8601String(); @@ -87,7 +87,7 @@ class Pentry { map["workingHours"] = (timer.durationInSecond / 60 / 60).toStringAsFixed(5); } if (files?.isNotEmpty ?? false) { - map["vAttachments"] = files.map((file) => {"attachmentName": _isLocalUrl(file.path) ? (file.path.split("/").last + "|" + base64Encode(file.readAsBytesSync())): file.path}).toList(); + map["vAttachments"] = files.map((file) => {"attachmentName": _isLocalUrl(file.path) ? (file.path.split("/").last + "|" + base64Encode(file.readAsBytesSync())) : file.path}).toList(); } map["travelingHours"] = travelingHours; // if(contacts?.isNotEmpty == true) { @@ -104,10 +104,12 @@ class Pentry { map["engSignature"] = signatureEngineer; //"${DateTime.now().toIso8601String()}.png|$signatureEngineer"; return map; } + bool _isLocalUrl(String url) { if (url?.isEmpty != false) return false; return url.startsWith("/") || url.startsWith("file://") || url.substring(1).startsWith(':\\'); } + factory Pentry.fromMap(Map map) { // List contacts = []; // if(map['contacts'] != null){ @@ -136,7 +138,7 @@ class Pentry { calibrationTools = (map['vCalibrationTools'] as List).map((e) => CalibrationTool.fromMap(e as Map)).toList(); } return Pentry( - status: Lookup(id: map["taskStatusId"], name: map["taskStatusName"]), + status: Lookup(id: map["deviceStatusId"], name: map["deviceStatusName"]), ppmVisitStatus: Lookup(id: map["visitStatusId"], name: map["visitStatusName"]), actualVisitDate: DateTime.tryParse(map["actualDate"] ?? ""), expectedVisitDate: DateTime.tryParse(map["expectedDate"] ?? ""), diff --git a/lib/views/widgets/pentry/pentry_info_form.dart b/lib/views/widgets/pentry/pentry_info_form.dart index 73c4364f..78f4e09d 100644 --- a/lib/views/widgets/pentry/pentry_info_form.dart +++ b/lib/views/widgets/pentry/pentry_info_form.dart @@ -57,7 +57,9 @@ class _PentryInfoFormState extends State { PentryVisitsStatusMenu( initialValue: widget.model.ppmVisitStatus, onSelect: (status) { - widget.model.ppmVisitStatus = status; + if (status != null) { + widget.model.ppmVisitStatus = status; + } }, ), const SizedBox(