From 780a83a2ace524b56ef284dd3a3c7a3c8bfc0ee5 Mon Sep 17 00:00:00 2001 From: Jadowyne Ulve Date: Sat, 9 Aug 2025 14:39:11 -0500 Subject: [PATCH] Implemented Searching in receipts barcode link modal --- .../__pycache__/receipts_api.cpython-313.pyc | Bin 19871 -> 20031 bytes application/receipts/receipts_api.py | 5 +- .../receipts/static/js/receiptHandler.js | 301 +++--------------- application/receipts/templates/receipt.html | 38 +-- 4 files changed, 55 insertions(+), 289 deletions(-) diff --git a/application/receipts/__pycache__/receipts_api.cpython-313.pyc b/application/receipts/__pycache__/receipts_api.cpython-313.pyc index e57363d897b8644bb7fdcc0750c73e699e2a65bc..710b213bb99950b26c35e2e6bf6fe2823f94c18d 100644 GIT binary patch delta 2500 zcma)83rv$&6z=T{`b2pY1v&~vXt6*6D5wS$59-MN~4kCjEN;^Plsb zd(Y$E9y-9z9%Po=7K>4ZpRbSXTi1Kia>JyauZF)&J~j?xnf1_IYl00kjPUEU1#sS6 zt!}pf%PWNMvNMW|Ehe9uTvaL`Q+}{Y5(ReSn`yut?G&q#-mCDUzbv9_d?YA1LLRFCvHWywsN)-wG;4|ghDvy?hz zHcPg|rB2?pt|Ok{;mBH9)o%$WqzxUB&JB{Iu_XXG)-W@}pfz77YtROUtuAJOF>8sA zdvI~^x7Fq{px~JJa63N9$!n!VGZMwQA0G?w8@Ds4Nr{$cWgiS2O*&>iY`*I7jyb$1 za?j;ob}YJ_6TFz+bZ+Ct8O=kM@r;5Y<9M25*mg0scJx%rezm_5DT2Hd(XEw}dZkDx z%HzBopLqpACBjNRhu)jGmNY(sxdc@N^I%VEabXRKwFo16zJTN+0vCasppKv(eoS@f zno;zDA?;@t7`>I2tu9%F3S|kr48{M5R&8^c?nUE^q1#qqT#9Z1{Kl_>H7y3l%=O6K zo0+0!i(qhO;q-^LbH@Xv?ra#JIdj^S&9JQ5dH3kucQ-S+k9v&4>tI<{p>73=Pr;_F zA28N4*#TDhBr4n*?j)1@a<`n+hJVT3rJT8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=mFjYah*(vB?iP_UG>!l=1 z4<=bO#^k(IWZOtG5|wml$UgmJ6}XUfn_}tSbZm>n7UHrRKk1GFE|`-hYsDV@RZGcB z)-(Fg3w=`q1xJ*f?YJLea}ix?Id43ch$flDytrob2pSMpu}0b#nVL9F1U`ah0zWib z>T6qxoR2W6WseeFN8luI5d;X@V3)$;ZiXN z9eN<5eZqDBf_3oN6I!gU}FTlEJEU~RGo`|uhk$Z%; z6I}DN^&!;!as6eXI;$DC824@tQnD_RiVsF3=?L3Q8yPs~u0Xq=xcv{=GVVLmgjO(Pxc#L1@Ipm)tfs1&dUiiQ>ju&e4zC*FPHP0WUjACLZ z@Q-X7i6@3*(ZP|pl%^c+L1u{UL}Y6aR>Gc3QQ5 zFEZc4Pnv>JUlH7FIDz*#-1wN#%mYK=;MFzLo-SAGvL?mii8LFA**>S1J3jy+U!{hU zc?Cv%RMo%u8im$ewEv&x>|7d#6@FU*4{ugE-KrgS_-%SX@@xF0tvs<``B$K+nwE{z zCDRWFT8o?+6!=#M?wR?twO-^keUK~!Ksn!`KaAw}WMKmO+dQyt{(7|V_WX(a7D551 zkbz`ib>mJt^*~DWxe!fTAOS6biQo|Y8L(-yO$23aZq0Gz{tA6QbM;?cgY-NH%utji{H$$S#O1h>1&HSZ&7fzqHC{pt<=E_CJUfJP7F#lU-Q2QFn5 z_MdD>v1D{?LwbVN}nIN{&%2FiH)(Oh6%I zbcaa=>ma%ULDntUfDne4~q@LfbynFp)4ct-%!)~Mmdx$tDJ(R JXH;rZ@fZ9u8$kd7 diff --git a/application/receipts/receipts_api.py b/application/receipts/receipts_api.py index f51f2cf..2bf2c03 100644 --- a/application/receipts/receipts_api.py +++ b/application/receipts/receipts_api.py @@ -43,8 +43,9 @@ def getItems(): limit = int(request.args.get('limit', 10)) site_name = session['selected_site'] offset = (page - 1) * limit - sort_order = "ID ASC" - payload = ("%%", limit, offset, sort_order) + search_string = f"%{str(request.args.get('search_string', ""))}%" + sort_order = "item_name ASC" + payload = (search_string, limit, offset, sort_order) recordset, count = receipts_database.getItemsWithQOH(site_name, payload) return jsonify({"items":recordset, "end":math.ceil(count['count']/limit), "error":False, "message":"items fetched succesfully!"}) return jsonify({"items":recordset, "end":math.ceil(count['count']/limit), "error":True, "message":"There was an error with this GET statement"}) diff --git a/application/receipts/static/js/receiptHandler.js b/application/receipts/static/js/receiptHandler.js index 9358f71..1810335 100644 --- a/application/receipts/static/js/receiptHandler.js +++ b/application/receipts/static/js/receiptHandler.js @@ -36,32 +36,6 @@ async function replenishFields(receipt) { } } -async function checkAPI(line_id, barcode) { - console.log(barcode) - const response = await fetch(`/receipts/api/checkAPI`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - line_id: line_id, - barcode: barcode - }), - }); - data = await response.json() - message_type = "primary" - if(data.error){ - message_type = "danger" - } - UIkit.notification({ - message: data.message, - status: message_type, - pos: 'top-right', - timeout: 5000 - }); - await refreshReceipt() -} - async function replenishLinesTable(receipt_items) { let linesTableBody = document.getElementById("linesTableBody") linesTableBody.innerHTML = "" @@ -102,16 +76,6 @@ async function replenishLinesTable(receipt_items) { let operationsCell = document.createElement('td') - let apiOp = document.createElement('a') - - if(receipt_items[i].type === "new sku"){ - apiOp.style = "margin-right: 5px;" - apiOp.setAttribute('class', 'uk-button uk-button-small uk-button-default') - apiOp.setAttribute('uk-icon', 'icon: pull') - apiOp.onclick = async function () { - await checkAPI(receipt_items[i].id, receipt_items[i].barcode) - } - } let linkOp = document.createElement('a') linkOp.style = "margin-right: 5px;" @@ -154,11 +118,6 @@ async function replenishLinesTable(receipt_items) { if (receipt_items[i].type === "new sku"){ - operationsCell.append(apiOp) - operationsCell.append(linkOp) - } - - if (receipt_items[i].type === "api"){ operationsCell.append(linkOp) } @@ -183,29 +142,6 @@ async function replenishLinesTable(receipt_items) { } } -async function replenishItemsTable(items) { - let itemsTableBody = document.getElementById("itemsTableBody") - itemsTableBody.innerHTML = "" - - for(let i = 0; i < items.length; i++){ - let tableRow = document.createElement('tr') - - let idCell = document.createElement('td') - idCell.innerHTML = items[i].id - let barcodeCell = document.createElement('td') - barcodeCell.innerHTML = items[i].barcode - let nameCell = document.createElement('td') - nameCell.innerHTML = items[i].item_name - - tableRow.onclick = async function() { - await addSKULine(items[i].id) - } - - tableRow.append(idCell, barcodeCell, nameCell) - itemsTableBody.append(tableRow) - } -} - async function replenishFilesCards(files) { let fileCards = document.getElementById('fileCards') fileCards.innerHTML = "" @@ -264,15 +200,6 @@ async function openCustomModal() { } -async function openSKUModal() { - pagination_current = 1 - let items = await getItems() - await replenishItemsTable(items) - await updateItemsPaginationElement() - UIkit.dropdown(document.getElementById("addLineDropDown")).hide(false); - UIkit.modal(document.getElementById("itemsModal")).show(); -} - async function openLineEditModal(line_data) { console.log(line_data) document.getElementById('lineName').value = line_data.name @@ -437,6 +364,7 @@ async function getReceipt(id) { return receipt; } +// SKU Modal functions let items_limit = 50; async function getItems() { console.log("getting items") @@ -533,7 +461,39 @@ async function updateItemsPaginationElement() { paginationElement.append(nextElement) } -// Select Vedor functions +async function openSKUModal() { + pagination_current = 1 + let items = await getItems() + await replenishItemsTable(items) + await updateItemsPaginationElement() + UIkit.dropdown(document.getElementById("addLineDropDown")).hide(false); + UIkit.modal(document.getElementById("itemsModal")).show(); +} + +async function replenishItemsTable(items) { + let itemsTableBody = document.getElementById("itemsTableBody") + itemsTableBody.innerHTML = "" + + for(let i = 0; i < items.length; i++){ + let tableRow = document.createElement('tr') + + let idCell = document.createElement('td') + idCell.innerHTML = items[i].id + let barcodeCell = document.createElement('td') + barcodeCell.innerHTML = items[i].barcode + let nameCell = document.createElement('td') + nameCell.innerHTML = items[i].item_name + + tableRow.onclick = async function() { + await addSKULine(items[i].id) + } + + tableRow.append(idCell, barcodeCell, nameCell) + itemsTableBody.append(tableRow) + } +} + +// Select Vendor functions let vendor_limit = 25 let vendor_current_page = 1 let vendor_end_page = 10 @@ -693,193 +653,19 @@ async function updateVendorsPaginationElement() { paginationElement.append(nextElement) } -// Select Vedor functions -let links_limit = 25 -let links_current_page = 1 -let links_end_page = 10 -async function getLinkedLists() { - const url = new URL('/receipts/api/getLinkedLists', window.location.origin); - url.searchParams.append('page', vendor_current_page); - url.searchParams.append('limit', vendor_limit); - const response = await fetch(url); - data = await response.json(); - links_end_page = data.end - return data.items; -} - -async function postLinkedItem(receipt_item_id, link_list_id, conv_factor) { - const response = await fetch(`/receipts/api/postLinkedItem`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - receipt_item_id: receipt_item_id, - link_list_id: link_list_id, - conv_factor: conv_factor - }), - }); - data = await response.json() - message_type = "primary" - if(data.error){ - message_type = "danger" - } - UIkit.notification({ - message: data.message, - status: message_type, - pos: 'top-right', - timeout: 5000 - }); - await refreshReceipt() - UIkit.modal(document.getElementById("linksModal")).hide(); -} - -async function openLinksSelectModal(receipt_item_id) { - let links = await getLinkedLists(); - await replenishLinksTableBody(links, receipt_item_id); - await updateLinksPaginationElement() - UIkit.modal(document.getElementById("linksModal")).show(); -} - -async function replenishLinksTableBody(links, receipt_item_id) { - let linksTableBody = document.getElementById('linksTableBody') - linksTableBody.innerHTML = "" - - for(let i=0; i < links.length; i++){ - let tableRow = document.createElement('tr') - - let idCell = document.createElement('td') - idCell.innerHTML = links[i].id - - let barcodeCell = document.createElement('td') - barcodeCell.innerHTML = links[i].barcode - - let nameCell = document.createElement('td') - nameCell.innerHTML = links[i].item_name - - let convFactorCell = document.createElement('td') - - let conv_factor_input = document.createElement('input') - conv_factor_input.setAttribute('class', 'uk-input') - conv_factor_input.setAttribute('id', `${links[i].id}_conv_factor`) - - convFactorCell.append(conv_factor_input) - - let addCell = document.createElement('td') - - let addbutton = document.createElement('button') - addbutton.setAttribute('class', 'uk-button') - addbutton.innerHTML = "Select" - addbutton.onclick = async function() { - let conv = document.getElementById(`${links[i].id}_conv_factor`) - if (!conv.value == ""){ - conv.classList.remove('uk-form-danger') - let conv_factor = parseFloat(conv.value) - await postLinkedItem(receipt_item_id, links[i].id, conv_factor) - } else { - conv.classList.add('uk-form-danger') - } - } - - addCell.append(addbutton) - - tableRow.append(idCell, barcodeCell, nameCell, convFactorCell, addCell) - linksTableBody.append(tableRow) - } - -} - -async function setLinksPage(pageNumber) { - links_current_page = pageNumber; - let links = await getLinkedLists() - await updateLinksPaginationElement() - await replenishLinksTableBody(links) -} - -async function updateLinksPaginationElement() { - let paginationElement = document.getElementById("linksPage"); - paginationElement.innerHTML = ""; - // previous - let previousElement = document.createElement('li') - if(links_current_page<=1){ - previousElement.innerHTML = ``; - previousElement.classList.add('uk-disabled'); - }else { - previousElement.innerHTML = ``; - } - paginationElement.append(previousElement) - - //first - let firstElement = document.createElement('li') - if(links_current_page<=1){ - firstElement.innerHTML = `1`; - firstElement.classList.add('uk-disabled'); - }else { - firstElement.innerHTML = `1`; - } - paginationElement.append(firstElement) - - // ... - if(links_current_page-2>1){ - let firstDotElement = document.createElement('li') - firstDotElement.classList.add('uk-disabled') - firstDotElement.innerHTML = ``; - paginationElement.append(firstDotElement) - } - // last - if(links_current_page-2>0){ - let lastElement = document.createElement('li') - lastElement.innerHTML = `${links_current_page-1}` - paginationElement.append(lastElement) - } - // current - if(links_current_page!=1 && links_current_page != links_end_page){ - let currentElement = document.createElement('li') - currentElement.innerHTML = `
  • ${links_current_page}
  • ` - paginationElement.append(currentElement) - } - // next - if(links_current_page+2${links_current_page+1}` - paginationElement.append(nextElement) - } - // ... - if(links_current_page+2<=links_end_page){ - let secondDotElement = document.createElement('li') - secondDotElement.classList.add('uk-disabled') - secondDotElement.innerHTML = ``; - paginationElement.append(secondDotElement) - } - //end - let endElement = document.createElement('li') - if(links_current_page>=links_end_page){ - endElement.innerHTML = `${links_end_page}`; - endElement.classList.add('uk-disabled'); - }else { - endElement.innerHTML = `${links_end_page}`; - } - paginationElement.append(endElement) - //next button - let nextElement = document.createElement('li') - if(links_current_page>=links_end_page){ - nextElement.innerHTML = ``; - nextElement.classList.add('uk-disabled'); - }else { - nextElement.innerHTML = ``; - console.log(nextElement.innerHTML) - } - paginationElement.append(nextElement) -} - // Select Barcode Link Functions var ItemBarcodeSelectModal_limit = 50 var ItemBarcodeSelectModal_page = 1 var ItemBarcodeSelectModal_page_end = 1 var selectedReceiptItemID = 0 +var ItemBarcodeSelectModal_search_text = "" async function openItemBarcodeSelectModal(receipt_item_id) { selectedReceiptItemID = receipt_item_id + ItemBarcodeSelectModal_search_text = "" + document.getElementById('ItemBarcodeSelectSearchInput').value = "" + ItemBarcodeSelectModal_page = 1 + ItemBarcodeSelectModal_page_end = 1 await setupItemsBarcodeSelect() UIkit.modal(document.getElementById("ItemBarcodeSelectModal")).show(); } @@ -933,11 +719,11 @@ async function generateItemsBarcodeSelectTable(items) { } } - async function getItemsForModal() { const url = new URL('/receipts/api/getItems', window.location.origin); url.searchParams.append('page', ItemBarcodeSelectModal_page); url.searchParams.append('limit', ItemBarcodeSelectModal_limit); + url.searchParams.append('search_string', ItemBarcodeSelectModal_search_text); const response = await fetch(url); data = await response.json(); ItemBarcodeSelectModal_page_end = data.end @@ -1026,6 +812,13 @@ async function ItemBarcodeSelectModalPage(pageNumber){ await setupItemsBarcodeSelect() } +async function ItemBarcodeSelectModalSearch(event) { + if (event.key === "Enter"){ + ItemBarcodeSelectModal_search_text = document.getElementById('ItemBarcodeSelectSearchInput').value + await setupItemsBarcodeSelect() + } +} + async function updateReceiptItemBarcode(payload) { UIkit.modal(document.getElementById("ItemBarcodeSelectModal")).hide(); diff --git a/application/receipts/templates/receipt.html b/application/receipts/templates/receipt.html index c38d062..220bb0a 100644 --- a/application/receipts/templates/receipt.html +++ b/application/receipts/templates/receipt.html @@ -300,7 +300,11 @@

    Select Item

    -

    Select an Item from the system...

    +

    Select an Item from the system that you would like to associate this unknown barcode to...

    +
    - -
    -
    -

    Select Linked List

    -

    Select an Linked List from the system...

    - - - - - - - - - - - - - -
    IDBarcodeNameConversion FactorOperations
    -
    -