updated code by aakash
This commit is contained in:
@@ -6,7 +6,6 @@ from model.Log import LogHelper
|
||||
|
||||
auth_bp = Blueprint('auth', __name__)
|
||||
|
||||
|
||||
@auth_bp.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
|
||||
|
||||
@@ -152,19 +152,17 @@ def show_table(filename):
|
||||
)
|
||||
|
||||
|
||||
# save Excel data
|
||||
# save Excel data
|
||||
@excel_bp.route('/save_data', methods=['POST'])
|
||||
def save_data():
|
||||
# Extract form data
|
||||
subcontractor_id = request.form.get("subcontractor_data")
|
||||
state_id = request.form.get("state_data")
|
||||
district_id = request.form.get("district_data")
|
||||
block_id = request.form.get("block_data")
|
||||
variables = request.form.getlist('variables[]')
|
||||
hold_columns = request.form.get("hold_columns")
|
||||
hold_counter = request.form.get("hold_counter")
|
||||
|
||||
if not data:
|
||||
return jsonify({"error": "No data provided to save"}), 400
|
||||
|
||||
if data:
|
||||
connection = config.get_db_connection()
|
||||
cursor = connection.cursor()
|
||||
@@ -174,7 +172,7 @@ def save_data():
|
||||
"PMC_No": entry.get("PMC_No"),
|
||||
"Invoice_Details": entry.get("Invoice_Details", ''),
|
||||
"Work_Type": 'none',
|
||||
"Invoice_Date": entry.get("Invoice_Date").strftime('%Y-%m-%d') if entry.get(
|
||||
"In oice_Date": entry.get("Invoice_Date").strftime('%Y-%m-%d') if entry.get(
|
||||
"Invoice_Date") else None,
|
||||
"Invoice_No": entry.get("Invoice_No", ''),
|
||||
"Basic_Amount": entry.get("Basic_Amount", 0.00),
|
||||
@@ -229,7 +227,6 @@ def save_data():
|
||||
else:
|
||||
work_type = " ".join(words[:work_pos + 1])
|
||||
if Invoice_Details and 'village' in Invoice_Details.lower() and 'work' in Invoice_Details.lower():
|
||||
print("village_name ::", village_name, "|| work_type ::", work_type)
|
||||
if block_id and village_name:
|
||||
village_id = None
|
||||
cursor.callproc("GetVillageId", (block_id, village_name))
|
||||
@@ -242,12 +239,7 @@ def save_data():
|
||||
for result in cursor.stored_results():
|
||||
result = result.fetchone()
|
||||
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 = (
|
||||
PMC_No, village_id, work_type, Invoice_Details, Invoice_Date, Invoice_No,
|
||||
Basic_Amount, Debit_Amount, After_Debit_Amount, Amount, GST_Amount, TDS_Amount,
|
||||
@@ -255,22 +247,24 @@ def save_data():
|
||||
subcontractor_id, 0
|
||||
)
|
||||
|
||||
print("All invoice Details ",args)
|
||||
results = cursor.callproc('SaveInvoice', args)
|
||||
invoice_id = results[-1]
|
||||
print("invoice id from the excel ", invoice_id)
|
||||
|
||||
|
||||
cursor.callproc("SavePayment",( PMC_No, Invoice_No, Payment_Amount, TDS_Payment_Amount,Total_Amount, UTR,invoice_id))
|
||||
|
||||
if isinstance(hold_columns, str):
|
||||
hold_columns = ast.literal_eval(hold_columns)
|
||||
if isinstance(hold_columns, list) and all(isinstance(hold, dict) for hold in hold_columns):
|
||||
for hold in hold_columns:
|
||||
print(f"Processing hold: {hold}")
|
||||
hold_column_name = hold.get('column_name') # Get column name
|
||||
hold_type_id = hold.get('hold_type_id') # Get hold_type_id
|
||||
|
||||
hold_column_name = hold.get('column_name')
|
||||
hold_type_id = hold.get('hold_type_id')
|
||||
if hold_column_name:
|
||||
hold_amount = entry.get(
|
||||
hold_column_name) # Get the value for that specific hold column
|
||||
hold_column_name)
|
||||
if hold_amount is not None:
|
||||
print(f"Processing hold type: {hold_column_name}, Hold Amount: {hold_amount}")
|
||||
|
||||
hold_join_data = {
|
||||
"Contractor_Id": subcontractor_id,
|
||||
"Invoice_Id": invoice_id,
|
||||
@@ -287,10 +281,9 @@ def save_data():
|
||||
print(f"Invalid hold entry: {hold}")
|
||||
else:
|
||||
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']):
|
||||
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(
|
||||
'AddCreditNoteFromExcel',
|
||||
[
|
||||
@@ -299,7 +292,7 @@ def save_data():
|
||||
subcontractor_id, Invoice_No
|
||||
]
|
||||
)
|
||||
#-----------------------------------------------Hold Amount----------------------------------------------------------------------
|
||||
#--------------------------Hold Amount-------------------------------------------------
|
||||
# Step 1: Normalize Invoice_Details: lowercase, trim, remove extra spaces
|
||||
normalized_details = re.sub(r'\s+', ' ', Invoice_Details.strip()).lower()
|
||||
# Step 2: Define lowercase keywords
|
||||
@@ -315,52 +308,57 @@ def save_data():
|
||||
]
|
||||
# Step 3: Matching condition
|
||||
if any(kw in normalized_details for kw in keywords):
|
||||
print("✅ Match found. Inserting hold release for:", Invoice_Details)
|
||||
# print(" Match found. Inserting hold release for:", Invoice_Details)
|
||||
cursor.callproc(
|
||||
'AddHoldReleaseFromExcel',
|
||||
[PMC_No, Invoice_No, Invoice_Details, Basic_Amount, Final_Amount, UTR, subcontractor_id]
|
||||
)
|
||||
connection.commit()
|
||||
print("✅ Hold release inserted for:", PMC_No, Invoice_Details)
|
||||
# print(" Hold release inserted for:", PMC_No, Invoice_Details)
|
||||
#------------------------------------------------------------------------------------------------------------------
|
||||
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)
|
||||
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(
|
||||
'AddGSTReleaseFromExcel',
|
||||
[PMC_No, Invoice_No, Basic_Amount, Final_Amount, Total_Amount, UTR, subcontractor_id]
|
||||
)
|
||||
|
||||
if PMC_No and Total_Amount and UTR:
|
||||
print("Payment :", PMC_No, Invoice_No, Payment_Amount, TDS_Payment_Amount, Total_Amount, UTR )
|
||||
cursor.callproc("SavePayment",(PMC_No, Invoice_No, Payment_Amount, TDS_Payment_Amount, Total_Amount, UTR ))
|
||||
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,
|
||||
subcontractor_id
|
||||
))
|
||||
# --------------------------------------
|
||||
# If no village/work detected, only PMC/Payment
|
||||
if not (Invoice_Details and 'village' in Invoice_Details.lower() and 'work' in Invoice_Details.lower()):
|
||||
# ---------- Only PMC / Payment rows ----------
|
||||
if PMC_No and not Invoice_No and UTR :
|
||||
|
||||
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()
|
||||
invoice_id = row[0] if row else None
|
||||
|
||||
# insert payment
|
||||
cursor.callproc(
|
||||
"SavePayment",
|
||||
(
|
||||
PMC_No,
|
||||
Invoice_No,
|
||||
Payment_Amount,
|
||||
TDS_Payment_Amount,
|
||||
Total_Amount,
|
||||
UTR,
|
||||
invoice_id
|
||||
)
|
||||
)
|
||||
|
||||
connection.commit()
|
||||
return jsonify({"success": "Data saved successfully!"}), 200
|
||||
except Exception as e:
|
||||
@@ -370,4 +368,3 @@ def save_data():
|
||||
cursor.close()
|
||||
connection.close()
|
||||
return render_template('index.html')
|
||||
# ---------------------- Report --------------------------------
|
||||
@@ -1,10 +1,10 @@
|
||||
# routes/gst_release_routes.py
|
||||
from flask import Blueprint, render_template, request, redirect, url_for, flash
|
||||
from flask_login import login_required
|
||||
from model.gst_release import GSTRelease
|
||||
from model.Log import LogHelper
|
||||
|
||||
gst_release_bp = Blueprint('gst_release_bp', __name__)
|
||||
|
||||
gst_service = GSTRelease()
|
||||
|
||||
# ---------------- ADD GST RELEASE ----------------
|
||||
|
||||
@@ -14,7 +14,7 @@ def add_hold_type():
|
||||
|
||||
if request.method == 'POST':
|
||||
hold.AddHoldType(request)
|
||||
# ✅ Always redirect to same page (NO JSON)
|
||||
# Always redirect to same page (NO JSON)
|
||||
return redirect(url_for("hold_types.add_hold_type"))
|
||||
|
||||
# GET request → show data
|
||||
@@ -42,10 +42,10 @@ def edit_hold_type(id):
|
||||
hold = HoldTypes()
|
||||
|
||||
if request.method == 'POST':
|
||||
hold.EditHoldType(request, id) # ✅
|
||||
hold.EditHoldType(request, id)
|
||||
return hold.resultMessage
|
||||
|
||||
hold_data = hold.GetHoldTypeByID(id) # ✅
|
||||
hold_data = hold.GetHoldTypeByID(id)
|
||||
|
||||
return render_template(
|
||||
"edit_hold_type.html",
|
||||
@@ -59,7 +59,7 @@ def edit_hold_type(id):
|
||||
def delete_hold_type(id):
|
||||
|
||||
hold = HoldTypes()
|
||||
hold.DeleteHoldType(request, id) # ✅
|
||||
hold.DeleteHoldType(request, id)
|
||||
|
||||
return redirect(url_for("hold_types.add_hold_type"))
|
||||
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
|
||||
|
||||
|
||||
# controllers/invoice_controller.py
|
||||
|
||||
from flask import Blueprint, request, jsonify, render_template
|
||||
from flask_login import login_required, current_user
|
||||
from model.Invoice import *
|
||||
@@ -83,7 +78,6 @@ def edit_invoice(invoice_id):
|
||||
if request.method == 'POST':
|
||||
data = request.form
|
||||
update_invoice(data, invoice_id)
|
||||
update_inpayment(data)
|
||||
log_action("Edit invoice", f"edited invoice '{invoice_id}'")
|
||||
return jsonify({"status": "success", "message": "Invoice updated successfully"}), 200
|
||||
|
||||
|
||||
@@ -28,8 +28,7 @@ def add_payment():
|
||||
utr = request.form['utr']
|
||||
|
||||
LogHelper.log_action("Add Payment", f"User {current_user.id} Add Payment '{pmc_no}'")
|
||||
Paymentmodel.insert_payment(pmc_no, invoice_no, amount, tds_amount, total_amount, utr)
|
||||
Paymentmodel.update_inpayment(subcontractor_id, pmc_no, invoice_no, amount, tds_amount, total_amount, utr)
|
||||
Paymentmodel.insert_payment(subcontractor_id,pmc_no, invoice_no, amount, tds_amount, total_amount, utr)
|
||||
|
||||
return redirect(url_for('payment_bp.add_payment'))
|
||||
|
||||
@@ -71,7 +70,6 @@ def edit_payment(payment_id):
|
||||
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)
|
||||
|
||||
# Update inpayment
|
||||
connection = Paymentmodel.get_connection()
|
||||
cursor = connection.cursor()
|
||||
cursor.callproc(
|
||||
|
||||
@@ -37,4 +37,5 @@ def download_pmc_report(pmc_no):
|
||||
|
||||
output_folder, file_name = result
|
||||
|
||||
return send_from_directory(output_folder, file_name, as_attachment=True)
|
||||
return send_from_directory(output_folder, file_name, as_attachment=True)
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
from flask import Blueprint, render_template, request, jsonify
|
||||
from flask import Blueprint, render_template, request, jsonify,send_file
|
||||
from flask_login import login_required, current_user
|
||||
|
||||
from model.Report import ReportHelper
|
||||
from model.Log import LogHelper
|
||||
|
||||
|
||||
report_bp = Blueprint("report", __name__)
|
||||
|
||||
|
||||
@@ -46,8 +45,10 @@ def contractor_report(contractor_id):
|
||||
|
||||
# ---------------- Contractor Download Report by contractor id ----------------
|
||||
@report_bp.route('/download_report/<int:contractor_id>')
|
||||
@login_required
|
||||
def download_report(contractor_id):
|
||||
output_file, error = ReportHelper.create_contractor_report(contractor_id)
|
||||
|
||||
if error:
|
||||
return error, 404
|
||||
|
||||
return ReportHelper().download_report(contractor_id=contractor_id)
|
||||
|
||||
return send_file(output_file, as_attachment=True)
|
||||
@@ -3,17 +3,12 @@ from flask_login import login_required
|
||||
from model.Subcontractor import Subcontractor
|
||||
from model.Utilities import HtmlHelper, ResponseHandler
|
||||
|
||||
|
||||
subcontractor_bp = Blueprint('subcontractor', __name__)
|
||||
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# LIST + ADD
|
||||
# ----------------------------------------------------------
|
||||
@subcontractor_bp.route('/subcontractor', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def subcontract():
|
||||
|
||||
sub = Subcontractor()
|
||||
|
||||
# ---------------- GET ----------------
|
||||
@@ -31,27 +26,22 @@ def subcontract():
|
||||
if request.method == 'POST':
|
||||
|
||||
sub.AddSubcontractor(request)
|
||||
|
||||
if not sub.isSuccess:
|
||||
return HtmlHelper.json_response(
|
||||
ResponseHandler.add_failure("Subcontractor"), 500
|
||||
)
|
||||
|
||||
# Reload list after insert
|
||||
subcontractor = sub.GetAllSubcontractors(request)
|
||||
|
||||
return render_template('add_subcontractor.html', subcontractor=subcontractor)
|
||||
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# EDIT
|
||||
# ----------------------------------------------------------
|
||||
@subcontractor_bp.route('/edit_subcontractor/<int:id>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def edit_subcontractor(id):
|
||||
|
||||
sub = Subcontractor()
|
||||
|
||||
# Fetch data
|
||||
subcontractor = sub.GetSubcontractorByID(id)
|
||||
|
||||
@@ -75,9 +65,7 @@ def edit_subcontractor(id):
|
||||
return render_template('edit_subcontractor.html', subcontractor=subcontractor)
|
||||
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# DELETE
|
||||
# ----------------------------------------------------------
|
||||
@subcontractor_bp.route('/deleteSubContractor/<int:id>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def deleteSubContractor(id):
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
|
||||
|
||||
|
||||
|
||||
from flask import Blueprint, render_template, request, redirect, url_for, flash, jsonify
|
||||
from flask_login import login_required
|
||||
|
||||
@@ -89,15 +85,14 @@ def delete_village(village_id):
|
||||
village = Village()
|
||||
village.DeleteVillage(request=request, village_id=village_id)
|
||||
|
||||
# ✅ Convert resultMessage to string if it's a Response or tuple
|
||||
# Convert resultMessage to string if it's a Response or tuple
|
||||
raw_msg = village.resultMessage
|
||||
|
||||
if isinstance(raw_msg, tuple):
|
||||
# e.g., (<Response ...>, 200)
|
||||
msg = "Village deleted successfully!"
|
||||
elif hasattr(raw_msg, 'get_data'):
|
||||
# Flask Response object
|
||||
msg = raw_msg.get_data(as_text=True) # get raw text
|
||||
msg = raw_msg.get_data(as_text=True)
|
||||
else:
|
||||
# fallback
|
||||
msg = str(raw_msg) if raw_msg else "Village deleted successfully!"
|
||||
@@ -135,7 +130,6 @@ def edit_village(village_id):
|
||||
)
|
||||
|
||||
else:
|
||||
# ✅ FIXED HERE (removed request)
|
||||
village_data = village.GetVillageByID(id=village_id)
|
||||
|
||||
if not village.isSuccess:
|
||||
|
||||
Reference in New Issue
Block a user