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: removed download count confirmation alert (#567) #568

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 60 additions & 76 deletions src/components/DownloadClosedCountModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ import {
IonSelectOption,
IonTitle,
IonToolbar,
alertController,
modalController
} from "@ionic/vue";
import emitter from "@/event-bus"
Expand All @@ -108,7 +107,6 @@ import store from "@/store";

const cycleCountStats = computed(() => (id: string) => store.getters["count/getCycleCountStats"](id))
const facilities = computed(() => store.getters["user/getFacilities"])
const currentFacility = computed(() => store.getters["user/getCurrentFacility"])
const getProduct = computed(() => (id: string) => store.getters["product/getProduct"](id))
const query = computed(() => store.getters["count/getQuery"])

Expand Down Expand Up @@ -217,80 +215,66 @@ async function fetchProducts(productIds: any){
}

async function downloadCSV() {
const alert = await alertController.create({
header: translate("Download closed counts"),
message: translate("Are you sure you want to download the cycle counts?"),
buttons: [{
text: translate("Cancel"),
role: 'cancel',
}, {
text: translate("Download"),
handler: async () => {
await modalController.dismiss({ dismissed: true });
await alert.dismiss();
emitter.emit("presentLoader", { message: "Preparing file to downlaod...", backdropDismiss: true });

const facilityDetails = getFacilityDetails();
const selectedFieldMappings: any = {
countId: "inventoryCountImportId",
countName: "countImportName",
acceptedByUser: "acceptedByUserLoginId",
createdDate: "createdDate",
lastSubmittedDate: "lastSubmittedDate",
closedDate: "closedDate",
facility: "facilityId",
primaryProductId: "primaryProductId",
secondaryProductId: "secondaryProductId",
lineStatus: "statusId",
expectedQuantity: "qoh",
countedQuantity: "quantity",
variance: "varianceQuantityOnHand",
};

const selectedData = Object.keys(selectedFields.value).filter((field) => selectedFields.value[field]);

const cycleCountItems = await fetchBulkCycleCountItems();
await fetchProducts([... new Set(cycleCountItems.map((item: any) => item.productId))]);

const downloadData = await Promise.all(cycleCountItems.map(async (item: any) => {
const facility = facilityDetails[item?.facilityId];
const product = getProduct.value(item.productId)

if(product.productId) {
const cycleCountDetails = selectedData.reduce((details: any, property: any) => {
if (property === 'createdDate') {
details[property] = getDateWithOrdinalSuffix(item.createdDate);
} else if (property === 'lastSubmittedDate') {
details[property] = getLastSubmittedDate(item);
} else if (property === 'closedDate') {
details[property] = getClosedDate(item);
} else if (property === 'facility') {
details[property] = facility[selectedFacilityField.value];
} else if (property === 'primaryProductId') {
details[property] = getProductIdentificationValue(selectedPrimaryProductId.value, product);
} else if (property === 'secondaryProductId') {
details[property] = getProductIdentificationValue(selectedSecondaryProductId.value, product);
} else if (property === 'countName' && item.countImportName) {
details[property] = item.countImportName;
} else if (property === "lineStatus") {
details[property] = item.itemStatusId === 'INV_COUNT_COMPLETED' ? 'Completed' : item.itemStatusId === 'INV_COUNT_REJECTED' ? 'Rejected' : item.itemStatusId;
} else {
details[property] = item[selectedFieldMappings[property]];
}
return details;
}, {});

return cycleCountDetails;
}
}));

const fileName = `CycleCounts-${DateTime.now().toLocaleString(DateTime.DATETIME_MED_WITH_SECONDS)}.csv`;
await jsonToCsv(downloadData, { download: true, name: fileName });
emitter.emit("dismissLoader")
}
}]
});
return alert.present();
await modalController.dismiss({ dismissed: true });
emitter.emit("presentLoader", { message: "Preparing file to downlaod...", backdropDismiss: true });

const facilityDetails = getFacilityDetails();
const selectedFieldMappings: any = {
countId: "inventoryCountImportId",
countName: "countImportName",
acceptedByUser: "acceptedByUserLoginId",
createdDate: "createdDate",
lastSubmittedDate: "lastSubmittedDate",
closedDate: "closedDate",
facility: "facilityId",
primaryProductId: "primaryProductId",
secondaryProductId: "secondaryProductId",
lineStatus: "statusId",
expectedQuantity: "qoh",
countedQuantity: "quantity",
variance: "varianceQuantityOnHand",
};

const selectedData = Object.keys(selectedFields.value).filter((field) => selectedFields.value[field]);

const cycleCountItems = await fetchBulkCycleCountItems();
await fetchProducts([... new Set(cycleCountItems.map((item: any) => item.productId))]);

const downloadData = await Promise.all(cycleCountItems.map(async (item: any) => {
const facility = facilityDetails[item?.facilityId];
const product = getProduct.value(item.productId)

if(product.productId) {
const cycleCountDetails = selectedData.reduce((details: any, property: any) => {
if (property === 'createdDate') {
details[property] = getDateWithOrdinalSuffix(item.createdDate);
} else if (property === 'lastSubmittedDate') {
details[property] = getLastSubmittedDate(item);
} else if (property === 'closedDate') {
details[property] = getClosedDate(item);
} else if (property === 'facility') {
details[property] = facility[selectedFacilityField.value];
} else if (property === 'primaryProductId') {
details[property] = getProductIdentificationValue(selectedPrimaryProductId.value, product);
} else if (property === 'secondaryProductId') {
details[property] = getProductIdentificationValue(selectedSecondaryProductId.value, product);
} else if (property === 'countName' && item.countImportName) {
details[property] = item.countImportName;
} else if (property === "lineStatus") {
details[property] = item.itemStatusId === 'INV_COUNT_COMPLETED' ? 'Completed' : item.itemStatusId === 'INV_COUNT_REJECTED' ? 'Rejected' : item.itemStatusId;
} else {
details[property] = item[selectedFieldMappings[property]];
}
return details;
}, {});

return cycleCountDetails;
}
}));

const fileName = `CycleCounts-${DateTime.now().toLocaleString(DateTime.DATETIME_MED_WITH_SECONDS)}.csv`;
await jsonToCsv(downloadData, { download: true, name: fileName });
emitter.emit("dismissLoader")
}
</script>

Expand Down
3 changes: 0 additions & 3 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"Auto assign to stores": "Auto assign to stores",
"Average variance": "Average variance",
"Are you sure you want to change the time zone to?": "Are you sure you want to change the time zone to {timeZoneId}?",
"Are you sure you want to download the cycle counts?": "Are you sure you want to download the cycle counts?",
"Assigned": "Assigned",
"Assign": "Assign",
"Assign a facility to the cycle count": "Assign a facility to the cycle count",
Expand Down Expand Up @@ -86,9 +85,7 @@
"count name": "count name",
"eCom Store": "eCom Store",
"due date": "due date",
"Download": "Download",
"Download results": "Download results",
"Download closed counts": "Download closed counts",
"Enter a SKU, or use the barcode scanner to search a product": "Enter a SKU, or use the barcode scanner to search a product",
"Enter a valid cycle count name": "Enter a valid cycle count name",
"Enter a valid product sku": "Enter a valid product sku",
Expand Down
Loading