AO model code commit
This commit is contained in:
@@ -32,34 +32,38 @@ class AOHandler:
|
||||
records = result.fetchall()
|
||||
|
||||
if records:
|
||||
print(records[0])
|
||||
return records[0] # return single record
|
||||
|
||||
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"
|
||||
# def add_itr(self, data):
|
||||
values = [data.get(f, 0) for f in fields]
|
||||
|
||||
# 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 = [data.get(col, 0) for col in columns]
|
||||
|
||||
# # Call your stored procedure
|
||||
# self.cursor.callproc("InsertITR", values)
|
||||
# self.conn.commit()
|
||||
self.cursor.callproc("InsertAO", values)
|
||||
self.conn.commit()
|
||||
|
||||
|
||||
# UPDATE ITR RECORD by ITR id
|
||||
# UPDATE ITR RECORD by AO id
|
||||
# def update(self, id, data):
|
||||
|
||||
# columns = [
|
||||
@@ -82,11 +86,11 @@ class AOHandler:
|
||||
# self.conn.commit()
|
||||
|
||||
|
||||
# # DELETE RECORD by ITR id
|
||||
# def delete_itr_by_id(self, id):
|
||||
# # Call the stored procedure
|
||||
# self.cursor.callproc('DeleteITRById', [id])
|
||||
# self.conn.commit()
|
||||
# DELETE RECORD by AO id
|
||||
def delete_ao_by_id(self, id):
|
||||
# Call the stored procedure
|
||||
self.cursor.callproc('DeleteAOById', [id])
|
||||
self.conn.commit()
|
||||
|
||||
|
||||
# CLOSE CONNECTION
|
||||
|
||||
Binary file not shown.
Binary file not shown.
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
|
||||
## =======================================================
|
||||
|
||||
@@ -1,30 +1,75 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Update AO Record</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='index.css') }}">
|
||||
<style>
|
||||
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background-color: #f8f9fa; padding: 20px; color: #333; }
|
||||
.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; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
||||
background-color: #f8f9fa;
|
||||
padding: 20px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.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>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h2>Update AO Record for Year {{ record.year }}</h2>
|
||||
<form method="POST" action="{{ url_for('update_ao', id=record.id) }}">
|
||||
{% for field in record.keys() if field != 'id' %}
|
||||
<label>{{ field.replace("_", " ").title() }}:</label>
|
||||
<input type="number" step="any" name="{{ field }}" value="{{ record[field] }}" required>
|
||||
{% endfor %}
|
||||
<button type="submit">Update Record</button>
|
||||
</form>
|
||||
<h2>Update AO Record for Year {{ record.year }}</h2>
|
||||
<form method="POST" action="{{ url_for('update_ao', id=record.id) }}">
|
||||
{% for field in record.keys() if field != 'id' %}
|
||||
<label>{{ field.replace("_", " ").title() }}:</label>
|
||||
<input type="number" step="any" name="{{ field }}" value="{{ record[field] }}" required>
|
||||
{% endfor %}
|
||||
<button type="submit">Update Record</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
103
test.py
103
test.py
@@ -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')
|
||||
Reference in New Issue
Block a user