diff --git a/src/services/CountService.ts b/src/services/CountService.ts index aae9db06..aa892305 100644 --- a/src/services/CountService.ts +++ b/src/services/CountService.ts @@ -153,6 +153,14 @@ const fetchCycleCountUploadedFileData = async (payload: any): Promise => { }); } +const fetchCycleCountsTotal = async (payload: any): Promise => { + return api({ + url: "cycleCounts/count", + method: "get", + params: payload + }) +} + export const CountService = { acceptItem, addProductToCount, @@ -168,6 +176,7 @@ export const CountService = { fetchCycleCountStats, fetchCycleCounts, fetchCycleCountItems, + fetchCycleCountsTotal, recountItems, updateCount, updateCycleCount, diff --git a/src/store/modules/count/CountState.ts b/src/store/modules/count/CountState.ts index 82fb2737..f094f41c 100644 --- a/src/store/modules/count/CountState.ts +++ b/src/store/modules/count/CountState.ts @@ -14,4 +14,5 @@ export default interface CountState { cycleCountImportSystemMessages: Array; defaultRecountUpdateBehaviour: String; cachedUnmatchProducts: any; + closedCycleCountsTotal: any; } \ No newline at end of file diff --git a/src/store/modules/count/actions.ts b/src/store/modules/count/actions.ts index 430d62df..3e884a05 100644 --- a/src/store/modules/count/actions.ts +++ b/src/store/modules/count/actions.ts @@ -66,6 +66,37 @@ const actions: ActionTree = { commit(types.COUNT_LIST_UPDATED, { counts, total , isScrollable }) }, + async fetchClosedCycleCountsTotal({ commit, state }) { + const params = { + statusId: "INV_COUNT_COMPLETED" + } as any; + // TODO: Currently, the search functionality works only on the count name. Once the API supports searching across + // multiple fields, we should include the count ID in the search parameters. + if(state.query.queryString.length) { + params["countImportName"] = state.query.queryString + params["countImportName_op"] = "contains" + } + + if(state.query.facilityIds.length) { + params["facilityId"] = state.query.facilityIds.join(",") + params["facilityId_op"] = "in" + } + + let total = ""; + try { + const resp = await CountService.fetchCycleCountsTotal(params); + if(!hasError(resp)) { + total = resp.data.count; + } else { + throw resp; + } + } catch(err) { + logger.error(err) + } + + commit(types.COUNT_CLOSED_CYCLE_COUNTS_TOTAL_UPDATED, total) + }, + async fetchCycleCountStats({ commit, state }, inventoryCountImportIds) { const cachedProducts = JSON.parse(JSON.stringify(state.cachedUnmatchProducts)) try { @@ -133,6 +164,7 @@ const actions: ActionTree = { statusId = "INV_COUNT_COMPLETED" } dispatch("fetchCycleCounts", { pageSize: process.env.VUE_APP_VIEW_SIZE, pageIndex: 0, statusId }) + if(payload.key === "facilityIds") dispatch("fetchClosedCycleCountsTotal") }, async updateQueryString({ commit }, payload) { diff --git a/src/store/modules/count/getters.ts b/src/store/modules/count/getters.ts index 960d6bf0..7bce1144 100644 --- a/src/store/modules/count/getters.ts +++ b/src/store/modules/count/getters.ts @@ -32,6 +32,9 @@ const getters: GetterTree = { }, getCachedUnmatchProducts: (state) => (id: string) => { return state.cachedUnmatchProducts[id] + }, + getClosedCycleCountsTotal(state) { + return state.closedCycleCountsTotal } }; diff --git a/src/store/modules/count/index.ts b/src/store/modules/count/index.ts index 8884396b..cb1f60e7 100644 --- a/src/store/modules/count/index.ts +++ b/src/store/modules/count/index.ts @@ -25,7 +25,8 @@ const countModule: Module = { }, cycleCountItems: {}, defaultRecountUpdateBehaviour: "add", - cachedUnmatchProducts: {} + cachedUnmatchProducts: {}, + closedCycleCountsTotal: "" }, getters, actions, diff --git a/src/store/modules/count/mutation-types.ts b/src/store/modules/count/mutation-types.ts index 35110189..fd3b26a7 100644 --- a/src/store/modules/count/mutation-types.ts +++ b/src/store/modules/count/mutation-types.ts @@ -6,4 +6,5 @@ export const COUNT_STATS_UPDATED = SN_COUNT + "/STATS_UPDATED" export const COUNT_UPDATED = SN_COUNT + '/UPDATED' export const COUNT_ITEMS_UPDATED = SN_COUNT + '/ITEMS_UPDATED' export const COUNT_IMPORT_SYSTEM_MESSAGES_UPDATED = SN_COUNT + 'IMPORT_SYSTEM_MESSAGES_UPDATED' -export const COUNT_CACHED_UNMATCH_PRODUCTS_UPDATED = SN_COUNT + 'CACHED_UNMATCHED_PRODUCTS_UPDATED' \ No newline at end of file +export const COUNT_CACHED_UNMATCH_PRODUCTS_UPDATED = SN_COUNT + 'CACHED_UNMATCHED_PRODUCTS_UPDATED' +export const COUNT_CLOSED_CYCLE_COUNTS_TOTAL_UPDATED = SN_COUNT + 'CLOSED_CYCLE_COUNTS_TOTAL_UPDATED' \ No newline at end of file diff --git a/src/store/modules/count/mutations.ts b/src/store/modules/count/mutations.ts index 44a75fe3..5bfcdae0 100644 --- a/src/store/modules/count/mutations.ts +++ b/src/store/modules/count/mutations.ts @@ -37,6 +37,9 @@ const mutations: MutationTree = { }, [types.COUNT_CACHED_UNMATCH_PRODUCTS_UPDATED] (state, payload) { state.cachedUnmatchProducts = payload + }, + [types.COUNT_CLOSED_CYCLE_COUNTS_TOTAL_UPDATED] (state, payload) { + state.closedCycleCountsTotal = payload } } diff --git a/src/views/Closed.vue b/src/views/Closed.vue index 2ea5b9c5..89994b0e 100644 --- a/src/views/Closed.vue +++ b/src/views/Closed.vue @@ -23,7 +23,7 @@ {{ translate("Counts closed") }} - {{ cycleCounts.length }} + {{ (closedCycleCountsTotal || closedCycleCountsTotal === 0) ? closedCycleCountsTotal : "-" }} @@ -115,13 +115,14 @@ const cycleCounts = computed(() => store.getters["count/getCounts"]) const cycleCountStats = computed(() => (id: string) => store.getters["count/getCycleCountStats"](id)) const isScrollable = computed(() => store.getters["count/isCycleCountListScrollable"]) const query = computed(() => store.getters["count/getQuery"]) +const closedCycleCountsTotal = computed(() => store.getters["count/getClosedCycleCountsTotal"]) const isScrollingEnabled = ref(false); const contentRef = ref({}) as any const infiniteScrollRef = ref({}) as any onIonViewWillEnter(async () => { - await fetchClosedCycleCounts() + await Promise.allSettled([fetchClosedCycleCounts(), store.dispatch("count/fetchClosedCycleCountsTotal")]) }) onIonViewWillLeave(async () => { @@ -142,7 +143,7 @@ function enableScrolling() { async function updateQueryString(key: string, value: any) { await store.dispatch("count/updateQueryString", { key, value }) - fetchClosedCycleCounts(); + await Promise.allSettled([fetchClosedCycleCounts(), store.dispatch("count/fetchClosedCycleCountsTotal")]) } async function loadMoreCycleCounts(event: any) {