From ab91baf216d00517d95521beb4c035c2159a9ae2 Mon Sep 17 00:00:00 2001 From: WaseemAbbasi22 Date: Mon, 7 Apr 2025 11:54:04 +0300 Subject: [PATCH] bug fixes mentioned on excel sheet and tested with backend --- .../providers/api/parts_provider.dart | 20 +- .../providers/api/ppm_provider.dart | 13 + lib/extensions/widget_extensions.dart | 4 +- .../plan_preventive_visit_model.dart | 260 +++++----- lib/models/service_request/spare_parts.dart | 14 +- .../land_page/requests/ppm_item_view.dart | 2 +- .../service_request_detail_view.dart | 2 +- .../forms/spare_part/spare_part_request.dart | 2 +- .../pages/user/ppm/ppm_details_page.dart | 12 +- .../components/room_inspection_card.dart | 2 + .../components/task_info_widget.dart | 2 +- .../recurrent_work_order_view.dart | 3 +- .../ppm_calibration_tools_form.dart | 131 ++--- .../update_ppm/ppm_external_details_form.dart | 308 ++++++------ .../update_ppm/ppm_pm_check_list_form.dart | 126 ++--- .../user/ppm/update_ppm/ppm_pm_kits_form.dart | 129 ++--- .../pages/user/ppm/update_ppm/update_ppm.dart | 76 +-- .../user/ppm/update_ppm/wo_info_form.dart | 465 +++++++++--------- 18 files changed, 844 insertions(+), 727 deletions(-) diff --git a/lib/controllers/providers/api/parts_provider.dart b/lib/controllers/providers/api/parts_provider.dart index 7ec4d8fc..fc2829b8 100644 --- a/lib/controllers/providers/api/parts_provider.dart +++ b/lib/controllers/providers/api/parts_provider.dart @@ -96,11 +96,29 @@ class PartsProvider extends ChangeNotifier { if (response.statusCode >= 200 && response.statusCode < 300) { // client's request was successfully received List categoriesListJson = json.decode(response.body)["data"]; - page = categoriesListJson.map((part) => SparePart.fromJson(part)).toList(); + page = categoriesListJson.map((part) => SparePart.fromJson(part,false)).toList(); } return page; } catch (error) { return []; } } + // Implement this only for spare part request for now show and search on display name .... + + Future> getPartsListByDisplayName({num? assetId, String? displayName}) async { + late Response response; + try { + response = await ApiManager.instance.post(URLs.getPartNumber, body: {"displayName": displayName, }); + List page = []; + if (response.statusCode >= 200 && response.statusCode < 300) { + // client's request was successfully received + List categoriesListJson = json.decode(response.body)["data"]; + page = categoriesListJson.map((part) => SparePart.fromJson(part,true)).toList(); + } + return page; + } catch (error) { + return []; + } + } + } diff --git a/lib/controllers/providers/api/ppm_provider.dart b/lib/controllers/providers/api/ppm_provider.dart index 0af12483..ea5dc266 100644 --- a/lib/controllers/providers/api/ppm_provider.dart +++ b/lib/controllers/providers/api/ppm_provider.dart @@ -22,6 +22,14 @@ class PpmProvider extends ChangeNotifier { PlanPreventiveVisit? _planPreventiveVisit; late int _totalTabs = 4; TabController? tabController; + bool _isReadOnly = false; + + bool get isReadOnly => _isReadOnly; + + set isReadOnly(bool value) { + _isReadOnly = value; + notifyListeners(); + } int get totalTabs => _totalTabs; @@ -155,6 +163,11 @@ class PpmProvider extends ChangeNotifier { if (response.statusCode >= 200 && response.statusCode < 300) { ppmPlanAttachments = []; planPreventiveVisit = PlanPreventiveVisit.fromJson(json.decode(response.body)["data"]); + if(planPreventiveVisit?.visitStatus?.value! == 1 || planPreventiveVisit?.visitStatus?.value == 3){ + isReadOnly =true; + }else{ + isReadOnly =false; + } isLoading = false; notifyListeners(); return planPreventiveVisit; diff --git a/lib/extensions/widget_extensions.dart b/lib/extensions/widget_extensions.dart index 23a5a6a1..dd971fd4 100644 --- a/lib/extensions/widget_extensions.dart +++ b/lib/extensions/widget_extensions.dart @@ -55,8 +55,8 @@ extension WidgetExtensions on Widget { Widget toExpanded({int flex = 1}) => Expanded(flex: flex, child: this); - Widget handlePopScope(BuildContext _cxt, VoidCallback onSave) { - return PopScope( + Widget handlePopScope(BuildContext _cxt, VoidCallback onSave,) { + return PopScope( canPop: false, onPopInvokedWithResult: (didPop, result) { if (didPop) { diff --git a/lib/models/plan_preventive_visit/plan_preventive_visit_model.dart b/lib/models/plan_preventive_visit/plan_preventive_visit_model.dart index 1dcb94f6..3a131ae1 100644 --- a/lib/models/plan_preventive_visit/plan_preventive_visit_model.dart +++ b/lib/models/plan_preventive_visit/plan_preventive_visit_model.dart @@ -783,136 +783,136 @@ class PreventiveVisitSuppliers { } } -class Supplier { - int? id; - String? suppliername; - String? name; - String? website; - String? email; - String? code; - int? suppNo; - String? suppStatusId; - String? cityId; - String? person; - String? comment; - String? zipcode; - String? contact; - List? telephones; - List? faxes; - List? addresses; - List? attachments; - List? suppPersons; - List? suppTCodes; - - Supplier( - {this.id, - this.suppliername, - this.name, - this.website, - this.email, - this.code, - this.suppNo, - this.suppStatusId, - this.cityId, - this.person, - this.comment, - this.zipcode, - this.contact, - this.telephones, - this.faxes, - this.addresses, - this.attachments, - this.suppPersons, - this.suppTCodes}); - - Supplier.fromJson(Map json) { - id = json['id']; - suppliername = json['suppliername']; - name = json['name']; - website = json['website']; - email = json['email']; - code = json['code']; - suppNo = json['suppNo']; - suppStatusId = json['suppStatusId']; - cityId = json['cityId']; - person = json['person']; - comment = json['comment']; - zipcode = json['zipcode']; - contact = json['contact']; - if (json['telephones'] != null) { - telephones = []; - json['telephones'].forEach((v) { - telephones!.add(v); - }); - } - if (json['faxes'] != null) { - faxes = []; - json['faxes'].forEach((v) { - faxes!.add(v); - }); - } - if (json['addresses'] != null) { - addresses = []; - json['addresses'].forEach((v) { - addresses!.add(v); - }); - } - if (json['attachments'] != null) { - attachments = []; - json['attachments'].forEach((v) { - attachments!.add(v); - }); - } - if (json['suppPersons'] != null) { - suppPersons = []; - json['suppPersons'].forEach((v) { - suppPersons!.add(SuppPersons.fromJson(v)); - }); - } - if (json['suppTCodes'] != null) { - suppTCodes = []; - json['suppTCodes'].forEach((v) { - suppTCodes!.add(v); - }); - } - } - - Map toJson() { - final Map data = {}; - data['id'] = id; - data['suppliername'] = suppliername; - data['name'] = name; - data['website'] = website; - data['email'] = email; - data['code'] = code; - data['suppNo'] = suppNo; - data['suppStatusId'] = suppStatusId; - data['cityId'] = cityId; - data['person'] = person; - data['comment'] = comment; - data['zipcode'] = zipcode; - data['contact'] = contact; - if (telephones != null) { - data['telephones'] = telephones!.map((v) => v).toList(); - } - if (faxes != null) { - data['faxes'] = faxes!.map((v) => v).toList(); - } - if (addresses != null) { - data['addresses'] = addresses!.map((v) => v).toList(); - } - if (attachments != null) { - data['attachments'] = attachments!.map((v) => v).toList(); - } - if (suppPersons != null) { - data['suppPersons'] = suppPersons!.map((v) => v.toJson()).toList(); - } - if (suppTCodes != null) { - data['suppTCodes'] = suppTCodes!.map((v) => v).toList(); - } - return data; - } -} +// class Supplier { +// int? id; +// String? suppliername; +// String? name; +// String? website; +// String? email; +// String? code; +// int? suppNo; +// String? suppStatusId; +// String? cityId; +// String? person; +// String? comment; +// String? zipcode; +// String? contact; +// List? telephones; +// List? faxes; +// List? addresses; +// List? attachments; +// List? suppPersons; +// List? suppTCodes; +// +// Supplier( +// {this.id, +// this.suppliername, +// this.name, +// this.website, +// this.email, +// this.code, +// this.suppNo, +// this.suppStatusId, +// this.cityId, +// this.person, +// this.comment, +// this.zipcode, +// this.contact, +// this.telephones, +// this.faxes, +// this.addresses, +// this.attachments, +// this.suppPersons, +// this.suppTCodes}); +// +// Supplier.fromJson(Map json) { +// id = json['id']; +// suppliername = json['suppliername']; +// name = json['name']; +// website = json['website']; +// email = json['email']; +// code = json['code']; +// suppNo = json['suppNo']; +// suppStatusId = json['suppStatusId']; +// cityId = json['cityId']; +// person = json['person']; +// comment = json['comment']; +// zipcode = json['zipcode']; +// contact = json['contact']; +// if (json['telephones'] != null) { +// telephones = []; +// json['telephones'].forEach((v) { +// telephones!.add(v); +// }); +// } +// if (json['faxes'] != null) { +// faxes = []; +// json['faxes'].forEach((v) { +// faxes!.add(v); +// }); +// } +// if (json['addresses'] != null) { +// addresses = []; +// json['addresses'].forEach((v) { +// addresses!.add(v); +// }); +// } +// if (json['attachments'] != null) { +// attachments = []; +// json['attachments'].forEach((v) { +// attachments!.add(v); +// }); +// } +// if (json['suppPersons'] != null) { +// suppPersons = []; +// json['suppPersons'].forEach((v) { +// suppPersons!.add(SuppPersons.fromJson(v)); +// }); +// } +// if (json['suppTCodes'] != null) { +// suppTCodes = []; +// json['suppTCodes'].forEach((v) { +// suppTCodes!.add(v); +// }); +// } +// } +// +// Map toJson() { +// final Map data = {}; +// data['id'] = id; +// data['suppliername'] = suppliername; +// data['name'] = name; +// data['website'] = website; +// data['email'] = email; +// data['code'] = code; +// data['suppNo'] = suppNo; +// data['suppStatusId'] = suppStatusId; +// data['cityId'] = cityId; +// data['person'] = person; +// data['comment'] = comment; +// data['zipcode'] = zipcode; +// data['contact'] = contact; +// if (telephones != null) { +// data['telephones'] = telephones!.map((v) => v).toList(); +// } +// if (faxes != null) { +// data['faxes'] = faxes!.map((v) => v).toList(); +// } +// if (addresses != null) { +// data['addresses'] = addresses!.map((v) => v).toList(); +// } +// if (attachments != null) { +// data['attachments'] = attachments!.map((v) => v).toList(); +// } +// if (suppPersons != null) { +// data['suppPersons'] = suppPersons!.map((v) => v.toJson()).toList(); +// } +// if (suppTCodes != null) { +// data['suppTCodes'] = suppTCodes!.map((v) => v).toList(); +// } +// return data; +// } +// } // class SuppPersons { // int? id; diff --git a/lib/models/service_request/spare_parts.dart b/lib/models/service_request/spare_parts.dart index 5571d179..11f183a9 100644 --- a/lib/models/service_request/spare_parts.dart +++ b/lib/models/service_request/spare_parts.dart @@ -5,7 +5,7 @@ class SparePartsWorkOrders extends Base { SparePartsWorkOrders.fromJson(dynamic json) { id = json['id']; - sparePart = json['sparePart'] != null ? SparePart.fromJson(json['sparePart']) : null; + sparePart = json['sparePart'] != null ? SparePart.fromJson(json['sparePart'],true) : null; qty = json['qty']; returnQty = json['returnQty']; @@ -40,33 +40,37 @@ class SparePart extends Base { this.partNo, this.partName, this.oracleCode, + this.displayName, this.assetId, }) : super(identifier: id?.toString(), name: partName); - SparePart.fromJson(dynamic json) { + SparePart.fromJson(dynamic json,bool ?isDisplayName) { id = json['id']; identifier = id?.toString(); partNo = json['partNo']; partName = json['partName']; + displayName = json['displayName']; oracleCode = json['oracleCode']; - name = partName; + name = isDisplayName!=null&&isDisplayName?displayName: partName; assetId = json['assetId']; } num? id; String? partNo; String? partName; + String? displayName; String? oracleCode; num? assetId; - SparePart copyWith({num? id, String? partNo, String? partName, num? assetId,String?oracleCode}) => - SparePart(id: id ?? this.id,oracleCode: oracleCode?? this.oracleCode, partNo: partNo ?? this.partNo, partName: partName ?? this.partName, assetId: assetId ?? this.assetId); + SparePart copyWith({num? id, String? partNo, String? partName, num? assetId,String?oracleCode,String ?displayName}) => + SparePart(id: id ?? this.id,oracleCode: oracleCode?? this.oracleCode, partNo: partNo ?? this.partNo, partName: partName ?? this.partName, assetId: assetId ?? this.assetId,displayName: displayName??this.displayName); Map toJson() { final map = {}; map['id'] = id; map['partNo'] = partNo; map['partName'] = partName; + map['displayName'] = displayName; map['oracleCode'] = oracleCode; map['assetId'] = assetId; return map; diff --git a/lib/new_views/pages/land_page/requests/ppm_item_view.dart b/lib/new_views/pages/land_page/requests/ppm_item_view.dart index ba30b5c7..100f47de 100644 --- a/lib/new_views/pages/land_page/requests/ppm_item_view.dart +++ b/lib/new_views/pages/land_page/requests/ppm_item_view.dart @@ -100,7 +100,7 @@ class PpmItemView extends StatelessWidget { 8.height, (requestDetails?.nameOfType ?? context.translation.ppmRequest).heading5(context), 8.height, - '${context.translation.assetName}: ${requestDetails!.assetName}'.bodyText(context), + '${context.translation.assetName}: ${requestDetails!.assetName}'.bodyText(context), '${context.translation.assetNumber}: ${requestDetails!.assetNo}'.bodyText(context), '${context.translation.assetSN}: ${requestDetails!.assetSN}'.bodyText(context), // '${context.translation.code}: ${request.code}'.bodyText(context), diff --git a/lib/service_request_latest/views/components/service_request_detail_view.dart b/lib/service_request_latest/views/components/service_request_detail_view.dart index 92ca9575..3979e955 100644 --- a/lib/service_request_latest/views/components/service_request_detail_view.dart +++ b/lib/service_request_latest/views/components/service_request_detail_view.dart @@ -126,7 +126,7 @@ class _ServiceRequestDetailViewState extends State { radius: 4, label:'${workOrder.since} days', textColor: AppColor.neutral50, - backgroundColor: AppColor.orange80, + backgroundColor: AppColor.orange30, ), ], 1.width.expanded, diff --git a/lib/service_request_latest/views/forms/spare_part/spare_part_request.dart b/lib/service_request_latest/views/forms/spare_part/spare_part_request.dart index 36d5c6a4..44b105b8 100644 --- a/lib/service_request_latest/views/forms/spare_part/spare_part_request.dart +++ b/lib/service_request_latest/views/forms/spare_part/spare_part_request.dart @@ -80,7 +80,7 @@ class _SparePartRequestState extends State with TickerProvider _isLoading = true; _files = _requestDetailProvider?.sparePartHelperModel?.sparePartAttachments?.map((e) => MultiFilesPickerModel(e.id!, File(e.name!))).toList() ?? []; setState(() {}); - _spareParts = await _partsProvider!.getPartsList(assetId: _requestDetailProvider?.currentWorkOrder?.data?.asset?.id); + _spareParts = await _partsProvider!.getPartsListByDisplayName(assetId: _requestDetailProvider?.currentWorkOrder?.data?.asset?.id); _isLoading = false; setState(() {}); diff --git a/lib/views/pages/user/ppm/ppm_details_page.dart b/lib/views/pages/user/ppm/ppm_details_page.dart index ecd40444..0ad5d7a0 100644 --- a/lib/views/pages/user/ppm/ppm_details_page.dart +++ b/lib/views/pages/user/ppm/ppm_details_page.dart @@ -106,7 +106,7 @@ class _PpmDetailsPageState extends State { ], ).toShadowContainer(context).paddingAll(16), ).expanded, - if (userProvider!.user!.type == UsersTypes.engineer && (planPreventiveVisit.visitStatus!.id! != 270 && planPreventiveVisit.visitStatus!.id! != 269)) + if (userProvider!.user!.type == UsersTypes.engineer && (!ppmProvider.isReadOnly))...[ AppFilledButton( onPressed: () async { await Navigator.of(context).push(MaterialPageRoute(builder: (_) => UpdatePpm(ppm: null, planPreventiveVisit: planPreventiveVisit))); @@ -114,6 +114,16 @@ class _PpmDetailsPageState extends State { }, label: context.translation.updateWorkOrder, ).paddingAll(16) + ] + else ...[ + AppFilledButton( + onPressed: () async { + await Navigator.of(context).push(MaterialPageRoute(builder: (_) => UpdatePpm(ppm: null, planPreventiveVisit: planPreventiveVisit))); + getVisitData(); + }, + label: context.translation.viewDetails, + ).paddingAll(16) + ] ]); }), ), diff --git a/lib/views/pages/user/ppm/ppm_work_order/recurrent_wo/components/room_inspection_card.dart b/lib/views/pages/user/ppm/ppm_work_order/recurrent_wo/components/room_inspection_card.dart index 0f2c5720..a4161ce5 100644 --- a/lib/views/pages/user/ppm/ppm_work_order/recurrent_wo/components/room_inspection_card.dart +++ b/lib/views/pages/user/ppm/ppm_work_order/recurrent_wo/components/room_inspection_card.dart @@ -57,6 +57,7 @@ class _RoomInspectionCardState extends State { required PlanRecurrentMedicalTaskRoomTabAttributes model, required BuildContext context, }) { + bool status = (model.attribute == null || model.attributeValue == null) ? true : model.attribute != null @@ -65,6 +66,7 @@ class _RoomInspectionCardState extends State { : false : false; + return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, diff --git a/lib/views/pages/user/ppm/ppm_work_order/recurrent_wo/components/task_info_widget.dart b/lib/views/pages/user/ppm/ppm_work_order/recurrent_wo/components/task_info_widget.dart index aace2400..95a90f16 100644 --- a/lib/views/pages/user/ppm/ppm_work_order/recurrent_wo/components/task_info_widget.dart +++ b/lib/views/pages/user/ppm/ppm_work_order/recurrent_wo/components/task_info_widget.dart @@ -79,7 +79,7 @@ class RecurrentTaskInfoWidget extends StatelessWidget { label: context.translation.timer, timer: snapshot.recurrentWoData?.recurrentWoTimerModel, width: double.infinity, - // enabled: snapshot.recurrentWoData?.recurrentWoTimerModel?.endAt == null, + enabled: snapshot.recurrentWoData?.status?.value != 1, decoration: BoxDecoration( color: AppColor.neutral100, borderRadius: BorderRadius.circular(10), diff --git a/lib/views/pages/user/ppm/ppm_work_order/recurrent_wo/recurrent_work_order_view.dart b/lib/views/pages/user/ppm/ppm_work_order/recurrent_wo/recurrent_work_order_view.dart index 0edb2d7c..ef25b37b 100644 --- a/lib/views/pages/user/ppm/ppm_work_order/recurrent_wo/recurrent_work_order_view.dart +++ b/lib/views/pages/user/ppm/ppm_work_order/recurrent_wo/recurrent_work_order_view.dart @@ -65,7 +65,6 @@ class _RecurrentWorkOrderViewState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ RecurrentTaskInfoWidget(model: requestProvider.recurrentWoData), - // 8.height, requestProvider.recurrentWoData!.planRecurrentMedicalTaskRooms!.isNotEmpty ? Column( children: [ @@ -77,7 +76,7 @@ class _RecurrentWorkOrderViewState extends State { ], ).paddingAll(12), ).paddingOnly(bottom: 85), - if (requestProvider.recurrentWoData?.status?.id != 270) ...[ + if (requestProvider.recurrentWoData?.status?.value != 1) ...[ FooterActionButton.footerContainer( child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, diff --git a/lib/views/pages/user/ppm/update_ppm/ppm_calibration_tools_form.dart b/lib/views/pages/user/ppm/update_ppm/ppm_calibration_tools_form.dart index fe6c6ae3..9684d49a 100644 --- a/lib/views/pages/user/ppm/update_ppm/ppm_calibration_tools_form.dart +++ b/lib/views/pages/user/ppm/update_ppm/ppm_calibration_tools_form.dart @@ -30,7 +30,8 @@ class _PpmCalibrationToolsFormState extends State { @override Widget build(BuildContext context) { final userProvider = Provider.of(context); - int totalTabs = Provider.of(context, listen: false).totalTabs; + final ppmProvider = Provider.of(context, listen: false); + int totalTabs = ppmProvider.totalTabs; int currentIndex = totalTabs == 4 ? 2 : 1; return ListView.separated( itemCount: widget.models!.length + 1, @@ -38,27 +39,30 @@ class _PpmCalibrationToolsFormState extends State { separatorBuilder: (cxt, index) => 16.height, itemBuilder: (context, index) { if (index == widget.models!.length) { - return AppFilledButton( - label: "Add More Calibration Tools".addTranslation, - maxWidth: true, - textColor: AppColor.black10, - buttonColor: context.isDark ? AppColor.neutral60 : AppColor.white10, - icon: Icon(Icons.add_circle, color: AppColor.blueStatus(context)), - showIcon: true, - onPressed: () async { - if (widget.models?.isNotEmpty ?? false) { - if (widget.models!.last.asset?.id == null) { - await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.assetNumber}"); - return; + return Visibility( + visible: !ppmProvider.isReadOnly, + child: AppFilledButton( + label: "Add More Calibration Tools".addTranslation, + maxWidth: true, + textColor: AppColor.black10, + buttonColor: context.isDark ? AppColor.neutral60 : AppColor.white10, + icon: Icon(Icons.add_circle, color: AppColor.blueStatus(context)), + showIcon: true, + onPressed: () async { + if (widget.models?.isNotEmpty ?? false) { + if (widget.models!.last.asset?.id == null) { + await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.assetNumber}"); + return; + } + if (widget.models!.last.calibrationDateOfTesters == null) { + await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.date}"); + return; + } } - if (widget.models!.last.calibrationDateOfTesters == null) { - await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.date}"); - return; - } - } - widget.models!.add(PreventiveVisitCalibrations(id: 0)); - setState(() {}); - }, + widget.models!.add(PreventiveVisitCalibrations(id: 0)); + setState(() {}); + }, + ), ); } PreventiveVisitCalibrations model = widget.models![index]; @@ -69,48 +73,51 @@ class _PpmCalibrationToolsFormState extends State { borderRadius: BorderRadius.circular(20), boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.03), blurRadius: 14)], ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - (index == 0 ? "$currentIndex /$totalTabs . Calibration Tools" : "").heading5(context), - "trash".toSvgAsset(height: 20, width: 15).onPress(() { - widget.models!.remove(model); + child: IgnorePointer( + ignoring:ppmProvider.isReadOnly, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + (index == 0 ? "$currentIndex /$totalTabs . Calibration Tools" : "").heading5(context), + "trash".toSvgAsset(height: 20, width: 15).onPress(() { + widget.models!.remove(model); + setState(() {}); + }), + ], + ), + 16.height, + CalibrationToolAssetPicker( + initialValue: model.asset?.id == null ? null : Lookup(id: model.asset?.id?.toInt(), name: model.asset?.assetNumber ?? ""), + hospitalId: userProvider.user!.clientId, + onPick: (asset) { + model.asset = Asset(id: asset.id, assetNumber: asset.assetNumber, assetSerialNo: asset.assetSerialNo); + setState(() {}); + }, + ), + 12.height, + if (model.asset?.assetNumber != null) + Text("Asset Number: ${model.asset?.assetNumber?.cleanupWhitespace.capitalizeFirstOfEach}", style: AppTextStyles.bodyText2.copyWith(color: AppColor.neutral120)), + // if (model.assetName != null) Text("Asset Name: ${model.assetName?.cleanupWhitespace.capitalizeFirstOfEach}", style: AppTextStyles.bodyText2.copyWith(color: AppColor.neutral120)), + if (model.asset?.assetSerialNo != null) + Text("Asset Serial No: ${model.asset?.assetSerialNo?.cleanupWhitespace.capitalizeFirstOfEach}", style: AppTextStyles.bodyText2.copyWith(color: AppColor.neutral120)), + 12.height, + ADatePicker( + label: context.translation.calibrationDate, + date: DateTime.tryParse(model.calibrationDateOfTesters ?? ""), + from: DateTime.now().subtract(const Duration(days: 90)), + backgroundColor: context.isDark ? AppColor.neutral50 : AppColor.neutral100, + withBorder: false, + hideShadow: true, + onDatePicker: (date) { + model.calibrationDateOfTesters = date.toIso8601String(); setState(() {}); - }), - ], - ), - 16.height, - CalibrationToolAssetPicker( - initialValue: model.asset?.id == null ? null : Lookup(id: model.asset?.id?.toInt(), name: model.asset?.assetNumber ?? ""), - hospitalId: userProvider.user!.clientId, - onPick: (asset) { - model.asset = Asset(id: asset.id, assetNumber: asset.assetNumber, assetSerialNo: asset.assetSerialNo); - setState(() {}); - }, - ), - 12.height, - if (model.asset?.assetNumber != null) - Text("Asset Number: ${model.asset?.assetNumber?.cleanupWhitespace.capitalizeFirstOfEach}", style: AppTextStyles.bodyText2.copyWith(color: AppColor.neutral120)), - // if (model.assetName != null) Text("Asset Name: ${model.assetName?.cleanupWhitespace.capitalizeFirstOfEach}", style: AppTextStyles.bodyText2.copyWith(color: AppColor.neutral120)), - if (model.asset?.assetSerialNo != null) - Text("Asset Serial No: ${model.asset?.assetSerialNo?.cleanupWhitespace.capitalizeFirstOfEach}", style: AppTextStyles.bodyText2.copyWith(color: AppColor.neutral120)), - 12.height, - ADatePicker( - label: context.translation.calibrationDate, - date: DateTime.tryParse(model.calibrationDateOfTesters ?? ""), - from: DateTime.now().subtract(const Duration(days: 90)), - backgroundColor: context.isDark ? AppColor.neutral50 : AppColor.neutral100, - withBorder: false, - hideShadow: true, - onDatePicker: (date) { - model.calibrationDateOfTesters = date.toIso8601String(); - setState(() {}); - }, - ), - ], + }, + ), + ], + ), ), ); }, diff --git a/lib/views/pages/user/ppm/update_ppm/ppm_external_details_form.dart b/lib/views/pages/user/ppm/update_ppm/ppm_external_details_form.dart index 72aba1aa..8fb7db23 100644 --- a/lib/views/pages/user/ppm/update_ppm/ppm_external_details_form.dart +++ b/lib/views/pages/user/ppm/update_ppm/ppm_external_details_form.dart @@ -237,6 +237,8 @@ // } import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:test_sa/controllers/providers/api/ppm_provider.dart'; import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/int_extensions.dart'; import 'package:test_sa/extensions/string_extensions.dart'; @@ -289,20 +291,23 @@ class _PpmExternalDetailsFormState extends State { @override Widget build(BuildContext context) { - print("widget.models!.length:${widget.models!.length}"); + final ppmProvider = Provider.of(context, listen: false); return ListView.builder( itemCount: widget.models!.length + 1, padding: const EdgeInsets.all(16), itemBuilder: (context, index) { if (index == widget.models!.length) { - return AppFilledButton( - label: "Add More External Details".addTranslation, - maxWidth: true, - textColor: AppColor.black10, - buttonColor: context.isDark ? AppColor.neutral60 : AppColor.white10, - icon: Icon(Icons.add_circle, color: AppColor.blueStatus(context)), - showIcon: true, - onPressed: _addNewEntry, + return Visibility( + visible: !ppmProvider.isReadOnly, + child: AppFilledButton( + label: "Add More External Details".addTranslation, + maxWidth: true, + textColor: AppColor.black10, + buttonColor: context.isDark ? AppColor.neutral60 : AppColor.white10, + icon: Icon(Icons.add_circle, color: AppColor.blueStatus(context)), + showIcon: true, + onPressed: _addNewEntry, + ), ); } // return !isLoading @@ -336,10 +341,12 @@ class ExternalDetailItem extends StatefulWidget { class _ExternalDetailItemState extends State { TextEditingController? controller; + PpmProvider? _ppmProvider; @override void initState() { controller = TextEditingController(text: widget.model.workingHours != null ? widget.model.workingHours.toString() : ''); + _ppmProvider= Provider.of(context,listen:false); super.initState(); } @@ -353,148 +360,151 @@ class _ExternalDetailItemState extends State { borderRadius: BorderRadius.circular(20), boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.03), blurRadius: 14)], ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - (widget.index == 0 ? "1 /4 . External Details" : "").heading5(context), - Container( - height: 32, - width: 32, - padding: const EdgeInsets.all(6), - child: "trash".toSvgAsset(height: 20, width: 20), - ).onPress(() { - widget.onRemove(); - }), - ], - ), - 16.height, - SingleItemDropDownMenu( - context: context, - title: context.translation.supplier, - initialValue: widget.model.supplier, - backgroundColor: AppColor.neutral100, - showAsBottomSheet: true, - showShadow: false, - onSelect: (supplier) { - if (supplier != null) { - setState(() { - widget.model.supplier = supplier; - }); - } - }, - ), - 8.height, - SingleItemDropDownMenu( - context: context, - title: context.translation.supplierEngineer, - enabled: widget.model.supplier != null, - backgroundColor: AppColor.neutral100, - initialValue: widget.model.suppPerson, - staticData: widget.model.supplier?.suppPersons, - showAsBottomSheet: true, - showShadow: false, - onSelect: (suppPerson) { - if (suppPerson != null) { - widget.model.suppPerson = suppPerson; - } - }, - ), - 8.height, - Row( - mainAxisSize: MainAxisSize.min, - children: [ - ADatePicker( - label: context.translation.startTime, - hideShadow: true, - backgroundColor: AppColor.neutral100, - date: widget.model.startDateTime, - formatDateWithTime: true, - onDatePicker: (selectedDate) { - showTimePicker( - context: context, - initialTime: TimeOfDay.now(), - ).then((selectedTime) { - if (selectedTime != null) { - DateTime selectedDateTime = DateTime( - selectedDate.year, - selectedDate.month, - selectedDate.day, - selectedTime.hour, - selectedTime.minute, - ); - setState(() { - widget.model.startDateTime = selectedDateTime; - }); - widget.model.endDateTime = null; - controller?.clear(); - ServiceRequestUtils.calculateAndAssignWorkingHours( - startTime: widget.model.startDateTime, - endTime: widget.model.endDateTime, - workingHoursController: controller!, - updateModel: (hours) { - widget.model.workingHours = hours; - }, - ); - } + child: IgnorePointer( + ignoring: _ppmProvider!.isReadOnly, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + (widget.index == 0 ? "1 /4 . External Details" : "").heading5(context), + Container( + height: 32, + width: 32, + padding: const EdgeInsets.all(6), + child: "trash".toSvgAsset(height: 20, width: 20), + ).onPress(() { + widget.onRemove(); + }), + ], + ), + 16.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.supplier, + initialValue: widget.model.supplier, + backgroundColor: AppColor.neutral100, + showAsBottomSheet: true, + showShadow: false, + onSelect: (supplier) { + if (supplier != null) { + setState(() { + widget.model.supplier = supplier; }); - }, - ).expanded, - 8.width, - ADatePicker( - label: context.translation.endTime, - hideShadow: true, - backgroundColor: AppColor.neutral100, - date: widget.model.endDateTime, - formatDateWithTime: true, - onDatePicker: (selectedDate) { - showTimePicker( - context: context, - initialTime: TimeOfDay.now(), - ).then((selectedTime) { - if (selectedTime != null) { - DateTime selectedDateTime = DateTime( - selectedDate.year, - selectedDate.month, - selectedDate.day, - selectedTime.hour, - selectedTime.minute, - ); - if (widget.model.startDateTime != null && selectedDateTime.isBefore(widget.model.startDateTime!)) { - "End Date time must be greater than start date".showToast; - return; + } + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.supplierEngineer, + enabled: widget.model.supplier != null, + backgroundColor: AppColor.neutral100, + initialValue: widget.model.suppPerson, + staticData: widget.model.supplier?.suppPersons, + showAsBottomSheet: true, + showShadow: false, + onSelect: (suppPerson) { + if (suppPerson != null) { + widget.model.suppPerson = suppPerson; + } + }, + ), + 8.height, + Row( + mainAxisSize: MainAxisSize.min, + children: [ + ADatePicker( + label: context.translation.startTime, + hideShadow: true, + backgroundColor: AppColor.neutral100, + date: widget.model.startDateTime, + formatDateWithTime: true, + onDatePicker: (selectedDate) { + showTimePicker( + context: context, + initialTime: TimeOfDay.now(), + ).then((selectedTime) { + if (selectedTime != null) { + DateTime selectedDateTime = DateTime( + selectedDate.year, + selectedDate.month, + selectedDate.day, + selectedTime.hour, + selectedTime.minute, + ); + setState(() { + widget.model.startDateTime = selectedDateTime; + }); + widget.model.endDateTime = null; + controller?.clear(); + ServiceRequestUtils.calculateAndAssignWorkingHours( + startTime: widget.model.startDateTime, + endTime: widget.model.endDateTime, + workingHoursController: controller!, + updateModel: (hours) { + widget.model.workingHours = hours; + }, + ); } - setState(() { - widget.model.endDateTime = selectedDateTime; - }); - ServiceRequestUtils.calculateAndAssignWorkingHours( - startTime: widget.model.startDateTime, - endTime: widget.model.endDateTime, - workingHoursController: controller!, - updateModel: (hours) { - widget.model.workingHours = hours; - }, - ); - } - }); - }, - ).expanded, - ], - ), - 8.height, - AppTextFormField( - labelText: context.translation.workingHours, - backgroundColor: AppColor.neutral80, - controller: controller, - textAlign: TextAlign.center, - enable: false, - showShadow: false, - style: Theme.of(context).textTheme.titleMedium, - ), - 8.height, - ], + }); + }, + ).expanded, + 8.width, + ADatePicker( + label: context.translation.endTime, + hideShadow: true, + backgroundColor: AppColor.neutral100, + date: widget.model.endDateTime, + formatDateWithTime: true, + onDatePicker: (selectedDate) { + showTimePicker( + context: context, + initialTime: TimeOfDay.now(), + ).then((selectedTime) { + if (selectedTime != null) { + DateTime selectedDateTime = DateTime( + selectedDate.year, + selectedDate.month, + selectedDate.day, + selectedTime.hour, + selectedTime.minute, + ); + if (widget.model.startDateTime != null && selectedDateTime.isBefore(widget.model.startDateTime!)) { + "End Date time must be greater than start date".showToast; + return; + } + setState(() { + widget.model.endDateTime = selectedDateTime; + }); + ServiceRequestUtils.calculateAndAssignWorkingHours( + startTime: widget.model.startDateTime, + endTime: widget.model.endDateTime, + workingHoursController: controller!, + updateModel: (hours) { + widget.model.workingHours = hours; + }, + ); + } + }); + }, + ).expanded, + ], + ), + 8.height, + AppTextFormField( + labelText: context.translation.workingHours, + backgroundColor: AppColor.neutral80, + controller: controller, + textAlign: TextAlign.center, + enable: false, + showShadow: false, + style: Theme.of(context).textTheme.titleMedium, + ), + 8.height, + ], + ), ), ); } diff --git a/lib/views/pages/user/ppm/update_ppm/ppm_pm_check_list_form.dart b/lib/views/pages/user/ppm/update_ppm/ppm_pm_check_list_form.dart index f8c55d5d..7d6e727e 100644 --- a/lib/views/pages/user/ppm/update_ppm/ppm_pm_check_list_form.dart +++ b/lib/views/pages/user/ppm/update_ppm/ppm_pm_check_list_form.dart @@ -32,6 +32,7 @@ class _PpmPmChecklistFormState extends State { @override Widget build(BuildContext context) { int totalTabs = Provider.of(context, listen: false).totalTabs; + final ppmProvider = Provider.of(context, listen: false); int currentIndex = totalTabs == 4 ? 4 : 3; List? list = widget.checkList ?? []; return (list.isEmpty) @@ -42,68 +43,71 @@ class _PpmPmChecklistFormState extends State { shrinkWrap: true, separatorBuilder: (cxt, index) => 12.height, itemBuilder: (context, index) { - return Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (index == 0) ...[ - "$currentIndex /$totalTabs . PM Checklist".heading5(context), - 16.height, + return IgnorePointer( + ignoring: ppmProvider.isReadOnly, + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (index == 0) ...[ + "$currentIndex /$totalTabs . PM Checklist".heading5(context), + 16.height, + ], + AppTextFormField( + labelText: "Task".addTranslation, + labelStyle: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120, fontWeight: FontWeight.w500), + initialValue: list[index].instructionText?.text ?? "", + enable: false, + showShadow: false, + makeMultiLinesNull: true, + enableColor: AppColor.neutral100, + backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100, + // backgroundColor: context.isDark ? AppColor.neutral50 : null, + onChange: (text) { + list[index].taskComment = text; + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + showShadow: false, + backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100, + initialValue: list[index].taskStatus?.id == null ? null : Lookup(id: list[index].taskStatus?.id?.toInt(), name: list[index].taskStatus?.name), + title: context.translation.taskStatus, + onSelect: (value) { + if (value != null) { + list[index].taskStatus = Lookup(id: value.id, name: value.name, value: value.value); + } + }, + ), + 8.height, + AppTextFormField( + labelText: context.translation.measuredValue, + labelStyle: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120, fontWeight: FontWeight.w500), + initialValue: list[index].measuredValue ?? "", + // enable: false, + backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100, + showShadow: false, + onChange: (text) { + list[index].measuredValue = text; + }, + ), + 8.height, + AppTextFormField( + labelText: "Task Comment".addTranslation, + labelStyle: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120, fontWeight: FontWeight.w500), + initialValue: list[index].taskComment ?? "", + textInputType: TextInputType.multiline, + makeMultiLinesNull: true, + backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100, + showShadow: false, + onChange: (text) { + list[index].taskComment = text; + }, + ), ], - AppTextFormField( - labelText: "Task".addTranslation, - labelStyle: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120, fontWeight: FontWeight.w500), - initialValue: list[index].instructionText?.text ?? "", - enable: false, - showShadow: false, - makeMultiLinesNull: true, - enableColor: AppColor.neutral100, - backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100, - // backgroundColor: context.isDark ? AppColor.neutral50 : null, - onChange: (text) { - list[index].taskComment = text; - }, - ), - 8.height, - SingleItemDropDownMenu( - context: context, - showShadow: false, - backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100, - initialValue: list[index].taskStatus?.id == null ? null : Lookup(id: list[index].taskStatus?.id?.toInt(), name: list[index].taskStatus?.name), - title: context.translation.taskStatus, - onSelect: (value) { - if (value != null) { - list[index].taskStatus = Lookup(id: value.id, name: value.name, value: value.value); - } - }, - ), - 8.height, - AppTextFormField( - labelText: context.translation.measuredValue, - labelStyle: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120, fontWeight: FontWeight.w500), - initialValue: list[index].measuredValue ?? "", - // enable: false, - backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100, - showShadow: false, - onChange: (text) { - list[index].measuredValue = text; - }, - ), - 8.height, - AppTextFormField( - labelText: "Task Comment".addTranslation, - labelStyle: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120, fontWeight: FontWeight.w500), - initialValue: list[index].taskComment ?? "", - textInputType: TextInputType.multiline, - makeMultiLinesNull: true, - backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100, - showShadow: false, - onChange: (text) { - list[index].taskComment = text; - }, - ), - ], - ).toShadowContainer(context, showShadow: false, borderRadius: 20); + ).toShadowContainer(context, showShadow: false, borderRadius: 20), + ); }, ); } diff --git a/lib/views/pages/user/ppm/update_ppm/ppm_pm_kits_form.dart b/lib/views/pages/user/ppm/update_ppm/ppm_pm_kits_form.dart index fc3ffc94..516250a5 100644 --- a/lib/views/pages/user/ppm/update_ppm/ppm_pm_kits_form.dart +++ b/lib/views/pages/user/ppm/update_ppm/ppm_pm_kits_form.dart @@ -26,7 +26,8 @@ class PpmPMKitsForm extends StatefulWidget { class _PpmPMKitsFormState extends State { @override Widget build(BuildContext context) { - int totalTabs = Provider.of(context, listen: false).totalTabs; + final ppmProvider = Provider.of(context, listen: false); + int totalTabs = ppmProvider.totalTabs; int currentIndex = totalTabs == 4 ? 3 : 2; return ListView.builder( itemCount: widget.models!.length + 1, @@ -34,27 +35,30 @@ class _PpmPMKitsFormState extends State { padding: const EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 16), itemBuilder: (context, index) { if (index == widget.models!.length) { - return AppFilledButton( - label: "Add More PM Kits".addTranslation, - maxWidth: true, - textColor: AppColor.black10, - buttonColor: context.isDark ? AppColor.neutral60 : AppColor.white10, - icon: Icon(Icons.add_circle, color: AppColor.blueStatus(context)), - showIcon: true, - onPressed: () async { - if (widget.models?.isNotEmpty ?? false) { - if (widget.models!.last.partCatalogItem?.partNumber == null) { - await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.partNumber}"); - return; + return Visibility( + visible: !ppmProvider.isReadOnly, + child: AppFilledButton( + label: "Add More PM Kits".addTranslation, + maxWidth: true, + textColor: AppColor.black10, + buttonColor: context.isDark ? AppColor.neutral60 : AppColor.white10, + icon: Icon(Icons.add_circle, color: AppColor.blueStatus(context)), + showIcon: true, + onPressed: () async { + if (widget.models?.isNotEmpty ?? false) { + if (widget.models!.last.partCatalogItem?.partNumber == null) { + await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.partNumber}"); + return; + } + if (widget.models!.last.partCatalogItem?.partName == null) { + await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.partName}"); + return; + } } - if (widget.models!.last.partCatalogItem?.partName == null) { - await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.partName}"); - return; - } - } - widget.models!.add(PreventiveVisitKits(id: 0)); - setState(() {}); - }, + widget.models!.add(PreventiveVisitKits(id: 0)); + setState(() {}); + }, + ), ); } final model = widget.models![index]; @@ -66,47 +70,50 @@ class _PpmPMKitsFormState extends State { borderRadius: BorderRadius.circular(20), boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.03), blurRadius: 14)], ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - (index == 0 ? "$currentIndex /$totalTabs . PM Kits" : "").heading5(context), - Container( - height: 32, - width: 32, - padding: const EdgeInsets.all(6), - child: "trash".toSvgAsset(height: 20, width: 20), - ).onPress(() { - widget.models!.remove(model); + child: IgnorePointer( + ignoring: ppmProvider.isReadOnly, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + (index == 0 ? "$currentIndex /$totalTabs . PM Kits" : "").heading5(context), + Container( + height: 32, + width: 32, + padding: const EdgeInsets.all(6), + child: "trash".toSvgAsset(height: 20, width: 20), + ).onPress(() { + widget.models!.remove(model); + setState(() {}); + }), + ], + ), + 16.height, + AutoCompletePartsField( + assetId: widget.assetId, + clearAfterPick: false, + byName: true, + initialValue: model.partCatalogItem?.partName ?? "", + onPick: (part) { + model.partCatalogItem = PartCatalogItem(id: part.sparePart?.id, partNumber: part.sparePart?.partNo, partName: part.sparePart?.partName, oracleCode: part.sparePart?.oracleCode); + setState(() {}); + }, + ), + 8.height, + AutoCompletePartsField( + assetId: widget.assetId, + clearAfterPick: false, + byName: false, + initialValue: model.partCatalogItem?.partNumber ?? "", + onPick: (part) { + model.partCatalogItem = PartCatalogItem(id: part.sparePart?.id, partNumber: part.sparePart?.partNo, partName: part.sparePart?.partName, oracleCode: part.sparePart?.oracleCode); setState(() {}); - }), - ], - ), - 16.height, - AutoCompletePartsField( - assetId: widget.assetId, - clearAfterPick: false, - byName: true, - initialValue: model.partCatalogItem?.partName ?? "", - onPick: (part) { - model.partCatalogItem = PartCatalogItem(id: part.sparePart?.id, partNumber: part.sparePart?.partNo, partName: part.sparePart?.partName, oracleCode: part.sparePart?.oracleCode); - setState(() {}); - }, - ), - 8.height, - AutoCompletePartsField( - assetId: widget.assetId, - clearAfterPick: false, - byName: false, - initialValue: model.partCatalogItem?.partNumber ?? "", - onPick: (part) { - model.partCatalogItem = PartCatalogItem(id: part.sparePart?.id, partNumber: part.sparePart?.partNo, partName: part.sparePart?.partName, oracleCode: part.sparePart?.oracleCode); - setState(() {}); - }, - ), - ], + }, + ), + ], + ), ), ); }, diff --git a/lib/views/pages/user/ppm/update_ppm/update_ppm.dart b/lib/views/pages/user/ppm/update_ppm/update_ppm.dart index 51255a31..a0fcbf30 100644 --- a/lib/views/pages/user/ppm/update_ppm/update_ppm.dart +++ b/lib/views/pages/user/ppm/update_ppm/update_ppm.dart @@ -79,9 +79,12 @@ class _UpdatePpmState extends State with TickerProviderStateMixin { @override void initState() { + ppmProvider = Provider.of(context, listen: false); _planPreventiveVisit = widget.planPreventiveVisit; - initTabs(_planPreventiveVisit.typeOfService); + // WidgetsBinding.instance.addPostFrameCallback((_) { + initTabs(_planPreventiveVisit.typeOfService); + // }); super.initState(); } @@ -112,7 +115,7 @@ class _UpdatePpmState extends State with TickerProviderStateMixin { backgroundColor: AppColor.neutral110, appBar: DefaultAppBar( title: context.translation.preventiveMaintenance, - onWillPopScope: () { + onWillPopScope:ppmProvider.isReadOnly?null: () { _onSubmit(status: 0); }, ), @@ -186,8 +189,8 @@ class _UpdatePpmState extends State with TickerProviderStateMixin { children: [ if (tabIndex == 1) ...[ AppFilledButton( - buttonColor: _tabController!.index == 0 ? null:AppColor.background(context), - textColor: _tabController!.index == 0 ? null: AppColor.blueStatus(context), + buttonColor: _tabController!.index == 0 ? null : AppColor.background(context), + textColor: _tabController!.index == 0 ? null : AppColor.blueStatus(context), showBorder: true, disableButton: _tabController!.index == 0, onPressed: () { @@ -202,30 +205,47 @@ class _UpdatePpmState extends State with TickerProviderStateMixin { ).expanded, 8.width, ], - AppFilledButton( - buttonColor: AppColor.white60, - textColor: AppColor.neutral50, - onPressed: () { - _onSubmit(status: 0); - }, - label: context.translation.save, - ).expanded, - 8.width, - AppFilledButton( - onPressed: () { - if (tabIndex == 0) { - _onSubmit(status: 1); - return; - } - if (ppmProvider.totalTabs == _tabController!.index + 1) { - _onSubmit(status: 1); - } else { - _tabController?.animateTo(_tabController!.index + 1); - setState(() {}); - } - }, - label: tabIndex == 0 ? "Complete".addTranslation : ((ppmProvider.totalTabs == _tabController!.index + 1) ? "Complete".addTranslation : context.translation.next), - ).expanded, + if (!ppmProvider.isReadOnly) ...[ + AppFilledButton( + buttonColor: AppColor.white60, + textColor: AppColor.neutral50, + onPressed: () { + _onSubmit(status: 0); + }, + label: context.translation.save, + ).expanded, + 8.width, + AppFilledButton( + onPressed: () { + if (tabIndex == 0) { + _onSubmit(status: 1); + return; + } + if (ppmProvider.totalTabs == _tabController!.index + 1) { + _onSubmit(status: 1); + } else { + _tabController?.animateTo(_tabController!.index + 1); + setState(() {}); + } + }, + label: tabIndex == 0 ? "Complete".addTranslation : ((ppmProvider.totalTabs == _tabController!.index + 1) ? "Complete".addTranslation : context.translation.next), + ).expanded, + ] else ...[ + Visibility( + visible: tabIndex != 0, + child: AppFilledButton( + onPressed: () { + if(ppmProvider.totalTabs == _tabController!.index + 1){ + Navigator.pop(context); + return; + } + _tabController?.animateTo(_tabController!.index + 1); + setState(() {}); + }, + label:ppmProvider.totalTabs == _tabController!.index + 1? context.translation.close: context.translation.next, + ).expanded, + ), + ] ], ).toShadowContainer(context, showShadow: false, borderRadius: 0), ], diff --git a/lib/views/pages/user/ppm/update_ppm/wo_info_form.dart b/lib/views/pages/user/ppm/update_ppm/wo_info_form.dart index 577dcc2d..1000d39e 100644 --- a/lib/views/pages/user/ppm/update_ppm/wo_info_form.dart +++ b/lib/views/pages/user/ppm/update_ppm/wo_info_form.dart @@ -6,8 +6,15 @@ import 'package:test_sa/controllers/providers/api/ppm_provider.dart'; import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/int_extensions.dart'; import 'package:test_sa/extensions/string_extensions.dart'; +import 'package:test_sa/models/device/model_definition.dart'; +import 'package:test_sa/models/device/supplier.dart'; import 'package:test_sa/extensions/text_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart'; +import 'package:test_sa/models/new_models/building.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/models/new_models/site.dart'; import 'package:test_sa/models/plan_preventive_visit/plan_preventive_visit_model.dart'; import 'package:test_sa/new_views/app_style/app_color.dart'; import 'package:test_sa/providers/ppm_asset_availability_provider.dart'; @@ -59,232 +66,238 @@ class _WoInfoFormState extends State { totalWorkingHours = totalWorkingHours; return Consumer(builder: (context, ppmProvider, child) { + return ListView( padding: const EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 16), children: [ - Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (widget.planPreventiveVisit.visitStatus != null) - StatusLabel( - label: widget.planPreventiveVisit.visitStatus?.name, - textColor: AppColor.getRequestStatusTextColorByName(context, widget.planPreventiveVisit.visitStatus?.name), - backgroundColor: AppColor.getRequestStatusColorByName(context, widget.planPreventiveVisit.visitStatus?.name), - ), - 8.height, - widget.planPreventiveVisit.planName!.bodyText(context).custom(color: AppColor.black10), - 2.height, - '${context.translation.pmPlanNo}: ${widget.planPreventiveVisit.planNo}'.bodyText2(context).custom(color: AppColor.neutral120), - //need to add in translation it's suggestion from ahmed.. - 'Work Order Number: ${widget.planPreventiveVisit.visitNo}'.bodyText2(context).custom(color: AppColor.neutral120), - '${context.translation.creationDate}: ${widget.planPreventiveVisit.creationDate?.toMonthYearFormat}'.bodyText2(context).custom(color: AppColor.neutral120), - '${context.translation.closedDate}: ${widget.planPreventiveVisit.closedDate != null ? widget.planPreventiveVisit.closedDate?.toMonthYearFormat : '-'}' - .bodyText2(context) - .custom(color: AppColor.neutral120), - - '${context.translation.nextPmDate}: ${widget.planPreventiveVisit.nextPMDate != null ? widget.planPreventiveVisit.nextPMDate!.toMonthYearFormat : '-'}' - .bodyText2(context) - .custom(color: AppColor.neutral120), - '${context.translation.assignEngineer}: ${widget.planPreventiveVisit.assignedEmployee?.userName ?? ""}'.bodyText2(context).custom(color: AppColor.neutral120), - '${context.translation.executionTimeFrame}: ${widget.planPreventiveVisit.executionTimeFrame ?? ""} days'.bodyText2(context).custom(color: AppColor.neutral120), - ], - ).toShadowContainer(context), - 12.height, - Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - widget.planPreventiveVisit.assetName!.bodyText(context).custom(color: AppColor.black10), - "info_icon".toSvgAsset(height: 17, width: 17).onPress( - () { - // There is only limited information for asset is returned from backend to show all info need to return the whole model from backend... - showModalBottomSheet( - context: context, - isScrollControlled: true, - shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.vertical( - top: Radius.circular(20), - ), - ), - clipBehavior: Clip.antiAliasWithSaveLayer, - builder: (BuildContext context) => _buildAssetDetailBottomSheet(context), - ); - }, - ) - ], - ), - 2.height, - '${context.translation.assetNo}: ${widget.planPreventiveVisit.asset?.assetNumber}'.bodyText2(context).custom(color: AppColor.neutral120), - '${context.translation.model}: ${widget.planPreventiveVisit.model}'.bodyText2(context).custom(color: AppColor.neutral120), - ], - ).toShadowContainer(context), + IgnorePointer( + ignoring: ppmProvider.isReadOnly, + child: Column( + children: [ + Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (widget.planPreventiveVisit.visitStatus != null) + StatusLabel( + label: widget.planPreventiveVisit.visitStatus?.name, + textColor: AppColor.getRequestStatusTextColorByName(context, widget.planPreventiveVisit.visitStatus?.name), + backgroundColor: AppColor.getRequestStatusColorByName(context, widget.planPreventiveVisit.visitStatus?.name), + ), + 8.height, + widget.planPreventiveVisit.planName!.bodyText(context).custom(color: AppColor.black10), + 2.height, + '${context.translation.pmPlanNo}: ${widget.planPreventiveVisit.planNo}'.bodyText2(context).custom(color: AppColor.neutral120), + //need to add in translation it's suggestion from ahmed.. + 'Work Order Number: ${widget.planPreventiveVisit.visitNo}'.bodyText2(context).custom(color: AppColor.neutral120), + '${context.translation.creationDate}: ${widget.planPreventiveVisit.creationDate?.toMonthYearFormat}'.bodyText2(context).custom(color: AppColor.neutral120), + '${context.translation.closedDate}: ${widget.planPreventiveVisit.closedDate != null ? widget.planPreventiveVisit.closedDate?.toMonthYearFormat : '-'}' + .bodyText2(context) + .custom(color: AppColor.neutral120), - // SingleItemDropDownMenu( - // context: context, - // initialValue: - // widget.planPreventiveVisit.visitStatus?.id == null ? null : Lookup(name: widget.planPreventiveVisit.visitStatus?.name ?? "", id: widget.planPreventiveVisit.visitStatus?.id?.toInt()), - // title: context.translation.ppmVisit, - // onSelect: (value) { - // if (value?.value == 4) { - // "Status cannot be change to ${value?.name}.".addTranslation.showToast; - // setState(() {}); - // return; - // } - // - // if (value != null) { - // widget.planPreventiveVisit.visitStatus?.name = value.name; - // widget.planPreventiveVisit.visitStatus?.id = value.id; - // } - // }, - // ), + '${context.translation.nextPmDate}: ${widget.planPreventiveVisit.nextPMDate != null ? widget.planPreventiveVisit.nextPMDate!.toMonthYearFormat : '-'}' + .bodyText2(context) + .custom(color: AppColor.neutral120), + '${context.translation.assignEngineer}: ${widget.planPreventiveVisit.assignedEmployee?.userName ?? ""}'.bodyText2(context).custom(color: AppColor.neutral120), + '${context.translation.executionTimeFrame}: ${widget.planPreventiveVisit.executionTimeFrame ?? ""} days'.bodyText2(context).custom(color: AppColor.neutral120), + ], + ).toShadowContainer(context), + 12.height, + Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + widget.planPreventiveVisit.assetName!.bodyText(context).custom(color: AppColor.black10), + "info_icon".toSvgAsset(height: 17, width: 17).onPress( + () { + // There is only limited information for asset is returned from backend to show all info need to return the whole model from backend... + showModalBottomSheet( + context: context, + isScrollControlled: true, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.vertical( + top: Radius.circular(20), + ), + ), + clipBehavior: Clip.antiAliasWithSaveLayer, + builder: (BuildContext context) => _buildAssetDetailBottomSheet(context), + ); + }, + ) + ], + ), + 2.height, + '${context.translation.assetNo}: ${widget.planPreventiveVisit.asset?.assetNumber}'.bodyText2(context).custom(color: AppColor.neutral120), + '${context.translation.model}: ${widget.planPreventiveVisit.model}'.bodyText2(context).custom(color: AppColor.neutral120), + ], + ).toShadowContainer(context), - // SingleItemDropDownMenu( - // context: context, - // initialValue: widget.planPreventiveVisit.deviceStatusId == null ? null : Lookup(name: widget.model.deviceStatusName ?? "", id: widget.model.deviceStatusId?.toInt()), - // title: context.translation.deviceStatus, - // onSelect: (value) { - // if (value != null) { - // widget.planPreventiveVisit.deviceStatusId = value.id; - // widget.planPreventiveVisit.deviceStatusName = value.name; - // } - // }, - // ), - 8.height, - Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - //TODO Ahmed need to provide look up value.... + // SingleItemDropDownMenu( + // context: context, + // initialValue: + // widget.planPreventiveVisit.visitStatus?.id == null ? null : Lookup(name: widget.planPreventiveVisit.visitStatus?.name ?? "", id: widget.planPreventiveVisit.visitStatus?.id?.toInt()), + // title: context.translation.ppmVisit, + // onSelect: (value) { + // if (value?.value == 4) { + // "Status cannot be change to ${value?.name}.".addTranslation.showToast; + // setState(() {}); + // return; + // } + // + // if (value != null) { + // widget.planPreventiveVisit.visitStatus?.name = value.name; + // widget.planPreventiveVisit.visitStatus?.id = value.id; + // } + // }, + // ), - SingleItemDropDownMenu( - context: context, - showShadow: false, - initialValue: widget.planPreventiveVisit.taskStatus == null ? null : Lookup(name: widget.planPreventiveVisit.taskStatus?.name ?? "", id: widget.planPreventiveVisit.taskStatus?.id), - title: context.translation.pmTestResult, - backgroundColor: AppColor.neutral100, - onSelect: (value) { - if (value != null) { - widget.planPreventiveVisit.taskStatus = value; - } - }, - ), - 8.height, - ADatePicker( - label: context.translation.actualVisit, - hideShadow: true, - backgroundColor: AppColor.neutral100, - date: widget.planPreventiveVisit.acutalDateOfVisit, - formatDateWithTime: true, - onDatePicker: (selectedDate) { - showTimePicker( - context: context, - initialTime: TimeOfDay.now(), - ).then((selectedTime) { - if (selectedTime != null) { - DateTime selectedDateTime = DateTime( - selectedDate.year, - selectedDate.month, - selectedDate.day, - selectedTime.hour, - selectedTime.minute, - ); - setState(() { - widget.planPreventiveVisit.acutalDateOfVisit = selectedDateTime; - }); - } - }); - }, - ), - // SingleItemDropDownMenu( - // context: context, - // backgroundColor: AppColor.neutral100, - // initialValue: widget.planPreventiveVisit.safety?.id == null ? null : Lookup(name: widget.planPreventiveVisit.safety?.name ?? "", id: widget.planPreventiveVisit.safety?.id), - // title: context.translation.actualVisit, - // onSelect: (value) { - // if (value != null) { - // widget.planPreventiveVisit.safety = value; - // // widget.planPreventiveVisit.safety?.id = value.id; - // // widget.planPreventiveVisit.safety?.name = value.name; - // } - // }, - // ), + // SingleItemDropDownMenu( + // context: context, + // initialValue: widget.planPreventiveVisit.deviceStatusId == null ? null : Lookup(name: widget.model.deviceStatusName ?? "", id: widget.model.deviceStatusId?.toInt()), + // title: context.translation.deviceStatus, + // onSelect: (value) { + // if (value != null) { + // widget.planPreventiveVisit.deviceStatusId = value.id; + // widget.planPreventiveVisit.deviceStatusName = value.name; + // } + // }, + // ), + 8.height, + Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + SingleItemDropDownMenu( + context: context, + showShadow: false, + initialValue: widget.planPreventiveVisit.taskStatus == null ? null : Lookup(name: widget.planPreventiveVisit.taskStatus?.name ?? "", id: widget.planPreventiveVisit.taskStatus?.id), + title: context.translation.pmTestResult, + backgroundColor: AppColor.neutral100, + onSelect: (value) { + if (value != null) { + widget.planPreventiveVisit.taskStatus = value; + } + }, + ), + 8.height, + ADatePicker( + label: context.translation.actualVisit, + hideShadow: true, + backgroundColor: AppColor.neutral100, + date: widget.planPreventiveVisit.acutalDateOfVisit, + formatDateWithTime: true, + onDatePicker: (selectedDate) { + showTimePicker( + context: context, + initialTime: TimeOfDay.now(), + ).then((selectedTime) { + if (selectedTime != null) { + DateTime selectedDateTime = DateTime( + selectedDate.year, + selectedDate.month, + selectedDate.day, + selectedTime.hour, + selectedTime.minute, + ); + setState(() { + widget.planPreventiveVisit.acutalDateOfVisit = selectedDateTime; + }); + } + }); + }, + ), + // SingleItemDropDownMenu( + // context: context, + // backgroundColor: AppColor.neutral100, + // initialValue: widget.planPreventiveVisit.safety?.id == null ? null : Lookup(name: widget.planPreventiveVisit.safety?.name ?? "", id: widget.planPreventiveVisit.safety?.id), + // title: context.translation.actualVisit, + // onSelect: (value) { + // if (value != null) { + // widget.planPreventiveVisit.safety = value; + // // widget.planPreventiveVisit.safety?.id = value.id; + // // widget.planPreventiveVisit.safety?.name = value.name; + // } + // }, + // ), - 8.height, - SingleItemDropDownMenu( - context: context, - backgroundColor: AppColor.neutral100, - showShadow: false, - initialValue: widget.planPreventiveVisit.safety?.id == null ? null : Lookup(name: widget.planPreventiveVisit.safety?.name ?? "", id: widget.planPreventiveVisit.safety?.id), - title: "Electrical Safety", - onSelect: (value) { - if (value != null) { - widget.planPreventiveVisit.safety = value; - } - }, - ), - 8.height, - SingleItemDropDownMenu( - context: context, - backgroundColor: AppColor.neutral100, - showShadow: false, - initialValue: widget.planPreventiveVisit.assetAvailability == null - ? null - : Lookup(name: widget.planPreventiveVisit.assetAvailability?.name ?? "", id: widget.planPreventiveVisit.assetAvailability?.id), - title: "Asset Availability", - onSelect: (value) { - if (value != null) { - widget.planPreventiveVisit.assetAvailability = value; - } - }, - ), - 8.height, - SingleItemDropDownMenu( - context: context, - backgroundColor: AppColor.neutral100, - showShadow: false, - initialValue: widget.planPreventiveVisit.typeOfService == null - ? null - : Lookup(name: widget.planPreventiveVisit.typeOfService?.name ?? "", id: widget.planPreventiveVisit.typeOfService?.id?.toInt()), - title: context.translation.typeOfPm, - onSelect: (value) { - if (value != null) { - widget.planPreventiveVisit.typeOfService = value; - if (widget.planPreventiveVisit.typeOfService?.id == 66) { - ppmProvider.totalTabs = 4; - } else { - ppmProvider.totalTabs = 3; - } - widget.onTypeOfServiceChange!(value); - } - }, - ), - 8.height, - _timerWidget(context, totalWorkingHours), - 8.height, - AppTextFormField( - labelText: context.translation.comment, - backgroundColor: AppColor.neutral100, - showShadow: false, - initialValue: (widget.planPreventiveVisit.comments ?? "").toString(), - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.titleMedium, - onChange: (value) { - widget.planPreventiveVisit.comments = value; - }, - ), - 16.height, - MultiFilesPicker( - label: context.translation.attachments, - files: ppmProvider.ppmPlanAttachments, - buttonColor: AppColor.black10, - onlyImages: false, - buttonIcon: 'image-plus'.toSvgAsset(color: AppColor.neutral120), - ), - ], - ).toShadowContainer(context), + 8.height, + SingleItemDropDownMenu( + context: context, + backgroundColor: AppColor.neutral100, + showShadow: false, + initialValue: widget.planPreventiveVisit.safety?.id == null ? null : Lookup(name: widget.planPreventiveVisit.safety?.name ?? "", id: widget.planPreventiveVisit.safety?.id), + title: "Electrical Safety", + onSelect: (value) { + if (value != null) { + widget.planPreventiveVisit.safety = value; + } + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + backgroundColor: AppColor.neutral100, + showShadow: false, + initialValue: widget.planPreventiveVisit.assetAvailability == null + ? null + : Lookup(name: widget.planPreventiveVisit.assetAvailability?.name ?? "", id: widget.planPreventiveVisit.assetAvailability?.id), + title: "Asset Availability", + onSelect: (value) { + if (value != null) { + widget.planPreventiveVisit.assetAvailability = value; + } + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + backgroundColor: AppColor.neutral100, + showShadow: false, + initialValue: widget.planPreventiveVisit.typeOfService == null + ? null + : Lookup(name: widget.planPreventiveVisit.typeOfService?.name ?? "", id: widget.planPreventiveVisit.typeOfService?.id?.toInt()), + title: context.translation.typeOfPm, + onSelect: (value) { + if (value != null) { + widget.planPreventiveVisit.typeOfService = value; + if (widget.planPreventiveVisit.typeOfService?.id == 66) { + ppmProvider.totalTabs = 4; + } else { + ppmProvider.totalTabs = 3; + } + widget.onTypeOfServiceChange!(value); + } + }, + ), + 8.height, + _timerWidget(context, totalWorkingHours), + 8.height, + AppTextFormField( + labelText: context.translation.comment, + backgroundColor: AppColor.neutral100, + showShadow: false, + initialValue: (widget.planPreventiveVisit.comments ?? "").toString(), + textAlign: TextAlign.center, + style: Theme.of(context).textTheme.titleMedium, + onChange: (value) { + widget.planPreventiveVisit.comments = value; + }, + ), + 16.height, + MultiFilesPicker( + label: context.translation.attachments, + files: ppmProvider.ppmPlanAttachments, + buttonColor: AppColor.black10, + onlyImages: false, + buttonIcon: 'image-plus'.toSvgAsset(color: AppColor.neutral120), + ), + ], + ).toShadowContainer(context), + ], + ), + ), //TODO need to check this also... // ESignature( // title: context.translation.nurseSignature, @@ -311,8 +324,18 @@ class _WoInfoFormState extends State { _buildAssetDetailBottomSheet(BuildContext context) { PlanPreventiveVisit model = widget.planPreventiveVisit; - - Asset asset = Asset(id: model.asset?.id, assetSerialNo: model.asset?.assetSerialNo, assetNumber: model.asset?.assetNumber); + Asset asset = Asset( + id: model.asset?.id, + assetSerialNo: model.asset?.assetSerialNo, + assetNumber: model.asset?.assetNumber, + building: Building(name: model.buildingName), + floor: Floor(name: model.floorName), + site: Site(custName: model.siteName), + supplier: Supplier(suppliername: model.supplierName), + modelDefinition: ModelDefinition(modelName: model.model, manufacturerName: model.manufacturer), + room: Rooms(value: int.tryParse(model.roomName??'')), + department: Department(departmentName: model.departmentName), + ); return AssetDetailBottomSheet(asset); }