Files
IncomeTaxSystem/AppCode/ITATHandler.py

209 lines
8.4 KiB
Python
Raw Normal View History

from AppCode.Config import DBConfig
import mysql.connector
import pandas as pd
import io
2025-12-01 12:04:07 +05:30
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):
2026-02-14 17:32:30 +05:30
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', 'per_tax_a', 'tax_a_cal', 'per_surcharge_a', 'surcharge_a_cal', 'per_cess_a', 'edu_cess_a_cal', 'sum_of_a',
'per_tax_b', 'tax_b_cal', 'per_surcharge_b', 'surcharge_b_cal', 'per_cess_b', 'edu_cess_b_cal', 'sum_of_b',
'tax_payable','total_tax_payable', 'opening_balance', 'mat_credit_created', 'mat_credit_utilized', 'closing_balance',
'interest_234c', 'total_tax', 'advance_tax', 'tds', 'tcs', 'sat', 'tax_on_assessment', 'refund',
'interest_244a_per143', 'refund_received', 'balance_receivable', 'remarks', 'created_at'
]
values = [data.get(col, 0) for col in columns]
self.cursor.callproc("InsertITAT", values)
self.conn.commit()
2025-12-01 12:04:07 +05:30
# UPDATE ITAT (PROC)
def update_itat(self, id, data):
2026-02-14 17:32:30 +05:30
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', 'per_tax_a', 'tax_a_cal', 'per_surcharge_a', 'surcharge_a_cal', 'per_cess_a', 'edu_cess_a_cal', 'sum_of_a',
'per_tax_b', 'tax_b_cal', 'per_surcharge_b', 'surcharge_b_cal', 'per_cess_b', 'edu_cess_b_cal', 'sum_of_b',
'tax_payable','total_tax_payable', 'opening_balance', 'mat_credit_created', 'mat_credit_utilized', 'closing_balance',
'interest_234c', 'total_tax', 'advance_tax', 'tds', 'tcs', 'sat', 'tax_on_assessment', 'refund',
'interest_244a_per143', 'refund_received', 'balance_receivable', 'remarks', 'updated_at'
]
values = [id] + [data.get(col, 0) for col in columns]
2025-12-01 12:04:07 +05:30
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()
def itat_report_download(self, selected_year):
2026-01-24 18:22:28 +05:30
try:
# AY calculation (2020 -> AY 2020-2021)
ay_start = int(selected_year)
ay_end = ay_start + 1
assessment_year = f"AY {ay_start}-{ay_end}"
# Fetch ITAT data
self.cursor.callproc("GetITATByYear", [selected_year])
rows = []
for result in self.cursor.stored_results():
rows = result.fetchall()
if not rows:
return None
2026-01-24 18:22:28 +05:30
# Remove id column if exists
for row in rows:
row.pop("id", None)
# Mapping DB fields → readable Excel labels
field_mapping = {
"gross_total_income": "Gross Total Income",
"disallowance_14a": "Add: Disallowance u/s 14A",
"disallowance_37": "Add: Disallowance u/s 37",
2026-02-14 17:32:30 +05:30
"-" : "-",
2026-01-24 18:22:28 +05:30
"deduction_80ia_business": "Less: Deduction u/s 80IA - On Business Income",
"deduction_80ia_misc": "On Misc Receipts",
"deduction_80ia_other": "On Other",
"deduction_sec37_disallowance": "On Sec 37 Disallowance",
"deduction_80g": "Less: Deduction u/s 80G",
"net_taxable_income": "Net Taxable Income",
2026-02-17 16:54:43 +05:30
"--" : "-",
2026-02-14 17:32:30 +05:30
"per_tax_a" : "Per% Tax @(A)",
"tax_a_cal" : "Tax cal(A)",
"per_surcharge_a" : "Per% surcharge @(A)",
"surcharge_a_cal" : "Surcharge cal (A)",
"per_cess_a" : "Per% cess(A)",
"edu_cess_a_cal" : "Edu cess cal(A)",
"sum_of_a" : "Sum of tax_cal(A)",
2026-02-17 16:54:43 +05:30
"---" : "-",
2026-02-14 17:32:30 +05:30
"per_tax_b" : "Per% Tax @(B)",
"tax_b_cal" : "Tax cal(B)",
"per_surcharge_b" : "Per% surcharge @(B)",
"surcharge_b_cal" : "Surcharge cal (B)",
"per_cess_b" : "Per% cess(B)",
"edu_cess_b_cal" : "Edu cess cal(B)",
"sum_of_b" : "Sum of tax_cal(B)",
2026-01-24 18:22:28 +05:30
"tax_payable": "Tax Payable",
"total_tax_payable": "Total Tax Payable",
2026-02-14 17:32:30 +05:30
"opening_balance": "Opening Balance",
"mat_credit_created": "Add: MAT Credit Created",
"mat_credit_utilized": "Less: MAT Credit Utilized",
2026-02-14 17:32:30 +05:30
"closing_balance": "Closing Balance",
2026-01-24 18:22:28 +05:30
"interest_234c": "Add: Interest u/s 234C",
"total_tax": "Total Tax",
"advance_tax": "Advance Tax",
"tds": "TDS",
"tcs": "TCS",
"sat": "SAT",
"tax_on_assessment": "Tax on Regular Assessment",
2026-02-14 17:32:30 +05:30
"refund" : "Refund",
"interest_244a_per143" : "Add : Interest u/s 244A as per 143",
"refund_received" : "Less : Refund Received on",
"balance_receivable" : "Balance Receivable",
"Remarks" : "Remarks"
2026-01-24 18:22:28 +05:30
}
2026-02-14 17:32:30 +05:30
2026-01-24 18:22:28 +05:30
# Vertical ITAT structure
data = []
for key, label in field_mapping.items():
value = rows[0].get(key, 0)
data.append([label, value])
df = pd.DataFrame(data, columns=["Particulars", "ITAT"])
# Excel output
output = io.BytesIO()
with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
workbook = writer.book
worksheet = workbook.add_worksheet("ITAT Report")
writer.sheets["ITAT Report"] = worksheet
# Formats
title_fmt = workbook.add_format({
"bold": True,
"align": "center",
"font_size": 14
})
header_fmt = workbook.add_format({
"bold": True,
"border": 1,
"align": "center"
})
text_fmt = workbook.add_format({"border": 1})
num_fmt = workbook.add_format({
"border": 1,
"num_format": "#,##0.00"
})
# Company Name
worksheet.merge_range(
"A1:B1",
"Laxmi Civil Engineering Services Pvt Ltd",
title_fmt
)
# Assessment Year
worksheet.merge_range(
"A2:B2",
f"Assessment Year : {assessment_year}",
workbook.add_format({"bold": True, "align": "center"})
)
# Header
worksheet.write_row("A4", ["Particulars", "ITAT"], header_fmt)
# Data rows
row_no = 4
for _, row in df.iterrows():
worksheet.write(row_no, 0, row["Particulars"], text_fmt)
worksheet.write(row_no, 1, row["ITAT"], num_fmt)
row_no += 1
# Column widths
worksheet.set_column("A:A", 45)
worksheet.set_column("B:B", 20)
output.seek(0)
return output
except mysql.connector.Error as e:
print("MySQL Error →", e)
return None
# CLOSE CONNECTION
2025-12-01 12:04:07 +05:30
def close(self):
self.cursor.close()
self.conn.close()