Download all report bysubcontractor id commit
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,7 +1,6 @@
|
|||||||
# Ignore folders
|
# Ignore folders
|
||||||
instance/
|
instance/
|
||||||
static/uploads/
|
app/static/uploads/
|
||||||
|
|
||||||
# Ignore files
|
# Ignore files
|
||||||
.env
|
.env
|
||||||
|
|
||||||
|
|||||||
@@ -29,23 +29,3 @@ def create_app():
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# from flask import Flask
|
|
||||||
# from app.config import Config
|
|
||||||
|
|
||||||
# def create_app():
|
|
||||||
# app = Flask(__name__)
|
|
||||||
# app.config.from_object(Config)
|
|
||||||
|
|
||||||
# # Register Blueprints
|
|
||||||
# from app.routes.dashboard import dashboard_bp
|
|
||||||
# from app.routes.file_import import file_import_bp
|
|
||||||
# from app.routes.user import user_bp
|
|
||||||
|
|
||||||
# app.register_blueprint(dashboard_bp)
|
|
||||||
# app.register_blueprint(file_import_bp)
|
|
||||||
# app.register_blueprint(user_bp)
|
|
||||||
|
|
||||||
# return app
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,10 +1,16 @@
|
|||||||
# app/routes/file_report.py
|
from flask import Blueprint, render_template, request, send_file, flash
|
||||||
|
|
||||||
from flask import Blueprint, render_template, request, flash
|
|
||||||
from app.models.subcontractor_model import Subcontractor
|
from app.models.subcontractor_model import Subcontractor
|
||||||
|
from app.models.manhole_excavation_model import ManholeExcavation
|
||||||
|
from app.models.trench_excavation_model import TrenchExcavation
|
||||||
|
from app.models.manhole_domestic_chamber_model import ManholeDomesticChamber
|
||||||
|
from app import db
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
import io
|
||||||
|
|
||||||
file_report_bp = Blueprint("file_report", __name__, url_prefix="/file")
|
file_report_bp = Blueprint("file_report", __name__, url_prefix="/file")
|
||||||
|
|
||||||
|
|
||||||
@file_report_bp.route("/report", methods=["GET", "POST"])
|
@file_report_bp.route("/report", methods=["GET", "POST"])
|
||||||
def report_file():
|
def report_file():
|
||||||
subcontractors = Subcontractor.query.all()
|
subcontractors = Subcontractor.query.all()
|
||||||
@@ -14,9 +20,110 @@ def report_file():
|
|||||||
|
|
||||||
if not subcontractor_id:
|
if not subcontractor_id:
|
||||||
flash("Please select a subcontractor.", "danger")
|
flash("Please select a subcontractor.", "danger")
|
||||||
else:
|
return render_template("report.html", subcontractors=subcontractors)
|
||||||
flash(f"Report generated for Subcontractor ID: {subcontractor_id}", "success")
|
|
||||||
|
|
||||||
return render_template("report.html", title="Report Download", subcontractors=subcontractors)
|
# Fetch subcontractor for file name
|
||||||
|
subcontractor = Subcontractor.query.get(subcontractor_id)
|
||||||
|
|
||||||
|
manhole_excavation = ManholeExcavation.query.filter_by(subcontractor_id=subcontractor_id).all()
|
||||||
|
trench_excavation = TrenchExcavation.query.filter_by(subcontractor_id=subcontractor_id).all()
|
||||||
|
domestic_chamber = ManholeDomesticChamber.query.filter_by(subcontractor_id=subcontractor_id).all()
|
||||||
|
|
||||||
|
|
||||||
|
# Convert to DataFrame
|
||||||
|
df_mh_exc = pd.DataFrame([m.__dict__ for m in manhole_excavation])
|
||||||
|
df_trench = pd.DataFrame([t.__dict__ for t in trench_excavation])
|
||||||
|
df_domestic = pd.DataFrame([d.__dict__ for d in domestic_chamber])
|
||||||
|
|
||||||
|
# Drop unnecessary SQLAlchemy fields
|
||||||
|
drop_cols = ["id", "subcontractor_id", "created_at", "_sa_instance_state","Remarks"]
|
||||||
|
|
||||||
|
df_mh_exc.drop(columns=drop_cols, errors="ignore", inplace=True)
|
||||||
|
df_trench.drop(columns=drop_cols, errors="ignore", inplace=True)
|
||||||
|
df_domestic.drop(columns=drop_cols, errors="ignore", inplace=True)
|
||||||
|
|
||||||
|
|
||||||
|
mh_exc_columns = [
|
||||||
|
"Location", "MH_NO", "Upto_IL_Depth", "Cutting_Depth", "ID_of_MH_m",
|
||||||
|
"Ex_Dia_of_Manhole", "Area_of_Manhole",
|
||||||
|
|
||||||
|
"Soft_Murum_0_to_1_5", "Soft_Murum_1_5_to_3_0", "Soft_Murum_3_0_to_4_5",
|
||||||
|
"Hard_Murum_0_to_1_5", "Hard_Murum_1_5_to_3_0",
|
||||||
|
"Soft_Rock_0_to_1_5", "Soft_Rock_1_5_to_3_0",
|
||||||
|
"Hard_Rock_0_to_1_5", "Hard_Rock_1_5_to_3_0",
|
||||||
|
"Hard_Rock_3_0_to_4_5", "Hard_Rock_4_5_to_6_0", "Hard_Rock_6_0_to_7_5",
|
||||||
|
|
||||||
|
"Soft_Murum_0_to_1_5_total", "Soft_Murum_1_5_to_3_0_total",
|
||||||
|
"Soft_Murum_3_0_to_4_5_total",
|
||||||
|
"Hard_Murum_0_to_1_5_total", "Hard_Murum_1_5_and_above_total",
|
||||||
|
"Soft_Rock_0_to_1_5_total", "Soft_Rock_1_5_and_above_total",
|
||||||
|
"Hard_Rock_0_to_1_5_total", "Hard_Rock_1_5_and_above_total",
|
||||||
|
"Hard_Rock_3_0_to_4_5_total", "Hard_Rock_4_5_to_6_0_total",
|
||||||
|
"Hard_Rock_6_0_to_7_5_total",
|
||||||
|
|
||||||
|
"Remarks", "Total"
|
||||||
|
]
|
||||||
|
|
||||||
|
trench_columns = [
|
||||||
|
"Location", "MH_NO", "CC_length", "Invert_Level", "MH_Top_Level",
|
||||||
|
"Ground_Level", "ID_of_MH_m", "Actual_Trench_Length", "Pipe_Dia_mm",
|
||||||
|
|
||||||
|
"Width_0_to_2_5", "Width_2_5_to_3_0", "Width_3_0_to_4_5", "Width_4_5_to_6_0",
|
||||||
|
|
||||||
|
"Upto_IL_Depth", "Cutting_Depth", "Avg_Depth",
|
||||||
|
|
||||||
|
"Soft_Murum_0_to_1_5", "Soft_Murum_1_5_to_3_0", "Soft_Murum_3_0_to_4_5",
|
||||||
|
"Hard_Murum_0_to_1_5", "Hard_Murum_1_5_to_3_0",
|
||||||
|
|
||||||
|
"Soft_Rock_0_to_1_5", "Soft_Rock_1_5_to_3_0",
|
||||||
|
|
||||||
|
"Hard_Rock_0_to_1_5", "Hard_Rock_1_5_to_3_0",
|
||||||
|
"Hard_Rock_3_0_to_4_5", "Hard_Rock_4_5_to_6_0", "Hard_Rock_6_0_to_7_5",
|
||||||
|
|
||||||
|
"Soft_Murum_0_to_1_5_total", "Soft_Murum_1_5_to_3_0_total",
|
||||||
|
"Soft_Murum_3_0_to_4_5_total",
|
||||||
|
"Hard_Murum_0_to_1_5_total", "Hard_Murum_1_5_and_above_total",
|
||||||
|
"Soft_Rock_0_to_1_5_total", "Soft_Rock_1_5_and_above_total",
|
||||||
|
"Hard_Rock_0_to_1_5_total", "Hard_Rock_1_5_and_above_total",
|
||||||
|
"Hard_Rock_3_0_to_4_5_total", "Hard_Rock_4_5_to_6_0_total",
|
||||||
|
"Hard_Rock_6_0_to_7_5_total",
|
||||||
|
|
||||||
|
"Remarks", "Total"
|
||||||
|
]
|
||||||
|
|
||||||
|
domestic_columns = [
|
||||||
|
"Location", "Node_No", "Depth_of_MH",
|
||||||
|
"d_0_to_0_75", "d_1_06_to_1_65", "d_1_66_to_2_15",
|
||||||
|
"d_2_16_to_2_65", "d_2_66_to_3_15", "d_3_16_to_3_65",
|
||||||
|
"d_3_66_to_4_15", "d_4_16_to_4_65", "d_4_66_to_5_15",
|
||||||
|
"d_5_16_to_5_65", "d_5_66_to_6_15", "d_6_16_to_6_65",
|
||||||
|
"d_6_66_to_7_15", "d_7_16_to_7_65", "d_7_66_to_8_15",
|
||||||
|
"d_8_16_to_8_65", "d_8_66_to_9_15", "d_9_16_to_9_65",
|
||||||
|
"Domestic_Chambers"
|
||||||
|
]
|
||||||
|
|
||||||
|
# Reorder columns serial wise
|
||||||
|
df_mh_exc = df_mh_exc.reindex(columns=mh_exc_columns, fill_value="")
|
||||||
|
df_trench = df_trench.reindex(columns=trench_columns, fill_value="")
|
||||||
|
df_domestic = df_domestic.reindex(columns=domestic_columns, fill_value="")
|
||||||
|
|
||||||
|
# WRITE EXCEL FILE
|
||||||
|
output = io.BytesIO()
|
||||||
|
file_name = f"{subcontractor.subcontractor_name}_Report.xlsx"
|
||||||
|
|
||||||
|
with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
|
||||||
|
df_trench.to_excel(writer, index=False, sheet_name="Tr.Ex.")
|
||||||
|
df_mh_exc.to_excel(writer, index=False, sheet_name="MH.Ex.")
|
||||||
|
df_domestic.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)
|
||||||
|
|
||||||
return render_template("report.html", title="Report Download", subcontractors=subcontractors)
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="nav-item"><a class="nav-link" href="/user/list">Users</a></li>
|
<li class="nav-item"><a class="nav-link" href="/user/list">Users</a></li>
|
||||||
|
|
||||||
<!-- <li class="nav-item"><a class="nav-link" href="/user/list">Users</a></li> -->
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -63,3 +62,4 @@
|
|||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,28 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2 class="mb-4">File Report</h2>
|
<div class="container mt-4">
|
||||||
|
|
||||||
<div class="card p-4 shadow-sm">
|
<h2 class="mb-4">File Report</h2>
|
||||||
|
|
||||||
|
<!-- FLASH MESSAGES -->
|
||||||
|
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||||
|
{% if messages %}
|
||||||
|
{% for category, message in messages %}
|
||||||
|
<div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
|
||||||
|
{{ message }}
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endwith %}
|
||||||
|
|
||||||
|
<div class="card p-4 shadow-sm">
|
||||||
|
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
|
|
||||||
<!-- SELECT SUBCONTRACTOR -->
|
<!-- SELECT SUBCONTRACTOR -->
|
||||||
<label class="form-label">Select Subcontractor</label>
|
<label class="form-label fw-semibold">Select Subcontractor</label>
|
||||||
<select name="subcontractor_id" id="subcontractor_id" class="form-select mb-3" required>
|
<select name="subcontractor_id" id="subcontractor_id" class="form-select mb-3" required>
|
||||||
<option value="">-- Select Subcontractor --</option>
|
<option value="">-- Select Subcontractor --</option>
|
||||||
|
|
||||||
@@ -20,5 +34,6 @@
|
|||||||
<button class="btn btn-primary w-100">Generate Report</button>
|
<button class="btn btn-primary w-100">Generate Report</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user