class SbTables(): def __init__(self, tableId=None): self.conn = DBSysbar().conn() self.cursor = self.conn.cursor() self.tableId = tableId def set_table_id(self, tableId): self.tableId = tableId def get_table_id(self): return self.tableId def get_tables_list(self): self.cursor.execute( "SELECT ID_table, table_price, busy_table, table_capacity FROM sb_tables" ) result = self.cursor.fetchall() if not result: return {'rStatus': 0} return {'rStatus': 1, 'data': result} def search_table(self, tableId): self.cursor.execute( "SELECT ID_table FROM sb_tables WHERE ID_table={}".format(tableId)) result = self.cursor.fetchone() if not result: return False return True
class SbBNUProduct(): def __init__(self): self.conn = DBSysbar().conn(False) self.cursor = self.conn.cursor() def get_product_id(self): return self.idProduct def set_product_id(self, idProduct): self.idProduct = idProduct def check_product_barcode(self, barcode): self.cursor.execute("SELECT ID_product FROM sb_product WHERE barcode='{}' LIMIT 1".format(barcode)) result = self.cursor.fetchone() if not result: return False return True def check_product_id(self): self.cursor.execute("SELECT ID_product FROM sb_meta_product WHERE ID_product='{}' LIMIT 1".format(self.idProduct)) result = self.cursor.fetchone() if not result: return False return True
class SbCategory(): def __init__(self, categoryId=None): self.conn = DBSysbar().conn() self.cursor = self.conn.cursor() self.categoryId = categoryId def set_category_id(self, categoryId): self.categoryId = categoryId def get_categories(self): self.cursor.execute( "SELECT ID_category, category FROM sb_list_categories") result = self.cursor.fetchall() if not result: return {'rStatus': 0} return {'rStatus': 1, 'data': result} def insert_category(self, name): try: self.cursor.execute( """INSERT INTO sb_list_categories (category, register) VALUES (?, ?)""", (name, datetime.now())) self.conn.commit() return True except: return False def update_category(self, name): print(self.categoryId) try: self.cursor.execute( """UPDATE sb_list_categories SET category = ?, register = ? WHERE ID_category = ?""", (name, datetime.now(), self.categoryId)) self.conn.commit() return True except: return False
class SbWProducts(): def __init__(self, idProduct=None): self.cursor = DBSysbar().conn(True) self.idProduct = idProduct def get_products_for_category(self, categoryId): self.cursor.execute( """SELECT sb_product.ID_product, sb_product.product_name, sb_product.product_description, sb_product.product_price, sb_product.product_stock, sb_product.stock_status, sb_meta_product.unity, sb_meta_product.amount FROM sb_product INNER JOIN sb_meta_product ON sb_product.ID_product=sb_meta_product.ID_product WHERE sb_meta_product.ID_category = {} AND sb_meta_product.virtual_menu='1'""" .format(categoryId)) result = self.cursor.fetchall() if not result: return {'rStatus': 0} items = {'rStatus': 1, 'data': []} for x in result: if x[5] == 1 and x[4] <= 0: continue items['data'].append({ 'ID_product': x[0], 'name': x[1], 'description': x[2], 'price': str(x[3]).replace(".", ","), 'unity': x[6], 'amount': x[7] }) return items def get_product_simple_info(self): self.cursor.execute( "SELECT sb_product.*, sb_meta_product.unity, sb_meta_product.amount, sb_meta_product.people_served FROM sb_product INNER JOIN sb_meta_product ON sb_meta_product.ID_product=sb_product.ID_product WHERE sb_product.ID_product='{}' LIMIT 1" .format(self.idProduct)) result = self.cursor.fetchone() if not result: return {'rStatus': 0} return { 'rStatus': 1, 'data': { 'id': result[0], 'barcode': result[1], 'name': result[2], 'description': result[4], 'ingre': result[5], 'price': str(result[6]).replace(".", ","), 'discount': json.loads(result[8]), 'stock': result[9], 'statusStock': result[10], 'unity': result[13], 'amount': str(result[14]).replace(".", ","), 'peopleServed': result[15], } }
def __init__(self, tableId=None): self.conn = DBSysbar().conn() self.cursor = self.conn.cursor() self.tableId = tableId
def __init__(self, categoryId=None): self.conn = DBSysbar().conn() self.cursor = self.conn.cursor() self.categoryId = categoryId
def __init__(self, idProduct=None): self.cursor = DBSysbar().conn(True) self.idProduct = idProduct
class SbProducts(): def __init__(self, idProduct=None): self.cursor = DBSysbar().conn(True) self.idProduct = idProduct def get_product_id(self): return self.idProduct def set_product_id(self, idProduct): self.idProduct = idProduct def get_product_list(self): self.cursor.execute( "SELECT ID_product, barcode, product_name, product_price, product_stock, stock_status FROM sb_product" ) result = self.cursor.fetchall() if not result: return {'rStatus': 0} return {'rStatus': 1, 'data': result} def get_product_info(self): self.cursor.execute( "SELECT sb_product.*, sb_meta_product.*, sb_list_categories.category FROM sb_product INNER JOIN sb_meta_product ON sb_product.ID_product=sb_meta_product.ID_product INNER JOIN sb_list_categories ON sb_meta_product.ID_category=sb_list_categories.ID_category WHERE sb_product.ID_product='{}' LIMIT 1" .format(self.idProduct)) result = self.cursor.fetchone() if not result: return {'rStatus': 0} return { 'rStatus': 1, 'data': { 'id': result[0], 'barcode': result[1], 'name': result[2], 'description': result[4], 'ingre': result[5], 'price': result[6], 'custPrice': result[7], 'discount': result[8], 'stock': result[9], 'statusStock': result[10], 'register': result[11], 'lastChange': result[12], 'virtualMenu': result[15], 'specialRequest': result[16], 'delivery': result[17], 'unity': result[18], 'amount': result[19], 'peopleServed': result[20], 'printer': result[21], 'category': result[22], 'idCategory': result[14] } } def search_product(self, code=False): if not code: self.cursor.execute( "SELECT ID_product, barcode, product_name, product_img, product_price, product_discount, product_stock, stock_status FROM sb_product WHERE ID_product='{}' LIMIT 1" .format(self.idProduct)) else: self.cursor.execute( "SELECT ID_product, barcode, product_name, product_img, product_price, product_discount, product_stock, stock_status FROM sb_product WHERE barcode='{}' LIMIT 1" .format(code)) result = self.cursor.fetchone() if not result: return {'rStatus': 0} return {'rStatus': 1, 'data': result}
def __init__(self): self.conn = DBSysbar().conn(False) self.cursor = self.conn.cursor()
def __init__(self, orderId=None): self.conn = DBSysbar().conn() self.cursor = self.conn.cursor() self.orderId = orderId
class SbOrders(): def __init__(self, orderId=None): self.conn = DBSysbar().conn() self.cursor = self.conn.cursor() self.orderId = orderId def set_order_id(self, orderId): self.orderId = orderId def get_order_id(self): return self.orderId def get_orders_list(self): self.cursor.execute( "SELECT sb_orders.ID_order, sb_orders.ID_comanda, sb_comandas.ID_table, sb_client.client_name, sb_product.ID_product, sb_product.product_name, sb_meta_product.printer, sb_orders.amount, sb_orders.comment, sb_orders.register FROM sb_orders INNER JOIN sb_comandas ON sb_orders.ID_comanda=sb_comandas.ID_comanda INNER JOIN sb_client ON sb_comandas.ID_client=sb_client.ID_client INNER JOIN sb_product ON sb_orders.ID_product=sb_product.ID_product INNER JOIN sb_meta_product ON sb_product.ID_product=sb_meta_product.ID_product WHERE order_status=1" ) result = self.cursor.fetchall() if not result: return {'rStatus': 0} items = {'rStatus': 1, 'data': {}} for x in result: if x[1] in items['data']: if x[6] == 1: items['data'][x[1]]['printer'].append({ 'ID_order': x[0], 'ID_product': x[4], 'name': x[5], 'amount': x[7], 'comment': x[8], 'register': x[9] }) else: items['data'][x[1]]['items'].append({ 'ID_order': x[0], 'ID_product': x[4], 'name': x[5], 'amount': x[7], 'comment': x[8], 'register': x[9] }) else: items['data'][x[1]] = { 'ID_comanda': x[1], 'ID_table': x[2], 'client_name': x[3], 'printer': [], 'items': [] } if x[6] == 1: items['data'][x[1]]['printer'].append({ 'ID_order': x[0], 'ID_product': x[4], 'name': x[5], 'amount': x[7], 'comment': x[8], 'register': x[9] }) else: items['data'][x[1]]['items'].append({ 'ID_order': x[0], 'ID_product': x[4], 'name': x[5], 'amount': x[7], 'comment': x[8], 'register': x[9] }) return items def get_order_info(self): self.cursor.execute( "SELECT sb_orders.ID_order, sb_orders.ID_comanda, sb_comandas.ID_table, sb_client.ID_client, sb_client.client_name, sb_product.ID_product, sb_product.product_name, sb_orders.price, sb_orders.amount, sb_orders.discount, sb_orders.shared, sb_orders.comment, sb_orders.order_status, sb_orders.register FROM sb_orders INNER JOIN sb_comandas ON sb_orders.ID_comanda=sb_comandas.ID_comanda INNER JOIN sb_client ON sb_comandas.ID_client=sb_client.ID_client INNER JOIN sb_product ON sb_orders.ID_product=sb_product.ID_product INNER JOIN sb_meta_product ON sb_product.ID_product=sb_meta_product.ID_product WHERE ID_order={} LIMIT 1" .format(self.orderId)) result = self.cursor.fetchone() if not result: return {'rStatus': 0} return { 'rStatus': 1, 'data': { 'ID_comanda': result[1], 'ID_table': result[2], 'ID_client': result[3], 'client_name': result[4], 'item': { 'ID_order': result[0], 'ID_product': result[5], 'name': result[6], 'price': result[7], 'amount': result[8], 'discount': result[9], 'shared': result[10], 'comment': result[11], 'order_status': result[12], 'register': result[13] } } }