|
|
|
|
@ -1,116 +1,85 @@
|
|
|
|
|
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/common_widgets/autocomplete_generic_field.dart';
|
|
|
|
|
import 'package:test_sa/controllers/api_routes/urls.dart';
|
|
|
|
|
import 'package:test_sa/controllers/providers/api/device_transfer_provider.dart';
|
|
|
|
|
import 'package:test_sa/dashboard_latest/dashboard_provider.dart';
|
|
|
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
|
|
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
|
|
|
import 'package:test_sa/extensions/string_extensions.dart';
|
|
|
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
|
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
|
import 'package:test_sa/models/device/asset.dart';
|
|
|
|
|
import 'package:test_sa/models/device/asset_transfer_attachment.dart';
|
|
|
|
|
import 'package:test_sa/models/device/device_transfer.dart';
|
|
|
|
|
import 'package:test_sa/models/enums/user_types.dart';
|
|
|
|
|
import 'package:test_sa/models/generic_attachment_model.dart';
|
|
|
|
|
import 'package:test_sa/models/new_models/department.dart';
|
|
|
|
|
import 'package:test_sa/models/new_models/floor.dart';
|
|
|
|
|
import 'package:test_sa/models/service_request/pending_service_request_model.dart';
|
|
|
|
|
import 'package:test_sa/models/service_request/spare_parts.dart';
|
|
|
|
|
import 'package:test_sa/models/service_request/supplier_details.dart';
|
|
|
|
|
import 'package:test_sa/modules/cm_module/utilities/service_request_utils.dart';
|
|
|
|
|
import 'package:test_sa/modules/asset_inventory_module/models/asset_inventory_model.dart';
|
|
|
|
|
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart';
|
|
|
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
|
|
|
import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart';
|
|
|
|
|
import 'package:test_sa/providers/ppm_service_provider.dart';
|
|
|
|
|
import 'package:test_sa/providers/work_order/vendor_provider.dart';
|
|
|
|
|
import 'package:test_sa/views/pages/user/requests/pending_requests_screen.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/equipment/asset_picker.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/images/files_list.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/parts/auto_complete_parts_field.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/requests/request_status.dart';
|
|
|
|
|
|
|
|
|
|
import '../../../models/new_models/building.dart';
|
|
|
|
|
import '../../../models/new_models/site.dart';
|
|
|
|
|
import '../../../new_views/common_widgets/app_filled_button.dart';
|
|
|
|
|
import '../../../new_views/common_widgets/default_app_bar.dart';
|
|
|
|
|
import '../../../new_views/common_widgets/single_item_drop_down_menu.dart';
|
|
|
|
|
import '../../../providers/gas_request_providers/site_provider.dart';
|
|
|
|
|
import '../../../providers/loading_list_notifier.dart';
|
|
|
|
|
|
|
|
|
|
class AssetInventoryFormView extends StatefulWidget {
|
|
|
|
|
static const String id = "/request-device-transfer";
|
|
|
|
|
static const String id = "/asset-inventory-form";
|
|
|
|
|
// TODO need to use only one model AssetInventoryModel everywhere after completing flow .
|
|
|
|
|
Asset ? assetLocation;
|
|
|
|
|
|
|
|
|
|
const AssetInventoryFormView({Key? key}) : super(key: key);
|
|
|
|
|
AssetInventoryFormView({Key? key,this.assetLocation}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<AssetInventoryFormView> createState() => _AssetInventoryFormViewState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _AssetInventoryFormViewState extends State<AssetInventoryFormView> {
|
|
|
|
|
//TODO Need to replace with provider and models we have ...
|
|
|
|
|
late DeviceTransferProvider _deviceTransferProvider;
|
|
|
|
|
final DeviceTransfer _transferModel = DeviceTransfer(id: 0);
|
|
|
|
|
final AssetInventoryModel _assetInventoryModel = AssetInventoryModel();
|
|
|
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
|
|
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
|
|
|
|
Asset _assetDestination = Asset();
|
|
|
|
|
Asset? _pickedAsset;
|
|
|
|
|
|
|
|
|
|
final List<GenericAttachmentModel> attachments = [];
|
|
|
|
|
|
|
|
|
|
void _onSubmit() async {
|
|
|
|
|
_transferModel.assetId = _pickedAsset?.id;
|
|
|
|
|
_transferModel.destSiteId = _assetDestination.site?.id;
|
|
|
|
|
_transferModel.destBuildingId = _assetDestination.building?.id;
|
|
|
|
|
_transferModel.destFloorId = _assetDestination.floor?.id;
|
|
|
|
|
_transferModel.destDepartmentId = _assetDestination.department?.id;
|
|
|
|
|
_transferModel.destRoomId = _assetDestination.room?.id;
|
|
|
|
|
_assetInventoryModel.assetId = _pickedAsset?.id;
|
|
|
|
|
_assetInventoryModel.oldSiteId = widget.assetLocation?.site?.id;
|
|
|
|
|
_assetInventoryModel.oldBuildingId = widget.assetLocation?.building?.id;
|
|
|
|
|
_assetInventoryModel.oldFloorId = widget.assetLocation?.floor?.id;
|
|
|
|
|
_assetInventoryModel.oldDepartmentId = widget.assetLocation?.department?.id;
|
|
|
|
|
_assetInventoryModel.oldRoomId = widget.assetLocation?.room?.id;
|
|
|
|
|
|
|
|
|
|
if (!_formKey.currentState!.validate() || !(await validateRequest())) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_formKey.currentState!.save();
|
|
|
|
|
List<AssetTransferAttachment> attachement = [];
|
|
|
|
|
for (var item in attachments) {
|
|
|
|
|
String fileName = ServiceRequestUtils.isLocalUrl(item.name ?? '') ? ("${item.name ?? ''.split("/").last}|${base64Encode(File(item.name ?? '').readAsBytesSync())}") : item.name ?? '';
|
|
|
|
|
attachement.add(AssetTransferAttachment(id: item.id, attachmentName: fileName));
|
|
|
|
|
}
|
|
|
|
|
_transferModel.attachments = attachement;
|
|
|
|
|
|
|
|
|
|
await _deviceTransferProvider.createRequest(
|
|
|
|
|
context: context,
|
|
|
|
|
model: _transferModel,
|
|
|
|
|
);
|
|
|
|
|
if (_deviceTransferProvider.stateCode == 200) {
|
|
|
|
|
DashBoardProvider dashBoardProvider = Provider.of<DashBoardProvider>(context, listen: false);
|
|
|
|
|
dashBoardProvider.refreshDashboard(context: context, userType: UsersTypes.nurse);
|
|
|
|
|
}
|
|
|
|
|
//TODO need to confirm attachment structure and final api calling .
|
|
|
|
|
// List<AssetTransferAttachment> attachement = [];
|
|
|
|
|
// for (var item in attachments) {
|
|
|
|
|
// String fileName = ServiceRequestUtils.isLocalUrl(item.name ?? '') ? ("${item.name ?? ''.split("/").last}|${base64Encode(File(item.name ?? '').readAsBytesSync())}") : item.name ?? '';
|
|
|
|
|
// attachement.add(AssetTransferAttachment(id: item.id, attachmentName: fileName));
|
|
|
|
|
// }
|
|
|
|
|
// _assetInventoryModel.attachments = attachement;
|
|
|
|
|
// await _deviceTransferProvider.createRequest(
|
|
|
|
|
// context: context,
|
|
|
|
|
// model: _transferModel,
|
|
|
|
|
// );
|
|
|
|
|
// if (_deviceTransferProvider.stateCode == 200) {
|
|
|
|
|
// DashBoardProvider dashBoardProvider = Provider.of<DashBoardProvider>(context, listen: false);
|
|
|
|
|
// dashBoardProvider.refreshDashboard(context: context, userType: UsersTypes.nurse);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
|
|
|
//need to get internal and external request type data..
|
|
|
|
|
await Provider.of<PpmServiceProvider>(context, listen: false).getData();
|
|
|
|
|
});
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_deviceTransferProvider.reset();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
_deviceTransferProvider = Provider.of<DeviceTransferProvider>(context, listen: false);
|
|
|
|
|
return Scaffold(
|
|
|
|
|
key: _scaffoldKey,
|
|
|
|
|
appBar: DefaultAppBar(
|
|
|
|
|
@ -136,18 +105,19 @@ class _AssetInventoryFormViewState extends State<AssetInventoryFormView> {
|
|
|
|
|
showBorder: true,
|
|
|
|
|
onPick: (asset) async {
|
|
|
|
|
_pickedAsset = asset;
|
|
|
|
|
if (_pickedAsset?.site != null && _transferModel.transferType?.value == 1) {
|
|
|
|
|
await _deviceTransferProvider.getSiteData(siteId: int.tryParse(_pickedAsset!.site!.id.toString()));
|
|
|
|
|
_assetDestination.site = _deviceTransferProvider.internalAssetDestination?.site;
|
|
|
|
|
_assetDestination.building = null;
|
|
|
|
|
_assetDestination.floor = null;
|
|
|
|
|
_assetDestination.department = null;
|
|
|
|
|
} else if (_pickedAsset?.site != null && _transferModel.transferType?.value == 2) {
|
|
|
|
|
_assetDestination.site = null;
|
|
|
|
|
_assetDestination.building = null;
|
|
|
|
|
_assetDestination.floor = null;
|
|
|
|
|
_assetDestination.department = null;
|
|
|
|
|
}
|
|
|
|
|
//TODO set value to model .
|
|
|
|
|
// if (_pickedAsset?.site != null && _transferModel.transferType?.value == 1) {
|
|
|
|
|
// await _deviceTransferProvider.getSiteData(siteId: int.tryParse(_pickedAsset!.site!.id.toString()));
|
|
|
|
|
// _assetDestination.site = _deviceTransferProvider.internalAssetDestination?.site;
|
|
|
|
|
// _assetDestination.building = null;
|
|
|
|
|
// _assetDestination.floor = null;
|
|
|
|
|
// _assetDestination.department = null;
|
|
|
|
|
// } else if (_pickedAsset?.site != null && _transferModel.transferType?.value == 2) {
|
|
|
|
|
// _assetDestination.site = null;
|
|
|
|
|
// _assetDestination.building = null;
|
|
|
|
|
// _assetDestination.floor = null;
|
|
|
|
|
// _assetDestination.department = null;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
setState(() {});
|
|
|
|
|
}),
|
|
|
|
|
@ -170,9 +140,6 @@ class _AssetInventoryFormViewState extends State<AssetInventoryFormView> {
|
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
|
),
|
|
|
|
|
12.height,
|
|
|
|
|
//TODO need to indentify where to
|
|
|
|
|
12.height,
|
|
|
|
|
//model..
|
|
|
|
|
AutoCompleteGenericField<SparePartsWorkOrders>(
|
|
|
|
|
clearAfterPick: false,
|
|
|
|
|
label: 'Asset Name'.addTranslation,
|
|
|
|
|
@ -256,75 +223,16 @@ class _AssetInventoryFormViewState extends State<AssetInventoryFormView> {
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
12.height,
|
|
|
|
|
SingleItemDropDownMenu<Site, SiteProvider>(
|
|
|
|
|
context: context,
|
|
|
|
|
title: context.translation.site,
|
|
|
|
|
initialValue: _assetDestination.site,
|
|
|
|
|
disableValue: _pickedAsset?.site,
|
|
|
|
|
showShadow: false,
|
|
|
|
|
loading: _deviceTransferProvider.isSiteLoading,
|
|
|
|
|
enabled: false,
|
|
|
|
|
backgroundColor: AppColor.fieldBgColor(context),
|
|
|
|
|
showAsBottomSheet: true,
|
|
|
|
|
onSelect: (value) {
|
|
|
|
|
_assetDestination.site = value;
|
|
|
|
|
_assetDestination.building = null;
|
|
|
|
|
_assetDestination.floor = null;
|
|
|
|
|
_assetDestination.department = null;
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
siteInfoContainer(label: context.translation.site, value:widget.assetLocation?.site?.name??'-' ),
|
|
|
|
|
12.height,
|
|
|
|
|
SingleItemDropDownMenu<Building, NullableLoadingProvider>(
|
|
|
|
|
context: context,
|
|
|
|
|
title: context.translation.building,
|
|
|
|
|
initialValue: _assetDestination.building,
|
|
|
|
|
showShadow: false,
|
|
|
|
|
showAsBottomSheet: true,
|
|
|
|
|
backgroundColor: AppColor.fieldBgColor(context),
|
|
|
|
|
enabled: _assetDestination.site?.buildings?.isNotEmpty ?? false,
|
|
|
|
|
staticData: _assetDestination.site?.buildings ?? [],
|
|
|
|
|
onSelect: (value) {
|
|
|
|
|
_assetDestination.building = value;
|
|
|
|
|
_assetDestination.floor = null;
|
|
|
|
|
_assetDestination.department = null;
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
siteInfoContainer(label: context.translation.building, value:widget.assetLocation?.building?.name??'-' ),
|
|
|
|
|
12.height,
|
|
|
|
|
SingleItemDropDownMenu<Floor, NullableLoadingProvider>(
|
|
|
|
|
context: context,
|
|
|
|
|
title: context.translation.floor,
|
|
|
|
|
showShadow: false,
|
|
|
|
|
showAsBottomSheet: true,
|
|
|
|
|
initialValue: _assetDestination.floor,
|
|
|
|
|
backgroundColor: AppColor.fieldBgColor(context),
|
|
|
|
|
enabled: _assetDestination.building?.floors?.isNotEmpty ?? false,
|
|
|
|
|
staticData: _assetDestination.building?.floors ?? [],
|
|
|
|
|
onSelect: (value) {
|
|
|
|
|
_assetDestination.floor = value;
|
|
|
|
|
_assetDestination.department = null;
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
siteInfoContainer(label: context.translation.floor, value:widget.assetLocation?.floor?.name??'-' ),
|
|
|
|
|
12.height,
|
|
|
|
|
SingleItemDropDownMenu<Department, NullableLoadingProvider>(
|
|
|
|
|
context: context,
|
|
|
|
|
title: context.translation.department,
|
|
|
|
|
showShadow: false,
|
|
|
|
|
showAsBottomSheet: true,
|
|
|
|
|
initialValue: _assetDestination.department,
|
|
|
|
|
backgroundColor: AppColor.fieldBgColor(context),
|
|
|
|
|
enabled: _assetDestination.floor?.departments?.isNotEmpty ?? false,
|
|
|
|
|
staticData: _assetDestination.floor?.departments ?? [],
|
|
|
|
|
onSelect: (value) {
|
|
|
|
|
_assetDestination.department = value;
|
|
|
|
|
_assetDestination.room = null;
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
siteInfoContainer(label: context.translation.department, value:widget.assetLocation?.department?.name??'-' ),
|
|
|
|
|
12.height,
|
|
|
|
|
siteInfoContainer(label: context.translation.room, value:widget.assetLocation?.room?.name??'-' ),
|
|
|
|
|
12.height,
|
|
|
|
|
classificationWidget(label: 'Found'),
|
|
|
|
|
12.height,
|
|
|
|
|
@ -362,7 +270,7 @@ class _AssetInventoryFormViewState extends State<AssetInventoryFormView> {
|
|
|
|
|
textInputType: TextInputType.multiline,
|
|
|
|
|
showShadow: false,
|
|
|
|
|
onSaved: (text) {
|
|
|
|
|
_transferModel.comment = text;
|
|
|
|
|
_assetInventoryModel.remarks = text;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
// 100.height,
|
|
|
|
|
@ -380,6 +288,26 @@ class _AssetInventoryFormViewState extends State<AssetInventoryFormView> {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Widget siteInfoContainer({required String label , required String value}){
|
|
|
|
|
//TODO may be need to hide value for if empty or null .
|
|
|
|
|
return Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 12.toScreenWidth,vertical: 12.toScreenHeight),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: AppColor.neutral80,
|
|
|
|
|
borderRadius: BorderRadius.circular(8)
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(label,style: Theme.of(context).textTheme.bodySmall?.copyWith(color: context.isDark ? null : AppColor.neutral20, fontWeight: FontWeight.w500)),
|
|
|
|
|
Text(value,style:Theme.of(context).textTheme.bodyLarge,),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget classificationWidget({String? label}) {
|
|
|
|
|
return Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
@ -404,22 +332,22 @@ class _AssetInventoryFormViewState extends State<AssetInventoryFormView> {
|
|
|
|
|
await Fluttertoast.showToast(msg: "Please Select Asset");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (_assetDestination.site == null) {
|
|
|
|
|
await Fluttertoast.showToast(msg: "Please Select Site");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (_assetDestination.building == null) {
|
|
|
|
|
await Fluttertoast.showToast(msg: "Please Select Building");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (_assetDestination.floor == null) {
|
|
|
|
|
await Fluttertoast.showToast(msg: "Please Select Floor");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (_assetDestination.department == null) {
|
|
|
|
|
await Fluttertoast.showToast(msg: "Please Select Department");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// if (_assetDestination.site == null) {
|
|
|
|
|
// await Fluttertoast.showToast(msg: "Please Select Site");
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// if (_assetDestination.building == null) {
|
|
|
|
|
// await Fluttertoast.showToast(msg: "Please Select Building");
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// if (_assetDestination.floor == null) {
|
|
|
|
|
// await Fluttertoast.showToast(msg: "Please Select Floor");
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// if (_assetDestination.department == null) {
|
|
|
|
|
// await Fluttertoast.showToast(msg: "Please Select Department");
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|