add code for nurse edit gas refill request

design_3.0_task_module_new
WaseemAbbasi22 6 months ago
parent 0b97ffe296
commit b320e3751a

@ -241,6 +241,7 @@ class URLs {
static get getGasStatus => "$_baseUrl/Lookups/GetLookup?lookupEnum=609"; // get
static get requestGasRefill => "$_baseUrl/GasRefill/AddGasRefillFromMobile"; // get
static get updateGasRefill => "$_baseUrl/GazRefill/UpdateGazRefill"; // get
static get updateGasRefillByNurse => "$_baseUrl/GazRefill/UpdateGasRefillByNurseForMobile"; //update gas refill by nurse
static get getGasRefill => "$_baseUrl/GazRefill/GetGazRefills"; // get
// static get getGasRefillById => "$_baseUrl/GazRefill/GetGazRefillById"; // get older endpoint..
static get getGasRefillById => "$_baseUrl/GasRefill/GetGasRefillById"; // get

@ -12,6 +12,7 @@ import 'package:test_sa/models/hospital.dart';
import 'package:test_sa/models/new_models/gas_refill_model.dart';
import 'package:test_sa/models/timer_model.dart';
import 'package:test_sa/models/user.dart';
import 'package:test_sa/views/pages/user/gas_refill/update_gas_refill_request.dart';
import '../../../new_views/common_widgets/app_lazy_loading.dart';
@ -138,6 +139,33 @@ class GasRefillProvider extends ChangeNotifier {
print(error);
}
}
Future<void> updateGasRefillRequestByNurse({
required BuildContext context,
required GasRefillModel model,
}) async {
late Response response;
try {
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
response = await ApiManager.instance.post(URLs.updateGasRefillByNurse, body: model.toJson());
stateCode = response.statusCode;
if (response.statusCode >= 200 && response.statusCode < 300) {
if (items != null) {
reset();
notifyListeners();
}
Fluttertoast.showToast(msg: context.translation.createdSuccessfully);
Navigator.pop(context);
} else {
Fluttertoast.showToast(msg: "${context.translation.failedToCompleteRequest} :${json.decode(response.body)['message']}");
}
Navigator.pop(context);
} catch (error) {
stateCode = -1;
notifyListeners();
Navigator.pop(context);
print(error);
}
}
Future<int> updateGasRefill({required int status, required GasRefillModel model}) async {
isLoading = true;

@ -36,6 +36,10 @@ class GasRefillModel {
this.assignedEmployee,
this.status,
this.comment,
this.mapSite,
this.mappedFloor,
this.mappedBuilding,
this.mappedDepartment,
this.techComment,
this.gasRefillDetails,
this.localEngineerSignature,
@ -132,12 +136,21 @@ class GasRefillModel {
// } catch (e) {
// print(e);
// }
print('building # ${json['building']}');
print('department # ${json['department']}');
print('floor # ${json['floor']}');
engSignature = json['engSignature'];
nurseSignature = json['nurseSignature'];
site = json['site'] != null ? Site.fromJson(json['site']) : null;
building = json['building'] != null ? Building.fromJson(json['building']) : null;
floor = json['floor'] != null ? Floor.fromJson(json['floor']) : null;
department = json['department'] != null ? Department.fromJson(json['department']) : null;
mapSite = json['site'] != null ? MappedSite.fromJson(json['site']) : null;
print('site i got is ::${mapSite?.toJson()}');
mappedBuilding = mapSite?.buildings?.firstWhere((element) => element.identifier == building?.identifier, orElse: () => MappedBuilding());
mappedFloor = mappedBuilding?.floors?.firstWhere((element) => element.identifier == floor?.identifier, orElse: () => MappedFloor());
mappedDepartment = mappedFloor?.departments?.firstWhere((element) => element.identifier == department?.identifier, orElse: () => MappedDepartment());
assignedEmployee = json['assignedEmployee'] != null ? AssignedEmployee.fromJson(json['assignedEmployee']) : null;
status = json['status'] != null ? Lookup.fromJson(json['status']) : null;
if (json['gasRefillDetails'] != null) {
@ -150,6 +163,7 @@ class GasRefillModel {
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['id'] = id ?? 0;
map['gasTypeId'] = gasRefillDetails?[0].gasType?.id;
map['cylinderTypeId'] = gasRefillDetails?[0].cylinderType?.id;

@ -239,7 +239,7 @@ class MappedBuilding extends Base {
customerId = json['customerId'];
clientBuildingId = json['clientBuildingId'];
clientBuildingName = json['clientBuildingName'];
name = clientBuildingName;
name = clientBuildingName??json['name'];
floors = (json['floors'] as List?)?.map((e) => MappedFloor.fromJson(e)).toList();
}
@ -274,7 +274,7 @@ class MappedFloor extends Base {
buildingId = json['buildingId'];
clientFloorId = json['clientFloorId'];
clientFloorName = json['clientFloorName'];
name = clientFloorName;
name = clientFloorName??json['name'];
departments = (json['departments'] as List?)?.map((e) => MappedDepartment.fromJson(e)).toList();
}
@ -308,7 +308,7 @@ class MappedDepartment extends Base {
floorId = json['floorId'];
departmentId = json['departmentId'];
departmentName = json['departmentName'];
name = departmentName;
name = departmentName??json['name'];
// rooms = json['rooms'];
}

@ -330,3 +330,358 @@ class _GasRefillRequestFormState extends State<GasRefillRequestForm> {
// },
// ),
}
//TODO uncommit this to use editable form for nurse side.
// import 'dart:convert';
// import 'dart:io';
// import 'package:flutter/material.dart';
// import 'package:fluttertoast/fluttertoast.dart';
// import 'package:provider/provider.dart';
// import 'package:test_sa/cm_module/utilities/service_request_utils.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';
// import 'package:test_sa/extensions/widget_extensions.dart';
// import 'package:test_sa/models/enums/user_types.dart';
// import 'package:test_sa/models/lookup.dart';
// import 'package:test_sa/models/new_models/gas_refill_model.dart';
// import 'package:test_sa/models/new_models/mapped_sites.dart';
// import 'package:test_sa/new_views/app_style/app_color.dart';
// import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
// import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart';
// import 'package:test_sa/new_views/common_widgets/single_item_drop_down_menu.dart';
// import 'package:test_sa/providers/gas_request_providers/cylinder_size_provider.dart';
// import 'package:test_sa/providers/gas_request_providers/cylinder_type_provider.dart';
// import 'package:test_sa/providers/gas_request_providers/gas_types_provider.dart';
// import 'package:test_sa/providers/gas_request_providers/site_provider.dart';
// import 'package:test_sa/providers/loading_list_notifier.dart';
//
// import 'package:test_sa/cm_module/views/components/action_button/footer_action_button.dart';
// import 'package:test_sa/views/widgets/images/multi_image_picker.dart';
// import '../../controllers/providers/api/gas_refill_provider.dart';
// import '../common_widgets/default_app_bar.dart';
//
// class GasRefillRequestForm extends StatefulWidget {
// static const String routeName = "/gas_refill_request_form";
// final GasRefillModel? gasModel;
// final GasRefillDetails? gasRefillDetails;
//
// const GasRefillRequestForm({this.gasModel, this.gasRefillDetails, Key? key}) : super(key: key);
//
// @override
// State<GasRefillRequestForm> createState() => _GasRefillRequestFormState();
// }
//
// class _GasRefillRequestFormState extends State<GasRefillRequestForm> {
// late GasRefillDetails _currentDetails;
// late GasRefillModel _gasModel;
// Lookup? _requestedQuantity;
// final TextEditingController _commentController = TextEditingController();
// GasRefillProvider? _gasRefillProvider;
// List<File> _files = [];
//
// static List<Lookup> 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();
// _gasRefillProvider ??= Provider.of<GasRefillProvider>(context, listen: false);
// _currentDetails = widget.gasRefillDetails ?? GasRefillDetails();
// _gasModel = widget.gasModel ?? GasRefillModel(gasRefillDetails: []);
// if (_gasModel.gasRefillAttachments != null && _gasModel.gasRefillAttachments!.isNotEmpty) {
// _files.addAll(_gasModel.gasRefillAttachments!.map((e) => File(e.attachmentName!)).toList());
// }
// if (widget.gasRefillDetails != null && widget.gasRefillDetails?.requestedQty != null) {
// _requestedQuantity = Lookup(name: "1", id: 1, value: int.parse(widget.gasRefillDetails!.requestedQty!.toStringAsFixed(0)));
// }
// }
//
// @override
// void dispose() {
// super.dispose();
// }
//
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// appBar: DefaultAppBar(title: widget.gasModel == null ? context.translation.newGasRefillRequest : context.translation.updateRequest),
// body: Column(
// children: [
// 12.height,
// SingleChildScrollView(
// child: Column(
// children: [
// SingleItemDropDownMenu<Lookup, GasTypesProvider>(
// context: context,
// title: context.translation.gasType,
// initialValue: _currentDetails.gasType,
// backgroundColor: AppColor.neutral100,
// showShadow: false,
// showAsBottomSheet: true,
// onSelect: (value) {
// _currentDetails.gasType = value;
// },
// ),
// 8.height,
// SingleItemDropDownMenu<Lookup, CylinderTypesProvider>(
// context: context,
// title: context.translation.cylinderType,
// initialValue: _currentDetails.cylinderType,
// backgroundColor: AppColor.neutral100,
// showShadow: false,
// onSelect: (value) {
// _currentDetails.cylinderType = value;
// },
// ),
// 8.height,
// SingleItemDropDownMenu<Lookup, CylinderSizeProvider>(
// context: context,
// title: context.translation.cylinderSize,
// initialValue: _currentDetails.cylinderSize,
// showAsBottomSheet: true,
// backgroundColor: AppColor.neutral100,
// showShadow: false,
// onSelect: (value) {
// _currentDetails.cylinderSize = value;
// },
// ),
// 8.height,
// SingleItemDropDownMenu<Lookup, NullableLoadingProvider>(
// context: context,
// title: context.translation.quantity,
// showAsBottomSheet: true,
// initialValue: _requestedQuantity,
// staticData: gasQuantity,
// backgroundColor: AppColor.neutral100,
// showShadow: false,
// onSelect: (value) {
// _requestedQuantity = value;
// _currentDetails.requestedQty = value?.value;
// },
// ),
// 8.height,
// Row(
// children: [
// SingleItemDropDownMenu<MappedSite, MappedSiteProvider>(
// context: context,
// title: context.translation.site,
// initialValue: _gasModel.mapSite,
// showAsBottomSheet: true,
// backgroundColor: AppColor.neutral100,
// showShadow: false,
// onSelect: (value) {
// setState(() {
// _gasModel.mapSite = value;
// _gasModel.mappedBuilding = null;
// _gasModel.mappedFloor = null;
// _gasModel.mappedDepartment = null;
// });
// },
// ).expanded,
// 8.width,
// SingleItemDropDownMenu<MappedBuilding, NullableLoadingProvider>(
// context: context,
// title: context.translation.building,
// initialValue: _gasModel.mappedBuilding,
// enabled: _gasModel.mapSite?.buildings?.isNotEmpty ?? false,
// staticData: _gasModel.mapSite?.buildings ?? [],
// showAsBottomSheet: true,
// backgroundColor: AppColor.neutral100,
// showShadow: false,
// onSelect: (value) {
// setState(() {
// _gasModel.mappedBuilding = value;
// _gasModel.mappedFloor = null;
// _gasModel.mappedDepartment = null;
// });
// },
// ).expanded,
// ],
// ),
// 8.height,
// Row(
// children: [
// SingleItemDropDownMenu<MappedFloor, NullableLoadingProvider>(
// context: context,
// title: context.translation.floor,
// initialValue: _gasModel.mappedFloor,
// enabled: _gasModel.mappedBuilding?.floors?.isNotEmpty ?? false,
// staticData: _gasModel.mappedBuilding?.floors ?? [],
// showAsBottomSheet: true,
// backgroundColor: AppColor.neutral100,
// showShadow: false,
// onSelect: (value) {
// if (value != null) {
// setState(() {
// _gasModel.mappedFloor = value;
// _gasModel.department = null;
// });
// }
// },
// ).expanded,
// 8.width,
// SingleItemDropDownMenu<MappedDepartment, NullableLoadingProvider>(
// context: context,
// title: context.translation.department,
// initialValue: _gasModel.mappedDepartment,
// enabled: _gasModel.mappedFloor?.departments?.isNotEmpty ?? false,
// staticData: _gasModel.mappedFloor?.departments ?? [],
// showAsBottomSheet: true,
// backgroundColor: AppColor.neutral100,
// showShadow: false,
// onSelect: (value) {
// _gasModel.mappedDepartment = value;
// },
// ).expanded,
// ],
// ),
// 8.height,
// AppTextFormField(
// labelText: context.translation.callComments,
// labelStyle: AppTextStyles.tinyFont.copyWith(color: AppColor.neutral120),
// textInputType: TextInputType.multiline,
// alignLabelWithHint: true,
// initialValue: _gasModel.comment,
// backgroundColor: AppColor.neutral100,
// showShadow: false,
// controller: _commentController,
// onChange: (value) {
// _gasModel.comment = value;
// },
// onSaved: (value) {},
// ),
// 8.height,
// MultiFilesPicker(
// label: context.translation.attachFiles,
// files: _files,
// buttonColor: AppColor.black10,
// onlyImages: false,
// buttonIcon: 'image-plus'.toSvgAsset(color: AppColor.neutral120),
// ),
// ],
// ).toShadowContainer(context, padding: 10).paddingOnly(start: 16, end: 16, top: 16),
// ).expanded,
// 16.height,
// FooterActionButton.footerContainer(
// child: AppFilledButton(label: widget.gasModel == null ? context.translation.submitRequest : context.translation.updateRequest, maxWidth: true, onPressed: _submit)),
// ],
// ),
// );
// }
//
// Future<void> _submit() async {
// if (await validateRequest()) {
// _gasModel.gasRefillDetails = [];
// _gasModel.gasRefillDetails?.add(_currentDetails);
// _gasModel.gasRefillAttachments = [];
// for (var item in _files) {
// _gasModel.gasRefillAttachments?.add(GasRefillAttachments(
// id: 0, gasRefillId: _gasModel.id ?? 0, attachmentName: ServiceRequestUtils.isLocalUrl(item.path) ? "${item.path.split("/").last}|${base64Encode(item.readAsBytesSync())}" : item.path));
// }
// if (widget.gasModel != null) {
// //TODO need to call api here for update for nurse APi has issue need to discuss with backend..
// await _gasRefillProvider?.updateGasRefillRequestByNurse(
// context: context,
// model: _gasModel,
// );
// } else {
// await _gasRefillProvider?.addGasRefillRequest(
// context: context,
// model: _gasModel,
// );
// }
// if (_gasRefillProvider?.stateCode == 200) {
// DashBoardProvider dashBoardProvider = Provider.of<DashBoardProvider>(context, listen: false);
// dashBoardProvider.refreshDashboard(context: context, userType: UsersTypes.nurse);
// }
// }
// }
//
// Future<bool> validateRequest() async {
// if (_currentDetails.gasType == null) {
// await Fluttertoast.showToast(msg: "Please Select Gas Type");
// return false;
// }
// if (_gasModel.mapSite == null) {
// await Fluttertoast.showToast(msg: "Please Select Site");
// return false;
// }
// if (_gasModel.mappedBuilding == null) {
// await Fluttertoast.showToast(msg: "Please Select Building");
// return false;
// }
// if (_gasModel.mappedFloor == null) {
// await Fluttertoast.showToast(msg: "Please Select Floor");
// return false;
// }
// if (_gasModel.mappedDepartment == null) {
// await Fluttertoast.showToast(msg: "Please Select Department");
// return false;
// }
// return true;
// }
//
// //older code....
// // if (_gasModel.gasRefillDetails?.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.gasRefillDetails?.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.gasRefillDetails![index].gasType?.name ?? "").heading5(context),
// // 8.height,
// // ("${context.translation.quantity}: ${_gasModel.gasRefillDetails![index].requestedQty}").bodyText(context),
// // ("${context.translation.cylinderSize}: ${_gasModel.gasRefillDetails![index].cylinderSize?.name}").bodyText(context),
// // ("${context.translation.cylinderType}: ${_gasModel.gasRefillDetails![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),
// // ),
// // 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);
// // },
// // ),
// }

@ -27,18 +27,18 @@ class RequestItemViewList extends StatelessWidget {
shrinkWrap: true,
itemBuilder: (cxt, index) {
if (isLoading) return const SizedBox().toRequestShimmer(cxt, isLoading);
switch(list[index].transactionType){
switch (list[index].transactionType) {
case 1:
return ServiceRequestItemView(requestDetails: list[index]);
case 2:
return GasRefillItemView(requestDetails: list[index]);
return GasRefillItemView(requestDetails: list[index]);
case 3:
return DeviceItemView(requestDetails: list[index]);
case 4:
return PpmItemView(requestDetails: list[index]);
case 5:
return RecurrentWoItemView(requestDetails: list[index]);
case 6:
case 6:
return TaskRequestItemView(requestDetails: list[index]);
default:
Container(
@ -46,7 +46,6 @@ class RequestItemViewList extends StatelessWidget {
width: double.infinity,
color: Colors.grey,
);
}
// bool isServiceRequest = list[index].transactionType == 1;
// bool isGasRefill = list[index].transactionType == 2;

@ -11,6 +11,7 @@ import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/string_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
import 'package:test_sa/new_views/pages/gas_refill_request_form.dart';
import 'package:test_sa/views/pages/user/gas_refill/update_gas_refill_request.dart';
import 'package:test_sa/views/widgets/images/files_list.dart';
import 'package:test_sa/views/widgets/loaders/app_loading.dart';
@ -73,7 +74,6 @@ class _GasRefillDetailsPageState extends State<GasRefillDetailsPage> {
padding: const EdgeInsets.all(16),
child: informationCard(_model),
).expanded,
if (_userProvider.user!.type == UsersTypes.engineer && (_model.status!.value! != 2)) ...[
AppFilledButton(
onPressed: () async {
@ -82,11 +82,17 @@ class _GasRefillDetailsPageState extends State<GasRefillDetailsPage> {
},
label: context.translation.updateRequest,
).paddingAll(16)
]
// else if(_model.status!.value! == 0)...[
//TODO need to uncomment this to enable nurse edit gas refill request.
// else if (_model.status!.value! == 0) ...[
// AppFilledButton(
// onPressed: () async {
// await Navigator.of(context).push(MaterialPageRoute(builder: (_) => UpdateGasRefillRequest(gasRefillModel: _model)));
// await Navigator.of(context).push(MaterialPageRoute(
// builder: (_) => GasRefillRequestForm(
// gasModel: _model,
// gasRefillDetails: _model.gasRefillDetails?[0],
// )));
// // getVisitData();
// },
// label: context.translation.updateRequest,

Loading…
Cancel
Save