diff --git a/src/views/CountDetail.vue b/src/views/CountDetail.vue index 29d8833a..ae32e931 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); @@ -297,13 +295,11 @@ 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] await store.dispatch("product/currentProduct", itemsList.value[0]) - updateNavigationState(0); barcodeInput.value?.$el?.setFocus(); }) @@ -351,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 @@ -439,15 +431,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 } } @@ -470,9 +458,7 @@ 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); - updateNavigationState(currentIndex); product.value.isRecounting = false; } } @@ -487,12 +473,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 +486,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..9bf446bc 100644 --- a/src/views/HardCountDetail.vue +++ b/src/views/HardCountDetail.vue @@ -106,7 +106,7 @@ - + {{ translate("Add to existing count") }} @@ -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") }} @@ -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); @@ -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.productId + 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; + item["isMatching"] = false; + if(prevItem && Object.keys(prevItem)?.length && !hasErrorSavingCount) delete item["scannedCount"] } }) 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() { @@ -542,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; } @@ -620,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) {