Initial commit

This commit is contained in:
Swapnil9693
2025-11-26 14:28:15 +05:30
parent 3a2a22bf99
commit 1054d1f7e5
3 changed files with 18 additions and 990 deletions

49
main.py
View File

@@ -568,8 +568,7 @@ def edit_district(district_id):
# Retrieve all states for dropdown
try:
# cursor.execute("SELECT State_ID, State_Name FROM states")
# states = cursor.fetchall()
cursor.callproc("GetAllStates")
for res in cursor.stored_results():
states = res.fetchall()
@@ -580,8 +579,7 @@ def edit_district(district_id):
# Retrieve district info
try:
# cursor.execute("SELECT District_Name, State_Id FROM districts WHERE District_id = %s", (district_id,))
# districtdata = cursor.fetchone()
cursor.callproc("GetDistrictDataByID", (district_id,))
for rs in cursor.stored_results():
districtdata = rs.fetchone()
@@ -596,8 +594,7 @@ def edit_district(district_id):
state_id = request.form['state_Id']
try:
# cursor.execute( "UPDATE districts SET District_Name = %s, State_Id = %s WHERE District_id = %s",
# (district_name, state_id, district_id) )
cursor.callproc("UpdateDistrict", (district_id, state_id, district_name,))
connection.commit()
@@ -622,8 +619,7 @@ def add_block():
if connection:
cursor = connection.cursor()
try:
# cursor.execute("SELECT State_ID, State_Name FROM states")
# states = cursor.fetchall()
cursor.callproc("GetAllStates")
for res in cursor.stored_results():
states = res.fetchall()
@@ -640,9 +636,7 @@ def add_block():
return json_response(ResponseHandler.invalid_name("block"), 400)
try:
# cursor.execute("SELECT * FROM blocks WHERE Block_Name = %s AND District_id = %s",
# (block_name, district_id))
# existing_block = cursor.fetchone()
cursor.callproc("GetBlockByNameAndDistrict", (block_name, district_id,))
for rs in cursor.stored_results():
existing_block = rs.fetchone()
@@ -766,7 +760,7 @@ def delete_block(block_id):
if connection:
cursor = connection.cursor()
try:
# cursor.execute("DELETE FROM blocks WHERE Block_Id = %s", (block_id,))
cursor.callproc("DeleteBlock", (block_id,))
log_action("Delete Block", f"User {current_user.id} Deleted block '{block_id}'")
connection.commit()
@@ -906,8 +900,7 @@ def check_village():
if not block_id or not village_name:
return json_response({'status': 'error', 'message': 'Block and Village Name are required!'}, 400)
# cursor.execute("SELECT * FROM villages WHERE Village_Name = %s AND Block_Id = %s", (village_name, block_id))
# existing_village = cursor.fetchone()
cursor.callproc("GetVillageByNameAndBlocks", (village_name, block_id))
for rs in cursor.stored_results():
existing_village = rs.fetchone()
@@ -975,11 +968,11 @@ def delete_village(village_id):
cursor = connection.cursor()
try:
# cursor.execute("DELETE FROM villages WHERE Village_Id = %s", (village_id,))
cursor.callproc("DeleteVillage", (village_id,))
log_action("Delete villages", f"User {current_user.id} Deletedvillages '{village_id}'")
connection.commit()
# return json_response(ResponseHandler.delete_success("village"), 200)
except mysql.connector.Error as e:
print(f"Error: {e}")
return json_response(ResponseHandler.add_failure("village"), 500)
@@ -1074,8 +1067,7 @@ def add_invoice():
hold_count = 0
for hold_type, hold_amount in zip(hold_types, hold_amounts):
# cursor.execute("SELECT hold_type_id FROM hold_types WHERE hold_type = %s", (hold_type,))
# hold_type_result = cursor.fetchone()
cursor.callproc('GetHoldTypeIdByName', [hold_type])
for result in cursor.stored_results():
hold_type_result = result.fetchone()
@@ -1175,7 +1167,7 @@ def get_hold_types():
return jsonify(hold_types)
except mysql.connector.Error as e:
return ResponseHandler.fetch_failure({str(e)}), 500
# return jsonify({"status": "error", "message": f"Failed to fetch hold types: {str(e)}"}), 500
finally:
cursor.close()
connection.close()
@@ -1334,7 +1326,7 @@ def delete_invoice(invoice_id):
try:
cursor = connection.cursor()
# cursor.execute("DELETE FROM invoice WHERE Invoice_Id = %s", (invoice_id,))
cursor.callproc("DeleteInvoice", (invoice_id,))
log_action("Delete invoice", f"User {current_user.id} Delete invoice'{ invoice_id}'")
@@ -2118,8 +2110,7 @@ def save_data():
SD_Amount, On_Commission, Hydro_Testing, GST_SD_Amount, Final_Amount,
subcontractor_id, 0
)
# for result in cursor.stored_results():
# invoice_id = result.fetchone()['invoice_id']
print("All invoice Details ",args)
results = cursor.callproc('SaveInvoice', args)
@@ -2207,7 +2198,7 @@ def save_data():
elif Invoice_Details and any(
keyword in Invoice_Details.lower() for keyword in ['gst', 'release', 'note']):
print("Gst rels :", PMC_No, Invoice_No, Basic_Amount, Final_Amount,Total_Amount,UTR, subcontractor_id)
#cursor.callproc("SaveGSTRelease", (PMC_No, Invoice_No, Basic_Amount, Final_Amount,Total_Amount,UTR))
cursor.execute(
"""INSERT INTO gst_release (PMC_No, Invoice_No, Basic_Amount, Final_Amount,Total_Amount,UTR, Contractor_Id) VALUES (%s,%s, %s, %s, %s, %s, %s)""",
(PMC_No, Invoice_No, Basic_Amount, Final_Amount, Total_Amount, UTR, subcontractor_id))
@@ -2223,7 +2214,7 @@ def save_data():
connection.commit()
return jsonify({"success": "Data saved successfully!"}), 200
# return render_template('uploadExcelFile.html')
except Exception as e:
connection.rollback()
return jsonify({"error": f"An unexpected error occurred: {e}"}), 500
@@ -2865,10 +2856,7 @@ def pmc_report(pmc_no):
ORDER BY invoice_no ASC
""", (pmc_no,))
payments = cursor.fetchall()
# cursor.callproc('GetPaymentByPMC', [pmc_no])
#
# for result in cursor.stored_results():
# payments = result.fetchall()
total_pay_amount = sum(row.get('Payment_Amount', 0) or 0 for row in payments)
total_pay_total = sum(row.get('Total_amount', 0) or 0 for row in payments)
@@ -3319,8 +3307,7 @@ def delete_hold_type(id):
cursor = connection.cursor()
try:
# cursor.execute("SELECT * FROM hold_types WHERE hold_type_id = %s", (id,))
# hold_type = cursor.fetchone()
cursor.callproc("GetHoldTypesById", (id,))
for hold in cursor.stored_results():
hold_type = hold.fetchone()
@@ -3329,7 +3316,7 @@ def delete_hold_type(id):
return jsonify({'status': 'error', 'message': 'Hold Type not found.'}), 404
# Proceed with deletion
# cursor.execute("DELETE FROM hold_types WHERE hold_type_id = %s", (id,))
cursor.callproc("DeleteHoldType", (id,))
connection.commit()
return jsonify(ResponseHandler.delete_success('Hold Type'))