From aa063b7a8047d5eaa9a338a95098e90a01dbdc42 Mon Sep 17 00:00:00 2001 From: pjpatil12 Date: Mon, 1 Dec 2025 12:04:07 +0530 Subject: [PATCH] cit model commit. --- AppCode/AOHandler.py | 2 +- AppCode/CITHandler.py | 74 +++++ AppCode/ITATHandler.py | 67 ++++ AppCode/__pycache__/AOHandler.cpython-313.pyc | Bin 2992 -> 2991 bytes .../__pycache__/CITHandler.cpython-313.pyc | Bin 0 -> 3003 bytes .../__pycache__/ITATHandler.cpython-313.pyc | Bin 0 -> 3418 bytes main.py | 305 ++++++++++++------ test.py | 103 ++++++ 8 files changed, 456 insertions(+), 95 deletions(-) create mode 100644 AppCode/CITHandler.py create mode 100644 AppCode/ITATHandler.py create mode 100644 AppCode/__pycache__/CITHandler.cpython-313.pyc create mode 100644 AppCode/__pycache__/ITATHandler.cpython-313.pyc create mode 100644 test.py diff --git a/AppCode/AOHandler.py b/AppCode/AOHandler.py index fb1d374..f8e2b37 100644 --- a/AppCode/AOHandler.py +++ b/AppCode/AOHandler.py @@ -24,7 +24,7 @@ class AOHandler: def get_ao_by_id(self, id): # Call stored procedure - self.cursor.callproc('GetAORById', [id]) + self.cursor.callproc('GetAOById', [id]) # Fetch result records = [] diff --git a/AppCode/CITHandler.py b/AppCode/CITHandler.py new file mode 100644 index 0000000..af283ef --- /dev/null +++ b/AppCode/CITHandler.py @@ -0,0 +1,74 @@ +from AppCode.Config import DBConfig +import mysql.connector + +class CITHandler: + + def __init__(self): + db = DBConfig() + self.conn = db.get_db_connection() + self.cursor = self.conn.cursor(dictionary=True) + + # GET ALL CIT RECORDS + def get_all_cit(self): + self.cursor.callproc("GetAllCIT") + records = [] + + for result in self.cursor.stored_results(): + records = result.fetchall() + + return records + + # GET CIT BY ID + def get_cit_by_id(self, id): + self.cursor.callproc("GetCITById", [id]) + records = [] + + for result in self.cursor.stored_results(): + records = result.fetchall() + + if records: + return records[0] + + return None + + # INSERT CIT RECORD + def add_cit(self, data): + 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 = [data.get(col, 0) for col in columns] + + self.cursor.callproc("InsertCIT", values) + self.conn.commit() + + # UPDATE CIT RECORD + # def update_cit(self, id, data): + # 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" + # ] + + # set_clause = ", ".join([f"{col}=%s" for col in columns]) + # query = f"UPDATE cit SET {set_clause} WHERE id=%s" + + # values = [data.get(col, 0) for col in columns] + # values.append(id) + + # self.cursor.execute(query, tuple(values)) + # self.conn.commit() + + # DELETE CIT RECORD + def delete_cit(self, id): + self.cursor.callproc("DeleteCITById", [id]) + self.conn.commit() + + # CLOSE CONNECTION + def close(self): + self.cursor.close() + self.conn.close() diff --git a/AppCode/ITATHandler.py b/AppCode/ITATHandler.py new file mode 100644 index 0000000..85ec3d4 --- /dev/null +++ b/AppCode/ITATHandler.py @@ -0,0 +1,67 @@ +# AppCode/ITATHandler.py +from AppCode.Config import DBConfig + + +class ITATHandler: + + def __init__(self): + self.conn = DBConfig.get_db_connection() + self.cursor = self.conn.cursor(dictionary=True) + + # GET ALL ITAT RECORDS (PROC) + def get_all_itat(self): + self.cursor.callproc("GetAllITAT") + records = [] + for result in self.cursor.stored_results(): + records = result.fetchall() + return records + + + # GET ITAT BY ID (PROC) + def get_itat_by_id(self, id): + self.cursor.callproc("GetITATById", [id]) + records = [] + for result in self.cursor.stored_results(): + records = result.fetchall() + if records: + return records[0] + return None + + + # INSERT ITAT (PROC) + def add_itat(self, data): + values = [ + data.get("cit_id"), + data.get("year"), + data.get("mat_tax_credit"), + data.get("surcharge"), + data.get("cess"), + data.get("total_credit") + ] + self.cursor.callproc("InsertITAT", values) + self.conn.commit() + + + # UPDATE ITAT (PROC) + def update_itat(self, id, data): + values = [ + id, + data.get("year"), + data.get("mat_tax_credit"), + data.get("surcharge"), + data.get("cess"), + data.get("total_credit") + ] + self.cursor.callproc("UpdateITAT", values) + self.conn.commit() + + # DELETE ITAT BY ID (PROC) + def delete_itat_by_id(self, id): + self.cursor.callproc("DeleteITATById", [id]) + self.conn.commit() + + + # CLOSE CONNECTION + def close(self): + self.cursor.close() + self.conn.close() diff --git a/AppCode/__pycache__/AOHandler.cpython-313.pyc b/AppCode/__pycache__/AOHandler.cpython-313.pyc index 268477c326e0d284a13fd7df5dacc480b70dc056..895d00007ef85142165bb17b8cba1a026395e24e 100644 GIT binary patch delta 47 zcmdlWzFwU7GcPX}0}#wm)y0n%svt$}5pha6@dt3^4`|f1i3X4=aq6v21c)2&t=EogLPcRDKfjrI^JeD# z-uumNx3{MVw1vSpoUfCF{ED4=QzK>jbx>A_PIT!!c~@dm0d@Jj%#=QIfapq|=;|@K zX3f;HT#P-&PEiut7z;97R@e)hE`^~>aDE`Qrub~bVYYq^2%58cZR+{>LVV)kJrQB z_O~EbFo5vi+I9=SE**=YDv%)rY4??}R$qkFfybr+a#iVhz5%(f`AdDRWL(B|#H{1|473Ts2t1hY+_ zSzN>;6TEz(P+%Q6n?{_$nwm}^a!s*s8b>#L0>llnskPlo-%M|4{cBqPoy+T5akD$S zlz0T;zp{K~BR9O38-AEOvUFxM*MHkz_V4Fj{rv1xh4hX-iIY9OOC78W{FsgOg-)X! zet^!4;Zc%?qgm;^>)P#A+6EKdW#)5E13xfaARlBY(QDaOHDo(FHtZO5uF4(H=3MmeOmN#A zJwYvpL)G}77@ld1_MO?W;j-xV0L#F*Zp^uM-E#-@>F6+Bu$c+8D6-g}^ZhFns(2o7 z9~q;^L>fmIj73~2+IW>gC9|?kM~;XToQ#@q7CI`rYKLw%PE`!ZA0PrK<95djY$*1C z9vMAqie$rDqz&sDo)}LjlmJLU2}}xK;3u7-QN;d7m&WE99Q; zri_oq4uUDa2;v6Wl4F_FQsQX`89IKy>-cx&Z}{!O<-t3n-$)O;58N#;#qV_;fAlOl ztq!bfBS=`uo5>BWZ%ylapymJEN|5do;VEwJ8{e<)PDKnh{XbL$d5Y!T(w;{!n5Rhf z?US}^2X@3Ez#K^TJCSDiVN#UCFte9HkKW!InWwC9aTw2@rg-iQBa3q+uvYq@t8CR; z*G608RU?Jw;>N-aNx=o>MS`?blK&7M^xD#P)%k>{dP<+qdh4T{zP(rsAnW8zeP}n3;zP0qjaSJ literal 0 HcmV?d00001 diff --git a/AppCode/__pycache__/ITATHandler.cpython-313.pyc b/AppCode/__pycache__/ITATHandler.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e748652cc607709c27a946abec2e55c668753593 GIT binary patch literal 3418 zcmcIn-EY%Y6u)-t#7W$gwjs2kunbCBwoyI?Y_JKfP>pueswr-^Np!P}?RFN9-Ca9~ zzVS4*(6# zz1{8U$q;A{PaZSa6d}K1Cu&?M?2dr2N+cpNpOB9k%9O|;IYcD3NTkFWHkd`(d9KVq z!cLj-go%rnY-`S#R|9Q;OxW4I0KzJnC6ti}WhI6t&=}>U1RyVQfJuo5Oi4*VK}rFp zB>^xarD=9PQ_gzXshRPaNyXAkoj&5hq8i!9&*0`0@VDy%tdc8$L92utj{5j}h@1(# zRbsaERZ@vu5Sv^9H+43Nk=Sz#ti><-ZJv}9(=*_SjAp2=VOt7aEOQj~Uf;a#%Gy;~ zwJl5cl^%z(msIQ2vFSSFagJ`zIe4CucmC4(*)ME*ZFWMxuABBkO}E_HDND6$`iycz zT6A2!HaotsaLLy6*_cnp78X50mJQ2rW!cNeHPI*@#d! zS+MR2s$!Z8)KePBgxg)MYi!G9k*FULrgInG2m?X$wZ zGAoH{;<>D_Emqh!V4v6&;JV66EK)u~{3P@sudcho=+qCYb>2%rl=vlpVh~Wg55c@$s~K*T@SLW&ikG~u zn02uBM79fxrUjY)M1_q;OJL2p0dSK%6!+YkT%NrBWkWpJ4CT)o;&3Q$>^;&DM8<)NiV0jg~3f>@PSYa;xAr&Tk%&2 z;}44G^CPgkz8!(x_3a4ku5U+RcYP}YA;Jrny)|J5QaHBAo#X>41|@49>f`MBOC+hC`H-2zbJ^5eepUJQ;gv{8vuhP*M2{7%e7BTY{}%9l@8AKV(%+}~ ztK-%GK-}w3so#gi4$|3i0c;#Nc8^_iw}jK(Gb^4sxB#4L)lHN|S^l=Jn4zXumgfxWxTaz0mMzP) z7Z%eZ!fOZ^`1BOQSpytJ_dz#dWE1weISUEUy!P6aGt!;{D!*4 jCwvf`?gG6CW9U|=AK-C', 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/', 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/', 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/', 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/', 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/', 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/', 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/', methods=['GET', 'POST']) -def update_itat(id): - conn = get_db_connection() - cursor = conn.cursor(dictionary=True) +# @app.route('/itat/update/', 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/', 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/', 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')) diff --git a/test.py b/test.py new file mode 100644 index 0000000..f9ddca0 --- /dev/null +++ b/test.py @@ -0,0 +1,103 @@ +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')