AO, cit, itat report download code commit.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
from AppCode.Config import DBConfig
|
||||
import mysql.connector
|
||||
import pandas as pd
|
||||
import io
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -91,3 +94,43 @@ class AOHandler:
|
||||
def close(self):
|
||||
self.cursor.close()
|
||||
self.conn.close()
|
||||
|
||||
def ao_report_download(self, selected_year):
|
||||
try:
|
||||
# Call stored proc to fetch year-wise records
|
||||
self.cursor.callproc("GetAOByYear", [selected_year])
|
||||
|
||||
rows = []
|
||||
for result in self.cursor.stored_results():
|
||||
rows = result.fetchall()
|
||||
|
||||
if not rows:
|
||||
return None
|
||||
|
||||
df = pd.DataFrame(rows)
|
||||
|
||||
# TRANSPOSE
|
||||
df_transposed = df.transpose()
|
||||
df_transposed.insert(0, 'Field', df_transposed.index)
|
||||
|
||||
# Rename columns: Record 1, 2, 3...
|
||||
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)
|
||||
|
||||
# Excel Output
|
||||
output = io.BytesIO()
|
||||
with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
|
||||
df_transposed.to_excel(writer, index=False, sheet_name="AO_Vertical")
|
||||
worksheet = writer.sheets["AO_Vertical"]
|
||||
worksheet.set_column(0, 0, 30)
|
||||
|
||||
output.seek(0)
|
||||
return output
|
||||
|
||||
except mysql.connector.Error as e:
|
||||
print("MySQL Error:", e)
|
||||
return None
|
||||
@@ -1,5 +1,9 @@
|
||||
from AppCode.Config import DBConfig
|
||||
import mysql.connector
|
||||
import pandas as pd
|
||||
import io
|
||||
|
||||
|
||||
|
||||
class CITHandler:
|
||||
|
||||
@@ -75,3 +79,42 @@ class CITHandler:
|
||||
def close(self):
|
||||
self.cursor.close()
|
||||
self.conn.close()
|
||||
|
||||
|
||||
def cit_report_download(self, selected_year):
|
||||
try:
|
||||
# Call stored procedure
|
||||
self.cursor.callproc("GetCITByYear", [selected_year])
|
||||
|
||||
rows = []
|
||||
for result in self.cursor.stored_results():
|
||||
rows = result.fetchall()
|
||||
|
||||
if not rows:
|
||||
return None
|
||||
|
||||
df = pd.DataFrame(rows)
|
||||
|
||||
# Excel output
|
||||
output = io.BytesIO()
|
||||
with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
|
||||
|
||||
for i, (_, row) in enumerate(df.iterrows(), start=1):
|
||||
# Convert row to vertical format
|
||||
vertical_df = pd.DataFrame(row).reset_index()
|
||||
vertical_df.columns = ['Field', 'Value']
|
||||
|
||||
start_row = (i - 1) * (len(vertical_df) + 3) # gap between blocks
|
||||
vertical_df.to_excel(
|
||||
writer,
|
||||
sheet_name='CIT_Report',
|
||||
index=False,
|
||||
startrow=start_row
|
||||
)
|
||||
|
||||
output.seek(0)
|
||||
return output
|
||||
|
||||
except mysql.connector.Error as e:
|
||||
print("MySQL Error:", e)
|
||||
return None
|
||||
@@ -1,6 +1,8 @@
|
||||
# AppCode/ITATHandler.py
|
||||
from AppCode.Config import DBConfig
|
||||
|
||||
from AppCode.Config import DBConfig
|
||||
import mysql.connector
|
||||
import pandas as pd
|
||||
import io
|
||||
|
||||
class ITATHandler:
|
||||
|
||||
@@ -59,7 +61,34 @@ class ITATHandler:
|
||||
self.conn.commit()
|
||||
|
||||
|
||||
# CLOSE CONNECTION
|
||||
|
||||
def itat_report_download(self, selected_year):
|
||||
try:
|
||||
# Call stored procedure
|
||||
self.cursor.callproc("GetITATByYear", [selected_year])
|
||||
|
||||
rows = []
|
||||
for result in self.cursor.stored_results():
|
||||
rows = result.fetchall()
|
||||
|
||||
if not rows:
|
||||
return None
|
||||
|
||||
df = pd.DataFrame(rows)
|
||||
|
||||
# Excel output
|
||||
output = io.BytesIO()
|
||||
with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
|
||||
df.T.to_excel(writer, header=False, sheet_name="ITAT_Report")
|
||||
|
||||
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()
|
||||
|
||||
@@ -116,7 +116,6 @@ class ITRHandler:
|
||||
|
||||
|
||||
|
||||
|
||||
def itr_report_download(self, selected_year):
|
||||
|
||||
try:
|
||||
@@ -137,6 +136,9 @@ class ITRHandler:
|
||||
df_transposed = df.transpose()
|
||||
df_transposed.insert(0, 'Field', df_transposed.index)
|
||||
|
||||
print("df-->",df_transposed)
|
||||
|
||||
|
||||
record_cols = {
|
||||
i: f"Record {i}"
|
||||
for i in df_transposed.columns if isinstance(i, int)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user