Skip to content

Commit

Permalink
Merge pull request #623 from amansinghbais/#622
Browse files Browse the repository at this point in the history
Improved: fetching closed cycle counts total on closed page in admin screen (#622)
  • Loading branch information
ymaheshwari1 authored Jan 16, 2025
2 parents 63b7956 + 8dc403b commit d373134
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/services/CountService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ const fetchCycleCountUploadedFileData = async (payload: any): Promise <any> => {
});
}

const fetchCycleCountsTotal = async (payload: any): Promise<any> => {
return api({
url: "cycleCounts/count",
method: "get",
params: payload
})
}

export const CountService = {
acceptItem,
addProductToCount,
Expand All @@ -168,6 +176,7 @@ export const CountService = {
fetchCycleCountStats,
fetchCycleCounts,
fetchCycleCountItems,
fetchCycleCountsTotal,
recountItems,
updateCount,
updateCycleCount,
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/count/CountState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export default interface CountState {
cycleCountImportSystemMessages: Array<any>;
defaultRecountUpdateBehaviour: String;
cachedUnmatchProducts: any;
closedCycleCountsTotal: any;
}
32 changes: 32 additions & 0 deletions src/store/modules/count/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,37 @@ const actions: ActionTree<CountState, RootState> = {
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 {
Expand Down Expand Up @@ -133,6 +164,7 @@ const actions: ActionTree<CountState, RootState> = {
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) {
Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/count/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const getters: GetterTree<CountState, RootState> = {
},
getCachedUnmatchProducts: (state) => (id: string) => {
return state.cachedUnmatchProducts[id]
},
getClosedCycleCountsTotal(state) {
return state.closedCycleCountsTotal
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/count/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const countModule: Module<CountState, RootState> = {
},
cycleCountItems: {},
defaultRecountUpdateBehaviour: "add",
cachedUnmatchProducts: {}
cachedUnmatchProducts: {},
closedCycleCountsTotal: ""
},
getters,
actions,
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/count/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
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'
3 changes: 3 additions & 0 deletions src/store/modules/count/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const mutations: MutationTree <CountState> = {
},
[types.COUNT_CACHED_UNMATCH_PRODUCTS_UPDATED] (state, payload) {
state.cachedUnmatchProducts = payload
},
[types.COUNT_CLOSED_CYCLE_COUNTS_TOTAL_UPDATED] (state, payload) {
state.closedCycleCountsTotal = payload
}

}
Expand Down
7 changes: 4 additions & 3 deletions src/views/Closed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<ion-item lines="full">
<ion-icon slot="start" :icon="listOutline"/>
<ion-label>{{ translate("Counts closed") }}</ion-label>
<ion-label slot="end">{{ cycleCounts.length }}</ion-label>
<ion-label slot="end">{{ (closedCycleCountsTotal || closedCycleCountsTotal === 0) ? closedCycleCountsTotal : "-" }}</ion-label>
</ion-item>
<ion-item lines="full">
<ion-icon slot="start" :icon="thermometerOutline"/>
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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) {
Expand Down

0 comments on commit d373134

Please sign in to comment.