From 0488f5df5a5e8833dcd96e3a52d1c49d053998da Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Mon, 23 Dec 2024 14:33:48 +0530 Subject: [PATCH 1/6] Improved: added to logic to save count of item already counted after product fetching (#528) --- src/views/CountDetail.vue | 19 +------- src/views/HardCountDetail.vue | 83 ++++++++++++++++++++++------------- 2 files changed, 54 insertions(+), 48 deletions(-) diff --git a/src/views/CountDetail.vue b/src/views/CountDetail.vue index 29d8833a..488452c0 100644 --- a/src/views/CountDetail.vue +++ b/src/views/CountDetail.vue @@ -88,11 +88,11 @@ {{ `${currentItemIndex + 1}/${itemsList.length}` }} - + - + @@ -288,8 +288,6 @@ let cycleCount = ref([]); const queryString = ref(''); const inputCount = ref(''); -const isFirstItem = ref(true); -const isLastItem = ref(false); const isScrolling = ref(false); let previousItem = {}; let hasUnsavedChanges = ref(false); @@ -303,7 +301,6 @@ onIonViewDidEnter(async() => { queryString.value = ''; previousItem = itemsList.value[0] await store.dispatch("product/currentProduct", itemsList.value[0]) - updateNavigationState(0); barcodeInput.value?.$el?.setFocus(); }) @@ -439,15 +436,11 @@ function updateFilteredItems() { const updatedProduct = Object.keys(product.value)?.length ? itemsList.value.find((item) => item.productId === product.value.productId && item.importItemSeqId === product.value.importItemSeqId) : itemsList.value[0] if (updatedProduct) { store.dispatch("product/currentProduct", updatedProduct); - updateNavigationState(itemsList.value.indexOf(updatedProduct)); } else { store.dispatch("product/currentProduct", itemsList.value[0]); - updateNavigationState(0); } } else { store.dispatch("product/currentProduct", {}); - isFirstItem.value = true - isLastItem.value = false } } @@ -472,7 +465,6 @@ const onScroll = (event) => { if (currentProduct) { const currentIndex = itemsList.value?.indexOf(currentProduct); store.dispatch("product/currentProduct", currentProduct); - updateNavigationState(currentIndex); product.value.isRecounting = false; } } @@ -487,12 +479,6 @@ const onScroll = (event) => { }); }; -// Add this function to update the navigation state -const updateNavigationState = (currentIndex) => { - isFirstItem.value = currentIndex === 0; - isLastItem.value = currentIndex === itemsList.value.length - 1; -}; - async function changeProduct(direction) { if (isScrolling.value) return; isScrolling.value = true; @@ -506,7 +492,6 @@ async function changeProduct(direction) { if (productEl) productEl.scrollIntoView({ behavior: 'smooth' }); await new Promise(resolve => setTimeout(resolve, 500)); await store.dispatch("product/currentProduct", product); - updateNavigationState(index); } isScrolling.value = false; } diff --git a/src/views/HardCountDetail.vue b/src/views/HardCountDetail.vue index 211e899f..bb7da5e3 100644 --- a/src/views/HardCountDetail.vue +++ b/src/views/HardCountDetail.vue @@ -119,8 +119,8 @@ - - {{ translate("Save count") }} + + {{ translate((currentProduct.isMatchNotFound || currentProduct.isMatching) ? "Match product" : "Save count") }} @@ -143,8 +143,8 @@ {{ isItemAlreadyAdded(currentProduct) ? getVariance(currentProduct, true) : "-" }} - - {{ translate(currentProduct.isMatchNotFound ? "Match product" : "Save count") }} + + {{ translate((currentProduct.isMatchNotFound || currentProduct.isMatching) ? "Match product" : "Save count") }} @@ -321,13 +321,7 @@ async function changeProduct(direction: string) { if(index >= 0 && index < itemsList.value.length) { const product = itemsList.value[index]; - let productEl = {} as any; - if(isItemAlreadyAdded(product)) { - productEl = document.querySelector(`[data-seq="${product.importItemSeqId}"]`); - } else { - productEl = document.getElementById(product.scannedId); - } - if(productEl) productEl.scrollIntoView({ behavior: 'smooth' }); + scrollToProduct(product); await new Promise(resolve => setTimeout(resolve, 500)); await store.dispatch("product/currentProduct", product); } @@ -373,13 +367,7 @@ async function scanProduct() { const isAlreadySelected = isItemAlreadyAdded(selectedItem) ? (currentProduct.value.productId === selectedItem.productId && currentProduct.value.importItemSeqId === selectedItem.importItemSeqId) : (currentProduct.value.scannedId === selectedItem.scannedId); if(!isAlreadySelected) { - router.replace({ hash: isItemAlreadyAdded(selectedItem) ? `#${selectedItem.productId}-${selectedItem.importItemSeqId}` : `#${selectedItem.scannedId}` }); - setTimeout(() => { - const element = document.getElementById(isItemAlreadyAdded(selectedItem) ? `${selectedItem.productId}-${selectedItem.importItemSeqId}` : selectedItem.scannedId); - if (element) { - element.scrollIntoView({ behavior: 'smooth' }); - } - }, 0); + scrollToProduct(selectedItem); } else if(selectedItem.itemStatusId === "INV_COUNT_CREATED" && !isNewlyAdded) { inputCount.value++; } @@ -390,6 +378,16 @@ async function scanProduct() { queryString.value = "" } +function scrollToProduct(product: any) { + router.replace({ hash: isItemAlreadyAdded(product) ? `#${product.productId}-${product.importItemSeqId}` : `#${product.scannedId}` }); + setTimeout(() => { + const element = document.getElementById(isItemAlreadyAdded(product) ? `${product.productId}-${product.importItemSeqId}` : product.scannedId); + if (element) { + element.scrollIntoView({ behavior: 'smooth' }); + } + }, 0); +} + async function addProductToItemsList() { const newItem = { scannedId: queryString.value, @@ -434,9 +432,42 @@ async function addProductToCount(productId: any) { return 0; } -function updateCurrentItemInList(importItemSeqId: any, product: any, scannedValue: string) { +async function updateCurrentItemInList(importItemSeqId: any, product: any, scannedValue: string) { const items = JSON.parse(JSON.stringify(cycleCountItems.value.itemList)); const updatedProduct = JSON.parse(JSON.stringify(currentProduct.value)) + let prevItem = {} as any, hasErrorSavingCount = false; + + if(updatedProduct.scannedId === scannedValue) { + if(importItemSeqId) { + updatedProduct["importItemSeqId"] = importItemSeqId + updatedProduct["productId"] = product.oroductId + updatedProduct["isMatchNotFound"] = false + } else { + updatedProduct["isMatchNotFound"] = true + } + updatedProduct["isMatching"] = false; + store.dispatch("product/currentProduct", updatedProduct); + } else if(importItemSeqId) { + prevItem = items.find((item: any) => item.scannedId === scannedValue); + + if(prevItem && prevItem?.scannedCount >= 0) { + try { + const resp = await CountService.updateCount({ + inventoryCountImportId: cycleCount.value.inventoryCountImportId, + importItemSeqId, + productId: product.productId, + quantity: prevItem.scannedCount, + countedByUserLoginId: userProfile.value.username + }) + + if(hasError(resp)) { + hasErrorSavingCount = true; + } + } catch(error) { + logger.error(error) + } + } + } items.map((item: any) => { if(item.scannedId === scannedValue) { @@ -447,22 +478,12 @@ function updateCurrentItemInList(importItemSeqId: any, product: any, scannedValu } else { item["isMatchNotFound"] = true } - item.isMatching = false; + if(prevItem && Object.keys(prevItem)?.length && !hasErrorSavingCount) delete item["scannedCount"] + updatedProduct["isMatching"] = false; } }) store.dispatch('count/updateCycleCountItems', items); - if(updatedProduct.scannedId === scannedValue) { - if(importItemSeqId) { - updatedProduct["importItemSeqId"] = importItemSeqId - updatedProduct["productId"] = product.oroductId - updatedProduct["isMatchNotFound"] = false - } else { - updatedProduct["isMatchNotFound"] = true - } - updatedProduct.isMatching = false; - store.dispatch("product/currentProduct", updatedProduct); - } } async function readyForReview() { From c6b01f653e255da7984453f42d88551dc14a4c87 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Mon, 23 Dec 2024 14:42:56 +0530 Subject: [PATCH 2/6] Fixed: handling for the update cycle count behavior (#528) --- src/views/HardCountDetail.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/views/HardCountDetail.vue b/src/views/HardCountDetail.vue index bb7da5e3..121680fa 100644 --- a/src/views/HardCountDetail.vue +++ b/src/views/HardCountDetail.vue @@ -106,7 +106,7 @@ - + {{ translate("Add to existing count") }} @@ -234,7 +234,7 @@ const selectedSegment = ref("all"); let previousItem = {} as any; const barcodeInputRef = ref(); const inputCount = ref("") as any; -const selectedCountUpdateType = ref("new"); +const selectedCountUpdateType = ref("add"); const isScrolling = ref(false); let isScanningInProgress = ref(false); @@ -563,7 +563,7 @@ async function saveCount(currentProduct: any, isScrollEvent = false) { const prevCount = currentProduct.scannedCount ? currentProduct.scannedCount : 0 item.countedByUserLoginId = userProfile.value.username - if(selectedCountUpdateType.value === "new") item.scannedCount = inputCount.value + if(selectedCountUpdateType.value === "replace") item.scannedCount = inputCount.value else item.scannedCount = inputCount.value + prevCount currentItem = item; } From 39943aa1e8347c94e1e983ba6315e8d99bdf5960 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Mon, 23 Dec 2024 14:51:04 +0530 Subject: [PATCH 3/6] Improved: reverted unwanted changes in countDetail and simplified cycleCount items fetching logic (#528) --- src/views/CountDetail.vue | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/views/CountDetail.vue b/src/views/CountDetail.vue index 488452c0..2d96b26d 100644 --- a/src/views/CountDetail.vue +++ b/src/views/CountDetail.vue @@ -295,8 +295,7 @@ const barcodeInput = ref(); let isScanningInProgress = ref(false); onIonViewDidEnter(async() => { - await fetchCycleCount(); - await fetchCycleCountItems(); + await Promise.allSettled([await fetchCycleCount(), store.dispatch("count/fetchCycleCountItems", { inventoryCountImportId : props?.id })]) selectedSegment.value = 'all'; queryString.value = ''; previousItem = itemsList.value[0] @@ -348,10 +347,6 @@ function inputCountValidation(event) { if(/[`!@#$%^&*()_+\-=\\|,.<>?~e]/.test(event.key) && event.key !== 'Backspace') event.preventDefault(); } -async function fetchCycleCountItems() { - await store.dispatch("count/fetchCycleCountItems", { inventoryCountImportId : props?.id }); -} - async function fetchCycleCount() { emitter.emit("presentLoader"); let payload = props?.id @@ -463,7 +458,6 @@ const onScroll = (event) => { previousItem = currentProduct // Update the previousItem variable with the current item if (currentProduct) { - const currentIndex = itemsList.value?.indexOf(currentProduct); store.dispatch("product/currentProduct", currentProduct); product.value.isRecounting = false; } From 210d3dd5fc16b538002afd77ba4104a8f60390de Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Mon, 23 Dec 2024 16:30:59 +0530 Subject: [PATCH 4/6] Fixed: issue in updating status of matching in the list (#528) --- src/views/HardCountDetail.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/HardCountDetail.vue b/src/views/HardCountDetail.vue index 121680fa..48b5e246 100644 --- a/src/views/HardCountDetail.vue +++ b/src/views/HardCountDetail.vue @@ -478,8 +478,8 @@ async function updateCurrentItemInList(importItemSeqId: any, product: any, scann } else { item["isMatchNotFound"] = true } + item["isMatching"] = false; if(prevItem && Object.keys(prevItem)?.length && !hasErrorSavingCount) delete item["scannedCount"] - updatedProduct["isMatching"] = false; } }) From 2fd98b5093c6f4a92ea4e975b5e4bba9ebe907d7 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Mon, 23 Dec 2024 18:18:01 +0530 Subject: [PATCH 5/6] Fixed: page leaving alert coming every time leaving the page (#528) --- src/views/HardCountDetail.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/HardCountDetail.vue b/src/views/HardCountDetail.vue index 48b5e246..ec43cb8a 100644 --- a/src/views/HardCountDetail.vue +++ b/src/views/HardCountDetail.vue @@ -641,7 +641,7 @@ function getVariance(item: any , isRecounting: boolean) { } function hasUnsavedChanges() { - return inputCount.value >= 0 || cycleCountItems.value.itemList.find((item: any) => item.scannedCount && !item.isMatchNotFound); + return (inputCount.value && inputCount.value >= 0) || cycleCountItems.value.itemList.find((item: any) => item.scannedCount && !item.isMatchNotFound); } function isItemAlreadyAdded(product: any) { From e326ca03d17afed385ce1c21fb7723d13c28121d Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Mon, 23 Dec 2024 18:21:41 +0530 Subject: [PATCH 6/6] Fixed: typo in disabled property and in productId (#528) --- src/views/CountDetail.vue | 2 +- src/views/HardCountDetail.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/CountDetail.vue b/src/views/CountDetail.vue index 2d96b26d..ae32e931 100644 --- a/src/views/CountDetail.vue +++ b/src/views/CountDetail.vue @@ -92,7 +92,7 @@ - + diff --git a/src/views/HardCountDetail.vue b/src/views/HardCountDetail.vue index ec43cb8a..9bf446bc 100644 --- a/src/views/HardCountDetail.vue +++ b/src/views/HardCountDetail.vue @@ -440,7 +440,7 @@ async function updateCurrentItemInList(importItemSeqId: any, product: any, scann if(updatedProduct.scannedId === scannedValue) { if(importItemSeqId) { updatedProduct["importItemSeqId"] = importItemSeqId - updatedProduct["productId"] = product.oroductId + updatedProduct["productId"] = product.productId updatedProduct["isMatchNotFound"] = false } else { updatedProduct["isMatchNotFound"] = true