diff --git a/py_app/app/routes.py b/py_app/app/routes.py index 178d6aa..40ff3f7 100644 --- a/py_app/app/routes.py +++ b/py_app/app/routes.py @@ -252,7 +252,30 @@ def get_report_data(): conn = get_db_connection() cursor = conn.cursor() - if report == "1": + if report == "1": # Logic for the 1-day report + # Calculate the date 1 day ago + one_day_ago = datetime.now() - timedelta(days=1) + cursor.execute(""" + SELECT Id, operator_code, CP_base_code, OC1_code, OC2_code, quality_code, date, time, approved_quantity, rejected_quantity + FROM scan1_orders + WHERE date >= ? + ORDER BY date DESC, time DESC + """, (one_day_ago.strftime('%Y-%m-%d'),)) + rows = cursor.fetchall() + + # Debugging: Print fetched rows + print("Fetched rows for report 1 (last 1 day):", rows) + + # Define headers based on database column names + data["headers"] = ["Id", "Operator Code", "CP Base Code", "OC1 Code", "OC2 Code", "Quality Code", "Date", "Time", "Approved Quantity", "Rejected Quantity"] + + # Convert rows to JSON serializable format + data["rows"] = [ + [str(cell) if isinstance(cell, (datetime, timedelta)) else cell for cell in row] + for row in rows + ] + + elif report == "2": # Logic for the 5-day report # Calculate the date 5 days ago five_days_ago = datetime.now() - timedelta(days=5) cursor.execute(""" @@ -264,7 +287,7 @@ def get_report_data(): rows = cursor.fetchall() # Debugging: Print fetched rows - print("Fetched rows for report 1:", rows) + print("Fetched rows for report 2 (last 5 days):", rows) # Define headers based on database column names data["headers"] = ["Id", "Operator Code", "CP Base Code", "OC1 Code", "OC2 Code", "Quality Code", "Date", "Time", "Approved Quantity", "Rejected Quantity"]