updated code of prajakta block,payment, gst
This commit is contained in:
102
model/payment.py
102
model/payment.py
@@ -1,8 +1,13 @@
|
||||
import config
|
||||
import mysql.connector
|
||||
import config
|
||||
import mysql.connector
|
||||
from enum import Enum
|
||||
from model.Utilities import ItemCRUDType
|
||||
|
||||
class Paymentmodel:
|
||||
|
||||
# ---------------- Database Connection ----------------
|
||||
@staticmethod
|
||||
def get_connection():
|
||||
connection = config.get_db_connection()
|
||||
@@ -10,6 +15,7 @@ class Paymentmodel:
|
||||
return None
|
||||
return connection
|
||||
|
||||
# ---------------- Payment Methods ----------------
|
||||
@staticmethod
|
||||
def fetch_all_payments():
|
||||
connection = Paymentmodel.get_connection()
|
||||
@@ -52,14 +58,8 @@ class Paymentmodel:
|
||||
try:
|
||||
cursor = connection.cursor()
|
||||
cursor.callproc('UpdateInpaymentRecord', [
|
||||
subcontractor_id,
|
||||
pmc_no,
|
||||
invoice_no,
|
||||
amount,
|
||||
tds_amount,
|
||||
total_amount,
|
||||
utr
|
||||
])
|
||||
subcontractor_id, pmc_no, invoice_no, amount, tds_amount, total_amount, utr
|
||||
])
|
||||
connection.commit()
|
||||
return True
|
||||
except mysql.connector.Error as e:
|
||||
@@ -80,7 +80,6 @@ class Paymentmodel:
|
||||
cursor.callproc("GetPaymentById", (payment_id,))
|
||||
for result in cursor.stored_results():
|
||||
payment_data = result.fetchone()
|
||||
# Convert to array for template
|
||||
if payment_data:
|
||||
payment_data = [
|
||||
payment_data.get('Payment_Id'),
|
||||
@@ -117,42 +116,99 @@ class Paymentmodel:
|
||||
|
||||
@staticmethod
|
||||
def delete_payment(payment_id):
|
||||
"""
|
||||
Deletes a payment and resets the related inpayment fields in one go.
|
||||
Returns (success, pmc_no, invoice_no)
|
||||
"""
|
||||
connection = Paymentmodel.get_connection()
|
||||
if not connection:
|
||||
return False, None, None
|
||||
|
||||
try:
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
# Fetch PMC & Invoice before deleting
|
||||
cursor.callproc('GetPaymentPMCInvoiceById', [payment_id])
|
||||
|
||||
record = {}
|
||||
for result in cursor.stored_results():
|
||||
record = result.fetchone() or {}
|
||||
if not record:
|
||||
return False, None, None
|
||||
|
||||
pmc_no = record['PMC_No']
|
||||
invoice_no = record['Invoice_No']
|
||||
|
||||
# Step 2: Delete the payment using the stored procedure
|
||||
# Delete payment
|
||||
cursor.callproc("DeletePayment", (payment_id,))
|
||||
connection.commit()
|
||||
|
||||
# Step 3: Reset inpayment fields using the stored procedure
|
||||
# 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}")
|
||||
return False, None, None
|
||||
finally:
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
# ---------------- Item CRUD Methods ----------------
|
||||
@staticmethod
|
||||
def fetch_items(item_type: ItemCRUDType):
|
||||
connection = Paymentmodel.get_connection()
|
||||
items = []
|
||||
if connection:
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
try:
|
||||
cursor.callproc('GetItemsByType', [item_type.value])
|
||||
for result in cursor.stored_results():
|
||||
items = result.fetchall()
|
||||
except mysql.connector.Error as e:
|
||||
print(f"Error fetching {item_type.name}: {e}")
|
||||
finally:
|
||||
cursor.close()
|
||||
connection.close()
|
||||
return items
|
||||
|
||||
@staticmethod
|
||||
def insert_item(item_type: ItemCRUDType, name: str):
|
||||
connection = Paymentmodel.get_connection()
|
||||
if not connection:
|
||||
return False
|
||||
try:
|
||||
cursor = connection.cursor()
|
||||
cursor.callproc('InsertItem', [item_type.value, name])
|
||||
connection.commit()
|
||||
return True
|
||||
except mysql.connector.Error as e:
|
||||
print(f"Error inserting {item_type.name}: {e}")
|
||||
return False
|
||||
finally:
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
@staticmethod
|
||||
def update_item(item_type: ItemCRUDType, item_id: int, new_name: str):
|
||||
connection = Paymentmodel.get_connection()
|
||||
if not connection:
|
||||
return False
|
||||
try:
|
||||
cursor = connection.cursor()
|
||||
cursor.callproc('UpdateItem', [item_type.value, item_id, new_name])
|
||||
connection.commit()
|
||||
return True
|
||||
except mysql.connector.Error as e:
|
||||
print(f"Error updating {item_type.name}: {e}")
|
||||
return False
|
||||
finally:
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
@staticmethod
|
||||
def delete_item(item_type: ItemCRUDType, item_id: int):
|
||||
connection = Paymentmodel.get_connection()
|
||||
if not connection:
|
||||
return False
|
||||
try:
|
||||
cursor = connection.cursor()
|
||||
cursor.callproc('DeleteItem', [item_type.value, item_id])
|
||||
connection.commit()
|
||||
return True
|
||||
except mysql.connector.Error as e:
|
||||
print(f"Error deleting {item_type.name}: {e}")
|
||||
return False
|
||||
finally:
|
||||
cursor.close()
|
||||
connection.close()
|
||||
Reference in New Issue
Block a user