2024-08-04 10:29:43 +02:00
|
|
|
var all_products
|
|
|
|
|
|
2024-08-04 11:01:52 +02:00
|
|
|
let barcodeForm
|
|
|
|
|
|
2024-08-04 17:59:05 +02:00
|
|
|
const api_url = "http://127.0.0.1:8000"
|
|
|
|
|
|
|
|
|
|
var to_fill_product_index = 0
|
|
|
|
|
|
2024-08-05 13:14:24 +02:00
|
|
|
var total_price = 0
|
|
|
|
|
|
2024-08-04 10:19:24 +02:00
|
|
|
async function makeAPIRequest(request) {
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(request);
|
|
|
|
|
const result = await response.json();
|
|
|
|
|
return result
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error:", error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-24 13:21:02 +02:00
|
|
|
async function loadCash(price) {
|
|
|
|
|
const cashAmountRequest = new Request(api_url + '/price_to_cash/' + price)
|
|
|
|
|
const cashAmount = await makeAPIRequest(cashAmountRequest)
|
|
|
|
|
|
|
|
|
|
const cash_bills_row = document.getElementById('cash_bills')
|
|
|
|
|
|
|
|
|
|
for (var bill_type in cashAmount){
|
|
|
|
|
bill_amount = cashAmount[bill_type]
|
|
|
|
|
console.log(bill_type, bill_amount)
|
|
|
|
|
for (var x = 0; x < bill_amount; x++){
|
|
|
|
|
const new_column = document.createElement('div')
|
|
|
|
|
new_column.classList.add('col')
|
|
|
|
|
new_column.innerHTML = bill_type
|
|
|
|
|
cash_bills_row.appendChild(new_column)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-04 10:19:24 +02:00
|
|
|
async function loadProducts() {
|
2024-08-04 17:59:05 +02:00
|
|
|
const loadProductRequest = new Request(api_url + "/products")
|
2024-08-04 10:29:43 +02:00
|
|
|
all_products = await makeAPIRequest(loadProductRequest)
|
|
|
|
|
console.log("Loaded products:", all_products)
|
2024-08-04 17:59:05 +02:00
|
|
|
|
2024-08-04 11:01:52 +02:00
|
|
|
barcodeForm = document.getElementById("barcode_form");
|
2024-08-04 17:59:05 +02:00
|
|
|
|
2024-08-04 11:01:52 +02:00
|
|
|
barcodeForm.addEventListener("submit", (e) => {
|
|
|
|
|
e.preventDefault();
|
2024-08-05 18:05:41 +02:00
|
|
|
|
|
|
|
|
if (to_fill_product_index < 5) {
|
2024-08-04 11:01:52 +02:00
|
|
|
|
2024-08-05 18:05:41 +02:00
|
|
|
const barcode = document.getElementById('barcode_input').value
|
|
|
|
|
var chosen_product
|
|
|
|
|
for (index = 0; index < all_products.length; index++) {
|
|
|
|
|
if (all_products[index].barcode == barcode) {
|
|
|
|
|
chosen_product = all_products[index]
|
|
|
|
|
}
|
2024-08-04 11:01:52 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-05 18:05:41 +02:00
|
|
|
barcode_input.value = ""
|
|
|
|
|
|
|
|
|
|
const product_placeholders = document.getElementsByClassName('product_col')
|
|
|
|
|
const chosen_product_placeholder = product_placeholders[to_fill_product_index]
|
|
|
|
|
const image_product = chosen_product_placeholder.getElementsByClassName('product_image')[0]
|
|
|
|
|
const price_product = chosen_product_placeholder.getElementsByClassName('product_price')[0]
|
|
|
|
|
const total_price_holder = document.getElementById("totalprice")
|
|
|
|
|
|
|
|
|
|
total_price += chosen_product.price
|
|
|
|
|
|
|
|
|
|
image_product.setAttribute('src', api_url + "/icons/" + chosen_product.image_filename);
|
|
|
|
|
price_product.textContent = "\u20AC " + chosen_product.price
|
|
|
|
|
total_price_holder.textContent = "\u20AC " + total_price
|
2024-08-04 17:59:05 +02:00
|
|
|
|
2024-08-05 18:05:41 +02:00
|
|
|
to_fill_product_index += 1
|
|
|
|
|
}else{
|
|
|
|
|
barcode_input.value = ""
|
|
|
|
|
}
|
2024-08-04 11:01:52 +02:00
|
|
|
});
|
2024-08-04 17:59:05 +02:00
|
|
|
|
2024-08-04 11:01:52 +02:00
|
|
|
}
|