total = 0 products = [] menus = [] paymentMethod = null balance = 0 username = "" id = 0 function get_product(barcode){ res = $.get("getProduct/" + barcode, function(data){ add_product(data.pk, data.barcode, data.name, data.amount); }); } function get_menu(barcode){ res = $.get("getMenu/" + barcode, function(data){ add_menu(data.pk, data.barcode, data.name, data.amount); }); } function add_product(pk, barcode, name, amount){ exist = false index = -1 for(k=0;k < products.length; k++){ if(products[k].pk == pk){ exist = true index = k } } if(exist){ products[index].quantity += 1; }else{ products.push({"pk": pk, "barcode": barcode, "name": name, "amount": amount, "quantity": 1}); } generate_html() } function add_menu(pk, barcode, name, amount){ exist = false; index = -1; for(k=0; k < menus.length; k++){ if(menus[k].pk == pk){ exist = true; index = k; } } if(exist){ menus[index].quantity += 1; }else{ menus.push({"pk": pk, "barcode": barcode, "name": name, "amount": amount, "quantity":1}); } generate_html(); } function generate_html(){ html ="" for(k=0;k' + product.name + '' + String(product.amount) + '' + String(product.quantity * product.amount) + ''; } for(k=0; k' + menu.name + '' + String(menu.amount) + '' + String(menu.quantity * menu.amount) + ''; } $("#items").html(html) updateTotal(); } function updateTotal(){ total = 0 for(k=0;k