diff --git a/lib/controllers/api_routes/urls.dart b/lib/controllers/api_routes/urls.dart index 6e2115c2..f0b83404 100644 --- a/lib/controllers/api_routes/urls.dart +++ b/lib/controllers/api_routes/urls.dart @@ -320,4 +320,6 @@ class URLs { static get getAssetsTemp => '$_baseUrl/AssetInventory/GetAssetsTemp'; static get convertDetailToComplete => '$_baseUrl/AssetInventory/ConvertDetailToComplete'; + + static get getClassification => '$_baseUrl/AssetInventory/Classification'; } 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 d7acf11c..1313849f 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 @@ -108,6 +108,9 @@ class _AssetInventoryFormViewState extends State { onChanged: (value) { isRegistered = value; resetData(); + if (value) { + _scannedAssetModel?.status = 'Not Registered'; + } setState(() {}); }, disabledOpacity: 1, @@ -164,7 +167,7 @@ class _AssetInventoryFormViewState extends State { if (value != null) { _pickedAssetModel = value; _scannedAssetModel = _scannedAssetModel?.mergeWith(_pickedAssetModel) ?? _pickedAssetModel; - + getClassificationData(assetImportId: _pickedAssetModel?.assetImportId); populateFormValues(); setState(() {}); } @@ -288,9 +291,11 @@ class _AssetInventoryFormViewState extends State { siteInfoContainer(label: context.translation.department, value: _scannedAssetModel?.departmentName ?? '-'), 12.height, siteInfoContainer(label: context.translation.room, value: _scannedAssetModel?.roomName ?? '-'), + ], + if (_scannedAssetModel?.status != null && _scannedAssetModel!.status!.isNotEmpty) ...[ 12.height, + classificationWidget(label: _scannedAssetModel?.status), ], - if (_scannedAssetModel?.status != null && _scannedAssetModel!.status!.isNotEmpty) classificationWidget(label: _scannedAssetModel?.status), 12.height, Text( 'Asset Photo'.addTranslation, @@ -463,4 +468,22 @@ class _AssetInventoryFormViewState extends State { sessionId: (widget.assetInventoryModel?.sessionId ?? 0).toInt(), ); } + + Future getClassificationData({num? assetImportId}) async { + AssetInventoryProvider provider = Provider.of(context, listen: false); + Map payload = { + "assetImportId": assetImportId, + "sessionId": widget.assetInventoryModel?.sessionId, + "siteId": widget.assetInventoryModel?.site?.id, + "buildingId": widget.assetInventoryModel?.building?.id, + "floorId": widget.assetInventoryModel?.floor?.id, + "departmentId": widget.assetInventoryModel?.department?.id, + }; + await provider.getClassification(payload: payload).then((value) { + if (value != null) { + _scannedAssetModel?.status = value; + } + setState(() {}); + }); + } } diff --git a/lib/modules/asset_inventory_module/provider/asset_inventory_provider.dart b/lib/modules/asset_inventory_module/provider/asset_inventory_provider.dart index ed694c44..c712c26c 100644 --- a/lib/modules/asset_inventory_module/provider/asset_inventory_provider.dart +++ b/lib/modules/asset_inventory_module/provider/asset_inventory_provider.dart @@ -284,7 +284,6 @@ class AssetInventoryProvider extends ChangeNotifier { }) async { isLoading = true; try { - log('payload i got is ${model?.toJson()}'); final response = await ApiManager.instance.post(URLs.saveAssetInSession, body: model?.toJson() ?? {}); stateCode = response.statusCode; if (response.statusCode >= 200 && response.statusCode < 300) { @@ -303,6 +302,32 @@ class AssetInventoryProvider extends ChangeNotifier { } } + Future getClassification({ + required Map payload, + }) async { + isLoading = true; + String? classification; + try { + final response = await ApiManager.instance.post(URLs.getClassification, body: payload); + stateCode = response.statusCode; + if (response.statusCode >= 200 && response.statusCode < 300) { + log('classifcation on response ${json.decode(response.body)["data"]['classification']}'); + classification = json.decode(response.body)["data"]['classification']; + isLoading = false; + notifyListeners(); + return classification; + } else { + isLoading = false; + notifyListeners(); + return classification; + } + } catch (error) { + isLoading = false; + notifyListeners(); + return classification; + } + } + Future deleteAssetISession({required num id}) async { try { isLoading = true;