${items[i].description}
` + content.innerHTML = `${items[i].item_description}
` let footer = document.createElement('div') footer.classList.add('uk-card-footer') - footer.innerHTML = `edit - History` + footer.innerHTML = `edit + History` listItem.append(header) if(!items[i].description == ""){ @@ -263,7 +265,7 @@ async function updateListElements(){ items_list.append(main_list) } -let sort = "id" +let sort = "item_uuid" async function setSort(sort_string) { sort = sort_string await getItems() @@ -278,7 +280,7 @@ async function setOrder(order_string) { } async function getItems(){ - const url = new URL('/items/getItemsWithQOH', window.location.origin); + const url = new URL('/items/api/getItemsWithQOH', window.location.origin); url.searchParams.append('page', current_page); url.searchParams.append('limit', limit); url.searchParams.append('search_text', searchText); diff --git a/application/items/static/transactionHandler.js b/application/items/static/transactionHandler.js index 8210cfc..5100dc8 100644 --- a/application/items/static/transactionHandler.js +++ b/application/items/static/transactionHandler.js @@ -37,68 +37,62 @@ async function replenishItemsTable(items) { 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.append(idCell) - tableRow.append(barcodeCell) - tableRow.append(nameCell) + let opCell = document.createElement('td') - tableRow.onclick = function(){ - selectItem(items[i].id) + let selectButton = document.createElement('button') + selectButton.setAttribute('class', 'uk-button uk-button-small uk-button-primary') + selectButton.innerHTML = "Select" + selectButton.onclick = async function(){ + console.log('clicked') + await selectItem(items[i].item_uuid) } + opCell.append(selectButton) + tableRow.append(nameCell, opCell) itemsTableBody.append(tableRow) } } async function populateForm() { if (item){ - console.log(item) - document.getElementById('database_id').value = item.id - document.getElementById('barcode').value = item.barcode + document.getElementById('database_uuid').value = item.item_uuid document.getElementById('name').value = item.item_name - document.getElementById('transaction_cost').value = parseFloat(item.item_info.cost) + document.getElementById('transaction_cost').value = parseFloat(item.item_cost) await selectLocation( - item.logistics_info.primary_zone.id, - item.logistics_info.primary_location.id, - item.logistics_info.primary_zone.name, - item.logistics_info.primary_location.name + item.primary_zone.zone_uuid, + item.primary_location.location_uuid, + item.primary_zone.zone_name, + item.primary_location.location_name ) - let quantity_on_hand = 0 - let locations = await getItemLocations() - for(let i = 0; i < locations.length; i++){ - quantity_on_hand = quantity_on_hand + locations[i].quantity_on_hand - } - document.getElementById('QOH').value = quantity_on_hand - document.getElementById('UOM').value = item.item_info.uom.fullname + document.getElementById('QOH').value = item.item_quantity_on_hand + document.getElementById('UOM').value = item.unit_fullname - await replenishItemLocationsTable(locations) + await replenishItemLocationsTable(item.item_locations) } } -async function selectItem(id) { +async function selectItem(item_uuid) { + console.log(item_uuid) UIkit.modal(document.getElementById("itemsModal")).hide(); - item = await getItem(id) + item = await getItem(item_uuid) + console.log(item) await populateForm() } -var transaction_zone_id = 0 -var transaction_item_location_id = 0 -async function selectLocation(zone_id, location_id, zone_name, location_name) { +var transaction_zone_uuid = "" +var transaction_location_uuid = "" +async function selectLocation(zone_uuid, location_uuid, zone_name, location_name) { document.getElementById('zone').value = zone_name document.getElementById('location').value = location_name - transaction_zone_id = zone_id - transaction_item_location_id = location_id + transaction_zone_uuid = zone_uuid + transaction_item_location_uuid = location_uuid } async function openItemsModal(elementID){ @@ -139,7 +133,7 @@ async function replenishItemLocationsTable(locations) { for(let i = 0; i < locations.length; i++){ let tableRow = document.createElement('tr') - let loca = locations[i].uuid.split('@') + let loca = locations[i].location_shortname.split('@') let zoneCell = document.createElement('td') zoneCell.innerHTML = loca[0] @@ -148,13 +142,13 @@ async function replenishItemLocationsTable(locations) { locationCell.innerHTML = loca[1] let qohCell = document.createElement('td') - qohCell.innerHTML = parseFloat(locations[i].quantity_on_hand) + qohCell.innerHTML = parseFloat(locations[i].item_quantity_on_hand) tableRow.append(zoneCell, locationCell, qohCell) tableRow.onclick = async function(){ await selectLocation( - locations[i].zone_id, - locations[i].id, + locations[i].zone_uuid, + locations[i].location_uuid, loca[0], loca[1] ) @@ -182,7 +176,7 @@ async function getItemLocations() { let items_limit = 50; async function getItems() { console.log("getting items") - const url = new URL('/items/getModalItems', window.location.origin); + const url = new URL('/items/api/getModalItems', window.location.origin); url.searchParams.append('page', pagination_current); url.searchParams.append('limit', items_limit); url.searchParams.append('search_string', search_string) @@ -193,10 +187,10 @@ async function getItems() { return items; } -async function getItem(id) { - console.log(`selected item: ${id}`) - const url = new URL('/items/getItem', window.location.origin); - url.searchParams.append('id', id); +async function getItem(item_uuid) { + console.log(`selected item: ${item_uuid}`) + const url = new URL('/items/api/getTransactionItem', window.location.origin); + url.searchParams.append('item_uuid', item_uuid); const response = await fetch(url); data = await response.json(); item = data.item; @@ -273,9 +267,7 @@ async function submitTransaction() { 'Content-Type': 'application/json', }, body: JSON.stringify({ - item_id: item.id, - logistics_info_id: item.logistics_info_id, - barcode: item.barcode, + item_uuid: item.item_uuid, item_name: item.item_name, transaction_type: document.getElementById('trans_type').value, quantity: parseFloat(document.getElementById('transaction_quantity').value), @@ -283,7 +275,7 @@ async function submitTransaction() { cost: cost, vendor: 0, expires: null, - location_id: transaction_item_location_id + location_id: transaction_location_uuid }), }); data = await response.json(); diff --git a/application/items/static/transactionsHandler.js b/application/items/static/transactionsHandler.js index 7047302..a2d76c8 100644 --- a/application/items/static/transactionsHandler.js +++ b/application/items/static/transactionsHandler.js @@ -4,21 +4,22 @@ var pagination_end = 10 var item; document.addEventListener('DOMContentLoaded', async function() { - item = await getItem(item_id); + //item = await getItem(item_uuid); let transactions = await getTransactions() + console.log(transactions) replenishTransactionsTable(transactions) updatePaginationElement() }) async function populateTransactionReceipt(transaction) { - document.getElementById('trans_barcode').innerHTML = transaction.barcode - document.getElementById('trans_database_id').innerHTML = transaction.id - document.getElementById('trans_timestamp').innerHTML = transaction.timestamp - document.getElementById('trans_name').innerHTML = transaction.name + document.getElementById('trans_barcode').innerHTML = '' + document.getElementById('trans_database_id').innerHTML = '' + document.getElementById('trans_timestamp').innerHTML = transaction.transaction_created_at + document.getElementById('trans_name').innerHTML = transaction.transaction_name document.getElementById('trans_type').innerHTML = transaction.transaction_type - document.getElementById('trans_qty').innerHTML = transaction.quantity - document.getElementById('trans_description').innerHTML = transaction.description - document.getElementById('trans_user').innerHTML = transaction.user_id + document.getElementById('trans_qty').innerHTML = transaction.transaction_quantity + document.getElementById('trans_description').innerHTML = transaction.transaction_description + document.getElementById('trans_user').innerHTML = transaction.transaction_created_by let receiptTableBody = document.getElementById('receiptTableBody') receiptTableBody.innerHTML = "" @@ -38,8 +39,7 @@ async function populateTransactionReceipt(transaction) { } } -async function inspectTransactions(id) { - let transaction = await getTransaction(id) +async function inspectTransactions(transaction) { await populateTransactionReceipt(transaction) UIkit.modal(document.getElementById("transactionModal")).show(); @@ -56,25 +56,25 @@ async function replenishTransactionsTable(transactions) { let timestampCell = document.createElement('td') - timestampCell.innerHTML = transactions[i].timestamp + timestampCell.innerHTML = transactions[i].transaction_created_at let barcodeCell = document.createElement('td') - barcodeCell.innerHTML = transactions[i].barcode + barcodeCell.innerHTML = '' let nameCell = document.createElement('td') - nameCell.innerHTML = transactions[i].name + nameCell.innerHTML = transactions[i].transaction_name let typeCell = document.createElement('td') typeCell.innerHTML = transactions[i].transaction_type let qtyCell = document.createElement('td') - qtyCell.innerHTML = transactions[i].quantity + qtyCell.innerHTML = transactions[i].transaction_quantity let descriptionCell = document.createElement('td') - descriptionCell.innerHTML = transactions[i].description + descriptionCell.innerHTML = transactions[i].transaction_description let userCell = document.createElement('td') - userCell.innerHTML = transactions[i].user_id + userCell.innerHTML = transactions[i].transaction_created_by tableRow.append( @@ -88,7 +88,7 @@ async function replenishTransactionsTable(transactions) { ) tableRow.onclick = async function() { - await inspectTransactions(transactions[i].id) + await inspectTransactions(transactions[i]) } transactionsTableBody.append(tableRow) @@ -96,7 +96,7 @@ async function replenishTransactionsTable(transactions) { } async function getItem(id) { - const url = new URL('/items/getItem', window.location.origin); + const url = new URL('/items/api/getItem', window.location.origin); url.searchParams.append('id', id); const response = await fetch(url); data = await response.json(); @@ -114,10 +114,10 @@ async function getTransaction(id) { } async function getTransactions(){ - const url = new URL('/items/getTransactions', window.location.origin); + const url = new URL('/items/api/getTransactions', window.location.origin); url.searchParams.append('page', pagination_current); url.searchParams.append('limit', limit); - url.searchParams.append('logistics_info_id', item.logistics_info_id) + url.searchParams.append('item_uuid', item_uuid) const response = await fetch(url); data = await response.json(); pagination_end = data.end diff --git a/application/items/templates/index.html b/application/items/templates/index.html index 6ab2d81..d5dcb24 100644 --- a/application/items/templates/index.html +++ b/application/items/templates/index.html @@ -15,7 +15,7 @@ - {% if session['user']['flags']['darkmode'] %} + {% if session['user']['user_flags']['darkmode'] %} {% endif %} @@ -25,10 +25,10 @@ - {% if session['user']['flags']['darkmode'] %} + {% if session['user']['user_flags']['darkmode'] %} {% else %} @@ -86,7 +86,7 @@