def update_user_bank_account(user_selected_bank_account): statement = "UPDATE BANKACCOUNT SET Name = ?, Amount = ?, Description = ?, Account_ID = ?, User_ID = ? WHERE Account_ID = ?" cursor().execute(statement, ( user_selected_bank_account.Name, user_selected_bank_account.Amount, user_selected_bank_account.Description, user_selected_bank_account.Account_ID, user_selected_bank_account.User_ID, user_selected_bank_account.Account_ID, )) commit()
def commit_incomestatement(self): """ This method is used to input a new IncomeStatement into the database. ... Parameters ---------- self : IncomeStatement Object A fully created/populated income statement object """ statement = "INSERT INTO INCOMESTATEMENT (Date, Amount, UnBudgeted, Description, User_ID) VALUES (?, ?, ?, ?, ?)" cursor().execute(statement, (self.Date, self.Amount, self.UnBudgeted, self.Description, self.User_ID)) commit()
def commit_bank_accout(self): """ This method is used to input a new BankAccount into the database. ... Parameters ---------- self : BankAccount Object A fully created/populated BankAccount Object """ statement = "INSERT INTO BANKACCOUNT (Name, Amount, Description, User_ID) VALUES (?, ?, ?, ?)" cursor().execute( statement, (self.Name, self.Amount, self.Description, self.User_ID)) commit()
def commit_user(self): """ This method is used to input a new User into the database. Parameters ---------- self : IncomeStatement Object A fully created/populated User object """ statement = "INSERT INTO USER (Username, First_Name, Last_Name, Password) VALUES (?, ?, ?, ?)" cursor().execute(statement, ( self.Username, self.First_Name, self.Last_Name, self.Password, )) commit()
def edit_incomestatement_instance(user_selected_statement): user_still_editing_selected_income_statement = True while user_still_editing_selected_income_statement: #Printing the Income Statement the user is editng print( "\n-----------------------\n|Income Statement Info|\n-----------------------" ) print("\n\nDate: " + str(user_statements[user_selected_statement].Date)) print( "Description: " + str(user_statements[user_selected_statement].Description)) print("Amount: $" + str(user_statements[user_selected_statement].Amount)) user_edit_choice = input( "\nPlease enter the number of what you would like to enter: \n\n1)Date\n2)Description\n3)Amount\n4)Done Editing\n\nYour Input: " ) while user_edit_choice == "": user_edit_choice = input( "\nPlease enter one of the valid options: \n\n1)Date\n2)Description\n3)Amount\n4)Done Editing\n\nYour Input: " ) user_edit_choice = int(user_edit_choice) if user_edit_choice == 4: try: user_still_editing_selected_income_statement = False statement = "UPDATE INCOMESTATEMENT SET Date = ?, Amount = ?, Description = ?, IncomeStatement_ID = ?, UnBudgeted = ?, User_ID = ? WHERE IncomeStatement_ID = ?" cursor().execute(statement, ( user_statements[user_selected_statement].Date, user_statements[user_selected_statement].Amount, user_statements[user_selected_statement]. Description, user_statements[user_selected_statement]. IncomeStatement_ID, user_statements[user_selected_statement]. UnBudgeted, user_statements[user_selected_statement].User_ID, user_statements[user_selected_statement]. IncomeStatement_ID, )) commit() #TODO : When the user edits an IncomeStatement, all of the budgets associated with the income statement have to be edited as well so money that doesn't # exist for the user is not sitting inside of budgets except Exception as e: print( "\n\nUnable to commit that to the database, try again!\nIf this continues try retarting the app." ) logging.exception("Unable to made update to database") elif user_edit_choice == 1: #Asking the user for their input for the date of their income print( "\n----------------------------------------------------------\n" ) date = input( "\nPlease input the new date you received the income (Please use the MM/DD/YYYY format): " ) gooddate = False #Trying to turn the date the user put in into a date time object #If it works then GoodDate is set to True and the program won't fall into the while #loop below for checking user dataBud try: date = datetime.datetime.strptime(date, '%m/%d/%Y') gooddate = True #This is just here so the try command doesn't yell at me except Exception as e: logging.exception("Date format not correct") pass #If the date entered by the user wasn't able to be put into a date time object this loop will run #It will run the same code above but will keep running until the object is able to be created #by the users input while gooddate == False: print( "\n----------------------------------------------------------\n" ) date = input( "\nPlease input the date using the correct formatting (Please use the MM/DD/YYYY format)\n\nInput: " ) try: date = datetime.datetime.strptime(date, '%m/%d/%Y') gooddate = True except: logging.exception("Date format not correct") pass user_statements[user_selected_statement].Date = date elif user_edit_choice == 2: #Asking the user to input a description for their paycheck. This is one of the key ways that users will use determine what the paycheck is # print("\n----------------------------------------------------------\n") description = input( "\nPlease enter a short description of the income.\nThis, along with the date, will be how you have to recognize the income statement. Please be descriptive.\n\nInput:" ) while description == "": print( "\n----------------------------------------------------------\n" ) description = input( "\nPlease enter something, an empty input is not allowed.\nThis, along with the date, will be how you have to recognize the income statement. Please be descriptive.\n\nInput:" ) user_statements[ user_selected_statement].Description = description elif user_edit_choice == 3: #Asking the user to enter in the money amount of their income statement print( "\n----------------------------------------------------------\n" ) amount = input( "\nPlease input the amount of the income (Please use standard money input)\n\nInput: $" ) goodmoney = False #This will try to format the input into the ##.## format. If it can not format it into a two decimal format then it will fail #and will run the accept statement bwloe try: amount = "{:.2f}".format(float(amount)) goodmoney = True change_income = True #This will only run if the amount the user input wasn't able to be formated correctly except Exception as e: logging.exception("Money format not correct") #This loop will run until the input of the user is able to be formated correctly for storage while goodmoney == False: print( "\n----------------------------------------------------------\n" ) amount = input( "\nThat format didn't work, please try again (Please use standard money input without commas)\n\nInput: $" ) try: amount = "{:.2f}".format(float(amount)) goodmoney = True change_income = True except Exception as e: logging.exception("Money format not correct") print(e) user_statements[user_selected_statement].Amount = amount user_statements[ user_selected_statement].UnBudgeted = amount
def RunApp(user): #Loading the global defaults for logging logger() #If the user object is empty, the the user is asked to login if user == None: logger() load_DB(os.getcwd() + '/BudgetBuddy.db') user = None print( '--------------------------\n|WELCOME TO BUDGET BUDDY!|\n--------------------------' ) user = login() cont = True #If the user object is filled, the program will continue to the main menu elif user != None: cont = True #If for something else happens, the program will be reset and start over else: user = None RunApp(user) #Loop for the main menu while cont == True: Menu_Choice = input( "\n\n-----------------------------------------------------\n|Please choose what you would like to interact with:|\n----------------------------------------------------- \n\n1)Income Statements\n2)Expenses \n3)Budgets \n4)Bank Accounts \n5)Your Account \n6)Exit the Program \n\nYour Input:" ) while Menu_Choice == '': Menu_Choice = input( "\n\n-----------------------------------------------------\n|Please choose what you would like to interact with:|\n----------------------------------------------------- \n\n1)Income Statements\n2)Expenses \n3)Budgets \n4)Bank Accounts \n5)Your Account \n6)Exit the Program \n\nYour Input:" ) Menu_Choice = int(Menu_Choice) if Menu_Choice == 1: cont1 = True while cont1: IncomeStatement_Choice = int( input( "\n\n\n------------------------------------------\n|Please select what you would like to do:|\n------------------------------------------ \n\n1)Create a New Income Statement \n2)Edit an Existing Income Statement \n3)View Your Existing Income Statements \n4)Return to the Main Menu\n\nYour Input:" )) while IncomeStatement_Choice != 1 and IncomeStatement_Choice != 2 and IncomeStatement_Choice != 3 and IncomeStatement_Choice != 4: IncomeStatement_Choice = int( input( "\n\n\n------------------------------------------\n|Please only select one of these choices:|\n------------------------------------------ \n\n1)Create a New Income Statement \n2)Edit an Existing Income Statement \n3)View Your Existing Income Statements \n4)Return to the Main Menu\n\nYour Input:" )) if IncomeStatement_Choice == 1: IncomeStatement.create(user) elif IncomeStatement_Choice == 2: IncomeStatement.edit_user_statements(user) elif IncomeStatement_Choice == 3: IncomeStatement.view_user_statements(user) elif IncomeStatement_Choice == 4: RunApp(user) elif Menu_Choice == 2: pass elif Menu_Choice == 3: cont3 = True while cont3: budget_choice = input( "\n\n\n------------------------------------------\n|Please select what you would like to do:|\n------------------------------------------ \n\n1)Create a New Budget \n2)Edit an Existing Budget \n3)View Your Existing Budgets \n4)Return to the Main Menu\n\nYour Input:" ) while budget_choice == "" or budget_choice != '1' and budget_choice != '2' and budget_choice != '3' and budget_choice != '4': budget_choice = input( "\n\n\n--------------------------------------------\n|Please only select one of these statements:|\n--------------------------------------------\n\n1)Create a New Budget \n2)Edit an Existing Budget \n3)View Your Existing Budgets \n4)Return to the Main Menu\n\nYour Input:" ) if budget_choice == '1': pass elif budget_choice == '2': pass elif budget_choice == '3': Budget.view_user_budgets(user) elif budget_choice == '4': RunApp(user) elif Menu_Choice == 4: cont4 = True while cont4: bank_account_choice = input( "\n\n\n------------------------------------------\n|Please select what you would like to do:|\n------------------------------------------ \n\n1)Create a New Bank Account \n2)Edit an Existing Bank Account \n3)View Your Existing Bank Accounts \n4)Return to the Main Menu\n\nYour Input:" ) while bank_account_choice == "" or bank_account_choice != '1' and bank_account_choice != '2' and bank_account_choice != '3' and bank_account_choice != '4': bank_account_choice = input( "\n\n\n--------------------------------------------\n|Please only select one of these statements:|\n--------------------------------------------\n\n1)Create a New Bank Account \n2)Edit an Existing Bank Account \n3)View Your Existing Bank Accounts \n4)Return to the Main Menu\n\nYour Input:" ) if bank_account_choice == '1': BankAccount.create(user) elif bank_account_choice == '2': BankAccount.edit_user_bank_accounts(user) elif bank_account_choice == '3': BankAccount.view_user_bank_accounts(user) elif bank_account_choice == '4': RunApp(user) elif Menu_Choice == 5: pass elif Menu_Choice == 6: cont = False commit() print("\n\nClosing DataBase...") print("\nHave a nice day! ") close() exit()