diff --git a/lib/controllers/providers/api/all_requests_provider.dart b/lib/controllers/providers/api/all_requests_provider.dart index 86579328..b1bb12cf 100644 --- a/lib/controllers/providers/api/all_requests_provider.dart +++ b/lib/controllers/providers/api/all_requests_provider.dart @@ -172,6 +172,10 @@ class AllRequestsProvider extends ChangeNotifier { } // loan module + if (context.settingProvider.isUserFlowMedical && !context.userProvider.isNurse) { + list = [16]; + } + return list; } diff --git a/lib/modules/demo_module/demo_provider.dart b/lib/modules/demo_module/demo_provider.dart index 453df42b..18e64600 100644 --- a/lib/modules/demo_module/demo_provider.dart +++ b/lib/modules/demo_module/demo_provider.dart @@ -11,7 +11,7 @@ class DemoProvider extends ChangeNotifier { try { Response response = await ApiManager.instance.post(URLs.addLoan, body: body, showToast: false); if (response.statusCode >= 200 && response.statusCode < 300) { - String message = (jsonDecode(response.body)["message"] ?? ""); + String message = (jsonDecode(response.body)["data"] ?? "") + " " + (jsonDecode(response.body)["message"] ?? ""); Fluttertoast.showToast(msg: message ?? "", toastLength: Toast.LENGTH_LONG); return true; } diff --git a/lib/modules/incident_module/create_incident_request_page.dart b/lib/modules/incident_module/create_incident_request_page.dart index 45a5eb86..606a7265 100644 --- a/lib/modules/incident_module/create_incident_request_page.dart +++ b/lib/modules/incident_module/create_incident_request_page.dart @@ -74,6 +74,10 @@ class _CreateIncidentRequestPageState extends State { @override void initState() { super.initState(); + payload["id"] = 0; + payload["isFromMobile"] = 0; + payload["requestorUserId"] = context.userProvider.user!.userID; + payload["requestorSiteId"] = context.userProvider.user!.clientId; } @override @@ -583,10 +587,7 @@ class _CreateIncidentRequestPageState extends State { } Utils.showLoading(context); IncidentProvider incidentProvider = Provider.of(context, listen: false); - payload["id"] = 0; - payload["isFromMobile"] = 0; - payload["requestorUserId"] = context.userProvider.user!.userID; - payload["requestorSiteId"] = context.userProvider.user!.clientId; + payload["incidentAttachments"] = attachmentList.map((v) => v.toJson()).toList(); bool isSuccess = await incidentProvider.addIncidentRequest(payload); Utils.hideLoading(context); diff --git a/lib/modules/incident_module/incident_data_model.dart b/lib/modules/incident_module/incident_data_model.dart new file mode 100644 index 00000000..6e5e46f1 --- /dev/null +++ b/lib/modules/incident_module/incident_data_model.dart @@ -0,0 +1,313 @@ +import 'package:test_sa/modules/incident_module/incident_attachment_model.dart'; + +class IncidentDataModel { + int? id; + int? reqNo; + String? reqCode; + int? incidentStatusId; + String? incidentStatusName; + int? incidentStatusValue; + int? incidentClassificationId; + String? incidentClassificationName; + int? incidentClassificationValue; + int? existingOvrTicketId; + String? existingOvrTicketName; + int? existingOvrTicketValue; + String? ovrTicketNumber; + String? incidentTitle; + String? incidentDescription; + int? assetId; + String? assetNumber; + String? oracleCode; + String? model; + String? manufacturer; + String? assetOrigin; + int? siteId; + String? siteName; + int? buildingId; + String? buildingName; + int? departmentId; + String? departmentName; + int? floorId; + String? floorName; + int? rootCauseId; + String? rootCauseName; + int? rootCauseValue; + String? otherRootCause; + String? comments; + int? personInvolvedId; + String? personInvolvedName; + int? personInvolvedValue; + int? genderId; + String? genderName; + int? personInvolvedEmployeeId; + String? personInvolvedEmployeeName; + String? assignedQAId; + String? assignedQAName; + String? assignedSecondaryQAId; + String? assignedSecondaryQAName; + String? qaLeaderId; + String? qaLeaderName; + String? correctiveAction; + int? escalateToOvrId; + String? escalateToOvrName; + int? immediateActionId; + String? immediateActionName; + int? clinicalOrNonClinicalId; + String? clinicalOrNonClinicalName; + String? recommendation; + String? requestorUserId; + String? requesterEmployeeId; + String? requesterEmployeeName; + String? requesterEmployeeEmail; + String? requesterPosition; + String? requesterContactNo; + String? requesterExtensionNo; + int? requestorSiteId; + String? requestorSiteName; + int? requestorDepartmentId; + String? requestorDepartmentName; + int? requestorFlowDepartmentId; + String? requestorFlowDepartmentName; + String? requestorFlowDepartmentShortCode; + String? approvalSignature; + String? occurrenceDate; + String? createdDate; + List? incidentAttachments; + + IncidentDataModel( + {this.id, + this.reqNo, + this.reqCode, + this.incidentStatusId, + this.incidentStatusName, + this.incidentStatusValue, + this.incidentClassificationId, + this.incidentClassificationName, + this.incidentClassificationValue, + this.existingOvrTicketId, + this.existingOvrTicketName, + this.existingOvrTicketValue, + this.ovrTicketNumber, + this.incidentTitle, + this.incidentDescription, + this.assetId, + this.assetNumber, + this.oracleCode, + this.model, + this.manufacturer, + this.assetOrigin, + this.siteId, + this.siteName, + this.buildingId, + this.buildingName, + this.departmentId, + this.departmentName, + this.floorId, + this.floorName, + this.rootCauseId, + this.rootCauseName, + this.rootCauseValue, + this.otherRootCause, + this.comments, + this.personInvolvedId, + this.personInvolvedName, + this.personInvolvedValue, + this.genderId, + this.genderName, + this.personInvolvedEmployeeId, + this.personInvolvedEmployeeName, + this.assignedQAId, + this.assignedQAName, + this.assignedSecondaryQAId, + this.assignedSecondaryQAName, + this.qaLeaderId, + this.qaLeaderName, + this.correctiveAction, + this.escalateToOvrId, + this.escalateToOvrName, + this.immediateActionId, + this.immediateActionName, + this.clinicalOrNonClinicalId, + this.clinicalOrNonClinicalName, + this.recommendation, + this.requestorUserId, + this.requesterEmployeeId, + this.requesterEmployeeName, + this.requesterEmployeeEmail, + this.requesterPosition, + this.requesterContactNo, + this.requesterExtensionNo, + this.requestorSiteId, + this.requestorSiteName, + this.requestorDepartmentId, + this.requestorDepartmentName, + this.requestorFlowDepartmentId, + this.requestorFlowDepartmentName, + this.requestorFlowDepartmentShortCode, + this.approvalSignature, + this.occurrenceDate, + this.createdDate, + this.incidentAttachments}); + + IncidentDataModel.fromJson(Map json) { + id = json['id']; + reqNo = json['reqNo']; + reqCode = json['reqCode']; + incidentStatusId = json['incidentStatusId']; + incidentStatusName = json['incidentStatusName']; + incidentStatusValue = json['incidentStatusValue']; + incidentClassificationId = json['incidentClassificationId']; + incidentClassificationName = json['incidentClassificationName']; + incidentClassificationValue = json['incidentClassificationValue']; + existingOvrTicketId = json['existingOvrTicketId']; + existingOvrTicketName = json['existingOvrTicketName']; + existingOvrTicketValue = json['existingOvrTicketValue']; + ovrTicketNumber = json['ovrTicketNumber']; + incidentTitle = json['incidentTitle']; + incidentDescription = json['incidentDescription']; + assetId = json['assetId']; + assetNumber = json['assetNumber']; + oracleCode = json['oracleCode']; + model = json['model']; + manufacturer = json['manufacturer']; + assetOrigin = json['assetOrigin']; + siteId = json['siteId']; + siteName = json['siteName']; + buildingId = json['buildingId']; + buildingName = json['buildingName']; + departmentId = json['departmentId']; + departmentName = json['departmentName']; + floorId = json['floorId']; + floorName = json['floorName']; + rootCauseId = json['rootCauseId']; + rootCauseName = json['rootCauseName']; + rootCauseValue = json['rootCauseValue']; + otherRootCause = json['otherRootCause']; + comments = json['comments']; + personInvolvedId = json['personInvolvedId']; + personInvolvedName = json['personInvolvedName']; + personInvolvedValue = json['personInvolvedValue']; + genderId = json['genderId']; + genderName = json['genderName']; + personInvolvedEmployeeId = json['personInvolvedEmployeeId']; + personInvolvedEmployeeName = json['personInvolvedEmployeeName']; + assignedQAId = json['assignedQAId']; + assignedQAName = json['assignedQAName']; + assignedSecondaryQAId = json['assignedSecondaryQAId']; + assignedSecondaryQAName = json['assignedSecondaryQAName']; + qaLeaderId = json['qaLeaderId']; + qaLeaderName = json['qaLeaderName']; + correctiveAction = json['correctiveAction']; + escalateToOvrId = json['escalateToOvrId']; + escalateToOvrName = json['escalateToOvrName']; + immediateActionId = json['immediateActionId']; + immediateActionName = json['immediateActionName']; + clinicalOrNonClinicalId = json['clinicalOrNonClinicalId']; + clinicalOrNonClinicalName = json['clinicalOrNonClinicalName']; + recommendation = json['recommendation']; + requestorUserId = json['requestorUserId']; + requesterEmployeeId = json['requesterEmployeeId']; + requesterEmployeeName = json['requesterEmployeeName']; + requesterEmployeeEmail = json['requesterEmployeeEmail']; + requesterPosition = json['requesterPosition']; + requesterContactNo = json['requesterContactNo']; + requesterExtensionNo = json['requesterExtensionNo']; + requestorSiteId = json['requestorSiteId']; + requestorSiteName = json['requestorSiteName']; + requestorDepartmentId = json['requestorDepartmentId']; + requestorDepartmentName = json['requestorDepartmentName']; + requestorFlowDepartmentId = json['requestorFlowDepartmentId']; + requestorFlowDepartmentName = json['requestorFlowDepartmentName']; + requestorFlowDepartmentShortCode = json['requestorFlowDepartmentShortCode']; + approvalSignature = json['approvalSignature']; + occurrenceDate = json['occurrenceDate']; + createdDate = json['createdDate']; + if (json['incidentAttachments'] != null) { + incidentAttachments = []; + json['incidentAttachments'].forEach((v) { + incidentAttachments!.add(IncidentAttachments.fromJson(v)); + }); + } + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['reqNo'] = this.reqNo; + data['reqCode'] = this.reqCode; + data['incidentStatusId'] = this.incidentStatusId; + data['incidentStatusName'] = this.incidentStatusName; + data['incidentStatusValue'] = this.incidentStatusValue; + data['incidentClassificationId'] = this.incidentClassificationId; + data['incidentClassificationName'] = this.incidentClassificationName; + data['incidentClassificationValue'] = this.incidentClassificationValue; + data['existingOvrTicketId'] = this.existingOvrTicketId; + data['existingOvrTicketName'] = this.existingOvrTicketName; + data['existingOvrTicketValue'] = this.existingOvrTicketValue; + data['ovrTicketNumber'] = this.ovrTicketNumber; + data['incidentTitle'] = this.incidentTitle; + data['incidentDescription'] = this.incidentDescription; + data['assetId'] = this.assetId; + data['assetNumber'] = this.assetNumber; + data['oracleCode'] = this.oracleCode; + data['model'] = this.model; + data['manufacturer'] = this.manufacturer; + data['assetOrigin'] = this.assetOrigin; + data['siteId'] = this.siteId; + data['siteName'] = this.siteName; + data['buildingId'] = this.buildingId; + data['buildingName'] = this.buildingName; + data['departmentId'] = this.departmentId; + data['departmentName'] = this.departmentName; + data['floorId'] = this.floorId; + data['floorName'] = this.floorName; + data['rootCauseId'] = this.rootCauseId; + data['rootCauseName'] = this.rootCauseName; + data['rootCauseValue'] = this.rootCauseValue; + data['otherRootCause'] = this.otherRootCause; + data['comments'] = this.comments; + data['personInvolvedId'] = this.personInvolvedId; + data['personInvolvedName'] = this.personInvolvedName; + data['personInvolvedValue'] = this.personInvolvedValue; + data['genderId'] = this.genderId; + data['genderName'] = this.genderName; + data['personInvolvedEmployeeId'] = this.personInvolvedEmployeeId; + data['personInvolvedEmployeeName'] = this.personInvolvedEmployeeName; + data['assignedQAId'] = this.assignedQAId; + data['assignedQAName'] = this.assignedQAName; + data['assignedSecondaryQAId'] = this.assignedSecondaryQAId; + data['assignedSecondaryQAName'] = this.assignedSecondaryQAName; + data['qaLeaderId'] = this.qaLeaderId; + data['qaLeaderName'] = this.qaLeaderName; + data['correctiveAction'] = this.correctiveAction; + data['escalateToOvrId'] = this.escalateToOvrId; + data['escalateToOvrName'] = this.escalateToOvrName; + data['immediateActionId'] = this.immediateActionId; + data['immediateActionName'] = this.immediateActionName; + data['clinicalOrNonClinicalId'] = this.clinicalOrNonClinicalId; + data['clinicalOrNonClinicalName'] = this.clinicalOrNonClinicalName; + data['recommendation'] = this.recommendation; + data['requestorUserId'] = this.requestorUserId; + data['requesterEmployeeId'] = this.requesterEmployeeId; + data['requesterEmployeeName'] = this.requesterEmployeeName; + data['requesterEmployeeEmail'] = this.requesterEmployeeEmail; + data['requesterPosition'] = this.requesterPosition; + data['requesterContactNo'] = this.requesterContactNo; + data['requesterExtensionNo'] = this.requesterExtensionNo; + data['requestorSiteId'] = this.requestorSiteId; + data['requestorSiteName'] = this.requestorSiteName; + data['requestorDepartmentId'] = this.requestorDepartmentId; + data['requestorDepartmentName'] = this.requestorDepartmentName; + data['requestorFlowDepartmentId'] = this.requestorFlowDepartmentId; + data['requestorFlowDepartmentName'] = this.requestorFlowDepartmentName; + data['requestorFlowDepartmentShortCode'] = this.requestorFlowDepartmentShortCode; + data['approvalSignature'] = this.approvalSignature; + data['occurrenceDate'] = this.occurrenceDate; + data['createdDate'] = this.createdDate; + if (this.incidentAttachments != null) { + data['incidentAttachments'] = this.incidentAttachments!.map((v) => v.toJson()).toList(); + } + return data; + } +} diff --git a/lib/modules/incident_module/incident_detail_page.dart b/lib/modules/incident_module/incident_detail_page.dart new file mode 100644 index 00000000..ea9f9b1f --- /dev/null +++ b/lib/modules/incident_module/incident_detail_page.dart @@ -0,0 +1,178 @@ +import 'dart:developer'; + +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:test_sa/controllers/api_routes/urls.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/extensions/text_extensions.dart'; +import 'package:test_sa/extensions/widget_extensions.dart'; +import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart'; +import 'package:test_sa/modules/incident_module/incident_attachment_model.dart'; +import 'package:test_sa/modules/incident_module/incident_data_model.dart'; +import 'package:test_sa/modules/incident_module/incident_provider.dart'; +import 'package:test_sa/modules/internal_audit_module/models/internal_audit_attachment_model.dart'; +import 'package:test_sa/modules/internal_audit_module/models/system_internal_audit_data_model.dart'; +import 'package:test_sa/modules/internal_audit_module/pages/equipment_internal_audit/update_equipment_internal_audit_page.dart'; +import 'package:test_sa/modules/internal_audit_module/pages/system_internal_audit/update_system_internal_audit_page.dart'; +import 'package:test_sa/modules/internal_audit_module/provider/internal_audit_provider.dart'; +import 'package:test_sa/modules/loan_module/models/loan_attachment_model.dart'; +import 'package:test_sa/modules/loan_module/models/loan_request_model.dart'; +import 'package:test_sa/modules/loan_module/provider/loan_provider.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/default_app_bar.dart'; +import 'package:test_sa/views/widgets/images/files_list.dart'; + +import 'package:test_sa/views/widgets/loaders/app_loading.dart'; +import 'package:test_sa/views/widgets/loaders/no_data_found.dart'; +import 'package:test_sa/views/widgets/requests/request_status.dart'; + +class IncidentDetailPage extends StatelessWidget { + static const String id = "/incident-detail-page"; + final int incidentId; + + IncidentDetailPage({Key? key, required this.incidentId}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: const DefaultAppBar(title: "Request Details"), + body: SafeArea( + child: FutureBuilder( + future: Provider.of(context, listen: false).getIncidentById(97), + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) return const CircularProgressIndicator(color: AppColor.primary10).center; + if (snapshot.data == null) return const NoDataFound().center; + + List allAttachments = snapshot.data!.incidentAttachments!; + + return ListView( + padding: const EdgeInsets.all(16), + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + StatusLabel( + label: snapshot.data!.incidentStatusName!, + textColor: AppColor.getRequestStatusTextColorByName(context, snapshot.data!.incidentStatusName!), + backgroundColor: AppColor.getRequestStatusColorByName(context, snapshot.data!.incidentStatusName!), + ), + 1.width.expanded, + Text( + snapshot.data!.createdDate?.toServiceRequestCardFormat ?? "-", + textAlign: TextAlign.end, + style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50), + ), + ], + ), + 12.height, + ...requesterDetails(context, snapshot.data!), + const Divider().defaultStyle(context), + ...requestDetails(context, snapshot.data!), + const Divider().defaultStyle(context), + ...assetDetails(context, snapshot.data!), + const Divider().defaultStyle(context), + ...personInvolvedDetails(context, snapshot.data!), + if (allAttachments.isNotEmpty) ...[ + const Divider().defaultStyle(context), + Text( + "Attachments".addTranslation, + style: AppTextStyles.heading4.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50), + ), + FilesList(images: allAttachments.map((e) => URLs.getFileUrl(e.attachmentName ?? '') ?? '').toList() ?? []), + ], + ], + ).toShadowContainer(context, padding: 12), + ], + ); + }), + )); + } + + List requestDetails(BuildContext context, IncidentDataModel incidentData) { + return [ + Text("Request Details", style: AppTextStyles.heading4.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50)), + 'Incident No: ${incidentData.reqCode ?? "-"}'.bodyText(context), + 'Incident Type: ${incidentData.incidentClassificationName ?? "-"}'.bodyText(context), + 'Incident Title: ${incidentData.incidentTitle ?? "-"}'.bodyText(context), + 'Incident Description: ${incidentData.incidentDescription ?? "-"}'.bodyText(context), + 'Exist OVR: ${incidentData.existingOvrTicketName ?? "-"}'.bodyText(context), + 'Site: ${incidentData.siteName ?? "-"}'.bodyText(context), + 'Building: ${incidentData.buildingName ?? "-"}'.bodyText(context), + 'Floor: ${incidentData.floorName ?? "-"}'.bodyText(context), + 'Department: ${incidentData.departmentName ?? "-"}'.bodyText(context), + 'Occurrence Date: ${incidentData.occurrenceDate?.toServiceRequestDetailsFormat ?? "-"}'.bodyText(context), + 'Root Cause: ${incidentData.rootCauseName ?? "-"}'.bodyText(context), + if (incidentData.rootCauseValue == 5) 'Root reason: ${incidentData.otherRootCause ?? "-"}'.bodyText(context), + 'Comments: ${incidentData.comments ?? "-"}'.bodyText(context), + ]; + } + + List personInvolvedDetails(BuildContext context, IncidentDataModel incidentData) { + return [ + Text("Person Involved Information", style: AppTextStyles.heading4.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50)), + 'Person Involved: ${incidentData.personInvolvedName ?? "-"}'.bodyText(context), + 'Gender: ${incidentData.genderName ?? "-"}'.bodyText(context), + 'Person Involved ID: ${incidentData.personInvolvedEmployeeId ?? "-"}'.bodyText(context), + 'Person Involved Name: ${incidentData.personInvolvedEmployeeName ?? "-"}'.bodyText(context), + ]; + } + + List assetDetails(BuildContext context, IncidentDataModel loanData) { + return [ + Text("Asset Information", style: AppTextStyles.heading4.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50)), + '${context.translation.assetName}: ${loanData.assetOrigin ?? "-"}'.bodyText(context), + '${context.translation.assetNo}: ${loanData.assetNumber ?? "-"}'.bodyText(context), + // '${context.translation.serialNumber}: ${loanData.assetSerialNumber ?? "-"}'.bodyText(context), + '${context.translation.manufacture}: ${loanData.manufacturer ?? "-"}'.bodyText(context), + '${context.translation.model}: ${loanData.model ?? "-"}'.bodyText(context), + ]; + } + + List requesterDetails(BuildContext context, IncidentDataModel incidentData) { + return [ + Text("Requester Information", style: AppTextStyles.heading4.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral50)), + 'Name: ${incidentData.requesterEmployeeName ?? "-"}'.bodyText(context), + 'Email: ${incidentData.requesterEmployeeEmail ?? "-"}'.bodyText(context), + 'Contact: ${incidentData.requesterContactNo ?? "-"}'.bodyText(context), + 'Extension: ${incidentData.requesterExtensionNo ?? "-"}'.bodyText(context), + 'Site: ${incidentData.requestorSiteName ?? "-"}'.bodyText(context), + 'Department: ${incidentData.requestorFlowDepartmentName ?? "-"}'.bodyText(context), + ]; + } + + Widget labelValueText(BuildContext context, String label, String? value) { + if (value == null || value.isEmpty) return const SizedBox.shrink(); + + return Padding( + padding: const EdgeInsets.only(bottom: 4), + child: Text( + '$label: $value', + style: AppTextStyles.bodyText.copyWith( + color: context.isDark ? AppColor.neutral30 : AppColor.neutral120, + ), + ), + ); + } + + Widget checklistWidget(BuildContext context, {required String value}) { + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + Checkbox( + value: true, + activeColor: AppColor.neutral120, + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + visualDensity: const VisualDensity(horizontal: -4, vertical: -3), + onChanged: (value) {}, + ), + value.bodyText(context), + ], + ); + } +} diff --git a/lib/modules/incident_module/incident_item_view.dart b/lib/modules/incident_module/incident_item_view.dart new file mode 100644 index 00000000..ff4db6fa --- /dev/null +++ b/lib/modules/incident_module/incident_item_view.dart @@ -0,0 +1,117 @@ +import 'dart:developer'; + +import 'package:flutter/material.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/extensions/text_extensions.dart'; +import 'package:test_sa/extensions/widget_extensions.dart'; +import 'package:test_sa/models/all_requests_and_count_model.dart'; +import 'package:test_sa/models/new_models/dashboard_detail.dart'; +import 'package:test_sa/modules/internal_audit_module/pages/equipment_internal_audit/equipment_internal_audit_detail_page.dart'; +import 'package:test_sa/new_views/app_style/app_color.dart'; +import 'package:test_sa/views/widgets/requests/request_status.dart'; + +import 'incident_detail_page.dart'; + +class IncidentItemView extends StatelessWidget { + final Data? requestData; + final RequestsDetails? requestDetails; + final bool showShadow; + + const IncidentItemView({Key? key, this.requestData, this.requestDetails, this.showShadow = true}) : super(key: key); + + @override + Widget build(BuildContext context) { + if (requestData != null) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + StatusLabel( + label: requestData!.statusName!, + textColor: AppColor.getRequestStatusTextColorByName(context, requestData!.statusName!), + backgroundColor: AppColor.getRequestStatusColorByName(context, requestData!.statusName!), + ), + 1.width.expanded, + Text( + requestData!.transactionDate?.toServiceRequestCardFormat ?? "", + textAlign: TextAlign.end, + style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50), + ), + ], + ), + 8.height, + (requestData?.typeTransaction ?? "Loan Request").heading5(context), + infoWidget(label: context.translation.requestType, value: requestData?.requestTypeName, context: context), + infoWidget(label: "Incident No", value: requestData?.requestNo, context: context), + // infoWidget(label: context.translation.site, value: requestData?., context: context), + 8.height, + Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + context.translation.viewDetails, + style: AppTextStyles.bodyText.copyWith(color: AppColor.blueStatus(context)), + ), + 4.width, + Icon(Icons.arrow_forward, color: AppColor.blueStatus(context), size: 14) + ], + ), + ], + ).toShadowContainer(context, withShadow: showShadow).onPress(() async { + Navigator.push(context, MaterialPageRoute(builder: (context) => IncidentDetailPage(incidentId: requestDetails!.id!))); + }); + } + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + StatusLabel( + label: requestDetails!.status!, + textColor: AppColor.getRequestStatusTextColorByName(context, requestDetails?.status!), + backgroundColor: AppColor.getRequestStatusColorByName(context, requestDetails?.status!), + ), + 1.width.expanded, + Text( + requestDetails!.date?.toServiceRequestCardFormat ?? "", + textAlign: TextAlign.end, + style: AppTextStyles.tinyFont.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral50), + ), + ], + ), + 8.height, + (requestDetails?.nameOfType ?? "Loan Request").heading5(context), + 8.height, + infoWidget(label: context.translation.requestType, value: requestDetails!.requestType, context: context), + infoWidget(label: "Incident No", value: requestDetails!.requestNo, context: context), + infoWidget(label: context.translation.site, value: requestDetails!.site, context: context), + 8.height, + Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + context.translation.viewDetails, + style: AppTextStyles.bodyText.copyWith(color: AppColor.blueStatus(context)), + ), + 4.width, + Icon(Icons.arrow_forward, color: AppColor.blueStatus(context), size: 14) + ], + ), + ], + ).toShadowContainer(context, withShadow: showShadow).onPress(() async { + Navigator.push(context, MaterialPageRoute(builder: (context) => IncidentDetailPage(incidentId: requestDetails!.id!))); + }); + } + + Widget infoWidget({required String label, String? value, required BuildContext context}) { + if (value != null && value.isNotEmpty) { + return '$label: $value'.bodyText(context); + } + return const SizedBox(); + } +} diff --git a/lib/modules/incident_module/incident_provider.dart b/lib/modules/incident_module/incident_provider.dart index c4f24389..bb692016 100644 --- a/lib/modules/incident_module/incident_provider.dart +++ b/lib/modules/incident_module/incident_provider.dart @@ -6,12 +6,14 @@ import 'package:test_sa/controllers/api_routes/urls.dart'; import 'package:test_sa/modules/loan_module/models/loan_request_model.dart'; import 'dart:convert'; +import 'incident_data_model.dart'; + class IncidentProvider extends ChangeNotifier { Future addIncidentRequest(Map body) async { try { Response response = await ApiManager.instance.post(URLs.addIncident, body: body); if (response.statusCode >= 200 && response.statusCode < 300) { - String message = (jsonDecode(response.body)["message"] ?? ""); + String message = (jsonDecode(response.body)["data"] ?? "") + " " + (jsonDecode(response.body)["message"] ?? ""); Fluttertoast.showToast(msg: message ?? "", toastLength: Toast.LENGTH_LONG); return true; } @@ -23,12 +25,12 @@ class IncidentProvider extends ChangeNotifier { bool isLoading = false; - Future getIncidentById(int id) async { - LoanRequestModel? loanData; + Future getIncidentById(int id) async { + IncidentDataModel? loanData; try { Response response = await ApiManager.instance.get(URLs.getIncidentById + "?incidentId=$id"); if (response.statusCode >= 200 && response.statusCode < 300) { - loanData = LoanRequestModel.fromJson(json.decode(response.body)["data"]); + loanData = IncidentDataModel.fromJson(json.decode(response.body)["data"]); } } catch (error) { print(error); diff --git a/lib/modules/loan_module/provider/loan_provider.dart b/lib/modules/loan_module/provider/loan_provider.dart index deccfe79..b2a3a5e3 100644 --- a/lib/modules/loan_module/provider/loan_provider.dart +++ b/lib/modules/loan_module/provider/loan_provider.dart @@ -11,7 +11,7 @@ class LoanProvider extends ChangeNotifier { try { Response response = await ApiManager.instance.post(URLs.addLoan, body: body, showToast: false); if (response.statusCode >= 200 && response.statusCode < 300) { - String message = (jsonDecode(response.body)["message"] ?? ""); + String message = (jsonDecode(response.body)["data"] ?? "") + " " + (jsonDecode(response.body)["message"] ?? ""); Fluttertoast.showToast(msg: message ?? "", toastLength: Toast.LENGTH_LONG); return true; } diff --git a/lib/new_views/pages/land_page/my_request/all_requests_filter_page.dart b/lib/new_views/pages/land_page/my_request/all_requests_filter_page.dart index 35253c86..a5226b80 100644 --- a/lib/new_views/pages/land_page/my_request/all_requests_filter_page.dart +++ b/lib/new_views/pages/land_page/my_request/all_requests_filter_page.dart @@ -79,9 +79,9 @@ class _AllRequestsFilterPageState extends State { if (isEngineer) { types[context.translation.recurrentWo] = 5; - if (context.settingProvider.isUserFlowMedical) types["Equipment Internal Audit".addTranslation] = 10; - if (context.settingProvider.isUserFlowMedical) types["System Internal Audit".addTranslation] = 11; - if (context.settingProvider.isUserFlowMedical) types["Medical Gas Inspection".addTranslation] = 11; + if (context.settingProvider.isUserFlowMedical) types["Equipment Internal Audit".addTranslation] = 10; + if (context.settingProvider.isUserFlowMedical) types["System Internal Audit".addTranslation] = 11; + if (context.settingProvider.isUserFlowMedical) types["Medical Gas Inspection".addTranslation] = 11; } if (context.settingProvider.isUserFlowMedical && isEngineer) { @@ -104,8 +104,8 @@ class _AllRequestsFilterPageState extends State { // } if (context.userProvider.isQualityUser) { if (context.settingProvider.isUserFlowMedical) types = {'Recall and Alert': 7}; - if (context.settingProvider.isUserFlowMedical) types['Equipment Internal Audit'] = 10; - if (context.settingProvider.isUserFlowMedical) types['System Internal Audit'] = 11; + if (context.settingProvider.isUserFlowMedical) types['Equipment Internal Audit'] = 10; + if (context.settingProvider.isUserFlowMedical) types['System Internal Audit'] = 11; } if (context.userProvider.isCommissioningEngineer) { ///TODO need to check what other requests type needed here. @@ -114,6 +114,10 @@ class _AllRequestsFilterPageState extends State { }; } + if (context.settingProvider.isUserFlowMedical && !context.userProvider.isNurse) { + types = {'Incidents': 16}; + } + final statuses = { "All WO": 0, context.translation.open: 1, diff --git a/lib/new_views/pages/land_page/my_request/my_requests_page.dart b/lib/new_views/pages/land_page/my_request/my_requests_page.dart index e28dca9c..14a8530f 100644 --- a/lib/new_views/pages/land_page/my_request/my_requests_page.dart +++ b/lib/new_views/pages/land_page/my_request/my_requests_page.dart @@ -66,7 +66,7 @@ class _MyRequestsPageState extends State { // if (context.userProvider.user!.type == UsersTypes.normal_user) { // requestsList.add(Request(9, 'TRAF')); // } - if (context.userProvider.isEngineer &&context.settingProvider.isUserFlowMedical) { + if (context.userProvider.isEngineer && context.settingProvider.isUserFlowMedical) { requestsList.add(Request(10, 'Equipment Internal Audit')); requestsList.add(Request(11, 'System Internal Audit')); //Need to be added for new user role commissioning engineer @@ -93,11 +93,15 @@ class _MyRequestsPageState extends State { requestsList = [ Request(null, context.translation.allWorkOrder), if (context.settingProvider.isUserFlowMedical) Request(7, 'Recall and Alert'), - if (context.settingProvider.isUserFlowMedical) Request(10, 'Equipment Internal Audit'), - if (context.settingProvider.isUserFlowMedical) Request(11, 'System Internal Audit'), + if (context.settingProvider.isUserFlowMedical) Request(10, 'Equipment Internal Audit'), + if (context.settingProvider.isUserFlowMedical) Request(11, 'System Internal Audit'), ]; } + if (context.settingProvider.isUserFlowMedical && !context.userProvider.isNurse) { + requestsList.add(Request(16, "Incidents")); + } + _provider = Provider.of(context, listen: false); _provider!.reset(); WidgetsBinding.instance.addPostFrameCallback((_) { diff --git a/lib/new_views/pages/land_page/requests/request_paginated_listview.dart b/lib/new_views/pages/land_page/requests/request_paginated_listview.dart index f4d83656..ab6c9a78 100644 --- a/lib/new_views/pages/land_page/requests/request_paginated_listview.dart +++ b/lib/new_views/pages/land_page/requests/request_paginated_listview.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:test_sa/extensions/int_extensions.dart'; import 'package:test_sa/models/new_models/dashboard_detail.dart'; import 'package:test_sa/modules/asset_delivery_module/pages/asset_delivery_item_view.dart'; +import 'package:test_sa/modules/incident_module/incident_item_view.dart'; import 'package:test_sa/modules/internal_audit_module/pages/equipment_internal_audit/equipment_internal_audit_item_view.dart'; import 'package:test_sa/modules/internal_audit_module/pages/system_internal_audit/system_internal_audit_item_view.dart'; import 'package:test_sa/modules/asset_inventory_module/pages/inventory_session_item_view.dart'; @@ -77,10 +78,12 @@ class RequestPaginatedListview extends StatelessWidget { return SystemInternalAuditItemView(requestData: request); case 12: return LoanEquipmentItemView(requestData: request); - case 13: + case 13: return AssetDeliveryItemView(requestData: request); - case 14: + case 14: return MedicalGasInspectionItemView(requestData: request); + case 16: + return IncidentItemView(requestData: request); default: return Container( height: 100, diff --git a/lib/new_views/pages/land_page/widgets/request_item_view_list.dart b/lib/new_views/pages/land_page/widgets/request_item_view_list.dart index 10339da7..4ae0167d 100644 --- a/lib/new_views/pages/land_page/widgets/request_item_view_list.dart +++ b/lib/new_views/pages/land_page/widgets/request_item_view_list.dart @@ -7,6 +7,7 @@ import 'package:test_sa/extensions/int_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/models/all_requests_and_count_model.dart'; import 'package:test_sa/modules/asset_delivery_module/pages/asset_delivery_item_view.dart'; +import 'package:test_sa/modules/incident_module/incident_item_view.dart'; import 'package:test_sa/modules/internal_audit_module/pages/equipment_internal_audit/equipment_internal_audit_item_view.dart'; import 'package:test_sa/modules/internal_audit_module/pages/system_internal_audit/system_internal_audit_item_view.dart'; import 'package:test_sa/modules/asset_inventory_module/pages/inventory_session_item_view.dart'; @@ -77,7 +78,8 @@ class RequestItemViewList extends StatelessWidget { return AssetDeliveryItemView(requestDetails: list[index]); case 14: return MedicalGasInspectionItemView(requestDetails: list[index]); - + case 16: + return IncidentItemView(requestDetails: list[index]); default: Container( height: 100,