From c94c501625a70e490619f3c4f348c57c164e7a60 Mon Sep 17 00:00:00 2001 From: Aashutosh soni Date: Thu, 6 Feb 2025 11:00:31 +0530 Subject: [PATCH 01/15] Implented: Step1- fetching current facility lat-lon from facilityId. --- src/services/UtilService.ts | 11 +++++++++- src/store/modules/util/UtilState.ts | 1 + src/store/modules/util/actions.ts | 27 +++++++++++++++++++++++- 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/OtherStoresInventoryModal.vue | 15 ++++++++++--- src/views/ProductDetail.vue | 4 ++-- 9 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/services/UtilService.ts b/src/services/UtilService.ts index 7cbff83d9..0dd991109 100644 --- a/src/services/UtilService.ts +++ b/src/services/UtilService.ts @@ -147,6 +147,14 @@ const fetchEnumerations = async (payload: any): Promise => { }); } +const fetchCurrentFacilityLatLon = async (payload: any): Promise => { + return api({ + url: "performFind", + method: "post", + data: payload + }); +} + export const UtilService = { createEnumeration, createProductStoreSetting, @@ -163,5 +171,6 @@ export const UtilService = { isEnumExists, resetPicker, updateProductStoreSetting, - fetchReservedQuantity + fetchReservedQuantity, + fetchCurrentFacilityLatLon } \ No newline at end of file diff --git a/src/store/modules/util/UtilState.ts b/src/store/modules/util/UtilState.ts index ed52feb8e..84f0f5494 100644 --- a/src/store/modules/util/UtilState.ts +++ b/src/store/modules/util/UtilState.ts @@ -7,4 +7,5 @@ export default interface UtilState { cancelReasons: Array; facilities: any; enumerations: any; + currentFacilityLatLon: any; } \ No newline at end of file diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index e4123c751..356fcea50 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -378,7 +378,32 @@ const actions: ActionTree = { async clearEnumerations({ commit }) { commit(types.UTIL_ENUMERATIONS_UPDATED, {}) - } + }, + + async fetchCurrentFacilityLatLon({ commit }, facilityId) { + const payload = { + inputFields: { + facilityId: facilityId + }, + entityName: "FacilityContactDetailByPurpose", + orderBy: "fromDate DESC", + filterByDate: "Y", + fieldList: ["latitude", "longitude"], + viewSize: 5 + } + + try { + const resp = await UtilService.fetchCurrentFacilityLatLon(payload) + + if (!hasError(resp) && resp.data?.docs.length > 0) { + commit(types.UTIL_CURRENT_FACILITY_LATLON_UPDATED, resp.data.docs[0]) + } else { + throw resp.data + } + } catch (err) { + console.error("Failed to fetch facility lat/long information", err) + } + }, } export default actions; \ No newline at end of file diff --git a/src/store/modules/util/getters.ts b/src/store/modules/util/getters.ts index db6a9e91a..edbc17975 100644 --- a/src/store/modules/util/getters.ts +++ b/src/store/modules/util/getters.ts @@ -27,5 +27,8 @@ const getters: GetterTree = { getEnumDescription: (state) => (enumId: string) => { return state.enumerations[enumId] ? state.enumerations[enumId] : enumId }, + getCurrentFacilityLatLong: (state) => (facilityId: string) => { + return state.currentFacilityLatLon[facilityId] ? state.currentFacilityLatLon[facilityId] : {} + } } 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 3d91b0aeb..2fad5e0f5 100644 --- a/src/store/modules/util/index.ts +++ b/src/store/modules/util/index.ts @@ -15,7 +15,8 @@ const utilModule: Module = { partyNames: {}, cancelReasons: [], facilities: {}, - enumerations: {} + enumerations: {}, + currentFacilityLatLon: {}, }, getters, actions, diff --git a/src/store/modules/util/mutation-types.ts b/src/store/modules/util/mutation-types.ts index 4ec560a08..c8c956284 100644 --- a/src/store/modules/util/mutation-types.ts +++ b/src/store/modules/util/mutation-types.ts @@ -7,3 +7,4 @@ export const UTIL_PARTY_NAMES_UPDATED = SN_UTIL + '/PARTY_NAMES_UPDATED' export const UTIL_CANCEL_REASONS_UPDATED = SN_UTIL + '/CANCEL_REASONS_UPDATED' export const UTIL_FACILITIES_UPDATED = SN_UTIL + '/FACILITIES_UPDATED' export const UTIL_ENUMERATIONS_UPDATED = SN_UTIL + '/ENUMERATIONS_UPDATED' +export const UTIL_CURRENT_FACILITY_LATLON_UPDATED = SN_UTIL + '/CURRENT_FACILITY_LATLON_UPDATED' diff --git a/src/store/modules/util/mutations.ts b/src/store/modules/util/mutations.ts index 31f36a0b3..618401d32 100644 --- a/src/store/modules/util/mutations.ts +++ b/src/store/modules/util/mutations.ts @@ -27,5 +27,8 @@ const mutations: MutationTree = { [types.UTIL_ENUMERATIONS_UPDATED] (state, payload) { state.enumerations = payload }, + [types.UTIL_CURRENT_FACILITY_LATLON_UPDATED] (state, payload) { + state.currentFacilityLatLon = payload + } } export default mutations; \ No newline at end of file diff --git a/src/views/OtherStoresInventoryModal.vue b/src/views/OtherStoresInventoryModal.vue index 3cc393db3..3c610f04d 100644 --- a/src/views/OtherStoresInventoryModal.vue +++ b/src/views/OtherStoresInventoryModal.vue @@ -39,8 +39,9 @@ import { IonToolbar, modalController } from "@ionic/vue"; -import { defineComponent } from "vue"; +import { computed, defineComponent } from "vue"; import { close } from "ionicons/icons"; +import { mapGetters } from "vuex"; import { useStore } from "@/store"; import { translate } from "@hotwax/dxp-components"; @@ -60,16 +61,24 @@ export default defineComponent({ IonTitle, IonToolbar }, - props: ["otherStoresInventory"], + props: ["otherStoresInventory","currentFacilityId"], data() { return{ queryString: "", storesInventory: [] as any } }, - mounted() { + computed: { + ...mapGetters({ + FacilityLatLong: 'util/getCurrentFacilityLatLon', + }), + }, + async mounted() { // Create a copy of otherStoresInventory on mount this.storesInventory = this.otherStoresInventory.slice(); + + // fetch latitude and longitude of the facility by dispaching an action + await this.store.dispatch("util/fetchCurrentFacilityLatLon", this.currentFacilityId); }, methods: { closeModal() { diff --git a/src/views/ProductDetail.vue b/src/views/ProductDetail.vue index dab076234..94330d807 100644 --- a/src/views/ProductDetail.vue +++ b/src/views/ProductDetail.vue @@ -300,7 +300,7 @@ export default defineComponent({ this.warehouseInventory += storeInventory.atp } else if (!isCurrentStore) { // Only add to list if it is not a current store - this.otherStoresInventoryDetails.push({ facilityName: storeInventory.facilityName, stock: storeInventory.atp }) + this.otherStoresInventoryDetails.push({ facilityName: storeInventory.facilityName, stock: storeInventory.atp, facilityId: storeInventory.facilityId }) this.otherStoresInventory += storeInventory.atp } } @@ -314,7 +314,7 @@ export default defineComponent({ async getOtherStoresInventoryDetails() { const otherStoresInventoryModal = await modalController.create({ component: OtherStoresInventoryModal, - componentProps: { otherStoresInventory: this.otherStoresInventoryDetails } + componentProps: { otherStoresInventory: this.otherStoresInventoryDetails, currentFacilityId: this.currentFacility?.facilityId } }); return otherStoresInventoryModal.present(); } From a285f0a1ffaa3705621e50c81f5191fc237cecd2 Mon Sep 17 00:00:00 2001 From: Aashutosh soni Date: Thu, 6 Feb 2025 11:47:55 +0530 Subject: [PATCH 02/15] Fixed: step1 showing lat-long in card, bugfixes. --- src/store/modules/util/actions.ts | 11 +++++++++-- src/store/modules/util/getters.ts | 4 ++-- src/views/OtherStoresInventoryModal.vue | 12 +++++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index 356fcea50..dbd939ecd 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -396,14 +396,21 @@ const actions: ActionTree = { const resp = await UtilService.fetchCurrentFacilityLatLon(payload) if (!hasError(resp) && resp.data?.docs.length > 0) { - commit(types.UTIL_CURRENT_FACILITY_LATLON_UPDATED, resp.data.docs[0]) + // Find first doc with non-null coordinates + const validCoords = resp.data.docs.find((doc: any) => + doc.latitude !== null && doc.longitude !== null + ) + + if (validCoords) { + commit(types.UTIL_CURRENT_FACILITY_LATLON_UPDATED, validCoords) + } } else { throw resp.data } } catch (err) { console.error("Failed to fetch facility lat/long information", err) } - }, + }, } export default actions; \ No newline at end of file diff --git a/src/store/modules/util/getters.ts b/src/store/modules/util/getters.ts index edbc17975..0de0fe35c 100644 --- a/src/store/modules/util/getters.ts +++ b/src/store/modules/util/getters.ts @@ -27,8 +27,8 @@ const getters: GetterTree = { getEnumDescription: (state) => (enumId: string) => { return state.enumerations[enumId] ? state.enumerations[enumId] : enumId }, - getCurrentFacilityLatLong: (state) => (facilityId: string) => { - return state.currentFacilityLatLon[facilityId] ? state.currentFacilityLatLon[facilityId] : {} + getCurrentFacilityLatLon: (state) => { + return state.currentFacilityLatLon ? state.currentFacilityLatLon : {} } } export default getters; \ No newline at end of file diff --git a/src/views/OtherStoresInventoryModal.vue b/src/views/OtherStoresInventoryModal.vue index 3c610f04d..fe16bcc27 100644 --- a/src/views/OtherStoresInventoryModal.vue +++ b/src/views/OtherStoresInventoryModal.vue @@ -12,6 +12,13 @@ + + Current Facility Coordinates: + + Lat: {{ currentFacilityCoords.latitude }}, + Long: {{ currentFacilityCoords.longitude }} + + {{ storeInventory.facilityName }} {{ translate('ATP', { count: storeInventory.stock}) }} @@ -70,8 +77,11 @@ export default defineComponent({ }, computed: { ...mapGetters({ - FacilityLatLong: 'util/getCurrentFacilityLatLon', + FacilityLatLon: 'util/getCurrentFacilityLatLon' }), + currentFacilityCoords() { + return this.FacilityLatLon; + } }, async mounted() { // Create a copy of otherStoresInventory on mount From 8e6428933caffa2f7795d300a8cbd35d117dc565 Mon Sep 17 00:00:00 2001 From: Aashutosh soni Date: Thu, 6 Feb 2025 12:58:44 +0530 Subject: [PATCH 03/15] Implemented : Step 2- fetching stores using lat-lon to obtain distance and operational hours. --- src/services/UtilService.ts | 11 +++++++++- src/store/modules/util/UtilState.ts | 1 + src/store/modules/util/actions.ts | 19 +++++++++++++++++ src/store/modules/util/getters.ts | 3 +++ src/store/modules/util/index.ts | 1 + src/store/modules/util/mutation-types.ts | 1 + src/store/modules/util/mutations.ts | 3 +++ src/views/OtherStoresInventoryModal.vue | 26 ++++++++++++++++++++++-- 8 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/services/UtilService.ts b/src/services/UtilService.ts index 0dd991109..5c76e1d4e 100644 --- a/src/services/UtilService.ts +++ b/src/services/UtilService.ts @@ -155,6 +155,14 @@ const fetchCurrentFacilityLatLon = async (payload: any): Promise => { }); } +const fetchStoreLookupByLatLon = async (payload: any): Promise => { + return api({ + url: "storeLookup", + method: "post", + data: payload + }); +} + export const UtilService = { createEnumeration, createProductStoreSetting, @@ -172,5 +180,6 @@ export const UtilService = { resetPicker, updateProductStoreSetting, fetchReservedQuantity, - fetchCurrentFacilityLatLon + fetchCurrentFacilityLatLon, + fetchStoreLookupByLatLon } \ No newline at end of file diff --git a/src/store/modules/util/UtilState.ts b/src/store/modules/util/UtilState.ts index 84f0f5494..f7ff1c368 100644 --- a/src/store/modules/util/UtilState.ts +++ b/src/store/modules/util/UtilState.ts @@ -8,4 +8,5 @@ export default interface UtilState { facilities: any; enumerations: any; currentFacilityLatLon: any; + storeLookupByLatLon: any; } \ No newline at end of file diff --git a/src/store/modules/util/actions.ts b/src/store/modules/util/actions.ts index dbd939ecd..07d854805 100644 --- a/src/store/modules/util/actions.ts +++ b/src/store/modules/util/actions.ts @@ -411,6 +411,25 @@ const actions: ActionTree = { console.error("Failed to fetch facility lat/long information", err) } }, + + async fetchStoreLookupByLatLon({ commit }, point) { + const payload = { + viewSize: 250, + filters: ["storeType: RETAIL_STORE"], + point: `${point.latitude},${point.longitude}` } + + try { + const resp = await UtilService.fetchStoreLookupByLatLon(payload) + + if (!hasError(resp) && resp.data?.response?.docs?.length > 0) { + commit(types.UTIL_STORE_LOOKUP_BY_LATLON_UPDATED, resp.data.response.docs) + } else { + throw resp.data + } + } catch (err) { + console.error("Failed to fetch stores by lat/lon information", err) + } + }, } export default actions; \ No newline at end of file diff --git a/src/store/modules/util/getters.ts b/src/store/modules/util/getters.ts index 0de0fe35c..71c7513c9 100644 --- a/src/store/modules/util/getters.ts +++ b/src/store/modules/util/getters.ts @@ -29,6 +29,9 @@ const getters: GetterTree = { }, getCurrentFacilityLatLon: (state) => { return state.currentFacilityLatLon ? state.currentFacilityLatLon : {} + }, + getStoreLookupByLatLon: (state) => { + return state.storeLookupByLatLon ? state.storeLookupByLatLon : {} } } 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 2fad5e0f5..862a40e26 100644 --- a/src/store/modules/util/index.ts +++ b/src/store/modules/util/index.ts @@ -17,6 +17,7 @@ const utilModule: Module = { facilities: {}, enumerations: {}, currentFacilityLatLon: {}, + storeLookupByLatLon: {} }, getters, actions, diff --git a/src/store/modules/util/mutation-types.ts b/src/store/modules/util/mutation-types.ts index c8c956284..94207ec6c 100644 --- a/src/store/modules/util/mutation-types.ts +++ b/src/store/modules/util/mutation-types.ts @@ -8,3 +8,4 @@ export const UTIL_CANCEL_REASONS_UPDATED = SN_UTIL + '/CANCEL_REASONS_UPDATED' export const UTIL_FACILITIES_UPDATED = SN_UTIL + '/FACILITIES_UPDATED' export const UTIL_ENUMERATIONS_UPDATED = SN_UTIL + '/ENUMERATIONS_UPDATED' export const UTIL_CURRENT_FACILITY_LATLON_UPDATED = SN_UTIL + '/CURRENT_FACILITY_LATLON_UPDATED' +export const UTIL_STORE_LOOKUP_BY_LATLON_UPDATED = SN_UTIL + '/STORE_LOOKUP_BY_LATLON_UPDATED' diff --git a/src/store/modules/util/mutations.ts b/src/store/modules/util/mutations.ts index 618401d32..c6308eaf5 100644 --- a/src/store/modules/util/mutations.ts +++ b/src/store/modules/util/mutations.ts @@ -29,6 +29,9 @@ const mutations: MutationTree = { }, [types.UTIL_CURRENT_FACILITY_LATLON_UPDATED] (state, payload) { state.currentFacilityLatLon = payload + }, + [types.UTIL_STORE_LOOKUP_BY_LATLON_UPDATED] (state, payload) { + state.storeLookupByLatLon = payload } } export default mutations; \ No newline at end of file diff --git a/src/views/OtherStoresInventoryModal.vue b/src/views/OtherStoresInventoryModal.vue index fe16bcc27..c844fced3 100644 --- a/src/views/OtherStoresInventoryModal.vue +++ b/src/views/OtherStoresInventoryModal.vue @@ -18,6 +18,11 @@ Lat: {{ currentFacilityCoords.latitude }}, Long: {{ currentFacilityCoords.longitude }} +
+
+ {{ store.storeCode }} - {{ store.dist }} km +
+
{{ storeInventory.facilityName }} @@ -77,18 +82,35 @@ export default defineComponent({ }, computed: { ...mapGetters({ - FacilityLatLon: 'util/getCurrentFacilityLatLon' + FacilityLatLon: 'util/getCurrentFacilityLatLon', + storeLookupByLatLon: 'util/getStoreLookupByLatLon' }), currentFacilityCoords() { return this.FacilityLatLon; + }, + nearbyStores() { + return this.storeLookupByLatLon || []; } }, async mounted() { // Create a copy of otherStoresInventory on mount this.storesInventory = this.otherStoresInventory.slice(); - // fetch latitude and longitude of the facility by dispaching an action + // fetch latitude and longitude of the facility by dispatching an action + try { await this.store.dispatch("util/fetchCurrentFacilityLatLon", this.currentFacilityId); + + if (this.currentFacilityCoords?.latitude && this.currentFacilityCoords?.longitude) { + await this.store.dispatch("util/fetchStoreLookupByLatLon", { + latitude: this.currentFacilityCoords.latitude, + longitude: this.currentFacilityCoords.longitude + }); + } else { + throw new Error('Invalid facility coordinates'); + } + } catch (error) { + throw new Error('Error fetching facility coordinates'); + } }, methods: { closeModal() { From b0d620e0aa8e7b7900c8afc02ec2362c0928534d Mon Sep 17 00:00:00 2001 From: Aashutosh soni Date: Thu, 6 Feb 2025 16:36:24 +0530 Subject: [PATCH 04/15] Implemented: Step 3- atp + storeLookup data in new array, alphabetical sorting, distance based sorting, atp based toggle, improved search function. --- src/views/OtherStoresInventoryModal.vue | 157 ++++++++++++++++-------- 1 file changed, 109 insertions(+), 48 deletions(-) diff --git a/src/views/OtherStoresInventoryModal.vue b/src/views/OtherStoresInventoryModal.vue index c844fced3..aa8efd517 100644 --- a/src/views/OtherStoresInventoryModal.vue +++ b/src/views/OtherStoresInventoryModal.vue @@ -6,37 +6,49 @@ - {{ translate("Other stores inventory") }} + {{ translate("Other stores") }} + + + + + + + + + - - - + + - Current Facility Coordinates: - - Lat: {{ currentFacilityCoords.latitude }}, - Long: {{ currentFacilityCoords.longitude }} - -
-
- {{ store.storeCode }} - {{ store.dist }} km -
-
-
- - {{ storeInventory.facilityName }} - {{ translate('ATP', { count: storeInventory.stock}) }} + Hide facilities without stock + +
+ + +

{{ inventory.storeCode }}

+

{{ inventory.storeName }}

+ open +

{{ inventory.dist }} miles

+
+ + {{ translate('ATP', { count: inventory.stock }) }} + +
+
+
+

{{ translate("No inventory details found")}}

+
-
-

{{ translate("No inventory details found")}}

-