Skip to content

Commit

Permalink
Fixed move, new, pay so math was right and trans log was good.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrogman committed Nov 27, 2024
1 parent eca3ee0 commit 7e93d9d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
4 changes: 2 additions & 2 deletions managarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def payment_received(ctx, *, user: str, amount: float):
if not search_results:
await ctx.followup.send(f"{ctx.user.name} No user found matching the given identifier: {user}")
return
information = {'what': 'payment', 'paymentAmount': amount}
information = {'what': 'payment', 'paidAmount': amount}
await ctx.followup.send("Select the correct user", view=discordFunctions.UpdateSelectorView(search_results, information), ephemeral=True)


Expand All @@ -69,7 +69,7 @@ async def move_user(ctx, *, user: str, amount: float = None):
if not search_results:
await ctx.followup.send(f"No user found matching the given identifier: {user}", ephemeral=True)
return
information = {'what': 'move', 'paymentAmount': amount}
information = {'what': 'move', 'paidAmount': amount}
await ctx.followup.send("Select the correct user", view=discordFunctions.UpdateSelectorView(search_results, information), ephemeral=True)


Expand Down
50 changes: 30 additions & 20 deletions modules/dbFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,27 +121,37 @@ def log_transaction(information):
connection = create_connection()
if connection:
cursor = connection.cursor()

# Loop through each user in the information's "users" list
for user in information.get('users', []):
# Extract data for each user
description = information.get('what', 'Transaction') # General description
entity_id = user.get('primaryEmail', 'general_cost') # Email or 'general_cost'
amount = user.get('paymentAmount', 0.00) # Payment amount
payment_method = user.get('paymentMethod', 'Unknown') # Payment method
if description == "payment":
term_length = str(user.get('term_length', "")) + " Months"
notes = f"Server: {user.get('server')} | Length: {term_length}"

# SQL query to insert a new transaction
insert_query = """
INSERT INTO transactions (description, entity_id, amount, payment_method, notes)
VALUES (%s, %s, %s, %s, %s)
"""
cursor.execute(insert_query, (description, entity_id, amount, payment_method, notes))

# Log success for each user
logging.info(f"Logged transaction for {entity_id} with amount: {amount}")
description = information.get('what', 'Transaction') # General description
amount = information.get('paidAmount')

if description == "payment":
for user in information.get('users', []):
# Extract data for each user
entity_id = user.get('primaryEmail', 'Unknown')
payment_method = user.get('paymentMethod', 'Unknown')

term_length = str(user.get('term_length', "")) + " Months"
notes = f"Server: {user.get('server')} | 4k: {user.get('4k')} | Length: {term_length}"
elif description == "move":
for user in information.get('users', []):
entity_id = user.get('primaryEmail', 'Unknown')
payment_method = user.get('paymentMethod', 'Unknown')
notes = f"Server: {user.get('server')}"
elif description == "newuser":
entity_id = information.get('primaryEmail', 'Unknown')
payment_method = information.get('paymentMethod', 'Unknown')
notes = f"Server: {information.get('server')} | 4k: {information.get('4k')} | Length: {information.get('termLength')}"

# SQL query to insert a new transaction
insert_query = """
INSERT INTO transactions (description, entity_id, amount, payment_method, notes)
VALUES (%s, %s, %s, %s, %s)
"""
cursor.execute(insert_query, (description, entity_id, amount, payment_method, notes))

# Log success for each user
logging.info(f"Logged transaction for {entity_id} with amount: {amount}")

# Commit all changes after the loop
connection.commit()
Expand Down
7 changes: 3 additions & 4 deletions modules/discordFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,8 @@ async def correct_callback(self, button):

if new_server != old_server:
dbFunctions.update_database(self.information.get('id'), "server", new_server)
if self.information['paymentAmount'] is not None:
newPaidAmount = float(self.information['paidAmount']) + float(self.information['paymentAmount'])
if self.information['paidAmount'] is not None:
newPaidAmount = float(self.information['paidAmount']) + float(self.information['users'][0]['paidAmount'])
dbFunctions.update_database(self.information.get('id'), "paidAmount", newPaidAmount)
dbFunctions.log_transaction(information=self.information)
if old_4k != new_4k:
Expand Down Expand Up @@ -638,7 +638,7 @@ async def handle_payment(self, interaction, selected_users):
total_prices['12Month'] += pricing_section['12Month']
user['prices'] = pricing_section

total_amount = self.information['paymentAmount']
total_amount = self.information['paidAmount']
matching_lengths = [key for key, value in total_prices.items() if value == total_amount]
not_rounded = True
each_extra_balance = 0
Expand Down Expand Up @@ -700,7 +700,6 @@ async def handle_move(self, interaction, selected_users):
self.information['startDate'] = selected_users[0].get('startDate')
self.information['endDate'] = selected_users[0].get('endDate')
self.information['status'] = selected_users[0].get('status')
self.information['paidAmount'] = selected_users[0].get('paidAmount')
self.information['id'] = selected_users[0].get('id')
self.information['primaryDiscordId'] = selected_users[0].get('primaryDiscordId')

Expand Down

0 comments on commit 7e93d9d

Please sign in to comment.