cit model commit.
This commit is contained in:
305
main.py
305
main.py
@@ -4,13 +4,16 @@ 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 AppCode.CITHandler import CITHandler
|
||||
from AppCode.ITATHandler import ITATHandler
|
||||
|
||||
from config import db_config
|
||||
from AppCode.Config import DBConfig
|
||||
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key="secret1234"
|
||||
app.config['UPLOAD_FOLDER'] = FileHandler.UPLOAD_FOLDER
|
||||
@@ -268,41 +271,51 @@ def update_ao(id):
|
||||
# DISPLAY all CIT records
|
||||
@app.route('/cit_records')
|
||||
def display_cit():
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
cursor.execute("SELECT * FROM cit ORDER BY year DESC, id DESC")
|
||||
cit_records = cursor.fetchall()
|
||||
cursor.close()
|
||||
conn.close()
|
||||
cit = CITHandler()
|
||||
cit_records = cit.get_all_cit()
|
||||
cit.close()
|
||||
return render_template('display_cit.html', cit_records=cit_records)
|
||||
|
||||
|
||||
|
||||
# ADD a new CIT record
|
||||
@app.route('/cit/add', methods=['GET', 'POST'])
|
||||
def add_cit():
|
||||
if request.method == 'POST':
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
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]
|
||||
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()
|
||||
cit = CITHandler()
|
||||
cit.add_cit(request.form)
|
||||
cit.close()
|
||||
flash("CIT record added successfully!", "success")
|
||||
return redirect(url_for('display_cit'))
|
||||
|
||||
return render_template('add_cit.html')
|
||||
|
||||
|
||||
@app.route('/cit/delete/<int:id>', methods=['POST'])
|
||||
def delete_cit(id):
|
||||
cit = CITHandler()
|
||||
cit.delete_cit(id)
|
||||
cit.close()
|
||||
flash("CIT record deleted successfully!", "success")
|
||||
return redirect(url_for('display_cit'))
|
||||
|
||||
|
||||
# @app.route('/cit/update/<int:id>', methods=['GET', 'POST'])
|
||||
# def update_cit(id):
|
||||
# handler = CITHandler()
|
||||
# record = handler.get_cit_by_id(id)
|
||||
|
||||
# if not record:
|
||||
# handler.close()
|
||||
# return "CIT record not found", 404
|
||||
|
||||
# if request.method == 'POST':
|
||||
# handler.update_cit(id, request.form)
|
||||
# handler.close()
|
||||
# return redirect(url_for('display_cit'))
|
||||
|
||||
# handler.close()
|
||||
# return render_template('add_cit.html', record=record)
|
||||
|
||||
|
||||
|
||||
@app.route('/cit/update/<int:id>', methods=['GET', 'POST'])
|
||||
def update_cit(id):
|
||||
conn = get_db_connection()
|
||||
@@ -334,30 +347,61 @@ def update_cit(id):
|
||||
conn.close()
|
||||
return render_template('add_cit.html', record=record)
|
||||
|
||||
# DISPLAY all CIT records
|
||||
# @app.route('/cit_records')
|
||||
# def display_cit():
|
||||
# conn = get_db_connection()
|
||||
# cursor = conn.cursor(dictionary=True)
|
||||
# cursor.execute("SELECT * FROM cit ORDER BY year DESC, id DESC")
|
||||
# cit_records = cursor.fetchall()
|
||||
# cursor.close()
|
||||
# conn.close()
|
||||
# return render_template('display_cit.html', cit_records=cit_records)
|
||||
|
||||
@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'))
|
||||
|
||||
# ADD a new CIT record
|
||||
# @app.route('/cit/add', methods=['GET', 'POST'])
|
||||
# def add_cit():
|
||||
# if request.method == 'POST':
|
||||
# conn = get_db_connection()
|
||||
# cursor = conn.cursor()
|
||||
|
||||
# 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]
|
||||
# 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')
|
||||
|
||||
|
||||
|
||||
# (You will also need to add update_cit and delete_cit functions later)
|
||||
# @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'))
|
||||
|
||||
|
||||
#
|
||||
# ADD THESE FINAL FUNCTIONS FOR ITAT TO YOUR APP.PY FILE
|
||||
#
|
||||
|
||||
## =======================================================
|
||||
## ITAT (Income Tax Appellate Tribunal) Routes
|
||||
@@ -366,16 +410,89 @@ def delete_cit(id):
|
||||
# DISPLAY all ITAT records
|
||||
@app.route('/itat_records')
|
||||
def display_itat():
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
# Querying the 'itat' table
|
||||
cursor.execute("SELECT * FROM itat ORDER BY year DESC, id DESC")
|
||||
records = cursor.fetchall()
|
||||
cursor.close()
|
||||
conn.close()
|
||||
# Rendering the 'display_itat.html' template
|
||||
itat = ITATHandler()
|
||||
records = itat.get_all_itat()
|
||||
itat.close()
|
||||
return render_template('display_itat.html', records=records)
|
||||
|
||||
# ADD a new ITAT record
|
||||
# @app.route('/itat/add', methods=['GET', 'POST'])
|
||||
# def add_itat():
|
||||
# cit = CITHandler()
|
||||
# cit_records = cit.get_all_cit()
|
||||
# cit.close()
|
||||
|
||||
# if request.method == 'POST':
|
||||
# data = {
|
||||
# "cit_id": request.form.get("cit_id"),
|
||||
# "year": request.form.get("year"),
|
||||
# "mat_tax_credit": request.form.get("mat_tax_credit"),
|
||||
# "surcharge": request.form.get("surcharge"),
|
||||
# "cess": request.form.get("cess"),
|
||||
# "total_credit": request.form.get("total_credit")
|
||||
# }
|
||||
|
||||
# itat = ITATHandler()
|
||||
# itat.add_itat(data)
|
||||
# itat.close()
|
||||
|
||||
# flash("ITAT Record Added Successfully!", "success")
|
||||
# return redirect(url_for('display_itat'))
|
||||
|
||||
# return render_template('add_itat.html', cit_records=cit_records)
|
||||
|
||||
|
||||
@app.route('/itat/delete/<int:id>', methods=['POST'])
|
||||
def delete_itat(id):
|
||||
itat = ITATHandler()
|
||||
itat.delete_itat_by_id(id)
|
||||
itat.close()
|
||||
flash("ITAT Record Deleted!", "success")
|
||||
return redirect(url_for('display_itat'))
|
||||
|
||||
|
||||
@app.route('/itat/update/<int:id>', methods=['GET', 'POST'])
|
||||
def update_itat(id):
|
||||
itat = ITATHandler()
|
||||
record = itat.get_itat_by_id(id)
|
||||
|
||||
if not record:
|
||||
flash("Record Not Found!", "danger")
|
||||
return redirect(url_for('display_itat'))
|
||||
|
||||
if request.method == 'POST':
|
||||
data = {
|
||||
"year": request.form.get("year"),
|
||||
"mat_tax_credit": request.form.get("mat_tax_credit"),
|
||||
"surcharge": request.form.get("surcharge"),
|
||||
"cess": request.form.get("cess"),
|
||||
"total_credit": request.form.get("total_credit")
|
||||
}
|
||||
|
||||
itat.update_itat(id, data)
|
||||
itat.close()
|
||||
flash("ITAT Record Updated!", "success")
|
||||
return redirect(url_for('display_itat'))
|
||||
|
||||
itat.close()
|
||||
return render_template('update_itat.html', record=record)
|
||||
|
||||
|
||||
|
||||
|
||||
# DISPLAY all ITAT records
|
||||
# @app.route('/itat_records')
|
||||
# def display_itat():
|
||||
# conn = get_db_connection()
|
||||
# cursor = conn.cursor(dictionary=True)
|
||||
# # Querying the 'itat' table
|
||||
# cursor.execute("SELECT * FROM itat ORDER BY year DESC, id DESC")
|
||||
# records = cursor.fetchall()
|
||||
# cursor.close()
|
||||
# conn.close()
|
||||
# # Rendering the 'display_itat.html' template
|
||||
# return render_template('display_itat.html', records=records)
|
||||
|
||||
|
||||
# ADD a new ITAT record
|
||||
@app.route('/itat/add', methods=['GET', 'POST'])
|
||||
@@ -409,53 +526,53 @@ def add_itat():
|
||||
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)
|
||||
# @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()
|
||||
# # 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 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'))
|
||||
# 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)
|
||||
# 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'))
|
||||
# @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'))
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user