updated receipts linking to be barcode based
This commit is contained in:
parent
ce61b21a9e
commit
8b265bb4f0
Binary file not shown.
Binary file not shown.
@ -197,6 +197,19 @@ def postLinkedItem():
|
|||||||
return jsonify({'error': False, "message": "Line Saved Succesfully"})
|
return jsonify({'error': False, "message": "Line Saved Succesfully"})
|
||||||
return jsonify({'error': True, "message": "Something went wrong while saving line!"})
|
return jsonify({'error': True, "message": "Something went wrong while saving line!"})
|
||||||
|
|
||||||
|
@receipt_api.route('/api/saveBarcodeLink', methods=["POST"])
|
||||||
|
@access_api.login_required
|
||||||
|
def saveBarcodeLink():
|
||||||
|
if request.method == "POST":
|
||||||
|
print(request.get_json())
|
||||||
|
site_name = session['selected_site']
|
||||||
|
user_id = session['user_id']
|
||||||
|
receipts_processes.linkBarcodeToItem(site_name, user_id, request.get_json())
|
||||||
|
#receipts_processes.linkItem(site_name, user_id, payload)
|
||||||
|
|
||||||
|
return jsonify({'error': False, "message": "Line Saved Succesfully"})
|
||||||
|
return jsonify({'error': True, "message": "Something went wrong while saving line!"})
|
||||||
|
|
||||||
@receipt_api.route('/api/resolveLine', methods=["POST"])
|
@receipt_api.route('/api/resolveLine', methods=["POST"])
|
||||||
@access_api.login_required
|
@access_api.login_required
|
||||||
def resolveLine():
|
def resolveLine():
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import PIL
|
|||||||
import openfoodfacts
|
import openfoodfacts
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import datetime
|
import datetime
|
||||||
|
import pprint
|
||||||
# APPLICATION IMPORTS
|
# APPLICATION IMPORTS
|
||||||
from application.receipts import receipts_database
|
from application.receipts import receipts_database
|
||||||
from application import database_payloads
|
from application import database_payloads
|
||||||
@ -23,6 +23,52 @@ def create_pdf_preview(pdf_path, output_path, size=(600, 400)):
|
|||||||
img.save(output_path)
|
img.save(output_path)
|
||||||
return file_name + '.jpg'
|
return file_name + '.jpg'
|
||||||
|
|
||||||
|
def linkBarcodeToItem(site, user_id, data, conn=None):
|
||||||
|
self_conn = False
|
||||||
|
if not conn:
|
||||||
|
database_config = config.config()
|
||||||
|
conn = psycopg2.connect(**database_config)
|
||||||
|
conn.autocommit = False
|
||||||
|
self_conn = True
|
||||||
|
|
||||||
|
receipt_item_id = data['receipt_item_id']
|
||||||
|
payload = data['payload']
|
||||||
|
item_uuid = payload['item_uuid']
|
||||||
|
|
||||||
|
receipt_item = receipts_database.selectReceiptItemsTuple(site, (receipt_item_id,))
|
||||||
|
item = receipts_database.getItemAllByUUID(site, (item_uuid,))
|
||||||
|
|
||||||
|
barcode_tuple = database_payloads.BarcodesPayload(
|
||||||
|
barcode=receipt_item['barcode'],
|
||||||
|
item_uuid=item_uuid,
|
||||||
|
in_exchange=payload['in_exchange'],
|
||||||
|
out_exchange=payload['out_exchange'],
|
||||||
|
descriptor=payload['descriptor']
|
||||||
|
)
|
||||||
|
|
||||||
|
receipts_database.insertBarcodesTuple(site, barcode_tuple.payload(), conn=conn)
|
||||||
|
|
||||||
|
new_data = receipt_item['data']
|
||||||
|
new_quantity = float(receipt_item['qty'] * payload['in_exchange'])
|
||||||
|
new_data['expires'] = item['food_info']['expires']
|
||||||
|
receipts_item_update = {'id': receipt_item_id, 'update': {
|
||||||
|
'type': 'sku',
|
||||||
|
'name': item['item_name'],
|
||||||
|
'uom': item['item_info']['uom']['id'],
|
||||||
|
'item_uuid': item['item_uuid'],
|
||||||
|
'data': new_data,
|
||||||
|
'qty': new_quantity
|
||||||
|
}}
|
||||||
|
|
||||||
|
receipts_database.updateReceiptItemsTuple(site, receipts_item_update, conn=conn)
|
||||||
|
|
||||||
|
if self_conn:
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
return False
|
||||||
|
|
||||||
|
return conn
|
||||||
|
|
||||||
def linkItem(site, user_id, data, conn=None):
|
def linkItem(site, user_id, data, conn=None):
|
||||||
""" this is a higher level function used to process a new item into the system,
|
""" this is a higher level function used to process a new item into the system,
|
||||||
link it to another item, and update the receipt_item to the new linked item data.
|
link it to another item, and update the receipt_item to the new linked item data.
|
||||||
@ -119,6 +165,7 @@ def postLine(site, user_id, data, conn=None):
|
|||||||
expiration = None
|
expiration = None
|
||||||
|
|
||||||
#if receipt_item['type'] == 'sku':
|
#if receipt_item['type'] == 'sku':
|
||||||
|
# receipts_database.get
|
||||||
# linked_item = receipts_database.getLinkedItemByBarcode(site, (receipt_item['barcode'], ), conn=conn)
|
# linked_item = receipts_database.getLinkedItemByBarcode(site, (receipt_item['barcode'], ), conn=conn)
|
||||||
# if len(linked_item) > 1:
|
# if len(linked_item) > 1:
|
||||||
# conv_factor = linked_item['conv_factor']
|
# conv_factor = linked_item['conv_factor']
|
||||||
|
|||||||
@ -118,7 +118,7 @@ async function replenishLinesTable(receipt_items) {
|
|||||||
linkOp.setAttribute('class', 'uk-button uk-button-small uk-button-default')
|
linkOp.setAttribute('class', 'uk-button uk-button-small uk-button-default')
|
||||||
linkOp.setAttribute('uk-icon', 'icon: link')
|
linkOp.setAttribute('uk-icon', 'icon: link')
|
||||||
linkOp.onclick = async function () {
|
linkOp.onclick = async function () {
|
||||||
await openLinksSelectModal(receipt_items[i].id)
|
await openItemBarcodeSelectModal(receipt_items[i].id)
|
||||||
}
|
}
|
||||||
|
|
||||||
let editOp = document.createElement('a')
|
let editOp = document.createElement('a')
|
||||||
@ -871,3 +871,176 @@ async function updateLinksPaginationElement() {
|
|||||||
}
|
}
|
||||||
paginationElement.append(nextElement)
|
paginationElement.append(nextElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Select Barcode Link Functions
|
||||||
|
var ItemBarcodeSelectModal_limit = 50
|
||||||
|
var ItemBarcodeSelectModal_page = 1
|
||||||
|
var ItemBarcodeSelectModal_page_end = 1
|
||||||
|
var selectedReceiptItemID = 0
|
||||||
|
|
||||||
|
async function openItemBarcodeSelectModal(receipt_item_id) {
|
||||||
|
selectedReceiptItemID = receipt_item_id
|
||||||
|
await setupItemsBarcodeSelect()
|
||||||
|
UIkit.modal(document.getElementById("ItemBarcodeSelectModal")).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setupItemsBarcodeSelect() {
|
||||||
|
let items = await getItemsForModal()
|
||||||
|
await generateItemsBarcodeSelectTable(items)
|
||||||
|
await updateItemsBarcodeSelectPagination()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function generateItemsBarcodeSelectTable(items) {
|
||||||
|
let ItemBarcodeSelectTable = document.getElementById('ItemBarcodeSelectTable')
|
||||||
|
ItemBarcodeSelectTable.innerHTML = ""
|
||||||
|
|
||||||
|
for(let i = 0; i < items.length; i++){
|
||||||
|
let tableRow = document.createElement('tr')
|
||||||
|
|
||||||
|
let nameCell = document.createElement('td')
|
||||||
|
nameCell.innerHTML = items[i].item_name
|
||||||
|
|
||||||
|
let inCell = document.createElement('td')
|
||||||
|
inCell.innerHTML = `<input id="${items[i].item_uuid}_in" class="uk-input" type="number" value="1" aria-label="Input">`
|
||||||
|
|
||||||
|
let outCell = document.createElement('td')
|
||||||
|
outCell.innerHTML = `<input id="${items[i].item_uuid}_out" class="uk-input" type="number" value="1" aria-label="Input">`
|
||||||
|
|
||||||
|
let descriptorCell = document.createElement('td')
|
||||||
|
descriptorCell.innerHTML = `<input id="${items[i].item_uuid}_descriptor" class="uk-input" type="text" value="${items[i].item_name}" aria-label="Input">`
|
||||||
|
|
||||||
|
|
||||||
|
let opCell = document.createElement('td')
|
||||||
|
|
||||||
|
let selectButton = document.createElement('button')
|
||||||
|
selectButton.setAttribute('class', 'uk-button uk-button-small uk-button-primary')
|
||||||
|
selectButton.innerHTML = "Select"
|
||||||
|
selectButton.onclick = async function() {
|
||||||
|
let payload = {
|
||||||
|
item_uuid: items[i].item_uuid,
|
||||||
|
in_exchange: parseFloat(document.getElementById(`${items[i].item_uuid}_in`).value),
|
||||||
|
out_exchange: parseFloat(document.getElementById(`${items[i].item_uuid}_out`).value),
|
||||||
|
descriptor: document.getElementById(`${items[i].item_uuid}_descriptor`).value
|
||||||
|
}
|
||||||
|
await updateReceiptItemBarcode(payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
opCell.append(selectButton)
|
||||||
|
|
||||||
|
tableRow.append(nameCell, inCell, outCell, descriptorCell, opCell)
|
||||||
|
|
||||||
|
ItemBarcodeSelectTable.append(tableRow)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
const response = await fetch(url);
|
||||||
|
data = await response.json();
|
||||||
|
ItemBarcodeSelectModal_page_end = data.end
|
||||||
|
let items = data.items;
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateItemsBarcodeSelectPagination() {
|
||||||
|
let paginationElement = document.getElementById("ItemBarcodeSelectModalPage");
|
||||||
|
paginationElement.innerHTML = "";
|
||||||
|
// previous
|
||||||
|
let previousElement = document.createElement('li')
|
||||||
|
if(pagination_current<=1){
|
||||||
|
previousElement.innerHTML = `<a><span uk-pagination-previous></span></a>`;
|
||||||
|
previousElement.classList.add('uk-disabled');
|
||||||
|
}else {
|
||||||
|
previousElement.innerHTML = `<a onclick="ItemBarcodeSelectModalPage(${ItemBarcodeSelectModal_page-1})"><span uk-pagination-previous></span></a>`;
|
||||||
|
}
|
||||||
|
paginationElement.append(previousElement)
|
||||||
|
|
||||||
|
//first
|
||||||
|
let firstElement = document.createElement('li')
|
||||||
|
if(pagination_current<=1){
|
||||||
|
firstElement.innerHTML = `<a><strong>1</strong></a>`;
|
||||||
|
firstElement.classList.add('uk-disabled');
|
||||||
|
}else {
|
||||||
|
firstElement.innerHTML = `<a onclick="ItemBarcodeSelectModalPage(1)">1</a>`;
|
||||||
|
}
|
||||||
|
paginationElement.append(firstElement)
|
||||||
|
|
||||||
|
// ...
|
||||||
|
if(pagination_current-2>1){
|
||||||
|
let firstDotElement = document.createElement('li')
|
||||||
|
firstDotElement.classList.add('uk-disabled')
|
||||||
|
firstDotElement.innerHTML = `<span>…</span>`;
|
||||||
|
paginationElement.append(firstDotElement)
|
||||||
|
}
|
||||||
|
// last
|
||||||
|
if(ItemBarcodeSelectModal_page-2>0){
|
||||||
|
let lastElement = document.createElement('li')
|
||||||
|
lastElement.innerHTML = `<a onclick="ItemBarcodeSelectModalPage(${ItemBarcodeSelectModal_page-1})">${ItemBarcodeSelectModal_page-1}</a>`
|
||||||
|
paginationElement.append(lastElement)
|
||||||
|
}
|
||||||
|
// current
|
||||||
|
if(ItemBarcodeSelectModal_page!=1 && ItemBarcodeSelectModal_page != ItemBarcodeSelectModal_page_end){
|
||||||
|
let currentElement = document.createElement('li')
|
||||||
|
currentElement.innerHTML = `<li class="uk-active"><span aria-current="page"><strong>${ItemBarcodeSelectModal_page}</strong></span></li>`
|
||||||
|
paginationElement.append(currentElement)
|
||||||
|
}
|
||||||
|
// next
|
||||||
|
if(ItemBarcodeSelectModal_page+2<ItemBarcodeSelectModal_page_end+1){
|
||||||
|
let nextElement = document.createElement('li')
|
||||||
|
nextElement.innerHTML = `<a onclick="ItemBarcodeSelectModalPage(${ItemBarcodeSelectModal_page+1})">${ItemBarcodeSelectModal_page+1}</a>`
|
||||||
|
paginationElement.append(nextElement)
|
||||||
|
}
|
||||||
|
// ...
|
||||||
|
if(ItemBarcodeSelectModal_page+2<=ItemBarcodeSelectModal_page_end){
|
||||||
|
let secondDotElement = document.createElement('li')
|
||||||
|
secondDotElement.classList.add('uk-disabled')
|
||||||
|
secondDotElement.innerHTML = `<span>…</span>`;
|
||||||
|
paginationElement.append(secondDotElement)
|
||||||
|
}
|
||||||
|
//end
|
||||||
|
let endElement = document.createElement('li')
|
||||||
|
if(pagination_current>=ItemBarcodeSelectModal_page_end){
|
||||||
|
endElement.innerHTML = `<a><strong>${ItemBarcodeSelectModal_page_end}</strong></a>`;
|
||||||
|
endElement.classList.add('uk-disabled');
|
||||||
|
}else {
|
||||||
|
endElement.innerHTML = `<a onclick="ItemBarcodeSelectModalPage(${ItemBarcodeSelectModal_page_end})">${ItemBarcodeSelectModal_page_end}</a>`;
|
||||||
|
}
|
||||||
|
paginationElement.append(endElement)
|
||||||
|
//next button
|
||||||
|
let nextElement = document.createElement('li')
|
||||||
|
if(pagination_current>=ItemBarcodeSelectModal_page_end){
|
||||||
|
nextElement.innerHTML = `<a><span uk-pagination-next></span></a>`;
|
||||||
|
nextElement.classList.add('uk-disabled');
|
||||||
|
}else {
|
||||||
|
nextElement.innerHTML = `<a onclick="ItemBarcodeSelectModalPage(${ItemBarcodeSelectModal_page+1})"><span uk-pagination-next></span></a>`;
|
||||||
|
console.log(nextElement.innerHTML)
|
||||||
|
}
|
||||||
|
paginationElement.append(nextElement)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ItemBarcodeSelectModalPage(pageNumber){
|
||||||
|
ItemBarcodeSelectModal_page = pageNumber;
|
||||||
|
await setupItemsBarcodeSelect()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateReceiptItemBarcode(payload) {
|
||||||
|
|
||||||
|
UIkit.modal(document.getElementById("ItemBarcodeSelectModal")).hide();
|
||||||
|
|
||||||
|
const response = await fetch(`/receipts/api/saveBarcodeLink`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
receipt_item_id: selectedReceiptItemID,
|
||||||
|
payload: payload
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
await refreshReceipt()
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -296,6 +296,38 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- ItemBarcodeSelect Modal -->
|
||||||
|
<div id="ItemBarcodeSelectModal" class="uk-modal-container" uk-modal>
|
||||||
|
<div id="ItemBarcodeSelectModalInner" class="uk-modal-dialog uk-modal-body " uk-overflow-auto>
|
||||||
|
<h2 class="uk-modal-title">Select Item</h2>
|
||||||
|
<p>Select an Item from the system...</p>
|
||||||
|
<nav aria-label="Pagination">
|
||||||
|
<ul id="ItemBarcodeSelectModalPage" class="uk-pagination uk-flex-center" uk-margin>
|
||||||
|
<li><a href="#"><span uk-pagination-previous></span></a></li>
|
||||||
|
<li><a href="#">1</a></li>
|
||||||
|
<li class="uk-disabled"><span>…</span></li>
|
||||||
|
<li><a href="#">5</a></li>
|
||||||
|
<li><a href="#">6</a></li>
|
||||||
|
<li class="uk-active"><span aria-current="page">7</span></li>
|
||||||
|
<li><a href="#">8</a></li>
|
||||||
|
<li><a href="#"><span uk-pagination-next></span></a></li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<table class="uk-table uk-table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>In Exchange</th>
|
||||||
|
<th>Out Exchange</th>
|
||||||
|
<th>Descriptor</th>
|
||||||
|
<th>Operations</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="ItemBarcodeSelectTable">
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<!-- SKU LinkedList Modal -->
|
<!-- SKU LinkedList Modal -->
|
||||||
<div id="linksModal" class="uk-modal-container" uk-modal>
|
<div id="linksModal" class="uk-modal-container" uk-modal>
|
||||||
<div id="linksModalInner" class="uk-modal-dialog uk-modal-body " uk-overflow-auto>
|
<div id="linksModalInner" class="uk-modal-dialog uk-modal-body " uk-overflow-auto>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user