diff --git a/__pycache__/admin.cpython-312.pyc b/__pycache__/admin.cpython-312.pyc new file mode 100644 index 0000000..bb65872 Binary files /dev/null and b/__pycache__/admin.cpython-312.pyc differ diff --git a/__pycache__/api.cpython-312.pyc b/__pycache__/api.cpython-312.pyc index cc6fb28..bbf1038 100644 Binary files a/__pycache__/api.cpython-312.pyc and b/__pycache__/api.cpython-312.pyc differ diff --git a/__pycache__/config.cpython-312.pyc b/__pycache__/config.cpython-312.pyc index 034c139..7cae409 100644 Binary files a/__pycache__/config.cpython-312.pyc and b/__pycache__/config.cpython-312.pyc differ diff --git a/__pycache__/html_factory.cpython-312.pyc b/__pycache__/html_factory.cpython-312.pyc new file mode 100644 index 0000000..fa7ca7c Binary files /dev/null and b/__pycache__/html_factory.cpython-312.pyc differ diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc index 071609e..9f98366 100644 Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ diff --git a/__pycache__/manage.cpython-312.pyc b/__pycache__/manage.cpython-312.pyc new file mode 100644 index 0000000..659efe4 Binary files /dev/null and b/__pycache__/manage.cpython-312.pyc differ diff --git a/__pycache__/user_api.cpython-312.pyc b/__pycache__/user_api.cpython-312.pyc new file mode 100644 index 0000000..570b711 Binary files /dev/null and b/__pycache__/user_api.cpython-312.pyc differ diff --git a/admin.py b/admin.py new file mode 100644 index 0000000..b5d3477 --- /dev/null +++ b/admin.py @@ -0,0 +1,122 @@ +from flask import Blueprint, request, render_template, redirect, session, url_for, send_file, jsonify, Response +import psycopg2, math, json, datetime, main, copy, requests, html_factory +from config import config, sites_config +from main import unfoldCostLayers, get_sites, get_roles, create_site_secondary, getUser +from manage import create + +admin = Blueprint('admin_api', __name__) + +@admin.route("/admin/getSites") +def getSites(): + sites = get_sites(session.get('user')[13]) + return jsonify(sites=sites) + +@admin.route("/getRoles") +def getRoles(): + sites_roles = {} + sites = get_sites(session.get('user')[13]) + for site in sites: + site_roles = get_roles(site_id=site[0]) + sites_roles[site[1]] = site_roles + return jsonify(sites=sites_roles) + +@admin.route("/admin/getUsers", methods=["POST"]) +def getUsers(): + if request.method == "POST": + page = request.get_json()['page'] + limit = request.get_json()['limit'] + offset = (page - 1) * limit + + database_config = config() + with psycopg2.connect(**database_config) as conn: + try: + with conn.cursor() as cur: + sql = f"SELECT * FROM logins LIMIT %s OFFSET %s;" + cur.execute(sql, (limit, offset)) + users = cur.fetchall() + cur.execute("SELECT COUNT(*) FROM main_items;") + count = cur.fetchone()[0] + return jsonify(users=users, endpage=math.ceil(count/limit)) + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return jsonify(message="FAILED") + return jsonify(message="FAILED") + + +@admin.route("/admin/editRole/") +def getRole(id): + database_config = config() + with psycopg2.connect(**database_config) as conn: + try: + with conn.cursor() as cur: + sql = f"SELECT * FROM roles LEFT JOIN sites ON sites.id = roles.site_id WHERE roles.id = %s;" + cur.execute(sql, (id, )) + role = cur.fetchone() + return render_template("admin/role.html", role=role, proto={'referrer': request.referrer}) + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return jsonify(message="FAILED") + +@admin.route("/addRole", methods=["POST"]) +def addRole(): + if request.method == "POST": + role_name = request.get_json()['role_name'] + role_description = request.get_json()['role_description'] + site_id = request.get_json()['site_id'] + + + sql = f"INSERT INTO roles (role_name, role_description, site_id) VALUES (%s, %s, %s);" + print(role_name, role_description, site_id) + + + database_config = config() + with psycopg2.connect(**database_config) as conn: + try: + with conn.cursor() as cur: + data = (role_name, role_description, site_id) + cur.execute(sql, data) + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return jsonify(message="FAILED") + + return jsonify(message="SUCCESS") + + return jsonify(message="FAILED") + +@admin.route("/deleteRole", methods=["POST"]) +def deleteRole(): + if request.method == "POST": + role_id = request.get_json()['role_id'] + database_config = config() + with psycopg2.connect(**database_config) as conn: + try: + with conn.cursor() as cur: + sql = f"DELETE FROM roles WHERE roles.id = %s;" + cur.execute(sql, (role_id, )) + return jsonify(message="Role Deleted!") + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return jsonify(message=error) + return jsonify(message="FAILED") + +@admin.route("/addSite", methods=["POST"]) +async def addSite(): + if request.method == "POST": + site_name = request.get_json()['site_name'] + site_description = request.get_json()['site_description'] + default_zone = request.get_json()["default_zone"] + default_location = request.get_json()['default_location'] + username = session.get('user')[1] + user_id = session.get('user')[0] + + create(site_name, username, default_zone, default_location) + result = await create_site_secondary(site_name, user_id, default_zone, default_location, default_location, site_description) + + if result: + return jsonify(message="Success!") + + return jsonify(message="Failed!") \ No newline at end of file diff --git a/api.py b/api.py index 3ae5527..e4cdea9 100644 --- a/api.py +++ b/api.py @@ -116,8 +116,11 @@ def paginate_groups(): print(group[3]) for item_id in group[3]: cur.execute(sql_item, (item_id,)) - item_row = cur.fetchone() - qty += float(item_row[2]) + item_row = list(cur.fetchone()) + cur.execute(f"SELECT quantity_on_hand FROM {site_name}_item_locations WHERE part_id=%s;", (item_id, )) + item_locations = cur.fetchall()[0] + qty += float(sum(item_locations)) + item_row[2] = sum(item_locations) items.append(item_row) group[3] = items group.append(qty) @@ -1060,10 +1063,15 @@ def paginate_lists(): custom_items = shopping_list[4] list_length = len(custom_items) + sqlfile = open(f"sites/{site_name}/sql/unique/shopping_lists_safetystock_count.sql", "r+") + sql = "\n".join(sqlfile.readlines()) + sqlfile.close() + print(sql) if shopping_list[10] == 'calculated': - item_sql = f"SELECT COUNT(*) FROM {site_name}_items LEFT JOIN {site_name}_logistics_info ON {site_name}_items.logistics_info_id = {site_name}_logistics_info.id LEFT JOIN {site_name}_item_info ON {site_name}_items.item_info_id = {site_name}_item_info.id LEFT JOIN {site_name}_food_info ON {site_name}_items.food_info_id = {site_name}_food_info.id WHERE {site_name}_logistics_info.quantity_on_hand < {site_name}_item_info.safety_stock AND shopping_lists @> ARRAY[%s];" - cur.execute(item_sql, (shopping_list[0], )) + print(shopping_list[0]) + cur.execute(sql, (shopping_list[0], )) list_length += cur.fetchone()[0] + else: list_length += len(pantry_items) @@ -1089,13 +1097,17 @@ def get_list_view(): shopping_list = list(cur.fetchone()) if shopping_list[10] == "calculated": - itemSQL = f"SELECT {site_name}_items.id, {site_name}_items.barcode, {site_name}_items.item_name, {site_name}_items.links, {site_name}_logistics_info.quantity_on_hand, {site_name}_item_info.safety_stock, {site_name}_item_info.uom FROM {site_name}_items LEFT JOIN {site_name}_logistics_info ON {site_name}_items.logistics_info_id = {site_name}_logistics_info.id LEFT JOIN {site_name}_item_info ON {site_name}_items.item_info_id = {site_name}_item_info.id LEFT JOIN {site_name}_food_info ON {site_name}_items.food_info_id = {site_name}_food_info.id WHERE {site_name}_logistics_info.quantity_on_hand < {site_name}_item_info.safety_stock AND shopping_lists @> ARRAY[%s];" + sqlfile = open(f"sites/{site_name}/sql/unique/shopping_lists_safetystock.sql", "r+") + sql = "\n".join(sqlfile.readlines()) + sqlfile.close() else: - itemSQL = f"SELECT {site_name}_items.id, {site_name}_items.barcode, {site_name}_items.item_name, {site_name}_items.links, {site_name}_logistics_info.quantity_on_hand, {site_name}_item_info.safety_stock, {site_name}_item_info.uom FROM {site_name}_items LEFT JOIN {site_name}_logistics_info ON {site_name}_items.logistics_info_id = {site_name}_logistics_info.id LEFT JOIN {site_name}_item_info ON {site_name}_items.item_info_id = {site_name}_item_info.id LEFT JOIN {site_name}_food_info ON {site_name}_items.food_info_id = {site_name}_food_info.id WHERE shopping_lists @> ARRAY[%s];" - - cur.execute(itemSQL, (id, )) + sqlfile = open(f"sites/{site_name}/sql/unique/shopping_lists_safetystock_uncalculated.sql", "r+") + sql = "\n".join(sqlfile.readlines()) + sqlfile.close() + + cur.execute(sql, (id, )) shopping_list[3] = list(cur.fetchall()) - print(shopping_list) + print(shopping_list[4]) except (Exception, psycopg2.DatabaseError) as error: print(error) diff --git a/config.py b/config.py index 0d83e02..b883f0a 100644 --- a/config.py +++ b/config.py @@ -27,20 +27,33 @@ def sites_config(filename='database.ini', section='manage'): parser.read(filename) # get section, default to postgresql - sites = {} + instance_config = {} + first_setup = False if parser.has_section(section): - params = parser.items(section) + params = parser.items(section) + print(params) for param in params: - sites[param[0]] = param[1].split(',') + instance_config[param[0]] = param[1].split(',') else: raise Exception('Section {0} not found in the {1} file'.format(section, filename)) - return sites + instance_config['first_setup'] = parser.getboolean('manage', 'first_setup') + instance_config['signup_enabled'] = parser.getboolean('manage', 'signup_enabled') + print(instance_config) + return instance_config + +def setFirstSetupDone(): + config = ConfigParser() + config.read('database.ini') + config.set('manage', 'first_setup', 'False') + with open('database.ini', 'w') as configFile: + config.write(configFile) + def write_new_site(site_name): - old_value = sites_config()['sites'] + old_value = [site for site in sites_config()['sites'] if site != ""] print(old_value) old_value.append(site_name) diff --git a/database.ini b/database.ini index 4967f8a..5679f20 100644 --- a/database.ini +++ b/database.ini @@ -6,5 +6,7 @@ password = test port = 5432 [manage] -sites = ,test,main,Backpack +sites = Backpack,main +first_setup = False +signup_enabled = False diff --git a/html_factory.py b/html_factory.py new file mode 100644 index 0000000..9684b03 --- /dev/null +++ b/html_factory.py @@ -0,0 +1,56 @@ +import math + + +def manufactureUsersTable(rows): + table = """ + + + + + + + %%rows%% + +
Username
+ """ + + string_rows = [] + for row in rows: + string_row = f""" + {row[1]} + """ + string_rows.append(string_row) + + table = table.replace("%%rows%%", "".join(string_rows)) + + return table + + +def manufacturePagination(current_page:int , count:int, limit:int): + total_pages = math.ceil(count/limit) + pag = "" + limits = "hx-vals='{" + f'"limit": "{str(limit)}"' + "}'" + if count >= limit: + pag += '" + + return pag + \ No newline at end of file diff --git a/main.py b/main.py index b7012c5..d7ca28a 100644 --- a/main.py +++ b/main.py @@ -189,7 +189,6 @@ def setLogisticsDataTransaction(conn, site_name, location, logistics_info_id, qt return error return "success" - def handleNegativeQuantityOnHand(qty, cost_layers): cost_layers = [ast.literal_eval(item) for item in ast.literal_eval(cost_layers.replace('{', '[').replace('}', ']'))] dummy_quantity = qty @@ -415,11 +414,12 @@ def delete_site(site_name): drop_table(f'sites/{site_name}/sql/drop/shopping_lists.sql') drop_table(f'sites/{site_name}/sql/drop/item_locations.sql') -def create_site(site_name): - - site_config = config(f"sites/{site_name}/site.ini", 'defaults') +def create_site(site_name, admin_user: tuple, default_zone, default_primary, default_auto, description): create_table(f'sites/{site_name}/sql/create/logins.sql') + create_table(f"sites/{site_name}/sql/create/sites.sql") + create_table(f"sites/{site_name}/sql/create/roles.sql") + create_table(f'sites/{site_name}/sql/create/groups.sql') create_table(f'sites/{site_name}/sql/create/linked_items.sql') create_table(f'sites/{site_name}/sql/create/brands.sql') @@ -437,16 +437,69 @@ def create_site(site_name): create_table(f'sites/{site_name}/sql/create/shopping_lists.sql') create_table(f'sites/{site_name}/sql/create/item_locations.sql') - + add_admin_sql = f"INSERT INTO logins(username, password, email) VALUES(%s, %s, %s) RETURNING id;" + add_site_sql = f"INSERT INTO sites(site_name, creation_date, site_owner_id, flags, default_zone, default_auto_issue_location, default_primary_location, site_description) VALUES (%s, %s, %s, %s, %s, %s, %s, %s) RETURNING id;" + add_admin_role = f"INSERT INTO roles(role_name, site_id) VALUES(%s, %s) RETURNING id;" + sql = f"INSERT INTO {site_name}_zones(name) VALUES (%s) RETURNING id;" sqltwo = f"INSERT INTO {site_name}_locations(uuid, name, zone_id, items) VALUES (%s, %s, %s, %s);" sqlthree = f"INSERT INTO {site_name}_vendors(vendor_name, creation_date, created_by) VALUES (%s, %s, %s);" + database_config = config() with psycopg2.connect(**database_config) as conn: + try: + with conn.cursor() as cur: + cur.execute(add_admin_sql, admin_user) + rows = cur.fetchone() + if rows: + user_id = rows[0] + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return False + print(user_id) + + # set up site in database + try: + with conn.cursor() as cur: + data = (site_name, str(datetime.datetime.now()), user_id, json.dumps({}), default_zone, default_auto, default_primary, description) + cur.execute(add_site_sql, data) + rows = cur.fetchone() + if rows: + site_id = rows[0] + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return False + + # add admin role for site + try: + with conn.cursor() as cur: + data = ('Admin', site_id) + cur.execute(add_admin_role, data) + rows = cur.fetchone() + if rows: + role_id = rows[0] + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return False + + # update user with site_id and admin role. + try: + with conn.cursor() as cur: + data = (site_id, role_id, user_id) + cur.execute(f"UPDATE logins SET sites = sites || %s, site_roles = site_roles || %s WHERE id=%s;", data) + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return False + + # setup the default zone. zone_id = None try: with conn.cursor() as cur: - cur.execute(sql, (site_config["default_zone"], )) + cur.execute(sql, (default_zone, )) rows = cur.fetchone() if rows: zone_id = rows[0] @@ -455,11 +508,11 @@ def create_site(site_name): conn.rollback() return False - uuid = f"{site_config["default_zone"]}@{site_config["default_primary_location"]}" + uuid = f"{default_zone}@{default_primary}" try: with conn.cursor() as cur: - cur.execute(sqltwo, (uuid, site_config["default_primary_location"], zone_id, json.dumps({}))) + cur.execute(sqltwo, (uuid, default_primary, zone_id, json.dumps({}))) except (Exception, psycopg2.DatabaseError) as error: print(error) conn.rollback() @@ -473,9 +526,171 @@ def create_site(site_name): conn.rollback() return False + conn.commit() + +async def create_site_secondary(site_name, user_id, default_zone, default_primary, default_auto, description): + + create_table(f'sites/{site_name}/sql/create/logins.sql') + create_table(f"sites/{site_name}/sql/create/sites.sql") + create_table(f"sites/{site_name}/sql/create/roles.sql") + + create_table(f'sites/{site_name}/sql/create/groups.sql') + create_table(f'sites/{site_name}/sql/create/linked_items.sql') + create_table(f'sites/{site_name}/sql/create/brands.sql') + create_table(f'sites/{site_name}/sql/create/food_info.sql') + create_table(f'sites/{site_name}/sql/create/item_info.sql') + create_table(f'sites/{site_name}/sql/create/logistics_info.sql') + create_table(f'sites/{site_name}/sql/create/transactions.sql') + create_table(f'sites/{site_name}/sql/create/item.sql') + create_table(f'sites/{site_name}/sql/create/zones.sql') + create_table(f'sites/{site_name}/sql/create/locations.sql') + create_table(f'sites/{site_name}/sql/create/vendors.sql') + create_table(f'sites/{site_name}/sql/create/receipts.sql') + create_table(f'sites/{site_name}/sql/create/receipt_items.sql') + create_table(f'sites/{site_name}/sql/create/recipes.sql') + create_table(f'sites/{site_name}/sql/create/shopping_lists.sql') + create_table(f'sites/{site_name}/sql/create/item_locations.sql') + + add_site_sql = f"INSERT INTO sites(site_name, creation_date, site_owner_id, flags, default_zone, default_auto_issue_location, default_primary_location, site_description) VALUES (%s, %s, %s, %s, %s, %s, %s, %s) RETURNING id;" + add_admin_role = f"INSERT INTO roles(role_name, site_id, role_description) VALUES(%s, %s, %s) RETURNING id;" + + sql = f"INSERT INTO {site_name}_zones(name) VALUES (%s) RETURNING id;" + sqltwo = f"INSERT INTO {site_name}_locations(uuid, name, zone_id, items) VALUES (%s, %s, %s, %s);" + sqlthree = f"INSERT INTO {site_name}_vendors(vendor_name, creation_date, created_by) VALUES (%s, %s, %s);" + + database_config = config() + with psycopg2.connect(**database_config) as conn: + # set up site in database + try: + with conn.cursor() as cur: + data = (site_name, str(datetime.datetime.now()), user_id, json.dumps({}), default_zone, default_auto, default_primary, description) + cur.execute(add_site_sql, data) + rows = cur.fetchone() + if rows: + site_id = rows[0] + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return False + + # add admin role for site + try: + with conn.cursor() as cur: + data = ('Admin', site_id, f"This is the admin role for {site_name}.") + cur.execute(add_admin_role, data) + rows = cur.fetchone() + if rows: + role_id = rows[0] + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return False + + # update user with site_id and admin role. + try: + with conn.cursor() as cur: + data = (site_id, role_id, user_id) + cur.execute(f"UPDATE logins SET sites = sites || %s, site_roles = site_roles || %s WHERE id=%s;", data) + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return False + + # setup the default zone. + zone_id = None + try: + with conn.cursor() as cur: + cur.execute(sql, (default_zone, )) + rows = cur.fetchone() + if rows: + zone_id = rows[0] + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return False + + uuid = f"{default_zone}@{default_primary}" + + try: + with conn.cursor() as cur: + cur.execute(sqltwo, (uuid, default_primary, zone_id, json.dumps({}))) + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return False + + try: + with conn.cursor() as cur: + cur.execute(sqlthree, ("None", str(datetime.datetime.now()), 1)) + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return False conn.commit() + return True + + +def getUser(username, password): + database_config = config() + with psycopg2.connect(**database_config) as conn: + try: + with conn.cursor() as cur: + sql = f"SELECT * FROM logins WHERE username=%s;" + cur.execute(sql, (username,)) + user = cur.fetchone() + if user and user[2] == password: + return list(user) + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return [] + +def setSystemAdmin(user_id: int): + database_config = config() + with psycopg2.connect(**database_config) as conn: + try: + with conn.cursor() as cur: + cur.execute(f"UPDATE logins SET system_admin = TRUE WHERE id=%s;", (user_id, )) + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return False + +def get_roles(site_id): + database_config = config() + with psycopg2.connect(**database_config) as conn: + try: + with conn.cursor() as cur: + cur.execute(f"SELECT * FROM roles WHERE site_id=%s;", (site_id, )) + roles = cur.fetchall() + return roles + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return False + + +def get_sites(sites=[]): + database_config = config() + with psycopg2.connect(**database_config) as conn: + try: + with conn.cursor() as cur: + site_rows = [] + for each in sites: + cur.execute(f"SELECT * FROM sites WHERE id=%s;", (each, )) + site_rows.append(cur.fetchone()) + print(site_rows) + return site_rows + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() + return False + + + + transaction_payload = { "timestamp": None, "logistics_info_id": 0, diff --git a/manage.py b/manage.py index 05ef3e8..2420b3a 100644 --- a/manage.py +++ b/manage.py @@ -55,19 +55,7 @@ def rename_create_sql(site_name): with open(f"sites/{site_name}/sql/create/{file_name}", "w") as file: file.write(words) -def create(): - site_name = input("Site Name: ") - site_owner = input("Site Owner: ") - email = input("Contact Email: ") - - default_zone_name = input("Set Default Zone Name (default): ").strip() - if default_zone_name == "": - default_zone_name = "default" - - print(f"Now you will set the default location that you wish for things to be received into (primary location) and used from (auto-issue).") - default_location_name = input("Set Default Location (all): ").strip() - if default_location_name == "": - default_location_name = "all" +def create(site_name, owner_name, default_zone_name, default_location_name, email=""): if not os.path.exists(f"sites/{site_name}"): print(f"Creating {site_name} site...") @@ -82,7 +70,7 @@ def create(): with open(f"sites/{site_name}/site.ini", "w+") as config: config.write(f"[site]\n") config.write(f"site_name={site_name}\n") - config.write(f"site_owner={site_owner}\n") + config.write(f"site_owner={owner_name}\n") config.write(f"email={email}\n") config.write(f"\n") diff --git a/scratch.py b/scratch.py index 5b04d32..aaacbca 100644 --- a/scratch.py +++ b/scratch.py @@ -1,38 +1,25 @@ -sql = "SELECT items FROM main_locations WHERE id=1;" from config import config import psycopg2, requests -import main, datetime +import main, datetime, json -"""database_config = config() + +database_config = config() with psycopg2.connect(**database_config) as conn: - result = main.setLocationData(conn, "main", "default@all", 1, 4.0, 0.0) - print(result)""" -url = "http://192.168.1.45:5810/resolveReceiptItem" -"""payload_receipt = { - "receipt_id": 123456, - "receipt_status": "Unresolved", - "date_submitted": str(datetime.datetime.now()), - "submitted_by": 1, - "vendor_id": 0, - "files": {}, - "items": [ - ("FOOD", 0, "%1234%", "test_item", 1.0, {"cost": 1.99, "EXPIRES": False}, "Unresolved"), - ("FOOD", 0, "%1235%", "test_item", 1.0, {"cost": 1.99, "EXPIRES": False}, "Unresolved"), - ("FOOD", 0, "%1236%", "test_item", 1.0, {"cost": 1.99, "EXPIRES": False}, "Unresolved"), - ], - "site_name": "main" -}""" +# update user with site_id and admin role. + sqlfile = open('sites/main/sql/unique/shopping_lists_safetystock_uncalculated.sql', "r+") + sql = sqlfile.readlines() + sql = "\n".join(sql) + sqlfile.close() + try: + with conn.cursor() as cur: + cur.execute(sql, (1, )) + x = cur.fetchall() + for _ in x: + print(_) - - - - -response = requests.post(url) - -receipt_id = response.json()["receipt_id"] - - -print(receipt_id) + except (Exception, psycopg2.DatabaseError) as error: + print(error) + conn.rollback() diff --git a/sites/Backpack/site.ini b/sites/Backpack/site.ini index a63d838..b7537b5 100644 --- a/sites/Backpack/site.ini +++ b/sites/Backpack/site.ini @@ -1,9 +1,9 @@ [site] site_name=Backpack -site_owner=Jadowyne +site_owner=jadowyne email= [defaults] -default_zone=default -default_primary_location=all -default_auto_issue_location=all +default_zone=MAIN +default_primary_location=POUCH A +default_auto_issue_location=POUCH A diff --git a/sites/Backpack/sql/create/logins.sql b/sites/Backpack/sql/create/logins.sql index f69b01b..3630312 100644 --- a/sites/Backpack/sql/create/logins.sql +++ b/sites/Backpack/sql/create/logins.sql @@ -2,15 +2,21 @@ CREATE TABLE IF NOT EXISTS logins( id SERIAL PRIMARY KEY, username VARCHAR(255), password VARCHAR(255), - favorites JSONB, - unseen_pantry_items INTEGER [], - unseen_groups INTEGER [], - unseen_shopping_lists INTEGER [], - unseen_recipes INTEGER [], - seen_pantry_items INTEGER [], - seen_groups INTEGER[], - seen_shopping_lists INTEGER [], - seen_recipes INTEGER [], - flags JSONB + email VARCHAR(255) UNIQUE NOT NULL, + favorites JSONB DEFAULT '{}', + unseen_pantry_items INTEGER [] DEFAULT '{}', + unseen_groups INTEGER [] DEFAULT '{}', + unseen_shopping_lists INTEGER [] DEFAULT '{}', + unseen_recipes INTEGER [] DEFAULT '{}', + seen_pantry_items INTEGER [] DEFAULT '{}', + seen_groups INTEGER[] DEFAULT '{}', + seen_shopping_lists INTEGER [] DEFAULT '{}', + seen_recipes INTEGER [] DEFAULT '{}', + sites INTEGER [] DEFAULT '{}', + site_roles INTEGER [] DEFAULT '{}', + system_admin BOOLEAN DEFAULT FALSE, + flags JSONB DEFAULT '{}', + UNIQUE(username), + CHECK (email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$') ); diff --git a/sites/Backpack/sql/create/roles.sql b/sites/Backpack/sql/create/roles.sql new file mode 100644 index 0000000..802584f --- /dev/null +++ b/sites/Backpack/sql/create/roles.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS roles( + id SERIAL PRIMARY KEY, + role_name VARCHAR(255) NOT NULL, + role_description TEXT, + site_id INTEGER NOT NULL, + flags JSONB DEFAULT '{}', + UNIQUE(role_name, site_id), + CONSTRAINT fk_site + FOREIGN KEY(site_id) + REFERENCES sites(id) +); \ No newline at end of file diff --git a/sites/Backpack/sql/create/sites.sql b/sites/Backpack/sql/create/sites.sql new file mode 100644 index 0000000..c4573b3 --- /dev/null +++ b/sites/Backpack/sql/create/sites.sql @@ -0,0 +1,15 @@ +CREATE TABLE IF NOT EXISTS sites ( + id SERIAL PRIMARY KEY, + site_name VARCHAR(120), + site_description TEXT, + creation_date TIMESTAMP, + site_owner_id INTEGER NOT NULL, + flags JSONB, + default_zone VARCHAR(32), + default_auto_issue_location VARCHAR(32), + default_primary_location VARCHAR(32), + UNIQUE(site_name), + CONSTRAINT fk_site_owner + FOREIGN KEY(site_owner_id) + REFERENCES logins(id) +); \ No newline at end of file diff --git a/sites/Backpack/sql/unique/shopping_lists_safetystock.sql b/sites/Backpack/sql/unique/shopping_lists_safetystock.sql new file mode 100644 index 0000000..4efc5e5 --- /dev/null +++ b/sites/Backpack/sql/unique/shopping_lists_safetystock.sql @@ -0,0 +1,43 @@ +WITH sum_cte AS ( + SELECT mi.id, SUM(mil.quantity_on_hand) AS total_sum + FROM Backpack_item_locations mil + JOIN Backpack_items mi ON mil.part_id = mi.id + GROUP BY mi.id +) +SELECT * +FROM Backpack_items +LEFT JOIN Backpack_item_info ON Backpack_items.item_info_id = Backpack_item_info.id +LEFT JOIN sum_cte ON Backpack_items.id = sum_cte.id +WHERE Backpack_item_info.safety_stock > COALESCE(sum_cte.total_sum, 0) +AND Backpack_item_info.shopping_lists @> ARRAY[%s]; + +/* +00 - item_id +01 - barcode +02 - item_name +03 - brand (id) +04 - description +05 - tags +06 - links +07 - item_info_id +08 - logistics_info_id +09 - food_info_id +10 - row_type +11 - item_type +12 - search_string +13 - item_info_id +14 - barcode +15 - linked_items +16 - shopping_lists +17 - recipes +18 - groups +19 - packaging +20 - uom +21 - cost +22 - safety_stock +23 - lead_time_days +24 - ai_pick +25 - sum_cte_id +26 - total_sum/QOH +*/ + diff --git a/sites/Backpack/sql/unique/shopping_lists_safetystock_count.sql b/sites/Backpack/sql/unique/shopping_lists_safetystock_count.sql new file mode 100644 index 0000000..756fe85 --- /dev/null +++ b/sites/Backpack/sql/unique/shopping_lists_safetystock_count.sql @@ -0,0 +1,12 @@ +WITH sum_cte AS ( + SELECT mi.id, SUM(mil.quantity_on_hand) AS total_sum + FROM Backpack_item_locations mil + JOIN Backpack_items mi ON mil.part_id = mi.id + GROUP BY mi.id +) +SELECT COUNT(*) +FROM Backpack_items +LEFT JOIN Backpack_item_info ON Backpack_items.item_info_id = Backpack_item_info.id +LEFT JOIN sum_cte ON Backpack_items.id = sum_cte.id +WHERE Backpack_item_info.safety_stock > COALESCE(sum_cte.total_sum, 0) +AND Backpack_item_info.shopping_lists @> ARRAY[%s]; \ No newline at end of file diff --git a/sites/Backpack/sql/unique/shopping_lists_safetystock_uncalculated.sql b/sites/Backpack/sql/unique/shopping_lists_safetystock_uncalculated.sql new file mode 100644 index 0000000..7f52ab9 --- /dev/null +++ b/sites/Backpack/sql/unique/shopping_lists_safetystock_uncalculated.sql @@ -0,0 +1,11 @@ +WITH sum_cte AS ( + SELECT mi.id, SUM(mil.quantity_on_hand) AS total_sum + FROM Backpack_item_locations mil + JOIN Backpack_items mi ON mil.part_id = mi.id + GROUP BY mi.id +) +SELECT * +FROM Backpack_items +LEFT JOIN Backpack_item_info ON Backpack_items.item_info_id = Backpack_item_info.id +LEFT JOIN sum_cte ON Backpack_items.id = sum_cte.id +WHERE Backpack_item_info.shopping_lists @> ARRAY[%s]; \ No newline at end of file diff --git a/sites/default/sql/create/logins.sql b/sites/default/sql/create/logins.sql index f69b01b..3630312 100644 --- a/sites/default/sql/create/logins.sql +++ b/sites/default/sql/create/logins.sql @@ -2,15 +2,21 @@ CREATE TABLE IF NOT EXISTS logins( id SERIAL PRIMARY KEY, username VARCHAR(255), password VARCHAR(255), - favorites JSONB, - unseen_pantry_items INTEGER [], - unseen_groups INTEGER [], - unseen_shopping_lists INTEGER [], - unseen_recipes INTEGER [], - seen_pantry_items INTEGER [], - seen_groups INTEGER[], - seen_shopping_lists INTEGER [], - seen_recipes INTEGER [], - flags JSONB + email VARCHAR(255) UNIQUE NOT NULL, + favorites JSONB DEFAULT '{}', + unseen_pantry_items INTEGER [] DEFAULT '{}', + unseen_groups INTEGER [] DEFAULT '{}', + unseen_shopping_lists INTEGER [] DEFAULT '{}', + unseen_recipes INTEGER [] DEFAULT '{}', + seen_pantry_items INTEGER [] DEFAULT '{}', + seen_groups INTEGER[] DEFAULT '{}', + seen_shopping_lists INTEGER [] DEFAULT '{}', + seen_recipes INTEGER [] DEFAULT '{}', + sites INTEGER [] DEFAULT '{}', + site_roles INTEGER [] DEFAULT '{}', + system_admin BOOLEAN DEFAULT FALSE, + flags JSONB DEFAULT '{}', + UNIQUE(username), + CHECK (email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$') ); diff --git a/sites/default/sql/create/roles.sql b/sites/default/sql/create/roles.sql new file mode 100644 index 0000000..802584f --- /dev/null +++ b/sites/default/sql/create/roles.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS roles( + id SERIAL PRIMARY KEY, + role_name VARCHAR(255) NOT NULL, + role_description TEXT, + site_id INTEGER NOT NULL, + flags JSONB DEFAULT '{}', + UNIQUE(role_name, site_id), + CONSTRAINT fk_site + FOREIGN KEY(site_id) + REFERENCES sites(id) +); \ No newline at end of file diff --git a/sites/default/sql/create/sites.sql b/sites/default/sql/create/sites.sql new file mode 100644 index 0000000..c4573b3 --- /dev/null +++ b/sites/default/sql/create/sites.sql @@ -0,0 +1,15 @@ +CREATE TABLE IF NOT EXISTS sites ( + id SERIAL PRIMARY KEY, + site_name VARCHAR(120), + site_description TEXT, + creation_date TIMESTAMP, + site_owner_id INTEGER NOT NULL, + flags JSONB, + default_zone VARCHAR(32), + default_auto_issue_location VARCHAR(32), + default_primary_location VARCHAR(32), + UNIQUE(site_name), + CONSTRAINT fk_site_owner + FOREIGN KEY(site_owner_id) + REFERENCES logins(id) +); \ No newline at end of file diff --git a/sites/default/sql/unique/shopping_lists_safetystock.sql b/sites/default/sql/unique/shopping_lists_safetystock.sql new file mode 100644 index 0000000..7ab5d25 --- /dev/null +++ b/sites/default/sql/unique/shopping_lists_safetystock.sql @@ -0,0 +1,43 @@ +WITH sum_cte AS ( + SELECT mi.id, SUM(mil.quantity_on_hand) AS total_sum + FROM %sitename%_item_locations mil + JOIN %sitename%_items mi ON mil.part_id = mi.id + GROUP BY mi.id +) +SELECT * +FROM %sitename%_items +LEFT JOIN %sitename%_item_info ON %sitename%_items.item_info_id = %sitename%_item_info.id +LEFT JOIN sum_cte ON %sitename%_items.id = sum_cte.id +WHERE %sitename%_item_info.safety_stock > COALESCE(sum_cte.total_sum, 0) +AND %sitename%_item_info.shopping_lists @> ARRAY[%s]; + +/* +00 - item_id +01 - barcode +02 - item_name +03 - brand (id) +04 - description +05 - tags +06 - links +07 - item_info_id +08 - logistics_info_id +09 - food_info_id +10 - row_type +11 - item_type +12 - search_string +13 - item_info_id +14 - barcode +15 - linked_items +16 - shopping_lists +17 - recipes +18 - groups +19 - packaging +20 - uom +21 - cost +22 - safety_stock +23 - lead_time_days +24 - ai_pick +25 - sum_cte_id +26 - total_sum/QOH +*/ + diff --git a/sites/default/sql/unique/shopping_lists_safetystock_count.sql b/sites/default/sql/unique/shopping_lists_safetystock_count.sql new file mode 100644 index 0000000..3f9d4c1 --- /dev/null +++ b/sites/default/sql/unique/shopping_lists_safetystock_count.sql @@ -0,0 +1,12 @@ +WITH sum_cte AS ( + SELECT mi.id, SUM(mil.quantity_on_hand) AS total_sum + FROM %sitename%_item_locations mil + JOIN %sitename%_items mi ON mil.part_id = mi.id + GROUP BY mi.id +) +SELECT COUNT(*) +FROM %sitename%_items +LEFT JOIN %sitename%_item_info ON %sitename%_items.item_info_id = %sitename%_item_info.id +LEFT JOIN sum_cte ON %sitename%_items.id = sum_cte.id +WHERE %sitename%_item_info.safety_stock > COALESCE(sum_cte.total_sum, 0) +AND %sitename%_item_info.shopping_lists @> ARRAY[%s]; \ No newline at end of file diff --git a/sites/default/sql/unique/shopping_lists_safetystock_uncalculated.sql b/sites/default/sql/unique/shopping_lists_safetystock_uncalculated.sql new file mode 100644 index 0000000..44f7e66 --- /dev/null +++ b/sites/default/sql/unique/shopping_lists_safetystock_uncalculated.sql @@ -0,0 +1,11 @@ +WITH sum_cte AS ( + SELECT mi.id, SUM(mil.quantity_on_hand) AS total_sum + FROM %sitename%_item_locations mil + JOIN %sitename%_items mi ON mil.part_id = mi.id + GROUP BY mi.id +) +SELECT * +FROM %sitename%_items +LEFT JOIN %sitename%_item_info ON %sitename%_items.item_info_id = %sitename%_item_info.id +LEFT JOIN sum_cte ON %sitename%_items.id = sum_cte.id +WHERE %sitename%_item_info.shopping_lists @> ARRAY[%s]; \ No newline at end of file diff --git a/sites/main/site.ini b/sites/main/site.ini index 2d7e2e6..4c1e583 100644 --- a/sites/main/site.ini +++ b/sites/main/site.ini @@ -1,9 +1,9 @@ [site] site_name=main -site_owner= -email= +site_owner=jadowyne +email=jadowyne.ulve@outlook.com [defaults] -default_zone=default -default_primary_location=all -default_auto_issue_location=all +default_zone=DEFAULT +default_primary_location=ALL +default_auto_issue_location=ALL diff --git a/sites/main/sql/create/logins.sql b/sites/main/sql/create/logins.sql index f69b01b..3630312 100644 --- a/sites/main/sql/create/logins.sql +++ b/sites/main/sql/create/logins.sql @@ -2,15 +2,21 @@ CREATE TABLE IF NOT EXISTS logins( id SERIAL PRIMARY KEY, username VARCHAR(255), password VARCHAR(255), - favorites JSONB, - unseen_pantry_items INTEGER [], - unseen_groups INTEGER [], - unseen_shopping_lists INTEGER [], - unseen_recipes INTEGER [], - seen_pantry_items INTEGER [], - seen_groups INTEGER[], - seen_shopping_lists INTEGER [], - seen_recipes INTEGER [], - flags JSONB + email VARCHAR(255) UNIQUE NOT NULL, + favorites JSONB DEFAULT '{}', + unseen_pantry_items INTEGER [] DEFAULT '{}', + unseen_groups INTEGER [] DEFAULT '{}', + unseen_shopping_lists INTEGER [] DEFAULT '{}', + unseen_recipes INTEGER [] DEFAULT '{}', + seen_pantry_items INTEGER [] DEFAULT '{}', + seen_groups INTEGER[] DEFAULT '{}', + seen_shopping_lists INTEGER [] DEFAULT '{}', + seen_recipes INTEGER [] DEFAULT '{}', + sites INTEGER [] DEFAULT '{}', + site_roles INTEGER [] DEFAULT '{}', + system_admin BOOLEAN DEFAULT FALSE, + flags JSONB DEFAULT '{}', + UNIQUE(username), + CHECK (email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$') ); diff --git a/sites/main/sql/create/roles.sql b/sites/main/sql/create/roles.sql new file mode 100644 index 0000000..802584f --- /dev/null +++ b/sites/main/sql/create/roles.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS roles( + id SERIAL PRIMARY KEY, + role_name VARCHAR(255) NOT NULL, + role_description TEXT, + site_id INTEGER NOT NULL, + flags JSONB DEFAULT '{}', + UNIQUE(role_name, site_id), + CONSTRAINT fk_site + FOREIGN KEY(site_id) + REFERENCES sites(id) +); \ No newline at end of file diff --git a/sites/main/sql/create/sites.sql b/sites/main/sql/create/sites.sql new file mode 100644 index 0000000..c4573b3 --- /dev/null +++ b/sites/main/sql/create/sites.sql @@ -0,0 +1,15 @@ +CREATE TABLE IF NOT EXISTS sites ( + id SERIAL PRIMARY KEY, + site_name VARCHAR(120), + site_description TEXT, + creation_date TIMESTAMP, + site_owner_id INTEGER NOT NULL, + flags JSONB, + default_zone VARCHAR(32), + default_auto_issue_location VARCHAR(32), + default_primary_location VARCHAR(32), + UNIQUE(site_name), + CONSTRAINT fk_site_owner + FOREIGN KEY(site_owner_id) + REFERENCES logins(id) +); \ No newline at end of file diff --git a/sites/main/sql/unique/shopping_lists_safetystock.sql b/sites/main/sql/unique/shopping_lists_safetystock.sql new file mode 100644 index 0000000..244bd62 --- /dev/null +++ b/sites/main/sql/unique/shopping_lists_safetystock.sql @@ -0,0 +1,12 @@ +WITH sum_cte AS ( + SELECT mi.id, SUM(mil.quantity_on_hand) AS total_sum + FROM main_item_locations mil + JOIN main_items mi ON mil.part_id = mi.id + GROUP BY mi.id +) +SELECT * +FROM main_items +LEFT JOIN main_item_info ON main_items.item_info_id = main_item_info.id +LEFT JOIN sum_cte ON main_items.id = sum_cte.id +WHERE main_item_info.safety_stock > COALESCE(sum_cte.total_sum, 0) +AND main_item_info.shopping_lists @> ARRAY[%s]; \ No newline at end of file diff --git a/sites/main/sql/unique/shopping_lists_safetystock_count.sql b/sites/main/sql/unique/shopping_lists_safetystock_count.sql new file mode 100644 index 0000000..605525f --- /dev/null +++ b/sites/main/sql/unique/shopping_lists_safetystock_count.sql @@ -0,0 +1,12 @@ +WITH sum_cte AS ( + SELECT mi.id, SUM(mil.quantity_on_hand) AS total_sum + FROM main_item_locations mil + JOIN main_items mi ON mil.part_id = mi.id + GROUP BY mi.id +) +SELECT COUNT(*) +FROM main_items +LEFT JOIN main_item_info ON main_items.item_info_id = main_item_info.id +LEFT JOIN sum_cte ON main_items.id = sum_cte.id +WHERE main_item_info.safety_stock > COALESCE(sum_cte.total_sum, 0) +AND main_item_info.shopping_lists @> ARRAY[%s]; \ No newline at end of file diff --git a/sites/main/sql/unique/shopping_lists_safetystock_uncalculated.sql b/sites/main/sql/unique/shopping_lists_safetystock_uncalculated.sql new file mode 100644 index 0000000..19d9baf --- /dev/null +++ b/sites/main/sql/unique/shopping_lists_safetystock_uncalculated.sql @@ -0,0 +1,11 @@ +WITH sum_cte AS ( + SELECT mi.id, SUM(mil.quantity_on_hand) AS total_sum + FROM main_item_locations mil + JOIN main_items mi ON mil.part_id = mi.id + GROUP BY mi.id +) +SELECT * +FROM main_items +LEFT JOIN main_item_info ON main_items.item_info_id = main_item_info.id +LEFT JOIN sum_cte ON main_items.id = sum_cte.id +WHERE main_item_info.shopping_lists @> ARRAY[%s]; \ No newline at end of file diff --git a/sites/test/site.ini b/sites/test/site.ini deleted file mode 100644 index 388ddf8..0000000 --- a/sites/test/site.ini +++ /dev/null @@ -1,9 +0,0 @@ -[site] -site_name=test -site_owner= -email= - -[defaults] -default_zone=default -default_primary_location=all -default_auto_issue_location=all diff --git a/sites/test/sql/create/brands.sql b/sites/test/sql/create/brands.sql deleted file mode 100644 index 6cd9f9c..0000000 --- a/sites/test/sql/create/brands.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE IF NOT EXISTS test_brands ( - id SERIAL PRIMARY KEY, - name VARCHAR(255) -); \ No newline at end of file diff --git a/sites/test/sql/create/food_info.sql b/sites/test/sql/create/food_info.sql deleted file mode 100644 index bedbe47..0000000 --- a/sites/test/sql/create/food_info.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE IF NOT EXISTS test_food_info ( - id SERIAL PRIMARY KEY, - food_groups TEXT [], - ingrediants TEXT [], - nutrients JSONB, - expires BOOLEAN -); \ No newline at end of file diff --git a/sites/test/sql/create/groups.sql b/sites/test/sql/create/groups.sql deleted file mode 100644 index b97fdab..0000000 --- a/sites/test/sql/create/groups.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE IF NOT EXISTS test_groups( - id SERIAL PRIMARY KEY, - name VARCHAR(255) NOT NULL, - description TEXT, - included_items INTEGER [], - group_type VARCHAR(255), - UNIQUE (name) -); \ No newline at end of file diff --git a/sites/test/sql/create/item.sql b/sites/test/sql/create/item.sql deleted file mode 100644 index e01be05..0000000 --- a/sites/test/sql/create/item.sql +++ /dev/null @@ -1,32 +0,0 @@ -CREATE TABLE IF NOT EXISTS test_items( - id SERIAL PRIMARY KEY, - barcode VARCHAR(255) NOT NULL, - item_name VARCHAR(255) NOT NULL, - brand INTEGER, - description TEXT, - tags TEXT [], - links JSONB, - item_info_id INTEGER NOT NULL, - logistics_info_id INTEGER NOT NULL, - food_info_id INTEGER, - row_type VARCHAR(255) NOT NULL, - item_type VARCHAR(255) NOT NULL, - search_string TEXT NOT NULL, - UNIQUE(barcode, item_info_id), - CONSTRAINT fk_item_info - FOREIGN KEY(item_info_id) - REFERENCES test_item_info(id) - ON DELETE CASCADE, - CONSTRAINT fk_food_info - FOREIGN KEY(food_info_id) - REFERENCES test_food_info(id) - ON DELETE CASCADE, - CONSTRAINT fk_brand - FOREIGN KEY(brand) - REFERENCES test_brands(id) - ON DELETE CASCADE, - CONSTRAINT fk_logistics_info - FOREIGN KEY(logistics_info_id) - REFERENCES test_logistics_info(id) - ON DELETE CASCADE -); diff --git a/sites/test/sql/create/item_info.sql b/sites/test/sql/create/item_info.sql deleted file mode 100644 index 317106c..0000000 --- a/sites/test/sql/create/item_info.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE IF NOt EXISTS test_item_info ( - id SERIAL PRIMARY KEY, - barcode VARCHAR(255) NOT NULL, - linked_items INTEGER [], - shopping_lists INTEGER [], - recipes INTEGER [], - groups INTEGER [], - packaging VARCHAR(255), - uom VARCHAR(255), - cost FLOAT8, - safety_stock FLOAT8, - lead_time_days FLOAT8, - ai_pick BOOLEAN, - UNIQUE(barcode) -); \ No newline at end of file diff --git a/sites/test/sql/create/item_locations.sql b/sites/test/sql/create/item_locations.sql deleted file mode 100644 index 30aec57..0000000 --- a/sites/test/sql/create/item_locations.sql +++ /dev/null @@ -1,23 +0,0 @@ -DO $$ -BEGIN - IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'cost_layer') THEN - CREATE TYPE cost_layer AS (qty FLOAT8, cost FLOAT8); - END IF; -END $$; - -CREATE TABLE IF NOT EXISTS test_item_locations( - id SERIAL PRIMARY KEY, - part_id INTEGER NOT NULL, - location_id INTEGER NOT NULL, - quantity_on_hand FLOAT8 NOT NULL, - cost_layers cost_layer[], - UNIQUE(part_id, location_id), - CONSTRAINT fk_part_id - FOREIGN KEY(part_id) - REFERENCES test_items(id) - ON DELETE CASCADE, - CONSTRAINT fk_location_id - FOREIGN KEY(location_id) - REFERENCES test_locations(id) - ON DELETE CASCADE -); \ No newline at end of file diff --git a/sites/test/sql/create/linked_items.sql b/sites/test/sql/create/linked_items.sql deleted file mode 100644 index 16a24e2..0000000 --- a/sites/test/sql/create/linked_items.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE IF NOT EXISTS test_itemlinks ( - id SERIAL PRIMARY KEY, - barcode VARCHAR(255) NOt NULL, - link INTEGER NOT NULL, - data JSONB NOT NULL, - conv_factor FLOAT8 NOt NULL, - UNIQUE(barcode) -); \ No newline at end of file diff --git a/sites/test/sql/create/locations.sql b/sites/test/sql/create/locations.sql deleted file mode 100644 index da7ecdc..0000000 --- a/sites/test/sql/create/locations.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE IF NOT EXISTS test_locations( - id SERIAL PRIMARY KEY, - uuid VARCHAR(255) NOT NULL, - name VARCHAR(32) NOT NULL, - zone_id INTEGER NOT NULL, - items JSONB, - UNIQUE(uuid), - CONSTRAINT fk_zone - FOREIGN KEY(zone_id) - REFERENCES test_zones(id) -); \ No newline at end of file diff --git a/sites/test/sql/create/logins.sql b/sites/test/sql/create/logins.sql deleted file mode 100644 index f69b01b..0000000 --- a/sites/test/sql/create/logins.sql +++ /dev/null @@ -1,16 +0,0 @@ -CREATE TABLE IF NOT EXISTS logins( - id SERIAL PRIMARY KEY, - username VARCHAR(255), - password VARCHAR(255), - favorites JSONB, - unseen_pantry_items INTEGER [], - unseen_groups INTEGER [], - unseen_shopping_lists INTEGER [], - unseen_recipes INTEGER [], - seen_pantry_items INTEGER [], - seen_groups INTEGER[], - seen_shopping_lists INTEGER [], - seen_recipes INTEGER [], - flags JSONB -); - diff --git a/sites/test/sql/create/logistics_info.sql b/sites/test/sql/create/logistics_info.sql deleted file mode 100644 index 7a77d79..0000000 --- a/sites/test/sql/create/logistics_info.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE IF NOT EXISTS test_logistics_info( - id SERIAL PRIMARY KEY, - barcode VARCHAR(255) NOT NULL, - primary_location VARCHAR(64), - auto_issue_location VARCHAR(64), - dynamic_locations JSONB, - location_data JSONB, - quantity_on_hand FLOAT8 NOT NULL, - UNIQUE(barcode) -); \ No newline at end of file diff --git a/sites/test/sql/create/receipt_items.sql b/sites/test/sql/create/receipt_items.sql deleted file mode 100644 index ef34fd6..0000000 --- a/sites/test/sql/create/receipt_items.sql +++ /dev/null @@ -1,13 +0,0 @@ -CREATE TABLE IF NOT EXISTS test_receipt_items ( - id SERIAL PRIMARY KEY, - type VARCHAR(255) NOT NULL, - receipt_id INTEGER NOT NULL, - barcode VARCHAR(255) NOT NULL, - name VARCHAR(255) NOT NULL, - qty FLOAT8 NOT NULL, - data JSONB, - status VARCHAR (64), - CONSTRAINT fk_receipt - FOREIGN KEY(receipt_id) - REFERENCES test_receipts(id) -); \ No newline at end of file diff --git a/sites/test/sql/create/receipts.sql b/sites/test/sql/create/receipts.sql deleted file mode 100644 index fbafa32..0000000 --- a/sites/test/sql/create/receipts.sql +++ /dev/null @@ -1,13 +0,0 @@ -CREATE TABLE IF NOT EXISTS test_receipts ( - id SERIAL PRIMARY KEY, - receipt_id VARCHAR (32) NOT NULL, - receipt_status VARCHAR (64) NOT NULL, - date_submitted TIMESTAMP NOT NULL, - submitted_by INTEGER NOT NULL, - vendor_id INTEGER, - files JSONB, - UNIQUE(receipt_id), - CONSTRAINT fk_vendor - FOREIGN KEY(vendor_id) - REFERENCES test_vendors(id) -); \ No newline at end of file diff --git a/sites/test/sql/create/recipes.sql b/sites/test/sql/create/recipes.sql deleted file mode 100644 index 150b4cc..0000000 --- a/sites/test/sql/create/recipes.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE TABLE IF NOT EXISTS test_recipes ( - id SERIAL PRIMARY KEY, - name VARCHAR, - author INTEGER, - description TEXT, - creation_date TIMESTAMP, - custom_items JSONB, - pantry_items JSONB, - group_items JSONB, - instructions TEXT [], - picture_path TEXT -); \ No newline at end of file diff --git a/sites/test/sql/create/shopping_lists.sql b/sites/test/sql/create/shopping_lists.sql deleted file mode 100644 index 9661ef6..0000000 --- a/sites/test/sql/create/shopping_lists.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE TABLE IF NOT EXISTS test_shopping_lists ( - id SERIAL PRIMARY KEY, - name VARCHAR(255) NOT NULL, - description TEXT, - pantry_items INTEGER [], - custom_items JSONB, - recipes INTEGER [], - groups INTEGER [], - quantities JSONB, - author INTEGER, - creation_date TIMESTAMP, - type VARCHAR(64), - UNIQUE(name) -); \ No newline at end of file diff --git a/sites/test/sql/create/transactions.sql b/sites/test/sql/create/transactions.sql deleted file mode 100644 index c781b14..0000000 --- a/sites/test/sql/create/transactions.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE IF NOT EXISTS test_Transactions ( - id SERIAL PRIMARY KEY, - timestamp TIMESTAMP, - logistics_info_id INTEGER NOT NULL, - barcode VARCHAR(255) NOT NULL, - name VARCHAR(255), - transaction_type VARCHAR(255) NOT NULL, - quantity FLOAT8 NOT NULL, - description TEXT, - user_id INTEGER NOT NULL, - data JSONB, - CONSTRAINT fk_logistics_info - FOREIGN KEY(logistics_info_id) - REFERENCES test_logistics_info(id) -); \ No newline at end of file diff --git a/sites/test/sql/create/vendors.sql b/sites/test/sql/create/vendors.sql deleted file mode 100644 index eedc869..0000000 --- a/sites/test/sql/create/vendors.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE TABLE IF NOT EXISTS test_vendors ( - id SERIAL PRIMARY KEY, - vendor_name VARCHAR(255) NOT NULL, - vendor_address VARCHAR(255), - creation_date TIMESTAMP NOT NULL, - created_by INTEGER NOT NULL, - phone_number VARCHAR(32) -); \ No newline at end of file diff --git a/sites/test/sql/create/zones.sql b/sites/test/sql/create/zones.sql deleted file mode 100644 index 0ed0a9e..0000000 --- a/sites/test/sql/create/zones.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TABLE IF NOT EXISTS test_zones( - id SERIAL PRIMARY KEY, - name VARCHAR(32) NOT NULL, - UNIQUE(name) -); diff --git a/sites/test/sql/drop/brands.sql b/sites/test/sql/drop/brands.sql deleted file mode 100644 index f407a8c..0000000 --- a/sites/test/sql/drop/brands.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_brands CASCADE; \ No newline at end of file diff --git a/sites/test/sql/drop/food_info.sql b/sites/test/sql/drop/food_info.sql deleted file mode 100644 index a4c3056..0000000 --- a/sites/test/sql/drop/food_info.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_food_info CASCADE; \ No newline at end of file diff --git a/sites/test/sql/drop/groups.sql b/sites/test/sql/drop/groups.sql deleted file mode 100644 index 6b62f3b..0000000 --- a/sites/test/sql/drop/groups.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_groups CASCADE; \ No newline at end of file diff --git a/sites/test/sql/drop/item_info.sql b/sites/test/sql/drop/item_info.sql deleted file mode 100644 index c84b0d1..0000000 --- a/sites/test/sql/drop/item_info.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_item_info CASCADE; \ No newline at end of file diff --git a/sites/test/sql/drop/item_locations.sql b/sites/test/sql/drop/item_locations.sql deleted file mode 100644 index 005ec66..0000000 --- a/sites/test/sql/drop/item_locations.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_item_locations CASCADE; diff --git a/sites/test/sql/drop/items.sql b/sites/test/sql/drop/items.sql deleted file mode 100644 index 097b9a7..0000000 --- a/sites/test/sql/drop/items.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_items CASCADE; \ No newline at end of file diff --git a/sites/test/sql/drop/linked_items.sql b/sites/test/sql/drop/linked_items.sql deleted file mode 100644 index bcc9093..0000000 --- a/sites/test/sql/drop/linked_items.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_itemlinks CASCADE; \ No newline at end of file diff --git a/sites/test/sql/drop/locations.sql b/sites/test/sql/drop/locations.sql deleted file mode 100644 index 4a1f42e..0000000 --- a/sites/test/sql/drop/locations.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_locations CASCADE; \ No newline at end of file diff --git a/sites/test/sql/drop/logistics_info.sql b/sites/test/sql/drop/logistics_info.sql deleted file mode 100644 index cb5abcd..0000000 --- a/sites/test/sql/drop/logistics_info.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_logistics_info CASCADE; \ No newline at end of file diff --git a/sites/test/sql/drop/receipt_items.sql b/sites/test/sql/drop/receipt_items.sql deleted file mode 100644 index 0f77f60..0000000 --- a/sites/test/sql/drop/receipt_items.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_receipt_items CASCADE; \ No newline at end of file diff --git a/sites/test/sql/drop/receipts.sql b/sites/test/sql/drop/receipts.sql deleted file mode 100644 index 1d9502f..0000000 --- a/sites/test/sql/drop/receipts.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_receipts CASCADE; \ No newline at end of file diff --git a/sites/test/sql/drop/recipes.sql b/sites/test/sql/drop/recipes.sql deleted file mode 100644 index 0a626bd..0000000 --- a/sites/test/sql/drop/recipes.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_recipes CASCADE; \ No newline at end of file diff --git a/sites/test/sql/drop/shopping_lists.sql b/sites/test/sql/drop/shopping_lists.sql deleted file mode 100644 index a4cec6d..0000000 --- a/sites/test/sql/drop/shopping_lists.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_shopping_lists CASCADE; \ No newline at end of file diff --git a/sites/test/sql/drop/transactions.sql b/sites/test/sql/drop/transactions.sql deleted file mode 100644 index 1356e47..0000000 --- a/sites/test/sql/drop/transactions.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_transactions CASCADE; \ No newline at end of file diff --git a/sites/test/sql/drop/vendors.sql b/sites/test/sql/drop/vendors.sql deleted file mode 100644 index 28351e8..0000000 --- a/sites/test/sql/drop/vendors.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_vendors CASCADE; \ No newline at end of file diff --git a/sites/test/sql/drop/zones.sql b/sites/test/sql/drop/zones.sql deleted file mode 100644 index c84c67b..0000000 --- a/sites/test/sql/drop/zones.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE test_zones CASCADE; \ No newline at end of file diff --git a/sites/test/sql/unique/Insert_transaction.sql b/sites/test/sql/unique/Insert_transaction.sql deleted file mode 100644 index 7449439..0000000 --- a/sites/test/sql/unique/Insert_transaction.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO test_transactions -(timestamp, logistics_info_id, barcode, name, transaction_type, quantity, description, user_id, data) -VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s); \ No newline at end of file diff --git a/sites/test/sql/unique/logistics_transactions.sql b/sites/test/sql/unique/logistics_transactions.sql deleted file mode 100644 index 1b3d28d..0000000 --- a/sites/test/sql/unique/logistics_transactions.sql +++ /dev/null @@ -1,3 +0,0 @@ -UPDATE test_logistics_info -SET quantity_on_hand = %s, location_data = %s -WHERE id = %s; diff --git a/sites/test/sql/unique/select_item_all.sql b/sites/test/sql/unique/select_item_all.sql deleted file mode 100644 index c9943d3..0000000 --- a/sites/test/sql/unique/select_item_all.sql +++ /dev/null @@ -1,45 +0,0 @@ -SELECT * FROM test_items - LEFT JOIN test_logistics_info ON test_items.logistics_info_id = test_logistics_info.id - LEFT JOIN test_item_info ON test_items.item_info_id = test_item_info.id - LEFT JOIN test_food_info ON test_items.food_info_id = test_food_info.id -WHERE test_items.id=%s; - -/* -00 - item_id -01 - barcode -02 - item_name -03 - brand (id) -04 - description -05 - tags -06 - links -07 - item_info_id -08 - logistics_info_id -09 - food_info_id -10 - row_type -11 - item_type -12 - search_string -13 - logistics_info_id -14 - barcode -15 - primary_location -16 - auto_issue_location -17 - dynamic_locations -18 - location_data -19 - quantity_on_hand -20 - item_info_id -21 - barcode -22 - linked_items -23 - shopping_lists -24 - recipes -25 - groups -26 - packaging -27 - uom -28 - cost -29 - safety_stock -30 - lead_time_days -31 - ai_pick -32 - food_info_id -33 - food_groups -34 - ingrediants -35 - nutrients -36 - expires -*/ \ No newline at end of file diff --git a/sites/test/sql/unique/select_item_all_barcode.sql b/sites/test/sql/unique/select_item_all_barcode.sql deleted file mode 100644 index 58ded7c..0000000 --- a/sites/test/sql/unique/select_item_all_barcode.sql +++ /dev/null @@ -1,45 +0,0 @@ -SELECT * FROM test_items - LEFT JOIN test_logistics_info ON test_items.logistics_info_id = test_logistics_info.id - LEFT JOIN test_item_info ON test_items.item_info_id = test_item_info.id - LEFT JOIN test_food_info ON test_items.food_info_id = test_food_info.id -WHERE test_items.barcode=%s; - -/* -00 - item_id -01 - barcode -02 - item_name -03 - brand (id) -04 - description -05 - tags -06 - links -07 - item_info_id -08 - logistics_info_id -09 - food_info_id -10 - row_type -11 - item_type -12 - search_string -13 - logistics_info_id -14 - barcode -15 - primary_location -16 - auto_issue_location -17 - dynamic_locations -18 - location_data -19 - quantity_on_hand -20 - item_info_id -21 - barcode -22 - linked_items -23 - shopping_lists -24 - recipes -25 - groups -26 - packaging -27 - uom -28 - cost -29 - safety_stock -30 - lead_time_days -31 - ai_pick -32 - food_info_id -33 - food_groups -34 - ingrediants -35 - nutrients -36 - expires -*/ \ No newline at end of file diff --git a/sites/test/sql/unique/set_location_data.sql b/sites/test/sql/unique/set_location_data.sql deleted file mode 100644 index 4a44e02..0000000 --- a/sites/test/sql/unique/set_location_data.sql +++ /dev/null @@ -1,3 +0,0 @@ -UPDATE test_locations -SET items = %s -WHERE id = %s; \ No newline at end of file diff --git a/static/adminHandler.js b/static/adminHandler.js new file mode 100644 index 0000000..8dca71a --- /dev/null +++ b/static/adminHandler.js @@ -0,0 +1,28 @@ +async function clickRoleRow(role_id){ + const roleurl = new URL(`/admin/editRole/${role_id}`, window.location.origin); + window.location.href = roleurl.toString(); +} + +async function fetchSites() { + const url = new URL('/admin/getSites', window.location.origin); + const response = await fetch(url); + const data = await response.json(); + return data.sites; +} + +async function fetchUsers(limit, page) { + const url = new URL('/admin/getUsers', window.location.origin); + const response = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + limit: limit, + page: page + }), + }); + const data = await response.json(); + return data.users; +} + diff --git a/static/pictures/logo.jpg b/static/pictures/logo.jpg new file mode 100644 index 0000000..96cad74 Binary files /dev/null and b/static/pictures/logo.jpg differ diff --git a/templates/admin.html b/templates/admin.html new file mode 100644 index 0000000..1339684 --- /dev/null +++ b/templates/admin.html @@ -0,0 +1,449 @@ + + + + + Admin + + + + + + + + + +
+
+
+
+ + home + Profile +
+
+
+
+

Your Sites

+
+
+

Listed below are all the sites within your instance of MyPantry. Clicking on one will allow you + edit most of the attributes inherited by the site.

+
+
+ + + + + +
SiteDescription
+
+
+ +
+
+
+
+

Your Roles

+
+
+

Listed below are all the roles within your instance of MyPantry. Clicking on one will allow you + edit most of the attributes inherited by the role.

+
+
+ + + + + + +
SiteRoleRole Description
+
+
+ +
+
+
+
+

Your Users

+
+
+

Listed below is all the users that have access to your instance.

+
+
+ + + + + +
UsernameEmail
+
+
+ +
+
+
+
+
+
+ + + + + + + + + + \ No newline at end of file diff --git a/templates/admin/role.html b/templates/admin/role.html new file mode 100644 index 0000000..eaaa84a --- /dev/null +++ b/templates/admin/role.html @@ -0,0 +1,131 @@ + + + + + Edit Role + + + + + + + +
+
+
+ +
+ + +
+
+ + +
+
+ + +
+
+

Permissions

+
+
+
All
+
+
+

+ +

+

+ +

+
+
+

+ +

+

+ +

+
+
+ + +
+
+
+
+ + + + \ No newline at end of file diff --git a/templates/admin/users.html b/templates/admin/users.html new file mode 100644 index 0000000..7d8582c --- /dev/null +++ b/templates/admin/users.html @@ -0,0 +1,17 @@ +
+
+

Your Users

+
+
+

This is where all the users who have access to this instance!

+
+
+ %%userstable%% +
+
+ +
+
+ %%pagination%% +
+
diff --git a/templates/items/index.html b/templates/items/index.html index e01ae49..75dc955 100644 --- a/templates/items/index.html +++ b/templates/items/index.html @@ -19,45 +19,42 @@ cursor: pointer; } [type="radio"]:checked + span:after { - border: 2px solid rgb(0 128 0 / 30%); /* Outline color */ - background-color: rgb(0 128 0 / 30%); /* Fill color */ + border: 2px solid rgb(0 128 0 / 30%); + background-color: rgb(0 128 0 / 30%); } - header, main, footer, body { - padding-left: 300px; - } - @media only screen and (max-width : 992px) { - header, main, footer, body { - padding-left: 0; + .dropdown-disabled { + pointer-events: none; + opacity: 0.5; } - } - .dropdown-disabled { - pointer-events: none; - opacity: 0.5; /* or your desired degree of transparency */ - } + -