Skip to content

Commit

Permalink
Merge pull request #661 from amansinghbais/#616
Browse files Browse the repository at this point in the history
Improved: download closed counts functionality to work with the filters applied (#616)
  • Loading branch information
ravilodhi authored Jan 24, 2025
2 parents ae47305 + 613b3cd commit 45dd9a4
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 20 deletions.
93 changes: 74 additions & 19 deletions src/components/DownloadClosedCountModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ import {
import emitter from "@/event-bus"
import { computed, ref } from "vue";
import { closeOutline, cloudDownloadOutline } from "ionicons/icons";
import { getDateWithOrdinalSuffix, getProductIdentificationValue, hasError, jsonToCsv } from "@/utils";
import { convertIsoToMillis, getDateWithOrdinalSuffix, getProductIdentificationValue, hasError, jsonToCsv, showToast } from "@/utils";
import { CountService } from "@/services/CountService"
import { translate } from '@/i18n';
import { DateTime } from "luxon";
Expand Down Expand Up @@ -171,39 +171,94 @@ function getFacilityDetails() {
}
async function fetchBulkCycleCountItems() {
let payload = {
statusId: "INV_COUNT_COMPLETED",
pageSize: 200,
facilityId: query.value.facilityIds,
pageIndex: 0
};
let resp = {} as any, counts = [] as any, pageIndex = 0;
const pageSize = process.env.VUE_APP_VIEW_SIZE ? JSON.parse(process.env.VUE_APP_VIEW_SIZE) : 20;
const params = {
statusId: "INV_COUNT_COMPLETED,INV_COUNT_REJECTED",
statusId_op: "in",
facilityId: query.value.facilityIds.join(","),
facilityId_op: "in",
pageSize,
pageIndex
} as any;
let allItems = [] as any;
let resp;
if(query.value.queryString.length) {
params["countImportName"] = query.value.queryString
params["countImportName_op"] = "contains"
}
// created after date
if(query.value.createdDate_from) {
params["createdDate_from"] = convertIsoToMillis(query.value.createdDate_from, "from");
}
// created before date
if(query.value.createdDate_thru) {
params["createdDate_thru"] = convertIsoToMillis(query.value.createdDate_thru, "thru");
}
// closed after date
if(query.value.closedDate_from) {
params["closedDate_from"] = convertIsoToMillis(query.value.closedDate_from, "from");
}
// closed before date
if(query.value.closedDate_thru) {
params["closedDate_thru"] = convertIsoToMillis(query.value.closedDate_thru, "thru");
}
try {
do {
resp = await CountService.fetchBulkCycleCountItems(payload);
if (!hasError(resp) && resp?.data.itemList.length) {
allItems = allItems.concat(resp.data.itemList);
payload.pageIndex++;
resp = await CountService.fetchCycleCounts(params);
if(!hasError(resp) && resp.data?.length) {
counts = counts.concat(resp.data)
pageIndex++;
} else {
throw resp.data;
throw resp
}
} while (resp.data.itemList.length >= payload.pageSize);
} catch (err) {
logger.error(err);
return [];
} while(resp.data.length >= pageSize)
} catch(err) {
logger.error(err)
}
return allItems;
if(!counts.length) return [];
let countItems = [] as any, count = {} as any;
for(count of counts) {
let items = [] as any, resp, index = 0;
try {
do {
resp = await CountService.fetchCycleCountItems({ inventoryCountImportId : count.inventoryCountImportId, pageSize: 100, pageIndex: index })
if(!hasError(resp) && resp.data?.itemList?.length) {
items = items.concat(resp.data.itemList)
index++;
} else {
throw resp.data;
}
} while(resp.data.itemList?.length >= 100)
} catch(err) {
logger.error(err)
items = []
}
countItems = countItems.concat(items);
}
return countItems
}
async function fetchProducts(productIds: any){
await store.dispatch("product/fetchProducts", { productIds });
}
async function downloadCSV() {
if(!query.value.facilityIds?.length) {
showToast(translate("Please select atleast one facility in filters."))
return;
}
if(!(query.value.createdDate_from && query.value.createdDate_thru) && !(query.value.closedDate_from && query.value.closedDate_thru)) {
showToast(translate("Please select atleast one of the date filter range."))
return;
}
await modalController.dismiss({ dismissed: true });
emitter.emit("presentLoader", { message: "Preparing file to downlaod...", backdropDismiss: true });
Expand Down
2 changes: 1 addition & 1 deletion src/components/SelectFacilityModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function closeModal(value = "") {
function filterFacilities() {
if(queryString.value.trim()) {
filteredFacilities.value = facilities.value.filter((facility: any) => facility.facilityName.toLowerCase().includes(queryString.value.toLowerCase()) || facility.facilityId.toLowerCase().includes(queryString.value.toLowerCase()))
filteredFacilities.value = facilities.value.filter((facility: any) => facility.facilityName?.toLowerCase().includes(queryString.value.toLowerCase()) || facility.facilityId.toLowerCase().includes(queryString.value.toLowerCase()))
} else {
filteredFacilities.value = facilities.value
}
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@
"Please provide a valid barcode identifier.": "Please provide a valid barcode identifier.",
"Please select at least one field to generate CSV": "Please select at least one field to generate CSV",
"Please select a Product identifier": "Please select a Product identifier",
"Please select atleast one facility in filters.": "Please select atleast one facility in filters.",
"Please select atleast one of the date filter range.": "Please select atleast one of the date filter range.",
"Please select the column that corresponds to the product identifier": "Please select the column that corresponds to the product identifier",
"Preparing file to downlaod...": "Preparing file to downlaod...",
"Primary": "Primary",
Expand Down

0 comments on commit 45dd9a4

Please sign in to comment.