diff --git a/lib/extensions/enum_extensions.dart b/lib/extensions/enum_extensions.dart index ced51f78..0325affb 100644 --- a/lib/extensions/enum_extensions.dart +++ b/lib/extensions/enum_extensions.dart @@ -5,7 +5,7 @@ import 'package:test_sa/models/enums/work_order_next_step.dart'; extension EnumExtensionsWorkOrder on WorkOrderNextStepEnum { int getIntFromWorkOrderNextStepEnum() { switch (this) { - case WorkOrderNextStepEnum.onlyView: + case WorkOrderNextStepEnum.assignToMe: return 2; case WorkOrderNextStepEnum.markedAsFixed: return 3; @@ -46,7 +46,7 @@ extension IntExtensionsWorkOrder on int { WorkOrderNextStepEnum toWorkOrderNextStepEnum() { switch (this) { case 2: - return WorkOrderNextStepEnum.onlyView; + return WorkOrderNextStepEnum.assignToMe; case 3: return WorkOrderNextStepEnum.markedAsFixed; case 5: @@ -72,7 +72,7 @@ extension IntExtensionsWorkOrder on int { case 36: return WorkOrderNextStepEnum.eNeedVisit; default: - return WorkOrderNextStepEnum.onlyView; + return WorkOrderNextStepEnum.assignToMe; } } diff --git a/lib/models/enums/work_order_next_step.dart b/lib/models/enums/work_order_next_step.dart index 20405c21..16f95028 100644 --- a/lib/models/enums/work_order_next_step.dart +++ b/lib/models/enums/work_order_next_step.dart @@ -1,5 +1,5 @@ enum WorkOrderNextStepEnum { - onlyView, // 2 + assignToMe, // 2 markedAsFixed, // 3 nTakeAction, // 5 eRejectAccept, // 9 diff --git a/lib/models/new_models/gas_refill_model.dart b/lib/models/new_models/gas_refill_model.dart index 5b5c6b97..eb944aa4 100644 --- a/lib/models/new_models/gas_refill_model.dart +++ b/lib/models/new_models/gas_refill_model.dart @@ -186,18 +186,18 @@ class GasRefillModel { return map; } - Future validate(BuildContext context) async { + bool validate(BuildContext context) { if (site == null) { - await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.destinationSite}"); + Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.destinationSite}"); return false; } else if (building == null) { - await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.building}"); + Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.building}"); return false; } else if (floor == null) { - await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.floor}"); + Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.floor}"); return false; } else if (department == null) { - await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.department}"); + Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.department}"); return false; } return true; @@ -290,15 +290,18 @@ class GasRefillDetails { return map; } - Future validate(BuildContext context) async { + bool validate(BuildContext context) { if (gasType == null) { - await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.gasType}"); + Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.gasType}"); + return false; + } else if (requestedQty == null) { + Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.quantity}"); return false; } else if (cylinderType == null) { - await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.cylinderType}"); + Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.cylinderType}"); return false; } else if (cylinderSize == null) { - await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.cylinderSize}"); + Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.cylinderSize}"); return false; } return true; 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 879865da..a5a462f9 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 @@ -178,6 +178,9 @@ class _SingleItemDropDownMenuState { late GasRefillDetails _currentDetails; late GasRefillModel _gasModel; - late GlobalKey _formKey; - late TextEditingController _quantityController; + Lookup? _requestedQuantity; + + static List gasQuantity = [ + Lookup(name: "1", id: 1, value: 1), + Lookup(name: "2", id: 2, value: 2), + Lookup(name: "3", id: 3, value: 3), + Lookup(name: "4", id: 4, value: 4), + Lookup(name: "5", id: 5, value: 5) + ]; @override void initState() { super.initState(); - _formKey = GlobalKey(); _currentDetails = GasRefillDetails(); _gasModel = GasRefillModel(gazRefillDetails: []); - _quantityController = TextEditingController(); } @override void dispose() { - _quantityController.dispose(); super.dispose(); } @@ -63,175 +67,162 @@ class _NewGasRefillRequestPageState extends State { body: Column( children: [ SingleChildScrollView( - child: Form( - key: _formKey, - child: Column( - children: [ - 16.height, - SingleItemDropDownMenu( - context: context, - title: context.translation.gasType, - initialValue: _currentDetails.gasType, - onSelect: (value) { - _currentDetails.gasType = value; - }, - ), - 8.height, - AppTextFormField( - controller: _quantityController, - labelText: context.translation.quantity, - textInputType: TextInputType.number, - validator: (value) => Validator.hasValue(value!) - ? Validator.isNumeric(value) - ? null - : context.translation.onlyNumbers - : context.translation.requiredField, - onSaved: (text) { - _currentDetails.requestedQty = double.tryParse(text ?? "") ?? 0; - }, - ), - 8.height, - SingleItemDropDownMenu( - context: context, - title: context.translation.cylinderType, - initialValue: _currentDetails.cylinderType, - onSelect: (value) { - _currentDetails.cylinderType = value; - }, - ), - 8.height, - SingleItemDropDownMenu( - context: context, - title: context.translation.cylinderSize, - initialValue: _currentDetails.cylinderSize, - onSelect: (value) { - _currentDetails.cylinderSize = value; - }, - ), - 8.height, - SingleItemDropDownMenu( - context: context, - title: context.translation.site, - initialValue: _gasModel.site, - showAsBottomSheet: true, - onSelect: (value) { - setState(() { - _gasModel.site = value; - _gasModel.building = null; - _gasModel.floor = null; - _gasModel.department = null; - }); - }, + child: Column( + children: [ + 16.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.gasType, + initialValue: _currentDetails.gasType, + showAsBottomSheet: true, + onSelect: (value) { + _currentDetails.gasType = value; + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.quantity, + initialValue: _requestedQuantity, + staticData: gasQuantity, + onSelect: (value) { + _requestedQuantity = value; + _currentDetails.requestedQty = value?.value; + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.cylinderType, + initialValue: _currentDetails.cylinderType, + onSelect: (value) { + _currentDetails.cylinderType = value; + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.cylinderSize, + initialValue: _currentDetails.cylinderSize, + showAsBottomSheet: true, + onSelect: (value) { + _currentDetails.cylinderSize = value; + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.site, + initialValue: _gasModel.site, + showAsBottomSheet: true, + onSelect: (value) { + setState(() { + _gasModel.site = value; + _gasModel.building = null; + _gasModel.floor = null; + _gasModel.department = null; + }); + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.building, + initialValue: _gasModel.building, + enabled: _gasModel.site?.buildings?.isNotEmpty ?? false, + staticData: _gasModel.site?.buildings ?? [], + showAsBottomSheet: true, + onSelect: (value) { + setState(() { + _gasModel.building = value; + _gasModel.floor = null; + _gasModel.department = null; + }); + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.floor, + initialValue: _gasModel.floor, + enabled: _gasModel.building?.floors?.isNotEmpty ?? false, + staticData: _gasModel.building?.floors ?? [], + showAsBottomSheet: true, + onSelect: (value) { + setState(() { + _gasModel.floor = value; + _gasModel.department = null; + }); + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.department, + initialValue: _gasModel.department, + enabled: _gasModel.floor?.departments?.isNotEmpty ?? false, + staticData: _gasModel.floor?.departments ?? [], + showAsBottomSheet: true, + onSelect: (value) { + _gasModel.department = value; + }, + ), + 8.height, + if (_gasModel.gazRefillDetails?.isEmpty ?? true) + AppFilledButton( + label: context.translation.add, + maxWidth: true, + textColor: Colors.white, + buttonColor: context.isDark ? AppColor.neutral60 : AppColor.neutral50, + onPressed: _add, ), - 8.height, - SingleItemDropDownMenu( - context: context, - title: context.translation.building, - initialValue: _gasModel.building, - enabled: _gasModel.site?.buildings?.isNotEmpty ?? false, - staticData: _gasModel.site?.buildings ?? [], - onSelect: (value) { - setState(() { - _gasModel.building = value; - _gasModel.floor = null; - _gasModel.department = null; - }); - }, - ), - 8.height, - SingleItemDropDownMenu( - context: context, - title: context.translation.floor, - initialValue: _gasModel.floor, - enabled: _gasModel.building?.floors?.isNotEmpty ?? false, - staticData: _gasModel.building?.floors ?? [], - onSelect: (value) { - setState(() { - _gasModel.floor = value; - _gasModel.department = null; - }); - }, - ), - 8.height, - SingleItemDropDownMenu( - context: context, - title: context.translation.department, - initialValue: _gasModel.department, - enabled: _gasModel.floor?.departments?.isNotEmpty ?? false, - staticData: _gasModel.floor?.departments ?? [], - onSelect: (value) { - _gasModel.department = value; - }, - ), - 8.height, - if (_gasModel.gazRefillDetails?.isEmpty ?? true) - AppFilledButton( - label: context.translation.add, - maxWidth: true, - textColor: Colors.white, - buttonColor: context.isDark ? AppColor.neutral60 : AppColor.neutral50, - onPressed: _add, - ), - ListView.builder( - shrinkWrap: true, - itemCount: _gasModel.gazRefillDetails?.length, - padding: const EdgeInsets.only(top: 12, bottom: 24), - physics: const NeverScrollableScrollPhysics(), - itemBuilder: (context, index) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - (_gasModel.gazRefillDetails![index].gasType?.name ?? "").heading5(context), - 8.height, - ("${context.translation.quantity}: ${_gasModel.gazRefillDetails![index].requestedQty}").bodyText(context), - ("${context.translation.cylinderSize}: ${_gasModel.gazRefillDetails![index].cylinderSize?.name}").bodyText(context), - ("${context.translation.cylinderType}: ${_gasModel.gazRefillDetails![index].cylinderType?.name}").bodyText(context), - ], + ListView.builder( + shrinkWrap: true, + itemCount: _gasModel.gazRefillDetails?.length, + padding: const EdgeInsets.only(top: 12, bottom: 24), + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (context, index) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + (_gasModel.gazRefillDetails![index].gasType?.name ?? "").heading5(context), + 8.height, + ("${context.translation.quantity}: ${_gasModel.gazRefillDetails![index].requestedQty}").bodyText(context), + ("${context.translation.cylinderSize}: ${_gasModel.gazRefillDetails![index].cylinderSize?.name}").bodyText(context), + ("${context.translation.cylinderType}: ${_gasModel.gazRefillDetails![index].cylinderType?.name}").bodyText(context), + ], + ), + Container( + height: 48.toScreenWidth, + width: 48.toScreenWidth, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(100), + border: Border.all(color: context.isDark ? AppColor.neutral50 : AppColor.neutral30), ), - Container( - height: 48.toScreenWidth, - width: 48.toScreenWidth, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(100), - border: Border.all(color: context.isDark ? AppColor.neutral50 : AppColor.neutral30), - ), - padding: EdgeInsets.symmetric(vertical: 12.toScreenHeight), - child: "trash".toSvgAsset(fit: BoxFit.fitHeight, color: context.isDark ? AppColor.red40 : AppColor.red50), - ).onPress(() { - _delete(index); - }), - ], - ), - const Divider().defaultStyle(context), - ("${context.translation.site}: ${_gasModel.site?.custName}").bodyText(context), - ("${context.translation.building}: ${_gasModel.building?.name}").bodyText(context), - ("${context.translation.floor}: ${_gasModel.floor?.name}").bodyText(context), - ("${context.translation.department}: ${_gasModel.department?.departmentName}").bodyText(context), - ], - ).toShadowContainer(context); - }, - ), - // 8.height, - - // // todo sikander, check it with FM - // AppTextFormField( - // labelText: context.translation.comments, - // textInputType: TextInputType.multiline, - // alignLabelWithHint: true, - // onChange: (text) { - // _gasModel.comment = text; - // }, - // ), - //40.height, - ], - ), + padding: EdgeInsets.symmetric(vertical: 12.toScreenHeight), + child: "trash".toSvgAsset(fit: BoxFit.fitHeight, color: context.isDark ? AppColor.red40 : AppColor.red50), + ).onPress(() { + _delete(index); + }), + ], + ), + const Divider().defaultStyle(context), + ("${context.translation.site}: ${_gasModel.site?.custName}").bodyText(context), + ("${context.translation.building}: ${_gasModel.building?.name}").bodyText(context), + ("${context.translation.floor}: ${_gasModel.floor?.name}").bodyText(context), + ("${context.translation.department}: ${_gasModel.department?.departmentName}").bodyText(context), + ], + ).toShadowContainer(context); + }, + ), + ], ), ).expanded, 16.height, @@ -242,11 +233,10 @@ class _NewGasRefillRequestPageState extends State { } void _add() async { - if (_formKey.currentState!.validate() && await _currentDetails.validate(context) && await _gasModel.validate(context)) { - _formKey.currentState!.save(); + if (_currentDetails.validate(context) && _gasModel.validate(context)) { _gasModel.gazRefillDetails!.add(_currentDetails); - _quantityController.clear(); _currentDetails = GasRefillDetails(); + _requestedQuantity = null; setState(() {}); } } diff --git a/lib/service_request_latest/views/components/action_button/footer_action_button.dart b/lib/service_request_latest/views/components/action_button/footer_action_button.dart index 7159aac1..6674009c 100644 --- a/lib/service_request_latest/views/components/action_button/footer_action_button.dart +++ b/lib/service_request_latest/views/components/action_button/footer_action_button.dart @@ -1,10 +1,6 @@ -import 'dart:convert'; - -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:test_sa/controllers/providers/api/user_provider.dart'; -import 'package:test_sa/dashboard_latest/dashboard_provider.dart'; import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/int_extensions.dart'; import 'package:test_sa/extensions/text_extensions.dart'; @@ -35,13 +31,18 @@ class FooterActionButton { } static Widget requestDetailsFooterWidget( - {required WorkOrderNextStepEnum workOrderNextStepStatus, List activities = const [], required BuildContext context, required UserProvider userProvider}) { + {required WorkOrderNextStepEnum workOrderNextStepStatus, + List activities = const [], + required BuildContext context, + required UserProvider userProvider, + bool isEmpIsAssigned = false}) { ServiceRequestDetailProvider requestDetailProvider = Provider.of(context, listen: false); - bool showMarkAsFixedButton = activities.isEmpty ? false : activities.any((object) => object.activityStatus!.value == 14 || object.activityStatus!.value == 19);// 14 = Fixed and 14 = Out of scope //todo Ask backend for out of scope value + bool showMarkAsFixedButton = activities.isEmpty ? false : activities.any((object) => object.activityStatus!.value == 14 || object.activityStatus!.value == 19); if (userProvider.user?.type == UsersTypes.engineer) { + if (workOrderNextStepStatus == WorkOrderNextStepEnum.assignToMe && isEmpIsAssigned) return const SizedBox(); switch (workOrderNextStepStatus) { - case WorkOrderNextStepEnum.onlyView: + case WorkOrderNextStepEnum.assignToMe: return footerContainer( child: AppFilledButton( label: 'Assign To Me', 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 a79a0681..9f94b6d0 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 @@ -55,6 +55,7 @@ class ServiceRequestDetailView extends StatelessWidget { FooterActionButton.requestDetailsFooterWidget( workOrderNextStepStatus: requestProvider.currentWorkOrder!.data!.nextStep!.workOrderNextStepEnum!, // workOrderNextStepStatus: WorkOrderNextStepEnum.eNeedVisit, + isEmpIsAssigned: requestProvider.currentWorkOrder!.data!.assignedEmployee != null, activities: requestProvider.currentWorkOrder!.data?.activities ?? [], userProvider: _userProvider, context: context), @@ -368,4 +369,3 @@ class ServiceRequestDetailView extends StatelessWidget { } } } - 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 42c8c115..c5aa13df 100644 --- a/lib/views/pages/user/gas_refill/request_gas_refill.dart +++ b/lib/views/pages/user/gas_refill/request_gas_refill.dart @@ -16,6 +16,7 @@ import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/models/lookup.dart'; import 'package:test_sa/models/timer_model.dart'; import 'package:test_sa/new_views/common_widgets/app_filled_button.dart'; +import 'package:test_sa/providers/loading_list_notifier.dart'; import 'package:test_sa/views/widgets/loaders/loading_manager.dart'; import '../../../../controllers/providers/api/hospitals_provider.dart'; @@ -58,12 +59,27 @@ class _RequestGasRefillState extends State { final GlobalKey _scaffoldKey = GlobalKey(); bool _firstTime = true; + + Lookup? _deliveredQuantity; + + static List deliveredQuantity = [ + Lookup(name: "1", id: 1, value: 1), + Lookup(name: "2", id: 2, value: 2), + Lookup(name: "3", id: 3, value: 3), + Lookup(name: "4", id: 4, value: 4), + Lookup(name: "5", id: 5, value: 5) + ]; + @override void initState() { super.initState(); if (widget.gasRefillModel != null) { _formModel.fromGasRefillModel(widget.gasRefillModel!); _commentController.text = _formModel.comment ?? ""; + try { + _deliveredQuantity = deliveredQuantity.singleWhere((element) => element.value == _formModel.gazRefillDetails![0].deliverdQty); + _currentDetails.deliverdQty = _deliveredQuantity!.value; + } catch (ex) {} } } @@ -119,17 +135,23 @@ class _RequestGasRefillState extends State { } } - Future _addNewModel(BuildContext context) async { + bool _addNewModel(BuildContext context) { _validate = true; - if (!_formKey.currentState!.validate()) { + if (_currentDetails.deliverdQty == null) { + Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.quantity}"); setState(() {}); return false; } + // if (!_formKey.currentState!.validate()) { + // setState(() {}); + // return false; + // } _formKey.currentState!.save(); _currentDetails.gasType = _formModel.gazRefillDetails![0].gasType; _currentDetails.cylinderSize = _formModel.gazRefillDetails![0].cylinderSize; _currentDetails.cylinderType = _formModel.gazRefillDetails![0].cylinderType; - if (!(await _currentDetails.validate(context))) { + _currentDetails.requestedQty = _formModel.gazRefillDetails![0].requestedQty; + if (!( _currentDetails.validate(context))) { setState(() {}); return false; } @@ -202,8 +224,6 @@ class _RequestGasRefillState extends State { children: [ context.translation.gasRefill.heading5(context), 8.height, - - /// TBD '${context.translation.gasRequest}: ${widget.gasRefillModel!.gazRefillDetails![0].gasType!.name}'.bodyText(context), '${context.translation.cylinderType}: ${widget.gasRefillModel!.gazRefillDetails![0].cylinderType!.name}'.bodyText(context), '${context.translation.cylinderSize}: ${widget.gasRefillModel!.gazRefillDetails![0].cylinderSize!.name}'.bodyText(context), @@ -238,20 +258,31 @@ class _RequestGasRefillState extends State { }, ), 8.height, - AppTextFormField( - initialValue: _formModel.gazRefillDetails?[0].deliverdQty?.toString() ?? "", - labelText: context.translation.deliveredQuantity, - onSaved: (value) { - _currentDetails.deliverdQty = double.tryParse(value); + SingleItemDropDownMenu( + context: context, + title: context.translation.quantity, + initialValue: _deliveredQuantity, + staticData: deliveredQuantity, + onSelect: (value) { + _deliveredQuantity = value; + _currentDetails.deliverdQty = value!.value; }, - textInputType: TextInputType.number, - controller: _deliveredQuantityController, - validator: (value) => value == null || value.isEmpty - ? context.translation.requiredField - : Validator.isNumeric(value) - ? null - : context.translation.onlyNumbers, ), + // 8.height, + // AppTextFormField( + // initialValue: _formModel.gazRefillDetails?[0].deliverdQty?.toString() ?? "", + // labelText: context.translation.deliveredQuantity, + // onSaved: (value) { + // _currentDetails.deliverdQty = double.tryParse(value); + // }, + // textInputType: TextInputType.number, + // controller: _deliveredQuantityController, + // validator: (value) => value == null || value.isEmpty + // ? context.translation.requiredField + // : Validator.isNumeric(value) + // ? null + // : context.translation.onlyNumbers, + // ), 8.height, /// TBD