update code and remove comments
This commit is contained in:
@@ -90,9 +90,6 @@ def edit_block(block_id):
|
|||||||
for rs in cursor.stored_results():
|
for rs in cursor.stored_results():
|
||||||
states = rs.fetchall()
|
states = rs.fetchall()
|
||||||
|
|
||||||
# cursor.callproc("GetAllDistrictsData")
|
|
||||||
# for rs in cursor.stored_results():
|
|
||||||
# districts = rs.fetchall()
|
|
||||||
cursor.callproc("GetAllDistricts")
|
cursor.callproc("GetAllDistricts")
|
||||||
for rs in cursor.stored_results():
|
for rs in cursor.stored_results():
|
||||||
districts = rs.fetchall()
|
districts = rs.fetchall()
|
||||||
|
|||||||
@@ -244,11 +244,6 @@ def save_data():
|
|||||||
for result in cursor.stored_results():
|
for result in cursor.stored_results():
|
||||||
result = result.fetchone()
|
result = result.fetchone()
|
||||||
village_id = result[0] if result else None
|
village_id = result[0] if result else None
|
||||||
# print("village_id :", village_id)
|
|
||||||
# print("block_id :", block_id)
|
|
||||||
# print("invoice :", PMC_No, village_id, work_type, Invoice_Details, Invoice_Date, Invoice_No,
|
|
||||||
# Basic_Amount, Debit_Amount, After_Debit_Amount, Amount, GST_Amount, TDS_Amount,
|
|
||||||
# SD_Amount, On_Commission, Hydro_Testing, GST_SD_Amount, Final_Amount)
|
|
||||||
|
|
||||||
args = (
|
args = (
|
||||||
PMC_No, village_id, work_type, Invoice_Details, Invoice_Date, Invoice_No,
|
PMC_No, village_id, work_type, Invoice_Details, Invoice_Date, Invoice_No,
|
||||||
@@ -261,9 +256,7 @@ def save_data():
|
|||||||
# add subcontarctor id in invoice table
|
# add subcontarctor id in invoice table
|
||||||
results = cursor.callproc('SaveInvoice', args)
|
results = cursor.callproc('SaveInvoice', args)
|
||||||
invoice_id = results[-1]
|
invoice_id = results[-1]
|
||||||
print("**************************************************************")
|
|
||||||
print(invoice_id)
|
|
||||||
print("**************************************************************")
|
|
||||||
cursor.callproc(
|
cursor.callproc(
|
||||||
"SavePayment",
|
"SavePayment",
|
||||||
(
|
(
|
||||||
@@ -308,8 +301,6 @@ def save_data():
|
|||||||
print("Hold columns data is not a valid list of dictionaries.")
|
print("Hold columns data is not a valid list of dictionaries.")
|
||||||
#---------------------------------------------Credit Note---------------------------------------------------------------------------
|
#---------------------------------------------Credit Note---------------------------------------------------------------------------
|
||||||
elif any(keyword in Invoice_Details.lower() for keyword in ['credit note','logging report']):
|
elif any(keyword in Invoice_Details.lower() for keyword in ['credit note','logging report']):
|
||||||
# print("Credit note found:", PMC_No, Invoice_No, Basic_Amount, Debit_Amount, Final_Amount,
|
|
||||||
# After_Debit_Amount, GST_Amount, Amount, Final_Amount, Payment_Amount, Total_Amount, UTR, Invoice_No)
|
|
||||||
cursor.callproc(
|
cursor.callproc(
|
||||||
'AddCreditNoteFromExcel',
|
'AddCreditNoteFromExcel',
|
||||||
[
|
[
|
||||||
@@ -334,17 +325,14 @@ def save_data():
|
|||||||
]
|
]
|
||||||
# Step 3: Matching condition
|
# Step 3: Matching condition
|
||||||
if any(kw in normalized_details for kw in keywords):
|
if any(kw in normalized_details for kw in keywords):
|
||||||
# print("✅ Match found. Inserting hold release for:", Invoice_Details)
|
|
||||||
cursor.callproc(
|
cursor.callproc(
|
||||||
'AddHoldReleaseFromExcel',
|
'AddHoldReleaseFromExcel',
|
||||||
[PMC_No, Invoice_No, Invoice_Details, Basic_Amount, Final_Amount, UTR, subcontractor_id]
|
[PMC_No, Invoice_No, Invoice_Details, Basic_Amount, Final_Amount, UTR, subcontractor_id]
|
||||||
)
|
)
|
||||||
connection.commit()
|
connection.commit()
|
||||||
# print("✅ Hold release inserted for:", PMC_No, Invoice_Details)
|
|
||||||
#------------------------------------------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------------------------------------------
|
||||||
elif Invoice_Details and any(
|
elif Invoice_Details and any(
|
||||||
keyword in Invoice_Details.lower() for keyword in ['gst', 'release', 'gst release note']):
|
keyword in Invoice_Details.lower() for keyword in ['gst', 'release', 'gst release note']):
|
||||||
# print("Gst rels :", PMC_No, Invoice_No, Basic_Amount, Final_Amount,Total_Amount,UTR, subcontractor_id)
|
|
||||||
cursor.callproc(
|
cursor.callproc(
|
||||||
'AddGSTReleaseFromExcel',
|
'AddGSTReleaseFromExcel',
|
||||||
[PMC_No, Invoice_No, Basic_Amount, Final_Amount, Total_Amount, UTR, subcontractor_id]
|
[PMC_No, Invoice_No, Basic_Amount, Final_Amount, Total_Amount, UTR, subcontractor_id]
|
||||||
@@ -352,39 +340,13 @@ def save_data():
|
|||||||
|
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
# If no village/work detected, only PMC/Payment
|
# If no village/work detected, only PMC/Payment
|
||||||
if not (Invoice_Details and 'village' in Invoice_Details.lower() and 'work' in Invoice_Details.lower()):
|
|
||||||
# if not (Invoice_Details and 'village' in Invoice_Details.lower() and 'work' in Invoice_Details.lower() and 'gst' in Invoice_Details.lower() and 'gst release note' in Invoice_Details.lower() and 'release' in Invoice_Details.lower()):
|
|
||||||
|
|
||||||
|
if not (Invoice_Details and 'village' in Invoice_Details.lower() and 'work' in Invoice_Details.lower()):
|
||||||
# ---------- Only PMC / Payment rows ----------
|
# ---------- Only PMC / Payment rows ----------
|
||||||
if PMC_No and not Invoice_No and UTR :
|
if PMC_No and not Invoice_No and UTR :
|
||||||
# print("No village/work, using PMC only :", PMC_No)
|
|
||||||
|
|
||||||
# check invoice exists
|
|
||||||
# cursor.execute(
|
|
||||||
# "SELECT invoice_id FROM invoice WHERE PMC_No=%s ORDER BY invoice_id DESC LIMIT 1",
|
|
||||||
# (PMC_No,)
|
|
||||||
# )
|
|
||||||
# row = cursor.fetchone()
|
|
||||||
# invoice_id = row[0] if row else None
|
|
||||||
|
|
||||||
# # insert invoice if not exists
|
|
||||||
|
|
||||||
# if not invoice_id:
|
|
||||||
print(" extra payment :", PMC_No,Total_Amount,UTR, subcontractor_id)
|
print(" extra payment :", PMC_No,Total_Amount,UTR, subcontractor_id)
|
||||||
|
|
||||||
# cursor.execute(
|
|
||||||
# """
|
|
||||||
# INSERT INTO invoice (PMC_No,Contractor_Id) VALUES (%s, %s);
|
|
||||||
# """,
|
|
||||||
# (PMC_No, subcontractor_id)
|
|
||||||
# )
|
|
||||||
# connection.commit()
|
|
||||||
|
|
||||||
# cursor.execute(
|
|
||||||
# "SELECT invoice_id FROM invoice WHERE PMC_No=%s AND Contractor_Id =%s ORDER BY invoice_id DESC LIMIT 1",
|
|
||||||
# (PMC_No, subcontractor_id)
|
|
||||||
# )
|
|
||||||
# row = cursor.fetchone()
|
|
||||||
cursor.callproc("insertExtrapaymet",(PMC_No, subcontractor_id))
|
cursor.callproc("insertExtrapaymet",(PMC_No, subcontractor_id))
|
||||||
for result in cursor.stored_results():
|
for result in cursor.stored_results():
|
||||||
row = result.fetchone()
|
row = result.fetchone()
|
||||||
@@ -403,39 +365,6 @@ def save_data():
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# if PMC_No and Total_Amount and UTR:
|
|
||||||
# print("Payment :", PMC_No, Invoice_No, Payment_Amount, TDS_Payment_Amount, Total_Amount, UTR )
|
|
||||||
|
|
||||||
# Add inoice id in payment table
|
|
||||||
# cursor.callproc("SavePayment",(PMC_No, Invoice_No, Payment_Amount, TDS_Payment_Amount, Total_Amount, UTR, invoice_id))
|
|
||||||
|
|
||||||
# if not village_id:
|
|
||||||
# village_id = None
|
|
||||||
# cursor.callproc('InsertOrUpdateInPayment', (
|
|
||||||
# PMC_No,
|
|
||||||
# village_id,
|
|
||||||
# work_type,
|
|
||||||
# Invoice_Details,
|
|
||||||
# Invoice_Date,
|
|
||||||
# Invoice_No,
|
|
||||||
# Basic_Amount,
|
|
||||||
# Debit_Amount,
|
|
||||||
# After_Debit_Amount,
|
|
||||||
# Amount,
|
|
||||||
# GST_Amount,
|
|
||||||
# TDS_Amount,
|
|
||||||
# SD_Amount,
|
|
||||||
# On_Commission,
|
|
||||||
# Hydro_Testing,
|
|
||||||
# 0,
|
|
||||||
# GST_SD_Amount,
|
|
||||||
# Final_Amount,
|
|
||||||
# Payment_Amount,
|
|
||||||
# TDS_Payment_Amount,
|
|
||||||
# Total_Amount,
|
|
||||||
# UTR,f
|
|
||||||
# subcontractor_id
|
|
||||||
# ))
|
|
||||||
connection.commit()
|
connection.commit()
|
||||||
return jsonify({"success": "Data saved successfully!"}), 200
|
return jsonify({"success": "Data saved successfully!"}), 200
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -38,9 +38,6 @@ def add_invoice():
|
|||||||
village_id = village_result['Village_Id']
|
village_id = village_result['Village_Id']
|
||||||
invoice_id = insert_invoice(data, village_id)
|
invoice_id = insert_invoice(data, village_id)
|
||||||
# assign_subcontractor(data, village_id)
|
# assign_subcontractor(data, village_id)
|
||||||
print("********************************************************************")
|
|
||||||
print("Manully added invoice id :",invoice_id)
|
|
||||||
print("********************************************************************")
|
|
||||||
|
|
||||||
insert_hold_types(data, invoice_id)
|
insert_hold_types(data, invoice_id)
|
||||||
|
|
||||||
|
|||||||
@@ -71,14 +71,6 @@ def edit_payment(payment_id):
|
|||||||
LogHelper.log_action("Edit Payment", f"User {current_user.id} Edit Payment '{pmc_no}'")
|
LogHelper.log_action("Edit Payment", f"User {current_user.id} Edit Payment '{pmc_no}'")
|
||||||
Paymentmodel.call_update_payment_proc(payment_id, pmc_no, invoice_no, amount, tds_amount, total_amount, utr)
|
Paymentmodel.call_update_payment_proc(payment_id, pmc_no, invoice_no, amount, tds_amount, total_amount, utr)
|
||||||
|
|
||||||
# Update inpayment
|
|
||||||
# connection = Paymentmodel.get_connection()
|
|
||||||
# cursor = connection.cursor()
|
|
||||||
# cursor.callproc('UpdateInpaymentByPMCInvoiceUTR',[amount, tds_amount, total_amount, pmc_no, invoice_no, utr])
|
|
||||||
|
|
||||||
# connection.commit()
|
|
||||||
# cursor.close()
|
|
||||||
# connection.close()
|
|
||||||
|
|
||||||
return redirect(url_for('payment_bp.add_payment'))
|
return redirect(url_for('payment_bp.add_payment'))
|
||||||
|
|
||||||
|
|||||||
@@ -46,11 +46,6 @@ def contractor_report(contractor_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# # ---------------- Contractor Download Report by contractor id ----------------
|
# # ---------------- Contractor Download Report by contractor id ----------------
|
||||||
# @report_bp.route('/download_report/<int:contractor_id>')
|
|
||||||
# @login_required
|
|
||||||
# def download_report(contractor_id):
|
|
||||||
|
|
||||||
# return ReportHelper().download_report(contractor_id=contractor_id)
|
|
||||||
|
|
||||||
@report_bp.route('/download_report/<int:contractor_id>')
|
@report_bp.route('/download_report/<int:contractor_id>')
|
||||||
def download_report(contractor_id):
|
def download_report(contractor_id):
|
||||||
|
|||||||
@@ -70,22 +70,7 @@ def get_all_villages():
|
|||||||
# ------------------- Invoice Functions -------------------
|
# ------------------- Invoice Functions -------------------
|
||||||
def insert_invoice(data, village_id):
|
def insert_invoice(data, village_id):
|
||||||
def operation(cursor):
|
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', [
|
cursor.callproc('SaveInvoice', [
|
||||||
data.get('pmc_no'),
|
data.get('pmc_no'),
|
||||||
village_id,
|
village_id,
|
||||||
@@ -103,18 +88,6 @@ def insert_invoice(data, village_id):
|
|||||||
if row:
|
if row:
|
||||||
invoice_id = row['invoice_id']
|
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 invoice_id
|
||||||
|
|
||||||
return execute_db_operation(operation)
|
return execute_db_operation(operation)
|
||||||
@@ -159,18 +132,6 @@ def update_invoice(data, invoice_id):
|
|||||||
clear_results(cursor)
|
clear_results(cursor)
|
||||||
execute_db_operation(operation)
|
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 delete_invoice_data(invoice_id, user_id):
|
||||||
def operation(cursor):
|
def operation(cursor):
|
||||||
@@ -190,24 +151,10 @@ def delete_invoice_data(invoice_id, user_id):
|
|||||||
cursor.callproc("DeleteInvoice", (invoice_id,))
|
cursor.callproc("DeleteInvoice", (invoice_id,))
|
||||||
clear_results(cursor)
|
clear_results(cursor)
|
||||||
|
|
||||||
# Delete inpayment
|
|
||||||
# cursor.callproc('DeleteInpaymentByPMCInvoice', (pmc_no, invoice_no))
|
|
||||||
# clear_results(cursor)
|
|
||||||
|
|
||||||
execute_db_operation(operation)
|
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 -------------------
|
# ------------------- Hold Types Functions -------------------
|
||||||
def insert_hold_types(data, invoice_id):
|
def insert_hold_types(data, invoice_id):
|
||||||
|
|||||||
@@ -29,18 +29,6 @@ class PmcReport:
|
|||||||
|
|
||||||
invoices = []
|
invoices = []
|
||||||
hold_amount_total = 0
|
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))
|
hold_type_ids_str = ",".join(map(str, hold_type_ids))
|
||||||
cursor.callproc(
|
cursor.callproc(
|
||||||
'GetInvoices_WithHold',
|
'GetInvoices_WithHold',
|
||||||
@@ -148,10 +136,6 @@ class PmcReport:
|
|||||||
)
|
)
|
||||||
credit_note_map = {}
|
credit_note_map = {}
|
||||||
for cn in credit_notes:
|
for cn in credit_notes:
|
||||||
# key = (
|
|
||||||
# str(cn['PMC_No']).strip(),
|
|
||||||
# str(cn['Invoice_No']).replace(" ", "") if cn['Invoice_No'] else ""
|
|
||||||
# )
|
|
||||||
key = (
|
key = (
|
||||||
str(cn['PMC_No']).strip()
|
str(cn['PMC_No']).strip()
|
||||||
)
|
)
|
||||||
@@ -167,10 +151,7 @@ class PmcReport:
|
|||||||
)
|
)
|
||||||
gst_release_map = {}
|
gst_release_map = {}
|
||||||
for gr in gst_releases:
|
for gr in gst_releases:
|
||||||
# key = (
|
|
||||||
# str(gr['PMC_No']).strip(),
|
|
||||||
# str(gr['Invoice_No']).replace(" ", "") if gr['Invoice_No'] else ""
|
|
||||||
# )
|
|
||||||
key = (
|
key = (
|
||||||
str(gr['PMC_No']).strip()
|
str(gr['PMC_No']).strip()
|
||||||
)
|
)
|
||||||
@@ -181,17 +162,6 @@ class PmcReport:
|
|||||||
for h in hold_amounts:
|
for h in hold_amounts:
|
||||||
hold_data.setdefault(h['Invoice_Id'], {})[h['hold_type_id']] = h['hold_amount']
|
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 =================
|
# ================= LOG =================
|
||||||
LogHelper.log_action(
|
LogHelper.log_action(
|
||||||
@@ -199,126 +169,11 @@ class PmcReport:
|
|||||||
f"User {current_user.id} Download PMC Report '{pmc_no}'"
|
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(
|
ReportHelper.generate_excel(
|
||||||
0, contractor_info, invoices, hold_types, hold_data,
|
0, contractor_info, invoices, hold_types, hold_data,
|
||||||
credit_note_map,gst_release_map, output_file
|
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
|
return output_folder, filename
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -154,9 +154,6 @@ class ReportHelper:
|
|||||||
contractor = ContractorInfo(contractor_id)
|
contractor = ContractorInfo(contractor_id)
|
||||||
return contractor.contInfo if contractor.contInfo else None
|
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
|
@staticmethod
|
||||||
def generate_excel(contractor_id, contInfo, invoices, hold_types, hold_data,
|
def generate_excel(contractor_id, contInfo, invoices, hold_types, hold_data,
|
||||||
credit_note_map, gst_release_map, output_file):
|
credit_note_map, gst_release_map, output_file):
|
||||||
@@ -249,22 +246,6 @@ class ReportHelper:
|
|||||||
|
|
||||||
sheet.append(row)
|
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
|
# GST Releases
|
||||||
if key in gst_release_map and key not in processed_gst_releases:
|
if key in gst_release_map and key not in processed_gst_releases:
|
||||||
for gr in gst_release_map[key]:
|
for gr in gst_release_map[key]:
|
||||||
@@ -321,11 +302,8 @@ class ReportHelper:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_contractor_report(contractor_id):
|
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, )
|
|
||||||
|
|
||||||
|
fileName=f"Contractor_Report_{contractor_id}.xlsx"
|
||||||
output_file = FolderAndFile.get_download_path(filename=fileName)
|
output_file = FolderAndFile.get_download_path(filename=fileName)
|
||||||
|
|
||||||
# Fetch Data
|
# Fetch Data
|
||||||
@@ -342,21 +320,12 @@ class ReportHelper:
|
|||||||
hold_data = {}
|
hold_data = {}
|
||||||
for h in hold_amounts:
|
for h in hold_amounts:
|
||||||
hold_data.setdefault(h['Invoice_Id'], {})[h['hold_type_id']] = h['hold_amount']
|
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 MAP --------
|
||||||
credit_note_raw = ReportHelper.execute_sp(cursor, 'GetCreditNotesByContractor', [contractor_id])
|
credit_note_raw = ReportHelper.execute_sp(cursor, 'GetCreditNotesByContractor', [contractor_id])
|
||||||
credit_note_map = {}
|
credit_note_map = {}
|
||||||
for cn in credit_note_raw:
|
for cn in credit_note_raw:
|
||||||
# key = (
|
|
||||||
# str(cn['PMC_No']).strip(),
|
|
||||||
# str(cn['Invoice_No']).replace(" ", "") if cn['Invoice_No'] else ""
|
|
||||||
# )
|
|
||||||
key = (
|
key = (
|
||||||
str(cn['PMC_No']).strip()
|
str(cn['PMC_No']).strip()
|
||||||
)
|
)
|
||||||
@@ -366,21 +335,11 @@ class ReportHelper:
|
|||||||
gst_release_raw = ReportHelper.execute_sp(cursor, 'GstReleasesByContractorId', [contractor_id])
|
gst_release_raw = ReportHelper.execute_sp(cursor, 'GstReleasesByContractorId', [contractor_id])
|
||||||
gst_release_map = {}
|
gst_release_map = {}
|
||||||
for gr in gst_release_raw:
|
for gr in gst_release_raw:
|
||||||
# key = (
|
|
||||||
# str(gr['PMC_No']).strip(),
|
|
||||||
# str(gr['Invoice_No']).replace(" ", "") if gr['Invoice_No'] else ""
|
|
||||||
# )
|
|
||||||
key = (
|
key = (
|
||||||
str(gr['PMC_No']).strip()
|
str(gr['PMC_No']).strip()
|
||||||
)
|
)
|
||||||
gst_release_map.setdefault(key, []).append(gr)
|
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(
|
ReportHelper.generate_excel(
|
||||||
contractor_id, contInfo, invoices, hold_types, hold_data,
|
contractor_id, contInfo, invoices, hold_types, hold_data,
|
||||||
credit_note_map, gst_release_map, output_file
|
credit_note_map, gst_release_map, output_file
|
||||||
|
|||||||
@@ -72,24 +72,6 @@ class Paymentmodel:
|
|||||||
if connection:
|
if connection:
|
||||||
connection.close()
|
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
|
@staticmethod
|
||||||
def fetch_payment_by_id(payment_id):
|
def fetch_payment_by_id(payment_id):
|
||||||
@@ -155,9 +137,7 @@ class Paymentmodel:
|
|||||||
# Delete payment
|
# Delete payment
|
||||||
cursor.callproc("DeletePayment", (payment_id,))
|
cursor.callproc("DeletePayment", (payment_id,))
|
||||||
connection.commit()
|
connection.commit()
|
||||||
# Reset inpayment fields
|
|
||||||
# cursor.callproc("ResetInpayment", [pmc_no, invoice_no])
|
|
||||||
# connection.commit()
|
|
||||||
return True, pmc_no, invoice_no
|
return True, pmc_no, invoice_no
|
||||||
except mysql.connector.Error as e:
|
except mysql.connector.Error as e:
|
||||||
print(f"Error deleting payment: {e}")
|
print(f"Error deleting payment: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user