diff --git a/app/__init__.py b/app/__init__.py index 3eb635b..c236761 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,34 +1,3 @@ -# from flask import Flask -# from app.config import Config -# from app.services.db_service import db - -# def create_app(): -# app = Flask(__name__) -# app.config.from_object(Config) - -# db.init_app(app) - -# from app.routes.auth import auth_bp -# from app.routes.user import user_bp -# from app.routes.dashboard import dashboard_bp -# from app.routes.subcontractor_routes import subcontractor_bp -# from app.routes.file_import import file_import_bp -# from app.routes.file_report import file_report_bp -# from app.routes.generate_comparison_report import generate_report_bp -# from app.routes.file_format import file_format - -# app.register_blueprint(auth_bp) -# app.register_blueprint(user_bp) -# app.register_blueprint(dashboard_bp) -# app.register_blueprint(subcontractor_bp) -# app.register_blueprint(file_import_bp) -# app.register_blueprint(file_report_bp) -# app.register_blueprint(generate_report_bp) -# app.register_blueprint(file_format) - -# return app - - from flask import Flask, redirect, url_for from app.config import Config from app.services.db_service import db diff --git a/app/models/laying_client_model.py b/app/models/laying_client_model.py new file mode 100644 index 0000000..4152165 --- /dev/null +++ b/app/models/laying_client_model.py @@ -0,0 +1,47 @@ +from app import db +from datetime import datetime + +class LayingClient(db.Model): + __tablename__ = "laying_client" + + id = db.Column(db.Integer, primary_key=True) + # Foreign Key to Subcontractor tables + # subcontractor_id = db.Column(db.Integer, db.ForeignKey("subcontractors.id"), nullable=False) + # Relationship for easy access (subcontractor.subcontractor_name) + # subcontractor = db.relationship("Subcontractor", backref="laying_records") + + # Basic Fields + Location = db.Column(db.String(500)) + MH_NO = db.Column(db.String(100)) + CC_length = db.Column(db.Float) + + Pipe_Dia_mm = db.Column(db.Float) + ID_of_MH_m = db.Column(db.Float) + Laying_Length = db.Column(db.Float) + + pipe_150_mm = db.Column(db.Float) + pipe_200_mm = db.Column(db.Float) + pipe_250_mm = db.Column(db.Float) + pipe_300_mm = db.Column(db.Float) + pipe_350_mm = db.Column(db.Float) + pipe_400_mm = db.Column(db.Float) + pipe_450_mm = db.Column(db.Float) + pipe_500_mm = db.Column(db.Float) + pipe_600_mm = db.Column(db.Float) + pipe_700_mm = db.Column(db.Float) + pipe_900_mm = db.Column(db.Float) + pipe_1200_mm = db.Column(db.Float) + + + Total = db.Column(db.Float) + Remarks = db.Column(db.String(500)) + RA_Bill_No=db.Column(db.String(500)) + + created_at = db.Column(db.DateTime, default=datetime.today) + + + def __repr__(self): + return f"" + + def serialize(self): + return {c.name: getattr(self, c.name) for c in self.__table__.columns} diff --git a/app/models/laying_model.py b/app/models/laying_model.py index e43a1f1..b8510ff 100644 --- a/app/models/laying_model.py +++ b/app/models/laying_model.py @@ -5,7 +5,7 @@ class Laying(db.Model): __tablename__ = "laying" id = db.Column(db.Integer, primary_key=True) - # Foreign Key to Subcontractor table + # Foreign Key to Subcontractor tables subcontractor_id = db.Column(db.Integer, db.ForeignKey("subcontractors.id"), nullable=False) # Relationship for easy access (subcontractor.subcontractor_name) subcontractor = db.relationship("Subcontractor", backref="laying_records") @@ -14,7 +14,7 @@ class Laying(db.Model): Location = db.Column(db.String(500)) MH_NO = db.Column(db.String(100)) CC_length = db.Column(db.Float) - + Pipe_Dia_mm = db.Column(db.Float) ID_of_MH_m = db.Column(db.Float) Laying_Length = db.Column(db.Float) diff --git a/app/routes/file_report.py b/app/routes/file_report.py index 27e5c95..44febb3 100644 --- a/app/routes/file_report.py +++ b/app/routes/file_report.py @@ -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 diff --git a/app/services/file_service.py b/app/services/file_service.py index cbb07f3..206ec1c 100644 --- a/app/services/file_service.py +++ b/app/services/file_service.py @@ -16,6 +16,7 @@ from app.models.laying_model import Laying from app.models.tr_ex_client_model import TrenchExcavationClient from app.models.mh_ex_client_model import ManholeExcavationClient from app.models.mh_dc_client_model import ManholeDomesticChamberClient +from app.models.laying_client_model import LayingClient @@ -335,10 +336,12 @@ class FileService: df_tr_ex = pd.read_excel(filepath, sheet_name="Tr.Ex.", header=4) df_mh_ex = pd.read_excel(filepath, sheet_name="MH Ex.", header=4) df_mh_dc = pd.read_excel(filepath, sheet_name="MH & DC", header=3) + df_lay = pd.read_excel(filepath, sheet_name="Laying & Bedding", header=3) self.save_client_data(df_tr_ex, TrenchExcavationClient, RA_Bill_No) self.save_client_data(df_mh_ex, ManholeExcavationClient, RA_Bill_No) self.save_client_data(df_mh_dc, ManholeDomesticChamberClient, RA_Bill_No) + self.save_client_data(df_lay, LayingClient, RA_Bill_No) db.session.commit() return True, "Client file uploaded successfully." @@ -369,3 +372,4 @@ class FileService: record = model(RA_Bill_No=RA_Bill_No, **record_data) db.session.add(record) + diff --git a/app/templates/generate_comparison_client_vs_subcont.html b/app/templates/generate_comparison_client_vs_subcont.html index 56b7eef..edd5355 100644 --- a/app/templates/generate_comparison_client_vs_subcont.html +++ b/app/templates/generate_comparison_client_vs_subcont.html @@ -2,7 +2,7 @@ {% block content %}
-

File Comparison

+

Client File Reports

{% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} diff --git a/app/templates/report.html b/app/templates/report.html index 5834dbe..182e8c1 100644 --- a/app/templates/report.html +++ b/app/templates/report.html @@ -93,16 +93,22 @@
@@ -121,6 +127,12 @@ {{ tables.dc | safe }}
+ +
+
+ {{ tables.laying | safe }} +
+