From c10d328b06f99ba43e2947fa5950a32f8757d4d7 Mon Sep 17 00:00:00 2001 From: ske087 Date: Thu, 24 Apr 2025 15:22:59 +0300 Subject: [PATCH] updated reports --- py_app/app/__pycache__/routes.cpython-311.pyc | Bin 18649 -> 21097 bytes py_app/app/routes.py | 82 +++++++++++------- py_app/app/templates/quality.html | 12 +-- 3 files changed, 55 insertions(+), 39 deletions(-) diff --git a/py_app/app/__pycache__/routes.cpython-311.pyc b/py_app/app/__pycache__/routes.cpython-311.pyc index 2494f39cd6b3dc94340d4d45ce2ed11dc77c6766..ceec01e60a9bcb554506dc04ce280419a3edf2c5 100644 GIT binary patch delta 2764 zcmb7FdrVvB6~CV!JnZXNjBWf1mqH074zILH06Pg7X9Ni06$Jx{&j9YQ`AgTG)=2kPyJ&nm9~A~waI{_ zN_Tzl@%hgAopXNYyZ4^^hk5YVp91wwl}bV31MN}_`}TdLK4VmpwG>}prR1ne{}TG9 z%A`0aA)q+`zeIl1-gvv|E|5iY-d3Qoe1kz11%u!QMtmTm2og{TSo6`6LZix!=E91A zdRigk=QReCB1%OiQE5~bl}EF1Y<4;pEtiX3$EB zDqELEqTA+P^aE>wj^+zDq9`h`BTAzRvjHtzX(`cvZ#CQL=jl*RfSSht6JUaxlzOQN zFhotOaw%SifZ2>zEe??GNxz*3W}rj!nmp1IP@yl)rH`qax2Y=8an+i~R^^}G#MKa0 z{mi&^|GKC$6DqV_Zm;h0w0hj#%&`D-wDZJqCNkg;Rrxp=U}1zg)#T~)Fz$BW;CL|T z8{h&g<6;g^2@2*h$I14_`fd;U#<}w%@pgH-87|C1KhMF3p$_JRyK2j-dedrb+#ej_ zFKn^|{JdDw!SEyJMeVVrxA82?5PbwYRqUA@iSQ$#A%+d{@B)LDo;74o{aOT~o3c!~0 z=Wq2aPYNCV!kO<2fni~EOxOz(+DK9x5wwwe7qte#=uBu`Nv%r|&s3IFOp&uW#i`|C zp}j}wWrd-0!uhQ!NQQ$6ZB0^JBWP;~XWg}y*_N5(SB}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S-rIjho9jXedAl{{(ZM7Vv8N})VX z%n!ny<|!I>;DnOX(2LKN6f1p1z81bwvX9nw5EFSN=)$=c7YR6H$y4?a;dc0{<(2|= zgaex#P%}W3pUEA#i@VLXux86$NL`?DyP^ymtzG!L$|Lxpbw=eo7Xoe_zFXzNs>&Js zRP&a_e|ra*^NuF=r!^zsv&ThLL+30(#YQ*kY<(RP?_XBi+_2&sDYIVZ6W*=hygk) z@o%`FYK+ll|Z-H%UZP9T3n_fwUC0NzWg|*Blv}Pf8wz^r=AYl6pYmTECBP zb2|sxoE?5NC@H$5o<3O$$l4M7+)=2VB%a^M9au|Y%Z?(tLb(Zd<)>@zYuWKVqgBII z53tyH$ncCz7a9Mp*IVbA+6YrCGPN-k-qw^>7E>+u;C^OKOi9Rs)V!w>4A+gPjgZNT zX+UD?cwqGK@ZkqI*tC?c^16GTu|*i0$k^iP3jaGDNtU3)na%s51`EykY4#Mm6?|{i z*RP{*B^c}1(6`no>(}AWn=fQY1Bj&2L(-rjX_$~SKWGxSwXD{BOia>W5co0tPRle* s-vX;*fWQI`sNx7*AEP8ifOz|^KMJa#DFz5g&e90n5Th0qS(abrUr5s#(*OVf diff --git a/py_app/app/routes.py b/py_app/app/routes.py index 40ff3f7..86c536a 100644 --- a/py_app/app/routes.py +++ b/py_app/app/routes.py @@ -99,26 +99,37 @@ def scan(): date = request.form.get('date') time = request.form.get('time') - try: # Connect to the database conn = get_db_connection() cursor = conn.cursor() - # Insert query - insert_query = """ - INSERT INTO scan1_orders (operator_code, CP_full_code, OC1_code, OC2_code, quality_code, date, time) - VALUES (?, ?, ?, ?, ?, ?, ?) - """ - print(f"Executing query: {insert_query}") - print(f"With values: ('{operator_code}', '{cp_code}', '{oc1_code}', '{oc2_code}', '{defect_code}', '{date}', '{time}')") + # 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() - # Execute the query - cursor.execute(insert_query, (operator_code, cp_code, oc1_code, oc2_code, defect_code, date, time)) + 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 INTO scan1_orders (operator_code, CP_full_code, OC1_code, OC2_code, quality_code, date, time) + VALUES (?, ?, ?, ?, ?, ?, ?) + """ + 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.close() - flash('Scan data saved successfully.') except mariadb.Error as e: print(f"Error saving scan data: {e}") flash(f"Error saving scan data: {e}") @@ -253,7 +264,6 @@ def get_report_data(): cursor = conn.cursor() 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 @@ -262,21 +272,11 @@ def get_report_data(): 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 - ] + 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(""" 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 """, (five_days_ago.strftime('%Y-%m-%d'),)) rows = cursor.fetchall() - - # Debugging: Print fetched 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["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 == "3": # Logic for the report with non-zero quality_code (1 day) + one_day_ago = datetime.now() - timedelta(days=1) + 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 + """, (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() except mariadb.Error as e: print(f"Error fetching report data: {e}") data["error"] = "Error fetching report data." - # Debugging: Print the final data being returned print("Data being returned:", data) return jsonify(data) \ No newline at end of file diff --git a/py_app/app/templates/quality.html b/py_app/app/templates/quality.html index 2f20736..6704b93 100644 --- a/py_app/app/templates/quality.html +++ b/py_app/app/templates/quality.html @@ -6,20 +6,20 @@

Rapoarte

- +
- +
- - + +
- - + +