diff --git a/lib/models/ppm/ppm.dart b/lib/models/ppm/ppm.dart index c6c59272..02fd46dc 100644 --- a/lib/models/ppm/ppm.dart +++ b/lib/models/ppm/ppm.dart @@ -87,6 +87,9 @@ class Ppm { this.safetyName, this.siteId, this.siteName, + this. buildingName, + this. floorName, + this. roomName, this.supplierName, this.suppPerson, this.taskStatusName, @@ -203,6 +206,9 @@ class Ppm { safetyName = json['safetyName']; siteId = json['siteId']; siteName = json['siteName']; + buildingName = json['buildingName']; + floorName = json['floorName']; + roomName = json['roomName']; supplierName = json['supplierName']; suppPerson = json['suppPerson']; taskStatusName = json['taskStatusName']; @@ -288,6 +294,9 @@ class Ppm { String safetyName; num siteId; String siteName; + String buildingName; + String floorName; + String roomName; String supplierName; String suppPerson; String taskStatusName; @@ -376,6 +385,9 @@ class Ppm { String safetyName, num siteId, String siteName, + String buildingName, + String floorName, + String roomName, String supplierName, String suppPerson, String taskStatusName, @@ -458,6 +470,9 @@ class Ppm { safetyName: safetyName ?? this.safetyName, siteId: siteId ?? this.siteId, siteName: siteName ?? this.siteName, + buildingName: buildingName ?? this.buildingName, + floorName: floorName ?? this.floorName, + roomName: roomName ?? this.roomName, supplierName: supplierName ?? this.supplierName, suppPerson: suppPerson ?? this.suppPerson, taskStatusName: taskStatusName ?? this.taskStatusName, diff --git a/lib/new_views/common_widgets/single_item_drop_down_menu.dart b/lib/new_views/common_widgets/single_item_drop_down_menu.dart index 2bc9c484..4043a76b 100644 --- a/lib/new_views/common_widgets/single_item_drop_down_menu.dart +++ b/lib/new_views/common_widgets/single_item_drop_down_menu.dart @@ -2,17 +2,21 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/int_extensions.dart'; +import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/new_views/common_widgets/app_loading_manager.dart'; import 'package:test_sa/providers/loading_list_notifier.dart'; +import 'package:test_sa/views/widgets/bottom_sheets/selection_bottom_sheet.dart'; import '../../models/base.dart'; import '../app_style/app_color.dart'; -class SingleItemDropDownMenu extends StatefulWidget { +class SingleItemDropDownMenu + extends StatefulWidget { final BuildContext context; final Function(T) onSelect; final T initialValue; final bool enabled; + final bool showAsBottomSheet; final List staticData; final String title; final Color backgroundColor; @@ -27,16 +31,19 @@ class SingleItemDropDownMenu exte this.onSelect, this.initialValue, this.enabled = true, + this.showAsBottomSheet = false, this.staticData, this.backgroundColor, this.loading, }) : super(key: key); @override - State> createState() => _SingleItemDropDownMenuState(); + State> createState() => + _SingleItemDropDownMenuState(); } -class _SingleItemDropDownMenuState extends State> { +class _SingleItemDropDownMenuState extends State> { T _selectedItem; X provider; @@ -46,11 +53,15 @@ class _SingleItemDropDownMenuState(widget.context); } if (widget.initialValue != null) { - final result = (X == NullableLoadingProvider ? widget.staticData : provider.items)?.where((element) { + final result = + (X == NullableLoadingProvider ? widget.staticData : provider.items) + ?.where((element) { return element.identifier == widget.initialValue.identifier; }); if (result?.isNotEmpty ?? false) _selectedItem = result.first; - if (widget.onSelect != null && (widget.initialValue?.identifier ?? "") != (_selectedItem?.identifier ?? "")) { + if (widget.onSelect != null && + (widget.initialValue?.identifier ?? "") != + (_selectedItem?.identifier ?? "")) { widget.onSelect(_selectedItem); } } @@ -65,7 +76,9 @@ class _SingleItemDropDownMenuState oldWidget) { if (widget.initialValue != null) { - final result = (X == NullableLoadingProvider ? widget.staticData : provider.items)?.where((element) { + final result = + (X == NullableLoadingProvider ? widget.staticData : provider.items) + ?.where((element) { return element.identifier == widget.initialValue.identifier; }); if (result?.isNotEmpty ?? false) { @@ -73,7 +86,9 @@ class _SingleItemDropDownMenuState( value: _selectedItem, @@ -127,12 +153,14 @@ class _SingleItemDropDownMenuState>((value) { + items: ((X == NullableLoadingProvider) + ? widget.staticData + : provider.items) + ?.map>((value) { return DropdownMenuItem( value: value, child: Text( @@ -150,7 +181,31 @@ class _SingleItemDropDownMenuState SelectionBottomSheet( + items: ((X == NullableLoadingProvider) + ? widget.staticData + : provider.items), + selectedItem: _selectedItem, + title: widget.title, + builderString: (emp) => emp?.name ?? "", + ), + )) as T; + if(_selectedT !=null) { + widget.onSelect(_selectedT); + } + + } : null), ], ), ], diff --git a/lib/views/pages/user/ppm/ppm_details_page.dart b/lib/views/pages/user/ppm/ppm_details_page.dart index a76b34cb..c5430262 100644 --- a/lib/views/pages/user/ppm/ppm_details_page.dart +++ b/lib/views/pages/user/ppm/ppm_details_page.dart @@ -98,7 +98,10 @@ class _PpmDetailsPageState extends State { '${context.translation.assignedTo}: ${ppm.assignedToName ?? ""}'.bodyText(context), '${context.translation.engineerName}: ${ppm.assignedEmployeeName ?? ""}'.bodyText(context), '${context.translation.site}: ${ppm.siteName?.cleanupWhitespace?.capitalizeFirstOfEach}'.bodyText(context), + '${context.translation.building}: ${ppm.buildingName?.cleanupWhitespace?.capitalizeFirstOfEach}'.bodyText(context), + '${context.translation.floor}: ${ppm.floorName?.cleanupWhitespace?.capitalizeFirstOfEach}'.bodyText(context), '${context.translation.department}: ${ppm.departmentName?.cleanupWhitespace?.capitalizeFirstOfEach}'.bodyText(context), + '${context.translation.room}: ${(ppm.roomName??"").cleanupWhitespace?.capitalizeFirstOfEach}'.bodyText(context), ], ).toShadowContainer(context).paddingAll(16), ).expanded, diff --git a/lib/views/pages/user/requests/service_request_details.dart b/lib/views/pages/user/requests/service_request_details.dart index c55239b6..de7d7f96 100644 --- a/lib/views/pages/user/requests/service_request_details.dart +++ b/lib/views/pages/user/requests/service_request_details.dart @@ -147,10 +147,22 @@ class _ServiceRequestDetailsPageState extends State { '${context.translation.site}: ${serviceRequest.device.site.custName?.cleanupWhitespace?.capitalizeFirstOfEach}', style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20), ), + Text( + '${context.translation.building}: ${serviceRequest.device.building.name?.cleanupWhitespace?.capitalizeFirstOfEach}', + style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20), + ), + Text( + '${context.translation.floor}: ${serviceRequest.device.floor.name?.cleanupWhitespace?.capitalizeFirstOfEach}', + style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20), + ), Text( '${context.translation.department}: ${serviceRequest.device.department.departmentName?.cleanupWhitespace?.capitalizeFirstOfEach}', style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20), ), + Text( + '${context.translation.room}: ${(serviceRequest.device.room?.name ?? "").cleanupWhitespace?.capitalizeFirstOfEach}', + style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral20), + ), 8.height, if ((serviceRequest.callComments ?? "").isNotEmpty) ...[ const Divider().defaultStyle(context), diff --git a/lib/views/widgets/pentry/pentry_tbs_form.dart b/lib/views/widgets/pentry/pentry_tbs_form.dart index f8fb4f89..5b9e28c4 100644 --- a/lib/views/widgets/pentry/pentry_tbs_form.dart +++ b/lib/views/widgets/pentry/pentry_tbs_form.dart @@ -7,10 +7,13 @@ import 'package:test_sa/extensions/int_extensions.dart'; import 'package:test_sa/extensions/string_extensions.dart'; import 'package:test_sa/models/ppm/ppm.dart'; import 'package:test_sa/models/ppm/ppm_attachment.dart'; +import 'package:test_sa/models/service_request/supplier_details.dart'; +import 'package:test_sa/providers/loading_list_notifier.dart'; import 'package:test_sa/providers/ppm_asset_availability_provider.dart'; import 'package:test_sa/providers/ppm_electrical_safety_provider.dart'; import 'package:test_sa/providers/ppm_service_provider.dart'; import 'package:test_sa/providers/ppm_task_status_provider.dart'; +import 'package:test_sa/providers/work_order/vendor_provider.dart'; import '../../../models/lookup.dart'; import '../../../new_views/common_widgets/app_text_form_field.dart'; @@ -32,10 +35,16 @@ class PentryTBSForm extends StatefulWidget { } class _PentryTBSFormState extends State { + SupplierDetails initialSupplier; + SuppPersons _suppPerson; + @override Widget build(BuildContext context) { widget.model?.files ??= []; - widget.model?.files = (widget.model.files ?? []).where((element) => element.attachmentName != null && element.attachmentName.isNotEmpty).toList(); + widget.model?.files = (widget.model.files ?? []) + .where((element) => + element.attachmentName != null && element.attachmentName.isNotEmpty) + .toList(); return SingleChildScrollView( child: Column( @@ -44,11 +53,17 @@ class _PentryTBSFormState extends State { 8.height, SingleItemDropDownMenu( context: context, - initialValue: widget.model.visitStatusId == null ? null : Lookup(name: widget.model.visitStatusName ?? "", id: widget.model.visitStatusId), + initialValue: widget.model.visitStatusId == null + ? null + : Lookup( + name: widget.model.visitStatusName ?? "", + id: widget.model.visitStatusId), title: context.translation.ppmVisit, onSelect: (value) { if (value?.value == 4) { - "Status cannot be change to ${value.name}.".addTranslation.showToast; + "Status cannot be change to ${value.name}." + .addTranslation + .showToast; setState(() {}); return; } @@ -75,7 +90,11 @@ class _PentryTBSFormState extends State { 8.height, SingleItemDropDownMenu( context: context, - initialValue: widget.model.deviceStatusId == null ? null : Lookup(name: widget.model.deviceStatusName ?? "", id: widget.model.deviceStatusId), + initialValue: widget.model.deviceStatusId == null + ? null + : Lookup( + name: widget.model.deviceStatusName ?? "", + id: widget.model.deviceStatusId), title: context.translation.deviceStatus, onSelect: (value) { if (value != null) { @@ -87,7 +106,11 @@ class _PentryTBSFormState extends State { 8.height, SingleItemDropDownMenu( context: context, - initialValue: widget.model.taskStatusId == null ? null : Lookup(name: widget.model.taskStatusName ?? "", id: widget.model.taskStatusId), + initialValue: widget.model.taskStatusId == null + ? null + : Lookup( + name: widget.model.taskStatusName ?? "", + id: widget.model.taskStatusId), title: context.translation.taskStatus, onSelect: (value) { if (value != null) { @@ -99,7 +122,11 @@ class _PentryTBSFormState extends State { 8.height, SingleItemDropDownMenu( context: context, - initialValue: widget.model.assetAvailabilityId == null ? null : Lookup(name: widget.model.assetAvailabilityName ?? "", id: widget.model.assetAvailabilityId), + initialValue: widget.model.assetAvailabilityId == null + ? null + : Lookup( + name: widget.model.assetAvailabilityName ?? "", + id: widget.model.assetAvailabilityId), title: "Asset Availability", onSelect: (value) { if (value != null) { @@ -109,10 +136,13 @@ class _PentryTBSFormState extends State { }, ), 8.height, - SingleItemDropDownMenu( context: context, - initialValue: widget.model.typeOfServiceId == null ? null : Lookup(name: widget.model.typeOfServiceName ?? "", id: widget.model.typeOfServiceId), + initialValue: widget.model.typeOfServiceId == null + ? null + : Lookup( + name: widget.model.typeOfServiceName ?? "", + id: widget.model.typeOfServiceId), title: context.translation.serviceType, onSelect: (value) { if (value != null) { @@ -120,15 +150,29 @@ class _PentryTBSFormState extends State { widget.model.typeOfServiceName = value.name; widget.model.safetyId = null; widget.model.safetyName = null; + + + widget.model.supplierId = null; + widget.model.supplierName = null; + initialSupplier = null; + _suppPerson = null; + widget.model.suppPersonId = null; + widget.model.suppPerson = null; + + setState(() {}); } }, ), 8.height, - if(widget.model?.typeOfServiceId !=66)...[ + if (widget.model?.typeOfServiceId != 66) ...[ SingleItemDropDownMenu( context: context, - initialValue: widget.model.safetyId == null ? null : Lookup(name: widget.model.safetyName ?? "", id: widget.model.safetyId), + initialValue: widget.model.safetyId == null + ? null + : Lookup( + name: widget.model.safetyName ?? "", + id: widget.model.safetyId), title: "Electrical Safety", onSelect: (value) { if (value != null) { @@ -139,6 +183,43 @@ class _PentryTBSFormState extends State { ), 8.height, ], + if (widget.model?.typeOfServiceId == 66) ...[ + SingleItemDropDownMenu( + context: context, + title: context.translation.supplier, + initialValue: initialSupplier, + showAsBottomSheet: true, + onSelect: (supplier) { + if (supplier != null) { + widget.model.supplierId = supplier.id; + widget.model.supplierName = supplier.name; + initialSupplier = supplier; + _suppPerson = null; + widget.model.suppPersonId = null; + widget.model.suppPerson = null; + setState(() {}); + } + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.supplierEngineer, + enabled: initialSupplier?.suppPersons?.isNotEmpty ?? false, + initialValue: _suppPerson, + staticData: initialSupplier?.suppPersons, + showAsBottomSheet: true, + onSelect: (suppPerson) { + if (suppPerson != null) { + _suppPerson = suppPerson; + widget.model.suppPersonId = suppPerson.id; + widget.model.suppPerson = suppPerson.name; + setState(() {}); + } + }, + ), + 8.height, + ], ADatePicker( label: context.translation.actualVisitDate, @@ -147,7 +228,8 @@ class _PentryTBSFormState extends State { onDatePicker: (date) { if (date == null) return; if (date.isBefore(DateTime.parse(widget.model.expectedDate))) { - "Actual visit date must be greater then expected date".showToast; + "Actual visit date must be greater then expected date" + .showToast; return; } @@ -181,9 +263,12 @@ class _PentryTBSFormState extends State { 8.height, MultiFilesPicker( label: context.translation.attachImage, - files: widget.model.files.map((e) => File(e.attachmentName)).toList(), + files: + widget.model.files.map((e) => File(e.attachmentName)).toList(), onChange: (files) { - widget.model.files = files.map((e) => PpmAttachments(attachmentName: e.path)).toList(); + widget.model.files = files + .map((e) => PpmAttachments(attachmentName: e.path)) + .toList(); }, ), 8.height, @@ -193,7 +278,8 @@ class _PentryTBSFormState extends State { newSignature: widget.model.localNurseSignature, onChange: (signature) { widget.model.localNurseSignature = signature; - widget.model.nurseSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + widget.model.nurseSignature = + "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; }, ), 8.height, @@ -203,7 +289,8 @@ class _PentryTBSFormState extends State { newSignature: widget.model.localEngineerSignature, onChange: (signature) { widget.model.localEngineerSignature = signature; - widget.model.engSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; + widget.model.engSignature = + "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; }, ), 8.height,