changes of report
This commit is contained in:
@@ -14,7 +14,6 @@ from app.utils.helpers import login_required
|
||||
file_report_bp = Blueprint("file_report", __name__, url_prefix="/file")
|
||||
|
||||
# --- DATA WRAPPERS ---
|
||||
|
||||
class ClientBill:
|
||||
def __init__(self):
|
||||
self.df_tr = pd.DataFrame()
|
||||
@@ -43,6 +42,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 = {}
|
||||
@@ -54,65 +54,27 @@ 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)
|
||||
|
||||
# --- ROUTES ---
|
||||
|
||||
# @file_report_bp.route("/report", methods=["GET", "POST"])
|
||||
# @login_required
|
||||
# def report_file():
|
||||
# subcontractors = Subcontractor.query.all()
|
||||
# if request.method == "POST":
|
||||
# subcontractor_id = request.form.get("subcontractor_id")
|
||||
# ra_bill_no = request.form.get("ra_bill_no")
|
||||
# download_all = request.form.get("download_all") == "true"
|
||||
|
||||
# if not subcontractor_id:
|
||||
# flash("Please select a subcontractor.", "danger")
|
||||
# return render_template("report.html", subcontractors=subcontractors)
|
||||
|
||||
# subcontractor = Subcontractor.query.get(subcontractor_id)
|
||||
# bill_gen = SubcontractorBill()
|
||||
|
||||
# if download_all:
|
||||
# bill_gen.Fetch(subcontractor_id=subcontractor_id)
|
||||
# file_name = f"{subcontractor.subcontractor_name}_ALL_BILLS.xlsx"
|
||||
# else:
|
||||
# if not ra_bill_no:
|
||||
# flash("Please enter an RA Bill Number.", "danger")
|
||||
# return render_template("report.html", subcontractors=subcontractors)
|
||||
# bill_gen.Fetch(RA_Bill_No=ra_bill_no, subcontractor_id=subcontractor_id)
|
||||
# file_name = f"{subcontractor.subcontractor_name}_RA_{ra_bill_no}_Report.xlsx"
|
||||
|
||||
# if bill_gen.df_tr.empty and bill_gen.df_mh.empty and bill_gen.df_dc.empty:
|
||||
# flash("No data found for this selection.", "warning")
|
||||
# return render_template("report.html", subcontractors=subcontractors)
|
||||
|
||||
# output = io.BytesIO()
|
||||
# with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
|
||||
# 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")
|
||||
# output.seek(0)
|
||||
# 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)
|
||||
@file_report_bp.route("/report", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def report_file():
|
||||
subcontractors = Subcontractor.query.all()
|
||||
tables = None # Match the variable name used in HTML
|
||||
tables = None
|
||||
selected_sc_id = None
|
||||
ra_bill_no = None
|
||||
download_all = False
|
||||
@@ -151,23 +113,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
|
||||
|
||||
@@ -69,16 +69,22 @@
|
||||
<ul class="nav nav-tabs card-header-tabs" id="reportTabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
<button class="nav-link active" id="tr-tab" data-bs-toggle="tab" data-bs-target="#tr"
|
||||
type="button">Transport (Tr.Ex.)</button>
|
||||
type="button">Tr.Ex.</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button class="nav-link" id="mh-tab" data-bs-toggle="tab" data-bs-target="#mh"
|
||||
type="button">Manpower (MH.Ex.)</button>
|
||||
type="button">MH.Ex. </button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button class="nav-link" id="dc-tab" data-bs-toggle="tab" data-bs-target="#dc" type="button">MH
|
||||
& DC</button>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<button class="nav-link" id="dc-tab" data-bs-toggle="tab" data-bs-target="#dc"
|
||||
type="button">Laying</button>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
<div class="card-body tab-content" id="reportTabsContent">
|
||||
@@ -97,6 +103,12 @@
|
||||
{{ tables.dc | safe }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="laying" role="tabpanel">
|
||||
<div class="table-responsive">
|
||||
{{ tables.laying | safe }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user