changes of summary report

This commit is contained in:
2026-01-07 00:49:42 +05:30
parent f49935d706
commit 9c2486fdd6
8 changed files with 71 additions and 53 deletions

View File

@@ -79,22 +79,26 @@ class DocumentHandler:
connection.close()
# return redirect(url_for('view_documents'))
# Summary report
def Summary_report(self, request):
dbconfig = DBConfig()
connection = dbconfig.get_db_connection()
year = request.args.get('year')
# if not year get all year in list.
if not year:
year_str = request.args.get('year')
# If year not selected
if not year_str or not year_str.isdigit():
yearGetter = YearGet()
allYears = yearGetter.get_year_by_model("AllYearsInAllModel")
yearGetter.close()
return render_template(
'summary_reports.html',
years=allYears,
message="Please select a valid year to download."
)
return render_template('summary_reports.html', years=allYears,message="Please select a year to download.")
# Convert year to int (IMPORTANT FIX)
year = int(year_str)
# for excel
try:
stages = {
"ITR": "itr",
@@ -102,39 +106,43 @@ class DocumentHandler:
"CIT": "cit",
"ITAT": "itat",
}
# stages = ['itr', 'ao', 'cit', 'itat']
stage_data = {}
for stage_name, table_name in stages.items():
cursor = connection.cursor(dictionary=True)
cursor.callproc("sp_get_stage_data", [table_name, year])
rows = []
for result in cursor.stored_results():
rows = result.fetchall()
df = pd.DataFrame(rows) if rows else pd.DataFrame()
stage_data[stage_name] = df
stage_data[stage_name] = pd.DataFrame(rows) if rows else pd.DataFrame()
cursor.close()
def safe_get(df, col):
return df[col].values[0] if col in df.columns and not df.empty else "-"
particulars = [
"Gross Total Income", "Add: Disallowance u/s 14A", "Add: Disallowance u/s 37", "GTI as per",
"Less: Deduction u/s 80IA", "Less: Deduction u/s 80G", "Net Taxable Income", "Tax @ 30%",
"Tax @ 18.5% on Book Profit", "Surcharge @ 12%", "Education Cess @ 3%", "Total Tax Payable",
"Less: MAT Credit", "Net Tax", "Add: Interest u/s 234C", "Total Tax",
"Advance Tax", "TDS", "TCS", "SAT", "Tax on Regular Assessment", "Refund"
"Gross Total Income", "Add: Disallowance u/s 14A", "Add: Disallowance u/s 37",
"GTI as per", "Less: Deduction u/s 80IA - On Business Income", "- On Misc Receipts",
"- On Other", "- On Sec 37 Disallowance", "Less: Deduction u/s 80G", " ",
"Net Taxable Income", "Tax @ 30%", "Tax @ 18.5% on Book Profit",
"Tax Payable", "Surcharge @ %", "Education Cess @ 3%", "Total Tax Payable",
"Less: MAT Credit Utilized", "Add: Interest u/s 234C", "Total Tax", " ",
"Advance Tax", "TDS", "TCS", "SAT",
"Tax on Regular Assessment", "Refund" , "Remarks"
]
columns = [
'gross_total_income', 'disallowance_14a', 'disallowance_37', 'gti',
'deduction_80ia', 'deduction_80g', 'net_taxable_income', 'tax_30',
'book_profit_tax', 'surcharge_12', 'education_cess', 'total_tax',
'mat_credit', 'net_tax', 'interest_234c', 'total_tax_payable',
'advance_tax', 'tds', 'tcs', 'sat', 'tax_regular', 'refund'
'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', 'sat',
'tax_on_assessment', 'refund', 'Remarks'
]
data = {
@@ -147,13 +155,31 @@ class DocumentHandler:
df = pd.DataFrame(data)
# Export to Excel
# ===== Excel Export =====
output = io.BytesIO()
with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
df.to_excel(writer, index=False, sheet_name=f'AY {year}')
workbook = writer.book
worksheet = writer.sheets[f'AY {year}']
sheet_name = f"AY {year} - {year + 1}"
df.to_excel(writer, index=False, sheet_name=sheet_name, startrow=2)
workbook = writer.book
worksheet = writer.sheets[sheet_name]
# ===== Company Heading =====
company_heading = workbook.add_format({
'bold': True,
'font_size': 14,
'font_color': 'black',
'align': 'center',
'valign': 'middle'
})
worksheet.merge_range(
0, 0, 0, len(df.columns) - 1,
"Laxmi Civil Engineering Services Pvt Ltd",
company_heading
)
# ===== Header Format =====
header = workbook.add_format({
'bold': True,
'align': 'center',
@@ -165,29 +191,31 @@ class DocumentHandler:
cell = workbook.add_format({
'border': 1,
'align': 'center',
'align': 'left',
'valign': 'middle'
})
# Apply formatting
# Write headers
for col_num, col_name in enumerate(df.columns):
worksheet.write(0, col_num, col_name, header)
worksheet.write(2, col_num, col_name, header)
max_len = max(df[col_name].astype(str).map(len).max(), len(col_name)) + 2
worksheet.set_column(col_num, col_num, max_len)
for row in range(1, len(df) + 1):
# Write data rows
for row in range(3, len(df) + 3):
for col in range(len(df.columns)):
worksheet.write(row, col, df.iloc[row - 1, col], cell)
worksheet.write(row, col, df.iloc[row - 3, col], cell)
worksheet.freeze_panes(3, 1)
output.seek(0)
return send_file(
output,
download_name=f"Summary_Report_{year}.xlsx",
download_name=f"AY{year}-{year + 1}_Summary_Report.xlsx",
as_attachment=True,
mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)
finally:
connection.close()