From 710cc0aff0e5d48bda92d41568e97ae32c01d9ad Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Tue, 16 Jul 2024 10:41:05 +0530 Subject: [PATCH 01/12] Implemented: logic for force scan setting management through settings page (#325) --- src/locales/en.json | 6 ++ src/services/UtilService.ts | 29 +++++- src/store/index.ts | 2 +- src/store/modules/user/actions.ts | 4 +- src/store/modules/util/UtilState.ts | 1 + src/store/modules/util/actions.ts | 113 +++++++++++++++++++++++ src/store/modules/util/getters.ts | 3 + src/store/modules/util/index.ts | 3 +- src/store/modules/util/mutation-types.ts | 1 + src/store/modules/util/mutations.ts | 3 + src/views/Settings.vue | 26 +++++- 11 files changed, 184 insertions(+), 7 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index a5a529ea..23f16221 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -29,10 +29,13 @@ "Location": "Location", "Failed to receive shipment": "Failed to receive shipment", "Failed to receive some of the items": "Failed to receive some of the items", + "Failed to update force scan preference.": "Failed to update force scan preference.", "Failed to update product identifier preference": "Failed to update product identifier preference", "facility location": "facility location", "Facility locations were not found corresponding to destination facility of return shipment. Please add facility locations to avoid receive return shipment failure.": "Facility locations were not found corresponding to destination facility of return shipment. Please add facility locations to avoid receive return shipment failure.", "Fetching time zones": "Fetching time zones", + "Force scan": "Force scan", + "Force scan preference updated successfully.": "Force scan preference updated successfully.", "Go to Launchpad": "Go to Launchpad", "Go to OMS": "Go to OMS", "History": "History", @@ -57,6 +60,7 @@ "No shipments have been received against this purchase order yet": "No shipments have been received against {lineBreak} this purchase order yet", "OMS": "OMS", "OMS instance": "OMS instance", + "Only allow received quantity to be incremented by scanning the barcode of products.": "Only allow received quantity to be incremented by scanning the barcode of products.", "ordered": "ordered", "Orders not found": "Orders not found", "Password": "Password", @@ -81,6 +85,7 @@ "Receive Shipment": "Receive Shipment", "Receiving": "Receiving", "Refresh": "Refresh", + "Require scanning": "Require scanning", "Reset password": "Reset password", "Return Details": "Return Details", "Return received successfully": "Return received successfully {shipmentId}", @@ -129,6 +134,7 @@ "Timezone": "Timezone", "Time zone updated successfully": "Time zone updated successfully", "To close the purchase order, select all.": "To close the purchase order, select all.", + "Unable to update force scan preference.": "Unable to update force scan preference.", "Unable to update product identifier preference": "Unable to update product identifier preference", "Username": "Username", "Version: ": "Version: {appVersion}", diff --git a/src/services/UtilService.ts b/src/services/UtilService.ts index 176ff0af..bd0d8606 100644 --- a/src/services/UtilService.ts +++ b/src/services/UtilService.ts @@ -8,6 +8,33 @@ const fetchStatus = async (payload: any): Promise => { }) } +const updateForceScanSetting = async (payload: any): Promise => { + return api({ + url: "service/updateProductStoreSetting", + method: "post", + data: payload + }); +} + +const createForceScanSetting = async (payload: any): Promise => { + return api({ + url: "service/createProductStoreSetting", + method: "post", + data: payload + }); +} + +const getProductStoreSetting = async (payload: any): Promise => { + return api({ + url: "performFind", + method: "post", + data: payload + }); +} + export const UtilService = { - fetchStatus + createForceScanSetting, + fetchStatus, + getProductStoreSetting, + updateForceScanSetting } \ No newline at end of file diff --git a/src/store/index.ts b/src/store/index.ts index 37ee5c05..20132861 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -24,7 +24,7 @@ const state: any = { } const persistState = createPersistedState({ - paths: ['user', 'return.validStatusChange', 'util.productIdentifications'], + paths: ['user', 'return.validStatusChange', 'util.productIdentifications', 'util.isForceScanEnabled'], fetchBeforeUse: true }) diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index 904fcd8e..bc9ba793 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -91,7 +91,7 @@ const actions: ActionTree = { // TODO: fetch product identifications from enumeration instead of storing it in env this.dispatch('util/setProductIdentifications', process.env.VUE_APP_PRDT_IDENT ? JSON.parse(process.env.VUE_APP_PRDT_IDENT) : []) dispatch('getProductIdentificationPref', currentEComStore?.productStoreId); - + this.dispatch('util/getForceScanSetting', currentEComStore?.productStoreId); } catch (err: any) { // If any of the API call in try block has status code other than 2xx it will be handled in common catch block. // TODO Check if handling of specific status codes is required. @@ -136,6 +136,7 @@ const actions: ActionTree = { commit(types.USER_END_SESSION) this.dispatch('util/setProductIdentifications', []) this.dispatch('order/clearPurchaseOrders'); + this.dispatch('util/updateForceScanStatus', false) resetPermissions(); resetConfig(); @@ -161,6 +162,7 @@ const actions: ActionTree = { 'userPrefValue': payload.eComStore.productStoreId }); await dispatch('getProductIdentificationPref', payload.eComStore.productStoreId); + this.dispatch('util/getForceScanSetting', payload.ecomStore.productStoreId) }, /** diff --git a/src/store/modules/util/UtilState.ts b/src/store/modules/util/UtilState.ts index ad6439ee..6ba41046 100644 --- a/src/store/modules/util/UtilState.ts +++ b/src/store/modules/util/UtilState.ts @@ -1,4 +1,5 @@ export default interface UtilState { status: any; productIdentifications: Array; + isForceScanEnabled: boolean; } \ No newline at end of file diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index 38737c5f..e209433b 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -4,6 +4,9 @@ import * as types from './mutation-types' import { hasError } from '@/utils' import UtilState from './UtilState' import { UtilService } from '@/services/UtilService' +import store from '@/store'; +import { showToast } from '@/utils' +import { translate } from '@hotwax/dxp-components' const actions: ActionTree = { @@ -47,6 +50,116 @@ const actions: ActionTree = { }, async setProductIdentifications({ commit }, payload) { commit(types.UTIL_PRODUCT_IDENT_UPDATED, payload) + }, + + async getForceScanSetting({ commit, dispatch }, eComStoreId) { + const payload = { + "inputFields": { + "productStoreId": eComStoreId, + "settingTypeEnumId": "FULFILL_FORCE_SCAN" + }, + "filterByDate": 'Y', + "entityName": "ProductStoreSetting", + "fieldList": ["settingValue", "fromDate"], + "viewSize": 1 + } + + try { + const resp = await UtilService.getProductStoreSetting(payload) as any + if(!hasError(resp)) { + const respValue = resp.data.docs[0].settingValue + commit(types.UTIL_FORCE_SCAN_STATUS_UPDATED, respValue === "true") + } else { + dispatch('createForceScanSetting'); + } + } catch(err) { + console.error(err) + } + }, + + async createForceScanSetting({ commit }) { + const ecomStore = store.getters['user/getCurrentEComStore']; + const fromDate = Date.now() + + const params = { + fromDate, + "productStoreId": ecomStore.productStoreId, + "settingTypeEnumId": "FULFILL_FORCE_SCAN", + "settingValue": "false" + } + + try { + await UtilService.createForceScanSetting(params) as any + } catch(err) { + console.error(err) + } + + // not checking for resp success and fail case as every time we need to update the state with the + // default value when creating a scan setting + commit(types.UTIL_FORCE_SCAN_STATUS_UPDATED, false) + return fromDate; + }, + + async setForceScanSetting({ commit, dispatch, state }, value) { + let prefValue = state.isForceScanEnabled + const eComStoreId = store.getters['user/getCurrentEComStore'].productStoreId; + + let fromDate; + + try { + const resp = await UtilService.getProductStoreSetting({ + "inputFields": { + "productStoreId": eComStoreId, + "settingTypeEnumId": "FULFILL_FORCE_SCAN" + }, + "filterByDate": 'Y', + "entityName": "ProductStoreSetting", + "fieldList": ["fromDate"], + "viewSize": 1 + }) as any + if(!hasError(resp)) { + fromDate = resp.data.docs[0]?.fromDate + } + } catch(err) { + console.error(err) + } + + // when selecting none as ecom store, not updating the pref as it's not possible to save pref with empty productStoreId + if(!eComStoreId) { + showToast(translate("Unable to update force scan preference.")) + commit(types.UTIL_FORCE_SCAN_STATUS_UPDATED, prefValue) + return; + } + + if(!fromDate) { + fromDate = await dispatch("createForceScanSetting"); + } + + const params = { + "fromDate": fromDate, + "productStoreId": eComStoreId, + "settingTypeEnumId": "FULFILL_FORCE_SCAN", + "settingValue": `${value}` + } + + try { + const resp = await UtilService.updateForceScanSetting(params) as any + + if((!hasError(resp))) { + showToast(translate("Force scan preference updated successfully.")) + prefValue = value + } else { + throw resp.data; + } + } catch(err) { + showToast(translate("Failed to update force scan preference.")) + console.error(err) + } + commit(types.UTIL_FORCE_SCAN_STATUS_UPDATED, prefValue) + }, + + async updateForceScanStatus({ commit }, payload) { + commit(types.UTIL_FORCE_SCAN_STATUS_UPDATED, payload) } } diff --git a/src/store/modules/util/getters.ts b/src/store/modules/util/getters.ts index 36334e57..e44e79bf 100644 --- a/src/store/modules/util/getters.ts +++ b/src/store/modules/util/getters.ts @@ -8,6 +8,9 @@ const getters: GetterTree = { }, getProductIdentifications: (state) => { return state.productIdentifications + }, + isForceScanEnabled(state) { + return state.isForceScanEnabled } } export default getters; \ No newline at end of file diff --git a/src/store/modules/util/index.ts b/src/store/modules/util/index.ts index 4d7815e5..b922b546 100644 --- a/src/store/modules/util/index.ts +++ b/src/store/modules/util/index.ts @@ -9,7 +9,8 @@ const utilModule: Module = { namespaced: true, state: { status: {}, - productIdentifications: [] + productIdentifications: [], + isForceScanEnabled: false }, getters, actions, diff --git a/src/store/modules/util/mutation-types.ts b/src/store/modules/util/mutation-types.ts index f5433a7e..385d0767 100644 --- a/src/store/modules/util/mutation-types.ts +++ b/src/store/modules/util/mutation-types.ts @@ -1,3 +1,4 @@ export const SN_UTIL = 'util' export const UTIL_STATUS_UPDATED = SN_UTIL + '/STATUS_UPDATED' export const UTIL_PRODUCT_IDENT_UPDATED = SN_UTIL + '/PRODUCT_IDENT_UPDATED' +export const UTIL_FORCE_SCAN_STATUS_UPDATED = SN_UTIL + '/FORCE_SCAN_STATUS_UPDATED' diff --git a/src/store/modules/util/mutations.ts b/src/store/modules/util/mutations.ts index 58f175b9..4a641904 100644 --- a/src/store/modules/util/mutations.ts +++ b/src/store/modules/util/mutations.ts @@ -8,6 +8,9 @@ const mutations: MutationTree = { }, [types.UTIL_PRODUCT_IDENT_UPDATED](state, payload) { state.productIdentifications = payload + }, + [types.UTIL_FORCE_SCAN_STATUS_UPDATED](state, payload) { + state.isForceScanEnabled = payload } } export default mutations; \ No newline at end of file diff --git a/src/views/Settings.vue b/src/views/Settings.vue index 26ec3a64..3d29e860 100644 --- a/src/views/Settings.vue +++ b/src/views/Settings.vue @@ -83,13 +83,27 @@ + + + + + {{ translate("Force scan") }} + + + + {{ translate("Only allow received quantity to be incremented by scanning the barcode of products.") }} + + + {{ translate("Require scanning") }} + +