report formate changes all model

This commit is contained in:
2026-01-24 18:22:28 +05:30
parent 30a7a4287e
commit 1a21732174
9 changed files with 452 additions and 146 deletions

View File

@@ -81,48 +81,111 @@ class ITRHandler:
self.conn.commit()
# report download by year
# # report download by year
def itr_report_download(self, selected_year):
try:
# Call stored procedure
self.cursor.callproc("GetITRByYear", [selected_year])
try:
# Call stored procedure
self.cursor.callproc("GetITRByYear", [selected_year])
rows = []
for result in self.cursor.stored_results():
rows = result.fetchall()
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)
if not rows:
return None
for row in rows:
row.pop('id', None)
# Mapping DB fields → Excel labels (NO underscores)
field_mapping = {
"gross_total_income": "Gross Total Income",
"disallowance_14a": "Add: Disallowance u/s 14A",
"disallowance_37": "Add: Disallowance u/s 37",
"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",
"tax_30_percent": "Tax @ 30%",
"tax_book_profit_18_5": "Tax @ 18.5% on Book Profit",
"tax_payable": "Tax Payable",
"surcharge_12": "Surcharge @ 12%",
"edu_cess_3": "Education Cess @ 3%",
"total_tax_payable": "Total Tax Payable",
"mat_credit": "Less: MAT Credit Utilized",
"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",
"refund": "Refund"
}
# Convert to vertical 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", "ITR"])
# Excel output
output = io.BytesIO()
with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
workbook = writer.book
worksheet = workbook.add_worksheet("ITR Report")
writer.sheets["ITR Report"] = worksheet
# Formats
title_fmt = workbook.add_format({
"bold": True, "align": "center", "valign": "vcenter",
"font_size": 14
})
header_fmt = workbook.add_format({
"bold": True, "border": 1, "align": "center"
})
cell_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)
ay_start = int(selected_year)
ay_end = ay_start + 1
assessment_year = f"AY {ay_start}-{ay_end}"
# Assessment Year
worksheet.merge_range(
"A2:B2",
f"Assessment Year : {assessment_year}",
workbook.add_format({"align": "center", "bold": True})
)
# Headers
worksheet.write_row("A4", ["Particulars", "ITR"], header_fmt)
# Data rows
row_no = 4
for _, row in df.iterrows():
worksheet.write(row_no, 0, row["Particulars"], cell_fmt)
worksheet.write(row_no, 1, row["ITR"], 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
def close(self):
self.cursor.close()
self.conn.close()
self.conn.close()