Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: download closed counts functionality to work with the filters applied (#616) #661

Merged
merged 7 commits into from
Jan 24, 2025
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
Loading