changes of summary report
This commit is contained in:
@@ -22,20 +22,18 @@ class AOHandler:
|
||||
|
||||
return records
|
||||
|
||||
|
||||
# get ao recourd
|
||||
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():
|
||||
records = result.fetchall()
|
||||
|
||||
if records:
|
||||
return records[0] # return single record
|
||||
|
||||
return records[0]
|
||||
return None
|
||||
|
||||
# Add AO record
|
||||
def add_ao(self, data):
|
||||
fields = [
|
||||
"year","gross_total_income", "disallowance_14a", "disallowance_37",
|
||||
@@ -53,7 +51,7 @@ class AOHandler:
|
||||
self.conn.commit()
|
||||
|
||||
|
||||
# UPDATE ITR RECORD by AO id
|
||||
# UPDATE AO RECORD by AO id
|
||||
def update_ao(self, id, data):
|
||||
|
||||
fields = [
|
||||
@@ -75,7 +73,6 @@ class AOHandler:
|
||||
|
||||
# DELETE RECORD by AO id
|
||||
def delete_ao_by_id(self, id):
|
||||
# Call the stored procedure
|
||||
self.cursor.callproc('DeleteAOById', [id])
|
||||
self.conn.commit()
|
||||
|
||||
@@ -85,6 +82,7 @@ class AOHandler:
|
||||
self.cursor.close()
|
||||
self.conn.close()
|
||||
|
||||
# report download by year
|
||||
def ao_report_download(self, selected_year):
|
||||
try:
|
||||
# Call stored proc to fetch year-wise records
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class ITRHandler:
|
||||
|
||||
return records
|
||||
|
||||
|
||||
# get itr record by id
|
||||
def get_itr_by_id(self, id):
|
||||
# Call stored procedure
|
||||
self.cursor.callproc('GetITRById', [id])
|
||||
@@ -50,8 +50,6 @@ class ITRHandler:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
# INSERT ITR RECORD using procedure "add_itr"
|
||||
def add_itr(self, data):
|
||||
|
||||
@@ -70,7 +68,7 @@ class ITRHandler:
|
||||
self.cursor.callproc("InsertITR", values)
|
||||
self.conn.commit()
|
||||
|
||||
|
||||
# update itr by id
|
||||
def update(self, id, data):
|
||||
columns = [
|
||||
'year', 'gross_total_income', 'disallowance_14a', 'disallowance_37',
|
||||
@@ -91,12 +89,11 @@ class ITRHandler:
|
||||
|
||||
# DELETE RECORD by ITR id
|
||||
def delete_itr_by_id(self, id):
|
||||
# Call the stored procedure
|
||||
self.cursor.callproc('DeleteITRById', [id])
|
||||
self.conn.commit()
|
||||
|
||||
|
||||
|
||||
# report download by year
|
||||
def itr_report_download(self, selected_year):
|
||||
|
||||
try:
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -10,9 +10,6 @@
|
||||
{% block content %}
|
||||
<div class="main">
|
||||
<div class="container">
|
||||
|
||||
<!-- <a href="{{ url_for('index') }}" class="back-btn">← Back to Dashboard</a>-->
|
||||
|
||||
<h2>Download Year-wise Summary Report</h2>
|
||||
|
||||
{% if message %}
|
||||
@@ -38,6 +35,4 @@
|
||||
<script src="{{ url_for('static', filename='js/toggle.js') }}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %} <script src="{{ url_for('static', filename='js/year_dropdown.js') }}"></script>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user