AO model code commit

This commit is contained in:
2025-11-30 20:38:41 +05:30
parent 0f3c596854
commit 0d6c873515
7 changed files with 114 additions and 296 deletions

View File

@@ -32,34 +32,38 @@ class AOHandler:
records = result.fetchall() records = result.fetchall()
if records: if records:
print(records[0])
return records[0] # return single record return records[0] # return single record
return None return None
""" variable of AO model
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
"""
def add_ao(self, data):
fields = [
"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"
]
# INSERT ITR RECORD using procedure "add_itr" values = [data.get(f, 0) for f in fields]
# def add_itr(self, data):
# columns = [ self.cursor.callproc("InsertAO", values)
# 'year', 'gross_total_income', 'disallowance_14a', 'disallowance_37', self.conn.commit()
# '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 = [data.get(col, 0) for col in columns]
# # Call your stored procedure
# self.cursor.callproc("InsertITR", values)
# self.conn.commit()
# UPDATE ITR RECORD by ITR id # UPDATE ITR RECORD by AO id
# def update(self, id, data): # def update(self, id, data):
# columns = [ # columns = [
@@ -82,11 +86,11 @@ class AOHandler:
# self.conn.commit() # self.conn.commit()
# # DELETE RECORD by ITR id # DELETE RECORD by AO id
# def delete_itr_by_id(self, id): def delete_ao_by_id(self, id):
# # Call the stored procedure # Call the stored procedure
# self.cursor.callproc('DeleteITRById', [id]) self.cursor.callproc('DeleteAOById', [id])
# self.conn.commit() self.conn.commit()
# CLOSE CONNECTION # CLOSE CONNECTION

View File

@@ -5,4 +5,3 @@ db_config = {
'database': 'income_tax', 'database': 'income_tax',
'port': 3306 'port': 3306
} }

179
main.py
View File

@@ -14,41 +14,36 @@ from AppCode.Config import DBConfig
app = Flask(__name__) app = Flask(__name__)
app.secret_key="secret1234" app.secret_key="secret1234"
app.config['UPLOAD_FOLDER'] = FileHandler.UPLOAD_FOLDER app.config['UPLOAD_FOLDER'] = FileHandler.UPLOAD_FOLDER
#ALLOWED_EXTENSIONS = {'pdf', 'docx', 'doc', 'xlsx', 'xls'}
# welcome page
@app.route('/') @app.route('/')
def welcome(): def welcome():
return render_template('welcome.html') return render_template('welcome.html')
# Dashboard page
@app.route('/dashboard') @app.route('/dashboard')
def index(): def index():
return render_template('index.html') # Your dashboard page return render_template('index.html')
# Ensure folder exists # Ensure folder exists
def allowed_file(filename): def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in FileHandler.ALLOWED_EXTENSIONS return '.' in filename and filename.rsplit('.', 1)[1].lower() in FileHandler.ALLOWED_EXTENSIONS
# Upload route # Upload File route
@app.route('/upload', methods=['GET', 'POST']) @app.route('/upload', methods=['GET', 'POST'])
def upload_file(): def upload_file():
if request.method == 'POST': if request.method == 'POST':
FileHandler.CHeckExistingOrCreateNewUploadFolder() FileHandler.CHeckExistingOrCreateNewUploadFolder()
docHandler = DocumentHandler() docHandler = DocumentHandler()
docHandler.Upload(request=request) docHandler.Upload(request=request)
return redirect(url_for('view_documents')) return redirect(url_for('view_documents'))
return render_template('upload.html') return render_template('upload.html')
# View all documents with filters # View all documents with filters
@app.route('/documents') @app.route('/documents')
def view_documents(): def view_documents():
docHandler = DocumentHandler() docHandler = DocumentHandler()
docHandler.View(request=request) docHandler.View(request=request)
return render_template('view_docs.html', documents=docHandler.documents, years=docHandler.years) return render_template('view_docs.html', documents=docHandler.documents, years=docHandler.years)
@@ -75,73 +70,10 @@ def uploaded_file(filename):
else: else:
return abort(415) # Unsupported type for viewing return abort(415) # Unsupported type for viewing
# --- Download Mode ---
return send_file(filepath, as_attachment=True) 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 ## 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']) @app.route('/itr/update/<int:id>', methods=['GET', 'POST'])
def update_itr(id): def update_itr(id):
conn = get_db_connection() conn = get_db_connection()
@@ -179,19 +111,6 @@ def update_itr(id):
return render_template('update_itr.html', record=record) 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']) # @app.route('/itr', methods=['GET', 'POST'])
# def itr_form(): # def itr_form():
@@ -229,8 +148,12 @@ def update_itr(id):
# return redirect(url_for('index')) # return redirect(url_for('index'))
# return render_template('itr_form.html') # return render_template('itr_form.html')
## ===============================================
## ITR (Income Tax Return) Routes
## ===============================================
# new new ---
## 1. READ/DISPLAY all ITR records
@app.route('/itr_records') @app.route('/itr_records')
def display_itr(): def display_itr():
itr = ITRHandler() itr = ITRHandler()
@@ -239,7 +162,7 @@ def display_itr():
return render_template('display_itr.html', records=records) return render_template('display_itr.html', records=records)
# new new --- ## 2. CREATE/ADD a new ITR record
@app.route('/itr/add', methods=['GET', 'POST']) @app.route('/itr/add', methods=['GET', 'POST'])
def add_itr(): def add_itr():
if request.method == 'POST': if request.method == 'POST':
@@ -252,7 +175,7 @@ def add_itr():
return render_template('add_itr.html') return render_template('add_itr.html')
# new new --- ## 4. DELETE an ITR record
@app.route('/itr/delete/<int:id>', methods=['POST']) @app.route('/itr/delete/<int:id>', methods=['POST'])
def delete_itr(id): def delete_itr(id):
itr = ITRHandler() itr = ITRHandler()
@@ -263,25 +186,11 @@ def delete_itr(id):
#
# ADD THESE NEW FUNCTIONS TO YOUR APP.PY FILE
#
## =============================================== ## ===============================================
## AO (Assessing Officer) Routes ## AO (Assessing Officer) Routes
## =============================================== ## ===============================================
# DISPLAY all AO records # 1. 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') @app.route('/ao_records')
def display_ao(): def display_ao():
ao = AOHandler() ao = AOHandler()
@@ -290,39 +199,29 @@ def display_ao():
return render_template('display_ao.html', ao_records=ao_records) return render_template('display_ao.html', ao_records=ao_records)
# 2. ADD a new AO record
# ADD a new AO record
@app.route('/ao/add', methods=['GET', 'POST']) @app.route('/ao/add', methods=['GET', 'POST'])
def add_ao(): def add_ao():
if request.method == 'POST': if request.method == 'POST':
conn = get_db_connection() ao = AOHandler()
cursor = conn.cursor() ao.add_ao(request.form)
columns = [ ao.close()
'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()
flash("AO record added successfully!", "success") flash("AO record added successfully!", "success")
return redirect(url_for('display_ao')) return redirect(url_for('display_ao'))
return render_template('add_ao.html') 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']) @app.route('/ao/update/<int:id>', methods=['GET', 'POST'])
def update_ao(id): def update_ao(id):
conn = get_db_connection() 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 ## CIT (Commissioner of Income Tax) Routes
## ======================================================= ## =======================================================

View File

@@ -1,30 +1,75 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Update AO Record</title> <title>Update AO Record</title>
<link rel="stylesheet" href="{{ url_for('static', filename='index.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='index.css') }}">
<style> <style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background-color: #f8f9fa; padding: 20px; color: #333; } body {
.container { max-width: 600px; margin: auto; background: white; padding: 30px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); } font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
h2 { text-align: center; margin-bottom: 20px; } background-color: #f8f9fa;
label { display: block; margin-top: 10px; font-weight: bold; } padding: 20px;
input { width: 100%; padding: 8px; margin-top: 5px; border-radius: 5px; border: 1px solid #ccc; } color: #333;
button { margin-top: 20px; padding: 10px 15px; border: none; border-radius: 5px; background-color: #007bff; color: white; cursor: pointer; font-size: 16px; } }
button:hover { background-color: #0056b3; }
.container {
max-width: 600px;
margin: auto;
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
margin-bottom: 20px;
}
label {
display: block;
margin-top: 10px;
font-weight: bold;
}
input {
width: 100%;
padding: 8px;
margin-top: 5px;
border-radius: 5px;
border: 1px solid #ccc;
}
button {
margin-top: 20px;
padding: 10px 15px;
border: none;
border-radius: 5px;
background-color: #007bff;
color: white;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
</style> </style>
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<h2>Update AO Record for Year {{ record.year }}</h2> <h2>Update AO Record for Year {{ record.year }}</h2>
<form method="POST" action="{{ url_for('update_ao', id=record.id) }}"> <form method="POST" action="{{ url_for('update_ao', id=record.id) }}">
{% for field in record.keys() if field != 'id' %} {% for field in record.keys() if field != 'id' %}
<label>{{ field.replace("_", " ").title() }}:</label> <label>{{ field.replace("_", " ").title() }}:</label>
<input type="number" step="any" name="{{ field }}" value="{{ record[field] }}" required> <input type="number" step="any" name="{{ field }}" value="{{ record[field] }}" required>
{% endfor %} {% endfor %}
<button type="submit">Update Record</button> <button type="submit">Update Record</button>
</form> </form>
</div> </div>
</body> </body>
</html> </html>

103
test.py
View File

@@ -1,103 +0,0 @@
import os
from AppCode.Config import DBConfig
from AppCode.FileHandler import FileHandler
from werkzeug.utils import secure_filename
class DocumentHandler:
years = ""
documents = ""
isSuccess = False
resultMessage = ""
def View(self,request):
year = request.args.get('year')
stage = request.args.get('stage')
dbconfig = DBConfig()
connection = dbconfig.get_db_connection()
if not connection:
self.isSuccess = False
return
cursor = connection.cursor()
params = []
query = "SELECT * FROM documents WHERE 1=1"
if year:
query += " AND year = %s"
params.append(year)
if stage:
query += " AND stage = %s"
params.append(stage)
cursor.execute(query, params)
documentsdata = cursor.fetchall()
print("*************")
print(documentsdata)
cursor.callproc("GetYear")
# records = []
# for result in cursor.stored_results():
# records = result.fetchall()
yearsdata = ""
for res in cursor.stored_results():
yearsdata = res.fetchall()
print(yearsdata)
self.years = yearsdata
self.documents = documentsdata
self.isSuccess = True
print("document --",documentsdata)
cursor.close()
connection.close()
def Upload(self, request):
"""Log user actions with timestamp, user, action, and details."""
dbconfig = DBConfig()
connection = dbconfig.get_db_connection()
if connection:
cursor = connection.cursor()
files = request.files.getlist('documents')
year = request.form['year']
stage = request.form['stage']
for file in files:
if file is not FileHandler.ALLOWED_EXTENSIONS:
continue
filename = secure_filename(file.filename)
filepath = os.path.join(FileHandler.UPLOAD_FOLDER, filename)
extension = file.filename.rsplit('.', 1)[1]
# Need to Check whetehr all three items are required
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))
cursor.callproc('InsertDocument', [
filename,
filepath,
extension,
year,
stage
])
connection.commit()
cursor.close()
connection.close()
# return redirect(url_for('view_documents'))
#return render_template('upload.html')