import mysql.connector from mysql.connector import Error import config import openpyxl import os import re import ast from datetime import datetime class ContractorInfo: ID = "" contInfo = None def __init__(self, id): self.ID = id print(id) self.fetchData() def fetchData(self): try: connection = config.get_db_connection() cursor = connection.cursor(dictionary=True, buffered=True) print("here", flush=True) cursor.callproc('GetContractorInfoById', [self.contInfo]) #self.contInfo = next(cursor.stored_results()).fetchone() self.contInfo = cursor.fetchone() print(self.contInfo,flush=True) finally: cursor.close() connection.close() def fetchalldata(self): try: connection = config.get_db_connection() cursor = connection.cursor(dictionary=True, buffered=True) print("here", flush=True) # ---------------- Hold Types ---------------- cursor.execute(""" SELECT DISTINCT ht.hold_type_id, ht.hold_type FROM invoice_subcontractor_hold_join h JOIN hold_types ht ON h.hold_type_id = ht.hold_type_id WHERE h.Contractor_Id = %s """, (self.contractor_id,)) hold_types = cursor.fetchall() hold_type_map = {ht['hold_type_id']: ht['hold_type'] for ht in hold_types} # ---------------- Invoices ---------------- cursor.execute(""" SELECT i.*, v.Village_Name FROM assign_subcontractors asg INNER JOIN invoice i ON i.PMC_No = asg.PMC_No AND i.Village_Id = asg.Village_Id LEFT JOIN villages v ON i.Village_Id = v.Village_Id WHERE asg.Contractor_Id = %s ORDER BY i.PMC_No, i.Invoice_No """, (self.contractor_id,)) invoices = cursor.fetchall() # Remove duplicate invoices invoice_ids_seen = set() unique_invoices = [] for inv in invoices: if inv["Invoice_Id"] not in invoice_ids_seen: invoice_ids_seen.add(inv["Invoice_Id"]) unique_invoices.append(inv) invoices = unique_invoices finally: cursor.close() connection.close()