ITR model update code

This commit is contained in:
2025-11-30 16:24:49 +05:30
parent 602c87148d
commit d9a86f41a1
33 changed files with 1790 additions and 346 deletions

568
main.py
View File

@@ -1,13 +1,22 @@
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, abort
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, abort, flash,send_file
import os
import mysql.connector
from werkzeug.utils import secure_filename
from AppCode.FileHandler import FileHandler
from AppCode.DocumentHandler import DocumentHandler
from AppCode.ITRHandler import ITRHandler
from AppCode.AOHandler import AOHandler
from config import db_config
from AppCode.Config import DBConfig
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = os.path.join('static', 'uploads')
ALLOWED_EXTENSIONS = {'pdf', 'docx', 'doc', 'xlsx', 'xls'}
app.secret_key="secret1234"
app.config['UPLOAD_FOLDER'] = FileHandler.UPLOAD_FOLDER
#ALLOWED_EXTENSIONS = {'pdf', 'docx', 'doc', 'xlsx', 'xls'}
@app.route('/')
def welcome():
@@ -18,38 +27,19 @@ def index():
return render_template('index.html') # Your dashboard page
# Ensure folder exists
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
return '.' in filename and filename.rsplit('.', 1)[1].lower() in FileHandler.ALLOWED_EXTENSIONS
# Upload route
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
files = request.files.getlist('documents')
year = request.form['year']
stage = request.form['stage']
conn = mysql.connector.connect(**db_config)
cursor = conn.cursor()
for file in files:
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(filepath)
cursor.execute("""
INSERT INTO documents (filename, filepath, filetype, year, stage)
VALUES (%s, %s, %s, %s, %s)
""", (filename, filepath, file.filename.rsplit('.', 1)[1], year, stage))
conn.commit()
cursor.close()
conn.close()
FileHandler.CHeckExistingOrCreateNewUploadFolder()
docHandler = DocumentHandler()
docHandler.Upload(request=request)
return redirect(url_for('view_documents'))
return render_template('upload.html')
@@ -58,37 +48,13 @@ def upload_file():
# View all documents with filters
@app.route('/documents')
def view_documents():
year = request.args.get('year')
stage = request.args.get('stage')
conn = mysql.connector.connect(**db_config)
cursor = conn.cursor(dictionary=True)
query = "SELECT * FROM documents WHERE 1=1"
params = []
if year:
query += " AND year = %s"
params.append(year)
if stage:
query += " AND stage = %s"
params.append(stage)
cursor.execute(query, params)
documents = cursor.fetchall()
cursor.execute("SELECT DISTINCT year FROM documents ORDER BY year DESC")
years = [row['year'] for row in cursor.fetchall()]
cursor.close()
conn.close()
return render_template('view_docs.html', documents=documents, years=years)
docHandler = DocumentHandler()
docHandler.View(request=request)
return render_template('view_docs.html', documents=docHandler.documents, years=docHandler.years)
# Serve uploaded file
from flask import send_file
# Upload file documents
@app.route('/uploads/<filename>')
def uploaded_file(filename):
mode = request.args.get('mode', 'view')
@@ -117,47 +83,61 @@ def uploaded_file(filename):
## 1. READ/DISPLAY all ITR records
# This page will show all records in a table with Edit and Delete buttons.
@app.route('/itr_records')
def display_itr():
conn = get_db_connection()
cursor = conn.cursor(dictionary=True)
cursor.execute("SELECT * FROM itr ORDER BY year DESC, id DESC")
records = cursor.fetchall()
cursor.close()
conn.close()
return render_template('display_itr.html', records=records)
# @app.route('/itr_records')
# def display_itr():
# conn = get_db_connection()
# cursor = conn.cursor(dictionary=True)
# # cursor.execute("SELECT * FROM itr ORDER BY year DESC, id DESC")
# # records = cursor.fetchall()
# cursor.callproc("GetAllItr")
# records = []
# for result in cursor.stored_results():
# records = result.fetchall()
# cursor.close()
# conn.close()
# return render_template('display_itr.html', records=records)
## 2. CREATE/ADD a new ITR record
# This route handles both showing the blank form and saving the new data.
@app.route('/itr/add', methods=['GET', 'POST'])
def add_itr():
if request.method == 'POST':
conn = get_db_connection()
cursor = conn.cursor()
# @app.route('/itr/add', methods=['GET', 'POST'])
# def add_itr():
# if request.method == 'POST':
# conn = get_db_connection()
# cursor = conn.cursor()
# A list of all columns in your form and database table
columns = [
'year', 'gross_total_income', 'disallowance_14a', 'disallowance_37',
'deduction_80ia_business', 'deduction_80ia_misc', 'deduction_80ia_other',
'deduction_sec37_disallowance', 'deduction_80g', 'net_taxable_income',
'tax_30_percent', 'tax_book_profit_18_5', 'tax_payable', 'surcharge_12',
'edu_cess_3', 'total_tax_payable', 'mat_credit', 'interest_234c',
'total_tax', 'advance_tax', 'tds', 'tcs', 'tax_on_assessment', 'refund'
]
# # A list of all columns in your form and database table
# columns = [
# 'year', 'gross_total_income', 'disallowance_14a', 'disallowance_37',
# 'deduction_80ia_business', 'deduction_80ia_misc', 'deduction_80ia_other',
# 'deduction_sec37_disallowance', 'deduction_80g', 'net_taxable_income',
# 'tax_30_percent', 'tax_book_profit_18_5', 'tax_payable', 'surcharge_12',
# 'edu_cess_3', 'total_tax_payable', 'mat_credit', 'interest_234c',
# 'total_tax', 'advance_tax', 'tds', 'tcs', 'tax_on_assessment', 'refund'
# ]
query = f"INSERT INTO itr ({', '.join(columns)}) VALUES ({', '.join(['%s'] * len(columns))})"
values = [request.form.get(col, 0) for col in columns]
# values = [request.form.get(col, 0) for col in columns]
# # query = f"INSERT INTO itr ({', '.join(columns)}) VALUES ({', '.join(['%s'] * len(columns))})"
cursor.execute(query, tuple(values))
conn.commit()
cursor.close()
conn.close()
# After adding, redirect to the page that shows all records
return redirect(url_for('display_itr'))
# # cursor.execute(query, tuple(values))
# If it's a GET request, just show the blank form to add a record
return render_template('add_itr.html')
# cursor.callproc('InsertITR', values)
# conn.commit()
# cursor.close()
# conn.close()
# flash("ITAT record added successfully!", "success")
# # After adding, redirect to the page that shows all records
# return redirect(url_for('display_itr'))
# # If it's a GET request, just show the blank form to add a record
# return render_template('add_itr.html')
## 3. UPDATE an existing ITR record
@@ -201,52 +181,86 @@ def update_itr(id):
## 4. DELETE an ITR record
# This route also needs an ID to know which record to delete.
# @app.route('/itr/delete/<int:id>', methods=['POST'])
# def delete_itr(id):
# conn = get_db_connection()
# cursor = conn.cursor()
# cursor.execute("DELETE FROM itr WHERE id = %s", (id,))
# conn.commit()
# cursor.close()
# conn.close()
# # After deleting, redirect back to the display page
# return redirect(url_for('display_itr'))
# @app.route('/itr', methods=['GET', 'POST'])
# def itr_form():
# if request.method == 'POST':
# data = {key: request.form.get(key, 0) for key in request.form}
# conn = mysql.connector.connect(**db_config)
# cursor = conn.cursor()
# query = """
# INSERT INTO itr (
# year, gross_total_income, disallowance_14a, disallowance_37,
# deduction_80ia_business, deduction_80ia_misc, deduction_80ia_other,
# deduction_sec37_disallowance, deduction_80g, net_taxable_income,
# tax_30_percent, tax_book_profit_18_5, tax_payable, surcharge_12,
# edu_cess_3, total_tax_payable, mat_credit, interest_234c,
# total_tax, advance_tax, tds, tcs, tax_on_assessment, refund
# ) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
# """
# values = tuple([
# int(data.get('year', 0))
# ] + [
# float(data.get(col, 0)) for col in [
# 'gross_total_income', 'disallowance_14a', 'disallowance_37',
# 'deduction_80ia_business', 'deduction_80ia_misc', 'deduction_80ia_other',
# 'deduction_sec37_disallowance', 'deduction_80g', 'net_taxable_income',
# 'tax_30_percent', 'tax_book_profit_18_5', 'tax_payable', 'surcharge_12',
# 'edu_cess_3', 'total_tax_payable', 'mat_credit', 'interest_234c',
# 'total_tax', 'advance_tax', 'tds', 'tcs', 'tax_on_assessment', 'refund'
# ]
# ])
# cursor.execute(query, values)
# conn.commit()
# flash("ITR record deleted successfully!", "success")
# cursor.close()
# conn.close()
# return redirect(url_for('index'))
# return render_template('itr_form.html')
# new new ---
@app.route('/itr_records')
def display_itr():
itr = ITRHandler()
records = itr.get_all_itr()
itr.close()
return render_template('display_itr.html', records=records)
# new new ---
@app.route('/itr/add', methods=['GET', 'POST'])
def add_itr():
if request.method == 'POST':
itr = ITRHandler()
itr.add_itr(request.form)
itr.close()
flash("ITR record added successfully!", "success")
return redirect(url_for('display_itr'))
return render_template('add_itr.html')
# new new ---
@app.route('/itr/delete/<int:id>', methods=['POST'])
def delete_itr(id):
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("DELETE FROM itr WHERE id = %s", (id,))
conn.commit()
cursor.close()
conn.close()
# After deleting, redirect back to the display page
itr = ITRHandler()
itr.delete_itr_by_id(id=id)
itr.close()
return redirect(url_for('display_itr'))
@app.route('/itr', methods=['GET', 'POST'])
def itr_form():
if request.method == 'POST':
data = {key: request.form.get(key, 0) for key in request.form}
conn = mysql.connector.connect(**db_config)
cursor = conn.cursor()
query = """
INSERT INTO itr (
year, gross_total_income, disallowance_14a, disallowance_37,
deduction_80ia_business, deduction_80ia_misc, deduction_80ia_other,
deduction_sec37_disallowance, deduction_80g, net_taxable_income,
tax_30_percent, tax_book_profit_18_5, tax_payable, surcharge_12,
edu_cess_3, total_tax_payable, mat_credit, interest_234c,
total_tax, advance_tax, tds, tcs, tax_on_assessment, refund
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
"""
values = tuple([
int(data.get('year', 0))
] + [
float(data.get(col, 0)) for col in [
'gross_total_income', 'disallowance_14a', 'disallowance_37',
'deduction_80ia_business', 'deduction_80ia_misc', 'deduction_80ia_other',
'deduction_sec37_disallowance', 'deduction_80g', 'net_taxable_income',
'tax_30_percent', 'tax_book_profit_18_5', 'tax_payable', 'surcharge_12',
'edu_cess_3', 'total_tax_payable', 'mat_credit', 'interest_234c',
'total_tax', 'advance_tax', 'tds', 'tcs', 'tax_on_assessment', 'refund'
]
])
cursor.execute(query, values)
conn.commit()
cursor.close()
conn.close()
return redirect(url_for('index'))
return render_template('itr_form.html')
#
@@ -258,17 +272,25 @@ def itr_form():
## ===============================================
# DISPLAY all AO records
# @app.route('/ao_records')
# def display_ao():
# conn = get_db_connection()
# cursor = conn.cursor(dictionary=True) # dictionary=True to access fields by name
# cursor.execute("SELECT * FROM ao ORDER BY year DESC, id DESC")
# ao_records = cursor.fetchall()
# cursor.close()
# conn.close()
# return render_template('display_ao.html', ao_records=ao_records)
@app.route('/ao_records')
def display_ao():
conn = get_db_connection()
cursor = conn.cursor(dictionary=True)
# Note: Querying the 'ao' table
cursor.execute("SELECT * FROM ao ORDER BY year DESC, id DESC")
records = cursor.fetchall()
cursor.close()
conn.close()
# Note: Rendering the 'display_ao.html' template
return render_template('display_ao.html', records=records)
ao = AOHandler()
ao_records = ao.get_all_ao()
ao.close()
return render_template('display_ao.html', ao_records=ao_records)
# ADD a new AO record
@@ -277,8 +299,6 @@ def add_ao():
if request.method == 'POST':
conn = get_db_connection()
cursor = conn.cursor()
# Define the columns for the 'ao' table
columns = [
'year', 'gross_total_income', 'disallowance_14a', 'disallowance_37',
'deduction_80ia_business', 'deduction_sec37_disallowance', 'deduction_80g',
@@ -286,75 +306,82 @@ def add_ao():
'surcharge_12', 'edu_cess_3', 'total_tax_payable', 'mat_credit',
'interest_234c', 'total_tax', 'advance_tax', 'tds', 'tcs',
'tax_on_assessment', 'refund'
] # Make sure these match your 'ao' table columns!
# Note: Inserting into the 'ao' table
query = f"INSERT INTO ao ({', '.join(columns)}) VALUES ({', '.join(['%s'] * len(columns))})"
]
values = [request.form.get(col, 0) for col in columns]
query = f"INSERT INTO ao ({', '.join(columns)}) VALUES ({', '.join(['%s'] * len(columns))})"
cursor.execute(query, tuple(values))
conn.commit()
cursor.close()
conn.close()
# Note: Redirecting to the 'display_ao' function
flash("AO record added successfully!", "success")
return redirect(url_for('display_ao'))
# Note: Rendering the 'add_ao.html' template
return render_template('add_ao.html')
# (You will also need to add update_ao and delete_ao functions later)
# UPDATE AO record
@app.route('/ao/update/<int:id>', methods=['GET', 'POST'])
def update_ao(id):
conn = get_db_connection()
cursor = conn.cursor(dictionary=True)
cursor.execute("SELECT * FROM ao WHERE id = %s", (id,))
ao_record = cursor.fetchone()
if not ao_record:
cursor.close()
conn.close()
return "AO record not found", 404
@app.route('/ao', methods=['GET', 'POST'])
def ao_form():
if request.method == 'POST':
data = {key: request.form.get(key, 0) for key in request.form}
conn = mysql.connector.connect(**db_config)
cursor = conn.cursor()
query = """
INSERT INTO ao (
year, gross_total_income, disallowance_14a, disallowance_37,
deduction_80ia_business, deduction_sec37_disallowance, deduction_80g,
net_taxable_income, tax_30_percent, tax_book_profit_18_5,
surcharge_12, edu_cess_3, total_tax_payable, mat_credit,
interest_234c, total_tax, advance_tax, tds, tcs,
tax_on_assessment, refund
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
"""
values = tuple([
data.get('year'),
float(data.get('gross_total_income', 0)),
float(data.get('disallowance_14a', 0)),
float(data.get('disallowance_37', 0)),
float(data.get('deduction_80ia_business', 0)),
float(data.get('deduction_sec37_disallowance', 0)),
float(data.get('deduction_80g', 0)),
float(data.get('net_taxable_income', 0)),
float(data.get('tax_30_percent', 0)),
float(data.get('tax_book_profit_18_5', 0)),
float(data.get('surcharge_12', 0)),
float(data.get('edu_cess_3', 0)),
float(data.get('total_tax_payable', 0)),
float(data.get('mat_credit', 0)),
float(data.get('interest_234c', 0)),
float(data.get('total_tax', 0)),
float(data.get('advance_tax', 0)),
float(data.get('tds', 0)),
float(data.get('tcs', 0)),
float(data.get('tax_on_assessment', 0)),
float(data.get('refund', 0)),
])
cursor.execute(query, values)
columns = [
'year', 'gross_total_income', 'disallowance_14a', 'disallowance_37',
'deduction_80ia_business', 'deduction_sec37_disallowance', 'deduction_80g',
'net_taxable_income', 'tax_30_percent', 'tax_book_profit_18_5',
'surcharge_12', 'edu_cess_3', 'total_tax_payable', 'mat_credit',
'interest_234c', 'total_tax', 'advance_tax', 'tds', 'tcs',
'tax_on_assessment', 'refund'
]
values = [request.form.get(col, 0) for col in columns]
set_clause = ", ".join([f"{col}=%s" for col in columns])
query = f"UPDATE ao SET {set_clause} WHERE id=%s"
cursor.execute(query, tuple(values) + (id,))
conn.commit()
cursor.close()
conn.close()
return redirect(url_for('index'))
return render_template('ao_form.html')
flash("AO record updated successfully!", "success")
return redirect(url_for('display_ao'))
cursor.close()
conn.close()
return render_template('update_ao.html', record=ao_record)
# DELETE AO record safely
@app.route('/ao/delete/<int:id>', methods=['POST'])
def delete_ao(id):
try:
conn = get_db_connection()
cursor = conn.cursor()
# Delete dependent CIT records first
cursor.execute("DELETE FROM ao WHERE id = %s", (id,))
# Then delete AO record
cursor.execute("DELETE FROM ao WHERE id = %s", (id,))
conn.commit()
flash("AO record deleted successfully!", "success")
except Exception as err:
flash(f"Error deleting AO: {err}", "danger")
finally:
cursor.close()
conn.close()
return redirect(url_for('display_ao'))
#
@@ -370,13 +397,12 @@ def ao_form():
def display_cit():
conn = get_db_connection()
cursor = conn.cursor(dictionary=True)
# Querying the 'cit' table
cursor.execute("SELECT * FROM cit ORDER BY year DESC, id DESC")
records = cursor.fetchall()
cit_records = cursor.fetchall()
cursor.close()
conn.close()
# Rendering the 'display_cit.html' template
return render_template('display_cit.html', records=records)
return render_template('display_cit.html', cit_records=cit_records)
# ADD a new CIT record
@@ -386,28 +412,71 @@ def add_cit():
conn = get_db_connection()
cursor = conn.cursor()
# IMPORTANT: These columns match your 'cit' table structure
columns = [
'year', 'gross_total_income', 'deduction_80ia_business',
'deduction_sec37_disallowance', 'deduction_80g', 'net_taxable_income',
'tax_30_percent', 'tax_book_profit_18_5', 'tax_payable', 'surcharge_12',
'edu_cess_3', 'total_tax_payable', 'mat_credit', 'interest_234c',
'total_tax', 'advance_tax', 'tds', 'tcs', 'tax_on_assessment', 'refund'
"year", "gross_total_income", "deduction_80ia_business", "deduction_sec37_disallowance",
"deduction_80g", "net_taxable_income", "tax_30_percent", "tax_book_profit_18_5",
"tax_payable", "surcharge_12", "edu_cess_3", "total_tax_payable", "mat_credit",
"interest_234c", "total_tax", "advance_tax", "tds", "tcs", "tax_on_assessment", "refund"
]
# Inserting into the 'cit' table
query = f"INSERT INTO cit ({', '.join(columns)}) VALUES ({', '.join(['%s'] * len(columns))})"
values = [request.form.get(col, 0) for col in columns]
query = f"INSERT INTO cit ({', '.join(columns)}) VALUES ({', '.join(['%s']*len(columns))})"
cursor.execute(query, tuple(values))
conn.commit()
flash("ITAT record added successfully!", "success")
cursor.close()
conn.close()
return redirect(url_for('display_cit'))
return render_template('add_cit.html')
@app.route('/cit/update/<int:id>', methods=['GET', 'POST'])
def update_cit(id):
conn = get_db_connection()
cursor = conn.cursor(dictionary=True)
cursor.execute("SELECT * FROM cit WHERE id=%s", (id,))
record = cursor.fetchone()
if not record:
cursor.close()
conn.close()
return "CIT record not found", 404
if request.method == 'POST':
columns = [
"year", "gross_total_income", "deduction_80ia_business", "deduction_sec37_disallowance",
"deduction_80g", "net_taxable_income", "tax_30_percent", "tax_book_profit_18_5",
"tax_payable", "surcharge_12", "edu_cess_3", "total_tax_payable", "mat_credit",
"interest_234c", "total_tax", "advance_tax", "tds", "tcs", "tax_on_assessment", "refund"
]
values = [request.form.get(col, 0) for col in columns]
set_clause = ", ".join([f"{col}=%s" for col in columns])
query = f"UPDATE cit SET {set_clause} WHERE id=%s"
cursor.execute(query, tuple(values)+(id,))
conn.commit()
cursor.close()
conn.close()
# Redirecting to the 'display_cit' function
return redirect(url_for('display_cit'))
# Rendering the 'add_cit.html' template
return render_template('add_cit.html')
cursor.close()
conn.close()
return render_template('add_cit.html', record=record)
@app.route('/cit/delete/<int:id>', methods=['POST'])
def delete_cit(id):
try:
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("DELETE FROM cit WHERE id=%s", (id,))
conn.commit()
flash("ITR record deleted successfully!", "success")
except Exception as err:
print(f"Error deleting CIT record: {err}")
finally:
cursor.close()
conn.close()
return redirect(url_for('display_cit'))
# (You will also need to add update_cit and delete_cit functions later)
@@ -438,28 +507,83 @@ def display_itat():
# ADD a new ITAT record
@app.route('/itat/add', methods=['GET', 'POST'])
def add_itat():
conn = get_db_connection()
cursor = conn.cursor(dictionary=True)
# Fetch all CIT records to choose from
cursor.execute("SELECT id, year FROM cit ORDER BY year DESC")
cit_records = cursor.fetchall()
if request.method == 'POST':
conn = get_db_connection()
cursor = conn.cursor()
# NOTE: These are the specific columns for your 'itat' table
columns = [
'year', 'mat_tax_credit', 'surcharge', 'cess', 'total_credit'
]
# Inserting into the 'itat' table
cit_id = request.form.get('cit_id') # selected parent CIT id
columns = ['id', 'year','mat_tax_credit', 'surcharge', 'cess', 'total_credit']
values = [cit_id,
request.form.get('year', 0),
request.form.get('mat_tax_credit', 0),
request.form.get('surcharge', 0),
request.form.get('cess', 0),
request.form.get('total_credit', 0)]
query = f"INSERT INTO itat ({', '.join(columns)}) VALUES ({', '.join(['%s'] * len(columns))})"
values = [request.form.get(col, 0) for col in columns]
cursor.execute(query, tuple(values))
conn.commit()
cursor.close()
conn.close()
# Redirecting to the 'display_itat' function
flash("ITAT record added successfully!", "success")
return redirect(url_for('display_itat'))
# Rendering the 'add_itat.html' template
return render_template('add_itat.html')
cursor.close()
conn.close()
return render_template('add_itat.html', cit_records=cit_records)
@app.route('/itat/update/<int:id>', methods=['GET', 'POST'])
def update_itat(id):
conn = get_db_connection()
cursor = conn.cursor(dictionary=True)
# Fetch the existing record
cursor.execute("SELECT * FROM itat WHERE id=%s", (id,))
record = cursor.fetchone()
if not record:
cursor.close()
conn.close()
flash("ITAT record not found!", "danger")
return redirect(url_for('display_itat'))
if request.method == 'POST':
columns = ['year', 'mat_tax_credit', 'surcharge', 'cess', 'total_credit']
values = [request.form.get(col, 0) for col in columns]
set_clause = ", ".join([f"{col}=%s" for col in columns])
query = f"UPDATE itat SET {set_clause} WHERE id=%s"
cursor.execute(query, tuple(values) + (id,))
conn.commit()
cursor.close()
conn.close()
flash("ITAT record updated successfully!", "success")
return redirect(url_for('display_itat'))
cursor.close()
conn.close()
# Render a template with existing values filled in
return render_template('update_itat.html', record=record)
@app.route('/itat/delete/<int:id>', methods=['POST'])
def delete_itat(id):
try:
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("DELETE FROM itat WHERE id=%s", (id,))
conn.commit()
flash("ITAT record deleted successfully!", "success")
except Exception as err:
flash(f"Error deleting ITAT: {err}", "danger")
finally:
cursor.close()
conn.close()
return redirect(url_for('display_itat'))
# (You will also need to add update_itat and delete_itat functions later)