Merge pankaj-dev into main

This commit is contained in:
2026-01-16 11:30:49 +05:30
7 changed files with 86 additions and 43 deletions

View File

@@ -55,7 +55,6 @@ class SubcontractorBill:
file_report_bp = Blueprint("file_report", __name__, url_prefix="/file")
# --- DATA WRAPPERS ---
class ClientBill:
def __init__(self):
self.df_tr = pd.DataFrame()
@@ -84,6 +83,7 @@ class SubcontractorBill:
self.df_tr = pd.DataFrame()
self.df_mh = pd.DataFrame()
self.df_dc = pd.DataFrame()
self.df_laying = pd.DataFrame()
def Fetch(self, RA_Bill_No=None, subcontractor_id=None):
filters = {}
@@ -95,19 +95,22 @@ class SubcontractorBill:
trench = TrenchExcavation.query.filter_by(**filters).all()
mh = ManholeExcavation.query.filter_by(**filters).all()
dc = ManholeDomesticChamber.query.filter_by(**filters).all()
lay = ManholeDomesticChamber.query.filter_by(**filters).all()
self.df_tr = pd.DataFrame([c.serialize() for c in trench])
self.df_mh = pd.DataFrame([c.serialize() for c in mh])
self.df_dc = pd.DataFrame([c.serialize() for c in dc])
self.df_laying = pd.DataFrame([c.serialize() for c in lay])
if not self.df_dc.empty and "MH_NO" in self.df_dc.columns:
self.df_dc.rename(columns={"MH_NO": "Node_No"}, inplace=True)
# if not self.df_dc.empty and "MH_NO" in self.df_dc.columns:
# self.df_dc.rename(columns={"MH_NO": "Node_No"}, inplace=True)
drop_cols = ["id", "created_at", "_sa_instance_state"]
for df in [self.df_tr, self.df_mh, self.df_dc]:
for df in [self.df_tr, self.df_mh, self.df_dc, self.df_laying]:
if not df.empty:
df.drop(columns=drop_cols, errors="ignore", inplace=True)
<<<<<<< HEAD
# --- ROUTES ---
# @file_report_bp.route("/report", methods=["GET", "POST"])
@@ -149,11 +152,15 @@ class SubcontractorBill:
# return send_file(output, download_name=file_name, as_attachment=True, mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
# return render_template("report.html", subcontractors=subcontractors)
>>>>>>> pankaj-dev
=======
>>>>>>> pankaj-dev
@file_report_bp.route("/report", methods=["GET", "POST"])
@login_required
def report_file():
subcontractors = Subcontractor.query.all()
<<<<<<< HEAD
<<<<<<< HEAD
if request.method == "POST":
@@ -199,6 +206,9 @@ def report_file():
=======
tables = None # Match the variable name used in HTML
=======
tables = None
>>>>>>> pankaj-dev
selected_sc_id = None
ra_bill_no = None
download_all = False
@@ -237,23 +247,24 @@ def report_file():
bill_gen.df_tr.to_excel(writer, index=False, sheet_name="Tr.Ex.")
bill_gen.df_mh.to_excel(writer, index=False, sheet_name="MH.Ex.")
bill_gen.df_dc.to_excel(writer, index=False, sheet_name="MH & DC")
bill_gen.df_laying.to_excel(writer, index=False, sheet_name="Laying")
output.seek(0)
return send_file(output, download_name=file_name, as_attachment=True)
# PREVIEW LOGIC: Convert DataFrames to HTML for the 'tables' variable
# We add bootstrap classes directly to the pandas output
table_classes = "table table-hover table-bordered table-striped"
tables = {
"tr": bill_gen.df_tr.to_html(classes=table_classes, index=False),
"mh": bill_gen.df_mh.to_html(classes=table_classes, index=False),
"dc": bill_gen.df_dc.to_html(classes=table_classes, index=False)
"dc": bill_gen.df_dc.to_html(classes=table_classes, index=False),
"laying": bill_gen.df_laying.to_html(classes=table_classes, index=False)
}
selected_sc_id = subcontractor_id
return render_template(
"report.html",
subcontractors=subcontractors,
tables=tables, # This now matches your HTML
tables=tables,
selected_sc_id=selected_sc_id,
ra_bill_no=ra_bill_no,
download_all=download_all