update code and remove comments
This commit is contained in:
@@ -70,22 +70,7 @@ def get_all_villages():
|
||||
# ------------------- Invoice Functions -------------------
|
||||
def insert_invoice(data, village_id):
|
||||
def operation(cursor):
|
||||
# Insert invoice
|
||||
# cursor.callproc('InsertInvoice', [
|
||||
# data.get('pmc_no'),
|
||||
# village_id,
|
||||
# data.get('work_type'),
|
||||
# data.get('invoice_details'),
|
||||
# data.get('invoice_date'),
|
||||
# data.get('invoice_no'),
|
||||
# *get_numeric_values(data),
|
||||
# data.get('subcontractor_id')
|
||||
|
||||
# ])
|
||||
# invoice_row = fetch_one(cursor)
|
||||
# if not invoice_row:
|
||||
# raise Exception("Invoice ID not returned")
|
||||
# invoice_id = invoice_row.get('invoice_id')
|
||||
cursor.callproc('SaveInvoice', [
|
||||
data.get('pmc_no'),
|
||||
village_id,
|
||||
@@ -103,18 +88,6 @@ def insert_invoice(data, village_id):
|
||||
if row:
|
||||
invoice_id = row['invoice_id']
|
||||
|
||||
# # Insert inpayment
|
||||
# cursor.callproc('InsertInpayment', [
|
||||
# data.get('pmc_no'),
|
||||
# village_id,
|
||||
# data.get('work_type'),
|
||||
# data.get('invoice_details'),
|
||||
# data.get('invoice_date'),
|
||||
# data.get('invoice_no'),
|
||||
# *get_numeric_values(data),
|
||||
# data.get('subcontractor_id')
|
||||
# ])
|
||||
# clear_results(cursor)
|
||||
return invoice_id
|
||||
|
||||
return execute_db_operation(operation)
|
||||
@@ -159,18 +132,6 @@ def update_invoice(data, invoice_id):
|
||||
clear_results(cursor)
|
||||
execute_db_operation(operation)
|
||||
|
||||
# def update_inpayment(data):
|
||||
# def operation(cursor):
|
||||
# cursor.callproc('UpdateInpayment', [
|
||||
# data.get('work_type'),
|
||||
# data.get('invoice_details'),
|
||||
# data.get('invoice_date'),
|
||||
# *get_numeric_values(data),
|
||||
# data.get('pmc_no'),
|
||||
# data.get('invoice_no')
|
||||
# ])
|
||||
# clear_results(cursor)
|
||||
# execute_db_operation(operation)
|
||||
|
||||
def delete_invoice_data(invoice_id, user_id):
|
||||
def operation(cursor):
|
||||
@@ -190,24 +151,10 @@ def delete_invoice_data(invoice_id, user_id):
|
||||
cursor.callproc("DeleteInvoice", (invoice_id,))
|
||||
clear_results(cursor)
|
||||
|
||||
# Delete inpayment
|
||||
# cursor.callproc('DeleteInpaymentByPMCInvoice', (pmc_no, invoice_no))
|
||||
# clear_results(cursor)
|
||||
|
||||
execute_db_operation(operation)
|
||||
|
||||
|
||||
# ------------------- Subcontractor Functions -------------------
|
||||
# def assign_subcontractor(data, village_id):
|
||||
# def operation(cursor):
|
||||
# cursor.callproc('AssignSubcontractor', [
|
||||
# data.get('pmc_no'),
|
||||
# data.get('subcontractor_id'),
|
||||
# village_id
|
||||
# ])
|
||||
# clear_results(cursor)
|
||||
# execute_db_operation(operation)
|
||||
|
||||
|
||||
# ------------------- Hold Types Functions -------------------
|
||||
def insert_hold_types(data, invoice_id):
|
||||
|
||||
@@ -29,18 +29,6 @@ class PmcReport:
|
||||
|
||||
invoices = []
|
||||
hold_amount_total = 0
|
||||
# if hold_type_ids:
|
||||
# hold_type_ids_str = ",".join(map(str, hold_type_ids))
|
||||
# cursor.callproc(
|
||||
# 'GetInvoices_WithHold',
|
||||
# [pmc_no, pmc_info["Contractor_Id"], hold_type_ids_str]
|
||||
# )
|
||||
# else:
|
||||
# cursor.callproc(
|
||||
# 'GetInvoices_NoHold',
|
||||
# [pmc_no, pmc_info["Contractor_Id"]]
|
||||
# )
|
||||
|
||||
hold_type_ids_str = ",".join(map(str, hold_type_ids))
|
||||
cursor.callproc(
|
||||
'GetInvoices_WithHold',
|
||||
@@ -148,10 +136,6 @@ class PmcReport:
|
||||
)
|
||||
credit_note_map = {}
|
||||
for cn in credit_notes:
|
||||
# key = (
|
||||
# str(cn['PMC_No']).strip(),
|
||||
# str(cn['Invoice_No']).replace(" ", "") if cn['Invoice_No'] else ""
|
||||
# )
|
||||
key = (
|
||||
str(cn['PMC_No']).strip()
|
||||
)
|
||||
@@ -167,10 +151,7 @@ class PmcReport:
|
||||
)
|
||||
gst_release_map = {}
|
||||
for gr in gst_releases:
|
||||
# key = (
|
||||
# str(gr['PMC_No']).strip(),
|
||||
# str(gr['Invoice_No']).replace(" ", "") if gr['Invoice_No'] else ""
|
||||
# )
|
||||
|
||||
key = (
|
||||
str(gr['PMC_No']).strip()
|
||||
)
|
||||
@@ -181,17 +162,6 @@ class PmcReport:
|
||||
for h in hold_amounts:
|
||||
hold_data.setdefault(h['Invoice_Id'], {})[h['hold_type_id']] = h['hold_amount']
|
||||
|
||||
# credit_note_map = {}
|
||||
# for cn in credit_notes:
|
||||
# pmc = cn.get("PMC_No")
|
||||
# if pmc:
|
||||
# credit_note_map.setdefault(pmc, []).append(cn)
|
||||
|
||||
# gst_map = {}
|
||||
# for gst in gst_releases:
|
||||
# pmc = gst.get("PMC_No")
|
||||
# if pmc:
|
||||
# gst_map.setdefault(pmc, []).append(gst)
|
||||
|
||||
# ================= LOG =================
|
||||
LogHelper.log_action(
|
||||
@@ -199,126 +169,11 @@ class PmcReport:
|
||||
f"User {current_user.id} Download PMC Report '{pmc_no}'"
|
||||
)
|
||||
|
||||
# # ================= EXCEL =================
|
||||
# workbook = openpyxl.Workbook()
|
||||
# sheet = workbook.active
|
||||
# sheet.title = "PMC Report"
|
||||
|
||||
# # HEADER INFO
|
||||
# sheet.append(["", "", "Laxmi Civil Engineering Services PVT. LTD."])
|
||||
# sheet.append(["Contractor Name", contractor_info["Contractor_Name"]])
|
||||
# sheet.append(["State", contractor_info["State_Name"]])
|
||||
# sheet.append(["District", contractor_info["District_Name"]])
|
||||
# sheet.append(["Block", contractor_info["Block_Name"]])
|
||||
# sheet.append([])
|
||||
|
||||
# base_headers = [
|
||||
# "PMC No", "Village", "Work Type", "Invoice Details",
|
||||
# "Invoice Date", "Invoice No", "Basic Amount", "Debit", "After Debit Amount",
|
||||
# "GST", "Amount", "TDS", "SD", "On Commission", "Hydro Testing", "GST SD Amount"
|
||||
# ]
|
||||
|
||||
# hold_headers = [ht['hold_type'] for ht in hold_types]
|
||||
# payment_headers = ["Final Amount", "Payment Amount", "TDS Payment", "Total Paid", "UTR"]
|
||||
|
||||
# headers = base_headers + hold_headers + payment_headers
|
||||
# sheet.append(headers)
|
||||
# for cell in sheet[sheet.max_row]:
|
||||
# cell.font = Font(bold=True)
|
||||
|
||||
# # ================= INVOICE ROWS =================
|
||||
# for inv in invoices:
|
||||
# row = [
|
||||
# pmc_no,
|
||||
# inv.get("Village_Name", ""),
|
||||
# inv.get("Work_Type", ""),
|
||||
# inv.get("Invoice_Details", ""),
|
||||
# inv.get("Invoice_Date", ""),
|
||||
# inv.get("invoice_no", ""),
|
||||
# inv.get("Basic_Amount", ""),
|
||||
# inv.get("Debit_Amount", ""),
|
||||
# inv.get("After_Debit_Amount", ""),
|
||||
# inv.get("GST_Amount", ""),
|
||||
# inv.get("Amount", ""),
|
||||
# inv.get("TDS_Amount", ""),
|
||||
# inv.get("SD_Amount", ""),
|
||||
# inv.get("On_Commission", ""),
|
||||
# inv.get("Hydro_Testing", ""),
|
||||
# inv.get("GST_SD_Amount", "")
|
||||
# ]
|
||||
|
||||
# # HOLD DATA
|
||||
# invoice_holds = hold_data.get(inv.get("Invoice_Id"), {})
|
||||
# for ht_id in hold_type_map.keys():
|
||||
# row.append(invoice_holds.get(ht_id, ""))
|
||||
|
||||
# # PAYMENT DATA
|
||||
# row += [
|
||||
# inv.get("Final_Amount", ""),
|
||||
# inv.get("Payment_Amount", ""),
|
||||
# inv.get("TDS_Payment_Amount", ""),
|
||||
# inv.get("Total_Amount", ""),
|
||||
# inv.get("UTR", "")
|
||||
# ]
|
||||
|
||||
# # GST release placeholders (will add real GST below)
|
||||
# row += ["", ""]
|
||||
|
||||
# sheet.append(row)
|
||||
|
||||
# for pmc, cn_list in credit_note_map.items():
|
||||
# for cn in cn_list:
|
||||
# cn_row = [
|
||||
# pmc_no,
|
||||
# "", "", "Credit Note",
|
||||
# "", cn.get("Invoice_No", ""),
|
||||
# cn.get("Basic_Amount", ""),
|
||||
# "", "", "", "", "", "", "", "", "", "", ""
|
||||
# ]
|
||||
# cn_row += [""] * len(hold_headers)
|
||||
# cn_row += [
|
||||
# cn.get("Final_Amount", ""),
|
||||
# cn.get("Total_Amount", ""),
|
||||
# cn.get("UTR", "")
|
||||
# ]
|
||||
# sheet.append(cn_row)
|
||||
|
||||
# # ================= GST RELEASE ROWS =================
|
||||
# for gst in gst_releases:
|
||||
# gst_row = [
|
||||
# gst.get("PMC_No", ""),
|
||||
# "", "", "GST Release Note",
|
||||
# "", gst.get("Invoice_No", ""),
|
||||
# gst.get("Basic_Amount", ""),
|
||||
# "", "", "", "", "", "", "", "", ""
|
||||
# ]
|
||||
# gst_row += [""] * len(hold_headers)
|
||||
# gst_row += [
|
||||
# gst.get("Final_Amount", ""),
|
||||
# "",
|
||||
# "",
|
||||
# gst.get("Total_Amount", ""),
|
||||
# gst.get("UTR", "")
|
||||
# ]
|
||||
# sheet.append(gst_row)
|
||||
|
||||
# # ================= AUTO WIDTH =================
|
||||
# for col in sheet.columns:
|
||||
# max_len = max((len(str(cell.value)) for cell in col if cell.value), default=0)
|
||||
# sheet.column_dimensions[col[0].column_letter].width = max_len + 2
|
||||
|
||||
# workbook.save(output_file)
|
||||
# workbook.close()
|
||||
|
||||
|
||||
ReportHelper.generate_excel(
|
||||
0, contractor_info, invoices, hold_types, hold_data,
|
||||
credit_note_map,gst_release_map, output_file
|
||||
)
|
||||
# ReportHelper.generate_excel(
|
||||
# contractor_id, contInfo, invoices, hold_types, hold_data,
|
||||
# credit_note_map, gst_release_map, output_file
|
||||
# )
|
||||
|
||||
return output_folder, filename
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -154,9 +154,6 @@ class ReportHelper:
|
||||
contractor = ContractorInfo(contractor_id)
|
||||
return contractor.contInfo if contractor.contInfo else None
|
||||
|
||||
# @staticmethod
|
||||
# def generate_excel(contractor_id, contInfo, invoices, hold_types, hold_data,
|
||||
# extra_payments_map, credit_note_map, gst_release_map, output_file):
|
||||
@staticmethod
|
||||
def generate_excel(contractor_id, contInfo, invoices, hold_types, hold_data,
|
||||
credit_note_map, gst_release_map, output_file):
|
||||
@@ -249,22 +246,6 @@ class ReportHelper:
|
||||
|
||||
sheet.append(row)
|
||||
|
||||
# # Extra Payments
|
||||
# if pmc_no in extra_payments_map:
|
||||
# for ep in extra_payments_map[pmc_no]:
|
||||
# extra_row = [pmc_no] + [""] * (len(base_headers) - 1)
|
||||
# extra_row += [""] * len(hold_headers)
|
||||
# extra_row += [
|
||||
# "",
|
||||
# ep.get("Payment_Amount", ""),
|
||||
# ep.get("TDS_Payment_Amount", ""),
|
||||
# ep.get("Total_Amount", ""),
|
||||
# ep.get("utr", "")
|
||||
# ]
|
||||
# sheet.append(extra_row)
|
||||
|
||||
# del extra_payments_map[pmc_no]
|
||||
|
||||
# GST Releases
|
||||
if key in gst_release_map and key not in processed_gst_releases:
|
||||
for gr in gst_release_map[key]:
|
||||
@@ -321,11 +302,8 @@ class ReportHelper:
|
||||
|
||||
@staticmethod
|
||||
def create_contractor_report(contractor_id):
|
||||
# DOWNLOAD_FOLDER = os.path.join("static", "download")
|
||||
# os.makedirs(DOWNLOAD_FOLDER, exist_ok=True)
|
||||
|
||||
fileName=f"Contractor_Report_{contractor_id}.xlsx"
|
||||
# output_file = os.path.join(DOWNLOAD_FOLDER, )
|
||||
|
||||
output_file = FolderAndFile.get_download_path(filename=fileName)
|
||||
|
||||
# Fetch Data
|
||||
@@ -342,21 +320,12 @@ class ReportHelper:
|
||||
hold_data = {}
|
||||
for h in hold_amounts:
|
||||
hold_data.setdefault(h['Invoice_Id'], {})[h['hold_type_id']] = h['hold_amount']
|
||||
# # # -------- Extra Payments MAP --------
|
||||
# # extra_payments_raw = ReportHelper.execute_sp(cursor, 'GetExtraPayments')
|
||||
# # extra_payments_map = {}
|
||||
# # for ep in extra_payments_raw:
|
||||
# # pmc = str(ep['pmc_no']).strip()
|
||||
# # extra_payments_map.setdefault(pmc, []).append(ep)
|
||||
|
||||
# -------- Credit Note MAP --------
|
||||
credit_note_raw = ReportHelper.execute_sp(cursor, 'GetCreditNotesByContractor', [contractor_id])
|
||||
credit_note_map = {}
|
||||
for cn in credit_note_raw:
|
||||
# key = (
|
||||
# str(cn['PMC_No']).strip(),
|
||||
# str(cn['Invoice_No']).replace(" ", "") if cn['Invoice_No'] else ""
|
||||
# )
|
||||
|
||||
key = (
|
||||
str(cn['PMC_No']).strip()
|
||||
)
|
||||
@@ -366,21 +335,11 @@ class ReportHelper:
|
||||
gst_release_raw = ReportHelper.execute_sp(cursor, 'GstReleasesByContractorId', [contractor_id])
|
||||
gst_release_map = {}
|
||||
for gr in gst_release_raw:
|
||||
# key = (
|
||||
# str(gr['PMC_No']).strip(),
|
||||
# str(gr['Invoice_No']).replace(" ", "") if gr['Invoice_No'] else ""
|
||||
# )
|
||||
key = (
|
||||
str(gr['PMC_No']).strip()
|
||||
)
|
||||
gst_release_map.setdefault(key, []).append(gr)
|
||||
|
||||
# print("GST MAP:", gst_release_map)
|
||||
# Generate Excel
|
||||
# ReportHelper.generate_excel(
|
||||
# contractor_id, contInfo, invoices, hold_types, hold_data,
|
||||
# extra_payments_map, credit_note_map, gst_release_map, output_file
|
||||
# )
|
||||
ReportHelper.generate_excel(
|
||||
contractor_id, contInfo, invoices, hold_types, hold_data,
|
||||
credit_note_map, gst_release_map, output_file
|
||||
|
||||
@@ -72,24 +72,6 @@ class Paymentmodel:
|
||||
if connection:
|
||||
connection.close()
|
||||
|
||||
# @staticmethod
|
||||
# def update_inpayment(subcontractor_id, pmc_no, invoice_no, amount, tds_amount, total_amount, utr):
|
||||
# connection = Paymentmodel.get_connection()
|
||||
# if not connection:
|
||||
# return False
|
||||
# try:
|
||||
# cursor = connection.cursor()
|
||||
# cursor.callproc('UpdateInpaymentRecord', [
|
||||
# subcontractor_id, pmc_no, invoice_no, amount, tds_amount, total_amount, utr
|
||||
# ])
|
||||
# connection.commit()
|
||||
# return True
|
||||
# except mysql.connector.Error as e:
|
||||
# print(f"Error updating inpayment: {e}")
|
||||
# return False
|
||||
# finally:
|
||||
# cursor.close()
|
||||
# connection.close()
|
||||
|
||||
@staticmethod
|
||||
def fetch_payment_by_id(payment_id):
|
||||
@@ -155,9 +137,7 @@ class Paymentmodel:
|
||||
# Delete payment
|
||||
cursor.callproc("DeletePayment", (payment_id,))
|
||||
connection.commit()
|
||||
# Reset inpayment fields
|
||||
# cursor.callproc("ResetInpayment", [pmc_no, invoice_no])
|
||||
# connection.commit()
|
||||
|
||||
return True, pmc_no, invoice_no
|
||||
except mysql.connector.Error as e:
|
||||
print(f"Error deleting payment: {e}")
|
||||
|
||||
Reference in New Issue
Block a user