diff --git a/py_app/app/__pycache__/routes.cpython-312.pyc b/py_app/app/__pycache__/routes.cpython-312.pyc index b71b5fb..256aa1f 100644 Binary files a/py_app/app/__pycache__/routes.cpython-312.pyc and b/py_app/app/__pycache__/routes.cpython-312.pyc differ diff --git a/py_app/app/print_module.py b/py_app/app/print_module.py new file mode 100644 index 0000000..62f35e5 --- /dev/null +++ b/py_app/app/print_module.py @@ -0,0 +1,99 @@ +import mariadb +from flask import current_app + +def get_db_connection(): + """Get database connection using external server configuration""" + settings_file = current_app.instance_path + '/external_server.conf' + settings = {} + with open(settings_file, 'r') as f: + for line in f: + key, value = line.strip().split('=', 1) + settings[key] = value + return mariadb.connect( + user=settings['username'], + password=settings['password'], + host=settings['server_domain'], + port=int(settings['port']), + database=settings['database_name'] + ) + +def get_unprinted_orders_data(limit=100): + """ + Retrieve unprinted orders from the database for display + Returns list of order dictionaries where printed_labels != 1 + """ + try: + conn = get_db_connection() + cursor = conn.cursor() + + # Check if printed_labels column exists + cursor.execute("SHOW COLUMNS FROM order_for_labels LIKE 'printed_labels'") + column_exists = cursor.fetchone() + + if column_exists: + # Use printed_labels column + cursor.execute(""" + SELECT id, comanda_productie, cod_articol, descr_com_prod, cantitate, + com_achiz_client, nr_linie_com_client, customer_name, + customer_article_number, open_for_order, line_number, + printed_labels, created_at, updated_at + FROM order_for_labels + WHERE printed_labels != 1 + ORDER BY created_at DESC + LIMIT %s + """, (limit,)) + else: + # Fallback: get all orders if no printed_labels column + cursor.execute(""" + SELECT id, comanda_productie, cod_articol, descr_com_prod, cantitate, + com_achiz_client, nr_linie_com_client, customer_name, + customer_article_number, open_for_order, line_number, + created_at, updated_at + FROM order_for_labels + ORDER BY created_at DESC + LIMIT %s + """, (limit,)) + + orders = [] + for row in cursor.fetchall(): + if column_exists: + orders.append({ + 'id': row[0], + 'comanda_productie': row[1], + 'cod_articol': row[2], + 'descr_com_prod': row[3], + 'cantitate': row[4], + 'com_achiz_client': row[5], + 'nr_linie_com_client': row[6], + 'customer_name': row[7], + 'customer_article_number': row[8], + 'open_for_order': row[9], + 'line_number': row[10], + 'printed_labels': row[11], + 'created_at': row[12], + 'updated_at': row[13] + }) + else: + orders.append({ + 'id': row[0], + 'comanda_productie': row[1], + 'cod_articol': row[2], + 'descr_com_prod': row[3], + 'cantitate': row[4], + 'com_achiz_client': row[5], + 'nr_linie_com_client': row[6], + 'customer_name': row[7], + 'customer_article_number': row[8], + 'open_for_order': row[9], + 'line_number': row[10], + 'printed_labels': 0, # Default to not printed + 'created_at': row[11], + 'updated_at': row[12] + }) + + conn.close() + return orders + + except Exception as e: + print(f"Error retrieving unprinted orders: {e}") + return [] \ No newline at end of file diff --git a/py_app/app/routes.py b/py_app/app/routes.py index d45cf74..0da6f38 100644 --- a/py_app/app/routes.py +++ b/py_app/app/routes.py @@ -21,6 +21,7 @@ from app.settings import ( delete_user_handler, save_external_db_handler ) +from .print_module import get_unprinted_orders_data bp = Blueprint('main', __name__) warehouse_bp = Blueprint('warehouse', __name__) @@ -1148,6 +1149,19 @@ def view_orders(): orders = get_orders_from_database(200) # Get last 200 orders return render_template('view_orders.html', orders=orders) +@bp.route('/get_unprinted_orders', methods=['GET']) +def get_unprinted_orders(): + """Get all rows from order_for_labels where printed != 1""" + if 'role' not in session or session['role'] not in ['superadmin', 'warehouse_manager', 'etichete']: + return jsonify({'error': 'Access denied'}), 403 + + try: + data = get_unprinted_orders_data() + return jsonify(data) + + except Exception as e: + return jsonify({'error': str(e)}), 500 + @warehouse_bp.route('/create_locations', methods=['GET', 'POST']) def create_locations(): from app.warehouse import create_locations_handler diff --git a/py_app/app/templates/print_module.html b/py_app/app/templates/print_module.html index 1974a9b..4eabcbb 100644 --- a/py_app/app/templates/print_module.html +++ b/py_app/app/templates/print_module.html @@ -1,10 +1,184 @@ {% extends "base.html" %} -{% block title %}Print Module{% endblock %} +{% block head %} + +{% endblock %} {% block content %} -