created the second report
This commit is contained in:
@@ -252,7 +252,30 @@ def get_report_data():
|
|||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
cursor = conn.cursor()
|
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
|
# Calculate the date 5 days ago
|
||||||
five_days_ago = datetime.now() - timedelta(days=5)
|
five_days_ago = datetime.now() - timedelta(days=5)
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
@@ -264,7 +287,7 @@ def get_report_data():
|
|||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
# Debugging: Print fetched rows
|
# 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
|
# 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"]
|
data["headers"] = ["Id", "Operator Code", "CP Base Code", "OC1 Code", "OC2 Code", "Quality Code", "Date", "Time", "Approved Quantity", "Rejected Quantity"]
|
||||||
|
|||||||
Reference in New Issue
Block a user