Formated Subcontractor & Client Report
This commit is contained in:
@@ -188,10 +188,6 @@ def render_table_or_empty(df, model_key, table_class, raw_fields=None):
|
|||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------- EXCEL SHEET FORMATTING (Tr.Ex / Mh.Ex / MH & DC / Pipe Laying) ----------------
|
# ---------------- EXCEL SHEET FORMATTING (Tr.Ex / Mh.Ex / MH & DC / Pipe Laying) ----------------
|
||||||
|
|
||||||
SHEET_TITLES = {
|
SHEET_TITLES = {
|
||||||
@@ -250,12 +246,16 @@ def format_detail_sheet(workbook, worksheet, df, sheet_name, contractor_name="",
|
|||||||
label_format = workbook.add_format({"bold": True})
|
label_format = workbook.add_format({"bold": True})
|
||||||
value_format = workbook.add_format({})
|
value_format = workbook.add_format({})
|
||||||
|
|
||||||
info_fields = [
|
info_fields = [("Category:", report_title)]
|
||||||
("Category:", report_title),
|
|
||||||
("Contractor:", contractor_name or "-"),
|
# Client reports don't have a single contractor (data can span
|
||||||
("RA Bill No:", ra_bill_no or "All"),
|
# multiple subcontractors), so this field is only shown when a
|
||||||
("Date:", report_date),
|
# contractor name is actually passed in (Subcontractor report).
|
||||||
]
|
if contractor_name:
|
||||||
|
info_fields.append(("Contractor:", contractor_name))
|
||||||
|
|
||||||
|
info_fields.append(("RA Bill No:", ra_bill_no or "All"))
|
||||||
|
info_fields.append(("Date:", report_date))
|
||||||
|
|
||||||
col = 0
|
col = 0
|
||||||
for label, value in info_fields:
|
for label, value in info_fields:
|
||||||
@@ -301,8 +301,6 @@ def format_detail_sheet(workbook, worksheet, df, sheet_name, contractor_name="",
|
|||||||
worksheet.set_row(header_row, 30)
|
worksheet.set_row(header_row, 30)
|
||||||
|
|
||||||
|
|
||||||
=======
|
|
||||||
>>>>>>> 80d4e82f9b14a0454b3beb45992dab986ab8853f
|
|
||||||
# ---------------- FETCH ----------------
|
# ---------------- FETCH ----------------
|
||||||
class SubcontractorBill:
|
class SubcontractorBill:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -952,22 +950,52 @@ def client_report():
|
|||||||
# -------- DOWNLOAD --------
|
# -------- DOWNLOAD --------
|
||||||
if action == "download":
|
if action == "download":
|
||||||
|
|
||||||
|
report_date = datetime.now().strftime("%d-%b-%Y")
|
||||||
|
|
||||||
output = io.BytesIO()
|
output = io.BytesIO()
|
||||||
|
|
||||||
with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
|
with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
|
||||||
workbook = writer.book
|
workbook = writer.book
|
||||||
abstract_service.generate(workbook)
|
abstract_service.generate(workbook)
|
||||||
|
|
||||||
bill_gen.df_tr.to_excel(writer, index=False, sheet_name="Tr.Ex")
|
sheet_map = [
|
||||||
bill_gen.df_mh.to_excel(writer, index=False, sheet_name="Mh.Ex")
|
(bill_gen.df_tr, "Tr.Ex"),
|
||||||
bill_gen.df_dc.to_excel(writer, index=False, sheet_name="MH & DC")
|
(bill_gen.df_mh, "Mh.Ex"),
|
||||||
bill_gen.df_laying.to_excel(writer, index=False, sheet_name="Pipe Laying")
|
(bill_gen.df_dc, "MH & DC"),
|
||||||
|
(bill_gen.df_laying, "Pipe Laying"),
|
||||||
|
]
|
||||||
|
for df, sheet_name in sheet_map:
|
||||||
|
if not df.empty:
|
||||||
|
# Use a copy for the export only, same as the
|
||||||
|
# Subcontractor report, so the formatted sheet gets
|
||||||
|
# a clean "Sr No" column instead of the raw Id.
|
||||||
|
export_df = df.drop(columns=["Id"], errors="ignore").copy()
|
||||||
|
export_df.insert(0, "Sr No", range(1, len(export_df) + 1))
|
||||||
|
|
||||||
|
export_df.to_excel(writer, sheet_name=sheet_name, index=False, startrow=1)
|
||||||
|
worksheet = writer.sheets[sheet_name]
|
||||||
|
format_detail_sheet(
|
||||||
|
workbook, worksheet, export_df, sheet_name,
|
||||||
|
contractor_name="",
|
||||||
|
ra_bill_no=RA_Bill_No,
|
||||||
|
report_date=report_date
|
||||||
|
)
|
||||||
|
|
||||||
output.seek(0)
|
output.seek(0)
|
||||||
|
|
||||||
|
filename_parts = [f"Client_RA_{re.sub(r'[^A-Za-z0-9_-]+', '_', RA_Bill_No)}"]
|
||||||
|
|
||||||
|
if location:
|
||||||
|
filename_parts.append(re.sub(r'[^A-Za-z0-9_-]+', '_', location).strip('_'))
|
||||||
|
|
||||||
|
if category and category != "all":
|
||||||
|
filename_parts.append(category.upper())
|
||||||
|
|
||||||
|
filename = "_".join(filename_parts) + "_Report.xlsx"
|
||||||
|
|
||||||
return send_file(
|
return send_file(
|
||||||
output,
|
output,
|
||||||
download_name=f"Client_RA_{RA_Bill_No}_Report.xlsx",
|
download_name=filename,
|
||||||
as_attachment=True
|
as_attachment=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user