diff --git a/app/__init__.py b/app/__init__.py index fb7cc38..fe63ee8 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -11,16 +11,20 @@ def create_app(): db.init_app(app) # Register Blueprints + from app.routes.subcontractor_routes import subcontractor_bp from app.routes.dashboard import dashboard_bp from app.routes.file_import import file_import_bp # from app.routes.user import user_bp + from app.routes.file_report import file_report_bp + + app.register_blueprint(subcontractor_bp) app.register_blueprint(dashboard_bp) app.register_blueprint(file_import_bp) # app.register_blueprint(user_bp) + app.register_blueprint(file_report_bp) - from app.routes.subcontractor_routes import subcontractor_bp - app.register_blueprint(subcontractor_bp) + return app diff --git a/app/__pycache__/__init__.cpython-313.pyc b/app/__pycache__/__init__.cpython-313.pyc index 9535808..911bc21 100644 Binary files a/app/__pycache__/__init__.cpython-313.pyc and b/app/__pycache__/__init__.cpython-313.pyc differ diff --git a/app/models/__pycache__/manhole_domestic_chamber_model.cpython-313.pyc b/app/models/__pycache__/manhole_domestic_chamber_model.cpython-313.pyc index 4c27703..6ffca9a 100644 Binary files a/app/models/__pycache__/manhole_domestic_chamber_model.cpython-313.pyc and b/app/models/__pycache__/manhole_domestic_chamber_model.cpython-313.pyc differ diff --git a/app/routes/__pycache__/file_download.cpython-313.pyc b/app/routes/__pycache__/file_download.cpython-313.pyc new file mode 100644 index 0000000..a9958e9 Binary files /dev/null and b/app/routes/__pycache__/file_download.cpython-313.pyc differ diff --git a/app/routes/__pycache__/file_report.cpython-313.pyc b/app/routes/__pycache__/file_report.cpython-313.pyc new file mode 100644 index 0000000..e83b2f1 Binary files /dev/null and b/app/routes/__pycache__/file_report.cpython-313.pyc differ diff --git a/app/routes/file_report.py b/app/routes/file_report.py new file mode 100644 index 0000000..2a6cd1d --- /dev/null +++ b/app/routes/file_report.py @@ -0,0 +1,22 @@ +# app/routes/file_report.py + +from flask import Blueprint, render_template, request, flash +from app.models.subcontractor_model import Subcontractor + +file_report_bp = Blueprint("file_report", __name__, url_prefix="/file") + +@file_report_bp.route("/report", methods=["GET", "POST"]) +def report_file(): + subcontractors = Subcontractor.query.all() + + if request.method == "POST": + subcontractor_id = request.form.get("subcontractor_id") + + if not subcontractor_id: + flash("Please select a subcontractor.", "danger") + else: + flash(f"Report generated for Subcontractor ID: {subcontractor_id}", "success") + + return render_template("report.html", title="Report Download", subcontractors=subcontractors) + + return render_template("report.html", title="Report Download", subcontractors=subcontractors) diff --git a/app/services/__pycache__/file_service.cpython-313.pyc b/app/services/__pycache__/file_service.cpython-313.pyc index 5726a18..1bd5a8c 100644 Binary files a/app/services/__pycache__/file_service.cpython-313.pyc and b/app/services/__pycache__/file_service.cpython-313.pyc differ diff --git a/app/services/file_service.py b/app/services/file_service.py index 0935831..b7a5eab 100644 --- a/app/services/file_service.py +++ b/app/services/file_service.py @@ -52,7 +52,7 @@ class FileService: # Manhole and Domestic Chamber Construction save if file_type == "manhole_domestic_chamber": - return self.process_manhole_excavation(df, subcontractor_id) + return self.process_manhole_domestic_chamber(df, subcontractor_id) return True, "File uploaded successfully." @@ -64,17 +64,12 @@ class FileService: # Trench Excavation save method (TrenchExcavation model) def process_trench_excavation(self, df, subcontractor_id): - - # Clean column names (strip whitespace) df.columns = [str(c).strip() for c in df.columns] - # If the sheet has merged cells -> forward fill Location if "Location" in df.columns: df["Location"] = df["Location"].ffill() - # REMOVE empty rows - df = df.dropna(how="all") - + df = df.dropna(how="all") # REMOVE empty rows # Identify missing location rows before insert missing_loc = df[df["Location"].isna() | (df["Location"].astype(str).str.strip() == "")] if not missing_loc.empty: @@ -84,14 +79,11 @@ class FileService: try: for index, row in df.iterrows(): - record_data = {} - # Insert only fields that exist in model for col in df.columns: if hasattr(TrenchExcavation, col): value = row[col] - # Normalize empty values if pd.isna(value) or str(value).strip() in ["", "-", "—", "nan", "NaN"]: value = None @@ -116,17 +108,14 @@ class FileService: # Manhole Excavation save method (ManholeExcavation model) def process_manhole_excavation(self, df, subcontractor_id): - # Clean column names (strip whitespace) df.columns = [str(c).strip() for c in df.columns] - # If the sheet has merged cells -> forward fill Location if "Location" in df.columns: df["Location"] = df["Location"].ffill() # REMOVE empty rows df = df.dropna(how="all") - # Identify missing location rows before insert missing_loc = df[df["Location"].isna() | (df["Location"].astype(str).str.strip() == "")] if not missing_loc.empty: @@ -136,9 +125,7 @@ class FileService: try: for index, row in df.iterrows(): - record_data = {} - # Insert only fields that exist in model for col in df.columns: if hasattr(ManholeExcavation, col): @@ -167,18 +154,15 @@ class FileService: # Manhole and Domestic Chamber Construction save method (ManholeDomesticChamber model) - def process_manhole_excavation(self, df, subcontractor_id): - + def process_manhole_domestic_chamber(self, df, subcontractor_id): # Clean column names (strip whitespace) df.columns = [str(c).strip() for c in df.columns] - # If the sheet has merged cells -> forward fill Location if "Location" in df.columns: df["Location"] = df["Location"].ffill() # REMOVE empty rows df = df.dropna(how="all") - # Identify missing location rows before insert missing_loc = df[df["Location"].isna() | (df["Location"].astype(str).str.strip() == "")] if not missing_loc.empty: @@ -188,14 +172,12 @@ class FileService: try: for index, row in df.iterrows(): - record_data = {} # Insert only fields that exist in model for col in df.columns: if hasattr(ManholeDomesticChamber, col): value = row[col] - # Normalize empty values if pd.isna(value) or str(value).strip() in ["", "-", "—", "nan", "NaN"]: value = None @@ -222,4 +204,3 @@ class FileService: - \ No newline at end of file diff --git a/app/static/uploads/sub_3/test_comparison.xlsx b/app/static/uploads/sub_3/test_comparison.xlsx deleted file mode 100644 index 61dde37..0000000 Binary files a/app/static/uploads/sub_3/test_comparison.xlsx and /dev/null differ diff --git a/app/static/uploads/sub_4/MH__Dc.xlsx b/app/static/uploads/sub_4/MH__Dc.xlsx deleted file mode 100644 index fda6952..0000000 Binary files a/app/static/uploads/sub_4/MH__Dc.xlsx and /dev/null differ diff --git a/app/static/uploads/sub_4/Mh_Ex.xlsx b/app/static/uploads/sub_4/Mh_Ex.xlsx deleted file mode 100644 index 49a1748..0000000 Binary files a/app/static/uploads/sub_4/Mh_Ex.xlsx and /dev/null differ diff --git a/app/static/uploads/sub_4/Tr.Ex.xlsx b/app/static/uploads/sub_4/Tr.Ex.xlsx deleted file mode 100644 index 9bcd2db..0000000 Binary files a/app/static/uploads/sub_4/Tr.Ex.xlsx and /dev/null differ diff --git a/app/static/uploads/sub_4/testing11.xlsx b/app/static/uploads/sub_4/testing11.xlsx deleted file mode 100644 index dc3cba9..0000000 Binary files a/app/static/uploads/sub_4/testing11.xlsx and /dev/null differ diff --git a/app/templates/base.html b/app/templates/base.html index 5110505..2f5941b 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -25,8 +25,8 @@ - - + + + diff --git a/app/templates/report.html b/app/templates/report.html new file mode 100644 index 0000000..a2a6d11 --- /dev/null +++ b/app/templates/report.html @@ -0,0 +1,24 @@ +{% extends "base.html" %} + +{% block content %} +

File Report

+ +
+ +
+ + + + + + +
+ +
+{% endblock %} \ No newline at end of file