updated reports
This commit is contained in:
Binary file not shown.
@@ -99,26 +99,37 @@ def scan():
|
|||||||
date = request.form.get('date')
|
date = request.form.get('date')
|
||||||
time = request.form.get('time')
|
time = request.form.get('time')
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Connect to the database
|
# Connect to the database
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
# Insert query
|
# Check if the CP_full_code already exists
|
||||||
|
cursor.execute("SELECT Id FROM scan1_orders WHERE CP_full_code = ?", (cp_code,))
|
||||||
|
existing_entry = cursor.fetchone()
|
||||||
|
|
||||||
|
if existing_entry:
|
||||||
|
# Update the existing entry
|
||||||
|
update_query = """
|
||||||
|
UPDATE scan1_orders
|
||||||
|
SET operator_code = ?, OC1_code = ?, OC2_code = ?, quality_code = ?, date = ?, time = ?
|
||||||
|
WHERE CP_full_code = ?
|
||||||
|
"""
|
||||||
|
cursor.execute(update_query, (operator_code, oc1_code, oc2_code, defect_code, date, time, cp_code))
|
||||||
|
flash('Existing entry updated successfully.')
|
||||||
|
else:
|
||||||
|
# Insert a new entry
|
||||||
insert_query = """
|
insert_query = """
|
||||||
INSERT INTO scan1_orders (operator_code, CP_full_code, OC1_code, OC2_code, quality_code, date, time)
|
INSERT INTO scan1_orders (operator_code, CP_full_code, OC1_code, OC2_code, quality_code, date, time)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
"""
|
"""
|
||||||
print(f"Executing query: {insert_query}")
|
|
||||||
print(f"With values: ('{operator_code}', '{cp_code}', '{oc1_code}', '{oc2_code}', '{defect_code}', '{date}', '{time}')")
|
|
||||||
|
|
||||||
# Execute the query
|
|
||||||
cursor.execute(insert_query, (operator_code, cp_code, oc1_code, oc2_code, defect_code, date, time))
|
cursor.execute(insert_query, (operator_code, cp_code, oc1_code, oc2_code, defect_code, date, time))
|
||||||
|
flash('New entry inserted successfully.')
|
||||||
|
|
||||||
|
# Commit the transaction
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
flash('Scan data saved successfully.')
|
|
||||||
except mariadb.Error as e:
|
except mariadb.Error as e:
|
||||||
print(f"Error saving scan data: {e}")
|
print(f"Error saving scan data: {e}")
|
||||||
flash(f"Error saving scan data: {e}")
|
flash(f"Error saving scan data: {e}")
|
||||||
@@ -253,7 +264,6 @@ def get_report_data():
|
|||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
if report == "1": # Logic for the 1-day report
|
if report == "1": # Logic for the 1-day report
|
||||||
# Calculate the date 1 day ago
|
|
||||||
one_day_ago = datetime.now() - timedelta(days=1)
|
one_day_ago = datetime.now() - timedelta(days=1)
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT Id, operator_code, CP_base_code, OC1_code, OC2_code, quality_code, date, time, approved_quantity, rejected_quantity
|
SELECT Id, operator_code, CP_base_code, OC1_code, OC2_code, quality_code, date, time, approved_quantity, rejected_quantity
|
||||||
@@ -262,21 +272,11 @@ def get_report_data():
|
|||||||
ORDER BY date DESC, time DESC
|
ORDER BY date DESC, time DESC
|
||||||
""", (one_day_ago.strftime('%Y-%m-%d'),))
|
""", (one_day_ago.strftime('%Y-%m-%d'),))
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
# Debugging: Print fetched rows
|
|
||||||
print("Fetched rows for report 1 (last 1 day):", 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"]
|
data["headers"] = ["Id", "Operator Code", "CP Base Code", "OC1 Code", "OC2 Code", "Quality Code", "Date", "Time", "Approved Quantity", "Rejected Quantity"]
|
||||||
|
data["rows"] = [[str(cell) if isinstance(cell, (datetime, timedelta)) else cell for cell in row] for row in rows]
|
||||||
# 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
|
elif report == "2": # Logic for the 5-day report
|
||||||
# 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("""
|
||||||
SELECT Id, operator_code, CP_base_code, OC1_code, OC2_code, quality_code, date, time, approved_quantity, rejected_quantity
|
SELECT Id, operator_code, CP_base_code, OC1_code, OC2_code, quality_code, date, time, approved_quantity, rejected_quantity
|
||||||
@@ -285,24 +285,40 @@ def get_report_data():
|
|||||||
ORDER BY date DESC, time DESC
|
ORDER BY date DESC, time DESC
|
||||||
""", (five_days_ago.strftime('%Y-%m-%d'),))
|
""", (five_days_ago.strftime('%Y-%m-%d'),))
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
# Debugging: Print fetched rows
|
|
||||||
print("Fetched rows for report 2 (last 5 days):", 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"]
|
data["headers"] = ["Id", "Operator Code", "CP Base Code", "OC1 Code", "OC2 Code", "Quality Code", "Date", "Time", "Approved Quantity", "Rejected Quantity"]
|
||||||
|
data["rows"] = [[str(cell) if isinstance(cell, (datetime, timedelta)) else cell for cell in row] for row in rows]
|
||||||
|
|
||||||
# Convert rows to JSON serializable format
|
elif report == "3": # Logic for the report with non-zero quality_code (1 day)
|
||||||
data["rows"] = [
|
one_day_ago = datetime.now() - timedelta(days=1)
|
||||||
[str(cell) if isinstance(cell, (datetime, timedelta)) else cell for cell in row]
|
cursor.execute("""
|
||||||
for row in rows
|
SELECT Id, operator_code, CP_full_code, OC1_code, OC2_code, quality_code, date, time, approved_quantity, rejected_quantity
|
||||||
]
|
FROM scan1_orders
|
||||||
|
WHERE date >= ? AND quality_code != 0
|
||||||
|
ORDER BY date DESC, time DESC
|
||||||
|
""", (one_day_ago.strftime('%Y-%m-%d'),))
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
print("Fetched rows for report 3 (non-zero quality_code, last 1 day):", rows)
|
||||||
|
data["headers"] = ["Id", "Operator Code", "CP Full Code", "OC1 Code", "OC2 Code", "Quality Code", "Date", "Time", "Approved Quantity", "Rejected Quantity"]
|
||||||
|
data["rows"] = [[str(cell) if isinstance(cell, (datetime, timedelta)) else cell for cell in row] for row in rows]
|
||||||
|
|
||||||
|
elif report == "4": # Logic for the report with non-zero quality_code (5 days)
|
||||||
|
five_days_ago = datetime.now() - timedelta(days=5)
|
||||||
|
cursor.execute("""
|
||||||
|
SELECT Id, operator_code, CP_full_code, OC1_code, OC2_code, quality_code, date, time, approved_quantity, rejected_quantity
|
||||||
|
FROM scan1_orders
|
||||||
|
WHERE date >= ? AND quality_code != 0
|
||||||
|
ORDER BY date DESC, time DESC
|
||||||
|
""", (five_days_ago.strftime('%Y-%m-%d'),))
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
print("Fetched rows for report 4 (non-zero quality_code, last 5 days):", rows)
|
||||||
|
data["headers"] = ["Id", "Operator Code", "CP Full Code", "OC1 Code", "OC2 Code", "Quality Code", "Date", "Time", "Approved Quantity", "Rejected Quantity"]
|
||||||
|
data["rows"] = [[str(cell) if isinstance(cell, (datetime, timedelta)) else cell for cell in row] for row in rows]
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
except mariadb.Error as e:
|
except mariadb.Error as e:
|
||||||
print(f"Error fetching report data: {e}")
|
print(f"Error fetching report data: {e}")
|
||||||
data["error"] = "Error fetching report data."
|
data["error"] = "Error fetching report data."
|
||||||
|
|
||||||
# Debugging: Print the final data being returned
|
|
||||||
print("Data being returned:", data)
|
print("Data being returned:", data)
|
||||||
return jsonify(data)
|
return jsonify(data)
|
||||||
@@ -6,20 +6,20 @@
|
|||||||
<div class="card report-form-card">
|
<div class="card report-form-card">
|
||||||
<h3>Rapoarte</h3>
|
<h3>Rapoarte</h3>
|
||||||
<div class="form-centered">
|
<div class="form-centered">
|
||||||
<label class="report-description">Raport zilnic va exporta toate comenzile scanate la punctele de scanare calitate cu de acum 5 zile</label>
|
<label class="report-description">Raport zilnic va exporta toate comenzile scanate la punctele de scanare calitate</label>
|
||||||
<button class="btn report-btn" data-report="1">Raport zilnic de comenzi complet</button>
|
<button class="btn report-btn" data-report="1">Raport zilnic de comenzi complet</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-centered">
|
<div class="form-centered">
|
||||||
<label class="report-description">Report 1 va exporta toate comenzile scanate la punctele de scanare calitate cu de acum 5 zile</label>
|
<label class="report-description">Raport 5 zile va exporta toate comenzile scanate la punctele de scanare calitate</label>
|
||||||
<button class="btn report-btn" data-report="2">Raport 5 zile de comenzi complet</button>
|
<button class="btn report-btn" data-report="2">Raport 5 zile de comenzi complet</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-centered">
|
<div class="form-centered">
|
||||||
<label class="report-description">This report: Report 3 exports all rejected orders from the database.</label>
|
<label class="report-description">Raport articole cu probleme de calitate pe ziua curenta</label>
|
||||||
<button class="btn report-btn" data-report="3">Report 3</button>
|
<button class="btn report-btn" data-report="3">Raport Articole cu defecte ziua curenta</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-centered">
|
<div class="form-centered">
|
||||||
<label class="report-description">This report: Report 4 exports all orders with defects from the database.</label>
|
<label class="report-description">Raport articole cu probleme de calitate din ultimile 5 zile</label>
|
||||||
<button class="btn report-btn" data-report="4">Report 4</button>
|
<button class="btn report-btn" data-report="4">Raport Articole cu defecte in ultimile 5 zile</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-centered">
|
<div class="form-centered">
|
||||||
<label class="report-description">This report: Report 5 exports a summary of all orders from the database.</label>
|
<label class="report-description">This report: Report 5 exports a summary of all orders from the database.</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user