From 0d6c8735152ceeda74f7e53adb4757161eb0a4a0 Mon Sep 17 00:00:00 2001 From: pjpatil12 Date: Sun, 30 Nov 2025 20:38:41 +0530 Subject: [PATCH] AO model code commit --- AppCode/AOHandler.py | 50 ++--- AppCode/__pycache__/AOHandler.cpython-313.pyc | Bin 1957 -> 2992 bytes .../__pycache__/ITRHandler.cpython-313.pyc | Bin 3899 -> 3899 bytes config.py | 1 - main.py | 179 +++--------------- templates/update_ao.html | 77 ++++++-- test.py | 103 ---------- 7 files changed, 114 insertions(+), 296 deletions(-) delete mode 100644 test.py diff --git a/AppCode/AOHandler.py b/AppCode/AOHandler.py index 55ddafd..fb1d374 100644 --- a/AppCode/AOHandler.py +++ b/AppCode/AOHandler.py @@ -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 diff --git a/AppCode/__pycache__/AOHandler.cpython-313.pyc b/AppCode/__pycache__/AOHandler.cpython-313.pyc index 28aa3ee26ae0c285410a75c239a15090fd69ff16..268477c326e0d284a13fd7df5dacc480b70dc056 100644 GIT binary patch delta 1195 zcmZ8hO>7%Q6rTOF*Y?^@oZ3lTw{<`Q42Z;bObxB7CZbhMp$TzQ2_zVecgN0(^=_D5 z7ji%@m#XGK6s>@W1L_4Sc}aEZT|`qCY>pED8_&Bk@3Z>|Yj( z{y$PzRFMCjJTu8o0YgD%ad>diG}sgfY})@rz9`)EUsT@i9!zAni(79#(aszuC)hZc zbrE2=!XQYnkA4OC8qK1*@Sb3ctKtN@CAs1(azVNVS)AgEFboK}F#h&943!Ap?v?(7mOqW=e^C_`)ii`7vCr@a~=lP^TjgIb_j*Y8xCc%x4YueOx zd2VEIsa`&hgUIfXjK@dj>RgMbZ0cc;d`21;9cE9!8JFkqI%PVwJ$@=UHyr0EU7(SGeYOn7&3>3kodpC{%-W$dAi>{J57OYMpEZ%)A?I6A$Z*8m7nNrtMKiT@RPa z^E!|G=gwoqxIJhYV!7lQE`aU=Ay7f1#C0J1;i{VV--qk--Xtwfuy7FUlXZ+i>t+nk>?$3Ns3X0|zB;w5 zPCZq#{+G(b%oT{>$q}n=IW8ssO6Yi~6#t zRQsB$O!hMwMeCR1%DMisAStK+O87J3#q2vlMDQOtzB~0|+c7#8y~LLN&%@Kn4+SCH JM*$9;{slssPzeA4 delta 303 zcmdlWzLcNuGcPX}0}#BG)yZ7LJ&~`7QDdkF}Z-l zezG`Ap`0)SLo_Ey3kZZV1v9Y%X;VfpmqB527mK34CTkHlkY6MMB1A!i7?8NdT2Pdk zSE9*M#0%mvWu_E~gXAP8A7Zg#Oql$i#Y^%IkKhFL8Hy9NuJFj-5SE%@IMM0?kL&|} z;mM7ho5Ykr`uH9FJreU$a#D-*l5_HlQ)4H4a#=HSPHyG0=9UDRCl4Z&CST<;l>nLF z#_)-SiPhp04+pFGCox`Dk*^+1lXbYAfF8@|meAA%DgimZ7^L', 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/', 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/', 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/', 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/', 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/', 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 ## ======================================================= diff --git a/templates/update_ao.html b/templates/update_ao.html index 83a6c5a..180c7c3 100644 --- a/templates/update_ao.html +++ b/templates/update_ao.html @@ -1,30 +1,75 @@ + Update AO Record +
-

Update AO Record for Year {{ record.year }}

-
- {% for field in record.keys() if field != 'id' %} - - - {% endfor %} - -
+

Update AO Record for Year {{ record.year }}

+
+ {% for field in record.keys() if field != 'id' %} + + + {% endfor %} + +
- + + \ No newline at end of file diff --git a/test.py b/test.py deleted file mode 100644 index f9ddca0..0000000 --- a/test.py +++ /dev/null @@ -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')