updated structure in the table view

This commit is contained in:
Quality System Admin
2025-10-26 19:30:12 +02:00
parent 8cbede35d2
commit d142129de6
9 changed files with 760 additions and 185 deletions

View File

@@ -906,8 +906,8 @@ def api_get_production_data():
params = []
if search:
where_conditions.append("(production_order LIKE %s OR customer_code LIKE %s OR article_code LIKE %s)")
params.extend([f"%{search}%", f"%{search}%", f"%{search}%"])
where_conditions.append("(production_order LIKE %s OR open_for_order_line LIKE %s OR client_order_line LIKE %s OR customer_code LIKE %s OR article_code LIKE %s)")
params.extend([f"%{search}%", f"%{search}%", f"%{search}%", f"%{search}%", f"%{search}%"])
if filter_status:
where_conditions.append("production_status = %s")
@@ -927,10 +927,10 @@ def api_get_production_data():
# Get paginated data
offset = (page - 1) * per_page
data_query = f"""
SELECT id, production_order, customer_code, customer_name, client_order,
article_code, article_description, quantity_requested, delivery_date,
production_status, end_of_quilting, end_of_sewing, machine_code,
data_planificare
SELECT id, production_order, open_for_order_line, client_order_line,
customer_code, customer_name, article_code, article_description,
quantity_requested, delivery_date, production_status,
end_of_quilting, end_of_sewing, machine_code, data_planificare
FROM dm_production_orders {where_clause}
ORDER BY data_planificare DESC, production_order
LIMIT %s OFFSET %s
@@ -942,18 +942,19 @@ def api_get_production_data():
records.append({
'id': row[0],
'production_order': row[1],
'customer_code': row[2],
'customer_name': row[3],
'client_order': row[4],
'article_code': row[5],
'article_description': row[6],
'quantity_requested': row[7],
'delivery_date': str(row[8]) if row[8] else None,
'production_status': row[9],
'end_of_quilting': str(row[10]) if row[10] else None,
'end_of_sewing': str(row[11]) if row[11] else None,
'machine_code': row[12],
'data_planificare': str(row[13]) if row[13] else None
'open_for_order_line': row[2],
'client_order_line': row[3],
'customer_code': row[4],
'customer_name': row[5],
'article_code': row[6],
'article_description': row[7],
'quantity_requested': row[8],
'delivery_date': str(row[9]) if row[9] else None,
'production_status': row[10],
'end_of_quilting': str(row[11]) if row[11] else None,
'end_of_sewing': str(row[12]) if row[12] else None,
'machine_code': row[13],
'data_planificare': str(row[14]) if row[14] else None
})
dm_db.disconnect()
@@ -986,7 +987,8 @@ def api_update_production_data(record_id):
update_query = """
UPDATE dm_production_orders SET
customer_code = %s, customer_name = %s, client_order = %s,
open_for_order_line = %s, client_order_line = %s,
customer_code = %s, customer_name = %s,
article_code = %s, article_description = %s, quantity_requested = %s,
delivery_date = %s, production_status = %s, machine_code = %s,
updated_at = CURRENT_TIMESTAMP
@@ -994,9 +996,10 @@ def api_update_production_data(record_id):
"""
cursor.execute(update_query, (
data.get('open_for_order_line'),
data.get('client_order_line'),
data.get('customer_code'),
data.get('customer_name'),
data.get('client_order'),
data.get('article_code'),
data.get('article_description'),
data.get('quantity_requested'),
@@ -1013,4 +1016,106 @@ def api_update_production_data(record_id):
except Exception as e:
print(f"Error updating production data: {e}")
return jsonify({'error': str(e)}), 500
@daily_mirror_bp.route('/api/tune/production_data/<int:record_id>', methods=['DELETE'])
def api_delete_production_data(record_id):
"""API endpoint to delete a production record"""
access_check = check_daily_mirror_api_access()
if access_check:
return access_check
try:
dm_db = DailyMirrorDatabase()
dm_db.connect()
cursor = dm_db.connection.cursor()
# Delete the record
delete_query = "DELETE FROM dm_production_orders WHERE id = ?"
cursor.execute(delete_query, (record_id,))
if cursor.rowcount == 0:
dm_db.disconnect()
return jsonify({'error': 'Record not found'}), 404
dm_db.connection.commit()
dm_db.disconnect()
return jsonify({'success': True, 'message': 'Production record deleted successfully'})
except Exception as e:
print(f"Error deleting production data: {e}")
return jsonify({'error': str(e)}), 500
@daily_mirror_bp.route('/clear_production_orders', methods=['POST'])
def clear_production_orders():
"""Delete all rows from the Daily Mirror production orders table"""
# Check access
access_check = check_daily_mirror_api_access()
if access_check:
return access_check
try:
dm_db = DailyMirrorDatabase()
dm_db.connect()
result = dm_db.clear_production_orders()
dm_db.disconnect()
if result:
return jsonify({'success': True, 'message': 'All production orders deleted successfully.'})
else:
return jsonify({'success': False, 'message': 'Error deleting production orders.'}), 500
except Exception as e:
print(f"Error clearing production orders: {e}")
return jsonify({'error': str(e)}), 500
@daily_mirror_bp.route('/clear_orders', methods=['POST'])
def clear_orders():
"""Delete all rows from the Daily Mirror orders table"""
# Check access
access_check = check_daily_mirror_api_access()
if access_check:
return access_check
try:
dm_db = DailyMirrorDatabase()
dm_db.connect()
result = dm_db.clear_orders()
dm_db.disconnect()
if result:
return jsonify({'success': True, 'message': 'All orders deleted successfully.'})
else:
return jsonify({'success': False, 'message': 'Error deleting orders.'}), 500
except Exception as e:
print(f"Error clearing orders: {e}")
return jsonify({'error': str(e)}), 500
@daily_mirror_bp.route('/clear_delivery', methods=['POST'])
def clear_delivery():
"""Delete all rows from the Daily Mirror delivery table"""
# Check access
access_check = check_daily_mirror_api_access()
if access_check:
return access_check
try:
dm_db = DailyMirrorDatabase()
dm_db.connect()
result = dm_db.clear_delivery()
dm_db.disconnect()
if result:
return jsonify({'success': True, 'message': 'All delivery records deleted successfully.'})
else:
return jsonify({'success': False, 'message': 'Error deleting delivery records.'}), 500
except Exception as e:
print(f"Error clearing delivery records: {e}")
return jsonify({'error': str(e)}), 500