diff --git a/application/receipts/__pycache__/receipts_api.cpython-313.pyc b/application/receipts/__pycache__/receipts_api.cpython-313.pyc index e8bc1ce..d989544 100644 Binary files a/application/receipts/__pycache__/receipts_api.cpython-313.pyc and b/application/receipts/__pycache__/receipts_api.cpython-313.pyc differ diff --git a/application/receipts/receipts_api.py b/application/receipts/receipts_api.py index 401e326..c7336c0 100644 --- a/application/receipts/receipts_api.py +++ b/application/receipts/receipts_api.py @@ -126,7 +126,6 @@ def addSKULine(): site_name = session['selected_site'] item = receipts_database.getItemAllByID(site_name, (item_id, )) - #pprint.pprint(item) data = { 'cost': item['item_info']['cost'], 'expires': item['food_info']['expires'] @@ -145,6 +144,33 @@ def addSKULine(): return jsonify({'error': False, "message": "Line added Succesfully"}) return jsonify({'error': True, "message": "Something went wrong while add SKU line!"}) +@receipt_api.route('/api/addCustomLine', methods=["POST"]) +@access_api.login_required +def addCustomLine(): + if request.method == "POST": + receipt_id = int(request.get_json()['receipt_id']) + site_name = session['selected_site'] + print(receipt_id) + data = { + 'cost': request.get_json()['line_cost'], + 'expires': False + } + + receipt_item = database_payloads.ReceiptItemPayload( + type="custom", + receipt_id=receipt_id, + barcode=None, + item_uuid=None, + name=request.get_json()['line_name'], + qty=request.get_json()['line_qty'], + uom=request.get_json()['line_UOM'], + data=data + ) + receipts_database.insertReceiptItemsTuple(site_name, receipt_item.payload()) + return jsonify({'error': False, "message": "Line added Succesfully"}) + return jsonify({'error': True, "message": "Something went wrong while add SKU line!"}) + + @receipt_api.route('/api/deleteLine', methods=["POST"]) @access_api.login_required def deleteLine(): diff --git a/application/receipts/static/js/receiptHandler.js b/application/receipts/static/js/receiptHandler.js index 91d4ded..610f146 100644 --- a/application/receipts/static/js/receiptHandler.js +++ b/application/receipts/static/js/receiptHandler.js @@ -195,11 +195,6 @@ async function viewFile(source) { } -async function openCustomModal() { - console.log("custom") - -} - async function openLineEditModal(line_data) { console.log(line_data) document.getElementById('lineName').value = line_data.name @@ -287,6 +282,7 @@ async function uploadFile() { .then(response => response.json()) .then(data => console.log('File uploaded!', data)) .catch(error => console.error('Error:', error)); + await refreshReceipt() } async function saveLine(line_id){ @@ -364,6 +360,46 @@ async function getReceipt(id) { return receipt; } +// Custom Line Modal Functions +async function openAddCustomLineModal() { + console.log("custom") + document.getElementById('CustomlineName').value = "" + document.getElementById('CustomlineQty').value = 0 + document.getElementById('CustomlineUOM').value = 1 + document.getElementById('CustomlineCost').value = 0.00 + document.getElementById('saveCustomLineButton').innerHTML = "Add" + document.getElementById('saveCustomLineButton').onclick = async function() { + await addCustomLine() + } + + UIkit.modal(document.getElementById("CustomLineModal")).show(); +} + +async function addCustomLine(){ + let LineName = document.getElementById('CustomlineName').value + let LineQty = document.getElementById('CustomlineQty').value + let LineUOM = document.getElementById('CustomlineUOM').value + let LineCost = document.getElementById('CustomlineCost').value + console.log(LineName) + UIkit.modal(document.getElementById("CustomLineModal")).hide(); + + const response = await fetch(`/receipts/api/addCustomLine`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + line_name: LineName, + line_qty: LineQty, + line_UOM: LineUOM, + line_cost: LineCost, + receipt_id: receipt_id + }), + }); + await refreshReceipt() +} + + // SKU Modal functions let items_limit = 50; var ItemsModal_search_string = "" diff --git a/application/receipts/templates/receipt.html b/application/receipts/templates/receipt.html index 471d05b..845c4c6 100644 --- a/application/receipts/templates/receipt.html +++ b/application/receipts/templates/receipt.html @@ -184,7 +184,7 @@
@@ -336,6 +336,52 @@ + +| + | + |
|---|---|
| Name | ++ |
| QTY | ++ |
| UOM | ++ + | +
| COST | ++ |
+ + +
+