started implementation of transactions
This commit is contained in:
Binary file not shown.
@@ -38,18 +38,18 @@ def populate_transactions_table(transactions_table, account_id):
|
|||||||
transactions.sort(key=lambda x: x['timestamp'], reverse=True) # Sort transactions by timestamp in descending order
|
transactions.sort(key=lambda x: x['timestamp'], reverse=True) # Sort transactions by timestamp in descending order
|
||||||
for transaction in transactions: # Insert the transactions into the transactions_table
|
for transaction in transactions: # Insert the transactions into the transactions_table
|
||||||
transactions_table.insert('', 'end', values=(
|
transactions_table.insert('', 'end', values=(
|
||||||
transaction['transaction_id'],
|
transaction['description'],
|
||||||
transaction['transaction_type'],
|
transaction['transaction_type'],
|
||||||
format_balance(transaction['amount']),
|
format_balance(transaction['amount']),
|
||||||
transaction['timestamp'],
|
transaction['timestamp'],
|
||||||
transaction['description'],
|
|
||||||
transaction['account_id'],
|
transaction['account_id'],
|
||||||
transaction['recipient_account_id']
|
transaction['recipient_account_id'],
|
||||||
|
transaction['transaction_id']
|
||||||
))
|
))
|
||||||
|
|
||||||
def display_account_info(account_id):
|
def display_account_info(account_id):
|
||||||
"""Display the account information for the given account ID."""
|
"""Display the account information for the given account ID."""
|
||||||
account_info = get_account(account_id) # Fetch the account details
|
account_info = get_account(account_id)
|
||||||
if account_info is None or 'data' not in account_info:
|
if account_info is None or 'data' not in account_info:
|
||||||
messagebox.showerror("Error", "Could not fetch account details.")
|
messagebox.showerror("Error", "Could not fetch account details.")
|
||||||
return
|
return
|
||||||
@@ -66,7 +66,7 @@ def display_account_info(account_id):
|
|||||||
label_key.grid(row=0, column=i*2, sticky='w', padx=10)
|
label_key.grid(row=0, column=i*2, sticky='w', padx=10)
|
||||||
label_value.grid(row=0, column=i*2+1, sticky='w', padx=10)
|
label_value.grid(row=0, column=i*2+1, sticky='w', padx=10)
|
||||||
global notes_text
|
global notes_text
|
||||||
notes_text.configure(text=account.get('notes', '')) # Use config instead of configuration
|
notes_text.configure(text=account.get('notes', ''))
|
||||||
|
|
||||||
def on_transaction_double_click(event):
|
def on_transaction_double_click(event):
|
||||||
"""Handles double-click event on a transaction in the table."""
|
"""Handles double-click event on a transaction in the table."""
|
||||||
@@ -101,6 +101,7 @@ def edit_account_details():
|
|||||||
description_label.pack()
|
description_label.pack()
|
||||||
description_entry.pack()
|
description_entry.pack()
|
||||||
|
|
||||||
|
|
||||||
notes_label = customtkinter.CTkLabel(edit_window, text="Notes: ")
|
notes_label = customtkinter.CTkLabel(edit_window, text="Notes: ")
|
||||||
notes_entry = customtkinter.CTkEntry(edit_window)
|
notes_entry = customtkinter.CTkEntry(edit_window)
|
||||||
notes_label.pack()
|
notes_label.pack()
|
||||||
@@ -108,6 +109,7 @@ def edit_account_details():
|
|||||||
|
|
||||||
customtkinter.CTkLabel(edit_window, text=" ").pack() # Add space under the address box
|
customtkinter.CTkLabel(edit_window, text=" ").pack() # Add space under the address box
|
||||||
|
|
||||||
|
# Add the OTP code entry and button
|
||||||
otp_button = customtkinter.CTkButton(edit_window, text="Get OTP Code", command=generate_otp)
|
otp_button = customtkinter.CTkButton(edit_window, text="Get OTP Code", command=generate_otp)
|
||||||
otp_button.pack()
|
otp_button.pack()
|
||||||
|
|
||||||
@@ -182,9 +184,6 @@ info_frame = customtkinter.CTkFrame(root)
|
|||||||
info_frame.pack(fill=tk.X)
|
info_frame.pack(fill=tk.X)
|
||||||
display_account_info(account_id)
|
display_account_info(account_id)
|
||||||
|
|
||||||
table_frame = customtkinter.CTkFrame(root)
|
|
||||||
table_frame.pack(fill=tk.BOTH, expand=True)
|
|
||||||
|
|
||||||
# Add buttons for adding a new transaction, requesting the OTP, and editing the account details
|
# Add buttons for adding a new transaction, requesting the OTP, and editing the account details
|
||||||
button_frame = customtkinter.CTkFrame(root)
|
button_frame = customtkinter.CTkFrame(root)
|
||||||
button_frame.pack(fill=tk.X, pady=10)
|
button_frame.pack(fill=tk.X, pady=10)
|
||||||
@@ -195,12 +194,27 @@ request_otp_button.grid(row=0, column=1, padx=10)
|
|||||||
edit_account_details_button = customtkinter.CTkButton(button_frame, text="Edit Account Details", command=edit_account_details)
|
edit_account_details_button = customtkinter.CTkButton(button_frame, text="Edit Account Details", command=edit_account_details)
|
||||||
edit_account_details_button.grid(row=0, column=2, padx=10)
|
edit_account_details_button.grid(row=0, column=2, padx=10)
|
||||||
|
|
||||||
|
table_frame = customtkinter.CTkFrame(root)
|
||||||
|
table_frame.pack(fill=tk.BOTH, expand=True)
|
||||||
|
|
||||||
# Create the transactions table
|
# Create the transactions table
|
||||||
transactions_table = ttk.Treeview(table_frame, columns=("Transaction ID", "Transaction Type", "Amount", "Timestamp", "Description", "Account ID", "Recipient Account ID"), show="headings")
|
transactions_table = ttk.Treeview(table_frame, columns=("Description", "Transaction Type", "Amount", "Timestamp", "Sender", "Recipient", "Transaction ID"), show="headings")
|
||||||
transactions_table.pack(fill=tk.BOTH, expand=True)
|
transactions_table.pack(fill=tk.BOTH, expand=True)
|
||||||
for col in transactions_table["columns"]:
|
for col in transactions_table["columns"]:
|
||||||
transactions_table.heading(col, text=col)
|
transactions_table.heading(col, text=col)
|
||||||
|
|
||||||
|
transactions_table.column("Description", width=100)
|
||||||
|
transactions_table.column("Timestamp", width=75)
|
||||||
|
transactions_table.column("Transaction Type", width=50)
|
||||||
|
transactions_table.column("Amount", width=20)
|
||||||
|
transactions_table.column("Timestamp", width=75)
|
||||||
|
transactions_table.column("Sender", width=20)
|
||||||
|
transactions_table.column("Recipient", width=20)
|
||||||
|
transactions_table.column("Transaction ID", width=100)
|
||||||
|
|
||||||
populate_transactions_table(transactions_table, account_id)
|
populate_transactions_table(transactions_table, account_id)
|
||||||
|
|
||||||
|
transactions_table.bind("<Double-1>", on_transaction_double_click)
|
||||||
|
|
||||||
# Start the main event loop
|
# Start the main event loop
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|||||||
@@ -131,6 +131,22 @@ def get_account(account_id):
|
|||||||
print(f"RequestException: {e}")
|
print(f"RequestException: {e}")
|
||||||
return {'success': False, 'message': "Could not connect to the server. Please try again later."}
|
return {'success': False, 'message': "Could not connect to the server. Please try again later."}
|
||||||
|
|
||||||
|
def get_transaction(transaction_id):
|
||||||
|
"""Retrieves the transaction details for the given transaction_id."""
|
||||||
|
try:
|
||||||
|
with open('application\\session_data.json', 'r') as f:
|
||||||
|
session_data = json.load(f)
|
||||||
|
response = requests.get(CONFIG["server"]["url"] + "/Transaction", cookies=session_data['session_cookie'], params={'transaction_id': transaction_id})
|
||||||
|
response.raise_for_status()
|
||||||
|
return response.json() # Return the JSON response directly
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
print(f"RequestException: {e}")
|
||||||
|
return None, "Could not connect to the server. Please try again later."
|
||||||
|
except ValueError as ve:
|
||||||
|
print(f"ValueError: {ve}")
|
||||||
|
return None, "Invalid JSON response from server."
|
||||||
|
|
||||||
|
|
||||||
def update_account(account_id, otp_code:int, description=None, notes=None):
|
def update_account(account_id, otp_code:int, description=None, notes=None):
|
||||||
"""Updates the account details for the given account_id."""
|
"""Updates the account details for the given account_id."""
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import customtkinter
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from config import CONFIG
|
from config import CONFIG
|
||||||
from connection import logout_client, get_client, update_client, get_accounts, format_balance, generate_otp, change_password
|
from connection import logout_client, get_client, update_client, get_accounts, format_balance, generate_otp, change_password, new_transaction
|
||||||
|
|
||||||
|
|
||||||
# Global variables
|
# Global variables
|
||||||
@@ -284,24 +284,28 @@ button_frame = customtkinter.CTkFrame(root)
|
|||||||
button_frame.grid(row=1, column=0, columnspan=2, sticky='ew', pady=15)
|
button_frame.grid(row=1, column=0, columnspan=2, sticky='ew', pady=15)
|
||||||
|
|
||||||
# Create the OTP button
|
# Create the OTP button
|
||||||
otp_button = customtkinter.CTkButton(button_frame, text="Get OTP Code", command=generate_otp)
|
otp_button = customtkinter.CTkButton(button_frame, text="Get OTP Code", command=generate_otp, width=100)
|
||||||
otp_button.grid(row=0, column=0, padx=5)
|
otp_button.grid(row=0, column=0, padx=3)
|
||||||
|
|
||||||
# Create the reload button
|
# Create the OTP button
|
||||||
reload_button = customtkinter.CTkButton(button_frame, text="Reload", command=reload_info_and_accounts)
|
transaction_button = customtkinter.CTkButton(button_frame, text="New Transaction", command=new_transaction, width=100)
|
||||||
reload_button.grid(row=0, column=1, padx=5)
|
transaction_button.grid(row=0, column=1, padx=3)
|
||||||
|
|
||||||
# Create reset password button
|
# Create reset password button
|
||||||
password_button = customtkinter.CTkButton(button_frame, text="Reset Password", command=change_password_box)
|
password_button = customtkinter.CTkButton(button_frame, text="Reset Password", command=change_password_box, width=100)
|
||||||
password_button.grid(row=0, column=2, padx=5)
|
password_button.grid(row=0, column=2, padx=3)
|
||||||
|
|
||||||
|
# Create the reload button
|
||||||
|
reload_button = customtkinter.CTkButton(button_frame, text="Refresh", command=reload_info_and_accounts, width=50)
|
||||||
|
reload_button.grid(row=0, column=3, padx=3)
|
||||||
|
|
||||||
# Create the logout button
|
# Create the logout button
|
||||||
logout_button = customtkinter.CTkButton(button_frame, text="Logout", command=logout)
|
logout_button = customtkinter.CTkButton(button_frame, text="Logout", command=logout, width=50)
|
||||||
logout_button.grid(row=0, column=3, padx=5)
|
logout_button.grid(row=0, column=4, padx=3)
|
||||||
|
|
||||||
# Create the exit button
|
# Create the exit button
|
||||||
exit_button = customtkinter.CTkButton(button_frame, text="Exit", command=exit_application)
|
exit_button = customtkinter.CTkButton(button_frame, text="Exit", command=exit_application, width=50)
|
||||||
exit_button.grid(row=0, column=4, padx=5)
|
exit_button.grid(row=0, column=5, padx=3)
|
||||||
|
|
||||||
# Display client info after creating the buttons
|
# Display client info after creating the buttons
|
||||||
frame = customtkinter.CTkFrame(root)
|
frame = customtkinter.CTkFrame(root)
|
||||||
@@ -319,10 +323,8 @@ root.grid_columnconfigure(1, weight=1)
|
|||||||
|
|
||||||
# Create the table
|
# Create the table
|
||||||
table = ttk.Treeview(table_frame, columns=('Name', 'Account ID', 'Balance', 'Account Type'), show='headings')
|
table = ttk.Treeview(table_frame, columns=('Name', 'Account ID', 'Balance', 'Account Type'), show='headings')
|
||||||
table.heading('Name', text='Name')
|
for col in table['columns']:
|
||||||
table.heading('Account ID', text='Account ID')
|
table.heading(col, text=col)
|
||||||
table.heading('Balance', text='Balance')
|
|
||||||
table.heading('Account Type', text='Account Type')
|
|
||||||
|
|
||||||
# Set the column widths
|
# Set the column widths
|
||||||
table.column('Name', width=200)
|
table.column('Name', width=200)
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
{"session_cookie": {"session": "HHymBLOCpW9YTcajilxYA_B9aVPJ1FyS75TAz2995jk"}, "client_id": "d18e5ae0"}
|
{"session_cookie": {"session": "fhCFtlJIX2pSU0z4Cn4yMBZpKa4WAEBGJLu00aGXOtc"}, "client_id": "d18e5ae0"}
|
||||||
@@ -12,6 +12,49 @@ import sys
|
|||||||
### Functions ###
|
### Functions ###
|
||||||
#################
|
#################
|
||||||
|
|
||||||
|
if len(sys.argv) > 3: # Check if the transaction description is provided as a command line argument
|
||||||
|
transaction_id = sys.argv[1]
|
||||||
|
transaction_description = sys.argv[3]
|
||||||
|
else:
|
||||||
|
messagebox.showerror("Error", "Transaction ID and description were not provided by the server.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def display_transaction_info(transaction_id):
|
||||||
|
"""Display the transaction information for the given transaction ID."""
|
||||||
|
response = get_transaction(transaction_id) # Fetch the transaction details
|
||||||
|
print(response)
|
||||||
|
if response is None or 'data' not in response:
|
||||||
|
messagebox.showerror("Error", "Transaction details not found.")
|
||||||
|
return
|
||||||
|
|
||||||
|
transaction = response.get('data', {}) # Get transaction data or empty dictionary
|
||||||
|
if not transaction:
|
||||||
|
messagebox.showerror("Error", "Transaction details not found.")
|
||||||
|
return
|
||||||
|
global transaction_description
|
||||||
|
t_id = transaction['transaction_id']
|
||||||
|
t_description = transaction['description']
|
||||||
|
t_amount = format_balance(transaction['amount'])
|
||||||
|
t_timestamp = transaction['timestamp']
|
||||||
|
t_sender = transaction['account_id']
|
||||||
|
t_recipient = transaction['recipient_account_id']
|
||||||
|
t_type = transaction['transaction_type']
|
||||||
|
|
||||||
|
# Create labels for each piece of transaction information and pack them into the transaction_frame
|
||||||
|
id_label = customtkinter.CTkLabel(transaction_frame, text=f"Transaction ID: {t_id}")
|
||||||
|
id_label.pack()
|
||||||
|
description_label = customtkinter.CTkLabel(transaction_frame, text=f"Description: {t_description}")
|
||||||
|
description_label.pack()
|
||||||
|
amount_label = customtkinter.CTkLabel(transaction_frame, text=f"Amount: {t_amount}")
|
||||||
|
amount_label.pack()
|
||||||
|
timestamp_label = customtkinter.CTkLabel(transaction_frame, text=f"Timestamp: {t_timestamp}")
|
||||||
|
timestamp_label.pack()
|
||||||
|
sender_label = customtkinter.CTkLabel(transaction_frame, text=f"Sender: {t_sender}")
|
||||||
|
sender_label.pack()
|
||||||
|
recipient_label = customtkinter.CTkLabel(transaction_frame, text=f"Recipient: {t_recipient}")
|
||||||
|
recipient_label.pack()
|
||||||
|
type_label = customtkinter.CTkLabel(transaction_frame, text=f"Transaction Type: {t_type}")
|
||||||
|
type_label.pack()
|
||||||
|
|
||||||
|
|
||||||
##############
|
##############
|
||||||
@@ -24,6 +67,10 @@ root.title(f"Transactions: {transaction_description}")
|
|||||||
root.iconbitmap("application/luxbank.ico")
|
root.iconbitmap("application/luxbank.ico")
|
||||||
root.geometry("800x400")
|
root.geometry("800x400")
|
||||||
|
|
||||||
|
# Create a close button at the top of the window
|
||||||
|
close_button = customtkinter.CTkButton(root, text="Close", command=root.destroy)
|
||||||
|
close_button.pack(side="top", anchor="e")
|
||||||
|
|
||||||
if CONFIG["preferences"]["dark_theme"] == "dark": # Check if dark mode is enabled
|
if CONFIG["preferences"]["dark_theme"] == "dark": # Check if dark mode is enabled
|
||||||
customtkinter.set_appearance_mode("dark") # Set the style for dark mode
|
customtkinter.set_appearance_mode("dark") # Set the style for dark mode
|
||||||
else:
|
else:
|
||||||
@@ -32,3 +79,11 @@ else:
|
|||||||
# Display main window title
|
# Display main window title
|
||||||
welcome_label = customtkinter.CTkLabel(root, text=f"Transactions: {transaction_description}", font=("Helvetica", 24))
|
welcome_label = customtkinter.CTkLabel(root, text=f"Transactions: {transaction_description}", font=("Helvetica", 24))
|
||||||
welcome_label.pack(pady=10)
|
welcome_label.pack(pady=10)
|
||||||
|
|
||||||
|
# Create a frame for the transaction details
|
||||||
|
transaction_frame = customtkinter.CTkFrame(root)
|
||||||
|
transaction_frame.pack(pady=10)
|
||||||
|
display_transaction_info(transaction_id)
|
||||||
|
|
||||||
|
|
||||||
|
root.mainloop()
|
||||||
Reference in New Issue
Block a user