add itai model and irt report download code commit.

This commit is contained in:
2025-12-01 17:45:16 +05:30
parent aa063b7a80
commit 7cf8287b34
13 changed files with 503 additions and 235 deletions

View File

@@ -9,10 +9,8 @@ class AOHandler:
self.conn = DBConfig.get_db_connection()
self.cursor = self.conn.cursor(dictionary=True)
# GET ALL AO RECORDS using stored procedure "GetAllItr"
def get_all_ao(self):
self.cursor.callproc("GetAllAO")
records = []
@@ -25,7 +23,6 @@ class AOHandler:
def get_ao_by_id(self, id):
# Call stored procedure
self.cursor.callproc('GetAOById', [id])
# Fetch result
records = []
for result in self.cursor.stored_results():
@@ -64,26 +61,23 @@ class AOHandler:
# UPDATE ITR RECORD by AO id
# def update(self, id, data):
def update_ao(self, id, data):
# 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'
# ]
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"
]
# set_clause = ", ".join([f"{col}=%s" for col in columns])
values = [id] + [data.get(f, 0) for f in fields]
# query = f"UPDATE itr SET {set_clause} WHERE id = %s"
print("AO update values:", values)
# values = [data.get(col, 0) for col in columns]
# values.append(id)
# self.cursor.execute(query, tuple(values))
# self.conn.commit()
self.cursor.callproc("UpdateAOById", values)
self.conn.commit()
# DELETE RECORD by AO id

View File

@@ -45,23 +45,26 @@ class CITHandler:
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"
# ]
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 = [id] + [data.get(col, 0) for col in columns]
self.cursor.callproc("UpdateCITById", values)
self.conn.commit()
# 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):

View File

@@ -30,17 +30,15 @@ class ITATHandler:
# 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()
values = [
data.get("mat_tax_credit", 0),
data.get("surcharge", 0),
data.get("cess", 0),
data.get("total_credit", 0),
data.get("year", 0)
]
self.cursor.callproc("InsertITAT", values)
self.conn.commit()
# UPDATE ITAT (PROC)
def update_itat(self, id, data):

View File

@@ -1,5 +1,17 @@
from AppCode.Config import DBConfig
import mysql.connector
from AppCode.YearGet import YearGet
import pandas as pd
import pymysql
import io
# new
from AppCode.Config import DBConfig
import mysql.connector
import pandas as pd
import io
from flask import send_file, render_template, request
@@ -61,8 +73,24 @@ class ITRHandler:
# UPDATE ITR RECORD by ITR id
def update(self, id, data):
# def update(self, id, data):
# 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]
# values.insert(0, id) # first argument is ID
# print("values.insert(0, id)-->",values.insert(0, id))
# self.cursor.callproc("UpdateITR", values)
# self.conn.commit()
def update(self, id, data):
columns = [
'year', 'gross_total_income', 'disallowance_14a', 'disallowance_37',
'deduction_80ia_business', 'deduction_80ia_misc', 'deduction_80ia_other',
@@ -72,14 +100,11 @@ class ITRHandler:
'total_tax', 'advance_tax', 'tds', 'tcs', 'tax_on_assessment', 'refund'
]
set_clause = ", ".join([f"{col}=%s" for col in columns])
values = [id] + [data.get(col, 0) for col in columns]
query = f"UPDATE itr SET {set_clause} WHERE id = %s"
print("Final values:", values)
values = [data.get(col, 0) for col in columns]
values.append(id)
self.cursor.execute(query, tuple(values))
self.cursor.callproc("UpdateITR", values)
self.conn.commit()
@@ -90,6 +115,51 @@ class ITRHandler:
self.conn.commit()
def itr_report_download(self, selected_year):
try:
# Call stored procedure
self.cursor.callproc("GetITRByYear", [selected_year])
rows = []
for result in self.cursor.stored_results():
rows = result.fetchall()
if not rows:
return None
# Convert SQL rows to DataFrame
df = pd.DataFrame(rows)
# Transpose
df_transposed = df.transpose()
df_transposed.insert(0, 'Field', df_transposed.index)
record_cols = {
i: f"Record {i}"
for i in df_transposed.columns if isinstance(i, int)
}
df_transposed.rename(columns=record_cols, inplace=True)
df_transposed.reset_index(drop=True, inplace=True)
# Save to Excel in memory
output = io.BytesIO()
with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
df_transposed.to_excel(writer, index=False, sheet_name='ITR_Vertical')
worksheet = writer.sheets['ITR_Vertical']
worksheet.set_column(0, 0, 30)
output.seek(0)
return output
except mysql.connector.Error as e:
print("MySQL Error →", e)
return None
# CLOSE CONNECTION
def close(self):
self.cursor.close()

28
AppCode/YearGet.py Normal file
View File

@@ -0,0 +1,28 @@
from AppCode.Config import DBConfig
import mysql.connector
class YearGet:
def __init__(self):
self.conn = DBConfig.get_db_connection()
self.cursor = self.conn.cursor(dictionary=True)
def get_year_by_model(self, proc_name):
try:
self.cursor.callproc(proc_name)
years = []
for result in self.cursor.stored_results():
rows = result.fetchall()
years = [row["year"] for row in rows]
return years
except mysql.connector.Error as e:
print("MySQL Error:", e)
return []
def close(self):
self.cursor.close()
self.conn.close()

Binary file not shown.