From dd644732c906c32690bd2b95736cb8af13d59d0e Mon Sep 17 00:00:00 2001 From: WaseemAbbasi22 <50428976+WaseemAbbasi22@users.noreply.github.com> Date: Wed, 26 Aug 2026 10:46:51 +0300 Subject: [PATCH] bug fixes --- lib/models/generic_attachment_model.dart | 33 +++++++-------- .../pages/attachment_view.dart | 5 +-- .../models/asset_inventory_model.dart | 4 +- .../models/session_model.dart | 2 - .../pages/asset_inventory_form_view.dart | 14 ++++--- .../pages/create_loan_request_page.dart | 2 +- .../ppm_wo/update_ppm/wo_info_form.dart | 6 +++ .../widgets/images/multi_image_picker.dart | 42 +++++++++++-------- 8 files changed, 58 insertions(+), 50 deletions(-) diff --git a/lib/models/generic_attachment_model.dart b/lib/models/generic_attachment_model.dart index 684c3c61..41749f68 100644 --- a/lib/models/generic_attachment_model.dart +++ b/lib/models/generic_attachment_model.dart @@ -117,7 +117,7 @@ class GenericAttachmentModel { id = json['id']; name = json['attachmentName']; moduleReferenceId = json['gasRefillId']; - documentType = json['attachmentType'] != null ? Lookup.fromJson(json['attachmentType']) : null; + documentType = json['documentType'] != null ? Lookup.fromJson(json['documentType']) : null; } GenericAttachmentModel.fromIncidentJson(Map json) { @@ -199,8 +199,8 @@ class GenericAttachmentModel { data['id'] = id; data['attachmentName'] = name; data['loanId'] = moduleReferenceId; - data['loanAttachmentTypeId'] = attachmentTypeId; - data['documentTypeId'] = documentType?.id; + data['loanAttachmentTypeId'] = documentType?.id; + // data['documentTypeId'] = documentType?.id; data['attachmentDescription'] = attachmentDescription; return data; } @@ -221,16 +221,6 @@ class GenericAttachmentModel { return data; } -//TODO need to check where to use this need to verify with backend team. - Map toPpmJson() { - final Map data = {}; - data['id'] = id; - data['visitId'] = moduleReferenceId; - data['attachmentName'] = name; - data['documentTypeId'] = documentType?.id; - data['attachmentURL'] = attachmentURL; - return data; - } Map toGasRefillJson() { final Map data = {}; @@ -246,7 +236,7 @@ class GenericAttachmentModel { data['id'] = id; data['attachmentName'] = name; data['incidentId'] = moduleReferenceId; - data['documentTypeId'] = documentType?.id; + data['attachmentTypeId'] = documentType?.id; data['attachmentDescription'] = attachmentDescription; return data; } @@ -255,7 +245,7 @@ class GenericAttachmentModel { final Map data = {}; data['id'] = id; data['attachmentName'] = name; - data['documentTypeId'] = documentType?.id; + data['attachmentTypeId'] = documentType?.id; return data; } @@ -276,7 +266,7 @@ class GenericAttachmentModel { data['id'] = id; data['name'] = name; data['originalName'] = originalName; - data['documentTypeId'] = documentType?.id; + data['attachmentTypeId'] = documentType?.id; return data; } @@ -284,7 +274,7 @@ class GenericAttachmentModel { final Map data = {}; data['id'] = id; data['attachmentName'] = name; - data['documentTypeId'] = documentType?.id; + data['attachmentTypeId'] = documentType?.id; return data; } @@ -297,6 +287,15 @@ class GenericAttachmentModel { data['originalName'] = originalName; return data; } + Map toInventoryJson() { + final Map data = {}; + data['id'] = id; + data['attachmentName'] = name; + data['attachmentURL'] = attachmentURL; + data['attachmentTypeId'] = documentType?.id; + data['originalName'] = originalName; + return data; + } Map toTrafJson() { final Map data = {}; diff --git a/lib/modules/asset_delivery_module/pages/attachment_view.dart b/lib/modules/asset_delivery_module/pages/attachment_view.dart index 70f3a956..6d699a62 100644 --- a/lib/modules/asset_delivery_module/pages/attachment_view.dart +++ b/lib/modules/asset_delivery_module/pages/attachment_view.dart @@ -76,9 +76,7 @@ class _AssetDeliveryAttachmentViewState extends State v?.toAssetJson() ?? {}).toList() - : [], + 'assetInventoryDetailAssetAttachments': assetInventoryDetailAssetAttachments.map((v) => v.toInventoryJson() ?? {}).toList(), }; } diff --git a/lib/modules/asset_inventory_module/models/session_model.dart b/lib/modules/asset_inventory_module/models/session_model.dart index 8de8503b..ba18ab36 100644 --- a/lib/modules/asset_inventory_module/models/session_model.dart +++ b/lib/modules/asset_inventory_module/models/session_model.dart @@ -43,11 +43,9 @@ class SessionModel { statusName = json['statusName']; startDate = json['startDate']; endDate = json['endDate']; - if (json['assetInventorySites'] != null) { assetInventorySites = (json['assetInventorySites'] as List).map((e) => Site.fromJson(e)).toList(); } - if (json['assetInventoryAssignedEmployee'] != null) { assetInventoryAssignedEmployee = (json['assetInventoryAssignedEmployee'] as List).map((e) => AssetInventoryAssignedEmployee.fromJson(e)).toList(); } diff --git a/lib/modules/asset_inventory_module/pages/asset_inventory_form_view.dart b/lib/modules/asset_inventory_module/pages/asset_inventory_form_view.dart index 2fe422b4..48f5fcb0 100644 --- a/lib/modules/asset_inventory_module/pages/asset_inventory_form_view.dart +++ b/lib/modules/asset_inventory_module/pages/asset_inventory_form_view.dart @@ -24,6 +24,7 @@ import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart'; import 'package:test_sa/views/widgets/equipment/asset_picker.dart'; import 'package:test_sa/views/widgets/images/multi_image_picker.dart'; import 'package:test_sa/views/widgets/images/multi_image_picker_item.dart'; +import 'package:test_sa/views/widgets/item_views/info_header_widget.dart'; import 'package:test_sa/views/widgets/requests/request_status.dart'; import '../../../new_views/common_widgets/app_filled_button.dart'; import '../../../new_views/common_widgets/default_app_bar.dart'; @@ -295,11 +296,12 @@ class _AssetInventoryFormViewState extends State { classificationWidget(label: _scannedAssetModel?.status), ], 12.height, - Text( - 'Attachments'.addTranslation, - style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.white936), - ), - + InfoHeader16Widget('Attachments'.addTranslation), + // Text( + // 'Attachments'.addTranslation, + // style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.white936), + // ), + 8.height, AttachmentPicker( moduleId: RequestAttachmentTypeEnum.assetInventory.id, label: context.translation.attachFiles, @@ -409,7 +411,7 @@ class _AssetInventoryFormViewState extends State { // try { for (var item in attachments) { String fileName = CMRequestUtils.isLocalUrl(item.name ?? '') ? ("${item.name ?? ''.split("/").last}|${base64Encode(File(item.name ?? '').readAsBytesSync())}") : item.name ?? ''; - _scannedAssetModel?.assetInventoryDetailAssetAttachments.add(GenericAttachmentModel(id: item.id, name: fileName,documentType: item.documentType)); + _scannedAssetModel?.assetInventoryDetailAssetAttachments.add(GenericAttachmentModel(id: item.id, name: fileName, documentType: item.documentType)); } // // } catch (error) { // // print(error); diff --git a/lib/modules/loan_module/pages/create_loan_request_page.dart b/lib/modules/loan_module/pages/create_loan_request_page.dart index 2b40032b..6e03259f 100644 --- a/lib/modules/loan_module/pages/create_loan_request_page.dart +++ b/lib/modules/loan_module/pages/create_loan_request_page.dart @@ -629,7 +629,7 @@ class _CreateLoanRequestPageState extends State with Tick _loanFormModel.loanAttachment = []; for (var item in attachments) { String fileName = CMRequestUtils.isLocalUrl(item.name ?? '') ? ("${item.name ?? ''.split("/").last}|${base64Encode(File(item.name ?? '').readAsBytesSync())}") : item.name ?? ''; - _loanFormModel.loanAttachment?.add(GenericAttachmentModel(id: 0, name: fileName, moduleReferenceId: 0)); + _loanFormModel.loanAttachment?.add(GenericAttachmentModel(id: 0, name: fileName, moduleReferenceId: 0,documentType: item.documentType)); } Utils.showLoading(context); LoanProvider loanProvider = Provider.of(context, listen: false); diff --git a/lib/modules/pm_module/ppm_wo/update_ppm/wo_info_form.dart b/lib/modules/pm_module/ppm_wo/update_ppm/wo_info_form.dart index 122f13ca..e5d8ec05 100644 --- a/lib/modules/pm_module/ppm_wo/update_ppm/wo_info_form.dart +++ b/lib/modules/pm_module/ppm_wo/update_ppm/wo_info_form.dart @@ -1,3 +1,4 @@ +import 'dart:developer'; import 'dart:io'; import 'package:flutter/material.dart'; @@ -99,10 +100,15 @@ class _WoInfoFormState extends State { @override Widget build(BuildContext context) { + + // double totalWorkingHours = // widget.planPreventiveVisit.preventiveVisitTimers?.fold(0.0, (sum, item) => (sum ?? 0) + DateTime.parse(item.endDateTime!).difference(DateTime.parse(item.startDateTime!)).inSeconds) ?? 0; return Consumer(builder: (context, ppmProvider, child) { + ppmProvider.ppmPlanAttachments.forEach((e){ + log('attachemnt type ${e.documentType}'); + }); return ListView( padding: const EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 16), children: [ diff --git a/lib/views/widgets/images/multi_image_picker.dart b/lib/views/widgets/images/multi_image_picker.dart index 210dc816..2099b165 100644 --- a/lib/views/widgets/images/multi_image_picker.dart +++ b/lib/views/widgets/images/multi_image_picker.dart @@ -45,6 +45,7 @@ class AttachmentPicker extends StatefulWidget { final String pickerTitle; final String label; final bool error; + final bool showTypeDropdown; final int moduleId; final List attachment; final bool enabled, onlyImages; @@ -75,6 +76,7 @@ class AttachmentPicker extends StatefulWidget { // this.showAsListView = false, this.pickMultiple = false, this.checkQuality = false, + this.showTypeDropdown = true, this.child, this.buttonColor}) : super(key: key); @@ -227,7 +229,8 @@ class _AttachmentPickerState extends State with SingleTickerPr return StatefulBuilder( builder: (BuildContext context, StateSetter setModalState) { Widget listCard({required String icon, required String label, required VoidCallback onTap}) { - bool isEnabled = documentLookup != null; + + bool isEnabled = !widget.showTypeDropdown?true:documentLookup != null; return Container( padding: const EdgeInsets.all(12), decoration: BoxDecoration( @@ -302,24 +305,27 @@ class _AttachmentPickerState extends State with SingleTickerPr 8.height, InfoHeader16Widget(widget.pickerTitle), 8.height, - SingleItemDropDownMenu( - context: context, - height: 56.toScreenHeight, - requestById: widget.moduleId, - title: "Document Type", - initialValue: documentLookup, - showShadow: false, - backgroundColor: AppColor.fieldBgColor(context), - showAsBottomSheet: true, - onSelect: (value) { - documentLookup = value; - setModalState(() {}); - }, - ), - if (documentLookup == null) ...[ - 4.height, - const InfoTextLabelWidget(label: 'Please Select Document Type before picking file', color: AppColor.red30), + if(widget.showTypeDropdown)...[ + SingleItemDropDownMenu( + context: context, + height: 56.toScreenHeight, + requestById: widget.moduleId, + title: "Document Type", + initialValue: documentLookup, + showShadow: false, + backgroundColor: AppColor.fieldBgColor(context), + showAsBottomSheet: true, + onSelect: (value) { + documentLookup = value; + setModalState(() {}); + }, + ), + if (documentLookup == null) ...[ + 4.height, + const InfoTextLabelWidget(label: 'Please Select Document Type before picking file', color: AppColor.red30), + ], ], + GridView.builder( padding: const EdgeInsets.only(top: 16, bottom: 0), shrinkWrap: true,