webhook
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import pandas as pd
|
||||
import io
|
||||
import logging
|
||||
from flask import Blueprint, render_template, request, send_file, flash
|
||||
from app.utils.helpers import login_required
|
||||
|
||||
@@ -18,6 +19,9 @@ from app.models.laying_client_model import LayingClient
|
||||
|
||||
# --- BLUEPRINT DEFINITION ---
|
||||
file_report_bp = Blueprint("file_report", __name__, url_prefix="/file")
|
||||
|
||||
# Configure logging for debugging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# --- Client class ---
|
||||
class ClientBill:
|
||||
@@ -28,20 +32,57 @@ class ClientBill:
|
||||
self.df_laying = pd.DataFrame()
|
||||
|
||||
def Fetch(self, RA_Bill_No):
|
||||
trench = TrenchExcavationClient.query.filter_by(RA_Bill_No=RA_Bill_No).all()
|
||||
mh = ManholeExcavationClient.query.filter_by(RA_Bill_No=RA_Bill_No).all()
|
||||
dc = ManholeDomesticChamberClient.query.filter_by(RA_Bill_No=RA_Bill_No).all()
|
||||
lay = LayingClient.query.filter_by(RA_Bill_No=RA_Bill_No).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])
|
||||
|
||||
drop_cols = ["id", "created_at", "_sa_instance_state"]
|
||||
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)
|
||||
logger.info("=" * 60)
|
||||
logger.info("ClientBill.Fetch() - START")
|
||||
logger.info("=" * 60)
|
||||
logger.info(f"Fetching data for RA_Bill_No: '{RA_Bill_No}'")
|
||||
logger.debug(f" Type of RA_Bill_No: {type(RA_Bill_No)}")
|
||||
|
||||
try:
|
||||
logger.info("Step 1: Fetching TrenchExcavationClient records...")
|
||||
trench = TrenchExcavationClient.query.filter_by(RA_Bill_No=RA_Bill_No).all()
|
||||
logger.info(f"✓ Trench records found: {len(trench)}")
|
||||
|
||||
logger.info("Step 2: Fetching ManholeExcavationClient records...")
|
||||
mh = ManholeExcavationClient.query.filter_by(RA_Bill_No=RA_Bill_No).all()
|
||||
logger.info(f"✓ Manhole records found: {len(mh)}")
|
||||
|
||||
logger.info("Step 3: Fetching ManholeDomesticChamberClient records...")
|
||||
dc = ManholeDomesticChamberClient.query.filter_by(RA_Bill_No=RA_Bill_No).all()
|
||||
logger.info(f"✓ Domestic Chamber records found: {len(dc)}")
|
||||
|
||||
logger.info("Step 4: Fetching LayingClient records...")
|
||||
lay = LayingClient.query.filter_by(RA_Bill_No=RA_Bill_No).all()
|
||||
logger.info(f"✓ Laying records found: {len(lay)}")
|
||||
|
||||
logger.info("Step 5: Converting to DataFrames...")
|
||||
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])
|
||||
|
||||
logger.debug(f" Trench DF shape: {self.df_tr.shape}")
|
||||
logger.debug(f" Manhole DF shape: {self.df_mh.shape}")
|
||||
logger.debug(f" Domestic Chamber DF shape: {self.df_dc.shape}")
|
||||
logger.debug(f" Laying DF shape: {self.df_laying.shape}")
|
||||
|
||||
logger.info("Step 6: Cleaning DataFrames...")
|
||||
drop_cols = ["id", "created_at", "_sa_instance_state"]
|
||||
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)
|
||||
logger.debug(f" Cleaned DF with shape: {df.shape}")
|
||||
|
||||
logger.info("✓ ClientBill.Fetch() completed successfully")
|
||||
logger.info("=" * 60)
|
||||
|
||||
except Exception as e:
|
||||
logger.error("=" * 60)
|
||||
logger.error(f"ERROR in ClientBill.Fetch(): {str(e)}")
|
||||
logger.error(f"Error type: {type(e).__name__}")
|
||||
logger.exception("Full traceback:")
|
||||
logger.error("=" * 60)
|
||||
raise
|
||||
|
||||
# --- Subcontractor class ---
|
||||
class SubcontractorBill:
|
||||
@@ -52,26 +93,68 @@ class SubcontractorBill:
|
||||
self.df_laying = pd.DataFrame()
|
||||
|
||||
def Fetch(self, RA_Bill_No=None, subcontractor_id=None):
|
||||
filters = {}
|
||||
if subcontractor_id:
|
||||
filters["subcontractor_id"] = subcontractor_id
|
||||
if RA_Bill_No:
|
||||
filters["RA_Bill_No"] = RA_Bill_No
|
||||
|
||||
trench = TrenchExcavation.query.filter_by(**filters).all()
|
||||
mh = ManholeExcavation.query.filter_by(**filters).all()
|
||||
dc = ManholeDomesticChamber.query.filter_by(**filters).all()
|
||||
lay = Laying.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])
|
||||
|
||||
drop_cols = ["id", "created_at", "_sa_instance_state"]
|
||||
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)
|
||||
logger.info("=" * 60)
|
||||
logger.info("SubcontractorBill.Fetch() - START")
|
||||
logger.info("=" * 60)
|
||||
logger.info(f"Parameters:")
|
||||
logger.info(f" RA_Bill_No: '{RA_Bill_No}' (type: {type(RA_Bill_No)})")
|
||||
logger.info(f" subcontractor_id: '{subcontractor_id}' (type: {type(subcontractor_id)})")
|
||||
|
||||
try:
|
||||
filters = {}
|
||||
if subcontractor_id:
|
||||
filters["subcontractor_id"] = subcontractor_id
|
||||
logger.debug(f" Added filter - subcontractor_id: {subcontractor_id}")
|
||||
if RA_Bill_No:
|
||||
filters["RA_Bill_No"] = RA_Bill_No
|
||||
logger.debug(f" Added filter - RA_Bill_No: {RA_Bill_No}")
|
||||
|
||||
logger.info(f"Applied filters: {filters}")
|
||||
|
||||
logger.info("Step 1: Fetching TrenchExcavation records...")
|
||||
trench = TrenchExcavation.query.filter_by(**filters).all()
|
||||
logger.info(f"✓ Trench records found: {len(trench)}")
|
||||
|
||||
logger.info("Step 2: Fetching ManholeExcavation records...")
|
||||
mh = ManholeExcavation.query.filter_by(**filters).all()
|
||||
logger.info(f"✓ Manhole records found: {len(mh)}")
|
||||
|
||||
logger.info("Step 3: Fetching ManholeDomesticChamber records...")
|
||||
dc = ManholeDomesticChamber.query.filter_by(**filters).all()
|
||||
logger.info(f"✓ Domestic Chamber records found: {len(dc)}")
|
||||
|
||||
logger.info("Step 4: Fetching Laying records...")
|
||||
lay = Laying.query.filter_by(**filters).all()
|
||||
logger.info(f"✓ Laying records found: {len(lay)}")
|
||||
|
||||
logger.info("Step 5: Converting to DataFrames...")
|
||||
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])
|
||||
|
||||
logger.debug(f" Trench DF shape: {self.df_tr.shape}")
|
||||
logger.debug(f" Manhole DF shape: {self.df_mh.shape}")
|
||||
logger.debug(f" Domestic Chamber DF shape: {self.df_dc.shape}")
|
||||
logger.debug(f" Laying DF shape: {self.df_laying.shape}")
|
||||
|
||||
logger.info("Step 6: Cleaning DataFrames...")
|
||||
drop_cols = ["id", "created_at", "_sa_instance_state"]
|
||||
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)
|
||||
logger.debug(f" Cleaned DF with shape: {df.shape}")
|
||||
|
||||
logger.info("✓ SubcontractorBill.Fetch() completed successfully")
|
||||
logger.info("=" * 60)
|
||||
|
||||
except Exception as e:
|
||||
logger.error("=" * 60)
|
||||
logger.error(f"ERROR in SubcontractorBill.Fetch(): {str(e)}")
|
||||
logger.error(f"Error type: {type(e).__name__}")
|
||||
logger.exception("Full traceback:")
|
||||
logger.error("=" * 60)
|
||||
raise
|
||||
|
||||
|
||||
# --- subcontractor report only ---
|
||||
|
||||
Reference in New Issue
Block a user