From cb2329a6c21d2ab70c64527a8269d882e7f705b4 Mon Sep 17 00:00:00 2001 From: Sikander Saleem Date: Mon, 9 Feb 2026 16:45:01 +0300 Subject: [PATCH] incident create request completed. --- lib/controllers/api_routes/urls.dart | 2 + lib/main.dart | 2 + lib/models/device/model_definition.dart | 39 ++ lib/modules/demo_module/demo_provider.dart | 2 +- .../create_incident_request_page.dart | 446 +++++++++--------- .../incident_attachment_model.dart | 24 + .../incident_module/incident_provider.dart | 38 ++ .../loan_module/provider/loan_provider.dart | 2 +- 8 files changed, 343 insertions(+), 212 deletions(-) create mode 100644 lib/modules/incident_module/incident_attachment_model.dart create mode 100644 lib/modules/incident_module/incident_provider.dart diff --git a/lib/controllers/api_routes/urls.dart b/lib/controllers/api_routes/urls.dart index 17e0f4b6..10ea73dd 100644 --- a/lib/controllers/api_routes/urls.dart +++ b/lib/controllers/api_routes/urls.dart @@ -408,8 +408,10 @@ class URLs { static get getMedDepartmentBasedOnSite => "$_baseUrl/TRAFDataSource/GetDepartmentBasedOnSite"; static get getLoanById => '$_baseUrl/Loan/GetLoanById'; + static get getIncidentById => '$_baseUrl/Incident/GetIncidentById'; static get addLoan => '$_baseUrl/Loan/AddLoan'; + static get addIncident => '$_baseUrl/Incident/AddIncident'; //Asset Delivery Module static get getAssetDeliveryDetailsById => '$_baseUrl/AssetDeliveryExternal/GetAssetDeliveryExternalById'; diff --git a/lib/main.dart b/lib/main.dart index f6e9a9fb..1d64b423 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -40,6 +40,7 @@ import 'package:test_sa/modules/cx_module/chat/chat_provider.dart'; import 'package:test_sa/modules/demo_module/create_demo_request_page.dart'; import 'package:test_sa/modules/demo_module/demo_period_lookup_provider.dart'; import 'package:test_sa/modules/demo_module/demo_provider.dart'; +import 'package:test_sa/modules/incident_module/incident_provider.dart'; import 'package:test_sa/modules/internal_audit_module/pages/equipment_internal_audit/create_equipment_internal_audit_form.dart'; import 'package:test_sa/modules/internal_audit_module/pages/system_internal_audit/create_system_internal_audit_form.dart'; import 'package:test_sa/modules/internal_audit_module/pages/system_internal_audit/update_system_internal_audit_page.dart'; @@ -351,6 +352,7 @@ class MyApp extends StatelessWidget { ChangeNotifierProvider(create: (_) => IncidentPersonInvolvedLookupProvider()), ChangeNotifierProvider(create: (_) => ClinicalNonClinicalLookupProvider()), ChangeNotifierProvider(create: (_) => GenderLookupProvider()), + ChangeNotifierProvider(create: (_) => IncidentProvider()), ], child: GestureDetector( onTap: () { diff --git a/lib/models/device/model_definition.dart b/lib/models/device/model_definition.dart index a19a7a18..328909b8 100644 --- a/lib/models/device/model_definition.dart +++ b/lib/models/device/model_definition.dart @@ -37,6 +37,13 @@ class ModelDefinition { modelDefRelatedDefects!.add(ModelDefRelatedDefects.fromJson(v)); // Use '!' since modelDefRelatedDefects is initialized here }); } + + if (json['oracleCodes'] != null) { + oracleCodes = []; + json['oracleCodes'].forEach((v) { + oracleCodes!.add(OracleCode.fromJson(v)); // Use '!' since modelDefRelatedDefects is initialized here + }); + } if (json['suppliers'] != null) { suppliers = []; json['suppliers'].forEach((v) { @@ -59,6 +66,7 @@ class ModelDefinition { num? lifeSpan; // Now nullable List? modelDefRelatedDefects; // Now nullable List? suppliers; // Now nullable + List? oracleCodes; // Now nullable // ... (copyWith method remains the same, just with nullable parameters) @@ -108,3 +116,34 @@ class ModelDefRelatedDefects { return map; } } + +class OracleCode { + int? id; + int? assetNDId; + int? codeTypeId; + String? codeTypeName; + int? codeTypeValue; + String? codeValue; + + OracleCode({this.id, this.assetNDId, this.codeTypeId, this.codeTypeName, this.codeTypeValue, this.codeValue}); + + OracleCode.fromJson(Map json) { + id = json['id']; + assetNDId = json['assetNDId']; + codeTypeId = json['codeTypeId']; + codeTypeName = json['codeTypeName']; + codeTypeValue = json['codeTypeValue']; + codeValue = json['codeValue']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['assetNDId'] = this.assetNDId; + data['codeTypeId'] = this.codeTypeId; + data['codeTypeName'] = this.codeTypeName; + data['codeTypeValue'] = this.codeTypeValue; + data['codeValue'] = this.codeValue; + return data; + } +} diff --git a/lib/modules/demo_module/demo_provider.dart b/lib/modules/demo_module/demo_provider.dart index 18e64600..453df42b 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)["data"] ?? "") + " " + (jsonDecode(response.body)["message"] ?? ""); + String message = (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 817ffb44..45a5eb86 100644 --- a/lib/modules/incident_module/create_incident_request_page.dart +++ b/lib/modules/incident_module/create_incident_request_page.dart @@ -1,18 +1,27 @@ +import 'dart:convert'; +import 'dart:io'; + import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; import 'package:test_sa/controllers/validator/validator.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/helper/utils.dart'; import 'package:test_sa/models/device/asset.dart'; import 'package:test_sa/models/generic_attachment_model.dart'; import 'package:test_sa/models/lookup.dart'; import 'package:test_sa/models/new_models/building.dart'; import 'package:test_sa/models/new_models/floor.dart'; import 'package:test_sa/models/new_models/site.dart'; +import 'package:test_sa/modules/cm_module/cm_request_utils.dart'; import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart'; import 'package:test_sa/modules/incident_module/incident_lookup_provider.dart'; +import 'package:test_sa/modules/incident_module/incident_provider.dart'; +import 'package:test_sa/modules/loan_module/models/medical_department_model.dart'; +import 'package:test_sa/modules/loan_module/provider/medical_department_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/app_text_form_field.dart'; @@ -21,10 +30,12 @@ import 'package:test_sa/new_views/common_widgets/single_item_drop_down_menu.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/providers/lookups/yes_no_lookup_provider.dart'; +import 'package:test_sa/views/widgets/date_and_time/date_picker.dart'; import 'package:test_sa/views/widgets/equipment/asset_picker.dart'; import 'package:test_sa/views/widgets/images/multi_image_picker.dart'; import '../../models/new_models/department.dart'; +import 'incident_attachment_model.dart'; class CreateIncidentRequestPage extends StatefulWidget { static const String id = "/create-incident"; @@ -40,8 +51,10 @@ class CreateIncidentRequestPage extends StatefulWidget { class _CreateIncidentRequestPageState extends State { final GlobalKey _formKey = GlobalKey(); final GlobalKey _scaffoldKey = GlobalKey(); - final List attachments = []; + List attachments = []; + MedicalDepartmentModel? _medicalDepartmentModel; + Site? _empSite; Site? _selectedSite; Building? _selectedBuilding; Floor? _selectedFloor; @@ -51,6 +64,12 @@ class _CreateIncidentRequestPageState extends State { Lookup? incidentType; Lookup? ovrSystem; + Lookup? rootCause; + Lookup? involvedPerson; + Lookup? gender; + DateTime? occurrenceDate; + + Map payload = {}; @override void initState() { @@ -77,26 +96,39 @@ class _CreateIncidentRequestPageState extends State { crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ + ...empSiteSection(), + 16.height, ...incidentInfoSection(), if (incidentType?.value == 1) ...[ 16.height, + "Asset Details".bodyText(context).custom(color: AppColor.black10), + 8.height, AssetPicker( device: device, showLoading: false, borderColor: AppColor.black20, onPick: (asset) async { device = asset; + payload["assetId"] = asset.modelDefinition?.id; + payload["oracleCode"] = asset.modelDefinition?.oracleCodes?.first.codeValue; + payload["model"] = asset.modelDefinition?.modelName; + payload["manufacturer"] = asset.modelDefinition?.manufacturerId; + payload["assetOrigin"] = asset.modelDefinition?.assetName; setState(() {}); }, ) ], - if (incidentType?.value != 1) ...[ + if (incidentType?.value != null && incidentType?.value != 1) ...[ 16.height, ...siteSection(), ], 16.height, - ...vendorDetailsSection(), + ...detailsSection(), 16.height, + ...optionQuestions(), + 16.height, + "Attachments".bodyText(context).custom(color: AppColor.black10), + 8.height, AttachmentPicker( label: context.translation.attachments, attachment: attachments, @@ -104,8 +136,8 @@ class _CreateIncidentRequestPageState extends State { onlyImages: false, showAsListView: true, buttonIcon: 'image-plus'.toSvgAsset(color: context.isDark ? AppColor.primary10 : AppColor.neutral120), - onChange: (attachments) { - attachments = attachments; + onChange: (_attachments) { + attachments = _attachments; setState(() {}); }, ), @@ -127,6 +159,27 @@ class _CreateIncidentRequestPageState extends State { ); } + List optionQuestions() { + return [ + 'Additional Information & Comments'.addTranslation.bodyText(context).custom(color: AppColor.black10), + 8.height, + AppTextFormField( + initialValue: "", + labelText: "Some Comments", + style: TextStyle(fontWeight: FontWeight.w500, fontSize: context.isTablet() ? 16 : 12, color: context.isDark ? Colors.white : const Color(0xff3B3D4A)), + labelStyle: TextStyle(fontWeight: FontWeight.w500, fontSize: context.isTablet() ? 16 : 12, color: context.isDark ? Colors.white : const Color(0xff767676)), + floatingLabelStyle: TextStyle(fontWeight: FontWeight.w500, fontSize: context.isTablet() ? 16 : 12, color: context.isDark ? Colors.white : const Color(0xff3B3D4A)), + backgroundColor: AppColor.fieldBgColor(context), + showShadow: false, + textInputType: TextInputType.multiline, + makeMultiLinesNull: false, + onChange: (value) { + payload["comments"] = value; + }, + ), + ]; + } + List siteSection() { return [ 'Site Details'.addTranslation.bodyText(context).custom(color: AppColor.black10), @@ -144,6 +197,7 @@ class _CreateIncidentRequestPageState extends State { showAsBottomSheet: true, onSelect: (value) { _selectedSite = value; + payload["siteId"] = value?.id; setState(() {}); }, ), @@ -165,6 +219,7 @@ class _CreateIncidentRequestPageState extends State { _selectedBuilding = value; _selectedFloor = null; _selectedDepartment = null; + payload["buildingId"] = value?.id; setState(() {}); }, ), @@ -185,6 +240,7 @@ class _CreateIncidentRequestPageState extends State { onSelect: (value) { _selectedFloor = value; _selectedDepartment = null; + payload["floorId"] = value?.id; setState(() {}); }, ), @@ -204,53 +260,53 @@ class _CreateIncidentRequestPageState extends State { }, onSelect: (value) { _selectedDepartment = value; - // _demoFormModel.room = null; + payload["departmentId"] = value?.id; setState(() {}); }, ), ]; } - // List siteSection() { - // return [ - // 'Site Details'.addTranslation.bodyText(context).custom(color: AppColor.black10), - // 8.height, - // SingleItemDropDownMenu( - // context: context, - // title: context.translation.site, - // initialValue: _demoFormModel.site, - // showShadow: false, - // validator: (value) { - // if (value == null) return "Please select a site"; - // return null; - // }, - // backgroundColor: AppColor.fieldBgColor(context), - // showAsBottomSheet: true, - // onSelect: (value) { - // _demoFormModel.site = value; - // setState(() {}); - // }, - // ), - // 8.height, - // SingleItemDropDownMenu( - // context: context, - // title: context.translation.department, - // showShadow: false, - // validator: (value) { - // if (value == null) return "Please select a department"; - // return null; - // }, - // showAsBottomSheet: true, - // initialValue: _demoFormModel.department, - // requestById: context.userProvider.user?.clientId, - // backgroundColor: AppColor.fieldBgColor(context), - // onSelect: (value) { - // _demoFormModel.department = value; - // setState(() {}); - // }, - // ), - // ]; - // } + List empSiteSection() { + return [ + SingleItemDropDownMenu( + context: context, + title: "Employee Site", + initialValue: _empSite, + showShadow: false, + validator: (value) { + if (value == null) return "Please select a site"; + return null; + }, + backgroundColor: AppColor.fieldBgColor(context), + showAsBottomSheet: true, + onSelect: (value) { + _empSite = value; + payload["requestorSiteId"] = value?.id; + setState(() {}); + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: "Employee Department", + showShadow: false, + validator: (value) { + if (value == null) return "Please select a department"; + return null; + }, + showAsBottomSheet: true, + initialValue: _medicalDepartmentModel, + requestById: context.userProvider.user?.clientId, + backgroundColor: AppColor.fieldBgColor(context), + onSelect: (value) { + _medicalDepartmentModel = value; + payload["requestorFlowDepartmentId"] = value?.id; + setState(() {}); + }, + ), + ]; + } List incidentInfoSection() { return [ @@ -270,6 +326,7 @@ class _CreateIncidentRequestPageState extends State { showAsBottomSheet: true, onSelect: (value) { incidentType = value; + payload["incidentClassificationId"] = value?.id; setState(() {}); }, ), @@ -288,6 +345,7 @@ class _CreateIncidentRequestPageState extends State { showAsBottomSheet: true, onSelect: (value) { ovrSystem = value; + payload["existingOvrTicketId"] = value?.id; setState(() {}); }, ), @@ -307,31 +365,14 @@ class _CreateIncidentRequestPageState extends State { textInputType: TextInputType.name, textInputAction: TextInputAction.next, onChange: (value) { - // _demoFormModel.vendorRepresentativeName = value; + payload["ovrTicketNumber"] = value; }, ), ], 8.height, AppTextFormField( initialValue: "", - labelText: "Name", - validator: (value) { - if ((value ?? "").isEmpty) return "Mandatory"; - return null; - }, - style: Theme.of(context).textTheme.titleMedium, - backgroundColor: AppColor.fieldBgColor(context), - labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), - showShadow: false, - textInputType: TextInputType.text, - onChange: (value) { - // _demoFormModel.docName = value; - }, - ), - 8.height, - AppTextFormField( - initialValue: "", - labelText: "Contact Number", + labelText: "Incident Title", validator: (value) { if ((value ?? "").isEmpty) return "Mandatory"; return null; @@ -340,34 +381,16 @@ class _CreateIncidentRequestPageState extends State { backgroundColor: AppColor.fieldBgColor(context), labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), showShadow: false, - textInputType: TextInputType.phone, + textInputType: TextInputType.name, + textInputAction: TextInputAction.next, onChange: (value) { - // _demoFormModel.docNumber = value; + payload["incidentTitle"] = value; }, ), 8.height, AppTextFormField( initialValue: "", - labelText: "Email", - validator: (value) { - if ((value ?? "").isEmpty) { - return "Mandatory"; - } else { - return Validator.isEmail(value!) ? null : context.translation.emailValidateMessage; - } - }, - style: Theme.of(context).textTheme.titleMedium, - backgroundColor: AppColor.fieldBgColor(context), - labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), - showShadow: false, - textInputType: TextInputType.emailAddress, - onChange: (value) { - // _demoFormModel.docEmail = value; - }, - ), - 8.height, - AppTextFormField( - labelText: "Item Description", + labelText: "Incident Description", validator: (value) { if ((value ?? "").isEmpty) return "Mandatory"; return null; @@ -375,171 +398,167 @@ class _CreateIncidentRequestPageState extends State { style: Theme.of(context).textTheme.titleMedium, backgroundColor: AppColor.fieldBgColor(context), labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), - floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), - showShadow: false, - textInputType: TextInputType.text, - textInputAction: TextInputAction.next, - onChange: (value) { - // _demoFormModel.itemDescription = value; - }, - ), - 8.height, - AppTextFormField( - labelText: "Request Description", - // validator: (value) { - // if ((value ?? "").isEmpty) return "Mandatory"; - // return null; - // }, - style: Theme.of(context).textTheme.titleMedium, - backgroundColor: AppColor.fieldBgColor(context), - labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), - floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), showShadow: false, - textInputType: TextInputType.text, + textInputType: TextInputType.name, textInputAction: TextInputAction.next, onChange: (value) { - // _demoFormModel.requestDescription = value; + payload["incidentDescription"] = value; }, ), ]; } - List assetSection() { + List detailsSection() { return [ - 'Asset Details'.addTranslation.bodyText(context).custom(color: AppColor.black10), + 'Details'.addTranslation.bodyText(context).custom(color: AppColor.black10), 8.height, - AppTextFormField( - labelText: "Model", + SingleItemDropDownMenu( + context: context, + height: 56.toScreenHeight, + title: "Root Cause", + initialValue: rootCause, + showShadow: false, validator: (value) { - if ((value ?? "").isEmpty) return "Mandatory"; + if (value == null) return "Mandatory"; return null; }, - style: Theme.of(context).textTheme.titleMedium, backgroundColor: AppColor.fieldBgColor(context), - labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), - floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), - showShadow: false, - textInputType: TextInputType.text, - textInputAction: TextInputAction.next, - onChange: (value) { - // _demoFormModel.model = value; + showAsBottomSheet: true, + onSelect: (value) { + rootCause = value; + payload["rootCauseId"] = value?.id; + setState(() {}); }, ), + if (rootCause?.value == 5) ...[ + 8.height, + AppTextFormField( + initialValue: "", + labelText: "Root Cause (Other)", + validator: (value) { + if ((value ?? "").isEmpty) return "Mandatory"; + return null; + }, + style: Theme.of(context).textTheme.titleMedium, + backgroundColor: AppColor.fieldBgColor(context), + labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), + showShadow: false, + textInputType: TextInputType.name, + textInputAction: TextInputAction.next, + onChange: (value) { + payload["otherRootCause"] = value; + }, + ), + ], 8.height, - AppTextFormField( - labelText: "Manufacturer", + SingleItemDropDownMenu( + context: context, + height: 56.toScreenHeight, + title: "Person Involved", + initialValue: involvedPerson, + showShadow: false, validator: (value) { - if ((value ?? "").isEmpty) return "Mandatory"; + if (value == null) return "Mandatory"; return null; }, - style: Theme.of(context).textTheme.titleMedium, backgroundColor: AppColor.fieldBgColor(context), - labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), - floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), - showShadow: false, - textInputType: TextInputType.text, - textInputAction: TextInputAction.next, - onChange: (value) { - // _demoFormModel.manufacturer = value; + showAsBottomSheet: true, + onSelect: (value) { + involvedPerson = value; + payload["personInvolvedId"] = value?.id; }, ), - // 8.height, - // SingleItemDropDownMenu( - // context: context, - // height: 56.toScreenHeight, - // title: "Demo Period", - // initialValue: demoPeriodLookup, - // showShadow: false, - // validator: (value) { - // if (value == null) return "Mandatory"; - // return null; - // }, - // backgroundColor: AppColor.fieldBgColor(context), - // showAsBottomSheet: true, - // onSelect: (value) { - // demoPeriodLookup = value; - // setState(() {}); - // }, - // ), - ]; - } - - List vendorDetailsSection() { - return [ - 'Vendor Details'.addTranslation.bodyText(context).custom(color: AppColor.black10), 8.height, - AppTextFormField( - initialValue: "", - labelText: "Incident Title", + SingleItemDropDownMenu( + context: context, + height: 56.toScreenHeight, + title: "Gender", + initialValue: gender, + showShadow: false, validator: (value) { - if ((value ?? "").isEmpty) return "Mandatory"; + if (value == null) return "Mandatory"; return null; }, - style: Theme.of(context).textTheme.titleMedium, backgroundColor: AppColor.fieldBgColor(context), - labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), - showShadow: false, - textInputType: TextInputType.name, - textInputAction: TextInputAction.next, - onChange: (value) { - // _demoFormModel.vendorName = value; + showAsBottomSheet: true, + onSelect: (value) { + gender = value; + payload["genderId"] = value?.id; }, ), 8.height, AppTextFormField( initialValue: "", - labelText: "Incident Description", + labelText: "Person Involved ID", validator: (value) { - if ((value ?? "").isEmpty) return "Mandatory"; + if (involvedPerson?.value == 3 && (value ?? "").isEmpty) return "Mandatory"; return null; }, style: Theme.of(context).textTheme.titleMedium, backgroundColor: AppColor.fieldBgColor(context), labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), showShadow: false, - textInputType: TextInputType.name, + textInputType: TextInputType.number, textInputAction: TextInputAction.next, onChange: (value) { - // _demoFormModel.vendorRepresentativeName = value; + payload["personInvolvedEmployeeId"] = value; }, ), 8.height, AppTextFormField( initialValue: "", - labelText: "Contact Number", + labelText: "Person Involved Name", validator: (value) { - if ((value ?? "").isEmpty) return "Mandatory"; + if (involvedPerson?.value == 3 && (value ?? "").isEmpty) return "Mandatory"; return null; }, style: Theme.of(context).textTheme.titleMedium, backgroundColor: AppColor.fieldBgColor(context), labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), showShadow: false, - textInputType: TextInputType.phone, + textInputType: TextInputType.name, textInputAction: TextInputAction.next, onChange: (value) { - // _demoFormModel.vendorNumber = value; + payload["personInvolvedEmployeeName"] = value; }, ), 8.height, - AppTextFormField( - initialValue: "", - labelText: "Email", - validator: (value) { - if ((value ?? "").isEmpty) { - return "Mandatory"; - } else { - return Validator.isEmail(value!) ? null : context.translation.emailValidateMessage; - } - }, - style: Theme.of(context).textTheme.titleMedium, - backgroundColor: AppColor.fieldBgColor(context), - labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)), - showShadow: false, - textInputType: TextInputType.emailAddress, - textInputAction: TextInputAction.next, - onChange: (value) { - // _demoFormModel.vendorEmail = value; + ADatePicker( + label: "Occurrence Date & Time", + hideShadow: true, + backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral90, + date: occurrenceDate, + from: DateTime.now().subtract(const Duration(days: 365)), + // enable: widget.enabled ? _tempPickerTimer == null : false, + formatDateWithTime: true, + onDatePicker: (selectedDate) { + showTimePicker( + context: context, + initialTime: TimeOfDay.now(), + builder: (BuildContext context, Widget? child) { + final ThemeData currentTheme = Theme.of(context); + return Theme( + data: currentTheme.copyWith( + timePickerTheme: TimePickerThemeData( + dialHandColor: AppColor.primary10, + dialBackgroundColor: Colors.grey.withOpacity(0.1), + hourMinuteColor: MaterialStateColor.resolveWith((states) => states.contains(MaterialState.selected) ? AppColor.primary10 : Colors.grey.withOpacity(0.1)), + dayPeriodColor: MaterialStateColor.resolveWith((states) => states.contains(MaterialState.selected) ? AppColor.primary10 : Colors.transparent), + dayPeriodTextColor: MaterialStateColor.resolveWith((states) => states.contains(MaterialState.selected) ? Colors.white : AppColor.primary10), + dayPeriodBorderSide: BorderSide(color: Colors.grey.withOpacity(0.2)), + entryModeIconColor: AppColor.primary10, + ), + textButtonTheme: TextButtonThemeData(style: TextButton.styleFrom(foregroundColor: AppColor.primary10)), + ), + child: child!, + ); + }, + ).then((selectedTime) { + if (selectedTime != null) { + occurrenceDate = DateTime(selectedDate.year, selectedDate.month, selectedDate.day, selectedTime.hour, selectedTime.minute); + setState(() {}); + } + }); }, ), ]; @@ -548,25 +567,32 @@ class _CreateIncidentRequestPageState extends State { Future _submit() async { FocusScope.of(context).unfocus(); if (_formKey.currentState!.validate()) { + if (occurrenceDate == null) { + "Please select occurrence Data".showToast; + return; + } + + payload["occurrenceDate"] = occurrenceDate!.toIso8601String(); _formKey.currentState!.save(); - // _demoFormModel.demoAttachment = []; - // for (var item in attachments) { - // String fileName = CMRequestUtils.isLocalUrl(item.name ?? '') ? ("${item.name ?? ''.split("/").last}|${base64Encode(File(item.name ?? '').readAsBytesSync())}") : item.name ?? ''; - // _demoFormModel.demoAttachment?.add(DemoAttachments(id: 0, attachmentName: fileName, demoRequestId: 0)); - // } - // Utils.showLoading(context); - // LoanProvider loanProvider = Provider.of(context, listen: false); - // Map body = _demoFormModel.toJson(); - // body["id"] = 0; - // // body["LoanTypeId"] = 0; - // // body["requestorUserID"] = context.userProvider.user!.userID; - // - // bool isSuccess = await loanProvider.addLoanRequest(body); - // Utils.hideLoading(context); - // if (isSuccess) { - // Navigator.pop(context); - // } + List attachmentList = []; + + for (var item in attachments) { + String fileName = CMRequestUtils.isLocalUrl(item.name ?? '') ? ("${item.name ?? ''.split("/").last}|${base64Encode(File(item.name ?? '').readAsBytesSync())}") : item.name ?? ''; + attachmentList.add(IncidentAttachments(id: 0, attachmentName: fileName, incidentId: 0)); + } + 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); + if (isSuccess) { + Navigator.pop(context); + } } } } diff --git a/lib/modules/incident_module/incident_attachment_model.dart b/lib/modules/incident_module/incident_attachment_model.dart new file mode 100644 index 00000000..bf1eabc9 --- /dev/null +++ b/lib/modules/incident_module/incident_attachment_model.dart @@ -0,0 +1,24 @@ +class IncidentAttachments { + num? id; + num? incidentId; + String? attachmentName; + String? attachmentDescription; + + IncidentAttachments({this.id, this.attachmentName, this.incidentId, this.attachmentDescription}); + + IncidentAttachments.fromJson(dynamic json) { + id = json['id']; + incidentId = json['incidentId']; + attachmentName = json['attachmentName']; + attachmentDescription = json['attachmentDescription']; + } + + Map toJson() { + final map = {}; + map['id'] = id; + map['attachmentName'] = attachmentName; + map['incidentId'] = incidentId; + map['attachmentDescription'] = attachmentDescription; + return map; + } +} diff --git a/lib/modules/incident_module/incident_provider.dart b/lib/modules/incident_module/incident_provider.dart new file mode 100644 index 00000000..c4f24389 --- /dev/null +++ b/lib/modules/incident_module/incident_provider.dart @@ -0,0 +1,38 @@ +import 'package:flutter/cupertino.dart'; +import 'package:fluttertoast/fluttertoast.dart'; +import 'package:http/http.dart'; +import 'package:test_sa/controllers/api_routes/api_manager.dart'; +import 'package:test_sa/controllers/api_routes/urls.dart'; +import 'package:test_sa/modules/loan_module/models/loan_request_model.dart'; +import 'dart:convert'; + +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"] ?? ""); + Fluttertoast.showToast(msg: message ?? "", toastLength: Toast.LENGTH_LONG); + return true; + } + return false; + } catch (error) { + return false; + } + } + + bool isLoading = false; + + Future getIncidentById(int id) async { + LoanRequestModel? 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"]); + } + } catch (error) { + print(error); + } + return loanData; + } +} diff --git a/lib/modules/loan_module/provider/loan_provider.dart b/lib/modules/loan_module/provider/loan_provider.dart index b2a3a5e3..deccfe79 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)["data"] ?? "") + " " + (jsonDecode(response.body)["message"] ?? ""); + String message = (jsonDecode(response.body)["message"] ?? ""); Fluttertoast.showToast(msg: message ?? "", toastLength: Toast.LENGTH_LONG); return true; }