AO model code commit
This commit is contained in:
179
main.py
179
main.py
@@ -14,41 +14,36 @@ from AppCode.Config import DBConfig
|
||||
app = Flask(__name__)
|
||||
app.secret_key="secret1234"
|
||||
app.config['UPLOAD_FOLDER'] = FileHandler.UPLOAD_FOLDER
|
||||
#ALLOWED_EXTENSIONS = {'pdf', 'docx', 'doc', 'xlsx', 'xls'}
|
||||
|
||||
|
||||
|
||||
# welcome page
|
||||
@app.route('/')
|
||||
def welcome():
|
||||
return render_template('welcome.html')
|
||||
|
||||
# Dashboard page
|
||||
@app.route('/dashboard')
|
||||
def index():
|
||||
return render_template('index.html') # Your dashboard page
|
||||
return render_template('index.html')
|
||||
|
||||
# Ensure folder exists
|
||||
|
||||
def allowed_file(filename):
|
||||
return '.' in filename and filename.rsplit('.', 1)[1].lower() in FileHandler.ALLOWED_EXTENSIONS
|
||||
|
||||
|
||||
# Upload route
|
||||
# Upload File route
|
||||
@app.route('/upload', methods=['GET', 'POST'])
|
||||
def upload_file():
|
||||
|
||||
if request.method == 'POST':
|
||||
FileHandler.CHeckExistingOrCreateNewUploadFolder()
|
||||
docHandler = DocumentHandler()
|
||||
docHandler.Upload(request=request)
|
||||
return redirect(url_for('view_documents'))
|
||||
|
||||
return render_template('upload.html')
|
||||
|
||||
|
||||
# View all documents with filters
|
||||
@app.route('/documents')
|
||||
def view_documents():
|
||||
|
||||
docHandler = DocumentHandler()
|
||||
docHandler.View(request=request)
|
||||
return render_template('view_docs.html', documents=docHandler.documents, years=docHandler.years)
|
||||
@@ -75,73 +70,10 @@ def uploaded_file(filename):
|
||||
else:
|
||||
return abort(415) # Unsupported type for viewing
|
||||
|
||||
# --- Download Mode ---
|
||||
return send_file(filepath, as_attachment=True)
|
||||
|
||||
|
||||
# (Keep all your other routes and imports as they are)
|
||||
|
||||
## 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.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()
|
||||
|
||||
# # 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'
|
||||
# ]
|
||||
|
||||
# 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))
|
||||
|
||||
# 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
|
||||
# This route needs an ID to know which record to edit.
|
||||
@app.route('/itr/update/<int:id>', methods=['GET', 'POST'])
|
||||
def update_itr(id):
|
||||
conn = get_db_connection()
|
||||
@@ -179,19 +111,6 @@ def update_itr(id):
|
||||
return render_template('update_itr.html', record=record)
|
||||
|
||||
|
||||
## 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():
|
||||
@@ -229,8 +148,12 @@ def update_itr(id):
|
||||
# return redirect(url_for('index'))
|
||||
# return render_template('itr_form.html')
|
||||
|
||||
## ===============================================
|
||||
## ITR (Income Tax Return) Routes
|
||||
## ===============================================
|
||||
|
||||
# new new ---
|
||||
|
||||
## 1. READ/DISPLAY all ITR records
|
||||
@app.route('/itr_records')
|
||||
def display_itr():
|
||||
itr = ITRHandler()
|
||||
@@ -239,7 +162,7 @@ def display_itr():
|
||||
return render_template('display_itr.html', records=records)
|
||||
|
||||
|
||||
# new new ---
|
||||
## 2. CREATE/ADD a new ITR record
|
||||
@app.route('/itr/add', methods=['GET', 'POST'])
|
||||
def add_itr():
|
||||
if request.method == 'POST':
|
||||
@@ -252,7 +175,7 @@ def add_itr():
|
||||
|
||||
return render_template('add_itr.html')
|
||||
|
||||
# new new ---
|
||||
## 4. DELETE an ITR record
|
||||
@app.route('/itr/delete/<int:id>', methods=['POST'])
|
||||
def delete_itr(id):
|
||||
itr = ITRHandler()
|
||||
@@ -263,25 +186,11 @@ def delete_itr(id):
|
||||
|
||||
|
||||
|
||||
#
|
||||
# ADD THESE NEW FUNCTIONS TO YOUR APP.PY FILE
|
||||
#
|
||||
|
||||
## ===============================================
|
||||
## AO (Assessing Officer) Routes
|
||||
## ===============================================
|
||||
|
||||
# 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)
|
||||
|
||||
# 1. DISPLAY all AO records
|
||||
@app.route('/ao_records')
|
||||
def display_ao():
|
||||
ao = AOHandler()
|
||||
@@ -290,39 +199,29 @@ def display_ao():
|
||||
return render_template('display_ao.html', ao_records=ao_records)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ADD a new AO record
|
||||
# 2. ADD a new AO record
|
||||
@app.route('/ao/add', methods=['GET', 'POST'])
|
||||
def add_ao():
|
||||
if request.method == 'POST':
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
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]
|
||||
query = f"INSERT INTO ao ({', '.join(columns)}) VALUES ({', '.join(['%s'] * len(columns))})"
|
||||
cursor.execute(query, tuple(values))
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
ao = AOHandler()
|
||||
ao.add_ao(request.form)
|
||||
ao.close()
|
||||
flash("AO record added successfully!", "success")
|
||||
return redirect(url_for('display_ao'))
|
||||
|
||||
return render_template('add_ao.html')
|
||||
|
||||
|
||||
# 4. DELETE AO record safely
|
||||
@app.route('/ao/delete/<int:id>', methods=['POST'])
|
||||
def delete_ao(id):
|
||||
ao = AOHandler()
|
||||
ao.delete_ao_by_id(id=id)
|
||||
ao.close()
|
||||
flash("AO deleted successfully!", "success")
|
||||
return redirect(url_for('display_ao'))
|
||||
|
||||
# (You will also need to add update_ao and delete_ao functions later)
|
||||
# UPDATE AO record
|
||||
|
||||
# 3. UPDATE AO record
|
||||
@app.route('/ao/update/<int:id>', methods=['GET', 'POST'])
|
||||
def update_ao(id):
|
||||
conn = get_db_connection()
|
||||
@@ -360,34 +259,8 @@ def update_ao(id):
|
||||
|
||||
|
||||
|
||||
# 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'))
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
# ADD THESE NEW CIT FUNCTIONS TO YOUR APP.PY FILE
|
||||
#
|
||||
|
||||
## =======================================================
|
||||
## CIT (Commissioner of Income Tax) Routes
|
||||
## =======================================================
|
||||
|
||||
Reference in New Issue
Block a user