updated validation and auto submit
This commit is contained in:
@@ -299,6 +299,79 @@ def logout():
|
||||
session.pop('role', None)
|
||||
return redirect(url_for('main.login'))
|
||||
|
||||
# Finish Goods Scan Route
|
||||
@bp.route('/fg_scan', methods=['GET', 'POST'])
|
||||
def fg_scan():
|
||||
if 'role' not in session or session['role'] not in ['superadmin', 'administrator', 'admin', 'scan']:
|
||||
flash('Access denied: Scan users only.')
|
||||
return redirect(url_for('main.dashboard'))
|
||||
|
||||
if request.method == 'POST':
|
||||
# Handle form submission
|
||||
operator_code = request.form.get('operator_code')
|
||||
cp_code = request.form.get('cp_code')
|
||||
oc1_code = request.form.get('oc1_code')
|
||||
oc2_code = request.form.get('oc2_code')
|
||||
defect_code = request.form.get('defect_code')
|
||||
date = request.form.get('date')
|
||||
time = request.form.get('time')
|
||||
|
||||
try:
|
||||
# Connect to the database
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Check if the CP_full_code already exists in scanfg_orders
|
||||
cursor.execute("SELECT Id FROM scanfg_orders WHERE CP_full_code = ?", (cp_code,))
|
||||
existing_entry = cursor.fetchone()
|
||||
|
||||
if existing_entry:
|
||||
# Update the existing entry
|
||||
update_query = """
|
||||
UPDATE scanfg_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 scanfg_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()
|
||||
|
||||
except mariadb.Error as e:
|
||||
print(f"Error saving finish goods scan data: {e}")
|
||||
flash(f"Error saving scan data: {e}")
|
||||
|
||||
# Fetch the latest scan data for display from scanfg_orders
|
||||
scan_data = []
|
||||
try:
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
SELECT Id, operator_code, CP_base_code, OC1_code, OC2_code, quality_code, date, time, approved_quantity, rejected_quantity
|
||||
FROM scanfg_orders
|
||||
ORDER BY Id DESC
|
||||
LIMIT 15
|
||||
""")
|
||||
raw_scan_data = cursor.fetchall()
|
||||
# Apply formatting to scan data for consistent date display
|
||||
scan_data = [[format_cell_data(cell) for cell in row] for row in raw_scan_data]
|
||||
conn.close()
|
||||
except mariadb.Error as e:
|
||||
print(f"Error fetching finish goods scan data: {e}")
|
||||
flash(f"Error fetching scan data: {e}")
|
||||
|
||||
return render_template('fg_scan.html', scan_data=scan_data)
|
||||
|
||||
@bp.route('/create_user', methods=['POST'])
|
||||
def create_user():
|
||||
return create_user_handler()
|
||||
|
||||
Reference in New Issue
Block a user